Merge branch '716-jo-raffle-report' of gitlab.com:jankstudio/resq into 717-log-warranty-activities-from-app

Conflicts:
	config/acl.yaml
	config/routes/report.yaml
	src/Controller/ReportController.php
This commit is contained in:
Korina Cordero 2022-11-14 11:58:25 +00:00
commit 8d9c02ae72
5 changed files with 249 additions and 1 deletions

View file

@ -350,6 +350,8 @@ access_keys:
label: Hub Filter Report
- id: report.warranty.raffle
label: Warranty Raffle Report
- id: report.jo.raffle
label: JO Raffle Report
- id: service
label: Other Services

View file

@ -157,3 +157,13 @@ rep_warranty_raffle_submit:
path: /report/warranty_raffle_report
controller: App\Controller\ReportController::warrantyRaffleSubmit
methods: [POST]
rep_jo_raffle_form:
path: /report/jo_raffle_report
controller: App\Controller\ReportController::joRaffleForm
methods: [GET]
rep_jo_raffle_submit:
path: /report/jo_raffle_report
controller: App\Controller\ReportController::joRaffleSubmit
methods: [POST]

View file

@ -1232,6 +1232,16 @@ class ReportController extends Controller
return $this->render('report/warranty-raffle/form.html.twig');
}
/**
* @Menu(selected="outlet_list")
*/
public function joRaffleForm()
{
$this->denyAccessUnlessGranted('report.jo.raffle', null, 'No access.');
return $this->render('report/jo-raffle/form.html.twig');
}
public function warrantyRaffleSubmit(Request $req, EntityManagerInterface $em)
{
// get dates
@ -1253,7 +1263,7 @@ class ReportController extends Controller
'Product Name',
'Transaction Number', // Warranty ID
'Date',
'Outlet',
'Outlet',
'Plate Number',
'Warranty Class',
'First Name',
@ -1272,7 +1282,54 @@ class ReportController extends Controller
});
$filename = 'warranty_raffle_' . $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;
}
public function joRaffleSubmit(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->getJORaffleData($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, [
'Raffle Number',
'Serial Number',
'Product Name',
'Transaction Number', // JO ID
'Date',
'Outlet', // Hub
'Plate Number',
'Warranty Class',
'First Name',
'Last Name',
'Contact Number',
'Address',
'Email',
]);
foreach ($data as $row)
{
fputcsv($csv_handle, $row);
}
fclose($csv_handle);
});
$filename = 'jo_raffle_' . $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 . '"');
@ -2739,4 +2796,91 @@ class ReportController extends Controller
return $wrl_data;
}
protected function getJORaffleData($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') . ' 00:00:00';
$new_date_end = $date_end->format('Y-m-d H:i:s') . ' 23:59:59';
$db = $em->getConnection();
// get JOs that have been scheduled within the date range and are fulfilled
// and service type is battery sales
$jo_sql = 'SELECT jo.id AS jo_id, cv.warranty_code AS serial, jo.date_schedule AS date_schedule,
h.name AS hub_name, cv.plate_number AS plate_number, jo.warranty_class AS warranty_class,
c.first_name AS first_name, c.last_name AS last_name, c.phone_mobile AS mobile_number,
c.email AS email
FROM job_order jo, customer_vehicle cv, hub h, customer c
WHERE jo.cvehicle_id = cv.id
AND jo.customer_id = c.id
AND jo.hub_id = h.id
AND jo.status = :fulfilled
AND jo.service_type = :battery_sales
AND jo.date_schedule >= :date_start AND jo.date_schedule <= :date_end';
$jo_stmt = $db->prepare($jo_sql);
$jo_stmt->bindValue('fulfilled', JOStatus::FULFILLED);
$jo_stmt->bindValue('battery_sales', ServiceType::BATTERY_REPLACEMENT_NEW);
$jo_stmt->bindValue('date_start', $new_date_start);
$jo_stmt->bindValue('date_end', $new_date_end);
$jo_result = $jo_stmt->executeQuery();
$jo_data = [];
// go through rows
while($row = $jo_result->fetchAssociative())
{
// need to get the battery ordered
$jo_id = $row['jo_id'];
$b_sql = 'SELECT bmodel.name AS model_name, bsize.name AS size_name
FROM battery_model bmodel, battery_size bsize, battery b,
invoice i, invoice_item ii
WHERE b.model_id = bmodel.id
AND b.size_id = bsize.id
AND ii.invoice_id = i.id
AND ii.battery_id = b.id
AND i.job_order_id = :jo_id';
$b_stmt = $db->prepare($b_sql);
$b_stmt->bindValue('jo_id', $jo_id);
$b_result = $b_stmt->executeQuery();
$b_data = [];
$battery_name = '';
while ($b_row = $b_result->fetchAssociative())
{
$battery_name = $b_row['model_name'] . ' / ' . $b_row['size_name'];
}
// get the date from the date schedule
$date_array = explode(' ' , $row['date_schedule']);
$date_schedule = $date_array[0];
$raffle_number = '';
$address = '';
$jo_data[] = [
'raffle_num' => $raffle_number,
'serial' => $row['serial'],
'product_name' => $battery_name,
'jo_id' => $jo_id,
'date' => $date_schedule,
'hub' => $row['hub_name'],
'plate_number' => $row['plate_number'],
'warranty_class' => $row['warranty_class'],
'first_name' => $row['first_name'],
'last_name' => $row['last_name'],
'contact_number' => $row['mobile_number'],
'address' => $address,
'email' => $row['email']
];
}
return $jo_data;
}
}

View file

@ -182,6 +182,16 @@
</span>
</a>
</li>
<li class="m-menu__item " data-redirect="true" aria-haspopup="true">
<a href= "{{ url('rep_jo_raffle_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">
Job Order Raffle Report
</span>
</a>
</li>
</ul>
</li>
<li class="m-menu__item">

View 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">Job Order Raffle 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_raffle_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 %}