Move customer tag removal to service. #591
This commit is contained in:
parent
19ec112bd2
commit
e33b9eb719
3 changed files with 41 additions and 59 deletions
|
|
@ -66,7 +66,7 @@ class JobOrderController extends APIController
|
|||
|
||||
public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
||||
InventoryManager $im, MQTTClient $mclient, RiderAssignmentHandlerInterface $rah,
|
||||
PromoLogger $promo_logger, EntityManagerInterface $em, HubSelector $hub_select,
|
||||
EntityManagerInterface $em, HubSelector $hub_select,
|
||||
HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger, HubFilteringGeoChecker $hub_geofence,
|
||||
MobileAPIHandler $mah, JobOrderManager $jo_manager)
|
||||
{
|
||||
|
|
@ -154,15 +154,20 @@ class JobOrderController extends APIController
|
|||
'invoice' => $invoice_data
|
||||
];
|
||||
|
||||
$this->removeCustomerTag($jo, $jo->getCustomerVehicle(), $promo_logger, $mobile_user->getID());
|
||||
// check service type
|
||||
if ($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||
{
|
||||
$customer_tags = $cust->getCustomerTagObjects();
|
||||
$jo_manager->removeCustomerTag($jo, $customer_tags, $mobile_user->getID());
|
||||
}
|
||||
|
||||
return new APIResponse(true, 'Job order created', $data);
|
||||
}
|
||||
|
||||
public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
||||
InventoryManager $im, MQTTClient $mclient,
|
||||
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger,
|
||||
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger,
|
||||
RiderAssignmentHandlerInterface $rah, HubSelector $hub_select,
|
||||
HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger,
|
||||
HubFilteringGeoChecker $hub_geofence, EntityManagerInterface $em,
|
||||
MobileAPIHandler $mah, JobOrderManager $jo_manager)
|
||||
{
|
||||
|
|
@ -281,7 +286,12 @@ class JobOrderController extends APIController
|
|||
'invoice' => $invoice_data
|
||||
];
|
||||
|
||||
$this->removeCustomerTag($jo, $jo->getCustomerVehicle(), $promo_logger, $mobile_user->getID());
|
||||
// check service type
|
||||
if ($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||
{
|
||||
$customer_tags = $cust->getCustomerTagObjects();
|
||||
$jo_manager->removeCustomerTag($jo, $customer_tags, $mobile_user->getID());
|
||||
}
|
||||
|
||||
return new APIResponse(true, 'Job order created', $data);
|
||||
}
|
||||
|
|
@ -1167,39 +1177,6 @@ class JobOrderController extends APIController
|
|||
return $invoice_data;
|
||||
}
|
||||
|
||||
protected function removeCustomerTag(JobOrder $jo, CustomerVehicle $cv, PromoLogger $promo_logger, $mobile_user_id)
|
||||
{
|
||||
// check service type
|
||||
if ($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||
{
|
||||
$customer = $cv->getCustomer();
|
||||
$customer_tags = $customer->getCustomerTagObjects();
|
||||
if (!empty($customer_tags))
|
||||
{
|
||||
foreach ($customer_tags as $customer_tag)
|
||||
{
|
||||
if ($customer_tag->getID() == $invoice->getUsedCustomerTagId())
|
||||
{
|
||||
// remove associated entity
|
||||
$customer->removeCustomerTag($customer_tag);
|
||||
|
||||
// log the availment of promo from customer
|
||||
$created_by = $mobile_user_id;
|
||||
$cust_id = $jo->getCustomer()->getID();
|
||||
$cust_fname = $jo->getCustomer()->getFirstName();
|
||||
$cust_lname = $jo->getCustomer()->getLastName();
|
||||
$jo_id = $jo->getID();
|
||||
$invoice_id = $jo->getInvoice()->getID();
|
||||
// TODO: check if we store total price of invoice or just the discounted amount
|
||||
$amount = $jo->getInvoice()->getTotalPrice();
|
||||
$promo_logger->logPromoInfo($created_by, $cust_id, $cust_fname, $cust_lname, $jo_id,
|
||||
$invoice_id, $amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function generateJobOrderData($req, $jo, $rt, $mah)
|
||||
{
|
||||
$status = $jo->getStatus();
|
||||
|
|
|
|||
|
|
@ -403,30 +403,12 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
// check service type
|
||||
if ($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||
{
|
||||
$customer = $cust_vehicle->getCustomer();
|
||||
// process customer tags
|
||||
$customer_tags = $customer->getCustomerTagObjects();
|
||||
if (!empty($customer_tags))
|
||||
{
|
||||
foreach ($customer_tags as $customer_tag)
|
||||
{
|
||||
if ($customer_tag->getID() == $jo->getInvoice()->getUsedCustomerTagId())
|
||||
{
|
||||
// remove associated entity
|
||||
$customer->removeCustomerTag($customer_tag);
|
||||
|
||||
// log the availment of promo from customer
|
||||
$created_by = $jo->getCreatedBy()->getUsername();
|
||||
$cust_id = $jo->getCustomer()->getID();
|
||||
$cust_fname = $jo->getCustomer()->getFirstName();
|
||||
$cust_lname = $jo->getCustomer()->getLastName();
|
||||
$jo_id = $jo->getID();
|
||||
$invoice_id = $jo->getInvoice()->getID();
|
||||
// TODO: check if we store total price of invoice or just the discounted amount
|
||||
$amount = $jo->getInvoice()->getTotalPrice();
|
||||
$this->promo_logger->logPromoInfo($created_by, $cust_id, $cust_fname, $cust_lname, $jo_id,
|
||||
$invoice_id, $amount);
|
||||
}
|
||||
}
|
||||
$username = $jo->getCreatedBy()->getUsername();
|
||||
$this->jo_manager->removeCustomerTag($jo, $customer_tags, $username);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,4 +136,27 @@ class JobOrderManager
|
|||
}
|
||||
}
|
||||
|
||||
public function removeCustomerTag(JobOrder $jo, $customer_tags, $username)
|
||||
{
|
||||
foreach ($customer_tags as $customer_tag)
|
||||
{
|
||||
if ($customer_tag->getID() == $jo->getInvoice()->getUsedCustomerTagId())
|
||||
{
|
||||
// remove associated entity
|
||||
$customer->removeCustomerTag($customer_tag);
|
||||
|
||||
// log the availment of promo from customer
|
||||
$created_by = $username;
|
||||
$cust_id = $jo->getCustomer()->getID();
|
||||
$cust_fname = $jo->getCustomer()->getFirstName();
|
||||
$cust_lname = $jo->getCustomer()->getLastName();
|
||||
$jo_id = $jo->getID();
|
||||
$invoice_id = $jo->getInvoice()->getID();
|
||||
// TODO: check if we store total price of invoice or just the discounted amount
|
||||
$amount = $jo->getInvoice()->getTotalPrice();
|
||||
$this->promo_logger->logPromoInfo($created_by, $cust_id, $cust_fname, $cust_lname, $jo_id,
|
||||
$invoice_id, $amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue