Fix warranty creation issue. #690
This commit is contained in:
parent
0ea02ae04d
commit
48aa0b024f
1 changed files with 26 additions and 36 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;
|
||||
|
|
@ -37,8 +38,8 @@ class WarrantyHandler
|
|||
$bsize_id = '';
|
||||
$bmodel_name = '';
|
||||
$bsize_name ='';
|
||||
$sap_batt_id = '';
|
||||
$w_serial = null;
|
||||
$sap_batt_id = null;
|
||||
$w_serial = '';
|
||||
|
||||
foreach ($batt_list as $battery)
|
||||
{
|
||||
|
|
@ -61,7 +62,6 @@ 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);
|
||||
|
|
@ -73,56 +73,46 @@ class WarrantyHandler
|
|||
{
|
||||
$sap_batt_id = $row['id'];
|
||||
}
|
||||
*/
|
||||
$sap_batt_id = $sap_code;
|
||||
}
|
||||
}
|
||||
|
||||
// compute expiry date
|
||||
$date_expire = null;
|
||||
$str_date_expire = 'NULL';
|
||||
if ((!empty($warranty_class)) &&
|
||||
(count($batt_list) != 0))
|
||||
{
|
||||
$period = $this->getWarrantyPeriod($batt_list, $warranty_class);
|
||||
$date_expire = $this->computeDateExpire($date_purchase, $period);
|
||||
$str_date_expire = $date_expire->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
// set and save values
|
||||
if (trim($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
|
||||
$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();
|
||||
$sql_values = '(' . $bmodel_id . ',' . $bsize_id. ',';
|
||||
if (empty($sap_batt_id))
|
||||
$sql_values = $sql_values . 'NULL,';
|
||||
else
|
||||
$sql_values = $sql_values . '\'' . $sap_batt_id . '\',';
|
||||
|
||||
if (empty($w_serial))
|
||||
$sql_values = $sql_values . 'NULL,\'';
|
||||
else
|
||||
$sql_values = $sql_values . '\'' . $w_serial . '\',';
|
||||
|
||||
$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_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";
|
||||
$conn = $this->em->getConnection();
|
||||
$w_stmt = $conn->prepare($w_sql);
|
||||
$w_stmt->execute();
|
||||
|
||||
// log warranty creation
|
||||
$action = 'create';
|
||||
|
|
|
|||
Loading…
Reference in a new issue