diff --git a/src/Command/TestInvoiceManagerCommand.php b/src/Command/TestInvoiceManagerCommand.php index f47b6b52..6f223edb 100644 --- a/src/Command/TestInvoiceManagerCommand.php +++ b/src/Command/TestInvoiceManagerCommand.php @@ -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)); } diff --git a/src/InvoiceRule/BatteryReplacementWarranty.php b/src/InvoiceRule/BatteryReplacementWarranty.php index 816ff636..8fbfe76c 100644 --- a/src/InvoiceRule/BatteryReplacementWarranty.php +++ b/src/InvoiceRule/BatteryReplacementWarranty.php @@ -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 diff --git a/src/InvoiceRule/BatterySales.php b/src/InvoiceRule/BatterySales.php index 533a54b4..45b060d1 100644 --- a/src/InvoiceRule/BatterySales.php +++ b/src/InvoiceRule/BatterySales.php @@ -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 diff --git a/src/InvoiceRule/Fuel.php b/src/InvoiceRule/Fuel.php index a5529a6f..53e70af9 100644 --- a/src/InvoiceRule/Fuel.php +++ b/src/InvoiceRule/Fuel.php @@ -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, diff --git a/src/Service/InvoiceManager.php b/src/Service/InvoiceManager.php index e4a7dc44..ac3f7316 100644 --- a/src/Service/InvoiceManager.php +++ b/src/Service/InvoiceManager.php @@ -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; }