OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 72 → Rev 73

/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/invoice/ui/ListeDesEcheancesClientsPanel.java
16,17 → 16,16
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.IListFilterDatePanel;
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;
36,9 → 35,8
import org.openconcerto.sql.view.EditPanelListener;
import org.openconcerto.sql.view.IListPanel;
import org.openconcerto.sql.view.IListener;
import org.openconcerto.sql.view.list.IListe;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.EmailComposer;
import org.openconcerto.utils.GestionDevise;
 
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
46,25 → 44,17
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.MathContext;
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;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
 
75,12 → 65,16
private EditFrame editRelance = null;
private JButton relancer, encaisser;
 
public ListeDesEcheancesClientsPanel() {
this(false);
}
 
// TODO GEstion Relance (??? loi NRE pour le calcul des penalites)
public ListeDesEcheancesClientsPanel() {
public ListeDesEcheancesClientsPanel(boolean onlyOld) {
this.setLayout(new GridBagLayout());
final GridBagConstraints c = new DefaultGridBagConstraints();
 
this.panelEcheances = new ListPanelEcheancesClients();
this.panelEcheances = new ListPanelEcheancesClients(onlyOld);
 
// PANEL AVEC LA LISTE DES ECHEANCES
c.weightx = 1;
89,10 → 83,18
c.fill = GridBagConstraints.BOTH;
this.add(this.panelEcheances, c);
 
IListTotalPanel totalPanel = new IListTotalPanel(this.panelEcheances.getListe(), Arrays.asList(this.panelEcheances.getElement().getTable().getField("MONTANT")));
final IListe liste = this.panelEcheances.getListe();
IListFilterDatePanel datePanel = new IListFilterDatePanel(liste, liste.getRequest().getPrimaryTable().getField("DATE"), IListFilterDatePanel.getDefaultMap());
 
c.weighty = 0;
c.gridy++;
c.weightx = 1;
this.add(datePanel, c);
 
IListTotalPanel totalPanel = new IListTotalPanel(liste, Arrays.asList(this.panelEcheances.getElement().getTable().getField("MONTANT")));
 
c.weighty = 0;
c.gridy++;
c.anchor = GridBagConstraints.EAST;
c.weightx = 0;
c.fill = GridBagConstraints.NONE;
243,88 → 245,10
}
}
 
// Gestion du clic droit
if (mE.getButton() == MouseEvent.BUTTON3) {
JPopupMenu menuDroit = new JPopupMenu();
 
menuDroit.add(new AbstractAction("Voir la source") {
 
public void actionPerformed(ActionEvent e) {
MouvementSQLElement.showSource(row.getInt("ID_MOUVEMENT"));
}
});
 
 
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")) {
 
menuDroit.add(new AbstractAction("Annuler la régularisation en comptabilité") {
 
public void actionPerformed(ActionEvent e) {
 
int answer = JOptionPane.showConfirmDialog(ListeDesEcheancesClientsPanel.this, "Etes vous sûr de vouloir annuler la régularisation ?");
if (answer == JOptionPane.YES_OPTION) {
 
SQLRowValues rowVals = row.createEmptyUpdateRow();
rowVals.put("REG_COMPTA", Boolean.FALSE);
try {
rowVals.commit();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
} else {
 
menuDroit.add(new AbstractAction("Régularisation en comptabilité") {
 
public void actionPerformed(ActionEvent e) {
 
String price = GestionDevise.currencyToString(row.getLong("MONTANT"));
SQLRow rowClient = row.getForeignRow("ID_CLIENT");
String nomClient = rowClient.getString("NOM");
String piece = "";
SQLRow rowMvt = row.getForeignRow("ID_MOUVEMENT");
if (rowMvt != null) {
SQLRow rowPiece = rowMvt.getForeignRow("ID_PIECE");
piece = rowPiece.getString("NOM");
}
int answer = JOptionPane.showConfirmDialog(ListeDesEcheancesClientsPanel.this, "Etes vous sûr de vouloir régulariser l'échéance de " + nomClient
+ " d'un montant de " + price + "€ avec une saisie au kilometre?\nNom de la piéce : " + piece + ".");
if (answer == JOptionPane.YES_OPTION) {
 
SQLRowValues rowVals = row.createEmptyUpdateRow();
rowVals.put("REG_COMPTA", Boolean.TRUE);
try {
rowVals.commit();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
}
}
 
menuDroit.show(mE.getComponent(), mE.getX(), mE.getY());
}
 
}
});
 
this.panelEcheances.getListe().addIListener(new IListener() {
liste.addIListener(new IListener() {
public void selectionId(int id, int field) {
if (id > 1) {
final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
417,129 → 341,6
}
}
 
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 lRestantDevise = lRestant.longValue();
final String devise;
SQLRow rowTarif = rowFacture.getForeign("ID_TARIF");
if (rowTarif != null && !rowTarif.isUndefined()) {
SQLRow rowDevise = rowTarif.getForeign("ID_DEVISE");
BigDecimal t = (BigDecimal) rowDevise.getObject("TAUX");
BigDecimal bigDecimal = new BigDecimal(lRestantDevise);
lRestantDevise = (t.equals(BigDecimal.ZERO) ? lRestantDevise : bigDecimal.multiply(t, MathContext.DECIMAL128).setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
if (rowDevise.getString("CODE").trim().length() > 0) {
devise = rowDevise.getString("CODE");
} else {
devise = "€";
}
} else {
devise = "€";
}
 
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 references = rowFacture.getString("NOM");
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 "
+ devise
+ " "
+ GestionDevise.currencyToString(lRestantDevise, true)
+ " duedate "
+ dateFormat.format(dateEch)
+ (references.trim().length() == 0 ? "" : (". Your references : " + references))
+ ".\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 - " + references, text);
} 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;
}