Merge branch 'master' of gitlab.com:jankstudio/resq into 251-edit-warranty-via-api
This commit is contained in:
commit
26e805b5a1
9 changed files with 224 additions and 67 deletions
|
|
@ -88,9 +88,17 @@ class TestAPICommand extends Command
|
|||
];
|
||||
$api->post('/capi/warranties/' . $id . '/claim', $params);
|
||||
|
||||
// warranty cancel
|
||||
$id = 86811;
|
||||
$api->get('/capi/warranties/' . $id . '/cancel');
|
||||
|
||||
// plate warranty
|
||||
$api->get('/capi/plates/' . $plate_num . '/warranties');
|
||||
|
||||
// warranty delete
|
||||
$id = 86811;
|
||||
$api->post('/capi/warranties/' . $id . '/delete');
|
||||
|
||||
// battery
|
||||
$api->get('/capi/battery_brands');
|
||||
$api->get('/capi/battery_sizes');
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@ access_keys:
|
|||
label: Claim
|
||||
- id: warranty.update
|
||||
label: Update
|
||||
- id: warranty.cancel
|
||||
label: Cancel
|
||||
- id: warranty.delete
|
||||
label: Delete
|
||||
- id: batterybrand
|
||||
label: Battery Brand Access
|
||||
acls:
|
||||
|
|
|
|||
|
|
@ -90,6 +90,18 @@ capi_warranty_update:
|
|||
controller: App\Controller\CAPI\WarrantyController::update
|
||||
methods: [POST]
|
||||
|
||||
# cancel warranty
|
||||
capi_warranty_cancel:
|
||||
path: /capi/warranties/{id}/cancel
|
||||
controller: App\Controller\CAPI\WarrantyController::cancel
|
||||
methods: [GET]
|
||||
|
||||
# delete warranty
|
||||
capi_warranty_delete:
|
||||
path: /capi/warranties/{id}/delete
|
||||
controller: App\Controller\CAPI\WarrantyController::delete
|
||||
methods: [POST]
|
||||
|
||||
# customer vehicle api
|
||||
|
||||
# find customer vehicle by id
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ rep_popapp_comp_form:
|
|||
controller: App\Controller\ReportController::popappComparisonForm
|
||||
methods: [GET]
|
||||
|
||||
rep_popapp_comp_submit:
|
||||
path: /report/popapp_comparison
|
||||
controller: App\Controller\ReportController::popappComparisonSubmit
|
||||
rep_popapp_export_csv:
|
||||
path: /report/popapp_export
|
||||
controller: App\Controller\ReportController::popappExportCSV
|
||||
methods: [POST]
|
||||
|
|
|
|||
|
|
@ -404,4 +404,45 @@ class WarrantyController extends APIController
|
|||
|
||||
return new APIResponse(true, 'Warranty updated.', $data);
|
||||
}
|
||||
|
||||
public function cancel(Request $req, EntityManagerInterface $em, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('warranty.cancel', null, 'No access.');
|
||||
|
||||
// find warranty
|
||||
$warr = $em->getRepository(Warranty::class)->find($id);
|
||||
if ($warr == null)
|
||||
return new APIResponse(false, 'No warranty found with that id.', null, 404);
|
||||
|
||||
if ($warr->getStatus() == WarrantyStatus::CANCELLED)
|
||||
{
|
||||
return new APIResponse(false, 'Warranty already cancelled.');
|
||||
}
|
||||
|
||||
// set status to cancelled
|
||||
$warr->setStatus(WarrantyStatus::CANCELLED);
|
||||
|
||||
$em->persist($warr);
|
||||
$em->flush();
|
||||
|
||||
return new APIResponse(true, 'Warranty cancelled successfully.');
|
||||
}
|
||||
|
||||
public function delete(EntityManagerInterface $em, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('warranty.delete', null, 'No access.');
|
||||
|
||||
// find warranty
|
||||
$warr = $em->getRepository(Warranty::class)->find($id);
|
||||
if ($warr == null)
|
||||
{
|
||||
return new APIResponse(false, 'No warranty found with that id.', null, 404);
|
||||
}
|
||||
|
||||
// delete the warranty
|
||||
$em->remove($warr);
|
||||
$em->flush();
|
||||
|
||||
return new APIResponse(true, 'Warranty deleted successfully.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@ use App\Entity\MobileSession;
|
|||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
|
@ -420,7 +422,7 @@ class ReportController extends Controller
|
|||
/**
|
||||
* @Menu(selected="outlet_list")
|
||||
*/
|
||||
public function popappComparisonSubmit(Request $req)
|
||||
/* public function popappComparisonSubmit(Request $req)
|
||||
{
|
||||
// retrieve temporary info for file
|
||||
$file = $req->files->get('csv_file');
|
||||
|
|
@ -437,9 +439,62 @@ class ReportController extends Controller
|
|||
$params['data'] = $data;
|
||||
|
||||
return $this->render('report/popapp/form.html.twig', $params);
|
||||
} */
|
||||
|
||||
/**
|
||||
* @Menu(selected="outlet_list")
|
||||
*/
|
||||
public function popappExportCSV(Request $req, EntityManagerInterface $em)
|
||||
{
|
||||
// retrieve temporary info for file
|
||||
$file = $req->files->get('csv_file');
|
||||
|
||||
// process the csv file
|
||||
$data = $this->processPopappFile($file, $em);
|
||||
|
||||
$resp = new StreamedResponse();
|
||||
$resp->setCallback(function() use ($data) {
|
||||
// csv output
|
||||
$csv_handle = fopen('php://output', 'w+');
|
||||
fputcsv($csv_handle, [
|
||||
'Size/Model',
|
||||
'SKU',
|
||||
'Serial Number',
|
||||
'Created Date',
|
||||
'Branch Name',
|
||||
'Branch Code',
|
||||
'Customer ID',
|
||||
'Customer Last Name',
|
||||
'Customer First Name',
|
||||
'Customer Mobile Number',
|
||||
'Warranty Last Name',
|
||||
'Warranty First Name',
|
||||
'Plate Number',
|
||||
'Warranty Create Date',
|
||||
'Activation Status',
|
||||
'Has Mobile App?',
|
||||
'Date Mobile App Downloaded',
|
||||
'Mobile Number Using Mobile App',
|
||||
]);
|
||||
foreach ($data as $row)
|
||||
{
|
||||
fputcsv($csv_handle, $row);
|
||||
}
|
||||
|
||||
fclose($csv_handle);
|
||||
});
|
||||
|
||||
$filename = 'popapp_comparison_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)
|
||||
protected function processPopappFile(UploadedFile $csv_file, EntityManagerInterface $em)
|
||||
{
|
||||
// attempt to open file
|
||||
try
|
||||
|
|
@ -452,69 +507,117 @@ class ReportController extends Controller
|
|||
}
|
||||
|
||||
// loop through the rows
|
||||
$serial_numbers = [];
|
||||
$row_num = 0;
|
||||
$results = [];
|
||||
|
||||
while(($fields = fgetcsv($fh)) !== false)
|
||||
{
|
||||
if ($row_num <= 2)
|
||||
//error_log($row_num . ' ' . trim($fields[2]));
|
||||
if ($row_num < 1)
|
||||
{
|
||||
$row_num++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// get the serial numbers
|
||||
$serial_numbers[] = trim($fields[2]);
|
||||
// pre-populate the result array
|
||||
$results[] = [
|
||||
'model_size' => trim($fields[0]),
|
||||
'sku' => trim($fields[1]),
|
||||
'serial' => trim($fields[2]),
|
||||
'created_date' => trim($fields[3]),
|
||||
'branch_name' => trim($fields[4]),
|
||||
'branch_code' => trim($fields[5]),
|
||||
'cust_id' => '',
|
||||
'cust_lastname' => '',
|
||||
'cust_firstname' => '',
|
||||
'cust_mobile_number' => '',
|
||||
'warr_lastname' => '',
|
||||
'warr_firstname' => '',
|
||||
'plate_num' => '',
|
||||
'warr_date_create' => '',
|
||||
'warr_activation_status' => '',
|
||||
'has_mobile' => '',
|
||||
'date_mobile' => '',
|
||||
'mobile_number' => '',
|
||||
];
|
||||
}
|
||||
|
||||
// get the warranty for serial
|
||||
$warr_qb = $this->getDoctrine()
|
||||
->getRepository(Warranty::class)
|
||||
->createQueryBuilder('q');
|
||||
$warranty_query = $warr_qb->select('q')
|
||||
->where('q.serial IN(:serials)')
|
||||
->setParameter('serials', $serial_numbers, Connection::PARAM_STR_ARRAY);
|
||||
|
||||
$warr_results = $warranty_query->getQuery()->getResult();
|
||||
|
||||
// get the plate numbers
|
||||
$results = [];
|
||||
foreach ($warr_results as $warranty)
|
||||
foreach($results as $key => $data)
|
||||
{
|
||||
//error_log($warranty->getPlateNumber());
|
||||
// validate the plate number
|
||||
$isValid = InvalidPlateNumber::isInvalid($warranty->getPlateNumber());
|
||||
if ($isValid)
|
||||
{
|
||||
// get customer vehicle using plate number
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$cust_vehicles = $em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $warranty->getPlateNumber()]);
|
||||
foreach ($cust_vehicles as $cv)
|
||||
{
|
||||
// get customer info
|
||||
// get mobile session of customer
|
||||
//error_log($cv->getCustomer()->getLastName() . ' ' . $cv->getCustomer()->getFirstName());
|
||||
$has_mobile = false;
|
||||
$mobile_session = $em->getRepository(MobileSession::class)->findBy(['customer' => $cv->getCustomer()->getID()]);
|
||||
foreach ($mobile_session as $mobile)
|
||||
{
|
||||
error_log($mobile->getID());
|
||||
$has_mobile = true;
|
||||
}
|
||||
$results[] = [
|
||||
'cust_id' => $cv->getCustomer()->getID(),
|
||||
'cust_lastname' => $cv->getCustomer()->getLastName(),
|
||||
'cust_firstname' => $cv->getCustomer()->getFirstName(),
|
||||
'plate_num' => $cv->getPlateNumber(),
|
||||
'serial' => $warranty->getSerial(),
|
||||
'warr_date_create' => $warranty->getDateCreate()->format("d M Y"),
|
||||
'has_mobile' => $has_mobile,
|
||||
'warr_activation_status' => $warranty->isActivated(),
|
||||
];
|
||||
//error_log($results[$key]['model_size']);
|
||||
|
||||
// get the serial
|
||||
$serial = $results[$key]['serial'];
|
||||
|
||||
// if serial is empty, move to next element
|
||||
if (!empty($serial))
|
||||
{
|
||||
// get the warranty for serial
|
||||
$warr_qb = $this->getDoctrine()
|
||||
->getRepository(Warranty::class)
|
||||
->createQueryBuilder('q');
|
||||
$warranty_query = $warr_qb->select('q')
|
||||
->where('q.serial = :serial')
|
||||
->setParameter('serial', $serial);
|
||||
$warranty = $warranty_query->getQuery()->getOneOrNullResult();
|
||||
|
||||
if ($warranty != null)
|
||||
{
|
||||
$isValid = InvalidPlateNumber::isInvalid($warranty->getPlateNumber());
|
||||
if ($isValid)
|
||||
{
|
||||
// get customer vehicles using plate number
|
||||
$customer_vehicles = $em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $warranty->getPlateNumber()]);
|
||||
|
||||
// check if customer vehicle is empty
|
||||
if (count($customer_vehicles) != 0)
|
||||
{
|
||||
$has_mobile = false;
|
||||
$mobile_date = '';
|
||||
$mobile_number = '';
|
||||
|
||||
// get the first customer vehicle, store as best_cv until we find one with a mobile session
|
||||
$best_cv = current($customer_vehicles);
|
||||
|
||||
foreach($customer_vehicles as $cv)
|
||||
{
|
||||
// get mobile session of customer
|
||||
//error_log($cv->getCustomer()->getLastName() . ' ' . $cv->getCustomer()->getFirstName());
|
||||
$mobile_session = $em->getRepository(MobileSession::class)
|
||||
->findOneBy(['customer' => $cv->getCustomer()->getID()], ['date_generated' => 'ASC']);
|
||||
if ($mobile_session != null)
|
||||
{
|
||||
// get mobile data
|
||||
$has_mobile = true;
|
||||
$mobile_date = $mobile_session->getDateGenerated()->format("d M Y");
|
||||
$mobile_number = $mobile_session->getPhoneNumber();
|
||||
|
||||
// set best_cv to this customer vehicle with mobile session
|
||||
$best_cv = $cv;
|
||||
}
|
||||
}
|
||||
|
||||
// set the customer data in results
|
||||
$results[$key]['cust_id'] = $best_cv->getCustomer()->getID();
|
||||
$results[$key]['cust_lastname'] = $best_cv->getCustomer()->getLastName();
|
||||
$results[$key]['cust_firstname'] = $best_cv->getCustomer()->getFirstName();
|
||||
$results[$key]['cust_mobile_number'] = $best_cv->getCustomer()->getPhoneMobile();
|
||||
$results[$key]['plate_num'] = $best_cv->getPlateNumber();
|
||||
$results[$key]['has_mobile'] = ($has_mobile ? 'Yes' : 'No');
|
||||
$results[$key]['date_mobile'] = $mobile_date;
|
||||
$results[$key]['mobile_number'] = $mobile_number;
|
||||
}
|
||||
}
|
||||
// set the warranty data in results
|
||||
$results[$key]['warr_lastname'] = $warranty->getLastName();
|
||||
$results[$key]['warr_firstname'] = $warranty->getFirstName();
|
||||
$results[$key]['warr_date_create'] = $warranty->getDateCreate()->format("d M Y");
|
||||
$results[$key]['warr_activation_status'] = ($warranty->isActivated() ? 'Active' : 'Inactive');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ class WarrantySearchController extends Controller
|
|||
$this->denyAccessUnlessGranted('warranty.search', null, 'No access.');
|
||||
|
||||
$serial = $req->query->get('battery_serial');
|
||||
$name = $req->query->get('owner_name');
|
||||
$plate_num = $req->query->get('plate_num');
|
||||
|
||||
// find the warranty
|
||||
|
|
@ -63,7 +62,6 @@ class WarrantySearchController extends Controller
|
|||
}
|
||||
$params['data'] = $res;
|
||||
$params['battery_serial'] = $serial;
|
||||
$params['owner_name'] = $name;
|
||||
$params['plate_num'] = $plate_num;
|
||||
$params['mode'] = "results";
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
</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_popapp_comp_submit') }}" enctype="multipart/form-data">
|
||||
<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_popapp_export_csv') }}" enctype="multipart/form-data">
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group row">
|
||||
<input type="file" id="csv_file" name="csv_file" >
|
||||
|
|
@ -38,7 +38,7 @@
|
|||
<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>
|
||||
<button type="submit" class="btn btn-success">Export to CSV</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -96,8 +96,8 @@
|
|||
<td>{{ result.plate_num|default('') }}</td>
|
||||
<td>{{ result.serial|default('') }}</td>
|
||||
<td>{{ result.warr_date_create|default('') }}</td>
|
||||
<td>{{ result.warr_activation_status ? 'Active' : 'Inactive' }}</td>
|
||||
<td>{{ result.has_mobile ? 'Yes' : 'No' }} </td>
|
||||
<td>{{ result.warr_activation_status }}</td>
|
||||
<td>{{ result.has_mobile }} </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
|||
|
|
@ -35,19 +35,10 @@
|
|||
</div>
|
||||
<form id="warranty-search-form" autocomplete="off" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="get" action="{{ url('search_warranty') }}">
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group row">
|
||||
<label>
|
||||
Please fill up at least two (2) of the fields below to view battery's warranty status.
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<label data-field="battery_serial">Battery Serial Number</label>
|
||||
<input name="battery_serial" type="search"class="form-control" placeholder="xxxxxxxxxxxx" value="{{ battery_serial|default("") }}">
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<label data-field="owner_name">Owner Name</label>
|
||||
<input name="owner_name" type="search" class="form-control" placeholder="i.e. Juan Dela Cruz" value="{{ owner_name|default("") }}">
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<label data-field="plate_num">Vehicle Plate Number</label>
|
||||
<input name="plate_num" type="search" class="form-control" placeholder="i.e. ABC 123" value="{{ plate_num|default("") }}">
|
||||
|
|
|
|||
Loading…
Reference in a new issue