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

794 lines
30 KiB
Java

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.Banca;
import it.acxent.db.ApplParmFull;
import it.acxent.db.ResParm;
import it.acxent.db.WcString;
import it.acxent.util.DoubleOperator;
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;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
public class DocumentoScadenza extends _ContabAdapter implements Serializable {
private static final long serialVersionUID = -4810747675006169924L;
private long id_documentoScadenza;
private long id_documento;
private Documento documento;
private long id_distintaRiba;
private DistintaRiba distintaRiba;
private Date dataScadenza;
private double importoScadenza;
private long flgScadenzaSelezionata;
private long flgAccorpata;
private String listaDocumenti;
public DocumentoScadenza(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public DocumentoScadenza() {}
public long getId_documentoScadenza() {
return this.id_documentoScadenza;
}
public void setId_documentoScadenza(long id_incassoPagamento) {
this.id_documentoScadenza = id_incassoPagamento;
}
public void setDataScadenza(Date data) {
this.dataScadenza = data;
}
public double getImportoScadenza() {
return this.importoScadenza;
}
public void setImportoScadenza(double importo) {
this.importoScadenza = importo;
}
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;
}
protected void deleteCascade() {}
public ResParm delete() {
ResParm rp = new ResParm(true);
rp = super.delete();
return rp;
}
public ResParm save() {
return super.save();
}
public Vectumerator<DocumentoScadenza> findByDocumento(long l_id_documento) {
if (l_id_documento == 0L)
return AB_EMPTY_VECTUMERATOR;
String s_Sql_Find = "select A.* from DOCUMENTO_SCADENZA AS A";
String s_Sql_Order = " order by A.dataScadenza";
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 getFlgScadenzaSelezionata() {
return this.flgScadenzaSelezionata;
}
public void setFlgScadenzaSelezionata(long flgTipoIncasso) {
this.flgScadenzaSelezionata = flgTipoIncasso;
}
public Vectumerator<DocumentoScadenza> findByCR(DocumentoScadenzaCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "";
String s_Sql_Order = "";
WcString wc = new WcString();
s_Sql_Find = "SELECT * FROM DOCUMENTO_SCADENZA AS A INNER JOIN DOCUMENTO AS B ON A.id_documento = B.id_documento LEFT JOIN TIPO_PAGAMENTO AS C ON B.id_tipoPagamento = C.id_tipoPagamento ";
if (CR.getFlgOrderImporto() == 1L) {
s_Sql_Order = " ORDER BY A.importoScadenza DESC ";
} else {
s_Sql_Order = " ORDER BY A.dataScadenza";
}
if (CR.getDataScadenzaDa() != null)
wc.addWc(" A.dataScadenza >= ? ");
if (CR.getDataScadenzaA() != null)
wc.addWc(" A.dataScadenza <= ? ");
if (CR.getId_documento() > 0L)
wc.addWc(" A.id_documento = " + CR.getId_documento());
if (CR.getFlgDaEstrarre() > 0L)
wc.addWc(" (A.id_distintaRiba = 0 OR A.id_distintaRiba IS NULL) ");
if (CR.getId_distintaRiba() > 0L)
wc.addWc(" A.id_distintaRiba = " + CR.getId_distintaRiba());
if (CR.getId_clifor() > 0L)
wc.addWc(" B.id_clifor = " + CR.getId_clifor());
if (CR.getDataFatturaDa() != null)
wc.addWc(" B.dataDocumento >= ? ");
if (CR.getDataFatturaA() != null)
wc.addWc(" B.dataDocumento <= ? ");
if (CR.getFlgTipoPagamento() > 0L)
wc.addWc(" C.flgTipoPagamento = " + CR.getFlgTipoPagamento());
if (CR.getFlgSoloRiba() > 0L) {
s_Sql_Find = s_Sql_Find + " LEFT JOIN TIPO_PAGAMENTO AS T ON B.id_tipoPagamento = T.id_tipoPagamento ";
wc.addWc(" T.flgTipoPagamento = 1");
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
int dataCount = 0;
if (CR.getDataScadenzaDa() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataScadenzaDa());
}
if (CR.getDataScadenzaA() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataScadenzaA());
}
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 ByteArrayOutputStream creaReportPdf(DocumentoScadenzaCR 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");
if (new File(CR.getFilePdf()).exists())
new File(CR.getFilePdf()).delete();
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;
}
private Document creaReport(DocumentoScadenzaCR CR) {
try {
prepareNewPdfCorpoDocument();
int cellLeading = 10;
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
long id_clifor = 0L;
DoubleOperator dpRottura = new DoubleOperator();
DoubleOperator dpReport = new DoubleOperator();
String salvaDescrizioneCliente = "";
Cell cell = new Cell();
cell.add(new Chunk("REPORT SCADENZE", 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(" ", 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();
Vectumerator<DocumentoScadenza> vec = findByCR(CR, 0, 0);
while (vec.hasMoreElements()) {
DocumentoScadenza doc = (DocumentoScadenza)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().getNominativoCompleto(), PdfFontFactory.PDF_fGrandeB));
if (doc.getDocumento().getClifor().getFlgTipo().equals("F"))
cell.add(new Chunk(" iban: " + doc.getDocumento().getClifor().getIban(), PdfFontFactory.PDF_fGrandeB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(40);
this.pdfcorpo.addCell(cell);
}
salvaDescrizioneCliente = "";
}
dpRottura.add(doc.getImportoScadenza());
dpReport.add(doc.getImportoScadenza());
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;
}
public long getId_distintaRiba() {
return this.id_distintaRiba;
}
public void setId_distintaRiba(long id_distintaRiba) {
this.id_distintaRiba = id_distintaRiba;
setDistintaRiba(null);
}
public DistintaRiba getDistintaRiba() {
this.distintaRiba = (DistintaRiba)getSecondaryObject(this.distintaRiba, DistintaRiba.class, getId_distintaRiba());
return this.distintaRiba;
}
public void setDistintaRiba(DistintaRiba distintaRiba) {
this.distintaRiba = distintaRiba;
}
public Date getDataScadenza() {
return this.dataScadenza;
}
public ResParm deleteByDocumento(long id_documento) {
String sql = "DELETE FROM DOCUMENTO_SCADENZA WHERE id_documento = " + id_documento;
return delete(sql);
}
public long getFlgAccorpata() {
return this.flgAccorpata;
}
public void setFlgAccorpata(long flgAccorpata) {
this.flgAccorpata = flgAccorpata;
}
public String getListaDocumenti() {
return (this.listaDocumenti == null) ? "" : this.listaDocumenti;
}
public String getListaDocumentiPdf() {
if (getFlgAccorpata() == 0L)
return getDocumento().getTipoDocumento().getCodice() + " - " + getDocumento().getTipoDocumento().getCodice() + " del " + getDocumento().getNumeroDocumento();
return getListaDocumenti().replace("<br>", " ");
}
public void setListaDocumenti(String listaDocumenti) {
this.listaDocumenti = listaDocumenti;
}
public double getTotaleScadenzeByCR(DocumentoScadenzaCR CR) {
if ((CR.getDataFatturaDa() == null || CR.getDataFatturaA() == null) && (
CR.getDataScadenzaDa() == null || CR.getDataScadenzaA() == null)) {
System.out.println("No");
return 0.0D;
}
System.out.println("Si");
DoubleOperator dop = new DoubleOperator();
Vectumerator<DocumentoScadenza> vec = findByCR(CR, 0, 0);
while (vec.hasMoreElements()) {
DocumentoScadenza ds = (DocumentoScadenza)vec.nextElement();
dop.add(ds.getImportoScadenza());
}
return dop.getResult();
}
public String randomNumber(long length) {
char[] caratteri = "0123456789".toCharArray();
StringBuilder sb = new StringBuilder();
Random random = new Random();
for (int i = 0; (long)i < length; i++) {
char c = caratteri[random.nextInt(caratteri.length)];
sb.append(c);
}
return sb.toString();
}
public void creaDistinte(DocumentoScadenzaCR CR) {
ResParm rp = new ResParm(true);
DoubleOperator dopInc = new DoubleOperator();
DoubleOperator dopTot = new DoubleOperator();
double importoBanca = 0.0D;
double importoTotaleRiba = getTotaleScadenzeByCR(CR);
Vectumerator<DistintaRiba> vecd = new Vectumerator();
Vectumerator<DocumentoScadenza> vec = findByCR(CR, 0, 0);
CR.setTimestampElaborazione(Long.valueOf(randomNumber(9L)).longValue());
if (importoTotaleRiba > 0.0D)
while (CR.getVecRiba().hasMoreElements()) {
Banca row = (Banca)CR.getVecRiba().nextElement();
System.out.println(row.getDescrizione() + " " + row.getDescrizione());
importoBanca = row.getImportoRiba();
if (importoBanca > 0.0D && importoTotaleRiba > dopTot.getResult()) {
DistintaRiba dr = new DistintaRiba(getApFull());
dr.setId_banca(row.getId_banca());
dr.setDataPresentazione(CR.getDataDistintaRiba());
dr.setFlgAccorpaScadenze(CR.getFlgAccorpaScadenze());
dr.setFlgStatoDistinta(0L);
dr.setTimestampElaborazione(CR.getTimestampElaborazione());
dr.setMaxDistinta(importoBanca);
rp = dr.save();
if (rp.getStatus()) {
vecd.add(dr);
dopInc = new DoubleOperator(0.0F);
vec.moveFirst();
while (vec.hasMoreElements()) {
DocumentoScadenza ds = (DocumentoScadenza)vec.nextElement();
if (ds.getId_distintaRiba() == 0L) {
dopInc.add(ds.getImportoScadenza());
if (importoBanca >= dopInc.getResult()) {
dopTot.add(ds.getImportoScadenza());
ds.setFlgScadenzaSelezionata(0L);
ds.setId_distintaRiba(dr.getId_distintaRiba());
rp = ds.save();
if (!rp.getStatus());
continue;
}
dopInc.subtract(ds.getImportoScadenza());
}
}
}
}
}
while (vecd.hasMoreElements()) {
DistintaRiba dr = (DistintaRiba)vecd.nextElement();
if (dr.getImportoTotale() == 0.0D)
dr.delete();
}
}
private Document creaListaScadenze(DocumentoScadenzaCR CR) {
try {
prepareNewPdfCorpoDocument();
SimpleDateFormat df = getDataFormat();
int cellLeading = 10;
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
DoubleOperator dpReport = new DoubleOperator();
int[] col = { 4, 3, 14, 3, 10, 2, 4 };
Cell cell = new Cell();
cell.add(new Chunk("Lista scadenze", 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();
cell.add(new Chunk("Criteri ricerca: " + CR.getDescrizioneCR(), PdfFontFactory.PDF_fPiccolissimo));
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(" ", 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_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setBackgroundColor(Color.lightGray);
cell.setLeading((float)cellLeading);
cell.setColspan(col[0]);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("Data doc.", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setBackgroundColor(Color.lightGray);
cell.setLeading((float)cellLeading);
cell.setColspan(col[1]);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("Cliente", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setBackgroundColor(Color.lightGray);
cell.setLeading((float)cellLeading);
cell.setColspan(col[2]);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("Data scad.", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setBackgroundColor(Color.lightGray);
cell.setLeading((float)cellLeading);
cell.setColspan(col[3]);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("Tipo pag.", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setBackgroundColor(Color.lightGray);
cell.setLeading((float)cellLeading);
cell.setColspan(col[4]);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("N. dist.", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setBackgroundColor(Color.lightGray);
cell.setLeading((float)cellLeading);
cell.setColspan(col[5]);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk("Importo", PdfFontFactory.PDF_fMedioB));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setBackgroundColor(Color.lightGray);
cell.setLeading((float)cellLeading);
cell.setColspan(col[6]);
this.pdfcorpo.addCell(cell);
this.pdfcorpo.endHeaders();
Vectumerator<DocumentoScadenza> vec = findByCR(CR, 0, 0);
while (vec.hasMoreElements()) {
DocumentoScadenza doc = (DocumentoScadenza)vec.nextElement();
cell = new Cell(new Chunk(doc.getDocumento().getTipoDocumento().getCodice() + " " + doc.getDocumento().getTipoDocumento().getCodice(), PdfFontFactory.PDF_fPiccolo));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(col[0]);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(df.format(doc.getDocumento().getDataDocumento()), PdfFontFactory.PDF_fPiccolo));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(1);
cell.setLeading((float)cellLeading);
cell.setColspan(col[1]);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(doc.getDocumento().getClifor().getDescrizioneCompleta(), PdfFontFactory.PDF_fPiccolo));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(col[2]);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(df.format(doc.getDataScadenza()), PdfFontFactory.PDF_fPiccolo));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(1);
cell.setLeading((float)cellLeading);
cell.setColspan(col[3]);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(doc.getDocumento().getTipoPagamento().getDescrizioneTipo(), PdfFontFactory.PDF_fPiccolo));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(0);
cell.setLeading((float)cellLeading);
cell.setColspan(col[4]);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(String.valueOf(doc.getId_distintaRiba()), PdfFontFactory.PDF_fPiccolo));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(1);
cell.setLeading((float)cellLeading);
cell.setColspan(col[5]);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(nf.format(doc.getImportoScadenza()), PdfFontFactory.PDF_fPiccolo));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(2);
cell.setLeading((float)cellLeading);
cell.setColspan(col[6]);
this.pdfcorpo.addCell(cell);
dpReport.add(doc.getImportoScadenza());
}
if (dpReport.getResult() != 0.0D) {
cell = new Cell(new Chunk("Totale", PdfFontFactory.PDF_fMedio));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(2);
cell.setLeading((float)cellLeading);
cell.setColspan(col[0] + col[1] + col[2] + col[3] + col[4] + col[5]);
this.pdfcorpo.addCell(cell);
cell = new Cell(new Chunk(nf.format(dpReport.getResult()), PdfFontFactory.PDF_fMedio));
cell.setVerticalAlignment(4);
cell.setHorizontalAlignment(2);
cell.setLeading((float)cellLeading);
cell.setColspan(col[6]);
this.pdfcorpo.addCell(cell);
}
this.document.add((Element)this.pdfcorpo);
} catch (Exception e) {
e.printStackTrace();
}
return this.document;
}
public ByteArrayOutputStream creaListaScadenzePdf(DocumentoScadenzaCR 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() + "ReportScadenze.pdf");
if (new File(CR.getFilePdf()).exists())
new File(CR.getFilePdf()).delete();
this.document = creaListaScadenze(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 void creaDistintexx(DocumentoScadenzaCR CR) {
ResParm rp = new ResParm(true);
DoubleOperator dopInc = new DoubleOperator();
DoubleOperator dopTot = new DoubleOperator();
double importoBanca = 0.0D;
double importoTotaleRiba = getTotaleScadenzeByCR(CR);
Vectumerator<DistintaRiba> vecd = new Vectumerator();
Vectumerator<DocumentoScadenza> vec = findByCR(CR, 0, 0);
CR.setTimestampElaborazione(Long.valueOf(randomNumber(9L)).longValue());
HashMap<Long, Double> hm = new HashMap<>();
if (importoTotaleRiba > 0.0D) {
Iterator<Map.Entry> it = hm.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = it.next();
importoBanca = (Double)pair.getValue();
if (importoBanca > 0.0D && importoTotaleRiba > dopTot.getResult()) {
DistintaRiba dr = new DistintaRiba(getApFull());
dr.setId_banca(((Long)pair.getKey()).longValue());
dr.setDataPresentazione(CR.getDataDistintaRiba());
dr.setFlgAccorpaScadenze(CR.getFlgAccorpaScadenze());
dr.setFlgStatoDistinta(0L);
dr.setTimestampElaborazione(CR.getTimestampElaborazione());
dr.setMaxDistinta(importoBanca);
rp = dr.save();
if (rp.getStatus()) {
vecd.add(dr);
dopInc = new DoubleOperator(0.0F);
vec.moveFirst();
while (vec.hasMoreElements()) {
DocumentoScadenza ds = (DocumentoScadenza)vec.nextElement();
if (ds.getId_distintaRiba() == 0L) {
dopInc.add(ds.getImportoScadenza());
if (importoBanca >= dopInc.getResult()) {
dopTot.add(ds.getImportoScadenza());
ds.setFlgScadenzaSelezionata(0L);
ds.setId_distintaRiba(dr.getId_distintaRiba());
rp = ds.save();
if (!rp.getStatus());
continue;
}
dopInc.subtract(ds.getImportoScadenza());
}
}
}
}
}
}
while (vecd.hasMoreElements()) {
DistintaRiba dr = (DistintaRiba)vecd.nextElement();
if (dr.getImportoTotale() == 0.0D)
dr.delete();
}
}
public boolean hasScadenzaConRiba(long l_id_documento) {
if (l_id_documento == 0L)
return false;
String s_Sql_Find = "select A.* from DOCUMENTO_SCADENZA AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" A.id_documento = " + l_id_documento);
wc.addWc(" A.id_distintaRiba>0 ");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
Vectumerator<DocumentoScadenza> res = findRows(stmt, 1, 1);
if (res.hasMoreElements())
return true;
return false;
} catch (SQLException e) {
handleDebug(e);
return true;
}
}
}