Fix issues found during testing. #744

This commit is contained in:
Korina Cordero 2023-07-05 01:36:44 -04:00
parent b4bcc06e42
commit 2f3a77e96d
5 changed files with 54 additions and 49 deletions

View file

@ -45,13 +45,14 @@ class TestInvoiceManagerCommand extends Command
$this->testBatterySalesNoTradeInNoDiscountWithTax(); $this->testBatterySalesNoTradeInNoDiscountWithTax();
$this->testBatterySalesQuantityNoTradeInNoDiscountWithTax(); $this->testBatterySalesQuantityNoTradeInNoDiscountWithTax();
/*
// battery sales without tax // battery sales without tax
$this->testBatterySalesNoTradeInNoDiscountWithoutTax(); $this->testBatterySalesNoTradeInNoDiscountWithoutTax();
$this->testBatterySalesQuantityNoTradeInNoDiscountWithoutTax(); $this->testBatterySalesQuantityNoTradeInNoDiscountWithoutTax();
// battery sales with trade in with tax // battery sales with trade in with tax
$this->testBatterySalesTradeInSameBatteryPremiumNoDiscountWithTax(); $this->testBatterySalesTradeInSameBatteryPremiumNoDiscountWithTax();
$this->testBatterySalesTradeInSameBatteryMotoliteNoDiscountWithTax(); $this->testBatterySalesTradeInSameBatteryMotoliteNoDiscountWithTax();
$this->testBatterySalesTradeInSameBatteryOtherNoDiscountWithTax(); $this->testBatterySalesTradeInSameBatteryOtherNoDiscountWithTax();
$this->testBatterySalesTradeInDifferentBatteryPremiumNoDiscountWithTax(); $this->testBatterySalesTradeInDifferentBatteryPremiumNoDiscountWithTax();
@ -66,7 +67,7 @@ class TestInvoiceManagerCommand extends Command
$this->testBatterySalesTradeInDifferentBatteryPremiumNoDiscountWithoutTax(); $this->testBatterySalesTradeInDifferentBatteryPremiumNoDiscountWithoutTax();
$this->testBatterySalesTradeInDifferentBatteryMotoliteNoDiscountWithoutTax(); $this->testBatterySalesTradeInDifferentBatteryMotoliteNoDiscountWithoutTax();
$this->testBatterySalesTradeInDifferentBatteryOtherNoDiscountWithoutTax(); $this->testBatterySalesTradeInDifferentBatteryOtherNoDiscountWithoutTax();
$this->testBatterySalesTradeInQuantityNoDiscountWithoutTax(); $this->testBatterySalesTradeInQuantityNoDiscountWithoutTax();
// battery sales with discount with tax // battery sales with discount with tax
$this->testBatterySalesNoTradeInWithDiscountWithTax(); $this->testBatterySalesNoTradeInWithDiscountWithTax();
@ -151,10 +152,10 @@ class TestInvoiceManagerCommand extends Command
$this->testGenerateDraftInvoiceInvalidBattery(); $this->testGenerateDraftInvoiceInvalidBattery();
$this->testGenerateDraftInvoiceInvalidPromo(); $this->testGenerateDraftInvoiceInvalidPromo();
$this->testGenerateDraftInvoiceNonBatterySales(); $this->testGenerateDraftInvoiceNonBatterySales();
$this->testGenerateDraftInvoiceBatterySalesNoPromo(); $this->testGenerateDraftInvoiceBatterySalesNoPromo();
// test generateInvoiceInvoice call from ajax call // test generateInvoiceInvoice call from ajax call
$this->testGenerateInvoice(); */ $this->testGenerateInvoice();
return 0; return 0;
} }
@ -175,7 +176,7 @@ class TestInvoiceManagerCommand extends Command
$invoice_data = $this->inv_manager->compute($criteria); $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) foreach ($invoice_data as $data)
{ {
@ -303,6 +304,8 @@ class TestInvoiceManagerCommand extends Command
$invoice_data = $this->inv_manager->compute($criteria); $invoice_data = $this->inv_manager->compute($criteria);
error_log(print_r(json_encode($invoice_data), true));
foreach ($invoice_data as $data) foreach ($invoice_data as $data)
{ {
$invoice_items = $data['invoice_items']; $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('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)); 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('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)); 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('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)); 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('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)); error_log('TOTAL ' . print_r(json_encode($total), true));
} }

View file

@ -72,9 +72,10 @@ class BatteryReplacementWarranty implements InvoiceRuleInterface
public function validateInvoiceItems($criteria, $invoice_items) 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(); $stype = $criteria->getServiceType();
if ($stype != ServiceType::BATTERY_REPLACEMENT_NEW && $stype != ServiceType::BATTERY_REPLACEMENT_WARRANTY) if ($stype != ServiceType::BATTERY_REPLACEMENT_WARRANTY)
return null; return null;
// return error if there's a problem, false otherwise // return error if there's a problem, false otherwise

View file

@ -76,9 +76,10 @@ class BatterySales implements InvoiceRuleInterface
public function validateInvoiceItems($criteria, $invoice_items) 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(); $stype = $criteria->getServiceType();
if ($stype != ServiceType::BATTERY_REPLACEMENT_NEW && $stype != ServiceType::BATTERY_REPLACEMENT_WARRANTY) if ($stype != ServiceType::BATTERY_REPLACEMENT_NEW)
return null; return null;
// return error if there's a problem, false otherwise // return error if there's a problem, false otherwise

View file

@ -48,7 +48,7 @@ class Fuel implements InvoiceRuleInterface
case FuelType::GAS: case FuelType::GAS:
case FuelType::DIESEL: case FuelType::DIESEL:
$qty = 1; $qty = 1;
$price = $this->getFuelFee(); $price = $this->getFuelFee($ftype);
$items[] = [ $items[] = [
'service_type' => $this->getID(), 'service_type' => $this->getID(),
'qty' => $qty, 'qty' => $qty,

View file

@ -164,9 +164,11 @@ class InvoiceManager implements InvoiceGeneratorInterface
// no need to validate since generateDraftInvoice was called before this was called // no need to validate since generateDraftInvoice was called before this was called
// generate the invoice and from APIController, the fields were validated // generate the invoice and from APIController, the fields were validated
$invoice_data = $this->compute($criteria); $invoice_data = $this->compute($criteria);
$invoice = $this->createInvoice($invoice_data); $invoice = $this->createInvoice($invoice_data);
$invoice_items = $invoice->getItems();
return $invoice; return $invoice;
} }
@ -188,15 +190,6 @@ class InvoiceManager implements InvoiceGeneratorInterface
$promos = $criteria->getPromos(); $promos = $criteria->getPromos();
$is_taxable = $criteria->isTaxable(); $is_taxable = $criteria->isTaxable();
$flag_trade_in = false;
foreach ($entries as $entry)
{
if ($entry['trade_in'] != null)
{
$flag_trade_in = true;
}
}
$invoice_items = []; $invoice_items = [];
$data = []; $data = [];
foreach ($this->available_rules as $rule) foreach ($this->available_rules as $rule)
@ -204,37 +197,41 @@ class InvoiceManager implements InvoiceGeneratorInterface
$items = $rule->compute($criteria, $total); $items = $rule->compute($criteria, $total);
$promo = null; $promo = null;
foreach ($items as $item)
if (count($items) > 0)
{ {
$title = $item['title']; foreach ($items as $item)
$quantity = $item['qty']; {
$price = $item['price']; $title = $item['title'];
$quantity = $item['qty'];
$price = $item['price'];
$battery = null; $battery = null;
if (isset($item['battery'])) if (isset($item['battery']))
$battery = $item['battery']; $battery = $item['battery'];
$promo = null; $promo = null;
if (isset($item['promo'])) if (isset($item['promo']))
$promo = $item['promo']; $promo = $item['promo'];
$invoice_items[] = [ $invoice_items[] = [
'title' => $title, 'title' => $title,
'quantity' => $quantity, 'quantity' => $quantity,
'price' => $price, 'price' => $price,
'battery' => $battery, 'battery' => $battery,
'promo' => $promo, '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; return $data;
} }