OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 174 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.sales.pos.element;
14
 package org.openconcerto.erp.core.sales.pos.element;
15
 
15
 
-
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
-
 
18
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
-
 
19
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
-
 
20
import org.openconcerto.erp.core.sales.pos.TicketSheetXML;
-
 
21
import org.openconcerto.erp.core.sales.pos.model.Article;
-
 
22
import org.openconcerto.erp.core.sales.pos.model.Categorie;
-
 
23
import org.openconcerto.erp.core.sales.pos.model.Paiement;
-
 
24
import org.openconcerto.erp.core.sales.pos.model.ReceiptCode;
-
 
25
import org.openconcerto.erp.core.sales.pos.model.Ticket;
-
 
26
import org.openconcerto.sql.Configuration;
17
import org.openconcerto.sql.element.SQLComponent;
27
import org.openconcerto.sql.element.SQLComponent;
-
 
28
import org.openconcerto.sql.element.SQLElement;
-
 
29
import org.openconcerto.sql.element.SQLElementDirectory;
18
import org.openconcerto.sql.element.UISQLComponent;
30
import org.openconcerto.sql.element.UISQLComponent;
19
import org.openconcerto.sql.model.SQLBase;
31
import org.openconcerto.sql.model.SQLBase;
-
 
32
import org.openconcerto.sql.model.SQLRow;
-
 
33
import org.openconcerto.sql.model.SQLRowListRSH;
-
 
34
import org.openconcerto.sql.model.SQLSelect;
20
import org.openconcerto.sql.utils.PartialUniqueTrigger;
35
import org.openconcerto.sql.utils.PartialUniqueTrigger;
-
 
36
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
-
 
37
import org.openconcerto.sql.view.list.action.SQLRowValuesAction.PredicateRowAction;
-
 
38
import org.openconcerto.utils.DecimalUtils;
-
 
39
import org.openconcerto.utils.ExceptionHandler;
21
 
40
 
-
 
41
import java.math.BigDecimal;
-
 
42
import java.text.ParseException;
22
import java.util.ArrayList;
43
import java.util.ArrayList;
23
import java.util.Arrays;
44
import java.util.Arrays;
-
 
45
import java.util.Collections;
-
 
46
import java.util.HashMap;
24
import java.util.List;
47
import java.util.List;
-
 
48
import java.util.Map;
25
 
49
 
26
import javax.swing.JTextField;
50
import javax.swing.JTextField;
27
 
51
 
28
public class TicketCaisseSQLElement extends ComptaSQLConfElement {
52
public class TicketCaisseSQLElement extends ComptaSQLConfElement {
29
 
53
 
Line 44... Line 68...
44
        }
68
        }
45
    }
69
    }
46
 
70
 
47
    public TicketCaisseSQLElement() {
71
    public TicketCaisseSQLElement() {
48
        super("TICKET_CAISSE", "un ticket de caisse", "tickets de caisses");
72
        super("TICKET_CAISSE", "un ticket de caisse", "tickets de caisses");
-
 
73
 
-
 
74
        PredicateRowAction action = new PredicateRowAction(true, "ticket.document.generate", (le) -> {
-
 
75
            final TicketSheetXML bSheet = new TicketSheetXML(createTicket(le.getSelectedRow().asRow()), ComptaPropsConfiguration.getInstanceCompta());
-
 
76
            try {
-
 
77
                bSheet.createDocument();
-
 
78
                bSheet.showPrintAndExport(true, false, false, Collections.emptyList());
-
 
79
            } catch (Exception originalExn) {
-
 
80
                ExceptionHandler.handle("Erreur lors de la création de la facture", originalExn);
-
 
81
            }
-
 
82
        });
-
 
83
 
-
 
84
        action.setPredicate(IListeEvent.getSingleSelectionPredicate());
-
 
85
        getRowValuesActions().add(action);
49
    }
86
    }
50
 
87
 
51
    protected List<String> getListFields() {
88
    protected List<String> getListFields() {
52
        final List<String> l = new ArrayList<String>();
89
        final List<String> l = new ArrayList<String>();
53
        l.add("NUMERO");
90
        l.add("NUMERO");
Line 75... Line 112...
75
                this.addRequiredSQLObject(new JTextField(), "NOM", "right");
112
                this.addRequiredSQLObject(new JTextField(), "NOM", "right");
76
            }
113
            }
77
        };
114
        };
78
    }
115
    }
79
 
116
 
-
 
