Add initial changes to script that generates warranties for existing job orders

This commit is contained in:
Korina Cordero 2019-02-22 05:29:10 -05:00
parent 55d9fb329f
commit 7e7d99d9c9
2 changed files with 101 additions and 0 deletions

View file

@ -0,0 +1,86 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use App\Entity\JobOrder;
use App\Entity\Warranty;
use App\Entity\SAPBattery;
use App\Ramcar\ServiceType;
class GenerateWarrantyFromJobOrderCommand extends Command
{
protected $em;
public function __construct(ObjectManager $em)
{
$this->em = $em;
parent::__construct();
}
protected function configure()
{
$this->setName('warranty:generate')
->setDescription('Generates warranty from job order and inserts into database')
->setHelp('Generate warranty from job order');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->em;
$qb = $this->em->getRepository(JobOrder::class)->createQueryBuilder('j');
// get all job orders with service_type='battery_warranty'
$qb->select('j')
->where('j.service_type = :service_type')
->setParameter('service_type', ServiceType::BATTERY_REPLACEMENT_WARRANTY);
$query = $qb->getQuery();
$result = $query->getResult();
foreach ($result as $jo)
{
$invoice_items = [];
// For now, one invoice == one battery
$invoice_items = $jo->getInvoice()->getItems();
$invoice_item = $invoice_items[0];
if ($invoice_item != null)
{
if($invoice_item->getBattery() != null)
{
// manually retrieve the SAPBattery using the SAPCode
$battery_sap_code = $invoice_item->getBattery()->getSAPCode();
$sap_battery = $this->em->getRepository(SAPBattery::class)->find($battery_sap_code);
if ($jo->getInvoice()->getDatePaid() != 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 = 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())
->setBatteryModel($invoice_item->getBattery()->getModel())
->setBatterySize($invoice_item->getBattery()->getSize())
->setSAPBattery($sap_battery);
$em->persist($warranty);
}
$em->flush();
}
}
}
}
}

View file

@ -1,4 +1,16 @@
{
"creof/doctrine2-spatial": {
"version": "1.2.0"
},
"creof/geo-parser": {
"version": "2.1.0"
},
"creof/wkb-parser": {
"version": "v2.3.0"
},
"creof/wkt-parser": {
"version": "2.2.0"
},
"data-dog/audit-bundle": {
"version": "v0.1.10"
},
@ -263,6 +275,9 @@
"symfony/stopwatch": {
"version": "v4.0.2"
},
"symfony/thanks": {
"version": "v1.1.0"
},
"symfony/twig-bridge": {
"version": "v4.0.2"
},