diff --git a/config/routes/outlet.yaml b/config/routes/outlet.yaml index 72125245..70cc71e6 100644 --- a/config/routes/outlet.yaml +++ b/config/routes/outlet.yaml @@ -11,17 +11,17 @@ outlet_rows: outlet_create: path: /outlets/create - controller: App\Controller\OutletController::create + controller: App\Controller\OutletController::addForm methods: [GET] outlet_create_submit: path: /outlets/create - controller: App\Controller\OutletController::createSubmit + controller: App\Controller\OutletController::addSubmit methods: [POST] outlet_update: path: /outlets/{id} - controller: App\Controller\OutletController::update + controller: App\Controller\OutletController::updateForm methods: [GET] outlet_update_submit: diff --git a/src/Controller/OutletController.php b/src/Controller/OutletController.php index 0e95dd7e..58848159 100644 --- a/src/Controller/OutletController.php +++ b/src/Controller/OutletController.php @@ -11,6 +11,9 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; use Symfony\Component\Validator\Validator\ValidatorInterface; +use CrEOF\Spatial\PHP\Types\Geometry\Point; +use DateTime; + class OutletController extends BaseController { public function index() @@ -125,57 +128,49 @@ class OutletController extends BaseController ]); } - public function create() + public function addForm() { $this->denyAccessUnlessGranted('outlet.add', null, 'No access.'); $params = $this->initParameters('outlet_list'); - - // get roles - $em = $this->getDoctrine()->getManager(); - $params['roles'] = $em->getRepository(Role::class)->findAll(); + $params['obj'] = new Outlet(); + $params['mode'] = 'create'; // response return $this->render('outlet/form.html.twig', $params); } - public function createSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator) + public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator) { $this->denyAccessUnlessGranted('outlet.add', null, 'No access.'); - // create new row + error_log($req->request->get('time_open')); + + // create new object $em = $this->getDoctrine()->getManager(); - $row = new Outlet(); + $obj = new Outlet(); + + // coordinates + $point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat')); + + // times + $format = 'h:i A'; + $time_open = DateTime::createFromFormat($format, $req->request->get('time_open')); + $time_close = DateTime::createFromFormat($format, $req->request->get('time_close')); + + error_log(print_r($time_open, true)); + error_log(print_r(DateTime::getLastErrors(), true)); // set and save values - $row->setOutletname($req->request->get('outletname')) - ->setFirstName($req->request->get('first_name')) - ->setLastName($req->request->get('last_name')) - ->setEmail($req->request->get('email')) - ->setContactNumber($req->request->get('contact_no')) - ->setEnabled($req->request->get('enabled') ? true : false) - ->clearRoles(); - - // set roles - $roles = $req->request->get('roles'); - - if (!empty($roles)) { - foreach ($roles as $role_id) { - // check if role exists - $role = $em->getRepository(Role::class)->find($role_id); - if (!empty($role)) - { - // check access to super outlet roles - if ($role->isSuperAdmin() && !$this->isGranted('outlet.role.sadmin')) - continue; - - $row->addRole($role); - } - } - } + $obj->setName($req->request->get('name')) + ->setAddress($req->request->get('address')) + ->setContactNumbers($req->request->get('contact_nums')) + ->setTimeOpen($time_open) + ->setTimeClose($time_close) + ->setCoordinates($point); // validate - $errors = $validator->validate($row); + $errors = $validator->validate($obj); // initialize error list $error_array = []; @@ -185,24 +180,6 @@ class OutletController extends BaseController $error_array[$error->getPropertyPath()] = $error->getMessage(); } - // get password inputs - $password = $req->request->get('password'); - $confirm_password = $req->request->get('confirm_password'); - - // custom validation for password fields - if (!$password) { - $error_array['password'] = 'This value should not be blank.'; - } else if ($password != $confirm_password) { - $error_array['confirm_password'] = 'Passwords do not match.'; - } else { - // encode password - $enc = $ef->getEncoder($row); - $encoded_password = $enc->encodePassword($req->request->get('password'), $row->getSalt()); - - // set password - $row->setPassword($encoded_password); - } - // check if any errors were found if (!empty($error_array)) { // return validation failure response @@ -212,7 +189,7 @@ class OutletController extends BaseController ], 422); } else { // validated! save the entity - $em->persist($row); + $em->persist($obj); $em->flush(); // return successful response @@ -222,7 +199,7 @@ class OutletController extends BaseController } } - public function update($id) + public function updateForm($id) { $this->denyAccessUnlessGranted('outlet.update', null, 'No access.'); @@ -236,10 +213,6 @@ class OutletController extends BaseController if (empty($row)) throw $this->createNotFoundException('The item does not exist'); - // get roles - $em = $this->getDoctrine()->getManager(); - $params['roles'] = $em->getRepository(Role::class)->findAll(); - $params['row'] = $row; $params['values'] = []; diff --git a/src/Entity/Hub.php b/src/Entity/Hub.php index 22193d2a..a42b2db2 100644 --- a/src/Entity/Hub.php +++ b/src/Entity/Hub.php @@ -6,6 +6,10 @@ use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; use Symfony\Component\Validator\Constraints as Assert; +use CrEOF\Spatial\PHP\Types\Geometry\Point; +use DateTime; + + /** * @ORM\Entity * @ORM\Table(name="hub") @@ -20,6 +24,127 @@ class Hub */ protected $id; + // name of hub + /** + * @ORM\Column(type="string", length=80) + */ + protected $name; + // address + /** + * @ORM\Column(type="string", length=80) + */ + protected $address; + // address coordinates + /** + * @ORM\Column(type="point") + */ + protected $coordinates; + + // contact numbers + // this is displayed in a textarea + /** + * @ORM\Column(type="string", length=200) + */ + protected $contact_numbers; + + // opening time + /** + * @ORM\Column(type="time") + */ + protected $time_open; + + // closing time + /** + * @ORM\Column(type="time") + */ + protected $time_close; + + // riders assigned to this hub + /** + * @ORM\OneToMany(targetEntity="Rider", mappedBy="hub") + */ + protected $riders; + + public function __construct() + { + $this->riders = new ArrayCollection(); + } + + public function getID() + { + return $this->id; + } + + public function setName($name) + { + $this->name = $name; + return $this; + } + + public function getName() + { + return $this->name; + } + + public function setAddress($address) + { + $this->address = $address; + return $this; + } + + public function getAddress() + { + return $this->address; + } + + public function setCoordinates(Point $point) + { + $this->coordinates = $point; + return $this; + } + + public function getCoordinates() + { + return $this->coordinates; + } + + public function setContactNumbers($nums) + { + $this->contact_nums = $nums; + return $this; + } + + public function getContactNumbers() + { + return $this->contact_nums; + } + + public function setTimeOpen(DateTime $time_open) + { + $this->time_open = $time_open; + return $this; + } + + public function getTimeOpen() + { + return $this->time_open; + } + + public function setTimeClose(DateTime $time_close) + { + $this->time_close = $time_close; + return $this; + } + + public function getTimeClose() + { + return $this->time_close; + } + + public function getRiders() + { + return $this->riders; + } } diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index 43204acf..c8cdadb8 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -20,6 +20,25 @@ class JobOrder */ protected $id; + // date job order was created + protected $date_create; + + // date and time of schedule + // defaults to current date / time + protected $schedule; + // is it an advanced order (future date) + protected $flag_advance; + // user that created the job order + protected $created_by; + + // service type + protected $service_type; + + // customer that requested job order + protected $customer; + + // customer vehicle that needs servicing + protected $cus_vehicle; } diff --git a/src/Entity/Outlet.php b/src/Entity/Outlet.php index c21b23a4..8f3efc0e 100644 --- a/src/Entity/Outlet.php +++ b/src/Entity/Outlet.php @@ -6,6 +6,9 @@ use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; use Symfony\Component\Validator\Constraints as Assert; +use CrEOF\Spatial\PHP\Types\Geometry\Point; +use DateTime; + /** * @ORM\Entity * @ORM\Table(name="outlet") @@ -43,7 +46,7 @@ class Outlet /** * @ORM\Column(type="string", length=200) */ - protected $contact_numbers; + protected $contact_nums; // opening time /** @@ -57,4 +60,75 @@ class Outlet */ protected $time_close; + + public function getID() + { + return $this->id; + } + + public function setName($name) + { + $this->name = $name; + return $this; + } + + public function getName() + { + return $this->name; + } + + public function setAddress($address) + { + $this->address = $address; + return $this; + } + + public function getAddress() + { + return $this->address; + } + + public function setCoordinates(Point $point) + { + $this->coordinates = $point; + return $this; + } + + public function getCoordinates() + { + return $this->coordinates; + } + + public function setContactNumbers($nums) + { + $this->contact_nums = $nums; + return $this; + } + + public function getContactNumbers() + { + return $this->contact_nums; + } + + public function setTimeOpen(DateTime $time_open) + { + $this->time_open = $time_open; + return $this; + } + + public function getTimeOpen() + { + return $this->time_open; + } + + public function setTimeClose(DateTime $time_close) + { + $this->time_close = $time_close; + return $this; + } + + public function getTimeClose() + { + return $this->time_close; + } } diff --git a/src/Entity/Rider.php b/src/Entity/Rider.php index bbc0f497..f3b382fd 100644 --- a/src/Entity/Rider.php +++ b/src/Entity/Rider.php @@ -3,7 +3,6 @@ namespace App\Entity; use Doctrine\ORM\Mapping as ORM; -use Doctrine\Common\Collections\ArrayCollection; use Symfony\Component\Validator\Constraints as Assert; /** @@ -20,6 +19,76 @@ class Rider */ protected $id; + // first name + /** + * @ORM\Column(type="string", length=50, nullable=true) + */ + protected $first_name; + // last name + /** + * @ORM\Column(type="string", length=50, nullable=true) + */ + protected $last_name; + // contact number + /** + * @ORM\Column(type="string", length=20, nullable=true) + */ + protected $contact_num; + + /** + * @ORM\ManyToOne(targetEntity="Hub", inversedBy="riders") + * @ORM\JoinColumn(name="hub_id", referencedColumnName="id") + */ + protected $hub; + + public function getID() + { + return $this->id; + } + + public function setFirstName($name) + { + $this->first_name = $name; + return $this; + } + + public function getFirstName() + { + return $this->first_name; + } + + public function setLastName($name) + { + $this->last_name = $name; + return $this; + } + + public function getLastName() + { + return $this->last_name; + } + + public function setContactNumber($num) + { + $this->contact_num = $num; + return $this; + } + + public function getContactNumber() + { + return $this->contact_num; + } + + public function setHub(Hub $hub) + { + $this->hub = $hub; + return $this; + } + + public function getHub() + { + return $this->hub; + } } diff --git a/templates/outlet/form.html.twig b/templates/outlet/form.html.twig index 759f4137..44053343 100644 --- a/templates/outlet/form.html.twig +++ b/templates/outlet/form.html.twig @@ -1,219 +1,273 @@ {% extends 'base.html.twig' %} {% block body %} - -
-
-
-

Users

+ +
+
+
+

Outlet

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

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

+
+
+
+
+ +
+
+
+ + + +
+
+
+
+ + + +
+
+
+
+ + + +
+
+ +
+
+ +
+ + + + +
+ +
+
+ +
+ + + + +
+ +
+
+ +
+
+ + + +
+ + + + +
+
+
+
+ + +
+
+
+
+
+ + Cancel +
+
+
+
+
- -
- -
-
-
-
-
-
- - - -

- {% if row is defined %} - Edit User - {{ row.getUsername() }} - {% else %} - New User - {% endif %} -

-
-
-
-
- -
-
- -
- - - Unique alias for this user -
-
-
- -
- - - {% if row is defined %} - Leave both fields blank for unchanged - {% endif %} -
- -
- - -
-
-
- -
- - -
- -
- - -
-
-
- -
- - -
- -
- - -
-
-
- -
-
- {% for role in roles %} - {% if role.isSuperAdmin and not is_granted('user.role.sadmin') %} - {% else %} - - {% endif %} - {% endfor %} -
- - Check all roles that apply -
-
-
- -
- - - - -
-
-
-
-
-
-
- - Cancel -
-
-
-
-
-
-
-
-
+
{% endblock %} + {% block scripts %} - + - e.preventDefault(); + + +$(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('outlet_list') }}"; + } + }); + }).fail(function(response) { + 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'); + } +}); + {% endblock %} diff --git a/templates/test/map.html.twig b/templates/test/map.html.twig index 32685347..bad71224 100644 --- a/templates/test/map.html.twig +++ b/templates/test/map.html.twig @@ -42,7 +42,7 @@
-
+
@@ -51,7 +51,7 @@ {% endblock %} {% block scripts %} - +