Merge branch '288-additional-validations-for-warranty-upload' of gitlab.com:jankstudio/resq into 286-make-standard-warranty-adding
This commit is contained in:
commit
0a6c6eebfb
2 changed files with 160 additions and 51 deletions
|
|
@ -55,14 +55,20 @@ class TestAPICommand extends Command
|
|||
'last_name' => 'Last',
|
||||
'mobile_number' => '12345678910',
|
||||
];
|
||||
$api->post('/capi/warranties', $params);
|
||||
//$api->post('/capi/warranties', $params);
|
||||
|
||||
// get all warranties
|
||||
$api->get('/capi/warranties');
|
||||
$params = [
|
||||
'order' => 'DESC',
|
||||
'limit' => '5',
|
||||
'start' => '1',
|
||||
];
|
||||
|
||||
$api->get('/capi/warranties', $params);
|
||||
|
||||
|
||||
// warranty find
|
||||
$api->get('/capi/warranties/' . $serial);
|
||||
//$api->get('/capi/warranties/' . $serial);
|
||||
|
||||
// warranty update
|
||||
$id = 86811;
|
||||
|
|
@ -77,7 +83,7 @@ class TestAPICommand extends Command
|
|||
'last_name' => 'Last',
|
||||
'mobile_number' => '123456789111',
|
||||
];
|
||||
$api->post('/capi/warranties/'. $id, $params);
|
||||
//$api->post('/capi/warranties/'. $id, $params);
|
||||
|
||||
// warranty set privacy policy
|
||||
$id = 86811;
|
||||
|
|
@ -85,7 +91,7 @@ class TestAPICommand extends Command
|
|||
$params = [
|
||||
'privacy_policy_id' => $policy_id,
|
||||
];
|
||||
$api->post('/capi/warranties/' . $id .'/privacypolicy', $params);
|
||||
//$api->post('/capi/warranties/' . $id .'/privacypolicy', $params);
|
||||
|
||||
// warranty claim
|
||||
$id = 86811;
|
||||
|
|
@ -93,27 +99,27 @@ class TestAPICommand extends Command
|
|||
$params = [
|
||||
'serial' => $serial,
|
||||
];
|
||||
$api->post('/capi/warranties/' . $id . '/claim', $params);
|
||||
//$api->post('/capi/warranties/' . $id . '/claim', $params);
|
||||
|
||||
// warranty cancel
|
||||
$id = 86811;
|
||||
$api->get('/capi/warranties/' . $id . '/cancel');
|
||||
//$api->get('/capi/warranties/' . $id . '/cancel');
|
||||
|
||||
// plate warranty
|
||||
$api->get('/capi/plates/' . $plate_num . '/warranties');
|
||||
//$api->get('/capi/plates/' . $plate_num . '/warranties');
|
||||
|
||||
// warranty delete
|
||||
$id = 86811;
|
||||
$api->post('/capi/warranties/' . $id . '/delete');
|
||||
//$api->post('/capi/warranties/' . $id . '/delete');
|
||||
|
||||
// battery
|
||||
$api->get('/capi/battery_brands');
|
||||
$api->get('/capi/battery_sizes');
|
||||
$api->get('/capi/batteries');
|
||||
//$api->get('/capi/battery_brands');
|
||||
//$api->get('/capi/battery_sizes');
|
||||
//$api->get('/capi/batteries');
|
||||
|
||||
// vehicle
|
||||
$api->get('/capi/vehicle_manufacturers');
|
||||
$api->get('/capi/vehicles');
|
||||
//$api->get('/capi/vehicle_manufacturers');
|
||||
//$api->get('/capi/vehicles');
|
||||
|
||||
// privacy policy
|
||||
$privacy_policy_id = 2;
|
||||
|
|
|
|||
|
|
@ -469,11 +469,13 @@ class WarrantyController extends Controller
|
|||
$first_name = trim($fields[0]);
|
||||
$last_name = trim($fields[1]);
|
||||
$mobile_number = trim($fields[4]);
|
||||
$plate_number = trim($fields[9]);
|
||||
$plate = trim($fields[9]);
|
||||
$serial = trim($fields[10]);
|
||||
$purchase_date = trim($fields[12]);
|
||||
$battery_id = trim($fields[16]);
|
||||
|
||||
$plate_number = $this->cleanPlateNumber($plate);
|
||||
|
||||
// check if purchase_date or plate_number or serial is empty or if
|
||||
// purchase date is valid
|
||||
$date_purchase = DateTime::createFromFormat('d-M-y', $purchase_date);
|
||||
|
|
@ -521,53 +523,148 @@ class WarrantyController extends Controller
|
|||
}
|
||||
else
|
||||
{
|
||||
|
||||
// new warranty
|
||||
$warranty = new Warranty();
|
||||
|
||||
// get the battery purchased
|
||||
// check battery first. If not found, check sap_battery
|
||||
$battery = $em->getRepository(Battery::class)->find($battery_id);
|
||||
if ($battery != null)
|
||||
// additional validation
|
||||
// check if serial number and plate number already exists
|
||||
$warr_results = $em->getRepository(Warranty::class)->findBy(['serial' => $serial, 'plate_number' => $plate_number]);
|
||||
if (!empty($warr_results))
|
||||
{
|
||||
// get the battery model and battery size
|
||||
$model_id = $battery->getModel()->getID();
|
||||
$size_id = $battery->getSize()->getID();
|
||||
|
||||
$bty_model = $em->getRepository(BatteryModel::class)->find($model_id);
|
||||
$bty_size = $em->getRepository(BatterySize::class)->find($size_id);
|
||||
|
||||
if ($bty_model != null)
|
||||
foreach($warr_results as $warr)
|
||||
{
|
||||
$warranty->setBatteryModel($bty_model);
|
||||
}
|
||||
// check if details are complete
|
||||
//error_log('Updating warranty with serial number ' . $serial . ' and plate number ' . $plate_number);
|
||||
if (empty($warr->getFirstName()))
|
||||
{
|
||||
if (!empty($first_name))
|
||||
{
|
||||
$warr->setFirstName($first_name);
|
||||
}
|
||||
}
|
||||
if (empty($warr->getLastName()))
|
||||
{
|
||||
if (!empty($last_name))
|
||||
{
|
||||
$warr->setLastName($last_name);
|
||||
}
|
||||
}
|
||||
if (empty($warr->getMobileNumber()))
|
||||
{
|
||||
if (!empty($mobile_number))
|
||||
{
|
||||
$warr->setMobileNumber($mobile_number);
|
||||
}
|
||||
}
|
||||
if ((empty($warr->getBatteryModel())) ||
|
||||
(empty($warr->getBatterySize())))
|
||||
{
|
||||
if (!empty($battery_id))
|
||||
{
|
||||
// find battery
|
||||
$battery = $em->getRepository(Battery::class)->find($battery_id);
|
||||
if (!empty($battery))
|
||||
{
|
||||
// get the battery model and battery size
|
||||
$model_id = $battery->getModel()->getID();
|
||||
$size_id = $battery->getSize()->getID();
|
||||
|
||||
if ($bty_size != null)
|
||||
{
|
||||
$warranty->setBatterySize($bty_size);
|
||||
$bty_model = $em->getRepository(BatteryModel::class)->find($model_id);
|
||||
$bty_size = $em->getRepository(BatterySize::class)->find($size_id);
|
||||
|
||||
if ($bty_model != null)
|
||||
{
|
||||
$warr->setBatteryModel($bty_model);
|
||||
}
|
||||
if ($bty_size != null)
|
||||
{
|
||||
$warr->setBatterySize($bty_size);
|
||||
}
|
||||
$sap_code = $battery->getSAPCode();
|
||||
if (!empty($sap_code))
|
||||
{
|
||||
// find sap battery
|
||||
$sap_batt = $em->getRepository(SAPBattery::class)->find($sap_code);
|
||||
if (!empty($sap_batt))
|
||||
{
|
||||
$warr->setSAPBattery($sap_batt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($warr->getDatePurchase()))
|
||||
{
|
||||
if (!empty($date_purchase))
|
||||
{
|
||||
$warr->setDatePurchase($date_purchase);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: compute expiry date
|
||||
$em->persist($warr);
|
||||
$em->flush();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// find battery in sap_battery
|
||||
$battery = $em->getRepository(SAPBattery::class)->find($battery_id);
|
||||
{
|
||||
// TODO: what if serial exists but plate number is different?
|
||||
// check if just the serial exists
|
||||
// if warranty exists, ignore for now
|
||||
$w_results = $em->getRepository(Warranty::class)->findBy(['serial' => $serial]);
|
||||
if (!empty($w_results))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//error_log('Adding warranty with serial number ' . $serial . ' and plate number ' . $plate_number);
|
||||
// new warranty
|
||||
$warranty = new Warranty();
|
||||
|
||||
// get the battery purchased
|
||||
// check battery first. If not found, check sap_battery
|
||||
$battery = $em->getRepository(Battery::class)->find($battery_id);
|
||||
if ($battery != null)
|
||||
{
|
||||
// battery is SAPBattery
|
||||
$warranty->setSAPBattery($battery);
|
||||
// get the battery model and battery size
|
||||
$model_id = $battery->getModel()->getID();
|
||||
$size_id = $battery->getSize()->getID();
|
||||
|
||||
$bty_model = $em->getRepository(BatteryModel::class)->find($model_id);
|
||||
$bty_size = $em->getRepository(BatterySize::class)->find($size_id);
|
||||
|
||||
if ($bty_model != null)
|
||||
{
|
||||
$warranty->setBatteryModel($bty_model);
|
||||
}
|
||||
|
||||
if ($bty_size != null)
|
||||
{
|
||||
$warranty->setBatterySize($bty_size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// find battery in sap_battery
|
||||
$battery = $em->getRepository(SAPBattery::class)->find($battery_id);
|
||||
if ($battery != null)
|
||||
{
|
||||
// battery is SAPBattery
|
||||
$warranty->setSAPBattery($battery);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: compute expiry date
|
||||
|
||||
// set and save values
|
||||
$warranty->setSerial($serial)
|
||||
->setPlateNumber($plate_number)
|
||||
->setFirstName($first_name)
|
||||
->setLastName($last_name)
|
||||
->setMobileNumber($mobile_number)
|
||||
->setDatePurchase($date_purchase);
|
||||
|
||||
$em->persist($warranty);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
// set and save values
|
||||
$warranty->setSerial($serial)
|
||||
->setPlateNumber($plate_number)
|
||||
->setFirstName($first_name)
|
||||
->setLastName($last_name)
|
||||
->setMobileNumber($mobile_number)
|
||||
->setDatePurchase($date_purchase);
|
||||
|
||||
$em->persist($warranty);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
$row_num++;
|
||||
|
|
@ -595,4 +692,10 @@ class WarrantyController extends Controller
|
|||
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||
}
|
||||
}
|
||||
|
||||
protected function cleanPlateNumber($plate)
|
||||
{
|
||||
// remove spaces and make upper case
|
||||
return strtoupper(str_replace(' ', '', $plate));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue