Create interface for invoice creator. #265

This commit is contained in:
Korina Cordero 2019-09-19 07:28:48 +00:00
parent 37a8309943
commit f1cc1dfae1
6 changed files with 97 additions and 30 deletions

View file

@ -130,3 +130,9 @@ services:
$menu_name: "main_menu"
tags:
- { name: kernel.event_listener, event: kernel.controller, method: onKernelController }
# invoice creator
App\Service\InvoiceCreator\CMBInvoiceCreator: ~
# invoice creator interface
App\Service\InvoiceCreatorInterface: "@App\\Service\\InvoiceCreator\\CMBInvoiceCreator"

View file

@ -24,7 +24,7 @@ use App\Ramcar\TransactionOrigin;
use App\Ramcar\TradeInType;
use App\Ramcar\JOEventType;
use App\Service\InvoiceCreator;
use App\Service\InvoiceCreatorInterface;
use App\Service\RisingTideGateway;
use App\Service\MQTTClient;
use App\Service\GeofenceTracker;
@ -808,7 +808,7 @@ class APIController extends Controller
return $res->getReturnResponse();
}
public function requestJobOrder(Request $req, InvoiceCreator $ic, GeofenceTracker $geo)
public function requestJobOrder(Request $req, InvoiceCreatorInterface $ic, GeofenceTracker $geo)
{
// check required parameters and api key
$required_params = [
@ -1020,7 +1020,7 @@ class APIController extends Controller
return $res->getReturnResponse();
}
public function getEstimate(Request $req, InvoiceCreator $ic)
public function getEstimate(Request $req, InvoiceCreatorInterface $ic)
{
// $this->debugRequest($req);

View file

@ -27,7 +27,7 @@ use App\Entity\Battery;
use App\Entity\JOEvent;
use App\Entity\JORejection;
use App\Service\InvoiceCreator;
use App\Service\InvoiceCreatorInterface;
use App\Service\MapTools;
use App\Service\HubCounter;
use App\Service\MQTTClient;
@ -251,7 +251,7 @@ class JobOrderController extends Controller
return $this->render('job-order/form.html.twig', $params);
}
public function openEditSubmit(Request $req, ValidatorInterface $validator, InvoiceCreator $ic, $id)
public function openEditSubmit(Request $req, ValidatorInterface $validator, InvoiceCreatorInterface $ic, $id)
{
$this->denyAccessUnlessGranted('jo_open.edit', null, 'No access.');
@ -425,7 +425,7 @@ class JobOrderController extends Controller
return $this->render('job-order/form.html.twig', $params);
}
public function incomingSubmit(Request $req, ValidatorInterface $validator, InvoiceCreator $ic)
public function incomingSubmit(Request $req, ValidatorInterface $validator, InvoiceCreatorInterface $ic)
{
$this->denyAccessUnlessGranted('jo_in.list', null, 'No access.');
@ -2482,7 +2482,7 @@ class JobOrderController extends Controller
return null;
}
public function generateInvoice(Request $req, InvoiceCreator $ic)
public function generateInvoice(Request $req, InvoiceCreatorInterface $ic)
{
// error_log('generating invoice...');
$error = false;

View file

@ -25,7 +25,7 @@ use App\Ramcar\InvoiceStatus;
use App\Ramcar\ModeOfPayment;
use App\Ramcar\JOEventType;
use App\Service\InvoiceCreator;
use App\Service\InvoiceCreatorInterface;
use App\Service\MQTTClient;
use App\Entity\RiderSession;
@ -739,7 +739,7 @@ class RAPIController extends Controller
error_log(print_r($all, true));
}
public function changeService(Request $req, InvoiceCreator $ic)
public function changeService(Request $req, InvoiceCreatorInterface $ic)
{
$this->debugRequest($req);

View file

@ -1,6 +1,6 @@
<?php
namespace App\Service;
namespace App\Service\InvoiceCreator;
use App\Ramcar\InvoiceCriteria;
use App\Ramcar\TradeInType;
@ -12,28 +12,31 @@ use App\Entity\Invoice;
use App\Entity\InvoiceItem;
use App\Entity\User;
use App\Service\InvoiceCreatorInterface;
use Doctrine\Common\Util\Debug;
class InvoiceCreator
class CMBInvoiceCreator implements InvoiceCreatorInterface
{
const VAT_RATE = 0.12;
const TAX_RATE = 0.12;
const SERVICE_FEE = 300;
const RECHARGE_FEE = 300;
// creates invoice based on the criteria sent
public function __construct()
{
}
public function getVATAmount($price)
public function getTaxAmount($price)
{
$vat_ex_price = $this->getVATExclusivePrice($price);
$vat_ex_price = $this->getTaxExclusivePrice($price);
return $price - $vat_ex_price;
// return round($vat_ex_price * self::VAT_RATE, 2);
// return round($vat_ex_price * self::TAX_RATE, 2);
}
public function getVATExclusivePrice($price)
public function getTaxExclusivePrice($price)
{
return round($price / (1 + self::VAT_RATE), 2);
return round($price / (1 + self::TAX_RATE), 2);
}
public function getTradeInRate($ti)
@ -57,7 +60,7 @@ class InvoiceCreator
return 0;
}
protected function processEntries(&$total, InvoiceCriteria $criteria, Invoice $invoice)
public function processEntries(&$total, InvoiceCriteria $criteria, Invoice $invoice)
{
// error_log('processing entries...');
$entries = $criteria->getEntries();
@ -100,7 +103,7 @@ class InvoiceCreator
$this->processTradeIns($total, $con_tis, $invoice);
}
protected function processBatteries(&$total, $con_batts, Invoice $invoice)
public function processBatteries(&$total, $con_batts, Invoice $invoice)
{
// process batteries
foreach ($con_batts as $con_data)
@ -109,8 +112,8 @@ class InvoiceCreator
$qty = $con_data['qty'];
$sell_price = $batt->getSellingPrice();
$vat = $this->getVATAmount($sell_price);
// $vat_ex_price = $this->getVATExclusivePrice($sell_price);
$vat = $this->getTaxAmount($sell_price);
// $vat_ex_price = $this->getTaxExclusivePrice($sell_price);
$total['sell_price'] += $sell_price * $qty;
$total['vat'] += $vat * $qty;
@ -130,7 +133,7 @@ class InvoiceCreator
}
}
protected function processTradeIns(&$total, $con_tis, Invoice $invoice)
public function processTradeIns(&$total, $con_tis, Invoice $invoice)
{
foreach ($con_tis as $ti)
{
@ -151,7 +154,7 @@ class InvoiceCreator
}
}
protected function processDiscount(&$total, InvoiceCriteria $criteria, Invoice $invoice)
public function processDiscount(&$total, InvoiceCriteria $criteria, Invoice $invoice)
{
$promos = $criteria->getPromos();
if (count($promos) < 1)
@ -224,12 +227,12 @@ class InvoiceCreator
$item->setInvoice($invoice)
->setTitle('Recharge fee')
->setQuantity(1)
->setPrice(300.00);
->setPrice(self::RECHARGE_FEE);
$invoice->addItem($item);
$total['sell_price'] = 300.00;
$total['vat_ex_price'] = 300.00;
$total['total_price'] = 300.00;
$total['sell_price'] = self::RECHARGE_FEE;
$total['vat_ex_price'] = self::RECHARGE_FEE;
$total['total_price'] = self::RECHARGE_FEE;
}
public function processReplacement(&$total, $invoice)
@ -301,7 +304,7 @@ class InvoiceCreator
$total_price += 1600;
}
$vat_ex_price = $this->getVATExclusivePrice($total_price);
$vat_ex_price = $this->getTaxExclusivePrice($total_price);
$vat = $total_price - $vat_ex_price;
$total['total_price'] = $total_price;
$total['vat_ex_price'] = $vat_ex_price;
@ -324,7 +327,7 @@ class InvoiceCreator
$invoice->addItem($item);
$total_price = $fee;
$vat_ex_price = $this->getVATExclusivePrice($total_price);
$vat_ex_price = $this->getTaxExclusivePrice($total_price);
$vat = $total_price - $vat_ex_price;
$total['total_price'] = $total_price;
$total['vat_ex_price'] = $vat_ex_price;
@ -385,7 +388,7 @@ class InvoiceCreator
break;
}
$vat_ex_price = $this->getVATExclusivePrice($total_price);
$vat_ex_price = $this->getTaxExclusivePrice($total_price);
$vat = $total_price - $vat_ex_price;
$total['total_price'] = $total_price;
$total['vat_ex_price'] = $vat_ex_price;

