702 lines
26 KiB
Java
702 lines
26 KiB
Java
package it.acxent.tex.lav;
|
|
|
|
import it.acxent.anag.Clifor;
|
|
import it.acxent.contab.Documento;
|
|
import it.acxent.contab.RigaDocumento;
|
|
import it.acxent.db.ApplParmFull;
|
|
import it.acxent.db.DBAdapter;
|
|
import it.acxent.db.OrString;
|
|
import it.acxent.db.ResParm;
|
|
import it.acxent.db.WcString;
|
|
import it.acxent.util.DoubleOperator;
|
|
import it.acxent.util.SimpleDateFormat;
|
|
import it.acxent.util.StringTokenizer;
|
|
import it.acxent.util.Vectumerator;
|
|
import java.io.Serializable;
|
|
import java.sql.Date;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.sql.Timestamp;
|
|
import java.util.Calendar;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
public class LavPezza extends DBAdapter implements Serializable {
|
|
private static final long serialVersionUID = 1551182243537L;
|
|
|
|
private long id_rigaDocumento;
|
|
|
|
private Timestamp tsInserimento;
|
|
|
|
private String codicePezza;
|
|
|
|
private RigaDocumento rigaDocumento;
|
|
|
|
private Clifor clifor;
|
|
|
|
private long id_clifor;
|
|
|
|
private double mtPezza;
|
|
|
|
private RigaDocumento rigaDocumentoBolla;
|
|
|
|
private long id_rigaDocumentoBolla;
|
|
|
|
private long id_lavPezza;
|
|
|
|
private String codicePancale;
|
|
|
|
private long numColpi;
|
|
|
|
private long count;
|
|
|
|
public LavPezza(ApplParmFull newApplParmFull) {
|
|
super(newApplParmFull);
|
|
}
|
|
|
|
public LavPezza() {}
|
|
|
|
public void setId_lavPezza(long newId_lavPezza) {
|
|
this.id_lavPezza = newId_lavPezza;
|
|
}
|
|
|
|
public void setId_rigaDocumento(long newId_rigaDocumento) {
|
|
this.id_rigaDocumento = newId_rigaDocumento;
|
|
setRigaDocumento(null);
|
|
}
|
|
|
|
public void setTsInserimento(Timestamp newTsInserimento) {
|
|
this.tsInserimento = newTsInserimento;
|
|
}
|
|
|
|
public void setCodicePezza(String newCodicePezza) {
|
|
this.codicePezza = newCodicePezza;
|
|
}
|
|
|
|
public long getId_lavPezza() {
|
|
return this.id_lavPezza;
|
|
}
|
|
|
|
public long getId_rigaDocumento() {
|
|
return this.id_rigaDocumento;
|
|
}
|
|
|
|
public Timestamp getTsInserimento() {
|
|
return this.tsInserimento;
|
|
}
|
|
|
|
public String getCodicePezza() {
|
|
return (this.codicePezza == null) ? "" : this.codicePezza.trim();
|
|
}
|
|
|
|
public void setRigaDocumento(RigaDocumento newRigaDocumento) {
|
|
this.rigaDocumento = newRigaDocumento;
|
|
}
|
|
|
|
public RigaDocumento getRigaDocumento() {
|
|
this.rigaDocumento = (RigaDocumento)getSecondaryObject(this.rigaDocumento, RigaDocumento.class, getId_rigaDocumento());
|
|
return this.rigaDocumento;
|
|
}
|
|
|
|
protected ResParm checkDeleteCascade() {
|
|
return new ResParm(true);
|
|
}
|
|
|
|
protected void deleteCascade() {}
|
|
|
|
public long getTotPezzeByDocumentoDTESS(long l_id_documento) {
|
|
String s_Sql_Find = "select count(*) as tot from LAV_PEZZA AS A inner join RIGA_DOCUMENTO AS B ON A.id_rigaDocumento=B.id_rigaDocumento";
|
|
WcString wc = new WcString();
|
|
wc.addWc("B.id_documento=" + l_id_documento);
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
|
return (long)getTots(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return 0L;
|
|
}
|
|
}
|
|
|
|
public long getTotPezzeInviateDaFatturareByDocumentoDTESS(long l_id_documento) {
|
|
String s_Sql_Find = "select count(*) as tot from LAV_PEZZA AS A inner join RIGA_DOCUMENTO AS RDDISPO ON A.id_rigaDocumento=RDDISPO.id_rigadocumento inner join RIGA_DOCUMENTO AS RDBOLLA ON RDBOLLA.id_rigaDocumento=A.id_rigaDocumentoBolla left join RIGA_DOCUMENTO AS RDFT ON RDFT.id_documento=RDBOLLA.id_documentoPadre";
|
|
WcString wc = new WcString();
|
|
wc.addWc("RDDISPO.id_documento=" + l_id_documento);
|
|
wc.addWc("RDFT.id_rigaDocumento is null");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
|
return (long)getTots(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return 0L;
|
|
}
|
|
}
|
|
|
|
public long getTotPezzeInviateDaFatturareByRigaDocumentoDTESS(long l_id_rigaDocumento, HashMap<Long, Documento> hsDdtDaFatturare) {
|
|
String s_Sql_Find = "select count(*) as tot from LAV_PEZZA AS A inner join RIGA_DOCUMENTO AS RDDISPO ON A.id_rigaDocumento=RDDISPO.id_rigadocumento inner join RIGA_DOCUMENTO AS RDBOLLA ON RDBOLLA.id_rigaDocumento=A.id_rigaDocumentoBolla left join RIGA_DOCUMENTO AS RDFT ON RDFT.id_documento=RDBOLLA.id_documentoPadre";
|
|
WcString wc = new WcString();
|
|
wc.addWc("RDDISPO.id_rigaDocumento=" + l_id_rigaDocumento);
|
|
wc.addWc("RDFT.id_rigaDocumento is null");
|
|
if (hsDdtDaFatturare != null) {
|
|
OrString orBolle = new OrString();
|
|
for (Map.Entry<Long, Documento> me : hsDdtDaFatturare.entrySet())
|
|
orBolle.addOr("RDBOLLA.id_documento=" + me.getValue().getId_documento());
|
|
wc.addWc(orBolle.toString());
|
|
}
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
|
return (long)getTots(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return 0L;
|
|
}
|
|
}
|
|
|
|
public long getTotPezzeFatturateByDocumentoDTESS(long l_id_documento) {
|
|
String s_Sql_Find = "select count(*) as tot from LAV_PEZZA AS A inner join RIGA_DOCUMENTO AS B ON A.id_rigaDocumento=B.id_rigaDocumento inner join RIGA_DOCUMENTO AS BF ON A.id_rigaDocumentoBolla=BF.id_rigaDocumento inner join RIGA_DOCUMENTO AS RDFT ON BF.id_rigaDocumentoPadre=RDFT.id_rigaDocumento";
|
|
WcString wc = new WcString();
|
|
wc.addWc("B.id_documento=" + l_id_documento);
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
|
return (long)getTots(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return 0L;
|
|
}
|
|
}
|
|
|
|
public double getTotMetriByDocumentoDTESS(long l_id_documento, boolean soloInviate) {
|
|
String s_Sql_Find = "select sum(mtPezza) as _sum from LAV_PEZZA AS A inner join RIGA_DOCUMENTO AS B ON A.id_rigaDocumento=B.id_rigaDocumento";
|
|
WcString wc = new WcString();
|
|
wc.addWc("B.id_documento=" + l_id_documento);
|
|
if (soloInviate)
|
|
wc.addWc("A.id_rigaDocumentoBolla>0");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
|
return getSum(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return 0.0D;
|
|
}
|
|
}
|
|
|
|
public double getTotMetriDaFatturareByDocumentoDTESS(long l_id_documento) {
|
|
String s_Sql_Find = "select sum(mtPezza) as _sum from LAV_PEZZA AS A inner join RIGA_DOCUMENTO AS RDDISPO ON A.id_rigaDocumento=RDDISPO.id_rigadocumento inner join RIGA_DOCUMENTO AS RDBOLLA ON RDBOLLA.id_rigaDocumento=A.id_rigaDocumentoBolla left join RIGA_DOCUMENTO AS RDFT ON RDFT.id_documento=RDBOLLA.id_documentoPadre";
|
|
WcString wc = new WcString();
|
|
wc.addWc("RDDISPO.id_documento=" + l_id_documento);
|
|
wc.addWc("RDFT.id_rigaDocumento is null");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
|
return getSum(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return 0.0D;
|
|
}
|
|
}
|
|
|
|
public double getTotMetriDaFatturareByRigaDocumentoDTESS(long l_id_rigaDocumento, HashMap<Long, Documento> hsDdtDaFatturare) {
|
|
String s_Sql_Find = "select sum(mtPezza) as _sum from LAV_PEZZA AS A inner join RIGA_DOCUMENTO AS RDDISPO ON A.id_rigaDocumento=RDDISPO.id_rigadocumento inner join RIGA_DOCUMENTO AS RDBOLLA ON RDBOLLA.id_rigaDocumento=A.id_rigaDocumentoBolla left join RIGA_DOCUMENTO AS RDFT ON RDFT.id_documento=RDBOLLA.id_documentoPadre";
|
|
WcString wc = new WcString();
|
|
wc.addWc("RDDISPO.id_rigaDocumento=" + l_id_rigaDocumento);
|
|
wc.addWc("RDFT.id_rigaDocumento is null");
|
|
if (hsDdtDaFatturare != null) {
|
|
OrString orBolle = new OrString();
|
|
for (Map.Entry<Long, Documento> me : hsDdtDaFatturare.entrySet())
|
|
orBolle.addOr("RDBOLLA.id_documento=" + me.getValue().getId_documento());
|
|
wc.addWc(orBolle.toString());
|
|
}
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
|
return getSum(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return 0.0D;
|
|
}
|
|
}
|
|
|
|
public void findByCodicePezzaClifor(String l_codicePezza, long l_id_clifor) {
|
|
String s_Sql_Find = "select A.* from LAV_PEZZA AS A";
|
|
String s_Sql_Order = "";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.codicePezza='" + l_codicePezza + "'");
|
|
wc.addWc("A.id_clifor=" + l_id_clifor);
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
findFirstRecord(stmt);
|
|
} catch (SQLException e) {
|
|
removeCPConnection();
|
|
handleDebug(e);
|
|
}
|
|
}
|
|
|
|
public ResParm save() {
|
|
LavPezza bean = new LavPezza(getApFull());
|
|
long l_id_cliforPancale = bean.findClientePancaleNonInviato(getCodicePancale());
|
|
if (l_id_cliforPancale > 0L && l_id_cliforPancale != getId_clifor()) {
|
|
Clifor clifor = new Clifor(getApFull());
|
|
clifor.findByPrimaryKey(l_id_cliforPancale);
|
|
return new ResParm(false, "Errore! pezza " + getCodicePezza() + ": Pancale " + getCodicePancale() + " con pezze di " +
|
|
clifor.getDescrizioneCliente());
|
|
}
|
|
if (getTsInserimento() == null)
|
|
setTsInserimento(getTimestamp());
|
|
if (getNumColpi() > 0L) {
|
|
if (getRigaDocumento().getNumColpiDM() > 0L) {
|
|
DoubleOperator dop = new DoubleOperator((float)getNumColpi());
|
|
dop.setScale(2, 5);
|
|
dop.divide((float)getRigaDocumento().getNumColpiDM());
|
|
setMtPezza(dop.getResult());
|
|
} else {
|
|
return new ResParm(false, "Errore! Non è impostato Numero colpi metro sulla disposizione!");
|
|
}
|
|
} else if (getMtPezza() <= 0.0D) {
|
|
return new ResParm(false, "Errore! non hai impostato numero colpi o metri!");
|
|
}
|
|
return super.save();
|
|
}
|
|
|
|
public ResParm superSave() {
|
|
return super.save();
|
|
}
|
|
|
|
public Clifor getClifor() {
|
|
this.clifor = (Clifor)getSecondaryObject(this.clifor, Clifor.class, getId_clifor());
|
|
return this.clifor;
|
|
}
|
|
|
|
public long getId_clifor() {
|
|
return this.id_clifor;
|
|
}
|
|
|
|
public void setClifor(Clifor newClifor) {
|
|
this.clifor = newClifor;
|
|
}
|
|
|
|
public void setId_clifor(long newId_clifor) {
|
|
this.id_clifor = newId_clifor;
|
|
setClifor(null);
|
|
}
|
|
|
|
public Vectumerator<LavPezza> findByCR(LavPezzaCR CR, int pageNumber, int pageRows) {
|
|
String s_Sql_Find = "select A.* from LAV_PEZZA AS A";
|
|
String s_Sql_Order = " order by C.riferimento, B.descrizioneRiga, A.codicePezza, tsInserimento asc";
|
|
WcString wc = new WcString();
|
|
s_Sql_Find = s_Sql_Find + " inner join RIGA_DOCUMENTO AS B on A.id_rigaDocumento=B.id_rigaDocumento inner join DOCUMENTO as C on C.id_documento=B.id_documento";
|
|
if (CR.getId_documentoBolla() > 0L)
|
|
s_Sql_Find = s_Sql_Find + " inner join RIGA_DOCUMENTO AS BBOLLA on A.id_rigaDocumentoBolla=BBOLLA.id_rigaDocumento";
|
|
if (!CR.getSearchTxt().trim().isEmpty()) {
|
|
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
|
StringBuffer txt = new StringBuffer("(");
|
|
while (st.hasMoreTokens()) {
|
|
String token = st.nextToken();
|
|
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
|
if (st.hasMoreTokens())
|
|
txt.append(" and ");
|
|
}
|
|
txt.append(")");
|
|
wc.addWc(txt.toString());
|
|
}
|
|
if (CR.getId_rigaDocumento() > 0L)
|
|
wc.addWc("A.id_rigaDocumento=" + CR.getId_rigaDocumento());
|
|
if (CR.getId_rigaDocumentoBolla() > 0L)
|
|
wc.addWc("A.id_rigaDocumentoBolla=" + CR.getId_rigaDocumentoBolla());
|
|
if (CR.getId_documento() > 0L)
|
|
wc.addWc("B.id_documento=" + CR.getId_documento());
|
|
if (CR.getId_documentoBolla() > 0L)
|
|
wc.addWc("BBOLLA.id_documento=" + CR.getId_documentoBolla());
|
|
if (!CR.getRiferimento().isEmpty())
|
|
wc.addWc("C.riferimento like '%" + CR.getRiferimento() + "%'");
|
|
if (!CR.getCodicePezza().isEmpty())
|
|
wc.addWc("A.codicePezza like '%" + CR.getCodicePezza() + "%'");
|
|
if (CR.getProgDocumento() != 0L && CR.getProgDocumentoA() == 0L) {
|
|
wc.addWc("C.progDocumento =" + CR.getProgDocumento());
|
|
} else if (CR.getProgDocumento() != 0L && CR.getProgDocumentoA() != 0L) {
|
|
wc.addWc("C.progDocumento >=" + CR.getProgDocumento());
|
|
wc.addWc("C.progDocumento <=" + CR.getProgDocumentoA());
|
|
}
|
|
if (CR.getId_clifor() > 0L)
|
|
wc.addWc("C.id_clifor=" + CR.getId_clifor());
|
|
if (!CR.getCodicePancale().isEmpty())
|
|
wc.addWc("A.codicePancale='" + CR.getCodicePancale() + "'");
|
|
if (CR.getFlgConBolla() == 0L) {
|
|
wc.addWc("(A.id_rigaDocumentoBolla is null or A.id_rigaDocumentoBolla=0)");
|
|
} else if (CR.getFlgConBolla() > 0L) {
|
|
wc.addWc("A.id_rigaDocumentoBolla>0");
|
|
}
|
|
if (CR.getDataDocumentoDa() != null)
|
|
wc.addWc("C.dataDocumento>=?");
|
|
if (CR.getDataDocumentoA() != null)
|
|
wc.addWc("C.dataDocumento<=?");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
int dataCount = 0;
|
|
if (CR.getDataDocumentoDa() != null) {
|
|
dataCount++;
|
|
stmt.setDate(dataCount, CR.getDataDocumentoDa());
|
|
}
|
|
if (CR.getDataDocumentoA() != null) {
|
|
dataCount++;
|
|
stmt.setDate(dataCount, CR.getDataDocumentoA());
|
|
}
|
|
return findRows(stmt, pageNumber, pageRows);
|
|
} catch (SQLException e) {
|
|
removeCPConnection();
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public void findLastInserimentoByRigaDocumento(long l_id_rigaDocumento, long l_id_lavPezzaSave) {
|
|
String s_Sql_Find = "select A.* from LAV_PEZZA AS A";
|
|
String s_Sql_Order = " order by tsInserimento desc";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.id_rigaDocumento=" + l_id_rigaDocumento);
|
|
wc.addWc("A.id_lavPezza!=" + l_id_lavPezzaSave);
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
findFirstRecord(stmt);
|
|
} catch (SQLException e) {
|
|
removeCPConnection();
|
|
handleDebug(e);
|
|
}
|
|
}
|
|
|
|
public String getTsInserimentoS() {
|
|
return (getTsInserimento() == null) ? "" : getTimestampFormat().format(getTsInserimento());
|
|
}
|
|
|
|
public double getMtPezza() {
|
|
return this.mtPezza;
|
|
}
|
|
|
|
public void setMtPezza(double mtPezza) {
|
|
this.mtPezza = mtPezza;
|
|
}
|
|
|
|
public Vectumerator<LavPezza> findByRigaDocumento(long l_id_rigaDocumento) {
|
|
LavPezzaCR CR = new LavPezzaCR(getApFull());
|
|
CR.setId_rigaDocumento(l_id_rigaDocumento);
|
|
return findByCR(CR, 0, 0);
|
|
}
|
|
|
|
public Vectumerator<LavPezza> findByDocumentoBolla(long l_id_documentoBolla) {
|
|
LavPezzaCR CR = new LavPezzaCR(getApFull());
|
|
CR.setId_documentoBolla(l_id_documentoBolla);
|
|
CR.setFlgConBolla(1L);
|
|
return findByCR(CR, 0, 0);
|
|
}
|
|
|
|
public Vectumerator<LavPezza> findByRigaDocumentoBolla(long l_id_rigaDocumento) {
|
|
LavPezzaCR CR = new LavPezzaCR(getApFull());
|
|
CR.setId_rigaDocumentoBolla(l_id_rigaDocumento);
|
|
return findByCR(CR, 0, 0);
|
|
}
|
|
|
|
public Vectumerator<LavPezza> findByDocumento(long l_id_documento) {
|
|
LavPezzaCR CR = new LavPezzaCR(getApFull());
|
|
CR.setId_documento(l_id_documento);
|
|
CR.setFlgConBolla(-1L);
|
|
return findByCR(CR, 0, 0);
|
|
}
|
|
|
|
public ResParm creaBollaDaLista(LavPezzaCR CR, String[] id_lavPezze) {
|
|
ResParm rp = new ResParm(true);
|
|
HashMap<Long, Documento> lst = new HashMap<>();
|
|
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
|
boolean testRiferimenti = true;
|
|
if (testRiferimenti) {
|
|
for (int i = 0; i < id_lavPezze.length; i++) {
|
|
if (!id_lavPezze[i].isEmpty()) {
|
|
String riferimento;
|
|
LavPezza row = new LavPezza(getApFull());
|
|
row.findByPrimaryKey(Long.valueOf(id_lavPezze[i]));
|
|
if (CR.getSearchTxt().isEmpty()) {
|
|
riferimento = "";
|
|
} else {
|
|
riferimento = CR.getSearchTxt();
|
|
}
|
|
rp = row.creaBolla(CR.getId_users(), false, CR.getId_tipoDocumento(), CR.getDataEmissioneDocumento(), riferimento);
|
|
if (rp.getStatus()) {
|
|
Documento l_documento = (Documento)rp.getReturnObj();
|
|
if (!lst.containsKey(Long.valueOf(l_documento.getId_documento())))
|
|
lst.put(Long.valueOf(l_documento.getId_documento()), l_documento);
|
|
}
|
|
}
|
|
}
|
|
Vectumerator<Documento> vecDoc = new Vectumerator();
|
|
if (rp.getStatus()) {
|
|
StringBuilder sb = new StringBuilder();
|
|
for (Documento doc : lst.values()) {
|
|
if (CR.getFlgStato() > 0L) {
|
|
doc.setFlgStato(CR.getFlgStato());
|
|
} else {
|
|
doc.setFlgStato(1L);
|
|
}
|
|
doc.save();
|
|
vecDoc.add(doc);
|
|
}
|
|
rp.setMsg(sb.toString());
|
|
rp.setReturnObj(vecDoc);
|
|
}
|
|
} else {
|
|
rp.setStatus(false);
|
|
rp.setMsg("ERRORE! Non puoi creare fatture con riferimenti diversi tra loro.");
|
|
}
|
|
return rp;
|
|
}
|
|
|
|
public ResParm creaBolla(long l_id_users, boolean emetti, long l_id_tipoFattura, Date l_dataEmissioneDocumento, String riferimento) {
|
|
ResParm rp = new ResParm(true);
|
|
if (l_dataEmissioneDocumento == null)
|
|
l_dataEmissioneDocumento = getToday();
|
|
Documento documento = new Documento(getApFull());
|
|
documento.findDocumentoBozza(l_id_tipoFattura, getId_clifor());
|
|
if (documento.getDBState() == 0) {
|
|
documento.setId_users(l_id_users);
|
|
documento.setId_clifor(getId_clifor());
|
|
documento.setId_tipoPagamento(getClifor().getId_tipoPagamento());
|
|
documento.setId_tipoDocumento(l_id_tipoFattura);
|
|
documento.setDataDocumento(l_dataEmissioneDocumento);
|
|
Calendar cal = Calendar.getInstance();
|
|
cal.setTime(documento.getDataDocumento());
|
|
documento.setId_esercizio((long)cal.get(1));
|
|
documento.setId_documentoFiglio(0L);
|
|
rp = documento.superSave();
|
|
}
|
|
if (rp.getStatus()) {
|
|
creaRigheDocumento(documento);
|
|
setRigaDocumento(null);
|
|
save();
|
|
}
|
|
Vectumerator<RigaDocumento> vecrd = documento.findRigheDocumento(0, 0, 0);
|
|
documento.setNColli((long)vecrd.getTotNumberOfRecords());
|
|
documento.superSave();
|
|
rp.setMsg(String.valueOf(documento.getId_documento()));
|
|
rp.setReturnObj(documento);
|
|
return rp;
|
|
}
|
|
|
|
public ResParm creaRigheDocumento(Documento fatt) {
|
|
ResParm rp = new ResParm(true);
|
|
RigaDocumento rd = new RigaDocumento(getApFull());
|
|
StringBuilder sbDettaglio = new StringBuilder();
|
|
sbDettaglio.append(" N.: ");
|
|
if (getCodicePezza().length() > 2) {
|
|
String l_codicepezza = StringUtils.stripStart(getCodicePezza(), "0");
|
|
if (getRigaDocumento().getDocumento().getFlgBarcodeType() == 1L) {
|
|
sbDettaglio.append(l_codicepezza.substring(0, l_codicepezza.length() - 1));
|
|
} else {
|
|
sbDettaglio.append(l_codicepezza);
|
|
}
|
|
}
|
|
sbDettaglio.append(" ");
|
|
StringBuilder sbRaggruppamento = new StringBuilder();
|
|
sbRaggruppamento.append("Tela: ");
|
|
sbRaggruppamento.append(getRigaDocumento().getDocumento().getRiferimento());
|
|
sbRaggruppamento.append(" Articolo: ");
|
|
sbRaggruppamento.append(getRigaDocumento().getDescrizioneRiga());
|
|
rd.setDescrizioneRiga(sbDettaglio.toString() + sbDettaglio.toString());
|
|
rd.setDescrizioneRigaDettaglio(sbDettaglio.toString());
|
|
rd.setDescrizioneRigaRaggruppamento(sbRaggruppamento.toString());
|
|
rd.setMt(getMtPezza());
|
|
rd.setNr(getMtPezza());
|
|
rd.setId_documento(fatt.getId_documento());
|
|
rp = rd.superSave();
|
|
if (rp.getStatus()) {
|
|
setId_rigaDocumentoBolla(rd.getId_rigaDocumento());
|
|
rp = save();
|
|
}
|
|
return rp;
|
|
}
|
|
|
|
public Documento getDocumento() {
|
|
return getRigaDocumento().getDocumento();
|
|
}
|
|
|
|
public RigaDocumento getRigaDocumentoBolla() {
|
|
this.rigaDocumentoBolla = (RigaDocumento)getSecondaryObject(this.rigaDocumentoBolla, RigaDocumento.class, getId_rigaDocumentoBolla());
|
|
return this.rigaDocumentoBolla;
|
|
}
|
|
|
|
public void setRigaDocumentoBolla(RigaDocumento rigaDocumentoBolla) {
|
|
this.rigaDocumentoBolla = rigaDocumentoBolla;
|
|
}
|
|
|
|
public long getId_rigaDocumentoBolla() {
|
|
return this.id_rigaDocumentoBolla;
|
|
}
|
|
|
|
public void setId_rigaDocumentoBolla(long id_rigaDocumentoBolla) {
|
|
this.id_rigaDocumentoBolla = id_rigaDocumentoBolla;
|
|
}
|
|
|
|
public String getCodicePancale() {
|
|
return (this.codicePancale == null) ? "" : this.codicePancale.trim();
|
|
}
|
|
|
|
public void setCodicePancale(String codicePancale) {
|
|
this.codicePancale = codicePancale;
|
|
}
|
|
|
|
public long getNumColpi() {
|
|
return this.numColpi;
|
|
}
|
|
|
|
public void setNumColpi(long numColpi) {
|
|
this.numColpi = numColpi;
|
|
}
|
|
|
|
public long findClientePancaleNonInviato(String l_codicePancale) {
|
|
String s_Sql_Find = "select A.id_clifor from LAV_PEZZA AS A";
|
|
String s_Sql_Order = "";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.codicePancale='" + l_codicePancale + "'");
|
|
wc.addWc("(A.id_rigaDocumentoBolla is null or A.id_rigaDocumentoBolla=0)");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
Vectumerator<LavPezza> vec = findRows(stmt);
|
|
if (vec.hasMoreElements()) {
|
|
LavPezza row = (LavPezza)vec.nextElement();
|
|
return row.getId_clifor();
|
|
}
|
|
return 0L;
|
|
} catch (SQLException e) {
|
|
removeCPConnection();
|
|
handleDebug(e);
|
|
return 0L;
|
|
}
|
|
}
|
|
|
|
public long getTotPezzeInviateByDocumentoDTESS(long l_id_documento) {
|
|
String s_Sql_Find = "select count(*) as tot from LAV_PEZZA AS A inner join RIGA_DOCUMENTO AS B ON A.id_rigaDocumento=B.id_rigaDocumento";
|
|
WcString wc = new WcString();
|
|
wc.addWc("B.id_documento=" + l_id_documento);
|
|
wc.addWc("A.id_rigaDocumentoBolla>0");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
|
return (long)getTots(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return 0L;
|
|
}
|
|
}
|
|
|
|
public Vectumerator<LavPezza> findPezzeInviateDaFatturareByDocumento(long l_id_documento) {
|
|
String s_Sql_Find = "select A.* from LAV_PEZZA AS A inner join RIGA_DOCUMENTO AS RDDISPO ON A.id_rigaDocumento=RDDISPO.id_rigadocumento inner join RIGA_DOCUMENTO AS RDBOLLA ON RDBOLLA.id_rigaDocumento=A.id_rigaDocumentoBolla left join RIGA_DOCUMENTO AS RDFT ON RDFT.id_documento=RDBOLLA.id_documentoPadre";
|
|
WcString wc = new WcString();
|
|
wc.addWc("RDDISPO.id_documento=" + l_id_documento);
|
|
wc.addWc("RDFT.id_rigaDocumento is null");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
|
return findRows(stmt);
|
|
} catch (SQLException e) {
|
|
removeCPConnection();
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public Vectumerator<LavPezza> findPezzeInviateDaFatturareByRIGADocumento(long l_id_rigaDocumento, HashMap<Long, Documento> hsDdtDaFatturare) {
|
|
String s_Sql_Find = "select A.* from LAV_PEZZA AS A inner join RIGA_DOCUMENTO AS RDDISPO ON A.id_rigaDocumento=RDDISPO.id_rigadocumento inner join RIGA_DOCUMENTO AS RDBOLLA ON RDBOLLA.id_rigaDocumento=A.id_rigaDocumentoBolla left join RIGA_DOCUMENTO AS RDFT ON RDFT.id_documento=RDBOLLA.id_documentoPadre";
|
|
WcString wc = new WcString();
|
|
wc.addWc("RDDISPO.id_rigaDocumento=" + l_id_rigaDocumento);
|
|
wc.addWc("RDFT.id_rigaDocumento is null");
|
|
if (hsDdtDaFatturare != null) {
|
|
OrString orBolle = new OrString();
|
|
for (Map.Entry<Long, Documento> me : hsDdtDaFatturare.entrySet())
|
|
orBolle.addOr("RDBOLLA.id_documento=" + me.getValue().getId_documento());
|
|
wc.addWc(orBolle.toString());
|
|
}
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
|
|
return findRows(stmt);
|
|
} catch (SQLException e) {
|
|
removeCPConnection();
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public String getError() {
|
|
if (getId_lavPezza() == 0L)
|
|
return "";
|
|
StringBuilder errmsg = new StringBuilder();
|
|
if (getRigaDocumento().getId_documento() == 0L) {
|
|
errmsg.append("Pezza relativa ad un documento cancellato!!!");
|
|
} else if (getId_clifor() != getRigaDocumento().getDocumento().getId_clifor()) {
|
|
errmsg.append("Cliente pezza diverso da cliente documento: pezza: " + getClifor().getDescrizioneCliente() + " doc: " +
|
|
getRigaDocumento().getDocumento().getId_clifor() + " - " +
|
|
getRigaDocumento().getDocumento().getClifor().getDescrizioneCliente());
|
|
}
|
|
return errmsg.toString();
|
|
}
|
|
|
|
public boolean isError() {
|
|
if (getError().isEmpty())
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
public boolean isFatturata() {
|
|
if (getRigaDocumentoBolla().getId_documentoPadre() > 0L)
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
public String getDocumentoFatturaNumero() {
|
|
if (isFatturata())
|
|
return getRigaDocumentoBolla().getDocumentoPadre().getNumeroDocumentoCompleto();
|
|
return "";
|
|
}
|
|
|
|
public boolean isInviata() {
|
|
if (getId_rigaDocumentoBolla() > 0L)
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
public String getDocumentoBollaNumero() {
|
|
if (isInviata())
|
|
return getRigaDocumentoBolla().getDocumento().getNumeroDocumentoCompleto();
|
|
return "";
|
|
}
|
|
|
|
public Vectumerator<LavPezza> findDdtByRigaDocumento(long l_id_rigaDocumento) {
|
|
String s_Sql_Find = "select MAX(A.id_rigaDocumentoBolla) as id_rigaDocumentoBolla, count(1) as count, B.id_documento from LAV_PEZZA AS A inner join RIGA_DOCUMENTO AS B ON A.id_rigaDocumentoBolla=B.id_rigaDocumento";
|
|
String s_Sql_Order = " GROUP BY B.id_documento;";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.id_rigaDocumento=" + l_id_rigaDocumento);
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
return findRows(stmt);
|
|
} catch (SQLException e) {
|
|
removeCPConnection();
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public long getCount() {
|
|
return this.count;
|
|
}
|
|
|
|
public void setCount(long count) {
|
|
this.count = count;
|
|
}
|
|
|
|
protected void initFields() {
|
|
super.initFields();
|
|
setCount(0L);
|
|
}
|
|
|
|
protected void fillFields(ResultSet rst) {
|
|
super.fillFields(rst);
|
|
try {
|
|
if (isColumnInResultSet(rst, "count"))
|
|
setCount(rst.getLong("count"));
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
}
|
|
}
|
|
}
|