Merge branch '690-warranty-creation-issue-in-warrantyhandler' into 'master'
Resolve "Warranty creation issue in WarrantyHandler" Closes #690 See merge request jankstudio/resq!806
This commit is contained in:
commit
ae9b7ce061
1 changed files with 27 additions and 72 deletions
|
|
@ -14,6 +14,7 @@ use App\Entity\CustomerVehicle;
|
|||
use App\Service\WarrantyAPILogger;
|
||||
|
||||
use App\Ramcar\WarrantyClass;
|
||||
use App\Ramcar\WarrantyStatus;
|
||||
|
||||
use DateTime;
|
||||
use DateInterval;
|
||||
|
|
@ -33,12 +34,10 @@ class WarrantyHandler
|
|||
$batt_list, DateTime $date_purchase, $warranty_class, $user_id,
|
||||
$source, $customer, $cust_vehicle)
|
||||
{
|
||||
$bmodel_id = '';
|
||||
$bsize_id = '';
|
||||
$bmodel_name = '';
|
||||
$bsize_name ='';
|
||||
$sap_batt_id = '';
|
||||
$w_serial = null;
|
||||
$bty_model = null;
|
||||
$bty_size = null;
|
||||
$sap_batt = null;
|
||||
$w_serial = '';
|
||||
|
||||
foreach ($batt_list as $battery)
|
||||
{
|
||||
|
|
@ -61,20 +60,7 @@ class WarrantyHandler
|
|||
if (!empty($sap_code))
|
||||
{
|
||||
// find sap battery
|
||||
/*
|
||||
$conn = $this->em->getConnection();
|
||||
$sql = 'SELECT sap.id FROM sap_battery sap WHERE sap.id = :id';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array('id' => $sap_code));
|
||||
|
||||
$query_results = $stmt->fetchAll();
|
||||
|
||||
foreach($query_results as $row)
|
||||
{
|
||||
$sap_batt_id = $row['id'];
|
||||
}
|
||||
*/
|
||||
$sap_batt_id = $sap_code;
|
||||
$sap_batt = $this->em->getRepository(SAPBattery::class)->find($sap_code);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -91,62 +77,31 @@ class WarrantyHandler
|
|||
if (trim($serial) != '')
|
||||
$w_serial = $serial;
|
||||
|
||||
// insert warranty
|
||||
$q = $this->em->createQuery('INSERT App\Entity\Warranty w
|
||||
SET w.serial = :serial,
|
||||
w.plate_number = :plate_number,
|
||||
w.first_name = :first_name,
|
||||
w.last_name = :last_name,
|
||||
w.mobile_number = :mobile_number,
|
||||
w.date_purchase = :date_purchase,
|
||||
w.warranty_class = :warranty_class,
|
||||
w.create_source = :create_source,
|
||||
w.customer_id = :customer_id,
|
||||
w.vehicle_id = :vehicle_id,
|
||||
w.bty_model_id = :bmodel_id,
|
||||
w.bty_size_id = :bsize_id,
|
||||
w.sap_bty_id = :sap_batt_id,
|
||||
w.date_expire = :date_expire')
|
||||
->setParameters([
|
||||
'serial' => $serial,
|
||||
'plate_number' => $plate_number,
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'mobile_number' => $mobile_number,
|
||||
'date_purchase' => $date_purchase,
|
||||
'warranty_class' => $warranty_class,
|
||||
'create_source' => $source,
|
||||
'customer_id' => $customer->getID(),
|
||||
'vehicle_id' => $cust_vehicle->getID(),
|
||||
'bmodel_id' => $bmodel_id,
|
||||
'bsize_id' => $bsize_id,
|
||||
'sap_batt_id' => $sap_batt_id,
|
||||
'date_expire' => $date_expire]);
|
||||
$q->execute();
|
||||
$warranty = new Warranty();
|
||||
$warranty->setWarrantyClass($warranty_class)
|
||||
->setPlateNumber($plate_number)
|
||||
->setFirstName($first_name)
|
||||
->setLastName($last_name)
|
||||
->setMobileNumber($mobile_number)
|
||||
->setBatteryModel($bty_model)
|
||||
->setBatterySize($bty_size)
|
||||
->setSAPBattery($sap_batt)
|
||||
->setDatePurchase($date_purchase)
|
||||
->setCustomer($customer)
|
||||
->setVehicle($cust_vehicle)
|
||||
->setCreateSource($source);
|
||||
|
||||
// log warranty creation
|
||||
$action = 'create';
|
||||
$exp_date = '';
|
||||
// set serial
|
||||
if (!empty($w_serial))
|
||||
$warranty->setSerial($w_serial);
|
||||
|
||||
// set date expire
|
||||
if ($date_expire != null)
|
||||
$exp_date = $date_expire->format('d-M-y');
|
||||
$warranty->setDateExpire($date_expire);
|
||||
|
||||
$log_data = [
|
||||
'serial' => $serial,
|
||||
'warranty_class' => $warranty_class,
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'mobile_number' => $mobile_number,
|
||||
'date_purchase' => $date_purchase->format('d-M-y'),
|
||||
'date_expire' => $exp_date,
|
||||
'battery_model' => $bmodel_name,
|
||||
'battery_size' => $bsize_name,
|
||||
'sap_battery' => $sap_batt_id,
|
||||
'plate_number' => $plate_number,
|
||||
];
|
||||
//$this->logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
|
||||
$this->em->persist($warranty);
|
||||
$this->em->flush();
|
||||
|
||||
// update customer vehicle with warranty info
|
||||
//$this->updateCustomerVehicle($serial, $batt_list, $plate_number, $date_expire);
|
||||
}
|
||||
|
||||
public function updateCustomerVehicle($serial, $batteries, $plate_number, $date_expire)
|
||||
|
|
|
|||
Loading…
Reference in a new issue