Fix warranty creation issue. #690

This commit is contained in:
Korina Cordero 2022-06-28 12:47:42 +00:00
parent 0ea02ae04d
commit 48aa0b024f

View file

@ -14,6 +14,7 @@ use App\Entity\CustomerVehicle;
use App\Service\WarrantyAPILogger; use App\Service\WarrantyAPILogger;
use App\Ramcar\WarrantyClass; use App\Ramcar\WarrantyClass;
use App\Ramcar\WarrantyStatus;
use DateTime; use DateTime;
use DateInterval; use DateInterval;
@ -37,8 +38,8 @@ class WarrantyHandler
$bsize_id = ''; $bsize_id = '';
$bmodel_name = ''; $bmodel_name = '';
$bsize_name =''; $bsize_name ='';
$sap_batt_id = ''; $sap_batt_id = null;
$w_serial = null; $w_serial = '';
foreach ($batt_list as $battery) foreach ($batt_list as $battery)
{ {
@ -61,7 +62,6 @@ class WarrantyHandler
if (!empty($sap_code)) if (!empty($sap_code))
{ {
// find sap battery // find sap battery
/*
$conn = $this->em->getConnection(); $conn = $this->em->getConnection();
$sql = 'SELECT sap.id FROM sap_battery sap WHERE sap.id = :id'; $sql = 'SELECT sap.id FROM sap_battery sap WHERE sap.id = :id';
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
@ -73,56 +73,46 @@ class WarrantyHandler
{ {
$sap_batt_id = $row['id']; $sap_batt_id = $row['id'];
} }
*/
$sap_batt_id = $sap_code;
} }
} }
// compute expiry date // compute expiry date
$date_expire = null; $date_expire = null;
$str_date_expire = 'NULL';
if ((!empty($warranty_class)) && if ((!empty($warranty_class)) &&
(count($batt_list) != 0)) (count($batt_list) != 0))
{ {
$period = $this->getWarrantyPeriod($batt_list, $warranty_class); $period = $this->getWarrantyPeriod($batt_list, $warranty_class);
$date_expire = $this->computeDateExpire($date_purchase, $period); $date_expire = $this->computeDateExpire($date_purchase, $period);
$str_date_expire = $date_expire->format('Y-m-d H:i:s');
} }
// set and save values // set and save values
if (trim($serial) != '') if (trim($serial) != '')
$w_serial = $serial; $w_serial = $serial;
$str_date_purchase = $date_purchase->format('Y-m-d H:i:s');
$date_create = new DateTime();
$str_date_create = $date_create->format('Y-m-d H:i:s');
// insert warranty // insert warranty
$q = $this->em->createQuery('INSERT App\Entity\Warranty w $sql_values = '(' . $bmodel_id . ',' . $bsize_id. ',';
SET w.serial = :serial, if (empty($sap_batt_id))
w.plate_number = :plate_number, $sql_values = $sql_values . 'NULL,';
w.first_name = :first_name, else
w.last_name = :last_name, $sql_values = $sql_values . '\'' . $sap_batt_id . '\',';
w.mobile_number = :mobile_number,
w.date_purchase = :date_purchase, if (empty($w_serial))
w.warranty_class = :warranty_class, $sql_values = $sql_values . 'NULL,\'';
w.create_source = :create_source, else
w.customer_id = :customer_id, $sql_values = $sql_values . '\'' . $w_serial . '\',';
w.vehicle_id = :vehicle_id,
w.bty_model_id = :bmodel_id, $sql_values = $sql_values . $warranty_class . '\',\'' . $plate_number . '\',\'' . WarrantyStatus::ACTIVE . '\',\'' . $str_date_create . '\',\'' . $str_date_purchase . '\',\'' . $str_date_expire . '\',\'' . $first_name . '\',\'' . $last_name . '\',\'' . $mobile_number . '\','. 1 . ',' . $cust_vehicle->getID() . ',' . $customer->getID() . ',\'' . $source . '\')';
w.bty_size_id = :bsize_id,
w.sap_bty_id = :sap_batt_id, $w_sql = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,sap_bty_id,serial,warranty_class,plate_number,status,date_create,date_purchase,date_expire,first_name,last_name,mobile_number,flag_activated,vehicle_id,customer_id, create_source) VALUES ' . $sql_values . ';' . "\n";
w.date_expire = :date_expire') $conn = $this->em->getConnection();
->setParameters([ $w_stmt = $conn->prepare($w_sql);
'serial' => $serial, $w_stmt->execute();
'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();
// log warranty creation // log warranty creation
$action = 'create'; $action = 'create';