Draft: Resolve "Hub Filtered Job Order Report" #1540
5 changed files with 308 additions and 0 deletions
|
|
@ -346,6 +346,8 @@ access_keys:
|
|||
label: Customer Source Report
|
||||
- id: report.hub.filter
|
||||
label: Hub Filter Report
|
||||
- id: report.jo.hub_filtered
|
||||
label: Hub Filtered JobOrder Report
|
||||
|
||||
- id: service
|
||||
label: Other Services
|
||||
|
|
|
|||
|
|
@ -147,3 +147,13 @@ rep_hub_filter_submit:
|
|||
path: /report/hub_filter_report
|
||||
controller: App\Controller\ReportController::hubFilterSubmit
|
||||
methods: [POST]
|
||||
|
||||
rep_jo_hub_filtered_form:
|
||||
path: /report/jo_hub_filtered_report
|
||||
controller: App\Controller\ReportController::joHubFilteredForm
|
||||
methods: [GET]
|
||||
|
||||
rep_jo_hub_filtered_submit:
|
||||
path: /report/jo_hub_filtered_report
|
||||
controller: App\Controller\ReportController:joHubFilteredSubmit
|
||||
methods: [POST]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use App\Ramcar\JOStatus;
|
|||
use App\Ramcar\InvalidPlateNumber;
|
||||
use App\Ramcar\JOEventType;
|
||||
use App\Ramcar\SMSStatus;
|
||||
use App\Ramcar\WillingToWaitContent;
|
||||
|
||||
use App\Entity\JORejection;
|
||||
use App\Entity\Battery;
|
||||
|
|
@ -1177,6 +1178,66 @@ class ReportController extends Controller
|
|||
$resp->headers->set('Content-Type', 'text/csv; charset=utf-8');
|
||||
$resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
||||
|
||||
return $resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="outlet_list")
|
||||
*/
|
||||
public function joHubFilteredForm()
|
||||
{
|
||||
$this->denyAccessUnlessGranted('report.jo.hub_filtered', null, 'No access.');
|
||||
|
||||
return $this->render('report/jo-hub-filtered/form.html.twig');
|
||||
}
|
||||
|
||||
public function joHubFilteredSubmit(Request $req, EntityManagerInterface $em)
|
||||
{
|
||||
// get dates
|
||||
$raw_date_start = $req->request->get('date_start');
|
||||
$raw_date_end = $req->request->get('date_end');
|
||||
|
||||
$date_start = DateTime::createFromFormat('m/d/Y', $raw_date_start);
|
||||
$date_end = DateTime::createFromFormat('m/d/Y', $raw_date_end);
|
||||
|
||||
$data = $this->getJobOrderHubFilteredData($req, $em, $raw_date_start, $raw_date_end);
|
||||
|
||||
$resp = new StreamedResponse();
|
||||
$resp->setCallback(function() use ($data) {
|
||||
// csv output
|
||||
$csv_handle = fopen('php://output', 'w+');
|
||||
fputcsv($csv_handle, [
|
||||
'Job Order Number',
|
||||
'Customer Name',
|
||||
'Customer Mobile Number',
|
||||
'Plate Number',
|
||||
'Service Type',
|
||||
'Distributor',
|
||||
'Battery Facilitated By',
|
||||
'Scheduled Date and Time',
|
||||
'SKU',
|
||||
'Invoice/DR No.',
|
||||
'Created Date and Time',
|
||||
'Date and Time Dispatched',
|
||||
'Dispatcher',
|
||||
'Source',
|
||||
'Status',
|
||||
]);
|
||||
|
||||
foreach ($data as $row)
|
||||
{
|
||||
fputcsv($csv_handle, $row);
|
||||
}
|
||||
|
||||
fclose($csv_handle);
|
||||
});
|
||||
|
||||
$filename = 'job_orders_hub_filtered_' . $date_start->format('Ymd') . '_' . $date_end->format('Ymd') . '.csv';
|
||||
|
||||
$resp->setStatusCode(200);
|
||||
$resp->headers->set('Content-Type', 'text/csv; charset=utf-8');
|
||||
$resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
||||
|
||||
return $resp;
|
||||
|
||||
}
|
||||
|
|
@ -2361,6 +2422,149 @@ class ReportController extends Controller
|
|||
return $result;
|
||||
}
|
||||
|
||||
protected function getJobOrderHubFilteredData($req, $em, $raw_date_start, $raw_date_end)
|
||||
{
|
||||
$date_start = DateTime::createFromFormat('m/d/Y', $raw_date_start);
|
||||
$date_end = DateTime::createFromFormat('m/d/Y', $raw_date_end);
|
||||
|
||||
// change to this format: Y-m-d H:i:s
|
||||
$new_date_start = $date_start->format('Y-m-d H:i:s');
|
||||
$new_date_end = $date_end->format('Y-m-d H:i:s');
|
||||
|
||||
$non_emergency = WillingToWaitContent::WILLING_TO_WAIT;
|
||||
|
||||
// pdo connection. JO table and the hub filter log table get big very fast.
|
||||
$db = $em->getConnection();
|
||||
|
||||
// get job order ids that are non-emergency, are in the hub_filter_log
|
||||
// and has hub assigned, group by JO id and hub filter log's date create
|
||||
// between start and end date
|
||||
$sql = 'SELECT jo.id AS joid FROM job_order jo, hub_filter_log hf, hub h
|
||||
WHERE jo.will_wait=:non_emergency
|
||||
AND hf.jo_id=jo.id
|
||||
AND jo.hub_id=h.id
|
||||
AND hf.date_create >= :date_start
|
||||
AND hf.date_create <= :date_end
|
||||
GROUP BY jo.id
|
||||
ORDER BY hf.date_create';
|
||||
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute([
|
||||
'non_emergency' => $non_emergency,
|
||||
'date_start' => $new_date_start,
|
||||
'date_end' => $new_date_end,
|
||||
]);
|
||||
|
||||
$result = [];
|
||||
// go through rows
|
||||
while ($row = $stmt->fetch(PDO::FETCH_NUM))
|
||||
{
|
||||
// get jo details using the id
|
||||
$jo_id = $row[0];
|
||||
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
|
||||
|
||||
// get customer information
|
||||
$cust_name = '';
|
||||
$cust_mobile_number = '';
|
||||
$plate_number = '';
|
||||
|
||||
$customer = $jo->getCustomer();
|
||||
if ($customer != null)
|
||||
{
|
||||
$cust_name = $customer->getNameDisplay();
|
||||
|
||||
// get mobile number from mobile session
|
||||
// find latest generated mobile session for customer
|
||||
$mobile_sessions = $em->getRepository(MobileSession::class)->findBy(['customer' => $customer], ['date_generated' => 'DESC']);
|
||||
if ($mobile_sessions != null)
|
||||
{
|
||||
foreach($mobile_sessions as $mobile_session)
|
||||
{
|
||||
$cust_mobile_number = $mobile_session->getPhoneNumber();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get customer vehicle
|
||||
$cust_vehicle = $jo->getCustomerVehicle();
|
||||
if ($cust_vehicle != null)
|
||||
$plate_number = $cust_vehicle->getPlateNumber();
|
||||
|
||||
// get facilitated hub coordinates if any
|
||||
$fac_hub_name = '';
|
||||
$fac_hub = $jo->getFacilitatedBy();
|
||||
if ($fac_hub != null)
|
||||
$fac_hub_name = $fac_hub->getName();
|
||||
|
||||
// get jo date schedule if any
|
||||
$datetime_sked_jo = '';
|
||||
$jo_date_scheduled = $jo->getDateSchedule();
|
||||
if (empty($jo_date_scheduled))
|
||||
{
|
||||
// set to same date and time as date create of JO
|
||||
$datetime_sked_jo = $datetime_create_jo;
|
||||
}
|
||||
else
|
||||
$datetime_sked_jo = $jo_date_scheduled->format('d-M-Y H:i');
|
||||
|
||||
// get invoice date create and item sku if any
|
||||
$sku = '';
|
||||
$invoice = $jo->getInvoice();
|
||||
if ($invoice != null)
|
||||
{
|
||||
// get item sku
|
||||
$invoice_items = $invoice->getItems();
|
||||
foreach ($invoice_items as $item)
|
||||
{
|
||||
$battery = $item->getBattery();
|
||||
if ($battery != null)
|
||||
$sku = $battery->getModel()->getName() . ' ' . $battery->getSize()->getName();
|
||||
}
|
||||
}
|
||||
|
||||
// find date and time when JO was assigned a hub
|
||||
$datetime_hub_assign_jo = '';
|
||||
$hub_assign_event_type = JOEventType::HUB_ASSIGN;
|
||||
$hub_assign_events = $em->getRepository(JOEvent::class)->findBy(['job_order' => $jo, 'type_id'=> $hub_assign_event_type], ['date_happen' => 'DESC']);
|
||||
if ($hub_assign_events != null)
|
||||
{
|
||||
// TODO: what happens if JO was reassigned a hub multiple times?
|
||||
// right now, this gets the last time hub was assigned.
|
||||
foreach ($hub_assign_events as $hub_assign_event)
|
||||
{
|
||||
$datetime_hub_assign_jo = $hub_assign_event->getDateHappen()->format('d-M-Y H:i');
|
||||
}
|
||||
}
|
||||
|
||||
// get dispatcher if any
|
||||
$dispatcher_name = '';
|
||||
$dispatcher = $jo->getProcessedBy();
|
||||
if ($dispatcher != null)
|
||||
$dispatcher_name = $dispatcher->getFullName();
|
||||
|
||||
|
||||
$result[] = [
|
||||
$jo_id, // job order id
|
||||
$cust_name,
|
||||
$cust_mobile_number,
|
||||
$plate_number,
|
||||
$jo->getServiceType(),
|
||||
$jo->getHub()->getName(),
|
||||
$fac_hub_name,
|
||||
$datetime_sked_jo,
|
||||
$sku,
|
||||
$jo->getORName(),
|
||||
$jo->getDateCreate()->format('d-M-Y H:i'),
|
||||
$datetime_hub_assign_jo,
|
||||
$dispatcher_name,
|
||||
$jo->getSource(),
|
||||
$jo->getStatus(),
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getRESQCustomerIDs(EntityManagerInterface $em)
|
||||
{
|
||||
// pdo connection
|
||||
|
|
|
|||
|
|
@ -182,6 +182,16 @@
|
|||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="m-menu__item " data-redirect="true" aria-haspopup="true">
|
||||
<a href= "{{ url('rep_jo_hub_filtered_form') }}" class="m-menu__link">
|
||||
<i class="m-menu__link-bullet m-menu__link-bullet--dot">
|
||||
<span></span>
|
||||
</i>
|
||||
<span class="m-menu__link-text">
|
||||
Hub Filtered Job Orders Report
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="m-menu__item">
|
||||
|
|
|
|||
82
templates/report/jo-hub-filtered/form.html.twig
Normal file
82
templates/report/jo-hub-filtered/form.html.twig
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
<!-- BEGIN: Subheader -->
|
||||
<div class="m-subheader">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-auto">
|
||||
<h3 class="m-subheader__title">Hub Filtered Job Orders Report</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-6">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__head">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<span class="m-portlet__head-icon">
|
||||
<i class="fa fa-calendar"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text">
|
||||
Select a date range
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form id="row-form" autocomplete="off" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ url('rep_jo_hub_filtered_submit') }}">
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="input-daterange input-group" id="date-range">
|
||||
<input role="presentation" type="text" class="form-control m-input" name="date_start" placeholder="Start date" />
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text"><i class="la la-ellipsis-h"></i></span>
|
||||
</div>
|
||||
<input role="presentation" type="text" class="form-control" name="date_end" placeholder="End date" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__foot m-portlet__foot--fit">
|
||||
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<button type="submit" class="btn btn-success">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
$(function() {
|
||||
$("#date-range").datepicker({
|
||||
orientation: "bottom"
|
||||
});
|
||||
|
||||
$("#row-form").submit(function(e) {
|
||||
var form = $(this);
|
||||
|
||||
if (!$("[name='date_start']").val() || !$("[name='date_end']").val()) {
|
||||
e.preventDefault();
|
||||
|
||||
swal({
|
||||
title: 'Whoops!',
|
||||
text: 'Please fill in both date fields.',
|
||||
type: 'warning'
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
Loading…
Reference in a new issue