Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
SAMBUMBA
pasteque-server
Commits
e34d96bb
Commit
e34d96bb
authored
Sep 29, 2017
by
Karamel
Browse files
Add totals in Ticket, remove unused autocomputation (done on client side).
parent
78c636b9
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/lib/Model/Ticket.php
View file @
e34d96bb
...
...
@@ -36,7 +36,8 @@ use \Pasteque\Server\System\DAO\DoctrineModel;
class
Ticket
extends
DoctrineModel
{
public
function
getDirectFieldNames
()
{
return
[
'sequence'
,
'number'
,
'date'
,
'custCount'
,
'discountRate'
];
return
[
'sequence'
,
'number'
,
'date'
,
'custCount'
,
'discountRate'
,
'price'
,
'totalAmount'
,
'discountPrice'
,
'discountTotal'
];
}
public
function
getAssociationFields
()
{
return
[
...
...
@@ -177,7 +178,8 @@ class Ticket extends DoctrineModel
}
/**
* Array of tax totals.
* Array of tax totals. It holds the final tax base/amount for each
* tax. That is after all discounts (lines and ticket).
* @var \Pasteque\Ticket[]
* @SWG\Property()
* @OneToMany(targetEntity="\Pasteque\Server\Model\TicketTax", mappedBy="ticket", cascade={"persist"}, orphanRemoval=true)
...
...
@@ -279,44 +281,56 @@ public function getPayments() { return $this->payments; }
$this
->
discountProfile
=
$discountProfile
;
}
/**
Get subtotal, total and tax amount before ticket discount. This includes
*
line
discount
s. */
public
function
getTotals
()
{
$totals
=
[
'subtotal'
=>
0.0
,
'taxtotal'
=>
0.0
,
'total'
=>
0.0
];
foreach
(
$this
->
getLines
()
as
$line
)
{
$totals
[
'subtotal'
]
=
round
(
$totals
[
'subtotal'
]
+
$line
->
getDiscountPrice
(),
5
);
$totals
[
'taxtotal'
]
=
round
(
$totals
[
'taxtotal'
]
+
$line
->
getDiscountTax
(),
5
)
;
$totals
[
'total'
]
=
round
(
$totals
[
'total'
]
+
$line
->
getDiscountTotal
()
,
5
);
}
return
$totals
;
/**
*
Price without price nor ticket
discount
.
* @var float
* @SWG\Property()
* @Column(type="float")
*/
protected
$price
;
public
function
getPrice
()
{
return
round
(
$this
->
price
,
5
);
}
public
function
setPrice
(
$price
)
{
$this
->
price
=
round
(
$price
,
5
)
;
}
/** Get final subtotal, total and tax amount.*/
public
function
getDiscountTotals
()
{
$totals
=
$this
->
getTotals
();
$totals
[
'subtotal'
]
=
round
(
$totals
[
'subtotal'
]
*
(
1.0
-
$this
->
getDiscountRate
()),
5
);
$totals
[
'taxtotal'
]
=
round
(
$totals
[
'taxtotal'
]
*
(
1.0
-
$this
->
getDiscountRate
()),
5
);
$totals
[
'total'
]
=
round
(
$totals
[
'total'
]
*
(
1.0
-
$this
->
getDiscountRate
()),
5
);
return
$totals
;
/**
* Total price with tax before ticket 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
);
}
/** Get tax totals by tax after discount. */
public
function
getTaxTotals
()
{
$amounts
=
array
();
// Get line taxes
foreach
(
$this
->
lines
as
$line
)
{
$taxId
=
$line
->
getTax
()
->
getId
();
if
(
isset
(
$amounts
[
$taxId
]))
{
$amounts
[
$taxId
]
=
round
(
$amounts
[
$taxId
]
+
$line
->
getDiscountTax
(),
5
);
}
else
{
$amounts
[
$taxId
]
=
$line
->
getDiscountTax
();
}
}
// Apply ticket discount
foreach
(
$amounts
as
$id
=>
$amount
)
{
$amounts
[
$id
]
=
round
(
$amount
*
(
1.0
-
$this
->
getDiscountRate
()),
5
);
}
return
$amounts
;
/**
* Total price without taxes with discount rate.
* @var float
* @SWG\Property()
* @Column(type="float")
*/
protected
$discountPrice
;
public
function
getDiscountPrice
()
{
return
round
(
$this
->
discountPrice
,
5
);
}
public
function
setDiscountPrice
(
$discountPrice
)
{
$this
->
discountPrice
=
round
(
$discountPrice
,
5
);
}
/**
* Total price with taxes and discount rate.
* @var float
* @SWG\Property()
* @Column(type="float")
*/
protected
$discountTotal
;
public
function
getDiscountTotal
()
{
return
round
(
$this
->
discountTotal
,
5
);
}
public
function
setDiscountTotal
(
$discountTotal
)
{
$this
->
discountTotal
=
round
(
$discountTotal
,
5
);
}
public
function
toStruct
()
{
...
...
src/lib/Model/TicketLine.php
View file @
e34d96bb
...
...
@@ -209,7 +209,6 @@ class TicketLine extends DoctrineModel // Embedded class
/**
* Total price without taxes with discount rate.
* Can be autocomputed when discountRate is 0.0
* @var float
* @SWG\Property()
* @Column(type="float")
...
...
@@ -224,7 +223,6 @@ class TicketLine extends DoctrineModel // Embedded class
/**
* Total taxes with discount rate.
* Can be autocomputed when discountRate is 0.0
* @var float
* @SWG\Property()
* @Column(type="float")
...
...
@@ -239,7 +237,6 @@ class TicketLine extends DoctrineModel // Embedded class
/**
* Total price with taxes and discount rate.
* Can be autocomputed when discountRate is 0.0
* @var float
* @SWG\Property()
* @Column(type="float")
...
...
@@ -252,12 +249,4 @@ class TicketLine extends DoctrineModel // Embedded class
$this
->
discountTotal
=
round
(
$discountTotal
,
5
);
}
/** Compute discount values when from original values and discount rate. */
public
function
autocompute
()
{
$rate
=
$this
->
getDiscountRate
();
$this
->
setDiscountPrice
(
$this
->
getPrice
()
*
(
1.0
-
$rate
));
$this
->
setDiscountTax
(
$this
->
getTaxAmount
()
*
(
1.0
-
$rate
));
$this
->
setDiscountTotal
(
$this
->
getTotalAmount
()
*
(
1.0
-
$rate
));
}
}
tests/API/TicketAPITest.php
View file @
e34d96bb
...
...
@@ -34,6 +34,7 @@ use \Pasteque\Server\Model\Tax;
use
\
Pasteque\Server\Model\TariffArea
;
use
\
Pasteque\Server\Model\Ticket
;
use
\
Pasteque\Server\Model\TicketLine
;
use
\
Pasteque\Server\Model\TicketTax
;
use
\
Pasteque\Server\Model\TicketPayment
;
use
\
Pasteque\Server\Model\User
;
use
\
Pasteque\Server\System\DAO\DAOFactory
;
...
...
@@ -117,7 +118,8 @@ class TicketAPITest extends TestCase
foreach
(
$ftkts
as
$record
)
{
$this
->
dao
->
delete
(
$record
);
}
foreach
([
TicketPayment
::
class
,
TicketLine
::
class
,
Ticket
::
class
]
foreach
([
TicketPayment
::
class
,
TicketTax
::
class
,
TicketLine
::
class
,
Ticket
::
class
]
as
$class
)
{
$all
=
$this
->
dao
->
search
(
$class
);
foreach
(
$all
as
$record
)
{
...
...
@@ -199,8 +201,9 @@ class TicketAPITest extends TestCase
'unitPrice'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'product'
=>
$this
->
prd
,
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
],
$this
->
dao
);
$line1
->
autocompute
();
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
,
'discountPrice'
=>
10.0
,
'discountTax'
=>
1.0
,
'discountTotal'
=>
11.0
],
$this
->
dao
);
$tkt
=
new
Ticket
();
$tkt
->
setCashRegister
(
$this
->
session
->
getCashRegister
());
$tkt
->
setSequence
(
$this
->
session
->
getSequence
());
...
...
@@ -208,6 +211,11 @@ 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
);
$tax
=
new
TicketTax
();
$tax
->
setTax
(
$this
->
tax
);
$tax
->
setBase
(
10.0
);
$tax
->
setAmount
(
1.0
);
$tkt
->
addTax
(
$tax
);
$pm1
=
TicketPayment
::
fromStruct
([
'paymentMode'
=>
$this
->
pm
->
getId
(),
'currency'
=>
$this
->
curr
->
getId
(),
'dispOrder'
=>
1
,
...
...
@@ -223,8 +231,10 @@ class TicketAPITest extends TestCase
'unitPrice'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'product'
=>
$this
->
prd
,
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
],
$this
->
dao
);
$line1
->
autocompute
();
'product'
=>
$this
->
prd
,
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
,
'discountPrice'
=>
10.0
,
'discountTax'
=>
1.0
,
'discountTotal'
=>
11.0
],
$this
->
dao
);
$tkt
=
new
Ticket
();
$tkt
->
setCashRegister
(
$this
->
session
->
getCashRegister
());
$tkt
->
setSequence
(
$this
->
session
->
getSequence
());
...
...
@@ -232,6 +242,11 @@ 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
);
$tax
=
new
TicketTax
();
$tax
->
setTax
(
$this
->
tax
);
$tax
->
setBase
(
10.0
);
$tax
->
setAmount
(
1.0
);
$tkt
->
addTax
(
$tax
);
$pm1
=
TicketPayment
::
fromStruct
([
'paymentMode'
=>
$this
->
pm
->
getId
(),
'currency'
=>
$this
->
curr
->
getId
(),
'dispOrder'
=>
1
,
...
...
@@ -244,10 +259,8 @@ class TicketAPITest extends TestCase
$this
->
assertEquals
(
$this
->
cash
->
getId
(),
$readTkt
->
getCashRegister
()
->
getId
());
$this
->
assertEquals
(
$this
->
session
->
getSequence
(),
$readTkt
->
getSequence
());
$this
->
assertEquals
(
1
,
$readTkt
->
getNumber
());
$totals
=
$readTkt
->
getTotals
();
$this
->
assertEquals
(
10.0
,
$totals
[
'subtotal'
]);
$this
->
assertEquals
(
1.0
,
$totals
[
'taxtotal'
]);
$this
->
assertEquals
(
11.0
,
$totals
[
'total'
]);
$this
->
assertEquals
(
10.0
,
$readTkt
->
getPrice
());
$this
->
assertEquals
(
11.0
,
$readTkt
->
getTotalAmount
());
$readfTkt
=
$this
->
dao
->
read
(
FiscalTicket
::
class
,
[
'type'
=>
FiscalTicket
::
TYPE_TICKET
,
'sequence'
=>
FiscalTicket
::
getTicketSequence
(
$readTkt
),
...
...
@@ -272,8 +285,9 @@ class TicketAPITest extends TestCase
'unitPrice'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'product'
=>
$this
->
prd
,
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
],
$this
->
dao
);
$line11
->
autocompute
();
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
,
'discountPrice'
=>
10.0
,
'discountTax'
=>
1.0
,
'discountTotal'
=>
11.0
],
$this
->
dao
);
$tkt1
=
new
Ticket
();
$tkt1
->
setCashRegister
(
$this
->
session
->
getCashRegister
());
$tkt1
->
setSequence
(
$this
->
session
->
getSequence
());
...
...
@@ -281,6 +295,11 @@ 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
);
$tax1
=
new
TicketTax
();
$tax1
->
setTax
(
$this
->
tax
);
$tax1
->
setBase
(
10.0
);
$tax1
->
setAmount
(
1.0
);
$tkt1
->
addTax
(
$tax1
);
$pm11
=
TicketPayment
::
fromStruct
([
'paymentMode'
=>
$this
->
pm
->
getId
(),
'currency'
=>
$this
->
curr
->
getId
(),
'dispOrder'
=>
1
,
...
...
@@ -292,8 +311,9 @@ class TicketAPITest extends TestCase
'unitPrice'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'product'
=>
$this
->
prd
,
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
],
$this
->
dao
);
$line21
->
autocompute
();
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
,
'discountPrice'
=>
10.0
,
'discountTax'
=>
1.0
,
'discountTotal'
=>
11.0
],
$this
->
dao
);
$tkt2
=
new
Ticket
();
$tkt2
->
setCashRegister
(
$this
->
session
->
getCashRegister
());
$tkt2
->
setSequence
(
$this
->
session
->
getSequence
());
...
...
@@ -301,6 +321,11 @@ class TicketAPITest extends TestCase
$tkt2
->
setDate
(
new
\
DateTime
(
'2018-01-01 8:05'
));
$tkt2
->
setUser
(
$this
->
user
);
$tkt2
->
addLine
(
$line21
);
$tkt2
->
setPrice
(
10.0
);
$tkt2
->
setTotalAmount
(
11.0
);
$tkt2
->
setDiscountPrice
(
10.0
);
$tkt2
->
setDiscountTotal
(
11.0
);
$tax2
=
new
TicketTax
();
$tax2
->
setTax
(
$this
->
tax
);
$tax2
->
setBase
(
10.0
);
$tax2
->
setAmount
(
1.0
);
$tkt2
->
addTax
(
$tax2
);
$pm21
=
TicketPayment
::
fromStruct
([
'paymentMode'
=>
$this
->
pm
->
getId
(),
'currency'
=>
$this
->
curr
->
getId
(),
'dispOrder'
=>
1
,
...
...
@@ -319,8 +344,9 @@ class TicketAPITest extends TestCase
'unitPrice'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'product'
=>
$this
->
prd
,
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
],
$this
->
dao
);
$line1
->
autocompute
();
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
,
'discountPrice'
=>
10.0
,
'discountTax'
=>
1.0
,
'discountTotal'
=>
11.0
],
$this
->
dao
);
$tkt
=
new
Ticket
();
$tkt
->
setCashRegister
(
$this
->
session
->
getCashRegister
());
$tkt
->
setSequence
(
$this
->
session
->
getSequence
());
...
...
@@ -328,6 +354,11 @@ 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
);
$tax
=
new
TicketTax
();
$tax
->
setTax
(
$this
->
tax
);
$tax
->
setBase
(
10.0
);
$tax
->
setAmount
(
1.0
);
$tkt
->
addTax
(
$tax
);
$pm1
=
TicketPayment
::
fromStruct
([
'paymentMode'
=>
$this
->
pm
->
getId
(),
'currency'
=>
$this
->
curr
->
getId
(),
'dispOrder'
=>
1
,
...
...
@@ -350,8 +381,9 @@ class TicketAPITest extends TestCase
'unitPrice'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'product'
=>
$this
->
prd
,
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
],
$this
->
dao
);
$line1
->
autocompute
();
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
,
'discountPrice'
=>
10.0
,
'discountTax'
=>
1.0
,
'discountTotal'
=>
11.0
],
$this
->
dao
);
$tkt
=
new
Ticket
();
$tkt
->
setCashRegister
(
$this
->
session
->
getCashRegister
());
$tkt
->
setSequence
(
$this
->
session
->
getSequence
());
...
...
@@ -359,6 +391,11 @@ 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
);
$tax
=
new
TicketTax
();
$tax
->
setTax
(
$this
->
tax
);
$tax
->
setBase
(
10.0
);
$tax
->
setAmount
(
1.0
);
$tkt
->
addTax
(
$tax
);
$pm1
=
TicketPayment
::
fromStruct
([
'paymentMode'
=>
$this
->
pm
->
getId
(),
'currency'
=>
$this
->
curr
->
getId
(),
'dispOrder'
=>
1
,
...
...
tests/Model/TicketTest.php
deleted
100644 → 0
View file @
78c636b9
<?php
// Pasteque server testing
//
// Copyright (C)
// 2012 Scil (http://scil.coop)
// 2017 Karamel, Association Pastèque (karamel@creativekara.fr, https://pasteque.org)
//
// This file is part of Pasteque.
//
// Pasteque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pasteque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pasteque. If not, see <http://www.gnu.org/licenses/>.
namespace
Pasteque\Server
;
use
\
Pasteque\Server\Model\Category
;
use
\
Pasteque\Server\Model\CashRegister
;
use
\
Pasteque\Server\Model\CashSession
;
use
\
Pasteque\Server\Model\Currency
;
use
\
Pasteque\Server\Model\PaymentMode
;
use
\
Pasteque\Server\Model\Product
;
use
\
Pasteque\Server\Model\Role
;
use
\
Pasteque\Server\Model\Tax
;
use
\
Pasteque\Server\Model\TariffArea
;
use
\
Pasteque\Server\Model\Ticket
;
use
\
Pasteque\Server\Model\TicketLine
;
use
\
Pasteque\Server\Model\TicketPayment
;
use
\
Pasteque\Server\Model\User
;
use
\
Pasteque\Server\System\DAO\DAOFactory
;
use
\
PHPUnit\Framework\TestCase
;
require_once
(
dirname
(
dirname
(
__FILE__
))
.
"/common_load.php"
);
class
TicketTest
extends
TestCase
{
private
$tax
;
private
$cat
;
private
$prd
;
private
$cash
;
private
$session
;
private
$pm
;
private
$curr
;
private
$role
;
private
$user
;
private
$dao
;
protected
function
setUp
()
{
global
$dbInfo
;
$this
->
dao
=
DAOFactory
::
getDAO
(
$dbInfo
,
[
'debug'
=>
true
]);
$this
->
cat
=
new
Category
();
$this
->
cat
->
setReference
(
'category'
);
$this
->
cat
->
setLabel
(
'Category'
);
$this
->
dao
->
write
(
$this
->
cat
);
$this
->
tax
=
new
Tax
();
$this
->
tax
->
setLabel
(
'VAT'
);
$this
->
tax
->
setRate
(
0.1
);
$this
->
dao
->
write
(
$this
->
tax
);
$this
->
prd
=
new
Product
();
$this
->
prd
->
setReference
(
'product'
);
$this
->
prd
->
setLabel
(
'Product'
);
$this
->
prd
->
setTax
(
$this
->
tax
);
$this
->
prd
->
setCategory
(
$this
->
cat
);
$this
->
prd
->
setPriceSell
(
1.0
);
$this
->
dao
->
write
(
$this
->
prd
);
$this
->
pm
=
new
PaymentMode
();
$this
->
pm
->
setReference
(
'pm'
);
$this
->
pm
->
setLabel
(
'Payment mode'
);
$this
->
dao
->
write
(
$this
->
pm
);
$this
->
curr
=
new
Currency
();
$this
->
curr
->
setReference
(
'curr'
);
$this
->
curr
->
setLabel
(
'Currency'
);
$this
->
curr
->
setMain
(
true
);
$this
->
dao
->
write
(
$this
->
curr
);
$this
->
cash
=
new
CashRegister
();
$this
->
cash
->
setReference
(
'cash'
);
$this
->
cash
->
setLabel
(
'Cash'
);
$this
->
dao
->
write
(
$this
->
cash
);
$this
->
role
=
new
Role
();
$this
->
role
->
setName
(
'role'
);
$this
->
dao
->
write
(
$this
->
role
);
$this
->
user
=
new
User
();
$this
->
user
->
setName
(
'user'
);
$this
->
user
->
setRole
(
$this
->
role
);
$this
->
dao
->
write
(
$this
->
user
);
$this
->
session
=
new
CashSession
();
$this
->
session
->
setCashRegister
(
$this
->
cash
);
$this
->
session
->
setSequence
(
1
);
$this
->
dao
->
write
(
$this
->
session
);
$this
->
dao
->
commit
();
}
protected
function
tearDown
()
{
foreach
([
TicketPayment
::
class
,
TicketLine
::
class
,
Ticket
::
class
]
as
$class
)
{
$all
=
$this
->
dao
->
search
(
$class
);
foreach
(
$all
as
$record
)
{
$this
->
dao
->
delete
(
$record
);
}
}
// Directly deleting $this->session doesn't work
// and f**k it, you won't delete sessions anyway.
$sessions
=
$this
->
dao
->
search
(
CashSession
::
class
);
$this
->
dao
->
delete
(
$sessions
[
0
]);
$this
->
dao
->
delete
(
$this
->
cash
);
$this
->
dao
->
delete
(
$this
->
user
);
$this
->
dao
->
delete
(
$this
->
role
);
$this
->
dao
->
delete
(
$this
->
prd
);
$this
->
dao
->
delete
(
$this
->
cat
);
$this
->
dao
->
delete
(
$this
->
tax
);
$this
->
dao
->
delete
(
$this
->
pm
);
$this
->
dao
->
delete
(
$this
->
curr
);
$this
->
dao
->
commit
();
}
public
function
testNothing
()
{
// Just to ensure setup and teardown are not crashing.
}
public
function
testTotals
()
{
$line1
=
TicketLine
::
fromStruct
([
'dispOrder'
=>
1
,
'price'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
],
$this
->
dao
);
$line1
->
autocompute
();
$tkt
=
new
Ticket
();
$tkt
->
addLine
(
$line1
);
$totals
=
$tkt
->
getTotals
();
$discountTotals
=
$tkt
->
getDiscountTotals
();
$this
->
assertEquals
(
10.0
,
$totals
[
'subtotal'
]);
$this
->
assertEquals
(
1.0
,
$totals
[
'taxtotal'
]);
$this
->
assertEquals
(
11.0
,
$totals
[
'total'
]);
$this
->
assertEquals
(
10.0
,
$discountTotals
[
'subtotal'
]);
$this
->
assertEquals
(
1.0
,
$discountTotals
[
'taxtotal'
]);
$this
->
assertEquals
(
11.0
,
$discountTotals
[
'total'
]);
}
public
function
testTotalDiscount
()
{
$line1
=
TicketLine
::
fromStruct
([
'dispOrder'
=>
1
,
'price'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
],
$this
->
dao
);
$line1
->
autocompute
();
$tkt
=
new
Ticket
();
$tkt
->
addLine
(
$line1
);
$tkt
->
setDiscountRate
(
0.1
);
$totals
=
$tkt
->
getTotals
();
$discountTotals
=
$tkt
->
getDiscountTotals
();
$this
->
assertEquals
(
10.0
,
$totals
[
'subtotal'
]);
$this
->
assertEquals
(
1.0
,
$totals
[
'taxtotal'
]);
$this
->
assertEquals
(
11.0
,
$totals
[
'total'
]);
$this
->
assertEquals
(
9.0
,
$discountTotals
[
'subtotal'
]);
$this
->
assertEquals
(
0.9
,
$discountTotals
[
'taxtotal'
]);
$this
->
assertEquals
(
9.9
,
$discountTotals
[
'total'
]);
}
public
function
testLineDiscount
()
{
$line1
=
TicketLine
::
fromStruct
([
'dispOrder'
=>
1
,
'price'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
,
'discountRate'
=>
0.1
],
$this
->
dao
);
$line1
->
autocompute
();
$tkt
=
new
Ticket
();
$tkt
->
addLine
(
$line1
);
$totals
=
$tkt
->
getTotals
();
$discountTotals
=
$tkt
->
getDiscountTotals
();
$this
->
assertEquals
(
9.0
,
$totals
[
'subtotal'
]);
$this
->
assertEquals
(
0.9
,
$totals
[
'taxtotal'
]);
$this
->
assertEquals
(
9.9
,
$totals
[
'total'
]);
$this
->
assertEquals
(
9.0
,
$discountTotals
[
'subtotal'
]);
$this
->
assertEquals
(
9.9
,
$discountTotals
[
'total'
]);
$this
->
assertEquals
(
0.9
,
$discountTotals
[
'taxtotal'
]);
}
public
function
testBothDiscounts
()
{
$line1
=
TicketLine
::
fromStruct
([
'dispOrder'
=>
1
,
'price'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
,
'discountRate'
=>
0.1
],
$this
->
dao
);
$line1
->
autocompute
();
$tkt
=
new
Ticket
();
$tkt
->
addLine
(
$line1
);
$tkt
->
setDiscountRate
(
0.1
);
$totals
=
$tkt
->
getTotals
();
$discountTotals
=
$tkt
->
getDiscountTotals
();
$this
->
assertEquals
(
9.0
,
$totals
[
'subtotal'
]);
$this
->
assertEquals
(
0.9
,
$totals
[
'taxtotal'
]);
$this
->
assertEquals
(
9.9
,
$totals
[
'total'
]);
$this
->
assertEquals
(
8.1
,
$discountTotals
[
'subtotal'
]);
$this
->
assertEquals
(
0.81
,
$discountTotals
[
'taxtotal'
]);
$this
->
assertEquals
(
8.91
,
$discountTotals
[
'total'
]);
}
public
function
testTaxTotals
()
{
$line1
=
TicketLine
::
fromStruct
([
'dispOrder'
=>
1
,
'price'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
],
$this
->
dao
);
$line1
->
autocompute
();
$tkt
=
new
Ticket
();
$tkt
->
addLine
(
$line1
);
$totals
=
$tkt
->
getTaxTotals
();
$this
->
assertEquals
(
1
,
count
(
$totals
));
$this
->
assertEquals
(
1.0
,
$totals
[
$this
->
tax
->
getId
()]);
}
public
function
testTaxDiscountTotals
()
{
$line1
=
TicketLine
::
fromStruct
([
'dispOrder'
=>
1
,
'price'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
],
$this
->
dao
);
$line1
->
autocompute
();
$tkt
=
new
Ticket
();
$tkt
->
addLine
(
$line1
);
$tkt
->
setDiscountRate
(
0.1
);
$totals
=
$tkt
->
getTaxTotals
();
$this
->
assertEquals
(
1
,
count
(
$totals
));
$this
->
assertEquals
(
0.9
,
$totals
[
$this
->
tax
->
getId
()]);
}
public
function
testTaxDiscountLineTotals
()
{
$line1
=
TicketLine
::
fromStruct
([
'dispOrder'
=>
1
,
'price'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
,
'discountRate'
=>
0.1
],
$this
->
dao
);
$line1
->
autocompute
();
$tkt
=
new
Ticket
();
$tkt
->
addLine
(
$line1
);
$totals
=
$tkt
->
getTaxTotals
();
$this
->
assertEquals
(
1
,
count
(
$totals
));
$this
->
assertEquals
(
0.9
,
$totals
[
$this
->
tax
->
getId
()]);
}
public
function
testTaxBothDiscount
()
{
$line1
=
TicketLine
::
fromStruct
([
'dispOrder'
=>
1
,
'price'
=>
10.0
,
'quantity'
=>
1
,
'tax'
=>
$this
->
tax
->
getId
(),
'taxRate'
=>
0.1
,
'taxAmount'
=>
1.0
,
'totalAmount'
=>
11.0
,
'discountRate'
=>
0.1
],
$this
->
dao
);
$line1
->
autocompute
();
$tkt
=
new
Ticket
();
$tkt
->
addLine
(
$line1
);
$tkt
->
setDiscountRate
(
0.1
);
$totals
=
$tkt
->
getTaxTotals
();
$this
->
assertEquals
(
1
,
count
(
$totals
));
$this
->
assertEquals
(
0.81
,
$totals
[
$this
->
tax
->
getId
()]);
}
}
tests/testsuites.xml
View file @
e34d96bb
...
...
@@ -12,7 +12,6 @@
<file>
Model/TariffAreaTest.php
</file>
<file>
Model/PaymentModeTest.php
</file>
<file>
Model/CustomerTest.php
</file>
<file>
Model/TicketTest.php
</file>
<file>
Model/FiscalTicketTest.php
</file>
</testsuite>
<testsuite
name=
"API"
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment