Regenerate invoice when changing promo
This commit is contained in:
parent
a318d5ffcb
commit
46ebd223a2
2 changed files with 28 additions and 22 deletions
|
|
@ -656,31 +656,33 @@ class JobOrderController extends BaseController
|
||||||
protected function invoiceBatteries($em, InvoiceCriteria $criteria, $items)
|
protected function invoiceBatteries($em, InvoiceCriteria $criteria, $items)
|
||||||
{
|
{
|
||||||
// return error if there's a problem, false otherwise
|
// return error if there's a problem, false otherwise
|
||||||
|
if (!empty($items))
|
||||||
foreach ($items as $item)
|
|
||||||
{
|
{
|
||||||
// check if this is a valid battery
|
foreach ($items as $item)
|
||||||
$battery = $em->getRepository(Battery::class)->find($item['battery']);
|
|
||||||
|
|
||||||
if (empty($battery))
|
|
||||||
{
|
{
|
||||||
$error = 'Invalid battery specified.';
|
// check if this is a valid battery
|
||||||
return $error;
|
$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']))
|
||||||
|
$criteria->addTradeIn($item['trade_in'] == 'motolite', $qty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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']))
|
|
||||||
$criteria->addTradeIn($item['trade_in'] == 'motolite', $qty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -700,7 +702,6 @@ class JobOrderController extends BaseController
|
||||||
|
|
||||||
if (!$error)
|
if (!$error)
|
||||||
$error = $this->invoiceBatteries($em, $criteria, $items);
|
$error = $this->invoiceBatteries($em, $criteria, $items);
|
||||||
|
|
||||||
|
|
||||||
if ($error)
|
if ($error)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -921,6 +921,11 @@ $(function() {
|
||||||
generateInvoice();
|
generateInvoice();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// update invoice when promo is changed
|
||||||
|
$("#invoice-promo").change(function() {
|
||||||
|
generateInvoice();
|
||||||
|
});
|
||||||
|
|
||||||
function generateInvoice() {
|
function generateInvoice() {
|
||||||
var promo = $("#invoice-promo").val();
|
var promo = $("#invoice-promo").val();
|
||||||
var table = $("#invoice-table tbody");
|
var table = $("#invoice-table tbody");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue