Redo command to include open job orders.
This commit is contained in:
parent
4e1613540d
commit
789c919179
2 changed files with 31 additions and 71 deletions
|
|
@ -26,7 +26,7 @@ use App\Service\WarrantyHandler;
|
|||
use DateTime;
|
||||
use DateInterval;
|
||||
|
||||
class FulfillAssignedJobOrderCommand extends Command
|
||||
class FulfillOpenJobOrderCommand extends Command
|
||||
{
|
||||
protected $em;
|
||||
protected $wh;
|
||||
|
|
@ -41,9 +41,9 @@ class FulfillAssignedJobOrderCommand extends Command
|
|||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('joborder:fulfillassignednosms')
|
||||
->setDescription('Fulfill assigned job orders without sending an SMS message.')
|
||||
->setHelp('Mark assigned job orders as fulfilled and should not send a SMS message. Date format: YYYY-MM-DD')
|
||||
$this->setName('joborder:fulfillopenjosnosms')
|
||||
->setDescription('Fulfill open job orders without sending an SMS message.')
|
||||
->setHelp('Mark open job orders as fulfilled and should not send a SMS message. Date format: YYYY-MM-DD')
|
||||
->addArgument('end_date', InputArgument::REQUIRED, 'End date. Format: YYYY-MM-DD');
|
||||
}
|
||||
|
||||
|
|
@ -52,15 +52,29 @@ class FulfillAssignedJobOrderCommand extends Command
|
|||
// get the input date
|
||||
$str_date_end = $input->getArgument('end_date');
|
||||
|
||||
// retrieve job orders that have status assigned and has not been fulfilled starting from input date and before.
|
||||
// append the 23:59:59 to end date
|
||||
$str_date_end = $str_date_end . ' ' . '23:59:59';
|
||||
|
||||
// retrieve job orders that are open and have not been fulfilled starting from input date and before.
|
||||
// starting time to count is date schedule
|
||||
$date_end = new DateTime($str_date_end);
|
||||
|
||||
$query = $this->em->createQuery('SELECT jo FROM App\Entity\JobOrder jo WHERE jo.status = :status
|
||||
error_log($date_end->format('Y-m-d H:i:s'));
|
||||
|
||||
$query = $this->em->createQuery('SELECT jo FROM App\Entity\JobOrder jo
|
||||
WHERE (jo.status = :pending_status
|
||||
OR jo.status = :rider_assign_status
|
||||
OR jo.status = :assigned_status
|
||||
OR jo.status = :in_progress_status
|
||||
OR jo.status = :in_transit_status)
|
||||
AND jo.date_schedule <= :date_end');
|
||||
|
||||
$jo_results = $query->setParameters([
|
||||
'status' => JOStatus::ASSIGNED,
|
||||
'pending_status' => JOStatus::PENDING,
|
||||
'rider_assign_status' => JOStatus::RIDER_ASSIGN,
|
||||
'assigned_status' => JOStatus::ASSIGNED,
|
||||
'in_progress_status' => JOStatus::IN_PROGRESS,
|
||||
'in_transit_status' => JOStatus::IN_TRANSIT,
|
||||
'date_end' => $date_end,
|
||||
])
|
||||
->getResult();
|
||||
|
|
@ -88,75 +102,19 @@ class FulfillAssignedJobOrderCommand extends Command
|
|||
|
||||
$this->em->persist($event);
|
||||
|
||||
// update the customer vehicle battery record
|
||||
$this->updateVehicleBattery($jo);
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
// check if new battery
|
||||
// if yes, create warranty
|
||||
if ($this->checkIfNewBattery($jo))
|
||||
{
|
||||
$this->createWarranty($jo, $user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function updateVehicleBattery(JobOrder $jo)
|
||||
{
|
||||
// check if new battery
|
||||
if (!($this->checkIfNewBattery($jo)))
|
||||
return;
|
||||
|
||||
// customer vehicle
|
||||
$cv = $jo->getCustomerVehicle();
|
||||
if ($cv == null)
|
||||
return;
|
||||
|
||||
// invoice
|
||||
$invoice = $jo->getInvoice();
|
||||
if ($invoice == null)
|
||||
return;
|
||||
|
||||
// invoice items
|
||||
$items = $invoice->getItems();
|
||||
if (count($items) <= 0)
|
||||
return;
|
||||
|
||||
// get first battery from invoice
|
||||
$battery = null;
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$battery = $item->getBattery();
|
||||
if ($battery != null)
|
||||
break;
|
||||
}
|
||||
|
||||
// no battery in order
|
||||
if ($battery == null)
|
||||
return;
|
||||
|
||||
// warranty expiration
|
||||
$warr = $jo->getWarrantyClass();
|
||||
$warr_months = 0;
|
||||
if ($warr == WarrantyClass::WTY_PRIVATE)
|
||||
$warr_months = $battery->getWarrantyPrivate();
|
||||
else if ($warr == WarrantyClass::WTY_COMMERCIAL)
|
||||
$warr_months = $battery->getWarrantyCommercial();
|
||||
else if ($warr == WarrantyClass::WTY_TNV)
|
||||
$warr_months = 12;
|
||||
|
||||
$warr_date = new DateTime();
|
||||
$warr_date->add(new DateInterval('P' . $warr_months . 'M'));
|
||||
|
||||
// update customer vehicle battery
|
||||
$cv->setCurrentBattery($battery)
|
||||
->setHasMotoliteBattery(true)
|
||||
->setWarrantyExpiration($warr_date);
|
||||
}
|
||||
|
||||
protected function checkIfNewBattery(JobOrder $jo)
|
||||
{
|
||||
if ($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||
|
|
@ -43,11 +43,11 @@ class WarrantyHandler
|
|||
foreach ($batt_list as $battery)
|
||||
{
|
||||
// get the battery model and battery size
|
||||
$model_id = $battery->getModel()->getID();
|
||||
$size_id = $battery->getSize()->getID();
|
||||
$bty_model = $battery->getModel();
|
||||
$bty_size = $battery->getSize();
|
||||
|
||||
$bty_model = $this->em->getRepository(BatteryModel::class)->find($model_id);
|
||||
$bty_size = $this->em->getRepository(BatterySize::class)->find($size_id);
|
||||
//$bty_model = $this->em->getRepository(BatteryModel::class)->find($model_id);
|
||||
//$bty_size = $this->em->getRepository(BatterySize::class)->find($size_id);
|
||||
|
||||
if ($bty_model != null)
|
||||
{
|
||||
|
|
@ -149,12 +149,14 @@ class WarrantyHandler
|
|||
$q = $this->em->createQuery('update App\Entity\CustomerVehicle cv
|
||||
set cv.curr_battery = :batt_id,
|
||||
cv.warranty_code = :serial,
|
||||
cv.warranty_expiration = :expiry_date
|
||||
cv.warranty_expiration = :expiry_date,
|
||||
cv.flag_motolite_battery = :flag_motolite_battery
|
||||
where cv.plate_number = :plate_number')
|
||||
->setParameters([
|
||||
'batt_id' => $battery_id,
|
||||
'serial' => $serial,
|
||||
'expiry_date' => $date_expire,
|
||||
'flag_motolite_battery' => true,
|
||||
'plate_number' => $plate_number]);
|
||||
$q->execute();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue