diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index 82ec5c4e..6f4c6ddb 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -33,6 +33,7 @@ use App\Entity\BatterySize; use App\Entity\JobOrder; use DateTime; +use DateInterval; class CMBRiderAPIHandler implements RiderAPIHandlerInterface { @@ -305,25 +306,24 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface // get JOs assigned to rider for the month given // setup start date and end dates // get current year - $month = $req->query->get('month'); - $year = $req->query->get('year'); - $current_date = new DateTime(); - $current_year = $current_date->format('Y'); - if ($period == 'thismonth') + if ($period == 'lastmonth') { - $month = $current_date->format('m'); + $date_interval = new DateInterval('P1M'); + $period_date = $current_date->sub($date_interval); } else - { - } + $period_date = $current_date; + + $period_year = $period_date->format('Y'); + $period_month = $period_date->format('m'); // get number of days in month requested - $last_day = cal_days_in_month(CAL_GREGORIAN, $month, $current_year); + $last_day = cal_days_in_month(CAL_GREGORIAN, $period_month, $period_year); - $s_date = $current_year . '-' . $month . '-01 00:00:00'; - $e_date = $current_year . '-' . $month . '-' . $last_day . ' 23:59:59'; + $s_date = $period_year . '-' . $period_month . '-01 00:00:00'; + $e_date = $period_year . '-' . $period_month . '-' . $last_day . ' 23:59:59'; $qb = $this->em->getRepository(JobOrder::class)->createQueryBuilder('j'); @@ -767,6 +767,8 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface $jo->requeue(); + // TODO: do we leave JO as assigned to rider? + // add event log $rider = $this->session->getRider(); $event = new JOEvent();