OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 151
Line 18... Line 18...
18
import org.openconcerto.erp.core.sales.pos.io.Printable;
18
import org.openconcerto.erp.core.sales.pos.io.Printable;
19
import org.openconcerto.erp.core.sales.pos.io.TicketPrinter;
19
import org.openconcerto.erp.core.sales.pos.io.TicketPrinter;
20
import org.openconcerto.erp.core.sales.pos.model.Paiement;
20
import org.openconcerto.erp.core.sales.pos.model.Paiement;
21
import org.openconcerto.erp.core.sales.pos.model.RegisterLog;
21
import org.openconcerto.erp.core.sales.pos.model.RegisterLog;
22
import org.openconcerto.erp.core.sales.pos.model.RegisterState;
22
import org.openconcerto.erp.core.sales.pos.model.RegisterState;
23
import org.openconcerto.erp.core.sales.pos.model.Ticket;
-
 
24
import org.openconcerto.erp.core.sales.pos.model.RegisterState.Status;
23
import org.openconcerto.erp.core.sales.pos.model.RegisterState.Status;
-
 
24
import org.openconcerto.erp.core.sales.pos.model.Ticket;
25
 
25
 
26
import java.math.BigDecimal;
26
import java.math.BigDecimal;
27
import java.text.DateFormat;
27
import java.text.DateFormat;
28
import java.text.ParseException;
28
import java.text.ParseException;
29
import java.text.SimpleDateFormat;
29
import java.text.SimpleDateFormat;
30
import java.util.Date;
30
import java.util.Date;
31
import java.util.LinkedHashMap;
31
import java.util.LinkedHashMap;
32
import java.util.List;
32
import java.util.List;
33
import java.util.Map;
33
import java.util.Map;
34
import java.util.TreeMap;
-
 
35
import java.util.Map.Entry;
34
import java.util.Map.Entry;
-
 
35
import java.util.TreeMap;
36
import java.util.logging.Level;
36
import java.util.logging.Level;
37
 
37
 
38
abstract class RegisterSummary implements Printable {
38
abstract class RegisterSummary implements Printable {
39
 
39
 
40
    private final String name;
40
    private final String name;
Line 90... Line 90...
90
                valueByReceipt.put(t, receiptValue);
90
                valueByReceipt.put(t, receiptValue);
91
                paidByReceipt.put(t, receiptPaid);
91
                paidByReceipt.put(t, receiptPaid);
92
                total = total.add(receiptValue);
92
                total = total.add(receiptValue);
93
                totalPaid = totalPaid.add(receiptPaid);
93
                totalPaid = totalPaid.add(receiptPaid);
94
            }
94
            }
-
 
95
            final BigDecimal rendu = totalPaid.subtract(total);
95
 
96
 
96
            prt.addToBuffer(title, TicketPrinter.BOLD_LARGE);
97
            prt.addToBuffer(title, TicketPrinter.BOLD_LARGE);
97
            prt.addToBuffer("");
98
            prt.addToBuffer("");
98
            prt.addToBuffer("Edité le " + dateFormat.format(new Date()));
99
            prt.addToBuffer("Edité le " + dateFormat.format(new Date()));
99
            final RegisterState registerState = getLog().getRegisterState();
100
            final RegisterState registerState = getLog().getRegisterState();
Line 102... Line 103...
102
            prt.addToBuffer("");
103
            prt.addToBuffer("");
103
            prt.addToBuffer("Tickets de caisse", TicketPrinter.BOLD_LARGE);
104
            prt.addToBuffer("Tickets de caisse", TicketPrinter.BOLD_LARGE);
104
            prt.addToBuffer("");
105
            prt.addToBuffer("");
105
 
106
 
106
            Paiement espece = new Paiement(Paiement.ESPECES);
107
            Paiement espece = new Paiement(Paiement.ESPECES);
-
 
108
            // TODO same name as "Total TTC"
107
            prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "Total des ventes", totalPaid.toPlainString()), TicketPrinter.BOLD);
109
            prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "Total des ventes", total.toPlainString()), TicketPrinter.BOLD);
108
            for (final Entry<String, BigDecimal> e2 : totalByType.entrySet()) {
110
            for (final Entry<String, BigDecimal> e2 : totalByType.entrySet()) {
109
                final String typePayment = e2.getKey();
111
                final String typePayment = e2.getKey();
110
                if (typePayment.equals(espece.getTypeAsString())) {
112
                if (typePayment.equals(espece.getTypeAsString())) {
111
                    BigDecimal value = e2.getValue();
113
                    BigDecimal value = e2.getValue();
112
                    BigDecimal rendu = totalPaid.subtract(total);
-
 
113
                    value = value.subtract(rendu);
114
                    value = value.subtract(rendu);
114
                    prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "      " + typePayment, value.toPlainString()));
115
                    prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "      " + typePayment, value.toPlainString()));
115
                } else {
116
                } else {
116
                    prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "      " + typePayment, e2.getValue().toPlainString()));
117
                    prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "      " + typePayment, e2.getValue().toPlainString()));
117
                }
118
                }
Line 120... Line 121...
120
            prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "Total des paiements", totalPaid.toPlainString()), TicketPrinter.BOLD);
121
            prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "Total des paiements", totalPaid.toPlainString()), TicketPrinter.BOLD);
121
            for (final Entry<String, BigDecimal> e2 : totalByType.entrySet()) {
122
            for (final Entry<String, BigDecimal> e2 : totalByType.entrySet()) {
122
                prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "      " + e2.getKey(), e2.getValue().toPlainString()));
123
                prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "      " + e2.getKey(), e2.getValue().toPlainString()));
123
            }
124
            }
124
            prt.addToBuffer("");
125
            prt.addToBuffer("");
125
            prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "Total rendu", totalPaid.subtract(total).toPlainString()), TicketPrinter.BOLD);
126
            prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "Total rendu", rendu.toPlainString()), TicketPrinter.BOLD);
126
            prt.addToBuffer("");
127
            prt.addToBuffer("");
127
            prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "Total TTC (Euros)", total.toPlainString()), TicketPrinter.BOLD);
128
            prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "Total TTC (Euros)", total.toPlainString()), TicketPrinter.BOLD);
128
            prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "Nombre de tickets", "" + receipts.size()));
129
            prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "Nombre de tickets", "" + receipts.size()));
129
            final long avg = receipts.isEmpty() ? 0 : total.movePointRight(2).longValueExact() / receipts.size();
130
            final long avg = receipts.isEmpty() ? 0 : total.movePointRight(2).longValueExact() / receipts.size();
130
            prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "Panier moyen (Euros)", BigDecimal.valueOf(avg).movePointLeft(2).toPlainString()));
131
            prt.addToBuffer(DefaultTicketPrinter.formatSides(ticketWidth, "Panier moyen (Euros)", BigDecimal.valueOf(avg).movePointLeft(2).toPlainString()));