Merge branch 'master' of gitlab.com:jankstudio/resq into 634-put-fuel-charges-in-env-file

Conflicts:
	src/Service/InvoiceGenerator/ResqInvoiceGenerator.php
This commit is contained in:
Korina Cordero 2022-04-26 01:50:35 +00:00
commit dc81db96ac
22 changed files with 1072 additions and 117 deletions

View file

@ -0,0 +1,208 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\JobOrder;
use App\Entity\JOEvent;
use App\Entity\User;
use App\Entity\Warranty;
use App\Ramcar\JOStatus;
use App\Ramcar\JOEventType;
use App\Ramcar\DeliveryStatus;
use App\Ramcar\WarrantyClass;
use App\Ramcar\ServiceType;
use App\Ramcar\WarrantySource;
use App\Service\WarrantyHandler;
use DateTime;
use DateInterval;
class FulfillAssignedJobOrderCommand extends Command
{
protected $em;
protected $wh;
public function __construct(EntityManagerInterface $em, WarrantyHandler $wh)
{
$this->em = $em;
$this->wh = $wh;
parent::__construct();
}
protected function configure()
{
$this->setName('joborder:fulfillassignednosms')
->setDescription('Fulfill assigned job orders without sending an SMS message.')
->setHelp('Mark assigned job orders as fulfilled and should not send a SMS message. Date format: YYYY-MM-DD')
->addArgument('end_date', InputArgument::REQUIRED, 'End date. Format: YYYY-MM-DD');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// get the input date
$str_date_end = $input->getArgument('end_date');
// retrieve job orders that have status assigned and has not been fulfilled starting from input date and before.
// starting time to count is date schedule
$date_end = new DateTime($str_date_end);
$query = $this->em->createQuery('SELECT jo FROM App\Entity\JobOrder jo WHERE jo.status = :status
AND jo.date_schedule <= :date_end');
$jo_results = $query->setParameters([
'status' => JOStatus::ASSIGNED,
'date_end' => $date_end,
])
->getResult();
error_log('Found job orders ' . count($jo_results));
// get user. Use the admin user.
$user = $this->em->getRepository(User::class)->find(1);
foreach ($jo_results as $jo)
{
error_log('Fulfilling job order ' . $jo->getID());
$jo->fulfill();
// set delivery status
$jo->setDeliveryStatus(DeliveryStatus::FULFILLED);
// create JO event
$event = new JOEvent();
$event->setDateHappen(new DateTime())
->setTypeID(JOEventType::FULFILL)
->setJobOrder($jo)
->setUser($user);
$this->em->persist($event);
// update the customer vehicle battery record
$this->updateVehicleBattery($jo);
$this->em->flush();
// check if new battery
// if yes, create warranty
if ($this->checkIfNewBattery($jo))
{
$this->createWarranty($jo, $user);
}
}
return 0;
}
protected function updateVehicleBattery(JobOrder $jo)
{
// check if new battery
if (!($this->checkIfNewBattery($jo)))
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 = $jo->getWarrantyClass();
$warr_months = 0;
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 checkIfNewBattery(JobOrder $jo)
{
if ($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW)
return true;
return false;
}
protected function createWarranty(JobOrder $jo, User $user)
{
$serial = null;
$warranty_class = $jo->getWarrantyClass();
$first_name = $jo->getCustomer()->getFirstName();
$last_name = $jo->getCustomer()->getLastName();
$mobile_number = $jo->getCustomer()->getPhoneMobile();
// use date_schedule for warranty expiration computation
$date_purchase = $jo->getDateSchedule();
// validate plate number
$plate_number = Warranty::cleanPlateNumber($jo->getCustomerVehicle()->getPlateNumber());
if ($plate_number != false)
{
$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();
}
}
}
$user_id = $user->getUsername();
$source = WarrantySource::ADMIN_PANEL;
$this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class, $user_id, $source, $jo->getCustomer(), $jo->getCustomerVehicle()->getVehicle());
}
else
{
error_log('Invalid plate number for warranty. Plate number = ' . $jo->getCustomerVehicle()->getPlateNumber());
}
}
}

View file

@ -0,0 +1,463 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManagerInterface;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use DateTime;
use App\Entity\VehicleManufacturer;
use App\Entity\Vehicle;
use App\Entity\Battery;
use App\Entity\BatteryManufacturer;
use App\Entity\BatteryModel;
use App\Entity\BatterySize;
class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command
{
const F_V_BRAND = 0;
const F_V_MAKE = 1;
const F_V_MODEL_YEAR = 2;
const F_B_SIZE = 7;
const F_B_MODEL = 8;
//const F_B_ALT_PREM_MF = 10;
//const F_B_ALT_PREM_LM = 11;
//const F_B_ALT_SUPER_PREM_MF = 12;
//const F_B_ALT_SUPREME_MF = 13;
//const F_B_ALT_PLATINUM_MF = 14;
// the rest of the fields are irrelevant
protected $em;
protected $vmfg_index;
protected $v_index;
protected $batt_index;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
$this->vmfg_index = [];
$this->v_index = [];
$this->batt_index = [];
parent::__construct();
}
protected function configure()
{
$this->setName('yokohamavehicle:import')
->setDescription('Import Yokohama data CSV file with vehicles and batteries.')
->setHelp('Creates vehicles and batteries based on imported Yokohama CSV.')
->addArgument('input_file', InputArgument::REQUIRED, 'Path to the CSV file.')
->addArgument('output_file', InputArgument::REQUIRED, 'Path to output file.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$csv_file = $input->getArgument('input_file');
$output_file = $input->getArgument('output_file');
$this->populateVehicleManufacturerIndex();
$this->populateVehicleIndex();
$this->populateBatteryIndex();
// attempt to open file
try
{
$fh = fopen($csv_file, "r");
}
catch (Exception $e)
{
throw new Exception('The file "' . $csv_file . '" could be read.');
}
// get entity manager
$em = $this->em;
$vbrands = [];
$output_info = [];
// loop through rows
$row_num = 1;
$prem_mf_name = '';
$prem_lm_name = '';
$super_prem_mf_name = '';
$supreme_mf_name = '';
$platinum_mf_name = '';
while (($fields = fgetcsv($fh)) !== false)
{
$output->writeln("Parsing row " . $row_num . "...");
// alternate brands are not in file, so we just comment out
// get the alternate battery brand header names
/*
if ($row_num == 2)
{
$prem_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_PREM_MF]);
$prem_lm_name = $this->normalizeName($fields[SELF::F_B_ALT_PREM_LM]);
$super_prem_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_SUPER_PREM_MF]);
$supreme_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_SUPREME_MF]);
$platinum_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_PLATINUM_MF]);
}
*/
// process row
$output_info[] = $this->processRow($fields, $vbrands, $row_num, $prem_mf_name, $prem_lm_name,
$super_prem_mf_name, $supreme_mf_name, $platinum_mf_name);
$row_num++;
}
// save to db the valid ones
foreach ($vbrands as $brand_name => $vbrand)
{
// vehicles
foreach ($vbrand['vehicles'] as $row_num => $vdata)
{
$model = $vdata['model'];
if ($model == 'NONE')
{
$m_year_from = 0;
$m_year_to = 0;
}
else
{
$ex_model = explode('-', $model);
$m_year_from = trim($ex_model[0]);
if (isset($ex_model[1]))
$m_year_to = trim($ex_model[1]);
else
$m_year_to = 0;
}
$vehicle = $this->v_index[$brand_name][$vdata['make'] . '|' . intval($m_year_from) . '|' . intval($m_year_to)];
// recommended battery
$vdata['battery']->addVehicle($vehicle);
// alt_batteries
// alternate brands are not in file, so we just comment out
/*
if (isset($vdata['alt_battery_prem_mf']))
$vdata['alt_battery_prem_mf']->addVehicle($vehicle);
if (isset($vdata['alt_battery_prem_lm']))
$vdata['alt_battery_prem_lm']->addVehicle($vehicle);
if (isset($vdata['alt_battery_super_prem_mf']))
$vdata['alt_battery_super_prem_mf']->addVehicle($vehicle);
if (isset($vdata['alt_battery_supreme_mf']))
$vdata['alt_battery_supreme_mf']->addVehicle($vehicle);
if (isset($vdata['alt_battery_platinum_mf']))
$vdata['alt_battery_platinum_mf']->addVehicle($vehicle);
*/
}
}
$em->flush();
// write to output file
// error_log(print_r($output_info, true));
$this->outputVehicleBatteryInfo($output_file, $output_info);
fclose($fh);
return 0;
}
protected function processRow($fields, &$vbrands, $row_num, $prem_mf_name, $prem_lm_name,
$super_prem_mf_name, $supreme_mf_name, $platinum_mf_nam)
{
$output_info = [];
$brand = $this->normalizeName($fields[0]);
$make = $this->normalizeName($fields[1]);
$model = trim($fields[2]);
$bsize = $this->normalizeName($fields[self::F_B_SIZE]);
$bmodel = $this->normalizeName($fields[self::F_B_MODEL]);
// checking for valid vehicles and batteries should be done here so that only valid entries
// go into the vbrands array
$output_info = $this->validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel);
if (!empty($output_info))
return $output_info;
if (!isset($vbrands[$brand]))
{
// build array
$vbrands[$brand] = [
'vehicles' => [],
];
}
if (empty($model))
$model = 'NONE';
$vbrands[$brand]['vehicles'][$row_num] = [
'make' => $make,
'model' => $model,
];
// at this point we are sure we have battery
$batt_key = $this->getBatteryKey($bsize, $bmodel);
$vbrands[$brand]['vehicles'][$row_num]['battery'] = $this->batt_index[$batt_key];
// alternate brands are not in file, so we just comment out
// need to check alternate brands if battery exists
// go through the alternate fields, look for 'P'. Not kidding. It's what is in the csv file.
/*
if ($this->normalizeName($fields[SELF::F_B_ALT_PREM_MF]) == 'P')
{
// check if we have battery for name + size combo
$alt_batt_key = $this->getBatteryKey($field_bsize, $prem_mf_name);
if (isset($this->batt_index[$alt_batt_key]))
{
$vbrands[$brand]['vehicles'][$row_num]['alt_battery_prem_mf'] = $this->batt_index[$alt_batt_key];
}
}
if ($this->normalizeName($fields[SELF::F_B_ALT_PREM_LM]) == 'P')
{
// check if we have battery for name + size combo
$alt_batt_key = $this->getBatteryKey($field_bsize, $prem_lm_name);
if (isset($this->batt_index[$alt_batt_key]))
{
$vbrands[$brand]['vehicles'][$row_num]['alt_battery_prem_lm'] = $this->batt_index[$alt_batt_key];
}
}
if ($this->normalizeName($fields[SELF::F_B_ALT_SUPER_PREM_MF]) == 'P')
{
// check if we have battery for name + size combo
$alt_batt_key = $this->getBatteryKey($field_bsize, $super_prem_mf_name);
if (isset($this->batt_index[$alt_batt_key]))
{
$vbrands[$brand]['vehicles'][$row_num]['alt_battery_super_prem_mf'] = $this->batt_index[$alt_batt_key];
}
}
if ($this->normalizeName($fields[SELF::F_B_ALT_SUPREME_MF]) == 'P')
{
// check if we have battery for name + size combo
$alt_batt_key = $this->getBatteryKey($field_bsize, $supreme_mf_name);
if (isset($this->batt_index[$alt_batt_key]))
{
$vbrands[$brand]['vehicles'][$row_num]['alt_battery_supreme_mf'] = $this->batt_index[$alt_batt_key];
}
}
if ($this->normalizeName($fields[SELF::F_B_ALT_PLATINUM_MF]) == 'P')
{
// check if we have battery for name + size combo
$alt_batt_key = $this->getBatteryKey($field_bsize, $platinum_mf_name);
if (isset($this->batt_index[$alt_batt_key]))
{
$vbrands[$brand]['vehicles'][$row_num]['alt_battery_platinum_mf'] = $this->batt_index[$alt_batt_key];
}
}
*/
}
protected function validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel)
{
$output_info = [];
// check if manufacturer is blank
if (empty($brand))
{
$message = 'No manufacturer provided.';
$output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message);
return $output_info;
}
// check if make is blank
if (empty($make))
{
$message = 'No make provided.';
$output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message);
return $output_info;
}
// process model year data
if ($model == 'NONE')
{
$m_year_from = 0;
$m_year_to = 0;
}
else
{
$ex_model = explode('-', $model);
$m_year_from = trim($ex_model[0]);
if (isset($ex_model[1]))
$m_year_to = trim($ex_model[1]);
else
$m_year_to = 0;
}
// get manufacturer or make one
if (!isset($this->vmfg_index[$brand]))
{
// manufacturer
$mfg = new VehicleManufacturer();
$mfg->setName($brand);
$this->em->persist($mfg);
}
else
{
$mfg = $this->vmfg_index[$brand];
}
if (!isset($this->v_index[$brand][$make . '|' . intval($m_year_from) . '|' . intval($m_year_to)]))
{
// vehicle
$vehicle = new Vehicle();
$vehicle->setManufacturer($mfg)
->setMake($make)
->setModelYearFrom($m_year_from)
->setModelYearTo($m_year_to);
$this->em->persist($vehicle);
}
else
{
$vehicle = $this->v_index[$brand][$make . '|' . intval($m_year_from) . '|' . intval($m_year_to)];
}
// save to db new manufacturer and vehicle
$this->em->flush();
// add the vehicle manufacturer to hash
$this->vmfg_index[$brand] = $mfg;
// add the new vehicle to hash
$this->v_index[$brand][$make . '|' . $m_year_from . '|' . $m_year_to] = $vehicle;
// recommended battery
$batt_key = $this->getBatteryKey($bsize, $bmodel);
if (!isset($this->batt_index[$batt_key]))
{
$message = 'Could not find battery - ' . $bsize . ' - ' . $bmodel;
$output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message);
return $output_info;
}
return $output_info;
}
protected function setOutputInfo($fields, $status, $reason)
{
$mfg_name = trim($fields[SELF::F_V_BRAND]);
$model_name = trim($fields[SELF::F_V_MAKE]);
$model_year = trim($fields[SELF::F_V_MODEL_YEAR]);
$bsize = trim($fields[SELF::F_B_SIZE]);
$bmodel = trim($fields[SELF::F_B_MODEL]);
// alternate brands are not in file, so we just comment out
/*
$alt_prem_mf = trim($fields[SELF::F_B_ALT_PREM_MF]);
$alt_prem_lm = trim($fields[SELF::F_B_ALT_PREM_LM]);
$alt_super_prem_mf = trim($fields[SELF::F_B_ALT_SUPER_PREM_MF]);
$alt_supreme_mf = trim($fields[SELF::F_B_ALT_SUPREME_MF]);
$alt_platinum_mf = trim($fields[SELF::F_B_ALT_PLATINUM_MF]);
*/
return [
$mfg_name,
$model_name,
$model_year,
$bsize,
$bmodel,
$status,
$reason
];
}
protected function outputVehicleBatteryInfo($output_file, $entries)
{
try
{
$fh = fopen($output_file, "w");
}
catch (Exception $e)
{
throw new Exception('The file "' . $report_file . '" could be opened.');
}
// write the headers
fputcsv($fh, [
'Manufacturer',
'Vehicle Model',
'Year Model',
'Battery Size',
'Battery Model',
'Status',
'Reason',
]);
foreach($entries as $row)
{
if ($row != null)
fputcsv($fh, $row);
}
fclose($fh);
}
protected function populateVehicleManufacturerIndex()
{
$vmfgs = $this->em->getRepository(VehicleManufacturer::class)->findAll();
$this->vmfg_index = [];
foreach ($vmfgs as $vmfg)
{
$mfg_name = $this->normalizeName($vmfg->getName());
$this->vmfg_index[$mfg_name] = $vmfg;
}
}
protected function populateVehicleIndex()
{
$vs = $this->em->getRepository(Vehicle::class)->findAll();
$this->v_index = [];
foreach ($vs as $v)
{
$mfg_name = $this->normalizeName($v->getManufacturer()->getName());
if (!isset($this->v_index[$mfg_name]))
$this->v_index[$mfg_name] = [];
$this->v_index[$mfg_name][$this->normalizeName($v->getMake()) . '|' . $v->getModelYearFrom() . '|' . $v->getModelYearTo()] = $v;
}
}
protected function populateBatteryIndex()
{
$bs = $this->em->getRepository(Battery::class)->findAll();
$this->batt_index = [];
foreach ($bs as $b)
{
// get the battery size
$bsize = $b->getSize()->getName();
$key = $this->getBatteryKey($bsize, $b->getModel()->getName());
$this->batt_index[$key] = $b;
}
}
protected function getBatteryKey($size_name, $model_name)
{
return $this->normalizeName(str_replace(' ', '', $size_name)) .
'|' .
$this->normalizeName(str_replace(' ', '', $model_name));
}
protected function normalizeName($name)
{
$normalized_key = trim(strtoupper($name));
return $normalized_key;
}
}

View file

@ -0,0 +1,54 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use App\Service\MapTools;
class TestClosestOpenHubsCommand extends Command
{
protected $maptools;
protected function configure()
{
$this->setName('test:closestopenhubs')
->setDescription('Test the get closest open hubs service.')
->setHelp('Test the get closese open hubs service.')
->addArgument('long', InputArgument::REQUIRED, 'Longitude')
->addArgument('lat', InputArgument::REQUIRED, 'Latitude');
}
public function __construct(MapTools $maptools)
{
$this->maptools = $maptools;
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$long = $input->getArgument('long');
$lat = $input->getArgument('lat');
$point = new Point($long, $lat);
$hubs_with_distance = $this->maptools->getClosestOpenHubs($point, 10);
foreach($hubs_with_distance as $hub_dist)
{
$hub = $hub_dist['hub'];
$distance = $hub_dist['distance'];
error_log('Hub ID ' . $hub->getID() . ' - ' . $hub->getName() . ' = ' . $distance . ' kms away.');
}
return 0;
}
}

View file

@ -7,11 +7,14 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Service\RisingTideGateway;
class TestSMSCommand extends Command
{
protected $gateway;
protected $translator;
protected function configure()
{
@ -21,9 +24,10 @@ class TestSMSCommand extends Command
->addArgument('destination', InputArgument::REQUIRED, 'Destination number to send to');
}
public function __construct(RisingTideGateway $gateway)
public function __construct(RisingTideGateway $gateway, TranslatorInterface $translator)
{
$this->gateway = $gateway;
$this->translator = $translator;
parent::__construct();
}
@ -34,7 +38,7 @@ class TestSMSCommand extends Command
error_log('sending sms to ' . $number);
$msg = 'This is a test.';
$this->gateway->sendSMS($number, 'MOTOLITE', $msg);
$this->gateway->sendSMS($number, $this->translator->trans('message.battery_brand_allcaps'), $msg);
return 0;
}

View file

@ -7,6 +7,8 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Doctrine\ORM\EntityManagerInterface;
use App\Service\RisingTideGateway;
@ -18,6 +20,7 @@ class WarrantySMSCommand extends Command
{
protected $gateway;
protected $em;
protected $translator;
protected function configure()
{
@ -27,10 +30,11 @@ class WarrantySMSCommand extends Command
->addArgument('date', InputArgument::OPTIONAL, 'Date to use as basis of expiration. Defaults to current date.');
}
public function __construct(EntityManagerInterface $em, RisingTideGateway $gateway)
public function __construct(EntityManagerInterface $em, RisingTideGateway $gateway, TranslatorInterface $translator)
{
$this->em = $em;
$this->gateway = $gateway;
$this->translator = $translator;
parent::__construct();
}
@ -97,10 +101,10 @@ class WarrantySMSCommand extends Command
error_log(print_r($valid_numbers, true));
foreach ($valid_numbers as $wdata)
{
$msg = 'Hi ' . $wdata['name'] . ', the warranty for the ' . $wdata['batt'] . ' installed in your car(' . $wdata['plate'] . ') has expired already. Please call MOTOLITE EXPRESS HATID at 8370-6686 to have the status of your battery checked to avoid any inconvenience. Thank you for choosing Motolite.';
$msg = 'Hi ' . $wdata['name'] . ', the warranty for the ' . $wdata['batt'] . ' installed in your car(' . $wdata['plate'] . $this->translator->trans('message.partial_warrantysms');
error_log($wdata['number'] . ' - sending ' . $msg);
$this->gateway->sendSMS($wdata['number'], 'MOTOLITE', $msg);
$this->gateway->sendSMS($wdata['number'], $this->translator->trans('message.battery_brand_allcaps'), $msg);
}

View file

@ -242,14 +242,14 @@ class APIController extends Controller implements LoggedController
return sprintf("%06d", mt_rand(100000, 999999));
}
protected function sendConfirmationCode(RisingTideGateway $rt, $phone_number, $code)
protected function sendConfirmationCode(RisingTideGateway $rt, $phone_number, $code, TranslatorInterface $translator)
{
// send sms to number
$message = "Your Resq confirmation code is $code.";
$rt->sendSMS($phone_number, 'MOTOLITE', $message);
$message = $translator->trans('message.confirmation_code') . ' ' . $code;
$rt->sendSMS($phone_number, $translator->trans('message.battery_brand_allcaps'), $message);
}
public function confirmNumber(RisingTideGateway $rt, Request $req)
public function confirmNumber(RisingTideGateway $rt, Request $req, TranslatorInterface $translator)
{
// check parameters
$required_params = [
@ -306,7 +306,7 @@ class APIController extends Controller implements LoggedController
if ($otp_mode != 'test')
{
// send sms to number
$this->sendConfirmationCode($rt, $phone_number, $code);
$this->sendConfirmationCode($rt, $phone_number, $code, $translator);
}
// response
@ -2675,7 +2675,7 @@ class APIController extends Controller implements LoggedController
if (empty($nearest_hub_slots['hub']))
{
$res->setError(true)
->setErrorMessage('Thank you for reaching out to us. Due to the General Community Quarantine, our Operations are from 8AM to 6PM only. Please expect a call from us tomorrow and we will assist you with your request. Thank you and stay safe!');
->setErrorMessage('Thank you for reaching out to us. Please expect a call from us and we will assist you with your request. Thank you and stay safe!');
return $res->getReturnResponse();
}
}
@ -2687,7 +2687,7 @@ class APIController extends Controller implements LoggedController
if (empty($nearest_hub_slots['hub']))
{
$res->setError(true)
->setErrorMessage('Thank you for reaching out to us. Due to the General Community Quarantine, our Operations are from 8AM to 6PM only. Please expect a call from us tomorrow and we will assist you with your request. Thank you and stay safe!');
->setErrorMessage('Thank you for reaching out to us. Please expect a call from us and we will assist you with your request. Thank you and stay safe!');
return $res->getReturnResponse();
}
}
@ -4078,7 +4078,7 @@ class APIController extends Controller implements LoggedController
// send sms
error_log('sending sms to - ' . $this->session->getPhoneNumber());
$rt->sendSMS($this->session->getPhoneNumber(), 'MOTOLITE', $sms_msg);
$rt->sendSMS($this->session->getPhoneNumber(), $trans->trans('message.battery_brand_allcaps'), $sms_msg);
return $res;
}
@ -4306,9 +4306,11 @@ class APIController extends Controller implements LoggedController
// get the slots of hub
$hub_slots = $this->getHubRiderSlots($hub, $em);
$slots = $hub_slots['slot_data'];
$hub_data = [
'hub' => $hub,
'slots' => $hub_slots,
'slots' => $slots,
];
return $hub_data;
}
@ -4324,31 +4326,52 @@ class APIController extends Controller implements LoggedController
}
$nearest = null;
$hub_slots = [];
$slot_found = false;
// find the nearest hub
if (!empty($nearest_hubs_with_distance))
{
// get slots of nearest hub right after getting nearest hub.
// then check if hub has available slots. If not, get next nearest hub.
foreach ($nearest_hubs_with_distance as $nhd)
{
if (empty($nearest))
$nearest = $nhd;
{
// get the slots for the hub to check if hub is available for assignment
$hub_slots = $this->getHubRiderSlots($nhd['hub'], $em);
$flag_hub_available = $hub_slots['flag_hub_available'];
if ($flag_hub_available == true)
{
$nearest = $nhd;
}
}
else
{
if ($nhd['distance'] < $nearest['distance'])
$nearest = $nhd;
{
// get the slots for nearest which is nhd right now
$hub_slots = $this->getHubRiderSlots($nhd['hub'], $em);
$flag_hub_available = $hub_slots['flag_hub_available'];
// if hub is available, set hub to nearest
if ($flag_hub_available == true)
{
$nearest = $nhd;
}
}
}
}
}
// get slots of nearest hub
if ($nearest != null)
{
$hub_slots = $this->getHubRiderSlots($nearest['hub'], $em);
$hub_data = [
'hub' => $nearest['hub'],
'slots' => $hub_slots,
];
}
if ($nearest != null)
{
// set hub data to what is in nearest
$hub_data = [
'hub' => $nearest['hub'],
'slots' => $hub_slots['slot_data'],
];
}
return $hub_data;
@ -4473,18 +4496,25 @@ class APIController extends Controller implements LoggedController
$hub_slots = $this->generateHubSlots($hub_rider_slots, $slots);
error_log(print_r($hub_slots, true));
return $hub_slots;
}
protected function generateHubSlots($rider_slots, $slots)
{
$data = [];
$total_rslots = 0;
$total_unavailable_rslots = 0;
foreach ($rider_slots as $day_id => $rslot)
{
$data[$day_id] = [];
foreach ($rslot as $slot_id => $avail_slots)
{
// increment total rider slots
$total_rslots++;
$slot_data = [
'id' => $slot_id,
'label' => $slots[$slot_id],
@ -4493,14 +4523,32 @@ class APIController extends Controller implements LoggedController
// mark unavailable ones
if ($avail_slots <= 0)
{ // increment total number of unavailable slots
$total_unavailable_rslots++;
$slot_data['available'] = false;
}
// add to day data
$data[$day_id][] = $slot_data;
}
}
return $data;
// check if hub has available slots
$hub_available = true;
error_log('total rider slots ' . $total_rslots);
error_log('total unavailable slots ' . $total_unavailable_rslots);
if ($total_rslots == $total_unavailable_rslots)
{
error_log('hub has no available slots');
$hub_available = false;
}
$hs_data = [
'flag_hub_available' => $hub_available,
'slot_data' => $data,
];
return $hs_data;
}
protected function getTimeFromSlot($slot_id)

View file

@ -578,12 +578,12 @@ class CustomerWarrantyController extends APIController
// send sms confirmation
$this->sendSMSConfirmation($rt, $req->request->get('contact_num'), $sms_message);
$this->sendSMSConfirmation($rt, $req->request->get('contact_num'), $sms_message, $trans);
return new APIResponse(true, 'Warranty registered.', $data);
}
protected function sendSMSConfirmation($rt, $num, $message)
protected function sendSMSConfirmation($rt, $num, $message, $trans)
{
$clean_num = trim($num);
@ -602,6 +602,6 @@ class CustomerWarrantyController extends APIController
error_log('sending sms to - ' . $clean_num);
$rt->sendSMS($clean_num, 'MOTOLITE', $message);
$rt->sendSMS($clean_num, $trans->trans('message.battery_brand_allcaps'), $message);
}
}

View file

@ -6,6 +6,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Doctrine\ORM\Query;
use Doctrine\ORM\EntityManagerInterface;
@ -747,7 +749,7 @@ class RiderAppController extends APIController
}
public function payment(Request $req, EntityManagerInterface $em, JobOrderHandlerInterface $jo_handler,
RisingTideGateway $rt, WarrantyHandler $wh, MQTTClient $mclient)
RisingTideGateway $rt, WarrantyHandler $wh, MQTTClient $mclient, TranslatorInterface $translator)
{
$required_params = ['jo_id'];
@ -807,9 +809,8 @@ class RiderAppController extends APIController
$phone_number = $jo->getCustomer()->getPhoneMobile();
if (!empty($phone_number))
{
// TODO: put this in config file or somewhere
$message = "Your Resq job order has been completed.";
$rt->sendSMS($phone_number, 'MOTOLITE', $message);
$message = $translator->trans('message.joborder_completed');
$rt->sendSMS($phone_number, $translator->trans('message.battery_brand_allcaps'), $message);
}
$em->flush();

View file

@ -77,31 +77,48 @@ class VehicleController extends APIController
{
$this->denyAccessUnlessGranted('vehicle.list', null, 'No access.');
$conn = $em->getConnection();
// get manufacturers
$mfgs = $em->getRepository(VehicleManufacturer::class)->findBy([], ['name' => 'ASC']);
$mfg_sql = 'SELECT vmfg.id, vmfg.name FROM vehicle_manufacturer vmfg ORDER BY vmfg.name ASC';
// get manufacturer results
$mfg_stmt = $conn->prepare($mfg_sql);
$mfg_stmt->execute();
$mfg_results = $mfg_stmt->fetchAll();
// get vehicles
$vehicles = $em->getRepository(Vehicle::class)->findBy([], ['manufacturer' => 'ASC', 'make' => 'ASC']);
$vehicle_sql = 'SELECT v.id, v.manufacturer_id, v.make, v.model_year_from, v.model_year_to
FROM vehicle v ORDER BY v.manufacturer_id ASC, v.make ASC';
// get vehicle results
$vehicle_stmt = $conn->prepare($vehicle_sql);
$vehicle_stmt->execute();
$vehicle_results = $vehicle_stmt->fetchAll();
// process manufacturer results
$mfg_data = [];
foreach($mfgs as $mfg)
foreach($mfg_results as $mfg_row)
{
$mfg_data[] = [
'id' => $mfg->getID(),
'name' => $mfg->getName(),
'id' => $mfg_row['id'],
'name' => $mfg_row['name'],
];
}
// process vehicle results
$make_data = [];
foreach($vehicles as $vehicle)
foreach($vehicle_results as $vrow)
{
// format the model year from and model year to
$model_year = $vrow['model_year_from' ] . ' - ' . $vrow['model_year_to'];
$make_data[] = [
'id' => $vehicle->getID(),
'mfg_id' => $vehicle->getManufacturer()->getID(),
'make' => $vehicle->getMake(),
'model' => $vehicle->getModelYearFormatted(),
'id' => $vrow['id'],
'mfg_id' => $vrow['manufacturer_id'],
'make' => $vrow['make'],
'model' => $model_year,
];
}

View file

@ -506,13 +506,13 @@ class JobOrderController extends Controller
* @Menu(selected="jo_open")
*/
public function openHubForm(HubSelector $hub_selector, $id, JobOrderHandlerInterface $jo_handler,
GISManagerInterface $gis)
GISManagerInterface $gis, MotivConnector $motiv)
{
$this->denyAccessUnlessGranted('jo_open.list', null, 'No access.');
try
{
$params = $jo_handler->initializeHubForm($id, $hub_selector);
$params = $jo_handler->initializeHubForm($id, $hub_selector, $motiv);
}
catch (NotFoundHttpException $e)
{

View file

@ -36,7 +36,7 @@ class Vehicle
// make
/**
* @ORM\Column(type="string", length=80)
* @ORM\Column(type="string", length=110)
* @Assert\NotBlank()
*/
protected $make;

View file

@ -458,7 +458,7 @@ class HubSelector
{
// send SMS message
error_log('sending sms to - ' . $mobile_number);
$this->rt->sendSMS($mobile_number, 'MOTOLITE', $message);
$this->rt->sendSMS($mobile_number, $this->trans->trans('message.battery_brand_allcaps'), $message);
}
}
}

View file

@ -1873,7 +1873,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
}
// initialize hub form
public function initializeHubForm($id, $map_tools)
public function initializeHubForm($id, $map_tools, $motiv)
{
$em = $this->em;

View file

@ -2315,7 +2315,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
}
// initialize hub form
public function initializeHubForm($id, HubSelector $hub_selector)
public function initializeHubForm($id, HubSelector $hub_selector, $motiv)
{
$em = $this->em;
@ -2445,9 +2445,51 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
}
}
$params['hubs'][] = $hub;
// handle inventory data
$bcode = $hub['hub']->getBranchCode();
$hub['inventory'] = 0;
if ($bcode != '')
{
$branch_codes[] = $bcode;
$inv_data[$bcode] = [
'hub_id' => $hub_id,
'branch_code' => $bcode,
'inventory' => 0,
];
}
$params['hubs'][$hub_id] = $hub;
}
// get battery (if any)
$skus = [];
$invoice = $obj->getInvoice();
$inv_items = $invoice->getItems();
foreach ($inv_items as $inv_item)
{
$batt = $inv_item->getBattery();
if ($batt == null)
continue;
$skus[] = $batt->getSapCode();
}
// get inventory
$mres = $motiv->getInventory($branch_codes, $skus);
foreach ($mres as $mres_item)
{
$bcode = $mres_item['BranchCode'];
$inv_count = $mres_item['Quantity'];
if (isset($inv_data[$bcode]))
{
$hub_id = $inv_data[$bcode]['hub_id'];
$params['hubs'][$hub_id]['inventory'] = $inv_count;
}
}
error_log(print_r($mres, true));
$params['obj'] = $obj;
// get template to display
$params['template'] = $this->getTwigTemplate('jo_open_hub_form');
@ -2539,7 +2581,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// insert JO number
$pdf->SetFont($font_face, 'B', $jo_font_size);
$pdf->SetX($col2_x);
$pdf->Cell($label_width, $jo_line_height, 'JO Number:');
$pdf->Cell($label_width, $jo_line_height, $translator->trans('label.pdf.jo_number'));
$pdf->SetTextColor(9, 65, 150);
$pdf->Cell(0, $jo_line_height, $obj->getID());
@ -2554,14 +2596,14 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$y = $pdf->GetY();
$pdf->SetXY($col1_x, $y);
$pdf->Cell($label_width, $line_height, 'Customer Name:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.customer_name'));
$pdf->MultiCell($val_width, $line_height, $customer ? $customer->getFirstName() . ' ' . $customer->getLastName() : '', 0, 'L');
// get Y after left cell
$y1 = $pdf->GetY();
$pdf->SetXY($col2_x, $y);
$pdf->Cell($label_width, $line_height, 'Mobile Phone:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.mobile_phone'));
$pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneMobile() ? $this->country_code . $customer->getPhoneMobile() : '', 0, 'L');
// get Y after right cell
@ -2571,14 +2613,14 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$y = max($y1, $y2);
$pdf->SetXY($col1_x, $y);
$pdf->Cell($label_width, $line_height, 'Delivery Date:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.delivery_date'));
$pdf->MultiCell($val_width, $line_height, $obj->getDateSchedule() ? $obj->getDateSchedule()->format("m/d/Y") : '', 0, 'left');
// get Y after left cell
$y1 = $pdf->GetY();
$pdf->SetXY($col2_x, $y);
$pdf->Cell($label_width, $line_height, 'Landline:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.landline'));
$pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneLandline() ? $this->country_code . $customer->getPhoneLandline() : '', 0, 'L');
// get Y after right cell
@ -2588,11 +2630,11 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$y = max($y1, $y2);
$pdf->SetXY($col2_x, $y);
$pdf->Cell($label_width, $line_height, 'Office Phone:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.office_phone'));
$pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneOffice() ? $this->country_code . $customer->getPhoneOffice() : '', 0, 'L');
$pdf->SetX($col2_x);
$pdf->Cell($label_width, $line_height, 'Fax:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.fax'));
$pdf->MultiCell($val_width, $line_height, $customer && $customer->getPhoneFax() ? $this->country_code . $customer->getPhoneFax() : '', 0, 'L');
// insert vehicle info
@ -2600,21 +2642,21 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$vehicle = $cv->getVehicle();
$pdf->Ln();
$pdf->SetFont($font_face, 'B', $header_font_size);
$pdf->Cell($label_width, $line_height, 'Vehicle Details');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.vehicle_details'));
$pdf->Ln($line_height * 2);
// get current Y
$y = $pdf->GetY();
$pdf->SetFont($font_face, '', $body_font_size);
$pdf->Cell($label_width, $line_height, 'Plate Number:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.plate_number'));
$pdf->MultiCell($val_width, $line_height, $cv ? $cv->getPlateNumber() : '', 0, 'L');
// get Y after left cell
$y1 = $pdf->GetY();
$pdf->SetXY($col2_x, $y);
$pdf->Cell($label_width, $line_height, 'Vehicle Color:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.vehicle_color'));
$pdf->MultiCell(0, $line_height, $cv ? $cv->getColor() : '', 0, 'L');
// get Y after right cell
@ -2624,14 +2666,14 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$y = max($y1, $y2);
$pdf->SetXY($col1_x, $y);
$pdf->Cell($label_width, $line_height, 'Brand:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.brand'));
$pdf->MultiCell($val_width, $line_height, $vehicle && $vehicle->getManufacturer() ? $vehicle->getManufacturer()->getName() : '', 0, 'L');
// get Y after left cell
$y1 = $pdf->GetY();
$pdf->SetXY($col2_x, $y);
$pdf->Cell($label_width, $line_height, 'Model / Year:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.model_year'));
$pdf->MultiCell(0, $line_height, $cv ? $cv->getModelYear() : '', 0, 'L');
// get Y after right cell
@ -2641,14 +2683,14 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$y = max($y1, $y2);
$pdf->SetXY($col1_x, $y);
$pdf->Cell($label_width, $line_height, 'Make:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.make'));
$pdf->MultiCell($val_width, $line_height, $vehicle ? $vehicle->getMake() : '', 0, 'L');
// insert battery info
$battery = $cv->getCurrentBattery();
$pdf->Ln();
$pdf->SetFont($font_face, 'B', $header_font_size);
$pdf->Cell($label_width, $line_height, 'Battery Details');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.battery_details'));
$pdf->Ln($line_height * 2);
$pdf->SetFont($font_face, '', $body_font_size);
@ -2656,14 +2698,14 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// get current Y
$y = $pdf->GetY();
$pdf->Cell($label_width, $line_height, 'Current Battery:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.current_battery'));
$pdf->MultiCell($val_width, $line_height, $battery && $battery->getManufacturer() && $battery->getModel() && $battery->getSize() ? $battery->getManufacturer()->getName() . ' ' . $battery->getModel()->getName() . ' ' . $battery->getSize()->getName() . ' (' . $battery->getProductCode() . ')' : '', 0, 'L');
// get Y after left cell
$y1 = $pdf->GetY();
$pdf->SetXY($col2_x, $y);
$pdf->Cell($label_width, $line_height, 'Serial Number:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.serial_number'));
$pdf->MultiCell(0, $line_height, $cv ? $cv->getWarrantyCode() : '', 0, 'L');
// get Y after right cell
@ -2673,13 +2715,13 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$y = max($y1, $y2);
$pdf->SetXY($col1_x, $y);
$pdf->Cell($label_width, $line_height, 'Wty. Exp. Date:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.warranty_exp_date'));
$pdf->MultiCell($val_width, $line_height, $cv && $cv->getWarrantyExpiration() ? $cv->getWarrantyExpiration()->format("d/m/Y") : '', 0, 'L');
// insert transaction details
$pdf->Ln();
$pdf->SetFont($font_face, 'B', $header_font_size);
$pdf->Cell($label_width, $line_height, 'Transaction Details');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.transaction_details'));
$pdf->Ln($line_height * 2);
$pdf->SetFont($font_face, '', $body_font_size);
@ -2687,14 +2729,14 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// get current Y
$y = $pdf->GetY();
$pdf->Cell($label_width, $line_height, 'Warranty Class:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.warranty_class'));
$pdf->MultiCell($val_width, $line_height, WarrantyClass::getName($obj->getWarrantyClass()), 0, 'L');
// get Y after left cell
$y1 = $pdf->GetY();
$pdf->SetXY($col2_x, $y);
$pdf->Cell($label_width, $line_height, 'Mode of Payment:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.mode_of_payment'));
$pdf->MultiCell(0, $line_height, ModeOfPayment::getName($obj->getModeOfPayment()), 0, 'L');
// get Y after right cell
@ -2703,14 +2745,14 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// get row height
$y = max($y1, $y2);
$pdf->Cell($label_width, $line_height, 'Delivery Address:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.delivery_address'));
$pdf->MultiCell($val_width, $line_height, $obj->getDeliveryAddress(), 0, 'L');
// get Y after left cell
$y1 = $pdf->GetY();
$pdf->SetXY($col2_x, $y);
$pdf->Cell($label_width, $line_height, 'Landmark:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.landmark'));
$pdf->MultiCell(0, $line_height, $obj->getLandMark(), 0, 'L');
// get Y after right cell
@ -2720,14 +2762,14 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$y = max($y1, $y2);
$pdf->SetXY($col1_x, $y);
$pdf->Cell($label_width, $line_height, 'Dispatch Time:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.dispatch_time'));
$pdf->MultiCell($val_width, $line_height, $obj->getDateSchedule() ? $obj->getDateSchedule()->format("g:i A") : '', 0, 'L');
// get Y after left cell
$y1 = $pdf->GetY();
$pdf->SetXY($col2_x, $y);
$pdf->Cell($label_width, $line_height, 'Dispatched By:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.dispatched_by'));
$pdf->MultiCell(0, $line_height, $obj->getProcessedBy() ? $obj->getProcessedBy()->getFullName() : '', 0, 'L');
// get Y after right cell
@ -2740,7 +2782,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$pdf->SetY($y);
$pdf->Ln();
$pdf->SetFont($font_face, 'B', $header_font_size);
$pdf->Cell(0, $line_height, 'Delivery Instructions');
$pdf->Cell(0, $line_height, $translator->trans('label.pdf.delivery_instructions'));
$pdf->Ln();
$pdf->SetFont($font_face, '', $body_font_size);
@ -2749,16 +2791,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// insert invoice details
$pdf->Ln();
$pdf->SetFont($font_face, 'B', $header_font_size);
$pdf->Cell($label_width, $line_height, 'Invoice Details');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.invoice_details'));
$pdf->Ln();
// invoice table headers
$invoice = $obj->getInvoice();
$pdf->SetFont($font_face, 'B', $header_font_size);
$pdf->Cell($table_col_width * 6, $table_line_height, 'Item', 1, 0, 'L', 1);
$pdf->Cell($table_col_width * 2, $table_line_height, 'Quantity', 1, 0, 'R', 1);
$pdf->Cell($table_col_width * 2, $table_line_height, 'Unit Price', 1, 0, 'R', 1);
$pdf->Cell($table_col_width * 2, $table_line_height, 'Amount', 1, 1, 'R', 1);
$pdf->Cell($table_col_width * 6, $table_line_height, $translator->trans('label.pdf.item'), 1, 0, 'L', 1);
$pdf->Cell($table_col_width * 2, $table_line_height, $translator->trans('label.pdf.quantity'), 1, 0, 'R', 1);
$pdf->Cell($table_col_width * 2, $table_line_height, $translator->trans('label.pdf.unit_price'), 1, 0, 'R', 1);
$pdf->Cell($table_col_width * 2, $table_line_height, $translator->trans('label.pdf.amount'), 1, 1, 'R', 1);
$pdf->SetFont($font_face, '', $body_font_size);
// build invoice items table
@ -2783,7 +2825,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$y = $pdf->GetY();
// insert invoice footer details
$pdf->Cell($label_width, $line_height, 'Transaction Type:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.transaction_type'));
$pdf->MultiCell($val_width, $line_height, ServiceType::getName($obj->getServiceType()), 0, 'L');
// get Y after left cell
@ -2791,7 +2833,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$pdf->SetXY($col2_x, $y);
$pdf->SetFont($font_face, 'B');
$pdf->Cell($label_width, $line_height, 'SUBTOTAL:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.subtotal'));
$pdf->SetFont($font_face, '');
$pdf->MultiCell(0, $line_height, $invoice ? number_format($invoice->getVATExclusivePrice(), 2) : '', 0, 'R');
@ -2802,7 +2844,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$y = max($y1, $y2);
$pdf->SetXY($col1_x, $y);
$pdf->Cell($label_width, $line_height, 'OR Name:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.or_name'));
$pdf->MultiCell($val_width, $line_height, $obj->getORName(), 0, 'L');
// get Y after left cell
@ -2810,7 +2852,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$pdf->SetXY($col2_x, $y);
$pdf->SetFont($font_face, 'B');
$pdf->Cell($label_width, $line_height, 'TAX:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.tax'));
$pdf->SetFont($font_face, '');
$pdf->MultiCell(0, $line_height, $invoice ? number_format($invoice->getVAT(), 2) : '', 0, 'R');
@ -2821,7 +2863,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$y = max($y1, $y2);
$pdf->SetXY($col1_x, $y);
$pdf->Cell($label_width, $line_height, 'Emp. ID/Card No./Ref. By:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.emp_id_ref'));
$pdf->MultiCell($val_width, $line_height, $obj->getPromoDetail(), 0, 'L');
// get Y after left cell
@ -2829,7 +2871,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$pdf->SetXY($col2_x, $y);
$pdf->SetFont($font_face, 'B');
$pdf->Cell($label_width, $line_height, 'DISCOUNT:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.discount'));
$pdf->SetFont($font_face, '');
$pdf->MultiCell(0, $line_height, $invoice ? number_format($invoice->getDiscount(), 2) : '', 0, 'R');
@ -2840,12 +2882,12 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$y = max($y1, $y2);
$pdf->SetXY($col1_x, $y);
$pdf->Cell($label_width, $line_height, 'Discount Type:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.discount_type'));
$pdf->MultiCell($val_width, $line_height, $invoice && $invoice->getPromo() ? $invoice->getPromo()->getName() : '', 0, 'L');
$pdf->SetXY($col2_x, $y);
$pdf->SetFont($font_face, 'B');
$pdf->Cell($label_width, $line_height, 'FINAL AMOUNT:');
$pdf->Cell($label_width, $line_height, $translator->trans('label.pdf.final_amount'));
$pdf->MultiCell(0, $line_height, $invoice ? number_format($invoice->getTotalPrice(), 2) : '', 0, 'R');
$pdf->SetFont($font_face, '');
@ -3540,8 +3582,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
public function sendSMSToCustomer($phone_number)
{
// TODO: put this in config file or somewhere
$message = "Your Resq job order has been completed.";
$this->rt->sendSMS($phone_number, 'MOTOLITE', $message);
$message = $this->translator->trans('message.joborder_completed');
$this->rt->sendSMS($phone_number, $this->translator->trans('message.battery_brand_allcaps'), $message);
}
}

View file

@ -77,7 +77,7 @@ interface JobOrderHandlerInterface
public function initializeFulfillmentForm(int $id);
// initialize hub form
public function initializeHubForm(int $id, HubSelector $hub_selector);
public function initializeHubForm(int $id, HubSelector $hub_selector, $motiv);
// initialize rider form
public function initializeRiderForm(int $id);

View file

@ -6,6 +6,8 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Ramcar\ServiceType;
use App\Ramcar\TradeInType;
use App\Ramcar\JOStatus;
@ -57,7 +59,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
string $country_code, MQTTClient $mclient,
WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler,
InvoiceGeneratorInterface $ic, RisingTideGateway $rt,
RiderTracker $rider_tracker)
RiderTracker $rider_tracker, TranslatorInterface $translator)
{
$this->em = $em;
$this->redis = $redis;
@ -70,6 +72,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
$this->ic = $ic;
$this->rt = $rt;
$this->rider_tracker = $rider_tracker;
$this->translator = $translator;
// one device = one session, since we have control over the devices
// when a rider logs in, we just change the rider assigned to the device
@ -595,9 +598,8 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
$phone_number = $jo->getCustomer()->getPhoneMobile();
if (!empty($phone_number))
{
// TODO: put this in config file or somewhere
$message = "Your Resq job order has been completed.";
$this->rt->sendSMS($phone_number, 'MOTOLITE', $message);
$message = $this->translator->trans('message.joborder_completed');
$this->rt->sendSMS($phone_number, $this->translator->trans('message.battery_brand_allcaps'), $message);
}
$this->em->flush();

View file

@ -4,6 +4,8 @@ namespace App\Service\RiderAssignmentHandler;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Service\RiderAssignmentHandlerInterface;
use App\Service\MQTTClient;
use App\Service\APNSClient;
@ -18,13 +20,15 @@ class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface
protected $em;
protected $aclient;
protected $mclient;
protected $translator;
public function __construct(EntityManagerInterface $em, MQTTClient $mclient,
APNSClient $aclient)
APNSClient $aclient, TranslatorInterface $translator)
{
$this->em = $em;
$this->mclient = $mclient;
$this->aclient = $aclient;
$this->translator = $translator;
}
// assign job order to rider
@ -49,7 +53,7 @@ class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface
$this->mclient->sendRiderEvent($obj, $payload);
// send push notification
$this->aclient->sendPush($obj, "A RESQ rider is on his way to you.");
$this->aclient->sendPush($obj, $this->translator->trans('message.rider_otw'));
$this->em->flush();
}

View file

@ -32,6 +32,16 @@ class RisingTideGateway
public function sendSMS($mobile_num, $mask, $message)
{
// make sure number is acceptable to RT
// at this point, assume that mobile is numeric and valid mobile number
$clean_num = $this->cleanPhoneNumber($mobile_num);
if ($clean_num === false)
{
error_log('Invalid mobile number provided. Cannot send SMS message to ' . $mobile_num);
return;
}
$headers = [
'Content-Type: application/vnd.net.wyrls.Document-v3+json'
];
@ -39,7 +49,7 @@ class RisingTideGateway
$sms = new SMSMessage();
$sms->setFrom($this->shortcode)
->setFromAlias($mask)
->setTo($mobile_num)
->setTo($clean_num)
->setMessage($message)
->setStatus('sent');
@ -54,7 +64,7 @@ class RisingTideGateway
'id' => $sms->getID(),
'from' => $this->shortcode,
'from_alias' => $mask,
'to' => $mobile_num,
'to' => $clean_num,
'content_type' => 'text/plain',
'body' => $message,
'date' => $date_string,
@ -67,21 +77,21 @@ class RisingTideGateway
$userpwd = $this->user . ':' . $this->pass;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, self::SERVER_URL);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $userpwd);
$result = curl_exec($curl);
error_log('error_no - ' . curl_errno($curl));
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
error_log($http_code);
curl_close($curl);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, self::SERVER_URL);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $userpwd);
$result = curl_exec($curl);
error_log('error_no - ' . curl_errno($curl));
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
error_log($http_code);
curl_close($curl);
error_log($result);
error_log($result);
}
public function validatePhoneNumber($mobile)
@ -107,4 +117,41 @@ class RisingTideGateway
return true;
}
protected function cleanPhoneNumber($mobile)
{
// remove any non digit character from string
$clean_number = preg_replace('~\D~', '', $mobile);
error_log('cleaned ' . $clean_number);
// does it fit our 09XXXXXXXXX pattern?
if (preg_match('/^09[0-9]{9}$/', $clean_number))
{
// remove first '0'
$clean_number = substr($clean_number, 1);
// prepend 63
$clean_number = '63' . $clean_number;
error_log("CONVERTED TO $clean_number");
return $clean_number;
}
// does it fit our 63XXXXXXXXXX pattern?
else if (preg_match('/^63[0-9]{10}$/', $clean_number))
{
// leave alone
return $clean_number;
}
// does it fit our 9XXXXXXXXX pattern?
else if (preg_match('/^9[0-9]{9}$/', $clean_number))
{
// prepend 63
$clean_number = '63' . $clean_number;
error_log("CONVERT TO $clean_number");
return $clean_number;
}
return false;
}
}

View file

@ -125,8 +125,6 @@ class WarrantyHandler
// update customer vehicle with warranty info
$this->updateCustomerVehicle($serial, $batt_list, $plate_number, $date_expire);
$this->em->clear();
}
public function updateCustomerVehicle($serial, $batteries, $plate_number, $date_expire)

View file

@ -288,7 +288,7 @@
<span class="m-switch m-switch--icon block-switch">
<label>
<input type="checkbox" name="flag_motolite_battery" id="flag-motolite-battery" value="1" {{ obj.getCustomerVehicle.getCurrentBattery|default(false) ? obj.getCustomerVehicle.hasMotoliteBattery ? ' checked' }} disabled>
<label class="switch-label">This vehicle is using a Motolite battery</label>
<label class="switch-label">{% trans %}label.jo.vehicle_battery{% endtrans %}</label>
<span></span>
</label>
</span>

View file

@ -31,3 +31,51 @@ default_region: ph
# warranty text
warranty_register_confirm: Congratulations! Your warranty has been successfully registered! Read about Motolite's privacy policy at https://www.motolite.com/privacy/.
warranty_update_confirm: Congratulations! Your warranty has been successfully updated! Read about Motolite's privacy policy at https://www.motolite.com/privacy/.
# labels
label.pdf.jo_number: 'JO Number:'
label.pdf.customer_name: 'Customer Name:'
label.pdf.mobile_phone: 'Mobile Phone:'
label.pdf.delivery_date: 'Delivery Date:'
label.pdf.landline: 'Landline:'
label.pdf.office_phone: 'Office Phone:'
label.pdf.fax: 'Fax:'
label.pdf.vehicle_details: 'Vehicle Details'
label.pdf.plate_number: 'Plate Number:'
label.pdf.vehicle_color: 'Vehicle Color:'
label.pdf.brand: 'Brand:'
label.pdf.model_year: 'Model / Year:'
label.pdf.make: 'Make:'
label.pdf.battery_details: 'Battery Details'
label.pdf.current_battery: 'Current Battery:'
label.pdf.serial_number: 'Serial Number:'
label.pdf.warranty_exp_date: 'Wty. Exp. Date:'
label.pdf.transaction_details: 'Transaction Details'
label.pdf.warranty_class: 'Warranty Class:'
label.pdf.mode_of_payment: 'Mode of Payment:'
label.pdf.delivery_address: 'Delivery Address:'
label.pdf.landmark: 'Landmark:'
label.pdf.dispatch_time: 'Dispatch Time:'
label.pdf.dispatched_by: 'Dispatched By:'
label.pdf.delivery_instructions: 'Delivery Instructions'
label.pdf.invoice_details: 'Invoice Details'
label.pdf.item: 'Item'
label.pdf.quantity: 'Quantity'
label.pdf.unit_price: 'Unit Price'
label.pdf.amount: 'Amount'
label.pdf.transaction_type: 'Transaction Type:'
label.pdf.subtotal: 'SUBTOTAL:'
label.pdf.or_name: 'OR Name:'
label.pdf.tax: 'TAX:'
label.pdf.emp_id_ref: 'Emp. ID/Card No./Ref. By:'
label.pdf.discount: 'DISCOUNT:'
label.pdf.discount_type: 'Discount Type:'
label.pdf.final_amount: 'FINAL AMOUNT:'
label.jo.vehicle_battery: 'This vehicle is using a Motolite battery'
# messages
message.partial_warrantysms: ') has expired already. Please call MOTOLITE EXPRESS HATID at 8370-6686 to have the status of your battery checked to avoid any inconvenience. Thank you for choosing Motolite.'
message.battery_brand_allcaps: 'MOTOLITE'
message.confirmation_code: 'Your Resq confirmation code is'
message.joborder_completed: 'Your Resq job order has been completed.'
message.rider_otw: 'A RESQ rider is on his way to you.'

View file

@ -0,0 +1,15 @@
#!/bin/bash
# copy this script into /etc/letsencrypt/renewal-hooks/post
# to test: sudo certbot renew --dry-run
# copy the certificates into /etc/vernemq
cp -Lp /etc/letsencrypt/live/resqapi.jankstudio.com/*.pem /etc/vernemq
# change ownership and group of the certificates from root to vernemq
chown vernemq:vernemq /etc/vernemq/*.pem
sudo systemctl restart vernemq.service
sudo systemctl restart mqtt_sender.service
sudo systemctl restart riderloc.service