From 9840ecf633c44a12adf37ea09d5bc1452deec954 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Sun, 18 Jun 2023 23:23:29 -0400 Subject: [PATCH] Use interface for the invoice manager. #744 --- config/services.yaml | 2 +- src/Command/TestInvoiceManagerCommand.php | 6 +- src/Controller/JobOrderController.php | 5 +- src/InvoiceCriteria.php | 169 ------------------ src/Service/InvoiceManager.php | 4 +- .../JobOrderHandler/ResqJobOrderHandler.php | 7 +- 6 files changed, 12 insertions(+), 181 deletions(-) delete mode 100644 src/InvoiceCriteria.php diff --git a/config/services.yaml b/config/services.yaml index f2693988..d707b465 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -168,7 +168,7 @@ services: App\Service\InvoiceGenerator\ResqInvoiceGenerator: ~ # invoice generator interface - App\Service\InvoiceGeneratorInterface: "@App\\Service\\InvoiceGenerator\\ResqInvoiceGenerator" + App\Service\InvoiceGeneratorInterface: "@App\\Service\\InvoiceManager" # invoice manager App\Service\InvoiceManager: ~ diff --git a/src/Command/TestInvoiceManagerCommand.php b/src/Command/TestInvoiceManagerCommand.php index 6fd955cb..1de193ad 100644 --- a/src/Command/TestInvoiceManagerCommand.php +++ b/src/Command/TestInvoiceManagerCommand.php @@ -9,9 +9,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Doctrine\ORM\EntityManagerInterface; -use App\Service\InvoiceManager; -use App\InvoiceCriteria; +use App\Service\InvoiceGeneratorInterface; +use App\Ramcar\InvoiceCriteria; use App\Ramcar\ServiceType; use App\Entity\Battery; @@ -31,7 +31,7 @@ class TestInvoiceManagerCommand extends Command ->setHelp('Test invoice manager service.'); } - public function __construct(InvoiceManager $inv_manager, EntityManagerInterface $em) + public function __construct(InvoiceGeneratorInterface $inv_manager, EntityManagerInterface $em) { $this->em = $em; $this->inv_manager = $inv_manager; diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 5c955f2b..f3597173 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -16,6 +16,7 @@ use App\Entity\VehicleManufacturer; use App\Entity\Vehicle; use App\Entity\Hub; +use App\Service\InvoiceGeneratorInterface; use App\Service\JobOrderHandlerInterface; use App\Service\GISManagerInterface; use App\Service\MapTools; @@ -23,14 +24,12 @@ use App\Service\MQTTClient; use App\Service\APNSClient; use App\Service\InventoryManager; use App\Service\HubSelector; -use App\Service\InvoiceManager; use App\Service\RiderTracker; use App\Service\MotivConnector; use App\Service\GeofenceTracker; - use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -713,7 +712,7 @@ class JobOrderController extends Controller } - public function generateInvoice(Request $req, InvoiceManager $ic) + public function generateInvoice(Request $req, InvoiceGeneratorInterface $ic) { // error_log('generating invoice...'); $error = false; diff --git a/src/InvoiceCriteria.php b/src/InvoiceCriteria.php deleted file mode 100644 index 12ee71e0..00000000 --- a/src/InvoiceCriteria.php +++ /dev/null @@ -1,169 +0,0 @@ -stype = 0; - $this->promos = []; - $this->entries = []; - $this->cv = null; - $this->flag_coolant = false; - $this->discount = 0; - $this->service_charges = []; - $this->flag_taxable = false; - } - - public function setServiceType($stype) - { - // TODO: validate service type - $this->stype = $stype; - return $this; - } - - public function getServiceType() - { - return $this->stype; - } - - /* - public function addBattery(Battery $battery, $qty = 1) - { - for ($i = 0; $i < $qty; $i++) - $this->batteries[] = $battery; - return $this; - } - - public function getBatteries() - { - return $this->batteries; - } - */ - - public function addPromo(Promo $promo) - { - $this->promos[] = $promo; - return $this; - } - - public function getPromos() - { - return $this->promos; - } - - /* - public function addTradeIn($is_motolite, $qty = 1) - { - // NOTE: this asumes that all the rates for trade-ins are standardized - // for motolite and non-motolite trade-ins - - for ($i = 0; $i < $qty; $i++) - { - if ($is_motolite) - $trade_in = 'motolite'; - else - $trade_in = 'other'; - - $this->trade_ins[] = $trade_in; - } - return $this; - } - - public function getTradeIns() - { - return $this->trade_ins; - } - */ - - public function addEntry($battery, $trade_in, $qty) - { - // trade_in is null if no trade_in specified - - $entry = [ - 'battery' => $battery, - 'trade_in' => $trade_in, - 'qty' => $qty - ]; - - $this->entries[] = $entry; - } - - public function getEntries() - { - return $this->entries; - } - - public function setCustomerVehicle(CustomerVehicle $cv = null) - { - $this->cv = $cv; - return $this; - } - - public function getCustomerVehicle() - { - return $this->cv; - } - - public function setHasCoolant($flag = true) - { - $this->flag_coolant = $flag; - return $this; - } - - public function hasCoolant() - { - return $this->flag_coolant; - } - - public function setDiscount($discount) - { - $this->discount = $discount; - return $this; - } - - public function getDiscount() - { - return $this->discount; - } - - public function addServiceCharge(ServiceCharge $service_charge) - { - $this->service_charges[] = $service_charge; - return $this; - } - - public function getServiceCharges() - { - return $this->service_charges; - } - - public function setIsTaxable($flag = true) - { - $this->flag_taxable = $flag; - return $this; - } - - public function isTaxable() - { - return $this->flag_taxable; - } - -} diff --git a/src/Service/InvoiceManager.php b/src/Service/InvoiceManager.php index 4272b323..90b092c3 100644 --- a/src/Service/InvoiceManager.php +++ b/src/Service/InvoiceManager.php @@ -9,6 +9,8 @@ use Doctrine\ORM\EntityManagerInterface; use App\Invoice; +use App\Service\InvoiceGeneratorInterface; + use App\Ramcar\InvoiceCriteria; use App\Ramcar\InvoiceStatus; use App\Ramcar\ServiceType; @@ -20,7 +22,7 @@ use App\Entity\User; use App\Entity\Battery; use App\Entity\Promo; -class InvoiceManager +class InvoiceManager implements InvoiceGeneratorInterface { private $security; protected $em; diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index de3a63f5..691926fb 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -35,6 +35,7 @@ use App\Ramcar\ServiceType; use App\Ramcar\TradeInType; use App\Ramcar\JOEventType; use App\Ramcar\JOStatus; +use App\Ramcar\InvoiceCriteria; use App\Ramcar\WarrantyClass; use App\Ramcar\DiscountApply; use App\Ramcar\ModeOfPayment; @@ -53,6 +54,7 @@ use App\Ramcar\CustomerClassification; use App\Ramcar\Gender; use App\Ramcar\CallerClassification; +use App\Service\InvoiceGeneratorInterface; use App\Service\JobOrderHandlerInterface; use App\Service\RiderAssignmentHandlerInterface; use App\Service\WarrantyHandler; @@ -65,9 +67,6 @@ use App\Service\HubSelector; use App\Service\HubDistributor; use App\Service\HubFilteringGeoChecker; -use App\Service\InvoiceManager; -use App\InvoiceCriteria; - use CrEOF\Spatial\PHP\Types\Geometry\Point; use Mosquitto\Client as MosquittoClient; @@ -97,7 +96,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface protected $template_hash; public function __construct(Security $security, EntityManagerInterface $em, - InvoiceManager $ic, ValidatorInterface $validator, + InvoiceGeneratorInterface $ic, ValidatorInterface $validator, TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah, string $country_code, WarrantyHandler $wh, RisingTideGateway $rt, PromoLogger $promo_logger, HubDistributor $hub_dist, HubFilteringGeoChecker $hub_geofence,