Add saving of JOs. #427

This commit is contained in:
Korina Cordero 2020-06-18 04:38:08 +00:00
parent 9833a2709a
commit 0f06ca7339

View file

@ -10,7 +10,9 @@ 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;
@ -24,6 +26,7 @@ use App\Ramcar\TransactionOrigin;
use App\Ramcar\WarrantyClass;
use App\Ramcar\ModeOfPayment;
use App\Ramcar\JOStatus;
use App\Ramcar\InvoiceStatus;
class CreateJOTestDataCommand extends Command
{
@ -75,12 +78,28 @@ class CreateJOTestDataCommand extends Command
// 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');
$period_date = $current_date->sub($date_interval);
$last_month_date = $current_date->sub($date_interval);
$period_year = $period_date->format('Y');
$period_month = $period_date->format('m');
$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++)
{
@ -96,11 +115,11 @@ class CreateJOTestDataCommand extends Command
// set JO details
$point = new Point(121.0223, 14.6091);
$type = CMBServiceType::BATTERY_REPLACEMENT_NEW;
$s_type = CMBServiceType::BATTERY_REPLACEMENT_NEW;
$source = TransactionOrigin::CALL;
$advance_order = true;
$warranty_class = WarrantyClass::WTY_PRIVATE;
$status = JOStatus::ASSIGNED;
$status = JOStatus::FULFILLED;
$delivery_address = '#1234 Moogle Lane';
$mode_of_payment = ModeOfPayment::CASH;
@ -110,28 +129,45 @@ class CreateJOTestDataCommand extends Command
// set invoice item details
$invoice_item->setBattery($battery)
->setTitle($battery->getModel()->getName() - ' ' . $battery->getSize()->getName())
->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)
->setVAT(0.00);
$this->em->persist($invoice);
$jo->setInvoice($invoice);
$date_schedule = DateTime::createFromFormat("d M Y h:i A",
// 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();
}
}
return 0;
}
}