Add routes, acl and template changes for rejection report #184
This commit is contained in:
parent
d5a012cbef
commit
f59476c2d3
4 changed files with 375 additions and 36 deletions
|
|
@ -238,3 +238,11 @@ access_keys:
|
||||||
label: Update
|
label: Update
|
||||||
- id: promo.delete
|
- id: promo.delete
|
||||||
label: Delete
|
label: Delete
|
||||||
|
|
||||||
|
- id: report
|
||||||
|
label: Reports
|
||||||
|
acls:
|
||||||
|
- id: report.menu
|
||||||
|
label: Menu
|
||||||
|
- id: report.reject
|
||||||
|
label: Rejection Report
|
||||||
|
|
|
||||||
9
config/routes/report.yaml
Normal file
9
config/routes/report.yaml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
rep_reject_form:
|
||||||
|
path: /report/rejection
|
||||||
|
controller: App\Controller\ReportController::rejectForm
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
rep_reject_submit:
|
||||||
|
path: /report/rejection
|
||||||
|
controller: App\Controller\ReportController::rejectSubmit
|
||||||
|
methods: [POST]
|
||||||
350
src/Controller/ReportController.php
Normal file
350
src/Controller/ReportController.php
Normal file
|
|
@ -0,0 +1,350 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Ramcar\BaseController;
|
||||||
|
|
||||||
|
use App\Entity\JORejection;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Query;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
|
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
class ReportController extends BaseController
|
||||||
|
{
|
||||||
|
public function rejectForm()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('report.reject', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('outlet_list');
|
||||||
|
|
||||||
|
return $this->render('outlet/list.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rejectSubmit(Request $req)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('report.reject', null, 'No access.');
|
||||||
|
|
||||||
|
// get query builder
|
||||||
|
$qb = $this->getDoctrine()
|
||||||
|
->getRepository(Outlet::class)
|
||||||
|
->createQueryBuilder('q');
|
||||||
|
|
||||||
|
// get datatable params
|
||||||
|
$datatable = $req->request->get('datatable');
|
||||||
|
|
||||||
|
// count total records
|
||||||
|
$tquery = $qb->select('COUNT(q)')
|
||||||
|
->leftJoin('q.hub', 'hub');
|
||||||
|
|
||||||
|
// 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')
|
||||||
|
->addSelect('hub.name as hub_name')
|
||||||
|
->addSelect('hub.branch as hub_branch');
|
||||||
|
|
||||||
|
$this->setQueryFilters($datatable, $query);
|
||||||
|
|
||||||
|
// check if sorting is present, otherwise use default
|
||||||
|
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
|
||||||
|
$prefix = '';
|
||||||
|
|
||||||
|
if (!in_array($datatable['sort']['field'], ['hub_name']))
|
||||||
|
$prefix = 'q.';
|
||||||
|
|
||||||
|
$order = $datatable['sort']['sort'] ?? 'asc';
|
||||||
|
$query->orderBy($prefix . $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[0]->getID();
|
||||||
|
$row['name'] = $orow[0]->getName();
|
||||||
|
$row['branch'] = $orow[0]->getBranch();
|
||||||
|
$row['address'] = $orow[0]->getAddress();
|
||||||
|
$row['contact_nums'] = $orow[0]->getContactNumbers();
|
||||||
|
$row['time_open'] = $orow[0]->getTimeOpen()->format('g:i A');
|
||||||
|
$row['time_close'] = $orow[0]->getTimeClose()->format('g:i A');
|
||||||
|
$row['hub_name'] = $orow['hub_name'] . ' ' . $orow['hub_branch'];
|
||||||
|
|
||||||
|
// add row metadata
|
||||||
|
$row['meta'] = [
|
||||||
|
'update_url' => '',
|
||||||
|
'delete_url' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
// add crud urls
|
||||||
|
if ($this->isGranted('outlet.update'))
|
||||||
|
$row['meta']['update_url'] = $this->generateUrl('outlet_update', ['id' => $row['id']]);
|
||||||
|
if ($this->isGranted('outlet.delete'))
|
||||||
|
$row['meta']['delete_url'] = $this->generateUrl('outlet_delete', ['id' => $row['id']]);
|
||||||
|
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->json([
|
||||||
|
'meta' => $meta,
|
||||||
|
'data' => $rows
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addForm()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('outlet.add', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('outlet_list');
|
||||||
|
$params['obj'] = new Outlet();
|
||||||
|
$params['mode'] = 'create';
|
||||||
|
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
// get parent associations
|
||||||
|
$params['hubs'] = $em->getRepository(Hub::class)->findAll();
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('outlet/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setObject(Outlet $obj, Request $req)
|
||||||
|
{
|
||||||
|
// coordinates
|
||||||
|
$point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat'));
|
||||||
|
|
||||||
|
// times
|
||||||
|
$format = 'g:i A';
|
||||||
|
$time_open = DateTime::createFromFormat($format, $req->request->get('time_open'));
|
||||||
|
$time_close = DateTime::createFromFormat($format, $req->request->get('time_close'));
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$obj->setName($req->request->get('name'))
|
||||||
|
->setBranch($req->request->get('branch'))
|
||||||
|
->setAddress($req->request->get('address'))
|
||||||
|
->setContactNumbers($req->request->get('contact_nums'))
|
||||||
|
->setTimeOpen($time_open)
|
||||||
|
->setTimeClose($time_close)
|
||||||
|
->setCoordinates($point);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setQueryFilters($datatable, QueryBuilder $query)
|
||||||
|
{
|
||||||
|
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||||
|
$query->where('hub.name LIKE :filter')
|
||||||
|
->orWhere('q.name LIKE :filter')
|
||||||
|
->orWhere('q.branch LIKE :filter')
|
||||||
|
->orWhere('q.address LIKE :filter')
|
||||||
|
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('outlet.add', null, 'No access.');
|
||||||
|
|
||||||
|
// create new object
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = new Outlet();
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// custom validation for associations
|
||||||
|
$hub_id = $req->request->get('hub');
|
||||||
|
|
||||||
|
if ($hub_id) {
|
||||||
|
$hub = $em->getRepository(Hub::class)
|
||||||
|
->find($hub_id);
|
||||||
|
|
||||||
|
if (empty($hub))
|
||||||
|
$error_array['hub'] = 'Invalid hub selected.';
|
||||||
|
else
|
||||||
|
$obj->setHub($hub);
|
||||||
|
} else {
|
||||||
|
$error_array['hub'] = 'This value should not be blank.';
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if lat and lng are provided
|
||||||
|
if (empty($req->request->get('coord_lng')) || empty($req->request->get('coord_lat')))
|
||||||
|
{
|
||||||
|
$error_array['coordinates'] = 'No map coordinates provided. Please click on a location on the map.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($error_array))
|
||||||
|
{
|
||||||
|
// set object
|
||||||
|
$this->setObject($obj, $req);
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($obj);
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error)
|
||||||
|
{
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array))
|
||||||
|
{
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
// validated! save the entity
|
||||||
|
$em->persist($obj);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateForm($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('outlet.update', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('outlet_list');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = $em->getRepository(Outlet::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($obj))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
// get parent associations
|
||||||
|
$params['hubs'] = $em->getRepository(Hub::class)->findAll();
|
||||||
|
|
||||||
|
$params['obj'] = $obj;
|
||||||
|
$params['mode'] = 'update';
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('outlet/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator, $id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('outlet.update', null, 'No access.');
|
||||||
|
|
||||||
|
// get object data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = $em->getRepository(Outlet::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this object exists
|
||||||
|
if (empty($obj))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
$this->setObject($obj, $req);
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($obj);
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// custom validation for associations
|
||||||
|
$hub_id = $req->request->get('hub');
|
||||||
|
|
||||||
|
if ($hub_id) {
|
||||||
|
$hub = $em->getRepository(Hub::class)
|
||||||
|
->find($hub_id);
|
||||||
|
|
||||||
|
if (empty($hub))
|
||||||
|
$error_array['hub'] = 'Invalid hub selected.';
|
||||||
|
else
|
||||||
|
$obj->setHub($hub);
|
||||||
|
} else {
|
||||||
|
$error_array['hub'] = 'This value should not be blank.';
|
||||||
|
}
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
// validated! save the entity
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('outlet.delete', null, 'No access.');
|
||||||
|
|
||||||
|
$params = $this->initParameters('outlet_list');
|
||||||
|
|
||||||
|
// get objext data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = $em->getRepository(Outlet::class)->find($id);
|
||||||
|
|
||||||
|
if (empty($obj))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
// delete this object
|
||||||
|
$em->remove($obj);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// response
|
||||||
|
$response = new Response();
|
||||||
|
$response->setStatusCode(Response::HTTP_OK);
|
||||||
|
$response->send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -103,53 +103,24 @@
|
||||||
<li class="m-menu__item">
|
<li class="m-menu__item">
|
||||||
<h3 class="m-menu__heading m-menu__toggle">
|
<h3 class="m-menu__heading m-menu__toggle">
|
||||||
<span class="m-menu__link-text">
|
<span class="m-menu__link-text">
|
||||||
Finance Reports
|
Job Order Reports
|
||||||
</span>
|
</span>
|
||||||
<i class="m-menu__ver-arrow la la-angle-right"></i>
|
<i class="m-menu__ver-arrow la la-angle-right"></i>
|
||||||
</h3>
|
</h3>
|
||||||
<ul class="m-menu__inner">
|
<ul class="m-menu__inner">
|
||||||
<li class="m-menu__item " data-redirect="true" aria-haspopup="true">
|
<li class="m-menu__item " data-redirect="true" aria-haspopup="true">
|
||||||
<a href="header/actions.html" class="m-menu__link">
|
<a href="/" class="m-menu__link">
|
||||||
<i class="m-menu__link-icon flaticon-map"></i>
|
<i class="m-menu__link-bullet m-menu__link-bullet--dot">
|
||||||
|
<span></span>
|
||||||
|
</i>
|
||||||
<span class="m-menu__link-text">
|
<span class="m-menu__link-text">
|
||||||
Annual Reports
|
Rejection Report
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="m-menu__item " data-redirect="true" aria-haspopup="true">
|
|
||||||
<a href="header/actions.html" class="m-menu__link">
|
|
||||||
<i class="m-menu__link-icon flaticon-user"></i>
|
|
||||||
<span class="m-menu__link-text">
|
|
||||||
HR Reports
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="m-menu__item " data-redirect="true" aria-haspopup="true">
|
|
||||||
<a href="header/actions.html" class="m-menu__link">
|
|
||||||
<i class="m-menu__link-icon flaticon-clipboard"></i>
|
|
||||||
<span class="m-menu__link-text">
|
|
||||||
IPO Reports
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="m-menu__item " data-redirect="true" aria-haspopup="true">
|
|
||||||
<a href="header/actions.html" class="m-menu__link">
|
|
||||||
<i class="m-menu__link-icon flaticon-graphic-1"></i>
|
|
||||||
<span class="m-menu__link-text">
|
|
||||||
Finance Margins
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="m-menu__item " data-redirect="true" aria-haspopup="true">
|
|
||||||
<a href="header/actions.html" class="m-menu__link">
|
|
||||||
<i class="m-menu__link-icon flaticon-graphic-2"></i>
|
|
||||||
<span class="m-menu__link-text">
|
|
||||||
Revenue Reports
|
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
<!--
|
||||||
<li class="m-menu__item">
|
<li class="m-menu__item">
|
||||||
<h3 class="m-menu__heading m-menu__toggle">
|
<h3 class="m-menu__heading m-menu__toggle">
|
||||||
<span class="m-menu__link-text">
|
<span class="m-menu__link-text">
|
||||||
|
|
@ -342,6 +313,7 @@
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
-->
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue