Merge branch '547-customer-source-report-in-admin-panel' into 'master'
Resolve "Customer Source Report in admin panel" Closes #547 See merge request jankstudio/resq!648
This commit is contained in:
commit
73263d1039
5 changed files with 242 additions and 0 deletions
|
|
@ -342,6 +342,8 @@ access_keys:
|
|||
label: Auto Assigned Job Order Report
|
||||
- id: report.jo.advance_order
|
||||
label: Advance Order Job Order Report
|
||||
- id: report.customer.source
|
||||
label: Customer Source Report
|
||||
|
||||
- id: service
|
||||
label: Other Services
|
||||
|
|
|
|||
|
|
@ -127,3 +127,13 @@ rep_jo_advance_order_submit:
|
|||
path: /report/jo_advance_order_report
|
||||
controller: App\Controller\ReportController::jobOrderAdvanceOrderSubmit
|
||||
methods: [POST]
|
||||
|
||||
rep_customer_source_form:
|
||||
path: /report/customer_source_report
|
||||
controller: App\Controller\ReportController::customerSourceForm
|
||||
methods: [GET]
|
||||
|
||||
rep_customer_source_submit:
|
||||
path: /report/customer_source_report
|
||||
controller: App\Controller\ReportController::customerSourceSubmit
|
||||
methods: [POST]
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ use Catalyst\MenuBundle\Annotation\Menu;
|
|||
|
||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||
use DateTime;
|
||||
use PDO;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
|
|
@ -1016,6 +1017,64 @@ class ReportController extends Controller
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Menu(selected="outlet_list")
|
||||
*/
|
||||
public function customerSourceForm()
|
||||
{
|
||||
$this->denyAccessUnlessGranted('report.customer.source', null, 'No access.');
|
||||
|
||||
return $this->render('report/customer-source/form.html.twig');
|
||||
}
|
||||
|
||||
public function customerSourceSubmit(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->getCustomerSourceDetails($req, $em);
|
||||
|
||||
$resp = new StreamedResponse();
|
||||
$resp->setCallback(function() use ($data) {
|
||||
// csv output
|
||||
$csv_handle = fopen('php://output', 'w+');
|
||||
fputcsv($csv_handle, [
|
||||
'Customer ID',
|
||||
'First Name',
|
||||
'Last Name',
|
||||
'Mobile Phone',
|
||||
'Landline',
|
||||
'Office Phone',
|
||||
'Fax',
|
||||
'Email Address',
|
||||
'Vehicle Manufacturer',
|
||||
'Vehicle Make',
|
||||
'Model Year',
|
||||
'Plate Number',
|
||||
'Source',
|
||||
'Date Created',
|
||||
]);
|
||||
|
||||
foreach ($data as $row)
|
||||
{
|
||||
fputcsv($csv_handle, $row);
|
||||
}
|
||||
|
||||
fclose($csv_handle);
|
||||
});
|
||||
|
||||
$filename = 'customer_source_' . $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)
|
||||
{
|
||||
|
|
@ -2018,4 +2077,85 @@ class ReportController extends Controller
|
|||
return $result;
|
||||
}
|
||||
|
||||
protected function getCustomerSourceDetails(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);
|
||||
|
||||
// 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');
|
||||
|
||||
// get all mobile user customer id hash
|
||||
$resq_cust_ids = $this->getRESQCustomerIDs($em);
|
||||
|
||||
// pdo connection
|
||||
$db = $em->getConnection();
|
||||
|
||||
// get all customers
|
||||
$sql = 'select c.id, c.first_name, c.last_name, c.phone_mobile, c.phone_landline, c.phone_office, c.phone_fax, c.email, c.flag_mobile_app, vm.name, v.make, cv.model_year, cv.plate_number, c.date_create from customer c, customer_vehicle cv, vehicle v, vehicle_manufacturer vm where c.date_create >= :date_start and c.date_create <= :date_end and c.id = cv.customer_id and cv.vehicle_id = v.id and v.manufacturer_id = vm.id';
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute([
|
||||
'date_start' => $new_date_start,
|
||||
'date_end' => $new_date_end,
|
||||
]);
|
||||
|
||||
$result = [];
|
||||
// go through rows
|
||||
while ($row = $stmt->fetch(PDO::FETCH_NUM))
|
||||
{
|
||||
// TODO: find customer source
|
||||
// NOTE: flag_mobile_app is 0 for some reason
|
||||
// customer source
|
||||
if (isset($resq_cust_ids[$row[0]]))
|
||||
$source = 'resq';
|
||||
else
|
||||
$source = 'crm / owr';
|
||||
|
||||
$result[] = [
|
||||
$row[0], // id
|
||||
$row[1], // first name
|
||||
$row[2], // last name
|
||||
$row[3], // phone - mobile
|
||||
$row[4], // phone - landline
|
||||
$row[5], // phone - office
|
||||
$row[6], // phone - fax
|
||||
$row[7], // email
|
||||
$row[9], // vehicle manufacturer
|
||||
$row[10], // vehicle make
|
||||
$row[11], // vehicle model
|
||||
$row[12], // plate number
|
||||
$source, // customer source
|
||||
$row[13],
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getRESQCustomerIDs(EntityManagerInterface $em)
|
||||
{
|
||||
// pdo connection
|
||||
$db = $em->getConnection();
|
||||
|
||||
// get all customer ids of all mobile sessions
|
||||
$sql = 'select distinct customer_id from mobile_session';
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute();
|
||||
$res = $stmt->fetchAll();
|
||||
|
||||
$cust_ids = [];
|
||||
|
||||
foreach ($res as $cust)
|
||||
{
|
||||
$cust_ids[$cust['customer_id']] = $cust['customer_id'];
|
||||
}
|
||||
|
||||
return $cust_ids;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -241,6 +241,14 @@
|
|||
SMS Messages Report
|
||||
</span>
|
||||
</a>
|
||||
<a href="{{ url('rep_customer_source_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">
|
||||
Customer Source Report
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
|
|
|||
82
templates/report/customer-source/form.html.twig
Normal file
82
templates/report/customer-source/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">Customer Source 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_customer_source_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