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',
|
'last_name' => 'Last',
|
||||||
'mobile_number' => '12345678910',
|
'mobile_number' => '12345678910',
|
||||||
];
|
];
|
||||||
$api->post('/capi/warranties', $params);
|
//$api->post('/capi/warranties', $params);
|
||||||
|
|
||||||
// get all warranties
|
// get all warranties
|
||||||
$api->get('/capi/warranties');
|
$params = [
|
||||||
|
'order' => 'DESC',
|
||||||
|
'limit' => '5',
|
||||||
|
'start' => '1',
|
||||||
|
];
|
||||||
|
|
||||||
|
$api->get('/capi/warranties', $params);
|
||||||
|
|
||||||
|
|
||||||
// warranty find
|
// warranty find
|
||||||
$api->get('/capi/warranties/' . $serial);
|
//$api->get('/capi/warranties/' . $serial);
|
||||||
|
|
||||||
// warranty update
|
// warranty update
|
||||||
$id = 86811;
|
$id = 86811;
|
||||||
|
|
@ -77,7 +83,7 @@ class TestAPICommand extends Command
|
||||||
'last_name' => 'Last',
|
'last_name' => 'Last',
|
||||||
'mobile_number' => '123456789111',
|
'mobile_number' => '123456789111',
|
||||||
];
|
];
|
||||||
$api->post('/capi/warranties/'. $id, $params);
|
//$api->post('/capi/warranties/'. $id, $params);
|
||||||
|
|
||||||
// warranty set privacy policy
|
// warranty set privacy policy
|
||||||
$id = 86811;
|
$id = 86811;
|
||||||
|
|
@ -85,7 +91,7 @@ class TestAPICommand extends Command
|
||||||
$params = [
|
$params = [
|
||||||
'privacy_policy_id' => $policy_id,
|
'privacy_policy_id' => $policy_id,
|
||||||
];
|
];
|
||||||
$api->post('/capi/warranties/' . $id .'/privacypolicy', $params);
|
//$api->post('/capi/warranties/' . $id .'/privacypolicy', $params);
|
||||||
|
|
||||||
// warranty claim
|
// warranty claim
|
||||||
$id = 86811;
|
$id = 86811;
|
||||||
|
|
@ -93,27 +99,27 @@ class TestAPICommand extends Command
|
||||||
$params = [
|
$params = [
|
||||||
'serial' => $serial,
|
'serial' => $serial,
|
||||||
];
|
];
|
||||||
$api->post('/capi/warranties/' . $id . '/claim', $params);
|
//$api->post('/capi/warranties/' . $id . '/claim', $params);
|
||||||
|
|
||||||
// warranty cancel
|
// warranty cancel
|
||||||
$id = 86811;
|
$id = 86811;
|
||||||
$api->get('/capi/warranties/' . $id . '/cancel');
|
//$api->get('/capi/warranties/' . $id . '/cancel');
|
||||||
|
|
||||||
// plate warranty
|
// plate warranty
|
||||||
$api->get('/capi/plates/' . $plate_num . '/warranties');
|
//$api->get('/capi/plates/' . $plate_num . '/warranties');
|
||||||
|
|
||||||
// warranty delete
|
// warranty delete
|
||||||
$id = 86811;
|
$id = 86811;
|
||||||
$api->post('/capi/warranties/' . $id . '/delete');
|
//$api->post('/capi/warranties/' . $id . '/delete');
|
||||||
|
|
||||||
// battery
|
// battery
|
||||||
$api->get('/capi/battery_brands');
|
//$api->get('/capi/battery_brands');
|
||||||
$api->get('/capi/battery_sizes');
|
//$api->get('/capi/battery_sizes');
|
||||||
$api->get('/capi/batteries');
|
//$api->get('/capi/batteries');
|
||||||
|
|
||||||
// vehicle
|
// vehicle
|
||||||
$api->get('/capi/vehicle_manufacturers');
|
//$api->get('/capi/vehicle_manufacturers');
|
||||||
$api->get('/capi/vehicles');
|
//$api->get('/capi/vehicles');
|
||||||
|
|
||||||
// privacy policy
|
// privacy policy
|
||||||
$privacy_policy_id = 2;
|
$privacy_policy_id = 2;
|
||||||
|
|
|
||||||
|
|
@ -469,11 +469,13 @@ class WarrantyController extends Controller
|
||||||
$first_name = trim($fields[0]);
|
$first_name = trim($fields[0]);
|
||||||
$last_name = trim($fields[1]);
|
$last_name = trim($fields[1]);
|
||||||
$mobile_number = trim($fields[4]);
|
$mobile_number = trim($fields[4]);
|
||||||
$plate_number = trim($fields[9]);
|
$plate = trim($fields[9]);
|
||||||
$serial = trim($fields[10]);
|
$serial = trim($fields[10]);
|
||||||
$purchase_date = trim($fields[12]);
|
$purchase_date = trim($fields[12]);
|
||||||
$battery_id = trim($fields[16]);
|
$battery_id = trim($fields[16]);
|
||||||
|
|
||||||
|
$plate_number = $this->cleanPlateNumber($plate);
|
||||||
|
|
||||||
// check if purchase_date or plate_number or serial is empty or if
|
// check if purchase_date or plate_number or serial is empty or if
|
||||||
// purchase date is valid
|
// purchase date is valid
|
||||||
$date_purchase = DateTime::createFromFormat('d-M-y', $purchase_date);
|
$date_purchase = DateTime::createFromFormat('d-M-y', $purchase_date);
|
||||||
|
|
@ -521,7 +523,98 @@ class WarrantyController extends Controller
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// 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))
|
||||||
|
{
|
||||||
|
foreach($warr_results as $warr)
|
||||||
|
{
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
$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
|
||||||
|
{
|
||||||
|
// 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
|
// new warranty
|
||||||
$warranty = new Warranty();
|
$warranty = new Warranty();
|
||||||
|
|
||||||
|
|
@ -558,6 +651,8 @@ class WarrantyController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: compute expiry date
|
||||||
|
|
||||||
// set and save values
|
// set and save values
|
||||||
$warranty->setSerial($serial)
|
$warranty->setSerial($serial)
|
||||||
->setPlateNumber($plate_number)
|
->setPlateNumber($plate_number)
|
||||||
|
|
@ -570,6 +665,8 @@ class WarrantyController extends Controller
|
||||||
$em->flush();
|
$em->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$row_num++;
|
$row_num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -595,4 +692,10 @@ class WarrantyController extends Controller
|
||||||
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
->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