Update customer vehicle warranty information when warranty is uploaded. #290
This commit is contained in:
parent
85483ffab8
commit
10d9e6e5ae
3 changed files with 41 additions and 57 deletions
|
|
@ -61,7 +61,7 @@ class UpdateCustomerVehicleWarrantyCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
// find battery
|
// find battery
|
||||||
$batteries = $this->wh->getBatteriesForWarrantyPeriod($warr);
|
$batteries = $this->wh->getBatteriesForWarranty($warr);
|
||||||
|
|
||||||
// find customer vehicle using plate number
|
// find customer vehicle using plate number
|
||||||
error_log('Finding customer vehicle with plate number ' . $plate_number);
|
error_log('Finding customer vehicle with plate number ' . $plate_number);
|
||||||
|
|
@ -69,23 +69,6 @@ class UpdateCustomerVehicleWarrantyCommand extends Command
|
||||||
|
|
||||||
if (!empty($cust_vehicles))
|
if (!empty($cust_vehicles))
|
||||||
{
|
{
|
||||||
//foreach ($cust_vehicles as $cv)
|
|
||||||
//{
|
|
||||||
// if (!empty($batteries))
|
|
||||||
// {
|
|
||||||
// set current battery to the first battery in list.
|
|
||||||
// there are cases where multiple batteries linked to an SAP code.
|
|
||||||
//foreach ($batteries as $batt)
|
|
||||||
//{
|
|
||||||
// $cv->setCurrentBattery($batt);
|
|
||||||
//}
|
|
||||||
// }
|
|
||||||
//$cv->setWarrantyCode($serial)
|
|
||||||
// ->setWarrantyExpiration($expiry_date);
|
|
||||||
|
|
||||||
//$this->em->persist($cv);
|
|
||||||
//$this->em->flush();
|
|
||||||
|
|
||||||
if (!empty($batteries))
|
if (!empty($batteries))
|
||||||
{
|
{
|
||||||
// set current battery to the first battery in list.
|
// set current battery to the first battery in list.
|
||||||
|
|
|
||||||
|
|
@ -567,7 +567,7 @@ class WarrantyController extends Controller
|
||||||
{
|
{
|
||||||
// call service to check if warranty details is incomplete and then update warranty
|
// call service to check if warranty details is incomplete and then update warranty
|
||||||
// using details from csv file
|
// using details from csv file
|
||||||
//error_log('Updating warranty for ' . $warr->getID());
|
error_log('Updating warranty for ' . $warr->getID());
|
||||||
$wh->updateWarranty($warr, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase);
|
$wh->updateWarranty($warr, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -582,38 +582,9 @@ class WarrantyController extends Controller
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//error_log('Creating warranty for serial ' . $serial . ' and plate number ' . $plate_number);
|
error_log('Creating warranty for serial ' . $serial . ' and plate number ' . $plate_number);
|
||||||
|
|
||||||
$warranty = $wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
|
$wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
|
||||||
|
|
||||||
// update customer vehicle with warranty info
|
|
||||||
// get expiry date
|
|
||||||
// TODO: test this
|
|
||||||
$expiry_date = $warranty->getDateExpire();
|
|
||||||
|
|
||||||
// find customer vehicle
|
|
||||||
$cust_vehicles = $em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $plate_number]);
|
|
||||||
if (!empty($cust_vehicles))
|
|
||||||
{
|
|
||||||
if (!empty($batt_list))
|
|
||||||
{
|
|
||||||
// set current battery to the first battery in list.
|
|
||||||
// there are cases where multiple batteries linked to an SAP code.
|
|
||||||
$battery = $batt_list[0];
|
|
||||||
$battery_id = $battery->getID();
|
|
||||||
}
|
|
||||||
$q = $em->createQuery('update App\Entity\CustomerVehicle cv
|
|
||||||
set cv.curr_battery = :batt_id,
|
|
||||||
cv.warranty_code = :serial,
|
|
||||||
cv.warranty_expiration = :expiry_date
|
|
||||||
where cv.plate_number = :plate_number')
|
|
||||||
->setParameters([
|
|
||||||
'batt_id' => $battery_id,
|
|
||||||
'serial' => $serial,
|
|
||||||
'expiry_date' => $expiry_date,
|
|
||||||
'plate_number' => $plate_number]);
|
|
||||||
$q->execute();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use App\Entity\Battery;
|
||||||
use App\Entity\BatterySize;
|
use App\Entity\BatterySize;
|
||||||
use App\Entity\SAPBattery;
|
use App\Entity\SAPBattery;
|
||||||
use App\Entity\BatteryModel;
|
use App\Entity\BatteryModel;
|
||||||
|
use App\Entity\CustomerVehicle;
|
||||||
|
|
||||||
use App\Ramcar\WarrantyClass;
|
use App\Ramcar\WarrantyClass;
|
||||||
|
|
||||||
|
|
@ -61,6 +62,7 @@ class WarrantyHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute expiry date
|
// compute expiry date
|
||||||
|
$date_expire = null;
|
||||||
if ((!empty($warranty_class)) &&
|
if ((!empty($warranty_class)) &&
|
||||||
(count($batt_list) != 0))
|
(count($batt_list) != 0))
|
||||||
{
|
{
|
||||||
|
|
@ -80,12 +82,41 @@ class WarrantyHandler
|
||||||
|
|
||||||
$this->em->persist($warranty);
|
$this->em->persist($warranty);
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
|
||||||
|
// update customer vehicle with warranty info
|
||||||
|
$this->updateCustomerVehicle($serial, $batt_list, $plate_number, $date_expire);
|
||||||
|
|
||||||
$this->em->clear();
|
$this->em->clear();
|
||||||
|
}
|
||||||
|
|
||||||
if ($warranty == null)
|
public function updateCustomerVehicle($serial, $batteries, $plate_number, $date_expire)
|
||||||
error_log('warranty is null');
|
{
|
||||||
|
// find customer vehicle using plate number
|
||||||
return $warranty;
|
// error_log('Finding customer vehicle with plate number ' . $plate_number);
|
||||||
|
$cust_vehicles = $this->em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $plate_number]);
|
||||||
|
$battery_id = null;
|
||||||
|
if (!empty($cust_vehicles))
|
||||||
|
{
|
||||||
|
if (!empty($batteries))
|
||||||
|
{
|
||||||
|
// set current battery to the first battery in list.
|
||||||
|
// there are cases where multiple batteries linked to an SAP code.
|
||||||
|
$battery = $batteries[0];
|
||||||
|
$battery_id = $battery->getID();
|
||||||
|
}
|
||||||
|
//error_log('Serial/Warranty Code = ' . $serial);
|
||||||
|
$q = $this->em->createQuery('update App\Entity\CustomerVehicle cv
|
||||||
|
set cv.curr_battery = :batt_id,
|
||||||
|
cv.warranty_code = :serial,
|
||||||
|
cv.warranty_expiration = :expiry_date
|
||||||
|
where cv.plate_number = :plate_number')
|
||||||
|
->setParameters([
|
||||||
|
'batt_id' => $battery_id,
|
||||||
|
'serial' => $serial,
|
||||||
|
'expiry_date' => $date_expire,
|
||||||
|
'plate_number' => $plate_number]);
|
||||||
|
$q->execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateWarranty(Warranty $warr, $first_name, $last_name, $mobile_number, $batt_list, DateTime $date_purchase)
|
public function updateWarranty(Warranty $warr, $first_name, $last_name, $mobile_number, $batt_list, DateTime $date_purchase)
|
||||||
|
|
@ -166,7 +197,7 @@ class WarrantyHandler
|
||||||
$batteries = [];
|
$batteries = [];
|
||||||
if (count($batt_list) == 0)
|
if (count($batt_list) == 0)
|
||||||
{
|
{
|
||||||
$batteries = $this->getBatteriesForWarrantyPeriod($warr);
|
$batteries = $this->getBatteriesForWarranty($warr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -239,8 +270,7 @@ class WarrantyHandler
|
||||||
return $warranty_period;
|
return $warranty_period;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Need to rename this function
|
public function getBatteriesForWarranty($warr)
|
||||||
public function getBatteriesForWarrantyPeriod($warr)
|
|
||||||
{
|
{
|
||||||
// find battery via sku/sap battery first
|
// find battery via sku/sap battery first
|
||||||
// if sku is null, use battery model and battery size to find battery
|
// if sku is null, use battery model and battery size to find battery
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue