em = $em; $this->pt_manager = $pt_manager; } public function getID() { return 'jumpstart_troubleshoot'; } public function compute($criteria, &$total) { $stype = $criteria->getServiceType(); $source = $criteria->getSource(); $pt_id = $criteria->getPriceTier(); $items = []; if ($stype == $this->getID()) { $cv = $criteria->getCustomerVehicle(); // check if price tier has item price $pt_price = $this->getPriceTierItemPrice($pt_id, $source, $cv); if ($pt_price == null) $price = $this->getServiceTypeFee($source, $cv); else $price = $pt_price; // add the service fee to items $qty = 1; $items[] = [ 'service_type' => $this->getID(), 'qty' => $qty, 'title' => $this->getServiceTitle(), 'price' => $price, ]; $qty_price = bcmul($price, $qty, 2); $total['total_price'] = bcadd($total['total_price'], $qty_price, 2); } return $items; } public function getServiceTypeFee($source, CustomerVehicle $cv) { // check the source of JO // (1) if from app, service fee is 0 if motolite user. jumpstart fee for app if non-motolite user. // (2) any other source, jumpstart fees are charged whether motolite user or not if ($source == TransactionOrigin::MOBILE_APP) { if ($cv->hasMotoliteBattery()) $code = 'motolite_user_service_fee'; else $code = 'jumpstart_fee_mobile_app'; } else $code = 'jumpstart_fee'; $fee = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]); if ($fee == null) return 0; return $fee->getFee(); } public function validatePromo($criteria, $promo_id) { return false; } public function validateInvoiceItems($criteria, $invoice_items) { return null; } protected function getPriceTierItemPrice($pt_id, $source, $cv) { // price_tier is default if ($pt_id == 0) return null; // find the item type for service offering $item_type = $this->em->getRepository(ItemType::class)->findOneBy(['code' => 'service_offering']); if ($item_type == null) return null; // find the service offering // check the source of JO // (1) if from app, service fee is 0 if motolite user. jumpstart fee for app if non-motolite user. // (2) any other source, jumpstart fees are charged whether motolite user or not if ($source == TransactionOrigin::MOBILE_APP) { if ($cv->hasMotoliteBattery()) $code = 'motolite_user_service_fee'; else $code = 'jumpstart_fee_mobile_app'; } else $code = 'jumpstart_fee'; $service = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]); // check if service is null. If null, return null if ($service == null) return null; $item_type_id = $item_type->getID(); $item_id = $service->getID(); $price = $this->pt_manager->getItemPrice($pt_id, $item_type_id, $item_id); return $price; } protected function getServiceTitle() { $title = 'Service - Troubleshooting fee'; return $title; } }