View file

@ -0,0 +1,58 @@
<?php
namespace App\Service;
use App\Entity\Invoice;
use App\Ramcar\InvoiceCriteria;
interface InvoiceCreatorInterface
{
// process invoice criteria
public function processCriteria(InvoiceCriteria $criteria);
// process entries for invoice
public function processEntries(&$total, InvoiceCriteria $criteria, Invoice $invoice);
// process batteries
public function processBatteries(&$total, $con_batts, Invoice $invoice);
// get tradein rates
public function getTradeInRate($ti);
// process discounts
public function processDiscount(&$total, InvoiceCriteria $criteria, Invoice $invoice);
// process jumpstart service charges
public function processJumpstart(&$total, $invoice);
// process jumpstart service charges with warranty
public function processJumpstartWarranty(&$total, $invoice);
// process recharge costs
public function processRecharge(&$total, $invoice);
// process replacement charges
public function processReplacement(&$total, $invoice);
// process warranty charges
public function processWarranty(&$total, InvoiceCriteria $criteria, $invoice);
// process other charges
public function processOtherServices(&$total, $invoice, $stype);
// process overheat charges
public function processOverheat(&$total, $invoice, $cv, $has_coolant);
// process tire repair charges
public function processTireRepair(&$total, $invoice, $cv);
// process refuel charges
public function processRefuel(&$total, $invoice, $cv);
// compute tax
public function getTaxAmount($price);
// compute price without tax
public function getTaxExclusivePrice($price);
}