fixed periodic dates
This commit is contained in:
parent
f076338b3f
commit
c81ceaf71b
|
|
@ -277,43 +277,7 @@ abstract class Report
|
|||
|
||||
public function getFormattedDate($event, $date)
|
||||
{
|
||||
$formatted_date = null;
|
||||
|
||||
switch ($event->class->getSetting('period')) {
|
||||
case 'yearly':
|
||||
$financial_year = $this->getFinancialYear($event->class->model->year);
|
||||
|
||||
if ($date->greaterThanOrEqualTo($financial_year->getStartDate()) && $date->lessThanOrEqualTo($financial_year->getEndDate())) {
|
||||
if (setting('localisation.financial_denote') == 'begins') {
|
||||
$formatted_date = $financial_year->getStartDate()->copy()->format($this->getYearlyDateFormat());
|
||||
} else {
|
||||
$formatted_date = $financial_year->getEndDate()->copy()->format($this->getYearlyDateFormat());
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 'quarterly':
|
||||
$quarters = $this->getFinancialQuarters($event->class->model->year);
|
||||
|
||||
foreach ($quarters as $quarter) {
|
||||
if ($date->lessThan($quarter->getStartDate()) || $date->greaterThan($quarter->getEndDate())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$start = $quarter->getStartDate()->format($this->getQuarterlyDateFormat($event->class->model->year));
|
||||
$end = $quarter->getEndDate()->format($this->getQuarterlyDateFormat($event->class->model->year));
|
||||
|
||||
$formatted_date = $start . '-' . $end;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
$formatted_date = $date->copy()->format($this->getMonthlyDateFormat($event->class->model->year));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $formatted_date;
|
||||
return $this->getPeriodicDate($date, $event->class->getSetting('period'), $event->class->model->year);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -383,7 +383,7 @@ abstract class Report
|
|||
};
|
||||
|
||||
for ($j = 0; $j <= $counter; $j++) {
|
||||
$date = $this->getFormattedDate($start);
|
||||
$date = $this->getPeriodicDate($start, $this->getPeriod(), $this->year);
|
||||
|
||||
$this->dates[] = $date;
|
||||
|
||||
|
|
@ -425,7 +425,7 @@ abstract class Report
|
|||
// Make groups extensible
|
||||
$item = $this->applyGroups($item);
|
||||
|
||||
$date = $this->getFormattedDate(Date::parse($item->$date_field));
|
||||
$date = $this->getPeriodicDate(Date::parse($item->$date_field), $this->getPeriod(), $this->year);
|
||||
|
||||
if (!isset($item->$group_field)) {
|
||||
continue;
|
||||
|
|
@ -469,7 +469,7 @@ abstract class Report
|
|||
// Make groups extensible
|
||||
$item = $this->applyGroups($item);
|
||||
|
||||
$date = $this->getFormattedDate(Date::parse($item->$date_field));
|
||||
$date = $this->getPeriodicDate(Date::parse($item->$date_field), $this->getPeriod(), $this->year);
|
||||
|
||||
if (!isset($item->$group_field)) {
|
||||
continue;
|
||||
|
|
@ -536,62 +536,6 @@ abstract class Report
|
|||
return $model;
|
||||
}
|
||||
|
||||
public function getFormattedDate($date)
|
||||
{
|
||||
$formatted_date = null;
|
||||
|
||||
switch ($this->getPeriod()) {
|
||||
case 'yearly':
|
||||
$financial_year = $this->getFinancialYear($this->year);
|
||||
|
||||
if ($date->greaterThanOrEqualTo($financial_year->getStartDate()) && $date->lessThanOrEqualTo($financial_year->getEndDate())) {
|
||||
if (setting('localisation.financial_denote') == 'begins') {
|
||||
$formatted_date = $financial_year->copy()->getStartDate()->format($this->getYearlyDateFormat());
|
||||
} else {
|
||||
$formatted_date = $financial_year->copy()->getEndDate()->format($this->getYearlyDateFormat());
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 'quarterly':
|
||||
$quarters = $this->getFinancialQuarters($this->year);
|
||||
|
||||
foreach ($quarters as $quarter) {
|
||||
if ($date->lessThan($quarter->getStartDate()) || $date->greaterThan($quarter->getEndDate())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$start = $quarter->copy()->getStartDate()->format($this->getQuarterlyDateFormat($this->year));
|
||||
$end = $quarter->copy()->getEndDate()->format($this->getQuarterlyDateFormat($this->year));
|
||||
|
||||
$formatted_date = $start . ' - ' . $end;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'weekly':
|
||||
$weeks = $this->getFinancialWeeks($this->year);
|
||||
|
||||
foreach ($weeks as $week) {
|
||||
if ($date->lessThan($week->getStartDate()) || $date->greaterThan($week->getEndDate())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$start = $week->copy()->getStartDate()->format($this->getDailyDateFormat($this->year));
|
||||
$end = $week->copy()->getEndDate()->format($this->getDailyDateFormat($this->year));
|
||||
|
||||
$formatted_date = $start . ' - ' . $end;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
$formatted_date = $date->copy()->format($this->getMonthlyDateFormat($this->year));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $formatted_date;
|
||||
}
|
||||
|
||||
public function getUrl($action = 'print')
|
||||
{
|
||||
$url = company_id() . '/common/reports/' . $this->model->id . '/' . $action;
|
||||
|
|
@ -699,4 +643,10 @@ abstract class Report
|
|||
{
|
||||
return '#' . $this->randHexColorPart() . $this->randHexColorPart() . $this->randHexColorPart();
|
||||
}
|
||||
|
||||
// @deprecated 3.1
|
||||
public function getFormattedDate($date)
|
||||
{
|
||||
return $this->getPeriodicDate($date, $this->getPeriod(), $this->year);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -260,6 +260,60 @@ trait DateTime
|
|||
return 'Y';
|
||||
}
|
||||
|
||||
public function getPeriodicDate(Date $date, string $period, string $year): string
|
||||
{
|
||||
switch ($period) {
|
||||
case 'yearly':
|
||||
$financial_year = $this->getFinancialYear($year);
|
||||
|
||||
if ($date->greaterThanOrEqualTo($financial_year->getStartDate()) && $date->lessThanOrEqualTo($financial_year->getEndDate())) {
|
||||
if (setting('localisation.financial_denote') == 'begins') {
|
||||
$formatted_date = $financial_year->copy()->getStartDate()->format($this->getYearlyDateFormat());
|
||||
} else {
|
||||
$formatted_date = $financial_year->copy()->getEndDate()->format($this->getYearlyDateFormat());
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 'quarterly':
|
||||
$quarters = $this->getFinancialQuarters($year);
|
||||
|
||||
foreach ($quarters as $quarter) {
|
||||
if ($date->lessThan($quarter->getStartDate()) || $date->greaterThan($quarter->getEndDate())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$start = $quarter->copy()->getStartDate()->format($this->getQuarterlyDateFormat($year));
|
||||
$end = $quarter->copy()->getEndDate()->format($this->getQuarterlyDateFormat($year));
|
||||
|
||||
$formatted_date = $start . ' - ' . $end;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'weekly':
|
||||
$weeks = $this->getFinancialWeeks($year);
|
||||
|
||||
foreach ($weeks as $week) {
|
||||
if ($date->lessThan($week->getStartDate()) || $date->greaterThan($week->getEndDate())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$start = $week->copy()->getStartDate()->format($this->getDailyDateFormat($year));
|
||||
$end = $week->copy()->getEndDate()->format($this->getDailyDateFormat($year));
|
||||
|
||||
$formatted_date = $start . ' - ' . $end;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
$formatted_date = $date->copy()->format($this->getMonthlyDateFormat($year));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $formatted_date;
|
||||
}
|
||||
|
||||
public function getTimezones(): array
|
||||
{
|
||||
// The list of available timezone groups to use.
|
||||
|
|
|
|||
Loading…
Reference in New Issue