Commit 1682cee1 authored by Karamel's avatar Karamel
Browse files

Fix fiscal ticket import with load/merge.

parent 07c3fad3
......@@ -3,6 +3,7 @@
use Dflydev\FigCookies\FigResponseCookies;
use Dflydev\FigCookies\SetCookie;
use \Pasteque\Server\Exception\InvalidFieldException;
use \Pasteque\Server\Exception\RecordNotFoundException;
use \Pasteque\Server\Model\FiscalTicket;
use \Pasteque\Server\System\DateUtils;
use \Pasteque\Server\System\Login;
......@@ -433,20 +434,19 @@ function fiscal_importTickets($ptApp, $data) {
$tkts = [];
foreach ($data as $tkt) {
$tkt['date'] = DateUtils::readDate($tkt['date']);
if (!empty($tkt['id'])) {
// We don't care about id as FiscalTicketAPI checks with snapshots.
// And it messes things up with Doctrine
if ($tkt['id']['number'] === 0 && $tkt['number'] === 0) {
// Unless it's EOS which has to be messed up
if ($ptApp->getDao()->read(FiscalTicket::class, $tkt['id']) == null) {
// only when it already exists.
unset($tkt['id']);
}
} else {
unset($tkt['id']);
}
unset($tkt['id']);
$fTkt = null;
if ($tkt['number'] === 0) {
// Load EOS from database to update it
$fTkt = FiscalTicket::loadFromId(['type' => $tkt['type'],
'sequence' => $tkt['sequence'],
'number' => $tkt['number']], $ptApp->getDao());
}
if ($fTkt == null) {
// Create a new ticket if EOS is absent. For other tickets the API
// will check agains snapshots anyway.
$fTkt = new FiscalTicket();
}
$fTkt = new FiscalTicket();
$fTkt->merge($tkt, $ptApp->getDao());
$tkts[] = $fTkt;
}
......
Markdown is supported
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