Finish adding the test cases. #744
This commit is contained in:
parent
fe5121cf71
commit
4ebbd8cfd3
2 changed files with 225 additions and 12 deletions
|
|
@ -1999,7 +1999,7 @@ class TestInvoiceManagerCommand extends Command
|
|||
|
||||
$invoice = $this->inv_manager->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $error_array);
|
||||
|
||||
if ($invoice != null)
|
||||
if (empty($error_array))
|
||||
{
|
||||
error_log('TEST GENERATEINVOICECRITERIA:');
|
||||
error_log('INVOICE');
|
||||
|
|
@ -2017,14 +2017,124 @@ class TestInvoiceManagerCommand extends Command
|
|||
error_log($invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error_log('TEST GENERATE INVOICE CRITERIA: Errors found when generating invoice ' . print_r(json_encode($error_array), true));
|
||||
}
|
||||
}
|
||||
|
||||
protected function testGenerateInvoiceCriteriaInvalidPromo()
|
||||
{
|
||||
// create JO, set service type and customer vehicle
|
||||
$jo = new JobOrder();
|
||||
|
||||
$jo->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW);
|
||||
|
||||
// set customer vehicle
|
||||
$cv_id = 1306604;
|
||||
$cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id);
|
||||
|
||||
$jo->setCustomerVehicle($cv);
|
||||
|
||||
// create error_array
|
||||
$error_array = [];
|
||||
|
||||
// create array of invoice items
|
||||
$invoice_items = [[
|
||||
'battery' => 1038,
|
||||
'quantity' => 1,
|
||||
'trade_in' => '',
|
||||
], [
|
||||
'battery' => 1038,
|
||||
'quantity' => 1,
|
||||
'trade_in' => 'premium'
|
||||
]];
|
||||
|
||||
// error_log(print_r(json_encode($invoice_items), true));
|
||||
// promo id
|
||||
$promo_id = 99;
|
||||
|
||||
$invoice = $this->inv_manager->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $error_array);
|
||||
|
||||
if (empty($error_array))
|
||||
{
|
||||
error_log('TEST GENERATEINVOICECRITERIA:');
|
||||
error_log('INVOICE');
|
||||
error_log('TOTAL PRICE: ' . $invoice->getTotalPrice());
|
||||
error_log('VAT EXCLUSIVE PRICE: ' . $invoice->getVATExclusivePrice());
|
||||
error_log('VAT: ' . $invoice->getVAT());
|
||||
error_log('DISCOUNT: ' . $invoice->getDiscount());
|
||||
error_log('TRADE-IN: ' . $invoice->getTradeIn());
|
||||
error_log('STATUS: ' . $invoice->getStatus());
|
||||
|
||||
$invoice_items = $invoice->getItems();
|
||||
|
||||
foreach ($invoice_items as $invoice_item)
|
||||
{
|
||||
error_log($invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error_log('TEST GENERATE INVOICE CRITERIA INVALID PROMO: Errors found when generating invoice ' . print_r(json_encode($error_array), true));
|
||||
}
|
||||
}
|
||||
|
||||
protected function testGenerateInvoiceCriteriaInvalidBattery()
|
||||
{
|
||||
// create JO, set service type and customer vehicle
|
||||
$jo = new JobOrder();
|
||||
|
||||
$jo->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW);
|
||||
|
||||
// set customer vehicle
|
||||
$cv_id = 1306604;
|
||||
$cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id);
|
||||
|
||||
$jo->setCustomerVehicle($cv);
|
||||
|
||||
// create error_array
|
||||
$error_array = [];
|
||||
|
||||
// create array of invoice items
|
||||
$invoice_items = [[
|
||||
'battery' => 1,
|
||||
'quantity' => 1,
|
||||
'trade_in' => '',
|
||||
], [
|
||||
'battery' => 1038,
|
||||
'quantity' => 1,
|
||||
'trade_in' => 'premium'
|
||||
]];
|
||||
|
||||
// error_log(print_r(json_encode($invoice_items), true));
|
||||
// promo id
|
||||
$promo_id = 1;
|
||||
|
||||
$invoice = $this->inv_manager->generateInvoiceCriteria($jo, $promo_id, $invoice_items, $error_array);
|
||||
|
||||
if (empty($error_array))
|
||||
{
|
||||
error_log('TEST GENERATEINVOICECRITERIA:');
|
||||
error_log('INVOICE');
|
||||
error_log('TOTAL PRICE: ' . $invoice->getTotalPrice());
|
||||
error_log('VAT EXCLUSIVE PRICE: ' . $invoice->getVATExclusivePrice());
|
||||
error_log('VAT: ' . $invoice->getVAT());
|
||||
error_log('DISCOUNT: ' . $invoice->getDiscount());
|
||||
error_log('TRADE-IN: ' . $invoice->getTradeIn());
|
||||
error_log('STATUS: ' . $invoice->getStatus());
|
||||
|
||||
$invoice_items = $invoice->getItems();
|
||||
|
||||
foreach ($invoice_items as $invoice_item)
|
||||
{
|
||||
error_log($invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error_log('TEST GENERATE INVOICE CRITERIA INVALID BATTERY: Errors found when generating invoice ' . print_r(json_encode($error_array), true));
|
||||
}
|
||||
}
|
||||
|
||||
// test generateDraftInvoice call from ajax call
|
||||
|
|
@ -2094,7 +2204,7 @@ class TestInvoiceManagerCommand extends Command
|
|||
|
||||
// create array of invoice items
|
||||
$items = [[
|
||||
'battery' => 1,
|
||||
'battery' => 1038,
|
||||
'quantity' => 1,
|
||||
'trade_in' => '',
|
||||
], [
|
||||
|
|
@ -2113,20 +2223,131 @@ class TestInvoiceManagerCommand extends Command
|
|||
|
||||
protected function testGenerateDraftInvoiceInvalidPromo()
|
||||
{
|
||||
$criteria = new InvoiceCriteria();
|
||||
|
||||
$criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW);
|
||||
$criteria->setIsTaxable();
|
||||
|
||||
$promo_id = 99;
|
||||
$service_charges = [];
|
||||
|
||||
// create array of invoice items
|
||||
$items = [[
|
||||
'battery' => 1038,
|
||||
'quantity' => 1,
|
||||
'trade_in' => '',
|
||||
]];
|
||||
|
||||
$error = $this->inv_manager->generateDraftInvoice($criteria, $promo_id, $service_charges, $items);
|
||||
|
||||
if ($error)
|
||||
error_log('TEST GENERATE DRAFT INVOICE PROMO ERROR: Errors found when generating draft invoice ' . print_r($error, true));
|
||||
else
|
||||
error_log('TEST GENERATE DRAFT INVOICE PROMO ERROR: No errors here');
|
||||
}
|
||||
|
||||
protected function testGenerateDraftInvoiceNonBatterySales()
|
||||
{
|
||||
$criteria = new InvoiceCriteria();
|
||||
|
||||
$criteria->setServiceType(ServiceType::JUMPSTART_TROUBLESHOOT);
|
||||
$criteria->setIsTaxable();
|
||||
|
||||
$promo_id = 1;
|
||||
$service_charges = [];
|
||||
|
||||
// create array of invoice items
|
||||
$items = [[
|
||||
'battery' => 1038,
|
||||
'quantity' => 1,
|
||||
'trade_in' => '',
|
||||
]];
|
||||
|
||||
$error = $this->inv_manager->generateDraftInvoice($criteria, $promo_id, $service_charges, $items);
|
||||
|
||||
if ($error)
|
||||
error_log('TEST GENERATE DRAFT NON BATTERY SALES: Errors found when generating draft invoice ' . print_r($error, true));
|
||||
else
|
||||
error_log('TEST GENERATE DRAFT NON BATTERY SALES: No errors here');
|
||||
}
|
||||
|
||||
protected function testGenerateDraftInvoiceBatterySalesNoPromo()
|
||||
{
|
||||
$criteria = new InvoiceCriteria();
|
||||
|
||||
$criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW);
|
||||
$criteria->setIsTaxable();
|
||||
|
||||
$promo_id = '';
|
||||
$service_charges = [];
|
||||
|
||||
// create array of invoice items
|
||||
$items = [[
|
||||
'battery' => 1038,
|
||||
'quantity' => 1,
|
||||
'trade_in' => '',
|
||||
]];
|
||||
|
||||
$error = $this->inv_manager->generateDraftInvoice($criteria, $promo_id, $service_charges, $items);
|
||||
|
||||
if ($error)
|
||||
error_log('TEST GENERATE DRAFT INVOICE BATTERY SALES NO PROMO: Errors found when generating draft invoice ' . print_r($error, true));
|
||||
else
|
||||
error_log('TEST GENERATE DRAFT INVOICE BATTERY SALES NO PROMO: No errors here');
|
||||
}
|
||||
|
||||
|
||||
// test generateInvoiceInvoice call from ajax call
|
||||
protected function testGenerateInvoice()
|
||||
{
|
||||
$criteria = new InvoiceCriteria();
|
||||
|
||||
// TEST SCENARIO: new battery, trade-in different battery, premium, with discount, with tax
|
||||
$criteria->setServiceType(ServiceType::BATTERY_REPLACEMENT_NEW);
|
||||
|
||||
$battery_id = 1038;
|
||||
$battery = $this->em->getRepository(Battery::class)->find($battery_id);
|
||||
|
||||
$promo_id = 1;
|
||||
$promo = $this->em->getRepository(Promo::class)->find($promo_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);
|
||||
|
||||
$criteria->addPromo($promo);
|
||||
|
||||
$criteria->setIsTaxable();
|
||||
|
||||
$invoice = $this->inv_manager->generateInvoice($criteria);
|
||||
|
||||
if ($invoice != null)
|
||||
{
|
||||
error_log('TEST GENERATEINVOICE:');
|
||||
error_log('INVOICE');
|
||||
error_log('TOTAL PRICE: ' . $invoice->getTotalPrice());
|
||||
error_log('VAT EXCLUSIVE PRICE: ' . $invoice->getVATExclusivePrice());
|
||||
error_log('VAT: ' . $invoice->getVAT());
|
||||
error_log('DISCOUNT: ' . $invoice->getDiscount());
|
||||
error_log('TRADE-IN: ' . $invoice->getTradeIn());
|
||||
error_log('STATUS: ' . $invoice->getStatus());
|
||||
|
||||
$invoice_items = $invoice->getItems();
|
||||
|
||||
foreach ($invoice_items as $invoice_item)
|
||||
{
|
||||
error_log($invoice_item->getTitle() . ' ' . $invoice_item->getQuantity() . ' ' . $invoice_item->getPrice());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error_log('TEST GENERATE INVOICE: Error found. ');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,14 +125,10 @@ class InvoiceManager
|
|||
// this is called by JobOrderController when JS script generateInvoice is called
|
||||
public function generateDraftInvoice($criteria, $promo_id, $service_charges, $items)
|
||||
{
|
||||
error_log('generateDraftInvoice');
|
||||
$ierror = $this->validatePromo($criteria, $promo_id);
|
||||
|
||||
error_log(print_r($ierror, true));
|
||||
|
||||
if (!$ierror && !empty($items))
|
||||
{
|
||||
error_log('calling validateInvoiceItems');
|
||||
// validate the invoice items (batteries and trade ins)
|
||||
$ierror = $this->validateInvoiceItems($criteria, $items);
|
||||
}
|
||||
|
|
@ -303,8 +299,6 @@ class InvoiceManager
|
|||
// check if this is a valid promo
|
||||
$promo = $this->em->getRepository(Promo::class)->find($promo_id);
|
||||
|
||||
error_log('promo checkpoint');
|
||||
|
||||
if (empty($promo))
|
||||
return 'Invalid promo specified.';
|
||||
|
||||
|
|
@ -315,7 +309,6 @@ class InvoiceManager
|
|||
|
||||
protected function validateInvoiceItems($criteria, $invoice_items)
|
||||
{
|
||||
error_log('validate invoice items');
|
||||
// check service type. Only battery sales and battery warranty should have invoice items
|
||||
$stype = $criteria->getServiceType();
|
||||
if ($stype != ServiceType::BATTERY_REPLACEMENT_NEW && $stype != ServiceType::BATTERY_REPLACEMENT_WARRANTY)
|
||||
|
|
@ -327,7 +320,6 @@ class InvoiceManager
|
|||
// check if this is a valid battery
|
||||
foreach ($invoice_items as $item)
|
||||
{
|
||||
error_log($item['battery']);
|
||||
$battery = $this->em->getRepository(Battery::class)->find($item['battery']);
|
||||
|
||||
if (empty($battery))
|
||||
|
|
|
|||
Loading…
Reference in a new issue