Add service charges to invoice generation. #341
This commit is contained in:
parent
115c207868
commit
f3f941e0a0
3 changed files with 68 additions and 0 deletions
|
|
@ -694,6 +694,7 @@ class JobOrderController extends Controller
|
||||||
$items = $req->request->get('items');
|
$items = $req->request->get('items');
|
||||||
$promo_id = $req->request->get('promo');
|
$promo_id = $req->request->get('promo');
|
||||||
$cvid = $req->request->get('cvid');
|
$cvid = $req->request->get('cvid');
|
||||||
|
$service_charges = $req->request->get('service_charges');
|
||||||
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
|
@ -740,6 +741,9 @@ class JobOrderController extends Controller
|
||||||
// TODO: this snippet should be in the invoice generator
|
// TODO: this snippet should be in the invoice generator
|
||||||
$error = $ic->validateDiscount($criteria, $promo_id);
|
$error = $ic->validateDiscount($criteria, $promo_id);
|
||||||
|
|
||||||
|
// process service charges
|
||||||
|
$error = $ic->invoiceServiceCharges($criteria, $service_charges);
|
||||||
|
|
||||||
if (!$error)
|
if (!$error)
|
||||||
$error = $ic->invoiceBatteries($criteria, $items);
|
$error = $ic->invoiceBatteries($criteria, $items);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace App\Ramcar;
|
||||||
use App\Entity\Battery;
|
use App\Entity\Battery;
|
||||||
use App\Entity\Promo;
|
use App\Entity\Promo;
|
||||||
use App\Entity\CustomerVehicle;
|
use App\Entity\CustomerVehicle;
|
||||||
|
use App\Entity\ServiceCharge;
|
||||||
|
|
||||||
class InvoiceCriteria
|
class InvoiceCriteria
|
||||||
{
|
{
|
||||||
|
|
@ -13,6 +14,7 @@ class InvoiceCriteria
|
||||||
protected $cv;
|
protected $cv;
|
||||||
protected $flag_coolant;
|
protected $flag_coolant;
|
||||||
protected $discount;
|
protected $discount;
|
||||||
|
protected $service_charges;
|
||||||
|
|
||||||
// entries are battery and trade-in combos
|
// entries are battery and trade-in combos
|
||||||
protected $entries;
|
protected $entries;
|
||||||
|
|
@ -25,6 +27,7 @@ class InvoiceCriteria
|
||||||
$this->cv = null;
|
$this->cv = null;
|
||||||
$this->flag_coolant = false;
|
$this->flag_coolant = false;
|
||||||
$this->discount = 0;
|
$this->discount = 0;
|
||||||
|
$this->service_charges = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setServiceType($stype)
|
public function setServiceType($stype)
|
||||||
|
|
@ -138,4 +141,16 @@ class InvoiceCriteria
|
||||||
{
|
{
|
||||||
return $this->discount;
|
return $this->discount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addServiceCharge(ServiceCharge $service_charge)
|
||||||
|
{
|
||||||
|
$this->service_charges[] = $service_charge;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getServiceCharges()
|
||||||
|
{
|
||||||
|
return $this->service_charges;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ use App\Entity\Invoice;
|
||||||
use App\Entity\InvoiceItem;
|
use App\Entity\InvoiceItem;
|
||||||
use App\Entity\Battery;
|
use App\Entity\Battery;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
|
use App\Entity\ServiceCharge;
|
||||||
|
|
||||||
use App\Service\InvoiceGeneratorInterface;
|
use App\Service\InvoiceGeneratorInterface;
|
||||||
|
|
||||||
|
|
@ -105,6 +106,13 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface
|
||||||
// break;
|
// break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// process service charges if any
|
||||||
|
$service_charges = $criteria->getServiceCharges();
|
||||||
|
if (count($service_charges) > 0)
|
||||||
|
{
|
||||||
|
$this->processServiceCharges($total, $criteria, $invoice);
|
||||||
|
}
|
||||||
|
|
||||||
// get current user
|
// get current user
|
||||||
$user = $this->security->getUser();
|
$user = $this->security->getUser();
|
||||||
if ($user != null)
|
if ($user != null)
|
||||||
|
|
@ -286,6 +294,28 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function invoiceServiceCharges(InvoiceCriteria $criteria, $service_charges)
|
||||||
|
{
|
||||||
|
if (!empty($service_charges))
|
||||||
|
{
|
||||||
|
foreach ($service_charges as $service_charge)
|
||||||
|
{
|
||||||
|
// check if valid service charge
|
||||||
|
$sc = $this->em->getRepository(ServiceCharge::class)->find($service_charge['id']);
|
||||||
|
|
||||||
|
if (empty($sc))
|
||||||
|
{
|
||||||
|
$error = 'Invalid service charge specified.';
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
$criteria->addServiceCharge($sc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function processEntries(&$total, InvoiceCriteria $criteria, Invoice $invoice)
|
protected function processEntries(&$total, InvoiceCriteria $criteria, Invoice $invoice)
|
||||||
{
|
{
|
||||||
|
|
@ -604,4 +634,23 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface
|
||||||
$total['vat'] = $vat;
|
$total['vat'] = $vat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function processServiceCharges(&$total, InvoiceCriteria $criteria, Invoice $invoice)
|
||||||
|
{
|
||||||
|
$service_charges = $criteria->getServiceCharges();
|
||||||
|
|
||||||
|
foreach ($service_charges as $service_charge)
|
||||||
|
{
|
||||||
|
$amount = $service_charge->getAmount();
|
||||||
|
|
||||||
|
$total['total_price'] += $amount;
|
||||||
|
// add item
|
||||||
|
$item = new InvoiceItem();
|
||||||
|
$item->setInvoice($invoice)
|
||||||
|
->setTitle('Service Charge - ' . $service_charge->getName())
|
||||||
|
->setQuantity(1)
|
||||||
|
->setPrice($amount);
|
||||||
|
|
||||||
|
$invoice->addItem($item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue