Commit 75826423 authored by Karamel's avatar Karamel
Browse files

Use date of registration in FiscalTicket instead of the date of the ticket.

parent 710bd909
......@@ -16,6 +16,7 @@ WARNING: this version includes changes to the database. Run bin/updatedbto8.2.ph
### Changed
- Perpetual CS is added to cash sessions. The perpetual CS is computed server-side when writing a closed cash without including it to preserve retro-compatibility, but clients should be updated to send it along the other sums.
- FiscalTicket date refers to the date of its registration instead of the referenced ticket date.
- Assigning an empty array or null does not keep an association values but clear them. To keep the actual value, do not set it in the json structure.
- Finer control when reading records from associative arrays for errors, new records and updates.
......
......@@ -152,7 +152,7 @@ class CashsessionAPI extends APIHelper implements API
} else {
$fiscalTicket->setNumber(1);
}
$fiscalTicket->setDate($session->getCloseDate());
$fiscalTicket->setDate(new \DateTime());
$fiscalTicket->setContent(json_encode($session->toStone()));
// Sign
$fiscalTicket->sign($previousFTicket);
......
......@@ -67,7 +67,7 @@ class TicketAPI extends APIHelper implements API
} else {
$fiscalTicket->setNumber(1);
}
$fiscalTicket->setDate($ticket->getDate());
$fiscalTicket->setDate(new \DateTime());
$stone = $ticket->toStone();
$stone['failure'] = $reason;
$fiscalTicket->setContent(json_encode($stone));
......@@ -150,7 +150,7 @@ class TicketAPI extends APIHelper implements API
} else {
$fiscalTicket->setNumber(1);
}
$fiscalTicket->setDate($ticket->getDate());
$fiscalTicket->setDate(new \DateTime());
$fiscalTicket->setContent(json_encode($ticket->toStone()));
// Sign
$fiscalTicket->sign($previousFTicket);
......
......@@ -130,12 +130,14 @@ class CashsessionAPITest extends TestCase
$openDate->setTime(14, 0);
$session->setOpenDate($openDate);
$this->api->write($session);
$this->assertEquals($openDate->getTimestamp(), $session->getOpenDate()->getTimestamp());
$this->assertEquals($openDate->getTimestamp(),
$session->getOpenDate()->getTimestamp());
// Close and check FiscalTicket
$closeDate = new \DateTime();
$closeDate->add(new \DateInterval('PT3H'));
$session->setCloseDate($closeDate);
$this->api->write($session);
$now = new \DateTime();
$readfTkt = $this->dao->read(FiscalTicket::class, [
'type' => FiscalTicket::TYPE_ZTICKET,
'sequence' => FiscalTicket::getZTicketSequence($session),
......@@ -147,8 +149,10 @@ class CashsessionAPITest extends TestCase
'number' => 0]);
$this->assertNotNull($readfTkt);
$this->assertNotNull($readEOSTkt);
$this->assertTrue(DateUtils::equals($session->getCloseDate(), $readfTkt->getDate()));
$this->assertTrue(DateUtils::equals($readfTkt->getDate(), $readEOSTkt->getDate()));
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt->getDate()->getTimestamp()));
$this->assertTrue(DateUtils::equals($readfTkt->getDate(),
$readEOSTkt->getDate()));
$this->assertTrue($readfTkt->checkSignature(null));
$this->assertTrue($readEOSTkt->checkSignature($readfTkt));
}
......@@ -358,6 +362,7 @@ class CashsessionAPITest extends TestCase
try {
$this->api->write($session);
} catch (\BadMethodCallException $e) {
$now = new \DateTime();
$searchSession = $this->dao->search(CashSession::class);
$this->assertEquals(0, count($searchSession));
$readfTkt = $this->dao->read(FiscalTicket::class, [
......@@ -370,6 +375,8 @@ class CashsessionAPITest extends TestCase
'number' => 0]);
$this->assertNotNull($readfTkt);
$this->assertNotNull($readEOSTkt);
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt->getDate()->getTimestamp()));
$fdata = json_decode($readfTkt->getContent(), true);
$this->assertNotNull($fdata);
$this->assertEquals($fdata['failure'], 'Trying to close a session that was not registered as open.');
......@@ -400,6 +407,7 @@ class CashsessionAPITest extends TestCase
try {
$this->api->write($session);
} catch (\BadMethodCallException $e2) {
$now = new \DateTime();
$searchSession = $this->dao->search(CashSession::class);
$this->assertEquals(0, count($searchSession));
$readfTkt = $this->dao->read(FiscalTicket::class, [
......@@ -415,7 +423,12 @@ class CashsessionAPITest extends TestCase
'sequence' => FiscalTicket::getFailureZTicketSequence($session),
'number' => 0]);
$this->assertNotNull($readfTkt);
$this->assertNotNull($readfTkt2);
$this->assertNotNull($readEOSTkt);
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt->getDate()->getTimestamp()));
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt2->getDate()->getTimestamp()));
$fdata = json_decode($readfTkt->getContent(), true);
$this->assertNotNull($fdata);
$this->assertEquals($fdata['failure'], 'Trying to close a session that was not registered as open.');
......@@ -451,6 +464,7 @@ class CashsessionAPITest extends TestCase
try {
$this->api->write($session);
} catch (\BadMethodCallException $e) {
$now = new \DateTime();
$readfTkt = $this->dao->read(FiscalTicket::class, [
'type' => FiscalTicket::TYPE_ZTICKET,
'sequence' => FiscalTicket::getFailureTicketSequence($session),
......@@ -461,6 +475,8 @@ class CashsessionAPITest extends TestCase
'number' => 0]);
$this->assertNotNull($readfTkt);
$this->assertNotNull($readEOSTkt);
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt->getDate()->getTimestamp()));
$fdata = json_decode($readfTkt->getContent(), true);
$this->assertNotNull($fdata);
$this->assertEquals($fdata['failure'], 'Closed sessions are read-only.');
......
......@@ -258,6 +258,7 @@ class TicketAPITest extends TestCase
$this->api->write($tkt);
} catch (InvalidRecordException $e) {
$exceptionThrown = true;
$now = new \DateTime();
// Check the exception
$this->assertEquals(InvalidRecordException::CSTR_GENERATED,
$e->getConstraint());
......@@ -283,6 +284,8 @@ class TicketAPITest extends TestCase
$this->assertNotNull($readfTkt);
$fdata = json_decode($readfTkt->getContent(), true);
$this->assertNotNull($fdata);
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt->getDate()->getTimestamp()));
$this->assertEquals($fdata['failure'], 'Ticket number 0 is reserved.');
$this->assertTrue($readfTkt->checkSignature(null));
$this->assertTrue($readEOSTkt->checkSignature($readfTkt));
......@@ -296,6 +299,7 @@ class TicketAPITest extends TestCase
$tkt = new Ticket();
$tkt->merge($this->sampleTkt(), $this->dao);
$this->api->write($tkt);
$now = new \DateTime();
$readTkt = $this->dao->readSnapshot(Ticket::class, $tkt->getId());
$this->assertNotNull($readTkt);
assertTicketModelEqModel($tkt, $readTkt, $this);
......@@ -304,12 +308,15 @@ class TicketAPITest extends TestCase
'sequence' => FiscalTicket::getTicketSequence($readTkt),
'number' => 1]);
$this->assertNotNull($readfTkt);
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt->getDate()->getTimestamp()));
$readEOSTkt = $this->dao->read(FiscalTicket::class, [
'type' => FiscalTicket::TYPE_TICKET,
'sequence' => FiscalTicket::getTicketSequence($readTkt),
'number' => 0]);
$this->assertNotNull($readEOSTkt);
$this->assertTrue(DateUtils::equals($readTkt->getDate(), $readEOSTkt->getDate()));
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt->getDate()->getTimestamp()));
$this->assertTrue($readfTkt->checkSignature(null));
$this->assertTrue($readEOSTkt->checkSignature($readfTkt));
}
......@@ -327,6 +334,7 @@ class TicketAPITest extends TestCase
$this->api->write($tkt2);
} catch (InvalidRecordException $e) {
$exceptionThrown = true;
$now = new \DateTime();
// Check the exception
$this->assertEquals(InvalidRecordException::CSTR_READ_ONLY,
$e->getConstraint());
......@@ -351,6 +359,8 @@ class TicketAPITest extends TestCase
'number' => 0]);
$this->assertNotNull($readfTkt);
$this->assertNotNull($readEOSTkt);
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt->getDate()->getTimestamp()));
$fdata = json_decode($readfTkt->getContent(), true);
$this->assertNotNull($fdata);
$this->assertEquals($fdata['failure'], 'Tickets are read only.');
......@@ -372,6 +382,7 @@ class TicketAPITest extends TestCase
$this->api->write($tkt);
} catch (InvalidRecordException $e) {
$exceptionThrown = true;
$now = new \DateTime();
// Check the exception
$this->assertEquals(InvalidRecordException::CSTR_READ_ONLY,
$e->getConstraint());
......@@ -396,6 +407,8 @@ class TicketAPITest extends TestCase
'number' => 0]);
$this->assertNotNull($readfTkt);
$this->assertNotNull($readEOSTkt);
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt->getDate()->getTimestamp()));
$fdata = json_decode($readfTkt->getContent(), true);
$this->assertNotNull($fdata);
$this->assertEquals($fdata['failure'], 'Tickets are read only.');
......@@ -420,6 +433,7 @@ class TicketAPITest extends TestCase
$this->api->write($tkt);
} catch (InvalidRecordException $e) {
$exceptionThrown = true;
$now = new \DateTime();
// Check the exception
$this->assertEquals(InvalidRecordException::CSTR_READ_ONLY,
$e->getConstraint());
......@@ -449,6 +463,10 @@ class TicketAPITest extends TestCase
$this->assertNotNull($readfTkt);
$this->assertNotNull($readfTkt2);
$this->assertNotNull($readEOSTkt);
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt->getDate()->getTimestamp()));
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt2->getDate()->getTimestamp()));
$fdata = json_decode($readfTkt->getContent(), true);
$this->assertNotNull($fdata);
$this->assertEquals($fdata['failure'], 'Tickets are read only.');
......@@ -484,6 +502,7 @@ class TicketAPITest extends TestCase
$this->api->write($tkt);
} catch (UnicityException $e) {
$exceptionThrown = true;
$now = new \DateTime();
// Check the exception
$this->assertEquals(Ticket::class, $e->getClass());
$this->assertEquals('lines.dispOrder', $e->getField());
......@@ -502,6 +521,8 @@ class TicketAPITest extends TestCase
'number' => 0]);
$this->assertNotNull($readfTkt);
$this->assertNotNull($readEOSTkt);
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt->getDate()->getTimestamp()));
$fdata = json_decode($readfTkt->getContent(), true);
$this->assertNotNull($fdata);
$this->assertEquals('Error: duplicated line n°1',
......@@ -525,6 +546,7 @@ class TicketAPITest extends TestCase
$this->api->write($tkt);
} catch (InvalidFieldException $e) {
$exceptionThrown = true;
$now = new \DateTime();
// Check the exception
$this->assertEquals(InvalidFieldException::CSTR_OPENED_CASH,
$e->getConstraint());
......@@ -550,6 +572,8 @@ class TicketAPITest extends TestCase
'number' => 0]);
$this->assertNotNull($readfTkt);
$this->assertNotNull($readEOSTkt);
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt->getDate()->getTimestamp()));
$fdata = json_decode($readfTkt->getContent(), true);
$this->assertNotNull($fdata);
$this->assertEquals($fdata['failure'], 'Tickets must be assigned to an opened cash session.');
......@@ -575,6 +599,7 @@ class TicketAPITest extends TestCase
$this->api->write($tkt);
} catch (InvalidFieldException $e) {
$exceptionThrown = true;
$now = new \DateTime();
// Check the exception
$this->assertEquals(InvalidFieldException::CSTR_OPENED_CASH,
$e->getConstraint());
......@@ -600,6 +625,8 @@ class TicketAPITest extends TestCase
'number' => 0]);
$this->assertNotNull($readfTkt);
$this->assertNotNull($readEOSTkt);
$this->assertLessThan(3,
abs($now->getTimestamp() - $readfTkt->getDate()->getTimestamp()));
$fdata = json_decode($readfTkt->getContent(), true);
$this->assertNotNull($fdata);
$this->assertEquals($fdata['failure'], 'Tickets must be assigned to an opened cash session.');
......
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