Merge branch '773-add-a-dropdown-box-in-customer-information-to-indicate-if-customer-is-new-old' into '746-resq-2-0-final'
Resolve "Add a dropdown box in Customer Information to indicate if customer is new/old" See merge request jankstudio/resq!883
This commit is contained in:
commit
fba077d4d3
8 changed files with 210 additions and 14 deletions
80
src/Command/SetJobOrderCustNewCommand.php
Normal file
80
src/Command/SetJobOrderCustNewCommand.php
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Service\JobOrderManager;
|
||||
|
||||
class SetJobOrderCustNewCommand extends Command
|
||||
{
|
||||
protected $em;
|
||||
protected $jo_manager;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, JobOrderManager $jo_manager)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->jo_manager = $jo_manager;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('joborder:setcustomernew')
|
||||
->setDescription('Set job order\'s customer new flag for existing job orders.')
|
||||
->setHelp('Set job order\'s customer new flag for existing job orders');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$em = $this->em;
|
||||
|
||||
// pdo connection
|
||||
$db = $em->getConnection();
|
||||
|
||||
// get all the ids for all job orders
|
||||
$all_query_sql = 'SELECT id AS jo_id, customer_id AS cust_id FROM job_order ORDER BY id';
|
||||
|
||||
$all_query_stmt = $db->prepare($all_query_sql);
|
||||
$all_query_stmt->execute();
|
||||
|
||||
$all_jo_results = $all_query_stmt->fetchAll();
|
||||
|
||||
$output->writeln('Processing job orders...');
|
||||
|
||||
foreach ($all_jo_results as $jo_row)
|
||||
{
|
||||
// for each jo id, get the customer id
|
||||
$jo_id = $jo_row['jo_id'];
|
||||
$cust_id = $jo_row['cust_id'];
|
||||
|
||||
// check how many JOs have that customer id
|
||||
$jo_count = $this->jo_manager->getCustomerJobOrderCount($cust_id);
|
||||
|
||||
// if one or less, set flag_cust_new to true
|
||||
if ($jo_count <= 1)
|
||||
$this->updateCustNew($db, $jo_id);
|
||||
}
|
||||
|
||||
$output->writeln('All done!');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function updateCustNew($db, $jo_id)
|
||||
{
|
||||
$update_jo_sql = 'UPDATE job_order SET flag_cust_new = :flag_cust_new WHERE id = :jo_id';
|
||||
|
||||
$update_jo_stmt = $db->prepare($update_jo_sql);
|
||||
$update_jo_stmt->execute([
|
||||
'flag_cust_new' => true,
|
||||
'jo_id' => $jo_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -49,6 +49,7 @@ use App\Service\HubDistributor;
|
|||
use App\Service\HubFilterLogger;
|
||||
use App\Service\HubFilteringGeoChecker;
|
||||
use App\Service\HashGenerator;
|
||||
use App\Service\JobOrderManager;
|
||||
|
||||
use App\Entity\MobileSession;
|
||||
use App\Entity\Customer;
|
||||
|
|
@ -867,7 +868,7 @@ class APIController extends Controller implements LoggedController
|
|||
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
||||
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger,
|
||||
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger,
|
||||
HubFilteringGeoChecker $hub_geofence)
|
||||
HubFilteringGeoChecker $hub_geofence, JobOrderManager $jo_manager)
|
||||
{
|
||||
// check required parameters and api key
|
||||
$required_params = [
|
||||
|
|
@ -928,7 +929,15 @@ class APIController extends Controller implements LoggedController
|
|||
->setErrorMessage('No customer information found');
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
// check if customer has more than one job order already
|
||||
$flag_cust_new = false;
|
||||
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust->getID());
|
||||
if ($cust_jo_count <= 1)
|
||||
$flag_cust_new = true;
|
||||
|
||||
$jo->setCustomer($cust);
|
||||
$jo->setCustNew($flag_cust_new);
|
||||
|
||||
// validate service type
|
||||
$stype = $req->request->get('service_type');
|
||||
|
|
@ -2732,7 +2741,7 @@ class APIController extends Controller implements LoggedController
|
|||
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
||||
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger,
|
||||
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger,
|
||||
HubFilteringGeoChecker $hub_geofence)
|
||||
HubFilteringGeoChecker $hub_geofence, JobOrderManager $jo_manager)
|
||||
{
|
||||
// check required parameters and api key
|
||||
$required_params = [
|
||||
|
|
@ -2857,7 +2866,15 @@ class APIController extends Controller implements LoggedController
|
|||
// ->setErrorMessage('No customer information found');
|
||||
// return $res->getReturnResponse();
|
||||
// }
|
||||
|
||||
// check if customer has more than one job order already
|
||||
$flag_cust_new = false;
|
||||
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust->getID());
|
||||
if ($cust_jo_count <= 1)
|
||||
$flag_cust_new = true;
|
||||
|
||||
$jo->setCustomer($cust);
|
||||
$jo->setCustNew($flag_cust_new);
|
||||
|
||||
// validate service type
|
||||
$stype = $req->request->get('service_type');
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use App\Service\HubSelector;
|
|||
use App\Service\HubDistributor;
|
||||
use App\Service\HubFilterLogger;
|
||||
use App\Service\HubFilteringGeoChecker;
|
||||
use App\Service\JobOrderManager;
|
||||
use App\Ramcar\ServiceType;
|
||||
use App\Ramcar\APIRiderStatus;
|
||||
use App\Ramcar\InvoiceCriteria;
|
||||
|
|
@ -482,7 +483,8 @@ class JobOrderController extends ApiController
|
|||
HubSelector $hub_select,
|
||||
HubDistributor $hub_dist,
|
||||
HubFilterLogger $hub_filter_logger,
|
||||
HubFilteringGeoChecker $hub_geofence
|
||||
HubFilteringGeoChecker $hub_geofence,
|
||||
JobOrderManager $jo_manager
|
||||
) {
|
||||
// validate params
|
||||
$validity = $this->validateRequest($req, [
|
||||
|
|
@ -594,7 +596,16 @@ class JobOrderController extends ApiController
|
|||
// ->setErrorMessage('No customer information found');
|
||||
// return $res->getReturnResponse();
|
||||
// }
|
||||
|
||||
// check if customer has more than one job order already
|
||||
$flag_cust_new = false;
|
||||
|
||||
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust->getID());
|
||||
if ($cust_jo_count <= 1)
|
||||
$flag_cust_new = true;
|
||||
|
||||
$jo->setCustomer($cust);
|
||||
$jo->setCustNew($flag_cust_new);
|
||||
|
||||
// validate service type
|
||||
$stype = $req->request->get('service_type');
|
||||
|
|
@ -956,7 +967,8 @@ class JobOrderController extends ApiController
|
|||
HubSelector $hub_select,
|
||||
HubDistributor $hub_dist,
|
||||
HubFilterLogger $hub_filter_logger,
|
||||
HubFilteringGeoChecker $hub_geofence
|
||||
HubFilteringGeoChecker $hub_geofence,
|
||||
JobOrderManager $jo_manager
|
||||
) {
|
||||
// validate params
|
||||
$validity = $this->validateRequest($req, [
|
||||
|
|
@ -1011,7 +1023,16 @@ class JobOrderController extends ApiController
|
|||
if ($cust == null) {
|
||||
return new ApiResponse(false, 'No customer information found.');
|
||||
}
|
||||
|
||||
// check if customer has more than one job order already
|
||||
$flag_cust_new = false;
|
||||
|
||||
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust->getID());
|
||||
if ($cust_jo_count <= 1)
|
||||
$flag_cust_new = true;
|
||||
|
||||
$jo->setCustomer($cust);
|
||||
$jo->setCustNew($flag_cust_new);
|
||||
|
||||
// validate service type
|
||||
$stype = $req->request->get('service_type');
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ use App\Service\HubFilteringGeoChecker;
|
|||
use App\Service\RiderTracker;
|
||||
use App\Service\PromoLogger;
|
||||
use App\Service\MapTools;
|
||||
use App\Service\JobOrderManager;
|
||||
|
||||
use App\Entity\JobOrder;
|
||||
use App\Entity\CustomerVehicle;
|
||||
|
|
@ -78,7 +79,7 @@ class JobOrderController extends ApiController
|
|||
FCMSender $fcmclient,
|
||||
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger,
|
||||
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger,
|
||||
HubFilteringGeoChecker $hub_geofence, EntityManagerInterface $em)
|
||||
HubFilteringGeoChecker $hub_geofence, EntityManagerInterface $em, JobOrderManager $jo_manager)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('tapi_jo.request', null, 'No access.');
|
||||
|
||||
|
|
@ -107,7 +108,7 @@ class JobOrderController extends ApiController
|
|||
|
||||
// get data from request
|
||||
$data = [];
|
||||
$status = $this->getJobOrderRequestInfo($req, $em, $data);
|
||||
$status = $this->getJobOrderRequestInfo($req, $em, $jo_manager, $data);
|
||||
if ($status != null)
|
||||
return new APIResponse(false, $status);
|
||||
|
||||
|
|
@ -136,7 +137,8 @@ class JobOrderController extends ApiController
|
|||
->setModeOfPayment($data['payment_mode'])
|
||||
->setAdvanceOrder($data['is_advance_order'])
|
||||
->setStatusAutoAssign(AutoAssignStatus::NOT_ASSIGNED)
|
||||
->setLandmark($data['landmark']);
|
||||
->setLandmark($data['landmark'])
|
||||
->setCustNew($data['flag_cust_new']);
|
||||
|
||||
$jo->setCustomer($data['customer']);
|
||||
$jo->setCustomerVehicle($data['customer_vehicle']);
|
||||
|
|
@ -1245,7 +1247,7 @@ class JobOrderController extends ApiController
|
|||
return $file_path;
|
||||
}
|
||||
|
||||
protected function getJobOrderRequestInfo(Request $req, EntityManagerInterface $em, &$data)
|
||||
protected function getJobOrderRequestInfo(Request $req, EntityManagerInterface $em, JobOrderManager $jo_manager, &$data)
|
||||
{
|
||||
$error = $this->validateJORequest($req, $em);
|
||||
if ($error != null)
|
||||
|
|
@ -1368,7 +1370,7 @@ class JobOrderController extends ApiController
|
|||
];
|
||||
|
||||
// process customer and vehicle information
|
||||
$cust_data = $this->processCustomerAndVehicleInformation($c_data, $em);
|
||||
$cust_data = $this->processCustomerAndVehicleInformation($c_data, $em, $jo_manager);
|
||||
|
||||
$data = [
|
||||
'trade_in_type' => $trade_in_type,
|
||||
|
|
@ -1388,6 +1390,7 @@ class JobOrderController extends ApiController
|
|||
'customer_vehicle' => $cust_data['customer_vehicle'],
|
||||
'source' => TransactionOrigin::THIRD_PARTY,
|
||||
'warranty_class' => $warranty_class,
|
||||
'flag_cust_new' => $cust_data['flag_cust_new'],
|
||||
];
|
||||
|
||||
return null;
|
||||
|
|
@ -1544,7 +1547,7 @@ class JobOrderController extends ApiController
|
|||
return null;
|
||||
}
|
||||
|
||||
protected function processCustomerAndVehicleInformation($data, EntityManagerInterface $em)
|
||||
protected function processCustomerAndVehicleInformation($data, EntityManagerInterface $em, JobOrderManager $jo_manager)
|
||||
{
|
||||
$c_data = [];
|
||||
|
||||
|
|
@ -1561,6 +1564,7 @@ class JobOrderController extends ApiController
|
|||
|
||||
// find customer + customer vehicle combo
|
||||
$cust_vehicle = $this->findCustomerAndCustomerVehicle($data, $em);
|
||||
$flag_cust_new = false;
|
||||
if ($cust_vehicle == null)
|
||||
{
|
||||
// find customer given phone number
|
||||
|
|
@ -1596,7 +1600,8 @@ class JobOrderController extends ApiController
|
|||
|
||||
// add customer vehicle
|
||||
$cust_vehicle = $this->createCustomerVehicle($em, $cust, $data);
|
||||
|
||||
|
||||
$flag_cust_new = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1607,9 +1612,18 @@ class JobOrderController extends ApiController
|
|||
$em->flush();
|
||||
}
|
||||
|
||||
// check if customer has more than one job order already
|
||||
if ($cust != null)
|
||||
{
|
||||
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust->getID());
|
||||
if ($cust_jo_count <= 1)
|
||||
$flag_cust_new = true;
|
||||
}
|
||||
|
||||
$c_data = [
|
||||
'customer' => $cust_vehicle->getCustomer(),
|
||||
'customer_vehicle' => $cust_vehicle,
|
||||
'flag_cust_new' => $flag_cust_new,
|
||||
];
|
||||
|
||||
return $c_data;
|
||||
|
|
|
|||
|
|
@ -435,6 +435,12 @@ class JobOrder
|
|||
*/
|
||||
protected $inventory_count;
|
||||
|
||||
// flag to indicate if customer is new aka has one or less job order in system
|
||||
/**
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $flag_cust_new;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
|
|
@ -461,6 +467,8 @@ class JobOrder
|
|||
$this->will_wait = WillingToWaitContent::WILLING_TO_WAIT;
|
||||
|
||||
$this->inventory_count = 0;
|
||||
|
||||
$this->flag_cust_new = false;
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -1237,4 +1245,15 @@ class JobOrder
|
|||
return $this->inventory_count;
|
||||
}
|
||||
|
||||
public function setCustNew($flag_cust_new = true)
|
||||
{
|
||||
$this->flag_cust_new = $flag_cust_new;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isCustNew()
|
||||
{
|
||||
return $this->flag_cust_new;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ use App\Service\PromoLogger;
|
|||
use App\Service\HubSelector;
|
||||
use App\Service\HubDistributor;
|
||||
use App\Service\HubFilteringGeoChecker;
|
||||
use App\Service\JobOrderManager;
|
||||
|
||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||
|
||||
|
|
@ -94,6 +95,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
protected $hub_geofence;
|
||||
protected $cust_distance_limit;
|
||||
protected $hub_filter_enable;
|
||||
protected $jo_manager;
|
||||
|
||||
protected $template_hash;
|
||||
|
||||
|
|
@ -102,7 +104,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah,
|
||||
string $country_code, WarrantyHandler $wh, RisingTideGateway $rt,
|
||||
PromoLogger $promo_logger, HubDistributor $hub_dist, HubFilteringGeoChecker $hub_geofence,
|
||||
string $cust_distance_limit, string $hub_filter_enabled)
|
||||
string $cust_distance_limit, string $hub_filter_enabled, JobOrderManager $jo_manager)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->ic = $ic;
|
||||
|
|
@ -118,6 +120,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
$this->hub_geofence = $hub_geofence;
|
||||
$this->cust_distance_limit = $cust_distance_limit;
|
||||
$this->hub_filter_enabled = $hub_filter_enabled;
|
||||
$this->jo_manager = $jo_manager;
|
||||
|
||||
$this->loadTemplates();
|
||||
}
|
||||
|
|
@ -214,7 +217,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
($reason == CustomerNotWaitReason::RUSH_REQUEST))
|
||||
$is_emergency = true;
|
||||
}
|
||||
|
||||
|
||||
// add row data
|
||||
$row['id'] = $orow->getID();
|
||||
$row['customer_name'] = $orow->getCustomer()->getFirstName() . ' ' . $orow->getCustomer()->getLastName();
|
||||
|
|
@ -228,6 +231,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
$row['is_mobile'] = $orow->getSource() == TransactionOrigin::MOBILE_APP;
|
||||
$row['is_vip'] = $is_vip;
|
||||
$row['is_emergency'] = $is_emergency;
|
||||
$row['flag_cust_new'] = $orow->isCustNew();
|
||||
$row['date_assign'] = !empty($orow->getDateAssign()) ? $orow->getDateAssign()->format("c") : null;
|
||||
$row['date_fulfill'] = !empty($orow->getDateFulfill()) ? $orow->getDateFulfill()->format("c") : null;
|
||||
|
||||
|
|
@ -361,6 +365,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
// find customer
|
||||
$cust_id = $req->request->get('cid');
|
||||
$customer = $em->getRepository(Customer::class)->find($cust_id);
|
||||
$flag_cust_new = false;
|
||||
if (empty($customer))
|
||||
{
|
||||
$error_array['customer_vehicle'] = 'Invalid customer specified.';
|
||||
|
|
@ -390,6 +395,11 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
->setDpaConsent($is_dpa_checked);
|
||||
}
|
||||
|
||||
// check if customer has more than one job order already
|
||||
$cust_jo_count = $this->jo_manager->getCustomerJobOrderCount($customer->getID());
|
||||
if ($cust_jo_count <= 1)
|
||||
$flag_cust_new = true;
|
||||
|
||||
// check if lat and lng are provided
|
||||
if (empty($req->request->get('coord_lng')) || empty($req->request->get('coord_lat'))) {
|
||||
$error_array['coordinates'] = 'No map coordinates provided. Please click on a location on the map.';
|
||||
|
|
@ -521,7 +531,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
->setGender($gender)
|
||||
->setEmergencyType($etype)
|
||||
->setOwnershipType($owner_type)
|
||||
->setCustomerLocation($cust_location);
|
||||
->setCustomerLocation($cust_location)
|
||||
->setCustNew($flag_cust_new);
|
||||
|
||||
// check if user is null, meaning call to create came from API
|
||||
if ($user != null)
|
||||
|
|
|
|||
|
|
@ -5,9 +5,12 @@ namespace App\Service;
|
|||
use App\Entity\JobOrder;
|
||||
|
||||
use App\Ramcar\ServiceType;
|
||||
use App\Ramcar\JOStatus;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use PDO;
|
||||
|
||||
class JobOrderManager
|
||||
{
|
||||
protected $em;
|
||||
|
|
@ -36,6 +39,22 @@ class JobOrderManager
|
|||
return false;
|
||||
}
|
||||
|
||||
public function getCustomerJobOrderCount($customer_id)
|
||||
{
|
||||
$db = $this->em->getConnection();
|
||||
|
||||
$query_sql = 'SELECT COUNT(*) AS jo_count FROM job_order WHERE customer_id = :cust_id AND status != :status_cancelled';
|
||||
|
||||
$query_stmt = $db->prepare($query_sql);
|
||||
$query_stmt->bindValue('cust_id', $customer_id);
|
||||
$query_stmt->bindValue('status_cancelled', JOStatus::CANCELLED);
|
||||
|
||||
$jo_results = $query_stmt->executeQuery();
|
||||
$results = $jo_results->fetchAssociative();
|
||||
|
||||
return $results['jo_count'];
|
||||
}
|
||||
|
||||
protected function updateCustomerVehicleBattery($cust_vehicle, $invoice)
|
||||
{
|
||||
if (($cust_vehicle != null) && ($invoice != null))
|
||||
|
|
|
|||
|
|
@ -121,6 +121,21 @@
|
|||
field: 'plate_number',
|
||||
title: 'Plate #'
|
||||
},
|
||||
{
|
||||
field: 'flag_cust_new',
|
||||
title: 'New',
|
||||
template: function (row, index, datatable) {
|
||||
var tag = '';
|
||||
|
||||
if (row.flag_cust_new === true) {
|
||||
tag = '<span class="m-badge m-badge--success m-badge--wide">Yes</span>';
|
||||
} else {
|
||||
tag = '<span class="m-badge m-badge--danger m-badge--wide">No</span>';
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'customer_name',
|
||||
title: 'Customer'
|
||||
|
|
|
|||
Loading…
Reference in a new issue