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
Pasteque
pasteque-server
Commits
83fc0975
Commit
83fc0975
authored
Sep 10, 2018
by
Karamel
Browse files
Export fiscal tickets in json in an archive.
parent
591beb22
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/http/routes/fiscal.php
View file @
83fc0975
...
...
@@ -175,3 +175,40 @@ $app->any('/fiscal/', function ($request, $response, $args) {
return
$response
;
}
});
/** Fiscal export */
$app
->
GET
(
'/fiscal/export'
,
function
(
$request
,
$response
,
$args
)
{
$ptApp
=
$this
->
get
(
'settings'
)[
'ptApp'
];
$response
=
fiscalLogin
(
$this
,
$ptApp
,
$request
,
$response
);
if
(
$ptApp
->
getCurrentUser
()
==
null
)
{
fiscalTpl
(
$response
,
'login.php'
);
return
$response
;
}
else
{
// Get all fiscal tickets
$apiResult
=
APICaller
::
run
(
$ptApp
,
'fiscal'
,
'getAll'
,
[[
'type'
,
'sequence'
,
'number'
]]);
if
(
$apiResult
->
getStatus
()
==
APIResult
::
STATUS_CALL_OK
)
{
// Convert tickets to struct
$data
=
$apiResult
->
getContent
();
$ftkts
=
[];
for
(
$i
=
0
;
$i
<
count
(
$data
);
$i
++
)
{
$ftkts
[]
=
$data
[
$i
]
->
toStruct
();
}
// Set export file name
$now
=
new
DateTime
();
$exportName
=
sprintf
(
'fiscal_export-%s'
,
$now
->
format
(
'Ymd_Hi'
));
$tmpName
=
tempnam
(
sys_get_temp_dir
(),
'ptq'
);
$zip
=
new
ZipArchive
();
$zip
->
open
(
$tmpName
,
ZipArchive
::
CREATE
);
$zip
->
addFromString
(
sprintf
(
'%s.txt'
,
$exportName
),
json_encode
(
$ftkts
));
$zip
->
close
();
$response
=
$response
->
withHeader
(
'content-type'
,
'application/zip'
);
$response
=
$response
->
withHeader
(
'content-disposition'
,
sprintf
(
'attachment; filename="%s.zip"'
,
$exportName
));
$response
=
$response
->
write
(
file_get_contents
(
$tmpName
));
unlink
(
$tmpName
);
return
$response
;
}
else
{
fiscalTpl
(
$response
,
'apierror.php'
,
$apiResult
);
}
return
$response
;
}
});
\ No newline at end of file
src/http/templates/menu.php
View file @
83fc0975
...
...
@@ -8,5 +8,7 @@ function render($data) {
$ret
.
=
'<li>'
.
htmlspecialchars
(
$sequence
)
.
' : <a href="./sequence/'
.
htmlspecialchars
(
$sequence
)
.
'/z/" target="_blank">Tickets Z</a> <a href="./sequence/'
.
htmlspecialchars
(
$sequence
)
.
'/tickets/" target="_blank">Tickets</a></li>'
;
}
$ret
.
=
'</ul>'
;
$ret
.
=
'<h2>Export des tickets</h2>'
;
$ret
.
=
'<p><a href="./export">Exporter</a></p>'
;
return
$ret
;
}
src/lib/API/FiscalAPI.php
View file @
83fc0975
...
...
@@ -37,6 +37,13 @@ class FiscalAPI implements API
return
new
static
(
$app
->
getDao
());
}
/** Get all fiscal tickets, including EOS'.
* @param $order The order fields (see DAO->search) */
public
function
getAll
(
$order
=
null
)
{
return
$this
->
dao
->
search
(
FiscalTicket
::
class
,
null
,
null
,
null
,
$order
);
}
public
function
getLastFiscalTicket
(
$type
,
$sequence
)
{
// Look for an existing fiscal ticket
$lastFTicket
=
null
;
...
...
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