OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 18 → Rev 19

/trunk/OpenConcerto/src/org/openconcerto/erp/generationDoc/OOXMLField.java
14,6 → 14,7
package org.openconcerto.erp.generationDoc;
 
import org.openconcerto.erp.config.ComptaPropsConfiguration;
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
import org.openconcerto.map.model.Ville;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.element.SQLElement;
26,7 → 27,10
import org.openconcerto.sql.model.Where;
import org.openconcerto.utils.GestionDevise;
import org.openconcerto.utils.Nombre;
import org.openconcerto.utils.StringUtils;
import org.openconcerto.utils.Tuple2;
 
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
37,7 → 41,6
import java.util.List;
import java.util.Map;
 
 
import org.jdom.Element;
 
public class OOXMLField extends OOXMLElement {
44,11 → 47,10
 
private String op = "";
 
public OOXMLField(Element eltField, SQLRowAccessor row, SQLElement sqlElt, int id) {
super(eltField, sqlElt, id);
public OOXMLField(Element eltField, SQLRowAccessor row, SQLElement sqlElt, int id, SQLRow rowLanguage) {
super(eltField, sqlElt, id, rowLanguage);
 
String base = eltField.getAttributeValue("base");
 
this.op = eltField.getAttributeValue("op");
 
this.row = row;
55,7 → 57,7
if ((this.row == null || !this.row.getTable().getSchema().getName().equalsIgnoreCase("Common")) && base != null && base.equalsIgnoreCase("COMMON")) {
this.row = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
}
if (row == null) {
if (this.row == null) {
this.row = sqlElt.getTable().getRow(id);
}
 
102,10 → 104,14
 
String result = "";
for (Element ssComposant : children) {
OOXMLField childElt = new OOXMLField(ssComposant, foreignRow, this.sqlElt, this.id);
OOXMLField childElt = new OOXMLField(ssComposant, foreignRow, this.sqlElt, this.id, this.rowLanguage);
final Object valueComposantO = childElt.getValue();
result += (valueComposantO == null) ? "" : valueComposantO.toString() + " ";
}
String cellSize = this.elt.getAttributeValue("cellSize");
if (cellSize != null && cellSize.trim().length() != 0) {
result = splitStringCell(cellSize, result);
}
return result.trim();
} else {
return "";
112,7 → 118,7
}
} else {
if (isValid()) {
OOXMLField childElt = new OOXMLField(this.elt.getChild("field"), foreignRow, this.sqlElt, this.id);
OOXMLField childElt = new OOXMLField(this.elt.getChild("field"), foreignRow, this.sqlElt, this.id, this.rowLanguage);
return childElt.getValue();
} else {
return "";
145,11 → 151,24
}
 
// Liste des valeurs à ne pas afficher
List<String> listOfExpectedValues = null;
List<String> listOfExcludedValues = null;
if (this.elt.getAttributeValue("valuesExpected") != null) {
listOfExpectedValues = SQLRow.toList(this.elt.getAttributeValue("valuesExpected"));
listOfExcludedValues = SQLRow.toList(this.elt.getAttributeValue("valuesExpected"));
}
List<Element> excludeValue = this.elt.getChildren("exclude");
if (excludeValue != null && excludeValue.size() > 0) {
if (listOfExcludedValues == null) {
listOfExcludedValues = new ArrayList<String>();
} else {
listOfExcludedValues = new ArrayList<String>(listOfExcludedValues);
}
 
for (Element element : excludeValue) {
String attributeValue = element.getAttributeValue("value");
listOfExcludedValues.add(attributeValue);
}
}
 
// Champ boolean
String condField = this.elt.getAttributeValue("conditionField");
String condValue = this.elt.getAttributeValue("conditionExpValue");
192,10 → 211,11
}
 
// on ne fait rien si le champ n'est pas à afficher
if (listOfExpectedValues == null || ((!listOfExpectedValues.contains(stringValue)) && stringValue.trim().length() > 0)) {
if (listOfExcludedValues == null || ((!listOfExcludedValues.contains(stringValue)) && stringValue.trim().length() > 0)) {
String prefix = this.elt.getAttributeValue("prefix");
String suffix = this.elt.getAttributeValue("suffix");
String display = this.elt.getAttributeValue("display");
String cellSize = this.elt.getAttributeValue("cellSize");
if (prefix != null || suffix != null) {
 
String result = "";
212,7 → 232,9
if (suffix != null) {
result += suffix;
}
 
if (cellSize != null && cellSize.trim().length() != 0) {
result = splitStringCell(cellSize, result);
}
return result;
} else {
if (display == null || !display.equalsIgnoreCase("false")) {
226,13 → 248,23
}
}
 
return "";
return null;
 
}
 
private String splitStringCell(String cellSize, String result) {
try {
int nbCar = Integer.parseInt(cellSize);
result = StringUtils.splitString(result, nbCar);
} catch (NumberFormatException e) {
e.printStackTrace();
}
return result;
}
 
protected Object getSpecialValue(String typeComp) {
String field = this.elt.getAttributeValue("name");
final Object object = this.row.getObject(field);
final Object result = this.row.getObject(field);
 
// Liste des valeurs à ne pas afficher
List<String> listOfExpectedValues = null;
240,7 → 272,7
listOfExpectedValues = SQLRow.toList(this.elt.getAttributeValue("valuesExpected"));
}
 
String stringValue = (object == null) ? "" : object.toString();
String stringValue = (result == null) ? "" : result.toString();
if (typeComp != null && typeComp.trim().length() > 0) {
 
// Type spécial
250,13 → 282,10
SQLSelect sel = new SQLSelect(this.row.getTable().getBase());
sel.addSelect(this.row.getTable().getKey(), "COUNT");
Where w = new Where(this.row.getTable().getField("DATE"), "<=", this.row.getDate("DATE").getTime());
w = w.and(new Where(this.row.getTable().getField("ID_AFFAIRE"), "=", this.row.getInt("ID_AFFAIRE")));
sel.setWhere(w);
 
return this.row.getTable().getBase().getDataSource().executeScalar(sel.asString());
} else {
if (typeComp.equalsIgnoreCase("Devise")) {
Number prix = (Number) object;
} else if (typeComp.equalsIgnoreCase("Devise")) {
Number prix = (Number) result;
if (listOfExpectedValues != null) {
for (String string : listOfExpectedValues) {
Long l = Long.parseLong(string);
266,60 → 295,37
}
}
return new Double(GestionDevise.currencyToString(prix.longValue(), false));
} else {
if (typeComp.equalsIgnoreCase("globalAcompte")) {
Long prix = (Long) object;
} else if (typeComp.equalsIgnoreCase("globalAcompte")) {
Long prix = (Long) result;
int pourcent = this.row.getInt("POURCENT_ACOMPTE");
long l = Math.round(prix.longValue() / (pourcent / 100.0));
return new Double(GestionDevise.currencyToString(l, false));
} else {
if (typeComp.equalsIgnoreCase("DateEcheanceFiche")) {
Date d = getDateEch(this.row);
if (d != null) {
final DateFormat format2 = new SimpleDateFormat("dd/MM/yyyy");
return format2.format(d);
} else {
return "";
}
} else {
if (typeComp.equalsIgnoreCase("MoisEcheanceFiche")) {
return getMoisEch(this.row);
} else {
if (typeComp.equalsIgnoreCase("SituationAdminFiche")) {
return getSituationAdmin(this.row);
} else {
if (typeComp.equalsIgnoreCase("AcompteVerse")) {
return getAcompteVerse(this.row);
} else {
if (typeComp.equalsIgnoreCase("CumulPrec")) {
} else if (typeComp.equalsIgnoreCase("CumulPrec")) {
 
final long cumulPrecedent = getCumulPrecedent(this.row);
return new Double(GestionDevise.currencyToString(cumulPrecedent, false));
} else {
if (typeComp.equalsIgnoreCase("Activite")) {
return object.toString() + getActivite(this.id);
} else {
} else if (typeComp.equalsIgnoreCase("DeviseLettre")) {
// Devise exprimée en lettre
if (typeComp.equalsIgnoreCase("DeviseLettre")) {
Long prix = (Long) object;
return getLettreFromDevise(prix.longValue());
Long prix = (Long) result;
return getLettreFromDevise(prix.longValue(), Nombre.FR, Tuple2.create(" euros ", " cents"));
} else if (typeComp.equalsIgnoreCase("DeviseLettreEng")) {
// Devise exprimée en lettre
Long prix = (Long) result;
SQLRowAccessor tarif = this.row.getForeign("ID_TARIF");
if (tarif.isUndefined()) {
return getLettreFromDevise(prix.longValue(), Nombre.EN, Tuple2.create(" euros ", " cents"));
} else {
// Proposition associée à la facture (Notre
// propo N°
// ...
// du
// ...)
if (typeComp.equalsIgnoreCase("propositionFacture")) {
return getStringProposition(this.row);
SQLRowAccessor rowDevise = tarif.getForeign("ID_DEVISE");
if (rowDevise.isUndefined()) {
return getLettreFromDevise(prix.longValue(), Nombre.EN, Tuple2.create(" euros ", " cents"));
} else {
 
return getLettreFromDevise(prix.longValue(), Nombre.EN, Tuple2.create(" " + rowDevise.getString("LIBELLE") + " ", " " + rowDevise.getString("LIBELLE_CENT") + " "));
}
}
} else if (typeComp.equalsIgnoreCase("Ville")) {
// Ville si null on retourne la valeur du
// champ
// de
// la
// base
if (typeComp.equalsIgnoreCase("Ville")) {
stringValue = (object == null) ? "" : object.toString();
// champ de la base
stringValue = (result == null) ? "" : result.toString();
final String ville = getVille(stringValue);
if (ville == null) {
return stringValue;
326,40 → 332,26
} else {
return ville;
}
} else {
} else if (typeComp.equalsIgnoreCase("VilleCP")) {
// Code postal de la ville
if (typeComp.equalsIgnoreCase("ListeVerificateur")) {
return getListeVerificateur(this.row);
} else {
 
// Code postal de la ville
if (typeComp.equalsIgnoreCase("VilleCP")) {
stringValue = (object == null) ? "" : object.toString();
stringValue = (result == null) ? "" : result.toString();
return getVilleCP(stringValue, this.row);
} else {
 
} else if (typeComp.equalsIgnoreCase("DateEcheance")) {
// Retourne la date d'échéance
if (typeComp.equalsIgnoreCase("DateEcheance")) {
 
int idModeReglement = this.row.getInt("ID_MODE_REGLEMENT");
Date d = (Date) this.row.getObject("DATE");
return getDateEcheance(idModeReglement, d);
} else {
if (typeComp.equalsIgnoreCase("Jour")) {
} else if (typeComp.equalsIgnoreCase("Jour")) {
int day = this.row.getInt(field);
stringValue = "le " + String.valueOf(day);
if (day == 31) {
return "fin de mois";
} else {
if (day == 0) {
} else if (day == 0) {
return "Date de facture";
} else {
 
return stringValue;
}
}
} else {
if (typeComp.equalsIgnoreCase("Date")) {
} else if (typeComp.equalsIgnoreCase("Date")) {
 
String datePattern = this.elt.getAttributeValue("DatePattern");
if (datePattern == null || datePattern.trim().length() == 0) {
366,41 → 358,44
datePattern = "dd/MM/yyyy";
}
SimpleDateFormat format = new SimpleDateFormat(datePattern);
if (object != null) {
Date d = (Date) object;
if (result != null) {
Date d = (Date) result;
return format.format(d);
} else {
return "";
}
}
if (typeComp.equalsIgnoreCase("initiale")) {
stringValue = (object == null) ? "" : object.toString();
} else if (typeComp.equalsIgnoreCase("initiale")) {
stringValue = (result == null) ? "" : result.toString();
if (stringValue.trim().length() > 0) {
stringValue = String.valueOf(stringValue.charAt(0));
}
return stringValue;
}
 
}
 
return (result == null) ? "" : result;
}
 
private Object getTraduction() {
if (this.rowLanguage == null || this.rowLanguage.isUndefined()) {
return null;
}
int id = ReferenceArticleSQLElement.getIdForCNM(row.asRowValues(), false);
SQLTable table = Configuration.getInstance().getBase().getTable("ARTICLE_DESIGNATION");
SQLSelect sel = new SQLSelect(table.getBase());
sel.addSelectStar(table);
Where w = new Where(table.getField("ID_ARTICLE"), "=", id);
w = w.and(new Where(table.getField("ID_LANGUE"), "=", this.rowLanguage.getID()));
sel.setWhere(w);
List<SQLRow> rows = (List<SQLRow>) Configuration.getInstance().getBase().getDataSource().execute(sel.asString(), SQLRowListRSH.createFromSelect(sel));
if (rows != null && rows.size() > 0) {
return rows.get(0).getString(this.elt.getAttributeValue("name"));
} else {
return this.row.getObject(this.elt.getAttributeValue("name"));
}
}
}
}
}
}
}
}
}
}
}
}
}
}
 
return (object == null) ? "" : object;
}
 
public boolean isValid() {
String condField = this.elt.getAttributeValue("conditionField");
String condValue = this.elt.getAttributeValue("conditionExpValue");
418,7 → 413,10
Collection<? extends SQLRowAccessor> factElts = rowFact.getReferentRows(tableElt);
 
for (SQLRowAccessor row : factElts) {
Collection<? extends SQLRowAccessor> rowsElt = row.getForeign("ID_MISSION").getReferentRows(tableElt);
 
final SQLRowAccessor foreign = row.getForeign("ID_MISSION");
if (foreign.getID() > 1) {
Collection<? extends SQLRowAccessor> rowsElt = foreign.getReferentRows(tableElt);
for (SQLRowAccessor row2 : rowsElt) {
SQLRowAccessor rowFacture = row2.getForeign("ID_SAISIE_VENTE_FACTURE");
if (rowFacture.getDate("DATE").before(rowFact.getDate("DATE"))) {
426,81 → 424,56
}
}
}
}
 
return cumul;
}
 
private static Date getDateEch(SQLRowAccessor rowFiche) {
private static long getMontantGlobal(SQLRowAccessor rowFact) {
 
Date d = null;
long cumul = 0;
 
// On recupere les missions associées
Collection<? extends SQLRowAccessor> factElts = rowFiche.getReferentRows(rowFiche.getTable().getTable("FICHE_RENDEZ_VOUS_ELEMENT"));
SQLTable tableElt = Configuration.getInstance().getRoot().findTable("SAISIE_VENTE_FACTURE_ELEMENT");
Collection<? extends SQLRowAccessor> factElts = rowFact.getReferentRows(tableElt);
 
if (factElts != null && factElts.size() > 0) {
Object[] rows = factElts.toArray();
int i = 0;
Calendar date;
while (i < factElts.size()) {
date = ((SQLRow) rows[i]).getDate("DATE_ECHEANCE");
if (date != null) {
d = date.getTime();
break;
}
i++;
}
}
for (SQLRowAccessor row : factElts) {
Long p0 = (Long) row.getObject("MONTANT_INITIAL");
Long l0 = (Long) row.getObject("INDICE_0");
Long lN = (Long) row.getObject("INDICE_N");
final Object o = row.getObject("POURCENT_ACOMPTE");
final Object o2 = row.getObject("POURCENT_REMISE");
double lA = (o == null) ? 0 : ((BigDecimal) o).doubleValue();
double lremise = (o2 == null) ? 0 : ((BigDecimal) o2).doubleValue();
Long p;
if (l0 != 0) {
double d;
double coeff = ((double) lN) / ((double) l0);
 
return d;
d = 0.15 + (0.85 * coeff);
p = Math.round(d * p0);
} else {
p = p0;
}
 
private static String getMoisEch(SQLRowAccessor rowFiche) {
 
String mois = "";
 
// On recupere les missions associées
SQLTable tableElt = Configuration.getInstance().getRoot().findTable("FICHE_RENDEZ_VOUS_ELEMENT");
Collection<? extends SQLRowAccessor> factElts = rowFiche.getReferentRows(tableElt);
 
if (factElts != null && factElts.size() > 0) {
Object[] rows = factElts.toArray();
int i = 0;
while (i < factElts.size()) {
int idMois = ((SQLRow) rows[i]).getInt("ID_MOIS_PREV");
if (idMois > 1) {
mois = ((SQLRow) rows[i]).getForeign("ID_MOIS_PREV").getString("NOM");
break;
// if (lA >= 0 && lA != 100) {
// p = Math.round(p * (lA / 100.0));
// }
if (lremise > 0 && lremise != 100) {
p = Math.round(p * (100.0 - lremise) / 100.0);
}
i++;
cumul += p;
}
}
 
return mois;
// Echantillons
SQLTable tableEchElt = Configuration.getInstance().getRoot().findTable("ECHANTILLON_ELEMENT");
Collection<? extends SQLRowAccessor> echElts = rowFact.getReferentRows(tableEchElt);
for (SQLRowAccessor sqlRowAccessor : echElts) {
cumul += sqlRowAccessor.getLong("T_PV_HT");
}
 
private static String getSituationAdmin(SQLRowAccessor rowFiche) {
 
SQLTable tableElt = Configuration.getInstance().getRoot().findTable("FICHE_RENDEZ_VOUS_ELEMENT");
Collection<? extends SQLRowAccessor> rows = rowFiche.getReferentRows(tableElt);
 
String text = "";
List<String> l = new ArrayList<String>();
for (SQLRowAccessor row : rows) {
 
final String situation = row.getString("SITUATION_ADMIN");
if (!l.contains(situation)) {
text += situation + ", ";
l.add(situation);
return cumul;
}
}
 
if (text.length() > 0) {
text = text.substring(0, text.length() - 2);
}
 
return text;
}
 
private static List<Integer> getListId(Collection<SQLRow> rowFactElts) {
return getListId(rowFactElts, null);
}
518,32 → 491,7
return l;
}
 
/**
*
* @param idAffaire
* @return la liste des activités séparées par des -
*/
private static String getActivite(int idAffaire) {
 
SQLElement eltAffaire = Configuration.getInstance().getDirectory().getElement("AFFAIRE");
SQLElement eltAffaireElt = Configuration.getInstance().getDirectory().getElement("AFFAIRE_ELEMENT");
List<SQLRow> s = eltAffaire.getTable().getRow(idAffaire).getReferentRows(eltAffaireElt.getTable());
 
String codes = "";
List<String> l = new ArrayList<String>(s.size());
for (SQLRow row : s) {
 
final String string = row.getString("ACTIVITE");
if (!l.contains(string)) {
l.add(string);
String code = "-" + string;
codes += code;
}
}
 
return codes;
}
 
/**
* transforme une devise exprimée en chiffres en lettres
*
550,7 → 498,7
* @param value
* @return la devise exprimée en lettres
*/
private static String getLettreFromDevise(long value) {
private static String getLettreFromDevise(long value, int langue, Tuple2<String, String> deviseName) {
 
StringBuffer result = new StringBuffer();
 
557,13 → 505,15
Long decimal = Long.valueOf(value % 100);
Long entier = Long.valueOf(value / 100);
 
Nombre n1 = new Nombre(entier.intValue());
Nombre n2 = new Nombre(decimal.intValue());
Nombre n1 = new Nombre(entier.intValue(), langue);
Nombre n2 = new Nombre(decimal.intValue(), langue);
 
result.append(n1.getText() + " euros");
// result.append(n1.getText() + " euros");
result.append(n1.getText() + deviseName.get0());
 
if (decimal.intValue() > 0) {
result.append(" et " + n2.getText() + " cents");
// result.append(" et " + n2.getText() + " cents");
result.append((langue == Nombre.FR ? " et " : " and ") + n2.getText() + deviseName.get1());
}
if (result != null && result.length() > 0) {
return result.toString().replaceFirst(String.valueOf(result.charAt(0)), String.valueOf(result.charAt(0)).toUpperCase());
601,79 → 551,6
return ville.getCodepostal();
}
 
protected static void initCacheAffaireCT(SQLRow row) {
SQLSelect sel = new SQLSelect(row.getTable().getBase());
final SQLTable tableFactElt = row.getTable().getTable("SAISIE_VENTE_FACTURE_ELEMENT");
final SQLTable tableAffElt = row.getTable().getTable("AFFAIRE_ELEMENT");
 
sel.addSelectStar(tableFactElt);
sel.addJoin("LEFT", tableFactElt.getField("ID_AFFAIRE_ELEMENT"));
 
Where w = new Where(sel.getAlias(tableAffElt.getField("ID_AFFAIRE")), "=", row.getInt("ID_AFFAIRE"));
w = w.or(new Where(sel.getAlias(tableFactElt.getField("ID_SAISIE_VENTE_FACTURE")), "=", row.getID()));
sel.setWhere(w);
List<SQLRowAccessor> l = (List<SQLRowAccessor>) row.getTable().getBase().getDataSource().execute(sel.asString(), new SQLRowListRSH(tableFactElt, true));
System.err.println(l.size());
for (SQLRowAccessor sqlRow : l) {
 
// On cache les elt de factures references par les elements d'affaire
SQLRowAccessor affElt = OOXMLCache.getForeignRow(sqlRow, sqlRow.getTable().getField("ID_AFFAIRE_ELEMENT"));
Map<SQLRowAccessor, Map<SQLTable, List<SQLRowAccessor>>> cacheReferent = OOXMLCache.getCacheReferent();
if (affElt != null) {
 
Map<SQLTable, List<SQLRowAccessor>> m = cacheReferent.get(affElt);
if (m == null) {
m = new HashMap<SQLTable, List<SQLRowAccessor>>();
cacheReferent.put(affElt, m);
}
List<SQLRowAccessor> list = m.get(sqlRow.getTable());
if (list == null) {
list = new ArrayList();
m.put(sqlRow.getTable(), list);
}
list.add(sqlRow);
}
// On cache les elements de
if (sqlRow.getInt("ID_SAISIE_VENTE_FACTURE") == row.getID()) {
Map<SQLTable, List<SQLRowAccessor>> m = cacheReferent.get(row);
if (m == null) {
m = new HashMap<SQLTable, List<SQLRowAccessor>>();
cacheReferent.put(row, m);
}
List<SQLRowAccessor> list = m.get(sqlRow.getTable());
if (list == null) {
list = new ArrayList<SQLRowAccessor>();
m.put(sqlRow.getTable(), list);
}
list.add(sqlRow);
 
}
}
}
 
private static Double getAcompteVerse(SQLRowAccessor row) {
 
SQLRowAccessor rowAff = OOXMLCache.getForeignRow(row, row.getTable().getField("ID_AFFAIRE"));
List<? extends SQLRowAccessor> list = OOXMLCache.getReferentRows(rowAff, row.getTable());
 
double total = 0.0;
for (SQLRowAccessor sqlRow : list) {
Calendar date = row.getDate("DATE");
Calendar date2 = sqlRow.getDate("DATE");
if (date2.before(date)) {
total += sqlRow.getFloat("T_HT");
}
}
 
// On cumul ce qui a déja était verse
List<? extends SQLRowAccessor> listElt = OOXMLCache.getReferentRows(rowAff, rowAff.getTable().getTable("AFFAIRE_ELEMENT"));
for (SQLRowAccessor sqlRow : listElt) {
total += sqlRow.getFloat("TOTAL_HT_REALISE");
}
 
return total / 100.0;
}
 
private static Number calcul(Object o1, Object o2, String op) {
 
double d1 = (o1 == null) ? 0 : Double.parseDouble(o1.toString());