Use interface for the invoice manager. #744

This commit is contained in:
Korina Cordero 2023-06-18 23:23:29 -04:00
parent 282760fe5a
commit 9840ecf633
6 changed files with 12 additions and 181 deletions

View file

@ -168,7 +168,7 @@ services:
App\Service\InvoiceGenerator\ResqInvoiceGenerator: ~ App\Service\InvoiceGenerator\ResqInvoiceGenerator: ~
# invoice generator interface # invoice generator interface
App\Service\InvoiceGeneratorInterface: "@App\\Service\\InvoiceGenerator\\ResqInvoiceGenerator" App\Service\InvoiceGeneratorInterface: "@App\\Service\\InvoiceManager"
# invoice manager # invoice manager
App\Service\InvoiceManager: ~ App\Service\InvoiceManager: ~

View file

@ -9,9 +9,9 @@ use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use App\Service\InvoiceManager; use App\Service\InvoiceGeneratorInterface;
use App\InvoiceCriteria;
use App\Ramcar\InvoiceCriteria;
use App\Ramcar\ServiceType; use App\Ramcar\ServiceType;
use App\Entity\Battery; use App\Entity\Battery;
@ -31,7 +31,7 @@ class TestInvoiceManagerCommand extends Command
->setHelp('Test invoice manager service.'); ->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->em = $em;
$this->inv_manager = $inv_manager; $this->inv_manager = $inv_manager;

View file

@ -16,6 +16,7 @@ use App\Entity\VehicleManufacturer;
use App\Entity\Vehicle; use App\Entity\Vehicle;
use App\Entity\Hub; use App\Entity\Hub;
use App\Service\InvoiceGeneratorInterface;
use App\Service\JobOrderHandlerInterface; use App\Service\JobOrderHandlerInterface;
use App\Service\GISManagerInterface; use App\Service\GISManagerInterface;
use App\Service\MapTools; use App\Service\MapTools;
@ -23,14 +24,12 @@ use App\Service\MQTTClient;
use App\Service\APNSClient; use App\Service\APNSClient;
use App\Service\InventoryManager; use App\Service\InventoryManager;
use App\Service\HubSelector; use App\Service\HubSelector;
use App\Service\InvoiceManager;
use App\Service\RiderTracker; use App\Service\RiderTracker;
use App\Service\MotivConnector; use App\Service\MotivConnector;
use App\Service\GeofenceTracker; use App\Service\GeofenceTracker;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; 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_log('generating invoice...');
$error = false; $error = false;

View file

@ -1,169 +0,0 @@
<?php
namespace App;
use App\Entity\Battery;
use App\Entity\Promo;
use App\Entity\CustomerVehicle;
use App\Entity\ServiceCharge;
class InvoiceCriteria
{
protected $stype;
protected $promos;
protected $cv;
protected $flag_coolant;
protected $discount;
protected $service_charges;
protected $flag_taxable;
// entries are battery and trade-in combos
protected $entries;
public function __construct()
{
$this->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;
}
}

View file

@ -9,6 +9,8 @@ use Doctrine\ORM\EntityManagerInterface;
use App\Invoice; use App\Invoice;
use App\Service\InvoiceGeneratorInterface;
use App\Ramcar\InvoiceCriteria; use App\Ramcar\InvoiceCriteria;
use App\Ramcar\InvoiceStatus; use App\Ramcar\InvoiceStatus;
use App\Ramcar\ServiceType; use App\Ramcar\ServiceType;
@ -20,7 +22,7 @@ use App\Entity\User;
use App\Entity\Battery; use App\Entity\Battery;
use App\Entity\Promo; use App\Entity\Promo;
class InvoiceManager class InvoiceManager implements InvoiceGeneratorInterface
{ {
private $security; private $security;
protected $em; protected $em;

View file

@ -35,6 +35,7 @@ use App\Ramcar\ServiceType;
use App\Ramcar\TradeInType; use App\Ramcar\TradeInType;
use App\Ramcar\JOEventType; use App\Ramcar\JOEventType;
use App\Ramcar\JOStatus; use App\Ramcar\JOStatus;
use App\Ramcar\InvoiceCriteria;
use App\Ramcar\WarrantyClass; use App\Ramcar\WarrantyClass;
use App\Ramcar\DiscountApply; use App\Ramcar\DiscountApply;
use App\Ramcar\ModeOfPayment; use App\Ramcar\ModeOfPayment;
@ -53,6 +54,7 @@ use App\Ramcar\CustomerClassification;
use App\Ramcar\Gender; use App\Ramcar\Gender;
use App\Ramcar\CallerClassification; use App\Ramcar\CallerClassification;
use App\Service\InvoiceGeneratorInterface;
use App\Service\JobOrderHandlerInterface; use App\Service\JobOrderHandlerInterface;
use App\Service\RiderAssignmentHandlerInterface; use App\Service\RiderAssignmentHandlerInterface;
use App\Service\WarrantyHandler; use App\Service\WarrantyHandler;
@ -65,9 +67,6 @@ use App\Service\HubSelector;
use App\Service\HubDistributor; use App\Service\HubDistributor;
use App\Service\HubFilteringGeoChecker; use App\Service\HubFilteringGeoChecker;
use App\Service\InvoiceManager;
use App\InvoiceCriteria;
use CrEOF\Spatial\PHP\Types\Geometry\Point; use CrEOF\Spatial\PHP\Types\Geometry\Point;
use Mosquitto\Client as MosquittoClient; use Mosquitto\Client as MosquittoClient;
@ -97,7 +96,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
protected $template_hash; protected $template_hash;
public function __construct(Security $security, EntityManagerInterface $em, public function __construct(Security $security, EntityManagerInterface $em,
InvoiceManager $ic, ValidatorInterface $validator, InvoiceGeneratorInterface $ic, ValidatorInterface $validator,
TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah, TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah,
string $country_code, WarrantyHandler $wh, RisingTideGateway $rt, string $country_code, WarrantyHandler $wh, RisingTideGateway $rt,
PromoLogger $promo_logger, HubDistributor $hub_dist, HubFilteringGeoChecker $hub_geofence, PromoLogger $promo_logger, HubDistributor $hub_dist, HubFilteringGeoChecker $hub_geofence,