Commit 900ca5a1 authored by Karamel's avatar Karamel
Browse files

Add get ticket route.

parent 81b40812
......@@ -6,6 +6,33 @@ use \Pasteque\Server\System\API\APICaller;
use \Pasteque\Server\System\API\APIResult;
use \Pasteque\Server\System\DAO\DAOCondition;
/** Get a single ticket. */
$app->GET('/api/ticket/{cashregister}/{number}', function ($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$cashRes = APICaller::run($ptApp, 'cashRegister', 'get',
$args['cashregister']);
if ($cashRes->getStatus() != APIResult::STATUS_CALL_OK) {
return $response->withApiResult($cashRes);
}
$cashRegister = $cashRes->getContent();
if ($cashRegister === null) {
return $response->withStatus(404, 'Cash register not found');
}
$apiRes = APICaller::run($ptApp, 'ticket', 'search',
[new DAOCondition('cashRegister', '=', $cashRegister),
new DAOCondition('number', '=', $args['number'])]);
if ($apiRes->getStatus() == APIResult::STATUS_CALL_OK) {
$ticket = $apiRes->getContent();
if (count($ticket) > 0) {
return $response->withAPIResult(APIResult::success($ticket[0]));
} else {
$response->withStatus(404, 'Ticket not found');
}
}
return $response->withApiResult($apiRes);
});
/** Get tickets from a session. */
$app->GET('/api/ticket/session/{cashregister}/{sequence}', function ($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment