Add updating of customer vehicle information when warranty is added. #290
This commit is contained in:
parent
5544d99a98
commit
85483ffab8
2 changed files with 38 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ use App\Entity\Battery;
|
|||
use App\Entity\BatteryModel;
|
||||
use App\Entity\BatterySize;
|
||||
use App\Entity\Invoice;
|
||||
use App\Entity\CustomerVehicle;
|
||||
|
||||
use App\Ramcar\WarrantyClass;
|
||||
use App\Ramcar\WarrantyStatus;
|
||||
|
|
@ -583,10 +584,40 @@ class WarrantyController extends Controller
|
|||
|
||||
//error_log('Creating warranty for serial ' . $serial . ' and plate number ' . $plate_number);
|
||||
|
||||
$wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
|
||||
$warranty = $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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$em->clear();
|
||||
$row_num++;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,6 +81,11 @@ class WarrantyHandler
|
|||
$this->em->persist($warranty);
|
||||
$this->em->flush();
|
||||
$this->em->clear();
|
||||
|
||||
if ($warranty == null)
|
||||
error_log('warranty is null');
|
||||
|
||||
return $warranty;
|
||||
}
|
||||
|
||||
public function updateWarranty(Warranty $warr, $first_name, $last_name, $mobile_number, $batt_list, DateTime $date_purchase)
|
||||
|
|
|
|||
Loading…
Reference in a new issue