117
    public Ticket createTicket(SQLRow row) {
-
 
118
        // TODO merger ce code avec CaissepPanel.loadArticles si possible
-
 
119
        final Ticket t;
-
 
120
        try {
-
 
121
            t = new Ticket(new ReceiptCode(row.getString("NUMERO")), row.getDate("DATE"), row.getString("FILE_HASH_PREVIOUS"));
-
 
122
        } catch (ParseException e) {
-
 
123
            throw new IllegalStateException("Couldn't parse " + row, e);
-
 
124
        }
-
 
125
 
-
 
126
        final SQLElementDirectory directory = Configuration.getInstance().getDirectory();
-
 
127
        SQLElement eltEncaisser = directory.getElement("ENCAISSER_MONTANT");
-
 
128
        List<SQLRow> l = row.getReferentRows(eltEncaisser.getTable());
-
 
129
        for (SQLRow row2 : l) {
-
 
130
            long montant = row2.getLong("MONTANT");
-
 
131
            SQLRow rowMode = row2.getForeign("ID_MODE_REGLEMENT");
-
 
132
            int type = Paiement.CB;
-
 
133
            if (rowMode.getInt("ID_TYPE_REGLEMENT") == TypeReglementSQLElement.CB) {
-
 
134
                type = Paiement.CB;
-
 
135
            } else {
-
 
136
                if (rowMode.getInt("ID_TYPE_REGLEMENT") == TypeReglementSQLElement.CHEQUE) {
-
 
137
                    type = Paiement.CHEQUE;
-
 
138
                } else {
-
 
139
                    if (rowMode.getInt("ID_TYPE_REGLEMENT") == TypeReglementSQLElement.ESPECE) {
-
 
140
                        type = Paiement.ESPECES;
-
 
141
                    }
-
 
142
                }
-
 
143
            }
-
 
144
            Paiement p = new Paiement(type);
-
 
145
            p.setMontantInCents((int) montant);
-
 
146
            t.addPaiement(p);
-
 
147
        }
-
 
148
 
-
 
149
        SQLElement eltArticle = directory.getElement("SAISIE_VENTE_FACTURE_ELEMENT");
-
 
150
 
-
 
151
        final SQLSelect selUniteVente = new SQLSelect();
-
 
152
        selUniteVente.addSelectStar(directory.getElement("UNITE_VENTE").getTable());
-
 
153
        final Map<Integer, String> mapUniteVenteName = new HashMap<>();
-
 
154
        for (SQLRow rowUniteVente : SQLRowListRSH.execute(selUniteVente)) {
-
 
155
            mapUniteVenteName.put(rowUniteVente.getID(), rowUniteVente.getString("CODE"));
-
 
156
        }
-
 
157
 
-
 
158
        List<SQLRow> l2 = row.getReferentRows(eltArticle.getTable());
-
 
159
        Categorie c = new Categorie("");
-
 
160
        for (SQLRow row2 : l2) {
-
 
161
            Article a = new Article(c, row2.getString("NOM"), row2.getInt("ID_ARTICLE"));
-
 
162
            if (row2.getInt("ID_UNITE_VENTE") != 2) {
-
 
163
                a.setSalesUnit(mapUniteVenteName.get(row2.getInt("ID_UNITE_VENTE")));
-
 
164
            }
-
 
165
            BigDecimal ht = (BigDecimal) row2.getObject("PV_HT");
-
 
166
            a.setPriceWithoutTax(ht);
-
 
167
 
-
 
168
            BigDecimal percentRemise = row2.getBigDecimal("POURCENT_REMISE");
-
 
169
            if (percentRemise != null) {
-
 
170
                a.setDiscountPct(percentRemise.movePointLeft(2));
-
 
171
            }
-
 
172
 
-
 
173
            int idTaxe = row2.getInt("ID_TAXE");
-
 
174
            float tva = TaxeCache.getCache().getTauxFromId(idTaxe);
-
 
175
            a.setPriceWithTax(ht.multiply(BigDecimal.valueOf(1.0 + (tva / 100.0D)), DecimalUtils.HIGH_PRECISION));
-
 
176
            a.setIdTaxe(idTaxe);
-
 
177
            t.addArticle(a);
-
 
178
            if (a.getSalesUnit() == null) {
-
 
179
                t.setArticleCount(a, new BigDecimal(row2.getInt("QTE")));
-
 
180
            } else {
-
 
181
                t.setArticleCount(a, row2.getBigDecimal("QTE_UNITAIRE"));
-
 
182
            }
-
 
183
        }
-
 
184
 
-
 
185
        return t;
-
 
186
    }
-
 
187
 
80
    @Override
188
    @Override
81
    protected String createCode() {
189
    protected String createCode() {
82
        return createCodeOfPackage() + ".ticket";
190
        return createCodeOfPackage() + ".ticket";
83
    }
191
    }
84
}
192
}