Add command to add test JO data

This commit is contained in:
Korina Cordero 2020-06-18 03:47:46 +00:00
parent 2cd7a277cb
commit 9833a2709a

View file

@ -0,0 +1,137 @@
<?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 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;
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();
$date_interval = new DateInterval('P1M');
$period_date = $current_date->sub($date_interval);
$period_year = $period_date->format('Y');
$period_month = $period_date->format('m');
// 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);
$type = CMBServiceType::BATTERY_REPLACEMENT_NEW;
$source = TransactionOrigin::CALL;
$advance_order = true;
$warranty_class = WarrantyClass::WTY_PRIVATE;
$status = JOStatus::ASSIGNED;
$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);
// set invoice details
$invoice->setTotalPrice($battery->getSellingPrice())
->setStatus(InvoiceStatus::DRAFT)
->setVATExclusivePrice($battery->getSellingPrice())
->setDiscount(0.0)
->setTradeIn(0.0)
->setVAT(0.00)
$jo->setInvoice($invoice);
$date_schedule = DateTime::createFromFormat("d M Y h:i A",
}
}
return 0;
}
}