Resolve "New ticket types" #1601
3 changed files with 480 additions and 325 deletions
|
|
@ -9,8 +9,11 @@ use App\Ramcar\SourceOfAwareness;
|
|||
use App\Entity\Ticket;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\JobOrder;
|
||||
use App\Entity\TicketType as NewTicketType;
|
||||
use App\Entity\SubTicketType;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
|
@ -128,7 +131,7 @@ class TicketController extends Controller
|
|||
/**
|
||||
* @Menu(selected="ticket_list")
|
||||
*/
|
||||
public function addForm(Request $req, $customer_id, $job_order_id)
|
||||
public function addForm(Request $req, EntityManagerInterface $em, $customer_id, $job_order_id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ticket.add', null, 'No access.');
|
||||
|
||||
|
|
@ -140,7 +143,6 @@ class TicketController extends Controller
|
|||
|
||||
// get customer data
|
||||
if ($customer_id) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$customer = $em->getRepository(Customer::class)->find($customer_id);
|
||||
|
||||
// make sure this row exists
|
||||
|
|
@ -176,6 +178,8 @@ class TicketController extends Controller
|
|||
$params['redirect_url'] = $this->generateUrl('ticket_list');
|
||||
$params['soa_types'] = SourceOfAwareness::getCollection();
|
||||
|
||||
$params['sets'] = $this->generateFormSets($em);
|
||||
|
||||
// set redirect url
|
||||
if ($customer)
|
||||
{
|
||||
|
|
@ -236,12 +240,16 @@ class TicketController extends Controller
|
|||
$obj = new Ticket();
|
||||
|
||||
// get ticket type
|
||||
$ticket_type = $req->request->get('ticket_type');
|
||||
$other_ticket_type = '';
|
||||
//$ticket_type = $req->request->get('ticket_type');
|
||||
//$other_ticket_type = '';
|
||||
|
||||
if ($ticket_type == TicketType::OTHER) {
|
||||
$other_ticket_type = $req->request->get('other_ticket_type');
|
||||
}
|
||||
//if ($ticket_type == TicketType::OTHER) {
|
||||
// $other_ticket_type = $req->request->get('other_ticket_type');
|
||||
//}
|
||||
|
||||
// get the "new" ticket type
|
||||
$ttype_id = $req->request->get('new_ticket_type');
|
||||
$sub_ttype_id = $req->request->get('sub_ticket_type');
|
||||
|
||||
// get source of awareness if any
|
||||
$soa_type = $req->request->get('source_of_awareness');
|
||||
|
|
@ -254,8 +262,8 @@ class TicketController extends Controller
|
|||
->setLastName($last_name)
|
||||
->setContactNumber($contact_num)
|
||||
->setStatus($req->request->get('status'))
|
||||
->setTicketType($ticket_type)
|
||||
->setOtherTicketType($other_ticket_type)
|
||||
//->setTicketType($ticket_type)
|
||||
//->setOtherTicketType($other_ticket_type)
|
||||
->setDetails($req->request->get('details'))
|
||||
->setPlateNumber($req->request->get('plate_number'))
|
||||
->setDateCreate(new DateTime())
|
||||
|
|
@ -280,9 +288,21 @@ class TicketController extends Controller
|
|||
$errors = $validator->validate($obj);
|
||||
|
||||
// custom validation for other ticket type
|
||||
if ($ticket_type == TicketType::OTHER && empty($other_ticket_type)) {
|
||||
$error_array['other_ticket_type'] = 'Ticket type not specified.';
|
||||
}
|
||||
//if ($ticket_type == TicketType::OTHER && empty($other_ticket_type)) {
|
||||
// $error_array['other_ticket_type'] = 'Ticket type not specified.';
|
||||
//}
|
||||
// get ticket and sub ticket type objects
|
||||
$ttype = $em->getRepository(NewTicketType::class)->find($ttype_id);
|
||||
if (empty($ttype))
|
||||
$error_array['new_ticket_type'] = 'Ticket type not specified.';
|
||||
|
||||
$sub_ttype = $em->getRepository(SubTicketType::class)->find($sub_ttype_id);
|
||||
if (empty($sub_ttype))
|
||||
$error_array['sub_ticket_type'] = 'Sub ticket type not specified.';
|
||||
|
||||
// set the ticket type and sub ticket type for ticket
|
||||
$obj->setNewTicketType($ttype)
|
||||
->setSubTicketType($sub_ttype);
|
||||
|
||||
// add errors to list
|
||||
foreach ($errors as $error) {
|
||||
|
|
@ -311,22 +331,19 @@ class TicketController extends Controller
|
|||
/**
|
||||
* @Menu(selected="ticket_list")
|
||||
*/
|
||||
public function updateForm(Request $req, $id)
|
||||
public function updateForm(Request $req, $id, EntityManagerInterface $em)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ticket.update', null, 'No access.');
|
||||
|
||||
$params['mode'] = 'update';
|
||||
|
||||
// get row data
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$obj = $em->getRepository(Ticket::class)->find($id);
|
||||
|
||||
// make sure this row exists
|
||||
if (empty($obj))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
// $em = $this->getDoctrine()->getManager();
|
||||
|
||||
$customer = $obj->getCustomer();
|
||||
$job_order = $obj->getJobOrder();
|
||||
|
||||
|
|
@ -339,6 +356,8 @@ class TicketController extends Controller
|
|||
$params['redirect_url'] = $this->generateUrl('ticket_list');
|
||||
$params['soa_types'] = SourceOfAwareness::getCollection();
|
||||
|
||||
$params['sets'] = $this->generateFormSets($em);
|
||||
|
||||
// set redirect url
|
||||
if ($customer)
|
||||
{
|
||||
|
|
@ -428,12 +447,16 @@ class TicketController extends Controller
|
|||
}
|
||||
|
||||
// get ticket type
|
||||
$ticket_type = $req->request->get('ticket_type');
|
||||
$other_ticket_type = '';
|
||||
//$ticket_type = $req->request->get('ticket_type');
|
||||
//$other_ticket_type = '';
|
||||
|
||||
if ($ticket_type == TicketType::OTHER) {
|
||||
$other_ticket_type = $req->request->get('other_ticket_type');
|
||||
}
|
||||
//if ($ticket_type == TicketType::OTHER) {
|
||||
// $other_ticket_type = $req->request->get('other_ticket_type');
|
||||
//}
|
||||
|
||||
// get the "new" ticket type
|
||||
$ttype_id = $req->request->get('new_ticket_type');
|
||||
$sub_ttype_id = $req->request->get('sub_ticket_type');
|
||||
|
||||
// get source of awareness if any
|
||||
$soa_type = $req->request->get('source_of_awareness');
|
||||
|
|
@ -446,8 +469,8 @@ class TicketController extends Controller
|
|||
->setLastName($last_name)
|
||||
->setContactNumber($contact_num)
|
||||
->setStatus($req->request->get('status'))
|
||||
->setTicketType($ticket_type)
|
||||
->setOtherTicketType($other_ticket_type)
|
||||
//->setTicketType($ticket_type)
|
||||
//->setOtherTicketType($other_ticket_type)
|
||||
->setDetails($req->request->get('details'))
|
||||
->setPlateNumber($req->request->get('plate_number'))
|
||||
->setSourceOfAwareness($soa_type)
|
||||
|
|
@ -460,9 +483,21 @@ class TicketController extends Controller
|
|||
$errors = $validator->validate($obj);
|
||||
|
||||
// custom validation for other ticket type
|
||||
if ($ticket_type == TicketType::OTHER && empty($other_ticket_type)) {
|
||||
$error_array['other_ticket_type'] = 'Ticket type not specified.';
|
||||
}
|
||||
//if ($ticket_type == TicketType::OTHER && empty($other_ticket_type)) {
|
||||
// $error_array['other_ticket_type'] = 'Ticket type not specified.';
|
||||
//}
|
||||
// get ticket and sub ticket type objects
|
||||
$ttype = $em->getRepository(NewTicketType::class)->find($ttype_id);
|
||||
if (empty($ttype))
|
||||
$error_array['new_ticket_type'] = 'Ticket type not specified.';
|
||||
|
||||
$sub_ttype = $em->getRepository(SubTicketType::class)->find($sub_ttype_id);
|
||||
if (empty($sub_ttype))
|
||||
$error_array['sub_ticket_type'] = 'Sub ticket type not specified.';
|
||||
|
||||
// set the ticket type and sub ticket type for ticket
|
||||
$obj->setNewTicketType($ttype)
|
||||
->setSubTicketType($sub_ttype);
|
||||
|
||||
// add errors to list
|
||||
foreach ($errors as $error) {
|
||||
|
|
@ -508,6 +543,35 @@ class TicketController extends Controller
|
|||
$response->send();
|
||||
}
|
||||
|
||||
protected function generateFormSets(EntityManagerInterface $em)
|
||||
{
|
||||
// get ticket types
|
||||
$ttypes = $em->getRepository(NewTicketType::class)->findBy([], ['name' => 'asc']);
|
||||
$ttypes_set = [];
|
||||
foreach ($ttypes as $ttype)
|
||||
{
|
||||
$ttypes_set[$ttype->getID()] = $ttype->getName();
|
||||
}
|
||||
|
||||
// get sub ticket types
|
||||
$sub_ttypes = $em->getRepository(SubTicketType::class)->findBy([], ['name' => 'asc']);
|
||||
$sub_ttypes_set = [];
|
||||
foreach ($sub_ttypes as $sub_ttype)
|
||||
{
|
||||
$sub_ttypes_set[] = [
|
||||
'id' => $sub_ttype->getID(),
|
||||
'name' => $sub_ttype->getName(),
|
||||
'ticket_type_id' => $sub_ttype->getTicketType()->getID(),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'new_ticket_types' => $ttypes_set,
|
||||
'sub_ticket_types' => $sub_ttypes_set,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
// check if datatable filter is present and append to query
|
||||
protected function setQueryFilters($datatable, &$query, $qb) {
|
||||
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Ramcar\TicketType;
|
||||
use App\Ramcar\TicketType as LegacyTicketType;
|
||||
use App\Ramcar\TicketStatus;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
|
@ -44,8 +44,7 @@ class Ticket
|
|||
|
||||
// ticket type
|
||||
/**
|
||||
* @ORM\Column(type="string", length=15)
|
||||
* @Assert\NotBlank()
|
||||
* @ORM\Column(type="string", length=15, nullable=true)
|
||||
*/
|
||||
protected $ticket_type;
|
||||
|
||||
|
|
@ -120,6 +119,20 @@ class Ticket
|
|||
*/
|
||||
protected $remarks;
|
||||
|
||||
// new ticket type
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="TicketType", inversedBy="tickets")
|
||||
* @ORM\JoinColumn(name="ticket_type_id", referencedColumnName="id", nullable=true)
|
||||
*/
|
||||
protected $new_ticket_type;
|
||||
|
||||
// sub ticket type
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="SubTicketType", inversedBy="subtickets")
|
||||
* @ORM\JoinColumn(name="subticket_type_id", referencedColumnName="id", nullable=true)
|
||||
*/
|
||||
protected $subticket_type;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
|
|
@ -182,10 +195,10 @@ class Ticket
|
|||
|
||||
public function getTicketTypeText()
|
||||
{
|
||||
if ($this->ticket_type == TicketType::OTHER) {
|
||||
if ($this->ticket_type == LegacyTicketType::OTHER) {
|
||||
return $this->other_ticket_type;
|
||||
} else {
|
||||
$types = TicketType::getCollection();
|
||||
$types = LegacyTicketType::getCollection();
|
||||
return $types[$this->ticket_type] ?? "";
|
||||
}
|
||||
}
|
||||
|
|
@ -300,4 +313,25 @@ class Ticket
|
|||
return $this->remarks;
|
||||
}
|
||||
|
||||
public function setNewTicketType(TicketType $new_ticket_type = null)
|
||||
{
|
||||
$this->new_ticket_type = $new_ticket_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNewTicketType()
|
||||
{
|
||||
return $this->new_ticket_type;
|
||||
}
|
||||
|
||||
public function setSubTicketType(SubTicketType $subticket_type = null)
|
||||
{
|
||||
$this->subticket_type = $subticket_type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSubTicketType()
|
||||
{
|
||||
return $this->subticket_type;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,321 +1,378 @@
|
|||
{% 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">Tickets</h3>
|
||||
<!-- BEGIN: Subheader -->
|
||||
<div class="m-subheader">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-auto">
|
||||
<h3 class="m-subheader__title">Tickets</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-10">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__head">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<span class="m-portlet__head-icon">
|
||||
<i class="fa fa-ticket"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text">
|
||||
{% if mode == 'update' %}
|
||||
Edit Ticket
|
||||
<small>{{ obj.getID }}</small>
|
||||
{% else %}
|
||||
New Ticket
|
||||
{% if customer %}
|
||||
<small>for {{ customer.getFirstName ~ " " ~ customer.getLastName }}</small>
|
||||
{% endif %}
|
||||
{% 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('ticket_update_submit', {'id': obj.getId}) : url('ticket_create_submit', {'customer_id': customer ? customer.getID : false, 'job_order_id': job_order ? job_order.getID : false}) }}">
|
||||
<div class="m-portlet__body">
|
||||
<div class="m-form__section m-form__section--first{{ mode == 'create' ? ' m-form__section--last' }}">
|
||||
{% if (mode == 'update') and (obj.getTicketType != null) %}
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-4">
|
||||
<label data-field="status">Legacy Ticket Type</label>
|
||||
<select class="form-control m-input" id="ticket-type" name="ticket_type" disabled>
|
||||
<option value=""></option>
|
||||
{% for key, ticket_type in ticket_types %}
|
||||
<option value="{{ key }}"{{ key == obj.getTicketType ? ' selected' }}>{{ ticket_type }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="ticket_type"></div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<label data-field="other_ticket_type">Legacy Other Ticket Type <small>(please specify)</small></label>
|
||||
<input type="text" name="other_ticket_type" id="other-ticket-type" class="form-control m-input" value="{{ obj.getOtherTicketType }}" disabled>
|
||||
<div class="form-control-feedback hide" data-field="other_ticket_type"></div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-4">
|
||||
<label data-field="status">Ticket Type</label>
|
||||
<select class="form-control m-input" id="new-ticket-type" name="new_ticket_type">
|
||||
<option value="">Select a ticket type</option>
|
||||
{% for id, label in sets.new_ticket_types %}
|
||||
{% if obj.getNewTicketType %}
|
||||
<option value="{{ id }}"{{ id == obj.getNewTicketType.getID ? ' selected' }}>{{ label }}</option>
|
||||
{% else %}
|
||||
<option value="{{ id }}">{{ label }}</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="new_ticket_type"></div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<label data-field="sub_ticket_type">Sub Ticket Type</label>
|
||||
<select class="form-control m-input" id="sub-ticket-type" name="sub_ticket_type">
|
||||
{% if obj.getSubTicketType == null %}
|
||||
<option value="0">Select a ticket type first</option>
|
||||
{% else %}
|
||||
<option value="0">Select a sub-ticket type</option>
|
||||
{% for sub_ttype in sets.sub_ticket_types %}
|
||||
{% if sub_ttype.ticket_type_id == obj.getNewTicketType.getID %}
|
||||
{% if sub_ttype.id == obj.getSubTicketType.getID|default(0) %}
|
||||
<option value="{{ sub_ttype.id }}" selected>{{ sub_ttype.name }}</option>
|
||||
{% else %}
|
||||
<option value="{{ sub_ttype.id }}">{{ sub_ttype.name }}</option>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="sub_ticket_type"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<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="{{ customer and mode == 'create' ? customer.getFirstName : obj.getFirstName }}"{{ customer ? ' disabled' }}>
|
||||
<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="{{ customer and mode == 'create' ? customer.getLastName : obj.getLastName }}"{{ customer ? ' disabled' }}>
|
||||
<div class="form-control-feedback hide" data-field="last_name"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-4">
|
||||
<label data-field="contact_num">Contact Number</label>
|
||||
<div class="input-group m-input-group">
|
||||
<span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
|
||||
<input type="text" name="contact_num" class="form-control m-input" value="{{ customer and mode == 'create' and customer.getPhoneMobile is not empty ? customer.getPhoneMobile : obj.getContactNumber }}"{{ customer ? ' disabled' }}>
|
||||
<div class="form-control-feedback hide" data-field="contact_num"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-4">
|
||||
<label data-field="plate_number">Vehicle Plate Number</label>
|
||||
<input type="text" name="plate_number" class="form-control m-input" value="{{ obj.getPlateNumber }}">
|
||||
<div class="form-control-feedback hide" data-field="plate_number"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-4">
|
||||
<label data-field="status">Source of Awareness</label>
|
||||
<select class="form-control m-input" id="source-of-awareness" name="source_of_awareness">
|
||||
<option value=""></option>
|
||||
{% for key, soa in soa_types %}
|
||||
<option value="{{ key }}"{{ key == obj.getSourceOfAwareness ? ' selected' }}>{{ soa }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="source_of_awareness"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-12">
|
||||
<label for="remarks" data-field="remarks"> Remarks </label>
|
||||
<textarea class="form-control m-input" id="remarks" rows="6" name="remarks">{{ obj.getRemarks }}</textarea>
|
||||
<div class="form-control-feedback hide" data-field="remarks"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<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 statuses %}
|
||||
<option value="{{ key }}"{{ key == obj.getStatus ? ' selected' }}>{{ status }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="status"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-12">
|
||||
<label for="details" data-field="details">
|
||||
Details
|
||||
</label>
|
||||
<textarea class="form-control m-input" id="details" rows="6" name="details">{{ obj.getDetails }}</textarea>
|
||||
<div class="form-control-feedback hide" data-field="details"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-4">
|
||||
<label data-field="job_order_id">Linked Job Order</label>
|
||||
<input type="text" name="job_order_id" class="form-control m-input" value="{{ job_order.getID|default('None') }}" disabled>
|
||||
<div class="form-control-feedback hide" data-field="job_order_id"></div>
|
||||
</div>
|
||||
{% if job_order %}
|
||||
<div class="col-lg-4">
|
||||
<label> </label>
|
||||
<div>
|
||||
<a href="{{ url('jo_all_form', {'id': job_order.getID }) }}" class="btn btn-info">View Job Order</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if mode == 'update' %}
|
||||
<div class="m-form__seperator m-form__seperator--dashed"></div>
|
||||
<div class="m-form__section m-form__section--last">
|
||||
<div class="m-form__heading">
|
||||
<h3 class="m-form__heading-title">
|
||||
Related Tickets
|
||||
</h3>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-12">
|
||||
<div class="m_datatable" id="data-related-tickets"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</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="{{ redirect_url }}" class="btn btn-secondary">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END: Subheader -->
|
||||
<div class="m-content">
|
||||
<!--Begin::Section-->
|
||||
<div class="row">
|
||||
<div class="col-xl-10">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__head">
|
||||
<div class="m-portlet__head-caption">
|
||||
<div class="m-portlet__head-title">
|
||||
<span class="m-portlet__head-icon">
|
||||
<i class="fa fa-ticket"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text">
|
||||
{% if mode == 'update' %}
|
||||
Edit Ticket
|
||||
<small>{{ obj.getID }}</small>
|
||||
{% else %}
|
||||
New Ticket
|
||||
{% if customer %}
|
||||
<small>for {{ customer.getFirstName ~ " " ~ customer.getLastName }}</small>
|
||||
{% endif %}
|
||||
{% 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('ticket_update_submit', {'id': obj.getId}) : url('ticket_create_submit', {'customer_id': customer ? customer.getID : false, 'job_order_id': job_order ? job_order.getID : false}) }}">
|
||||
<div class="m-portlet__body">
|
||||
<div class="m-form__section m-form__section--first{{ mode == 'create' ? ' m-form__section--last' }}">
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-4">
|
||||
<label data-field="status">Ticket Type</label>
|
||||
<select class="form-control m-input" id="ticket-type" name="ticket_type">
|
||||
<option value=""></option>
|
||||
{% for key, ticket_type in ticket_types %}
|
||||
<option value="{{ key }}"{{ key == obj.getTicketType ? ' selected' }}>{{ ticket_type }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="ticket_type"></div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<label data-field="other_ticket_type">Other Ticket Type <small>(please specify)</small></label>
|
||||
<input type="text" name="other_ticket_type" id="other-ticket-type" class="form-control m-input" value="{{ obj.getOtherTicketType }}" disabled>
|
||||
<div class="form-control-feedback hide" data-field="other_ticket_type"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<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="{{ customer and mode == 'create' ? customer.getFirstName : obj.getFirstName }}"{{ customer ? ' disabled' }}>
|
||||
<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="{{ customer and mode == 'create' ? customer.getLastName : obj.getLastName }}"{{ customer ? ' disabled' }}>
|
||||
<div class="form-control-feedback hide" data-field="last_name"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-4">
|
||||
<label data-field="contact_num">Contact Number</label>
|
||||
<div class="input-group m-input-group">
|
||||
<span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
|
||||
<input type="text" name="contact_num" class="form-control m-input" value="{{ customer and mode == 'create' and customer.getPhoneMobile is not empty ? customer.getPhoneMobile : obj.getContactNumber }}"{{ customer ? ' disabled' }}>
|
||||
<div class="form-control-feedback hide" data-field="contact_num"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-4">
|
||||
<label data-field="plate_number">Vehicle Plate Number</label>
|
||||
<input type="text" name="plate_number" class="form-control m-input" value="{{ obj.getPlateNumber }}">
|
||||
<div class="form-control-feedback hide" data-field="plate_number"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-4">
|
||||
<label data-field="status">Source of Awareness</label>
|
||||
<select class="form-control m-input" id="source-of-awareness" name="source_of_awareness">
|
||||
<option value=""></option>
|
||||
{% for key, soa in soa_types %}
|
||||
<option value="{{ key }}"{{ key == obj.getSourceOfAwareness ? ' selected' }}>{{ soa }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="source_of_awareness"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-12">
|
||||
<label for="remarks" data-field="remarks"> Remarks </label>
|
||||
<textarea class="form-control m-input" id="remarks" rows="6" name="remarks">{{ obj.getRemarks }}</textarea>
|
||||
<div class="form-control-feedback hide" data-field="remarks"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<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 statuses %}
|
||||
<option value="{{ key }}"{{ key == obj.getStatus ? ' selected' }}>{{ status }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-control-feedback hide" data-field="status"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-12">
|
||||
<label for="details" data-field="details">
|
||||
Details
|
||||
</label>
|
||||
<textarea class="form-control m-input" id="details" rows="6" name="details">{{ obj.getDetails }}</textarea>
|
||||
<div class="form-control-feedback hide" data-field="details"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row no-border">
|
||||
<div class="col-lg-4">
|
||||
<label data-field="job_order_id">Linked Job Order</label>
|
||||
<input type="text" name="job_order_id" class="form-control m-input" value="{{ job_order.getID|default('None') }}" disabled>
|
||||
<div class="form-control-feedback hide" data-field="job_order_id"></div>
|
||||
</div>
|
||||
{% if job_order %}
|
||||
<div class="col-lg-4">
|
||||
<label> </label>
|
||||
<div>
|
||||
<a href="{{ url('jo_all_form', {'id': job_order.getID }) }}" class="btn btn-info">View Job Order</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if mode == 'update' %}
|
||||
<div class="m-form__seperator m-form__seperator--dashed"></div>
|
||||
<div class="m-form__section m-form__section--last">
|
||||
<div class="m-form__heading">
|
||||
<h3 class="m-form__heading-title">
|
||||
Related Tickets
|
||||
</h3>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-12">
|
||||
<div class="m_datatable" id="data-related-tickets"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</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="{{ redirect_url }}" class="btn btn-secondary">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
$(function() {
|
||||
$("#row-form").submit(function(e) {
|
||||
var form = $(this);
|
||||
<script>
|
||||
$(function() {
|
||||
$("#row-form").submit(function(e) {
|
||||
var form = $(this);
|
||||
|
||||
e.preventDefault();
|
||||
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 = "{{ redirect_url }}";
|
||||
}
|
||||
});
|
||||
}).fail(function(response) {
|
||||
if (response.status == 422) {
|
||||
var errors = response.responseJSON.errors;
|
||||
var firstfield = false;
|
||||
$.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 = "{{ redirect_url }}";
|
||||
}
|
||||
});
|
||||
}).fail(function(response) {
|
||||
if (response.status == 422) {
|
||||
var errors = response.responseJSON.errors;
|
||||
var firstfield = false;
|
||||
|
||||
// remove all error classes first
|
||||
removeErrors();
|
||||
// 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 + "']");
|
||||
// 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');
|
||||
// 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);
|
||||
// check if this field comes first in DOM
|
||||
var domfield = formfield.get(0);
|
||||
|
||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||
firstfield = domfield;
|
||||
}
|
||||
});
|
||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||
firstfield = domfield;
|
||||
}
|
||||
});
|
||||
|
||||
// focus on first bad field
|
||||
firstfield.focus();
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
});
|
||||
// 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');
|
||||
}
|
||||
// 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');
|
||||
}
|
||||
|
||||
// toggle other ticket type field
|
||||
$("#ticket-type").change(function() {
|
||||
var field = $("#other-ticket-type");
|
||||
// toggle other ticket type field
|
||||
$("#ticket-type").change(function() {
|
||||
var field = $("#other-ticket-type");
|
||||
|
||||
if ($(this).val() == '{{ other_ticket_type }}') {
|
||||
field.prop('disabled', false);
|
||||
} else {
|
||||
field.prop('disabled', true).val("");
|
||||
}
|
||||
}).change();
|
||||
if ($(this).val() == '{{ other_ticket_type }}') {
|
||||
field.prop('disabled', false);
|
||||
} else {
|
||||
field.prop('disabled', true).val("");
|
||||
}
|
||||
}).change();
|
||||
|
||||
{% if mode == 'update' %}
|
||||
// related tickets
|
||||
var ticketRows = [];
|
||||
{% if mode == 'update' %}
|
||||
// related tickets
|
||||
var ticketRows = [];
|
||||
|
||||
{% for ticket in related_tickets %}
|
||||
trow = {
|
||||
id: "{{ ticket.getID }}",
|
||||
date_create: "{{ ticket.getDateCreate|date('d M Y - h:i A') }}",
|
||||
ticket_type: "{{ ticket.getTicketTypeText }}",
|
||||
status: "{{ ticket.getStatusText }}",
|
||||
edit_url: "{{ url('ticket_update', {'id': ticket.getID}) }}"
|
||||
};
|
||||
{% for ticket in related_tickets %}
|
||||
trow = {
|
||||
id: "{{ ticket.getID }}",
|
||||
date_create: "{{ ticket.getDateCreate|date('d M Y - h:i A') }}",
|
||||
ticket_type: "{{ ticket.getTicketTypeText }}",
|
||||
status: "{{ ticket.getStatusText }}",
|
||||
edit_url: "{{ url('ticket_update', {'id': ticket.getID}) }}"
|
||||
};
|
||||
|
||||
ticketRows.push(trow);
|
||||
{% endfor %}
|
||||
ticketRows.push(trow);
|
||||
{% endfor %}
|
||||
|
||||
// tickets data table
|
||||
var ticketOptions = {
|
||||
data: {
|
||||
type: 'local',
|
||||
source: ticketRows,
|
||||
saveState: {
|
||||
cookie: false,
|
||||
webstorage: false
|
||||
}
|
||||
},
|
||||
layout: {
|
||||
scroll: true
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'id',
|
||||
title: 'ID',
|
||||
width: 30
|
||||
},
|
||||
{
|
||||
field: 'date_create',
|
||||
title: 'Date Created',
|
||||
width: 200
|
||||
},
|
||||
{
|
||||
field: 'ticket_type',
|
||||
title: 'Ticket Type'
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: 'Status'
|
||||
},
|
||||
{
|
||||
field: 'Actions',
|
||||
width: 70,
|
||||
title: 'Actions',
|
||||
sortable: false,
|
||||
overflow: 'visible',
|
||||
template: function (row, index, datatable) {
|
||||
return '<a href="' + row.edit_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-ticket" title="Edit"><i class="la la-edit"></i></a>';
|
||||
},
|
||||
}
|
||||
],
|
||||
pagination: false
|
||||
};
|
||||
// tickets data table
|
||||
var ticketOptions = {
|
||||
data: {
|
||||
type: 'local',
|
||||
source: ticketRows,
|
||||
saveState: {
|
||||
cookie: false,
|
||||
webstorage: false
|
||||
}
|
||||
},
|
||||
layout: {
|
||||
scroll: true
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'id',
|
||||
title: 'ID',
|
||||
width: 30
|
||||
},
|
||||
{
|
||||
field: 'date_create',
|
||||
title: 'Date Created',
|
||||
width: 200
|
||||
},
|
||||
{
|
||||
field: 'ticket_type',
|
||||
title: 'Ticket Type'
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: 'Status'
|
||||
},
|
||||
{
|
||||
field: 'Actions',
|
||||
width: 70,
|
||||
title: 'Actions',
|
||||
sortable: false,
|
||||
overflow: 'visible',
|
||||
template: function (row, index, datatable) {
|
||||
return '<a href="' + row.edit_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-ticket" title="Edit"><i class="la la-edit"></i></a>';
|
||||
},
|
||||
}
|
||||
],
|
||||
pagination: false
|
||||
};
|
||||
|
||||
var ticketTable = $("#data-related-tickets").mDatatable(ticketOptions);
|
||||
{% endif %}
|
||||
});
|
||||
</script>
|
||||
var ticketTable = $("#data-related-tickets").mDatatable(ticketOptions);
|
||||
{% endif %}
|
||||
});
|
||||
|
||||
var subticket_type_list = {{ sets.sub_ticket_types|json_encode|raw }};
|
||||
|
||||
// populate sub ticket type field
|
||||
$('form').on('change', '#new-ticket-type', function() {
|
||||
console.log('ticket type change');
|
||||
var ticket_type_id = $(this).val();
|
||||
|
||||
// build options for sub ticket type based on selected ticket type
|
||||
var options = '<option value="0">Select sub ticket type</option>';
|
||||
for (var i in subticket_type_list) {
|
||||
if (subticket_type_list[i].ticket_type_id == ticket_type_id) {
|
||||
options += '<option value="' + subticket_type_list[i].id + '">' + subticket_type_list[i].name + '</option>'
|
||||
}
|
||||
}
|
||||
|
||||
$('#sub-ticket-type').html(options);
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue