Add Warranty Details Report. #297
This commit is contained in:
parent
bcaa7bf982
commit
d810fc821a
5 changed files with 224 additions and 1 deletions
|
|
@ -300,6 +300,8 @@ access_keys:
|
||||||
label: Warranty Class Report
|
label: Warranty Class Report
|
||||||
- id: report.vehicle.battery.compatibility
|
- id: report.vehicle.battery.compatibility
|
||||||
label: Vehicle Battery Compatibility Report
|
label: Vehicle Battery Compatibility Report
|
||||||
|
- id: report.warranty.details
|
||||||
|
label: Warranty Details Report
|
||||||
|
|
||||||
- id: service
|
- id: service
|
||||||
label: Other Services
|
label: Other Services
|
||||||
|
|
|
||||||
|
|
@ -67,3 +67,13 @@ rep_vehicle_battery_compatibility_export_csv:
|
||||||
path: /report/vehicle_battery_compatibility_report
|
path: /report/vehicle_battery_compatibility_report
|
||||||
controller: App\Controller\ReportController::vehicleBatteryCompatibilityExportCSV
|
controller: App\Controller\ReportController::vehicleBatteryCompatibilityExportCSV
|
||||||
methods: [POST]
|
methods: [POST]
|
||||||
|
|
||||||
|
rep_warranty_details_form:
|
||||||
|
path: /report/warranty_details_report
|
||||||
|
controller: App\Controller\ReportController::warrantyDetailsForm
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
rep_warranty_details_export_csv:
|
||||||
|
path: /report/warranty_details_report
|
||||||
|
controller: App\Controller\ReportController::warrantyDetailsExportCSV
|
||||||
|
methods: [POST]
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ use App\Entity\Warranty;
|
||||||
use App\Entity\CustomerVehicle;
|
use App\Entity\CustomerVehicle;
|
||||||
use App\Entity\MobileSession;
|
use App\Entity\MobileSession;
|
||||||
use App\Entity\Customer;
|
use App\Entity\Customer;
|
||||||
|
use App\Entity\BatteryModel;
|
||||||
|
use App\Entity\BatterySize;
|
||||||
|
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
|
@ -659,6 +661,66 @@ class ReportController extends Controller
|
||||||
$resp->headers->set('Content-Type', 'text/csv; charset=utf-8');
|
$resp->headers->set('Content-Type', 'text/csv; charset=utf-8');
|
||||||
$resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
$resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
||||||
|
|
||||||
|
return $resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="outlet_list")
|
||||||
|
*/
|
||||||
|
public function warrantyDetailsForm()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('report.warranty.details', null, 'No access.');
|
||||||
|
$params['mode'] = 'form';
|
||||||
|
|
||||||
|
return $this->render('report/warranty-details/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="outlet_list")
|
||||||
|
*/
|
||||||
|
public function warrantyDetailsExportCSV(Request $resq, EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$data = $this->getWarrantyDetailsData($em);
|
||||||
|
|
||||||
|
$resp = new StreamedResponse();
|
||||||
|
$resp->setCallback(function() use ($data) {
|
||||||
|
// csv output
|
||||||
|
$csv_handle = fopen('php://output', 'w+');
|
||||||
|
fputcsv($csv_handle, [
|
||||||
|
'Warranty ID',
|
||||||
|
'Serial',
|
||||||
|
'Battery Model',
|
||||||
|
'Battery Size',
|
||||||
|
'Warranty Class',
|
||||||
|
'Plate Number',
|
||||||
|
'Status',
|
||||||
|
'Date Created',
|
||||||
|
'Date Purchased',
|
||||||
|
'Expiry Date',
|
||||||
|
'Date Claimed',
|
||||||
|
'SAP Battery ID',
|
||||||
|
'Claim ID',
|
||||||
|
'Last Name',
|
||||||
|
'First Name',
|
||||||
|
'Mobile Number',
|
||||||
|
'Privacy Policy Number',
|
||||||
|
'Activated?',
|
||||||
|
|
||||||
|
]);
|
||||||
|
foreach ($data as $row)
|
||||||
|
{
|
||||||
|
fputcsv($csv_handle, $row);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($csv_handle);
|
||||||
|
});
|
||||||
|
|
||||||
|
$filename = 'warranty_details_report' . '.csv';
|
||||||
|
|
||||||
|
$resp->setStatusCode(200);
|
||||||
|
$resp->headers->set('Content-Type', 'text/csv; charset=utf-8');
|
||||||
|
$resp->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
||||||
|
|
||||||
return $resp;
|
return $resp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1005,7 +1067,99 @@ class ReportController extends Controller
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getWarrantyDetailsData(EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$bm_hash = $this->loadBatteryModels($em);
|
||||||
|
$bs_hash = $this->loadBatterySizes($em);
|
||||||
|
|
||||||
|
$results = [];
|
||||||
|
|
||||||
|
$conn = $em->getConnection();
|
||||||
|
$sql = 'SELECT w.id, w.serial, w.warranty_class, w.plate_number,
|
||||||
|
w.status, w.date_create, w.date_purchase, w.date_expire,
|
||||||
|
w.date_claim, w.sap_bty_id, w.claim_id, w.first_name,
|
||||||
|
w.last_name, w.mobile_number, w.flag_activated,
|
||||||
|
w.warranty_privacy_policy, w.bty_model_id, w.bty_size_id
|
||||||
|
FROM warranty w';
|
||||||
|
|
||||||
|
$stmt = $conn->prepare($sql);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$query_results = $stmt->fetchAll();
|
||||||
|
|
||||||
|
foreach ($query_results as $row)
|
||||||
|
{
|
||||||
|
// get battery model and size names
|
||||||
|
$bmodel_name = '';
|
||||||
|
$bm_id = $row['bty_model_id'];
|
||||||
|
if (!empty($bm_id))
|
||||||
|
{
|
||||||
|
if (isset($bm_hash[$bm_id]))
|
||||||
|
$bmodel_name = $bm_hash[$bm_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
$bsize_name = '';
|
||||||
|
$bs_id = $row['bty_size_id'];
|
||||||
|
if (!empty($bs_id))
|
||||||
|
{
|
||||||
|
if (isset($bs_hash[$bs_id]))
|
||||||
|
$bsize_name = $bs_hash[$bs_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
$results[] = [
|
||||||
|
'id' => $row['id'],
|
||||||
|
'serial' => $row['serial'],
|
||||||
|
'battery_model' => $bmodel_name,
|
||||||
|
'battery_size' => $bsize_name,
|
||||||
|
'warranty_class' => $row['warranty_class'],
|
||||||
|
'plate_number' => $row['plate_number'],
|
||||||
|
'status' => $row['status'],
|
||||||
|
'date_create' => $row['date_create'],
|
||||||
|
'date_purchase' => $row['date_purchase'],
|
||||||
|
'date_expire' => $row['date_expire'],
|
||||||
|
'date_claim' => $row['date_claim'],
|
||||||
|
'sap_bty_id' => $row['sap_bty_id'],
|
||||||
|
'claim_id' => $row['claim_id'],
|
||||||
|
'last_name' => $row['last_name'],
|
||||||
|
'first_name' => $row['first_name'],
|
||||||
|
'mobile_number' => $row['mobile_number'],
|
||||||
|
'privacy_policy' => $row['warranty_privacy_policy'],
|
||||||
|
'flag_activated' => (boolean) $row['flag_activated'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function loadBatteryModels(EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$bmodel_hash = [];
|
||||||
|
|
||||||
|
$models = $em->getRepository(BatteryModel::class)->findAll();
|
||||||
|
foreach ($models as $model)
|
||||||
|
{
|
||||||
|
$bmodel_id = $model->getID();
|
||||||
|
$bmodel_hash[$bmodel_id] = $model->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bmodel_hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function loadBatterySizes(EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$bsize_hash = [];
|
||||||
|
|
||||||
|
$sizes = $em->getRepository(BatterySize::class)->findAll();
|
||||||
|
foreach ($sizes as $size)
|
||||||
|
{
|
||||||
|
$bsize_id = $size->getID();
|
||||||
|
$bsize_hash[$bsize_id] = $size->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bsize_hash;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -181,7 +181,14 @@
|
||||||
Vehicle Battery Compatibility Report
|
Vehicle Battery Compatibility Report
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
<a href="{{ url('rep_warranty_details_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 Details Report
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
50
templates/report/warranty-details/form.html.twig
Normal file
50
templates/report/warranty-details/form.html.twig
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
{% 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 Details 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-upload"></i>
|
||||||
|
</span>
|
||||||
|
<h3 class="m-portlet__head-text">
|
||||||
|
Generate Warranty Details CSV File
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form id="upload_form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ url('rep_warranty_details_export_csv') }}" enctype="multipart/form-data">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<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">Export to CSV</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
Loading…
Reference in a new issue