Commit 81b40812 authored by Karamel's avatar Karamel
Browse files

Update nextTicketId on TicketAPI->write.

parent 46fc9246
......@@ -46,6 +46,7 @@ class TicketAPI extends APIHelper implements API
$this->supportOrDie($data);
$data = (is_array($data)) ? $data : array($data);
$previousFTicket = null;
$affectedCashRegisters = [];
foreach ($data as $ticket) {
// Defensive checks
// Reserved number 0
......@@ -100,8 +101,24 @@ class TicketAPI extends APIHelper implements API
$this->dao->write($ticket);
$this->dao->write($fiscalTicket);
$previousFTicket = $fiscalTicket;
// Mark the cash register as affected to update nextTicketId
$cashReg = $ticket->getCashRegister();
if (!isset($affectedCashRegisters[$cashReg->getId()])) {
$affectedCashRegisters[$cashReg->getId()] = $cashReg;
}
}
$this->updateEOSTicket($previousFTicket);
// Update nextTicketId
foreach ($affectedCashRegisters as $id => $cashRegister) {
$search = $this->dao->search(Ticket::class,
new DAOCondition('cashRegister', '=', $cashRegister),
1, 0, '-number');
if (count($search) > 0) {
$max = $search[0]->getNumber();
$cashRegister->setNextTicketId($max + 1);
$this->dao->write($cashRegister);
}
}
$this->dao->commit();
if (count($data) === 1) {
return $data[0];
......
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