From 4765c34be8231e1bdc75b60bd625b23b4f00feb4 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 9 Mar 2022 03:44:16 +0000 Subject: [PATCH 01/27] Update fuel prices for gas and diesel. #647 --- src/Service/InvoiceGenerator/ResqInvoiceGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php index ee9bb91a..bc6f2d67 100644 --- a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php @@ -35,8 +35,8 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface const WARRANTY_FEE = 0; const OTHER_SERVICES_FEE = 200; const COOLANT_FEE = 1600; - const REFUEL_FEE_GAS = 300; - const REFUEL_FEE_DIESEL = 260; + const REFUEL_FEE_GAS = 320; + const REFUEL_FEE_DIESEL = 280; private $security; protected $em; From ae477ea440758e3f0f5dc6c4dc2b8748244167ea Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 15 Mar 2022 06:37:22 +0000 Subject: [PATCH 02/27] Move hardcoded labels to messages file. #649 --- .../JobOrderHandler/ResqJobOrderHandler.php | 76 +++++++++---------- translations/messages.en.yaml | 40 ++++++++++ 2 files changed, 78 insertions(+), 38 deletions(-) diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 8475484f..fcfd5201 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -2539,7 +2539,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 +2554,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 +2571,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 +2588,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 +2600,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 +2624,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 +2641,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 +2656,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 +2673,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 +2687,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 +2703,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 +2720,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 +2740,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 +2749,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 +2783,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 +2791,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 +2802,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 +2810,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 +2821,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 +2829,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 +2840,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, ''); diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index 735ef80a..75f17ce6 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -31,3 +31,43 @@ 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:' From a5a30ec7f946dc48e840e8894faadd4db3332a74 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 15 Mar 2022 07:51:58 +0000 Subject: [PATCH 03/27] Change hardcoded messages into entries in messages file. #649 --- src/Command/TestSMSCommand.php | 8 ++++++-- src/Command/WarrantySMSCommand.php | 10 +++++++--- src/Controller/APIController.php | 8 ++++---- src/Controller/CAPI/CustomerWarrantyController.php | 6 +++--- src/Controller/CAPI/RiderAppController.php | 9 +++++---- src/Service/HubSelector.php | 2 +- src/Service/JobOrderHandler/ResqJobOrderHandler.php | 4 ++-- src/Service/RiderAPIHandler/ResqRiderAPIHandler.php | 10 ++++++---- .../ResqRiderAssignmentHandler.php | 8 ++++++-- templates/job-order/form.html.twig | 2 +- translations/messages.en.yaml | 8 ++++++++ 11 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/Command/TestSMSCommand.php b/src/Command/TestSMSCommand.php index f431398f..99aaf36f 100644 --- a/src/Command/TestSMSCommand.php +++ b/src/Command/TestSMSCommand.php @@ -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; } diff --git a/src/Command/WarrantySMSCommand.php b/src/Command/WarrantySMSCommand.php index 14f4c531..77868a9b 100644 --- a/src/Command/WarrantySMSCommand.php +++ b/src/Command/WarrantySMSCommand.php @@ -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); } diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index c3a4bbf9..9fdd58a2 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -242,11 +242,11 @@ 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) @@ -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; } diff --git a/src/Controller/CAPI/CustomerWarrantyController.php b/src/Controller/CAPI/CustomerWarrantyController.php index bd75997b..0db793b5 100644 --- a/src/Controller/CAPI/CustomerWarrantyController.php +++ b/src/Controller/CAPI/CustomerWarrantyController.php @@ -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); } } diff --git a/src/Controller/CAPI/RiderAppController.php b/src/Controller/CAPI/RiderAppController.php index 0136b0b8..6b56e83e 100644 --- a/src/Controller/CAPI/RiderAppController.php +++ b/src/Controller/CAPI/RiderAppController.php @@ -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(); diff --git a/src/Service/HubSelector.php b/src/Service/HubSelector.php index 826a45d2..cf6cdd28 100644 --- a/src/Service/HubSelector.php +++ b/src/Service/HubSelector.php @@ -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); } } } diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index fcfd5201..a5ce340a 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -3540,8 +3540,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); } } diff --git a/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php b/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php index db83076b..3f10c763 100644 --- a/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php @@ -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(); diff --git a/src/Service/RiderAssignmentHandler/ResqRiderAssignmentHandler.php b/src/Service/RiderAssignmentHandler/ResqRiderAssignmentHandler.php index ddaf985e..6592734a 100644 --- a/src/Service/RiderAssignmentHandler/ResqRiderAssignmentHandler.php +++ b/src/Service/RiderAssignmentHandler/ResqRiderAssignmentHandler.php @@ -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(); } diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index e85a89f3..4fff73e0 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -288,7 +288,7 @@ diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index 75f17ce6..78f1b0d4 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -71,3 +71,11 @@ 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.' From 8c685536d33a59424133bbbdaf330bab835fd941 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 15 Mar 2022 09:01:53 +0000 Subject: [PATCH 04/27] Change query for vehicle manufacturers and vehicles to use raw sql. #650 --- src/Controller/CAPI/VehicleController.php | 37 +++++++++++++++++------ 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Controller/CAPI/VehicleController.php b/src/Controller/CAPI/VehicleController.php index 02de2d8e..1f3b13b4 100644 --- a/src/Controller/CAPI/VehicleController.php +++ b/src/Controller/CAPI/VehicleController.php @@ -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, ]; } From d8f5b7833d0b8f736fe61d24dc11ae0ca2efe290 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 23 Mar 2022 09:48:37 +0000 Subject: [PATCH 05/27] Add flag for unavailable slots. #651 --- src/Controller/APIController.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 9fdd58a2..17aac2d9 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -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; } @@ -4328,6 +4330,8 @@ class APIController extends Controller implements LoggedController // find the nearest hub if (!empty($nearest_hubs_with_distance)) { + // TODO: 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)) @@ -4479,12 +4483,17 @@ class APIController extends Controller implements LoggedController 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 +4502,27 @@ 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_unavailable = false; + if ($total_rslots == $total_unavailable_rslots) + $hub_unavailable = true; + + $hs_data = [ + 'flag_hub_available' => $hub_unavailable, + 'slot_data' => $data, + ]; + + return $hs_data; } protected function getTimeFromSlot($slot_id) From b7c5f5dafe2edd38e56d7b3a2e0b6ad35851e069 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 24 Mar 2022 05:07:26 +0000 Subject: [PATCH 06/27] Add checking for hub slots. #651 --- src/Controller/APIController.php | 40 ++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 17aac2d9..5d6b16d2 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -4330,7 +4330,7 @@ class APIController extends Controller implements LoggedController // find the nearest hub if (!empty($nearest_hubs_with_distance)) { - // TODO: get slots of nearest hub right after getting nearest hub. + // 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) { @@ -4339,20 +4339,26 @@ class APIController extends Controller implements LoggedController 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; + + // temporarily set hub_data to nearest + $hub_data = [ + 'hub' => $nhd['hub'], + 'slots' => $hub_slots['slot_data'], + ]; + } + } } } - - // get slots of nearest hub - if ($nearest != null) - { - $hub_slots = $this->getHubRiderSlots($nearest['hub'], $em); - - $hub_data = [ - 'hub' => $nearest['hub'], - 'slots' => $hub_slots, - ]; - } } return $hub_data; @@ -4477,6 +4483,8 @@ class APIController extends Controller implements LoggedController $hub_slots = $this->generateHubSlots($hub_rider_slots, $slots); + error_log(print_r($hub_slots, true)); + return $hub_slots; } @@ -4513,9 +4521,11 @@ class APIController extends Controller implements LoggedController } // check if hub has available slots - $hub_unavailable = false; + $hub_available = true; + error_log('total rider slots ' . $total_rslots); + error_log('total unavailable slots ' . $total_unavailable_slots); if ($total_rslots == $total_unavailable_rslots) - $hub_unavailable = true; + $hub_available = false; $hs_data = [ 'flag_hub_available' => $hub_unavailable, From 457bbece2bdb1c04adcfb05944799b9fb458a7eb Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 24 Mar 2022 05:28:15 +0000 Subject: [PATCH 07/27] Fix issues found while testing. #651 --- src/Controller/APIController.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 5d6b16d2..3e4d2906 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -4326,6 +4326,7 @@ class APIController extends Controller implements LoggedController } $nearest = null; + $hub_slots = []; $slot_found = false; // find the nearest hub if (!empty($nearest_hubs_with_distance)) @@ -4349,18 +4350,18 @@ class APIController extends Controller implements LoggedController if ($flag_hub_available == true) { $nearest = $nhd; - - // temporarily set hub_data to nearest - $hub_data = [ - 'hub' => $nhd['hub'], - 'slots' => $hub_slots['slot_data'], - ]; } } } } } + // set hub data to what is in nearest + $hub_data = [ + 'hub' => $nearest['hub'], + 'slots' => $hub_slots['slot_data'], + ]; + return $hub_data; } @@ -4525,7 +4526,10 @@ class APIController extends Controller implements LoggedController error_log('total rider slots ' . $total_rslots); error_log('total unavailable slots ' . $total_unavailable_slots); if ($total_rslots == $total_unavailable_rslots) + { + error_log('hub has no available slots'); $hub_available = false; + } $hs_data = [ 'flag_hub_available' => $hub_unavailable, From e80ce9db664e6884525f505f0568fc57b7458d84 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 24 Mar 2022 05:38:18 +0000 Subject: [PATCH 08/27] Fix issues found while testing. #651 --- src/Controller/APIController.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 3e4d2906..49cde869 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -4336,7 +4336,16 @@ class APIController extends Controller implements LoggedController 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']) From 73f0e69b9ab4c815f66bbcb4749d9d672ba999fe Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 24 Mar 2022 05:50:02 +0000 Subject: [PATCH 09/27] Fix issues found while testing. #651 --- src/Controller/APIController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 49cde869..d10d8269 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -4533,7 +4533,7 @@ class APIController extends Controller implements LoggedController // check if hub has available slots $hub_available = true; error_log('total rider slots ' . $total_rslots); - error_log('total unavailable slots ' . $total_unavailable_slots); + error_log('total unavailable slots ' . $total_unavailable_rslots); if ($total_rslots == $total_unavailable_rslots) { error_log('hub has no available slots'); @@ -4541,7 +4541,7 @@ class APIController extends Controller implements LoggedController } $hs_data = [ - 'flag_hub_available' => $hub_unavailable, + 'flag_hub_available' => $hub_available, 'slot_data' => $data, ]; From 85be728bf639f6974ad144e3708bad9e2b4e2245 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 24 Mar 2022 07:32:06 +0000 Subject: [PATCH 10/27] Create command to test getClosestOpenHubs. #652 --- src/Command/TestClosestOpenHubsCommand.php | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/Command/TestClosestOpenHubsCommand.php diff --git a/src/Command/TestClosestOpenHubsCommand.php b/src/Command/TestClosestOpenHubsCommand.php new file mode 100644 index 00000000..f82a1400 --- /dev/null +++ b/src/Command/TestClosestOpenHubsCommand.php @@ -0,0 +1,45 @@ +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); + $this->maptools->getClosestOpenHubs(); + + return 0; + } + +} From c8629692e9a2595312203dcbf783a2aad60757ae Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 24 Mar 2022 07:44:03 +0000 Subject: [PATCH 11/27] Change message when no hubs are found. Add checking for null if no hubs are found. #653 --- src/Controller/APIController.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index d10d8269..4c23cb17 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -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(); } } @@ -4365,11 +4365,14 @@ class APIController extends Controller implements LoggedController } } - // set hub data to what is in nearest - $hub_data = [ - 'hub' => $nearest['hub'], - 'slots' => $hub_slots['slot_data'], - ]; + if ($nearest != null) + { + // set hub data to what is in nearest + $hub_data = [ + 'hub' => $nearest['hub'], + 'slots' => $hub_slots['slot_data'], + ]; + } return $hub_data; From 3e238347be75a48015699fcb7d9f6da1bdce9be0 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 24 Mar 2022 08:19:44 +0000 Subject: [PATCH 12/27] Add hub output with distance. #652 --- src/Command/TestClosestOpenHubsCommand.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Command/TestClosestOpenHubsCommand.php b/src/Command/TestClosestOpenHubsCommand.php index f82a1400..f2cd25a2 100644 --- a/src/Command/TestClosestOpenHubsCommand.php +++ b/src/Command/TestClosestOpenHubsCommand.php @@ -13,7 +13,7 @@ use App\Service\MapTools; class TestClosestOpenHubsCommand extends Command { - $protected $maptools; + protected $maptools; protected function configure() { @@ -37,7 +37,16 @@ class TestClosestOpenHubsCommand extends Command $lat = $input->getArgument('lat'); $point = new Point($long, $lat); - $this->maptools->getClosestOpenHubs(); + + $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; } From 3315565000a29138eb3decd7ce5b9bbb39198051 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 30 Mar 2022 10:56:09 +0000 Subject: [PATCH 13/27] Create command to fulfill assigned job orders. #654 --- .../FulfillAssignedJobOrderCommand.php | 205 ++++++++++++++++++ src/Service/WarrantyHandler.php | 2 +- 2 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 src/Command/FulfillAssignedJobOrderCommand.php diff --git a/src/Command/FulfillAssignedJobOrderCommand.php b/src/Command/FulfillAssignedJobOrderCommand.php new file mode 100644 index 00000000..ae17f5ac --- /dev/null +++ b/src/Command/FulfillAssignedJobOrderCommand.php @@ -0,0 +1,205 @@ +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 after a set time has passed with no update and should not send a SMS message'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + // retrieve job orders that have status assigned and has not been updated after a certain amount of time has passed. + // starting time to count is date schedule + $time_now = new DateTime(); + $date_end = new DateTime(); + // TODO: for now set to 2 hours + $date_end->add(new DateInterval('PT2H')); + + $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) + { + $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()); + } + } +} diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index 7ba9c6f8..753b425c 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -126,7 +126,7 @@ class WarrantyHandler // update customer vehicle with warranty info $this->updateCustomerVehicle($serial, $batt_list, $plate_number, $date_expire); - $this->em->clear(); + // $this->em->clear(); } public function updateCustomerVehicle($serial, $batteries, $plate_number, $date_expire) From 618769ab5d93d34f85f4f375b0b08f49ed9e6ab8 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 31 Mar 2022 02:10:10 +0000 Subject: [PATCH 14/27] Remove clearing of entitymanager. #654 --- src/Service/WarrantyHandler.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index 753b425c..a465de6e 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -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) From 4e1613540d5d255a071a0add841cc56670c48902 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 31 Mar 2022 06:45:40 +0000 Subject: [PATCH 15/27] Add date argument to command. #654 --- src/Command/FulfillAssignedJobOrderCommand.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Command/FulfillAssignedJobOrderCommand.php b/src/Command/FulfillAssignedJobOrderCommand.php index ae17f5ac..a26067e2 100644 --- a/src/Command/FulfillAssignedJobOrderCommand.php +++ b/src/Command/FulfillAssignedJobOrderCommand.php @@ -43,17 +43,18 @@ class FulfillAssignedJobOrderCommand extends Command { $this->setName('joborder:fulfillassignednosms') ->setDescription('Fulfill assigned job orders without sending an SMS message.') - ->setHelp('Mark assigned job orders as fulfilled after a set time has passed with no update and should not send a 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) { - // retrieve job orders that have status assigned and has not been updated after a certain amount of time has passed. + // 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 - $time_now = new DateTime(); - $date_end = new DateTime(); - // TODO: for now set to 2 hours - $date_end->add(new DateInterval('PT2H')); + $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'); @@ -71,6 +72,8 @@ class FulfillAssignedJobOrderCommand extends Command foreach ($jo_results as $jo) { + error_log('Fulfilling job order ' . $jo->getID()); + $jo->fulfill(); // set delivery status From 6cc9cddf1f9682e6212bbf0938bbe823eb73e3af Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 6 Apr 2022 11:01:27 +0000 Subject: [PATCH 16/27] Add command to import vehicle battery compatibility for Yokohama. #655 --- ...hamaVehicleBatteryCompatibilityCommand.php | 425 ++++++++++++++++++ 1 file changed, 425 insertions(+) create mode 100644 src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php diff --git a/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php b/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php new file mode 100644 index 00000000..ba45414d --- /dev/null +++ b/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php @@ -0,0 +1,425 @@ +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->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 . "..."); + + // 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++; + } + // print_r($b_models); + // print_r($batteries); + // save to db + + 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 + 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 + $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); + + error_log(count($output_info)); + + 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]; + + // 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 = []; + // 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; + } + + if (!isset($this->v_index[$brand][$make . '|' . intval($m_year_from) . '|' . intval($m_year_to)])) + { + $message = 'Invalid vehicle'; + $output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message); + return $output_info; + } + + // 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]); + $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, + $alt_prem_mf, + $alt_prem_lm, + $alt_super_prem_mf, + $alt_supreme_mf, + $alt_platinum_mf, + $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) + { + fputcsv($fh, $row); + } + + fclose($fh); + } + + protected function populateVehicleIndex() + { + $vs = $this->em->getRepository(Vehicle::class)->findAll(); + + $this->v_index = []; + $this->vmfg_index = []; + foreach ($vs as $v) + { + $mfg_name = $this->normalizeName($v->getManufacturer()->getName()); + $this->vmfg_index[$mfg_name] = $v->getManufacturer(); + if (!isset($this->v_index[$mfg_name])) + $this->v_index[$mfg_name] = []; + + error_log('vehicle keys ' . $mfg_name . ' ' . $this->normalizeName($v->getMake()) . '|' . $v->getModelYearFrom() . '|' . $v->getModelYearTo()); + + $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(); + + error_log($bsize); + + // check if size has / + $bsizes = []; + $pos = stripos($bsize, '/'); + if ($pos == false) + { + // no '/' in size + $bsizes[] = $this->normalizeName($bsize); + } + else + { + // if yes, we need to split it. + $sizes = explode('/', $bsize); + foreach ($sizes as $size) + { + $bsizes[] = $this->normalizeName($size); + } + } + + foreach ($bsizes as $battery_size) + { + error_log('Adding ' . $battery_size . ' to key'); + $key = $this->getBatteryKey($battery_size, $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; + } + +} From 928257ccdcbf47fe55a12bb0c4f4ca83ce8b30fd Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 7 Apr 2022 09:58:17 +0000 Subject: [PATCH 17/27] Add motiv call to initializeOpenHubForm. #656 --- src/Controller/JobOrderController.php | 4 +- .../JobOrderHandler/CMBJobOrderHandler.php | 2 +- .../JobOrderHandler/ResqJobOrderHandler.php | 46 ++++++++++++++++++- src/Service/JobOrderHandlerInterface.php | 2 +- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index fbab3cb2..f847a842 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -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) { diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 1dc1e735..24933e8f 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -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; diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index a5ce340a..40be027a 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -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'); diff --git a/src/Service/JobOrderHandlerInterface.php b/src/Service/JobOrderHandlerInterface.php index cff06242..644db54a 100644 --- a/src/Service/JobOrderHandlerInterface.php +++ b/src/Service/JobOrderHandlerInterface.php @@ -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); From bc1c6110e82e140728e109ba9cf4047a15ec5e94 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 8 Apr 2022 09:06:55 +0000 Subject: [PATCH 18/27] Fix issues found during testing. #655 --- ...hamaVehicleBatteryCompatibilityCommand.php | 67 +++++++------------ 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php b/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php index ba45414d..50296cad 100644 --- a/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php +++ b/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php @@ -26,11 +26,11 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command 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; + //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; @@ -92,7 +92,9 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command { $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]); @@ -101,6 +103,7 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $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, @@ -108,10 +111,8 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $row_num++; } - // print_r($b_models); - // print_r($batteries); - // save to db + // save to db the valid ones foreach ($vbrands as $brand_name => $vbrand) { // vehicles @@ -140,6 +141,8 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $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'])) @@ -150,12 +153,14 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $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); @@ -177,8 +182,6 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command // go into the vbrands array $output_info = $this->validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel); - error_log(count($output_info)); - if (!empty($output_info)) return $output_info; @@ -202,8 +205,10 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $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 @@ -249,6 +254,7 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $vbrands[$brand]['vehicles'][$row_num]['alt_battery_platinum_mf'] = $this->batt_index[$alt_batt_key]; } } + */ } protected function validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel) @@ -297,11 +303,14 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $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, @@ -309,11 +318,6 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $model_year, $bsize, $bmodel, - $alt_prem_mf, - $alt_prem_lm, - $alt_super_prem_mf, - $alt_supreme_mf, - $alt_platinum_mf, $status, $reason ]; @@ -343,7 +347,8 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command foreach($entries as $row) { - fputcsv($fh, $row); + if ($row != null) + fputcsv($fh, $row); } fclose($fh); @@ -362,8 +367,6 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command if (!isset($this->v_index[$mfg_name])) $this->v_index[$mfg_name] = []; - error_log('vehicle keys ' . $mfg_name . ' ' . $this->normalizeName($v->getMake()) . '|' . $v->getModelYearFrom() . '|' . $v->getModelYearTo()); - $this->v_index[$mfg_name][$this->normalizeName($v->getMake()) . '|' . $v->getModelYearFrom() . '|' . $v->getModelYearTo()] = $v; } } @@ -378,33 +381,9 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command // get the battery size $bsize = $b->getSize()->getName(); - error_log($bsize); + $key = $this->getBatteryKey($bsize, $b->getModel()->getName()); - // check if size has / - $bsizes = []; - $pos = stripos($bsize, '/'); - if ($pos == false) - { - // no '/' in size - $bsizes[] = $this->normalizeName($bsize); - } - else - { - // if yes, we need to split it. - $sizes = explode('/', $bsize); - foreach ($sizes as $size) - { - $bsizes[] = $this->normalizeName($size); - } - } - - foreach ($bsizes as $battery_size) - { - error_log('Adding ' . $battery_size . ' to key'); - $key = $this->getBatteryKey($battery_size, $b->getModel()->getName()); - - $this->batt_index[$key] = $b; - } + $this->batt_index[$key] = $b; } } From 688b890fd74bdf4f1ab472213881f65e02f4e68b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 11 Apr 2022 03:04:43 +0000 Subject: [PATCH 19/27] Modify script to create vehicle if vehicle does not exist. Modify length of make in Vehicle. #655 --- ...hamaVehicleBatteryCompatibilityCommand.php | 69 +++++++++++++++++-- src/Entity/Vehicle.php | 2 +- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php b/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php index 50296cad..1599eef3 100644 --- a/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php +++ b/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php @@ -62,6 +62,7 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $csv_file = $input->getArgument('input_file'); $output_file = $input->getArgument('output_file'); + $this->populateVehicleManufacturerIndex(); $this->populateVehicleIndex(); $this->populateBatteryIndex(); @@ -260,6 +261,23 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command 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') { @@ -277,12 +295,42 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $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)])) { - $message = 'Invalid vehicle'; - $output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message); - return $output_info; + // 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); @@ -354,16 +402,27 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command 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 = []; - $this->vmfg_index = []; foreach ($vs as $v) { $mfg_name = $this->normalizeName($v->getManufacturer()->getName()); - $this->vmfg_index[$mfg_name] = $v->getManufacturer(); if (!isset($this->v_index[$mfg_name])) $this->v_index[$mfg_name] = []; diff --git a/src/Entity/Vehicle.php b/src/Entity/Vehicle.php index a93bed4e..61fdcec9 100644 --- a/src/Entity/Vehicle.php +++ b/src/Entity/Vehicle.php @@ -36,7 +36,7 @@ class Vehicle // make /** - * @ORM\Column(type="string", length=80) + * @ORM\Column(type="string", length=110) * @Assert\NotBlank() */ protected $make; From 466d6c124f6fbac876093f06bb4b31cc6a8d1545 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 12 Apr 2022 09:30:00 +0000 Subject: [PATCH 20/27] Prepend country code to mobile numbers for SMS messaging. #658 --- src/Service/RisingTideGateway.php | 36 +++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Service/RisingTideGateway.php b/src/Service/RisingTideGateway.php index acd7d4d5..bcbc1073 100644 --- a/src/Service/RisingTideGateway.php +++ b/src/Service/RisingTideGateway.php @@ -32,6 +32,10 @@ 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); + $headers = [ 'Content-Type: application/vnd.net.wyrls.Document-v3+json' ]; @@ -39,7 +43,7 @@ class RisingTideGateway $sms = new SMSMessage(); $sms->setFrom($this->shortcode) ->setFromAlias($mask) - ->setTo($mobile_num) + ->setTo($clean_num) ->setMessage($message) ->setStatus('sent'); @@ -54,7 +58,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, @@ -107,4 +111,32 @@ class RisingTideGateway return true; } + + protected function cleanPhoneNumber($mobile) + { + $num = trim($mobile); + + // at this point, assume that mobile is numeric and valid mobile number + + // check if number begins with 63 and length is 12 for the format 639XXXXXXXXX + if ((strlen($num) == 12) && (substr($num, 0, 2) == '63')) + return $num; + + if ($num[0] == '0') + { + // remove the 0, prepend 63 + $stripped_num = substr($num, 1); + $clean_num = '63' . $stripped_num; + return $clean_num; + } + + if ($num[0] == '9') + { + // prepend 63 + $clean_num = '63' . $num; + return $clean_num; + } + + return $num; + } } From a6add363bd64fccc336a7b14ad9d784b743bf43f Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 12 Apr 2022 09:53:01 +0000 Subject: [PATCH 21/27] Refine the cleaning of mobile number. #658 --- src/Service/RisingTideGateway.php | 134 +++++++++++++++++------------- 1 file changed, 74 insertions(+), 60 deletions(-) diff --git a/src/Service/RisingTideGateway.php b/src/Service/RisingTideGateway.php index bcbc1073..2a01799c 100644 --- a/src/Service/RisingTideGateway.php +++ b/src/Service/RisingTideGateway.php @@ -36,56 +36,61 @@ class RisingTideGateway // at this point, assume that mobile is numeric and valid mobile number $clean_num = $this->cleanPhoneNumber($mobile_num); - $headers = [ - 'Content-Type: application/vnd.net.wyrls.Document-v3+json' - ]; + if ($clean_num != '') + { + $headers = [ + 'Content-Type: application/vnd.net.wyrls.Document-v3+json' + ]; - $sms = new SMSMessage(); - $sms->setFrom($this->shortcode) - ->setFromAlias($mask) - ->setTo($clean_num) - ->setMessage($message) - ->setStatus('sent'); + $sms = new SMSMessage(); + $sms->setFrom($this->shortcode) + ->setFromAlias($mask) + ->setTo($clean_num) + ->setMessage($message) + ->setStatus('sent'); - $this->em->persist($sms); - $this->em->flush(); + $this->em->persist($sms); + $this->em->flush(); - $date = $sms->getDateCreate(); - // $date = new DateTime(); - $date_string = $date->format('Y-m-d') . 'T' . $date->format('H:m:s'); + $date = $sms->getDateCreate(); + // $date = new DateTime(); + $date_string = $date->format('Y-m-d') . 'T' . $date->format('H:m:s'); - $data = [ - 'id' => $sms->getID(), - 'from' => $this->shortcode, - 'from_alias' => $mask, - 'to' => $clean_num, - 'content_type' => 'text/plain', - 'body' => $message, - 'date' => $date_string, - 'usagetype' => $this->usage_type, - 'delivery_receipt_url' => $this->dr_url, - ]; - error_log(print_r($data, true)); + $data = [ + 'id' => $sms->getID(), + 'from' => $this->shortcode, + 'from_alias' => $mask, + 'to' => $clean_num, + 'content_type' => 'text/plain', + 'body' => $message, + 'date' => $date_string, + 'usagetype' => $this->usage_type, + 'delivery_receipt_url' => $this->dr_url, + ]; + error_log(print_r($data, true)); - $data_json = json_encode($data); + $data_json = json_encode($data); - $userpwd = $this->user . ':' . $this->pass; + $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); + } + else + error_log('Invalid mobile number provided. Cannot send SMS message.'); } public function validatePhoneNumber($mobile) @@ -114,29 +119,38 @@ class RisingTideGateway protected function cleanPhoneNumber($mobile) { - $num = trim($mobile); + // remove any non digit character from string + $clean_number = preg_replace('~\D~', '', $mobile); + error_log('cleaned ' . $clean_number); - // at this point, assume that mobile is numeric and valid mobile number - - // check if number begins with 63 and length is 12 for the format 639XXXXXXXXX - if ((strlen($num) == 12) && (substr($num, 0, 2) == '63')) - return $num; - - if ($num[0] == '0') + // does it fit our 09XXXXXXXXX pattern? + if (preg_match('/^09[0-9]{9}$/', $clean_number)) { - // remove the 0, prepend 63 - $stripped_num = substr($num, 1); - $clean_num = '63' . $stripped_num; - return $clean_num; - } + // remove first '0' + $clean_number = substr($clean_number, 1); + + // prepend 63 + $clean_number = '63' . $clean_number; - if ($num[0] == '9') + 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_num = '63' . $num; - return $clean_num; + $clean_number = '63' . $clean_number; + + error_log("CONVERT TO $clean_number"); + return $clean_number; } - - return $num; + + return ""; } } From 6fff162c0e68f3a23d56b96fef531caa97bc04f0 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 12 Apr 2022 09:59:35 +0000 Subject: [PATCH 22/27] Improve error message and return value. #658 --- src/Service/RisingTideGateway.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Service/RisingTideGateway.php b/src/Service/RisingTideGateway.php index 2a01799c..0a4ba1aa 100644 --- a/src/Service/RisingTideGateway.php +++ b/src/Service/RisingTideGateway.php @@ -36,7 +36,9 @@ class RisingTideGateway // at this point, assume that mobile is numeric and valid mobile number $clean_num = $this->cleanPhoneNumber($mobile_num); - if ($clean_num != '') + if ($clean_num == false) + error_log('Invalid mobile number provided. Cannot send SMS message to ' . $mobile_num); + else { $headers = [ 'Content-Type: application/vnd.net.wyrls.Document-v3+json' @@ -89,8 +91,6 @@ class RisingTideGateway error_log($result); } - else - error_log('Invalid mobile number provided. Cannot send SMS message.'); } public function validatePhoneNumber($mobile) @@ -151,6 +151,6 @@ class RisingTideGateway return $clean_number; } - return ""; + return false; } } From b712b35a971639f86c339d1cc433e5357c89289e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 12 Apr 2022 10:01:14 +0000 Subject: [PATCH 23/27] Fix checking for return. #658 --- src/Service/RisingTideGateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/RisingTideGateway.php b/src/Service/RisingTideGateway.php index 0a4ba1aa..5928e72e 100644 --- a/src/Service/RisingTideGateway.php +++ b/src/Service/RisingTideGateway.php @@ -36,7 +36,7 @@ class RisingTideGateway // at this point, assume that mobile is numeric and valid mobile number $clean_num = $this->cleanPhoneNumber($mobile_num); - if ($clean_num == false) + if ($clean_num === false) error_log('Invalid mobile number provided. Cannot send SMS message to ' . $mobile_num); else { From 9bc1f44ca2323788e40b6b74870d2b60b0a6454b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 12 Apr 2022 10:08:13 +0000 Subject: [PATCH 24/27] Clean up code. #658 --- src/Service/RisingTideGateway.php | 105 +++++++++++++++--------------- 1 file changed, 53 insertions(+), 52 deletions(-) diff --git a/src/Service/RisingTideGateway.php b/src/Service/RisingTideGateway.php index 5928e72e..0681edd4 100644 --- a/src/Service/RisingTideGateway.php +++ b/src/Service/RisingTideGateway.php @@ -37,60 +37,61 @@ class RisingTideGateway $clean_num = $this->cleanPhoneNumber($mobile_num); if ($clean_num === false) - error_log('Invalid mobile number provided. Cannot send SMS message to ' . $mobile_num); - else { - $headers = [ - 'Content-Type: application/vnd.net.wyrls.Document-v3+json' - ]; - - $sms = new SMSMessage(); - $sms->setFrom($this->shortcode) - ->setFromAlias($mask) - ->setTo($clean_num) - ->setMessage($message) - ->setStatus('sent'); - - $this->em->persist($sms); - $this->em->flush(); - - $date = $sms->getDateCreate(); - // $date = new DateTime(); - $date_string = $date->format('Y-m-d') . 'T' . $date->format('H:m:s'); - - $data = [ - 'id' => $sms->getID(), - 'from' => $this->shortcode, - 'from_alias' => $mask, - 'to' => $clean_num, - 'content_type' => 'text/plain', - 'body' => $message, - 'date' => $date_string, - 'usagetype' => $this->usage_type, - 'delivery_receipt_url' => $this->dr_url, - ]; - error_log(print_r($data, true)); - - $data_json = json_encode($data); - - $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); - - error_log($result); + error_log('Invalid mobile number provided. Cannot send SMS message to ' . $mobile_num); + return; } + + $headers = [ + 'Content-Type: application/vnd.net.wyrls.Document-v3+json' + ]; + + $sms = new SMSMessage(); + $sms->setFrom($this->shortcode) + ->setFromAlias($mask) + ->setTo($clean_num) + ->setMessage($message) + ->setStatus('sent'); + + $this->em->persist($sms); + $this->em->flush(); + + $date = $sms->getDateCreate(); + // $date = new DateTime(); + $date_string = $date->format('Y-m-d') . 'T' . $date->format('H:m:s'); + + $data = [ + 'id' => $sms->getID(), + 'from' => $this->shortcode, + 'from_alias' => $mask, + 'to' => $clean_num, + 'content_type' => 'text/plain', + 'body' => $message, + 'date' => $date_string, + 'usagetype' => $this->usage_type, + 'delivery_receipt_url' => $this->dr_url, + ]; + error_log(print_r($data, true)); + + $data_json = json_encode($data); + + $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); + + error_log($result); } public function validatePhoneNumber($mobile) From dad3caecf34c1cf6feb135a12521208642f1430e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 12 Apr 2022 11:00:43 +0000 Subject: [PATCH 25/27] Fix bugs found when testing with app. #658 --- src/Controller/APIController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 4c23cb17..73643bbf 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -249,7 +249,7 @@ class APIController extends Controller implements LoggedController $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 From cea8df1a2c81b988ecbb123f53fca27296e6ba3e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 22 Apr 2022 08:26:13 +0000 Subject: [PATCH 26/27] Add script to copy the new certificates to vernemq folder and restart the needed services --- utils/post_cert_renewal/post_cert_renewal.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 utils/post_cert_renewal/post_cert_renewal.sh diff --git a/utils/post_cert_renewal/post_cert_renewal.sh b/utils/post_cert_renewal/post_cert_renewal.sh new file mode 100755 index 00000000..39d75ce1 --- /dev/null +++ b/utils/post_cert_renewal/post_cert_renewal.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# 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 + From 4d07f350bb8dde87d5e5b74edd167d62a8b0c444 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 22 Apr 2022 09:24:39 +0000 Subject: [PATCH 27/27] Add comments on how to install the script. #695 --- utils/post_cert_renewal/post_cert_renewal.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils/post_cert_renewal/post_cert_renewal.sh b/utils/post_cert_renewal/post_cert_renewal.sh index 39d75ce1..2ee902c0 100755 --- a/utils/post_cert_renewal/post_cert_renewal.sh +++ b/utils/post_cert_renewal/post_cert_renewal.sh @@ -1,4 +1,8 @@ #!/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