Add one time promo. #570
This commit is contained in:
parent
69fb2d77ee
commit
5b42cf5ce9
16 changed files with 1298 additions and 38 deletions
|
|
@ -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
|
||||
|
|
|
|||
33
config/routes/customer_tag.yaml
Normal file
33
config/routes/customer_tag.yaml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
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]
|
||||
|
|
@ -270,3 +270,8 @@ services:
|
|||
App\Service\WarrantyAPILogger:
|
||||
arguments:
|
||||
$em: "@doctrine.orm.entity_manager"
|
||||
|
||||
# promo logger
|
||||
App\Service\PromoLogger:
|
||||
arguments:
|
||||
$em: "@doctrine.orm.entity_manager"
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ use App\Service\MapTools;
|
|||
use App\Service\InventoryManager;
|
||||
use App\Service\RiderAssignmentHandlerInterface;
|
||||
use App\Service\WarrantyAPILogger;
|
||||
use App\Service\PromoLogger;
|
||||
|
||||
use App\Entity\MobileSession;
|
||||
use App\Entity\Customer;
|
||||
|
|
@ -846,7 +847,7 @@ class APIController extends Controller implements LoggedController
|
|||
|
||||
public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
||||
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
||||
RiderAssignmentHandlerInterface $rah)
|
||||
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger)
|
||||
{
|
||||
// check required parameters and api key
|
||||
$required_params = [
|
||||
|
|
@ -1122,6 +1123,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);
|
||||
|
||||
|
|
@ -2332,7 +2364,7 @@ class APIController extends Controller implements LoggedController
|
|||
|
||||
public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
||||
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
||||
RiderAssignmentHandlerInterface $rah)
|
||||
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger)
|
||||
{
|
||||
// check required parameters and api key
|
||||
$required_params = [
|
||||
|
|
@ -2668,6 +2700,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);
|
||||
|
||||
|
|
|
|||
267
src/Controller/CustomerTagController.php
Normal file
267
src/Controller/CustomerTagController.php
Normal file
|
|
@ -0,0 +1,267 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\CustomerTag;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
use Catalyst\MenuBundle\Annotation\Menu;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class CustomerTagController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Menu(selected="customer_tag_list")
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->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();
|
||||
|
||||
$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($tag_details_json);
|
||||
|
||||
// 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');
|
||||
|
||||
$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($tag_details_json);
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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,36 @@ class Customer
|
|||
{
|
||||
return $this->create_source;
|
||||
}
|
||||
|
||||
public function addCustomerTag(CustomerTag $customer_tag)
|
||||
{
|
||||
$this->customer_tags[$customer_tag->getID()] = $customer_tag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function clearCustomerTags()
|
||||
{
|
||||
$this->customer_tags->clear();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCustomerTags()
|
||||
{
|
||||
$str_cust_tags = [];
|
||||
foreach ($this->customer_tags as $cust_tag)
|
||||
$str_cust_tags[] = $cust_tag->getID();
|
||||
|
||||
return $str_cust_tags;
|
||||
}
|
||||
|
||||
public function getCustomerTagObjects()
|
||||
{
|
||||
return $this->customer_tags;
|
||||
}
|
||||
|
||||
public function removeCustomerTag(CustomerTag $customer_tag)
|
||||
{
|
||||
$this->customer_tags->removeElement($customer_tag);
|
||||
$customer_tag->removeCustomer($this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
125
src/Entity/CustomerTag.php
Normal file
125
src/Entity/CustomerTag.php
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
use DateTime;
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="customer_tag")
|
||||
*/
|
||||
class CustomerTag
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="string", length=80, nullable=false, unique=true)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
// name of tag
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
// customers
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Customer", mappedBy="customer_tags", fetch="EXTRA_LAZY")
|
||||
*/
|
||||
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()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setID($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public function removeCustomer(Customer $customer)
|
||||
{
|
||||
$this->customers->removeElement($customer);
|
||||
}
|
||||
|
||||
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 json_encode($this->tag_details);
|
||||
}
|
||||
}
|
||||
|
||||
169
src/Entity/PromoLog.php
Normal file
169
src/Entity/PromoLog.php
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="promo_log")
|
||||
*/
|
||||
class PromoLog
|
||||
{
|
||||
// unique id
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
// date created
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
*/
|
||||
protected $date_create;
|
||||
|
||||
// user that created the JO
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80)
|
||||
*/
|
||||
protected $created_by;
|
||||
|
||||
// customer id
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
protected $cust_id;
|
||||
|
||||
// customer first name
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80)
|
||||
*/
|
||||
protected $cust_first_name;
|
||||
|
||||
// customer last name
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80)
|
||||
*/
|
||||
protected $cust_last_name;
|
||||
|
||||
// job order id
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
protected $jo_id;
|
||||
|
||||
// invoice id
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
protected $invoice_id;
|
||||
|
||||
// total amount
|
||||
/**
|
||||
* @ORM\Column(type="decimal", precision=9, scale=2)
|
||||
*/
|
||||
protected $amount;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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'] = $this->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)
|
||||
|
|
|
|||
|
|
@ -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,15 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface
|
|||
$stype = $criteria->getServiceType();
|
||||
$cv = $criteria->getCustomerVehicle();
|
||||
$has_coolant = $criteria->hasCoolant();
|
||||
|
||||
$cust_tag_info = [];
|
||||
if ($stype == ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||
{
|
||||
// check if criteria has entries
|
||||
$entries = $criteria->getEntries();
|
||||
if (!empty($entries))
|
||||
$cust_tag_info = $this->getCustomerTagInfo($cv);
|
||||
}
|
||||
// error_log($stype);
|
||||
switch ($stype)
|
||||
{
|
||||
|
|
@ -81,7 +91,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 +414,97 @@ 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 +725,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 +740,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 +782,33 @@ 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)
|
||||
{
|
||||
// TODO: can we keep the tag ids hardcoded?
|
||||
// check tag details
|
||||
$cust_tag_type = $customer_tag->getTagDetails('type');
|
||||
// TODO: might have to make this statement be more generic?
|
||||
if (($cust_tag_type != null) && ($cust_tag_type == 'one-time-discount'))
|
||||
{
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -50,6 +51,7 @@ use App\Service\MQTTClient;
|
|||
use App\Service\APNSClient;
|
||||
use App\Service\MapTools;
|
||||
use App\Service\RisingTideGateway;
|
||||
use App\Service\PromoLogger;
|
||||
|
||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||
|
||||
|
|
@ -71,13 +73,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
protected $country_code;
|
||||
protected $wh;
|
||||
protected $rt;
|
||||
protected $promo_logger;
|
||||
|
||||
protected $template_hash;
|
||||
|
||||
public function __construct(Security $security, EntityManagerInterface $em,
|
||||
InvoiceGeneratorInterface $ic, ValidatorInterface $validator,
|
||||
TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah,
|
||||
string $country_code, WarrantyHandler $wh, RisingTideGateway $rt)
|
||||
string $country_code, WarrantyHandler $wh, RisingTideGateway $rt,
|
||||
PromoLogger $promo_logger)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->ic = $ic;
|
||||
|
|
@ -88,6 +92,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
$this->country_code = $country_code;
|
||||
$this->wh = $wh;
|
||||
$this->rt = $rt;
|
||||
$this->promo_logger = $promo_logger;
|
||||
|
||||
$this->loadTemplates();
|
||||
}
|
||||
|
|
@ -288,10 +293,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
|
||||
|
|
@ -472,6 +480,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;
|
||||
|
|
@ -2685,6 +2728,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();
|
||||
|
|
|
|||
35
src/Service/PromoLogger.php
Normal file
35
src/Service/PromoLogger.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Entity\PromoLog;
|
||||
|
||||
class PromoLogger
|
||||
{
|
||||
protected $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
|
||||
156
templates/customer-tag/form.html.twig
Normal file
156
templates/customer-tag/form.html.twig
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
<!-- BEGIN: Subheader -->
|
||||
<div class="m-subheader">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-auto">
|
||||
<h3 class="m-subheader__title">Customer Tags</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-10">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__head">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<span class="m-portlet__head-icon">
|
||||
<i class="fa fa-building"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text">
|
||||
{% if mode == 'update' %}
|
||||
Edit Customer Tag
|
||||
<small>{{ obj.getName }}</small>
|
||||
{% else %}
|
||||
New Customer Tag
|
||||
{% endif %}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ mode == 'update' ? url('customertag_update_submit', {'id': obj.getId}) : url('customertag_create_submit') }}">
|
||||
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-6">
|
||||
<label for="id" data-field="id">
|
||||
Customer Tag ID
|
||||
</label>
|
||||
<input type="text" name="id" class="form-control m-input" value="{{ obj.getID }}">
|
||||
<div class="form-control-feedback hide" data-field="id"></div>
|
||||
<span class="m-form__help">Unique identifier for this customer tag</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-6">
|
||||
<label for="name" data-field="name">
|
||||
Name
|
||||
</label>
|
||||
<input type="text" name="name" class="form-control m-input" value="{{ obj.getName }}">
|
||||
<div class="form-control-feedback hide" data-field="name"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-6">
|
||||
<label for="tag_details" data-field="tag_details">
|
||||
Tag Details
|
||||
</label>
|
||||
<input type="text" name="tag_details" class="form-control m-input" value="{{ obj.getAllTagDetails|default('') }}">
|
||||
<div class="form-control-feedback hide" data-field="tag_details"></div>
|
||||
<span class="m-form__help">JSON format e.g. {"type":"discount", "discount_type":"percent", ...}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__foot m-portlet__foot--fit">
|
||||
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<button type="submit" class="btn btn-success">Submit</button>
|
||||
<a href="{{ url('customertag_list') }}" class="btn btn-secondary">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
$(function() {
|
||||
$("#row-form").submit(function(e) {
|
||||
var form = $(this);
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: form.prop('action'),
|
||||
data: form.serialize()
|
||||
}).done(function(response) {
|
||||
// remove all error classes
|
||||
removeErrors();
|
||||
swal({
|
||||
title: 'Done!',
|
||||
text: 'Your changes have been saved!',
|
||||
type: 'success',
|
||||
onClose: function() {
|
||||
window.location.href = "{{ url('customertag_list') }}";
|
||||
}
|
||||
});
|
||||
}).fail(function(response) {
|
||||
if (response.status == 422) {
|
||||
var errors = response.responseJSON.errors;
|
||||
var firstfield = false;
|
||||
|
||||
// remove all error classes first
|
||||
removeErrors();
|
||||
|
||||
// display errors contextually
|
||||
$.each(errors, function(field, msg) {
|
||||
var formfield = $("[name='" + field + "']");
|
||||
var label = $("label[data-field='" + field + "']");
|
||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||
|
||||
// add error classes to bad fields
|
||||
formfield.addClass('form-control-danger');
|
||||
label.addClass('has-danger');
|
||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||
|
||||
// check if this field comes first in DOM
|
||||
var domfield = formfield.get(0);
|
||||
|
||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||
firstfield = domfield;
|
||||
}
|
||||
});
|
||||
|
||||
// focus on first bad field
|
||||
firstfield.focus();
|
||||
|
||||
// scroll to above that field to make it visible
|
||||
$('html, body').animate({
|
||||
scrollTop: $(firstfield).offset().top - 200
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// remove all error classes
|
||||
function removeErrors() {
|
||||
$(".form-control-danger").removeClass('form-control-danger');
|
||||
$("[data-field]").removeClass('has-danger');
|
||||
$(".form-control-feedback[data-field]").addClass('hide');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
144
templates/customer-tag/list.html.twig
Normal file
144
templates/customer-tag/list.html.twig
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
<!-- BEGIN: Subheader -->
|
||||
<div class="m-subheader">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-auto">
|
||||
<h3 class="m-subheader__title">
|
||||
Customer Tags
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__body">
|
||||
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-xl-8 order-2 order-xl-1">
|
||||
<div class="form-group m-form__group row align-items-center">
|
||||
<div class="col-md-4">
|
||||
<div class="m-input-icon m-input-icon--left">
|
||||
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
|
||||
<span class="m-input-icon__icon m-input-icon__icon--left">
|
||||
<span><i class="la la-search"></i></span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
||||
<a href="{{ url('customertag_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||
<span>
|
||||
<i class="la la-star-o"></i>
|
||||
<span>New Customer Tag</span>
|
||||
</span>
|
||||
</a>
|
||||
<div class="m-separator m-separator--dashed d-xl-none"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--begin: Datatable -->
|
||||
<div id="data-rows"></div>
|
||||
<!--end: Datatable -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
$(function() {
|
||||
var options = {
|
||||
data: {
|
||||
type: 'remote',
|
||||
source: {
|
||||
read: {
|
||||
url: '{{ url("customertag_rows") }}',
|
||||
method: 'POST',
|
||||
}
|
||||
},
|
||||
saveState: {
|
||||
cookie: false,
|
||||
webstorage: false
|
||||
},
|
||||
pageSize: 10,
|
||||
serverPaging: true,
|
||||
serverFiltering: true,
|
||||
serverSorting: true
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'id',
|
||||
title: 'ID',
|
||||
width: 250
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: 'Name'
|
||||
},
|
||||
{
|
||||
field: 'Actions',
|
||||
width: 110,
|
||||
title: 'Actions',
|
||||
sortable: false,
|
||||
overflow: 'visible',
|
||||
template: function (row, index, datatable) {
|
||||
var actions = '';
|
||||
|
||||
if (row.meta.update_url != '') {
|
||||
actions += '<a href="' + row.meta.update_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.name + '" title="Edit"><i class="la la-edit"></i></a>';
|
||||
}
|
||||
|
||||
if (row.meta.delete_url != '') {
|
||||
actions += '<a href="' + row.meta.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.name + '" title="Delete"><i class="la la-trash"></i></a>';
|
||||
}
|
||||
|
||||
return actions;
|
||||
},
|
||||
}
|
||||
],
|
||||
search: {
|
||||
onEnter: false,
|
||||
input: $('#data-rows-search'),
|
||||
delay: 400
|
||||
}
|
||||
};
|
||||
|
||||
var table = $("#data-rows").mDatatable(options);
|
||||
|
||||
$(document).on('click', '.btn-delete', function(e) {
|
||||
var url = $(this).prop('href');
|
||||
var id = $(this).data('id');
|
||||
var btn = $(this);
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
swal({
|
||||
title: 'Confirmation',
|
||||
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
||||
type: 'warning',
|
||||
showCancelButton: true
|
||||
}).then((result) => {
|
||||
if (result.value) {
|
||||
$.ajax({
|
||||
method: "DELETE",
|
||||
url: url
|
||||
}).done(function(response) {
|
||||
table.row(btn.parents('tr')).remove();
|
||||
table.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
|
|
@ -103,6 +103,19 @@
|
|||
</span>
|
||||
<div class="form-control-feedback hide" data-field="flag_active"></div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<div class="col-lg-12 form-group-inner">
|
||||
<div class="m-checkbox-list">
|
||||
{% for customer_tag in customer_tags %}
|
||||
<label class="m-checkbox">
|
||||
<input type="checkbox" name="customer_tags[]" value="{{ customer_tag.getID() }}"{{ customer_tag.getID() in obj.getCustomerTags() ? ' checked' : '' }}>
|
||||
{{ customer_tag.getName() }}
|
||||
<span></span>
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<div class="col-lg-12 form-group-inner">
|
||||
<label data-field="source">Marketing Promo</label>
|
||||
|
|
|
|||
|
|
@ -201,11 +201,29 @@
|
|||
</div>
|
||||
<div class="col-lg-3">
|
||||
{% if is_granted('customer.dpa') %}
|
||||
<input type="checkbox" name="flag_dpa_consent" id="flag-dpa-consent" value="1"{{ obj.getCustomer ? obj.getCustomer.isDpaConsent ? ' checked' }} i>
|
||||
<input type="checkbox" name="flag_dpa_consent" id="flag-dpa-consent" value="1"{{ obj.getCustomer ? obj.getCustomer.isDpaConsent ? ' checked' }} >
|
||||
<label class="switch-label">With DPA Consent</label>
|
||||
<div class="form-control-feedback hide" data-field="flag_dpa_consent"></div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<div class="col-lg-12 form-group-inner">
|
||||
<div class="m-checkbox-list">
|
||||
{% for customer_tag in customer_tags %}
|
||||
<label class="m-checkbox">
|
||||
{% if obj.getCustomer %}
|
||||
<input type="checkbox" name="customer_tags[]" value="{{ customer_tag.getID() }}"{{ customer_tag.getID() in obj.getCustomer.getCustomerTags() ? ' checked' : '' }} disabled>
|
||||
{{ customer_tag.getName() }}
|
||||
{% else %}
|
||||
<input type="checkbox" name="customer_tags[]" value="{{ customer_tag.getID() }}" disabled>
|
||||
{{ customer_tag.getName() }}
|
||||
{% endif %}
|
||||
<span></span>
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-form__section">
|
||||
|
|
@ -1371,6 +1389,19 @@ $(function() {
|
|||
$("#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 +1448,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
|
||||
|
|
|
|||
Loading…
Reference in a new issue