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:
commit
fd0738ad57
5 changed files with 108 additions and 85 deletions
|
|
@ -28,6 +28,8 @@ RT_SHORTCODE=1234
|
|||
MQTT_IP_ADDRESS=localhost
|
||||
MQTT_PORT=8883
|
||||
MQTT_CERT=/location/of/cert/file.crt
|
||||
MQTT_WS_HOST=insertiphere
|
||||
MQTT_WS_PORT=8083
|
||||
|
||||
# redis client
|
||||
REDIS_CLIENT_SCHEME=tcp
|
||||
|
|
|
|||
|
|
@ -17,16 +17,19 @@ use App\Ramcar\APIResult;
|
|||
use App\Ramcar\JOStatus;
|
||||
use App\Ramcar\InvoiceCriteria;
|
||||
use App\Ramcar\CMBServiceType;
|
||||
use App\Ramcar\ServiceType;
|
||||
use App\Ramcar\WarrantyClass;
|
||||
use App\Ramcar\APIRiderStatus;
|
||||
use App\Ramcar\TransactionOrigin;
|
||||
use App\Ramcar\CMBTradeInType;
|
||||
use App\Ramcar\TradeInType;
|
||||
use App\Ramcar\InvoiceStatus;
|
||||
use App\Ramcar\ModeOfPayment;
|
||||
use App\Ramcar\JOEventType;
|
||||
|
||||
use App\Service\InvoiceGeneratorInterface;
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\WarrantyHandler;
|
||||
use App\Service\RedisClientProvider;
|
||||
|
||||
use App\Entity\RiderSession;
|
||||
|
|
@ -49,6 +52,7 @@ use DateTime;
|
|||
use DateInterval;
|
||||
|
||||
// Rider API controller
|
||||
// TODO: Need to refactor this into a service
|
||||
class RAPIController extends Controller
|
||||
{
|
||||
protected $session;
|
||||
|
|
@ -606,7 +610,7 @@ class RAPIController extends Controller
|
|||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function payment(Request $req, MQTTClient $mclient)
|
||||
public function payment(Request $req, MQTTClient $mclient, WarrantyHandler $wh)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$required_params = ['jo_id'];
|
||||
|
|
@ -634,8 +638,49 @@ class RAPIController extends Controller
|
|||
|
||||
// TODO: tag rider as unavailable
|
||||
|
||||
// save to customer vehicle battery record
|
||||
// TODO: this has to move to JOHandler
|
||||
$this->updateVehicleBattery($jo);
|
||||
|
||||
$em->flush();
|
||||
|
||||
// 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();
|
||||
$image_url = $req->getScheme() . '://' . $req->getHttpHost() . $req->getBasePath() . '/assets/images/user.gif';
|
||||
|
|
@ -650,12 +695,6 @@ class RAPIController extends Controller
|
|||
];
|
||||
$mclient->sendEvent($jo, $payload);
|
||||
|
||||
// create the warranty if new battery only
|
||||
if ($jo->getServiceType () == CMBServiceType::BATTERY_REPLACEMENT_NEW)
|
||||
{
|
||||
$this->createWarranty($jo);
|
||||
}
|
||||
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
|
|
@ -774,7 +813,8 @@ class RAPIController extends Controller
|
|||
|
||||
// check service type
|
||||
$stype_id = $req->request->get('stype_id');
|
||||
if (!CMBServiceType::validate($stype_id))
|
||||
if ((!CMBServiceType::validate($stype_id)) ||
|
||||
(!ServiceType::validate($stype_id)))
|
||||
{
|
||||
$res->setError(true)
|
||||
->setErrorMessage('Invalid service type - ' . $stype_id);
|
||||
|
|
@ -836,7 +876,8 @@ class RAPIController extends Controller
|
|||
|
||||
// check 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;
|
||||
|
||||
// check mode of payment
|
||||
|
|
@ -890,79 +931,59 @@ class RAPIController extends Controller
|
|||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
protected function createWarranty($jo)
|
||||
protected function updateVehicleBattery(JobOrder $jo)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$warranty = new Warranty();
|
||||
// check if new battery
|
||||
if (($jo->getServiceType() != ServiceType::BATTERY_REPLACEMENT_NEW) ||
|
||||
($jo->getServiceType() != CMBServiceType::BATTERY_REPLACEMENT_NEW))
|
||||
|
||||
$warranty_class = $jo->getWarrantyClass();
|
||||
$first_name = $jo->getCustomer()->getFirstName();
|
||||
$last_name = $jo->getCustomer()->getLastName();
|
||||
$mobile_number = $jo->getCustomer()->getPhoneMobile();
|
||||
return;
|
||||
|
||||
// check if date fulfilled is null
|
||||
if ($jo->getDateFulfill() == null)
|
||||
$date_create = $jo->getDateCreate();
|
||||
else
|
||||
$date_create = $jo->getDateFulfill();
|
||||
// customer vehicle
|
||||
$cv = $jo->getCustomerVehicle();
|
||||
if ($cv == null)
|
||||
return;
|
||||
|
||||
// normalize the plate number
|
||||
$plate_number = $this->normalizePlateNumber($jo->getCustomerVehicle()->getPlateNumber());
|
||||
// invoice
|
||||
$invoice = $jo->getInvoice();
|
||||
if ($invoice == null)
|
||||
return;
|
||||
|
||||
// get battery and its warranty periods
|
||||
$warranty_period = 0;
|
||||
$invoice_items = $jo->getInvoice()->getItems();
|
||||
foreach ($invoice_items as $item)
|
||||
{
|
||||
if ($item->getBattery() != null)
|
||||
// invoice items
|
||||
$items = $invoice->getItems();
|
||||
if (count($items) <= 0)
|
||||
return;
|
||||
|
||||
// get first battery from invoice
|
||||
$battery = null;
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$battery = $item->getBattery();
|
||||
$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();
|
||||
}
|
||||
if ($battery != null)
|
||||
break;
|
||||
}
|
||||
|
||||
// compute expiry date
|
||||
$expiry_date = $this->computeDateExpire($date_create, $warranty_period);
|
||||
// no battery in order
|
||||
if ($battery == null)
|
||||
return;
|
||||
|
||||
$warranty->setWarrantyClass($warranty_class)
|
||||
->setFirstName($first_name)
|
||||
->setLastName($last_name)
|
||||
->setMobileNumber($mobile_number)
|
||||
->setDatePurchase($date_create)
|
||||
->setDateExpire($expiry_date)
|
||||
->setPlateNumber($plate_number);
|
||||
// warranty expiration
|
||||
$warr_months = 0;
|
||||
$warr = $jo->getWarrantyClass();
|
||||
if ($warr == WarrantyClass::WTY_PRIVATE)
|
||||
$warr_months = $battery->getWarrantyPrivate();
|
||||
else if ($warr == WarrantyClass::WTY_COMMERCIAL)
|
||||
$warr_months = $battery->getWarrantyCommercial();
|
||||
else if ($warr == WarrantyClass::WTY_TNV)
|
||||
$warr_months = 12;
|
||||
|
||||
$em->persist($warranty);
|
||||
$em->flush();
|
||||
$warr_date = new DateTime();
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@
|
|||
<div class="col-lg-6">
|
||||
<label data-field="customer_phone_mobile">Mobile Phone</label>
|
||||
<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>
|
||||
<div class="form-control-feedback hide" data-field="customer_phone_mobile"></div>
|
||||
</div>
|
||||
|
|
@ -104,7 +104,7 @@
|
|||
<div class="col-lg-6">
|
||||
<label data-field="customer_phone_landline">Landline</label>
|
||||
<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>
|
||||
<div class="form-control-feedback hide" data-field="customer_phone_landline"></div>
|
||||
</div>
|
||||
|
|
@ -114,7 +114,7 @@
|
|||
<div class="col-lg-6">
|
||||
<label data-field="customer_phone_office">Office Phone</label>
|
||||
<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>
|
||||
<div class="form-control-feedback hide" data-field="customer_phone_office"></div>
|
||||
</div>
|
||||
|
|
@ -122,7 +122,7 @@
|
|||
<div class="col-lg-6">
|
||||
<label data-field="customer_phone_fax">Fax</label>
|
||||
<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>
|
||||
<div class="form-control-feedback hide" data-field="customer_phone_fax"></div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@
|
|||
<div class="col-lg-6">
|
||||
<label data-field="customer_phone_mobile">Mobile Phone</label>
|
||||
<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>
|
||||
<div class="form-control-feedback hide" data-field="customer_phone_mobile"></div>
|
||||
</div>
|
||||
|
|
@ -118,7 +118,7 @@
|
|||
<div class="col-lg-6">
|
||||
<label data-field="customer_phone_landline">Landline</label>
|
||||
<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>
|
||||
<div class="form-control-feedback hide" data-field="customer_phone_landline"></div>
|
||||
</div>
|
||||
|
|
@ -128,7 +128,7 @@
|
|||
<div class="col-lg-6">
|
||||
<label data-field="customer_phone_office">Office Phone</label>
|
||||
<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>
|
||||
<div class="form-control-feedback hide" data-field="customer_phone_office"></div>
|
||||
</div>
|
||||
|
|
@ -136,7 +136,7 @@
|
|||
<div class="col-lg-6">
|
||||
<label data-field="customer_phone_fax">Fax</label>
|
||||
<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>
|
||||
<div class="form-control-feedback hide" data-field="customer_phone_fax"></div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@
|
|||
<div class="col-lg-6">
|
||||
<label data-field="customer_phone_mobile">Mobile Phone</label>
|
||||
<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>
|
||||
<div class="form-control-feedback hide" data-field="customer_phone_mobile"></div>
|
||||
</div>
|
||||
|
|
@ -102,7 +102,7 @@
|
|||
<div class="col-lg-6">
|
||||
<label data-field="customer_phone_landline">Landline</label>
|
||||
<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>
|
||||
<div class="form-control-feedback hide" data-field="customer_phone_landline"></div>
|
||||
</div>
|
||||
|
|
@ -112,7 +112,7 @@
|
|||
<div class="col-lg-6">
|
||||
<label data-field="customer_phone_office">Office Phone</label>
|
||||
<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>
|
||||
<div class="form-control-feedback hide" data-field="customer_phone_office"></div>
|
||||
</div>
|
||||
|
|
@ -120,7 +120,7 @@
|
|||
<div class="col-lg-6">
|
||||
<label data-field="customer_phone_fax">Fax</label>
|
||||
<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>
|
||||
<div class="form-control-feedback hide" data-field="customer_phone_fax"></div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue