Merge branch '427-cmb-jo-test-data-for-rider-api' into '424-cmb-release'
Resolve "CMB - JO test data for Rider API" See merge request jankstudio/resq!493
This commit is contained in:
commit
38d9839a96
1 changed files with 173 additions and 0 deletions
173
src/Command/CreateJOTestDataCommand.php
Normal file
173
src/Command/CreateJOTestDataCommand.php
Normal file
|
|
@ -0,0 +1,173 @@
|
||||||
|
<?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\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use DateInterval;
|
||||||
|
|
||||||
|
use App\Entity\JobOrder;
|
||||||
|
use App\Entity\Rider;
|
||||||
|
use App\Entity\CustomerVehicle;
|
||||||
|
use App\Entity\Invoice;
|
||||||
|
use App\Entity\InvoiceItem;
|
||||||
|
use App\Entity\Battery;
|
||||||
|
|
||||||
|
use App\Ramcar\CMBServiceType;
|
||||||
|
use App\Ramcar\TransactionOrigin;
|
||||||
|
use App\Ramcar\WarrantyClass;
|
||||||
|
use App\Ramcar\ModeOfPayment;
|
||||||
|
use App\Ramcar\JOStatus;
|
||||||
|
use App\Ramcar\InvoiceStatus;
|
||||||
|
|
||||||
|
class CreateJOTestDataCommand extends Command
|
||||||
|
{
|
||||||
|
protected $em;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$this->em = $em;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this->setName('joborder:create_testdata')
|
||||||
|
->setDescription('Create JO test data, given a rider id.')
|
||||||
|
->setHelp('Create JO test data, given a rider id.')
|
||||||
|
->addArgument('rider_id', InputArgument::REQUIRED, 'Rider id.');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$rider_id = $input->getArgument('rider_id');
|
||||||
|
|
||||||
|
$rider = $this->em->getRepository(Rider::class)->find($rider_id);
|
||||||
|
|
||||||
|
// get customer vehicles where plate number is not null
|
||||||
|
$cv_query = $this->em->createQuery('SELECT cv FROM App\Entity\CustomerVehicle cv WHERE cv.plate_number is not null');
|
||||||
|
$cv_results = $cv_query->getResult();
|
||||||
|
|
||||||
|
// get the first customer vehicle
|
||||||
|
$cv = current($cv_results);
|
||||||
|
|
||||||
|
// get batteries
|
||||||
|
$battery_results = $this->em->getRepository(Battery::class)->findAll();
|
||||||
|
|
||||||
|
// get the first battery
|
||||||
|
$battery = current($battery_results);
|
||||||
|
|
||||||
|
error_log($cv->getPlateNumber());
|
||||||
|
error_log($battery->getID());
|
||||||
|
|
||||||
|
if (empty($rider))
|
||||||
|
{
|
||||||
|
error_log('Rider not found.');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// get current date
|
||||||
|
$current_date = new DateTime();
|
||||||
|
|
||||||
|
// for this month JO
|
||||||
|
$current_year = $current_date->format('Y');
|
||||||
|
$current_month = $current_date->format('M');
|
||||||
|
|
||||||
|
// for last month JO
|
||||||
|
$date_interval = new DateInterval('P1M');
|
||||||
|
$last_month_date = $current_date->sub($date_interval);
|
||||||
|
|
||||||
|
$last_month_year = $last_month_date->format('Y');
|
||||||
|
$last_month_month = $last_month_date->format('M');
|
||||||
|
|
||||||
|
$time_schedule = $current_date->format('h:i A');
|
||||||
|
|
||||||
|
$this->createJobOrders($rider, $cv, $battery, $last_month_year, $last_month_month, $time_schedule);
|
||||||
|
$this->createJobOrders($rider, $cv, $battery, $current_year, $current_month, $time_schedule);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createJobOrders(Rider $rider, CustomerVehicle $cv, Battery $battery, $year, $month, $time)
|
||||||
|
{
|
||||||
|
// insert 15 JOs for last month
|
||||||
|
for ($i = 1; $i <= 15; $i++)
|
||||||
|
{
|
||||||
|
$jo = new JobOrder();
|
||||||
|
|
||||||
|
// set customer data
|
||||||
|
$jo->setCustomerVehicle($cv);
|
||||||
|
$jo->setCustomer($cv->getCustomer());
|
||||||
|
|
||||||
|
// set hub and rider data
|
||||||
|
$jo->setRider($rider);
|
||||||
|
$jo->setHub($rider->getHub());
|
||||||
|
|
||||||
|
// set JO details
|
||||||
|
$point = new Point(121.0223, 14.6091);
|
||||||
|
$s_type = CMBServiceType::BATTERY_REPLACEMENT_NEW;
|
||||||
|
$source = TransactionOrigin::CALL;
|
||||||
|
$advance_order = true;
|
||||||
|
$warranty_class = WarrantyClass::WTY_PRIVATE;
|
||||||
|
$status = JOStatus::FULFILLED;
|
||||||
|
$delivery_address = '#1234 Moogle Lane';
|
||||||
|
$mode_of_payment = ModeOfPayment::CASH;
|
||||||
|
|
||||||
|
// set invoice details
|
||||||
|
$invoice = new Invoice();
|
||||||
|
$invoice_item = new InvoiceItem();
|
||||||
|
|
||||||
|
// set invoice item details
|
||||||
|
$invoice_item->setBattery($battery)
|
||||||
|
->setTitle($battery->getModel()->getName() . ' ' . $battery->getSize()->getName())
|
||||||
|
->setQuantity(1)
|
||||||
|
->setPrice($battery->getSellingPrice())
|
||||||
|
->setInvoice($invoice);
|
||||||
|
|
||||||
|
$invoice->addItem($invoice_item);
|
||||||
|
|
||||||
|
$this->em->persist($invoice_item);
|
||||||
|
|
||||||
|
// set invoice details
|
||||||
|
$invoice->setTotalPrice($battery->getSellingPrice())
|
||||||
|
->setStatus(InvoiceStatus::DRAFT)
|
||||||
|
->setVATExclusivePrice($battery->getSellingPrice())
|
||||||
|
->setDiscount(0.0)
|
||||||
|
->setTradeIn(0.0)
|
||||||
|
->setVAT(0.00);
|
||||||
|
|
||||||
|
$this->em->persist($invoice);
|
||||||
|
|
||||||
|
$jo->setInvoice($invoice);
|
||||||
|
|
||||||
|
// for last month
|
||||||
|
$date_schedule_date = $i . ' ' . $month . ' ' . $year . ' ' . $time;
|
||||||
|
error_log('Adding JO with date schedule ' . $date_schedule_date);
|
||||||
|
$date_schedule = DateTime::createFromFormat("d M Y h:i A", $date_schedule_date);
|
||||||
|
|
||||||
|
$jo->setDateSchedule($date_schedule)
|
||||||
|
->setCoordinates($point)
|
||||||
|
->setAdvanceOrder($advance_order)
|
||||||
|
->setServiceType($s_type)
|
||||||
|
->setWarrantyClass($warranty_class)
|
||||||
|
->setSource($source)
|
||||||
|
->setStatus($status)
|
||||||
|
->setDeliveryAddress($delivery_address);
|
||||||
|
|
||||||
|
$this->em->persist($jo);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue