diff --git a/src/Command/TestInvoiceManagerCommand.php b/src/Command/TestInvoiceManagerCommand.php index f82b8c25..7feafcb9 100644 --- a/src/Command/TestInvoiceManagerCommand.php +++ b/src/Command/TestInvoiceManagerCommand.php @@ -39,60 +39,104 @@ class TestInvoiceManagerCommand extends Command protected function execute(InputInterface $input, OutputInterface $output) { - // battery sales - $this->testBatterySalesNoTradeInNoDiscount(); - $this->testBatterySalesQuantityNoTradeInNoDiscount(); + // battery sales with tax + $this->testBatterySalesNoTradeInNoDiscountWithTax(); + $this->testBatterySalesQuantityNoTradeInNoDiscountWithTax(); - // battery sales with trade in - $this->testBatterySalesTradeInSameBatteryPremiumNoDiscount(); - $this->testBatterySalesTradeInSameBatteryMotoliteNoDiscount(); - $this->testBatterySalesTradeInSameBatteryOtherNoDiscount(); - $this->testBatterySalesTradeInDifferentBatteryPremiumNoDiscount(); - $this->testBatterySalesTradeInDifferentBatteryMotoliteNoDiscount(); - $this->testBatterySalesTradeInDifferentBatteryOtherNoDiscount(); - $this->testBatterySalesTradeInQuantityNoDiscount(); + // battery sales without tax + $this->testBatterySalesNoTradeInNoDiscountWithoutTax(); + $this->testBatterySalesQuantityNoTradeInNoDiscountWithoutTax(); - // battery sales with discount + // battery sales with trade in with tax + $this->testBatterySalesTradeInSameBatteryPremiumNoDiscountWithTax(); + $this->testBatterySalesTradeInSameBatteryMotoliteNoDiscountWithTax(); + $this->testBatterySalesTradeInSameBatteryOtherNoDiscountWithTax(); + $this->testBatterySalesTradeInDifferentBatteryPremiumNoDiscountWithTax(); + $this->testBatterySalesTradeInDifferentBatteryMotoliteNoDiscountWithTax(); + $this->testBatterySalesTradeInDifferentBatteryOtherNoDiscountWithTax(); + $this->testBatterySalesTradeInQuantityNoDiscountWithTax(); - // battery replacement warranty - $this->testBatteryReplacementWarranty(); + // battery sales with trade in without tax + $this->testBatterySalesTradeInSameBatteryPremiumNoDiscountWithoutTax(); + $this->testBatterySalesTradeInSameBatteryMotoliteNoDiscountWithoutTax(); + $this->testBatterySalesTradeInSameBatteryOtherNoDiscountWithoutTax(); + $this->testBatterySalesTradeInDifferentBatteryPremiumNoDiscountWithoutTax(); + $this->testBatterySalesTradeInDifferentBatteryMotoliteNoDiscountWithoutTax(); + $this->testBatterySalesTradeInDifferentBatteryOtherNoDiscountWithoutTax(); + $this->testBatterySalesTradeInQuantityNoDiscountWithoutTax(); - // fuel - $this->testFuelGasWithServiceFee(); - $this->testFuelDieselWithServiceFee(); - $this->testFuelGasWithNoServiceFee(); - $this->testFuelDieselWithNoServiceFee(); + // battery sales with discount with tax + // battery sales with discount without tax - // jumpstart - $this->testJumpstart(); + // battery replacement warranty with tax + $this->testBatteryReplacementWarrantyWithTax(); - // jumpstart warranty - $this->testJumpstartWarranty(); + // battery replacement warranty without tax + $this->testBatteryReplacementWarrantyWithoutTax(); - // overheat - $this->testOverheatAssistanceWithCoolant(); - $this->testOverheatAssistanceWithoutCoolant(); + // fuel with tax + $this->testFuelGasWithServiceFeeWithTax(); + $this->testFuelDieselWithServiceFeeWithTax(); + $this->testFuelGasWithNoServiceFeeWithTax(); + $this->testFuelDieselWithNoServiceFeeWithTax(); - // post-recharged - $this->testPostRecharged(); + // fuel without tax + $this->testFuelGasWithServiceFeeWithoutTax(); + $this->testFuelDieselWithServiceFeeWithoutTax(); + $this->testFuelGasWithNoServiceFeeWithoutTax(); + $this->testFuelDieselWithNoServiceFeeWithoutTax(); - // post replacement - $this->testPostReplacement(); + // jumpstart with tax + $this->testJumpstartWithTax(); - // tire repair - $this->testTireRepairWithServiceFee(); - $this->testTireRepairWithoutServiceFee(); + // jumpstart without tax + $this->testJumpstartWithoutTax(); + + // jumpstart warranty with tax + $this->testJumpstartWarrantyWithTax(); + + // jumpstart warranty without tax + $this->testJumpstartWarrantyWithoutTax(); + + // overheat with tax + $this->testOverheatAssistanceWithCoolantWithTax(); + $this->testOverheatAssistanceWithoutCoolantWithTax(); + + // overheat without tax + $this->testOverheatAssistanceWithCoolantWithoutTax(); + $this->testOverheatAssistanceWithoutCoolantWithoutTax(); + + // post-recharged with tax + $this->testPostRechargedWithTax(); + + // post-recharged without tax + $this->testPostRechargedWithoutTax(); + + // post replacement with tax + $this->testPostReplacementWithTax(); + + // post replacement without tax + $this->testPostReplacementWithoutTax(); + + // tire repair with tax + $this->testTireRepairWithServiceFeeWithTax(); + $this->testTireRepairWithoutServiceFeeWithTax(); + + // tire repair without tax + $this->testTireRepairWithServiceFeeWithoutTax(); + $this->testTireRepairWithoutServiceFeeWithoutTax(); // TEST SCENARIO: new battery with discount // TEST SCENARIO: new battery with discount and trade-in return 0; } - protected function testBatterySalesNoTradeInNoDiscount() + // 1battery sales with tax + protected function testBatterySalesNoTradeInNoDiscountWithTax() { $criteria = new InvoiceCriteria(); - // TEST SCENARIO: new battery, no trade-in, no discount + // TEST SCENARIO: new battery, no trade-in, no discount, with tax $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); $battery_id = 1038; @@ -116,18 +160,18 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' NO TRADE IN NO DISCOUNT ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' NO TRADE IN NO DISCOUNT WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testBatterySalesQuantityNoTradeInNoDiscount() + protected function testBatterySalesQuantityNoTradeInNoDiscountWithTax() { $criteria = new InvoiceCriteria(); - // TEST SCENARIO: new battery, more than 1, no trade-in, no discount + // TEST SCENARIO: new battery, more than 1, no trade-in, no discount, with tax $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); $battery_id = 1038; @@ -151,14 +195,84 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' QUANTITY NO TRADE IN NO DISCOUNT ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' QUANTITY NO TRADE IN NO DISCOUNT WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testBatterySalesTradeInSameBatteryPremiumNoDiscount() + // battery sales without tax + protected function testBatterySalesNoTradeInNoDiscountWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, no trade-in, no discount, no tax + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + $criteria->addEntry($battery, null, 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + // error_log(print_r(json_encode($invoice_data), true)); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' NO TRADE IN NO DISCOUNT WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + protected function testBatterySalesQuantityNoTradeInNoDiscountWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, more than 1, no trade-in, no discount, without tax + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + $criteria->addEntry($battery, null, 2); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + // error_log(print_r(json_encode($invoice_data), true)); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' QUANTITY NO TRADE IN NO DISCOUNT WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + // battery sales with trade in with tax + protected function testBatterySalesTradeInSameBatteryPremiumNoDiscountWithTax() { $criteria = new InvoiceCriteria(); @@ -188,14 +302,14 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' PREMIUM TRADE IN SAME BATTERY NO DISCOUNT ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' PREMIUM TRADE IN SAME BATTERY NO DISCOUNT WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testBatterySalesTradeInSameBatteryMotoliteNoDiscount() + protected function testBatterySalesTradeInSameBatteryMotoliteNoDiscountWithTax() { $criteria = new InvoiceCriteria(); @@ -226,14 +340,14 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' MOTOLITE TRADE IN SAME BATTERY NO DISCOUNT ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' MOTOLITE TRADE IN SAME BATTERY NO DISCOUNT WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testBatterySalesTradeInSameBatteryOtherNoDiscount() + protected function testBatterySalesTradeInSameBatteryOtherNoDiscountWithTax() { $criteria = new InvoiceCriteria(); @@ -264,14 +378,14 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' OTHER TRADE IN SAME BATTERY NO DISCOUNT ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' OTHER TRADE IN SAME BATTERY NO DISCOUNT WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testBatterySalesTradeInDifferentBatteryPremiumNoDiscount() + protected function testBatterySalesTradeInDifferentBatteryPremiumNoDiscountWithTax() { $criteria = new InvoiceCriteria(); @@ -305,14 +419,14 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' PREMIUM TRADE IN DIFFERENT BATTERY NO DISCOUNT ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' PREMIUM TRADE IN DIFFERENT BATTERY NO DISCOUNT WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testBatterySalesTradeInDifferentBatteryMotoliteNoDiscount() + protected function testBatterySalesTradeInDifferentBatteryMotoliteNoDiscountWithTax() { $criteria = new InvoiceCriteria(); @@ -346,14 +460,14 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' MOTOLITE TRADE IN DIFFERENT BATTERY NO DISCOUNT ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' MOTOLITE TRADE IN DIFFERENT BATTERY NO DISCOUNT WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testBatterySalesTradeInDifferentBatteryOtherNoDiscount() + protected function testBatterySalesTradeInDifferentBatteryOtherNoDiscountWithTax() { $criteria = new InvoiceCriteria(); @@ -387,14 +501,14 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' OTHER TRADE IN DIFFERENT BATTERY NO DISCOUNT ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' OTHER TRADE IN DIFFERENT BATTERY NO DISCOUNT WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testBatterySalesTradeInQuantityNoDiscount() + protected function testBatterySalesTradeInQuantityNoDiscountWithTax() { $criteria = new InvoiceCriteria(); @@ -428,16 +542,282 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' QUANTITY TRADE IN NO DISCOUNT ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' QUANTITY TRADE IN NO DISCOUNT WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testBatteryReplacementWarranty() + // start: battery sales with trade in without tax + protected function testBatterySalesTradeInSameBatteryPremiumNoDiscountWithoutTax() { - // TEST SCENARIO: battery replacement warranty + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, trade-in same battery, premium, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + // add battery + $criteria->addEntry($battery, null, 1); + + // add battery for trade in + $criteria->addEntry($battery, 'premium', 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' PREMIUM TRADE IN SAME BATTERY NO DISCOUNT WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + protected function testBatterySalesTradeInSameBatteryMotoliteNoDiscountWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, trade-in same battery, motolite, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + // add battery + $criteria->addEntry($battery, null, 1); + + // add battery for trade in + $criteria->addEntry($battery, 'motolite', 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' MOTOLITE TRADE IN SAME BATTERY NO DISCOUNT WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + protected function testBatterySalesTradeInSameBatteryOtherNoDiscountWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, trade-in same battery, other, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + // add battery + $criteria->addEntry($battery, null, 1); + + // add battery for trade in + $criteria->addEntry($battery, 'other', 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' OTHER TRADE IN SAME BATTERY NO DISCOUNT WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + protected function testBatterySalesTradeInDifferentBatteryPremiumNoDiscountWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, trade-in different battery, premium, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + // add battery + $criteria->addEntry($battery, null, 1); + + $trade_battery_id = 1037; + $trade_battery = $this->em->getRepository(Battery::class)->find($trade_battery_id); + + // add battery for trade in + $criteria->addEntry($trade_battery, 'premium', 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' PREMIUM TRADE IN DIFFERENT BATTERY NO DISCOUNT WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + protected function testBatterySalesTradeInDifferentBatteryMotoliteNoDiscountWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, trade-in different battery, motolite, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + // add battery + $criteria->addEntry($battery, null, 1); + + $trade_battery_id = 1037; + $trade_battery = $this->em->getRepository(Battery::class)->find($trade_battery_id); + + // add battery for trade in + $criteria->addEntry($trade_battery, 'motolite', 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' MOTOLITE TRADE IN DIFFERENT BATTERY NO DISCOUNT WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + protected function testBatterySalesTradeInDifferentBatteryOtherNoDiscountWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, trade-in different battery, other, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + // add battery + $criteria->addEntry($battery, null, 1); + + $trade_battery_id = 1037; + $trade_battery = $this->em->getRepository(Battery::class)->find($trade_battery_id); + + // add battery for trade in + $criteria->addEntry($trade_battery, 'other', 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' OTHER TRADE IN DIFFERENT BATTERY NO DISCOUNT WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + protected function testBatterySalesTradeInQuantityNoDiscountWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: new battery, trade-in different battery, premium, no discount + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + // add battery + $criteria->addEntry($battery, null, 1); + + $trade_battery_id = 1037; + $trade_battery = $this->em->getRepository(Battery::class)->find($trade_battery_id); + + // add battery for trade in + $criteria->addEntry($trade_battery, 'other', 3); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_NEW) . ' QUANTITY TRADE IN NO DISCOUNT WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + // battery replacement warranty with tax + protected function testBatteryReplacementWarrantyWithTax() + { + // TEST SCENARIO: battery replacement warranty with tax $criteria = new InvoiceCriteria(); $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_WARRANTY); @@ -462,18 +842,52 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_WARRANTY) . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_WARRANTY) . ' WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testFuelGasWithServiceFee() + // battery replacement warranty without tax + protected function testBatteryReplacementWarrantyWithoutTax() + { + // TEST SCENARIO: battery replacement warranty without tax + $criteria = new InvoiceCriteria(); + + $criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_WARRANTY); + + $battery_id = 1038; + $battery = $this->em->getRepository(Battery::class)->find($battery_id); + + $criteria->addEntry($battery, null, 1); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::BATTERY_REPLACEMENT_WARRANTY) . ' WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + // fuel with tax + protected function testFuelGasWithServiceFeeWithTax() { $criteria = new InvoiceCriteria(); - // TEST SCENARIO: fuel, gas, service fee + // TEST SCENARIO: fuel, gas, service fee, with tax $criteria->setServiceType(ServiceType::EMERGENCY_REFUEL); // set customer vehicle @@ -497,18 +911,18 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::EMERGENCY_REFUEL) . ' GAS WITH SERVICE FEE' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::EMERGENCY_REFUEL) . ' GAS WITH SERVICE FEE WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testFuelDieselWithServiceFee() + protected function testFuelDieselWithServiceFeeWithTax() { $criteria = new InvoiceCriteria(); - // TEST SCENARIO: fuel, diesel, service fee + // TEST SCENARIO: fuel, diesel, service fee, with tax $criteria->setServiceType(ServiceType::EMERGENCY_REFUEL); // set customer vehicle @@ -532,18 +946,18 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::EMERGENCY_REFUEL) . ' DIESEL WITH SERVICE FEE ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::EMERGENCY_REFUEL) . ' DIESEL WITH SERVICE FEE WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testFuelGasWithNoServiceFee() + protected function testFuelGasWithNoServiceFeeWithTax() { $criteria = new InvoiceCriteria(); - // TEST SCENARIO: fuel, gas, no service fee + // TEST SCENARIO: fuel, gas, no service fee, with tax $criteria->setServiceType(ServiceType::EMERGENCY_REFUEL); // set customer vehicle @@ -567,18 +981,18 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::EMERGENCY_REFUEL) . ' GAS WITH NO SERVICE FEE ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::EMERGENCY_REFUEL) . ' GAS WITH NO SERVICE FEE WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testFuelDieselWithNoServiceFee() + protected function testFuelDieselWithNoServiceFeeWithTax() { $criteria = new InvoiceCriteria(); - // TEST SCENARIO: fuel, diesel, no service fee + // TEST SCENARIO: fuel, diesel, no service fee, with tax $criteria->setServiceType(ServiceType::EMERGENCY_REFUEL); // set customer vehicle @@ -602,16 +1016,150 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::EMERGENCY_REFUEL) . ' DIESEL WITH NO SERVICE FEE ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::EMERGENCY_REFUEL) . ' DIESEL WITH NO SERVICE FEE WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testJumpstart() + // fuel without tax + protected function testFuelGasWithServiceFeeWithoutTax() { - // TEST SCENARIO: jumpstart + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: fuel, gas, service fee, without tax + $criteria->setServiceType(ServiceType::EMERGENCY_REFUEL); + + // set customer vehicle + $cv_id = 1306614; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::EMERGENCY_REFUEL) . ' GAS WITH SERVICE FEE WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + protected function testFuelDieselWithServiceFeeWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: fuel, diesel, service fee, without tax + $criteria->setServiceType(ServiceType::EMERGENCY_REFUEL); + + // set customer vehicle + $cv_id = 1306612; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::EMERGENCY_REFUEL) . ' DIESEL WITH SERVICE FEE WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + protected function testFuelGasWithNoServiceFeeWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: fuel, gas, no service fee, without tax + $criteria->setServiceType(ServiceType::EMERGENCY_REFUEL); + + // set customer vehicle + $cv_id = 1306604; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::EMERGENCY_REFUEL) . ' GAS WITH NO SERVICE FEE WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + protected function testFuelDieselWithNoServiceFeeWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: fuel, diesel, no service fee, without tax + $criteria->setServiceType(ServiceType::EMERGENCY_REFUEL); + + // set customer vehicle + $cv_id = 1306581; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::EMERGENCY_REFUEL) . ' DIESEL WITH NO SERVICE FEE WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + // jumpstart with tax + protected function testJumpstartWithTax() + { + // TEST SCENARIO: jumpstart with tax $criteria = new InvoiceCriteria(); $criteria->setServiceType(ServiceType::JUMPSTART_TROUBLESHOOT); @@ -631,16 +1179,45 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::JUMPSTART_TROUBLESHOOT) . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::JUMPSTART_TROUBLESHOOT) . ' WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testJumpstartWarranty() + // jumpstart without tax + protected function testJumpstartWithoutTax() { - // TEST SCENARIO: jumpstart warranty + // TEST SCENARIO: jumpstart without tax + $criteria = new InvoiceCriteria(); + + $criteria->setServiceType(ServiceType::JUMPSTART_TROUBLESHOOT); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::JUMPSTART_TROUBLESHOOT) . ' WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + // jumpstart warranty with tax + protected function testJumpstartWarrantyWithTax() + { + // TEST SCENARIO: jumpstart warranty with tax $criteria = new InvoiceCriteria(); $criteria->setServiceType(ServiceType::JUMPSTART_WARRANTY); @@ -660,18 +1237,47 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::JUMPSTART_WARRANTY) . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::JUMPSTART_WARRANTY) . ' WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testOverheatAssistanceWithCoolant() + // jumpstart warranty without tax + protected function testJumpstartWarrantyWithoutTax() + { + // TEST SCENARIO: jumpstart warranty without tax + $criteria = new InvoiceCriteria(); + + $criteria->setServiceType(ServiceType::JUMPSTART_WARRANTY); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::JUMPSTART_WARRANTY) . ' WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + // overheat assistance with tax + protected function testOverheatAssistanceWithCoolantWithTax() { $criteria = new InvoiceCriteria(); - // TEST SCENARIO: overheat assistance with coolant + // TEST SCENARIO: overheat assistance with coolant with tax $criteria->setServiceType(ServiceType::OVERHEAT_ASSISTANCE); // set customer vehicle @@ -695,18 +1301,18 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::OVERHEAT_ASSISTANCE) . ' WITH COOLANT ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::OVERHEAT_ASSISTANCE) . ' WITH COOLANT WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testOverheatAssistanceWithoutCoolant() + protected function testOverheatAssistanceWithoutCoolantWithTax() { $criteria = new InvoiceCriteria(); - // TEST SCENARIO: overheat assistance without coolant + // TEST SCENARIO: overheat assistance without coolant with tax $criteria->setServiceType(ServiceType::OVERHEAT_ASSISTANCE); // set customer vehicle @@ -729,18 +1335,87 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::OVERHEAT_ASSISTANCE) . ' WITHOUT COOLANT ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::OVERHEAT_ASSISTANCE) . ' WITHOUT COOLANT WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testPostRecharged() + // overheat assistance without tax + protected function testOverheatAssistanceWithCoolantWithoutTax() { $criteria = new InvoiceCriteria(); - // TEST SCENARIO: post recharged + // TEST SCENARIO: overheat assistance with coolant without tax + $criteria->setServiceType(ServiceType::OVERHEAT_ASSISTANCE); + + // set customer vehicle + $cv_id = 1306614; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + $criteria->setHasCoolant(); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::OVERHEAT_ASSISTANCE) . ' WITH COOLANT WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + protected function testOverheatAssistanceWithoutCoolantWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: overheat assistance without coolant without tax + $criteria->setServiceType(ServiceType::OVERHEAT_ASSISTANCE); + + // set customer vehicle + $cv_id = 1306614; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::OVERHEAT_ASSISTANCE) . ' WITHOUT COOLANT WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + // post recharged with tax + protected function testPostRechargedWithTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: post recharged with tax $criteria->setServiceType(ServiceType::POST_RECHARGED); $criteria->setIsTaxable(); @@ -758,18 +1433,47 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::POST_RECHARGED) . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::POST_RECHARGED) . ' WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testPostReplacement() + // post recharged without tax + protected function testPostRechargedWithoutTax() { $criteria = new InvoiceCriteria(); - // TEST SCENARIO: post replacement + // TEST SCENARIO: post recharged with tax + $criteria->setServiceType(ServiceType::POST_RECHARGED); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::POST_RECHARGED) . ' WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + // post replacement with tax + protected function testPostReplacementWithTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: post replacement with tax $criteria->setServiceType(ServiceType::POST_REPLACEMENT); $criteria->setIsTaxable(); @@ -787,18 +1491,49 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::POST_REPLACEMENT) . ' ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::POST_REPLACEMENT) . ' WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testTireRepairWithServiceFee() + // post replacement without tax + protected function testPostReplacementWithoutTax() { $criteria = new InvoiceCriteria(); - // TEST SCENARIO: tire repair with service fee + // TEST SCENARIO: post replacement without tax + $criteria->setServiceType(ServiceType::POST_REPLACEMENT); + + $criteria->setIsTaxable(); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::POST_REPLACEMENT) . ' WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + // tire repair with tax + protected function testTireRepairWithServiceFeeWithTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: tire repair with service fee with tax $criteria->setServiceType(ServiceType::TIRE_REPAIR); // set customer vehicle @@ -822,18 +1557,18 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::TIRE_REPAIR) . ' WITH SERVICE FEE ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::TIRE_REPAIR) . ' WITH SERVICE FEE WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } - protected function testTireRepairWithoutServiceFee() + protected function testTireRepairWithoutServiceFeeWithTax() { $criteria = new InvoiceCriteria(); - // TEST SCENARIO: tire repair no service fee + // TEST SCENARIO: tire repair no service fee with tax $criteria->setServiceType(ServiceType::TIRE_REPAIR); // set customer vehicle @@ -857,11 +1592,78 @@ class TestInvoiceManagerCommand extends Command foreach ($invoice_items as $invoice_item) { - error_log('TEST: ' . strtoupper(ServiceType::TIRE_REPAIR) . ' WITHOUT SERVICE FEE ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + error_log('TEST: ' . strtoupper(ServiceType::TIRE_REPAIR) . ' WITHOUT SERVICE FEE WITH TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); } error_log('TOTAL ' . print_r(json_encode($total), true)); } } + // tire repair without tax + protected function testTireRepairWithServiceFeeWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: tire repair with service fee without tax + $criteria->setServiceType(ServiceType::TIRE_REPAIR); + + // set customer vehicle + $cv_id = 1306612; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::TIRE_REPAIR) . ' WITH SERVICE FEE WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + + protected function testTireRepairWithoutServiceFeeWithoutTax() + { + $criteria = new InvoiceCriteria(); + + // TEST SCENARIO: tire repair no service fee without tax + $criteria->setServiceType(ServiceType::TIRE_REPAIR); + + // set customer vehicle + $cv_id = 1306604; + $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); + + $criteria->setCustomerVehicle($cv); + + $rules = $this->inv_manager->check($criteria); + + // error_log(print_r($rules, true)); + + $invoice_data = $this->inv_manager->compute($criteria, $rules); + + foreach ($invoice_data as $data) + { + $invoice_items = $data['invoice_items']; + $total = $data['total']; + + foreach ($invoice_items as $invoice_item) + { + error_log('TEST: ' . strtoupper(ServiceType::TIRE_REPAIR) . ' WITHOUT SERVICE FEE WITHOUT TAX ' . $invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice()); + } + + error_log('TOTAL ' . print_r(json_encode($total), true)); + } + } + } diff --git a/src/Invoice/BatteryReplacementWarranty.php b/src/Invoice/BatteryReplacementWarranty.php index 525793f1..108016ac 100644 --- a/src/Invoice/BatteryReplacementWarranty.php +++ b/src/Invoice/BatteryReplacementWarranty.php @@ -24,7 +24,7 @@ class BatteryReplacementWarranty implements InvoiceInterface return 'battery_warranty'; } - public function compute($criteria, $stype_fees) + public function compute($criteria, $stype_fees, &$total) { $stype = $criteria->getServiceType(); @@ -48,6 +48,9 @@ class BatteryReplacementWarranty implements InvoiceInterface 'title' => $this->getTitle($batt), 'price' => $price, ]; + + $qty_price = bcmul($price, $qty, 2); + $total['total_price'] = bcadd($total['total_price'], $qty_price, 2); } } diff --git a/src/Invoice/BatterySales.php b/src/Invoice/BatterySales.php index 40d77b9e..e1b94282 100644 --- a/src/Invoice/BatterySales.php +++ b/src/Invoice/BatterySales.php @@ -24,7 +24,7 @@ class BatterySales implements InvoiceInterface return 'battery_new'; } - public function compute($criteria, $stype_fees) + public function compute($criteria, $stype_fees, &$total) { $stype = $criteria->getServiceType(); @@ -56,6 +56,11 @@ class BatterySales implements InvoiceInterface 'title' => $this->getTitle($batt), 'price' => $price, ]; + + $qty_price = bcmul($price, $qty, 2); + + $total['sell_price'] = bcadd($total['sell_price'], $qty_price, 2); + $total['total_price'] = bcadd($total['total_price'], $qty_price, 2); } } } diff --git a/src/Invoice/DiscountType.php b/src/Invoice/DiscountType.php index 31a6e835..a1bea802 100644 --- a/src/Invoice/DiscountType.php +++ b/src/Invoice/DiscountType.php @@ -4,6 +4,8 @@ namespace App\Invoice; use App\InvoiceInterface; +use App\Ramcar\DiscountApply; + class DiscountType implements InvoiceInterface { public function check($criteria) @@ -25,7 +27,7 @@ class DiscountType implements InvoiceInterface return 'discount_type'; } - public function compute($criteria, $stype_fees) + public function compute($criteria, $stype_fees, &$total) { $items = []; diff --git a/src/Invoice/Fuel.php b/src/Invoice/Fuel.php index 6cc5e338..2cc8bbeb 100644 --- a/src/Invoice/Fuel.php +++ b/src/Invoice/Fuel.php @@ -26,12 +26,11 @@ class Fuel implements InvoiceInterface return 'fuel'; } - public function compute($criteria, $stype_fees) + public function compute($criteria, $stype_fees, &$total) { $stype = $criteria->getServiceType(); $items = []; - if ($stype == $this->getID()) { @@ -52,6 +51,9 @@ class Fuel implements InvoiceInterface 'title' => $this->getServiceTitle($ftype), 'price' => $fee, ]; + + $qty_fee = bcmul($qty, $fee, 2); + $total_price = $qty_fee; $stype_fees_id = $this->getID() . '_fee_' . $ftype; @@ -68,6 +70,9 @@ class Fuel implements InvoiceInterface 'price' => $price, ]; + $qty_price = bcmul($price, $qty, 2); + $total_price = bcadd($total_price, $qty_price, 2); + break; default: $qty = 1; @@ -78,8 +83,14 @@ class Fuel implements InvoiceInterface 'title' => $this->getTitle('Unknown'), 'price' => $price, ]; + + $qty_price = bcmul($price, $qty, 2); + $total_price = bcadd($total_price, $qty_price, 2); + break; } + + $total['total_price'] = bcadd($total['total_price'], $total_price, 2); } return $items; diff --git a/src/Invoice/Jumpstart.php b/src/Invoice/Jumpstart.php index 088bb020..747c1217 100644 --- a/src/Invoice/Jumpstart.php +++ b/src/Invoice/Jumpstart.php @@ -23,7 +23,7 @@ class Jumpstart implements InvoiceInterface return 'jumpstart_troubleshoot'; } - public function compute($criteria, $stype_fees) + public function compute($criteria, $stype_fees, &$total) { $stype = $criteria->getServiceType(); @@ -43,6 +43,9 @@ class Jumpstart implements InvoiceInterface 'title' => $this->getServiceTitle(), 'price' => $fee, ]; + + $qty_price = bcmul($fee, $qty, 2); + $total['total_price'] = bcadd($total['total_price'], $qty_price, 2); } return $items; diff --git a/src/Invoice/JumpstartWarranty.php b/src/Invoice/JumpstartWarranty.php index c4b3192e..634e79b8 100644 --- a/src/Invoice/JumpstartWarranty.php +++ b/src/Invoice/JumpstartWarranty.php @@ -23,7 +23,7 @@ class JumpstartWarranty implements InvoiceInterface return 'jumpstart_warranty'; } - public function compute($criteria, $stype_fees) + public function compute($criteria, $stype_fees, &$total) { $stype = $criteria->getServiceType(); @@ -43,6 +43,9 @@ class JumpstartWarranty implements InvoiceInterface 'title' => $this->getServiceTitle(), 'price' => $fee, ]; + + $qty_price = bcmul($fee, $qty, 2); + $total['total_price'] = bcadd($total['total_price'], $qty_price, 2); } return $items; diff --git a/src/Invoice/Overheat.php b/src/Invoice/Overheat.php index e05eb657..4700b9b2 100644 --- a/src/Invoice/Overheat.php +++ b/src/Invoice/Overheat.php @@ -25,7 +25,7 @@ class Overheat implements InvoiceInterface return 'overheat'; } - public function compute($criteria, $stype_fees) + public function compute($criteria, $stype_fees, &$total) { $stype = $criteria->getServiceType(); $has_coolant = $criteria->hasCoolant(); @@ -50,6 +50,9 @@ class Overheat implements InvoiceInterface 'price' => $fee, ]; + $qty_fee = bcmul($qty, $fee, 2); + $total_price = $qty_fee; + if ($has_coolant) { $coolant_fee = $stype_fees['coolant_fee']; @@ -59,7 +62,12 @@ class Overheat implements InvoiceInterface 'title' => $this->getServiceCoolantTitle(), 'price' => $coolant_fee, ]; + + $qty_price = bcmul($coolant_fee, $qty, 2); + $total_price = bcadd($total_price, $qty_price, 2); } + + $total['total_price'] = bcadd($total['total_price'], $total_price, 2); } return $items; diff --git a/src/Invoice/PostRecharged.php b/src/Invoice/PostRecharged.php index 84f2f03a..9984e6a2 100644 --- a/src/Invoice/PostRecharged.php +++ b/src/Invoice/PostRecharged.php @@ -23,7 +23,7 @@ class PostRecharged implements InvoiceInterface return 'post_recharged'; } - public function compute($criteria, $stype_fees) + public function compute($criteria, $stype_fees, &$total) { $stype = $criteria->getServiceType(); @@ -41,6 +41,9 @@ class PostRecharged implements InvoiceInterface 'price' => $fee, ]; + $qty_price = bcmul($fee, $qty, 2); + $total['total_price'] = bcadd($total['total_price'], $qty_price, 2); + } return $items; diff --git a/src/Invoice/PostReplacement.php b/src/Invoice/PostReplacement.php index 014f021f..5d5ec7ba 100644 --- a/src/Invoice/PostReplacement.php +++ b/src/Invoice/PostReplacement.php @@ -23,7 +23,7 @@ class PostReplacement implements InvoiceInterface return 'post_replacement'; } - public function compute($criteria, $stype_fees) + public function compute($criteria, $stype_fees, &$total) { $stype = $criteria->getServiceType(); @@ -41,6 +41,8 @@ class PostReplacement implements InvoiceInterface 'price' => $fee, ]; + $qty_price = bcmul($fee, $qty, 2); + $total['total_price'] = bcadd($total['total_price'], $qty_price, 2); } return $items; diff --git a/src/Invoice/Tax.php b/src/Invoice/Tax.php index 377dc2b6..45172286 100644 --- a/src/Invoice/Tax.php +++ b/src/Invoice/Tax.php @@ -53,29 +53,21 @@ class Tax implements InvoiceInterface $price_minus_vat = bcsub($price, $vat, 2); $qty_price_minus_vat = bcmul($price_minus_vat, $qty, 2); - $total['sell_price'] = bcadd($total['sell_price'], $qty_price, 2); $total['vat'] = bcadd($total['vat'], $qty_vat, 2); $total['vat_ex_price'] = bcadd($total['vat_ex_price'], $qty_price_minus_vat, 2); - - $total['total_price'] = bcadd($total['total_price'], $qty_price, 2); } } - else - { - // for all other service types - // add the item price to total_price. we compute VAT from the total price - $total_price = bcadd($total_price, $price, 2); - } } } // compute VAT after adding all item costs, if service type is not battery sales if (!$is_battery_sales) { + $total_price = $total['total_price']; + $vat_ex_price = $this->getTaxExclusivePrice($total_price, $tax_rate); $vat = bcsub($total_price, $vat_ex_price, 2); - $total['total_price'] = $total_price; $total['vat_ex_price'] = $vat_ex_price; $total['vat'] = $vat; } diff --git a/src/Invoice/TireRepair.php b/src/Invoice/TireRepair.php index d4fdcecd..4ec85945 100644 --- a/src/Invoice/TireRepair.php +++ b/src/Invoice/TireRepair.php @@ -23,7 +23,7 @@ class TireRepair implements InvoiceInterface return 'tire'; } - public function compute($criteria, $stype_fees) + public function compute($criteria, $stype_fees, &$total) { $stype = $criteria->getServiceType(); @@ -46,6 +46,9 @@ class TireRepair implements InvoiceInterface 'title' => $this->getServiceTitle(), 'price' => $fee, ]; + + $qty_price = bcmul($fee, $qty, 2); + $total['total_price'] = bcadd($total['total_price'], $qty_price, 2); } return $items; diff --git a/src/Service/InvoiceManager.php b/src/Service/InvoiceManager.php index a6503d7b..b1baf521 100644 --- a/src/Service/InvoiceManager.php +++ b/src/Service/InvoiceManager.php @@ -60,7 +60,7 @@ class InvoiceManager 'battery_warranty_fee' => 0, 'other_services_fee' => 200, 'fuel_fee_gas' => 320, - 'fuel_fee_diesel' => 320, + 'fuel_fee_diesel' => 340, ]; } @@ -124,7 +124,7 @@ class InvoiceManager { $items = []; - $computed_items = $active_rule->compute($criteria, $stype_fees); + $computed_items = $active_rule->compute($criteria, $stype_fees, $total); foreach ($computed_items as $computed_item) { if (!empty($computed_item)) @@ -133,6 +133,17 @@ class InvoiceManager } } + // check if tax is needed + if ($is_taxable) + { + $tax_rate = $this->getTaxRate(); + + if (isset($active_rules['tax'])) + { + $active_rules['tax']->compute($tax_rate, $items, $total); + } + } + // process trade-ins by calling the trade-in rule if there are trade-ins among the entries if ($flag_trade_in) { @@ -146,14 +157,12 @@ class InvoiceManager } } - // check if tax is needed - if ($is_taxable) + // process promos, if any + if (count($promos) > 0) { - $tax_rate = $this->getTaxRate(); - - if (isset($active_rules['tax'])) + if (isset($active_rules['discount_type'])) { - $active_rules['tax']->compute($tax_rate, $items, $total); + $discount_items = $active_rules['discount_type']->compute($criteria, $stype_fees); } } @@ -171,15 +180,6 @@ class InvoiceManager $invoice_items[] = $invoice_item; } - // process promos, if any - if (count($promos) > 0) - { - if (isset($active_rules['discount_type'])) - { - $discount_items = $active_rules['discount_type']->compute($criteria, $stype_fees); - } - } - // also need to return the total $data[] = [ 'invoice_items' => $invoice_items,