Merge branch 'master' of gitlab.com:jankstudio/resq into 229-create-test-scripts
This commit is contained in:
commit
4f398876cd
17 changed files with 1819 additions and 73 deletions
|
|
@ -34,4 +34,11 @@ REDIS_CLIENT_SCHEME=tcp
|
||||||
REDIS_CLIENT_HOST=127.0.0.1
|
REDIS_CLIENT_HOST=127.0.0.1
|
||||||
REDIS_CLIENT_PORT=6379
|
REDIS_CLIENT_PORT=6379
|
||||||
REDIS_CLIENT_PASSWORD=foobared
|
REDIS_CLIENT_PASSWORD=foobared
|
||||||
#
|
|
||||||
|
# privacy policy ids
|
||||||
|
POLICY_PROMO=insertpromopolicyidhere
|
||||||
|
POLICY_THIRD_PARTY=insertthirdpartypolicyidhere
|
||||||
|
POLICY_MOBILE=insertmobilepolicyidhere
|
||||||
|
|
||||||
|
# OTP
|
||||||
|
OTP_MODE=settotestorrandom
|
||||||
|
|
|
||||||
|
|
@ -252,6 +252,7 @@ access_keys:
|
||||||
label: Search
|
label: Search
|
||||||
- id: warranty.search
|
- id: warranty.search
|
||||||
label: Customer Battery Search
|
label: Customer Battery Search
|
||||||
|
|
||||||
- id: ticket
|
- id: ticket
|
||||||
label: Ticket Access
|
label: Ticket Access
|
||||||
acls:
|
acls:
|
||||||
|
|
@ -329,3 +330,29 @@ access_keys:
|
||||||
label: View
|
label: View
|
||||||
- id: review.delete
|
- id: review.delete
|
||||||
label: Delete
|
label: Delete
|
||||||
|
|
||||||
|
- id: privacypolicy
|
||||||
|
label: Privacy Policy
|
||||||
|
acls:
|
||||||
|
- id: privacy_policy.menu
|
||||||
|
label: Menu
|
||||||
|
- id: privacy_policy.list
|
||||||
|
label: List
|
||||||
|
- id: privacy_policy.add
|
||||||
|
label: Add
|
||||||
|
- id: privacy_policy.update
|
||||||
|
label: Update
|
||||||
|
- id: privacy_policy.delete
|
||||||
|
label: Delete
|
||||||
|
|
||||||
|
- id: warranty
|
||||||
|
label: Warranty
|
||||||
|
acls:
|
||||||
|
- id: warranty.menu
|
||||||
|
label: Menu
|
||||||
|
- id: warranty.list
|
||||||
|
label: List
|
||||||
|
- id: warranty.add
|
||||||
|
label: Add
|
||||||
|
- id: warranty.update
|
||||||
|
label: Update
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,14 @@ main_menu:
|
||||||
acl: warranty.search
|
acl: warranty.search
|
||||||
label: Customer Battery Search
|
label: Customer Battery Search
|
||||||
parent: support
|
parent: support
|
||||||
|
- id: privacy_policy_list
|
||||||
|
acl: privacy_policy.list
|
||||||
|
label: Privacy Policy
|
||||||
|
parent: support
|
||||||
|
- id: warranty_list
|
||||||
|
acl: warranty.list
|
||||||
|
label: Warranty
|
||||||
|
parent: support
|
||||||
|
|
||||||
- id: service
|
- id: service
|
||||||
acl: service.menu
|
acl: service.menu
|
||||||
|
|
|
||||||
33
config/routes/privacy_policy.yaml
Normal file
33
config/routes/privacy_policy.yaml
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
privacy_policy_list:
|
||||||
|
path: /privacy_policies
|
||||||
|
controller: App\Controller\PrivacyPolicyController::index
|
||||||
|
|
||||||
|
privacy_policy_rows:
|
||||||
|
path: /privacy_policies/rows
|
||||||
|
controller: App\Controller\PrivacyPolicyController::rows
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
privacy_policy_create:
|
||||||
|
path: /privacy_policies/create
|
||||||
|
controller: App\Controller\PrivacyPolicyController::addForm
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
privacy_policy_create_submit:
|
||||||
|
path: /privacy_policies/create
|
||||||
|
controller: App\Controller\PrivacyPolicyController:addSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
privacy_policy_update:
|
||||||
|
path: /privacy_policies/{id}
|
||||||
|
controller: App\Controller\PrivacyPolicyController::updateForm
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
privacy_policy_update_submit:
|
||||||
|
path : /privacy_policies/{id}
|
||||||
|
controller: App\Controller\PrivacyPolicyController:updateSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
privacy_policy_delete:
|
||||||
|
path: /privacy_policies/{id}
|
||||||
|
controller: App\Controller\PrivacyPolicyController:destroy
|
||||||
|
methods: [DELETE]
|
||||||
|
|
@ -1,10 +1,30 @@
|
||||||
# warranty
|
# warranty
|
||||||
|
|
||||||
warranty_search:
|
warranty_list:
|
||||||
path: /warranty_search
|
path: /warranties
|
||||||
controller: App\Controller\WarrantyController::index
|
controller: App\Controller\WarrantyController::index
|
||||||
|
|
||||||
search_warranty:
|
warranty_rows:
|
||||||
path: /warranty_search/warranty
|
path: /warranties/rows
|
||||||
controller: App\Controller\WarrantyController::search
|
controller: App\Controller\WarrantyController::rows
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
warranty_create:
|
||||||
|
path: /warranties/create
|
||||||
|
controller: App\Controller\WarrantyController::addForm
|
||||||
methods: [GET]
|
methods: [GET]
|
||||||
|
|
||||||
|
warranty_create_submit:
|
||||||
|
path: /warranties/create
|
||||||
|
controller: App\Controller\WarrantyController::addSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
warranty_update:
|
||||||
|
path: /warranties/{id}
|
||||||
|
controller: App\Controller\WarrantyController::updateForm
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
warranty_update_submit:
|
||||||
|
path: /warranties/{id}
|
||||||
|
controller: App\Controller\WarrantyController::updateSubmit
|
||||||
|
methods: [POST]
|
||||||
|
|
|
||||||
10
config/routes/warranty_search.yaml
Normal file
10
config/routes/warranty_search.yaml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# warranty search
|
||||||
|
|
||||||
|
warranty_search:
|
||||||
|
path: /warranty_search
|
||||||
|
controller: App\Controller\WarrantySearchController::index
|
||||||
|
|
||||||
|
search_warranty:
|
||||||
|
path: /warranty_search/warranty
|
||||||
|
controller: App\Controller\WarrantySearchController::search
|
||||||
|
methods: [GET]
|
||||||
84
src/Command/SetCustomerPrivacyPolicyCommand.php
Normal file
84
src/Command/SetCustomerPrivacyPolicyCommand.php
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Dotenv\Dotenv;
|
||||||
|
|
||||||
|
use Doctrine\Common\Persistence\ObjectManager;
|
||||||
|
|
||||||
|
use App\Entity\Customer;
|
||||||
|
use App\Entity\PrivacyPolicy;
|
||||||
|
use App\Entity\MobileSession;
|
||||||
|
|
||||||
|
class SetCustomerPrivacyPolicyCommand extends Command
|
||||||
|
{
|
||||||
|
private $em;
|
||||||
|
|
||||||
|
public function __construct(ObjectManager $om)
|
||||||
|
{
|
||||||
|
$this->em = $om;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this->setName('customer:setprivacypolicy')
|
||||||
|
->setDescription('Set customer private policy.')
|
||||||
|
->setHelp('Set customer private policy.');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
// get the policy ids from .env
|
||||||
|
$dotenv = new Dotenv();
|
||||||
|
$dotenv->loadEnv(__DIR__.'/../../.env');
|
||||||
|
|
||||||
|
$policy_promo_id = $_ENV['POLICY_PROMO'];
|
||||||
|
$policy_third_party_id = $_ENV['POLICY_THIRD_PARTY'];
|
||||||
|
$policy_mobile_id = $_ENV['POLICY_MOBILE'];
|
||||||
|
|
||||||
|
// get third party policy
|
||||||
|
$third_party_policy = $this->em->getRepository(PrivacyPolicy::class)->find($policy_third_party_id);
|
||||||
|
|
||||||
|
// get customers on third party
|
||||||
|
$third_party_customers = $this->em->getRepository(Customer::class)->findBy(['priv_third_party' => true]);
|
||||||
|
foreach ($third_party_customers as $cust)
|
||||||
|
{
|
||||||
|
$cust->setPrivacyPolicyThirdParty($third_party_policy);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get promo policy
|
||||||
|
$promo_policy = $this->em->getRepository(PrivacyPolicy::class)->find($policy_promo_id);
|
||||||
|
|
||||||
|
// get customers on promo
|
||||||
|
$promo_customers = $this->em->getRepository(Customer::class)->findBy(['priv_promo' => true]);
|
||||||
|
foreach ($promo_customers as $cust)
|
||||||
|
{
|
||||||
|
$cust->setPrivacyPolicyPromo($promo_policy);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
|
// get mobile policy
|
||||||
|
$mobile_policy = $this->em->getRepository(PrivacyPolicy::class)->find($policy_mobile_id);
|
||||||
|
|
||||||
|
// get mobile sessions
|
||||||
|
$mobile_sessions = $this->em->getRepository(MobileSession::class)->findAll();
|
||||||
|
foreach ($mobile_sessions as $session)
|
||||||
|
{
|
||||||
|
$cust = $session->getCustomer();
|
||||||
|
if (!(is_null($cust)))
|
||||||
|
{
|
||||||
|
$cust->setPrivacyPolicyMobile($mobile_policy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->em->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\Dotenv\Dotenv;
|
||||||
|
|
||||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||||
|
|
||||||
|
|
@ -43,6 +44,7 @@ use App\Entity\Warranty;
|
||||||
use App\Entity\Service;
|
use App\Entity\Service;
|
||||||
use App\Entity\Partner;
|
use App\Entity\Partner;
|
||||||
use App\Entity\Review;
|
use App\Entity\Review;
|
||||||
|
use App\Entity\PrivacyPolicy;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
@ -237,8 +239,14 @@ class APIController extends Controller
|
||||||
// phone number
|
// phone number
|
||||||
$phone_number = $req->request->get('phone_number');
|
$phone_number = $req->request->get('phone_number');
|
||||||
|
|
||||||
// check if the phone number is our test number
|
// get otp_mode from .env
|
||||||
if ($phone_number == '639991112233')
|
$dotenv = new Dotenv();
|
||||||
|
$dotenv->loadEnv(__DIR__.'/../../.env');
|
||||||
|
|
||||||
|
$otp_mode = $_ENV['OTP_MODE'];
|
||||||
|
|
||||||
|
// check if otp_mode is test
|
||||||
|
if ($otp_mode == 'test')
|
||||||
{
|
{
|
||||||
$code = '123456';
|
$code = '123456';
|
||||||
$this->session->setConfirmCode($code)
|
$this->session->setConfirmCode($code)
|
||||||
|
|
@ -253,18 +261,16 @@ class APIController extends Controller
|
||||||
// TODO: validate phone number
|
// TODO: validate phone number
|
||||||
|
|
||||||
// generate code and save
|
// generate code and save
|
||||||
// $code = '123456';
|
|
||||||
$code = $this->generateConfirmCode();
|
$code = $this->generateConfirmCode();
|
||||||
$this->session->setConfirmCode($code)
|
$this->session->setConfirmCode($code)
|
||||||
->setPhoneNumber($phone_number);
|
->setPhoneNumber($phone_number);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
if ($otp_mode != 'test')
|
||||||
|
{
|
||||||
// send sms to number
|
// send sms to number
|
||||||
$this->sendConfirmationCode($rt, $phone_number, $code);
|
$this->sendConfirmationCode($rt, $phone_number, $code);
|
||||||
/*
|
}
|
||||||
$message = "Your Resq confirmation code is $code.";
|
|
||||||
$rt->sendSMS($phone_number, 'MOTOLITE', $message);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// response
|
// response
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
|
|
@ -395,6 +401,17 @@ class APIController extends Controller
|
||||||
// update mobile phone of customer
|
// update mobile phone of customer
|
||||||
$cust->setPhoneMobile(substr($this->session->getPhoneNumber(), 2));
|
$cust->setPhoneMobile(substr($this->session->getPhoneNumber(), 2));
|
||||||
|
|
||||||
|
// get privacy policy for mobile
|
||||||
|
$policy = $em->createQuery('SELECT policy FROM App\Entity\PrivacyPolicy policy WHERE policy.name LIKE :policy_type')
|
||||||
|
->setParameter('policy_type', "%" . "mobile" . "%")
|
||||||
|
->getOneOrNullResult();
|
||||||
|
|
||||||
|
// set policy id
|
||||||
|
if ($policy != null)
|
||||||
|
{
|
||||||
|
$cust->setPrivacyPolicyMobile($policy);
|
||||||
|
}
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
|
|
@ -1807,9 +1824,43 @@ class APIController extends Controller
|
||||||
|
|
||||||
// set privacy settings
|
// set privacy settings
|
||||||
$priv_promo = $req->request->get('priv_promo', false);
|
$priv_promo = $req->request->get('priv_promo', false);
|
||||||
$cust->setPrivacyThirdParty($req->request->get('priv_third_party'))
|
$priv_third_party = $req->request->get('priv_third_party');
|
||||||
|
$cust->setPrivacyThirdParty($priv_third_party)
|
||||||
->setPrivacyPromo($priv_promo);
|
->setPrivacyPromo($priv_promo);
|
||||||
|
|
||||||
|
// get the policy ids from .env
|
||||||
|
$dotenv = new Dotenv();
|
||||||
|
$dotenv->loadEnv(__DIR__.'/../../.env');
|
||||||
|
|
||||||
|
$policy_promo_id = $_ENV['POLICY_PROMO'];
|
||||||
|
$policy_third_party_id = $_ENV['POLICY_THIRD_PARTY'];
|
||||||
|
|
||||||
|
// check if privacy settings are true
|
||||||
|
// if true, set the private policy for the customer
|
||||||
|
if ($priv_promo)
|
||||||
|
{
|
||||||
|
// find the promo policy
|
||||||
|
$policy = $em->getRepository(PrivacyPolicy::class)->find($policy_promo_id);
|
||||||
|
|
||||||
|
// set policy id
|
||||||
|
if ($policy != null)
|
||||||
|
{
|
||||||
|
$cust->setPrivacyPolicyPromo($policy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($priv_third_party)
|
||||||
|
{
|
||||||
|
// find the third party policy
|
||||||
|
$policy = $em->getRepository(PrivacyPolicy::class)->find($policy_third_party_id);
|
||||||
|
|
||||||
|
// set policy id
|
||||||
|
if ($policy != null)
|
||||||
|
{
|
||||||
|
$cust->setPrivacyPolicyThirdParty($policy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
|
|
@ -1859,16 +1910,11 @@ class APIController extends Controller
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
// get first entry
|
// activate all entries
|
||||||
$warranty = current($warranty_results);
|
foreach ($warranty_results as $warranty)
|
||||||
if ($warranty->isActivated())
|
|
||||||
{
|
{
|
||||||
$res->setError(true)
|
|
||||||
->setErrorMessage('Warranty already activated');
|
|
||||||
return $res->getReturnResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
$warranty->setActivated();
|
$warranty->setActivated();
|
||||||
|
}
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
|
@ -2017,19 +2063,17 @@ class APIController extends Controller
|
||||||
|
|
||||||
// get reviews for partner
|
// get reviews for partner
|
||||||
$reviews = $em->getRepository(Review::class)->findBy(['partner' => $partner]);
|
$reviews = $em->getRepository(Review::class)->findBy(['partner' => $partner]);
|
||||||
$rev = [];
|
|
||||||
|
// get average rating for all reviews
|
||||||
if (!empty($reviews))
|
if (!empty($reviews))
|
||||||
{
|
{
|
||||||
|
$rating = 0;
|
||||||
foreach($reviews as $review)
|
foreach($reviews as $review)
|
||||||
{
|
{
|
||||||
$rev[] = [
|
$rating = $rating + $review->getRating();
|
||||||
'id' => $review->getID(),
|
|
||||||
'rating' => $review->getRating(),
|
|
||||||
'message' => $review->getMessage(),
|
|
||||||
'date_create' => $review->getDateCreate()->format("d M Y g:i A"),
|
|
||||||
// 'mobile_session' => $review->getMobileSession()->getID(),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$average_rating = $rating / sizeof($reviews);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data['partner'] = [
|
$data['partner'] = [
|
||||||
|
|
@ -2042,7 +2086,7 @@ class APIController extends Controller
|
||||||
'time_close' => $partner->getTimeClose()->format("g:i A"),
|
'time_close' => $partner->getTimeClose()->format("g:i A"),
|
||||||
'longitude' => $partner->getCoordinates()->getLongitude(),
|
'longitude' => $partner->getCoordinates()->getLongitude(),
|
||||||
'latitude' => $partner->getCoordinates()->getLatitude(),
|
'latitude' => $partner->getCoordinates()->getLatitude(),
|
||||||
'reviews' => $rev,
|
'average_rating' => $average_rating,
|
||||||
];
|
];
|
||||||
|
|
||||||
$res->setData($data);
|
$res->setData($data);
|
||||||
|
|
|
||||||
272
src/Controller/PrivacyPolicyController.php
Normal file
272
src/Controller/PrivacyPolicyController.php
Normal file
|
|
@ -0,0 +1,272 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\PrivacyPolicy;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Query;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
|
||||||
|
use Catalyst\MenuBundle\Annotation\Menu;
|
||||||
|
|
||||||
|
class PrivacyPolicyController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Menu(selected="privacy_policy_list")
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('privacy_policy.list', null, 'No access.');
|
||||||
|
|
||||||
|
return $this->render('privacy-policy/list.html.twig');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rows(Request $req)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('privacy_policy.list', null, 'No access.');
|
||||||
|
|
||||||
|
// build query
|
||||||
|
$qb = $this->getDoctrine()
|
||||||
|
->getRepository(PrivacyPolicy::class)
|
||||||
|
->createQueryBuilder('q');
|
||||||
|
|
||||||
|
// get datatable params
|
||||||
|
$datatable = $req->request->get('datatable');
|
||||||
|
|
||||||
|
// count total records
|
||||||
|
$tquery = $qb->select('COUNT(q)');
|
||||||
|
|
||||||
|
// add fitlers to count query
|
||||||
|
$this->setQueryFilters($datatable, $tquery);
|
||||||
|
|
||||||
|
$total = $tquery->getQuery()
|
||||||
|
->getSingleScalarResult();
|
||||||
|
|
||||||
|
// get current page number
|
||||||
|
$page = $datatable['pagination']['page'] ?? 1;
|
||||||
|
|
||||||
|
$perpage = $datatable['pagination']['perpage'];
|
||||||
|
$offset = ($page - 1) * $perpage;
|
||||||
|
|
||||||
|
// add metadata
|
||||||
|
$meta = [
|
||||||
|
'page' => $page,
|
||||||
|
'perpage' => $perpage,
|
||||||
|
'pages' => ceil($total / $perpage),
|
||||||
|
'total' => $total,
|
||||||
|
'sort' => 'asc',
|
||||||
|
'field' => 'id'
|
||||||
|
];
|
||||||
|
|
||||||
|
// build query
|
||||||
|
$query = $qb->select('q');
|
||||||
|
|
||||||
|
// add filters to query
|
||||||
|
$this->setQueryFilters($datatable, $query);
|
||||||
|
|
||||||
|
// check if sorting is present, otherwise use default
|
||||||
|
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
|
||||||
|
$order = $datatable['sort']['sort'] ?? 'asc';
|
||||||
|
$query->orderBy('q.' . $datatable['sort']['field'], $order);
|
||||||
|
} else {
|
||||||
|
$query->orderBy('q.id', 'asc');
|
||||||
|
}
|
||||||
|
|
||||||
|
// get rows for this page
|
||||||
|
$obj_rows = $query->setFirstResult($offset)
|
||||||
|
->setMaxResults($perpage)
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
// process rows
|
||||||
|
$rows = [];
|
||||||
|
foreach ($obj_rows as $orow) {
|
||||||
|
// add row data
|
||||||
|
$row['id'] = $orow->getID();
|
||||||
|
$row['name'] = $orow->getName();
|
||||||
|
|
||||||
|
// add row metadata
|
||||||
|
$row['meta'] = [
|
||||||
|
'update_url' => '',
|
||||||
|
'delete_url' => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
// add crud urls
|
||||||
|
if ($this->isGranted('privacy_policy.update'))
|
||||||
|
$row['meta']['update_url'] = $this->generateUrl('privacy_policy_update', ['id' => $row['id']]);
|
||||||
|
if ($this->isGranted('privacy_policy.delete'))
|
||||||
|
$row['meta']['delete_url'] = $this->generateUrl('privacy_policy_delete', ['id' => $row['id']]);
|
||||||
|
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->json([
|
||||||
|
'meta' => $meta,
|
||||||
|
'data' => $rows
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="privacy_policy_list")
|
||||||
|
*/
|
||||||
|
public function addForm()
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('privacy_policy.add', null, 'No access.');
|
||||||
|
|
||||||
|
$params = [];
|
||||||
|
$params['obj'] = new PrivacyPolicy();
|
||||||
|
$params['mode'] = 'create';
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('privacy-policy/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSubmit(Request $req, ValidatorInterface $validator)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('privacy_policy.add', null, 'No access.');
|
||||||
|
|
||||||
|
// create new object
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = new PrivacyPolicy();
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$row->setName($req->request->get('name'));
|
||||||
|
$row->setContent($req->request->get('content'));
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($row);
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
} else {
|
||||||
|
// validated! save the entity
|
||||||
|
$em->persist($row);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="privacy_policy_list")
|
||||||
|
*/
|
||||||
|
public function updateForm($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('privacy_policy.update', null, 'No access.');
|
||||||
|
|
||||||
|
$params = [];
|
||||||
|
$params['mode'] = 'update';
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(PrivacyPolicy::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
$params['obj'] = $row;
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('privacy-policy/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateSubmit(Request $req, ValidatorInterface $validator, $id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('privacy_policy.update', null, 'No access.');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(PrivacyPolicy::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$row->setName($req->request->get('name'));
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($row);
|
||||||
|
|
||||||
|
// initialize error list
|
||||||
|
$error_array = [];
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
} else {
|
||||||
|
// validated! save the entity
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="privacy_policy_list")
|
||||||
|
*/
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('privacy_policy.delete', null, 'No access.');
|
||||||
|
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$row = $em->getRepository(PrivacyPolicy::class)->find($id);
|
||||||
|
|
||||||
|
if (empty($row))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
// delete this row
|
||||||
|
$em->remove($row);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// response
|
||||||
|
$response = new Response();
|
||||||
|
$response->setStatusCode(Response::HTTP_OK);
|
||||||
|
$response->send();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setQueryFilters($datatable, &$query)
|
||||||
|
{
|
||||||
|
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||||
|
$query->where('q.name LIKE :filter')
|
||||||
|
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,12 @@
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Entity\Warranty;
|
use App\Entity\Warranty;
|
||||||
|
use App\Entity\SAPBattery;
|
||||||
|
use App\Entity\BatteryModel;
|
||||||
|
use App\Entity\BatterySize;
|
||||||
|
|
||||||
|
use App\Ramcar\WarrantyClass;
|
||||||
|
use App\Ramcar\WarrantyStatus;
|
||||||
|
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
@ -10,64 +16,359 @@ use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
use Catalyst\MenuBundle\Annotation\Menu;
|
use Catalyst\MenuBundle\Annotation\Menu;
|
||||||
|
|
||||||
class WarrantyController extends Controller
|
class WarrantyController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @Menu(selected="warranty_search")
|
* @Menu(selected="warranty_list")
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$this->denyaccessUnlessGranted('warranty.search', null, 'No access.');
|
$this->denyAccessUnlessGranted('warranty.list', null, 'No access.');
|
||||||
$params["mode"] = "form";
|
|
||||||
|
return $this->render('warranty/list.html.twig');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rows(Request $req)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('warranty.list', null, 'No access.');
|
||||||
|
|
||||||
|
// get query builder
|
||||||
|
$qb = $this->getDoctrine()
|
||||||
|
->getRepository(Warranty::class)
|
||||||
|
->createQueryBuilder('q');
|
||||||
|
|
||||||
|
// get datatable params
|
||||||
|
$datatable = $req->request->get('datatable');
|
||||||
|
|
||||||
|
// count total records
|
||||||
|
$tquery = $qb->select('COUNT(q)');
|
||||||
|
|
||||||
|
// add filters to count query
|
||||||
|
$this->setQueryFilters($datatable, $tquery);
|
||||||
|
|
||||||
|
$total = $tquery->getQuery()
|
||||||
|
->getSingleScalarResult();
|
||||||
|
|
||||||
|
// get current page number
|
||||||
|
$page = $datatable['pagination']['page'] ?? 1;
|
||||||
|
|
||||||
|
$perpage = $datatable['pagination']['perpage'];
|
||||||
|
$offset = ($page - 1) * $perpage;
|
||||||
|
|
||||||
|
// add metadata
|
||||||
|
$meta = [
|
||||||
|
'page' => $page,
|
||||||
|
'perpage' => $perpage,
|
||||||
|
'pages' => ceil($total / $perpage),
|
||||||
|
'total' => $total,
|
||||||
|
'sort' => 'asc',
|
||||||
|
'field' => 'id'
|
||||||
|
];
|
||||||
|
|
||||||
|
// build query
|
||||||
|
$query = $qb->select('q');
|
||||||
|
|
||||||
|
// add filters to query
|
||||||
|
$this->setQueryFilters($datatable, $query);
|
||||||
|
|
||||||
|
// check if sorting is present, otherwise use default
|
||||||
|
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
|
||||||
|
$order = $datatable['sort']['sort'] ?? 'asc';
|
||||||
|
$query->orderBy('q.' . $datatable['sort']['field'], $order);
|
||||||
|
} else {
|
||||||
|
$query->orderBy('q.id', 'asc');
|
||||||
|
}
|
||||||
|
|
||||||
|
// get rows for this page
|
||||||
|
$obj_rows = $query->setFirstResult($offset)
|
||||||
|
->setMaxResults($perpage)
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
// process rows
|
||||||
|
$rows = [];
|
||||||
|
foreach ($obj_rows as $orow) {
|
||||||
|
// add row data
|
||||||
|
$row['id'] = $orow->getID();
|
||||||
|
$row['serial'] = $orow->getSerial();
|
||||||
|
$row['plate_number'] = $orow->getPlateNumber();
|
||||||
|
$row['warranty_class'] = $orow->getWarrantyClass();
|
||||||
|
$row['status'] = $orow->getStatus();
|
||||||
|
$row['is_activated'] = $orow->isActivated();
|
||||||
|
|
||||||
|
// add row metadata
|
||||||
|
$row['meta'] = [
|
||||||
|
'update_url' => '',
|
||||||
|
];
|
||||||
|
|
||||||
|
// add crud urls
|
||||||
|
if ($this->isGranted('warranty.update'))
|
||||||
|
$row['meta']['update_url'] = $this->generateUrl('warranty_update', ['id' => $row['id']]);
|
||||||
|
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
// response
|
// response
|
||||||
return $this->render('warranty-search/form.html.twig', $params);
|
return $this->json([
|
||||||
|
'meta' => $meta,
|
||||||
|
'data' => $rows
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Menu(selected="warranty_search")
|
* @Menu(selected="warranty_list")
|
||||||
*/
|
*/
|
||||||
public function search(Request $req)
|
public function addForm()
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('warranty.search', null, 'No access.');
|
$this->denyAccessUnlessGranted('warranty.add', null, 'No access.');
|
||||||
|
|
||||||
$serial = $req->query->get('battery_serial');
|
$params['obj'] = new Warranty();
|
||||||
$name = $req->query->get('owner_name');
|
$params['mode'] = 'create';
|
||||||
$plate_num = $req->query->get('plate_num');
|
|
||||||
|
|
||||||
// find the warranty
|
// get dropdown parameters
|
||||||
$qb = $this->getDoctrine()
|
$this->fillDropdownParameters($params);
|
||||||
->getRepository(Warranty::class)
|
|
||||||
->createQueryBuilder('w');
|
|
||||||
|
|
||||||
$query = $qb;
|
|
||||||
if (!empty($serial))
|
|
||||||
{
|
|
||||||
$qb->where('w.serial = :serial')
|
|
||||||
->setParameter('serial', $serial);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($plate_num))
|
|
||||||
{
|
|
||||||
$qb->andWhere('w.plate_number = :plate_num')
|
|
||||||
->setParameter('plate_num', $plate_num);
|
|
||||||
}
|
|
||||||
|
|
||||||
$results = $query->getQuery()->getResult();
|
|
||||||
|
|
||||||
$res = [];
|
|
||||||
foreach ($results as $result) {
|
|
||||||
$res[] = $result;
|
|
||||||
}
|
|
||||||
$params['data'] = $res;
|
|
||||||
$params['battery_serial'] = $serial;
|
|
||||||
$params['owner_name'] = $name;
|
|
||||||
$params['plate_num'] = $plate_num;
|
|
||||||
$params['mode'] = "results";
|
|
||||||
|
|
||||||
// response
|
// response
|
||||||
return $this->render('warranty-search/form.html.twig', $params);
|
return $this->render('warranty/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSubmit(Request $req, ValidatorInterface $validator)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('warranty.add', null, 'No access.');
|
||||||
|
|
||||||
|
// create new row
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = new Warranty();
|
||||||
|
|
||||||
|
$date_purchase = DateTime::createFromFormat('d M Y', $req->request->get('date_purchase'));
|
||||||
|
$date_claim = DateTime::createFromFormat('d M Y', $req->request->get('date_claim'));
|
||||||
|
$date_expire = DateTime::createFromFormat('d M Y', $req->request->get('date_expire'));
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$obj->setSerial($req->request->get('serial'))
|
||||||
|
->setWarrantyClass($req->request->get('warranty_class'))
|
||||||
|
->setFirstName($req->request->get('first_name'))
|
||||||
|
->setLastName($req->request->get('last_name'))
|
||||||
|
->setMobileNumber($req->request->get('mobile_number'))
|
||||||
|
->setDatePurchase($date_purchase)
|
||||||
|
->setClaimedFrom($req->request->get('claim_from'))
|
||||||
|
->setStatus($req->request->get('status'));
|
||||||
|
|
||||||
|
if ($date_claim)
|
||||||
|
{
|
||||||
|
$obj->setDateClaim($date_claim);
|
||||||
|
}
|
||||||
|
if ($date_expire)
|
||||||
|
{
|
||||||
|
$obj->setDateExpire($date_expire);
|
||||||
|
}
|
||||||
|
|
||||||
|
// custom validation for battery model
|
||||||
|
$model = $em->getRepository(BatteryModel::class)
|
||||||
|
->find($req->request->get('battery_model'));
|
||||||
|
|
||||||
|
if (empty($model))
|
||||||
|
$error_array['battery_model'] = 'Invalid model selected.';
|
||||||
|
else
|
||||||
|
$obj->setBatteryModel($model);
|
||||||
|
|
||||||
|
// custom validation for battery size
|
||||||
|
$size = $em->getRepository(BatterySize::class)
|
||||||
|
->find($req->request->get('battery_size'));
|
||||||
|
|
||||||
|
if (empty($size))
|
||||||
|
$error_array['battery_size'] = 'Invalid size selected.';
|
||||||
|
else
|
||||||
|
$obj->setBatterySize($size);
|
||||||
|
|
||||||
|
// custom validation for SAP battery
|
||||||
|
$sap = $em->getRepository(SAPBattery::class)
|
||||||
|
->find($req->request->get('sap_battery'));
|
||||||
|
|
||||||
|
if (empty($sap))
|
||||||
|
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
||||||
|
else
|
||||||
|
$obj->setSAPBattery($sap);
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($obj);
|
||||||
|
|
||||||
|
$cleaned_plate_number = Warranty::cleanPlateNumber($req->request->get('plate_number'));
|
||||||
|
if (!$cleaned_plate_number)
|
||||||
|
{
|
||||||
|
$error_array['plate_number'] = 'Invalid plate number specified.';
|
||||||
|
}
|
||||||
|
$obj->setPlateNumber($cleaned_plate_number);
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
} else {
|
||||||
|
// validated! save the entity
|
||||||
|
$em->persist($obj);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="warranty_list")
|
||||||
|
*/
|
||||||
|
public function updateForm($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('warranty.update', null, 'No access.');
|
||||||
|
|
||||||
|
$params['mode'] = 'update';
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = $em->getRepository(Warranty::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($obj))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
$params['obj'] = $obj;
|
||||||
|
|
||||||
|
// get dropdown parameters
|
||||||
|
$this->fillDropdownParameters($params);
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('warranty/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateSubmit(Request $req, ValidatorInterface $validator, $id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('warranty.update', null, 'No access.');
|
||||||
|
|
||||||
|
// get row data
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$obj = $em->getRepository(Warranty::class)->find($id);
|
||||||
|
|
||||||
|
// make sure this row exists
|
||||||
|
if (empty($obj))
|
||||||
|
throw $this->createNotFoundException('The item does not exist');
|
||||||
|
|
||||||
|
$date_purchase = DateTime::createFromFormat('d M Y', $req->request->get('date_purchase'));
|
||||||
|
$date_claim = DateTime::createFromFormat('d M Y', $req->request->get('date_claim'));
|
||||||
|
$date_expire = DateTime::createFromFormat('d M Y', $req->request->get('date_expire'));
|
||||||
|
|
||||||
|
// set and save values
|
||||||
|
$obj->setSerial($req->request->get('serial'))
|
||||||
|
->setWarrantyClass($req->request->get('warranty_class'))
|
||||||
|
->setFirstName($req->request->get('first_name'))
|
||||||
|
->setLastName($req->request->get('last_name'))
|
||||||
|
->setMobileNumber($req->request->get('mobile_number'))
|
||||||
|
->setDatePurchase($date_purchase)
|
||||||
|
->setClaimedFrom($req->request->get('claim_from'))
|
||||||
|
->setStatus($req->request->get('status'));
|
||||||
|
|
||||||
|
if ($date_claim)
|
||||||
|
{
|
||||||
|
$obj->setDateClaim($date_claim);
|
||||||
|
}
|
||||||
|
if ($date_expire)
|
||||||
|
{
|
||||||
|
$obj->setDateExpire($date_expire);
|
||||||
|
}
|
||||||
|
|
||||||
|
// custom validation for battery model
|
||||||
|
$model = $em->getRepository(BatteryModel::class)
|
||||||
|
->find($req->request->get('battery_model'));
|
||||||
|
|
||||||
|
if (empty($model))
|
||||||
|
$error_array['battery_model'] = 'Invalid model selected.';
|
||||||
|
else
|
||||||
|
$obj->setBatteryModel($model);
|
||||||
|
|
||||||
|
// custom validation for battery size
|
||||||
|
$size = $em->getRepository(BatterySize::class)
|
||||||
|
->find($req->request->get('battery_size'));
|
||||||
|
|
||||||
|
if (empty($size))
|
||||||
|
$error_array['battery_size'] = 'Invalid size selected.';
|
||||||
|
else
|
||||||
|
$obj->setBatterySize($size);
|
||||||
|
|
||||||
|
// custom validation for SAP battery
|
||||||
|
$sap = $em->getRepository(SAPBattery::class)
|
||||||
|
->find($req->request->get('sap_battery'));
|
||||||
|
|
||||||
|
if (empty($sap))
|
||||||
|
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
||||||
|
else
|
||||||
|
$obj->setSAPBattery($sap);
|
||||||
|
|
||||||
|
// validate
|
||||||
|
$errors = $validator->validate($obj);
|
||||||
|
|
||||||
|
$cleaned_plate_number = Warranty::cleanPlateNumber($req->request->get('plate_number'));
|
||||||
|
if (!$cleaned_plate_number)
|
||||||
|
{
|
||||||
|
$error_array['plate_number'] = 'Invalid plate number specified.';
|
||||||
|
}
|
||||||
|
$obj->setPlateNumber($cleaned_plate_number);
|
||||||
|
|
||||||
|
// add errors to list
|
||||||
|
foreach ($errors as $error) {
|
||||||
|
$error_array[$error->getPropertyPath()] = $error->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if any errors were found
|
||||||
|
if (!empty($error_array)) {
|
||||||
|
// return validation failure response
|
||||||
|
return $this->json([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => $error_array
|
||||||
|
], 422);
|
||||||
|
} else {
|
||||||
|
// validated! save the entity
|
||||||
|
$em->persist($obj);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
// return successful response
|
||||||
|
return $this->json([
|
||||||
|
'success' => 'Changes have been saved!'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function fillDropdownParameters(&$params)
|
||||||
|
{
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
$params['batt_models'] = $em->getRepository(BatteryModel::class)->findAll();
|
||||||
|
$params['batt_sizes'] = $em->getRepository(BatterySize::class)->findAll();
|
||||||
|
$params['sap_batts'] = $em->getRepository(SAPBattery::class)->findAll();
|
||||||
|
$params['warranty_classes'] = WarrantyClass::getCollection();
|
||||||
|
$params['warranty_statuses'] = WarrantyStatus::getCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if datatable filter is present and append to query
|
||||||
|
protected function setQueryFilters($datatable, &$query) {
|
||||||
|
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||||
|
$query->where('q.serial LIKE :filter')
|
||||||
|
->orWhere('q.plate_number LIKE :filter')
|
||||||
|
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
73
src/Controller/WarrantySearchController.php
Normal file
73
src/Controller/WarrantySearchController.php
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Warranty;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Query;
|
||||||
|
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;
|
||||||
|
|
||||||
|
class WarrantySearchController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Menu(selected="warranty_search")
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$this->denyaccessUnlessGranted('warranty.search', null, 'No access.');
|
||||||
|
$params["mode"] = "form";
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('warranty-search/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="warranty_search")
|
||||||
|
*/
|
||||||
|
public function search(Request $req)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('warranty.search', null, 'No access.');
|
||||||
|
|
||||||
|
$serial = $req->query->get('battery_serial');
|
||||||
|
$name = $req->query->get('owner_name');
|
||||||
|
$plate_num = $req->query->get('plate_num');
|
||||||
|
|
||||||
|
// find the warranty
|
||||||
|
$qb = $this->getDoctrine()
|
||||||
|
->getRepository(Warranty::class)
|
||||||
|
->createQueryBuilder('w');
|
||||||
|
|
||||||
|
$query = $qb;
|
||||||
|
if (!empty($serial))
|
||||||
|
{
|
||||||
|
$qb->where('w.serial = :serial')
|
||||||
|
->setParameter('serial', $serial);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($plate_num))
|
||||||
|
{
|
||||||
|
$qb->andWhere('w.plate_number = :plate_num')
|
||||||
|
->setParameter('plate_num', $plate_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
$results = $query->getQuery()->getResult();
|
||||||
|
|
||||||
|
$res = [];
|
||||||
|
foreach ($results as $result) {
|
||||||
|
$res[] = $result;
|
||||||
|
}
|
||||||
|
$params['data'] = $res;
|
||||||
|
$params['battery_serial'] = $serial;
|
||||||
|
$params['owner_name'] = $name;
|
||||||
|
$params['plate_num'] = $plate_num;
|
||||||
|
$params['mode'] = "results";
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('warranty-search/form.html.twig', $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -147,6 +147,27 @@ class Customer
|
||||||
*/
|
*/
|
||||||
protected $priv_promo;
|
protected $priv_promo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_mobile_app")
|
||||||
|
* @ORM\JoinColumn(name="policy_mobile_app_id", referencedColumnName="id")
|
||||||
|
* @Assert\NotBlank()
|
||||||
|
*/
|
||||||
|
protected $privpol_mobile_app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_third_party")
|
||||||
|
* @ORM\JoinColumn(name="policy_third_party_id", referencedColumnName="id")
|
||||||
|
* @Assert\NotBlank()
|
||||||
|
*/
|
||||||
|
protected $privpol_third_party;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_promo")
|
||||||
|
* @ORM\JoinColumn(name="policy_promo_id", referencedColumnName="id")
|
||||||
|
* @Assert\NotBlank()
|
||||||
|
*/
|
||||||
|
protected $privpol_promo;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->numbers = new ArrayCollection();
|
$this->numbers = new ArrayCollection();
|
||||||
|
|
@ -433,4 +454,39 @@ class Customer
|
||||||
{
|
{
|
||||||
return $this->priv_promo;
|
return $this->priv_promo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setPrivacyPolicyMobile($privpol_mobile_app)
|
||||||
|
{
|
||||||
|
$this->privpol_mobile_app = $privpol_mobile_app;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPrivacyPolicyMobile()
|
||||||
|
{
|
||||||
|
return $this->privpol_mobile_app;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPrivacyPolicyThirdParty($privpol_third_party)
|
||||||
|
{
|
||||||
|
$this->privpol_third_party = $privpol_third_party;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPrivacyPolicyThirdParty()
|
||||||
|
{
|
||||||
|
return $this->privpol_third_party;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPrivacyPolicyPromo($privpol_promo)
|
||||||
|
{
|
||||||
|
$this->privpol_promo = $privpol_promo;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPrivacyPolicyPromo()
|
||||||
|
{
|
||||||
|
return $this->privpol_promo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
116
src/Entity/PrivacyPolicy.php
Normal file
116
src/Entity/PrivacyPolicy.php
Normal file
|
|
@ -0,0 +1,116 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity
|
||||||
|
* @ORM\Table(name="privacy_policy")
|
||||||
|
*/
|
||||||
|
class PrivacyPolicy
|
||||||
|
{
|
||||||
|
// unique id
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
// name
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=80)
|
||||||
|
*/
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
// content
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="text")
|
||||||
|
*/
|
||||||
|
protected $content;
|
||||||
|
|
||||||
|
// link to mobile app customers
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(targetEntity="Customer", mappedBy="privpol_mobile_app")
|
||||||
|
*/
|
||||||
|
protected $cust_mobile_app;
|
||||||
|
|
||||||
|
// link to third party customers
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(targetEntity="Customer", mappedBy="privpol_third_party")
|
||||||
|
*/
|
||||||
|
protected $cust_third_party;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(targetEntity="Customer", mappedBy="privpol_promo")
|
||||||
|
*/
|
||||||
|
protected $cust_promo;
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
$this->content = $content;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContent()
|
||||||
|
{
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCustMobileApp($cust_mobile_app)
|
||||||
|
{
|
||||||
|
$this->cust_mobile_app = $cust_mobile_app;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCustMobileApp()
|
||||||
|
{
|
||||||
|
return $this->cust_mobile_app;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCustThirdParty($cust_third_party)
|
||||||
|
{
|
||||||
|
$this->cust_third_party = $cust_third_party;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCustThirdParty()
|
||||||
|
{
|
||||||
|
return $this->cust_third_party;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCustPromo($cust_promo)
|
||||||
|
{
|
||||||
|
$this->cust_promo = $cust_promo;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCustPromo()
|
||||||
|
{
|
||||||
|
return $this->cust_promo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
142
templates/privacy-policy/form.html.twig
Normal file
142
templates/privacy-policy/form.html.twig
Normal file
|
|
@ -0,0 +1,142 @@
|
||||||
|
{% 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">Privacy Policies</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section -->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-8">
|
||||||
|
<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="la la-key"></i>
|
||||||
|
</span>
|
||||||
|
<h3 class="m-portlet__head-text">
|
||||||
|
{% if mode == 'update' %}
|
||||||
|
Edit Policy
|
||||||
|
<small>{{ obj.getID() }}</small>
|
||||||
|
{% else %}
|
||||||
|
New Policy
|
||||||
|
{% 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('privacy_policy_update_submit', {'id': obj.getID()}) : url('privacy_policy_create_submit') }}">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="form-group m-form__group row no-border">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<label 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-12">
|
||||||
|
<label data-field="content">
|
||||||
|
Content
|
||||||
|
</label>
|
||||||
|
<textarea name="content" class="form-control m-input" data-name="content" rows="4">{{ obj.getContent() }}</textarea>
|
||||||
|
<div class="form-control-feedback hide" data-field="content"></div>
|
||||||
|
</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('privacy_policy_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('privacy_policy_list') }}";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).fail(function(response) {
|
||||||
|
if (response.status == 422 || response.status == 403) {
|
||||||
|
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 %}
|
||||||
142
templates/privacy-policy/list.html.twig
Normal file
142
templates/privacy-policy/list.html.twig
Normal file
|
|
@ -0,0 +1,142 @@
|
||||||
|
{% 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">
|
||||||
|
Privacy Policies
|
||||||
|
</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('privacy_policy_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||||
|
<span>
|
||||||
|
<i class="la la-key"></i>
|
||||||
|
<span>New Policy</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("privacy_policy_rows") }}',
|
||||||
|
method: 'POST'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
saveState: {
|
||||||
|
cookie: false,
|
||||||
|
webstorage: false
|
||||||
|
},
|
||||||
|
pageSize: 10,
|
||||||
|
serverPaging: true,
|
||||||
|
serverFiltering: true,
|
||||||
|
serverSorting: true
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: 'ID'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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.id + '" 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 %}
|
||||||
282
templates/warranty/form.html.twig
Normal file
282
templates/warranty/form.html.twig
Normal file
|
|
@ -0,0 +1,282 @@
|
||||||
|
{% 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">Warranties</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__head">
|
||||||
|
<div class="m-portlet__head-caption">
|
||||||
|
<div class="m-portlet__head-title">
|
||||||
|
<span class="m-portlet__head-icon">
|
||||||
|
<i class="la la-industry"></i>
|
||||||
|
</span>
|
||||||
|
<h3 class="m-portlet__head-text">
|
||||||
|
{% if mode == 'update' %}
|
||||||
|
Edit Warranty
|
||||||
|
{% else %}
|
||||||
|
New Warranty
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ mode == 'update' ? url('warranty_update_submit', {'id': obj.getId()}) : url('warranty_create_submit') }}">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<div class="m-form__section m-form__section--first">
|
||||||
|
<div class="m-form__heading">
|
||||||
|
<h3 class="m-form__heading-title">
|
||||||
|
Warranty Info
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<label data-field="serial">
|
||||||
|
Serial
|
||||||
|
</label>
|
||||||
|
<input type="text" name="serial" class="form-control m-input" value="{{ obj.getSerial }}" data-name="serial">
|
||||||
|
<div class="form-control-feedback hide" data-field="serial"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<label data-field="warranty_class">
|
||||||
|
Warranty Classification
|
||||||
|
</label>
|
||||||
|
<select name="warranty_class" class="form-control m-input">
|
||||||
|
{% for key, warranty_class in warranty_classes %}
|
||||||
|
<option value="{{ key }}"{{ obj.getWarrantyClass == key ? ' selected' }}>{{ warranty_class }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<div class="form-control-feedback hide" data-field="warranty_class"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<label data-field="plate_number">
|
||||||
|
Plate Number
|
||||||
|
</label>
|
||||||
|
<input type="text" name="plate_number" class="form-control m-input" value="{{ obj.getPlateNumber }}" data-name="plate_number">
|
||||||
|
<div class="form-control-feedback hide" data-field="plate_number"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<label data-field="first_name">
|
||||||
|
First Name
|
||||||
|
</label>
|
||||||
|
<input type="text" name="first_name" class="form-control m-input" value="{{ obj.getFirstName }}" data-name="first_name">
|
||||||
|
<div class="form-control-feedback hide" data-field="first_name"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<label data-field="last_name">
|
||||||
|
Last Name
|
||||||
|
</label>
|
||||||
|
<input type="text" name="last_name" class="form-control m-input" value="{{ obj.getLastName }}" data-name="last_name">
|
||||||
|
<div class="form-control-feedback hide" data-field="last_name"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<label data-field="mobile_number">
|
||||||
|
Mobile Phone
|
||||||
|
</label>
|
||||||
|
<div class="input-group m-input-group">
|
||||||
|
<span class="input-group-addon">+63</span>
|
||||||
|
<input type="text" name="mobile_number" class="form-control m-input" value="{{ obj.getMobileNumber|default('') }}" data-name="mobile_number">
|
||||||
|
<div class="form-control-feedback hide" data-field="mobile_number"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<label data-field="sap_battery">
|
||||||
|
SAP Battery
|
||||||
|
</label>
|
||||||
|
<select name="sap_battery" class="form-control m-input">
|
||||||
|
{% for sap_battery in sap_batts %}
|
||||||
|
<option value="{{ sap_battery.getID }}"{{ obj.getSAPBattery.getID|default(0) == sap_battery.getID ? ' selected' }}>{{ sap_battery.getID }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<div class="form-control-feedback hide" data-field="sap_battery"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<label data-field="battery_model">
|
||||||
|
Battery Model
|
||||||
|
</label>
|
||||||
|
<select name="battery_model" class="form-control m-input">
|
||||||
|
{% for model in batt_models %}
|
||||||
|
<option value="{{ model.getID }}"{{ obj.getBatteryModel.getID|default(0) == model.getID ? ' selected' }}>{{ model.getName }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<div class="form-control-feedback hide" data-field="battery_model"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<label data-field="size">
|
||||||
|
Battery Size
|
||||||
|
</label>
|
||||||
|
<select class="form-control m-input" id="battery_size" name="battery_size">
|
||||||
|
<option value=""></option>
|
||||||
|
{% for size in batt_sizes %}
|
||||||
|
<option value="{{ size.getID }}"{{ obj.getBatterySize.getID|default(0) == size.getID ? ' selected' }}>{{ size.getName }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<div class="form-control-feedback hide" data-field="size"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<label data-field="date_purchase">Purchase Date</label>
|
||||||
|
<div class="input-group date dp">
|
||||||
|
<input type="text" name="date_purchase" id="date_purchase" class="form-control m-input" value="{{ obj.getDatePurchase|default("now")|date('d M Y') }}" readonly placeholder="Select a date" >
|
||||||
|
<span class="input-group-addon">
|
||||||
|
<i class="la la-calendar glyphicon-th"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="form-control-feedback hide" data-field="date_purchase"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<label data-field="date_expire">Expiry Date</label>
|
||||||
|
<div class="input-group date dp">
|
||||||
|
<input type="text" name="date_expire" class="form-control m-input" value="{{ obj.getDateExpire is empty? "" : obj.getDateExpire|date('Y-m-d') }}" value="{{ obj.getDateExpire is empty? "" : obj.getDateExpire|date('Y-m-d') }}" readonly placeholder="Select a date">
|
||||||
|
<span class="input-group-addon">
|
||||||
|
<i class="la la-calendar glyphicon-th"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="form-control-feedback hide" data-field="date_expire"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<label data-field="date_claim">Claim Date</label>
|
||||||
|
<div class="input-group date dp">
|
||||||
|
<input type="text" name="date_claim" class="form-control m-input" data-default-value="{{ obj.getDateClaim is empty? "" : obj.getDateClaim|date('Y-m-d') }}" value="{{ obj.getDateClaim is empty? "" : obj.getDateClaim|date('Y-m-d') }}" readonly placeholder="Select a date" >
|
||||||
|
<span class="input-group-addon">
|
||||||
|
<i class="la la-calendar glyphicon-th"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="form-control-feedback hide" data-field="date_claim"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<label data-field="claim_from">
|
||||||
|
Claimed From
|
||||||
|
</label>
|
||||||
|
<input type="text" name="claim_from" class="form-control m-input" value="{{ obj.getClaimedFrom }}" data-name="claim_from">
|
||||||
|
<div class="form-control-feedback hide" data-field="claim_from"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<label data-field="status">
|
||||||
|
Status
|
||||||
|
</label>
|
||||||
|
<select class="form-control m-input" id="status" name="status">
|
||||||
|
{% for key, status in warranty_statuses %}
|
||||||
|
<option value="{{ key }}"{{ obj.getStatus == key ? ' selected' }}>{{ status }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<div class="form-control-feedback hide" data-field="status"></div>
|
||||||
|
</div>
|
||||||
|
</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('warranty_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('warranty_list') }}";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).fail(function(response) {
|
||||||
|
if (response.status == 422 || response.status == 403) {
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
|
// datepicker
|
||||||
|
$(".dp").datepicker({
|
||||||
|
format: "dd M yyyy",
|
||||||
|
todayHighlight: true,
|
||||||
|
autoclose: true,
|
||||||
|
pickerPosition: 'bottom-left',
|
||||||
|
bootcssVer: 3,
|
||||||
|
clearBtn: true
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
129
templates/warranty/list.html.twig
Normal file
129
templates/warranty/list.html.twig
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
{% 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">
|
||||||
|
Warranties
|
||||||
|
</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('warranty_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
||||||
|
<span>
|
||||||
|
<i class="la la-key"></i>
|
||||||
|
<span>New Warranty</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("warranty_rows") }}',
|
||||||
|
method: 'POST'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
saveState: {
|
||||||
|
cookie: false,
|
||||||
|
webstorage: false
|
||||||
|
},
|
||||||
|
pageSize: 10,
|
||||||
|
serverPaging: true,
|
||||||
|
serverFiltering: true,
|
||||||
|
serverSorting: true
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'id',
|
||||||
|
title: 'ID'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'serial',
|
||||||
|
title: 'Serial'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'plate_number',
|
||||||
|
title: 'Plate Number'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'warranty_class',
|
||||||
|
title: 'Warranty Class'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'status',
|
||||||
|
title: 'Status'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'is_activated',
|
||||||
|
title: 'Activation Status'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return actions;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
search: {
|
||||||
|
onEnter: false,
|
||||||
|
input: $('#data-rows-search'),
|
||||||
|
delay: 400
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var table = $("#data-rows").mDatatable(options);
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
Loading…
Reference in a new issue