Add command to update flag_cust_new for existing job orders. Rename flag for consistency. #773

This commit is contained in:
Korina Cordero 2023-11-09 18:03:17 +08:00
parent 806418db52
commit fd28be75d1
6 changed files with 103 additions and 32 deletions

View file

@ -0,0 +1,74 @@
<?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;
class SetJobOrderCustNewCommand extends Command
{
protected $em;
protected $jo_manager;
public function __construct(EntityManagerInterface $em, JobOrderManager)
{
$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();
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();
// if one or less, set flag_cust_new to true
if ($jo_count <= 1)
$this->updateCustNew($db, $jo_id);
}
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
]);
}
}

View file

@ -931,13 +931,13 @@ class APIController extends Controller implements LoggedController
}
// check if customer has more than one job order already
$flag_new_cust = false;
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust);
$flag_cust_new = false;
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust->getID());
if ($cust_jo_count <= 1)
$flag_new_cust = true;
$flag_cust_new = true;
$jo->setCustomer($cust);
$jo->setCustNew($flag_new_cust);
$jo->setCustNew($flag_cust_new);
// validate service type
$stype = $req->request->get('service_type');
@ -2868,14 +2868,13 @@ class APIController extends Controller implements LoggedController
// }
// check if customer has more than one job order already
$flag_new_cust = false;
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust);
error_log('cust jo count for customer id ' .$cust->getID() . ' ' . $cust_jo_count);
$flag_cust_new = false;
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust->getID());
if ($cust_jo_count <= 1)
$flag_new_cust = true;
$flag_cust_new = true;
$jo->setCustomer($cust);
$jo->setCustNew($flag_new_cust);
$jo->setCustNew($flag_cust_new);
// validate service type
$stype = $req->request->get('service_type');

View file

@ -598,14 +598,14 @@ class JobOrderController extends ApiController
// }
// check if customer has more than one job order already
$flag_new_cust = false;
$flag_cust_new = false;
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust);
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust->getID());
if ($cust_jo_count <= 1)
$flag_new_cust = true;
$flag_cust_new = true;
$jo->setCustomer($cust);
$jo->setCustNew($flag_new_cust);
$jo->setCustNew($flag_cust_new);
// validate service type
$stype = $req->request->get('service_type');
@ -1025,14 +1025,14 @@ class JobOrderController extends ApiController
}
// check if customer has more than one job order already
$flag_new_cust = false;
$flag_cust_new = false;
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust);
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust->getID());
if ($cust_jo_count <= 1)
$flag_new_cust = true;
$flag_cust_new = true;
$jo->setCustomer($cust);
$jo->setCustNew($flag_new_cust);
$jo->setCustNew($flag_cust_new);
// validate service type
$stype = $req->request->get('service_type');

View file

@ -138,7 +138,7 @@ class JobOrderController extends ApiController
->setAdvanceOrder($data['is_advance_order'])
->setStatusAutoAssign(AutoAssignStatus::NOT_ASSIGNED)
->setLandmark($data['landmark'])
->setCustNew($data['flag_new_cust']);
->setCustNew($data['flag_cust_new']);
$jo->setCustomer($data['customer']);
$jo->setCustomerVehicle($data['customer_vehicle']);
@ -1390,7 +1390,7 @@ class JobOrderController extends ApiController
'customer_vehicle' => $cust_data['customer_vehicle'],
'source' => TransactionOrigin::THIRD_PARTY,
'warranty_class' => $warranty_class,
'flag_new_cust' => $cust_data['flag_new_cust'],
'flag_cust_new' => $cust_data['flag_cust_new'],
];
return null;
@ -1564,7 +1564,7 @@ class JobOrderController extends ApiController
// find customer + customer vehicle combo
$cust_vehicle = $this->findCustomerAndCustomerVehicle($data, $em);
$flag_new_cust = false;
$flag_cust_new = false;
if ($cust_vehicle == null)
{
// find customer given phone number
@ -1601,7 +1601,7 @@ class JobOrderController extends ApiController
// add customer vehicle
$cust_vehicle = $this->createCustomerVehicle($em, $cust, $data);
$flag_new_cust = true;
$flag_cust_new = true;
}
else
{
@ -1615,15 +1615,15 @@ class JobOrderController extends ApiController
// check if customer has more than one job order already
if ($cust != null)
{
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust);
$cust_jo_count = $jo_manager->getCustomerJobOrderCount($cust->getID());
if ($cust_jo_count <= 1)
$flag_new_cust = true;
$flag_cust_new = true;
}
$c_data = [
'customer' => $cust_vehicle->getCustomer(),
'customer_vehicle' => $cust_vehicle,
'flag_new_cust' => $flag_new_cust,
'flag_cust_new' => $flag_cust_new,
];
return $c_data;

View file

@ -363,7 +363,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// find customer
$cust_id = $req->request->get('cid');
$customer = $em->getRepository(Customer::class)->find($cust_id);
$flag_new_cust = false;
$flag_cust_new = false;
if (empty($customer))
{
$error_array['customer_vehicle'] = 'Invalid customer specified.';
@ -394,9 +394,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
}
// check if customer has more than one job order already
$cust_jo_count = $this->jo_manager->getCustomerJobOrderCount($customer);
$cust_jo_count = $this->jo_manager->getCustomerJobOrderCount($customer->getID());
if ($cust_jo_count <= 1)
$flag_new_cust = true;
$flag_cust_new = true;
// check if lat and lng are provided
if (empty($req->request->get('coord_lng')) || empty($req->request->get('coord_lat'))) {
@ -530,7 +530,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
->setEmergencyType($etype)
->setOwnershipType($owner_type)
->setCustomerLocation($cust_location)
->setCustNew($flag_new_cust);
->setCustNew($flag_cust_new);
// check if user is null, meaning call to create came from API
if ($user != null)

View file

@ -39,16 +39,14 @@ class JobOrderManager
return false;
}
public function getCustomerJobOrderCount($customer)
public function getCustomerJobOrderCount($customer_id)
{
$db = $this->em->getConnection();
$cust_id = $customer->getID();
$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', $cust_id);
$query_stmt->bindValue('cust_id', $customer_id);
$query_stmt->bindValue('status_cancelled', JOStatus::CANCELLED);
$jo_results = $query_stmt->executeQuery();