Merge branch '746-resq-2-0-final' of gitlab.com:jankstudio/resq into 759-add-inventory-column-to-job-order-details-report

This commit is contained in:
Korina Cordero 2023-08-25 00:25:28 +00:00
commit f98b3e170c
30 changed files with 1071 additions and 103 deletions

View file

@ -618,6 +618,20 @@ catalyst_auth:
- id: ownership_type.delete
label: Delete
- id: service_offering
label: Service Offering Access
acls:
- id: service_offering.menu
label: Menu
- id: service_offering.list
label: List
- id: service_offering.add
label: Add
- id: service_offering.update
label: Update
- id: service_offering.delete
label: Delete
api:
user_entity: "App\\Entity\\ApiUser"
acl_data:

View file

@ -280,3 +280,7 @@ catalyst_menu:
acl: ownership_type.menu
label: '[menu.database.ownershiptypes]'
parent: database
- id: service_offering_list
acl: service_offering.menu
label: '[menu.database.serviceofferings]'
parent: database

View file

@ -0,0 +1,34 @@
service_offering_list:
path: /service-offerings
controller: App\Controller\ServiceOfferingController::index
methods: [GET]
service_offering_rows:
path: /service-offerings/rowdata
controller: App\Controller\ServiceOfferingController::datatableRows
methods: [POST]
service_offering_add_form:
path: /service-offerings/newform
controller: App\Controller\ServiceOfferingController::addForm
methods: [GET]
service_offering_add_submit:
path: /service-offerings
controller: App\Controller\ServiceOfferingController::addSubmit
methods: [POST]
service_offering_update_form:
path: /service-offerings/{id}
controller: App\Controller\ServiceOfferingController::updateForm
methods: [GET]
service_offering_update_submit:
path: /service-offerings/{id}
controller: App\Controller\ServiceOfferingController::updateSubmit
methods: [POST]
service_offering_delete:
path: /service-offerings/{id}
controller: App\Controller\ServiceOfferingController::deleteSubmit
methods: [DELETE]

View file

@ -1035,6 +1035,10 @@ class APIController extends Controller implements LoggedController
// set if taxable
$icrit->setIsTaxable();
// set JO source
// old app doesn't have separate jumpstart
$icrit->setSource(TransactionOrigin::CALL);
// send to invoice generator
$invoice = $ic->generateInvoice($icrit);
$jo->setInvoice($invoice);
@ -1317,6 +1321,10 @@ class APIController extends Controller implements LoggedController
// set taxable
$icrit->setIsTaxable(true);
// set JO source
// old app doesn't have separate jumpstart
$icrit->setSource(TransactionOrigin::CALL);
// check trade-in
// only allow motolite, other, none
$trade_in = $req->request->get('trade_in');
@ -2882,6 +2890,10 @@ class APIController extends Controller implements LoggedController
// set taxable
$icrit->setIsTaxable(true);
// set JO source
// old app doesn't have separate jumpstart
$icrit->setSource(TransactionOrigin::CALL);
// check promo
$promo_id = $req->request->get('promo_id');
if (!empty($promo_id))

View file

@ -8,6 +8,7 @@ use Catalyst\ApiBundle\Component\Response as ApiResponse;
use App\Service\InvoiceGeneratorInterface;
use App\Ramcar\InvoiceCriteria;
use App\Ramcar\TradeInType;
use App\Ramcar\TransactionOrigin;
use App\Entity\CustomerVehicle;
use App\Entity\Promo;
use App\Entity\Battery;
@ -101,6 +102,9 @@ class InvoiceController extends ApiController
// set if taxable
$icrit->setIsTaxable();
// set JO source
$icrit->setSource(TransactionOrigin::MOBILE_APP);
// send to invoice generator
$invoice = $ic->generateInvoice($icrit);

View file

@ -682,6 +682,9 @@ class JobOrderController extends ApiController
// set taxable
$icrit->setIsTaxable();
// set JO source
$icrit->setSource(TransactionOrigin::MOBILE_APP);
// send to invoice generator
$invoice = $ic->generateInvoice($icrit);
$jo->setInvoice($invoice);
@ -1087,6 +1090,9 @@ class JobOrderController extends ApiController
// set taxable
$icrit->setIsTaxable();
// set JO source
$icrit->setSource(TransactionOrigin::MOBILE_APP);
$icrit->addEntry($batt, $trade_in, 1);
// send to invoice generator

View file

