Line 19... |
Line 19... |
19 |
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
|
19 |
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
|
20 |
import org.openconcerto.erp.model.PrixTTC;
|
20 |
import org.openconcerto.erp.model.PrixTTC;
|
21 |
import org.openconcerto.sql.model.SQLRow;
|
21 |
import org.openconcerto.sql.model.SQLRow;
|
22 |
import org.openconcerto.sql.model.SQLRowValues;
|
22 |
import org.openconcerto.sql.model.SQLRowValues;
|
23 |
import org.openconcerto.sql.model.SQLTable;
|
23 |
import org.openconcerto.sql.model.SQLTable;
|
- |
|
24 |
import org.openconcerto.sql.model.Where;
|
- |
|
25 |
import org.openconcerto.sql.request.UpdateBuilder;
|
24 |
|
26 |
|
25 |
import java.sql.SQLException;
|
27 |
import java.sql.SQLException;
|
26 |
import java.text.DateFormat;
|
28 |
import java.text.DateFormat;
|
27 |
import java.text.SimpleDateFormat;
|
29 |
import java.text.SimpleDateFormat;
|
- |
|
30 |
import java.util.ArrayList;
|
28 |
import java.util.Date;
|
31 |
import java.util.Date;
|
29 |
import java.util.HashMap;
|
32 |
import java.util.HashMap;
|
30 |
import java.util.List;
|
33 |
import java.util.List;
|
31 |
import java.util.Map;
|
34 |
import java.util.Map;
|
32 |
|
35 |
|
Line 59... |
Line 62... |
59 |
// "Règlement achat" + SOURCE.getNom() ??
|
62 |
// "Règlement achat" + SOURCE.getNom() ??
|
60 |
this.nom = "Règlement achat " + rowFournisseur.getString("NOM") + " (" + typeRegRow.getString("NOM") + ")";
|
63 |
this.nom = "Règlement achat " + rowFournisseur.getString("NOM") + " (" + typeRegRow.getString("NOM") + ")";
|
61 |
|
64 |
|
62 |
List<SQLRow> l = regMontantRow.getReferentRows(regMontantRow.getTable().getTable("REGLER_MONTANT_ELEMENT"));
|
65 |
List<SQLRow> l = regMontantRow.getReferentRows(regMontantRow.getTable().getTable("REGLER_MONTANT_ELEMENT"));
|
63 |
int mvtSource = -1;
|
66 |
int mvtSource = -1;
|
- |
|
67 |
List<Integer> factureFids = new ArrayList<Integer>();
|
- |
|
68 |
|
64 |
for (SQLRow sqlRow : l) {
|
69 |
for (SQLRow sqlRow : l) {
|
65 |
SQLRow mvtEch = sqlRow.getForeignRow("ID_MOUVEMENT_ECHEANCE");
|
70 |
SQLRow mvtEch = sqlRow.getForeignRow("ID_MOUVEMENT_ECHEANCE");
|
66 |
if (mvtEch.getID() != mvtSource) {
|
71 |
if (mvtEch.getID() != mvtSource) {
|
67 |
getNewMouvement("REGLER_MONTANT", idRegMontant, mvtEch.getID(), mvtEch.getInt("ID_PIECE"));
|
72 |
getNewMouvement("REGLER_MONTANT", idRegMontant, mvtEch.getID(), mvtEch.getInt("ID_PIECE"));
|
68 |
if (mvtSource == -1) {
|
73 |
if (mvtSource == -1) {
|
69 |
mvtSource = mvtEch.getID();
|
74 |
mvtSource = mvtEch.getID();
|
70 |
}
|
75 |
}
|
71 |
}
|
76 |
}
|
- |
|
77 |
if (!sqlRow.isForeignEmpty("ID_ECHEANCE_FOURNISSEUR")) {
|
- |
|
78 |
SQLRow ech = sqlRow.getForeign("ID_ECHEANCE_FOURNISSEUR");
|
- |
|
79 |
if (!ech.isForeignEmpty("ID_FACTURE_FOURNISSEUR")) {
|
- |
|
80 |
factureFids.add(ech.getForeignID("ID_FACTURE_FOURNISSEUR"));
|
- |
|
81 |
}
|
- |
|
82 |
}
|
72 |
}
|
83 |
}
|
73 |
|
84 |
|
74 |
SQLRow rowMvtSource = tableMouvement.getRow(mvtSource);
|
85 |
SQLRow rowMvtSource = tableMouvement.getRow(mvtSource);
|
75 |
if (rowMvtSource == null) {
|
86 |
if (rowMvtSource == null) {
|
76 |
throw new IllegalStateException("Aucun mouvement source associé aux échéances.\n(Mouvement source : " + mvtSource + ", REGLER_MONTANT " + regMontantRow.getID() + ")");
|
87 |
throw new IllegalStateException("Aucun mouvement source associé aux échéances.\n(Mouvement source : " + mvtSource + ", REGLER_MONTANT " + regMontantRow.getID() + ")");
|
Line 122... |
Line 133... |
122 |
this.putValue("DEBIT", new Long(0));
|
133 |
this.putValue("DEBIT", new Long(0));
|
123 |
this.putValue("CREDIT", new Long(prixTTC.getLongValue()));
|
134 |
this.putValue("CREDIT", new Long(prixTTC.getLongValue()));
|
124 |
ajoutEcriture();
|
135 |
ajoutEcriture();
|
125 |
|
136 |
|
126 |
}
|
137 |
}
|
- |
|
138 |
|
- |
|
139 |
setDateReglement(regMontantRow.getTable().getTable("FACTURE_FOURNISSEUR"), factureFids, this.date);
|
- |
|
140 |
|
127 |
} else {
|
141 |
} else {
|
128 |
|
142 |
|
129 |
Date dateEch = ModeDeReglementSQLElement.calculDate(modeRegRow.getInt("AJOURS"), modeRegRow.getInt("LENJOUR"), this.date);
|
143 |
Date dateEch = ModeDeReglementSQLElement.calculDate(modeRegRow.getInt("AJOURS"), modeRegRow.getInt("LENJOUR"), this.date);
|
130 |
DateFormat dateFormat = new SimpleDateFormat();
|
144 |
DateFormat dateFormat = new SimpleDateFormat();
|
131 |
System.out.println("Date d'échéance " + dateFormat.format(dateEch));
|
145 |
System.out.println("Date d'échéance " + dateFormat.format(dateEch));
|
Line 139... |
Line 153... |
139 |
} else {
|
153 |
} else {
|
140 |
|
154 |
|
141 |
// Ajout dans echeance
|
155 |
// Ajout dans echeance
|
142 |
Map<String, Object> mEcheance = new HashMap<String, Object>();
|
156 |
Map<String, Object> mEcheance = new HashMap<String, Object>();
|
143 |
|
157 |
|
144 |
this.idMvt = getNewMouvement("ECHEANCE_FOURNISSEUR", 1, rowMvtSource.getID(), rowMvtSource.getInt("ID_PIECE"));
|
158 |
this.idMvt = getNewMouvement(rowMvtSource.getString("SOURCE"), rowMvtSource.getInt("IDSOURCE"), rowMvtSource.getID(), rowMvtSource.getInt("ID_PIECE"));
|
145 |
mEcheance.put("ID_MOUVEMENT", new Integer(this.idMvt));
|
159 |
mEcheance.put("ID_MOUVEMENT", new Integer(this.idMvt));
|
146 |
|
160 |
|
147 |
mEcheance.put("DATE", dateEch);
|
161 |
mEcheance.put("DATE", dateEch);
|
148 |
mEcheance.put("MONTANT", new Long(prixTTC.getLongValue()));
|
162 |
mEcheance.put("MONTANT", new Long(prixTTC.getLongValue()));
|
149 |
|
163 |
|
Line 160... |
Line 174... |
160 |
|
174 |
|
161 |
}
|
175 |
}
|
162 |
}
|
176 |
}
|
163 |
}
|
177 |
}
|
164 |
|
178 |
|
- |
|
179 |
private void setDateReglement(SQLTable table, List<Integer> ids, Date d) throws SQLException {
|
- |
|
180 |
if (!ids.isEmpty()) {
|
- |
|
181 |
UpdateBuilder b = new UpdateBuilder(table);
|
- |
|
182 |
b.setObject("DATE_REGLEMENT", d);
|
- |
|
183 |
b.setWhere(new Where(table.getKey(), ids));
|
- |
|
184 |
table.getDBSystemRoot().getDataSource().execute(b.asString());
|
- |
|
185 |
}
|
- |
|
186 |
}
|
- |
|
187 |
|
165 |
private void paiementCheque(Date dateEch, SQLRow rowMvtSource, int idFourn, int idRegMontant) throws SQLException {
|
188 |
private void paiementCheque(Date dateEch, SQLRow rowMvtSource, int idFourn, int idRegMontant) throws SQLException {
|
166 |
|
189 |
|
167 |
SQLRow regMontantRow = base.getTable("REGLER_MONTANT").getRow(idRegMontant);
|
190 |
SQLRow regMontantRow = base.getTable("REGLER_MONTANT").getRow(idRegMontant);
|
168 |
PrixTTC prixTTC = new PrixTTC(((Long) regMontantRow.getObject("MONTANT")).longValue());
|
191 |
PrixTTC prixTTC = new PrixTTC(((Long) regMontantRow.getObject("MONTANT")).longValue());
|
169 |
|
192 |
|