diff --git a/config/acl.yaml b/config/acl.yaml index 81b49726..cf6791d5 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -431,3 +431,44 @@ access_keys: - id: analytics.forecast label: Forecasting + - id: sap_battery + label: SAP Battery Access + acls: + - id: sap_battery.menu + label: Menu + - id: sap_battery.list + label: List + - id: sap_battery.add + label: Add + - id: sap_battery.update + label: Update + - id: sap_battery.delete + label: Delete + + - id: sap_brand + label: SAP Battery Brand Access + acls: + - id: sap_brand.menu + label: Menu + - id: sap_brand.list + label: List + - id: sap_brand.add + label: Add + - id: sap_brand.update + label: Update + - id: sap_brand.delete + label: Delete + + - id: sap_bsize + label: SAP Battery Size Access + acls: + - id: sap_bsize.menu + label: Menu + - id: sap_bsize.list + label: List + - id: sap_bsize.add + label: Add + - id: sap_bsize.update + label: Update + - id: sap_bsize.delete + label: Delete diff --git a/config/menu.yaml b/config/menu.yaml index 246eda01..769c6d2d 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -63,6 +63,24 @@ main_menu: label: Promos parent: battery + - id: sapbattery + acl: sap_battery.menu + label: SAP Battery + icon: fa fa-battery + - id: sapbattery_list + acl: sap_battery.list + label: SAP Batteries + parent: sapbattery + - id: sapbrand_list + acl: sap_brand.list + label: SAP Battery Brands + parent: sapbattery + - id: sapbsize_list + acl: sap_bsize.list + label: SAP Battery Sizes + parent: sapbattery + + - id: vehicle acl: vehicle.menu label: Vehicle diff --git a/config/routes/sap_battery.yaml b/config/routes/sap_battery.yaml new file mode 100644 index 00000000..99c4ba9b --- /dev/null +++ b/config/routes/sap_battery.yaml @@ -0,0 +1,113 @@ +# sap battery + +sapbattery_list: + path: /sap-batteries + controller: App\Controller\SAPBatteryController::index + +sapbattery_rows: + path: /sap-batteries/rows + controller: App\Controller\SAPBatteryController::rows + methods: [POST] + +sapbattery_upload_image: + path: /sap-batteries/upload + controller: App\Controller\SAPBatteryController::uploadImage + methods: [POST] + +sapbattery_create: + path: /sap-batteries/create + controller: App\Controller\SAPBatteryController::addForm + methods: [GET] + +sapbattery_create_submit: + path: /sap-batteries/create + controller: App\Controller\SAPBatteryController::addSubmit + methods: [POST] + +sapbattery_update: + path: /sap-batteries/{id} + controller: App\Controller\SAPBatteryController::updateForm + methods: [GET] + +sapbattery_update_submit: + path: /sap-batteries/{id} + controller: App\Controller\SAPBatteryController::updateSubmit + methods: [POST] + +sapbattery_delete: + path: /sap-batteries/{id} + controller: App\Controller\SAPBatteryController::destroy + methods: [DELETE] + +# sap battery brands + +sapbrand_list: + path: /sap-battery-brands + controller: App\Controller\SAPBatteryBrandController::index + +sapbrand_rows: + path: /sap-battery-brands/rows + controller: App\Controller\SAPBatteryBrandController::rows + methods: [POST] + +sapbrand_create: + path: /sap-battery-brands/create + controller: App\Controller\SAPBatteryBrandController::addForm + methods: [GET] + +sapbrand_create_submit: + path: /sap-battery-brands/create + controller: App\Controller\SAPBatteryBrandController::addSubmit + methods: [POST] + +sapbrand_update: + path: /sap-battery-brands/{id} + controller: App\Controller\SAPBatteryBrandController::updateForm + methods: [GET] + +sapbrand_update_submit: + path: /sap-battery-brands/{id} + controller: App\Controller\SAPBatteryBrandController::updateSubmit + methods: [POST] + +sapbrand_delete: + path: /sap-battery-brands/{id} + controller: App\Controller\SAPBatteryBrandController::destroy + methods: [DELETE] + +# sap battery sizes + +sapbsize_list: + path: /sap-battery-sizes + controller: App\Controller\SAPBatterySizeController::index + +sapbsize_rows: + path: /sap-battery-sizes/rows + controller: App\Controller\SAPBatterySizeController::rows + methods: [POST] + +sapbsize_create: + path: /sap-battery-sizes/create + controller: App\Controller\SAPBatterySizeController::addForm + methods: [GET] + +sapbsize_create_submit: + path: /sap-battery-sizes/create + controller: App\Controller\SAPBatterySizeController::addSubmit + methods: [POST] + +sapbsize_update: + path: /sap-battery-sizes/{id} + controller: App\Controller\SAPBatterySizeController::updateForm + methods: [GET] + +sapbsize_update_submit: + path: /sap-battery-sizes/{id} + controller: App\Controller\SAPBatterySizeController::updateSubmit + methods: [POST] + +sapbsize_delete: + path: /sap-battery-sizes/{id} + controller: App\Controller\SAPBatterySizeController::destroy + methods: [DELETE] + diff --git a/src/Controller/SAPBatteryBrandController.php b/src/Controller/SAPBatteryBrandController.php new file mode 100644 index 00000000..700030f0 --- /dev/null +++ b/src/Controller/SAPBatteryBrandController.php @@ -0,0 +1,271 @@ +denyAccessUnlessGranted('sap_brand.list', null, 'No access.'); + + return $this->render('sap-battery-brand/list.html.twig'); + } + + public function rows(Request $req) + { + $this->denyAccessUnlessGranted('sap_brand.list', null, 'No access.'); + + // build query + $qb = $this->getDoctrine() + ->getRepository(SAPBatteryBrand::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 filter is present + if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { + $query->where('q.name LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + + // 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.name', '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['name'] = $orow->getName(); + + // add row metadata + $row['meta'] = [ + 'update_url' => '', + 'delete_url' => '' + ]; + + // add crud urls + if ($this->isGranted('sap_brand.update')) + $row['meta']['update_url'] = $this->generateUrl('sapbrand_update', ['id' => $row['id']]); + if ($this->isGranted('sap_brand.delete')) + $row['meta']['delete_url'] = $this->generateUrl('sapbrand_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } + + /** + * @Menu(selected="sapbrand_list") + */ + public function addForm() + { + $this->denyAccessUnlessGranted('sap_brand.add', null, 'No access.'); + + $params['obj'] = new SAPBatteryBrand(); + $params['mode'] = 'create'; + + // response + return $this->render('sap-battery-brand/form.html.twig', $params); + } + + public function addSubmit(Request $req, ValidatorInterface $validator) + { + $this->denyAccessUnlessGranted('sap_brand.add', null, 'No access.'); + + // create new row + $em = $this->getDoctrine()->getManager(); + $row = new SAPBatteryBrand(); + + // set and save values + $row->setName($req->request->get('name')); + + // validate + $errors = $validator->validate($row); + + // initialize error list + $error_array = []; + + // 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); + } else { + // validated! save the entity + $em->persist($row); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + /** + * @Menu(selected="sapbrand_list") + */ + public function updateForm($id) + { + $this->denyAccessUnlessGranted('sap_brand.update', null, 'No access.'); + + $params['mode'] = 'update'; + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(SAPBatteryBrand::class)->find($id); + + // make sure this row exists + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + $params['obj'] = $row; + + // response + return $this->render('sap-battery-brand/form.html.twig', $params); + } + + public function updateSubmit(Request $req, ValidatorInterface $validator, $id) + { + $this->denyAccessUnlessGranted('sap_brand.update', null, 'No access.'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(SAPBatteryBrand::class)->find($id); + + // make sure this row exists + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + // set and save values + $row->setName($req->request->get('name')); + + // validate + $errors = $validator->validate($row); + + // initialize error list + $error_array = []; + + // 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); + } else { + // validated! save the entity + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + public function destroy($id) + { + $this->denyAccessUnlessGranted('sap_brand.delete', null, 'No access.'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(SAPBatteryBrand::class)->find($id); + + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + // delete this row + $em->remove($row); + $em->flush(); + + // response + $response = new Response(); + $response->setStatusCode(Response::HTTP_OK); + $response->send(); + } + + // 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.name LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + } +} + diff --git a/src/Controller/SAPBatteryController.php b/src/Controller/SAPBatteryController.php new file mode 100644 index 00000000..b947834b --- /dev/null +++ b/src/Controller/SAPBatteryController.php @@ -0,0 +1,340 @@ +denyAccessUnlessGranted('sap_battery.list', null, 'No access.'); + + return $this->render('sap-battery/list.html.twig'); + } + + public function rows(Request $req) + { + $this->denyAccessUnlessGranted('sap_battery.list', null, 'No access.'); + + // build query + $qb = $this->getDoctrine() + ->getRepository(SAPBattery::class) + ->createQueryBuilder('q'); + + // get datatable params + $datatable = $req->request->get('datatable'); + + // count total records + $tquery = $qb->select('COUNT(q)') + ->join('q.brand', 'brand') + ->join('q.size', 'size'); + + // 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('brand.name as brand_name') + ->addSelect('size.name as size_name');; + + // add filters to query + $this->setQueryFilters($datatable, $query); + + // check if filter is present + if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { + $query->where('q.id LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + + // check if sorting is present, otherwise use default + if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) { + $prefix = ''; + + if (!in_array($datatable['sort']['field'], ['brand_name', 'size_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['brand_name'] = $orow['brand_name']; + $row['size_name'] = $orow['size_name']; + + // add row metadata + $row['meta'] = [ + 'update_url' => '', + 'delete_url' => '' + ]; + + // add crud urls + if ($this->isGranted('sap_battery.update')) + $row['meta']['update_url'] = $this->generateUrl('sapbattery_update', ['id' => $row['id']]); + if ($this->isGranted('sap_bsize.delete')) + $row['meta']['delete_url'] = $this->generateUrl('sapbattery_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } + + /** + * @Menu(selected="sapbattery_list") + */ + public function addForm() + { + $this->denyAccessUnlessGranted('sap_battery.add', null, 'No access.'); + + $params['obj'] = new SAPBattery(); + $params['mode'] = 'create'; + + $em = $this->getDoctrine()->getManager(); + + // get parent associations + $params['brands'] = $em->getRepository(SAPBatteryBrand::class)->findAll(); + $params['sizes'] = $em->getRepository(SAPBatterySize::class)->findAll(); + + // response + return $this->render('sap-battery/form.html.twig', $params); + } + + public function addSubmit(Request $req, ValidatorInterface $validator) + { + $this->denyAccessUnlessGranted('sap_battery.add', null, 'No access.'); + + // initialize error list + $error_array = []; + + // create new row + $em = $this->getDoctrine()->getManager(); + $row = new SAPBattery(); + + $id = trim($req->request->get('id')); + if (empty($id)) + $error_array['id'] = 'SAP code is required.'; + + // set and save values + $row->setID($id); + + // custom validation for battery brand + $brand = $em->getRepository(SAPBatteryBrand::class) + ->find($req->request->get('brand')); + + if (empty($brand)) + $error_array['brand'] = 'Invalid brand selected.'; + else + $row->setBrand($brand); + + // custom validation for battery size + $size = $em->getRepository(SAPBatterySize::class) + ->find($req->request->get('size')); + + if (empty($size)) + $error_array['size'] = 'Invalid size selected.'; + else + $row->setSize($size); + + // validate + $errors = $validator->validate($row); + + // 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); + } else { + // validated! save the entity + $em->persist($row); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + /** + * @Menu(selected="sapbattery_list") + */ + public function updateForm($id) + { + $this->denyAccessUnlessGranted('sap_battery.update', null, 'No access.'); + + $params['mode'] = 'update'; + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(SAPBattery::class)->find($id); + + // make sure this row exists + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + // get parent associations + $params['brands'] = $em->getRepository(SAPBatteryBrand::class)->findAll(); + $params['sizes'] = $em->getRepository(SAPBatterySize::class)->findAll(); + + + $params['obj'] = $row; + + // response + return $this->render('sap-battery/form.html.twig', $params); + } + + public function updateSubmit(Request $req, ValidatorInterface $validator, $id) + { + $this->denyAccessUnlessGranted('sap_battery.update', null, 'No access.'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(SAPBattery::class)->find($id); + + // make sure this row exists + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + // initialize error list + $error_array = []; + + $id = trim($req->request->get('id')); + if (empty($id)) + $error_array['id'] = 'SAP code is required.'; + + // set and save values + $row->setID($id); + + // custom validation for battery brand + $brand = $em->getRepository(SAPBatteryBrand::class) + ->find($req->request->get('brand')); + + if (empty($brand)) + $error_array['brand'] = 'Invalid brand selected.'; + else + $row->setBrand($brand); + + // custom validation for battery size + $size = $em->getRepository(SAPBatterySize::class) + ->find($req->request->get('size')); + + if (empty($size)) + $error_array['size'] = 'Invalid size selected.'; + else + $row->setSize($size); + + // validate + $errors = $validator->validate($row); + + // 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); + } else { + // validated! save the entity + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + public function destroy($id) + { + $this->denyAccessUnlessGranted('sap_battery.delete', null, 'No access.'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(SAPBattery::class)->find($id); + + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + // delete this row + $em->remove($row); + $em->flush(); + + // response + $response = new Response(); + $response->setStatusCode(Response::HTTP_OK); + $response->send(); + } + + // 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.id LIKE :filter') + ->orWhere('brand.name LIKE :filter') + ->orWhere('size.name LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + } +} + diff --git a/src/Controller/SAPBatterySizeController.php b/src/Controller/SAPBatterySizeController.php new file mode 100644 index 00000000..b2cd4138 --- /dev/null +++ b/src/Controller/SAPBatterySizeController.php @@ -0,0 +1,271 @@ +denyAccessUnlessGranted('sap_bsize.list', null, 'No access.'); + + return $this->render('sap-battery-size/list.html.twig'); + } + + public function rows(Request $req) + { + $this->denyAccessUnlessGranted('sap_bsize.list', null, 'No access.'); + + // build query + $qb = $this->getDoctrine() + ->getRepository(SAPBatterySize::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 filter is present + if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { + $query->where('q.name LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + + // 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.name', '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['name'] = $orow->getName(); + + // add row metadata + $row['meta'] = [ + 'update_url' => '', + 'delete_url' => '' + ]; + + // add crud urls + if ($this->isGranted('sap_bsize.update')) + $row['meta']['update_url'] = $this->generateUrl('sapbsize_update', ['id' => $row['id']]); + if ($this->isGranted('sap_bsize.delete')) + $row['meta']['delete_url'] = $this->generateUrl('sapbsize_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } + + /** + * @Menu(selected="sapbsize_list") + */ + public function addForm() + { + $this->denyAccessUnlessGranted('sap_bsize.add', null, 'No access.'); + + $params['obj'] = new SAPBatterySize(); + $params['mode'] = 'create'; + + // response + return $this->render('sap-battery-size/form.html.twig', $params); + } + + public function addSubmit(Request $req, ValidatorInterface $validator) + { + $this->denyAccessUnlessGranted('sap_bsize.add', null, 'No access.'); + + // create new row + $em = $this->getDoctrine()->getManager(); + $row = new SAPBatterySize(); + + // set and save values + $row->setName($req->request->get('name')); + + // validate + $errors = $validator->validate($row); + + // initialize error list + $error_array = []; + + // 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); + } else { + // validated! save the entity + $em->persist($row); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + /** + * @Menu(selected="sapbsize_list") + */ + public function updateForm($id) + { + $this->denyAccessUnlessGranted('sap_bsize.update', null, 'No access.'); + + $params['mode'] = 'update'; + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(SAPBatterySize::class)->find($id); + + // make sure this row exists + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + $params['obj'] = $row; + + // response + return $this->render('sap-battery-size/form.html.twig', $params); + } + + public function updateSubmit(Request $req, ValidatorInterface $validator, $id) + { + $this->denyAccessUnlessGranted('sap_bsize.update', null, 'No access.'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(SAPBatterySize::class)->find($id); + + // make sure this row exists + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + // set and save values + $row->setName($req->request->get('name')); + + // validate + $errors = $validator->validate($row); + + // initialize error list + $error_array = []; + + // 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); + } else { + // validated! save the entity + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + public function destroy($id) + { + $this->denyAccessUnlessGranted('sap_bsize.delete', null, 'No access.'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(SAPBatterySize::class)->find($id); + + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + // delete this row + $em->remove($row); + $em->flush(); + + // response + $response = new Response(); + $response->setStatusCode(Response::HTTP_OK); + $response->send(); + } + + // 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.name LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + } +} + diff --git a/templates/sap-battery-brand/form.html.twig b/templates/sap-battery-brand/form.html.twig new file mode 100644 index 00000000..ebd12a04 --- /dev/null +++ b/templates/sap-battery-brand/form.html.twig @@ -0,0 +1,134 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

SAP Battery Brands

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ {% if mode == 'update' %} + Edit SAP Battery Brand + {{ obj.getName() }} + {% else %} + New SAP Battery Brand + {% endif %} +

+
+
+
+
+
+
+ +
+ + + Display name for this brand +
+
+
+
+
+
+
+ + Back +
+
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/sap-battery-brand/list.html.twig b/templates/sap-battery-brand/list.html.twig new file mode 100644 index 00000000..94daa5b4 --- /dev/null +++ b/templates/sap-battery-brand/list.html.twig @@ -0,0 +1,146 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ SAP Battery Brands +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/sap-battery-size/form.html.twig b/templates/sap-battery-size/form.html.twig new file mode 100644 index 00000000..37671d9a --- /dev/null +++ b/templates/sap-battery-size/form.html.twig @@ -0,0 +1,134 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

SAP Battery Sizes

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ {% if mode == 'update' %} + Edit SAP Battery Size + {{ obj.getName() }} + {% else %} + New SAP Battery Size + {% endif %} +

+
+
+
+
+
+
+ +
+ + + Display name for this size +
+
+
+
+
+
+
+ + Back +
+
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/sap-battery-size/list.html.twig b/templates/sap-battery-size/list.html.twig new file mode 100644 index 00000000..f3924dff --- /dev/null +++ b/templates/sap-battery-size/list.html.twig @@ -0,0 +1,146 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ SAP Battery Sizes +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/sap-battery/form.html.twig b/templates/sap-battery/form.html.twig new file mode 100644 index 00000000..c2bf3fec --- /dev/null +++ b/templates/sap-battery/form.html.twig @@ -0,0 +1,166 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

SAP Batteries

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ {% if mode == 'update' %} + Edit SAP Battery + {{ obj.getID }} + {% else %} + New SAP Battery + {% endif %} +

+
+
+
+
+
+
+
+

+ Product Details +

+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+
+
+
+
+
+ + Back +
+
+
+
+ +
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/sap-battery/list.html.twig b/templates/sap-battery/list.html.twig new file mode 100644 index 00000000..06978d3f --- /dev/null +++ b/templates/sap-battery/list.html.twig @@ -0,0 +1,163 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ SAP Batteries +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %}