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)
|
||||
{
|
||||
// return error if there's a problem, false otherwise
|
||||
|
||||
foreach ($items as $item)
|
||||
if (!empty($items))
|
||||
{
|
||||
// check if this is a valid battery
|
||||
$battery = $em->getRepository(Battery::class)->find($item['battery']);
|
||||
|
||||
if (empty($battery))
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$error = 'Invalid battery specified.';
|
||||
return $error;
|
||||
// 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']))
|
||||
$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;
|
||||
}
|
||||
|
||||
|
|
@ -700,7 +702,6 @@ class JobOrderController extends BaseController
|
|||
|
||||
if (!$error)
|
||||
$error = $this->invoiceBatteries($em, $criteria, $items);
|
||||
|
||||
|
||||
if ($error)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -921,6 +921,11 @@ $(function() {
|
|||
generateInvoice();
|
||||
});
|
||||
|
||||
// update invoice when promo is changed
|
||||
$("#invoice-promo").change(function() {
|
||||
generateInvoice();
|
||||
});
|
||||
|
||||
function generateInvoice() {
|
||||
var promo = $("#invoice-promo").val();
|
||||
var table = $("#invoice-table tbody");
|
||||
|
|
|
|||
Loading…
Reference in a new issue