Rename the old Warranty controller to WarrantySearchController. Rename the old warranty.yaml to warranty_search.yaml. Add create, update, and view warranty to menu and acl yamls. Add WarrantyController and template file for Warranty. #236
This commit is contained in:
parent
85844aae3a
commit
2d1a91842a
7 changed files with 456 additions and 45 deletions
|
|
@ -344,3 +344,15 @@ access_keys:
|
||||||
label: Update
|
label: Update
|
||||||
- id: privacy_policy.delete
|
- id: privacy_policy.delete
|
||||||
label: Delete
|
label: Delete
|
||||||
|
|
||||||
|
- id: warranty
|
||||||
|
label: Warranty
|
||||||
|
acls:
|
||||||
|
- id: warranty.menu
|
||||||
|
label: Menu
|
||||||
|
- id: warranty.list
|
||||||
|
label: List
|
||||||
|
- id: warranty.add
|
||||||
|
label: Add
|
||||||
|
- id: warranty.update
|
||||||
|
label: Update
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,10 @@ main_menu:
|
||||||
acl: privacy_policy.list
|
acl: privacy_policy.list
|
||||||
label: Privacy Policy
|
label: Privacy Policy
|
||||||
parent: support
|
parent: support
|
||||||
|
- id: warranty_list
|
||||||
|
acl: warranty.list
|
||||||
|
label: Warranty
|
||||||
|
parent: support
|
||||||
|
|
||||||
- id: service
|
- id: service
|
||||||
acl: service.menu
|
acl: service.menu
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,30 @@
|
||||||
# warranty
|
# warranty
|
||||||
|
|
||||||
warranty_search:
|
warranty_list:
|
||||||
path: /warranty_search
|
path: /warranties
|
||||||
controller: App\Controller\WarrantyController::index
|
controller: App\Controller\WarrantyController::index
|
||||||
|
|
||||||
search_warranty:
|
warranty_rows:
|
||||||
path: /warranty_search/warranty
|
path: /warranties/rows
|
||||||
controller: App\Controller\WarrantyController::search
|
controller: App\Controller\WarrantyController::rows
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
warranty_create:
|
||||||
|
path: /warranties/create
|
||||||
|
controller: App\Controller\WarrantyController::addForm
|
||||||
methods: [GET]
|
methods: [GET]
|
||||||
|
|
||||||
|
warranty_create_submit:
|
||||||
|
path: /warranties/create
|
||||||
|
controller: App\Controller\WarrantyController::addSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
warranty_update:
|
||||||
|
path: /warranties/{id}
|
||||||
|
controller: App\Controller\WarrantyController::updateForm
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
warranty_update_submit:
|
||||||
|
path: /warranties/{id}
|
||||||
|
controller: App\Controller\WarrantyController::updateSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
|
||||||
10
config/routes/warranty_search.yaml
Normal file
10
config/routes/warranty_search.yaml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# warranty search
|
||||||
|
|
||||||
|
warranty_search:
|
||||||
|
path: /warranty_search
|
||||||
|
controller: App\Controller\WarrantySearchController::index
|
||||||
|
|
||||||
|
search_warranty:
|
||||||
|
path: /warranty_search/warranty
|
||||||
|
controller: App\Controller\WarrantySearchController::search
|
||||||
|
methods: [GET]
|
||||||
|
|
@ -4,6 +4,8 @@ namespace App\Controller;
|
||||||
|
|
||||||
use App\Entity\Warranty;
|
use App\Entity\Warranty;
|
||||||
|
|
||||||
|
use App\Ramcar\WarrantyClass;
|
||||||
|
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
@ -15,59 +17,220 @@ use Catalyst\MenuBundle\Annotation\Menu;
|
||||||
class WarrantyController extends Controller
|
class WarrantyController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @Menu(selected="warranty_search")
|
* @Menu(selected="warranty_list")
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$this->denyaccessUnlessGranted('warranty.search', null, 'No access.');
|
$this->denyAccessUnlessGranted('warranty.list', null, 'No access.');
|
||||||
$params["mode"] = "form";
|
|
||||||
|
return $this->render('warranty/list.html.twig');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rows(Request $req)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('warranty.list', null, 'No access.');
|
||||||
|
|
||||||
|
// get query builder
|
||||||
|
$qb = $this->getDoctrine()
|
||||||
|
->getRepository(Warranty::class)
|
||||||
|
->createQueryBuilder('q');
|
||||||
|
|
||||||
|
// get datatable params
|
||||||
|
$datatable = $req->request->get('datatable');
|
||||||
|
|
||||||
|
// count total records
|
||||||
|
$tquery = $qb->select('COUNT(q)');
|
||||||
|
|
||||||
|
// add filters to count query
|
||||||
|
$this->setQueryFilters($datatable, $tquery);
|
||||||
|
|
||||||
|
$total = $tquery->getQuery()
|
||||||
|
->getSingleScalarResult();
|
||||||
|
|
||||||
|
// get current page number
|
||||||
|
$page = $datatable['pagination']['page'] ?? 1;
|
||||||
|
|
||||||
|
$perpage = $datatable['pagination']['perpage'];
|
||||||
|
$offset = ($page - 1) * $perpage;
|
||||||
|
|
||||||
|
// add metadata
|
||||||
|
$meta = [
|
||||||
|
'page' => $page,
|
||||||
|
'perpage' => $perpage,
|
||||||
|
'pages' => ceil($total / $perpage),
|
||||||
|
'total' => $total,
|
||||||
|
'sort' => 'asc',
|
||||||
|
'field' => 'id'
|
||||||
|
];
|
||||||
|
|
||||||
|
// build query
|
||||||
|
$query = $qb->select('q');
|
||||||
|
|
||||||
|
// add filters to query
|
||||||
|
$this->setQueryFilters($datatable, $query);
|
||||||
|
|
||||||
|
// check if sorting is present, otherwise use default
|
||||||
|
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
|
||||||
|
$order = $datatable['sort']['sort'] ?? 'asc';
|
||||||
|
$query->orderBy('q.' . $datatable['sort']['field'], $order);
|
||||||
|
} else {
|
||||||
|
$query->orderBy('q.id', 'asc');
|
||||||
|
}
|
||||||
|
|
||||||
|
// get rows for this page
|
||||||
|
$obj_rows = $query->setFirstResult($offset)
|
||||||
|
->setMaxResults($perpage)
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
// process rows
|
||||||
|
$rows = [];
|
||||||
|
foreach ($obj_rows as $orow) {
|
||||||
|
// add row data
|
||||||
|
$row['id'] = $orow->getID();
|
||||||
|
$row['serial'] = $orow->getSerial();
|
||||||
|
$row['plate_number'] = $orow->getPlateNumber();
|
||||||
|
$row['warranty_class'] = $orow->getWarrantyClass();
|
||||||
|
$row['status'] = $orow->getStatus();
|
||||||
|
$row['is_activated'] = $orow->isActivated();
|
||||||
|
|
||||||
|
// add row metadata
|
||||||
|
$row['meta'] = [
|
||||||
|
'update_url' => '',
|
||||||
|
];
|
||||||
|
|
||||||
|
// add crud urls
|
||||||
|
if ($this->isGranted('warranty.update'))
|
||||||
|
$row['meta']['update_url'] = $this->generateUrl('warranty_update', ['id' => $row['id']]);
|
||||||
|
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
// response
|
// response
|
||||||
return $this->render('warranty-search/form.html.twig', $params);
|
return $this->json([
|
||||||
|
'meta' => $meta,
|
||||||
|
'data' => $rows
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Menu(selected="warranty_search")
|
* @Menu(selected="warranty_list")
|
||||||
*/
|
*/
|
||||||
public function search(Request $req)
|
public function addForm()
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('warranty.search', null, 'No access.');
|
$this->denyAccessUnlessGranted('warranty.add', null, 'No access.');
|
||||||
|
|
||||||
$serial = $req->query->get('battery_serial');
|
$params['obj'] = new Warranty();
|
||||||
$name = $req->query->get('owner_name');
|
$params['mode'] = 'create';
|
||||||
$plate_num = $req->query->get('plate_num');
|
|
||||||
|
|
||||||
// find the warranty
|
// get batteries (models and sizes)
|
||||||
$qb = $this->getDoctrine()
|
// get SAP batteries
|
||||||
->getRepository(Warranty::class)
|
// get warranty class
|
||||||
->createQueryBuilder('w');
|
|
||||||
|
|
||||||
$query = $qb;
|
|
||||||
if (!empty($serial))
|
|
||||||
{
|
|
||||||
$qb->where('w.serial = :serial')
|
|
||||||
->setParameter('serial', $serial);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($plate_num))
|
|
||||||
{
|
|
||||||
$qb->andWhere('w.plate_number = :plate_num')
|
|
||||||
->setParameter('plate_num', $plate_num);
|
|
||||||
}
|
|
||||||
|
|
||||||
$results = $query->getQuery()->getResult();
|
|
||||||
|
|
||||||
$res = [];
|
|
||||||
foreach ($results as $result) {
|
|
||||||
$res[] = $result;
|
|
||||||
}
|
|
||||||
$params['data'] = $res;
|
|
||||||
$params['battery_serial'] = $serial;
|
|
||||||
$params['owner_name'] = $name;
|
|
||||||
$params['plate_num'] = $plate_num;
|
|
||||||
$params['mode'] = "results";
|
|
||||||
|
|
||||||
// response
|
// response
|
||||||
return $this->render('warranty-search/form.html.twig', $params);
|
return $this->render('warranty/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSubmit(Request $req, ValidatorInterface $validator)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('warranty.add', null, 'No access.');
|
||||||
|
|
||||||
|
// create new row
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = new Warranty();
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$obj->setSerial($req->request->get('serial'))
|
||||||
|
->setWarrantyClass($req->request->get('warranty_class'))
|
||||||
|
->setFirstName($req->request->get('first_name'))
|
||||||
|
->setLastName($req->request->get('last_name'))
|
||||||
|
->setMobileNumber($req->request->get('mobile_number'))
|
||||||
|
->setDatePurchase(DateTime::createFromFormat("d M Y h:i A", $req->request->get('date_purchase')));
|
||||||
|
|
||||||
|
// need to get the battery and SAP battery set
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($obj);
|
||||||
|
|
||||||
|
$cleaned_plate_number = Warranty::cleanPlateNumber($req->request->get('plate_number'));
|
||||||
|
if (!$cleaned_plate_number)
|
||||||
|
{
|
||||||
|
$error_array['plate_number'] = 'Invalid plate number specified.';
|
||||||
|
}
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="warranty_list")
|
||||||
|
*/
|
||||||
|
public function updateForm($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('warranty.update', null, 'No access.');
|
||||||
|
|
||||||
|
$params['mode'] = 'update';
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = $em->getRepository(Warranty::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($obj))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
// get batteries (models and sizes)
|
||||||
|
// get SAP batteries
|
||||||
|
// get warranty class
|
||||||
|
// get status
|
||||||
|
|
||||||
|
$params['obj'] = $obj;
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('warranty/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateSubmit(Request $req, ValidatorInterface $validator, $id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('warranty.update', null, 'No access.');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = $em->getRepository(Warranty::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($obj))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function fillDropdownParameters(&$params)
|
||||||
|
{
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
// db loaded
|
||||||
|
$params['bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll();
|
||||||
|
|
||||||
|
// need to add battery model and sizes
|
||||||
|
|
||||||
|
// need to add SAP battery
|
||||||
|
|
||||||
|
// name values
|
||||||
|
$params['warranty_classes'] = WarrantyClass::getCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if datatable filter is present and append to query
|
||||||
|
protected function setQueryFilters($datatable, &$query) {
|
||||||
|
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||||
|
$query->where('q.serial LIKE :filter')
|
||||||
|
->orWhere('q.plate_number LIKE :filter')
|
||||||
|
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
73
src/Controller/WarrantySearchController.php
Normal file
73
src/Controller/WarrantySearchController.php
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Warranty;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Query;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
|
||||||
|
use Catalyst\MenuBundle\Annotation\Menu;
|
||||||
|
|
||||||
|
class WarrantySearchController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Menu(selected="warranty_search")
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$this->denyaccessUnlessGranted('warranty.search', null, 'No access.');
|
||||||
|
$params["mode"] = "form";
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('warranty-search/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="warranty_search")
|
||||||
|
*/
|
||||||
|
public function search(Request $req)
|
||||||
|
{
|
||||||
|
$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
|
||||||
|
$qb = $this->getDoctrine()
|
||||||
|
->getRepository(Warranty::class)
|
||||||
|
->createQueryBuilder('w');
|
||||||
|
|
||||||
|
$query = $qb;
|
||||||
|
if (!empty($serial))
|
||||||
|
{
|
||||||
|
$qb->where('w.serial = :serial')
|
||||||
|
->setParameter('serial', $serial);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($plate_num))
|
||||||
|
{
|
||||||
|
$qb->andWhere('w.plate_number = :plate_num')
|
||||||
|
->setParameter('plate_num', $plate_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
$results = $query->getQuery()->getResult();
|
||||||
|
|
||||||
|
$res = [];
|
||||||
|
foreach ($results as $result) {
|
||||||
|
$res[] = $result;
|
||||||
|
}
|
||||||
|
$params['data'] = $res;
|
||||||
|
$params['battery_serial'] = $serial;
|
||||||
|
$params['owner_name'] = $name;
|
||||||
|
$params['plate_num'] = $plate_num;
|
||||||
|
$params['mode'] = "results";
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('warranty-search/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
129
templates/warranty/list.html.twig
Normal file
129
templates/warranty/list.html.twig
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
{% 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">
|
||||||
|
Warranties
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-12">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col-xl-8 order-2 order-xl-1">
|
||||||
|
<div class="form-group m-form__group row align-items-center">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="m-input-icon m-input-icon--left">
|
||||||
|
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
|
||||||
|
<span class="m-input-icon__icon m-input-icon__icon--left">
|
||||||
|
<span><i class="la la-search"></i></span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
||||||
|
<a href="{{ url('warranty_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||||
|
<span>
|
||||||
|
<i class="la la-key"></i>
|
||||||
|
<span>New Warranty</span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<div class="m-separator m-separator--dashed d-xl-none"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--begin: Datatable -->
|
||||||
|
<div id="data-rows"></div>
|
||||||
|
<!--end: Datatable -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
var options = {
|
||||||
|
data: {
|
||||||
|
type: 'remote',
|
||||||
|
source: {
|
||||||
|
read: {
|
||||||
|
url: '{{ url("warranty_rows") }}',
|
||||||
|
method: 'POST'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
saveState: {
|
||||||
|
cookie: false,
|
||||||
|
webstorage: false
|
||||||
|
},
|
||||||
|
pageSize: 10,
|
||||||
|
serverPaging: true,
|
||||||
|
serverFiltering: true,
|
||||||
|
serverSorting: true
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: 'ID'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'serial',
|
||||||
|
title: 'Serial'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'plate_number',
|
||||||
|
title: 'Plate Number'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'warranty_class',
|
||||||
|
title: 'Warranty Class'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'status',
|
||||||
|
title: 'Status'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'is_activated',
|
||||||
|
title: 'Activation Status'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'Actions',
|
||||||
|
width: 110,
|
||||||
|
title: 'Actions',
|
||||||
|
sortable: false,
|
||||||
|
overflow: 'visible',
|
||||||
|
template: function (row, index, datatable) {
|
||||||
|
var actions = '';
|
||||||
|
if (row.meta.update_url != '') {
|
||||||
|
actions += '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.name + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return actions;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
search: {
|
||||||
|
onEnter: false,
|
||||||
|
input: $('#data-rows-search'),
|
||||||
|
delay: 400
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var table = $("#data-rows").mDatatable(options);
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
Loading…
Reference in a new issue