Initial commit for customer crud, add asserts/get/setters to entities

This commit is contained in:
Ramon Gutierrez 2018-01-12 08:38:12 +08:00
parent e8d978dae4
commit be949249d9
11 changed files with 1123 additions and 198 deletions

View file

@ -114,4 +114,17 @@ access_keys:
- id: vmfg.update
label: Update
- id: vmfg.delete
label: Delete
- id: customer
label: Customer Access
acls:
- id: customer.menu
label: Menu
- id: customer.list
label: List
- id: customer.add
label: Add
- id: customer.update
label: Update
- id: customer.delete
label: Delete

View file

@ -43,4 +43,8 @@ main_menu:
- id: vmfg_list
acl: vmfg.list
label: Vehicle Manufacturers
parent: database
- id: customer_list
acl: customer.list
label: Customers
parent: database

View file

@ -235,36 +235,36 @@ bsize_delete:
# vehicles
vehicle_list:
path: /vehicle
path: /vehicles
controller: App\Controller\VehicleController::index
vehicle_rows:
path: /vehicle/rows
path: /vehicles/rows
controller: App\Controller\VehicleController::rows
methods: [POST]
vehicle_create:
path: /vehicle/create
path: /vehicles/create
controller: App\Controller\VehicleController::create
methods: [GET]
vehicle_create_submit:
path: /vehicle/create
path: /vehicles/create
controller: App\Controller\VehicleController::createSubmit
methods: [POST]
vehicle_update:
path: /vehicle/{id}
path: /vehicles/{id}
controller: App\Controller\VehicleController::update
methods: [GET]
vehicle_update_submit:
path: /vehicle/{id}
path: /vehicles/{id}
controller: App\Controller\VehicleController::updateSubmit
methods: [POST]
vehicle_delete:
path: /vehicle/{id}
path: /vehicles/{id}
controller: App\Controller\VehicleController::destroy
methods: [DELETE]
@ -309,6 +309,42 @@ vmfg_delete:
controller: App\Controller\VehicleManufacturerController::destroy
methods: [DELETE]
# customers
customer_list:
path: /customers
controller: App\Controller\CustomerController::index
customer_rows:
path: /customers/rows
controller: App\Controller\CustomerController::rows
methods: [POST]
customer_create:
path: /customers/create
controller: App\Controller\CustomerController::create
methods: [GET]
customer_create_submit:
path: /customers/create
controller: App\Controller\CustomerController::createSubmit
methods: [POST]
customer_update:
path: /customers/{id}
controller: App\Controller\CustomerController::update
methods: [GET]
customer_update_submit:
path: /customers/{id}
controller: App\Controller\CustomerController::updateSubmit
methods: [POST]
customer_delete:
path: /customers/{id}
controller: App\Controller\CustomerController::destroy
methods: [DELETE]
# test
test_acl:

View file

@ -0,0 +1,269 @@
<?php
namespace App\Controller;
use App\Ramcar\BaseController;
use App\Entity\Customer;
use App\Entity\CustomerVehicle;
use App\Entity\Vehicle;
use App\Entity\VehicleManufacturer;
use Doctrine\ORM\Query;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use App\Menu\Generator as MenuGenerator;
use App\Access\Generator as ACLGenerator;
class CustomerController extends BaseController
{
protected $acl_gen;
public function __construct(MenuGenerator $menu_gen, ACLGenerator $acl_gen)
{
$this->acl_gen = $acl_gen;
parent::__construct($menu_gen);
}
public function index()
{
$this->denyAccessUnlessGranted('customer.list', null, 'No access.');
$params = $this->initParameters('customer_list');
// response
return $this->render('customer/list.html.twig', $params);
}
public function rows(Request $req)
{
$this->denyAccessUnlessGranted('customer.list', null, 'No access.');
// build query
$qb = $this->getDoctrine()
->getRepository(Customer::class)
->createQueryBuilder('q');
// count total records
$total = $qb->select('COUNT(q)')
->getQuery()
->getSingleScalarResult();
// get datatable params
$datatable = $req->request->get('datatable');
// 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');
// check if filter is present
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
$query->where('q.first_name LIKE :filter')
->orWhere('q.last_name LIKE :filter')
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
}
// 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.first_name', '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['first_name'] = $orow->getFirstName();
$row['last_name'] = $orow->getLastName();
// add row metadata
$row['meta'] = [
'update_url' => '',
'delete_url' => ''
];
// add crud urls
if ($this->isGranted('user.update'))
$row['meta']['update_url'] = $this->generateUrl('customer_update', ['id' => $row['id']]);
if ($this->isGranted('user.delete'))
$row['meta']['delete_url'] = $this->generateUrl('customer_delete', ['id' => $row['id']]);
$rows[] = $row;
}
// response
return $this->json([
'meta' => $meta,
'data' => $rows
]);
}
public function create()
{
$this->denyAccessUnlessGranted('customer.add', null, 'No access.');
$params = $this->initParameters('customer_list');
$em = $this->getDoctrine()->getManager();
// get parent associations
$params['vmfgs'] = $em->getRepository(VehicleManufacturer::class)->findAll();
// response
return $this->render('customer/form.html.twig', $params);
}
public function createSubmit(Request $req, ValidatorInterface $validator)
{
$this->denyAccessUnlessGranted('customer.add', null, 'No access.');
// create new row
$em = $this->getDoctrine()->getManager();
$row = new Customer();
// 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->persist($row);
$em->flush();
// return successful response
return $this->json([
'success' => 'Changes have been saved!'
]);
}
}
public function update($id)
{
$this->denyAccessUnlessGranted('customer.update', null, 'No access.');
$params = $this->initParameters('customer_list');
// get row data
$em = $this->getDoctrine()->getManager();
$row = $em->getRepository(Customer::class)->find($id);
// make sure this row exists
if (empty($row))
throw $this->createNotFoundException('The item does not exist');
$params['row'] = $row;
$params['values'] = [];
// response
return $this->render('customer/form.html.twig', $params);
}
public function updateSubmit(Request $req, ValidatorInterface $validator, $id)
{
$this->denyAccessUnlessGranted('customer.update', null, 'No access.');
// get row data
$em = $this->getDoctrine()->getManager();
$row = $em->getRepository(Customer::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!'
]);
}
}
public function destroy($id)
{
$this->denyAccessUnlessGranted('customer.delete', null, 'No access.');
$params = $this->initParameters('customer_list');
// get row data
$em = $this->getDoctrine()->getManager();
$row = $em->getRepository(Customer::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();
}
}

View file

@ -295,11 +295,6 @@ class Battery
public function getCustomerVehicles()
{
// has to return set of strings because symfony is trying to move away from role objects
$str_cust_vehicles = [];
foreach ($this->cust_vehicles as $cust_vehicle)
$str_cust_vehicles[] = $cust_vehicle->getName();
return $str_cust_vehicles;
return $this->cust_vehicles;
}
}

View file

@ -4,6 +4,7 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
@ -22,12 +23,14 @@ class Customer
// first name
/**
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank()
*/
protected $first_name;
// last name
/**
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank()
*/
protected $last_name;
@ -61,4 +64,93 @@ class Customer
$this->sessions = new ArrayCollection();
$this->vehicles = new ArrayCollection();
}
public function getID()
{
return $this->id;
}
public function setFirstName($first_name)
{
$this->first_name = $first_name;
return $this;
}
public function getFirstName()
{
return $this->first_name;
}
public function setLastName($last_name)
{
$this->last_name = $last_name;
return $this;
}
public function getLastName()
{
return $this->last_name;
}
public function addMobileNumber(MobileNumber $number)
{
$this->numbers->add($number);
return $this;
}
public function clearMobileNumbers()
{
$this->numbers->clear();
return $this;
}
public function getMobileNumbers()
{
return $this->numbers;
}
public function addMobileSession(MobileSession $session)
{
$this->sessions->add($session);
return $this;
}
public function clearMobileSessions()
{
$this->sessions->clear();
return $this;
}
public function getMobileSessions()
{
return $this->sessions;
}
public function addVehicle(Vehicle $vehicle)
{
$this->vehicles->add($vehicle);
return $this;
}
public function clearVehicles()
{
$this->vehicles->clear();
return $this;
}
public function getVehicles()
{
return $this->vehicles;
}
public function setConfirmed($flag_confirmed = true)
{
$this->flag_confirmed = $flag_confirmed;
return $this;
}
public function isConfirmed()
{
return $this->flag_confirmed;
}
}

View file

@ -4,6 +4,8 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="customer_vehicle")
@ -28,6 +30,7 @@ class CustomerVehicle
/**
* @ORM\ManyToOne(targetEntity="Customer", inversedBy="vehicles")
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $customer;
@ -35,30 +38,35 @@ class CustomerVehicle
/**
* @ORM\ManyToOne(targetEntity="Vehicle", inversedBy="customers")
* @ORM\JoinColumn(name="vehicle_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $vehicle;
// plate number
/**
* @ORM\Column(type="string", length=10)
* @Assert\NotBlank()
*/
protected $plate_number;
// model year
/**
* @ORM\Column(type="smallint")
* @Assert\NotBlank()
*/
protected $model_year;
// vehicle status (new / second-hand)
/**
* @ORM\Column(type="string", length=15)
* @Assert\NotBlank()
*/
protected $status_condition;
// fuel type - diesel, gas
/**
* @ORM\Column(type="string", length=15)
* @Assert\NotBlank()
*/
protected $fuel_type;
@ -66,12 +74,14 @@ class CustomerVehicle
// TODO: figure out how to check expiration
/**
* @ORM\Column(type="string", length=20)
* @Assert\NotBlank()
*/
protected $warranty_code;
// date that battery warranty expires
/**
* @ORM\Column(type="date")
* @Assert\NotBlank()
*/
protected $warranty_expiration;
@ -79,6 +89,7 @@ class CustomerVehicle
/**
* @ORM\ManyToOne(targetEntity="Battery", inversedBy="cust_vehicles")
* @ORM\JoinColumn(name="battery_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $curr_battery;
@ -93,4 +104,130 @@ class CustomerVehicle
* @ORM\Column(type="boolean")
*/
protected $flag_active;
public function getID()
{
return $this->id;
}
public function setCustomer(Customer $customer)
{
$this->customer = $customer;
return $this;
}
public function getCustomer()
{
return $this->customer;
}
public function setVehicle(Vehicle $vehicle)
{
$this->vehicle = $vehicle;
return $this;
}
public function getVehicle()
{
return $this->vehicle;
}
public function setPlateNumber($plate_number)
{
$this->plate_number = $plate_number;
return $this;
}
public function getPlateNumber()
{
return $this->plate_number;
}
public function setModelYear($model_year)
{
$this->model_year = $model_year;
return $this;
}
public function getModelYear()
{
return $this->model_year;
}
public function setStatusCondition($status_condition)
{
$this->status_condition = $status_condition;
return $this;
}
public function getStatusCondition()
{
return $this->status_condition;
}
public function setFuelType($fuel_type)
{
$this->fuel_type = $fuel_type;
return $this;
}
public function getFuelType()
{
return $this->fuel_type;
}
public function setWarrantyCode($warranty_code)
{
$this->warranty_code = $warranty_code;
return $this;
}
public function getWarrantyCode()
{
return $this->warranty_code;
}
public function setWarrantyExpiration($warranty_expiration)
{
$this->warranty_expiration = $warranty_expiration;
return $this;
}
public function getWarrantyExpiration()
{
return $this->warranty_expiration;
}
public function setCurrentBattery($curr_battery)
{
$this->curr_battery = $curr_battery;
return $this;
}
public function getCurrentBattery()
{
return $this->curr_battery;
}
public function setHasMotoliteBattery($flag_motolite_battery = true)
{
$this->flag_motolite_battery = $flag_motolite_battery;
return $this;
}
public function hasMotoliteBattery()
{
return $this->flag_motolite_battery;
}
public function setActive($active = true)
{
$this->active = $active;
return $this;
}
public function isActive()
{
return $this->active;
}
}

View file

@ -4,6 +4,8 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="mobile_number")
@ -15,6 +17,7 @@ class MobileNumber
/**
* @ORM\Id
* @ORM\Column(type="string", length=12)
* @Assert\NotBlank()
*/
protected $id;
@ -22,6 +25,7 @@ class MobileNumber
/**
* @ORM\ManyToOne(targetEntity="Customer", inversedBy="numbers")
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $customer;
@ -55,4 +59,59 @@ class MobileNumber
$this->confirm_code = null;
$this->flag_confirmed = false;
}
public function setID($id)
{
$this->id = $id;
return $this;
}
public function getID()
{
return $this->id;
}
public function setCustomer(Customer $customer)
{
$this->customer = $customer;
return $this;
}
public function getCustomer()
{
return $this->customer;
}
public function setConfirmCode($confirm_code)
{
$this->confirm_code = $confirm_code;
return $this;
}
public function getConfirmCode()
{
return $this->confirm_code;
}
public function setDateRegistered($date_registered)
{
$this->date_registered = $date_registered;
return $this;
}
public function getDateRegistered()
{
return $this->date_registered;
}
public function setDateConfirmed($date_confirmed)
{
$this->date_confirmed = $date_confirmed;
return $this;
}
public function getDateConfirmed()
{
return $this->date_confirmed;
}
}

View file

@ -32,192 +32,183 @@
</div>
</div>
</div>
<form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ row is defined ? url('battery_update_submit', {'id': row.getId()}) : url('battery_create_submit') }}">
<form id="row-form" class="m-form m-form--label-align-right" method="post" action="{{ row is defined ? url('battery_update_submit', {'id': row.getId()}) : url('battery_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">
Product Information
</h3>
</div>
<div class="form-group m-form__group row">
<label class="col-lg-1 col-form-label" data-field="prod_code">
Product Code:
</label>
<div class="col-lg-3">
<input type="text" name="prod_code" class="form-control m-input" value="{{ row is defined ? row.getProductCode() }}">
<div class="form-control-feedback hide" data-field="prod_code"></div>
<span class="m-form__help">Unique identifier for this product</span>
</div>
<label class="col-lg-1 col-form-label" data-field="sell_price">
Selling Price:
</label>
<div class="col-lg-3">
<input type="text" name="sell_price" class="form-control m-input" value="{{ row is defined ? row.getSellingPrice() }}">
<div class="form-control-feedback hide" data-field="sell_price"></div>
</div>
</div>
<div class="form-group m-form__group row">
<label class="col-lg-1 col-form-label" data-field="manufacturer">
Manufacturer:
</label>
<div class="col-lg-3">
<select class="form-control m-input" id="manufacturer" name="manufacturer">
<option value=""></option>
{% for manufacturer in bmfgs %}
<option value="{{ manufacturer.getID() }}"{{ row is defined and manufacturer.getID() == row.getManufacturer().getID() ? ' selected' }}>{{ manufacturer.getName() }}</option>
{% endfor %}
</select>
<div class="form-control-feedback hide" data-field="manufacturer"></div>
</div>
<label class="col-lg-1 col-form-label" data-field="model">
Model:
</label>
<div class="col-lg-3">
<select class="form-control m-input" id="model" name="model">
<option value=""></option>
{% for model in models %}
<option value="{{ model.getID() }}"{{ row is defined and model.getID() == row.getModel().getID() ? ' selected' }}>{{ model.getName() }}</option>
{% endfor %}
</select>
<div class="form-control-feedback hide" data-field="model"></div>
</div>
<label class="col-lg-1 col-form-label" data-field="size">
Size:
</label>
<div class="col-lg-3">
<select class="form-control m-input" id="size" name="size">
<option value=""></option>
{% for size in sizes %}
<option value="{{ size.getID() }}"{{ row is defined and size.getID() == row.getSize().getID() ? ' selected' }}>{{ size.getName() }}</option>
{% endfor %}
</select>
<div class="form-control-feedback hide" data-field="size"></div>
</div>
</div>
</div>
<div class="m-form__seperator m-form__seperator--dashed"></div>
<div class="m-form__section">
<div class="m-form__heading">
<h3 class="m-form__heading-title">
Warranty
</h3>
</div>
<div class="form-group m-form__group row">
<label class="col-lg-1 col-form-label" data-field="warr_personal">
Personal:
</label>
<div class="col-lg-3">
<input type="number" name="warr_personal" class="form-control m-input" value="{{ row is defined ? row.getWarrantyPersonal() }}">
<div class="form-control-feedback hide" data-field="warr_personal"></div>
<span class="m-form__help">In months</span>
</div>
<label class="col-lg-1 col-form-label" data-field="warr_commercial">
Commercial:
</label>
<div class="col-lg-3">
<input type="number" name="warr_commercial" class="form-control m-input" value="{{ row is defined ? row.getWarrantyCommercial() }}">
<div class="form-control-feedback hide" data-field="warr_commercial"></div>
<span class="m-form__help">In months</span>
</div>
</div>
</div>
<div class="m-form__section">
<div class="m-form__heading">
<h3 class="m-form__heading-title">
Specifications
</h3>
</div>
<div class="form-group m-form__group row">
<label class="col-lg-1 col-form-label" data-field="length">
Length:
</label>
<div class="col-lg-3">
<input type="number" name="length" class="form-control m-input" value="{{ row is defined ? row.getLength() }}">
<div class="form-control-feedback hide" data-field="length"></div>
<span class="m-form__help">In millimeters (mm)</span>
</div>
<label class="col-lg-1 col-form-label" data-field="width">
Width:
</label>
<div class="col-lg-3">
<input type="number" name="width" class="form-control m-input" value="{{ row is defined ? row.getWidth() }}">
<div class="form-control-feedback hide" data-field="width"></div>
<span class="m-form__help">In millimeters (mm)</span>
</div>
<label class="col-lg-1 col-form-label" data-field="height">
Height:
</label>
<div class="col-lg-3">
<input type="number" name="height" class="form-control m-input" value="{{ row is defined ? row.getHeight() }}">
<div class="form-control-feedback hide" data-field="height"></div>
<span class="m-form__help">In millimeters (mm)</span>
</div>
</div>
<div class="form-group m-form__group row">
<label class="col-lg-1 col-form-label" data-field="total_height">
Total Height:
</label>
<div class="col-lg-3">
<input type="number" name="total_height" class="form-control m-input" value="{{ row is defined ? row.getTotalHeight() }}">
<div class="form-control-feedback hide" data-field="total_height"></div>
<span class="m-form__help">In millimeters (mm)</span>
</div>
<label class="col-lg-1 col-form-label" data-field="res_capacity">
Reserve Capacity
</label>
<div class="col-lg-3">
<input type="number" name="res_capacity" class="form-control m-input" value="{{ row is defined ? row.getReserveCapacity() }}">
<div class="form-control-feedback hide" data-field="res_capacity"></div>
<span class="m-form__help">In minutes</span>
</div>
</div>
</div>
<div class="m-form__section m-form__section--last normal-font">
<div class="form-group m-form__group row">
<div class="col-lg-12">
<div class="form-group m-form__group row form-group-inner">
<div class="col-lg-12">
<div class="m-portlet m-portlet--success m-portlet--head-solid-bg">
<div class="m-portlet__head">
<div class="m-portlet__head-caption">
<div class="m-portlet__head-title">
<h3 class="m-portlet__head-text">
Vehicle Compatibility
</h3>
</div>
</div>
</div>
<div class="m-portlet__body">
<div class="form-group m-form__group row form-group-inner">
<div class="col-lg-12">
<div id="data-vehicles"></div>
</div>
</div>
<div class="form-group m-form__group row form-group-inner">
<label class="col-lg-1 col-form-label" data-field="vehicle_list">
Add Vehicle:
</label>
<div class="col-lg-3">
<select name="vehicle_list" class="form-control m-input" id="vmfg">
<option value="">Select a manufacturer</option>
{% for manufacturer in vmfgs %}
<option value="{{ manufacturer.getID() }}">{{ manufacturer.getName() }}</option>
{% endfor %}
</select>
</div>
<div class="col-lg-3">
<select name="vehicle_list" class="form-control m-input" id="vehicle" disabled>
<option value="">Select a manufacturer first</option>
</select>
</div>
<div class="col-lg-3">
<button type="button" class="btn btn-primary" id="btn-add-vehicle" disabled>Add to List</button>
</div>
</div>
</div>
</div>
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#product-info">Product Information</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#vehicle-compatibility">Vehicle Compatibility</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="product-info" role="tabpanel">
<div class="m-form__section m-form__section--first">
<div class="m-form__heading">
<h3 class="m-form__heading-title">
Product Details
</h3>
</div>
<div class="form-group m-form__group row">
<label class="col-lg-1 col-form-label" data-field="prod_code">
Product Code:
</label>
<div class="col-lg-3">
<input type="text" name="prod_code" class="form-control m-input" value="{{ row is defined ? row.getProductCode() }}">
<div class="form-control-feedback hide" data-field="prod_code"></div>
<span class="m-form__help">Unique identifier for this product</span>
</div>
<label class="col-lg-1 col-form-label" data-field="sell_price">
Selling Price:
</label>
<div class="col-lg-3">
<input type="text" name="sell_price" class="form-control m-input" value="{{ row is defined ? row.getSellingPrice() }}">
<div class="form-control-feedback hide" data-field="sell_price"></div>
</div>
</div>
<div class="form-group m-form__group row">
<label class="col-lg-1 col-form-label" data-field="manufacturer">
Manufacturer:
</label>
<div class="col-lg-3">
<select class="form-control m-input" id="manufacturer" name="manufacturer">
<option value=""></option>
{% for manufacturer in bmfgs %}
<option value="{{ manufacturer.getID() }}"{{ row is defined and manufacturer.getID() == row.getManufacturer().getID() ? ' selected' }}>{{ manufacturer.getName() }}</option>
{% endfor %}
</select>
<div class="form-control-feedback hide" data-field="manufacturer"></div>
</div>
<label class="col-lg-1 col-form-label" data-field="model">
Model:
</label>
<div class="col-lg-3">
<select class="form-control m-input" id="model" name="model">
<option value=""></option>
{% for model in models %}
<option value="{{ model.getID() }}"{{ row is defined and model.getID() == row.getModel().getID() ? ' selected' }}>{{ model.getName() }}</option>
{% endfor %}
</select>
<div class="form-control-feedback hide" data-field="model"></div>
</div>
<label class="col-lg-1 col-form-label" data-field="size">
Size:
</label>
<div class="col-lg-3">
<select class="form-control m-input" id="size" name="size">
<option value=""></option>
{% for size in sizes %}
<option value="{{ size.getID() }}"{{ row is defined and size.getID() == row.getSize().getID() ? ' selected' }}>{{ size.getName() }}</option>
{% endfor %}
</select>
<div class="form-control-feedback hide" data-field="size"></div>
</div>
</div>
</div>
<div class="m-form__seperator m-form__seperator--dashed"></div>
<div class="m-form__section">
<div class="m-form__heading">
<h3 class="m-form__heading-title">
Warranty
</h3>
</div>
<div class="form-group m-form__group row">
<label class="col-lg-1 col-form-label" data-field="warr_personal">
Personal:
</label>
<div class="col-lg-3">
<input type="number" name="warr_personal" class="form-control m-input" value="{{ row is defined ? row.getWarrantyPersonal() }}">
<div class="form-control-feedback hide" data-field="warr_personal"></div>
<span class="m-form__help">In months</span>
</div>
<label class="col-lg-1 col-form-label" data-field="warr_commercial">
Commercial:
</label>
<div class="col-lg-3">
<input type="number" name="warr_commercial" class="form-control m-input" value="{{ row is defined ? row.getWarrantyCommercial() }}">
<div class="form-control-feedback hide" data-field="warr_commercial"></div>
<span class="m-form__help">In months</span>
</div>
</div>
</div>
<div class="m-form__section">
<div class="m-form__heading">
<h3 class="m-form__heading-title">
Specifications
</h3>
</div>
<div class="form-group m-form__group row">
<label class="col-lg-1 col-form-label" data-field="length">
Length:
</label>
<div class="col-lg-3">
<input type="number" name="length" class="form-control m-input" value="{{ row is defined ? row.getLength() }}">
<div class="form-control-feedback hide" data-field="length"></div>
<span class="m-form__help">In millimeters (mm)</span>
</div>
<label class="col-lg-1 col-form-label" data-field="width">
Width:
</label>
<div class="col-lg-3">
<input type="number" name="width" class="form-control m-input" value="{{ row is defined ? row.getWidth() }}">
<div class="form-control-feedback hide" data-field="width"></div>
<span class="m-form__help">In millimeters (mm)</span>
</div>
<label class="col-lg-1 col-form-label" data-field="height">
Height:
</label>
<div class="col-lg-3">
<input type="number" name="height" class="form-control m-input" value="{{ row is defined ? row.getHeight() }}">
<div class="form-control-feedback hide" data-field="height"></div>
<span class="m-form__help">In millimeters (mm)</span>
</div>
</div>
<div class="form-group m-form__group row">
<label class="col-lg-1 col-form-label" data-field="total_height">
Total Height:
</label>
<div class="col-lg-3">
<input type="number" name="total_height" class="form-control m-input" value="{{ row is defined ? row.getTotalHeight() }}">
<div class="form-control-feedback hide" data-field="total_height"></div>
<span class="m-form__help">In millimeters (mm)</span>
</div>
<label class="col-lg-1 col-form-label" data-field="res_capacity">
Reserve Capacity
</label>
<div class="col-lg-3">
<input type="number" name="res_capacity" class="form-control m-input" value="{{ row is defined ? row.getReserveCapacity() }}">
<div class="form-control-feedback hide" data-field="res_capacity"></div>
<span class="m-form__help">In minutes</span>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="vehicle-compatibility" role="tabpanel">
<div class="form-group m-form__group row form-group-inner">
<div class="col-lg-12">
<div id="data-vehicles"></div>
</div>
</div>
<div class="form-group m-form__group row form-group-inner">
<label class="col-lg-1 col-form-label" data-field="vehicle_list">
Add Vehicle:
</label>
<div class="col-lg-3">
<select name="vehicle_list" class="form-control m-input" id="vmfg">
<option value="">Select a manufacturer</option>
{% for manufacturer in vmfgs %}
<option value="{{ manufacturer.getID() }}">{{ manufacturer.getName() }}</option>
{% endfor %}
</select>
</div>
<div class="col-lg-3">
<select name="vehicle_list" class="form-control m-input" id="vehicle" disabled>
<option value="">Select a manufacturer first</option>
</select>
</div>
<div class="col-lg-3">
<button type="button" class="btn btn-primary" id="btn-add-vehicle" disabled>Add to List</button>
</div>
</div>
</div>
@ -459,7 +450,6 @@
title: 'Actions',
sortable: false,
overflow: 'visible',
locked: {right: 'xl'},
template: function (row, index, datatable) {
return '<button data-id="' + row.id + '" type="button" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" title="Delete"><i class="la la-trash"></i></button>';
},

View file

@ -0,0 +1,159 @@
{% 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">Customers</h3>
</div>
</div>
</div>
<!-- END: Subheader -->
<div class="m-content">
<!--Begin::Section-->
<div class="row">
<div class="col-xl-8 offset-xl-2">
<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 row is defined %}
Edit Customer
<small>{{ row.getFirstName() ~ ' ' ~ row.getLastName() }}</small>
{% else %}
New Customer
{% endif %}
</h3>
</div>
</div>
</div>
<form id="row-form" class="m-form m-form--label-align-right" method="post" action="{{ row is defined ? url('customer_update_submit', {'id': row.getId()}) : url('customer_create_submit') }}">
<div class="m-portlet__body">
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#customer-info">Customer Info</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#mobile-numbers">Mobile Numbers</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#vehicles">Vehicles</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="customer-info" role="tabpanel">
<div class="form-group m-form__group row">
<label class="col-lg-2 col-form-label" data-field="first_name">
First Name:
</label>
<div class="col-lg-4">
<input type="text" name="first_name" class="form-control m-input" value="{{ row is defined ? row.getFirstName() }}">
<div class="form-control-feedback hide" data-field="first_name"></div>
</div>
<label class="col-lg-2 col-form-label" data-field="last_name">
Last Name:
</label>
<div class="col-lg-4">
<input type="text" name="last_name" class="form-control m-input" value="{{ row is defined ? row.getLastName() }}">
<div class="form-control-feedback hide" data-field="last_name"></div>
</div>
</div>
</div>
<div class="tab-pane" id="mobile-numbers" role="tabpanel">
</div>
<div class="tab-pane" id="vehicles" role="tabpanel">
</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('customer_list') }}" class="btn btn-secondary">Cancel</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('customer_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');
}
});
</script>
{% endblock %}

View file

@ -0,0 +1,171 @@
{% 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">
Customers
</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('customer_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
<span>
<i class="la la-user"></i>
<span>New Customer</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("customer_rows") }}',
method: 'POST'
}
},
saveState: {
cookie: false,
webstorage: false
},
pageSize: 10,
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
layout: {
scroll: true
},
columns: [
{
field: 'id',
title: 'ID',
width: 30
},
{
field: 'first_name',
title: 'First Name'
},
{
field: 'last_name',
title: 'Last Name'
},
{
field: 'flag_confirmed',
title: 'Status',
template: function (row, index, datatable) {
var tag = '';
if (row.flag_confirmed === true) {
tag = '<span class="m-badge m-badge--success m-badge--wide">Confirmed</span>';
} else {
tag = '<span class="m-badge m-badge--danger m-badge--wide">Unconfirmed</span>';
}
return tag;
}
},
{
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.first_name + ' ' + row.last_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.first_name + ' ' + row.last_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();
}).fail(function() {
swal({
title: 'Whoops',
text: 'An error occurred while deleting this item. Please contact support.',
type: 'error'
});
});
}
});
});
});
</script>
{% endblock %}