@ -7,6 +7,7 @@ use App\Ramcar\InvoiceCriteria;
use App\Ramcar\CMBServiceType;
use App\Ramcar\ServiceType;
use App\Ramcar\JOCancelReasons;
use App\Ramcar\TransactionOrigin;
use App\Entity\CustomerVehicle;
use App\Entity\Promo;
@ -738,7 +739,8 @@ class JobOrderController extends Controller
$criteria = new InvoiceCriteria();
$criteria->setServiceType($stype)
->setCustomerVehicle($cv)
->setIsTaxable();
->setIsTaxable()
->setSource(TransactionOrigin::CALL);
/*

View file

@ -0,0 +1,252 @@
<?php
namespace App\Controller;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Catalyst\MenuBundle\Annotation\Menu;
use App\Entity\ServiceOffering;
class ServiceOfferingController extends Controller
{
/**
* @Menu(selected="service_offering_list")
* @IsGranted("service_offering.list")
*/
public function index()
{
return $this->render('service-offering/list.html.twig');
}
/**
* @IsGranted("service_offering.list")
*/
public function datatableRows(Request $req)
{
// get query builder
$qb = $this->getDoctrine()
->getRepository(ServiceOffering::class)
->createQueryBuilder('q');
// get datatable params
$datatable = $req->request->get('datatable');
// count total records
$tquery = $qb->select('COUNT(q)');
$this->setQueryFilters($datatable, $tquery);
$total = $tquery->getQuery()
->getSingleScalarResult();
// get current page number
$page = $datatable['pagination']['page'] ?? 1;
$perpage = $datatable['pagination']['perpage'];
$offset = ($page - 1) * $perpage;
// add metadata
$meta = [
'page' => $page,
'perpage' => $perpage,
'pages' => ceil($total / $perpage),
'total' => $total,
'sort' => 'asc',
'field' => 'id'
];
// build query
$query = $qb->select('q');
$this->setQueryFilters($datatable, $query);
// check if sorting is present, otherwise use default
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
$order = $datatable['sort']['sort'] ?? 'asc';
$query->orderBy('q.' . $datatable['sort']['field'], $order);
} else {
$query->orderBy('q.id', 'asc');
}
// get rows for this page
$obj_rows = $query->setFirstResult($offset)
->setMaxResults($perpage)
->getQuery()
->getResult();
// process rows
$rows = [];
foreach ($obj_rows as $orow) {
// add row data
$row['id'] = $orow->getID();
$row['name'] = $orow->getName();
$row['fee'] = $orow->getFee();
// add row metadata
$row['meta'] = [
'update_url' => '',
'delete_url' => ''
];
// add crud urls
if ($this->isGranted('service_offering.update'))
$row['meta']['update_url'] = $this->generateUrl('service_offering_update_form', ['id' => $row['id']]);
if ($this->isGranted('service_offering.delete'))
$row['meta']['delete_url'] = $this->generateUrl('service_offering_delete', ['id' => $row['id']]);
$rows[] = $row;
}
// response
return $this->json([
'meta' => $meta,
'data' => $rows
]);
}
/**
* @Menu(selected="service_offering.list")
* @IsGranted("service_offering.add")
*/
public function addForm()
{
$service_offering = new ServiceOffering();
$params = [
'service_offering' => $service_offering,
'mode' => 'create',
];
// response
return $this->render('service-offering/form.html.twig', $params);
}
/**
* @IsGranted("service_offering.add")
*/
public function addSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator)
{
$service_offering = new ServiceOffering();
$this->setObject($service_offering, $req);
// validate
$errors = $validator->validate($service_offering);
// initialize error list
$error_array = [];
// add errors to list
foreach ($errors as $error) {
$error_array[$error->getPropertyPath()] = $error->getMessage();
}
// check if any errors were found
if (!empty($error_array)) {
// return validation failure response
return $this->json([
'success' => false,
'errors' => $error_array
], 422);
}
// validated! save the entity
$em->persist($service_offering);
$em->flush();
// return successful response
return $this->json([
'success' => 'Changes have been saved!'
]);
}
/**
* @Menu(selected="service_offering_list")
* @ParamConverter("service_offering", class="App\Entity\ServiceOffering")
* @IsGranted("service_offering.update")
*/
public function updateForm($id, EntityManagerInterface $em, ServiceOffering $service_offering)
{
$params = [];
$params['service_offering'] = $service_offering;
$params['mode'] = 'update';
// response
return $this->render('service-offering/form.html.twig', $params);
}
/**
* @ParamConverter("service_offering", class="App\Entity\ServiceOffering")
* @IsGranted("service_offering.update")
*/
public function updateSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator, ServiceOffering $service_offering)
{
$this->setObject($service_offering, $req);
// validate
$errors = $validator->validate($service_offering);
// initialize error list
$error_array = [];
// add errors to list
foreach ($errors as $error) {
$error_array[$error->getPropertyPath()] = $error->getMessage();
}
// check if any errors were found
if (!empty($error_array)) {
// return validation failure response
return $this->json([
'success' => false,
'errors' => $error_array
], 422);
}
// validated! save the entity
$em->flush();
// return successful response
return $this->json([
'success' => 'Changes have been saved!'
]);
}
/**
* @ParamConverter("service_offering", class="App\Entity\ServiceOffering")
* @IsGranted("service_offering.delete")
*/
public function deleteSubmit(EntityManagerInterface $em, ServiceOffering $service_offering)
{
// delete this object
$em->remove($service_offering);
$em->flush();
// response
$response = new Response();
$response->setStatusCode(Response::HTTP_OK);
$response->send();
}
protected function setObject(ServiceOffering $obj, Request $req)
{
// set and save values
$obj->setName($req->request->get('name'))
->setCode($req->request->get('code'))
->setFee($req->request->get('fee'));
}
protected function setQueryFilters($datatable, QueryBuilder $query)
{
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
$query->where('q.name LIKE :filter')
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
}
}
}

View file

@ -160,6 +160,9 @@ class JobOrderController extends ApiController
// set taxable
$icrit->setIsTaxable();
// set JO source
$icrit->setSource(TransactionOrigin::THIRD_PARTY);
$icrit->addEntry($data['batt'], $data['trade_in_type'], 1);
// send to invoice generator
@ -449,6 +452,12 @@ class JobOrderController extends ApiController
$icrit->addEntry($data['battery'], $data['trade_in_type'], 1);
// set taxable
$icrit->setIsTaxable();
// set JO source
$icrit->setSource('third_party');
// send to invoice generator
$invoice = $ic->generateInvoice($icrit);

View file

@ -0,0 +1,81 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="service_offering", indexes={
* @ORM\Index(name="service_offering_idx", columns={"code"}),
* })
*/
class ServiceOffering
{
// unique id
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank()
*/
protected $name;
/**
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank()
*/
protected $code;
// service fee
/**
* @ORM\Column(type="decimal", precision=9, scale=2)
*/
protected $fee;
public function getID()
{
return $this->id;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->name;
}
public function setCode($code)
{
$this->code = $code;
return $this;
}
public function getCode()
{
return $this->code;
}
public function setFee($fee)
{
$this->fee = $fee;
return $this;
}
public function getFee()
{
return $this->fee;
}
}

View file

@ -10,6 +10,7 @@ use App\Ramcar\ServiceType;
use App\Ramcar\TradeInType;
use App\Entity\Battery;
use App\Entity\ServiceOffering;
class BatteryReplacementWarranty implements InvoiceRuleInterface
{
@ -59,10 +60,16 @@ class BatteryReplacementWarranty implements InvoiceRuleInterface
public function getServiceTypeFee()
{
// TODO: we need to to put this somewhere like in .env
// so that if any chanages are to be made, we just edit the file
// instead of the code
$code = 'battery_replacement_warranty_fee';
// find the service fee using the code
// if we can't find the fee, return 0
$fee = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
if ($fee == null)
return 0;
return $fee->getFee();
}
public function validatePromo($criteria, $promo_id)

View file

@ -2,13 +2,25 @@
namespace App\InvoiceRule;
use Doctrine\ORM\EntityManagerInterface;
use App\InvoiceRuleInterface;
use App\Ramcar\FuelType;
use App\Ramcar\ServiceType;
use App\Entity\ServiceOffering;
use App\Entity\CustomerVehicle;
class Fuel implements InvoiceRuleInterface
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function getID()
{
return 'fuel';
@ -22,12 +34,9 @@ class Fuel implements InvoiceRuleInterface
if ($stype == $this->getID())
{
// check if customer vehicle has a motolite battery
$cv = $criteria->getCustomerVehicle();
if ($cv->hasMotoliteBattery())
$fee = 0;
else
$fee = $this->getServiceTypeFee();
$fee = $this->getServiceTypeFee($cv);
$ftype = $cv->getFuelType();
@ -82,29 +91,41 @@ class Fuel implements InvoiceRuleInterface
return $items;
}
public function getServiceTypeFee()
public function getServiceTypeFee(CustomerVehicle $cv)
{
// TODO: we need to to put this somewhere like in .env
// so that if any changes are to be made, we just edit the file
// instead of the code
return 300;
// check if customer vehicle has a motolite battery
// if yes, set the code to the motolite user service fee
if ($cv->hasMotoliteBattery())
$code = 'motolite_user_service_fee';
else
$code = 'fuel_service_fee';
// find the service fee using the code
// if we can't find the fee, return 0
$fee = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
if ($fee == null)
return 0;
return $fee->getFee();
}
public function getFuelFee($fuel_type)
{
// TODO: we need to to put this somewhere like in .env
// so that if any changes are to be made, we just edit the file
// instead of the code
$code = '';
if ($fuel_type == FuelType::GAS)
{
// gas fuel fee
return 340;
}
else
{
// diesel fuel fee
return 300;
}
$code = 'fuel_gas_fee';
if ($fuel_type == FuelType::DIESEL)
$code = 'fuel_diesel_fee';
// find the fuel fee for the specific fuel type using the code
// if we can't find the fee, return 0
$fee = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
if ($fee == null)
return 0;
return $fee->getFee();
}
public function validatePromo($criteria, $promo_id)

View file

@ -2,10 +2,23 @@
namespace App\InvoiceRule;
use Doctrine\ORM\EntityManagerInterface;
use App\InvoiceRuleInterface;
use App\Entity\ServiceOffering;
use App\Ramcar\TransactionOrigin;
class Jumpstart implements InvoiceRuleInterface
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function getID()
{
return 'jumpstart_troubleshoot';
@ -14,12 +27,13 @@ class Jumpstart implements InvoiceRuleInterface
public function compute($criteria, &$total)
{
$stype = $criteria->getServiceType();
$source = $criteria->getSource();
$items = [];
if ($stype == $this->getID())
{
$fee = $this->getServiceTypeFee();
$fee = $this->getServiceTypeFee($source);
// add the service fee to items
$qty = 1;
@ -37,12 +51,23 @@ class Jumpstart implements InvoiceRuleInterface
return $items;
}
public function getServiceTypeFee()
public function getServiceTypeFee($source)
{
// TODO: we need to to put this somewhere like in .env
// so that if any chanages are to be made, we just edit the file
// instead of the code
return 300;
// find the service fee for jumpstart using the code
// if we can't find the fee, return 0
// jumpstart fee depends on the JO source. Jumpstart from app has a different fee
// we set the code to search for the default
$code = 'jumpstart_fee';
if ($source == TransactionOrigin::MOBILE_APP)
$code = 'jumpstart_fee_mobile_app';
$fee = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
if ($fee == null)
return 0;
return $fee->getFee();
}
public function validatePromo($criteria, $promo_id)

View file

@ -2,10 +2,21 @@
namespace App\InvoiceRule;
use Doctrine\ORM\EntityManagerInterface;
use App\InvoiceRuleInterface;
use App\Entity\ServiceOffering;
class JumpstartWarranty implements InvoiceRuleInterface
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function getID()
{
return 'jumpstart_warranty';
@ -39,10 +50,16 @@ class JumpstartWarranty implements InvoiceRuleInterface
public function getServiceTypeFee()
{
// TODO: we need to to put this somewhere like in .env
// so that if any chanages are to be made, we just edit the file
// instead of the code
$code = 'jumpstart_warranty_fee';
// find the service fee using the code
// if we can't find the fee, return 0
$fee = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
if ($fee == null)
return 0;
return $fee->getFee();
}
public function validatePromo($criteria, $promo_id)

View file

@ -2,12 +2,24 @@
namespace App\InvoiceRule;
use Doctrine\ORM\EntityManagerInterface;
use App\InvoiceRuleInterface;
use App\Ramcar\ServiceType;
use App\Entity\ServiceOffering;
use App\Entity\CustomerVehicle;
class Overheat implements InvoiceRuleInterface
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function getID()
{
return 'overheat';
@ -22,12 +34,8 @@ class Overheat implements InvoiceRuleInterface
if ($stype == $this->getID())
{
// check if customer vehicle has a motolite battery
$cv = $criteria->getCustomerVehicle();
if ($cv->hasMotoliteBattery())
$fee = 0;
else
$fee = $this->getServiceTypeFee();
$fee = $this->getServiceTypeFee($cv);
// add the service fee to items
$qty = 1;
@ -61,20 +69,37 @@ class Overheat implements InvoiceRuleInterface
return $items;
}
public function getServiceTypeFee()
public function getServiceTypeFee(CustomerVehicle $cv)
{
// TODO: we need to to put this somewhere like in .env
// so that if any chanages are to be made, we just edit the file
// instead of the code
return 300;
$code = 'overheat_fee';
// check if customer vehicle has a motolite battery
// if yes, set the code to the motolite user service fee
if ($cv->hasMotoliteBattery())
$code = 'motolite_user_service_fee';
// find the service fee for overheat using the code
// if we can't find the fee, return 0
$fee = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
if ($fee == null)
return 0;
return $fee->getFee();
}
public function getCoolantFee()
{
// TODO: we need to to put this somewhere like in .env
// so that if any chanages are to be made, we just edit the file
// instead of the code
return 1600;
$code = 'coolant_fee';
// find the service fee using the code
// if we can't find the fee, return 0
$fee = $this->em->getRepository(ServiceOffering::class)->findOneBy($code);
if ($fee == null)
return 0;
return $fee->getFee();
}
public function validatePromo($criteria, $promo_id)

View file

@ -2,10 +2,21 @@
namespace App\InvoiceRule;
use Doctrine\ORM\EntityManagerInterface;
use App\InvoiceRuleInterface;
use App\Entity\ServiceOffering;
class PostRecharged implements InvoiceRuleInterface
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function getID()
{
return 'post_recharged';
@ -39,10 +50,16 @@ class PostRecharged implements InvoiceRuleInterface
public function getServiceTypeFee()
{
// TODO: we need to to put this somewhere like in .env
// so that if any chanages are to be made, we just edit the file
// instead of the code
return 300;
$code = 'post_recharged_fee';
// find the service fee for post recharged using the code
// if we can't find the fee, return 0
$fee = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
if ($fee == null)
return 0;
return $fee->getFee();
}
public function validatePromo($criteria, $promo_id)

View file

@ -2,10 +2,21 @@
namespace App\InvoiceRule;
use Doctrine\ORM\EntityManagerInterface;
use App\InvoiceRuleInterface;
use App\Entity\ServiceOffering;
class PostReplacement implements InvoiceRuleInterface
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function getID()
{
return 'post_replacement';
@ -38,10 +49,16 @@ class PostReplacement implements InvoiceRuleInterface
public function getServiceTypeFee()
{
// TODO: we need to to put this somewhere like in .env
// so that if any chanages are to be made, we just edit the file
// instead of the code
$code = 'post_replacement_fee';
// find the service fee using the code
// if we can't find the fee, return 0
$fee = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
if ($fee == null)
return 0;
return $fee->getFee();
}
public function validatePromo($criteria, $promo_id)

View file

@ -2,12 +2,23 @@
namespace App\InvoiceRule;
use Doctrine\ORM\EntityManagerInterface;
use App\InvoiceRuleInterface;
use App\Ramcar\ServiceType;
use App\Entity\ServiceOffering;
class Tax implements InvoiceRuleInterface
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function getID()
{
return 'tax';
@ -101,10 +112,16 @@ class Tax implements InvoiceRuleInterface
protected function getTaxRate()
{
// TODO: we need to to put this somewhere like in .env
// so that if any chanages are to be made, we just edit the file
// instead of the code
return 0.12;
$code = 'tax';
// find the service fee using the code
// if we can't find the fee, return 0
$fee = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
if ($fee == null)
return 0;
return $fee->getFee();
}
}

View file

@ -2,10 +2,22 @@
namespace App\InvoiceRule;
use Doctrine\ORM\EntityManagerInterface;
use App\InvoiceRuleInterface;
use App\Entity\ServiceOffering;
use App\Entity\CustomerVehicle;
class TireRepair implements InvoiceRuleInterface
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function getID()
{
return 'tire';
@ -19,12 +31,8 @@ class TireRepair implements InvoiceRuleInterface
if ($stype == $this->getID())
{
// check if customer vehicle has a motolite battery
$cv = $criteria->getCustomerVehicle();
if ($cv->hasMotoliteBattery())
$fee = 0;
else
$fee = $this->getServiceTypeFee();
$fee = $this->getServiceTypeFee($cv);
// add the service fee to items
$qty = 1;
@ -42,12 +50,23 @@ class TireRepair implements InvoiceRuleInterface
return $items;
}
protected function getServiceTypeFee()
protected function getServiceTypeFee(CustomerVehicle $cv)
{
// TODO: we need to to put this somewhere like in .env
// so that if any chanages are to be made, we just edit the file
// instead of the code
return 300;
$code = 'tire_repair_fee';
// check if customer vehicle has a motolite battery
// if yes, set the code to the motolite user service fee
if ($cv->hasMotoliteBattery())
$code = 'motolite_user_service_fee';
// find the service fee using the code
// if we can't find the fee, return 0
$fee = $this->em->getRepository(ServiceOffering::class)->findOneBy(['code' => $code]);
if ($fee == null)
return 0;
return $fee->getFee();
}
public function validatePromo($criteria, $promo_id)

View file

@ -16,6 +16,7 @@ class InvoiceCriteria
protected $discount;
protected $service_charges;
protected $flag_taxable;
protected $source; // use Ramcar's TransactionOrigin
// entries are battery and trade-in combos
protected $entries;
@ -30,6 +31,7 @@ class InvoiceCriteria
$this->discount = 0;
$this->service_charges = [];
$this->flag_taxable = false;
$this->source = '';
}
public function setServiceType($stype)
@ -166,4 +168,15 @@ class InvoiceCriteria
return $this->flag_taxable;
}
public function setSource($source)
{
$this->source = $source;
return $this;
}
public function getSource()
{
return $this->source;
}
}

View file

@ -134,7 +134,7 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface
}
// generate invoice criteria
public function generateInvoiceCriteria($jo, $discount, $invoice_items, &$error_array)
public function generateInvoiceCriteria($jo, $discount, $invoice_items, $source = null, &$error_array)
{
$em = $this->em;

View file

@ -144,7 +144,7 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface
}
// generate invoice criteria
public function generateInvoiceCriteria($jo, $promo_id, $invoice_items, &$error_array)
public function generateInvoiceCriteria($jo, $promo_id, $invoice_items, $source = null, &$error_array)
{
$em = $this->em;

View file

@ -13,7 +13,7 @@ interface InvoiceGeneratorInterface
public function generateInvoice(InvoiceCriteria $criteria);
// generate invoice criteria
public function generateInvoiceCriteria(JobOrder $jo, int $promo_id, array $invoice_items, array &$error_array);
public function generateInvoiceCriteria(JobOrder $jo, int $promo_id, array $invoice_items, $source, array &$error_array);
// prepare draft for invoice
public function generateDraftInvoice(InvoiceCriteria $criteria, int $promo_id, array $service_charges, array $items);

View file

@ -44,21 +44,21 @@ class InvoiceManager implements InvoiceGeneratorInterface
return [
new InvoiceRule\BatterySales($this->em),
new InvoiceRule\BatteryReplacementWarranty($this->em),
new InvoiceRule\Jumpstart(),
new InvoiceRule\JumpstartWarranty(),
new InvoiceRule\PostRecharged(),
new InvoiceRule\PostReplacement(),
new InvoiceRule\Overheat(),
new InvoiceRule\Fuel(),
new InvoiceRule\TireRepair(),
new InvoiceRule\Jumpstart($this->em),
new InvoiceRule\JumpstartWarranty($this->em),
new InvoiceRule\PostRecharged($this->em),
new InvoiceRule\PostReplacement($this->em),
new InvoiceRule\Overheat($this->em),
new InvoiceRule\Fuel($this->em),
new InvoiceRule\TireRepair($this->em),
new InvoiceRule\DiscountType($this->em),
new InvoiceRule\TradeIn(),
new InvoiceRule\Tax(),
new InvoiceRule\Tax($this->em),
];
}
// this is called when JO is submitted
public function generateInvoiceCriteria($jo, $promo_id, $invoice_items, &$error_array)
public function generateInvoiceCriteria($jo, $promo_id, $invoice_items, $source, &$error_array)
{
// instantiate the invoice criteria
$criteria = new InvoiceCriteria();
@ -70,6 +70,9 @@ class InvoiceManager implements InvoiceGeneratorInterface
// would mean adding it as a parameter to the call, impacting all calls
$criteria->setIsTaxable();
// set JO source
$criteria->setSource($source);
foreach ($this->available_rules as $avail_rule)
{
$ierror = $avail_rule->validatePromo($criteria, $promo_id);
@ -185,6 +188,7 @@ class InvoiceManager implements InvoiceGeneratorInterface
];
// get what is in criteria
// NOTE: is this snippet still needed? if not, remove
$stype = $criteria->getServiceType();
$entries = $criteria->getEntries();
$promos = $criteria->getPromos();

View file

@ -562,7 +562,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// check if invoice changed
if ($invoice_change)
{
$this->ic->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $error_array);
$source = $jo->getSource();
$this->ic->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $source, $error_array);
}
// validate
@ -792,7 +794,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$invoice_change = $req->request->get('invoice_change', 0);
if ($invoice_change)
{
$this->ic->generateInvoiceCriteria($obj, $promo_id, $invoice_items, $error_array);
$source = $obj->getSource();
$this->ic->generateInvoiceCriteria($obj, $promo_id, $invoice_items, $source, $error_array);
}
// validate
@ -2137,7 +2141,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// check if invoice changed
if ($invoice_change)
{
$this->ic->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $error_array);
// NOTE: this is CMB code but for compilation purposes we need to add this
$source = $jo->getSource();
$this->ic->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $source, $error_array);
}
// validate

View file

@ -16,6 +16,7 @@ use App\Ramcar\InvoiceStatus;
use App\Ramcar\ModeOfPayment;
use App\Ramcar\InvoiceCriteria;
use App\Ramcar\WarrantySource;
use App\Ramcar\TransactionOrigin;
use App\Service\RiderAPIHandlerInterface;
use App\Service\RedisClientProvider;
@ -869,6 +870,10 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
// set istaxable
$crit->setIsTaxable();
// set JO source
// set to anything other than mobile app
$icrit->setSource(TransactionOrigin::WALK_IN);
if ($promo != null)
$crit->addPromo($promo);

View file

@ -0,0 +1,151 @@
{% extends 'base.html.twig' %}
{% block body %}
<!-- BEGIN: Subheader -->
<div class="m-subheader">
<div class="d-flex align-items-center">
<div class="mr-auto">
<h3 class="m-subheader__title">Service Offerings</h3>
</div>
</div>
</div>
<!-- END: Subheader -->
<div class="m-content">
<!--Begin::Section-->
<div class="row">
<div class="col-xl-6">
<div class="m-portlet m-portlet--mobile">
<div class="m-portlet__head">
<div class="m-portlet__head-caption">
<div class="m-portlet__head-title">
<span class="m-portlet__head-icon">
<i class="la la-industry"></i>
</span>
<h3 class="m-portlet__head-text">
{% if mode == 'update' %}
Edit Service Offering
<small>{{ service_offering.getName() }}</small>
{% else %}
New Service Offering
{% endif %}
</h3>
</div>
</div>
</div>
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ mode == 'update' ? url('service_offering_update_submit', {'id': service_offering.getId()}) : url('service_offering_add_submit') }}">
<div class="m-portlet__body">
<div class="form-group m-form__group row no-border">
<label class="col-lg-3 col-form-label" data-field="name">
Name:
</label>
<div class="col-lg-9">
<input type="text" name="name" class="form-control m-input" value="{{ service_offering.getName() }}">
<div class="form-control-feedback hide" data-field="name"></div>
</div>
</div>
<div class="form-group m-form__group row no-border">
<label class="col-lg-3 col-form-label" data-field="code">
Code:
</label>
<div class="col-lg-9">
<input type="text" name="code" class="form-control m-input" value="{{ service_offering.getCode() }}">
<div class="form-control-feedback hide" data-field="code"></div>
</div>
</div>
<div class="form-group m-form__group row">
<label class="col-lg-3 col-form-label" data-field="fee">
Fee:
</label>
<div class="col-lg-9">
<input type="text" name="fee" class="form-control m-input" value="{{ service_offering.getFee() }}">
<div class="form-control-feedback hide" data-field="fee"></div>
</div>
</div>
</div>
<div class="m-portlet__foot m-portlet__foot--fit">
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
<div class="row">
<div class="col-lg-12">
<button type="submit" class="btn btn-success">Submit</button>
<a href="{{ url('service_offering_list') }}" class="btn btn-secondary">Back</a>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
$(function() {
$("#row-form").submit(function(e) {
var form = $(this);
e.preventDefault();
$.ajax({
method: "POST",
url: form.prop('action'),
data: form.serialize()
}).done(function(response) {
// remove all error classes
removeErrors();
swal({
title: 'Done!',
text: 'Your changes have been saved!',
type: 'success',
onClose: function() {
window.location.href = "{{ url('service_offering_list') }}";
}
});
}).fail(function(response) {
if (response.status == 422) {
var errors = response.responseJSON.errors;
var firstfield = false;
// remove all error classes first
removeErrors();
// display errors contextually
$.each(errors, function(field, msg) {
var formfield = $("[name='" + field + "']");
var label = $("label[data-field='" + field + "']");
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
// add error classes to bad fields
formfield.addClass('form-control-danger');
label.addClass('has-danger');
msgbox.html(msg).addClass('has-danger').removeClass('hide');
// check if this field comes first in DOM
var domfield = formfield.get(0);
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
firstfield = domfield;
}
});
// focus on first bad field
firstfield.focus();
// scroll to above that field to make it visible
$('html, body').animate({
scrollTop: $(firstfield).offset().top - 200
}, 100);
}
});
});
// remove all error classes
function removeErrors() {
$(".form-control-danger").removeClass('form-control-danger');
$("[data-field]").removeClass('has-danger');
$(".form-control-feedback[data-field]").addClass('hide');
}
});
</script>
{% endblock %}

View file

@ -0,0 +1,150 @@
{% extends 'base.html.twig' %}
{% block body %}
<!-- BEGIN: Subheader -->
<div class="m-subheader">
<div class="d-flex align-items-center">
<div class="mr-auto">
<h3 class="m-subheader__title">
Service Offerings
</h3>
</div>
</div>
</div>
<!-- END: Subheader -->
<div class="m-content">
<!--Begin::Section-->
<div class="row">
<div class="col-xl-12">
<div class="m-portlet m-portlet--mobile">
<div class="m-portlet__body">
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
<div class="row align-items-center">
<div class="col-xl-8 order-2 order-xl-1">
<div class="form-group m-form__group row align-items-center">
<div class="col-md-4">
<div class="m-input-icon m-input-icon--left">
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
<span class="m-input-icon__icon m-input-icon__icon--left">
<span><i class="la la-search"></i></span>
</span>
</div>
</div>
</div>
</div>
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
<a href="{{ url('service_offering_add_form') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
<span>
<i class="la la-industry"></i>
<span>New Service Offering</span>
</span>
</a>
<div class="m-separator m-separator--dashed d-xl-none"></div>
</div>
</div>
</div>
<!--begin: Datatable -->
<div id="data-rows"></div>
<!--end: Datatable -->
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
$(function() {
var options = {
data: {
type: 'remote',
source: {
read: {
url: '{{ url("service_offering_rows") }}',
method: 'POST'
}
},
saveState: {
cookie: false,
webstorage: false
},
pageSize: 10,
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
layout: {
scroll: true
},
columns: [
{
field: 'id',
title: 'ID',
width: 30
},
{
field: 'name',
title: 'Name'
},
{
field: 'fee',
title: 'Fee'
},
{
field: 'Actions',
width: 110,
title: 'Actions',
sortable: false,
overflow: 'visible',
template: function (row, index, datatable) {
var actions = '';
if (row.meta.update_url != '') {
actions += '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.name + '" title="Edit"><i class="la la-edit"></i></a>';
}
if (row.meta.delete_url != '') {
actions += '<a href="' + row.meta.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.name + '" title="Delete"><i class="la la-trash"></i></a>';
}
return actions;
},
}
],
search: {
onEnter: false,
input: $('#data-rows-search'),
delay: 400
}
};
var table = $("#data-rows").mDatatable(options);
$(document).on('click', '.btn-delete', function(e) {
var url = $(this).prop('href');
var id = $(this).data('id');
var btn = $(this);
e.preventDefault();
swal({
title: 'Confirmation',
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
type: 'warning',
showCancelButton: true
}).then((result) => {
if (result.value) {
$.ajax({
method: "DELETE",
url: url
}).done(function(response) {
table.row(btn.parents('tr')).remove();
table.reload();
});
}
});
});
});
</script>
{% endblock %}

View file

@ -157,6 +157,7 @@ menu.database.tickettypes: 'Ticket Types'
menu.database.subtickettypes: 'Sub Ticket Types'
menu.database.emergencytypes: 'Emergency Types'
menu.database.ownershiptypes: 'Ownership Types'
menu.database.serviceofferings: 'Service Offerings'
# fcm jo status updates
jo_fcm_title_outlet_assign: Looking for riders

View file

@ -0,0 +1,54 @@
-- MySQL dump 10.19 Distrib 10.3.35-MariaDB, for Linux (x86_64)
--
-- Host: localhost Database: resq
-- ------------------------------------------------------
-- Server version 10.3.35-MariaDB
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `service_offering`
--
DROP TABLE IF EXISTS `service_offering`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `service_offering` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(80) COLLATE utf8_unicode_ci NOT NULL,
`code` varchar(80) COLLATE utf8_unicode_ci NOT NULL,
`fee` decimal(9,2) NOT NULL,
PRIMARY KEY (`id`),
KEY `service_offering_idx` (`code`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `service_offering`
--
LOCK TABLES `service_offering` WRITE;
/*!40000 ALTER TABLE `service_offering` DISABLE KEYS */;
INSERT INTO `service_offering` VALUES (1,'Tax','tax',0.12),(2,'Motolite User Service Fee','motolite_user_service_fee',0.00),(3,'Battery Replacement Warranty Fee','battery_replacement_warranty_fee',0.00),(4,'Fuel Service Fee','fuel_service_fee',300.00),(5,'Fuel Gas Fee','fuel_gas_fee',340.00),(6,'Fuel Diesel Fee','fuel_diesel_fee',300.00),(7,'Jumpstart Fee','jumpstart_fee',150.00),(8,'Jumpstart Fee Mobile App','jumpstart_fee_mobile_app',300.00),(9,'Jumpstart Warranty Fee','jumpstart_warranty_fee',0.00),(10,'Overheat Fee','overheat_fee',300.00),(11,'Coolant Fee','coolant_fee',1600.00),(12,'Post Recharged Fee','post_recharged_fee',300.00),(13,'Post Replacement Fee','post_replacement_fee',0.00),(14,'Tire Repair Fee','tire_repair_fee',300.00);
/*!40000 ALTER TABLE `service_offering` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2023-08-23 2:02:51