Add trade in type for cmb. #270

This commit is contained in:
Korina Cordero 2019-10-09 06:35:11 +00:00
parent a9ed02b0b2
commit 610bbdcc7c
7 changed files with 79 additions and 138 deletions

View file

@ -153,62 +153,72 @@ class JobOrderController extends Controller
/**
* @Menu(selected="jo_proc")
*/
public function listProcessing()
public function listProcessing(JobOrderHandlerInterface $jo_handler)
{
$this->denyAccessUnlessGranted('jo_proc.list', null, 'No access.');
$template = $jo_handler->getTwigTemplate('jo_list_processing');
$params['table_refresh_rate'] = $this->container->getParameter('job_order_refresh_interval');
return $this->render('job-order/list.processing.html.twig', $params);
return $this->render($template, $params);
}
/**
* @Menu(selected="jo_assign")
*/
public function listAssigning()
public function listAssigning(JobOrderHandlerInterface $jo_handler)
{
$this->denyAccessUnlessGranted('jo_assign.list', null, 'No access.');
$template = $jo_handler->getTwigTemplate('jo_list_assigning');
$params['table_refresh_rate'] = $this->container->getParameter('job_order_refresh_interval');
return $this->render('job-order/list.assigning.html.twig', $params);
return $this->render($template, $params);
}
/**
* @Menu(selected="jo_fulfill")
*/
public function listFulfillment()
public function listFulfillment(JobOrderHandlerInterface $jo_handler)
{
$this->denyAccessUnlessGranted('jo_fulfill.list', null, 'No access.');
$template = $jo_handler->getTwigTemplate('jo_list_fulfillment');
$params['table_refresh_rate'] = $this->container->getParameter('job_order_refresh_interval');
return $this->render('job-order/list.fulfillment.html.twig', $params);
return $this->render($template, $params);
}
/**
* @Menu(selected="jo_open")
*/
public function listOpen()
public function listOpen(JobOrderHandlerInterface $jo_handler)
{
$this->denyAccessUnlessGranted('jo_open.list', null, 'No access.');
$template = $jo_handler->getTwigTemplate('jo_list_open');
$params['table_refresh_rate'] = $this->container->getParameter('job_order_refresh_interval');
$params['statuses'] = JOStatus::getCollection();
return $this->render('job-order/list.open.html.twig', $params);
return $this->render($template, $params);
}
/**
* @Menu(selected="jo_all")
*/
public function listAll()
public function listAll(JobOrderHandlerInterface $jo_handler)
{
$this->denyAccessUnlessGranted('jo_all.list', null, 'No access.');
$template = $jo_handler->getTwigTemplate('jo_list_all');
$params['table_refresh_rate'] = $this->container->getParameter('job_order_refresh_interval');
return $this->render('job-order/list.all.html.twig', $params);
return $this->render($template, $params);
}
/*
@ -645,74 +655,6 @@ class JobOrderController extends Controller
}
protected function invoicePromo($em, InvoiceCriteria $criteria, $promo_id)
{
// return error if there's a problem, false otherwise
// check service type
$stype = $criteria->getServiceType();
if ($stype != ServiceType::BATTERY_REPLACEMENT_NEW)
return null;
if (empty($promo_id))
return false;
// check if this is a valid promo
$promo = $em->getRepository(Promo::class)->find($promo_id);
if (empty($promo))
return 'Invalid promo specified.';
$criteria->addPromo($promo);
return false;
}
protected function invoiceBatteries($em, InvoiceCriteria $criteria, $items)
{
// check service type
$stype = $criteria->getServiceType();
if ($stype != ServiceType::BATTERY_REPLACEMENT_NEW && $stype != ServiceType::BATTERY_REPLACEMENT_WARRANTY)
return null;
// return error if there's a problem, false otherwise
if (!empty($items))
{
foreach ($items as $item)
{
// error_log('ITEMS');
// check if this is a valid battery
$battery = $em->getRepository(Battery::class)->find($item['battery']);
if (empty($battery))
{
$error = 'Invalid battery specified.';
return $error;
}
// quantity
$qty = $item['quantity'];
if ($qty < 1)
continue;
/*
// add to criteria
$criteria->addBattery($battery, $qty);
*/
// if this is a trade in, add trade in
if (!empty($item['trade_in']) && TradeInType::validate($item['trade_in']))
$trade_in = $item['trade_in'];
else
$trade_in = null;
$criteria->addEntry($battery, $trade_in, $qty);
}
}
return null;
}
public function generateInvoice(Request $req, InvoiceGeneratorInterface $ic)
{
// error_log('generating invoice...');
@ -763,11 +705,11 @@ class JobOrderController extends Controller
}
*/
$error = $this->invoicePromo($em, $criteria, $promo_id);
// TODO: this snippet should be in the invoice generator
$error = $ic->invoicePromo($criteria, $promo_id);
if (!$error)
$error = $this->invoiceBatteries($em, $criteria, $items);
$error = $ic->invoiceBatteries($criteria, $items);
if ($error)
{

View file

@ -0,0 +1,13 @@
<?php
namespace App\Ramcar;
class CMBTradeInType extends NameValue
{
const REGULAR = 'regular';
const COLLECTION = [
'regular' => 'Regular',
];
}

View file

@ -9,7 +9,7 @@ use Doctrine\ORM\EntityManagerInterface;
use App\Ramcar\InvoiceCriteria;
use App\Ramcar\InvoiceStatus;
use App\Ramcar\TradeInType;
use App\Ramcar\CMBTradeInType;
use App\Ramcar\DiscountApply;
use App\Ramcar\ServiceType;
use App\Ramcar\FuelType;
@ -66,7 +66,6 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface
$stype = $criteria->getServiceType();
$cv = $criteria->getCustomerVehicle();
$has_coolant = $criteria->hasCoolant();
// error_log($stype);
switch ($stype)
{
case ServiceType::JUMPSTART_TROUBLESHOOT:
@ -216,18 +215,16 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface
switch ($trade_in)
{
case TradeInType::MOTOLITE:
// TODO: for now, REGULAR uses getTIPriceMotolite.
// Might need to modify later
case CMBTradeInType::REGULAR:
return $size->getTIPriceMotolite();
case TradeInType::PREMIUM:
return $size->getTIPricePremium();
case TradeInType::OTHER:
return $size->getTIPriceOther();
}
return 0;
}
protected function invoicePromo(InvoiceCriteria $criteria, $promo_id)
public function invoicePromo(InvoiceCriteria $criteria, $promo_id)
{
// return error if there's a problem, false otherwise
// check service type
@ -251,7 +248,7 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface
return false;
}
protected function invoiceBatteries(InvoiceCriteria $criteria, $items)
public function invoiceBatteries(InvoiceCriteria $criteria, $items)
{
// check service type
$stype = $criteria->getServiceType();
@ -283,7 +280,7 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface
*/
// if this is a trade in, add trade in
if (!empty($item['trade_in']) && TradeInType::validate($item['trade_in']))
if (!empty($item['trade_in']) && CMBTradeInType::validate($item['trade_in']))
$trade_in = $item['trade_in'];
else
$trade_in = null;
@ -382,7 +379,7 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface
// add item
$item = new InvoiceItem();
$item->setInvoice($invoice)
->setTitle('Trade-in ' . TradeInType::getName($ti['trade_in']) . ' ' . $ti['size']->getName() . ' battery')
->setTitle('Trade-in ' . CMBTradeInType::getName($ti['trade_in']) . ' ' . $ti['size']->getName() . ' battery')
->setQuantity($qty)
->setPrice($ti_rate * -1);

View file

@ -225,7 +225,7 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface
return 0;
}
protected function invoicePromo(InvoiceCriteria $criteria, $promo_id)
public function invoicePromo(InvoiceCriteria $criteria, $promo_id)
{
// return error if there's a problem, false otherwise
// check service type
@ -249,7 +249,7 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface
return false;
}
protected function invoiceBatteries(InvoiceCriteria $criteria, $items)
public function invoiceBatteries(InvoiceCriteria $criteria, $items)
{
// check service type
$stype = $criteria->getServiceType();

View file

@ -26,7 +26,7 @@ use App\Entity\JORejection;
use App\Ramcar\InvoiceCriteria;
use App\Ramcar\ServiceType;
use App\Ramcar\TradeInType;
use App\Ramcar\CMBTradeInType;
use App\Ramcar\JOEventType;
use App\Ramcar\JOStatus;
use App\Ramcar\WarrantyClass;
@ -1937,6 +1937,17 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
return $params;
}
public function getTwigTemplate($id)
{
if (isset($this->template_hash[$id]))
{
return $this->template_hash[$id];
}
return null;
}
protected function fillDropdownParameters(&$params)
{
$em = $this->em;
@ -1954,14 +1965,14 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
}
// get the first two service types for POC
$scount = 0;
$scount = 1;
$selected_stypes = [];
$stypes = ServiceType::getCollection();
foreach ($stypes as $stype)
foreach ($stypes as $key => $data)
{
if ($scount < 2)
$selected_stypes[] = $stype;
$selected_stypes[$key] = $data;
else
break;
@ -1969,13 +1980,13 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
}
// name values
// $params['service_types'] = ServiceType::getCollection();
//$params['service_types'] = ServiceType::getCollection();
$params['service_types'] = $selected_stypes;
$params['warranty_classes'] = WarrantyClass::getCollection();
$params['modes_of_payment'] = ModeOfPayment::getCollection();
$params['statuses'] = JOStatus::getCollection();
$params['discount_apply'] = DiscountApply::getCollection();
$params['trade_in_types'] = TradeInType::getCollection();
$params['trade_in_types'] = CMBTradeInType::getCollection();
$params['facilitated_types'] = FacilitatedType::getCollection();
$params['facilitated_hubs'] = $fac_hubs;
$params['sources'] = TransactionOrigin::getCollection();
@ -2043,16 +2054,6 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
$this->template_hash['jo_list_all'] = 'job-order/list.all.html.twig';
}
protected function getTwigTemplate($id)
{
if (isset($this->template_hash[$id]))
{
return $this->template_hash[$id];
}
return null;
}
protected function checkTier($tier)
{
// check specified tier

View file

@ -53,7 +53,7 @@ use FPDF;
class ResqJobOrderHandler implements JobOrderHandlerInterface
{
const COUNTRY_CODE_PREFIX = '+63';
const COUNTRY_CODE_PREFIX = '+60';
protected $em;
protected $ic;
@ -1937,6 +1937,17 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
return $params;
}
public function getTwigTemplate($id)
{
if (isset($this->template_hash[$id]))
{
return $this->template_hash[$id];
}
return null;
}
protected function fillDropdownParameters(&$params)
{
$em = $this->em;
@ -1953,24 +1964,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$fac_hubs[$hub->getID()] = $hub->getName() . ' - ' . $hub->getBranch();
}
// get the first two service types for POC
$scount = 0;
$selected_stypes = [];
$stypes = ServiceType::getCollection();
foreach ($stypes as $stype)
{
if ($scount < 2)
$selected_stypes[] = $stype;
else
break;
$scount++;
}
// name values
// $params['service_types'] = ServiceType::getCollection();
$params['service_types'] = $selected_stypes;
$params['service_types'] = ServiceType::getCollection();
$params['warranty_classes'] = WarrantyClass::getCollection();
$params['modes_of_payment'] = ModeOfPayment::getCollection();
$params['statuses'] = JOStatus::getCollection();
@ -2043,16 +2038,6 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$this->template_hash['jo_list_all'] = 'job-order/list.all.html.twig';
}
protected function getTwigTemplate($id)
{
if (isset($this->template_hash[$id]))
{
return $this->template_hash[$id];
}
return null;
}
protected function checkTier($tier)
{
// check specified tier

View file

@ -75,4 +75,7 @@ interface JobOrderHandlerInterface
// generate pdf form for job order
public function generatePDFForm(Request $req, int $id, string $proj_path);
// get template to display
public function getTwigTemplate(string $id);
}