You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.1 KiB
62 lines
2.1 KiB
<?php
|
|
|
|
class CreateComboNo
|
|
{
|
|
private $comboarr = [
|
|
'week' => 'BW002',
|
|
'month' => 'EM002',
|
|
'quarter' => 'EQ002',
|
|
'half' => 'HY002',
|
|
'year' => 'EY002'
|
|
];
|
|
private $bwarr = [
|
|
'week', 'month', 'week', 'month', 'week', 'quarter',
|
|
'week', 'month', 'week', 'month', 'week', 'half',
|
|
'week', 'month', 'week', 'month', 'week', 'quarter',
|
|
'week', 'month', 'week', 'month', 'week', 'year'
|
|
];
|
|
private $emarr = [
|
|
'month', 'month', 'quarter', 'month', 'month', 'half',
|
|
'month', 'month', 'quarter', 'month', 'month', 'year'
|
|
];
|
|
private $combo;
|
|
private $startdate;
|
|
private $enddate;
|
|
public function __construct($combo, $startdate, $enddate)
|
|
{
|
|
$this->combo = $combo;
|
|
$this->startdate = $startdate;
|
|
$this->enddate = $enddate;
|
|
}
|
|
public function getComboNo()
|
|
{
|
|
$comboarr = (array) $this->combo === 'bw' ? $this->bwarr : $this->emarr;
|
|
|
|
$startdate = new DateTime($this->startdate);
|
|
$enddate = new DateTime($this->enddate);
|
|
|
|
$interval = date_diff($startdate, $enddate);
|
|
|
|
$months = $interval->y * 12 + $interval->m;
|
|
$months = $this->combo === 'bw' ? $months * 2 : $months;
|
|
|
|
$newarr = [];
|
|
$idx = 0;
|
|
$ori_first_month = date('m', strtotime($this->startdate));
|
|
$first_day = date('Y-m-d', strtotime($this->startdate . ' + 3 days'));
|
|
$new_first_month = date('m', strtotime($first_day));
|
|
if ($ori_first_month != $new_first_month) {
|
|
$first_day = date('Y-m-d', strtotime($this->startdate));
|
|
}
|
|
$scheduleDate = new DateTime($first_day);
|
|
for ($i = 0; $i <= $months; $i++) {
|
|
$newarr[] = [$this->comboarr[$comboarr[$idx]], $scheduleDate->format("Y-m-d")];
|
|
$idx++;
|
|
$scheduleDate = $scheduleDate->modify("+1 month");
|
|
if ($idx >= count($comboarr)) {
|
|
$idx = 0;
|
|
}
|
|
}
|
|
return json_encode($newarr);
|
|
}
|
|
}
|
|
|