Commit 2d465bee authored by Karamel's avatar Karamel
Browse files

Add perpetual CS. WARNING: CHANGES IN THE DATABASE, see changelogs.

parent 03451efa
......@@ -7,7 +7,10 @@ The semantic of version number is 'Level.Version'. Level is for compatibility be
## [Unreleased]
WARNING: this version includes changes to the database. Please read the changed section carefully.
### Changed
- Perpetual CS is added to cash sessions. Update your databases by running bin/addperpetualcs.php on all accounts. 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.
- 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.
### Fixed
......
<?php
// Import script. Public Domain, CC-0, WTFPL or anything you want.
// Licensed under GPLv3 or any later by Pasteque.
namespace Pasteque\bin;
use \Pasteque\Server\AppContext;
use \Pasteque\Server\API\CashregisterAPI;
use \Pasteque\Server\Model\CashRegister;
use \Pasteque\Server\Model\CashSession;
if ($argc < 2) {
die("addperpetualcs.php <v8 user id>\n"
. " Add the missing perpetual cs field.\n");
}
$v8User = $argv[1];
$projectRoot = dirname(__DIR__);
require_once $projectRoot . '/vendor/autoload.php';
// Set v8
$cfgFile = $projectRoot . '/config/config.ini';
if (!is_readable($cfgFile)) {
// Check for a moved configuration
$envCfgFile = getenv('PT_CONFIG_' . preg_replace('/[^[:alnum:]]/', '_', $projectRoot));
if (($envCfgFile === false) || !is_readable($envCfgFile)) {
die('No config file found');
}
$cfgFile = $envCfgFile;
}
$ptApp = AppContext::loadFromConfig(parse_ini_file($cfgFile));
unset($cfgFile);
$db = $ptApp->getDbModule()->getDatabase($v8User);
if ($db === false) {
die(sprintf("V8 user %s not found\n", $v8User));
}
$ptApp->login($ptApp->getIdentModule()->getUser($v8User));
$em = $ptApp->getDao()->getEntityManager();
$sql = '';
switch ($db['type']) {
case 'postgresql':
case 'mysql':
$sql = 'ALTER TABLE sessions ADD csperpetual DOUBLE PRECISION NOT NULL DEFAULT 0.0;';
break;
break;
case 'sqlite':
$sql = 'ALTER TABLE sessions ADD COLUMN csperpetual DOUBLE PRECISION NOT NULL DEFAULT 0.0;';
break;
default:
die(sprintf("Unknown database type %s\n", $db['type']));
}
$stmt = $em->getConnection()->prepare($sql);
$stmt->execute();
$crAPI = new CashregisterAPI($ptApp->getDao());
$cashRegisters = $crAPI->getAll();
foreach ($cashRegisters as $cr) {
$sessions = $ptApp->getDao()->search(CashSession::class, null, null, null,
'sequence');
$total = 0.0;
foreach ($sessions as $session) {
$session->setCSPerpetual($total + $session->getCS());
$ptApp->getDao()->write($session);
$total = $session->getCSPerpetual();
}
}
$ptApp->getDao()->commit();
$sql = '';
switch ($db['type']) {
case 'postgresql':
case 'mysql':
$sql = 'ALTER TABLE sessions ALTER COLUMN csperpetual DROP DEFAULT';
break;
case 'sqlite':
echo("Warning: The default value for csPerpetual is still there.\n");
break;
default:
die(sprintf("Unknown database type %s\n", $db['type']));
}
if ($sql != '') {
$stmt = $em->getConnection()->prepare($sql);
$stmt->execute();
}
......@@ -49,7 +49,7 @@ class CashSession extends DoctrineMainModel
return ['sequence', 'continuous', 'openDate', 'closeDate',
'openCash', 'closeCash', 'expectedCash',
'ticketCount', 'custCount',
'cs', 'csPeriod', 'csFYear'];
'cs', 'csPeriod', 'csFYear', 'csPerpetual'];
// 'closeType' (optional) imported on close but not exported nor stored.
}
protected static function getAssociationFields() {
......@@ -338,6 +338,18 @@ class CashSession extends DoctrineMainModel
$this->csFYear = round($csFYear, 5);
}
/**
* Consolidated sales total. It is never reset.
* @Column(type="float", nullable= false)
*/
protected $csPerpetual = 0.0;
public function getCsPerpetual() {
return round($this->csPerpetual, 5);
}
public function setCsPerpetual($csPerpetual) {
$this->csPerpetual = round($csPerpetual, 5);
}
/**
* Array of tax totals. It holds the final tax base/amount for each tax.
* @var \Pasteque\CashSessionTax[]
......@@ -515,6 +527,7 @@ class CashSession extends DoctrineMainModel
}
}
// Copy CS sums
$this->setCSPerpetual($prevCashSession->getCSPerpetual());
switch ($prevCashSession->closeType) {
case static::CLOSE_SIMPLE:
// Keep period
......@@ -536,6 +549,7 @@ class CashSession extends DoctrineMainModel
if (empty($struct['closeDate'])) {
unset($struct['csPeriod']);
unset($struct['csFYear']);
unset($struct['csPerpetual']);
unset($struct['taxes']);
} else {
// Save and unset taxes to merge data manually
......@@ -543,6 +557,22 @@ class CashSession extends DoctrineMainModel
unset($struct['taxes']);
}
parent::merge($struct, $dao);
// Compute csPerpetual if it was not given (by older clients)
if (empty($struct['csPerpetual']) && !empty($struct['closeDate'])) {
if ($this->sequence == 1) {
$this->setCSPerpetual($this->getCS());
} else {
$prevSearch = $dao->search(static::class,
[new DAOCondition('cashRegister', '=',
$this->getCashRegister()),
new DAOCondition('sequence', '=',
$this->getSequence() - 1)]);
$previousSession = $prevSearch[0];
$this->setCSPerpetual($previousSession->getCSPerpetual()
+ $this->getCS());
}
}
// Merge taxes
if ($structTaxes !== null && !empty($structTaxes)) {
foreach ($structTaxes as $sTax) {
$merged = false;
......
......@@ -151,7 +151,6 @@ class CashsessionAPITest extends TestCase
$this->assertTrue(DateUtils::equals($readfTkt->getDate(), $readEOSTkt->getDate()));
$this->assertTrue($readfTkt->checkSignature(null));
$this->assertTrue($readEOSTkt->checkSignature($readfTkt));
}
/** Open the session, set some cs and close. */
......@@ -167,6 +166,7 @@ class CashsessionAPITest extends TestCase
$session->setCS($cs);
$session->setCSPeriod($session->getCSPeriod() + $cs);
$session->setCSFYear($session->getCSFYear() + $cs);
$session->setCSPerpetual($session->getCSPerpetual() + $cs);
$tax = null;
if (count($session->getTaxes()) > 0) {
$tax = $session->getTaxes()->get(0);
......@@ -197,6 +197,7 @@ class CashsessionAPITest extends TestCase
$this->assertEquals(10.0, $session->getCS());
$this->assertEquals(10.0, $session->getCSPeriod());
$this->assertEquals(10.0, $session->getCSFYear());
$this->assertEquals(10.0, $session->getCSPerpetual());
$this->assertEquals(1, count($session->getTaxes()));
$tax = $session->getTaxes()->get(0);
$this->assertEquals(10.0, $tax->getBase());
......@@ -211,6 +212,7 @@ class CashsessionAPITest extends TestCase
$this->assertNull($next->getCS());
$this->assertEquals(10.0, $next->getCSPeriod());
$this->assertEquals(10.0, $next->getCSFYear());
$this->assertEquals(10.0, $next->getCSPerpetual());
$this->assertEquals(1, count($next->getTaxes()));
$tax = $next->getTaxes()->get(0);
$this->assertEquals(0.0, $tax->getBase());
......@@ -224,6 +226,7 @@ class CashsessionAPITest extends TestCase
$this->assertEquals(20.0, $next->getCS());
$this->assertEquals(30.0, $next->getCSPeriod());
$this->assertEquals(30.0, $next->getCSFYear());
$this->assertEquals(30.0, $next->getCSPerpetual());
$this->assertEquals(1, count($next->getTaxes()));
$tax = $next->getTaxes()->get(0);
$this->assertEquals(20.0, $tax->getBase());
......@@ -237,6 +240,7 @@ class CashsessionAPITest extends TestCase
$this->assertNull($next2->getCS());
$this->assertEquals(30.0, $next2->getCSPeriod());
$this->assertEquals(30.0, $next2->getCSFYear());
$this->assertEquals(30.0, $next2->getCSPerpetual());
$this->assertEquals(1, count($next2->getTaxes()));
$tax = $next2->getTaxes()->get(0);
$this->assertEquals(0.0, $tax->getBase());
......@@ -256,6 +260,7 @@ class CashsessionAPITest extends TestCase
$this->assertEquals(10.0, $session->getCS());
$this->assertEquals(10.0, $session->getCSPeriod());
$this->assertEquals(10.0, $session->getCSFYear());
$this->assertEquals(10.0, $session->getCSPerpetual());
$this->assertEquals(1, count($session->getTaxes()));
$tax = $session->getTaxes()->get(0);
$this->assertEquals(10.0, $tax->getBase());
......@@ -270,6 +275,7 @@ class CashsessionAPITest extends TestCase
$this->assertNull($next->getCS());
$this->assertEquals(0.0, $next->getCSPeriod());
$this->assertEquals(10.0, $next->getCSFYear());
$this->assertEquals(10.0, $next->getCSPerpetual());
$this->assertEquals(1, count($next->getTaxes()));
$tax = $next->getTaxes()->get(0);
$this->assertEquals(0.0, $tax->getBase());
......@@ -283,6 +289,7 @@ class CashsessionAPITest extends TestCase
$this->assertEquals(20.0, $next->getCS());
$this->assertEquals(20.0, $next->getCSPeriod());
$this->assertEquals(30.0, $next->getCSFYear());
$this->assertEquals(30.0, $next->getCSPerpetual());
$this->assertEquals(1, count($next->getTaxes()));
$tax = $next->getTaxes()->get(0);
$this->assertEquals(20.0, $tax->getBase());
......@@ -315,6 +322,7 @@ class CashsessionAPITest extends TestCase
$this->assertEquals(10.0, $session->getCS());
$this->assertEquals(10.0, $session->getCSPeriod());
$this->assertEquals(10.0, $session->getCSFYear());
$this->assertEquals(10.0, $session->getCSPerpetual());
$this->assertEquals(1, count($session->getTaxes()));
$tax = $session->getTaxes()->get(0);
$this->assertEquals(10.0, $tax->getBase());
......@@ -329,6 +337,7 @@ class CashsessionAPITest extends TestCase
$this->assertEquals(0.0, $next->getCS());
$this->assertEquals(0.0, $next->getCSPeriod());
$this->assertEquals(0.0, $next->getCSFYear());
$this->assertEquals(10.0, $next->getCSPerpetual());
$this->assertEquals(0, count($next->getTaxes()));
}
......
......@@ -350,6 +350,7 @@ class CashSessionTest extends TestCase
$session = $this->initEmptySession();
$session->setCSPeriod(10.0);
$session->setCSFYear(20.0);
$session->setCSPerpetual(30.0);
$tax = new CashSessionTax();
$tax->setTax($this->tax);
$tax->setTaxRate($this->tax->getRate());
......@@ -365,6 +366,7 @@ class CashSessionTest extends TestCase
$struct = $this->emptyStruct();
$struct['csPeriod'] = 15.0;
$struct['csFYear'] = 25.0;
$struct['csPerpetual'] = 35.0;
$struct['taxes'] = [['tax' => $this->tax->getId(),
'base' => 15.0, 'amount' => 1.5,
'basePeriod' => 25, 'amountPeriod' => 2.5,
......@@ -372,6 +374,7 @@ class CashSessionTest extends TestCase
$session->merge($struct, $this->dao);
$this->assertEquals(10.0, $session->getCSPeriod());
$this->assertEquals(20.0, $session->getCSFYear());
$this->assertEquals(30.0, $session->getCSPerpetual());
$this->assertEquals(1, count($session->getTaxes()));
$taxLine = $session->getTaxes()->get(0);
$this->assertEquals(10.0, $taxLine->getBase());
......@@ -401,6 +404,7 @@ class CashSessionTest extends TestCase
$struct = $this->emptyStruct();
$struct['csPeriod'] = 20.0;
$struct['csFYear'] = 30.0;
$struct['csPerpetual'] = 40;
$struct['closeDate'] = DateUtils::toTimestamp(new \DateTime());
$struct['taxes'] = [['tax' => $this->tax->getId(),
'base' => 15.0, 'amount' => 1.5,
......@@ -414,6 +418,119 @@ class CashSessionTest extends TestCase
$session->merge($struct, $this->dao);
$this->assertEquals(20.0, $session->getCSPeriod());
$this->assertEquals(30.0, $session->getCSFYear());
$this->assertEquals(40.0, $session->getCSPerpetual());
$this->assertEquals(2, count($session->getTaxes()));
$taxLine = $session->getTaxes()->get(0);
$this->assertEquals($this->tax->getId(), $taxLine->getTax()->getId());
$this->assertEquals(15.0, $taxLine->getBase());
$this->assertEquals(1.5, $taxLine->getAmount());
$this->assertEquals(25, $taxLine->getBasePeriod());
$this->assertEquals(2.5, $taxLine->getAmountPeriod());
$this->assertEquals(35.0, $taxLine->getBaseFYear());
$this->assertEquals(3.5, $taxLine->getAmountFYear());
$taxLine2 = $session->getTaxes()->get(1);
$this->assertEquals($this->tax2->getId(), $taxLine2->getTax()->getId());
$this->assertEquals(5.0, $taxLine2->getBase());
$this->assertEquals(1.0, $taxLine2->getAmount());
$this->assertEquals(6, $taxLine2->getBasePeriod());
$this->assertEquals(1.2, $taxLine2->getAmountPeriod());
$this->assertEquals(7.0, $taxLine2->getBaseFYear());
$this->assertEquals(1.4, $taxLine2->getAmountFYear());
}
public function testMergeSumsNoPerpetualFirst() {
$session = $this->initEmptySession();
$session->setCS(5.0);
$session->setCSPeriod(10.0);
$session->setCSFYear(20.0);
$tax = new CashSessionTax();
$tax->setTax($this->tax);
$tax->setTaxRate($this->tax->getRate());
$tax->setBase(10.0);
$tax->setAmount(1.0);
$tax->setBasePeriod(20.0);
$tax->setAmountPeriod(2.0);
$tax->setBaseFYear(30.0);
$tax->setAmountFYear(3.0);
$session->addTax($tax);
$this->dao->write($session);
$this->dao->commit();
$struct = $this->emptyStruct();
$struct['cs'] = 10.0;
$struct['csPeriod'] = 20.0;
$struct['csFYear'] = 30.0;
$struct['closeDate'] = DateUtils::toTimestamp(new \DateTime());
$struct['taxes'] = [['tax' => $this->tax->getId(),
'base' => 15.0, 'amount' => 1.5,
'basePeriod' => 25, 'amountPeriod' => 2.5,
'baseFYear' => 35, 'amountFYear' => 3.5],
['tax' => $this->tax2->getId(),
'base' => 5.0, 'amount' => 1.0,
'basePeriod' => 6.0, 'amountPeriod' => 1.2,
'baseFYear' => 7.0, 'amountFYear' => 1.4]];
$session = new CashSession();
$session->merge($struct, $this->dao);
$this->assertEquals(10.0, $session->getCS());
$this->assertEquals(20.0, $session->getCSPeriod());
$this->assertEquals(30.0, $session->getCSFYear());
$this->assertEquals(10.0, $session->getCSPerpetual());
$this->assertEquals(2, count($session->getTaxes()));
$taxLine = $session->getTaxes()->get(0);
$this->assertEquals($this->tax->getId(), $taxLine->getTax()->getId());
$this->assertEquals(15.0, $taxLine->getBase());
$this->assertEquals(1.5, $taxLine->getAmount());
$this->assertEquals(25, $taxLine->getBasePeriod());
$this->assertEquals(2.5, $taxLine->getAmountPeriod());
$this->assertEquals(35.0, $taxLine->getBaseFYear());
$this->assertEquals(3.5, $taxLine->getAmountFYear());
$taxLine2 = $session->getTaxes()->get(1);
$this->assertEquals($this->tax2->getId(), $taxLine2->getTax()->getId());
$this->assertEquals(5.0, $taxLine2->getBase());
$this->assertEquals(1.0, $taxLine2->getAmount());
$this->assertEquals(6, $taxLine2->getBasePeriod());
$this->assertEquals(1.2, $taxLine2->getAmountPeriod());
$this->assertEquals(7.0, $taxLine2->getBaseFYear());
$this->assertEquals(1.4, $taxLine2->getAmountFYear());
}
public function testMergeSumsNoPerpetualNext() {
$session = $this->initEmptySession();
$session->setCS(5.0);
$session->setCSPeriod(10.0);
$session->setCSFYear(20.0);
$session->setCSPerpetual(30.0);
$tax = new CashSessionTax();
$tax->setTax($this->tax);
$tax->setTaxRate($this->tax->getRate());
$tax->setBase(10.0);
$tax->setAmount(1.0);
$tax->setBasePeriod(20.0);
$tax->setAmountPeriod(2.0);
$tax->setBaseFYear(30.0);
$tax->setAmountFYear(3.0);
$session->addTax($tax);
$this->dao->write($session);
$this->dao->commit();
$struct = $this->emptyStruct();
$struct['sequence'] = 2;
$struct['cs'] = 10.0;
$struct['csPeriod'] = 20.0;
$struct['csFYear'] = 30.0;
$struct['closeDate'] = DateUtils::toTimestamp(new \DateTime());
$struct['taxes'] = [['tax' => $this->tax->getId(),
'base' => 15.0, 'amount' => 1.5,
'basePeriod' => 25, 'amountPeriod' => 2.5,
'baseFYear' => 35, 'amountFYear' => 3.5],
['tax' => $this->tax2->getId(),
'base' => 5.0, 'amount' => 1.0,
'basePeriod' => 6.0, 'amountPeriod' => 1.2,
'baseFYear' => 7.0, 'amountFYear' => 1.4]];
$session = new CashSession();
$session->merge($struct, $this->dao);
$this->assertEquals(10.0, $session->getCS());
$this->assertEquals(20.0, $session->getCSPeriod());
$this->assertEquals(30.0, $session->getCSFYear());
$this->assertEquals(40.0, $session->getCSPerpetual());
$this->assertEquals(2, count($session->getTaxes()));
$taxLine = $session->getTaxes()->get(0);
$this->assertEquals($this->tax->getId(), $taxLine->getTax()->getId());
......
......@@ -40,6 +40,7 @@ function assertSessionModelEqModel($m1, $m2, $ut) {
$ut->assertEquals($m1->getCs(), $m2->getCs());
$ut->assertEquals($m1->getCsPeriod(), $m2->getCsPeriod());
$ut->assertEquals($m1->getCsFYear(), $m2->getCsFYear());
$ut->assertEquals($m1->getCsPerpetual(), $m2->getCsPerpetual());
// Check payments
$ut->assertEquals(count($m1->getPayments()), count($m2->getPayments()));
for ($i = 0; $i < count($m1->getPayments()); $i++) {
......@@ -109,6 +110,7 @@ function assertSessionModelEqStruct($model, $struct, $ut) {
$ut->assertEquals($model->getCs(), $struct['cs']);
$ut->assertEquals($model->getCsPeriod(), $struct['csPeriod']);
$ut->assertEquals($model->getCsFYear(), $struct['csFYear']);
$ut->assertEquals($model->getCsPerpetual(), $struct['csPerpetual']);
// Check payments
$ut->assertEquals(count($model->getPayments()), count($struct['payments']));
for ($i = 0; $i < count($struct['payments']); $i++) {
......
......@@ -301,6 +301,7 @@ class HttpCashSessionTest extends TestCase
$structSess['cs'] = 1.1;
$structSess['csPeriod'] = 1.1;
$structSess['csFYear'] = 1.1;
$structSess['csPerpetual'] = 1.1;
$structSess['payments'] = [
['paymentMode' => $this->pm->getId(), 'currency' => $this->curr->getId(),
'amount' => 1.1, 'currencyAmount' => 1.1]
......@@ -328,5 +329,123 @@ class HttpCashSessionTest extends TestCase
$snap = $this->dao->readSnapshot(CashSession::class, $this->session->getId());
assertSessionModelEqStruct($snap, $structSess, $this);
assertSessionModelEqStruct($snap, $data, $this);
}
/** @depends testClose */
public function testCloseNoPerpetualFirst() {
// Open the session and add a ticket
$this->session->setOpenDate(new \DateTime('2018-01-01 10:00'));
$this->session->setOpenCash(200.0);
$this->dao->write($this->session);
$this->dao->commit();
$tkt = ticketNew($this->session->getCashRegister(), $this->session->getSequence(), 1, '2018-01-01 10:08', $this->user);
ticketAddLine($tkt, $this->prd, 1);
ticketAddPayment($tkt, $this->pm, $this->curr, 1.1);
ticketFinalize($tkt);
$this->dao->write($tkt);
$this->dao->commit();
$structSess = $this->session->toStruct();
$structSess['closeDate'] = '2018-01-01 11:00';
$structSess['closeCash'] = 201.1;
$structSess['expectedCash'] = 201.1;
$structSess['closeType'] = CashSession::CLOSE_SIMPLE;
$structSess['cs'] = 1.1;
$structSess['csPeriod'] = 1.1;
$structSess['csFYear'] = 1.1;
$structSess['payments'] = [
['paymentMode' => $this->pm->getId(), 'currency' => $this->curr->getId(),
'amount' => 1.1, 'currencyAmount' => 1.1]
];
$structSess['taxes'] = [
['tax' => $this->tax->getId(), 'taxRate' => $this->tax->getRate(),
'base' => 1.0, 'amount' => 0.1,
'basePeriod' => 1.0, 'amountPeriod' => 0.1,
'baseFYear' => 1.0, 'amountFYear' => 0.1]
];
$structSess['catSales'] = [
['reference' => $this->cat->getReference(), 'label' => $this->cat->getLabel(), 'amount' => 1.0]
];
$structSess['catTaxes'] = [
['tax' => $this->tax->getId(), 'reference' => $this->cat->getReference(), 'label' => $this->cat->getLabel(), 'base' => 1.0, 'amount' => 0.1]
];
curl_setopt($this->curl, CURLOPT_URL, apiUrl('api/cash'));
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($this->curl, CURLOPT_POSTFIELDS,
'session=' . json_encode($structSess));
$resp = curl_exec($this->curl);
$this->assertEquals(200, curl_getinfo($this->curl, CURLINFO_HTTP_CODE));
$data = json_decode($resp, true);
$this->assertNotNull($data);
$snap = $this->dao->readSnapshot(CashSession::class, $this->session->getId());
$structSess['csPerpetual'] = 1.1; // set to check equality
assertSessionModelEqStruct($snap, $structSess, $this);
assertSessionModelEqStruct($snap, $data, $this);
}
/** @depends testClose */
public function testCloseNoPerpetualNext() {
// Open the session and add a ticket
$this->session->setOpenDate(new \DateTime('2018-01-01 10:00'));
$this->session->setOpenCash(200.0);
$this->session->setCS(10.0);
$this->session->setCSPeriod(10.0);
$this->session->setCSFYear(10.0);
$this->session->setCSPerpetual(10.0);
$this->session->setCloseDate(new \DateTime('2018-01-01 13:00'));
$this->dao->write($this->session);
$this->dao->commit();
$session2 = new CashSession();
$session2->setCashRegister($this->cash);
$session2->setSequence(2);
$session2->setOpenDate(new \DateTime('2018-01-02 11:30'));
$session2->setCSPeriod(10.0);
$session2->setCSFYear(10.0);
$session2->setCSPerpetual(10.0);
$this->dao->write($session2);
$this->dao->commit();
$tkt = ticketNew($this->session->getCashRegister(),
$session2->getSequence(), 1, '2018-01-02 12:08', $this->user);
ticketAddLine($tkt, $this->prd, 1);
ticketAddPayment($tkt, $this->pm, $this->curr, 1.1);
ticketFinalize($tkt);
$this->dao->write($tkt);
$this->dao->commit();
$structSess = $session2->toStruct();
$structSess['closeDate'] = '2018-01-02 15:00';
$structSess['closeCash'] = 201.1;
$structSess['expectedCash'] = 201.1;
$structSess['closeType'] = CashSession::CLOSE_SIMPLE;
$structSess['cs'] = 1.1;
$structSess['csPeriod'] = 11.1;
$structSess['csFYear'] = 11.1;
unset($structSess['csPerpetual']);
$structSess['payments'] = [
['paymentMode' => $this->pm->getId(), 'currency' => $this->curr->getId(),
'amount' => 1.1, 'currencyAmount' => 1.1]
];
$structSess['taxes'] = [
['tax' => $this->tax->getId(), 'taxRate' => $this->tax->getRate(),
'base' => 1.0, 'amount' => 0.1,
'basePeriod' => 1.0, 'amountPeriod' => 0.1,
'baseFYear' => 1.0, 'amountFYear' => 0.1]
];
$structSess['catSales'] = [
['reference' => $this->cat->getReference(), 'label' => $this->cat->getLabel(), 'amount' => 1.0]
];
$structSess['catTaxes'] = [
['tax' => $this->tax->getId(), 'reference' => $this->cat->getReference(), 'label' => $this->cat->getLabel(), 'base' => 1.0, 'amount' => 0.1]
];
curl_setopt($this->curl, CURLOPT_URL, apiUrl('api/cash'));
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($this->curl, CURLOPT_POSTFIELDS,
'session=' . json_encode($structSess));
$resp = curl_exec($this->curl);
$this->assertEquals(200, curl_getinfo($this->curl, CURLINFO_HTTP_CODE));
$data = json_decode($resp, true);
$this->assertNotNull($data);
$snap = $this->dao->readSnapshot(CashSession::class, $session2->getId());
$structSess['csPerpetual'] = 11.1; // set to check equality
assertSessionModelEqStruct($snap, $structSess, $this);
assertSessionModelEqStruct($snap, $data, $this);
}
}
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