Create Symfony command to generate warranties from existing job orders #187

This commit is contained in:
Korina Cordero 2019-02-26 20:04:51 -05:00
parent 7e7d99d9c9
commit 084d058341

View file

@ -2,6 +2,9 @@
namespace App\Command;
use DateTime;
use DateInterval;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@ -33,6 +36,13 @@ class GenerateWarrantyFromJobOrderCommand extends Command
->setHelp('Generate warranty from job order');
}
protected function computeDateExpire($date_create, $warranty_period)
{
$expire_date = clone $date_create;
$expire_date->add(new DateInterval('P'.$warranty_period.'M'));
return $expire_date;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->em;
@ -61,18 +71,32 @@ class GenerateWarrantyFromJobOrderCommand extends Command
$battery_sap_code = $invoice_item->getBattery()->getSAPCode();
$sap_battery = $this->em->getRepository(SAPBattery::class)->find($battery_sap_code);
if ($jo->getInvoice()->getDatePaid() != null)
// get warranty period for battery
$warranty_period = 0;
if ($invoice_item->getBattery()->getWarrantyPrivate() != null)
{
// TODO: compute for date_expire = datePurchase + warranty period
// get warranty period from battery. Check if personal or commercial
// warranty period in battery is in months
$warranty_period = $invoice_item->getBattery()->getWarrantyPrivate();
}
else
{
$warranty_period = $invoice_item->getBattery()->getWarrantyCommercial();
}
if ($jo->getInvoice()->getDateCreate() != null)
{
// check if plate number is "clean". If not, do not insert into warranty
if (!(Warranty::cleanPlateNumber($jo->getCustomerVehicle()->getPlateNumber())))
{
continue;
}
$warranty = new Warranty();
$warranty->setWarrantyClass($jo->getWarrantyClass())
->setFirstName($jo->getCustomer()->getFirstName())
->setLastName($jo->getCustomer()->getLastName())
->setMobileNumber($jo->getCustomer()->getPhoneMobile())
->setPlateNumber($jo->getCustomerVehicle()->getPlateNumber())
->setDatePurchase($jo->getInvoice()->getDatePaid())
->setDatePurchase($jo->getInvoice()->getDateCreate())
->setDateExpire($this->computeDateExpire($jo->getInvoice()->getDateCreate(), $warranty_period))
->setBatteryModel($invoice_item->getBattery()->getModel())
->setBatterySize($invoice_item->getBattery()->getSize())
->setSAPBattery($sap_battery);