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/core/sales/invoice/ui/ListeDesEcheancesClientsPanel.java
16,14 → 16,17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
import org.openconcerto.erp.config.Gestion;
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
import org.openconcerto.erp.core.common.ui.IListTotalPanel;
import org.openconcerto.erp.core.customerrelationship.customer.element.RelanceSQLElement;
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
import org.openconcerto.erp.core.finance.payment.component.EncaisserMontantSQLComponent;
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
import org.openconcerto.erp.rights.ComptaUserRight;
import org.openconcerto.erp.rights.NXRights;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.SQLBase;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.SQLTable;
34,6 → 37,7
import org.openconcerto.sql.view.IListPanel;
import org.openconcerto.sql.view.IListener;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.EmailComposer;
import org.openconcerto.utils.GestionDevise;
 
import java.awt.GridBagConstraints;
42,10 → 46,15
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Set;
 
import javax.swing.AbstractAction;
import javax.swing.JButton;
78,6 → 87,16
c.fill = GridBagConstraints.BOTH;
this.add(this.panelEcheances, c);
 
IListTotalPanel totalPanel = new IListTotalPanel(this.panelEcheances.getListe(), Arrays.asList(this.panelEcheances.getElement().getTable().getField("MONTANT")));
 
c.weighty = 0;
c.gridy++;
c.anchor = GridBagConstraints.EAST;
c.weightx = 0;
c.fill = GridBagConstraints.NONE;
this.add(totalPanel, c);
 
c.anchor = GridBagConstraints.WEST;
c.gridx = 0;
c.gridy++;
c.gridwidth = 1;
233,6 → 252,16
}
});
 
 
if (row != null) {
menuDroit.add(new AbstractAction("Envoyer un e-mail de relance") {
 
public void actionPerformed(ActionEvent e) {
sendMail(row);
}
});
}
 
if (UserRightsManager.getCurrentUserRights().haveRight(ComptaUserRight.MENU)) {
if (row.getBoolean("REG_COMPTA")) {
 
386,6 → 415,108
}
}
 
SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.ENGLISH);
 
private void sendMail(SQLRow row) {
 
SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
SQLElement relanceElt = Configuration.getInstance().getDirectory().getElement("RELANCE");
 
this.rowSource = this.panelEcheances.getListe().getSelectedRow();
 
if (this.rowSource != null) {
int idMvtSource = MouvementSQLElement.getSourceId(rowSource.getInt("ID_MOUVEMENT"));
SQLRow rowMvtSource = base.getTable("MOUVEMENT").getRow(idMvtSource);
 
if (!rowMvtSource.getString("SOURCE").equalsIgnoreCase("SAISIE_VENTE_FACTURE")) {
this.relancer.setEnabled(false);
return;
}
int idFact = rowMvtSource.getInt("IDSOURCE");
SQLRow rowFacture = base.getTable("SAISIE_VENTE_FACTURE").getRow(idFact);
 
Set<SQLField> setContact = null;
SQLTable tableContact = Configuration.getInstance().getRoot().findTable("CONTACT");
setContact = row.getTable().getForeignKeys(tableContact);
 
Set<SQLField> setClient = null;
SQLTable tableClient = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete().getTable("CLIENT");
setClient = row.getTable().getForeignKeys(tableClient);
 
// Infos facture
Long lTotal = (Long) rowFacture.getObject("T_TTC");
Long lRestant = (Long) row.getObject("MONTANT");
Long lVerse = new Long(lTotal.longValue() - lRestant.longValue());
// m.put("FactureNumero", rowFacture.getString("NUMERO"));
// m.put("FactureTotal", GestionDevise.currencyToString(lTotal.longValue(), true));
// m.put("FactureRestant", GestionDevise.currencyToString(lRestant.longValue(), true));
// m.put("FactureVerse", GestionDevise.currencyToString(lVerse.longValue(), true));
// m.put("FactureDate", dateFormat2.format((Date) rowFacture.getObject("DATE")));
Date dFacture = (Date) rowFacture.getObject("DATE");
SQLRow modeRegRow = rowFacture.getForeignRow("ID_MODE_REGLEMENT");
Date dateEch = ModeDeReglementSQLElement.calculDate(modeRegRow.getInt("AJOURS"), modeRegRow.getInt("LENJOUR"), dFacture);
 
final String text = "Date: "
+ dateFormat.format(new Date())
+ "\n"
+ "Concerning : Late Payment reminder\n"
+ "\n\n\nTo "
+ rowFacture.getForeign("ID_CLIENT").getString("NOM")
+ ","
+
 
"\n\n\nIt has come to our attention that the following invoice has not been paid to this day."
+
 
"\nInvoice # "
+ rowFacture.getString("NUMERO")
+ " from "
+ dateFormat.format(rowFacture.getDate("DATE").getTime())
+ " of "
+ GestionDevise.currencyToString(lRestant.longValue(), true)
+ " duedate "
+ dateFormat.format(dateEch)
+ ".\nWe assume that this is a mere oversight and we would appreciate it if you would settle this invoice as soon as possible. In the event that this has already been accomplished in the meantime, please ignore this notice."
+
 
"\n\n\nThanking you in advance.";
String mail = "";
for (SQLField field : setContact) {
if (mail == null || mail.trim().length() == 0) {
mail = row.getForeignRow(field.getName()).getString("EMAIL");
}
}
 
for (SQLField field : setClient) {
SQLRow rowCli = row.getForeignRow(field.getName());
if (mail == null || mail.trim().length() == 0) {
mail = rowCli.getString("MAIL");
}
}
 
final String adresseMail = mail;
 
final Thread t = new Thread() {
@Override
public void run() {
 
try {
EmailComposer.getInstance().compose(adresseMail, "Late Payment reminder", text, null);
} catch (IOException exn) {
// TODO Bloc catch auto-généré
exn.printStackTrace();
} catch (InterruptedException exn) {
// TODO Bloc catch auto-généré
exn.printStackTrace();
}
 
}
};
 
t.start();
}
}
 
public IListPanel getListPanelEcheancesClients() {
return this.panelEcheances;
}