Fix for cmb to retain battery in invoice when editing JO. #343
This commit is contained in:
parent
a15b45173c
commit
984b0428d0
8 changed files with 86 additions and 31 deletions
|
|
@ -605,7 +605,7 @@ class JobOrderController extends Controller
|
|||
* @Menu(selected="jo_all")
|
||||
*/
|
||||
public function allForm($id, JobOrderHandlerInterface $jo_handler,
|
||||
GISManagerInterface $gis)
|
||||
GISManagerInterface $gis, EntityManagerInterface $em)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('jo_all.list', null, 'No access.');
|
||||
|
||||
|
|
@ -618,6 +618,8 @@ class JobOrderController extends Controller
|
|||
throw $this->createNotFoundException($e->getMessage());
|
||||
}
|
||||
|
||||
$params['vmfgs'] = $em->getRepository(VehicleManufacturer::class)->findAll();
|
||||
$params['vmakes'] = $em->getRepository(Vehicle::class)->findAll();
|
||||
$params['return_url'] = $this->generateUrl('jo_all');
|
||||
$params['submit_url'] = '';
|
||||
$params['map_js_file'] = $gis->getJSJOFile();
|
||||
|
|
|
|||
|
|
@ -280,6 +280,12 @@ class JobOrder
|
|||
*/
|
||||
protected $hub_rejections;
|
||||
|
||||
// meta
|
||||
/**
|
||||
* @ORM\Column(type="json")
|
||||
*/
|
||||
protected $meta;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
|
|
@ -297,6 +303,8 @@ class JobOrder
|
|||
$this->trade_in_type = null;
|
||||
$this->flag_rider_rating = false;
|
||||
$this->flag_coolant = false;
|
||||
|
||||
$this->meta = [];
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -802,4 +810,15 @@ class JobOrder
|
|||
{
|
||||
return $this->hub_rejections;
|
||||
}
|
||||
|
||||
public function addMeta($id, $value)
|
||||
{
|
||||
$this->meta[$id] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMeta($id)
|
||||
{
|
||||
return $this->meta[$id];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@ class InvoiceCriteria
|
|||
protected $promos;
|
||||
protected $cv;
|
||||
protected $flag_coolant;
|
||||
// for discount and other info
|
||||
protected $meta;
|
||||
protected $discount;
|
||||
|
||||
// entries are battery and trade-in combos
|
||||
protected $entries;
|
||||
|
|
@ -25,7 +24,7 @@ class InvoiceCriteria
|
|||
$this->entries = [];
|
||||
$this->cv = null;
|
||||
$this->flag_coolant = false;
|
||||
$this->meta = [];
|
||||
$this->discount = 0;
|
||||
}
|
||||
|
||||
public function setServiceType($stype)
|
||||
|
|
@ -129,14 +128,14 @@ class InvoiceCriteria
|
|||
return $this->flag_coolant;
|
||||
}
|
||||
|
||||
public function addMeta($id, $value)
|
||||
public function setDiscount($discount)
|
||||
{
|
||||
$this->meta[$id] = $value;
|
||||
$this->discount = $discount;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMeta()
|
||||
public function getDiscount()
|
||||
{
|
||||
return $this->meta;
|
||||
return $this->discount;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,18 +229,17 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface
|
|||
if ($stype != CMBServiceType::BATTERY_REPLACEMENT_NEW)
|
||||
return null;
|
||||
|
||||
|
||||
// check if discount is blank or 0
|
||||
if ((empty($discount)) || ($discount == 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if discount is greater than 50
|
||||
if ($discount > 50)
|
||||
// check if discount is greater than 50 or negative number
|
||||
if (($discount > 50) || ($discount < 0))
|
||||
return 'Invalid discount specified';
|
||||
|
||||
$criteria->addMeta('discount', $discount);
|
||||
$criteria->setDiscount($discount);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -385,12 +384,7 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface
|
|||
|
||||
protected function processDiscount(&$total, InvoiceCriteria $criteria, Invoice $invoice)
|
||||
{
|
||||
$discount = 0;
|
||||
$meta = $criteria->getMeta();
|
||||
if (isset($meta['discount']))
|
||||
$discount = $meta['discount'];
|
||||
else
|
||||
return;
|
||||
$discount = $criteria->getDiscount();
|
||||
|
||||
// if discount is higher than 0, display in invoice
|
||||
if ($discount > 0)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ use App\Entity\Invoice;
|
|||
use App\Entity\InvoiceItem;
|
||||
use App\Entity\User;
|
||||
use App\Entity\Battery;
|
||||
use App\Entity\Promo;
|
||||
|
||||
use App\Service\InvoiceGeneratorInterface;
|
||||
|
||||
|
|
|
|||
|
|
@ -522,6 +522,13 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
}
|
||||
}
|
||||
|
||||
// get discount and set to meta
|
||||
$discount = $req->request->get('invoice_promo');
|
||||
|
||||
// check if discount is greater than 50 or negative number
|
||||
if (($discount > 50) || ($discount < 0))
|
||||
$error_array['invoice_promo'] = 'Invalid discount specified';
|
||||
|
||||
if (empty($error_array))
|
||||
{
|
||||
// get current user
|
||||
|
|
@ -551,7 +558,9 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
->setHub($hub)
|
||||
->setRider($rider);
|
||||
|
||||
// check if user is null, meaning call to create came from API
|
||||
$jo->addMeta('discount', $discount);
|
||||
|
||||
// check if user is null, meaning call to create came from API
|
||||
if ($user != null)
|
||||
{
|
||||
$jo->setCreatedBy($user);
|
||||
|
|
@ -2488,6 +2497,13 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
$hub_coordinates = $hub->getCoordinates();
|
||||
}
|
||||
|
||||
// get discount and set to meta
|
||||
$discount = $req->request->get('invoice_promo');
|
||||
|
||||
// check if discount is greater than 50 or negative number
|
||||
if (($discount > 50) || ($discount < 0))
|
||||
$error_array['invoice_promo'] = 'Invalid discount specified';
|
||||
|
||||
if (empty($error_array))
|
||||
{
|
||||
// get current user
|
||||
|
|
@ -2513,6 +2529,8 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
->setCoordinates($hub_coordinates)
|
||||
->setHub($hub);
|
||||
|
||||
$jo->addMeta('discount', $discount);
|
||||
|
||||
// check if user is null, meaning call to create came from API
|
||||
if ($user != null)
|
||||
{
|
||||
|
|
@ -2670,6 +2688,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
$params['warranty_classes'] = CMBWarrantyClass::getCollection();
|
||||
$params['modes_of_payment'] = CMBModeOfPayment::getCollection();
|
||||
$params['statuses'] = JOStatus::getCollection();
|
||||
$params['discount_apply'] = DiscountApply::getCollection();
|
||||
$params['trade_in_types'] = CMBTradeInType::getCollection();
|
||||
$params['facilitated_types'] = FacilitatedType::getCollection();
|
||||
$params['facilitated_hubs'] = $fac_hubs;
|
||||
|
|
|
|||
|
|
@ -1268,6 +1268,21 @@ $(function() {
|
|||
|
||||
var invoiceItems = [];
|
||||
|
||||
// populate invoiceItems if editing so that we don't lose the battery
|
||||
{% if mode in ['open-edit', 'onestep-edit', 'walk-in-edit'] %}
|
||||
{% if (obj.getInvoice and obj.getInvoice.getItems|length > 0) %}
|
||||
{% for item in obj.getInvoice.getItems %}
|
||||
{% if item.getBattery() %}
|
||||
invoiceItems.push({
|
||||
battery: {{ item.getBattery().getID() }},
|
||||
quantity: {{ item.getQuantity() }},
|
||||
trade_in: {{ obj.getInvoice().getTradeIn }},
|
||||
});
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
// add to invoice
|
||||
$("#btn-add-to-invoice").click(function() {
|
||||
var bmfg = $("#invoice-bmfg").val();
|
||||
|
|
|
|||
|
|
@ -395,22 +395,13 @@
|
|||
<div class="col-lg-6">
|
||||
<label>Discount Type</label>
|
||||
{% if ftags.invoice_edit %}
|
||||
<select class="form-control m-input" id="invoice-promo" name="invoice_promo">
|
||||
<option value="">None</option>
|
||||
{% for promo in promos %}
|
||||
<option value="{{ promo.getID() }}">{{ promo.getName() ~ ' (' ~ promo.getDiscountRate * 100 ~ '% applied to ' ~ discount_apply[promo.getDiscountApply] ~ ')' }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<input type="number" id="invoice-promo" name="invoice_promo" class="form-control m-input min = "0" max="50" value="{{ obj.getInvoice ? obj.getInvoice.getDiscount }}">
|
||||
<div class="form-control-feedback hide" data-field="invoice_promo"></div>
|
||||
{% else %}
|
||||
<input type="text" id="invoice-promo" class="form-control m-input" value="{{ obj.getInvoice.getPromo.getName|default('None') }}" disabled>
|
||||
<input type="number" id="invoice-promo" name="invoice_promo" class="form-control m-input min="0" max="50" value="{{ obj.getInvoice ? obj.getInvoice.getDiscount }}" disabled>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<label>Promo Discount</label>
|
||||
<input type="text" id="invoice-promo-discount" class="form-control m-input text-right" value="{{ obj.getInvoice ? obj.getInvoice.getDiscount|number_format(2) : '0.00' }}" disabled>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<div class="col-lg-6">
|
||||
<label>Trade In</label>
|
||||
<input type="text" id="invoice-trade-in" class="form-control m-input text-right" value="{{ obj.getInvoice ? obj.getInvoice.getTradeIn|number_format(2) : '0.00' }}" disabled>
|
||||
</div>
|
||||
|
|
@ -892,6 +883,21 @@ var vdata = false;
|
|||
|
||||
var invoiceItems = [];
|
||||
|
||||
// populate invoiceItems if editing so that we don't lose the battery
|
||||
{% if mode in ['open-edit', 'onestep-edit', 'walk-in-edit'] %}
|
||||
{% if (obj.getInvoice and obj.getInvoice.getItems|length > 0) %}
|
||||
{% for item in obj.getInvoice.getItems %}
|
||||
{% if item.getBattery() %}
|
||||
invoiceItems.push({
|
||||
battery: {{ item.getBattery().getID() }},
|
||||
quantity: {{ item.getQuantity() }},
|
||||
trade_in: {{ obj.getInvoice().getTradeIn }},
|
||||
});
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
// add to invoice
|
||||
$("#btn-add-to-invoice").click(function() {
|
||||
var bmfg = $("#invoice-bmfg").val();
|
||||
|
|
|
|||
Loading…
Reference in a new issue