Redo warranty flow. #654
This commit is contained in:
parent
b831deacfb
commit
a50d591160
2 changed files with 82 additions and 37 deletions
|
|
@ -13,6 +13,7 @@ use App\Entity\JobOrder;
|
||||||
use App\Entity\JOEvent;
|
use App\Entity\JOEvent;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Entity\Warranty;
|
use App\Entity\Warranty;
|
||||||
|
use App\Entity\SAPBattery;
|
||||||
|
|
||||||
use App\Ramcar\JOStatus;
|
use App\Ramcar\JOStatus;
|
||||||
use App\Ramcar\JOEventType;
|
use App\Ramcar\JOEventType;
|
||||||
|
|
@ -49,6 +50,23 @@ class FulfillOpenJobOrderCommand extends Command
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
$sap_code = 'WSLMF9BR-RV100-L';
|
||||||
|
|
||||||
|
error_log($sap_code);
|
||||||
|
|
||||||
|
$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->fetchColumn();
|
||||||
|
|
||||||
|
error_log($query_results);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
*/
|
||||||
|
|
||||||
// get the input date
|
// get the input date
|
||||||
$str_date_end = $input->getArgument('end_date');
|
$str_date_end = $input->getArgument('end_date');
|
||||||
|
|
||||||
|
|
@ -59,25 +77,29 @@ class FulfillOpenJobOrderCommand extends Command
|
||||||
// starting time to count is date schedule
|
// starting time to count is date schedule
|
||||||
$date_end = new DateTime($str_date_end);
|
$date_end = new DateTime($str_date_end);
|
||||||
|
|
||||||
error_log($date_end->format('Y-m-d H:i:s'));
|
error_log('mogol ' . $date_end->format('Y-m-d H:i:s'));
|
||||||
|
|
||||||
|
/*
|
||||||
$query = $this->em->createQuery('SELECT jo FROM App\Entity\JobOrder jo
|
$query = $this->em->createQuery('SELECT jo FROM App\Entity\JobOrder jo
|
||||||
WHERE (jo.status = :pending_status
|
WHERE (jo.status = :pending_status
|
||||||
OR jo.status = :rider_assign_status
|
OR jo.status = :rider_assign_status
|
||||||
OR jo.status = :assigned_status
|
OR jo.status = :assigned_status
|
||||||
OR jo.status = :in_progress_status
|
OR jo.status = :in_progress_status
|
||||||
OR jo.status = :in_transit_status)
|
OR jo.status = :in_transit_status)
|
||||||
AND jo.date_schedule <= :date_end');
|
AND jo.date_schedule <= :date_end
|
||||||
|
AND jo.service_type = :stype');
|
||||||
|
|
||||||
$jo_results = $query->setParameters([
|
$query->setParameters([
|
||||||
'pending_status' => JOStatus::PENDING,
|
'pending_status' => JOStatus::PENDING,
|
||||||
'rider_assign_status' => JOStatus::RIDER_ASSIGN,
|
'rider_assign_status' => JOStatus::RIDER_ASSIGN,
|
||||||
'assigned_status' => JOStatus::ASSIGNED,
|
'assigned_status' => JOStatus::ASSIGNED,
|
||||||
'in_progress_status' => JOStatus::IN_PROGRESS,
|
'in_progress_status' => JOStatus::IN_PROGRESS,
|
||||||
'in_transit_status' => JOStatus::IN_TRANSIT,
|
'in_transit_status' => JOStatus::IN_TRANSIT,
|
||||||
'date_end' => $date_end,
|
'date_end' => $date_end,
|
||||||
])
|
'stype' => ServiceType::BATTERY_REPLACEMENT_NEW,
|
||||||
->getResult();
|
])->setMaxResults(1);
|
||||||
|
|
||||||
|
$jo_results = $query->getResult();
|
||||||
|
|
||||||
error_log('Found job orders ' . count($jo_results));
|
error_log('Found job orders ' . count($jo_results));
|
||||||
|
|
||||||
|
|
@ -111,6 +133,7 @@ class FulfillOpenJobOrderCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,12 +33,12 @@ class WarrantyHandler
|
||||||
$batt_list, DateTime $date_purchase, $warranty_class, $user_id,
|
$batt_list, DateTime $date_purchase, $warranty_class, $user_id,
|
||||||
$source, $customer, $cust_vehicle)
|
$source, $customer, $cust_vehicle)
|
||||||
{
|
{
|
||||||
// new warranty
|
$bmodel_id = '';
|
||||||
$warranty = new Warranty();
|
$bsize_id = '';
|
||||||
|
|
||||||
$bmodel_name = '';
|
$bmodel_name = '';
|
||||||
$bsize_name ='';
|
$bsize_name ='';
|
||||||
$sap_batt_id = '';
|
$sap_batt_id = '';
|
||||||
|
$w_serial = null;
|
||||||
|
|
||||||
foreach ($batt_list as $battery)
|
foreach ($batt_list as $battery)
|
||||||
{
|
{
|
||||||
|
|
@ -46,17 +46,14 @@ class WarrantyHandler
|
||||||
$bty_model = $battery->getModel();
|
$bty_model = $battery->getModel();
|
||||||
$bty_size = $battery->getSize();
|
$bty_size = $battery->getSize();
|
||||||
|
|
||||||
//$bty_model = $this->em->getRepository(BatteryModel::class)->find($model_id);
|
|
||||||
//$bty_size = $this->em->getRepository(BatterySize::class)->find($size_id);
|
|
||||||
|
|
||||||
if ($bty_model != null)
|
if ($bty_model != null)
|
||||||
{
|
{
|
||||||
$warranty->setBatteryModel($bty_model);
|
$bmodel_id = $bty_model->getID();
|
||||||
$bmodel_name = $bty_model->getName();
|
$bmodel_name = $bty_model->getName();
|
||||||
}
|
}
|
||||||
if ($bty_size != null)
|
if ($bty_size != null)
|
||||||
{
|
{
|
||||||
$warranty->setBatterySize($bty_size);
|
$bsize_id = $bty_size->getID();
|
||||||
$bsize_name = $bty_size->getName();
|
$bsize_name = $bty_size->getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,12 +61,20 @@ class WarrantyHandler
|
||||||
if (!empty($sap_code))
|
if (!empty($sap_code))
|
||||||
{
|
{
|
||||||
// find sap battery
|
// find sap battery
|
||||||
$sap_battery = $this->em->getRepository(SAPBattery::class)->find($sap_code);
|
/*
|
||||||
if ($sap_battery != null)
|
$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)
|
||||||
{
|
{
|
||||||
$warranty->setSAPBattery($sap_battery);
|
$sap_batt_id = $row['id'];
|
||||||
$sap_batt_id = $sap_battery->getID();
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
$sap_batt_id = $sap_code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,27 +85,44 @@ class WarrantyHandler
|
||||||
{
|
{
|
||||||
$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);
|
||||||
|
|
||||||
$warranty->setDateExpire($date_expire);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set and save values
|
// set and save values
|
||||||
if (trim($serial) == '')
|
if (trim($serial) != '')
|
||||||
$warranty->setSerial(null);
|
$w_serial = $serial;
|
||||||
else
|
|
||||||
$warranty->setSerial($serial);
|
|
||||||
$warranty->setPlateNumber($plate_number)
|
|
||||||
->setFirstName($first_name)
|
|
||||||
->setLastName($last_name)
|
|
||||||
->setMobileNumber($mobile_number)
|
|
||||||
->setDatePurchase($date_purchase)
|
|
||||||
->setWarrantyClass($warranty_class)
|
|
||||||
->setCreateSource($source)
|
|
||||||
->setCustomer($customer)
|
|
||||||
->setVehicle($cust_vehicle);
|
|
||||||
|
|
||||||
$this->em->persist($warranty);
|
// insert warranty
|
||||||
$this->em->flush();
|
$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();
|
||||||
|
|
||||||
// log warranty creation
|
// log warranty creation
|
||||||
$action = 'create';
|
$action = 'create';
|
||||||
|
|
@ -121,10 +143,10 @@ class WarrantyHandler
|
||||||
'sap_battery' => $sap_batt_id,
|
'sap_battery' => $sap_batt_id,
|
||||||
'plate_number' => $plate_number,
|
'plate_number' => $plate_number,
|
||||||
];
|
];
|
||||||
$this->logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
|
//$this->logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
|
||||||
|
|
||||||
// update customer vehicle with warranty info
|
// update customer vehicle with warranty info
|
||||||
$this->updateCustomerVehicle($serial, $batt_list, $plate_number, $date_expire);
|
//$this->updateCustomerVehicle($serial, $batt_list, $plate_number, $date_expire);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateCustomerVehicle($serial, $batteries, $plate_number, $date_expire)
|
public function updateCustomerVehicle($serial, $batteries, $plate_number, $date_expire)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue