Regalamiunsorriso/decompiled-libs/www/acxent-common-1.0.1/it/acxent/contab/DocumentoPagamento.java

974 lines
36 KiB
Java
Raw Normal View History

2026-04-22 18:41:37 +02:00
package it.acxent.contab;
import com.lowagie.text.Cell;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.HeaderFooter;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;
import it.acxent.anag.TipoPagamento;
import it.acxent.db.ApplParmFull;
import it.acxent.db.ResParm;
import it.acxent.db.WcString;
import it.acxent.util.DoubleOperator;
import it.acxent.util.FileWr;
import it.acxent.util.PdfFontFactory;
import it.acxent.util.SimpleDateFormat;
import it.acxent.util.Vectumerator;
import java.awt.Color;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.Serializable;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.NumberFormat;
import java.util.Calendar;
public class DocumentoPagamento extends _ContabAdapter implements Serializable {
private static final long serialVersionUID = 8044331984020899695L;
private long id_documentoPagamento;
private long id_documento;
private Documento documento;
private Date data;
private double importo;
private String nota;
private long id_tipoPagamento;
private TipoPagamento tipoPagamento;
private long flgTipoMovimento;
private long flgTipoIncasso;
public static final long DOCUMENTI_TUTTI = 0L;
public static final long DOCUMENTI_APERTI = 1L;
public static final long DOCUMENTI_CHIUSI = 2L;
public static final long TIPO_MOVIMENTO_DOCUMENTO = 1L;
public static final long TIPO_MOVIMENTO_RATA = 2L;
public static final long TIPO_MOVIMENTO_STORNO = 3L;
public static final long TIPO_INCASSO_ACCONTO = 0L;
public static final long TIPO_INCASSO_SALDO = 1L;
public DocumentoPagamento(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public DocumentoPagamento() {}
public long getId_documentoPagamento() {
return this.id_documentoPagamento;
}
public void setId_documentoPagamento(long id_incassoPagamento) {
this.id_documentoPagamento = id_incassoPagamento;
}
public Date getData() {
return this.data;
}
public void setData(Date data) {
this.data = data;
}
public double getImporto() {
return this.importo;
}
public void setImporto(double importo) {
this.importo = importo;
}
public String getNota() {
return (this.nota == null) ? "" : this.nota.trim();
}
public void setNota(String nota) {
this.nota = nota;
}
public long getId_documento() {
return this.id_documento;
}
public void setId_documento(long id_documento) {
this.id_documento = id_documento;
}
public Documento getDocumento() {
this.documento = (Documento)getSecondaryObject(this.documento, Documento.class, getId_documento());
return this.documento;
}
public void setDocumento(Documento documento) {
this.documento = documento;
}
public Vectumerator<DocumentoPagamento> findByCROldxx(DocumentoPagamentoCR CR, int pageNumber, int pageRows) {
String pre_S_Sql_Find = "SELECT * FROM DOCUMENTO_PAGAMENTO AS A WHERE A.id_documento IN (";
String post_S_Sql_Find = ")";
String s_Sql_Find = "";
if (CR.getFlgTipoSaldo() > 0L) {
s_Sql_Find = "select A.id_documento ";
} else {
s_Sql_Find = "select A.* ";
}
s_Sql_Find = s_Sql_Find + " FROM DOCUMENTO_PAGAMENTO AS A INNER JOIN DOCUMENTO AS B ON A.id_documento = B.id_documento ";
String s_Sql_Group = "";
String s_Sql_Order = " ORDER BY B.progDocumento, B.dataDocumento ";
String s_Sql_Having = "";
if (!CR.getFlgReport().isEmpty())
s_Sql_Order = " ORDER BY B.nominativoDocumento, B.progDocumento, B.dataDocumento ";
WcString wc = new WcString();
if (CR.getId_clifor() > 0L)
wc.addWc(" B.id_clifor = " + CR.getId_clifor());
if (CR.getDataDa() != null)
wc.addWc(" A.data >= ? ");
if (CR.getDataA() != null)
wc.addWc(" A.data <= ? ");
if (CR.getDataFatturaDa() != null)
wc.addWc(" B.dataDocumento >= ? ");
if (CR.getDataFatturaA() != null)
wc.addWc(" B.dataDocumento <= ? ");
if (CR.getId_tipoPagamentoS() > 0L)
wc.addWc(" A.id_tipoPagamento = " + CR.getId_tipoPagamentoS());
if (CR.getNumeroFattura() > 0L)
wc.addWc(" B.progDocumento = " + CR.getNumeroFattura());
if (CR.getAnnoFattura() > 0L)
wc.addWc(" B.id_esercizio = " + CR.getAnnoFattura());
if (CR.getId_documento() > 0L)
wc.addWc(" A.id_documento = " + CR.getId_documento());
if (CR.getId_tipoDocumento() > 0L)
wc.addWc(" B.id_tipoDocumento = " + CR.getId_tipoDocumento());
if (!CR.getRiferimento().isEmpty()) {
s_Sql_Find = s_Sql_Find + " inner join TIPO_DOCUMENTO AS T ON B.id_tipoDocumento=T.id_tipoDocumento";
wc.addWc(" T.riferimento = '" + CR.getRiferimento() + "'");
}
String sql = "";
if (CR.getFlgTipoSaldo() > 0L) {
sql = pre_S_Sql_Find + pre_S_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Group + s_Sql_Having + s_Sql_Order;
} else {
sql = s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Group + s_Sql_Having;
}
try {
PreparedStatement stmt = getConn().prepareStatement(sql);
int dataCount = 0;
if (CR.getDataDa() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataDa());
}
if (CR.getDataA() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataA());
}
if (CR.getDataFatturaDa() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataFatturaDa());
}
if (CR.getDataFatturaA() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataFatturaA());
}
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator<DocumentoPagamento> findSaldiByCR(DocumentoPagamentoCR CR, int pageNumber, int pageRows) {
String pre_S_Sql_Find = "SELECT * FROM DOCUMENTO_PAGAMENTO AS A WHERE A.id_documento IN (";
String post_S_Sql_Find = ")";
String s_Sql_Find = "";
if (CR.getFlgTipoSaldo() > 0L) {
s_Sql_Find = "select A.id_documento ";
} else {
s_Sql_Find = "select A.* ";
}
s_Sql_Find = s_Sql_Find + " FROM DOCUMENTO_PAGAMENTO AS A INNER JOIN DOCUMENTO AS B ON A.id_documento = B.id_documento ";
String s_Sql_Group = "";
String s_Sql_Order = " ORDER BY B.progDocumento, B.dataDocumento ";
String s_Sql_Having = "";
if (CR.getFlgTipoSaldo() == 1L) {
s_Sql_Group = " GROUP BY id_documento ";
s_Sql_Having = " HAVING SUM(importo) > 0 ";
} else if (CR.getFlgTipoSaldo() == 2L) {
s_Sql_Group = " GROUP BY id_documento ";
s_Sql_Having = " HAVING SUM(importo) <= 0 ";
}
if (!CR.getFlgReport().isEmpty())
s_Sql_Order = " ORDER BY B.nominativoDocumento, B.progDocumento, B.dataDocumento ";
WcString wc = new WcString();
if (CR.getId_clifor() > 0L)
wc.addWc(" B.id_clifor = " + CR.getId_clifor());
if (CR.getDataDa() != null)
wc.addWc(" A.data >= ? ");
if (CR.getDataA() != null)
wc.addWc(" A.data <= ? ");
if (CR.getDataFatturaDa() != null)
wc.addWc(" B.dataDocumento >= ? ");
if (CR.getDataFatturaA() != null)
wc.addWc(" B.dataDocumento <= ? ");
if (CR.getId_tipoPagamentoS() > 0L)
wc.addWc(" A.id_tipoPagamento = " + CR.getId_tipoPagamentoS());
if (CR.getNumeroFattura() > 0L)
wc.addWc(" B.progDocumento = " + CR.getNumeroFattura());
if (CR.getAnnoFattura() > 0L)
wc.addWc(" B.id_esercizio = " + CR.getAnnoFattura());
if (CR.getId_documento() > 0L)
wc.addWc(" A.id_documento = " + CR.getId_documento());
String sql = "";
if (CR.getFlgTipoSaldo() > 0L) {
sql = pre_S_Sql_Find + pre_S_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Group + s_Sql_Having + s_Sql_Order;
} else {
sql = s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Group + s_Sql_Having;
}
try {
PreparedStatement stmt = getConn().prepareStatement(sql);
int dataCount = 0;
if (CR.getDataDa() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataDa());
}
if (CR.getDataA() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataA());
}
if (CR.getDataFatturaDa() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataFatturaDa());
}
if (CR.getDataFatturaA() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataFatturaA());
}
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
protected void deleteCascade() {}
public void findRecordDocumentoByDocumento(long id_documento) {
String s_Sql_Find = "select A.* from DOCUMENTO_PAGAMENTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" A.id_documento = " + id_documento);
wc.addWc(" A.flgTipoMovimento = 1");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public double getSaldoControlloByDocumento() {
String s_Sql_Find = "select SUM(importo) AS _sum from DOCUMENTO_PAGAMENTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" A.id_documento = " + getId_documento());
if (getId_documentoPagamento() > 0L)
wc.addWc(" A.id_documentoPagamento != " + getId_documentoPagamento());
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return getSum(stmt);
} catch (SQLException e) {
handleDebug(e);
return 0.0D;
}
}
public double getSaldoByDocumento(long id_documento) {
String s_Sql_Find = "select SUM(importo) AS _sum from DOCUMENTO_PAGAMENTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" A.id_documento = " + id_documento);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return getSum(stmt);
} catch (SQLException e) {
handleDebug(e);
return 0.0D;
}
}
public double getTotByDocumento(long id_documento) {
String s_Sql_Find = "select SUM(importo) as _sum from DOCUMENTO_PAGAMENTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" A.id_documento = " + id_documento);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return getSum(stmt);
} catch (SQLException e) {
handleDebug(e);
return 0.0D;
}
}
public double getSaldoRateByDocumento(long id_documento) {
String s_Sql_Find = "select SUM(importo) as _sum from DOCUMENTO_PAGAMENTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" A.id_documento = " + id_documento);
wc.addWc(" (A.flgTipoMovimento = 2 OR A.flgTipoMovimento = 3)");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return getSum(stmt);
} catch (SQLException e) {
handleDebug(e);
return 0.0D;
}
}
public ResParm delete() {
ResParm rp = new ResParm(true);
rp = super.delete();
return rp;
}
public Vectumerator<DocumentoPagamento> findByClifor(long id_clifor, long tipoDocumenti) {
String s_Sql_Find = "select A.*, SUM(importo) AS importo, B.flgPagata as flgPagata FROM DOCUMENTO_PAGAMENTO AS A INNER JOIN DOCUMENTO AS B ON A.id_documento = B.id_documento ";
String s_Sql_Group = " GROUP BY id_documento";
String s_Sql_Order = "";
String s_Sql_Having = "";
WcString wc = new WcString();
wc.addWc(" B.id_clifor = " + id_clifor);
if (tipoDocumenti == 1L) {
s_Sql_Having = " HAVING SUM(importo) != 0 and (flgPagata is null or flgPagata=0)";
} else if (tipoDocumenti == 2L) {
s_Sql_Having = " HAVING SUM(importo) = 0";
}
try {
PreparedStatement stmt = getConn()
.prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Group + s_Sql_Order);
return findRows(stmt);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public long getId_tipoPagamento() {
return this.id_tipoPagamento;
}
public void setId_tipoPagamento(long id_tipoPagamento) {
this.id_tipoPagamento = id_tipoPagamento;
}
public TipoPagamento getTipoPagamento() {
this.tipoPagamento = (TipoPagamento)getSecondaryObject(this.tipoPagamento, TipoPagamento.class, getId_tipoPagamento());
return this.tipoPagamento;
}
public void setTipoPagamento(TipoPagamento pagamento) {
this.tipoPagamento = pagamento;
}
public long getFlgTipoMovimento() {
return this.flgTipoMovimento;
}
public void setFlgTipoMovimento(long flgTipoMovimento) {
this.flgTipoMovimento = flgTipoMovimento;
}
public ResParm save() {
if (getFlgTipoMovimento() == 2L || getFlgTipoMovimento() == 3L) {
if (getDocumento().getTipoDocumento().isFatturaVendita() || getDocumento().getTipoDocumento().isNotaCreditoAcquisto())
setImporto(-1.0D * getImporto());
} else if (getFlgTipoMovimento() == 1L) {
if (getDocumento().getTipoDocumento().isFatturaAcquisto() || getDocumento().getTipoDocumento().isNotaCreditoVendita())
setImporto(-1.0D * getImporto());
}
ResParm rp = super.save();
if (rp.getStatus() &&
getFlgTipoMovimento() == 2L) {
if (getFlgTipoIncasso() != 1L) {
double totDoc = getTotByDocumento(this.id_documento);
if (getDocumento().getTipoDocumento().isFatturaAcquisto() || getDocumento().getTipoDocumento().isNotaCreditoVendita())
totDoc *= -1.0D;
if (totDoc <= 0.0D) {
setFlgTipoIncasso(1L);
} else {
setFlgTipoIncasso(0L);
}
}
if (getFlgTipoIncasso() == 1L) {
Documento doc = new Documento(getApFull());
doc.findByPrimaryKey(getId_documento());
doc.impostaPagato(getData());
}
}
return rp;
}
public double getImportoVis() {
if (getImporto() < 0.0D)
return getImporto() * -1.0D;
return getImporto();
}
protected void afterDelete() {
super.afterDelete();
}
public boolean hasPagamentiEffettuatiByDocumento(long id_documento) {
String s_Sql_Find = "select A.* from DOCUMENTO_PAGAMENTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" A.id_documento = " + id_documento);
wc.addWc(" A.flgTipoMovimento = 2");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
Vectumerator<DocumentoPagamento> vec = findRows(stmt, 1, 1);
return vec.hasMoreElements();
} catch (SQLException e) {
handleDebug(e);
return false;
}
}
public Vectumerator<DocumentoPagamento> findByDocumento(long l_id_documento) {
if (l_id_documento == 0L)
return AB_EMPTY_VECTUMERATOR;
String s_Sql_Find = "select A.* from DOCUMENTO_PAGAMENTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" A.id_documento = " + l_id_documento);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return findRows(stmt);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public long getFlgTipoIncasso() {
return this.flgTipoIncasso;
}
public void setFlgTipoIncasso(long flgTipoIncasso) {
this.flgTipoIncasso = flgTipoIncasso;
}
public static final String getTipoIncasso(long l_flgTipoIncasso) {
String ret = "";
if (l_flgTipoIncasso == 0L) {
ret = "Acconto";
} else if (l_flgTipoIncasso == 1L) {
ret = "Saldo";
}
return ret;
}
public String getTipoIncasso() {
return getTipoIncasso(getFlgTipoIncasso());
}
public String getDescrizioneTipoMovimento() {
String ret = "";
if (getFlgTipoMovimento() == 1L) {
ret = "Documento";
} else if (getFlgTipoMovimento() == 2L) {
ret = "Rata";
} else if (getFlgTipoMovimento() == 3L) {
ret = "Storno";
}
return ret;
}
public Vectumerator<DocumentoPagamento> findByCR(DocumentoPagamentoCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "SELECT A.* FROM DOCUMENTO_PAGAMENTO AS A INNER JOIN DOCUMENTO AS B ON A.id_documento = B.id_documento inner join CLIFOR AS C ON B.id_clifor=C.id_clifor";
String s_Sql_Order = " ORDER BY B.id_esercizio, B.progDocumento, B.dataDocumento ";
if (!CR.getFlgReport().isEmpty())
if (CR.getFlgClienteFornitore().equals("F")) {
s_Sql_Order = " ORDER BY C.cognome, C.nome , B.dataRiferimento, B.riferimento ";
} else {
s_Sql_Order = " ORDER BY C.cognome, C.nome ,B.id_esercizio, B.progDocumento, B.dataDocumento ";
}
if (CR.getDataScadenzaA() != null || CR.getDataScadenzaDa() != null)
s_Sql_Find = s_Sql_Find + " left join DOCUMENTO_SCADENZA AS DS ON B.id_documento=DS.id_documento";
WcString wc = new WcString();
if (CR.getId_clifor() > 0L)
wc.addWc(" B.id_clifor = " + CR.getId_clifor());
if (CR.getId_tipoPagamentoS() > 0L)
wc.addWc(" A.id_tipoPagamento = " + CR.getId_tipoPagamentoS());
if (CR.getNumeroFattura() > 0L)
wc.addWc(" B.progDocumento = " + CR.getNumeroFattura());
if (CR.getAnnoFattura() > 0L)
wc.addWc(" B.id_esercizio = " + CR.getAnnoFattura());
if (CR.getId_documento() > 0L)
wc.addWc(" A.id_documento = " + CR.getId_documento());
if (CR.getId_tipoDocumento() > 0L)
wc.addWc(" B.id_tipoDocumento = " + CR.getId_tipoDocumento());
if (!CR.getRiferimento().isEmpty() || !CR.getFlgClienteFornitore().isEmpty()) {
s_Sql_Find = s_Sql_Find + " inner join TIPO_DOCUMENTO AS T ON B.id_tipoDocumento=T.id_tipoDocumento";
if (!CR.getRiferimento().isEmpty())
wc.addWc(" T.riferimento = '" + CR.getRiferimento() + "'");
if (!CR.getFlgClienteFornitore().isEmpty())
wc.addWc(" T.flgClienteFornitore = '" + CR.getFlgClienteFornitore() + "'");
}
if (CR.getFlgTipoSaldo() == 1L) {
wc.addWc("( B.flgPagata is null or B.flgPagata =0) ");
} else if (CR.getFlgTipoSaldo() == 2L) {
wc.addWc("B.flgPagata= 1 ");
}
if (!CR.getFlgTipoClifor().isEmpty())
wc.addWc("C.flgTipo='" + CR.getFlgTipoClifor() + "'");
if (CR.getDataDa() != null)
wc.addWc(" A.data >= ? ");
if (CR.getDataA() != null)
wc.addWc(" A.data <= ? ");
if (CR.getDataFatturaDa() != null)
wc.addWc(" B.dataDocumento >= ? ");
if (CR.getDataFatturaA() != null)
wc.addWc(" B.dataDocumento <= ? ");
if (CR.getDataRiferimentoDa() != null)
wc.addWc(" B.dataRiferimento >= ? ");
if (CR.getDataRiferimentoA() != null)
wc.addWc(" B.dataRiferimento <= ? ");
if (CR.getDataScadenzaDa() != null)
wc.addWc(" DS.dataScadenza >= ? ");
if (CR.getDataScadenzaA() != null)
wc.addWc(" DS.dataScadenza <= ? ");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
int dataCount = 0;
if (CR.getDataDa() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataDa());
}
if (CR.getDataA() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataA());
}
if (CR.getDataFatturaDa() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataFatturaDa());
}
if (CR.getDataFatturaA() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataFatturaA());
}
if (CR.getDataRiferimentoDa() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataRiferimentoDa());
}
if (CR.getDataRiferimentoA() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataRiferimentoA());
}
if (CR.getDataScadenzaDa() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataScadenzaDa());
}
if (CR.getDataScadenzaA() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataScadenzaA());
}
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public ByteArrayOutputStream creaReportPdf(DocumentoPagamentoCR CR) {
ByteArrayOutputStream ba = new ByteArrayOutputStream();
try {
this.document = new Document(PageSize.A4, 20.0F, 20.0F, 20.0F, 10.0F);
this.writer = PdfWriter.getInstance(this.document, ba);
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat sdfh = new SimpleDateFormat("hh:mm");
Phrase pH = new Phrase("Data/ora stampa: " + sdf.format(getToday()) + " " + sdfh.format(Long.valueOf(cal.getTimeInMillis())) + " pag. ");
HeaderFooter footer = new HeaderFooter(pH, true);
footer.setAlignment(2);
footer.setBorder(0);
this.document.setFooter(footer);
this.document.open();
CR.setFilePdf(getPathTmpFull() + "ReportPagamenti.pdf");
this.document = creaReport(CR);
this.document.close();
this.document = null;
FileOutputStream fos = new FileOutputStream(new File(CR.getFilePdf()));
fos.write(ba.toByteArray());
fos.close();
System.out.println("Creato file documento " + CR.getFilePdf());
} catch (Exception e) {
e.printStackTrace();
}
return ba;
}
public ResParm creaFileCvs(DocumentoPagamentoCR CR) {
ResParm rp = new ResParm(true);
try {
Vectumerator<DocumentoPagamento> list = findByCR(CR, 0, 0);
DoubleOperator dpRottura = new DoubleOperator();
DoubleOperator dpReport = new DoubleOperator();
DoubleOperator scadCliforTotal = new DoubleOperator();
DoubleOperator scadGrandTotal = new DoubleOperator();
String salvaDescrizioneCliente = "";
long l_id_clifor = 0L;
CR.setFileName(getPathTmp() + "exportPagamenti_" + getPathTmp() + "_" + getTimeNameForFileUpload() + ".csv");
String theCvsFile = getDocBase() + getDocBase();
String SEP = ";";
new File(theCvsFile).delete();
FileWr outCvsFile = new FileWr(theCvsFile, false);
String s1 = "Criteri di ricerca: " + CR.getDescrizioneCR() + "\nIntestazione;Documento;Data;Importo;Nota;Saldo;Data Scadenza;Importo Scadenza";
outCvsFile.writeLine(s1);
while (list.hasMoreElements()) {
String l_numDocumento, l_dataDocumento, l_nota;
DocumentoPagamento row = (DocumentoPagamento)list.nextElement();
System.out.println("creaFileCvs: " + row.getDocumento().getClifor().getDescrizioneCompleta() + " " +
row.getId_documentoPagamento());
if (row.getId_documentoPagamento() == 41407L)
System.out.println("aaaa");
if (l_id_clifor != row.getDocumento().getId_clifor()) {
if (l_id_clifor > 0L) {
s1 = SEP + SEP + SEP + SEP + "TOTALE PER " + SEP + salvaDescrizioneCliente + SEP + getNf().format(dpRottura.getResult()) + SEP + SEP;
outCvsFile.writeLine(s1);
dpRottura = new DoubleOperator();
scadCliforTotal = new DoubleOperator();
}
salvaDescrizioneCliente = "";
}
salvaDescrizioneCliente = row.getDocumento().getClifor().getDescrizioneCompleta();
if (row.getDocumento().getTipoDocumento().getFlgClienteFornitore().equals("F")) {
l_numDocumento = row.getDocumento().getRiferimento();
l_dataDocumento = getDataFormat().format(row.getDocumento().getDataRiferimento());
} else {
l_numDocumento = row.getDocumento().getNumeroDocumentoCompleto();
l_dataDocumento = getDataFormat().format(row.getDocumento().getDataDocumento());
}
String l_importo = getNf().format(row.getImporto());
if (row.getFlgTipoMovimento() != 1L) {
l_nota = "Pagamento - " + row.getNota();
} else {
l_nota = row.getNota();
}
s1 = salvaDescrizioneCliente + salvaDescrizioneCliente + SEP + l_numDocumento + SEP + l_dataDocumento + SEP + l_importo + SEP;
outCvsFile.writeLine(s1);
dpRottura.add(row.getImporto());
dpReport.add(row.getImporto());
l_id_clifor = row.getDocumento().getId_clifor();
if (row.getId_tipoPagamento() == 0L) {
Vectumerator<DocumentoScadenza> vecScadenze = row.getDocumento().getElencoScadenze(CR);
while (vecScadenze.hasMoreElements()) {
DocumentoScadenza rowBeanDS = (DocumentoScadenza)vecScadenze.nextElement();
s1 = ";;;;;;" + getDataFormat().format(rowBeanDS.getDataScadenza()) + SEP + getNf().format(rowBeanDS.getImportoScadenza());
outCvsFile.writeLine(s1);
scadCliforTotal.add(rowBeanDS.getImportoScadenza());
scadGrandTotal.add(rowBeanDS.getImportoScadenza());
}
}
}
if (l_id_clifor > 0L) {
s1 = SEP + SEP + SEP + SEP + "TOTALE PER " + SEP + SEP + getNf().format(dpRottura.getResult()) + SEP + SEP;
outCvsFile.writeLine(s1);
}
if (dpReport.getResult() != 0.0D) {
s1 = SEP + SEP + SEP + SEP + "TOTALE REPORT" + SEP + SEP + getNf().format(dpReport.getResult()) + SEP + SEP;
outCvsFile.writeLine(s1);
}
outCvsFile.closeFile();
} catch (Exception e) {
handleDebug(e);
rp.setException(e);
rp.setStatus(false);
}
return rp;
}
public String getDescrizioneFlgTipoIncasso() {
String ret = "";
if (getFlgTipoIncasso() == 0L) {
ret = "Acconto";
} else if (getFlgTipoIncasso() == 1L) {
ret = "Saldo";
}
return ret;
}
public static final String getTipoMovimento(long l_flgTipoMovimento) {
String ret = "";
if (l_flgTipoMovimento == 1L) {
ret = "Documento";
} else if (l_flgTipoMovimento == 2L) {
ret = "Rata";
} else if (l_flgTipoMovimento == 3L) {
ret = "Storno";
}
return ret;
}
public String getTipoMovimento() {
return getTipoMovimento(getFlgTipoMovimento());
}
public long getId_clifor() {
return getDocumento().getId_clifor();
}
private Document creaReport(DocumentoPagamentoCR CR) {
try {
prepareNewPdfCorpoDocument();
int cellLeading = 10;
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
long id_clifor = 0L;
DoubleOperator dpRottura = new DoubleOperator();
DoubleOperator dpReport = new DoubleOperator();
String salvaDescrizioneCliente = "";
Cell cell = new Cell();
cell.add(new Chunk("REPORT PAGAMENTI", PdfFontFactory.PDF_fIntestazione));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setBorder(0);
cell.setColspan(40);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(" ", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(2);
cell.setLeading((float)cellLeading);
cell.setBorder(0);
cell.setColspan(40);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(CR.getCriteriDiRicerca(), PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setBorder(0);
cell.setColspan(40);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(" ", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(2);
cell.setLeading((float)cellLeading);
cell.setBorder(0);
cell.setColspan(40);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("Documento", PdfFontFactory.PDF_fMedioBianco));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setBackgroundColor(Color.lightGray);
cell.setLeading((float)cellLeading);
cell.setColspan(15);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("Data", PdfFontFactory.PDF_fMedioBianco));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setBackgroundColor(Color.lightGray);
cell.setLeading((float)cellLeading);
cell.setColspan(5);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("Importo", PdfFontFactory.PDF_fMedioBianco));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setBackgroundColor(Color.lightGray);
cell.setLeading((float)cellLeading);
cell.setColspan(5);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("Nota", PdfFontFactory.PDF_fMedioBianco));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setBackgroundColor(Color.lightGray);
cell.setLeading((float)cellLeading);
cell.setColspan(15);
this.pdfcorpo.addCell(cell);
this.pdfcorpo.endHeaders();
CR.setFlgReport("S");
Vectumerator<DocumentoPagamento> vec = findByCR(CR, 0, 0);
while (vec.hasMoreElements()) {
DocumentoPagamento doc = (DocumentoPagamento)vec.nextElement();
if (id_clifor != doc.getDocumento().getId_clifor()) {
if (id_clifor > 0L) {
cell = new Cell(new Chunk("Totale per " + salvaDescrizioneCliente, PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(15);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(5);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(nf.format(dpRottura.getResult()), PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(2);
cell.setLeading((float)cellLeading);
cell.setColspan(5);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(15);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("_", PdfFontFactory.PDF_fMedioBianco));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(40);
this.pdfcorpo.addCell(cell);
dpRottura = new DoubleOperator();
}
if (!doc.getDocumento().getClifor().getNominativoCompleto().isEmpty()) {
cell = new Cell(new Chunk(doc.getDocumento().getClifor().getDescrizioneCompleta(), PdfFontFactory.PDF_fGrandeB));
if (doc.getDocumento().getClifor().getFlgTipo().equals("F")) {
cell.add(new Chunk(" iban: " + doc.getDocumento().getClifor().getIban(), PdfFontFactory.PDF_fGrandeB));
cell.add(new Chunk(" Pag: " + doc.getDocumento().getTipoPagamento().getDescrizione(), PdfFontFactory.PDF_fMedioB));
}
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(40);
this.pdfcorpo.addCell(cell);
}
salvaDescrizioneCliente = "";
}
if (doc.getFlgTipoMovimento() == 1L) {
if (doc.getDocumento().getTipoDocumento().getFlgClienteFornitore().equals("F")) {
cell = new Cell(new Chunk(doc.getDocumento().getRiferimento(), PdfFontFactory.PDF_fMedio));
} else {
cell = new Cell(new Chunk(doc.getDocumento().getNumeroDocumentoCompleto(), PdfFontFactory.PDF_fMedio));
}
} else {
cell = new Cell(new Chunk("", PdfFontFactory.PDF_fMedio));
}
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(15);
this.pdfcorpo.addCell(cell);
if (doc.getFlgTipoMovimento() == 1L) {
if (doc.getDocumento().getTipoDocumento().getFlgClienteFornitore().equals("F")) {
cell = new Cell(new Chunk(df.format(doc.getDocumento().getDataRiferimento()), PdfFontFactory.PDF_fMedio));
} else {
cell = new Cell(new Chunk(df.format(doc.getDocumento().getDataDocumento()), PdfFontFactory.PDF_fMedio));
}
} else {
cell = new Cell(new Chunk(df.format(doc.getData()), PdfFontFactory.PDF_fMedio));
}
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(1);
cell.setLeading((float)cellLeading);
cell.setColspan(5);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(nf.format(doc.getImporto()), PdfFontFactory.PDF_fMedio));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(2);
cell.setLeading((float)cellLeading);
cell.setColspan(5);
this.pdfcorpo.addCell(cell);
if (doc.getFlgTipoMovimento() != 1L) {
cell = new Cell(new Chunk("Pagamento - ", PdfFontFactory.PDF_fMedio));
cell.add(new Chunk(doc.getNota(), PdfFontFactory.PDF_fMedio));
} else {
cell = new Cell(new Chunk(doc.getNota(), PdfFontFactory.PDF_fMedio));
}
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(15);
this.pdfcorpo.addCell(cell);
dpRottura.add(doc.getImporto());
dpReport.add(doc.getImporto());
salvaDescrizioneCliente = doc.getDocumento().getClifor().getNominativoCompleto();
id_clifor = doc.getDocumento().getId_clifor();
}
if (id_clifor > 0L) {
cell = new Cell(new Chunk("Totale per " + salvaDescrizioneCliente, PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(15);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(5);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(nf.format(dpRottura.getResult()), PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(2);
cell.setLeading((float)cellLeading);
cell.setColspan(5);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(15);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("_", PdfFontFactory.PDF_fMedioBianco));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(40);
this.pdfcorpo.addCell(cell);
}
if (dpReport.getResult() != 0.0D) {
cell = new Cell(new Chunk("Totale Report ", PdfFontFactory.PDF_fGrandissimo));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(15);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(5);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(nf.format(dpReport.getResult()), PdfFontFactory.PDF_fGrandissimo));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(2);
cell.setLeading((float)cellLeading);
cell.setColspan(5);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(15);
this.pdfcorpo.addCell(cell);
}
this.document.add((Element)this.pdfcorpo);
} catch (Exception e) {
e.printStackTrace();
}
return this.document;
}
}