Add a service that sets the job order as fulfilled and sets the current battery of the customer vehicle to the battery that was purchased. Create a command that tests the service. #204
This commit is contained in:
parent
680f27316f
commit
fd6e617f95
2 changed files with 93 additions and 0 deletions
40
src/Command/TestJobOrderFulfillCommand.php
Normal file
40
src/Command/TestJobOrderFulfillCommand.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?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 App\Service\JobOrderFulfill;
|
||||
|
||||
class TestJobOrderFulfillCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('test:fulfilljoborder')
|
||||
->setDescription('Test fulfill job order service.')
|
||||
->setHelp('Test the fulfill job order service.')
|
||||
->addArgument('job_order_id', InputArgument::REQUIRED, 'Job Order ID');
|
||||
}
|
||||
|
||||
public function __construct(JobOrderFulfill $fulfill_jo)
|
||||
{
|
||||
$this->fulfill_jo = $fulfill_jo;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$jo_id = $input->getArgument('job_order_id');
|
||||
|
||||
$result = $this->fulfill_jo->fulfillJobOrder($jo_id);
|
||||
|
||||
if ($result)
|
||||
echo "Job Order successfully updated" . "\n";
|
||||
else
|
||||
echo "Job Order not updated" . "\n";
|
||||
}
|
||||
}
|
||||
53
src/Service/JobOrderFulfill.php
Normal file
53
src/Service/JobOrderFulfill.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\JobOrder;
|
||||
|
||||
use App\Ramcar\ServiceType;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class JobOrderFulfill
|
||||
{
|
||||
protected $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function fulfillJobOrder($jo_id)
|
||||
{
|
||||
$results = $this->em->getRepository(JobOrder::class)->findby(array('id' => $jo_id, 'service_type' => ServiceType::BATTERY_REPLACEMENT_NEW));
|
||||
if (isset($results[0]))
|
||||
{
|
||||
$jo = $results[0];
|
||||
$jo->fulfill();
|
||||
|
||||
$cust_vehicle = $jo->getCustomerVehicle();
|
||||
$invoice = $jo->getInvoice();
|
||||
$this->updateCustomerVehicleBattery($cust_vehicle, $invoice);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function updateCustomerVehicleBattery($cust_vehicle, $invoice)
|
||||
{
|
||||
if (($cust_vehicle != null) && ($invoice != null))
|
||||
{
|
||||
$items = $invoice->getItems();
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$new_battery = $item->getBattery();
|
||||
$cust_vehicle->setCurrentBattery($new_battery);
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue