Add mandatory cancellation reason to prompt #34
This commit is contained in:
parent
38a1fad607
commit
03f6b40ed3
2 changed files with 49 additions and 20 deletions
|
|
@ -573,6 +573,7 @@ class JobOrderController extends BaseController
|
|||
$params['warranty_classes'] = WarrantyClass::getCollection();
|
||||
$params['modes_of_payment'] = ModeOfPayment::getCollection();
|
||||
$params['statuses'] = JOStatus::getCollection();
|
||||
$params['status_cancelled'] = JOStatus::CANCELLED;
|
||||
$params['promos'] = $em->getRepository(Promo::class)->findAll();
|
||||
$params['discount_apply'] = DiscountApply::getCollection();
|
||||
$params['trade_in_types'] = TradeInType::getCollection();
|
||||
|
|
@ -770,6 +771,7 @@ class JobOrderController extends BaseController
|
|||
$params['warranty_classes'] = WarrantyClass::getCollection();
|
||||
$params['modes_of_payment'] = ModeOfPayment::getCollection();
|
||||
$params['statuses'] = JOStatus::getCollection();
|
||||
$params['status_cancelled'] = JOStatus::CANCELLED;
|
||||
$params['promos'] = $em->getRepository(Promo::class)->findAll();
|
||||
$params['discount_apply'] = DiscountApply::getCollection();
|
||||
$params['trade_in_types'] = TradeInType::getCollection();
|
||||
|
|
@ -899,6 +901,7 @@ class JobOrderController extends BaseController
|
|||
$params['warranty_classes'] = WarrantyClass::getCollection();
|
||||
$params['modes_of_payment'] = ModeOfPayment::getCollection();
|
||||
$params['statuses'] = JOStatus::getCollection();
|
||||
$params['status_cancelled'] = JOStatus::CANCELLED;
|
||||
$params['promos'] = $em->getRepository(Promo::class)->findAll();
|
||||
$params['discount_apply'] = DiscountApply::getCollection();
|
||||
$params['trade_in_types'] = TradeInType::getCollection();
|
||||
|
|
@ -1000,6 +1003,7 @@ class JobOrderController extends BaseController
|
|||
$params['warranty_classes'] = WarrantyClass::getCollection();
|
||||
$params['modes_of_payment'] = ModeOfPayment::getCollection();
|
||||
$params['statuses'] = JOStatus::getCollection();
|
||||
$params['status_cancelled'] = JOStatus::CANCELLED;
|
||||
$params['promos'] = $em->getRepository(Promo::class)->findAll();
|
||||
$params['discount_apply'] = DiscountApply::getCollection();
|
||||
$params['trade_in_types'] = TradeInType::getCollection();
|
||||
|
|
@ -1155,6 +1159,7 @@ class JobOrderController extends BaseController
|
|||
$params['warranty_classes'] = WarrantyClass::getCollection();
|
||||
$params['modes_of_payment'] = ModeOfPayment::getCollection();
|
||||
$params['statuses'] = JOStatus::getCollection();
|
||||
$params['status_cancelled'] = JOStatus::CANCELLED;
|
||||
$params['promos'] = $em->getRepository(Promo::class)->findAll();
|
||||
$params['discount_apply'] = DiscountApply::getCollection();
|
||||
$params['trade_in_types'] = TradeInType::getCollection();
|
||||
|
|
@ -1269,6 +1274,7 @@ class JobOrderController extends BaseController
|
|||
$params['warranty_classes'] = WarrantyClass::getCollection();
|
||||
$params['modes_of_payment'] = ModeOfPayment::getCollection();
|
||||
$params['statuses'] = JOStatus::getCollection();
|
||||
$params['status_cancelled'] = JOStatus::CANCELLED;
|
||||
$params['promos'] = $em->getRepository(Promo::class)->findAll();
|
||||
$params['discount_apply'] = DiscountApply::getCollection();
|
||||
$params['trade_in_types'] = TradeInType::getCollection();
|
||||
|
|
@ -1313,6 +1319,17 @@ class JobOrderController extends BaseController
|
|||
{
|
||||
$this->denyAccessUnlessGranted('joborder.cancel', null, 'No access.');
|
||||
|
||||
$cancel_reason = $req->request->get('cancel_reason');
|
||||
|
||||
if (empty($cancel_reason))
|
||||
{
|
||||
// something happened
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'error' => 'Reason for cancellation is required.'
|
||||
], 422);
|
||||
}
|
||||
|
||||
// get object data
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$obj = $em->getRepository(JobOrder::class)->find($id);
|
||||
|
|
@ -1322,7 +1339,8 @@ class JobOrderController extends BaseController
|
|||
throw $this->createNotFoundException('The item does not exist');
|
||||
|
||||
// cancel job order
|
||||
$obj->setStatus(JOStatus::CANCELLED);
|
||||
$obj->setStatus(JOStatus::CANCELLED)
|
||||
->setCancelReason($cancel_reason);
|
||||
|
||||
// save
|
||||
$em->flush();
|
||||
|
|
|
|||
|
|
@ -715,7 +715,7 @@
|
|||
{% if mode != 'update-all' %}
|
||||
<button type="submit" class="btn btn-success">{{ mode == 'update-fulfillment' ? 'Fulfill' : 'Submit' }}</button>
|
||||
{% endif %}
|
||||
{% if mode != 'create' and is_granted('joborder.cancel') %}
|
||||
{% if mode != 'create' and is_granted('joborder.cancel') and obj.getStatus != status_cancelled %}
|
||||
<a href="{{ url('jo_cancel', {'id': obj.getID}) }}" class="btn btn-danger btn-cancel-job-order">Cancel Job Order</button>
|
||||
{% endif %}
|
||||
{% if mode != 'create' %}
|
||||
|
|
@ -1361,26 +1361,37 @@ $(function() {
|
|||
e.preventDefault();
|
||||
|
||||
swal({
|
||||
title: 'Confirmation',
|
||||
html: 'Are you sure you want to cancel this job order?',
|
||||
title: 'Cancel Job Order',
|
||||
html: 'Please enter the reason for cancellation of this job order:',
|
||||
input: 'textarea',
|
||||
inputClass: 'form-control',
|
||||
type: 'warning',
|
||||
showCancelButton: true
|
||||
}).then((result) => {
|
||||
if (result.value) {
|
||||
$.ajax({
|
||||
method: "DELETE",
|
||||
url: url
|
||||
}).done(function(response) {
|
||||
swal({
|
||||
title: 'Done!',
|
||||
text: response.success,
|
||||
type: 'success',
|
||||
onClose: function() {
|
||||
window.location.href = "{{ return_url }}";
|
||||
}
|
||||
});
|
||||
});
|
||||
showCancelButton: true,
|
||||
width: '40rem',
|
||||
preConfirm: (reason) => {
|
||||
if (!reason) {
|
||||
swal.showValidationError(
|
||||
'Reason for cancellation is required.'
|
||||
)
|
||||
}
|
||||
}
|
||||
}).then((reason) => {
|
||||
$.ajax({
|
||||
method: "DELETE",
|
||||
url: url,
|
||||
data: {
|
||||
'cancel_reason': reason.value
|
||||
}
|
||||
}).done(function(response) {
|
||||
swal({
|
||||
title: 'Done!',
|
||||
text: response.success,
|
||||
type: 'success',
|
||||
onClose: function() {
|
||||
window.location.href = "{{ return_url }}";
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue