Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
SAMBUMBA
pasteque-server
Commits
efae5016
Commit
efae5016
authored
Dec 12, 2017
by
Karamel
Browse files
Set api/cash/search route.
parent
90baf211
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/http/routes/cash.php
View file @
efae5016
...
...
@@ -4,6 +4,7 @@ use \Pasteque\Server\Model\CashSession;
use
\
Pasteque\Server\System\DateUtils
;
use
\
Pasteque\Server\System\API\APICaller
;
use
\
Pasteque\Server\System\API\APIResult
;
use
\
Pasteque\Server\System\DAO\DAOCondition
;
/**
* GET cashIdGet
...
...
@@ -51,30 +52,49 @@ $app->POST('/api/cash', function($request, $response, $args) {
* Output-Formats: [application/json]
*/
$app
->
GET
(
'/api/cash/search/'
,
function
(
$request
,
$response
,
$args
)
{
$srv
=
new
CashesService
();
$db
=
DB
::
get
();
$ptApp
=
$this
->
get
(
'settings'
)[
'ptApp'
];
$queryParams
=
$request
->
getQueryParams
();
$cashRegisterId
=
$queryParams
[
'cashRegisterId'
];
$dateStart
=
$queryParams
[
'dateStart'
];
$dateEnd
=
$queryParams
[
'dateEnd'
];
$conditions
=
array
();
$cashRegisterId
=
(
empty
(
$queryParams
[
'cashRegister'
]))
?
null
:
$queryParams
[
'cashRegister'
];
// Check mandatory dateStart
$dateStart
=
(
empty
(
$queryParams
[
'dateStart'
]))
?
null
:
DateUtils
::
readDate
(
$queryParams
[
'dateStart'
]);
if
(
$dateStart
===
null
)
{
return
$response
->
withStatus
(
400
,
'Missing mandatory dateStart.'
);
}
if
(
$dateStart
===
false
)
{
return
$response
->
withStatus
(
400
,
'Invalid dateStart.'
);
}
// Get optional dateStop
$dateStop
=
(
empty
(
$queryParams
[
'dateStop'
]))
?
null
:
DateUtils
::
readDate
(
intval
(
$queryParams
[
'dateStop'
]));
// Check optional cash register
$cashRegister
=
null
;
if
(
$cashRegisterId
!==
null
)
{
$conditions
[]
=
array
(
"cashRegisterId"
,
"="
,
$cashRegisterId
);
$cashRegApiResp
=
APICaller
::
run
(
$ptApp
,
'cashRegister'
,
'get'
,
$cashRegisterId
);
if
(
$cashRegApiResp
->
getStatus
()
!=
APIResult
::
STATUS_CALL_OK
)
{
return
$response
->
withApiResult
(
$cashRegResp
);
}
$cashRegister
=
$cashRegApiResp
->
getContent
();
if
(
$cashRegister
===
null
)
{
return
$response
->
withStatus
(
404
,
'Cash register not found'
);
}
}
if
(
$dateStart
!==
null
)
{
$conditions
[]
=
array
(
"openDate"
,
">="
,
$db
->
dateVal
(
$dateStart
));
// Run search and return
$conditions
=
array
();
if
(
$cashRegister
!==
null
)
{
$conditions
[]
=
new
DAOCondition
(
'cashRegister'
,
'='
,
$cashRegister
);
}
if
(
$dateEnd
!==
null
)
{
$conditions
[]
=
array
(
"closeDate"
,
"<="
,
$db
->
dateVal
(
$date
End
)
);
$conditions
[]
=
new
DAOCondition
(
'openDate'
,
'>='
,
$dateStart
);
if
(
$dateStop
!==
null
)
{
$conditions
[]
=
new
DAOCondition
(
'openDate'
,
'<='
,
$date
Stop
);
}
return
$response
->
withJson
(
$srv
->
search
(
$conditions
));
// Always exclude non-closed cash because most of the sums are not updated.
$conditions
[]
=
new
DAOCondition
(
'closeDate'
,
'!='
,
null
);
$searchResp
=
APICaller
::
run
(
$ptApp
,
'cashSession'
,
'search'
,
[
$conditions
,
null
,
null
,
'openDate'
]);
return
$response
->
withApiResult
(
$searchResp
);
});
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment