From 59f29b223dfc6bb1812121d9edf334850eaebd42 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 5 May 2021 06:03:48 +0000 Subject: [PATCH 01/10] Add entities for the customer tag and promo log. #558 --- src/Entity/Customer.php | 30 +++++++ src/Entity/CustomerTag.php | 93 ++++++++++++++++++++ src/Entity/PromoLog.php | 168 +++++++++++++++++++++++++++++++++++++ 3 files changed, 291 insertions(+) create mode 100644 src/Entity/CustomerTag.php create mode 100644 src/Entity/PromoLog.php diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index f5e8e4e9..8ee3837a 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -208,12 +208,20 @@ class Customer */ protected $create_source; + // customer tags + /** + * @ORM\ManyToMany(targetEntity="CustomerTag", inversedBy="customers") + * @ORM\JoinTable(name="customer_customer_tags") + */ + protected $customer_tags; + public function __construct() { $this->numbers = new ArrayCollection(); $this->sessions = new ArrayCollection(); $this->vehicles = new ArrayCollection(); $this->job_orders = new ArrayCollection(); + $this->customer_tags = new ArrayCollection(); $this->customer_classification = CustomerClassification::REGULAR; $this->customer_notes = ''; @@ -608,4 +616,26 @@ class Customer { return $this->create_source; } + + public function addCustomerTag(CustomerTag $customer_tag) + { + $this->customer_tags->add($customer_tag); + return $this; + } + + public function clearCustomerTags() + { + $this->customer_tags->clear(); + return $this; + } + + public function getCustomerTags() + { + $str_customer_tags = []; + foreach ($this->customer_tags as $customer_tag) + $str_customer_tags[] = $customer_tag->getID(); + + return $str_customer_tags; + } + } diff --git a/src/Entity/CustomerTag.php b/src/Entity/CustomerTag.php new file mode 100644 index 00000000..a3c87423 --- /dev/null +++ b/src/Entity/CustomerTag.php @@ -0,0 +1,93 @@ +date_create = new DateTime(); + $this->customers = new ArrayCollection(); + $this->car_club_member = false; + $this->car_club_promo = false; + } + + public function getID() + { + return $this->id; + } + + public function setName($name) + { + $this->name = $name; + return $this; + } + + public function getName() + { + return $this->name; + } + + public function getDateCreate() + { + return $this->date_create; + } + + public function addCustomer(Customer $customer) + { + $this->customers[$customer->getID()] = $customer; + + return $this; + } + + public function clearCustomers() + { + $this->customers->clear(); + return $this; + } + + public function getCustomers() + { + return $this->customers; + } +} diff --git a/src/Entity/PromoLog.php b/src/Entity/PromoLog.php new file mode 100644 index 00000000..0decf2a7 --- /dev/null +++ b/src/Entity/PromoLog.php @@ -0,0 +1,168 @@ +date_create = new DateTime(); + } + + public function getID() + { + return $this->id; + } + + public function setDateCreate(DateTime $date_create) + { + $this->date_create = $date_create; + return $this; + } + + public function getDateCreate() + { + return $this->date_create; + } + + public function setCreatedBy($created_by) + { + $this->created_by = $created_by; + return $this; + } + + public function getCreatedBy() + { + return $this->created_by; + } + + public function setCustId($cust_id) + { + $this->cust_id = $cust_id; + return $this; + } + + public function getCustId() + { + return $this->cust_id; + } + + public function setCustFirstName($cust_first_name) + { + $this->cust_first_name = $cust_first_name; + return $this; + } + + public function getCustFirstName() + { + return $this->cust_first_name; + } + + public function setCustLastName($cust_last_name) + { + $this->cust_last_name = $cust_last_name; + return $this; + } + + public function getCustLastName() + { + return $this->cust_last_name; + } + + public function setJoId($jo_id) + { + $this->jo_id = $jo_id; + return $this; + } + + public function getJoId() + { + return $this->jo_id; + } + + public function setInvoiceId($invoice_id) + { + $this->invoice_id = $invoice_id; + return $this; + } + + public function getInvoiceId() + { + return $this->invoice_id; + } + + public function setAmount($amount) + { + $this->amount = $amount; + return $this; + } + + public function getAmount() + { + return $this->amount; + } +} From 601b23afdfca037246ea4126878352da218c7466 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 5 May 2021 09:18:35 +0000 Subject: [PATCH 02/10] Add CRUD for customer tag. #558 --- config/acl.yaml | 14 ++ config/menu.yaml | 4 + config/routes/customer_tag.yaml | 34 +++ src/Controller/CustomerTagController.php | 260 +++++++++++++++++++++++ src/Entity/CustomerTag.php | 39 +++- templates/customer-tag/form.html.twig | 145 +++++++++++++ templates/customer-tag/list.html.twig | 143 +++++++++++++ 7 files changed, 634 insertions(+), 5 deletions(-) create mode 100644 config/routes/customer_tag.yaml create mode 100644 src/Controller/CustomerTagController.php create mode 100644 templates/customer-tag/form.html.twig create mode 100644 templates/customer-tag/list.html.twig diff --git a/config/acl.yaml b/config/acl.yaml index e694340c..0f858fa9 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -488,3 +488,17 @@ access_keys: label: Update - id: sap_csize.delete label: Delete + + - id: customer_tag + label: Customer Tags Access + acls: + - id: customer_tag.menu + label: Menu + - id: customer_tag.list + label: List + - id: customer_tag.add + label: Add + - id: customer_tag.update + label: Update + - id: customer_tag.delete + label: Delete diff --git a/config/menu.yaml b/config/menu.yaml index d90ba3da..35709ee0 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -185,6 +185,10 @@ main_menu: acl: static_content.list label: Static Content parent: support + - id: customertag_list + acl: customer_tag.list + label: Customer Tags + parent: support - id: service acl: service.menu diff --git a/config/routes/customer_tag.yaml b/config/routes/customer_tag.yaml new file mode 100644 index 00000000..9fd98906 --- /dev/null +++ b/config/routes/customer_tag.yaml @@ -0,0 +1,34 @@ +customertag_list: + path: /customer_tags + controller: App\Controller\CustomerTagController::index + +customertag_rows: + path: /customer_tags/rows + controller: App\Controller\CustomerTagController::rows + methods: [POST] + +customertag_create: + path: /customer_tags/create + controller: App\Controller\CustomerTagController::addForm + methods: [GET] + +customertag_create_submit: + path: /customer_tags/create + controller: App\Controller\CustomerTagController::addSubmit + methods: [POST] + +customertag_update: + path: /customer_tags/{id} + controller: App\Controller\CustomerTagController::updateForm + methods: [GET] + +customertag_update_submit: + path: /customer_tags/{id} + controller: App\Controller\CustomerTagController::updateSubmit + methods: [POST] + +customertag_delete: + path: /customer_tags/{id} + controller: App\Controller\CustomerTagController::destroy + methods: [DELETE] + diff --git a/src/Controller/CustomerTagController.php b/src/Controller/CustomerTagController.php new file mode 100644 index 00000000..ab4178f5 --- /dev/null +++ b/src/Controller/CustomerTagController.php @@ -0,0 +1,260 @@ +denyAccessUnlessGranted('customer_tag.list', null, 'No access.'); + + return $this->render('customer-tag/list.html.twig'); + } + + public function rows(Request $req) + { + $this->denyAccessUnlessGranted('customer_tag.list', null, 'No access.'); + + // get query builder + $qb = $this->getDoctrine() + ->getRepository(CustomerTag::class) + ->createQueryBuilder('q'); + + // get datatable params + $datatable = $req->request->get('datatable'); + + // count total records + $tquery = $qb->select('COUNT(q)'); + $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'); + $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('customer_tag.update')) + $row['meta']['update_url'] = $this->generateUrl('customertag_update', ['id' => $row['id']]); + if ($this->isGranted('customer_tag.delete')) + $row['meta']['delete_url'] = $this->generateUrl('customertag_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } + + protected function setQueryFilters($datatable, QueryBuilder $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'] . '%'); + } + } + + /** + * @Menu(selected="customer_tag_list") + */ + public function addForm() + { + $this->denyAccessUnlessGranted('customer_tag.add', null, 'No access.'); + + $params['obj'] = new CustomerTag(); + $params['mode'] = 'create'; + + // response + return $this->render('customer-tag/form.html.twig', $params); + } + + public function addSubmit(Request $req, ValidatorInterface $validator) + { + $this->denyAccessUnlessGranted('customer_tag.add', null, 'No access.'); + + // create new object + $em = $this->getDoctrine()->getManager(); + $obj = new CustomerTag(); + + $obj->setID($req->request->get('id')) + ->setName($req->request->get('name')); + + // validate + $errors = $validator->validate($obj); + + // 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($obj); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + /** + * @Menu(selected="customer_tag_list") + */ + public function updateForm($id) + { + $this->denyAccessUnlessGranted('customer_tag.update', null, 'No access.'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(CustomerTag::class)->find($id); + + // make sure this row exists + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + $params['obj'] = $obj; + $params['mode'] = 'update'; + + // response + return $this->render('customer-tag/form.html.twig', $params); + } + + public function updateSubmit(Request $req, ValidatorInterface $validator, $id) + { + $this->denyAccessUnlessGranted('customer_tag.update', null, 'No access.'); + + // get object data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(CustomerTag::class)->find($id); + + // make sure this object exists + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + $obj->setID($req->request->get('id')) + ->setName($req->request->get('name')); + + // validate + $errors = $validator->validate($obj); + + // 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); + } + + // validated! save the entity + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + + public function destroy($id) + { + $this->denyAccessUnlessGranted('customer_tag.delete', null, 'No access.'); + + // get object data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(CustomerTag::class)->find($id); + + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + // delete this object + $em->remove($obj); + $em->flush(); + + // response + $response = new Response(); + $response->setStatusCode(Response::HTTP_OK); + $response->send(); + } +} diff --git a/src/Entity/CustomerTag.php b/src/Entity/CustomerTag.php index a3c87423..f2d8f67e 100644 --- a/src/Entity/CustomerTag.php +++ b/src/Entity/CustomerTag.php @@ -4,6 +4,7 @@ namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; +use Symfony\Component\Validator\Constraints as Assert; use DateTime; /** @@ -12,17 +13,17 @@ use DateTime; */ class CustomerTag { - // unique id /** * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") + * @ORM\Column(type="string", length=80, nullable=false) + * @Assert\NotBlank() */ protected $id; // name of tag /** * @ORM\Column(type="string", length=80) + * @Assert\NotBlank() */ protected $name; @@ -48,8 +49,8 @@ class CustomerTag { $this->date_create = new DateTime(); $this->customers = new ArrayCollection(); - $this->car_club_member = false; - $this->car_club_promo = false; + $this->flag_car_club_member = false; + $this->flag_car_club_promo = false; } public function getID() @@ -57,6 +58,12 @@ class CustomerTag return $this->id; } + public function setID($id) + { + $this->id = $id; + return $this; + } + public function setName($name) { $this->name = $name; @@ -90,4 +97,26 @@ class CustomerTag { return $this->customers; } + + public function setCarClubMember($flag_car_club_member = true) + { + $this->flag_car_club_member = $flag_car_club_member; + return $this; + } + + public function isCarClubMember() + { + return $this->flag_car_club_member; + } + + public function setCarClubPromo($flag_car_club_promo = true) + { + $this->flag_car_club_promo = $flag_car_club_promo; + return $this; + } + + public function isCarClubPromo() + { + return $this->flag_car_club_promo; + } } diff --git a/templates/customer-tag/form.html.twig b/templates/customer-tag/form.html.twig new file mode 100644 index 00000000..ce574a44 --- /dev/null +++ b/templates/customer-tag/form.html.twig @@ -0,0 +1,145 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Customer Tags

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

+ {% if mode == 'update' %} + Edit Customer Tag + {{ obj.getName }} + {% else %} + New Customer Tag + {% endif %} +

+
+
+
+
+ +
+
+
+ + + + Unique identifier for this customer tag +
+
+
+
+ + + +
+
+
+
+
+
+
+ + Back +
+
+
+
+
+
+
+
+
+{% endblock %} + + +{% block scripts %} + +{% endblock %} diff --git a/templates/customer-tag/list.html.twig b/templates/customer-tag/list.html.twig new file mode 100644 index 00000000..6f895465 --- /dev/null +++ b/templates/customer-tag/list.html.twig @@ -0,0 +1,143 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Customer Tags +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} From 6ac92eba304ab83e16130f553c65ee881e0856c3 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 5 May 2021 10:33:46 +0000 Subject: [PATCH 03/10] Add customer tags to customer form. #558 --- src/Entity/Customer.php | 10 ++--- src/Entity/CustomerTag.php | 38 +------------------ .../CustomerHandler/ResqCustomerHandler.php | 22 ++++++++++- templates/customer/form.html.twig | 13 +++++++ 4 files changed, 40 insertions(+), 43 deletions(-) diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index 8ee3837a..02f61842 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -619,7 +619,7 @@ class Customer public function addCustomerTag(CustomerTag $customer_tag) { - $this->customer_tags->add($customer_tag); + $this->customer_tags[$customer_tag->getID()] = $customer_tag; return $this; } @@ -631,11 +631,11 @@ class Customer public function getCustomerTags() { - $str_customer_tags = []; - foreach ($this->customer_tags as $customer_tag) - $str_customer_tags[] = $customer_tag->getID(); + $str_cust_tags = []; + foreach ($this->customer_tags as $cust_tag) + $str_cust_tags[] = $cust_tag->getID(); - return $str_customer_tags; + return $str_cust_tags; } } diff --git a/src/Entity/CustomerTag.php b/src/Entity/CustomerTag.php index f2d8f67e..aa80e2e7 100644 --- a/src/Entity/CustomerTag.php +++ b/src/Entity/CustomerTag.php @@ -15,7 +15,7 @@ class CustomerTag { /** * @ORM\Id - * @ORM\Column(type="string", length=80, nullable=false) + * @ORM\Column(type="string", length=80, nullable=false, unique=true) * @Assert\NotBlank() */ protected $id; @@ -27,18 +27,6 @@ class CustomerTag */ protected $name; - // flag for car club member - /** - * @ORM\Column(type="boolean") - */ - protected $flag_car_club_member; - - // flag for car club promo - /** - * @ORM\Column(type="boolean") - */ - protected $flag_car_club_promo; - // customers /** * @ORM\ManyToMany(targetEntity="Customer", mappedBy="customer_tags", fetch="EXTRA_LAZY") @@ -49,8 +37,6 @@ class CustomerTag { $this->date_create = new DateTime(); $this->customers = new ArrayCollection(); - $this->flag_car_club_member = false; - $this->flag_car_club_promo = false; } public function getID() @@ -97,26 +83,4 @@ class CustomerTag { return $this->customers; } - - public function setCarClubMember($flag_car_club_member = true) - { - $this->flag_car_club_member = $flag_car_club_member; - return $this; - } - - public function isCarClubMember() - { - return $this->flag_car_club_member; - } - - public function setCarClubPromo($flag_car_club_promo = true) - { - $this->flag_car_club_promo = $flag_car_club_promo; - return $this; - } - - public function isCarClubPromo() - { - return $this->flag_car_club_promo; - } } diff --git a/src/Service/CustomerHandler/ResqCustomerHandler.php b/src/Service/CustomerHandler/ResqCustomerHandler.php index 76d20054..8c48650d 100644 --- a/src/Service/CustomerHandler/ResqCustomerHandler.php +++ b/src/Service/CustomerHandler/ResqCustomerHandler.php @@ -22,6 +22,7 @@ use App\Entity\Vehicle; use App\Entity\Battery; use App\Entity\VehicleManufacturer; use App\Entity\BatteryManufacturer; +use App\Entity\CustomerTag; use DateTime; @@ -151,6 +152,9 @@ class ResqCustomerHandler implements CustomerHandlerInterface $params['obj'] = new Customer(); $params['mode'] = 'create'; + // get customer tags + $params['customer_tags'] = $this->em->getRepository(CustomerTag::class)->findAll(); + // get dropdown parameters $this->fillDropdownParameters($params); @@ -307,6 +311,9 @@ class ResqCustomerHandler implements CustomerHandlerInterface if (empty($row)) throw new NotFoundHttpException('The item does not exist'); + // get customer tags + $params['customer_tags'] = $em->getRepository(CustomerTag::class)->findAll(); + // get dropdown parameters $this->fillDropdownParameters($params); @@ -603,13 +610,26 @@ class ResqCustomerHandler implements CustomerHandlerInterface ->setPromoEmail($req->request->get('flag_promo_email', false)) ->setDpaConsent($is_dpa_checked) ->setResearchSms($req->request->get('flag_research_sms', false)) - ->setResearchEmail($req->request->get('flag_research_email', false)); + ->setResearchEmail($req->request->get('flag_research_email', false)) + ->clearCustomerTags(); // phone numbers $obj->setPhoneMobile($req->request->get('phone_mobile')) ->setPhoneLandline($req->request->get('phone_landline')) ->setPhoneOffice($req->request->get('phone_office')) ->setPhoneFax($req->request->get('phone_fax')); + + // set car club flags + $customer_tags = $req->request->get('customer_tags'); + if (!empty($customer_tags)) + { + foreach($customer_tags as $customer_tag_id) + { + $customer_tag = $this->em->getRepository(CustomerTag::class)->find($customer_tag_id); + if (!empty($customer_tag)) + $obj->addCustomerTag($customer_tag); + } + } } protected function fillDropdownParameters(&$params) diff --git a/templates/customer/form.html.twig b/templates/customer/form.html.twig index eeae4bbe..5afa777f 100644 --- a/templates/customer/form.html.twig +++ b/templates/customer/form.html.twig @@ -160,6 +160,19 @@ +
+
+
+ {% for customer_tag in customer_tags %} + + {% endfor %} +
+
+
From bbc06479254f3af4c5185a28481414b71ff877c3 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 6 May 2021 03:45:51 +0000 Subject: [PATCH 04/10] Add tag details. #558 --- src/Controller/CustomerTagController.php | 6 +++-- src/Entity/CustomerTag.php | 33 ++++++++++++++++++++++++ templates/customer-tag/form.html.twig | 10 +++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/Controller/CustomerTagController.php b/src/Controller/CustomerTagController.php index ab4178f5..680b9ae6 100644 --- a/src/Controller/CustomerTagController.php +++ b/src/Controller/CustomerTagController.php @@ -139,7 +139,8 @@ class CustomerTagController extends Controller $obj = new CustomerTag(); $obj->setID($req->request->get('id')) - ->setName($req->request->get('name')); + ->setName($req->request->get('name')) + ->setTagDetails($req->request->get('tag_details')); // validate $errors = $validator->validate($obj); @@ -206,7 +207,8 @@ class CustomerTagController extends Controller throw $this->createNotFoundException('The item does not exist'); $obj->setID($req->request->get('id')) - ->setName($req->request->get('name')); + ->setName($req->request->get('name')) + ->setTagDetails($req->request->get('tag_details')); // validate $errors = $validator->validate($obj); diff --git a/src/Entity/CustomerTag.php b/src/Entity/CustomerTag.php index aa80e2e7..6aa506da 100644 --- a/src/Entity/CustomerTag.php +++ b/src/Entity/CustomerTag.php @@ -33,10 +33,17 @@ class CustomerTag */ protected $customers; + // tag details + /** + * @ORM\Column(type="json") + */ + protected $tag_details; + public function __construct() { $this->date_create = new DateTime(); $this->customers = new ArrayCollection(); + $this->tag_details = []; } public function getID() @@ -83,4 +90,30 @@ class CustomerTag { return $this->customers; } + + public function addTagDetails($id, $value) + { + $this->tag_details[$id] = $value; + return $this; + } + + public function setTagDetails($tag_details) + { + $this->tag_details = $tag_details; + return $this; + } + + public function getTagDetails($id) + { + // return null if we don't have it + if (!isset($this->tag_details[$id])) + return null; + + return $this->tag_details[$id]; + } + + public function getAllTagDetails() + { + return $this->tag_details; + } } diff --git a/templates/customer-tag/form.html.twig b/templates/customer-tag/form.html.twig index ce574a44..778378f6 100644 --- a/templates/customer-tag/form.html.twig +++ b/templates/customer-tag/form.html.twig @@ -54,6 +54,16 @@ +
+
+ + + + JSON format e.g. {type: 'discount', discount_type: 'percent', ...} +
+
From c41c8247449583af686fc47fce0f1bc88150df5f Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 6 May 2021 06:55:34 +0000 Subject: [PATCH 05/10] Add the customer tag to JO form. #558 --- .../CustomerHandler/ResqCustomerHandler.php | 1 + .../JobOrderHandler/ResqJobOrderHandler.php | 4 ++ templates/job-order/form.html.twig | 38 ++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Service/CustomerHandler/ResqCustomerHandler.php b/src/Service/CustomerHandler/ResqCustomerHandler.php index 8c48650d..2ef79b07 100644 --- a/src/Service/CustomerHandler/ResqCustomerHandler.php +++ b/src/Service/CustomerHandler/ResqCustomerHandler.php @@ -548,6 +548,7 @@ class ResqCustomerHandler implements CustomerHandlerInterface 'flag_promo_email' => $customer->isPromoEmail(), 'flag_research_sms' => $customer->isResearchSms(), 'flag_research_email' => $customer->isResearchEmail(), + 'customer_tags' => $customer->getCustomerTags(), ], 'vehicle' => [ 'id' => $vehicle->getID(), diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 6b736bf2..14660083 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -25,6 +25,7 @@ use App\Entity\Rider; use App\Entity\JORejection; use App\Entity\Warranty; use App\Entity\Customer; +use App\Entity\CustomerTag; use App\Ramcar\InvoiceCriteria; use App\Ramcar\ServiceType; @@ -2731,6 +2732,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $fac_hubs[$hub->getID()] = $hub->getName() . ' - ' . $hub->getBranch(); } + // list of customer tags + $params['customer_tags'] = $em->getRepository(CustomerTag::class)->findAll(); + // name values $params['service_types'] = ServiceType::getCollection(); $params['warranty_classes'] = WarrantyClass::getCollection(); diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index ac001767..f093882a 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -201,11 +201,29 @@
{% if is_granted('customer.dpa') %} - + {% endif %}
+
+
+
+ {% for customer_tag in customer_tags %} + + {% endfor %} +
+
+
@@ -1370,6 +1388,18 @@ $(function() { if (vdata.customer.flag_research_email === true) { $("#flag-research-email").prop("checked", true); } + if (vdata.customer.customer_tags.length > 0) { + var checkboxes = document.getElementsByName("customer_tags[]"); + for (var x = 0; checkboxes.length > x; x++) + { + if (vdata.customer.customer_tags.indexOf(checkboxes[x].value) !== -1) { + checkboxes[x].checked = true; + } + else { + checkboxes[x].checked = false; + } + } + } // set hidden customer id $("#cid").val(vdata.customer.id); @@ -1417,6 +1447,12 @@ $(function() { $("#flag-promo-email").prop("checked", false); $("#flag-research-sms").prop("checked", false); $("#flag-research-email").prop("checked", false); + + var checkboxes = document.getElementsByName("customer_tags[]"); + for (var x = 0; checkboxes.length > x; x++) + { + checkboxes[x].checked = false; + } } // datepicker From f1c45af22e2a7bbf80ec538f4a4c4240419edee1 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 6 May 2021 11:09:49 +0000 Subject: [PATCH 06/10] Add computation for customer tags in invoice. #558 --- src/Controller/CustomerTagController.php | 8 +- src/Entity/Customer.php | 5 + src/Entity/CustomerTag.php | 2 +- .../InvoiceGenerator/ResqInvoiceGenerator.php | 166 ++++++++++++++---- templates/customer-tag/form.html.twig | 2 +- 5 files changed, 143 insertions(+), 40 deletions(-) diff --git a/src/Controller/CustomerTagController.php b/src/Controller/CustomerTagController.php index 680b9ae6..219e828d 100644 --- a/src/Controller/CustomerTagController.php +++ b/src/Controller/CustomerTagController.php @@ -138,9 +138,11 @@ class CustomerTagController extends Controller $em = $this->getDoctrine()->getManager(); $obj = new CustomerTag(); + $tag_details = $req->request->get('tag_details'); + $tag_details_json = json_decode($tag_details, true); $obj->setID($req->request->get('id')) ->setName($req->request->get('name')) - ->setTagDetails($req->request->get('tag_details')); + ->setTagDetails($tag_details_json); // validate $errors = $validator->validate($obj); @@ -206,9 +208,11 @@ class CustomerTagController extends Controller if (empty($obj)) throw $this->createNotFoundException('The item does not exist'); + $tag_details = $req->request->get('tag_details'); + $tag_details_json = json_decode($tag_details, true); $obj->setID($req->request->get('id')) ->setName($req->request->get('name')) - ->setTagDetails($req->request->get('tag_details')); + ->setTagDetails($tag_details_json); // validate $errors = $validator->validate($obj); diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index 02f61842..d7c66525 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -638,4 +638,9 @@ class Customer return $str_cust_tags; } + public function getCustomerTagObjects() + { + return $this->customer_tags; + } + } diff --git a/src/Entity/CustomerTag.php b/src/Entity/CustomerTag.php index 6aa506da..43942a76 100644 --- a/src/Entity/CustomerTag.php +++ b/src/Entity/CustomerTag.php @@ -114,6 +114,6 @@ class CustomerTag public function getAllTagDetails() { - return $this->tag_details; + return json_encode($this->tag_details); } } diff --git a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php index 2999d622..2c0b1abf 100644 --- a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php @@ -19,6 +19,7 @@ use App\Entity\InvoiceItem; use App\Entity\User; use App\Entity\Battery; use App\Entity\Promo; +use App\Entity\Customer; use App\Service\InvoiceGeneratorInterface; @@ -66,6 +67,13 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface $stype = $criteria->getServiceType(); $cv = $criteria->getCustomerVehicle(); $has_coolant = $criteria->hasCoolant(); + + $cust_tag_info = []; + if ($stype == ServiceType::BATTERY_REPLACEMENT_NEW) + { + error_log('calling getCustomerTagInfo'); + $cust_tag_info = $this->getCustomerTagInfo($cv); + } // error_log($stype); switch ($stype) { @@ -81,7 +89,7 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface $this->processBatteries($total, $criteria, $invoice); $this->processTradeIns($total, $criteria, $invoice); */ - $this->processDiscount($total, $criteria, $invoice); + $this->processDiscount($total, $criteria, $invoice, $cust_tag_info); break; case ServiceType::BATTERY_REPLACEMENT_WARRANTY: @@ -404,45 +412,95 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface } } - protected function processDiscount(&$total, InvoiceCriteria $criteria, Invoice $invoice) + protected function processDiscount(&$total, InvoiceCriteria $criteria, Invoice $invoice, $cust_tag_info) { - $promos = $criteria->getPromos(); - if (count($promos) < 1) - return; - - // NOTE: only get first promo because only one is applicable anyway - $promo = $promos[0]; - - $rate = $promo->getDiscountRate(); - $apply_to = $promo->getDiscountApply(); - - switch ($apply_to) + if (empty($cust_tag_info)) { - case DiscountApply::SRP: - $discount = round($total['sell_price'] * $rate, 2); - break; - case DiscountApply::OPL: - // $discount = round($total['sell_price'] * 0.6 / 0.7 * $rate, 2); - $discount = round($total['sell_price'] * (1 - 1.5 / 0.7 * $rate), 2); - break; - } + error_log('empty cust tag'); + $promos = $criteria->getPromos(); + if (count($promos) < 1) + return; - // if discount is higher than 0, display in invoice - if ($discount > 0) + // NOTE: only get first promo because only one is applicable anyway + $promo = $promos[0]; + + $rate = $promo->getDiscountRate(); + $apply_to = $promo->getDiscountApply(); + + switch ($apply_to) + { + case DiscountApply::SRP: + $discount = round($total['sell_price'] * $rate, 2); + break; + case DiscountApply::OPL: + // $discount = round($total['sell_price'] * 0.6 / 0.7 * $rate, 2); + $discount = round($total['sell_price'] * (1 - 1.5 / 0.7 * $rate), 2); + break; + } + + // if discount is higher than 0, display in invoice + if ($discount > 0) + { + $item = new InvoiceItem(); + $item->setInvoice($invoice) + ->setTitle('Promo discount') + ->setQuantity(1) + ->setPrice(-1 * $discount); + $invoice->addItem($item); + } + + $total['discount'] = $discount; + $total['total_price'] -= $discount; + + // process + $invoice->setPromo($promo); + } + else { - $item = new InvoiceItem(); - $item->setInvoice($invoice) - ->setTitle('Promo discount') - ->setQuantity(1) - ->setPrice(-1 * $discount); - $invoice->addItem($item); + // since only one promo can only be used, we prioritize the tag promos + // TODO: need to test this for multiple tags + $total_discount_amount = 0; + $total_amount = $total['total_price']; + foreach ($cust_tag_info as $ct_info) + { + // check discount type + $discount_type = ''; + $discount_value = 0; + $discount_amount = 0; + $discounted_total = 0; + if (isset($ct_info['discount_type'])) + $discount_type = $ct_info['discount_type']; + if (isset($ct_info['discount_value'])) + { + $discount_value = $ct_info['discount_value']; + } + + if ($discount_type == 'percent') + { + $discount = round(($discount_value / 100), 2); + $discount_amount = $total_amount * $discount; + $discounted_total = $total_amount - $discount_amount; + } + else + { + // assume fixed amount for this + $discount = $discount_value; + $discounted_total = $total_amount - $discount; + } + + $total_discount_amount += $discounted_total; + + $item = new InvoiceItem(); + $item->setInvoice($invoice) + ->setTitle($ct_info['invoice_display']) + ->setQuantity(1) + ->setPrice(-1 * $total_discount_amount); + $invoice->addItem($item); + } + + $total['discount'] = $total_discount_amount; + $total['total_price'] -= $total_discount_amount; } - - $total['discount'] = $discount; - $total['total_price'] -= $discount; - - // process - $invoice->setPromo($promo); } protected function processJumpstart(&$total, $invoice) @@ -663,6 +721,7 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface $cv = $criteria->getCustomerVehicle(); $has_coolant = $criteria->hasCoolant(); // error_log($stype); + $cust_tag_info = []; switch ($stype) { case ServiceType::JUMPSTART_TROUBLESHOOT: @@ -677,7 +736,7 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface $this->processBatteries($total, $criteria, $invoice); $this->processTradeIns($total, $criteria, $invoice); */ - $this->processDiscount($total, $criteria, $invoice); + $this->processDiscount($total, $criteria, $invoice, $cust_tag_info); break; case ServiceType::BATTERY_REPLACEMENT_WARRANTY: @@ -719,4 +778,39 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface return $invoice; } + + protected function getCustomerTagInfo($cv) + { + $cust_tag_info = []; + // get customer and customer tags using customer vehicle + $customer = $cv->getCustomer(); + $customer_tags = $customer->getCustomerTagObjects(); + if (!empty($customer_tags)) + { + foreach ($customer_tags as $customer_tag) + { + // check tag details + $cust_tag_type = $customer_tag->getTagDetails('type'); + error_log($cust_tag_type); + if (($cust_tag_type != null) && ($cust_tag_type == 'one-time-discount')) + { + // get the discount type and discount amount + $cust_tag_discount_amount = $customer_tag->getTagDetails('discount_amount'); + + $cust_tag_invoice_display = $customer_tag->getTagDetails('invoice_display'); + + error_log($cust_tag_invoice_display); + + $cust_tag_info[] = [ + 'type' => $cust_tag_type, + 'discount_type' => $customer_tag->getTagDetails('discount_type'), + 'discount_amount' => $customer_tag->getTagDetails('discount_amount'), + 'discount_value' => $customer_tag->getTagDetails('discount_value'), + 'invoice_display' => $customer_tag->getTagDetails('invoice_display'), + ]; + } + } + } + return $cust_tag_info; + } } diff --git a/templates/customer-tag/form.html.twig b/templates/customer-tag/form.html.twig index 778378f6..e5e54544 100644 --- a/templates/customer-tag/form.html.twig +++ b/templates/customer-tag/form.html.twig @@ -61,7 +61,7 @@ - JSON format e.g. {type: 'discount', discount_type: 'percent', ...} + JSON format e.g. {"type":"discount", "discount_type":"percent", ...}
From df053166121836e2626b98dc8e5d73108ecdcd70 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 7 May 2021 07:20:08 +0000 Subject: [PATCH 07/10] Add logging when one time discount has been availed. Add removal of promo from customer when one time discount has been availed. #558 --- config/services.yaml | 5 +++ src/Entity/Customer.php | 5 +++ src/Entity/CustomerTag.php | 5 +++ .../InvoiceGenerator/ResqInvoiceGenerator.php | 10 +---- .../JobOrderHandler/ResqJobOrderHandler.php | 44 ++++++++++++++++++- 5 files changed, 60 insertions(+), 9 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index dea32a8b..0a176fd9 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -289,3 +289,8 @@ services: App\Service\WarrantyAPILogger: arguments: $em: "@doctrine.orm.entity_manager" + + # promo logger + App\Service\PromoLogger: + arguments: + $em: "@doctrine.orm.entity_manager" diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index d7c66525..2f593e00 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -643,4 +643,9 @@ class Customer return $this->customer_tags; } + public function removeCustomerTag(CustomerTag $customer_tag) + { + $this->customer_tags->removeElement($customer_tag); + $customer_tag->removeCustomer($this); + } } diff --git a/src/Entity/CustomerTag.php b/src/Entity/CustomerTag.php index 43942a76..28d41fd0 100644 --- a/src/Entity/CustomerTag.php +++ b/src/Entity/CustomerTag.php @@ -91,6 +91,11 @@ class CustomerTag return $this->customers; } + public function removeCustomer(Customer $customer) + { + $this->customers->removeElement($customer); + } + public function addTagDetails($id, $value) { $this->tag_details[$id] = $value; diff --git a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php index 2c0b1abf..f4c752bb 100644 --- a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php @@ -789,18 +789,12 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface { foreach ($customer_tags as $customer_tag) { + // TODO: can we keep the tag ids hardcoded? // check tag details $cust_tag_type = $customer_tag->getTagDetails('type'); - error_log($cust_tag_type); + // TODO: might have to make this statement be more generic? if (($cust_tag_type != null) && ($cust_tag_type == 'one-time-discount')) { - // get the discount type and discount amount - $cust_tag_discount_amount = $customer_tag->getTagDetails('discount_amount'); - - $cust_tag_invoice_display = $customer_tag->getTagDetails('invoice_display'); - - error_log($cust_tag_invoice_display); - $cust_tag_info[] = [ 'type' => $cust_tag_type, 'discount_type' => $customer_tag->getTagDetails('discount_type'), diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 14660083..ca6a747f 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -54,6 +54,7 @@ use App\Service\MapTools; use App\Service\RisingTideGateway; use App\Service\HubSelector; use App\Service\HubDistributor; +use App\Service\PromoLogger; use CrEOF\Spatial\PHP\Types\Geometry\Point; @@ -76,6 +77,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface protected $wh; protected $rt; protected $hub_dist; + protected $promo_logger; protected $template_hash; @@ -83,7 +85,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface InvoiceGeneratorInterface $ic, ValidatorInterface $validator, TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah, string $country_code, WarrantyHandler $wh, RisingTideGateway $rt, - HubDistributor $hub_dist) + HubDistributor $hub_dist, PromoLogger $promo_logger) { $this->em = $em; $this->ic = $ic; @@ -95,6 +97,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $this->wh = $wh; $this->rt = $rt; $this->hub_dist = $hub_dist; + $this->promo_logger = $promo_logger; $this->loadTemplates(); } @@ -295,10 +298,13 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $em = $this->em; $jo = $em->getRepository(JobOrder::class)->find($id); + // flag for new job order for the customer tags + $flag_new_jo = false; if (empty($jo)) { // new job order $jo = new JobOrder(); + $flag_new_jo = true; } // find customer @@ -471,6 +477,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $em->persist($event); $em->flush(); + } } @@ -479,6 +486,41 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface if ($jo != null) { $data['job_order'] = $jo; + + // need to get the customer tags but only if new JO + if ($flag_new_jo) + { + // check service type + if ($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW) + { + $customer = $cust_vehicle->getCustomer(); + $customer_tags = $customer->getCustomerTagObjects(); + if (!empty($customer_tags)) + { + foreach ($customer_tags as $customer_tag) + { + // TODO: not too comfy with this being hardcoded + if ($customer_tag->getID() == 'CAR_CLUB_PROMO') + { + // remove associated entity + $customer->removeCustomerTag($customer_tag); + + // log the availment of promo from customer + $created_by = $jo->getCreatedBy()->getUsername(); + $cust_id = $jo->getCustomer()->getID(); + $cust_fname = $jo->getCustomer()->getFirstName(); + $cust_lname = $jo->getCustomer()->getLastName(); + $jo_id = $jo->getID(); + $invoice_id = $jo->getInvoice()->getID(); + // TODO: check if we store total price of invoice or just the discounted amount + $amount = $jo->getInvoice()->getTotalPrice(); + $this->promo_logger->logPromoInfo($created_by, $cust_id, $cust_fname, $cust_lname, $jo_id, + $invoice_id, $amount); + } + } + } + } + } } return $data; From 03360a2ae9f4a1c80b03692269acda124dd670bb Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 7 May 2021 07:48:22 +0000 Subject: [PATCH 08/10] Add logging when one time discount has been availed for mobile. Add removal of promo from customer when one time discount has been availed for mobile. #558 --- src/Controller/APIController.php | 70 ++++++++++++++++++- .../JobOrderHandler/ResqJobOrderHandler.php | 2 +- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index f7004295..099f45a3 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -44,6 +44,7 @@ use App\Service\HubSelector; use App\Service\HubDistributor; use App\Service\HubFilterLogger; use App\Service\WarrantyAPILogger; +use App\Service\PromoLogger; use App\Entity\MobileSession; use App\Entity\Customer; @@ -852,7 +853,8 @@ class APIController extends Controller implements LoggedController public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo, MapTools $map_tools, InventoryManager $im, MQTTClient $mclient, RiderAssignmentHandlerInterface $rah, HubSelector $hub_select, - HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger) + HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger, + PromoLogger $promo_logger) { // check required parameters and api key $required_params = [ @@ -1160,6 +1162,37 @@ class APIController extends Controller implements LoggedController 'invoice' => $invoice_data ]; + // check service type + if ($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW) + { + $customer = $cv->getCustomer(); + $customer_tags = $customer->getCustomerTagObjects(); + if (!empty($customer_tags)) + { + foreach ($customer_tags as $customer_tag) + { + // TODO: not too comfy with this being hardcoded + if ($customer_tag->getID() == 'CAR_CLUB_PROMO') + { + // remove associated entity + $customer->removeCustomerTag($customer_tag); + + // log the availment of promo from customer + $created_by = $req->query->get('api_key');; + $cust_id = $jo->getCustomer()->getID(); + $cust_fname = $jo->getCustomer()->getFirstName(); + $cust_lname = $jo->getCustomer()->getLastName(); + $jo_id = $jo->getID(); + $invoice_id = $jo->getInvoice()->getID(); + // TODO: check if we store total price of invoice or just the discounted amount + $amount = $jo->getInvoice()->getTotalPrice(); + $this->promo_logger->logPromoInfo($created_by, $cust_id, $cust_fname, $cust_lname, $jo_id, + $invoice_id, $amount); + } + } + } + } + // set data $res->setData($data); @@ -2371,7 +2404,8 @@ class APIController extends Controller implements LoggedController public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo, MapTools $map_tools, InventoryManager $im, MQTTClient $mclient, RiderAssignmentHandlerInterface $rah, HubSelector $hub_select, - HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger) + HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger, + PromoLogger $promo_logger) { // check required parameters and api key $required_params = [ @@ -2740,6 +2774,38 @@ class APIController extends Controller implements LoggedController 'invoice' => $invoice_data ]; + // need to check for customer tag/promo + // check service type + if ($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW) + { + $customer = $cv->getCustomer(); + $customer_tags = $customer->getCustomerTagObjects(); + if (!empty($customer_tags)) + { + foreach ($customer_tags as $customer_tag) + { + // TODO: not too comfy with this being hardcoded + if ($customer_tag->getID() == 'CAR_CLUB_PROMO') + { + // remove associated entity + $customer->removeCustomerTag($customer_tag); + + // log the availment of promo from customer + $created_by = $req->query->get('api_key');; + $cust_id = $jo->getCustomer()->getID(); + $cust_fname = $jo->getCustomer()->getFirstName(); + $cust_lname = $jo->getCustomer()->getLastName(); + $jo_id = $jo->getID(); + $invoice_id = $jo->getInvoice()->getID(); + // TODO: check if we store total price of invoice or just the discounted amount + $amount = $jo->getInvoice()->getTotalPrice(); + $promo_logger->logPromoInfo($created_by, $cust_id, $cust_fname, $cust_lname, $jo_id, + $invoice_id, $amount); + } + } + } + } + // set data $res->setData($data); diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index ca6a747f..e0bf09a5 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -304,7 +304,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface { // new job order $jo = new JobOrder(); - $flag_new_jo = true; + $flag_new_jo = true; } // find customer From d99bfedb019419506b938a1a433facc4ee9b2b9e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 10 May 2021 03:36:54 +0000 Subject: [PATCH 09/10] Add promo logger service. #558 --- src/Service/PromoLogger.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/Service/PromoLogger.php diff --git a/src/Service/PromoLogger.php b/src/Service/PromoLogger.php new file mode 100644 index 00000000..ac4eb081 --- /dev/null +++ b/src/Service/PromoLogger.php @@ -0,0 +1,34 @@ +em = $em; + } + + public function logPromoInfo($created_by, $cust_id, $cust_fname, $cust_lname, $jo_id, + $invoice_id, $amount) + { + $log_entry = new PromoLog(); + + $log_entry->setCreatedBy($created_by) + ->setCustId($cust_id) + ->setCustFirstName($cust_fname) + ->setCustLastName($cust_lname) + ->setJoId($jo_id) + ->setInvoiceId($invoice_id) + ->setAmount($amount); + + $this->em->persist($log_entry); + $this->em->flush(); + } +} From 02bf16e78735cfb17aafda141bcd3042ee60b002 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 10 May 2021 03:52:00 +0000 Subject: [PATCH 10/10] Add checking if invoice has items before getting customer tags. #558 --- src/Service/InvoiceGenerator/ResqInvoiceGenerator.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php index f4c752bb..aa0340b1 100644 --- a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php @@ -71,8 +71,10 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface $cust_tag_info = []; if ($stype == ServiceType::BATTERY_REPLACEMENT_NEW) { - error_log('calling getCustomerTagInfo'); - $cust_tag_info = $this->getCustomerTagInfo($cv); + // check if criteria has entries + $entries = $criteria->getEntries(); + if (!empty($entries)) + $cust_tag_info = $this->getCustomerTagInfo($cv); } // error_log($stype); switch ($stype)