@Override
public Double render(Object v, ModelData m, String field, Map<String, Object> data) {
if (v == null) {
v = 0d;
}
LigTransfertppModel lig = (LigTransfertppModel) m;
return ((Double) v).doubleValue() + (lig.getQuantite() * lig.getPu());
}
});
montant.setRenderer(new GridCellRenderer<LigTransfertppModel>() {
@Override
public String render(LigTransfertppModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<LigTransfertppModel> store, Grid<LigTransfertppModel> grid) {
LigTransfertppModel lig = model;
if (lig.getDeVers().equalsIgnoreCase("vers")) {
return NumberFormat.getCurrencyFormat().format(lig.getPu() * lig.getQuantite() * (-1));
} else {
return NumberFormat.getCurrencyFormat().format(lig.getPu() * lig.getQuantite());
}
}
});
configs.add(montant);
SummaryColumnConfig<Integer> quantity = new SummaryColumnConfig<Integer>(LigTransfertppModel.QUANTITY, "Quantite", 100);
NumberField nfQuantity = createIntegerField(null, true);
nfQuantity.setAutoValidate(true);
nfQuantity.setAllowNegative(false);
nfQuantity.setAllowDecimals(false);
quantity.setSummaryType(new SummaryType<Integer>() {
@Override
public Integer render(Object v, ModelData m, String field, Map<String, Object> data) {
if (v == null) {
v = 1;
}
return ((Integer) v).intValue();
}
});
CellEditor ce1 = new CellEditor(nfQuantity);
ce1.setCancelOnEsc(true);
quantity.setMenuDisabled(true);
quantity.setAlignment(HorizontalAlignment.CENTER);
quantity.setSortable(false);
quantity.setEditor(ce1);
quantity.setSummaryType(SummaryType.COUNT);
configs.add(quantity);
SummaryColumnConfig<Double> pu = new SummaryColumnConfig<Double>(LigTransfertppModel.PU, "Pu", 100);
pu.setSortable(false);
pu.setMenuDisabled(true);
pu.setAlignment(HorizontalAlignment.CENTER);
pu.setSummaryFormat(NumberFormat.getCurrencyFormat());
pu.setNumberFormat(NumberFormat.getCurrencyFormat());
pu.setSummaryType(new SummaryType<Double>() {
@Override
public Double render(Object v, ModelData m, String field, Map<String, Object> data) {
if (v == null) {
v = 0d;
}
return ((Double) v).doubleValue();
}
});
/* pu.setAlignment(HorizontalAlignment.RIGHT); */
NumberField nf = new NumberField();
nf.setAutoValidate(true);
CellEditor ce = new CellEditor(nf);
ce.setCancelOnEsc(true);
pu.setEditor(ce);
pu.setAlignment(HorizontalAlignment.CENTER);
configs.add(pu);
column = new ColumnConfig();
/* column.setWidth(300); */
column.setId(LigTransfertppModel.COMMENTAIRES);
column.setHeader("Commentaire");
column.setAlignment(HorizontalAlignment.LEFT);
column.setFixed(true);
column.setSortable(false);
column.setMenuDisabled(true);
column.setResizable(false);
TextArea comment = new TextArea();
comment.setHeight(100);
comment.setMaxLength(MAX_LENGTH_5);
column.setEditor(new CellEditor(comment));
column.setRenderer(createTextAreaRenderer());
configs.add(column);
ColumnModel cm = new ColumnModel(configs);
storeLig = new GroupingStore<LigTransfertppModel>();
gridligModel = new EditorGrid<LigTransfertppModel>(storeLig, cm);
gridligModel.setStripeRows(true);
/* gridligModel.setWidth(1100); */
// gridligModel.setEnabled(false);
gridligModel.setHeight(230);
gridligModel.setAutoWidth(true);
gridligModel.setBorders(true);
gridligModel.setAutoExpandColumn(LigTransfertppModel.COMMENTAIRES);
gridligModel.setAutoExpandMax(700);
gridligModel.setAutoExpandMin(150);
gridligModel.setColumnReordering(true);
gridligModel.setColumnLines(true);
// WindowResizeBinder.bind(gridligModel);
gridligModel.getStore().addStoreListener(new StoreListener<LigTransfertppModel>() {
@Override
public void handleEvent(StoreEvent<LigTransfertppModel> e) {
double totalObjPositive = 0.0;
double totalObjNegative = 0.0;
double amountObj = 0.0;
double totalDeversPositive = 0.0;
double totalDeversNegative = 0.0;
double amountDevers = 0.0;
double totalTsPositive = 0.0;
double totalTsNegative = 0.0;
double amountTs = 0.0;
double totalRDPositive = 0.0;
double totalRDNegative = 0.0;
double amountRD = 0.0;
List<LigTransfertppModel> ligModels = gridligModel.getStore().getModels();
for (LigTransfertppModel lig : ligModels) {
if (lig.getRefTypeBudjConf().getId() == 1 && lig.getDeVers().equalsIgnoreCase("vers")) {
totalObjNegative += lig.getPu() * lig.getQuantite() * (-1);
}
if (lig.getRefTypeBudjConf().getId() == 1 && lig.getDeVers().equalsIgnoreCase("de")) {
totalObjPositive += lig.getPu() * lig.getQuantite();
}
if (lig.getRefTypeBudjConf().getId() == 2 && lig.getDeVers().equalsIgnoreCase("vers")) {
totalDeversNegative += lig.getPu() * lig.getQuantite() * (-1);
}
if (lig.getRefTypeBudjConf().getId() == 2 && lig.getDeVers().equalsIgnoreCase("de")) {
totalDeversPositive += lig.getPu() * lig.getQuantite();
}
if (lig.getRefTypeBudjConf().getId() == 3 && lig.getDeVers().equalsIgnoreCase("vers")) {
totalRDNegative += lig.getPu() * lig.getQuantite() * (-1);
}
if (lig.getRefTypeBudjConf().getId() == 3 && lig.getDeVers().equalsIgnoreCase("de")) {
totalRDPositive += lig.getPu() * lig.getQuantite();
}
if (lig.getRefTypeBudjConf().getId() == 4 && lig.getDeVers().equalsIgnoreCase("vers")) {
totalTsNegative += lig.getPu() * lig.getQuantite() * (-1);
}
if (lig.getRefTypeBudjConf().getId() == 4 && lig.getDeVers().equalsIgnoreCase("de")) {
totalTsPositive += lig.getPu() * lig.getQuantite();
}
}
amountObj = totalObjNegative + totalObjPositive;
amountDevers = totalDeversNegative + totalDeversPositive;
amountRD = totalRDNegative + totalRDPositive;
amountTs = totalTsNegative + totalTsPositive;
LigTransfertppModel ligModel = new LigTransfertppModel();
ligModel.setTotalDevers(amountDevers);
ligModel.setTotalObj(amountObj);
ligModel.setTotalTs(amountTs);
ligModel.setTotalRd(amountRD);
storeTotal.removeAll();
// gridligTotal.getStore().add(ligModel);
storeTotal.add(ligModel);
}
});