Add fulfill for cancelled job orders. #442

This commit is contained in:
Korina Cordero 2020-07-28 05:58:21 +00:00
parent afbe3aa00b
commit c3e36ad055
4 changed files with 59 additions and 5 deletions

View file

@ -254,6 +254,6 @@ jo_hub_view_form:
methods: [GET]
jo_fulfill_cancel_submit:
path: /job-order/all/{id}
path: /job-order/fulfillcancel/{id}
controller: App\Controller\JobOrderController::fulfillCancelSubmit
methods: [POST]

View file

@ -1157,9 +1157,8 @@ class JobOrderController extends Controller
$this->denyAccessUnlessGranted('jo_cancel.fulfill', null, 'No access.');
// TODO: make the service function to fulfill the cancelled JO
/*
$error_array = [];
$result = $jo_handler->openEditJobOrder($req, $id);
$result = $jo_handler->fulfillCancelledJobOrder($req, $id);
$error_array = $result['error_array'];
@ -1170,7 +1169,7 @@ class JobOrderController extends Controller
'success' => false,
'errors' => $error_array
], 422);
} */
}
// return successful response
return $this->json([

View file

@ -2968,4 +2968,37 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
return $params;
}
public function fulfillCancelledJobOrder(Request $req, $id)
{
// initialize error list
$error_array = [];
// get object data
$em = $this->em;
$obj = $em->getRepository(JobOrder::class)->find($id);
// make sure this object exists
if (empty($obj))
throw new NotFoundHttpException('The item does not exist');
$obj->fulfill();
// the event
$event = new JOEvent();
$event->setDateHappen(new DateTime())
->setTypeID(JOEventType::FULFILL)
->setJobOrder($obj);
// get current user
$user = $this->security->getUser();
if ($user != null)
{
$event->setUser($user);
}
$event->setUser($user);
$em->persist($event);
$em->flush();
}
}

View file

@ -849,7 +849,7 @@
<div class="col-lg-12">
{% if mode != 'update-all' %}
{% if mode == 'fulfill-cancel' %}
<button type="submit" class="btn btn-success"> Fulfill </button>
<a href="{{ url('jo_fulfill_cancel_submit', {'id': obj.getID}) }}" class="btn btn-success btn-fulfill-cancel-job-order">Fulfill</a>
{% else %}
<button type="submit" class="btn btn-success">{{ mode == 'update-fulfillment' ? 'Fulfill' : 'Submit' }}</button>
{% endif %}
@ -1772,6 +1772,28 @@ $(function() {
});
});
});
// fulfill cancelled job order
$(".btn-fulfill-cancel-job-order").click(function(e) {
var url = $(this).prop('href');
e.preventDefault();
$.ajax({
method: "POST",
url: url,
}).done(function(response) {
swal({
title: 'Done!',
text: response.success,
type: 'success',
onClose: function() {
window.location.href = "{{ return_url }}";
}
});
});
});
});
</script>
{% endblock %}