From fef70c36a4d44660feedea5ba413bc99112b9437 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 22 Jul 2019 04:12:20 +0000 Subject: [PATCH 01/17] Add average_rating for partner. #228 --- src/Controller/APIController.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 6d5e295a..2a476dce 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -1997,19 +1997,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'] = [ @@ -2022,7 +2020,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); From 4a13c3e6155c9537c6f8a46ece48bef63322197a Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 23 Jul 2019 03:39:53 +0000 Subject: [PATCH 02/17] Create PrivacyPolicy entity. Add links from Customer to PrivacyPolicy. #233 --- src/Entity/Customer.php | 56 +++++++++++++++++ src/Entity/PrivacyPolicy.php | 116 +++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 src/Entity/PrivacyPolicy.php diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index 08c39293..d1576621 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="mobile_policy_id", referencedColumnName="id") + * @Assert\NotBlank() + */ + protected $privpol_mobile_app; + + /** + * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_third_party") + * @ORM\JoinColumn(name="third_party_policy_id", referencedColumnName="id") + * @Assert\NotBlank() + */ + protected $privpol_third_party; + + /** + * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_promo") + * @ORM\JoinColumn(name="promo_policy_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; + } + + + + + +} + From 1535fd9cd96d877a4b8bdb770e9ec4bab6edf4c7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 23 Jul 2019 04:02:04 +0000 Subject: [PATCH 03/17] Rename the columns linking customer and privacy policy. #233 --- src/Entity/Customer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index d1576621..10ba5cd7 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -149,21 +149,21 @@ class Customer /** * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_mobile_app") - * @ORM\JoinColumn(name="mobile_policy_id", referencedColumnName="id") + * @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="third_party_policy_id", referencedColumnName="id") + * @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="promo_policy_id", referencedColumnName="id") + * @ORM\JoinColumn(name="policy_promo_id", referencedColumnName="id") * @Assert\NotBlank() */ protected $privpol_promo; From 50a3afb21326034b32fec58d88a159b9bcf3e0ee Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 23 Jul 2019 09:57:14 +0000 Subject: [PATCH 04/17] Add privacy policy in menu and acl yaml files. Add routes for private policy functions. Add PrivatePolicyController. Add twig files for private policy. #233 --- config/acl.yaml | 15 ++ config/menu.yaml | 4 + config/routes/privacy_policy.yaml | 33 +++ src/Controller/PrivacyPolicyController.php | 272 +++++++++++++++++++++ templates/privacy-policy/form.html.twig | 142 +++++++++++ templates/privacy-policy/list.html.twig | 142 +++++++++++ 6 files changed, 608 insertions(+) create mode 100644 config/routes/privacy_policy.yaml create mode 100644 src/Controller/PrivacyPolicyController.php create mode 100644 templates/privacy-policy/form.html.twig create mode 100644 templates/privacy-policy/list.html.twig diff --git a/config/acl.yaml b/config/acl.yaml index 5695e217..e868c7ec 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,17 @@ 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 diff --git a/config/menu.yaml b/config/menu.yaml index d470f680..b0a00d92 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -143,6 +143,10 @@ 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: 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/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/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 %} + +
+
+
+

Privacy Policies

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

+ {% if mode == 'update' %} + Edit Policy + {{ obj.getID() }} + {% else %} + New Policy + {% endif %} +

+
+
+
+
+
+
+
+ + + +
+
+
+
+ + + +
+
+
+
+
+
+
+ + Back +
+
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/privacy-policy/list.html.twig b/templates/privacy-policy/list.html.twig new file mode 100644 index 00000000..d0c40e11 --- /dev/null +++ b/templates/privacy-policy/list.html.twig @@ -0,0 +1,142 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Privacy Policies +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} From b657ae95d511882d1b36fd9c6d37ea905a556992 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 24 Jul 2019 08:45:52 +0000 Subject: [PATCH 05/17] Add setting of privacy policy for customer when user updates info for mobile session and when user sends privacy settings for third party and promo. #233 --- src/Controller/APIController.php | 44 +++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 2a476dce..63691592 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -395,6 +395,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(); @@ -1787,9 +1798,40 @@ 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); + // check if privacy settings are true + // if true, set the private policy for the customer + if ($priv_promo) + { + // find the promo policy + $policy = $em->createQuery('SELECT policy FROM App\Entity\PrivacyPolicy policy WHERE policy.name LIKE :policy_type') + ->setParameter('policy_type', "%" . "promo" . "%") + ->getOneOrNullResult(); + + // set policy id + if ($policy != null) + { + $cust->setPrivacyPolicyPromo($policy); + } + } + + if ($priv_third_party) + { + // find the third party policy + $policy = $em->createQuery('SELECT policy FROM App\Entity\PrivacyPolicy policy WHERE policy.name LIKE :policy_type') + ->setParameter('policy_type', "%" . "third party" . "%") + ->getOneOrNullResult(); + + // set policy id + if ($policy != null) + { + $cust->setPrivacyPolicyThirdParty($policy); + } + } + $em->flush(); return $res->getReturnResponse(); From 830803ac2d5794ef5f096d11b4585ded8cff8f32 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 24 Jul 2019 12:54:59 +0000 Subject: [PATCH 06/17] Create command to set the privacy policy for existing customers. #233 --- .../SetCustomerPrivacyPolicyCommand.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/Command/SetCustomerPrivacyPolicyCommand.php diff --git a/src/Command/SetCustomerPrivacyPolicyCommand.php b/src/Command/SetCustomerPrivacyPolicyCommand.php new file mode 100644 index 00000000..8e2f468f --- /dev/null +++ b/src/Command/SetCustomerPrivacyPolicyCommand.php @@ -0,0 +1,81 @@ +em = $om; + + parent::__construct(); + } + + protected function configure() + { + $this->setName('customer:setprivacypolicy') + ->setDescription('Set customer private policy.') + ->addArgument('third_party_policy_id', InputArgument::REQUIRED, 'third_party_policy_id') + ->addArgument('mobile_policy_id', InputArgument::REQUIRED, 'mobile_policy_id') + ->addArgument('promo_policy_id', InputArgument::REQUIRED, 'promo_policy_id' ) + ->setHelp('Set customer private policy. Order of ids: third party mobile promo'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $third_party_policy_id = $input->getArgument('third_party_policy_id'); + $mobile_policy_id = $input->getArgument('mobile_policy_id'); + $promo_policy_id = $input->getArgument('promo_policy_id'); + + // get third party policy + $third_party_policy = $this->em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $third_party_policy_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)->findOneBy(['id' => $promo_policy_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)->findOneBy(['id' => $mobile_policy_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(); + } +} From 06adce710f6a2b2017eeb7f620595038772538d2 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 25 Jul 2019 00:42:40 +0000 Subject: [PATCH 07/17] Add policy ids to the .env.dist file. Modify the query to get policy in the APIController. #233 --- .env.dist | 6 +++++- src/Controller/APIController.php | 17 +++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.env.dist b/.env.dist index 4c0b202a..320e69b7 100644 --- a/.env.dist +++ b/.env.dist @@ -34,4 +34,8 @@ 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 diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 63691592..f12d750c 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; @@ -1802,14 +1804,19 @@ class APIController extends Controller $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->createQuery('SELECT policy FROM App\Entity\PrivacyPolicy policy WHERE policy.name LIKE :policy_type') - ->setParameter('policy_type', "%" . "promo" . "%") - ->getOneOrNullResult(); + $policy = $em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $policy_promo_id]); // set policy id if ($policy != null) @@ -1821,9 +1828,7 @@ class APIController extends Controller if ($priv_third_party) { // find the third party policy - $policy = $em->createQuery('SELECT policy FROM App\Entity\PrivacyPolicy policy WHERE policy.name LIKE :policy_type') - ->setParameter('policy_type', "%" . "third party" . "%") - ->getOneOrNullResult(); + $policy = $em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $policy_third_party_id]); // set policy id if ($policy != null) From 3c460b86c98fddcaae13a50290310b89e4333655 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 25 Jul 2019 03:19:20 +0000 Subject: [PATCH 08/17] Use the env vars for the policy in the command. Improve the queries for privacy policy. #235 --- .../SetCustomerPrivacyPolicyCommand.php | 23 +++++++++++-------- src/Controller/APIController.php | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Command/SetCustomerPrivacyPolicyCommand.php b/src/Command/SetCustomerPrivacyPolicyCommand.php index 8e2f468f..d4431175 100644 --- a/src/Command/SetCustomerPrivacyPolicyCommand.php +++ b/src/Command/SetCustomerPrivacyPolicyCommand.php @@ -7,6 +7,8 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Dotenv\Dotenv; + use Doctrine\Common\Persistence\ObjectManager; use App\Entity\Customer; @@ -28,20 +30,21 @@ class SetCustomerPrivacyPolicyCommand extends Command { $this->setName('customer:setprivacypolicy') ->setDescription('Set customer private policy.') - ->addArgument('third_party_policy_id', InputArgument::REQUIRED, 'third_party_policy_id') - ->addArgument('mobile_policy_id', InputArgument::REQUIRED, 'mobile_policy_id') - ->addArgument('promo_policy_id', InputArgument::REQUIRED, 'promo_policy_id' ) - ->setHelp('Set customer private policy. Order of ids: third party mobile promo'); + ->setHelp('Set customer private policy.'); } protected function execute(InputInterface $input, OutputInterface $output) { - $third_party_policy_id = $input->getArgument('third_party_policy_id'); - $mobile_policy_id = $input->getArgument('mobile_policy_id'); - $promo_policy_id = $input->getArgument('promo_policy_id'); + // 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)->findOneBy(['id' => $third_party_policy_id]); + $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]); @@ -51,7 +54,7 @@ class SetCustomerPrivacyPolicyCommand extends Command } // get promo policy - $promo_policy = $this->em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $promo_policy_id]); + $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]); @@ -63,7 +66,7 @@ class SetCustomerPrivacyPolicyCommand extends Command $this->em->flush(); // get mobile policy - $mobile_policy = $this->em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $mobile_policy_id]); + $mobile_policy = $this->em->getRepository(PrivacyPolicy::class)->find($policy_mobile_id); // get mobile sessions $mobile_sessions = $this->em->getRepository(MobileSession::class)->findAll(); diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index f12d750c..5930d1f9 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -1816,7 +1816,7 @@ class APIController extends Controller if ($priv_promo) { // find the promo policy - $policy = $em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $policy_promo_id]); + $policy = $em->getRepository(PrivacyPolicy::class)->find($policy_promo_id); // set policy id if ($policy != null) @@ -1828,7 +1828,7 @@ class APIController extends Controller if ($priv_third_party) { // find the third party policy - $policy = $em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $policy_third_party_id]); + $policy = $em->getRepository(PrivacyPolicy::class)->find($policy_third_party_id); // set policy id if ($policy != null) From 2d1a91842a22871a864173004ffd4fe171c5ba81 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 26 Jul 2019 08:21:00 +0000 Subject: [PATCH 09/17] 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 --- config/acl.yaml | 12 + config/menu.yaml | 4 + config/routes/warranty.yaml | 30 ++- config/routes/warranty_search.yaml | 10 + src/Controller/WarrantyController.php | 243 ++++++++++++++++---- src/Controller/WarrantySearchController.php | 73 ++++++ templates/warranty/list.html.twig | 129 +++++++++++ 7 files changed, 456 insertions(+), 45 deletions(-) create mode 100644 config/routes/warranty_search.yaml create mode 100644 src/Controller/WarrantySearchController.php create mode 100644 templates/warranty/list.html.twig diff --git a/config/acl.yaml b/config/acl.yaml index e868c7ec..9de80027 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -344,3 +344,15 @@ access_keys: 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 b0a00d92..92b29c2d 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -147,6 +147,10 @@ main_menu: 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/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/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index 5e572229..3f5be3cf 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -4,6 +4,8 @@ namespace App\Controller; use App\Entity\Warranty; +use App\Ramcar\WarrantyClass; + use Doctrine\ORM\Query; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -15,59 +17,220 @@ 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 batteries (models and sizes) + // get SAP batteries + // get warranty class // 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'] . '%'); + } + } + + + + } 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/templates/warranty/list.html.twig b/templates/warranty/list.html.twig new file mode 100644 index 00000000..0a3efa47 --- /dev/null +++ b/templates/warranty/list.html.twig @@ -0,0 +1,129 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Warranties +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} + From 2deea2ea8ee9ad3ee6a6c9287892360522180906 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 29 Jul 2019 04:38:00 +0000 Subject: [PATCH 10/17] Add form to add/update warranty. #236 --- src/Controller/WarrantyController.php | 23 ++---- templates/warranty/form.html.twig | 102 ++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 templates/warranty/form.html.twig diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index 3f5be3cf..dab8e7c0 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -3,6 +3,8 @@ namespace App\Controller; use App\Entity\Warranty; +use App\Entity\SAPBattery; +use App\Entity\BatteryManufacturer; use App\Ramcar\WarrantyClass; @@ -123,9 +125,8 @@ class WarrantyController extends Controller $params['obj'] = new Warranty(); $params['mode'] = 'create'; - // get batteries (models and sizes) - // get SAP batteries - // get warranty class + // get dropdown parameters + $this->fillDropdownParameters($params); // response return $this->render('warranty/form.html.twig', $params); @@ -181,13 +182,11 @@ class WarrantyController extends Controller 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; + // get dropdown parameters + $this->fillDropdownParameters($params); + // response return $this->render('warranty/form.html.twig', $params); } @@ -210,14 +209,8 @@ class WarrantyController extends Controller { $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['sap_batts'] = $em->getRepository(SAPBattery::class)->findAll(); $params['warranty_classes'] = WarrantyClass::getCollection(); } diff --git a/templates/warranty/form.html.twig b/templates/warranty/form.html.twig new file mode 100644 index 00000000..3e9da5dd --- /dev/null +++ b/templates/warranty/form.html.twig @@ -0,0 +1,102 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Warranties

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

+ {% if mode == 'update' %} + Edit Warranty + {% else %} + New Warranty + {% endif %} +

+
+
+
+
+
+
+
+

+ Warranty Info +

+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+
+
+ + + +
+
+ + + +
+
+ +
+ +63 + + +
+
+
+
+
+
+
+
+
+
+{% endblock %} From a18654b0d129b569e619dfbfcdf7444229e62aa9 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 29 Jul 2019 05:33:12 +0000 Subject: [PATCH 11/17] Add OTP_MODE variable to .env.dist. Modify checking for the confirmCode to set, depending on the value of OTP_MODE. #237 --- .env.dist | 3 +++ src/Controller/APIController.php | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.env.dist b/.env.dist index 320e69b7..4e10dffc 100644 --- a/.env.dist +++ b/.env.dist @@ -39,3 +39,6 @@ REDIS_CLIENT_PASSWORD=foobared POLICY_PROMO=insertpromopolicyidhere POLICY_THIRD_PARTY=insertthirdpartypolicyidhere POLICY_MOBILE=insertmobilepolicyidhere + +# OTP +OTP_MODE=settotestorrandom diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 5930d1f9..b5fe5909 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -239,8 +239,16 @@ class APIController extends Controller // phone number $phone_number = $req->request->get('phone_number'); + // get otp_mode from .env + $dotenv = new Dotenv(); + $dotenv->loadEnv(__DIR__.'/../../.env'); + + $otp_mode = $_ENV['OTP_MODE']; + // check if the phone number is our test number - if ($phone_number == '639991112233') + //if ($phone_number == '639991112233') + // check if otp_mode is test + if ($otp_mode == 'test') { $code = '123456'; $this->session->setConfirmCode($code) @@ -255,7 +263,6 @@ class APIController extends Controller // TODO: validate phone number // generate code and save - // $code = '123456'; $code = $this->generateConfirmCode(); $this->session->setConfirmCode($code) ->setPhoneNumber($phone_number); From 2e022c893cff9331655528232504f35ec90b87ff Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 29 Jul 2019 08:32:48 +0000 Subject: [PATCH 12/17] Add form for warranty submission. #236 --- src/Controller/WarrantyController.php | 60 ++++++++- templates/warranty/form.html.twig | 175 ++++++++++++++++++++++++++ 2 files changed, 231 insertions(+), 4 deletions(-) diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index dab8e7c0..832cfd53 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -4,9 +4,11 @@ namespace App\Controller; use App\Entity\Warranty; use App\Entity\SAPBattery; -use App\Entity\BatteryManufacturer; +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; @@ -146,9 +148,38 @@ class WarrantyController extends Controller ->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'))); + ->setDatePurchase(DateTime::createFromFormat("d M Y h:i A", $req->request->get('date_purchase'))) + ->setDateExpire(DateTime::createFromFormat("d M Y h:i A", $req->request->get('date_expire'))) + ->setDateClaim(DateTime::createFromFormat("d M Y h:i A", $req->request->get('date_claim'))) + ->setClaimFrom($req->request->get('claim_from')) + ->setStatus($req->request->get('status')); - // need to get the battery and SAP battery set + // 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); @@ -163,6 +194,25 @@ class WarrantyController extends Controller 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!' + ]); + } + } /** @@ -209,9 +259,11 @@ class WarrantyController extends Controller { $em = $this->getDoctrine()->getManager(); - $params['bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll(); + $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 diff --git a/templates/warranty/form.html.twig b/templates/warranty/form.html.twig index 3e9da5dd..d5c629f4 100644 --- a/templates/warranty/form.html.twig +++ b/templates/warranty/form.html.twig @@ -92,6 +92,99 @@ +
+
+ + + +
+
+ + + +
+
+ + + +
+
+
+
+ +
+ + + + +
+ +
+
+ + + +
+
+
+
+ +
+ + + + +
+ +
+
+ + + +
+
+ + + +
+
+ + +
+
+
+
+ + Back +
+
@@ -100,3 +193,85 @@ {% endblock %} + +{% block scripts %} + +{% endblock %} From 978735adbd90f35d167eef8bd16c7c5ee411cb7e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 30 Jul 2019 03:39:32 +0000 Subject: [PATCH 13/17] Fix error for add warranty. #236 --- src/Controller/WarrantyController.php | 17 +++++++++++++---- templates/warranty/form.html.twig | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index 832cfd53..145ffe85 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -16,6 +16,8 @@ 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 @@ -142,18 +144,24 @@ class WarrantyController extends Controller $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')); + // 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'))) - ->setDateExpire(DateTime::createFromFormat("d M Y h:i A", $req->request->get('date_expire'))) - ->setDateClaim(DateTime::createFromFormat("d M Y h:i A", $req->request->get('date_claim'))) - ->setClaimFrom($req->request->get('claim_from')) + ->setDatePurchase($date_purchase) + ->setClaimedFrom($req->request->get('claim_from')) ->setStatus($req->request->get('status')); + if ($date_claim) + { + $obj->setDateClaim($date_claim); + } + // custom validation for battery model $model = $em->getRepository(BatteryModel::class) ->find($req->request->get('battery_model')); @@ -189,6 +197,7 @@ class WarrantyController extends Controller { $error_array['plate_number'] = 'Invalid plate number specified.'; } + $obj->setPlateNumber($cleaned_plate_number); // add errors to list foreach ($errors as $error) { diff --git a/templates/warranty/form.html.twig b/templates/warranty/form.html.twig index d5c629f4..be1fab1e 100644 --- a/templates/warranty/form.html.twig +++ b/templates/warranty/form.html.twig @@ -132,7 +132,7 @@
- + @@ -214,7 +214,7 @@ text: 'Your changes have been saved!', type: 'success', onClose: function() { - window.location.href = "{{ url('service_list') }}"; + window.location.href = "{{ url('warranty_list') }}"; } }); }).fail(function(response) { From 31dd5c4cf23cc50eb1b67f5639e97c38d5f5431a Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 30 Jul 2019 03:55:50 +0000 Subject: [PATCH 14/17] Add checking for otp mode for sending of confirmation code. #237 --- src/Controller/APIController.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index b5fe5909..4510fbf8 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -245,8 +245,6 @@ class APIController extends Controller $otp_mode = $_ENV['OTP_MODE']; - // check if the phone number is our test number - //if ($phone_number == '639991112233') // check if otp_mode is test if ($otp_mode == 'test') { @@ -268,12 +266,11 @@ class APIController extends Controller ->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(); From ad27ec3cf2d915c57468799237cc7830ca712bad Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 30 Jul 2019 06:20:16 +0000 Subject: [PATCH 15/17] Add update warranty. #236 --- src/Controller/WarrantyController.php | 90 ++++++++++++++++++++++++++- templates/warranty/form.html.twig | 11 +++- 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index 145ffe85..2f61d572 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -146,6 +146,7 @@ class WarrantyController extends Controller $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')) @@ -161,6 +162,10 @@ class WarrantyController extends Controller { $obj->setDateClaim($date_claim); } + if ($date_expire) + { + $obj->setDateExpire($date_expire); + } // custom validation for battery model $model = $em->getRepository(BatteryModel::class) @@ -221,7 +226,6 @@ class WarrantyController extends Controller 'success' => 'Changes have been saved!' ]); } - } /** @@ -261,6 +265,90 @@ class WarrantyController extends Controller // 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!' + ]); + } + } diff --git a/templates/warranty/form.html.twig b/templates/warranty/form.html.twig index be1fab1e..d1d4592f 100644 --- a/templates/warranty/form.html.twig +++ b/templates/warranty/form.html.twig @@ -110,7 +110,7 @@ @@ -122,7 +122,7 @@ @@ -141,7 +141,12 @@
- +
+ + + + +
From 9c2fd4ed3a555dd5a0f32dfdc05d03bb05535c1c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 30 Jul 2019 06:33:40 +0000 Subject: [PATCH 16/17] Add default value for purchase date. Default for date expiry and date claim is empty. #236 --- src/Controller/WarrantyController.php | 4 ---- templates/warranty/form.html.twig | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index 2f61d572..0dc5a43e 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -371,8 +371,4 @@ class WarrantyController extends Controller ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); } } - - - - } diff --git a/templates/warranty/form.html.twig b/templates/warranty/form.html.twig index d1d4592f..d99470cb 100644 --- a/templates/warranty/form.html.twig +++ b/templates/warranty/form.html.twig @@ -142,7 +142,7 @@
- + From 6655869c4f6f55d23c13c4f05abf8c0199e1f1af Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 31 Jul 2019 02:19:46 +0000 Subject: [PATCH 17/17] Activate all warranties found for a plate number. #238 --- src/Controller/APIController.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 4510fbf8..3965c4f2 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -1890,17 +1890,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();