Merge branch '309-replace-63-in-templates-with-proper-country-code' into '270-final-cmb-fixes'

Resolve "Replace +63 in templates with proper country code"

See merge request jankstudio/resq!350
This commit is contained in:
Kendrick Chan 2020-01-28 02:54:08 +00:00
commit 6dd3f3377e
7 changed files with 121 additions and 24 deletions

View file

@ -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

View file

@ -11,6 +11,7 @@ parameters:
app_acl_file: 'acl.yaml'
app_access_key: 'access_keys'
cvu_brand_id: "%env(CVU_BRAND_ID)%"
country_code: "%env(COUNTRY_CODE)%"
services:
# default configuration for services in *this* file

View file

@ -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\Service\RiderCache;
@ -50,6 +53,7 @@ use DateTime;
use DateInterval;
// Rider API controller
// TODO: Need to refactor this into a service
class RAPIController extends Controller
{
protected $session;
@ -615,7 +619,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'];
@ -643,8 +647,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';
@ -659,12 +704,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();
}
@ -783,7 +822,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);
@ -845,7 +885,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
@ -899,6 +940,60 @@ class RAPIController extends Controller
return $res->getReturnResponse();
}
protected function updateVehicleBattery(JobOrder $jo)
{
// check if new battery
if (($jo->getServiceType() != ServiceType::BATTERY_REPLACEMENT_NEW) ||
($jo->getServiceType() != CMBServiceType::BATTERY_REPLACEMENT_NEW))
return;
// customer vehicle
$cv = $jo->getCustomerVehicle();
if ($cv == null)
return;
// invoice
$invoice = $jo->getInvoice();
if ($invoice == null)
return;
// invoice items
$items = $invoice->getItems();
if (count($items) <= 0)
return;
// get first battery from invoice
$battery = null;
foreach ($items as $item)
{
$battery = $item->getBattery();
if ($battery != null)
break;
}
// no battery in order
if ($battery == null)
return;
// 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;
$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 createWarranty($jo)
{
$em = $this->getDoctrine()->getManager();
@ -972,6 +1067,4 @@ class RAPIController extends Controller
$expire_date->add(new DateInterval('P'.$warranty_period.'M'));
return $expire_date;
}
}

View file

@ -78,7 +78,8 @@ class WarrantyHandler
->setFirstName($first_name)
->setLastName($last_name)
->setMobileNumber($mobile_number)
->setDatePurchase($date_purchase);
->setDatePurchase($date_purchase)
->setWarrantyClass($warranty_class);
$this->em->persist($warranty);
$this->em->flush();

View file

@ -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>

View file

@ -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>

View file

@ -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>