Merge branch 'master-fix' of gitlab.com:jankstudio/resq into 586-crud-for-dealers

This commit is contained in:
Korina Cordero 2021-06-17 04:26:48 +00:00
commit f4b4685f70
3 changed files with 68 additions and 18 deletions

View file

@ -73,9 +73,9 @@ rep_warranty_details_form:
controller: App\Controller\ReportController::warrantyDetailsForm
methods: [GET]
rep_warranty_details_export_csv:
rep_warranty_details_submit:
path: /report/warranty_details_report
controller: App\Controller\ReportController::warrantyDetailsExportCSV
controller: App\Controller\ReportController::warrantyDetailsSubmit
methods: [POST]
rep_jo_details_form:

View file

@ -683,9 +683,9 @@ class ReportController extends Controller
/**
* @Menu(selected="outlet_list")
*/
public function warrantyDetailsExportCSV(Request $resq, EntityManagerInterface $em)
public function warrantyDetailsSubmit(Request $req, EntityManagerInterface $em)
{
$data = $this->getWarrantyDetailsData($em);
$data = $this->getWarrantyDetailsData($req, $em);
$resp = new StreamedResponse();
$resp->setCallback(function() use ($data) {
@ -1468,11 +1468,24 @@ class ReportController extends Controller
return $results;
}
protected function getWarrantyDetailsData(EntityManagerInterface $em)
protected function getWarrantyDetailsData(Request $req, EntityManagerInterface $em)
{
$bm_hash = $this->loadBatteryModels($em);
$bs_hash = $this->loadBatterySizes($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);
$date_start->setTime(0,0);
$date_end->setTime(23,59);
// convert to string in the correct format so we can plug it in the query
$str_date_start = $date_start->format('Y-m-d H:i:s');
$str_date_end = $date_end->format('Y-m-d H:i:s');
$results = [];
$conn = $em->getConnection();
@ -1495,11 +1508,13 @@ class ReportController extends Controller
c.flag_research_sms, c.flag_research_email, c.create_source AS c_create_source,
v.id AS v_id, v.manufacturer_id, v.make, v.model_year_from,
v.model_year_to, v.flag_mobile
FROM warranty w JOIN customer c ON w.customer_id = c.id
JOIN vehicle v ON w.vehicle_id = v.id';
FROM warranty w LEFT JOIN customer c ON w.customer_id = c.id
LEFT JOIN vehicle v ON w.vehicle_id = v.id
WHERE w.date_create >= :start_date
AND w.date_create <= :end_date';
$stmt = $conn->prepare($sql);
$stmt->execute();
$stmt->execute(['start_date' => $str_date_start, 'end_date' => $str_date_end]);
$query_results = $stmt->fetchAll();

View file

@ -21,30 +21,65 @@
<div class="m-portlet__head-caption">
<div class="m-portlet__head-title">
<span class="m-portlet__head-icon">
<i class="fa fa-upload"></i>
<i class="fa fa-calendar"></i>
</span>
<h3 class="m-portlet__head-text">
Generate Warranty Details CSV File
Select a date range
</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">
<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_details_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">Export to CSV</button>
</div>
<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 %}