Skip to content

Commit ed67217

Browse files
committed
Domain: Done breaking changes, Payment related stuff
1 parent 0230dc5 commit ed67217

File tree

6 files changed

+281
-260
lines changed

6 files changed

+281
-260
lines changed

kriolos-opos-domain/src/main/java/com/openbravo/pos/forms/DataLogicSales.java

+22-12
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public final ProductInfoExt getProductInfo(String id) throws BasicException {
281281
* @return
282282
* @throws BasicException
283283
*/
284-
public final ProductInfoExt getProductInfoByCode(String sCode) throws BasicException {
284+
public final ProductInfoExt getProductInfoByCode(String sCode) throws BasicException {
285285
return new PreparedSentence<String, ProductInfoExt>(s,
286286
"SELECT "
287287
+ "ID, "
@@ -1610,15 +1610,14 @@ public final TicketInfo loadTicket(final int tickettype, final int ticketid) thr
16101610
}
16111611

16121612
/**
1613-
*
1613+
* Save Ticket information (Receipt, Payments, Ticket, TaxLine, TicketLine, Customer debt, Voucher)
16141614
* @param ticket
16151615
* @param location
16161616
* @throws BasicException
16171617
*/
16181618
public final void saveTicket(final TicketInfo ticket, final String location) throws BasicException {
16191619

1620-
Transaction t;
1621-
t = new Transaction(s) {
1620+
Transaction t = new Transaction(s) {
16221621
@Override
16231622
public Object transact() throws BasicException {
16241623

@@ -1642,6 +1641,7 @@ public Object transact() throws BasicException {
16421641
}
16431642
}
16441643

1644+
//Ticket Properties
16451645
byte[] properties = null;
16461646
try {
16471647
ByteArrayOutputStream o = new ByteArrayOutputStream();
@@ -1651,6 +1651,7 @@ public Object transact() throws BasicException {
16511651

16521652
}
16531653

1654+
//Receipt Writer
16541655
SerializerWrite<Object[]> sw = new SerializerWriteBasicExt(
16551656
new Datas[]{Datas.STRING, Datas.STRING, Datas.TIMESTAMP, Datas.BYTES, Datas.STRING},
16561657
new int[]{0, 1, 2, 3, 4});
@@ -1661,6 +1662,7 @@ public Object transact() throws BasicException {
16611662
properties,
16621663
ticket.getProperty("person")};
16631664

1665+
//Receipt Prepared
16641666
new PreparedSentence(s,
16651667
"INSERT INTO receipts (ID, MONEY, DATENEW, ATTRIBUTES, PERSON) VALUES (?, ?, ?, ?, ?)",
16661668
sw)
@@ -1684,7 +1686,7 @@ public Object transact() throws BasicException {
16841686
sw)
16851687
.exec(params);
16861688

1687-
// update status of existing ticket
1689+
//Ticket: Update status (This is Receipt or TicketType: 0)
16881690
new PreparedSentence(s,
16891691
"UPDATE tickets SET STATUS = ? "
16901692
+ "WHERE TICKETTYPE = 0 AND TICKETID = ?",
@@ -1698,6 +1700,7 @@ public void writeValues() throws BasicException {
16981700
}
16991701
});
17001702

1703+
//Ticket Lines
17011704
SentenceExec ticketlineinsert = new PreparedSentenceExec(s,
17021705
"INSERT INTO ticketlines (TICKET, LINE, "
17031706
+ "PRODUCT, ATTRIBUTESETINSTANCE_ID, "
@@ -1723,6 +1726,7 @@ public void writeValues() throws BasicException {
17231726
}
17241727
}
17251728

1729+
//Payments
17261730
final Payments payments = new Payments();
17271731
SentenceExec paymentinsert = new PreparedSentence(s,
17281732
"INSERT INTO payments (ID, RECEIPT, PAYMENT, TOTAL, TRANSID, RETURNMSG, "
@@ -1733,33 +1737,38 @@ public void writeValues() throws BasicException {
17331737
payments.addPayment(p.getName(), p.getTotal(), p.getPaid(), ticket.getReturnMessage(), p.getVoucher());
17341738
});
17351739
while (payments.getSize() >= 1) {
1740+
1741+
pName = payments.getFirstElement();
1742+
getTotal = payments.getPaidAmount(pName);
1743+
getTendered = payments.getTendered(pName);
1744+
getRetMsg = payments.getRtnMessage(pName);
1745+
getVoucher = payments.getVoucher(pName);
1746+
payments.removeFirst(pName);
1747+
17361748
paymentinsert.exec(new DataParams() {
1749+
17371750
@Override
17381751
public void writeValues() throws BasicException {
1739-
pName = payments.getFirstElement();
1740-
getTotal = payments.getPaidAmount(pName);
1741-
getTendered = payments.getTendered(pName);
1742-
getRetMsg = payments.getRtnMessage(pName);
1743-
getVoucher = payments.getVoucher(pName);
1744-
payments.removeFirst(pName);
17451752

17461753
setString(1, UUID.randomUUID().toString());
17471754
setString(2, ticket.getId());
17481755
setString(3, pName);
17491756
setDouble(4, getTotal);
17501757
setString(5, ticket.getTransactionID());
1751-
setBytes(6, (byte[]) Formats.BYTEA.parseValue(getRetMsg));
1758+
setBytes(6, Formats.BYTEA.parseValue(getRetMsg));
17521759
setDouble(7, getTendered);
17531760
setString(8, getCardName);
17541761
setString(9, getVoucher);
17551762
payments.removeFirst(pName);
17561763
}
17571764
});
17581765

1766+
// Payment method: Disable that Voucher
17591767
if (payments.getVoucher(pName) != null) {
17601768
getVoucherNonActive().exec(payments.getVoucher(pName));
17611769
}
17621770

1771+
//Payment method: Add debt to Customer Account
17631772
if ("debt".equals(pName) || "debtpaid".equals(pName)) {
17641773
ticket.getCustomer().updateCurDebt(getTotal, ticket.getDate());
17651774
getDebtUpdate().exec(new DataParams() {
@@ -1774,6 +1783,7 @@ public void writeValues() throws BasicException {
17741783
}
17751784
}
17761785

1786+
//TAX Lines
17771787
SentenceExec taxlinesinsert = new PreparedSentence(s,
17781788
"INSERT INTO taxlines (ID, RECEIPT, TAXID, BASE, AMOUNT) "
17791789
+ "VALUES (?, ?, ?, ?, ?)",

kriolos-opos-domain/src/main/java/com/openbravo/pos/forms/Payments.java

+47-52
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
1716
package com.openbravo.pos.forms;
1817

1918
import java.util.HashMap;
@@ -23,23 +22,21 @@
2322
* @author Jack Gerrard
2423
*/
2524
public class Payments {
26-
private Double amount;
27-
private Double tendered;
28-
private final HashMap paymentPaid;
29-
private final HashMap paymentTendered;
30-
private final HashMap rtnMessage;
31-
private String name;
32-
private final HashMap paymentVoucher;
25+
26+
private final HashMap<String, Double> paymentPaid;
27+
private final HashMap<String, Double> paymentTendered;
28+
private final HashMap<String, String> rtnMessage;
29+
private final HashMap<String, String> paymentVoucher;
3330

3431
/**
3532
*
3633
*/
3734
public Payments() {
38-
paymentPaid = new HashMap();
39-
paymentTendered = new HashMap();
40-
rtnMessage = new HashMap();
41-
paymentVoucher = new HashMap();
42-
35+
paymentPaid = new HashMap<>();
36+
paymentTendered = new HashMap<>();
37+
rtnMessage = new HashMap<>();
38+
paymentVoucher = new HashMap<>();
39+
4340
}
4441

4542
/**
@@ -49,19 +46,18 @@ public Payments() {
4946
* @param pTendered
5047
* @param rtnMsg
5148
*/
52-
53-
public void addPayment (String pName, Double pAmountPaid, Double pTendered, String rtnMsg){
54-
if (paymentPaid.containsKey(pName)){
55-
paymentPaid.put(pName,Double.parseDouble(paymentPaid.get(pName).toString()) + pAmountPaid);
56-
paymentTendered.put(pName,Double.parseDouble(paymentTendered.get(pName).toString()) + pTendered);
57-
rtnMessage.put(pName, rtnMsg);
58-
}else {
49+
public void addPayment(String pName, Double pAmountPaid, Double pTendered, String rtnMsg) {
50+
if (paymentPaid.containsKey(pName)) {
51+
paymentPaid.put(pName, paymentPaid.get(pName) + pAmountPaid);
52+
paymentTendered.put(pName, paymentTendered.get(pName) + pTendered);
53+
rtnMessage.put(pName, rtnMsg);
54+
} else {
5955
paymentPaid.put(pName, pAmountPaid);
60-
paymentTendered.put(pName,pTendered);
61-
rtnMessage.put(pName, rtnMsg);
62-
}
56+
paymentTendered.put(pName, pTendered);
57+
rtnMessage.put(pName, rtnMsg);
58+
}
6359
}
64-
60+
6561
/**
6662
*
6763
* @param pName
@@ -70,79 +66,78 @@ public void addPayment (String pName, Double pAmountPaid, Double pTendered, Stri
7066
* @param rtnMsg
7167
* @param pVoucher
7268
*/
73-
public void addPayment (String pName, Double pAmountPaid, Double pTendered, String rtnMsg, String pVoucher){
74-
if (paymentPaid.containsKey(pName)){
75-
paymentPaid.put(pName,Double.parseDouble(paymentPaid.get(pName).toString()) + pAmountPaid);
76-
paymentTendered.put(pName,Double.parseDouble(paymentTendered.get(pName).toString()) + pTendered);
69+
public void addPayment(String pName, Double pAmountPaid, Double pTendered, String rtnMsg, String pVoucher) {
70+
if (paymentPaid.containsKey(pName)) {
71+
paymentPaid.put(pName, paymentPaid.get(pName) + pAmountPaid);
72+
paymentTendered.put(pName, paymentTendered.get(pName) + pTendered);
7773
rtnMessage.put(pName, rtnMsg);
7874
paymentVoucher.put(pName, pVoucher);
79-
80-
}else {
75+
76+
} else {
8177
paymentPaid.put(pName, pAmountPaid);
82-
paymentTendered.put(pName,pTendered);
78+
paymentTendered.put(pName, pTendered);
8379
rtnMessage.put(pName, rtnMsg);
84-
if (pVoucher !=null) {
85-
paymentVoucher.put(pName, pVoucher);
80+
if (pVoucher != null) {
81+
paymentVoucher.put(pName, pVoucher);
8682
} else {
8783
pVoucher = "0";
88-
paymentVoucher.put(pName, pVoucher);
84+
paymentVoucher.put(pName, pVoucher);
8985
}
90-
}
86+
}
9187
}
92-
9388

9489
/**
9590
*
9691
* @param pName
9792
* @return
9893
*/
99-
public Double getTendered (String pName){
100-
return(Double.parseDouble(paymentTendered.get(pName).toString()));
94+
public Double getTendered(String pName) {
95+
return paymentTendered.get(pName);
10196
}
10297

10398
/**
10499
*
105100
* @param pName
106101
* @return
107102
*/
108-
public Double getPaidAmount (String pName){
109-
return(Double.parseDouble(paymentPaid.get(pName).toString()));
103+
public Double getPaidAmount(String pName) {
104+
return paymentPaid.get(pName);
110105
}
111106

112107
/**
113108
*
114109
* @return
115110
*/
116-
public Integer getSize(){
117-
return (paymentPaid.size());
111+
public Integer getSize() {
112+
return paymentPaid.size();
118113
}
119114

120115
/**
121116
*
122117
* @param pName
123118
* @return
124119
*/
125-
public String getRtnMessage(String pName){
126-
return (rtnMessage.get(pName).toString());
120+
public String getRtnMessage(String pName) {
121+
return rtnMessage.get(pName);
127122
}
128-
129-
public String getVoucher(String pName){
130-
return (paymentVoucher.get(pName).toString());
123+
124+
public String getVoucher(String pName) {
125+
return paymentVoucher.get(pName);
131126
}
132127

133-
public String getFirstElement(){
134-
String rtnKey= paymentPaid.keySet().iterator().next().toString();
135-
return(rtnKey);
128+
public String getFirstElement() {
129+
String rtnKey = paymentPaid.keySet().iterator().next();
130+
return rtnKey;
136131
}
137132

138133
/**
139134
*
140135
* @param pName
141136
*/
142-
public void removeFirst (String pName){
137+
public void removeFirst(String pName) {
143138
paymentPaid.remove(pName);
144139
paymentTendered.remove(pName);
145140
rtnMessage.remove(pName);
146141
}
147142

148-
}
143+
}

0 commit comments

Comments
 (0)