Fix issues found during testing. #744
This commit is contained in:
parent
b4bcc06e42
commit
2f3a77e96d
5 changed files with 54 additions and 49 deletions
|
|
@ -45,13 +45,14 @@ class TestInvoiceManagerCommand extends Command
|
|||
$this->testBatterySalesNoTradeInNoDiscountWithTax();
|
||||
$this->testBatterySalesQuantityNoTradeInNoDiscountWithTax();
|
||||
|
||||
/*
|
||||
|
||||
// battery sales without tax
|
||||
$this->testBatterySalesNoTradeInNoDiscountWithoutTax();
|
||||
$this->testBatterySalesQuantityNoTradeInNoDiscountWithoutTax();
|
||||
|
||||
// battery sales with trade in with tax
|
||||
$this->testBatterySalesTradeInSameBatteryPremiumNoDiscountWithTax();
|
||||
|
||||
$this->testBatterySalesTradeInSameBatteryMotoliteNoDiscountWithTax();
|
||||
$this->testBatterySalesTradeInSameBatteryOtherNoDiscountWithTax();
|
||||
$this->testBatterySalesTradeInDifferentBatteryPremiumNoDiscountWithTax();
|
||||
|
|
@ -66,7 +67,7 @@ class TestInvoiceManagerCommand extends Command
|
|||
$this->testBatterySalesTradeInDifferentBatteryPremiumNoDiscountWithoutTax();
|
||||
$this->testBatterySalesTradeInDifferentBatteryMotoliteNoDiscountWithoutTax();
|
||||
$this->testBatterySalesTradeInDifferentBatteryOtherNoDiscountWithoutTax();
|
||||
$this->testBatterySalesTradeInQuantityNoDiscountWithoutTax();
|
||||
$this->testBatterySalesTradeInQuantityNoDiscountWithoutTax();
|
||||
|
||||
// battery sales with discount with tax
|
||||
$this->testBatterySalesNoTradeInWithDiscountWithTax();
|
||||
|
|
@ -151,10 +152,10 @@ class TestInvoiceManagerCommand extends Command
|
|||
$this->testGenerateDraftInvoiceInvalidBattery();
|
||||
$this->testGenerateDraftInvoiceInvalidPromo();
|
||||
$this->testGenerateDraftInvoiceNonBatterySales();
|
||||
$this->testGenerateDraftInvoiceBatterySalesNoPromo();
|
||||
$this->testGenerateDraftInvoiceBatterySalesNoPromo();
|
||||
|
||||
// test generateInvoiceInvoice call from ajax call
|
||||
$this->testGenerateInvoice(); */
|
||||
$this->testGenerateInvoice();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -175,7 +176,7 @@ class TestInvoiceManagerCommand extends Command
|
|||
|
||||
$invoice_data = $this->inv_manager->compute($criteria);
|
||||
|
||||
// error_log(print_r(json_encode($invoice_data), true));
|
||||
error_log(print_r(json_encode($invoice_data), true));
|
||||
|
||||
foreach ($invoice_data as $data)
|
||||
{
|
||||
|
|
@ -303,6 +304,8 @@ class TestInvoiceManagerCommand extends Command
|
|||
|
||||
$invoice_data = $this->inv_manager->compute($criteria);
|
||||
|
||||
error_log(print_r(json_encode($invoice_data), true));
|
||||
|
||||
foreach ($invoice_data as $data)
|
||||
{
|
||||
$invoice_items = $data['invoice_items'];
|
||||
|
|
@ -805,7 +808,8 @@ class TestInvoiceManagerCommand extends Command
|
|||
error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' NO TRADE IN WITH DISCOUNT WITH TAX ' . $invoice_item['title'] . ' ' . $invoice_item['quantity'] . ' ' . $invoice_item['price']);
|
||||
}
|
||||
|
||||
error_log('PROMO ' . $promo->getName());
|
||||
if ($promo != null)
|
||||
error_log('PROMO ' . $promo->getName());
|
||||
|
||||
error_log('TOTAL ' . print_r(json_encode($total), true));
|
||||
}
|
||||
|
|
@ -844,7 +848,8 @@ class TestInvoiceManagerCommand extends Command
|
|||
error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' NO TRADE IN WITH DISCOUNT WITHOUT TAX ' . $invoice_item['title'] . ' ' . $invoice_item['quantity'] . ' ' . $invoice_item['price']);
|
||||
}
|
||||
|
||||
error_log('PROMO ' . $promo->getName());
|
||||
if ($promo != null)
|
||||
error_log('PROMO ' . $promo->getName());
|
||||
|
||||
error_log('TOTAL ' . print_r(json_encode($total), true));
|
||||
}
|
||||
|
|
@ -888,8 +893,8 @@ class TestInvoiceManagerCommand extends Command
|
|||
error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' TRADE IN SAME BATTERY WITH DISCOUNT WITH TAX ' . $invoice_item['title'] . ' ' . $invoice_item['quantity'] . ' ' . $invoice_item['price']);
|
||||
}
|
||||
|
||||
error_log('PROMO ' . $promo->getName());
|
||||
|
||||
if ($promo != null)
|
||||
error_log('PROMO ' . $promo->getName());
|
||||
error_log('TOTAL ' . print_r(json_encode($total), true));
|
||||
}
|
||||
}
|
||||
|
|
@ -972,7 +977,8 @@ class TestInvoiceManagerCommand extends Command
|
|||
error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' TRADE IN SAME BATTERY WITH DISCOUNT WITHOUT TAX ' . $invoice_item['title'] . ' ' . $invoice_item['quantity'] . ' ' . $invoice_item['price']);
|
||||
}
|
||||
|
||||
error_log('PROMO ' . $promo->getName());
|
||||
if ($promo != null)
|
||||
error_log('PROMO ' . $promo->getName());
|
||||
|
||||
error_log('TOTAL ' . print_r(json_encode($total), true));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,9 +72,10 @@ class BatteryReplacementWarranty implements InvoiceRuleInterface
|
|||
|
||||
public function validateInvoiceItems($criteria, $invoice_items)
|
||||
{
|
||||
// check service type. Only battery sales and battery warranty should have invoice items
|
||||
// check service type. Only battery sales and battery warranty should have invoice items. Since this is the
|
||||
// battery replacement warranty rule, we only check for battery replacement warranty.
|
||||
$stype = $criteria->getServiceType();
|
||||
if ($stype != ServiceType::BATTERY_REPLACEMENT_NEW && $stype != ServiceType::BATTERY_REPLACEMENT_WARRANTY)
|
||||
if ($stype != ServiceType::BATTERY_REPLACEMENT_WARRANTY)
|
||||
return null;
|
||||
|
||||
// return error if there's a problem, false otherwise
|
||||
|
|
|
|||
|
|
@ -76,9 +76,10 @@ class BatterySales implements InvoiceRuleInterface
|
|||
|
||||
public function validateInvoiceItems($criteria, $invoice_items)
|
||||
{
|
||||
// check service type. Only battery sales and battery warranty should have invoice items
|
||||
// check service type. Only battery sales and battery warranty should have invoice items. Since this is the battery sales
|
||||
// rule, we only check for battery sales.
|
||||
$stype = $criteria->getServiceType();
|
||||
if ($stype != ServiceType::BATTERY_REPLACEMENT_NEW && $stype != ServiceType::BATTERY_REPLACEMENT_WARRANTY)
|
||||
if ($stype != ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||
return null;
|
||||
|
||||
// return error if there's a problem, false otherwise
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class Fuel implements InvoiceRuleInterface
|
|||
case FuelType::GAS:
|
||||
case FuelType::DIESEL:
|
||||
$qty = 1;
|
||||
$price = $this->getFuelFee();
|
||||
$price = $this->getFuelFee($ftype);
|
||||
$items[] = [
|
||||
'service_type' => $this->getID(),
|
||||
'qty' => $qty,
|
||||
|
|
|
|||
|
|
@ -164,9 +164,11 @@ class InvoiceManager implements InvoiceGeneratorInterface
|
|||
// no need to validate since generateDraftInvoice was called before this was called
|
||||
// generate the invoice and from APIController, the fields were validated
|
||||
$invoice_data = $this->compute($criteria);
|
||||
|
||||
|
||||
$invoice = $this->createInvoice($invoice_data);
|
||||
|
||||
$invoice_items = $invoice->getItems();
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
|
|
@ -188,15 +190,6 @@ class InvoiceManager implements InvoiceGeneratorInterface
|
|||
$promos = $criteria->getPromos();
|
||||
$is_taxable = $criteria->isTaxable();
|
||||
|
||||
$flag_trade_in = false;
|
||||
foreach ($entries as $entry)
|
||||
{
|
||||
if ($entry['trade_in'] != null)
|
||||
{
|
||||
$flag_trade_in = true;
|
||||
}
|
||||
}
|
||||
|
||||
$invoice_items = [];
|
||||
$data = [];
|
||||
foreach ($this->available_rules as $rule)
|
||||
|
|
@ -204,37 +197,41 @@ class InvoiceManager implements InvoiceGeneratorInterface
|
|||
$items = $rule->compute($criteria, $total);
|
||||
|
||||
$promo = null;
|
||||
foreach ($items as $item)
|
||||
|
||||
if (count($items) > 0)
|
||||
{
|
||||
$title = $item['title'];
|
||||
$quantity = $item['qty'];
|
||||
$price = $item['price'];
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$title = $item['title'];
|
||||
$quantity = $item['qty'];
|
||||
$price = $item['price'];
|
||||
|
||||
$battery = null;
|
||||
if (isset($item['battery']))
|
||||
$battery = $item['battery'];
|
||||
$battery = null;
|
||||
if (isset($item['battery']))
|
||||
$battery = $item['battery'];
|
||||
|
||||
$promo = null;
|
||||
if (isset($item['promo']))
|
||||
$promo = $item['promo'];
|
||||
$promo = null;
|
||||
if (isset($item['promo']))
|
||||
$promo = $item['promo'];
|
||||
|
||||
$invoice_items[] = [
|
||||
'title' => $title,
|
||||
'quantity' => $quantity,
|
||||
'price' => $price,
|
||||
'battery' => $battery,
|
||||
'promo' => $promo,
|
||||
];
|
||||
$invoice_items[] = [
|
||||
'title' => $title,
|
||||
'quantity' => $quantity,
|
||||
'price' => $price,
|
||||
'battery' => $battery,
|
||||
'promo' => $promo,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// also need to return the total and the promo
|
||||
$data[] = [
|
||||
'promo' => $promo,
|
||||
'invoice_items' => $invoice_items,
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
|
||||
// also need to return the total and the promo
|
||||
$data[] = [
|
||||
'promo' => $promo,
|
||||
'invoice_items' => $invoice_items,
|
||||
'total' => $total,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue