Dépôt officiel du code source de l'ERP OpenConcerto
Rev 174 | Blame | Compare with Previous | Last modification | View Log | RSS feed
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.generationDoc.provider;
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext;
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLTable;
import java.math.BigDecimal;
import java.util.Collection;
public class QteTotalDocProvider extends UserInitialsValueProvider {
private enum TypeQteTotalDocProvider {
QTE_KG, QTE, COLIS, PDS_BRUT, QTE_MULT
};
private final TypeQteTotalDocProvider type;
private boolean ha = false;
public QteTotalDocProvider(TypeQteTotalDocProvider t) {
this(t, false);
}
public QteTotalDocProvider(TypeQteTotalDocProvider t, boolean ha) {
this.type = t;
this.ha = ha;
}
@Override
public Object getValue(SpreadSheetCellValueContext context) {
SQLRowAccessor row = context.getRow();
final SQLTable table = row.getTable();
Collection<? extends SQLRowAccessor> cols = row.getReferentRows(table.getTable(table.getName() + "_ELEMENT"));
BigDecimal total = BigDecimal.ZERO;
for (SQLRowAccessor sqlRowAccessor : cols) {
if (!sqlRowAccessor.getTable().contains("NIVEAU") || sqlRowAccessor.getInt("NIVEAU") == 1) {
String field = "PV_HT";
if (this.ha) {
field = "PA_HT";
}
BigDecimal prixUnitaire = sqlRowAccessor.getBigDecimal(field);
if (prixUnitaire != null && prixUnitaire.signum() != 0) {
if (this.type == TypeQteTotalDocProvider.QTE || this.type == TypeQteTotalDocProvider.QTE_KG) {
if (this.type == TypeQteTotalDocProvider.QTE || sqlRowAccessor.getForeignID("ID_UNITE_VENTE") == 7) {
BigDecimal qte = sqlRowAccessor.getBigDecimal("QTE_UNITAIRE").multiply(new BigDecimal(sqlRowAccessor.getInt("QTE")));
total = total.add(qte);
}
} else if (this.type == TypeQteTotalDocProvider.PDS_BRUT) {
total = total.add(sqlRowAccessor.getBigDecimal("T_POIDS_BRUT"));
} else if (this.type == TypeQteTotalDocProvider.QTE_MULT) {
BigDecimal qte = new BigDecimal(sqlRowAccessor.getInt("QTE"));
total = total.add(qte);
} else {
if (sqlRowAccessor.getObject("NB_COLIS") != null) {
total = total.add(new BigDecimal(sqlRowAccessor.getInt("NB_COLIS")));
}
}
}
}
}
return total;
}
public static void register() {
SpreadSheetCellValueProviderManager.put("sales.qty.multiple.total", new QteTotalDocProvider(TypeQteTotalDocProvider.QTE_MULT));
SpreadSheetCellValueProviderManager.put("sales.qty.total", new QteTotalDocProvider(TypeQteTotalDocProvider.QTE));
SpreadSheetCellValueProviderManager.put("purchase.qty.total", new QteTotalDocProvider(TypeQteTotalDocProvider.QTE, true));
SpreadSheetCellValueProviderManager.put("sales.qty.total.kg", new QteTotalDocProvider(TypeQteTotalDocProvider.QTE_KG));
SpreadSheetCellValueProviderManager.put("sales.package.total", new QteTotalDocProvider(TypeQteTotalDocProvider.COLIS));
SpreadSheetCellValueProviderManager.put("sales.package.brut", new QteTotalDocProvider(TypeQteTotalDocProvider.PDS_BRUT));
}
}