Merge branch '267-report-of-crm-customers-with-resq-app' into 'master'

Resolve "Report of crm customers with resq app"

Closes #267

See merge request jankstudio/resq!311
This commit is contained in:
Kendrick Chan 2019-09-17 04:04:02 +00:00
commit 5b8bcd852f
6 changed files with 175 additions and 0 deletions

View file

@ -292,6 +292,8 @@ access_keys:
label: Battery Conflict Report
- id: report.popapp.comparison
label: Popapp Comparison Report
- id: report.meh.customer
label: RESQ MEH Customer Report
- id: service
label: Other Services

View file

@ -37,3 +37,13 @@ rep_popapp_export_csv:
path: /report/popapp_export
controller: App\Controller\ReportController::popappExportCSV
methods: [POST]
rep_resq_meh_form:
path: /report/meh_customer
controller: App\Controller\ReportController::mehCustomerForm
methods: [GET]
rep_resq_meh_export_csv:
path: /report/meh_customer_export
controller: App\Controller\ReportController::mehCustomerExportCSV
methods: [POST]

View file

@ -13,6 +13,7 @@ use App\Entity\JobOrder;
use App\Entity\Warranty;
use App\Entity\CustomerVehicle;
use App\Entity\MobileSession;
use App\Entity\Customer;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
@ -26,6 +27,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Dotenv\Dotenv;
use Catalyst\MenuBundle\Annotation\Menu;
@ -494,6 +496,55 @@ class ReportController extends Controller
}
/**
* @Menu(selected="outlet_list")
*/
public function mehCustomerForm()
{
$this->denyAccessUnlessGranted('report.meh.customer', null, 'No access.');
$params['mode'] = 'form';
return $this->render('report/meh/form.html.twig', $params);
}
/**
* @Menu(selected="outlet_list")
*/
public function mehCustomerExportCSV(Request $req, EntityManagerInterface $em)
{
$data = $this->getMEHCustomerData($em);
$resp = new StreamedResponse();
$resp->setCallback(function() use ($data) {
// csv output
$csv_handle = fopen('php://output', 'w+');
fputcsv($csv_handle, [
'Last Name',
'First Name',
'Mobile Number',
'Landline Number',
'Office Number',
'Fax Number',
'Date Mobile App Downloaded',
'Mobile Number Using Mobile App',
]);
foreach ($data as $row)
{
fputcsv($csv_handle, $row);
}
fclose($csv_handle);
});
$filename = 'resq_meh_customer_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;
}
protected function processPopappFile(UploadedFile $csv_file, EntityManagerInterface $em)
{
// attempt to open file
@ -620,4 +671,51 @@ class ReportController extends Controller
return $results;
}
protected function getMEHCustomerData(EntityManagerInterface $em)
{
$results = [];
$conn = $em->getConnection();
$sql = 'SELECT c.id, c.last_name, c.first_name, c.phone_mobile, c.phone_landline,
c.phone_office, c.phone_fax, jo.source FROM job_order jo,
customer_vehicle cv, customer c
WHERE c.id = cv.customer_id
AND jo.cvehicle_id = cv.id
AND c.policy_mobile_app_id IS NOT NULL
AND jo.source != :source';
$stmt = $conn->prepare($sql);
$stmt->execute(array('source' => 'mobile_app'));
$query_results = $stmt->fetchAll();
foreach($query_results as $row)
{
$mobile_date = '';
$mobile_number = '';
$mobile_session = $em->getRepository(MobileSession::class)
->findOneBy(['customer' => $row['id']], ['date_generated' => 'ASC']);
if ($mobile_session != null)
{
$mobile_date = $mobile_session->getDateGenerated()->format("d M Y");
$mobile_number = $mobile_session->getPhoneNumber();
}
$results[] = [
'last_name' => $row['last_name'],
'first_name' => $row['first_name'],
'cust_mobile_number' => $row['phone_mobile'],
'landline_number' => $row['phone_landline'],
'office_number' => $row['phone_office'],
'fax_number' => $row['phone_fax'],
'date_mobile' => $mobile_date,
'mobile_number' => $mobile_number,
];
}
return $results;
}
}

View file

@ -119,6 +119,8 @@ class CustomerVehicle
public function __construct()
{
$this->flag_active = true;
$this->job_orders = new ArrayCollection();
}
public function getID()
@ -256,6 +258,11 @@ class CustomerVehicle
return $this->curr_battery;
}
public function getJobOrders()
{
return $this->job_orders;
}
public function setHasMotoliteBattery($flag_motolite_battery = true)
{
$this->flag_motolite_battery = $flag_motolite_battery;

View file

@ -157,6 +157,14 @@
Popapp Comparison Report
</span>
</a>
<a href="{{ url('rep_resq_meh_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">
RESQ MEH Customer Report
</span>
</a>
</li>
</ul>
</li>

View 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">
RESQ MEH Customer 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 Customer 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_resq_meh_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 %}