Add the new ticket fields into the ticket form. #676
This commit is contained in:
parent
96ce1f81fa
commit
d89f67bc76
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,10 +38,11 @@
|
|||
<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">Ticket Type</label>
|
||||
<select class="form-control m-input" id="ticket-type" name="ticket_type">
|
||||
<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>
|
||||
|
|
@ -50,11 +51,48 @@
|
|||
<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>
|
||||
<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>
|
||||
|
|
@ -317,5 +355,24 @@
|
|||
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