Fix memory issue for warranty generation #213
This commit is contained in:
parent
8adea20f59
commit
754af5e1e4
1 changed files with 32 additions and 8 deletions
|
|
@ -66,15 +66,22 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
{
|
||||
$this->warranties_hash = [];
|
||||
|
||||
/*
|
||||
$warranties = $this->em->getRepository(Warranty::class)->findAll();
|
||||
foreach($warranties as $warranty)
|
||||
{
|
||||
$plate_number = $warranty->getPlateNumber();
|
||||
$date_expire = $warranty->getDateExpire();
|
||||
|
||||
// skip null date expire
|
||||
if ($date_expire == null)
|
||||
continue;
|
||||
|
||||
$expiry_date = $date_expire->format('Y-m-d');
|
||||
|
||||
$this->warranties_hash[$plate_number][$expiry_date] = $warranty->getID();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
protected function findSAPBattery($batt_id)
|
||||
|
|
@ -102,19 +109,32 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
{
|
||||
$em = $this->em;
|
||||
|
||||
// to save on joins, go with invoice item first
|
||||
$query = $em->createQuery('select ii,i,jo,cv from App\Entity\InvoiceItem ii inner join ii.invoice i inner join i.job_order jo inner join jo.cus_vehicle cv join jo.customer c where ii.battery is not null and jo.service_type = :service_type');
|
||||
$query->setParameter('service_type', ServiceType::BATTERY_REPLACEMENT_NEW);
|
||||
/*
|
||||
$query = $em->createQuery('SELECT jo FROM App\Entity\JobOrder jo
|
||||
WHERE jo.service_type = :service_type');
|
||||
$query->setParameter('service_type', ServiceType::BATTERY_REPLACEMENT_NEW);
|
||||
*/
|
||||
|
||||
$result = $query->iterate();
|
||||
|
||||
foreach ($result as $row)
|
||||
{
|
||||
$jo = $row[0];
|
||||
$invoice_item = $row[0];
|
||||
$invoice = $invoice_item->getInvoice();
|
||||
$jo = $invoice->getJobOrder();
|
||||
$cv = $jo->getCustomerVehicle();
|
||||
$customer = $jo->getCustomer();
|
||||
/*
|
||||
$invoice_items = [];
|
||||
// For now, one invoice == one battery
|
||||
// for now, one invoice == one battery
|
||||
|
||||
|
||||
$invoice_items = $jo->getInvoice()->getItems();
|
||||
$invoice_item = $invoice_items[0];
|
||||
*/
|
||||
if ($invoice_item != null)
|
||||
{
|
||||
if($invoice_item->getBattery() != null)
|
||||
|
|
@ -129,6 +149,7 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
}
|
||||
|
||||
// get warranty period for battery
|
||||
// TODO: base it on the battery type
|
||||
$warranty_period = 0;
|
||||
if ($invoice_item->getBattery()->getWarrantyPrivate() != null)
|
||||
{
|
||||
|
|
@ -143,15 +164,17 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
$warranty_period = $invoice_item->getBattery()->getWarrantyTnv();
|
||||
}
|
||||
|
||||
if ($jo->getInvoice()->getDateCreate() != null)
|
||||
if ($invoice->getDateCreate() != null)
|
||||
{
|
||||
// check if plate number is "clean". If not, do not insert into warranty
|
||||
if (!(Warranty::cleanPlateNumber($jo->getCustomerVehicle()->getPlateNumber())))
|
||||
if (!(Warranty::cleanPlateNumber($cv->getPlateNumber())))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// check if warranty already exists
|
||||
$cleaned_plate_number = Warranty::cleanPlateNumber($jo->getCustomerVehicle()->getPlateNumber());
|
||||
$cleaned_plate_number = Warranty::cleanPlateNumber($cv->getPlateNumber());
|
||||
|
||||
$expiry_date = $this->computeDateExpire($jo->getInvoice()->getDateCreate(), $warranty_period);
|
||||
$found_warranty = $this->findWarranty($cleaned_plate_number, $expiry_date);
|
||||
if (!$found_warranty)
|
||||
|
|
@ -167,9 +190,9 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
|
||||
$date_expire = $expiry_date->format('Y-m-d');
|
||||
|
||||
$first_name = addslashes(trim($jo->getCustomer()->getFirstName()));
|
||||
$last_name = addslashes(trim($jo->getCustomer()->getLastName()));
|
||||
$mobile_number = addslashes(trim($jo->getCustomer()->getPhoneMobile()));
|
||||
$first_name = addslashes(trim($customer->getFirstName()));
|
||||
$last_name = addslashes(trim($customer->getLastName()));
|
||||
$mobile_number = addslashes(trim($customer->getPhoneMobile()));
|
||||
|
||||
$values = '(' . $bty_model_id . ',' . $bty_size_id . ',NULL,\'' . $warranty_class . '\',\''
|
||||
. $cleaned_plate_number . '\',\'' . WarrantyStatus::ACTIVE . '\',\'' . $date_create . '\',\'' . $date_purchase
|
||||
|
|
@ -184,6 +207,7 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$em->detach($row[0]);
|
||||
$em->clear();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue