Create Symfony command to generate warranties from existing job orders #187
This commit is contained in:
parent
7e7d99d9c9
commit
084d058341
1 changed files with 29 additions and 5 deletions
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
namespace App\Command;
|
namespace App\Command;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use DateInterval;
|
||||||
|
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
|
@ -33,6 +36,13 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
||||||
->setHelp('Generate warranty from job order');
|
->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)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$em = $this->em;
|
$em = $this->em;
|
||||||
|
|
@ -61,18 +71,32 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
||||||
$battery_sap_code = $invoice_item->getBattery()->getSAPCode();
|
$battery_sap_code = $invoice_item->getBattery()->getSAPCode();
|
||||||
$sap_battery = $this->em->getRepository(SAPBattery::class)->find($battery_sap_code);
|
$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
|
$warranty_period = $invoice_item->getBattery()->getWarrantyPrivate();
|
||||||
// get warranty period from battery. Check if personal or commercial
|
}
|
||||||
// warranty period in battery is in months
|
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 = new Warranty();
|
||||||
$warranty->setWarrantyClass($jo->getWarrantyClass())
|
$warranty->setWarrantyClass($jo->getWarrantyClass())
|
||||||
->setFirstName($jo->getCustomer()->getFirstName())
|
->setFirstName($jo->getCustomer()->getFirstName())
|
||||||
->setLastName($jo->getCustomer()->getLastName())
|
->setLastName($jo->getCustomer()->getLastName())
|
||||||
->setMobileNumber($jo->getCustomer()->getPhoneMobile())
|
->setMobileNumber($jo->getCustomer()->getPhoneMobile())
|
||||||
->setPlateNumber($jo->getCustomerVehicle()->getPlateNumber())
|
->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())
|
->setBatteryModel($invoice_item->getBattery()->getModel())
|
||||||
->setBatterySize($invoice_item->getBattery()->getSize())
|
->setBatterySize($invoice_item->getBattery()->getSize())
|
||||||
->setSAPBattery($sap_battery);
|
->setSAPBattery($sap_battery);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue