From fd6e617f95eb5c453b64968449d57a24326bdd9c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 12 Apr 2019 07:39:21 +0000 Subject: [PATCH 1/3] 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 --- src/Command/TestJobOrderFulfillCommand.php | 40 ++++++++++++++++ src/Service/JobOrderFulfill.php | 53 ++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 src/Command/TestJobOrderFulfillCommand.php create mode 100644 src/Service/JobOrderFulfill.php diff --git a/src/Command/TestJobOrderFulfillCommand.php b/src/Command/TestJobOrderFulfillCommand.php new file mode 100644 index 00000000..258fac01 --- /dev/null +++ b/src/Command/TestJobOrderFulfillCommand.php @@ -0,0 +1,40 @@ +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"; + } +} diff --git a/src/Service/JobOrderFulfill.php b/src/Service/JobOrderFulfill.php new file mode 100644 index 00000000..b73044a8 --- /dev/null +++ b/src/Service/JobOrderFulfill.php @@ -0,0 +1,53 @@ +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(); + } + } +} From 24715196e5be3db3cb0de17efd894237a5590460 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 15 Apr 2019 08:58:30 +0000 Subject: [PATCH 2/3] Create command to update the battery of the customer vehicle to the battery last purchased. #204 --- .../UpdateCustomerVehicleBatteryCommand.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/Command/UpdateCustomerVehicleBatteryCommand.php diff --git a/src/Command/UpdateCustomerVehicleBatteryCommand.php b/src/Command/UpdateCustomerVehicleBatteryCommand.php new file mode 100644 index 00000000..f7e09e30 --- /dev/null +++ b/src/Command/UpdateCustomerVehicleBatteryCommand.php @@ -0,0 +1,67 @@ +em = $om; + $this->custvehicle_hash = []; + + parent::__construct(); + } + + protected function configure() + { + $this->setName('joborder:updatebattery') + ->setDescription('Update customer vehicle battery information.') + ->setHelp('Updates the customer vehicle battery based on the latest battery purchased. '); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + // get all job orders with fulfilled status + $jos = $this->em->getRepository(JobOrder::class)->findBy(['status' => JOStatus::FULFILLED], ['date_create' => 'DESC']); + foreach ($jos as $jo) + { + if ($jo->getCustomerVehicle() != null) + { + $custvehicle_id = $jo->getCustomerVehicle()->getID(); + // check if custvehicle is in hash. This would mean that the battery has already been set + if(!isset($this->custvehicle_hash[$custvehicle_id])) + { + // get battery purchased from job order + $items = $jo->getInvoice()->getItems(); + foreach($items as $item) + { + if ($item->getBattery() != null) + { + // set battery of vehicle to the latest battery purchased + $new_battery = $item->getBattery(); + $jo->getCustomerVehicle()->setCurrentBattery($new_battery); + + // add customer vehicle to hash + $this->custvehicle_hash[$custvehicle_id] = true; + } + } + $this->em->flush(); + } + } + } + } +} From 4e711ca2c329c725e3499e8e1945d7ecc883acb6 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 22 Apr 2019 06:04:22 +0000 Subject: [PATCH 3/3] Rename the service to JobOrderManager. #204 --- ...lfillCommand.php => TestJobOrderManagerCommand.php} | 10 +++++----- .../{JobOrderFulfill.php => JobOrderManager.php} | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) rename src/Command/{TestJobOrderFulfillCommand.php => TestJobOrderManagerCommand.php} (78%) rename src/Service/{JobOrderFulfill.php => JobOrderManager.php} (98%) diff --git a/src/Command/TestJobOrderFulfillCommand.php b/src/Command/TestJobOrderManagerCommand.php similarity index 78% rename from src/Command/TestJobOrderFulfillCommand.php rename to src/Command/TestJobOrderManagerCommand.php index 258fac01..4beeea46 100644 --- a/src/Command/TestJobOrderFulfillCommand.php +++ b/src/Command/TestJobOrderManagerCommand.php @@ -7,9 +7,9 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use App\Service\JobOrderFulfill; +use App\Service\JobOrderManager; -class TestJobOrderFulfillCommand extends Command +class TestJobOrderManagerCommand extends Command { protected function configure() { @@ -19,9 +19,9 @@ class TestJobOrderFulfillCommand extends Command ->addArgument('job_order_id', InputArgument::REQUIRED, 'Job Order ID'); } - public function __construct(JobOrderFulfill $fulfill_jo) + public function __construct(JobOrderManager $jo_manager) { - $this->fulfill_jo = $fulfill_jo; + $this->jo_manager = $jo_manager; parent::__construct(); } @@ -30,7 +30,7 @@ class TestJobOrderFulfillCommand extends Command { $jo_id = $input->getArgument('job_order_id'); - $result = $this->fulfill_jo->fulfillJobOrder($jo_id); + $result = $this->jo_manager->fulfillJobOrder($jo_id); if ($result) echo "Job Order successfully updated" . "\n"; diff --git a/src/Service/JobOrderFulfill.php b/src/Service/JobOrderManager.php similarity index 98% rename from src/Service/JobOrderFulfill.php rename to src/Service/JobOrderManager.php index b73044a8..94d923a3 100644 --- a/src/Service/JobOrderFulfill.php +++ b/src/Service/JobOrderManager.php @@ -8,7 +8,7 @@ use App\Ramcar\ServiceType; use Doctrine\ORM\EntityManagerInterface; -class JobOrderFulfill +class JobOrderManager { protected $em;