Merge branch '309-replace-63-in-templates-with-proper-country-code' of gitlab.com:jankstudio/resq into 312-cmb-highlight-selected-hub-and-rider-in-onestep-edit

This commit is contained in:
Korina Cordero 2020-01-25 01:50:06 +00:00
commit fd0738ad57
5 changed files with 108 additions and 85 deletions

View file

@ -28,6 +28,8 @@ RT_SHORTCODE=1234
MQTT_IP_ADDRESS=localhost MQTT_IP_ADDRESS=localhost
MQTT_PORT=8883 MQTT_PORT=8883
MQTT_CERT=/location/of/cert/file.crt MQTT_CERT=/location/of/cert/file.crt
MQTT_WS_HOST=insertiphere
MQTT_WS_PORT=8083
# redis client # redis client
REDIS_CLIENT_SCHEME=tcp REDIS_CLIENT_SCHEME=tcp

View file

@ -17,16 +17,19 @@ use App\Ramcar\APIResult;
use App\Ramcar\JOStatus; use App\Ramcar\JOStatus;
use App\Ramcar\InvoiceCriteria; use App\Ramcar\InvoiceCriteria;
use App\Ramcar\CMBServiceType; use App\Ramcar\CMBServiceType;
use App\Ramcar\ServiceType;
use App\Ramcar\WarrantyClass; use App\Ramcar\WarrantyClass;
use App\Ramcar\APIRiderStatus; use App\Ramcar\APIRiderStatus;
use App\Ramcar\TransactionOrigin; use App\Ramcar\TransactionOrigin;
use App\Ramcar\CMBTradeInType; use App\Ramcar\CMBTradeInType;
use App\Ramcar\TradeInType;
use App\Ramcar\InvoiceStatus; use App\Ramcar\InvoiceStatus;
use App\Ramcar\ModeOfPayment; use App\Ramcar\ModeOfPayment;
use App\Ramcar\JOEventType; use App\Ramcar\JOEventType;
use App\Service\InvoiceGeneratorInterface; use App\Service\InvoiceGeneratorInterface;
use App\Service\MQTTClient; use App\Service\MQTTClient;
use App\Service\WarrantyHandler;
use App\Service\RedisClientProvider; use App\Service\RedisClientProvider;
use App\Entity\RiderSession; use App\Entity\RiderSession;
@ -49,6 +52,7 @@ use DateTime;
use DateInterval; use DateInterval;
// Rider API controller // Rider API controller
// TODO: Need to refactor this into a service
class RAPIController extends Controller class RAPIController extends Controller
{ {
protected $session; protected $session;
@ -606,7 +610,7 @@ class RAPIController extends Controller
return $res->getReturnResponse(); return $res->getReturnResponse();
} }
public function payment(Request $req, MQTTClient $mclient) public function payment(Request $req, MQTTClient $mclient, WarrantyHandler $wh)
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$required_params = ['jo_id']; $required_params = ['jo_id'];
@ -634,9 +638,50 @@ class RAPIController extends Controller
// TODO: tag rider as unavailable // TODO: tag rider as unavailable
// save to customer vehicle battery record
// TODO: this has to move to JOHandler
$this->updateVehicleBattery($jo);
$em->flush(); $em->flush();
// send mqtt event (fulfilled) // create warranty
if (($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW) ||
($jo->getServiceType() == CMBServiceType::BATTERY_REPLACEMENT_NEW))
{
$serial = null;
$warranty_class = $jo->getWarrantyClass();
$first_name = $jo->getCustomer()->getFirstName();
$last_name = $jo->getCustomer()->getLastName();
$mobile_number = $jo->getCustomer()->getPhoneMobile();
// check if date fulfilled is null
if ($jo->getDateFulfill() == null)
$date_purchase = $jo->getDateCreate();
else
$date_purchase = $jo->getDateFulfill();
$plate_number = $wh->cleanPlateNumber($jo->getCustomerVehicle()->getPlateNumber());
$batt_list = array();
$invoice = $jo->getInvoice();
if (!empty($invoice))
{
// get battery
$invoice_items = $invoice->getItems();
foreach ($invoice_items as $item)
{
$battery = $item->getBattery();
if ($battery != null)
{
$batt_list[] = $item->getBattery();
}
}
}
$wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
}
// send mqtt event (fulfilled)
$rider = $this->session->getRider(); $rider = $this->session->getRider();
$image_url = $req->getScheme() . '://' . $req->getHttpHost() . $req->getBasePath() . '/assets/images/user.gif'; $image_url = $req->getScheme() . '://' . $req->getHttpHost() . $req->getBasePath() . '/assets/images/user.gif';
if ($rider->getImageFile() != null) if ($rider->getImageFile() != null)
@ -650,12 +695,6 @@ class RAPIController extends Controller
]; ];
$mclient->sendEvent($jo, $payload); $mclient->sendEvent($jo, $payload);
// create the warranty if new battery only
if ($jo->getServiceType () == CMBServiceType::BATTERY_REPLACEMENT_NEW)
{
$this->createWarranty($jo);
}
return $res->getReturnResponse(); return $res->getReturnResponse();
} }
@ -774,7 +813,8 @@ class RAPIController extends Controller
// check service type // check service type
$stype_id = $req->request->get('stype_id'); $stype_id = $req->request->get('stype_id');
if (!CMBServiceType::validate($stype_id)) if ((!CMBServiceType::validate($stype_id)) ||
(!ServiceType::validate($stype_id)))
{ {
$res->setError(true) $res->setError(true)
->setErrorMessage('Invalid service type - ' . $stype_id); ->setErrorMessage('Invalid service type - ' . $stype_id);
@ -836,7 +876,8 @@ class RAPIController extends Controller
// check trade in // check trade in
$trade_in = $req->request->get('trade_in'); $trade_in = $req->request->get('trade_in');
if (!CMBTradeInType::validate($trade_in)) if ((!CMBTradeInType::validate($trade_in)) ||
(!TradeInType::validate($trade_in)))
$trade_in = null; $trade_in = null;
// check mode of payment // check mode of payment
@ -890,79 +931,59 @@ class RAPIController extends Controller
return $res->getReturnResponse(); return $res->getReturnResponse();
} }
protected function createWarranty($jo) protected function updateVehicleBattery(JobOrder $jo)
{ {
$em = $this->getDoctrine()->getManager(); // check if new battery
$warranty = new Warranty(); if (($jo->getServiceType() != ServiceType::BATTERY_REPLACEMENT_NEW) ||
($jo->getServiceType() != CMBServiceType::BATTERY_REPLACEMENT_NEW))
return;
$warranty_class = $jo->getWarrantyClass(); // customer vehicle
$first_name = $jo->getCustomer()->getFirstName(); $cv = $jo->getCustomerVehicle();
$last_name = $jo->getCustomer()->getLastName(); if ($cv == null)
$mobile_number = $jo->getCustomer()->getPhoneMobile(); return;
// check if date fulfilled is null // invoice
if ($jo->getDateFulfill() == null) $invoice = $jo->getInvoice();
$date_create = $jo->getDateCreate(); if ($invoice == null)
else return;
$date_create = $jo->getDateFulfill();
// normalize the plate number // invoice items
$plate_number = $this->normalizePlateNumber($jo->getCustomerVehicle()->getPlateNumber()); $items = $invoice->getItems();
if (count($items) <= 0)
return;
// get battery and its warranty periods // get first battery from invoice
$warranty_period = 0; $battery = null;
$invoice_items = $jo->getInvoice()->getItems(); foreach ($items as $item)
foreach ($invoice_items as $item)
{ {
if ($item->getBattery() != null) $battery = $item->getBattery();
{ if ($battery != null)
$battery = $item->getBattery(); break;
$warranty->setBatteryModel($battery->getModel());
$warranty->setBatterySize($battery->getSize());
if ($warranty_class == WarrantyClass::WTY_PRIVATE)
$warranty_period = $battery->getWarrantyPrivate();
else if ($warranty_class == WarrantyClass::WTY_COMMERCIAL)
$warranty_period = $battery->getWarrantyCommercial();
else if ($warranty_class == WarrantyClass::WTY_TNV)
$warranty_period = $battery->getWarrantyTnv();
}
} }
// compute expiry date // no battery in order
$expiry_date = $this->computeDateExpire($date_create, $warranty_period); if ($battery == null)
return;
$warranty->setWarrantyClass($warranty_class) // warranty expiration
->setFirstName($first_name) $warr_months = 0;
->setLastName($last_name) $warr = $jo->getWarrantyClass();
->setMobileNumber($mobile_number) if ($warr == WarrantyClass::WTY_PRIVATE)
->setDatePurchase($date_create) $warr_months = $battery->getWarrantyPrivate();
->setDateExpire($expiry_date) else if ($warr == WarrantyClass::WTY_COMMERCIAL)
->setPlateNumber($plate_number); $warr_months = $battery->getWarrantyCommercial();
else if ($warr == WarrantyClass::WTY_TNV)
$warr_months = 12;
$em->persist($warranty); $warr_date = new DateTime();
$em->flush(); $warr_date->add(new DateInterval('P' . $warr_months . 'M'));
// update customer vehicle battery
$cv->setCurrentBattery($battery)
->setHasMotoliteBattery(true)
->setWarrantyExpiration($warr_date);
} }
protected function normalizePlateNumber($plate_number)
{
// make it upper case
$plate_number = trim(strtoupper($plate_number));
// remove special characters and spaces
$plate_number = preg_replace('/[^A-Za-z0-9]/', '', $plate_number);
//error_log('plate number ' . $plate_number);
return $plate_number;
}
protected function computeDateExpire($date_create, $warranty_period)
{
$expire_date = clone $date_create;
$expire_date->add(new DateInterval('P'.$warranty_period.'M'));
return $expire_date;
}
} }

View file

@ -96,7 +96,7 @@
<div class="col-lg-6"> <div class="col-lg-6">
<label data-field="customer_phone_mobile">Mobile Phone</label> <label data-field="customer_phone_mobile">Mobile Phone</label>
<div class="input-group m-input-group"> <div class="input-group m-input-group">
<span class="input-group-addon">+63</span> <span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="customer_phone_mobile" id="customer-phone-mobile" class="form-control m-input" value="{{ obj.getCustomer.getPhoneMobile|default('') }}" data-vehicle-field="1" disabled> <input type="text" name="customer_phone_mobile" id="customer-phone-mobile" class="form-control m-input" value="{{ obj.getCustomer.getPhoneMobile|default('') }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="customer_phone_mobile"></div> <div class="form-control-feedback hide" data-field="customer_phone_mobile"></div>
</div> </div>
@ -104,7 +104,7 @@
<div class="col-lg-6"> <div class="col-lg-6">
<label data-field="customer_phone_landline">Landline</label> <label data-field="customer_phone_landline">Landline</label>
<div class="input-group m-input-group"> <div class="input-group m-input-group">
<span class="input-group-addon">+63</span> <span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="customer_phone_landline" id="customer-phone-landline" class="form-control m-input" value="{{ obj.getCustomer.getPhoneLandline|default('') }}" data-vehicle-field="1" disabled> <input type="text" name="customer_phone_landline" id="customer-phone-landline" class="form-control m-input" value="{{ obj.getCustomer.getPhoneLandline|default('') }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="customer_phone_landline"></div> <div class="form-control-feedback hide" data-field="customer_phone_landline"></div>
</div> </div>
@ -114,7 +114,7 @@
<div class="col-lg-6"> <div class="col-lg-6">
<label data-field="customer_phone_office">Office Phone</label> <label data-field="customer_phone_office">Office Phone</label>
<div class="input-group m-input-group"> <div class="input-group m-input-group">
<span class="input-group-addon">+63</span> <span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="customer_phone_office" id="customer-phone-office" class="form-control m-input" value="{{ obj.getCustomer.getPhoneOffice|default('') }}" data-vehicle-field="1" disabled> <input type="text" name="customer_phone_office" id="customer-phone-office" class="form-control m-input" value="{{ obj.getCustomer.getPhoneOffice|default('') }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="customer_phone_office"></div> <div class="form-control-feedback hide" data-field="customer_phone_office"></div>
</div> </div>
@ -122,7 +122,7 @@
<div class="col-lg-6"> <div class="col-lg-6">
<label data-field="customer_phone_fax">Fax</label> <label data-field="customer_phone_fax">Fax</label>
<div class="input-group m-input-group"> <div class="input-group m-input-group">
<span class="input-group-addon">+63</span> <span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="customer_phone_fax" id="customer-phone-fax" class="form-control m-input" value="{{ obj.getCustomer.getPhoneFax|default('') }}" data-vehicle-field="1" disabled> <input type="text" name="customer_phone_fax" id="customer-phone-fax" class="form-control m-input" value="{{ obj.getCustomer.getPhoneFax|default('') }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="customer_phone_fax"></div> <div class="form-control-feedback hide" data-field="customer_phone_fax"></div>
</div> </div>

View file

@ -110,7 +110,7 @@
<div class="col-lg-6"> <div class="col-lg-6">
<label data-field="customer_phone_mobile">Mobile Phone</label> <label data-field="customer_phone_mobile">Mobile Phone</label>
<div class="input-group m-input-group"> <div class="input-group m-input-group">
<span class="input-group-addon">+63</span> <span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="customer_phone_mobile" id="customer-phone-mobile" class="form-control m-input" value="{{ obj.getCustomer.getPhoneMobile|default('') }}" data-vehicle-field="1" disabled> <input type="text" name="customer_phone_mobile" id="customer-phone-mobile" class="form-control m-input" value="{{ obj.getCustomer.getPhoneMobile|default('') }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="customer_phone_mobile"></div> <div class="form-control-feedback hide" data-field="customer_phone_mobile"></div>
</div> </div>
@ -118,7 +118,7 @@
<div class="col-lg-6"> <div class="col-lg-6">
<label data-field="customer_phone_landline">Landline</label> <label data-field="customer_phone_landline">Landline</label>
<div class="input-group m-input-group"> <div class="input-group m-input-group">
<span class="input-group-addon">+63</span> <span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="customer_phone_landline" id="customer-phone-landline" class="form-control m-input" value="{{ obj.getCustomer.getPhoneLandline|default('') }}" data-vehicle-field="1" disabled> <input type="text" name="customer_phone_landline" id="customer-phone-landline" class="form-control m-input" value="{{ obj.getCustomer.getPhoneLandline|default('') }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="customer_phone_landline"></div> <div class="form-control-feedback hide" data-field="customer_phone_landline"></div>
</div> </div>
@ -128,7 +128,7 @@
<div class="col-lg-6"> <div class="col-lg-6">
<label data-field="customer_phone_office">Office Phone</label> <label data-field="customer_phone_office">Office Phone</label>
<div class="input-group m-input-group"> <div class="input-group m-input-group">
<span class="input-group-addon">+63</span> <span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="customer_phone_office" id="customer-phone-office" class="form-control m-input" value="{{ obj.getCustomer.getPhoneOffice|default('') }}" data-vehicle-field="1" disabled> <input type="text" name="customer_phone_office" id="customer-phone-office" class="form-control m-input" value="{{ obj.getCustomer.getPhoneOffice|default('') }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="customer_phone_office"></div> <div class="form-control-feedback hide" data-field="customer_phone_office"></div>
</div> </div>
@ -136,7 +136,7 @@
<div class="col-lg-6"> <div class="col-lg-6">
<label data-field="customer_phone_fax">Fax</label> <label data-field="customer_phone_fax">Fax</label>
<div class="input-group m-input-group"> <div class="input-group m-input-group">
<span class="input-group-addon">+63</span> <span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="customer_phone_fax" id="customer-phone-fax" class="form-control m-input" value="{{ obj.getCustomer.getPhoneFax|default('') }}" data-vehicle-field="1" disabled> <input type="text" name="customer_phone_fax" id="customer-phone-fax" class="form-control m-input" value="{{ obj.getCustomer.getPhoneFax|default('') }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="customer_phone_fax"></div> <div class="form-control-feedback hide" data-field="customer_phone_fax"></div>
</div> </div>

View file

@ -94,7 +94,7 @@
<div class="col-lg-6"> <div class="col-lg-6">
<label data-field="customer_phone_mobile">Mobile Phone</label> <label data-field="customer_phone_mobile">Mobile Phone</label>
<div class="input-group m-input-group"> <div class="input-group m-input-group">
<span class="input-group-addon">+63</span> <span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="customer_phone_mobile" id="customer-phone-mobile" class="form-control m-input" value="{{ obj.getCustomer.getPhoneMobile|default('') }}" data-vehicle-field="1" disabled> <input type="text" name="customer_phone_mobile" id="customer-phone-mobile" class="form-control m-input" value="{{ obj.getCustomer.getPhoneMobile|default('') }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="customer_phone_mobile"></div> <div class="form-control-feedback hide" data-field="customer_phone_mobile"></div>
</div> </div>
@ -102,7 +102,7 @@
<div class="col-lg-6"> <div class="col-lg-6">
<label data-field="customer_phone_landline">Landline</label> <label data-field="customer_phone_landline">Landline</label>
<div class="input-group m-input-group"> <div class="input-group m-input-group">
<span class="input-group-addon">+63</span> <span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="customer_phone_landline" id="customer-phone-landline" class="form-control m-input" value="{{ obj.getCustomer.getPhoneLandline|default('') }}" data-vehicle-field="1" disabled> <input type="text" name="customer_phone_landline" id="customer-phone-landline" class="form-control m-input" value="{{ obj.getCustomer.getPhoneLandline|default('') }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="customer_phone_landline"></div> <div class="form-control-feedback hide" data-field="customer_phone_landline"></div>
</div> </div>
@ -112,7 +112,7 @@
<div class="col-lg-6"> <div class="col-lg-6">
<label data-field="customer_phone_office">Office Phone</label> <label data-field="customer_phone_office">Office Phone</label>
<div class="input-group m-input-group"> <div class="input-group m-input-group">
<span class="input-group-addon">+63</span> <span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="customer_phone_office" id="customer-phone-office" class="form-control m-input" value="{{ obj.getCustomer.getPhoneOffice|default('') }}" data-vehicle-field="1" disabled> <input type="text" name="customer_phone_office" id="customer-phone-office" class="form-control m-input" value="{{ obj.getCustomer.getPhoneOffice|default('') }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="customer_phone_office"></div> <div class="form-control-feedback hide" data-field="customer_phone_office"></div>
</div> </div>
@ -120,7 +120,7 @@
<div class="col-lg-6"> <div class="col-lg-6">
<label data-field="customer_phone_fax">Fax</label> <label data-field="customer_phone_fax">Fax</label>
<div class="input-group m-input-group"> <div class="input-group m-input-group">
<span class="input-group-addon">+63</span> <span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="customer_phone_fax" id="customer-phone-fax" class="form-control m-input" value="{{ obj.getCustomer.getPhoneFax|default('') }}" data-vehicle-field="1" disabled> <input type="text" name="customer_phone_fax" id="customer-phone-fax" class="form-control m-input" value="{{ obj.getCustomer.getPhoneFax|default('') }}" data-vehicle-field="1" disabled>
<div class="form-control-feedback hide" data-field="customer_phone_fax"></div> <div class="form-control-feedback hide" data-field="customer_phone_fax"></div>
</div> </div>