Add warranty raffle report. #717

This commit is contained in:
Korina Cordero 2022-11-14 08:11:49 +00:00
parent f2a661f696
commit 29468c629b
5 changed files with 244 additions and 0 deletions

View file

@ -348,6 +348,8 @@ access_keys:
label: Customer Source Report
- id: report.hub.filter
label: Hub Filter Report
- id: report.warranty.raffle
label: Warranty Raffle Report
- id: service
label: Other Services

View file

@ -147,3 +147,13 @@ rep_hub_filter_submit:
path: /report/hub_filter_report
controller: App\Controller\ReportController::hubFilterSubmit
methods: [POST]
rep_warranty_raffle_form:
path: /report/warranty_raffle_report
controller: App\Controller\ReportController::warrantyRaffleForm
methods: [GET]
rep_warranty_raffle_submit:
path: /report/warranty_raffle_report
controller: App\Controller\ReportController::warrantyRaffleSubmit
methods: [POST]

View file

@ -1222,6 +1222,64 @@ class ReportController extends Controller
}
/**
* @Menu(selected="outlet_list")
*/
public function warrantyRaffleForm()
{
$this->denyAccessUnlessGranted('report.warranty.raffle', null, 'No access.');
return $this->render('report/warranty-raffle/form.html.twig');
}
public function warrantyRaffleSubmit(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->getWarrantyRaffleData($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', // Warranty ID
'Date',
'Outlet',
'Plate Number',
'Warranty Class',
'First Name',
'Last Name',
'Contact Number',
'Address',
'Email',
]);
foreach ($data as $row)
{
fputcsv($csv_handle, $row);
}
fclose($csv_handle);
});
$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;
}
protected function processPopappFile(UploadedFile $csv_file, EntityManagerInterface $em)
{
// attempt to open file
@ -2598,4 +2656,87 @@ class ReportController extends Controller
return $cust_ids;
}
protected function getWarrantyRaffleData($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 the data from warranty_raffle_log
$wrl_sql = 'SELECT wrl.serial AS serial, wrl.warranty_id AS warranty_id,
wrl.batt_model_name AS model_name, wrl.batt_size_name AS size_name,
wrl.date_create AS date_create, wrl.plate_number AS plate_number,
wrl.first_name AS first_name, wrl.last_name AS last_name,
wrl.contact_num AS contact_num, wrl.address AS address, wrl.email AS email
FROM warranty_raffle_log wrl
WHERE wrl.date_create >= :date_start
AND wrl.date_create <= :date_end';
$wrl_stmt = $db->prepare($wrl_sql);
$wrl_stmt->bindValue('date_start', $new_date_start);
$wrl_stmt->bindValue('date_end', $new_date_end);
$wrl_result = $wrl_stmt->executeQuery();
$wrl_data = [];
// go through rows
while($row = $wrl_result->fetchAssociative())
{
// check if entry has a warranty id
$w_id = $row['warranty_id'];
$warranty_id = '';
$warranty_class = '';
if ($w_id != null)
{
$warranty_id = $w_id;
// find the warranty to get the warranty class
$w_sql = 'SELECT w.warranty_class AS warranty_class
FROM warranty w
WHERE w.id = :warranty_id';
$w_stmt = $db->prepare($w_sql);
$w_stmt->bindValue('warranty_id' , $w_id);
$w_result = $w_stmt->executeQuery();
while ($w_row = $w_result->fetchAssociative())
{
$warranty_class = $w_row['warranty_class'];
}
}
$raffle_number = '';
$hub = '';
$battery_name = $row['model_name'] . ' / ' . $row['size_name'];
// get the date from the date schedule
$date_array = explode(' ' , $row['date_create']);
$date_create = $date_array[0];
$wrl_data[] = [
'raffle_num' => $raffle_number,
'serial' => $row['serial'],
'product_name' => $battery_name,
'warranty_id' => $warranty_id,
'date' => $date_create,
'hub' => $hub,
'plate_number' => $row['plate_number'],
'warranty_class' => $warranty_class,
'first_name' => $row['first_name'],
'last_name' => $row['last_name'],
'contact_number' => $row['contact_num'],
'address' => $row['address'],
'email' => $row['email']
];
}
return $wrl_data;
}
}

View file

@ -257,6 +257,14 @@
Hub Filter Report
</span>
</a>
<a href="{{ url('rep_warranty_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">
Warranty Raffle Report
</span>
</a>
</li>
</ul>
</li>

View file

@ -0,0 +1,83 @@
{% 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">Warranty 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_warranty_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 %}