Commit f5b7304c authored by Karamel's avatar Karamel
Browse files

Update ticket prices for a clearer name and avoid rounding issues.

parent 78362d58
CREATE TABLE paymentmodes (id INT AUTO_INCREMENT NOT NULL, reference VARCHAR(255) NOT NULL, `label` VARCHAR(255) NOT NULL, backLabel VARCHAR(255) NOT NULL, type INT NOT NULL, hasImage TINYINT(1) NOT NULL, disp_order INT NOT NULL, visible TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_263B9843AEA34913 (reference), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE resources (`label` VARCHAR(255) NOT NULL, type INT NOT NULL, content LONGBLOB NOT NULL, PRIMARY KEY(`label`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE tickets (id INT AUTO_INCREMENT NOT NULL, cashregister_id INT NOT NULL, user_id INT NOT NULL, customer_id INT DEFAULT NULL, tariffarea_id INT DEFAULT NULL, discountprofile_id INT DEFAULT NULL, sequence INT NOT NULL, number INT NOT NULL, date DATETIME NOT NULL, custCount INT DEFAULT NULL, discountRate DOUBLE PRECISION NOT NULL, price DOUBLE PRECISION NOT NULL, totalAmount DOUBLE PRECISION NOT NULL, discountPrice DOUBLE PRECISION NOT NULL, discountTotal DOUBLE PRECISION NOT NULL, custBalance DOUBLE PRECISION NOT NULL, INDEX IDX_54469DF49ED3320C (cashregister_id), INDEX IDX_54469DF4A76ED395 (user_id), INDEX IDX_54469DF49395C3F3 (customer_id), INDEX IDX_54469DF454EC7A8F (tariffarea_id), INDEX IDX_54469DF4E1BC3B58 (discountprofile_id), UNIQUE INDEX ticket_index (cashregister_id, number), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE tickets (id INT AUTO_INCREMENT NOT NULL, cashregister_id INT NOT NULL, user_id INT NOT NULL, customer_id INT DEFAULT NULL, tariffarea_id INT DEFAULT NULL, discountprofile_id INT DEFAULT NULL, sequence INT NOT NULL, number INT NOT NULL, date DATETIME NOT NULL, custCount INT DEFAULT NULL, discountRate DOUBLE PRECISION NOT NULL, price DOUBLE PRECISION DEFAULT NULL, taxedPrice DOUBLE PRECISION DEFAULT NULL, finalPrice DOUBLE PRECISION NOT NULL, finalTaxedPrice DOUBLE PRECISION NOT NULL, custBalance DOUBLE PRECISION NOT NULL, INDEX IDX_54469DF49ED3320C (cashregister_id), INDEX IDX_54469DF4A76ED395 (user_id), INDEX IDX_54469DF49395C3F3 (customer_id), INDEX IDX_54469DF454EC7A8F (tariffarea_id), INDEX IDX_54469DF4E1BC3B58 (discountprofile_id), UNIQUE INDEX ticket_index (cashregister_id, number), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE floors (id INT AUTO_INCREMENT NOT NULL, `label` VARCHAR(255) NOT NULL, image LONGBLOB DEFAULT NULL, disp_order INT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE compositiongroups (id INT AUTO_INCREMENT NOT NULL, product_id INT NOT NULL, `label` VARCHAR(255) NOT NULL, disp_order INT NOT NULL, image LONGBLOB DEFAULT NULL, INDEX IDX_C72568934584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE sessioncustbalances (cashsession_id INT NOT NULL, customer_id INT NOT NULL, balance DOUBLE PRECISION NOT NULL, INDEX IDX_9D3CBD8BC914703E (cashsession_id), INDEX IDX_9D3CBD8B9395C3F3 (customer_id), PRIMARY KEY(cashsession_id, customer_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
......@@ -16,7 +16,7 @@ CREATE TABLE tariffareaprices (tariffarea_id INT NOT NULL, product_id INT NOT NU
CREATE TABLE compositionproducts (compositiongroup_id INT NOT NULL, product_id INT NOT NULL, disp_order INT NOT NULL, INDEX IDX_DA85AC5F976B2F42 (compositiongroup_id), INDEX IDX_DA85AC5F4584665A (product_id), PRIMARY KEY(compositiongroup_id, product_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE cashregisters (id INT AUTO_INCREMENT NOT NULL, reference VARCHAR(255) NOT NULL, `label` VARCHAR(255) NOT NULL, nextTicketId INT NOT NULL, nextSessionId INT NOT NULL, UNIQUE INDEX UNIQ_4DC8569BAEA34913 (reference), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE sessionpayments (cashsession_id INT NOT NULL, paymentmode_id INT NOT NULL, currency_id INT NOT NULL, amount DOUBLE PRECISION NOT NULL, currencyAmount DOUBLE PRECISION NOT NULL, INDEX IDX_342F815C914703E (cashsession_id), INDEX IDX_342F815ABEEF95F (paymentmode_id), INDEX IDX_342F81538248176 (currency_id), PRIMARY KEY(cashsession_id, paymentmode_id, currency_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE ticketlines (ticket_id INT NOT NULL, product_id INT DEFAULT NULL, tax_id INT NOT NULL, dispOrder INT NOT NULL, productLabel VARCHAR(255) NOT NULL, unitPrice DOUBLE PRECISION NOT NULL, quantity DOUBLE PRECISION NOT NULL, price DOUBLE PRECISION NOT NULL, taxRate DOUBLE PRECISION NOT NULL, taxAmount DOUBLE PRECISION NOT NULL, totalAmount DOUBLE PRECISION NOT NULL, discountRate DOUBLE PRECISION NOT NULL, discountPrice DOUBLE PRECISION NOT NULL, discountTax DOUBLE PRECISION NOT NULL, discountTotal DOUBLE PRECISION NOT NULL, INDEX IDX_20FFE9B5700047D2 (ticket_id), INDEX IDX_20FFE9B54584665A (product_id), INDEX IDX_20FFE9B5B2A824D8 (tax_id), PRIMARY KEY(ticket_id, dispOrder)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE ticketlines (ticket_id INT NOT NULL, product_id INT DEFAULT NULL, tax_id INT NOT NULL, dispOrder INT NOT NULL, productLabel VARCHAR(255) NOT NULL, unitPrice DOUBLE PRECISION DEFAULT NULL, taxedUnitPrice DOUBLE PRECISION DEFAULT NULL, quantity DOUBLE PRECISION NOT NULL, price DOUBLE PRECISION DEFAULT NULL, taxedPrice DOUBLE PRECISION NOT NULL, taxRate DOUBLE PRECISION NOT NULL, discountRate DOUBLE PRECISION NOT NULL, finalPrice DOUBLE PRECISION DEFAULT NULL, finalTaxedPrice DOUBLE PRECISION DEFAULT NULL, INDEX IDX_20FFE9B5700047D2 (ticket_id), INDEX IDX_20FFE9B54584665A (product_id), INDEX IDX_20FFE9B5B2A824D8 (tax_id), PRIMARY KEY(ticket_id, dispOrder)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE sessions (id INT AUTO_INCREMENT NOT NULL, cashregister_id INT NOT NULL, sequence INT NOT NULL, continuous TINYINT(1) NOT NULL, openDate DATETIME DEFAULT NULL, closeDate DATETIME DEFAULT NULL, openCash DOUBLE PRECISION DEFAULT NULL, closeCash DOUBLE PRECISION DEFAULT NULL, expectedCash DOUBLE PRECISION DEFAULT NULL, ticketCount INT DEFAULT NULL, custCount INT DEFAULT NULL, cs DOUBLE PRECISION DEFAULT NULL, csPeriod DOUBLE PRECISION NOT NULL, csFYear DOUBLE PRECISION NOT NULL, INDEX IDX_9A609D139ED3320C (cashregister_id), UNIQUE INDEX session_index (cashregister_id, sequence), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE ticketpayments (ticket_id INT NOT NULL, paymentmode_id INT NOT NULL, currency_id INT NOT NULL, dispOrder INT NOT NULL, amount DOUBLE PRECISION NOT NULL, currencyAmount DOUBLE PRECISION NOT NULL, INDEX IDX_1D56231D700047D2 (ticket_id), INDEX IDX_1D56231DABEEF95F (paymentmode_id), INDEX IDX_1D56231D38248176 (currency_id), PRIMARY KEY(ticket_id, dispOrder)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE categories (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, reference VARCHAR(255) NOT NULL, `label` VARCHAR(255) NOT NULL, hasImage TINYINT(1) NOT NULL, disp_order INT NOT NULL, UNIQUE INDEX UNIQ_3AF34668AEA34913 (reference), INDEX IDX_3AF34668727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
......
......@@ -209,6 +209,7 @@ class CashsessionAPI extends APIHelper implements API
$summaryCusts = [];
foreach ($tickets as $tkt) {
$ticketCount++;
$cs += $tkt->getFinalPrice();
if (!empty($tkt->getCustCount())) {
if ($custCount === null) {
$custCount = $tkt->getCustCount();
......@@ -241,36 +242,51 @@ class CashsessionAPI extends APIHelper implements API
}
$summaryCusts[$custId]['balance'] += $tkt->getCustBalance();
}
// Line sums
$tktLines = $tkt->getLines();
foreach ($tktLines as $line) {
if ($line->getProduct() === null
|| (!$line->getProduct()->isPrepay())) {
// Add in CS only if not a prepay refill
$cs += $line->getDiscountPrice();
}
// Tax
$taxId = $line->getTax()->getId();
// Tax sums
$tktTax = $tkt->getTaxes();
foreach ($tktTax as $tax) {
$taxId = $tax->getTax()->getId();
if (!isset($summaryTaxes[$taxId])) {
$summaryTaxes[$taxId] = ['tax' => $taxId, // desktop
'base' => 0.0,
'amount' => 0.0];
}
$summaryTaxes[$taxId]['base'] += $line->getDiscountPrice();
$summaryTaxes[$taxId]['amount'] += $line->getDiscountTax();
$summaryTaxes[$taxId]['base'] += $tax->getBase();
$summaryTaxes[$taxId]['amount'] += $tax->getAmount();
}
// Line sums
$tktLines = $tkt->getLines();
foreach ($tktLines as $line) {
if ($line->getProduct() !== null
&& ($line->getProduct()->isPrepay())) {
// Remove from CS if it is a prepayment refill
if ($line->getFinalTaxedPrice() !== null) {
$cs -= $line->getFinalTaxedPrice();
} else {
$cs -= $line->getFinalPrice(); // it should be the same
}
// And don't include it in category sales and taxes
// It is already set in customer balances
continue;
}
// Category
// This one may give rounding issues. The accounting service
// will deal with it.
$catId = ($line->getProduct() != null)
? $line->getProduct()->getCategory()->getId()
: 0;
if (!isset($summaryCats[$catId])) {
$summaryCats[$catId] = ['category' => $catId, // desktop
'amount' => 0.0, 'taxes' => []];
'amount' => 0.0];
}
$summaryCats[$catId]['amount'] += $line->getDiscountPrice();
if (!isset($summaryCats[$catId]['taxes'][$taxId])) {
$summaryCats[$catId]['taxes'][$taxId] = ['tax' => $taxId,
'base' => 0.0, 'amount' => 0.0];
$finalPrice = $line->getFinalPrice();
if ($finalPrice === null) {
// This is where rounding issues come.
$finalPrice = $line->getFinalTaxedPrice()
/ (1.0 + $line->getTax()->getRate());
$finalPrice = round($finalPrice, 2);
}
$summaryCats[$catId]['amount'] += $finalPrice;
// Category tax
if (!isset($summaryCatTaxes[$catId])) {
$summaryCatTaxes[$catId] = [];
......@@ -286,8 +302,9 @@ class CashsessionAPI extends APIHelper implements API
'reference' => $ref, 'label' => $label,
'base' => 0.0, 'amount' => 0.0];
}
$summaryCatTaxes[$catId][$taxId]['base'] += $line->getDiscountPrice();
$summaryCatTaxes[$catId][$taxId]['amount'] += $line->getDiscountTax();
$summaryCatTaxes[$catId][$taxId]['base'] += $finalPrice;
$taxAmount = round($finalPrice * $line->getTax()->getRate(), 2);
$summaryCatTaxes[$catId][$taxId]['amount'] += $taxAmount;
}
} // foreach $tickets end
foreach ($summaryPmts as $pmtRef => $sum) {
......
......@@ -300,16 +300,16 @@ class Product extends DoctrineModel
public function getTaxedPrice() {
$tax = $this->getTax();
$price = $this->getPriceSell();
return round($price * (1 + $tax->getRate()), 5);
return round($price * (1 + $tax->getRate()), 2);
}
public function getTaxValue() {
return round($this->getTaxedPrice() - $this->getPriceSell(), 5);
return round($this->getTaxedPrice() - $this->getPriceSell(), 2);
}
public function toStruct() {
$struct = parent::toStruct();
$struct['taxPrice'] = $this->getTaxedPrice();
$struct['taxedPrice'] = $this->getTaxedPrice();
$struct['taxValue'] = $this->getTaxValue();
if ($this->isPrepay()) {
// Remove irrelevent fields
......
......@@ -36,8 +36,9 @@ use \Pasteque\Server\System\DAO\DoctrineModel;
class Ticket extends DoctrineModel
{
public function getDirectFieldNames() {
return ['sequence', 'number', 'date', 'custCount', 'discountRate',
'price', 'totalAmount', 'discountPrice', 'discountTotal',
return ['sequence', 'number', 'date', 'custCount',
'price', 'taxedPrice',
'discountRate', 'finalPrice', 'finalTaxedPrice',
'custBalance'];
}
public function getAssociationFields() {
......@@ -283,55 +284,67 @@ public function getPayments() { return $this->payments; }
}
/**
* Price without price nor ticket discount.
* Price without taxes nor ticket discount.
* It is null when taxedPrice is set.
* @var float
* @SWG\Property()
* @Column(type="float")
* @Column(type="float", nullable=true)
*/
protected $price;
public function getPrice() { return round($this->price, 5); }
protected $price = null;
public function getPrice() {
if ($this->price === null) { return null; }
else { return round($this->price, 2); }
}
public function setPrice($price) {
$this->price = round($price, 5);
if ($price === null) { $this->price = null; }
else { $this->price = round($price, 2); }
}
/**
* Total price with tax before ticket discount.
* Price without taxes nor ticket discount.
* It is null when price is set.
* @var float
* @SWG\Property()
* @Column(type="float")
* @Column(type="float", nullable=true)
*/
protected $totalAmount;
public function getTotalAmount() { return round($this->totalAmount, 5); }
public function setTotalAmount($totalAmount) {
$this->totalAmount = round($totalAmount, 5);
protected $taxedPrice = null;
public function getTaxedPrice() {
if ($this->taxedPrice === null) { return null; }
else { return round($this->taxedPrice, 2); }
}
public function setTaxedPrice($taxedPrice) {
if ($taxedPrice === null) { $this->taxedPrice = null; }
else { $this->taxedPrice = round($taxedPrice, 2); }
}
/**
* Total price without taxes with discount rate.
* It is never null.
* @var float
* @SWG\Property()
* @Column(type="float")
*/
protected $discountPrice;
public function getDiscountPrice() {
return round($this->discountPrice, 5);
protected $finalPrice;
public function getFinalPrice() {
return round($this->finalPrice, 2);
}
public function setDiscountPrice($discountPrice) {
$this->discountPrice = round($discountPrice, 5);
public function setFinalPrice($finalPrice) {
$this->finalPrice = round($finalPrice, 2);
}
/**
* Total price with taxes and discount rate.
* It is never null.
* @var float
* @SWG\Property()
* @Column(type="float")
*/
protected $discountTotal;
public function getDiscountTotal() {
return round($this->discountTotal, 5);
protected $finalTaxedPrice;
public function getFinalTaxedPrice() {
return round($this->finalTaxedPrice, 2);
}
public function setDiscountTotal($discountTotal) {
$this->discountTotal = round($discountTotal, 5);
public function setFinalTaxedPrice($finalTaxedPrice) {
$this->finalTaxedPrice = round($finalTaxedPrice, 2);
}
/**
......@@ -342,10 +355,10 @@ public function getPayments() { return $this->payments; }
*/
protected $custBalance = 0.0;
public function getCustBalance() {
return round($this->custBalance, 5);
return round($this->custBalance, 2);
}
public function setCustBalance($custBalance) {
$this->custBalance = round($custBalance, 5);
$this->custBalance = round($custBalance, 2);
}
public function toStruct() {
......
......@@ -36,9 +36,11 @@ use \Pasteque\Server\System\DAO\DoctrineModel;
class TicketLine extends DoctrineModel // Embedded class
{
public function getDirectFieldNames() {
return ['dispOrder', 'productLabel', 'unitPrice', 'quantity', 'price',
'taxRate', 'taxAmount', 'totalAmount', 'discountRate',
'discountPrice', 'discountTax', 'discountTotal' ];
return ['dispOrder', 'productLabel',
'unitPrice', 'taxedUnitPrice',
'quantity', 'price', 'taxedPrice',
'taxRate',
'discountRate', 'finalPrice', 'finalTaxedPrice' ];
}
public function getAssociationFields() {
return [
......@@ -116,16 +118,37 @@ class TicketLine extends DoctrineModel // Embedded class
}
/**
* Unit price without tax and before applying discount
* Id of taxe on the ticket line
* Unit price without tax and before applying discount.
* It is null when taxedUnitPrice is set.
* @var float
* @SWG\Property()
* @Column(type="float")
* @Column(type="float", nullable=true)
*/
protected $unitPrice;
public function getUnitPrice() { return round($this->unitPrice, 5); }
protected $unitPrice = null;
public function getUnitPrice() {
if ($this->unitPrice === null) { return null; }
else { return round($this->unitPrice, 5); }
}
public function setUnitPrice($unitPrice) {
$this->unitPrice = round($unitPrice, 5);
if ($unitPrice === null) { $this->unitPrice = null; }
else { $this->unitPrice = round($unitPrice, 5); }
}
/**
* Unit price with tax and before applying discount.
* It is null when unitPrice is set.
* @var float
* @SWG\Property()
* @Column(type="float", nullable=true)
*/
protected $taxedUnitPrice = null;
public function getTaxedUnitPrice() {
if ($this->taxedUnitPrice === null) { return null; }
else { return round($this->taxedUnitPrice, 5); }
}
public function setTaxedUnitPrice($taxedUnitPrice) {
if ($taxedUnitPrice === null) { $this->taxedUnitPrice = null; }
else { $this->taxedUnitPrice = round($taxedUnitPrice, 5); }
}
/**
......@@ -142,14 +165,36 @@ class TicketLine extends DoctrineModel // Embedded class
/**
* In quantity price without tax and before applying discount.
* It is null when taxedPrice is set.
* @var float
* @SWG\Property()
* @Column(type="float")
* @Column(type="float", nullable=true)
*/
protected $price;
public function getPrice() { return round($this->price, 5); }
protected $price = null;
public function getPrice() {
if ($this->price === null) { return null; }
else { return round($this->price, 2); }
}
public function setPrice($price) {
$this->price = round($price, 5);
if ($price === null) { $this->price = null; }
else { $this->price = round($price, 2); }
}
/**
* In quantity price with tax and before applying discount.
* It is null when price is set.
* @var float
* @SWG\Property()
* @Column(type="float")
*/
protected $taxedPrice = null;
public function getTaxedPrice() {
if ($this->taxedPrice === null) { return null; }
else { return round($this->taxedPrice, 2); }
}
public function setTaxedPrice($taxedPrice) {
if ($taxedPrice === null) { $this->taxedPrice = null; }
else { $this->taxedPrice = round($taxedPrice, 2); }
}
/**
......@@ -173,30 +218,6 @@ class TicketLine extends DoctrineModel // Embedded class
public function getTaxRate() { return $this->taxRate; }
public function setTaxRate($taxRate) { $this->taxRate = $taxRate; }
/**
* Total amount of tax before discount.
* @var float
* @SWG\Property()
* @Column(type="float")
*/
protected $taxAmount;
public function getTaxAmount() { return round($this->taxAmount, 5); }
public function setTaxAmount($taxAmount) {
$this->taxAmount = round($taxAmount, 5);
}
/**
* Total price with tax before discount.
* @var float
* @SWG\Property()
* @Column(type="float")
*/
protected $totalAmount;
public function getTotalAmount() { return round($this->totalAmount, 5); }
public function setTotalAmount($totalAmount) {
$this->totalAmount = round($totalAmount, 5);
}
/**
* Rate of discount on this ticket line
* @var float
......@@ -209,44 +230,36 @@ class TicketLine extends DoctrineModel // Embedded class
/**
* Total price without taxes with discount rate.
* It is null when finalTaxedPrice is set.
* @var float
* @SWG\Property()
* @Column(type="float")
* @Column(type="float", nullable=true)
*/
protected $discountPrice;
public function getDiscountPrice() {
return round($this->discountPrice, 5);
protected $finalPrice = null;
public function getFinalPrice() {
if ($this->finalPrice === null) { return null; }
else { return round($this->finalPrice, 2); }
}
public function setDiscountPrice($discountPrice) {
$this->discountPrice = round($discountPrice, 5);
}
/**
* Total taxes with discount rate.
* @var float
* @SWG\Property()
* @Column(type="float")
*/
protected $discountTax;
public function getDiscountTax() {
return round($this->discountTax, 5);
}
public function setDiscountTax($discountTax) {
$this->discountTax = round($discountTax, 5);
public function setFinalPrice($finalPrice) {
if ($finalPrice === null) { $this->finalPrice = null; }
else { $this->finalPrice = round($finalPrice, 2); }
}
/**
* Total price with taxes and discount rate.
* It is null when finalPrice is set.
* @var float
* @SWG\Property()
* @Column(type="float")
* @Column(type="float", nullable=true)
*/
protected $discountTotal;
public function getDiscountTotal() {
return round($this->discountTotal, 5);
protected $finalTaxedPrice = null;
public function getFinalTaxedPrice() {
if ($this->finalTaxedPrice === null) { return null; }
else { return round($this->finalTaxedPrice, 2); }
}
public function setDiscountTotal($discountTotal) {
$this->discountTotal = round($discountTotal, 5);
public function setFinalTaxedPrice($finalTaxedPrice) {
if ($finalTaxedPrice === null) { $this->finalTaxedPrice = null; }
else { $this->finalTaxedPrice = round($finalTaxedPrice, 2); }
}
}
......@@ -26,7 +26,7 @@ use \Pasteque\Server\System\DAO\DAO;
use \Pasteque\Server\System\DAO\DoctrineModel;
/**
* Class TicketTax. Sum of the taxes amount by tax.
* Class TicketTax. Sum of the taxes amount by tax, including ticket discount.
* This class is for fast data analysis only.
* For declarations see FiscalTicket.
* @package Pasteque
......@@ -103,9 +103,9 @@ class TicketTax extends DoctrineModel // Embedded class
* @Column(type="float")
*/
protected $base;
public function getBase() { return round($this->base, 5); }
public function getBase() { return round($this->base, 2); }
public function setBase($base) {
$this->base = round($base, 5);
$this->base = round($base, 2);
}
/**
......@@ -115,9 +115,9 @@ class TicketTax extends DoctrineModel // Embedded class
* @Column(type="float")
*/
protected $amount;
public function getAmount() { return round($this->amount, 5); }
public function getAmount() { return round($this->amount, 2); }
public function setAmount($amount) {
$this->amount = round($amount, 5);
$this->amount = round($amount, 2);
}
}
......@@ -204,13 +204,12 @@ class TicketAPITest extends TestCase
/** @expectedException \BadMethodCallException
* @expectedExceptionMessage Ticket number 0 is reserved. */
public function testSaveTicket0() {
$line1 = TicketLine::fromStruct(['dispOrder' => 1, 'price' => 10.0,
'unitPrice' => 10.0,
$line1 = TicketLine::fromStruct(['dispOrder' => 1,
'taxedUnitPrice' => 11.0,
'quantity' => 1, 'tax' => $this->tax->getId(),
'product' => $this->prd,
'taxRate' => 0.1, 'taxAmount' => 1.0, 'totalAmount' => 11.0,
'discountPrice' => 10.0, 'discountTax' => 1.0,
'discountTotal' => 11.0], $this->dao);
'taxRate' => 0.1, 'taxedPrice' => 11.0,
'finalTaxedPrice' => 11.0], $this->dao);
$tkt = new Ticket();
$tkt->setCashRegister($this->session->getCashRegister());
$tkt->setSequence($this->session->getSequence());
......@@ -218,8 +217,8 @@ class TicketAPITest extends TestCase
$tkt->setDate(new \DateTime('2018-01-01 8:05'));
$tkt->setUser($this->user);
$tkt->addLine($line1);
$tkt->setPrice(10.0); $tkt->setTotalAmount(11.0);
$tkt->setDiscountPrice(10.0); $tkt->setDiscountTotal(11.0);
$tkt->setTaxedPrice(11.0);
$tkt->setFinalPrice(10.0); $tkt->setFinalTaxedPrice(11.0);
$tax = new TicketTax();
$tax->setTax($this->tax); $tax->setBase(10.0); $tax->setAmount(1.0);
$tkt->addTax($tax);
......@@ -234,14 +233,12 @@ class TicketAPITest extends TestCase
/** @depends testUpdateEOSCreate */
public function testSaveTicket() {
$line1 = TicketLine::fromStruct(['dispOrder' => 1, 'price' => 10.0,
'unitPrice' => 10.0,
$line1 = TicketLine::fromStruct(['dispOrder' => 1,
'taxedUnitPrice' => 11.0,
'quantity' => 1, 'tax' => $this->tax->getId(),
'product' => $this->prd,
'product' => $this->prd,
'taxRate' => 0.1, 'taxAmount' => 1.0, 'totalAmount' => 11.0,
'discountPrice' => 10.0, 'discountTax' => 1.0,
'discountTotal' => 11.0], $this->dao);
'taxRate' => 0.1, 'taxedPrice' => 11.0,
'finalTaxedPrice' => 11.0], $this->dao);
$tkt = new Ticket();
$tkt->setCashRegister($this->session->getCashRegister());
$tkt->setSequence($this->session->getSequence());
......@@ -249,8 +246,8 @@ class TicketAPITest extends TestCase
$tkt->setDate(new \DateTime('2018-01-01 8:05'));
$tkt->setUser($this->user);
$tkt->addLine($line1);
$tkt->setPrice(10.0); $tkt->setTotalAmount(11.0);
$tkt->setDiscountPrice(10.0); $tkt->setDiscountTotal(11.0);
$tkt->setTaxedPrice(11.0);
$tkt->setFinalPrice(10.0); $tkt->setFinalTaxedPrice(11.0);
$tax = new TicketTax();
$tax->setTax($this->tax); $tax->setBase(10.0); $tax->setAmount(1.0);
$tkt->addTax($tax);
......@@ -266,8 +263,10 @@ class TicketAPITest extends TestCase
$this->assertEquals($this->cash->getId(), $readTkt->getCashRegister()->getId());
$this->assertEquals($this->session->getSequence(), $readTkt->getSequence());
$this->assertEquals(1, $readTkt->getNumber());
$this->assertEquals(10.0, $readTkt->getPrice());
$this->assertEquals(11.0, $readTkt->getTotalAmount());
$this->assertNull($readTkt->getPrice());
$this->assertEquals(11.0, $readTkt->getTaxedPrice());
$this->assertEquals(10.0, $readTkt->getFinalPrice());
$this->assertEquals(11.0, $readTkt->getFinalTaxedPrice());
$readfTkt = $this->dao->read(FiscalTicket::class, [
'type' => FiscalTicket::TYPE_TICKET,
'sequence' => FiscalTicket::getTicketSequence($readTkt),
......@@ -289,13 +288,13 @@ class TicketAPITest extends TestCase
* @epxectedExceptionMessage Tickets are read only.
* Test the unique constraint. */
public function testSaveDoubleTicket() {
$line11 = TicketLine::fromStruct(['dispOrder' => 1, 'price' => 10.0,
'unitPrice' => 10.0,
$line11 = TicketLine::fromStruct(['dispOrder' => 1,
'taxedUnitPrice' => 11.0,
'quantity' => 1, 'tax' => $this->tax->getId(),
'product' => $this->prd,
'taxRate' => 0.1, 'taxAmount' => 1.0, 'totalAmount' => 11.0,
'discountPrice' => 10.0, 'discountTax' => 1.0,
'discountTotal' => 11.0], $this->dao);
'taxRate' => 0.1,
'taxedPrice' => 11.0,
'finalTaxedPrice' => 11.0], $this->dao);
$tkt1 = new Ticket();
$tkt1->setCashRegister($this->session->getCashRegister());
$tkt1->setSequence($this->session->getSequence());
......@@ -303,8 +302,8 @@ class TicketAPITest extends TestCase
$tkt1->setDate(new \DateTime('2018-01-01 8:05'));
$tkt1->setUser($this->user);
$tkt1->addLine($line11);
$tkt1->setPrice(10.0); $tkt1->setTotalAmount(11.0);
$tkt1->setDiscountPrice(10.0); $tkt1->setDiscountTotal(11.0);
$tkt1->setTaxedPrice(11.0);
$tkt1->setFinalPrice(10.0); $tkt1->setFinalTaxedPrice(11.0);
$tax1 = new TicketTax();
$tax1->setTax($this->tax); $tax1->setBase(10.0); $tax1->setAmount(1.0);
$tkt1->addTax($tax1);
......@@ -315,13 +314,13 @@ class TicketAPITest extends TestCase
'currencyAmount' => 11.0], $this->dao);
$tkt1->addPayment($pm11);
$this->api->write($tkt1);
$line21 = TicketLine::fromStruct(['dispOrder' => 1, 'price' => 10.0,
'unitPrice' => 10.0,
$line21 = TicketLine::fromStruct(['dispOrder' => 1,
'taxedUnitPrice' => 11.0,
'quantity' => 1, 'tax' => $this->tax->getId(),
'product' => $this->prd,
'taxRate' => 0.1, 'taxAmount' => 1.0, 'totalAmount' => 11.0,
'discountPrice' => 10.0, 'discountTax' => 1.0,
'discountTotal' => 11.0], $this->dao);
'taxRate' => 0.1,
'taxedPrice' => 11.0,