Add job order processing form
This commit is contained in:
parent
139cbdfc3d
commit
4a216996ae
4 changed files with 190 additions and 13 deletions
|
|
@ -24,6 +24,6 @@ jo_proc_form:
|
|||
methods: [GET]
|
||||
|
||||
jo_proc_submit:
|
||||
path: /job-order/processing
|
||||
path: /job-order/processing/{id}
|
||||
controller: App\Controller\JobOrderController::processingSubmit
|
||||
methods: [POST]
|
||||
|
|
|
|||
|
|
@ -110,6 +110,10 @@ span.has-danger,
|
|||
text-align: center;
|
||||
}
|
||||
|
||||
.table-clickable tr {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@media (min-width: 995px) {
|
||||
.modal-lg {
|
||||
max-width: 1024px;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ use App\Entity\CustomerVehicle;
|
|||
use App\Entity\Outlet;
|
||||
use App\Entity\Rider;
|
||||
|
||||
use App\Service\MapTools;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
|
@ -235,6 +237,82 @@ class JobOrderController extends BaseController
|
|||
]);
|
||||
}
|
||||
|
||||
public function processingForm(MapTools $map_tools, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('jo_proc.list', null, 'No access.');
|
||||
|
||||
$params = $this->initParameters('jo_proc');
|
||||
$params['mode'] = 'update';
|
||||
|
||||
// get row data
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$obj = $em->getRepository(JobOrder::class)->find($id);
|
||||
|
||||
// make sure this row exists
|
||||
if (empty($obj))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
// get parent associations
|
||||
$params['bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll();
|
||||
$params['customers'] = $em->getRepository(Customer::class)->findAll();
|
||||
$params['outlet'] = $em->getRepository(Outlet::class)->findAll();
|
||||
$params['rider'] = $em->getRepository(Rider::class)->findAll();
|
||||
$params['service_types'] = ServiceType::getCollection();
|
||||
$params['statuses'] = JOStatus::getCollection();
|
||||
|
||||
// get closest outlets
|
||||
$outlets = $map_tools->getClosestOutlets($obj->getCoordinates(), 10);
|
||||
|
||||
$params['outlets'] = [];
|
||||
|
||||
// format seconds into friendly time
|
||||
foreach ($outlets as $outlet) {
|
||||
$seconds = $outlet['duration'];
|
||||
|
||||
if (!empty($seconds) && $seconds > 0) {
|
||||
$hours = floor($seconds / 3600);
|
||||
$minutes = floor(($seconds / 60) % 60);
|
||||
$seconds = $seconds % 60;
|
||||
|
||||
$outlet['duration'] = $hours . "hrs, " . $minutes . " mins, " . $seconds . " secs";
|
||||
} else {
|
||||
$outlet['duration'] = false;
|
||||
}
|
||||
|
||||
$params['outlets'][] = $outlet;
|
||||
}
|
||||
|
||||
$params['obj'] = $obj;
|
||||
|
||||
// response
|
||||
return $this->render('job-order/form.html.twig', $params);
|
||||
}
|
||||
|
||||
public function processingSubmit(Request $req, ValidatorInterface $validator, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('jo_in.list', null, 'No access.');
|
||||
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
||||
// get object data
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$obj = $em->getRepository(JobOrder::class)->find($id);
|
||||
|
||||
// make sure this object exists
|
||||
if (empty($obj))
|
||||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
error_log(print_r($req->request->all(), true));
|
||||
|
||||
// TODO: validation and saving of updated job order
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
}
|
||||
|
||||
// TODO: re-enable search, figure out how to group the orWhere filters into one, so can execute that plus the pending filter
|
||||
|
||||
// check if datatable filter is present and append to query
|
||||
|
|
|
|||
|
|
@ -22,23 +22,32 @@
|
|||
<i class="flaticon-transport"></i>
|
||||
</span>
|
||||
<h3 class="m-portlet__head-text">
|
||||
Incoming
|
||||
{% if mode == 'update' %}
|
||||
Processing
|
||||
<small>{{ obj.getID() }}</small>
|
||||
{% else %}
|
||||
Incoming
|
||||
{% endif %}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ url('jo_in_submit') }}">
|
||||
<form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ mode == 'update' ? url('jo_proc_submit', {'id': obj.getId()}) : url('jo_in_submit') }}">
|
||||
<div class="m-portlet__body">
|
||||
<div class="m-form__section m-form__section--first">
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-6">
|
||||
<label data-field="customer_vehicle">Select a vehicle:</label>
|
||||
<select class="form-control m-select2" id="customer-vehicle" name="customer_vehicle"></select>
|
||||
<div class="form-control-feedback hide" data-field="customer_vehicle"></div>
|
||||
|
||||
{% if mode == 'create' %}
|
||||
<div class="m-form__section m-form__section--first">
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-6">
|
||||
<label data-field="customer_vehicle">Select a vehicle:</label>
|
||||
<select class="form-control m-select2" id="customer-vehicle" name="customer_vehicle"></select>
|
||||
<div class="form-control-feedback hide" data-field="customer_vehicle"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-form__section">
|
||||
{% endif %}
|
||||
|
||||
<div class="m-form__section{{ mode == 'update' ? ' m-form__section--first' }}">
|
||||
<div class="m-form__heading">
|
||||
<h3 class="m-form__heading-title">
|
||||
Customer Details
|
||||
|
|
@ -228,7 +237,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="m-form__seperator m-form__seperator--dashed"></div>
|
||||
<div class="m-form__section m-form__section--last">
|
||||
<div class="m-form__section{{ mode == 'create' ? ' m-form__section--last' }}">
|
||||
<div class="m-form__heading">
|
||||
<h3 class="m-form__heading-title">
|
||||
Invoice
|
||||
|
|
@ -305,6 +314,60 @@
|
|||
</div>
|
||||
</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">
|
||||
Nearest Outlets
|
||||
</h3>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-12">
|
||||
<table id="outlets-table" class="table table-compact table-hover table-clickable m-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Address</th>
|
||||
<th>Numbers</th>
|
||||
<th>Opening</th>
|
||||
<th>Closing</th>
|
||||
<th class="text-right">Sales Count</th>
|
||||
<th class="text-right">Sales Amount</th>
|
||||
<th class="text-right">Service Count</th>
|
||||
<th class="text-right">Distance</th>
|
||||
<th class="text-right">Travel Time</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="placeholder-row{{ outlets|length > 0 ? ' hide' }}">
|
||||
<td colspan="10">
|
||||
No items to display.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{% for outlet in outlets %}
|
||||
<tr data-id="{{ outlet.outlet.getID }}">
|
||||
<td>{{ outlet.outlet.getName }}</td>
|
||||
<td>{{ outlet.outlet.getAddress }}</td>
|
||||
<td>{{ outlet.outlet.getContactNumbers }}</td>
|
||||
<td>{{ outlet.outlet.getTimeOpen|date("g:i A") }}</td>
|
||||
<td>{{ outlet.outlet.getTimeClose|date("g:i A") }}</td>
|
||||
<td class="text-right">0.00</td>
|
||||
<td class="text-right">0.00</td>
|
||||
<td class="text-right">0</td>
|
||||
<td class="text-right">{{ outlet.distance ? outlet.distance|number_format ~ ' m' : '-' }}</td>
|
||||
<td class="text-right">{{ outlet.duration ? outlet.duration : '-' }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</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">
|
||||
|
|
@ -404,6 +467,11 @@ $(function() {
|
|||
// add invoice items to data
|
||||
fields['invoice_items'] = invoiceItems;
|
||||
|
||||
{% if mode == 'update' %}
|
||||
// add selected outlet to data
|
||||
fields['outlet'] = selectedOutlet;
|
||||
{% endif %}
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
|
|
@ -418,7 +486,7 @@ $(function() {
|
|||
text: 'Your changes have been saved!',
|
||||
type: 'success',
|
||||
onClose: function() {
|
||||
window.location.href = "{{ url('jo_in') }}";
|
||||
window.location.href = "{{ mode == 'create' ? url('jo_in') : url('jo_proc') }}";
|
||||
}
|
||||
});
|
||||
}).fail(function(response) {
|
||||
|
|
@ -719,6 +787,33 @@ $(function() {
|
|||
tbody.find('.placeholder-row').removeClass('hide');
|
||||
}
|
||||
});
|
||||
|
||||
{% if mode == 'update' %}
|
||||
|
||||
var selectedOutlet = false;
|
||||
|
||||
$("#outlets-table tbody tr").click(function() {
|
||||
var id = $(this).data('id');
|
||||
|
||||
if (id != selectedOutlet) {
|
||||
// highlight this row, set outlet value
|
||||
$("#outlets-table")
|
||||
.find('.m-table__row--primary')
|
||||
.removeClass('.m-table__row--primary');
|
||||
|
||||
$(this).addClass('m-table__row--primary');
|
||||
|
||||
// set value
|
||||
selectedOutlet = id;
|
||||
} else {
|
||||
// unhighlight this row
|
||||
$(this).removeClass('m-table__row--primary');
|
||||
|
||||
// remove id value
|
||||
selectedOutlet = false;
|
||||
}
|
||||
});
|
||||
{% endif %}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue