diff --git a/.env.dist b/.env.dist index 4c0b202a..4e10dffc 100644 --- a/.env.dist +++ b/.env.dist @@ -34,4 +34,11 @@ REDIS_CLIENT_SCHEME=tcp REDIS_CLIENT_HOST=127.0.0.1 REDIS_CLIENT_PORT=6379 REDIS_CLIENT_PASSWORD=foobared -# + +# privacy policy ids +POLICY_PROMO=insertpromopolicyidhere +POLICY_THIRD_PARTY=insertthirdpartypolicyidhere +POLICY_MOBILE=insertmobilepolicyidhere + +# OTP +OTP_MODE=settotestorrandom diff --git a/config/acl.yaml b/config/acl.yaml index 5695e217..9de80027 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -252,6 +252,7 @@ access_keys: label: Search - id: warranty.search label: Customer Battery Search + - id: ticket label: Ticket Access acls: @@ -329,3 +330,29 @@ access_keys: label: View - id: review.delete label: Delete + + - id: privacypolicy + label: Privacy Policy + acls: + - id: privacy_policy.menu + label: Menu + - id: privacy_policy.list + label: List + - id: privacy_policy.add + label: Add + - id: privacy_policy.update + label: Update + - id: privacy_policy.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 diff --git a/config/menu.yaml b/config/menu.yaml index d470f680..92b29c2d 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -143,6 +143,14 @@ main_menu: acl: warranty.search label: Customer Battery Search parent: support + - id: privacy_policy_list + acl: privacy_policy.list + label: Privacy Policy + parent: support + - id: warranty_list + acl: warranty.list + label: Warranty + parent: support - id: service acl: service.menu diff --git a/config/routes/privacy_policy.yaml b/config/routes/privacy_policy.yaml new file mode 100644 index 00000000..6a5708b2 --- /dev/null +++ b/config/routes/privacy_policy.yaml @@ -0,0 +1,33 @@ +privacy_policy_list: + path: /privacy_policies + controller: App\Controller\PrivacyPolicyController::index + +privacy_policy_rows: + path: /privacy_policies/rows + controller: App\Controller\PrivacyPolicyController::rows + methods: [POST] + +privacy_policy_create: + path: /privacy_policies/create + controller: App\Controller\PrivacyPolicyController::addForm + methods: [GET] + +privacy_policy_create_submit: + path: /privacy_policies/create + controller: App\Controller\PrivacyPolicyController:addSubmit + methods: [POST] + +privacy_policy_update: + path: /privacy_policies/{id} + controller: App\Controller\PrivacyPolicyController::updateForm + methods: [GET] + +privacy_policy_update_submit: + path : /privacy_policies/{id} + controller: App\Controller\PrivacyPolicyController:updateSubmit + methods: [POST] + +privacy_policy_delete: + path: /privacy_policies/{id} + controller: App\Controller\PrivacyPolicyController:destroy + methods: [DELETE] diff --git a/config/routes/warranty.yaml b/config/routes/warranty.yaml index 8e4156e2..86c3e9b9 100644 --- a/config/routes/warranty.yaml +++ b/config/routes/warranty.yaml @@ -1,10 +1,30 @@ # warranty -warranty_search: - path: /warranty_search +warranty_list: + path: /warranties controller: App\Controller\WarrantyController::index -search_warranty: - path: /warranty_search/warranty - controller: App\Controller\WarrantyController::search +warranty_rows: + path: /warranties/rows + controller: App\Controller\WarrantyController::rows + methods: [POST] + +warranty_create: + path: /warranties/create + controller: App\Controller\WarrantyController::addForm 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] diff --git a/config/routes/warranty_search.yaml b/config/routes/warranty_search.yaml new file mode 100644 index 00000000..0dd525c8 --- /dev/null +++ b/config/routes/warranty_search.yaml @@ -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] diff --git a/src/Command/SetCustomerPrivacyPolicyCommand.php b/src/Command/SetCustomerPrivacyPolicyCommand.php new file mode 100644 index 00000000..d4431175 --- /dev/null +++ b/src/Command/SetCustomerPrivacyPolicyCommand.php @@ -0,0 +1,84 @@ +em = $om; + + parent::__construct(); + } + + protected function configure() + { + $this->setName('customer:setprivacypolicy') + ->setDescription('Set customer private policy.') + ->setHelp('Set customer private policy.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + // get the policy ids from .env + $dotenv = new Dotenv(); + $dotenv->loadEnv(__DIR__.'/../../.env'); + + $policy_promo_id = $_ENV['POLICY_PROMO']; + $policy_third_party_id = $_ENV['POLICY_THIRD_PARTY']; + $policy_mobile_id = $_ENV['POLICY_MOBILE']; + + // get third party policy + $third_party_policy = $this->em->getRepository(PrivacyPolicy::class)->find($policy_third_party_id); + + // get customers on third party + $third_party_customers = $this->em->getRepository(Customer::class)->findBy(['priv_third_party' => true]); + foreach ($third_party_customers as $cust) + { + $cust->setPrivacyPolicyThirdParty($third_party_policy); + } + + // get promo policy + $promo_policy = $this->em->getRepository(PrivacyPolicy::class)->find($policy_promo_id); + + // get customers on promo + $promo_customers = $this->em->getRepository(Customer::class)->findBy(['priv_promo' => true]); + foreach ($promo_customers as $cust) + { + $cust->setPrivacyPolicyPromo($promo_policy); + } + + $this->em->flush(); + + // get mobile policy + $mobile_policy = $this->em->getRepository(PrivacyPolicy::class)->find($policy_mobile_id); + + // get mobile sessions + $mobile_sessions = $this->em->getRepository(MobileSession::class)->findAll(); + foreach ($mobile_sessions as $session) + { + $cust = $session->getCustomer(); + if (!(is_null($cust))) + { + $cust->setPrivacyPolicyMobile($mobile_policy); + } + } + + $this->em->flush(); + } +} diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 73b40583..1aef7004 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -10,6 +10,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\Dotenv\Dotenv; use CrEOF\Spatial\PHP\Types\Geometry\Point; @@ -43,6 +44,7 @@ use App\Entity\Warranty; use App\Entity\Service; use App\Entity\Partner; use App\Entity\Review; +use App\Entity\PrivacyPolicy; use DateTime; use Exception; @@ -237,8 +239,14 @@ class APIController extends Controller // phone number $phone_number = $req->request->get('phone_number'); - // check if the phone number is our test number - if ($phone_number == '639991112233') + // get otp_mode from .env + $dotenv = new Dotenv(); + $dotenv->loadEnv(__DIR__.'/../../.env'); + + $otp_mode = $_ENV['OTP_MODE']; + + // check if otp_mode is test + if ($otp_mode == 'test') { $code = '123456'; $this->session->setConfirmCode($code) @@ -253,18 +261,16 @@ class APIController extends Controller // TODO: validate phone number // generate code and save - // $code = '123456'; $code = $this->generateConfirmCode(); $this->session->setConfirmCode($code) ->setPhoneNumber($phone_number); $em->flush(); - // send sms to number - $this->sendConfirmationCode($rt, $phone_number, $code); - /* - $message = "Your Resq confirmation code is $code."; - $rt->sendSMS($phone_number, 'MOTOLITE', $message); - */ + if ($otp_mode != 'test') + { + // send sms to number + $this->sendConfirmationCode($rt, $phone_number, $code); + } // response return $res->getReturnResponse(); @@ -395,6 +401,17 @@ class APIController extends Controller // update mobile phone of customer $cust->setPhoneMobile(substr($this->session->getPhoneNumber(), 2)); + // get privacy policy for mobile + $policy = $em->createQuery('SELECT policy FROM App\Entity\PrivacyPolicy policy WHERE policy.name LIKE :policy_type') + ->setParameter('policy_type', "%" . "mobile" . "%") + ->getOneOrNullResult(); + + // set policy id + if ($policy != null) + { + $cust->setPrivacyPolicyMobile($policy); + } + $em->flush(); return $res->getReturnResponse(); @@ -1807,9 +1824,43 @@ class APIController extends Controller // set privacy settings $priv_promo = $req->request->get('priv_promo', false); - $cust->setPrivacyThirdParty($req->request->get('priv_third_party')) + $priv_third_party = $req->request->get('priv_third_party'); + $cust->setPrivacyThirdParty($priv_third_party) ->setPrivacyPromo($priv_promo); + // get the policy ids from .env + $dotenv = new Dotenv(); + $dotenv->loadEnv(__DIR__.'/../../.env'); + + $policy_promo_id = $_ENV['POLICY_PROMO']; + $policy_third_party_id = $_ENV['POLICY_THIRD_PARTY']; + + // check if privacy settings are true + // if true, set the private policy for the customer + if ($priv_promo) + { + // find the promo policy + $policy = $em->getRepository(PrivacyPolicy::class)->find($policy_promo_id); + + // set policy id + if ($policy != null) + { + $cust->setPrivacyPolicyPromo($policy); + } + } + + if ($priv_third_party) + { + // find the third party policy + $policy = $em->getRepository(PrivacyPolicy::class)->find($policy_third_party_id); + + // set policy id + if ($policy != null) + { + $cust->setPrivacyPolicyThirdParty($policy); + } + } + $em->flush(); return $res->getReturnResponse(); @@ -1859,17 +1910,12 @@ class APIController extends Controller return $res->getReturnResponse(); } - // get first entry - $warranty = current($warranty_results); - if ($warranty->isActivated()) + // activate all entries + foreach ($warranty_results as $warranty) { - $res->setError(true) - ->setErrorMessage('Warranty already activated'); - return $res->getReturnResponse(); + $warranty->setActivated(); } - $warranty->setActivated(); - $em->flush(); return $res->getReturnResponse(); @@ -2017,19 +2063,17 @@ class APIController extends Controller // get reviews for partner $reviews = $em->getRepository(Review::class)->findBy(['partner' => $partner]); - $rev = []; + + // get average rating for all reviews if (!empty($reviews)) { + $rating = 0; foreach($reviews as $review) { - $rev[] = [ - 'id' => $review->getID(), - 'rating' => $review->getRating(), - 'message' => $review->getMessage(), - 'date_create' => $review->getDateCreate()->format("d M Y g:i A"), - // 'mobile_session' => $review->getMobileSession()->getID(), - ]; + $rating = $rating + $review->getRating(); } + + $average_rating = $rating / sizeof($reviews); } $data['partner'] = [ @@ -2042,7 +2086,7 @@ class APIController extends Controller 'time_close' => $partner->getTimeClose()->format("g:i A"), 'longitude' => $partner->getCoordinates()->getLongitude(), 'latitude' => $partner->getCoordinates()->getLatitude(), - 'reviews' => $rev, + 'average_rating' => $average_rating, ]; $res->setData($data); diff --git a/src/Controller/PrivacyPolicyController.php b/src/Controller/PrivacyPolicyController.php new file mode 100644 index 00000000..70b39278 --- /dev/null +++ b/src/Controller/PrivacyPolicyController.php @@ -0,0 +1,272 @@ +denyAccessUnlessGranted('privacy_policy.list', null, 'No access.'); + + return $this->render('privacy-policy/list.html.twig'); + } + + public function rows(Request $req) + { + $this->denyAccessUnlessGranted('privacy_policy.list', null, 'No access.'); + + // build query + $qb = $this->getDoctrine() + ->getRepository(PrivacyPolicy::class) + ->createQueryBuilder('q'); + + // get datatable params + $datatable = $req->request->get('datatable'); + + // count total records + $tquery = $qb->select('COUNT(q)'); + + // add fitlers 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['name'] = $orow->getName(); + + // add row metadata + $row['meta'] = [ + 'update_url' => '', + 'delete_url' => '' + ]; + + // add crud urls + if ($this->isGranted('privacy_policy.update')) + $row['meta']['update_url'] = $this->generateUrl('privacy_policy_update', ['id' => $row['id']]); + if ($this->isGranted('privacy_policy.delete')) + $row['meta']['delete_url'] = $this->generateUrl('privacy_policy_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } + + /** + * @Menu(selected="privacy_policy_list") + */ + public function addForm() + { + $this->denyAccessUnlessGranted('privacy_policy.add', null, 'No access.'); + + $params = []; + $params['obj'] = new PrivacyPolicy(); + $params['mode'] = 'create'; + + // response + return $this->render('privacy-policy/form.html.twig', $params); + } + + public function addSubmit(Request $req, ValidatorInterface $validator) + { + $this->denyAccessUnlessGranted('privacy_policy.add', null, 'No access.'); + + // create new object + $em = $this->getDoctrine()->getManager(); + $row = new PrivacyPolicy(); + + // set and save values + $row->setName($req->request->get('name')); + $row->setContent($req->request->get('content')); + + // 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="privacy_policy_list") + */ + public function updateForm($id) + { + $this->denyAccessUnlessGranted('privacy_policy.update', null, 'No access.'); + + $params = []; + $params['mode'] = 'update'; + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(PrivacyPolicy::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('privacy-policy/form.html.twig', $params); + } + + public function updateSubmit(Request $req, ValidatorInterface $validator, $id) + { + $this->denyAccessUnlessGranted('privacy_policy.update', null, 'No access.'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(PrivacyPolicy::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!' + ]); + } + } + + /** + * @Menu(selected="privacy_policy_list") + */ + public function destroy($id) + { + $this->denyAccessUnlessGranted('privacy_policy.delete', null, 'No access.'); + + $params = []; + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(PrivacyPolicy::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(); + } + + 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/WarrantyController.php b/src/Controller/WarrantyController.php index 5e572229..0dc5a43e 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -3,6 +3,12 @@ namespace App\Controller; use App\Entity\Warranty; +use App\Entity\SAPBattery; +use App\Entity\BatteryModel; +use App\Entity\BatterySize; + +use App\Ramcar\WarrantyClass; +use App\Ramcar\WarrantyStatus; use Doctrine\ORM\Query; use Symfony\Component\HttpFoundation\Request; @@ -10,64 +16,359 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use DateTime; + use Catalyst\MenuBundle\Annotation\Menu; class WarrantyController extends Controller { /** - * @Menu(selected="warranty_search") + * @Menu(selected="warranty_list") */ public function index() { - $this->denyaccessUnlessGranted('warranty.search', null, 'No access.'); - $params["mode"] = "form"; + $this->denyAccessUnlessGranted('warranty.list', null, 'No access.'); + + 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 - 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'); - $name = $req->query->get('owner_name'); - $plate_num = $req->query->get('plate_num'); + $params['obj'] = new Warranty(); + $params['mode'] = 'create'; - // 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"; + // get dropdown parameters + $this->fillDropdownParameters($params); // 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(); + + $date_purchase = DateTime::createFromFormat('d M Y', $req->request->get('date_purchase')); + $date_claim = DateTime::createFromFormat('d M Y', $req->request->get('date_claim')); + $date_expire = DateTime::createFromFormat('d M Y', $req->request->get('date_expire')); + + // 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($date_purchase) + ->setClaimedFrom($req->request->get('claim_from')) + ->setStatus($req->request->get('status')); + + if ($date_claim) + { + $obj->setDateClaim($date_claim); + } + if ($date_expire) + { + $obj->setDateExpire($date_expire); + } + + // custom validation for battery model + $model = $em->getRepository(BatteryModel::class) + ->find($req->request->get('battery_model')); + + if (empty($model)) + $error_array['battery_model'] = 'Invalid model selected.'; + else + $obj->setBatteryModel($model); + + // custom validation for battery size + $size = $em->getRepository(BatterySize::class) + ->find($req->request->get('battery_size')); + + if (empty($size)) + $error_array['battery_size'] = 'Invalid size selected.'; + else + $obj->setBatterySize($size); + + // custom validation for SAP battery + $sap = $em->getRepository(SAPBattery::class) + ->find($req->request->get('sap_battery')); + + if (empty($sap)) + $error_array['sap_battery'] = 'Invalid SAP battery selected.'; + else + $obj->setSAPBattery($sap); + + // 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.'; + } + $obj->setPlateNumber($cleaned_plate_number); + + // 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($obj); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + /** + * @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'); + + $params['obj'] = $obj; + + // get dropdown parameters + $this->fillDropdownParameters($params); + + // 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'); + + $date_purchase = DateTime::createFromFormat('d M Y', $req->request->get('date_purchase')); + $date_claim = DateTime::createFromFormat('d M Y', $req->request->get('date_claim')); + $date_expire = DateTime::createFromFormat('d M Y', $req->request->get('date_expire')); + + // 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($date_purchase) + ->setClaimedFrom($req->request->get('claim_from')) + ->setStatus($req->request->get('status')); + + if ($date_claim) + { + $obj->setDateClaim($date_claim); + } + if ($date_expire) + { + $obj->setDateExpire($date_expire); + } + + // custom validation for battery model + $model = $em->getRepository(BatteryModel::class) + ->find($req->request->get('battery_model')); + + if (empty($model)) + $error_array['battery_model'] = 'Invalid model selected.'; + else + $obj->setBatteryModel($model); + + // custom validation for battery size + $size = $em->getRepository(BatterySize::class) + ->find($req->request->get('battery_size')); + + if (empty($size)) + $error_array['battery_size'] = 'Invalid size selected.'; + else + $obj->setBatterySize($size); + + // custom validation for SAP battery + $sap = $em->getRepository(SAPBattery::class) + ->find($req->request->get('sap_battery')); + + if (empty($sap)) + $error_array['sap_battery'] = 'Invalid SAP battery selected.'; + else + $obj->setSAPBattery($sap); + + // 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.'; + } + $obj->setPlateNumber($cleaned_plate_number); + + // 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($obj); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + + } + + + protected function fillDropdownParameters(&$params) + { + $em = $this->getDoctrine()->getManager(); + + $params['batt_models'] = $em->getRepository(BatteryModel::class)->findAll(); + $params['batt_sizes'] = $em->getRepository(BatterySize::class)->findAll(); + $params['sap_batts'] = $em->getRepository(SAPBattery::class)->findAll(); + $params['warranty_classes'] = WarrantyClass::getCollection(); + $params['warranty_statuses'] = WarrantyStatus::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'] . '%'); + } } } diff --git a/src/Controller/WarrantySearchController.php b/src/Controller/WarrantySearchController.php new file mode 100644 index 00000000..f73d6267 --- /dev/null +++ b/src/Controller/WarrantySearchController.php @@ -0,0 +1,73 @@ +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); + } +} diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index 08c39293..10ba5cd7 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -147,6 +147,27 @@ class Customer */ protected $priv_promo; + /** + * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_mobile_app") + * @ORM\JoinColumn(name="policy_mobile_app_id", referencedColumnName="id") + * @Assert\NotBlank() + */ + protected $privpol_mobile_app; + + /** + * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_third_party") + * @ORM\JoinColumn(name="policy_third_party_id", referencedColumnName="id") + * @Assert\NotBlank() + */ + protected $privpol_third_party; + + /** + * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_promo") + * @ORM\JoinColumn(name="policy_promo_id", referencedColumnName="id") + * @Assert\NotBlank() + */ + protected $privpol_promo; + public function __construct() { $this->numbers = new ArrayCollection(); @@ -433,4 +454,39 @@ class Customer { return $this->priv_promo; } + + public function setPrivacyPolicyMobile($privpol_mobile_app) + { + $this->privpol_mobile_app = $privpol_mobile_app; + return $this; + } + + public function getPrivacyPolicyMobile() + { + return $this->privpol_mobile_app; + } + + public function setPrivacyPolicyThirdParty($privpol_third_party) + { + $this->privpol_third_party = $privpol_third_party; + return $this; + } + + public function getPrivacyPolicyThirdParty() + { + return $this->privpol_third_party; + } + + public function setPrivacyPolicyPromo($privpol_promo) + { + $this->privpol_promo = $privpol_promo; + return $this; + } + + public function getPrivacyPolicyPromo() + { + return $this->privpol_promo; + } + + } diff --git a/src/Entity/PrivacyPolicy.php b/src/Entity/PrivacyPolicy.php new file mode 100644 index 00000000..b59ee551 --- /dev/null +++ b/src/Entity/PrivacyPolicy.php @@ -0,0 +1,116 @@ +id; + } + + public function setName($name) + { + $this->name = $name; + return $this; + } + + public function getName() + { + return $this->name; + } + + public function setContent($content) + { + $this->content = $content; + return $this; + } + + public function getContent() + { + return $this->content; + } + + public function setCustMobileApp($cust_mobile_app) + { + $this->cust_mobile_app = $cust_mobile_app; + return $this; + } + + public function getCustMobileApp() + { + return $this->cust_mobile_app; + } + + public function setCustThirdParty($cust_third_party) + { + $this->cust_third_party = $cust_third_party; + return $this; + } + + public function getCustThirdParty() + { + return $this->cust_third_party; + } + + public function setCustPromo($cust_promo) + { + $this->cust_promo = $cust_promo; + return $this; + } + + public function getCustPromo() + { + return $this->cust_promo; + } + + + + + +} + diff --git a/templates/privacy-policy/form.html.twig b/templates/privacy-policy/form.html.twig new file mode 100644 index 00000000..efd2f3b3 --- /dev/null +++ b/templates/privacy-policy/form.html.twig @@ -0,0 +1,142 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +