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

6630 lines
261 KiB
Java
Raw Normal View History

2026-04-22 18:41:37 +02:00
package it.acxent.contab;
import it.acxent.anag.Clifor;
import it.acxent.anag.Iva;
import it.acxent.anag.IvaInterface;
import it.acxent.anag.MagFisico;
import it.acxent.art.Articolo;
import it.acxent.art.ArticoloCR;
import it.acxent.art.ArticoloFornitore;
import it.acxent.art.ArticoloProgettista;
import it.acxent.art.ArticoloTaglia;
import it.acxent.art.ArticoloUsato;
import it.acxent.art.ArticoloVariante;
import it.acxent.art.Reparto;
import it.acxent.art.TipologiaArticolo;
import it.acxent.cc.Attivita;
import it.acxent.db.ApplParmFull;
import it.acxent.db.DbInterface;
import it.acxent.db.OrString;
import it.acxent.db.ResParm;
import it.acxent.db.WcString;
import it.acxent.fattele.FEDettaglioLineeInterface;
import it.acxent.fattele.FEScontoMaggiorazione;
import it.acxent.fattele.FEScontoMaggiorazioneInterface;
import it.acxent.mail.MailMessage;
import it.acxent.newsletter.CodaMessaggi;
import it.acxent.tex.anag.ArticoloArticoloTessuto;
import it.acxent.tex.anag.ArticoloFilato;
import it.acxent.tex.anag.ArticoloFilatoColore;
import it.acxent.tex.anag.ArticoloFilatoColoreRitorto;
import it.acxent.tex.anag.ArticoloTessuto;
import it.acxent.tex.anag.ArticoloTessutoColore;
import it.acxent.tex.anag.FaseLavorazione;
import it.acxent.tex.anag.Pezza;
import it.acxent.tex.anag.Telaio;
import it.acxent.tex.conf.NumeroTeliRiga;
import it.acxent.tex.lav.LavPezza;
import it.acxent.util.AbMessages;
import it.acxent.util.DoubleOperator;
import it.acxent.util.FileWr;
import it.acxent.util.StringTokenizer;
import it.acxent.util.Vectumerator;
import java.io.File;
import java.io.Serializable;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
public class RigaDocumento extends _ContabAdapter implements Serializable, FEDettaglioLineeInterface, RigaDocumentoInterface {
private static final long serialVersionUID = 5978813491971046901L;
public static final long CODICE_RIGA_0_PRINCIPALE = 0L;
public static final long CODICE_RIGA_1_SECONDARIA = 1L;
public static final long CODICE_RIGA_100_DISPO_TAGLIO = 100L;
public static final long TIPO_RICERCA_SOLO_MAGAZZINO = 0L;
public static final long TIPO_RICERCA_MAGAZZINO_INTERNO = 1L;
public static final long TIPO_RICERCA_MAGAZZINO_ESTERNO = 2L;
public static final long TIPO_RICERCA_MAGAZZINO_INTERNO_E_ESTERNO = 3L;
public static final long STATO_DA_ORDINARE = 0L;
public static final long STATO_ORDINATO_TUTTO = 10L;
public static final long STATO_ORDINATO_PARZIALE = 15L;
public static final long STATO_ARRIVATO_PARZIALE = 20L;
public static final long STATO_ARRIVATO_TUTTO = 30L;
public static final long STATO_CHIUSO = 40L;
private long id_rigaDocumento;
private long id_documento;
private long ordineRiga;
private long id_articoloVariante;
private long id_iva = getCodiceIvaVendStd();
private long id_magFisico;
private long id_articoloTaglia;
private String serialeSost;
private double imponibile;
private double sconto;
private double quantita;
private String descrizioneRiga;
private String descrizioneCodiceRiga;
private String notaBarcode;
private Documento documento;
private Articolo articolo;
private ArticoloVariante articoloVariante;
private Iva iva;
private MagFisico magFisico;
private ArticoloTaglia articoloTaglia;
private double quantitaOld;
private long flgRigaPrelevata;
private double quantitaPrelevata;
private double quantitaAssociata;
private long flgSingleLineArt;
private double prezzoPubblicoConIva;
private Reparto reparto;
private double importo;
private long segnoMov;
private long flgCodiceRiga;
private long flgPrenotazioneArrivata;
private String seriale;
private Documento documentoPadre;
private long id_documentoPadre;
private long id_rigaDocumentoPadre;
private long id_articolo;
private String notaRigaDocumento;
private long flgIgnoraPrenotazione;
private double kg;
private double mt;
private double nr;
private long qtaSlipStampate;
private long statoPrenotazione;
private double qtaSaldoMovimento;
private CausaleMagazzino causaleMagazzino;
private Clifor clifor;
private long id_causaleMagazzino;
private long id_clifor;
private long flgReso;
private long flgDaCancellare;
private long flgStatoLavorazioneRiga;
private long id_rigaDocumentoMov;
private long id_rigaDocumentoPrelevata;
private RigaDocumento rigaDocumentoPrelevata;
private long id_articoloFilato;
private long id_articoloFilatoColore;
private ArticoloFilatoColore articoloFilatoColore;
private ArticoloFilatoColoreRitorto articoloFilatoColoreRitorto;
private long id_pezza;
private Pezza pezza;
private long id_faseLavorazione;
private FaseLavorazione faseLavorazione;
private long id_articoloTessuto;
private ArticoloTessuto articoloTessuto;
private long id_articoloPrecedente;
private double percL1;
private double percL2;
private double percL3;
private String codiceCartellinoIniziale;
private double metriStacchi;
private long rifTipoArticolo = 1L;
private long id_reparto;
private long stacchi;
private String codiceCartellinoStart;
private String codiceCartellinoStop;
private long numColpiDM;
private long flgUdm;
private long colpoFinaleRiga;
private long colpoInizialeRiga;
private long id_articoloTessutoColore;
private ArticoloTessutoColore articoloTessutoColore;
private long capiPerTelo;
private long id_telaio;
private Telaio telaio;
private Timestamp tsFineLavorazioneRiga;
private Timestamp tsInizioLavorazioneRiga;
private long numTeliRiga;
private long flgMov;
private NumeroTeliRiga numeroTeliRiga;
private double nrOriginale;
private String descrizioneRigaRaggruppamento;
private String descrizioneRigaDettaglio;
private String flgDescPadreGenerazioneRiga;
private long ordine;
private long id_articoloFilatoColoreRitorto;
private long id_rigaDocumentoTessutoA;
private RigaDocumento rigaDocumentoTessutoA;
public String getDescrizioneCodiceRiga() {
if (getId_articoloTaglia() > 0L)
return getArticoloTaglia().getCodiceAT();
if (getId_articoloVariante() > 0L)
return getArticoloVariante().getCodiceVariante();
if (getId_articolo() > 0L)
return getArticolo().getCodice();
return (this.descrizioneCodiceRiga == null) ? "" : this.descrizioneCodiceRiga.trim();
}
public void setDescrizioneCodiceRiga(String descrizioneCodiceRiga) {
this.descrizioneCodiceRiga = descrizioneCodiceRiga;
}
public String getFlgDescPadreGenerazioneRiga() {
return (this.flgDescPadreGenerazioneRiga == null) ? "" : this.flgDescPadreGenerazioneRiga.trim();
}
public void setFlgDescPadreGenerazioneRiga(String flgDescPadreGenerazioneRiga) {
this.flgDescPadreGenerazioneRiga = flgDescPadreGenerazioneRiga;
}
public long getCapiPerTelo() {
return this.capiPerTelo;
}
public void setCapiPerTelo(long capiPerTelo) {
this.capiPerTelo = capiPerTelo;
}
public long getNumColpiDM() {
return this.numColpiDM;
}
public void setNumColpiDM(long numColpiMetro) {
this.numColpiDM = numColpiMetro;
}
public RigaDocumento(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public void setId_rigaDocumento(long newId_rigaDocumento) {
this.id_rigaDocumento = newId_rigaDocumento;
}
public void setId_documento(long newId_documento) {
this.id_documento = newId_documento;
setDocumento(null);
}
public void setId_articolo(long newId_articolo) {
this.id_articolo = newId_articolo;
setArticolo(null);
}
public void setId_articoloVariante(long newId_articoloVariante) {
this.id_articoloVariante = newId_articoloVariante;
setArticoloVariante(null);
}
public void setId_iva(long newId_iva) {
this.id_iva = newId_iva;
setIva(null);
}
public void setId_magFisico(long newId_magFisico) {
this.id_magFisico = newId_magFisico;
setMagFisico(null);
}
public void setId_articoloTaglia(long newId_taglia) {
this.id_articoloTaglia = newId_taglia;
setArticoloTaglia(null);
}
public void setSeriale(String newSeriale) {
this.seriale = newSeriale;
}
public void setImponibile(double newImponibile) {
this.imponibile = newImponibile;
}
public void setFlgUdm(long newFlgUdm) {
this.flgUdm = newFlgUdm;
}
public void setQuantita(double newQuantita) {
if (getParm("USA_MAGAZZINO").isFalse()) {
long l_flgUdm;
if (getId_articoloVariante() > 0L || getId_articolo() > 0L) {
l_flgUdm = getArticolo().getTipologiaArticolo().getFlgUdm();
} else if (getId_articoloFilatoColore() > 0L) {
l_flgUdm = getArticoloFilatoColore().getTipologiaArticolo().getFlgUdm();
} else if (getId_articoloTessutoColore() > 0L) {
l_flgUdm = getArticoloTessutoColore().getArticoloTessuto().getTipologiaArticolo().getFlgUdm();
} else if (getId_articoloTessuto() > 0L) {
l_flgUdm = getArticoloTessuto().getTipologiaArticolo().getFlgUdm();
} else {
l_flgUdm = 1L;
}
if (l_flgUdm == 1L) {
setNr(newQuantita);
} else if (l_flgUdm == 3L) {
setMt(newQuantita);
} else if (l_flgUdm == 2L) {
setKg(newQuantita);
}
}
this.quantita = newQuantita;
}
public void setDescrizioneRiga(String newDescrizioneRiga) {
this.descrizioneRiga = newDescrizioneRiga;
}
public void setNotaRigaDocumento(String newNoteRiga) {
this.notaRigaDocumento = newNoteRiga;
}
public long getId_rigaDocumento() {
return this.id_rigaDocumento;
}
public long getId_documento() {
return this.id_documento;
}
public long getId_articolo() {
return this.id_articolo;
}
public long getId_articoloVariante() {
return this.id_articoloVariante;
}
public long getId_iva() {
return this.id_iva;
}
public long getId_magFisico() {
return this.id_magFisico;
}
public long getId_articoloTaglia() {
return this.id_articoloTaglia;
}
public String getSeriale() {
return (this.seriale == null) ? "" : this.seriale.trim();
}
public double getImponibile() {
if (getFlgReso() == 1L)
return -Math.abs(this.imponibile);
return this.imponibile;
}
public long getFlgUdm() {
long l_flgUdm = 0L;
if (getId_articoloVariante() > 0L || getId_articolo() > 0L) {
l_flgUdm = getArticolo().getTipologiaArticolo().getFlgUdm();
} else if (getId_articoloFilatoColore() > 0L) {
l_flgUdm = getArticoloFilatoColore().getTipologiaArticolo().getFlgUdm();
} else if (getId_articoloTessutoColore() > 0L) {
l_flgUdm = getArticoloTessutoColore().getArticoloTessuto().getTipologiaArticolo().getFlgUdm();
} else if (getId_articoloTessuto() > 0L) {
l_flgUdm = getArticoloTessuto().getTipologiaArticolo().getFlgUdm();
}
if (l_flgUdm == 0L) {
if (this.flgUdm == 0L)
return 1L;
return this.flgUdm;
}
return l_flgUdm;
}
public String getQuantitaMagazzinoHtml() {
if (getId_articoloVariante() == 0L)
return getArticolo().getQuantitaMagazzinoMovimentoHtml();
return getArticoloVariante().getQuantitaMagazzinoMovimentoHtml();
}
public String getQuantitaRigaHtml() {
StringBuilder sb = new StringBuilder();
sb.append(getUdmQuantita());
if (getQuantitaAssociata() > 0.0D) {
sb.append(" <span style=\"color:#00CC00\">");
sb.append(getQuantitaAssociata());
sb.append("</span> ");
}
if (getQuantitaPrelevata() > 0.0D) {
sb.append(" <span style=\"color:#FF6600\"> ");
sb.append(getQuantitaPrelevata());
sb.append("</span> ");
}
return sb.toString();
}
public String getDescrizioneRiga() {
return (this.descrizioneRiga == null) ? "" : this.descrizioneRiga.trim();
}
public String getDescrizioneRigaCompleta() {
String star, sn;
if (getId_articolo() != 0L || getId_articoloFilatoColore() != 0L) {
star = "";
} else {
star = "";
}
if (getId_articoloFilatoColore() != 0L) {
sn = " lotto: ";
} else {
sn = " s/n: ";
}
if (getSeriale().isEmpty())
return getDescrizioneRiga() + getDescrizioneRiga();
return getDescrizioneRiga() + getDescrizioneRiga() + star + sn;
}
public String getNotaRigaDocumento() {
return (this.notaRigaDocumento == null) ? "" : this.notaRigaDocumento.trim();
}
public void setDocumento(Documento newDocumento) {
this.documento = newDocumento;
}
public Documento getDocumento() {
this.documento = (Documento)getSecondaryObject(this.documento, Documento.class, getId_documento());
return this.documento;
}
public void setArticolo(Articolo newArticolo) {
this.articolo = newArticolo;
}
public Articolo getArticolo() {
this.articolo = (Articolo)getSecondaryObject(this.articolo, Articolo.class, getId_articolo());
return this.articolo;
}
public void setArticoloVariante(ArticoloVariante newArticoloVariante) {
this.articoloVariante = newArticoloVariante;
}
public ArticoloVariante getArticoloVariante() {
this.articoloVariante = (ArticoloVariante)getSecondaryObject(this.articoloVariante, ArticoloVariante.class, getId_articoloVariante());
return this.articoloVariante;
}
public void setIva(Iva newIva) {
this.iva = newIva;
}
public Iva getIva() {
this.iva = (Iva)getSecondaryObject(this.iva, Iva.class, getId_iva());
return this.iva;
}
public void setMagFisico(MagFisico newMagFisico) {
this.magFisico = newMagFisico;
}
public MagFisico getMagFisico() {
this.magFisico = (MagFisico)getSecondaryObject(this.magFisico, MagFisico.class, getId_magFisico());
return this.magFisico;
}
public void setArticoloTaglia(ArticoloTaglia newArticoloTaglia) {
this.articoloTaglia = newArticoloTaglia;
}
public ArticoloTaglia getArticoloTaglia() {
this.articoloTaglia = (ArticoloTaglia)getSecondaryObject(this.articoloTaglia, ArticoloTaglia.class, getId_articoloTaglia());
return this.articoloTaglia;
}
protected void deleteCascade() {
if (getFlgCodiceRiga() == 0L) {
delete("delete from NUMERO_TELI_RIGA where id_rigaDocumentoArticolo=" + getId_rigaDocumento());
update("update LAV_PEZZA set id_rigaDocumentoBolla=null where id_rigaDocumentoBolla=" + getId_rigaDocumento());
} else if (getFlgCodiceRiga() == 1L) {
delete("delete from NUMERO_TELI_RIGA where id_rigaDocumentoTessuto=" + getId_rigaDocumento());
}
new RigaDocumentoProgettista(getApFull()).deleteByRigaDocumento(getId_rigaDocumento());
ResParm rp = update("update RIGA_DOCUMENTO set id_rigaDocumentoPadre=null where id_rigaDocumentoPadre=" + getId_rigaDocumento());
rp = update("update RIGA_DOCUMENTO set id_rigaDocumentoMov=null where id_rigaDocumentoMov=" + getId_rigaDocumento());
rp = update("update RIGA_DOCUMENTO set id_rigaDocumentoPrelevata=null where id_rigaDocumentoPrelevata=" + getId_rigaDocumento());
rp = update("update LAV_PEZZA set id_rigaDocumentoBolla=null where id_rigaDocumentoBolla=" + getId_rigaDocumento());
}
public Vectumerator findByCROld(RigaDocumentoCR CR, int pageNumber, int pageRows) {
if (CR.getFlgTipoRicerca() == 1L)
return findCompattaByCR(CR, pageNumber, pageRows);
boolean flgOttimizzo = true;
if (pageNumber == 0 && pageRows == 0)
flgOttimizzo = false;
StringBuffer s_Sql_Find = new StringBuffer("select A.* from RIGA_DOCUMENTO AS A INNER JOIN DOCUMENTO AS B ON A.id_documento=B.id_documento ");
s_Sql_Find.append(" INNER JOIN TIPO_DOCUMENTO AS C ON B.id_tipoDocumento=C.id_tipoDocumento ");
String s_Sql_Order = " order by B.dataDocumento desc, B.id_documentoFiglio desc ";
if (CR.getFlgOrderBy() == 5L)
s_Sql_Order = " order by B.dataDocumento asc ";
WcString wc = new WcString();
findByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt;
if ((pageNumber == 0 && pageRows == 0) || !flgOttimizzo) {
stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString());
} else {
if (pageNumber == 0)
pageNumber = 1;
int start = (pageNumber - 1) * pageRows;
int stop = start + pageRows;
stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString() + " limit " + s_Sql_Order + "," + start);
}
findByCRCreateStmtDate(CR, stmt);
if ((pageNumber == 0 && pageRows == 0) || !flgOttimizzo) {
Vectumerator vectumerator = findRows(stmt, pageNumber, pageRows);
if (!CR.getFlgReport().isEmpty())
creaFileCvs(vectumerator, CR);
return vectumerator;
}
Vectumerator vec = findRows(stmt, 1, pageRows);
vec.setPageNumber(pageNumber);
vec.setTotNumberOfRecords(findByCRTotRecord(CR));
if (!CR.getFlgReport().isEmpty())
creaFileCvs(vec, CR);
return vec;
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator findByDocumentoPerSlip(long l_id_documento) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A left join ARTICOLO AS B on A.id_articolo=B.id_articolo ";
String s_Sql_order = " order by A.id_rigaDocumento desc";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
wc.addWc("A.quantita>coalesce(qtaSlipStampate,0)");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return findRows(stmt);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public double getTotImportoRM() {
if (getIva().getFlgTipo().equals("R")) {
if (getSconto() > 0.0D) {
DoubleOperator temp = new DoubleOperator(100.0F);
temp.setScale(4, 5);
temp.subtract(getSconto());
temp.multiply(getTotImponibileRiga());
temp.divide(100.0F);
temp.setScale(2, 5);
return temp.getResult();
}
return getTotImponibileRiga();
}
return 0.0D;
}
public double getTotImportoRMRighe(long l_id_documento) {
Vectumerator<RigaDocumento> vec = findByDocumento(l_id_documento, 0L, "", 0, 0, 1);
DoubleOperator temp = new DoubleOperator();
while (vec.hasMoreElements())
RigaDocumento row = (RigaDocumento)vec.nextElement();
return temp.getResult();
}
public double getTotIvaRiga4() {
DoubleOperator l_iva = new DoubleOperator(getTotImponibileRigaConSconto());
if (!getIva().getFlgTipo().equals("R")) {
l_iva.setScale(4, 5);
l_iva.multiply(getIva().getAliquota());
l_iva.divide(100.0F);
} else {
l_iva = new DoubleOperator(0.0F);
}
return l_iva.getResult();
}
public double getTotCostoUsato() {
DoubleOperator temp = new DoubleOperator(getArticolo().getCostoAcquisto());
temp.multiply(getQuantita());
temp.setScale(3, 5);
return temp.getResult();
}
public double getTotImponibileRigaConScontoOLD() {
if (!getIva().getFlgTipo().equals("R")) {
if (getSconto() == 0.0D && getPercL1() == 0.0D && getPercL2() == 0.0D && getPercL3() == 0.0D)
return getTotImponibileRiga();
if (getSconto() > 0.0D) {
DoubleOperator doubleOperator = new DoubleOperator(100.0F);
doubleOperator.setScale(4, 5);
doubleOperator.subtract(getSconto());
doubleOperator.multiply(getTotImponibileRiga());
doubleOperator.divide(100.0F);
doubleOperator.setScale(2, 5);
return doubleOperator.getResult();
}
DoubleOperator temp = new DoubleOperator(100.0F);
temp.setScale(4, 5);
double imponibile = getTotImponibileRiga();
if (getPercL1() > 0.0D) {
temp.subtract(getPercL1());
temp.multiply(imponibile);
temp.divide(100.0F);
imponibile = temp.getResult();
}
if (getPercL2() > 0.0D) {
temp = new DoubleOperator(100.0F);
temp.subtract(getPercL2());
temp.multiply(imponibile);
temp.divide(100.0F);
imponibile = temp.getResult();
}
if (getPercL3() > 0.0D) {
temp = new DoubleOperator(100.0F);
temp.subtract(getPercL3());
temp.multiply(imponibile);
temp.divide(100.0F);
}
temp.setScale(2, 5);
return temp.getResult();
}
return getTotImponibileRiga();
}
public double getSconto() {
return this.sconto;
}
public void setSconto(double sconto) {
this.sconto = sconto;
}
public static String getUdm(long l_flgUdm) {
return TipologiaArticolo.getUdm(l_flgUdm);
}
public String getUdm() {
return getUdm(getFlgUdm());
}
public String getUdmQuantita() {
return getUdm() + " " + getUdm();
}
public ResParm deleteMov() {
if (getId_rigaDocumentoMov() > 0L)
return super.delete();
return new ResParm(false, "ERRORE! Tentativo di cancellare riga documento tramite deleteMov!!!");
}
private static final synchronized ResParm deleteMagArticolo(RigaDocumento rd) {
ResParm rp = new ResParm(true);
rp = deleteUsato(rd);
if (rp.getStatus()) {
if (rd.getArticolo().usaMagazzino() && rd.getDocumento().getTipoDocumento().getFlgMovMagazzino() != 0L &&
rd.getDocumento().getFlgStato() == 1L &&
rd.getDocumento().getFlgStatoOrdineWww() != 99L) {
DoubleOperator dop = new DoubleOperator((float)rd.getDocumento().getTipoDocumento().getFlgMovMagazzino());
dop.multiply(-1);
dop.multiply(rd.getNr());
dop.add(rd.getArticolo().getQuantita());
rd.getArticolo().setQuantita(dop.getResult());
rd.getArticolo().handleQuantitaDebugBeforeSave("rigaDocumento.deleteMagArticolo");
rp = rd.getArticolo().superSave();
}
if (rp.getStatus())
rp.append(rd.superDelete());
}
return rp;
}
private static final synchronized ResParm deleteUsato(RigaDocumento rd) {
ResParm rp = new ResParm(true);
if (rd.getArticolo().getFlgUsato() > 0L) {
Documento doc = rd.getDocumento();
long l_id_documento = rd.getId_documento();
if (doc.getTipoDocumento().getFlgUsato() == 1L) {
if (rd.getArticolo().isArticoloUsatoVenduto()) {
ArticoloUsato au = new ArticoloUsato(rd.getApFull());
Vectumerator vec = au.findByRigaDocumento(rd.getId_rigaDocumento());
while (vec.hasMoreElements()) {
au = (ArticoloUsato)vec.nextElement();
if (au.getId_rigaDocumento() == rd.getId_rigaDocumento()) {
Articolo articolo = au.getArticolo();
rp = au.delete();
if (rp.getStatus()) {
articolo.setFlgEscludiWebArt(0L);
articolo.save();
}
continue;
}
rp.setStatus(false);
rp.setMsg("ERRORE! Impossibile eliminare, esistono movimenti successivi dell'articolo " + rd.getId_articolo() + "!");
}
} else {
rp.setStatus(false);
rp.setMsg("ERRORE! Impossibile eliminare, esistono movimenti successivi dell'articolo " + rd.getId_articolo() + "!");
}
} else if (!rd.getArticolo().isArticoloUsatoVenduto()) {
ArticoloUsato au = new ArticoloUsato(rd.getApFull());
Vectumerator vec = au.findByRigaDocumento(rd.getId_rigaDocumento());
while (vec.hasMoreElements()) {
au = (ArticoloUsato)vec.nextElement();
if (au.getId_rigaDocumento() == rd.getId_rigaDocumento()) {
Articolo articolo = au.getArticolo();
rp = au.delete();
if (rp.getStatus()) {
articolo.setFlgEscludiWebArt(1L);
articolo.save();
}
continue;
}
rp.setStatus(false);
rp.setMsg("ERRORE! Impossibile eliminare, esistono movimenti successivi dell'articolo " + rd.getId_articolo() + "!");
}
} else {
rp.setStatus(false);
rp.setMsg("ERRORE! Impossibile eliminare, esistono movimenti successivi dell'articolo " + rd.getId_articolo() + "!");
}
}
return rp;
}
public ResParm delete() {
if (getId_rigaDocumento() == 0L)
return new ResParm(false, "ATTENZIONE! Tentativo di cancellare una riga documento nulla!!!");
ResParm rp = getDocumento().checkEMSTA();
if (!rp.getStatus())
return new ResParm(false, "ATTENZIONE! Tentativo di cancellare una riga documento: " + rp.getMsg());
if (getParm("USA_MAGAZZINO").isTrue())
return deleteMagArticolo(this);
synchronized (this) {
rp = deleteUsato(this);
if (rp.getStatus()) {
if (getId_articolo() > 0L && (getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoArrivo() > 0L ||
getDocumento().getTipoDocumento().getCausaleMagazzino().getFlgPartenzaInterno() == 1L ||
getDocumento().getTipoDocumento().getCausaleMagazzino().getFlgPartenzaLavorazione() == 1L)) {
RigaDocumento rd = new RigaDocumento(getApFull());
if (rd.getDocumento().getTipoDocumento().getCausaleMagazzino().isMagArrivo()) {
rd.findMagDisponibilitaPuntualeMagazziniInterni(getId_articolo(), getId_articoloVariante(),
getId_articoloTaglia(), getSeriale(), 0L);
if (rd.getQuantita() < getQuantita())
return new ResParm(false, "ERRORE RD! Quantità non più disponibile in magazzino. E' stato effettuato uno scarico!");
}
rd = new RigaDocumento(getApFull());
rd.findRigaImpegnoBySeriale(getId_articolo(), getId_articoloVariante(), getSeriale());
if (rd.getDBState() == 1)
return new ResParm(false, "ERRORE! Esiste una prenotazione per questo seriale!");
}
RigaDocumento bean = (RigaDocumento)clone();
if (getDocumento().getTipoDocumento().getFlgTipologia() == 3L) {
RigaDocumentoPM rdPM = new RigaDocumentoPM(getApFull());
rdPM.findByRigaDocumento(getId_rigaDocumento());
if (rdPM.getDBState() == 1)
rdPM.delete();
}
if (getDocumento().getTipoDocumento().getFlgTipologia() == 4L) {
RigaDocumentoPM rdPM = new RigaDocumentoPM(getApFull());
Vectumerator vec = rdPM.findByRigaDocumentoPrelevata(getId_rigaDocumento());
while (vec.hasMoreElements()) {
DbInterface row = (DbInterface)vec.nextElement();
row.delete();
}
}
if (getDocumento().getTipoDocumento().getFlgTipologia() == 0L && getDocumento()
.getTipoDocumento().getFlgClienteFornitore().equals("C")) {
LavPezza rowLP = new LavPezza(getApFull());
Vectumerator<LavPezza> vecLP = rowLP.findByRigaDocumentoBolla(getId_rigaDocumento());
while (vecLP.hasMoreElements()) {
LavPezza row = (LavPezza)vecLP.nextElement();
row.setId_rigaDocumentoBolla(0L);
row.save();
}
}
if (getDocumento().isDocumentoFiglioCreabile()) {
Vectumerator<RigaDocumento> vecRDFigli = new RigaDocumento(getApFull()).findByDocumentoPadre(getId_documento(), 0, 0);
while (vecRDFigli.hasMoreElements()) {
RigaDocumento rowFiglio = (RigaDocumento)vecRDFigli.nextElement();
rowFiglio.setId_documentoPadre(0L);
rowFiglio.setId_rigaDocumentoPadre(0L);
rowFiglio.superSave();
}
}
String sql_delete_mov = "DELETE FROM RIGA_DOCUMENTO WHERE id_rigaDocumentoMov=" + getId_rigaDocumento();
rp = delete(sql_delete_mov);
if (rp.getStatus()) {
long l_id_articolo = getId_articolo();
long l_id_articoloVariante = getId_articoloVariante();
long l_id_articoloTaglia = getId_articoloTaglia();
long l_id_articoloFilatoColore = getId_articoloFilatoColore();
long l_id_articoloTessuto = getId_articoloTessuto();
long l_id_articoloTessutoColore = getId_articoloTessutoColore();
rp = super.delete();
setId_articolo(getId_articolo());
setId_articoloVariante(l_id_articoloVariante);
setId_articoloTaglia(l_id_articoloTaglia);
setId_articoloFilatoColore(l_id_articoloFilatoColore);
setId_articoloTessuto(l_id_articoloTessuto);
setId_articoloTessutoColore(l_id_articoloTessutoColore);
rp = aggiornaDispo();
}
if (rp.getStatus()) {
if (bean.getId_rigaDocumentoPadre() != 0L) {
RigaDocumento beanPadre = new RigaDocumento(getApFull());
beanPadre.findByPrimaryKey(bean.getId_rigaDocumentoPadre());
beanPadre.setFlgRigaPrelevata(0L);
rp = beanPadre.superSave();
Documento doc = new Documento(getApFull());
doc.findByPrimaryKey(beanPadre.getId_documento());
doc.setDataChiusura(null);
doc.setFlgDocumentoPrelevato(0L);
doc.superSave();
}
if (bean.getDocumento().getTipoDocumento().getId_causaleMagazzino() > 0L ||
bean.getDocumento().getTipoDocumento().getFlgTipologia() == 4L)
bean.checkStatoPrenotazione();
}
}
return rp;
}
}
public void calcolaStatoLavorazioneRiga() {
if (getId_telaio() == 0L) {
setFlgStatoLavorazioneRiga(0L);
setTsInizioLavorazioneRiga(null);
setTsFineLavorazioneRiga(null);
setColpoFinaleRiga(0L);
setColpoInizialeRiga(0L);
} else {
if (getColpoInizialeRiga() > 0L) {
if (getTsInizioLavorazioneRiga() == null)
setTsInizioLavorazioneRiga(getTimestamp());
} else {
setTsInizioLavorazioneRiga(null);
setTsFineLavorazioneRiga(null);
setColpoFinaleRiga(0L);
}
if (getColpoInizialeRiga() > 0L && getColpoFinaleRiga() > 0L) {
setFlgStatoLavorazioneRiga(100L);
if (getTsFineLavorazioneRiga() == null)
setTsFineLavorazioneRiga(getTimestamp());
} else if (getColpoInizialeRiga() > 0L) {
setFlgStatoLavorazioneRiga(20L);
} else {
setFlgStatoLavorazioneRiga(10L);
}
}
}
public ResParm save() {
ResParm rp = getDocumento().checkEMSTA();
if (!rp.getStatus()) {
rp.setInfoMsg(rp.getMsg());
return rp;
}
long l_id_articoloPrecedente = getId_articoloPrecedente();
calcolaStatoLavorazioneRiga();
rp = synchroSave(this);
if (rp.getStatus()) {
rp = aggiornaDispo();
if (getDocumento().isFatturaONotaDiCredito()) {
if (getId_rigaDocumento() > 0L)
new RigaDocumentoProgettista(getApFull()).deleteByRigaDocumento(getId_rigaDocumento());
Vectumerator vecPro = getArticolo().getProgettistiArticolo();
while (vecPro.hasMoreElements()) {
ArticoloProgettista rowAP = (ArticoloProgettista)vecPro.nextElement();
RigaDocumentoProgettista da = new RigaDocumentoProgettista(getApFull());
da.setId_rigaDocumento(getId_rigaDocumento());
da.setId_cliforRDA(rowAP.getId_progettista());
da.setPercRDA(rowAP.getPercProvvigione());
da.save();
}
}
if (getDocumento().getTipoDocumento().getFlgUsato() == 1L &&
getArticolo().getFlgUsato() > 0L) {
ArticoloUsato au = new ArticoloUsato(getApFull());
Vectumerator vecAu = au.findByRigaDocumento(getId_rigaDocumento());
while (vecAu.hasMoreElements())
((DbInterface)vecAu.nextElement()).delete();
au.setId_articolo(getId_articolo());
au.setDataDocumento(getDocumento().getDataDocumento());
au.setNumeroDocumento(getDocumento().getNumeroDocumento());
if (!getDocumento().getTipoDocumento().isNotaCreditoVendita()) {
au.setFlgTipoDocumento(2L);
} else {
au.setFlgTipoDocumento(3L);
}
au.setId_rigaDocumento(getId_rigaDocumento());
au.setId_cliente(getDocumento().getId_clifor());
au.setImporto(getImponibile());
rp = au.save();
if (rp.getStatus())
if (getDocumento().getTipoDocumento().isNotaCreditoVendita()) {
au.getArticolo().setFlgEscludiWebArt(0L);
} else {
au.getArticolo().setFlgEscludiWebArt(1L);
}
au.getArticolo().save();
}
}
return rp;
}
private ResParm aggiornaDispo() {
if (getId_articolo() > 0L && getArticolo().usaMagazzino())
return aggiornaDispo(getApFull(), getId_articolo(), getId_articoloVariante(), getId_articoloTaglia(), getLastUpdId_user());
if (getId_articoloTessuto() > 0L && getArticoloTessuto().usaMagazzino())
return aggiornaDispoTessuto(getApFull(), getId_articoloTessuto(), getId_articoloTessutoColore(), getLastUpdId_user());
if (getId_articoloFilatoColore() > 0L && getArticoloFilatoColore().usaMagazzino())
return aggiornaDispoFilato(getApFull(), getId_articoloFilatoColore(), getLastUpdId_user());
return new ResParm(true);
}
public ResParm saveFilato() {
ResParm rp = synchroSaveFilato(this);
if (rp.getStatus())
if (getArticoloFilatoColore().usaMagazzino())
rp = aggiornaDispoFilato(getApFull(), getId_articoloFilatoColore(), getLastUpdId_user());
return rp;
}
public ResParm saveTessuto() {
ResParm rp = synchroSaveTessuto(this);
if (rp.getStatus())
if (getArticoloTessuto().usaMagazzino())
rp = aggiornaDispoTessuto(getApFull(), getId_articoloTessuto(), getId_articoloTessutoColore(), getLastUpdId_user());
return rp;
}
public double getQuantitaOld() {
return this.quantitaOld;
}
public void setQuantitaOld(double quantitaOld) {
this.quantitaOld = quantitaOld;
}
protected void fillFields(ResultSet rst) {
super.fillFields(rst);
if (getParm("USA_MAGAZZINO").isTrue())
setQuantitaOld(getQuantita());
setId_articoloPrecedente(getId_articolo());
try {
resetRstColumns();
if (isColumnInResultSet(rst, "id_articoloFilato")) {
setId_articoloFilato(rst.getLong("id_articoloFilato"));
} else if (isColumnInResultSet(rst, "id_articoloTessutoColore")) {
setId_articoloTessutoColore(rst.getLong("id_articoloTessutoColore"));
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (getDocumento().getTipoDocumento().getFlgImportoIva() == 1L)
setPrezzoPubblicoConIva(getImporto());
} catch (Exception e) {
String temp = "######### RIGADOCUMENTO FILLFIELD EXCEPTION ######\n";
temp = temp + "id_rigadocumento: " + temp + " id_documento: " + getId_rigaDocumento() + "\n";
temp = temp + "AP: " + temp + "\n";
System.out.println(temp);
e.printStackTrace();
System.out.println("***************************************************************");
handleDebug(temp + "*********************************", 0);
}
}
protected void initFields() {
super.initFields();
setQuantitaOld(0.0D);
setId_iva(getCodiceIvaVendStd());
setStatoPrenotazione(-1L);
setId_articoloFilato(0L);
setId_articoloPrecedente(0L);
setRifTipoArticolo(1L);
setNumeroTeliRiga(null);
}
public String getDescrizioneTipoMovimento() {
if (getFlgReso() == 1L)
return "RESO";
return getDocumento().getTipoDocumento().getCausaleMagazzino().getDescrizione();
}
protected void prepareSave(PreparedStatement ps) throws SQLException {
if (getDocumento().getTipoDocumento().getFlgTipologia() == 201L);
if (getDocumento().getTipoDocumento().getFlgTipologia() == 200L)
if (getDocumento().getFlgBarcodeType() != 100L)
if (!getCodiceCartellinoIniziale().isEmpty())
try {
if (getDocumento().getFlgBarcodeType() == 0L) {
String start = getCodiceCartellinoIniziale().substring(0, getCodiceCartellinoIniziale().length());
String pre = start.substring(0, start.length() - (int)getDocumento().getFlgBarcodeSequenzaNumeri());
long numeroIniziale = Long.valueOf(
start.substring(start.length() - (int)getDocumento().getFlgBarcodeSequenzaNumeri(), start.length()));
long numeroFinale = numeroIniziale + getStacchi() - 1L;
setCodiceCartellinoStart(pre + pre);
setCodiceCartellinoStop(pre + pre);
} else if (getDocumento().getFlgBarcodeType() == 1L) {
String start = getCodiceCartellinoIniziale().substring(0, getCodiceCartellinoIniziale().length() - 1);
String pre = start.substring(0, start.length() - (int)getDocumento().getFlgBarcodeSequenzaNumeri());
long numeroIniziale = Long.valueOf(
start.substring(start.length() - (int)getDocumento().getFlgBarcodeSequenzaNumeri(), start.length()));
long numeroFinale = numeroIniziale + getStacchi() - 1L;
setCodiceCartellinoStart(pre + pre);
setCodiceCartellinoStop(pre + pre);
}
} catch (Exception e) {}
if (getStacchi() > 0L && getMetriStacchi() > 0.0D) {
DoubleOperator dop = new DoubleOperator((float)getStacchi());
dop.multiply(getMetriStacchi());
dop.setScale(2, 5);
setMt(dop.getResult());
}
if (getDocumento().getTipoDocumento().getFlgImportoIva() == 1L) {
setImporto(getPrezzoPubblicoConIva());
setImponibile(Documento.scorporaIva(getPrezzoPubblicoConIva(), getIva()));
} else {
setImporto(getImportoCalc());
}
super.prepareSave(ps);
}
public MagFisico getMagFisicoPartenza() {
return getDocumento().getTipoDocumento().getCausaleMagazzino().getMagFisicoPartenza();
}
public MagFisico getMagFisicoArrivo() {
return getDocumento().getTipoDocumento().getCausaleMagazzino().getMagFisicoArrivo();
}
public long getFlgSingleLineArt() {
return this.flgSingleLineArt;
}
public void setFlgSingleLineArt(long flgSingleLineArt) {
this.flgSingleLineArt = flgSingleLineArt;
}
public void findFirstByDocumentoArticoloVariante(long l_id_documento, long l_id_articoloVariante) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_order = "";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
wc.addWc("A.id_articoloVariante=" + l_id_articoloVariante);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
findFirstRecord(stmt);
} catch (Exception e) {
handleDebug(e, 0);
}
}
public void addQuantita(double l_quantita) {
DoubleOperator dop = new DoubleOperator(getQuantita());
dop.add(l_quantita);
setQuantita(dop.getResult());
setQuantitaUdm(dop.getResult());
}
public String getCashStringSiemens() {
if (getImportoConSconto() != 0.0D) {
StringBuffer temp = new StringBuffer();
String sep = "|";
if (getQuantita() > 1.0D) {
temp.append("KX" + (int)getQuantita() + "* ");
temp.append(sep);
}
String importo = getNf2().format(getImportoConSconto());
importo = importo.replace(".", "");
importo = importo.replace(",", "");
String reparto = getReparto().getSigla() + getReparto().getSigla();
if (reparto.isEmpty())
reparto = "R9VARIE..";
if (getImportoConSconto() < 0.0D) {
temp.append("KX- ");
temp.append(sep);
String rigaSconto = getDescrizioneRiga();
if (rigaSconto.length() > 11)
rigaSconto = rigaSconto.substring(0, 11);
temp.append("KX" + importo.substring(1) + "GE" + rigaSconto);
} else {
temp.append("KX" + importo + reparto);
}
if (!getNotaRigaDocumento().isEmpty()) {
temp.append(sep);
temp.append("KXSE" + subString(getNotaRigaDocumento(), 24));
}
if (isDescScontrinoFull()) {
temp.append(sep);
if (getId_articoloVariante() != 0L) {
temp.append("KXSE" + subString(getArticoloVariante().getDescrizioneCompleta(), 24));
} else {
temp.append("KXSE" + subString(getArticolo().getDescrizioneCompleta(), 24));
}
if (!getSeriale().isEmpty()) {
temp.append(sep);
temp.append("KXSES/N" + getSeriale());
}
}
if (getIva().getAliquota() == 0L) {
temp.append(sep);
temp.append("KXSE" + getIva().getDescrizione());
}
return temp.toString();
}
return "";
}
public double getTotImportoRigaConSconto() {
DoubleOperator temp = new DoubleOperator(getImportoConSconto());
temp.multiply(getQuantita());
temp.setScale(3, 5);
return temp.getResult();
}
public double getImportoConSconto() {
if (getSconto() == 0.0D && getPercL1() == 0.0D && getPercL2() == 0.0D && getPercL3() == 0.0D)
return getImporto();
DoubleOperator temp = new DoubleOperator(getImporto());
temp.setScale(4, 5);
temp.subtract(getImportoSconto());
temp.setScale(2, 5);
return temp.getResult();
}
public double getImponibileRigaConSconto() {
if (!getIva().getFlgTipo().equals("R")) {
if (getSconto() > 0.0D) {
DoubleOperator temp = new DoubleOperator(100.0F);
temp.setScale(4, 5);
temp.subtract(getSconto());
temp.multiply(getImponibile());
temp.divide(100.0F);
temp.setScale(2, 5);
return temp.getResult();
}
return getImponibile();
}
return 0.0D;
}
protected ResParm aggiornaCostoUltimoFornitore() {
ResParm rp = new ResParm(true);
if (getId_articolo() == 0L && getId_articoloTessuto() == 0L)
return rp;
long l_id_clifor = 0L;
if (getDocumento().getTipoDocumento().getFlgClienteFornitore().equals("F"))
l_id_clifor = getDocumento().getId_clifor();
if (l_id_clifor != 0L && getImponibile() > 0.0D && (getId_articolo() > 0L || getId_articoloTessuto() > 0L)) {
ArticoloFornitore af = new ArticoloFornitore(getApFull());
if (getId_articolo() > 0L) {
af.findByFornitoreArticolo(l_id_clifor, getId_articolo(), -1L);
} else if (getId_articoloTessuto() > 0L) {
af.findByArticoloTessutoFornitore(l_id_clifor, getId_articoloTessuto());
}
af.setId_articolo(getId_articolo());
af.setId_articoloVariante(getId_articoloVariante());
af.setId_articoloTessuto(getId_articoloTessuto());
af.setId_articoloTessutoColore(getId_articoloTessutoColore());
af.setId_clifor(getDocumento().getId_clifor());
af.setCostoVecchio(af.getCostoTotale());
af.setCosto(getImponibile());
af.setDataUltimoPrezzo(getDocumento().getDataDocumento());
rp = af.save();
if (getId_articolo() > 0L) {
getArticolo().aggiornaUltimoCosto(getImponibile(), getDocumento().getDataDocumento());
} else if (getId_articoloTessuto() > 0L) {
}
}
return rp;
}
public String getDescrizione() {
if (getId_articoloTaglia() != 0L)
return getArticoloTaglia().getDescrizioneCompleta();
if (getId_articoloVariante() == 0L)
return getArticolo().getNome();
return getArticoloVariante().getNomeV();
}
public void findFirstByDocumentoArticolo(long l_id_documento, long l_id_articolo) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_order = "";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
wc.addWc("A.id_articolo=" + l_id_articolo);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
findFirstRecord(stmt);
} catch (Exception e) {
handleDebug(e, 0);
}
}
public Vectumerator findRighePrelevabiliByDocumento(Documento l_documento, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A , DOCUMENTO AS B";
String s_Sql_order = "";
WcString wc = new WcString();
wc.addWc("A.id_documento=B.id_documento");
wc.addWc("B.flgStato =1");
wc.addWc("A.flgRigaPrelevata !=1");
if (l_documento.getId_clifor() == 0L)
return AB_EMPTY_VECTUMERATOR;
if (!l_documento.getTipoDocumento().getFlgClienteFornitore().equals("A"))
wc.addWc("B.id_clifor=" + l_documento.getId_clifor());
Vectumerator<DocPrel> vectumerator = l_documento.getTipoDocumento().findDocPrel(0L, 0, 0);
if (!vectumerator.hasMoreElements())
return AB_EMPTY_VECTUMERATOR;
OrString or = new OrString();
while (vectumerator.hasMoreElements()) {
DocPrel row = (DocPrel)vectumerator.nextElement();
or.addOr("B.id_tipoDocumento=" + row.getId_tipoDocumentoPrel());
}
wc.addWc(or.toString());
Vectumerator<RigaDocumento> vec = findByDocumento(l_documento.getId_documento(), -1L, "", 0, 0, 0);
if (!vec.hasMoreElements())
return AB_EMPTY_VECTUMERATOR;
or = new OrString();
while (vec.hasMoreElements()) {
RigaDocumento row = (RigaDocumento)vec.nextElement();
if (row.getId_articoloVariante() == 0L) {
or.addOr("A.id_articolo=" + row.getId_articolo());
continue;
}
or.addOr("A.id_articoloVariante=" + row.getId_articoloVariante());
}
wc.addWc(or.toString());
wc.addWc(" B.dataDocumento <= ? ");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
stmt.setDate(1, l_documento.getDataDocumento());
return findRows(stmt, pageNumber, pageRows);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public String getCashStringNonFiscale() {
StringBuffer temp = new StringBuffer();
String sep = "|";
temp.append("KXCB");
if (getQuantita() > 1.0D)
temp.append("" + (int)getQuantita() + "* ");
if (getId_articoloVariante() != 0L) {
temp.append(subString(getArticoloVariante().getDescrizioneCompleta(), 24));
} else if (getId_articolo() != 0L) {
temp.append(subString(getArticolo().getDescrizioneCompleta(), 24));
} else {
temp.append(subString(getDescrizioneRiga(), 24));
}
if (!getNotaRigaDocumento().isEmpty()) {
temp.append(sep);
temp.append("KXSE" + subString(getNotaRigaDocumento(), 24));
}
temp.append(sep);
return temp.toString();
}
public long getTotalePezzeStacchiByDocumento(long l_id_documento) {
String s_Sql_Find = "select sum(A.stacchi) as _sum from RIGA_DOCUMENTO AS A";
WcString wc = new WcString();
if (l_id_documento == 0L)
return 0L;
wc.addWc("A.id_documento=" + l_id_documento);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
return (long)getSum(stmt);
} catch (Exception e) {
handleDebug(e, 0);
return 0L;
}
}
public double getQtaPrenotazioneAssegnata(long l_id_articolo, long l_id_articoloVariante) {
String s_Sql_Find = "select sum(A.quantita) as _sum from RIGA_DOCUMENTO AS A, DOCUMENTO AS B";
WcString wc = new WcString();
wc.addWc("A.id_documento=B.id_documento");
wc.addWc("A.flgPrenotazioneArrivata =1");
if (l_id_articolo != 0L)
wc.addWc("A.id_articolo =" + l_id_articolo);
if (l_id_articoloVariante != 0L)
wc.addWc("A.id_articoloVariante =" + l_id_articoloVariante);
wc.addWc("B.flgStatoPrenotazione<=20");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
return getSum(stmt);
} catch (Exception e) {
handleDebug(e, 0);
return 0.0D;
}
}
public void setQuantitaPrelevata(double quantitaPrelevata) {
this.quantitaPrelevata = quantitaPrelevata;
}
public double getQuantitaRimanente() {
DoubleOperator dop = new DoubleOperator(getQuantita());
dop.subtract(getQuantitaPrelevata());
return dop.getResult();
}
private static synchronized ResParm addRigaDocumentoP(RigaDocumento rd, RigaDocumentoP row) {
RigaDocumentoP bean = new RigaDocumentoP(rd.getApFull());
RigaDocumentoPKey theKey = new RigaDocumentoPKey(row.getId_rigaDocumento(), row.getId_rigaDocumentoPrelevata());
bean.findByKey(theKey);
row.setDBState(bean.getDBState());
ResParm rp = row.save();
return rp;
}
public ResParm addRigaDocumentoP(RigaDocumentoP row) {
return addRigaDocumentoP(this, row);
}
public ResParm delRigaDocumentoP(RigaDocumentoP row) {
return delRigaDocumentoP(this, row);
}
public ResParm addRigaDocumentoPM(RigaDocumentoPM row) {
return addRigaDocumentoPM(this, row);
}
public ResParm delRigaDocumentoPM(RigaDocumentoPM row) {
return delRigaDocumentoPM(this, row);
}
public void aggiornaQuantitaPrelevata() {
RigaDocumentoP rdp = new RigaDocumentoP(getApFull());
setQuantitaPrelevata(rdp.getQuantitaPrelevatoByRigaDocumentoPrelevata(getId_rigaDocumento()));
if (getQuantitaPrelevata() >= getQuantita() && getQuantitaPrelevata() > 0.0D && getQuantita() > 0.0D)
setFlgRigaPrelevata(1L);
superSave();
}
private static synchronized ResParm delRigaDocumentoP(RigaDocumento rd, RigaDocumentoP row) {
RigaDocumentoP bean = new RigaDocumentoP(rd.getApFull());
RigaDocumentoPKey theKey = new RigaDocumentoPKey(row.getId_rigaDocumento(), row.getId_rigaDocumentoPrelevata());
bean.findByKey(theKey);
return bean.delete();
}
public double getQuantitaAssociata() {
return this.quantitaAssociata;
}
public void setQuantitaAssociata(double quantitaAssociata) {
this.quantitaAssociata = quantitaAssociata;
}
public void aggiornaQuantitaAssociata() {
String s_Sql_Find = "select sum(A.quantitaPrelevata) as _sum from RIGA_DOCUMENTO_P AS A";
WcString wc = new WcString();
wc.addWc("A.id_rigaDocumento=" + getId_rigaDocumento());
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
setQuantitaAssociata(getSum(stmt));
superSave();
} catch (Exception e) {
handleDebug(e, 0);
}
}
public long getFlgRigaPrelevata() {
return this.flgRigaPrelevata;
}
public void setFlgRigaPrelevata(long flgRigaPrelevata) {
this.flgRigaPrelevata = flgRigaPrelevata;
}
public boolean isAllRighePrelevateByDocumento(long l_id_documento) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
wc.addWc("(A.id_rigaDocumentoMov=0 or A.id_rigaDocumentoMov is null)");
wc.addWc("(A.flgRigaPrelevata is null or A.flgRigaPrelevata=0)");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
Vectumerator vec = findRows(stmt, 1, 1);
if (vec.hasMoreElements())
return false;
return true;
} catch (Exception e) {
handleDebug(e, 0);
return false;
}
}
public double getPrezzoPubblicoConIva() {
return this.prezzoPubblicoConIva;
}
public void setPrezzoPubblicoConIva(double prezzoPubblicoConIva) {
this.prezzoPubblicoConIva = prezzoPubblicoConIva;
}
public double getImportoCalc() {
if (getId_iva() != 0L) {
DoubleOperator ppi = new DoubleOperator(getImponibile());
ppi.setScale(4, 5);
ppi.multiply(getIva().getAliquota());
ppi.divide(100.0F);
ppi.add(getImponibile());
ppi.setScale(2, 5);
return ppi.getResult();
}
return getImponibile();
}
public long getId_reparto() {
if (this.id_reparto == 0L && getId_articolo() != 0L)
return getArticolo().getTipo().getId_reparto();
return this.id_reparto;
}
public Reparto getReparto() {
this.reparto = (Reparto)getSecondaryObject(this.reparto, Reparto.class, getId_reparto());
return this.reparto;
}
public void setId_reparto(long id_reparto) {
this.id_reparto = id_reparto;
setReparto(null);
}
public void setReparto(Reparto reparto) {
this.reparto = reparto;
}
public double getImporto() {
if (getId_articolo() == 0L)
return this.importo;
if (getArticolo().getFlgNegativo() == 1L || getFlgReso() == 1L)
return -Math.abs(this.importo);
return Math.abs(this.importo);
}
public void setImporto(double importo) {
this.importo = importo;
}
public Vectumerator findRigheDocumentoPrelevateDaStornare() {
String s_Sql_Find = "select * from riga_documento where flgRigaPrelevata=1 and quantitaPrelevata!=nr";
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find);
return findRows(stmt);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public ResParm savexAggiornaCostoUltimoFornitore() {
synchronized (this) {
ResParm rp = aggiornaCostoUltimoFornitore();
return rp;
}
}
public Vectumerator findVenditeGiornaliere(DocumentoCR CR, long l_id_docCassa) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A left join ARTICOLO AS C on A.id_articolo=C.id_articolo left join TIPO AS D on C.id_tipo=D.id_tipo left join REPARTO AS E on A.id_reparto=E.id_reparto , DOCUMENTO AS B ";
String s_Sql_Order = " order by B.dataDocumento, E.descrizione, D.descrizione, A.descrizioneRiga, A.notaBarcode ";
WcString wc = new WcString();
wc.addWc("A.id_documento=B.id_documento");
wc.addWc("B.id_tipoDocumento= " + l_id_docCassa);
if (CR.getId_tipo() > 0L)
wc.addWc("(C.id_tipo=" + CR.getId_tipo() + " or D.indici like'%:" + CR.getId_tipo() + ":%')");
wc.addWc("B.dataDocumento>=?");
wc.addWc("B.dataDocumento<=?");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
int dataCount = 1;
stmt.setDate(dataCount, CR.getDataDocumentoDa());
dataCount++;
stmt.setDate(dataCount, CR.getDataDocumentoA());
return findRows(stmt);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public ResParm deleteNOMAG() {
synchronized (this) {
Vectumerator vec = new RigaDocumentoP(getApFull()).findByRigaDocumento(getId_rigaDocumento(), 0, 0);
while (vec.hasMoreElements()) {
DbInterface row = (DbInterface)vec.nextElement();
row.delete();
}
ResParm rp = super.delete();
return rp;
}
}
public ResParm superSave() {
return super.save();
}
public String getDescrizioneMovimentoMagazzino() {
String temp;
if (getFlgReso() == 1L) {
temp = getMagFisicoArrivo().getDescrizione() + "-->" + getMagFisicoArrivo().getDescrizione();
} else {
temp = getMagFisicoPartenza().getDescrizione() + "-->" + getMagFisicoPartenza().getDescrizione();
}
if (temp.equals("-->"))
return "";
return temp;
}
public double getQuantitaImpegnataByArticolo(long l_id_articolo) {
RigaDocumentoCR CR = new RigaDocumentoCR(getApFull());
RigaDocumento bean = new RigaDocumento(getApFull());
CR.setFlgTipologia(4L);
CR.setFlgRigaPrelevata(0L);
CR.setFlgStatoPrenotazione(200L);
CR.setId_articolo(l_id_articolo);
CR.setFlgTipoRicerca(0L);
Vectumerator vec = bean.findByCR(CR, 0, 0);
DoubleOperator dop = new DoubleOperator();
while (vec.hasMoreElements()) {
RigaDocumento row = (RigaDocumento)vec.nextElement();
dop.add(row.getQuantita());
dop.subtract(row.getQuantitaPrelevata());
}
return dop.getResult();
}
public double getQuantitaImpegnataFilatoByArticoloFilatoColoreSeriale(long l_id_articoloFilatoColore, long l_id_articoloFilato, long l_id_coloreFilato, String l_seriale) {
MagFisico mf = new MagFisico(getApFull());
mf.findMagazzinoOrdinato();
RigaDocumento rd = new RigaDocumento(getApFull());
rd.findMagFilatoDisponibilitaPuntuale(l_id_articoloFilatoColore, l_id_articoloFilato, l_id_coloreFilato, l_seriale,
mf.getId_magFisico(), 0L, 0L, "C");
return rd.getQuantita();
}
public double getQuantitaImpegnataTessutoByArticoloTessutoColoreSeriale(long l_id_articoloTessutoColore, long l_id_articoloTessuto, long l_id_coloreTessuto, String l_seriale) {
MagFisico mf = new MagFisico(getApFull());
mf.findMagazzinoOrdinato();
RigaDocumento rd = new RigaDocumento(getApFull());
rd.findMagTessutoDisponibilita(l_id_articoloTessuto, l_id_articoloTessutoColore, l_seriale, mf.getId_magFisico(), 0L, -1L, 0L, "C", DATA_NULL);
return rd.getQuantita();
}
public double getQuantitaInArrivoByArticolo(long l_id_articolo) {
MagFisico mf = new MagFisico(getApFull());
mf.findMagazzinoOrdinato();
if (mf.getId_magFisico() > 0L) {
RigaDocumento rd = new RigaDocumento(getApFull());
rd.findMagDisponibilitaPuntuale(l_id_articolo, 0L, 0L, null, mf.getId_magFisico(), 0L, 0L);
return rd.getQuantita();
}
return 0.0D;
}
public double getQuantitaFilatoInArrivoByArticoloFilatoColoreSeriale(long l_id_articoloFilatoColore, long l_id_articolofilato, long l_id_colore, String l_seriale) {
MagFisico mf = new MagFisico(getApFull());
mf.findMagazzinoOrdinato();
if (mf.getId_magFisico() > 0L) {
RigaDocumento rd = new RigaDocumento(getApFull());
rd.findMagFilatoDisponibilitaPuntuale(l_id_articoloFilatoColore, l_id_articolofilato, l_id_colore, l_seriale,
mf.getId_magFisico(), 0L, 0L, "F");
return rd.getQuantita();
}
return 0.0D;
}
public double getQuantitaTessutoInArrivoByArticoloTessutoColoreSeriale(long l_id_articoloTessutoColore, long l_id_articoloTessuto, long l_id_colore, String l_seriale) {
MagFisico mf = new MagFisico(getApFull());
mf.findMagazzinoOrdinato();
if (mf.getId_magFisico() > 0L) {
RigaDocumento rd = new RigaDocumento(getApFull());
rd.findMagTessutoDisponibilita(l_id_articoloTessuto, l_id_articoloTessutoColore, l_seriale, mf.getId_magFisico(), 0L, -1L, 0L, "F", DATA_NULL);
return rd.getQuantita();
}
return 0.0D;
}
public double getQuantitaTessutoLavorazioneByArticoloTessutoColoreSeriale(long l_id_articoloTessutoColore, long l_id_articoloTessuto, long l_id_colore, String l_seriale) {
RigaDocumento rd = new RigaDocumento(getApFull());
rd.findMagTessutoDisponibilita(l_id_articoloTessuto, l_id_articoloTessutoColore, l_seriale, 0L, 0L, 20L, 0L, "", DATA_NULL);
return rd.getQuantita();
}
public double getQuantitaInArrivoByArticoloM(long l_id_articolo) {
MagFisico mf = new MagFisico(getApFull());
mf.findMagazzinoOrdinato();
Movimento mov = new Movimento(getApFull());
mov.findDisponibilitaPuntuale(l_id_articolo, 0L, 0L, null, mf.getId_magFisico(), 0L);
return mov.getQuantita();
}
public double[] getQtaOrdinataPrelevataByRigaPrenotazione() {
double[] res = { 0.0D, 0.0D };
if (getId_rigaDocumento() == 0L)
return res;
String s_Sql_Find = "SELECT Sum(A.quantita) as quantita, Sum(A.quantitaPrelevata) AS quantitaPrelevata FROM RIGA_DOCUMENTO as A inner join RIGA_DOCUMENTO_P_M AS B ON A.id_rigaDocumento=B.id_rigaDocumento";
String s_Sql_Order = " ";
WcString wc = new WcString();
wc.addWc("B.id_rigaDocumentoPrelevata=" + getId_rigaDocumento());
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
Vectumerator vec = findRows(stmt);
if (vec.hasMoreElements()) {
RigaDocumento r = (RigaDocumento)vec.nextElement();
res[0] = r.getQuantita();
res[1] = r.getQuantitaPrelevata();
}
} catch (SQLException e) {
handleDebug(e);
}
return res;
}
private static synchronized ResParm synchroSaveMagArticolo(RigaDocumento bean) {
ResParm rp = new ResParm();
rp = bean.superSave();
if (rp.getStatus())
rp.append(bean.aggiornaCostoUltimoFornitore());
return rp;
}
private static synchronized ResParm synchroSave(RigaDocumento bean) {
ResParm rp = bean.getDocumento().checkEMSTA();
if (!rp.getStatus())
return new ResParm(false, "ATTENZIONE! Tentativo di modificare una riga documento: " + rp.getMsg());
if (bean.getParm("USA_MAGAZZINO").isTrue())
return synchroSaveMagArticolo(bean);
RigaDocumento rd = new RigaDocumento(bean.getApFull());
rd.findByPrimaryKey(bean.getId_rigaDocumento());
long l_flgRigaPrelevata = rd.getFlgRigaPrelevata();
if (bean.getDBState() == 1) {
if (bean.getFlgRigaPrelevata() == 1L)
return new ResParm(false, "ERRORE! Non puoi modificare una riga chiusa!");
if (bean.getQuantitaPrelevata() > 0.0D && bean.getQuantita() < bean.getQuantitaPrelevata())
return new ResParm(false, "ERRORE! La quantità prelevata è maggiore della quantità della riga");
}
if (bean.getQuantitaPrelevata() >= bean.getQuantita() && bean.getQuantitaPrelevata() > 0.0D && bean.getQuantita() > 0.0D)
bean.setFlgRigaPrelevata(1L);
double quantitaPrelevata1 = 0.0D;
if (bean.getArticolo().usaMagazzino()) {
RigaDocumentoP rdp = new RigaDocumentoP(bean.getApFull());
rd.getMagQuantitaPrelevatoByRigaDocumento(bean.getId_rigaDocumento());
quantitaPrelevata1 = rd.getQuantita();
double quantitaPrelevata2 = rdp.getQuantitaPrelevatoByRigaDocumento(bean.getId_rigaDocumento());
if (quantitaPrelevata1 != quantitaPrelevata2) {
System.out.println("Rigadocumento.synchroSave: ERRORE calcolo quantità prelevate" + quantitaPrelevata1 + "!= " + quantitaPrelevata2);
quantitaPrelevata1 = quantitaPrelevata2;
}
if (bean.getQuantita() < quantitaPrelevata1)
return new ResParm(false, "ERRORE! La quantità prelevata è maggiore della quantità della riga");
}
RigaDocumento beanRB = null;
if (bean.getId_rigaDocumento() != 0L) {
beanRB = new RigaDocumento(bean.getApFull());
beanRB.findByPrimaryKey(bean.getId_rigaDocumento());
}
rp = new ResParm(true);
if (bean.getId_articolo() != 0L && bean.getArticolo().usaMagazzino()) {
long magPartenza = 0L;
long magArrivo = 0L;
long flgInternoPartenza = 0L;
long flgInternoArrivo = 0L;
if (bean.getDocumento().getId_magFisicoPartenza() == 0L) {
if (bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoPartenza() > 0L) {
magPartenza = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoPartenza();
flgInternoPartenza = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getMagFisicoPartenza().getFlgTipo();
}
} else {
magPartenza = bean.getDocumento().getId_magFisicoPartenza();
flgInternoPartenza = bean.getDocumento().getMagFisicoPartenza().getFlgTipo();
}
if (bean.getDocumento().getId_magFisicoArrivo() == 0L) {
if (bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoArrivo() > 0L) {
magArrivo = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoArrivo();
flgInternoArrivo = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getMagFisicoArrivo().getFlgTipo();
}
} else {
magArrivo = bean.getDocumento().getId_magFisicoArrivo();
flgInternoArrivo = bean.getDocumento().getMagFisicoArrivo().getFlgTipo();
}
if (magPartenza != 0L || (magPartenza == 0L && magArrivo == 0L)) {
long segnoMov = -1L;
if (bean.getFlgReso() == 1L)
segnoMov = 1L;
if (magPartenza == 0L && magArrivo == 0L)
segnoMov = 0L;
bean.setSegnoMov(segnoMov);
bean.setId_causaleMagazzino(bean.getDocumento().getTipoDocumento().getId_causaleMagazzino());
bean.setId_magFisico(magPartenza);
if (flgInternoPartenza == 1L) {
bean.setId_clifor(0L);
} else {
bean.setId_clifor(bean.getDocumento().getId_clifor());
}
rp = bean.superSave();
}
if (rp.getStatus() && magArrivo != 0L) {
long segnoMov = 1L;
if (bean.getFlgReso() == 1L)
segnoMov = -1L;
if (magPartenza == 0L) {
bean.setSegnoMov(segnoMov);
bean.setId_causaleMagazzino(bean.getDocumento().getTipoDocumento().getId_causaleMagazzino());
bean.setId_magFisico(magArrivo);
if (flgInternoArrivo == 1L) {
bean.setId_clifor(0L);
} else {
bean.setId_clifor(bean.getDocumento().getId_clifor());
}
rp = bean.superSave();
} else {
try {
RigaDocumento rd2 = (RigaDocumento)bean.clone();
rd2.setDBState(0);
rd2.setId_rigaDocumento(0L);
rd2.setId_rigaDocumentoMov(bean.getId_rigaDocumento());
rd2.setSegnoMov(segnoMov);
rd2.setId_magFisico(magArrivo);
if (flgInternoArrivo == 1L) {
rd2.setId_clifor(0L);
} else {
rd2.setId_clifor(bean.getDocumento().getId_clifor());
}
rd2.setId_rigaDocumentoMov(bean.getId_rigaDocumento());
rp = bean.superSave();
} catch (Exception e) {
bean.handleDebug(e, 0);
rp.setException(e);
}
}
}
} else {
bean.setId_clifor(0L);
rp = bean.superSave();
}
if (rp.getStatus()) {
rp.append(bean.getDocumento().save());
rp.append(bean.aggiornaCostoUltimoFornitore());
if (l_flgRigaPrelevata != bean.getFlgRigaPrelevata())
if (bean.getFlgRigaPrelevata() == 0L) {
if (bean.getDocumento().getFlgDocumentoPrelevato() == 1L)
bean.getDocumento().aggiornaFlgDocumentoPrelevato(0L);
} else {
bean.getDocumento().verificaEAggiornaFlgDocumentoPrelevato();
}
if (bean.getArticolo().usaMagazzino() && (bean.getDocumento().getTipoDocumento().getId_causaleMagazzino() > 0L ||
bean.getDocumento().getTipoDocumento().getFlgTipologia() == 4L)) {
bean.resetStatoPrenotazioneByArticolo(bean.getId_articolo(), bean.getId_articoloVariante(), bean.getId_articoloTaglia());
bean.checkStatoPrenotazione();
}
}
if (rp.getStatus())
rp.setMsg(AbMessages.getMessage("SAVE_OK"));
return rp;
}
private static synchronized ResParm synchroSaveFilato(RigaDocumento bean) {
ResParm rp = bean.getDocumento().checkEMSTA();
if (!rp.getStatus())
return new ResParm(false, "ATTENZIONE! Tentativo di modificare una riga documento: " + rp.getMsg());
RigaDocumento rd = new RigaDocumento(bean.getApFull());
rd.findByPrimaryKey(bean.getId_rigaDocumento());
long l_flgRigaPrelevata = rd.getFlgRigaPrelevata();
if (bean.getDBState() == 1) {
if (bean.getFlgRigaPrelevata() == 1L)
return new ResParm(false, "ERRORE! Non puoi modificare una riga chiusa!");
if (bean.getQuantitaPrelevata() > 0.0D && bean.getQuantita() < bean.getQuantitaPrelevata())
return new ResParm(false, "ERRORE! La quantità prelevata è maggiore della quantità della riga");
}
if (bean.getQuantitaPrelevata() >= bean.getQuantita() && bean.getQuantitaPrelevata() > 0.0D && bean.getQuantita() > 0.0D)
bean.setFlgRigaPrelevata(1L);
double quantitaPrelevata1 = 0.0D;
System.out.println(bean.getId_articoloFilatoColore());
if (bean.getArticoloFilatoColore().isUsaMagazzino()) {
rd.getMagQuantitaPrelevatoByRigaDocumento(bean.getId_rigaDocumento());
quantitaPrelevata1 = rd.getQuantita();
if (bean.getQuantita() < quantitaPrelevata1)
return new ResParm(false, "ERRORE! La quantità prelevata è maggiore della quantità della riga");
}
RigaDocumento beanRB = null;
if (bean.getId_rigaDocumento() != 0L) {
beanRB = new RigaDocumento(bean.getApFull());
beanRB.findByPrimaryKey(bean.getId_rigaDocumento());
}
rp = new ResParm(true);
long magPartenza = 0L;
long magArrivo = 0L;
long flgTipoMagFisicoPartenza = 0L;
long flgTipoMagFisicoArrivo = 0L;
long l_id_causalemagazzino = 0L;
if (bean.getFlgCodiceRiga() == 0L) {
l_id_causalemagazzino = bean.getDocumento().getTipoDocumento().getId_causaleMagazzino();
if (bean.getDocumento().getId_magFisicoPartenza() == 0L) {
if (bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoPartenza() > 0L) {
magPartenza = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoPartenza();
flgTipoMagFisicoPartenza = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getMagFisicoPartenza().getFlgTipo();
}
} else {
magPartenza = bean.getDocumento().getId_magFisicoPartenza();
flgTipoMagFisicoPartenza = bean.getDocumento().getMagFisicoPartenza().getFlgTipo();
}
if (bean.getDocumento().getId_magFisicoArrivo() == 0L) {
if (bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoArrivo() > 0L) {
magArrivo = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoArrivo();
flgTipoMagFisicoArrivo = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getMagFisicoArrivo().getFlgTipo();
}
} else {
magArrivo = bean.getDocumento().getId_magFisicoArrivo();
flgTipoMagFisicoArrivo = bean.getDocumento().getMagFisicoArrivo().getFlgTipo();
}
} else {
l_id_causalemagazzino = bean.getDocumento().getTipoDocumento().getId_causaleMagazzino2();
if (bean.getDocumento().getId_magFisicoPartenza2() == 0L) {
if (bean.getDocumento().getTipoDocumento().getCausaleMagazzino2().getId_magFisicoPartenza() > 0L) {
magPartenza = bean.getDocumento().getTipoDocumento().getCausaleMagazzino2().getId_magFisicoPartenza();
flgTipoMagFisicoPartenza = bean.getDocumento().getTipoDocumento().getCausaleMagazzino2().getMagFisicoPartenza().getFlgTipo();
}
} else {
magPartenza = bean.getDocumento().getId_magFisicoPartenza2();
flgTipoMagFisicoPartenza = bean.getDocumento().getMagFisicoPartenza2().getFlgTipo();
}
if (bean.getDocumento().getId_magFisicoArrivo2() == 0L) {
if (bean.getDocumento().getTipoDocumento().getCausaleMagazzino2().getId_magFisicoArrivo() > 0L) {
magArrivo = bean.getDocumento().getTipoDocumento().getCausaleMagazzino2().getId_magFisicoArrivo();
flgTipoMagFisicoArrivo = bean.getDocumento().getTipoDocumento().getCausaleMagazzino2().getMagFisicoArrivo().getFlgTipo();
}
} else {
magArrivo = bean.getDocumento().getId_magFisicoArrivo2();
flgTipoMagFisicoArrivo = bean.getDocumento().getMagFisicoArrivo2().getFlgTipo();
}
}
if (bean.getId_articoloFilatoColore() != 0L && bean.getArticoloFilatoColore().usaMagazzino() && (magArrivo > 0L || magPartenza > 0L)) {
if (magPartenza != 0L) {
long segnoMov = -1L;
if (bean.getFlgReso() == 1L)
segnoMov = 1L;
bean.setSegnoMov(segnoMov);
bean.setId_causaleMagazzino(l_id_causalemagazzino);
bean.setId_magFisico(magPartenza);
if (flgTipoMagFisicoPartenza == 1L) {
bean.setId_clifor(0L);
} else {
bean.setId_clifor(bean.getDocumento().getId_clifor());
}
rp = bean.superSave();
}
if (rp.getStatus() && magArrivo != 0L) {
long segnoMov = 1L;
if (bean.getFlgReso() == 1L)
segnoMov = -1L;
if (magPartenza == 0L) {
bean.setSegnoMov(segnoMov);
bean.setId_causaleMagazzino(l_id_causalemagazzino);
bean.setId_magFisico(magArrivo);
if (flgTipoMagFisicoArrivo == 1L) {
bean.setId_clifor(0L);
} else {
bean.setId_clifor(bean.getDocumento().getId_clifor());
}
rp = bean.superSave();
} else {
try {
RigaDocumento rd2 = (RigaDocumento)bean.clone();
rd2.setDBState(0);
rd2.setId_rigaDocumento(0L);
rd2.setId_rigaDocumentoMov(bean.getId_rigaDocumento());
rd2.setSegnoMov(segnoMov);
rd2.setId_magFisico(magArrivo);
if (flgTipoMagFisicoArrivo == 1L) {
rd2.setId_clifor(0L);
} else {
rd2.setId_clifor(bean.getDocumento().getId_clifor());
}
rd2.setId_rigaDocumentoMov(bean.getId_rigaDocumento());
rp = bean.superSave();
} catch (Exception e) {
bean.handleDebug(e, 0);
rp.setException(e);
}
}
}
} else {
bean.setId_clifor(0L);
rp = bean.superSave();
}
if (rp.getStatus()) {
rp.append(bean.getDocumento().save());
rp.append(bean.aggiornaCostoUltimoFornitore());
if (l_flgRigaPrelevata != bean.getFlgRigaPrelevata())
if (bean.getFlgRigaPrelevata() == 0L) {
if (bean.getDocumento().getFlgDocumentoPrelevato() == 1L)
bean.getDocumento().aggiornaFlgDocumentoPrelevato(0L);
} else {
bean.getDocumento().verificaEAggiornaFlgDocumentoPrelevato();
}
}
if (rp.getStatus())
if (bean.getId_articoloFilatoColore() > 0L) {
rp.setMsg(AbMessages.getMessage("SAVE_OK"));
bean.getArticoloFilatoColore().getArticoloFilato().setQuantitaCalcolate(false);
bean.getArticoloFilatoColore().getArticoloFilato().superSave();
bean.getArticoloFilatoColore().setQuantitaCalcolate(false);
bean.getArticoloFilatoColore().superSave();
} else {
rp.setMsg("Attenzione! Articolo non in anagrafica!");
}
return rp;
}
public long getFlgReso() {
return this.flgReso;
}
public void setFlgReso(long flgReso) {
this.flgReso = flgReso;
}
public Vectumerator findOrdini(DocumentoCR CR) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A, DOCUMENTO AS B, ARTICOLO AS C, TIPO AS D, CLIFOR as E ";
String s_Sql_Order = " order by B.progDocumento, A.descrizioneRiga , A.seriale ";
WcString wc = new WcString();
wc.addWc("A.id_documento=B.id_documento");
wc.addWc("A.id_articolo=C.id_articolo");
wc.addWc("C.id_tipo=D.id_tipo");
wc.addWc("B.id_clifor=E.id_clifor");
wc.addWc("B.id_tipoDocumento= " + CR.getId_tipoDocumento());
if (CR.getId_tipo() > 0L)
wc.addWc("(C.id_tipo=" + CR.getId_tipo() + " or D.indici like'%:" + CR.getId_tipo() + ":%')");
wc.addWc("(B.flgDocumentoPrelevato is null or B.flgDocumentoPrelevato =0) ");
wc.addWc("(A.flgRigaPrelevata is null or A.flgRigaPrelevata =0) ");
if (CR.getDataDocumentoDa() != null)
wc.addWc("B.dataDocumento>=?");
if (CR.getDataDocumentoA() != null)
wc.addWc("B.dataDocumento<=?");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
int dataCount = 1;
if (CR.getDataDocumentoDa() != null) {
stmt.setDate(dataCount, CR.getDataDocumentoDa());
dataCount++;
}
if (CR.getDataDocumentoA() != null) {
stmt.setDate(dataCount, CR.getDataDocumentoA());
dataCount++;
}
return findRows(stmt);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public long getFlgPrenotazioneArrivata() {
return this.flgPrenotazioneArrivata;
}
public void setFlgPrenotazioneArrivata(long flgPrenotazioneArrivata) {
this.flgPrenotazioneArrivata = flgPrenotazioneArrivata;
}
public boolean isAllRighePrenotazioneArrivateByDocumento(long l_id_documento) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
wc.addWc("(A.flgPrenotazioneArrivata is null or A.flgPrenotazioneArrivata=0)");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
Vectumerator vec = findRows(stmt, 1, 1);
if (vec.hasMoreElements())
return false;
return true;
} catch (Exception e) {
handleDebug(e, 0);
return false;
}
}
public double getQuantitaPrelevata() {
return this.quantitaPrelevata;
}
public ResParm creaCodaMessaggio(String theMsg) {
ResParm rp = new ResParm();
if (getId_documento() > 0L && getSeriale().length() == 10) {
MailMessage mm = new MailMessage(getApFull());
mm.setTextMessage(theMsg);
CodaMessaggi cm = new CodaMessaggi(getApFull());
cm.setDataCreazione(getToday());
cm.setCellulare(getSeriale());
cm.setTestoMessaggio(mm.getMessage());
cm.setFlgTipo(2L);
cm.setFlgStatoInvio(0L);
rp = cm.save();
}
return rp;
}
public ResParm creaCodaMessaggiSms(RigaDocumentoCR CR) {
ResParm rp = new ResParm();
Vectumerator vec = findByCR(CR, 0, 0);
int numMsg = 0;
while (vec.hasMoreElements()) {
RigaDocumento row = (RigaDocumento)vec.nextElement();
rp = row.creaCodaMessaggio(CR.getTestoMessaggio());
if (rp.getStatus())
numMsg++;
}
rp.setMsg("Numero messaggi in coda: " + numMsg);
return rp;
}
private void findCompattaByCRCreateStmtDate(RigaDocumentoCR CR, PreparedStatement stmt) {
try {
int dataCount = 0;
if (CR.getDataDocumentoDa() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataDocumentoDa());
}
if (CR.getDataDocumentoA() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataDocumentoA());
}
if (CR.getDataRiferimentoDa() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataRiferimentoDa());
}
if (CR.getDataRiferimentoA() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataRiferimentoA());
}
} catch (SQLException e) {
handleDebug(e);
}
}
private void findCompattaByCRCreateWC(RigaDocumentoCR CR, StringBuffer s_Sql_Find, WcString wc) {
wc.addWc("(B.flgHaDocumentoPadre is null or B.flgHaDocumentoPadre =0)");
wc.addWc("D.id_causaleMagazzino>0");
if (CR.getId_tipo() != 0L)
wc.addWc("(F.id_tipo=" + CR.getId_tipo() + " or F.indici like'%:" + CR.getId_tipo() + ":%')");
if (CR.getId_clifor() != 0L)
wc.addWc("B.id_clifor=" + CR.getId_clifor());
if (CR.getProgDocumento() != 0L)
wc.addWc("B.progDocumento =" + CR.getProgDocumento());
if (CR.getId_esercizio() != 0L)
wc.addWc("B.id_esercizio=" + CR.getId_esercizio());
if (CR.getId_tipoDocumento() != 0L)
wc.addWc("B.id_tipoDocumento=" + CR.getId_tipoDocumento());
if (CR.getId_articoloVariante() != 0L) {
wc.addWc("A.id_articoloVariante=" + CR.getId_articoloVariante());
} else if (CR.getId_articolo() != 0L) {
wc.addWc("A.id_articolo=" + CR.getId_articolo());
}
if (CR.getFlgTipoMovimento() == 1L) {
wc.addWc("(B.flgTipoMovimento=1 or B.flgTipoMovimento=3)");
} else if (CR.getFlgTipoMovimento() == 2L) {
wc.addWc("(B.flgTipoMovimento=2 or B.flgTipoMovimento=3)");
}
if (!CR.getSeriale().isEmpty()) {
String temp = CR.getSeriale();
temp = prepareInputMySqlString(temp, false);
temp = temp.replace("*", "%");
wc.addWc("A.seriale like '" + temp + "'");
}
if (CR.getDataDocumentoDa() != null)
wc.addWc("B.dataDocumento>=?");
if (CR.getDataDocumentoA() != null)
wc.addWc("B.dataDocumento<=?");
if (CR.getDataRiferimentoDa() != null)
wc.addWc("B.dataRiferimento>=?");
if (CR.getDataRiferimentoA() != null)
wc.addWc("B.dataRiferimento<=?");
}
private void creaFileCvs(Vectumerator list, RigaDocumentoCR CR) {
try {
CR.setFileName(getPathTmp() + "exportMovimenti_" + getPathTmp() + ".csv");
String theCvsFile = getDocBase() + getDocBase();
String SEP = ";";
new File(theCvsFile).delete();
FileWr outCvsFile = new FileWr(theCvsFile, false);
String s1 = "Numero;Intestazione;Data;Articolo;Disp.Art.;Tipo Movimento;Magazzini;Q.ta;Sconto;Tot.;IVA;Importo Doc;n.colli tot";
if (CR.getFlgTipoReport() >= 1L)
s1 = s1 + ";Q.tà variante";
if (CR.getFlgTipoReport() == 2L)
s1 = s1 + ";Q.tà seriale";
outCvsFile.writeLine(s1);
while (list.hasMoreElements()) {
RigaDocumento row = (RigaDocumento)list.nextElement();
s1 = " " + row.getDocumento().getNumeroDocumentoCompleto() + "\"" + SEP + row.getDocumento().getClifor().getDescrizioneCompleta() + SEP + getDataFormat().format(row.getDocumento().getDataDocumento()) + SEP + row.getDescrizioneRigaCompleta() + SEP + getNf().format(row.getArticolo().getQuantita()) + SEP + row.getDescrizioneTipoMovimento() + SEP + row.getDescrizioneMovimentoMagazzino() + SEP + row.getUdmQuantita() + SEP + getNf().format(row.getSconto()) + SEP + getNf().format(row.getTotImponibileRiga()) + SEP + row.getIva().getDescrizione() + SEP + getNf().format(row.getDocumento().getTotaleDocumento()) + SEP + getNf().format(row.getDocumento().getNColli());
s1 = s1.replace("&euro;", "");
outCvsFile.writeLine(s1);
}
outCvsFile.closeFile();
} catch (Exception e) {
handleDebug(e);
}
}
public String getSerialeSost() {
return (this.serialeSost == null) ? "" : this.serialeSost.trim();
}
public void setSerialeSost(String serialeSost) {
this.serialeSost = serialeSost;
}
public Documento getDocumentoPadre() {
this.documentoPadre = (Documento)getSecondaryObject(this.documentoPadre, Documento.class, getId_documentoPadre());
return this.documentoPadre;
}
public long getId_documentoPadre() {
return this.id_documentoPadre;
}
public void setDocumentoPadre(Documento newDocumentoPadre) {
this.documentoPadre = newDocumentoPadre;
}
public void setId_documentoPadre(long newId_documentoPadre) {
this.id_documentoPadre = newId_documentoPadre;
setDocumentoPadre(null);
}
public Vectumerator findByDocumentoDocumentoPadre(long l_id_documento, long l_id_documentoPadre, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A left join ARTICOLO AS B on A.id_articolo=B.id_articolo ";
String s_Sql_order = " order by A.id_rigaDocumento desc";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
wc.addWc("A.id_documentoPadre=" + l_id_documentoPadre);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return findRows(stmt, pageNumber, pageRows);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator<RigaDocumento> findByDocumentoPadre(long l_id_documentoPadre, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_order = " order by A.id_rigaDocumento desc";
WcString wc = new WcString();
wc.addWc("A.id_documentoPadre=" + l_id_documentoPadre);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return findRows(stmt, pageNumber, pageRows);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public void findRigaAnnodaturaByDocumentoPadre(long l_id_documentoPadre) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_order = " order by A.id_rigaDocumento desc";
WcString wc = new WcString();
wc.addWc("A.id_documentoPadre=" + l_id_documentoPadre);
wc.addWc("A.rifTipoArticolo=21");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
findFirstRecord(stmt);
} catch (Exception e) {
handleDebug(e, 0);
}
}
public void findRigaCatenaByDocumentoPadre(long l_id_documentoPadre) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_order = " order by A.id_rigaDocumento desc";
WcString wc = new WcString();
wc.addWc("A.id_documentoPadre=" + l_id_documentoPadre);
wc.addWc("A.rifTipoArticolo=22");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
findFirstRecord(stmt);
} catch (Exception e) {
handleDebug(e, 0);
}
}
public void findByCodicePezza(String l_codicePezza) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A inner join DOCUMENTO AS B ON A.id_documento=B.id_documento";
String s_Sql_order = " order by A.id_rigaDocumento desc";
WcString wc = new WcString();
String l_codicePezza_1 = l_codicePezza.substring(0, l_codicePezza.length() - 1);
wc.addWc("(A.codiceCartellinoStart<='" + l_codicePezza_1 + "' and A.codiceCartellinoStop>='" + l_codicePezza_1 + "' and B.flgBarcodeType=1) or (A.codiceCartellinoStart<='" + l_codicePezza + "' and A.codiceCartellinoStop>='" + l_codicePezza + "' and (B.flgBarcodeType!=1 or B.flgBarcodeType is null))");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
System.out.println(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
findFirstRecord(stmt);
} catch (Exception e) {
handleDebug(e, 0);
}
}
public Vectumerator<RigaDocumento> findCompattaByCR(RigaDocumentoCR CR, int pageNumber, int pageRows) {
boolean flgOttimizzo = true;
if (pageNumber == 0 && pageRows == 0)
flgOttimizzo = false;
StringBuffer s_Sql_Find = new StringBuffer("select A.* from RIGA_DOCUMENTO AS A inner join DOCUMENTO AS B on A.id_documento=B.id_documento LEFT JOIN DOCUMENTO AS C ON B.id_documentoFiglio=C.id_documento inner join TIPO_DOCUMENTO AS D\tON B.id_tipoDocumento=D.id_tipoDocumento");
String s_Sql_Order = " order by B.dataDocumento desc, B.progDocumento desc ";
if (CR.getFlgOrderBy() == 9L)
s_Sql_Order = " order by T.descrizione , E.nome ";
WcString wc = new WcString();
if (CR.getId_tipo() != 0L || CR.getFlgOrderBy() == 9L) {
s_Sql_Find.append(", ARTICOLO AS E, TIPO AS F");
wc.addWc("A.id_articolo=E.id_articolo");
wc.addWc("E.id_tipo=F.id_tipo");
}
if (CR.getFlgOrderBy() == 9L) {
s_Sql_Find.append(", TIPO AS T");
wc.addWc("E.id_tipo=T.id_tipo");
}
findCompattaByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt;
if ((pageNumber == 0 && pageRows == 0) || !flgOttimizzo) {
stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString());
} else {
if (pageNumber == 0)
pageNumber = 1;
int start = (pageNumber - 1) * pageRows;
int stop = start + pageRows;
stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString() + " limit " + s_Sql_Order + "," + start);
}
findCompattaByCRCreateStmtDate(CR, stmt);
if ((pageNumber == 0 && pageRows == 0) || !flgOttimizzo) {
Vectumerator<RigaDocumento> vectumerator = findRows(stmt, pageNumber, pageRows);
if (!CR.getFlgReport().isEmpty())
if (CR.getFlgOrderBy() == 9L) {
creaFileCvsTipoArticolo(vectumerator, CR);
} else {
creaFileCvs(vectumerator, CR);
}
return vectumerator;
}
Vectumerator<RigaDocumento> vec = findRows(stmt, 1, pageRows);
vec.setPageNumber(pageNumber);
vec.setTotNumberOfRecords(findCompattaByCRTotRecord(CR));
if (!CR.getFlgReport().isEmpty())
if (CR.getFlgOrderBy() == 9L) {
creaFileCvsTipoArticolo(vec, CR);
} else {
creaFileCvs(vec, CR);
}
return vec;
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
private int findCompattaByCRTotRecord(RigaDocumentoCR CR) {
StringBuffer s_Sql_Find = new StringBuffer("select count(A.id_rigaDocumento) as tot from RIGA_DOCUMENTO AS A inner join DOCUMENTO AS B on A.id_documento=B.id_documento LEFT JOIN DOCUMENTO AS C ON B.id_documentoFiglio=C.id_documento inner join TIPO_DOCUMENTO AS D\tON B.id_tipoDocumento=D.id_tipoDocumento");
WcString wc = new WcString();
if (CR.getId_tipo() != 0L || CR.getFlgOrderBy() == 9L) {
s_Sql_Find.append(", ARTICOLO AS E, TIPO AS F");
wc.addWc("A.id_articolo=E.id_articolo");
wc.addWc("E.id_tipo=F.id_tipo");
}
findCompattaByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find));
findByCRCreateStmtDate(CR, stmt);
return (int)getTots(stmt);
} catch (Exception e) {
handleDebug(e);
return 0;
}
}
private void creaFileCvsTipoArticolo(Vectumerator list, RigaDocumentoCR CR) {
try {
CR.setFileName(getPathTmp() + "exportMovimenti_" + getPathTmp() + ".csv");
String theCvsFile = getDocBase() + getDocBase();
String SEP = ";";
new File(theCvsFile).delete();
FileWr outCvsFile = new FileWr(theCvsFile, false);
String s1 = "Numero;Intestazione;Data;Riferimento;Tipo;Articolo;Tipo Movimento;Q.ta;Sconto;Imp. Riga;IVA;Importo Doc.";
if (CR.getFlgTipoReport() >= 1L)
s1 = s1 + ";Q.tà variante";
if (CR.getFlgTipoReport() == 2L)
s1 = s1 + ";Q.tà seriale";
outCvsFile.writeLine(s1);
long l_id_currentArticolo = 0L;
DoubleOperator totQta = new DoubleOperator();
while (list.hasMoreElements()) {
RigaDocumento row = (RigaDocumento)list.nextElement();
if (l_id_currentArticolo != row.getId_articolo()) {
if (l_id_currentArticolo != 0L) {
s1 = ";;;;;;;" + getNf().format(totQta.getResult());
totQta = new DoubleOperator();
outCvsFile.writeLine(s1);
}
l_id_currentArticolo = row.getId_articolo();
}
totQta.add(row.getQuantita());
s1 = " " + row.getDocumento().getNumeroDocumentoCompleto() + "\"" + SEP + row.getDocumento().getClifor().getDescrizioneCompleta() + SEP + getDataFormat().format(row.getDocumento().getDataDocumento()) + SEP + row.getDocumento().getRiferimento() + " " + getDataFormat().format(row.getDocumento().getDataRiferimento()) + SEP + row.getArticolo().getTipo().getDescrizione() + SEP + row.getArticolo().getNome() + SEP + row.getDescrizioneTipoMovimento() + SEP + getNf().format(row.getQuantita()) + SEP + getNf().format(row.getSconto()) + SEP + getNf().format(row.getTotImponibileRiga()) + SEP + row.getIva().getDescrizione() + SEP + getNf().format(row.getDocumento().getTotaleDocumento()) + SEP;
s1 = s1.replace("&euro;", "");
outCvsFile.writeLine(s1);
}
s1 = ";;;;;;;" + getNf().format(totQta.getResult());
outCvsFile.writeLine(s1);
outCvsFile.closeFile();
} catch (Exception e) {
handleDebug(e);
}
}
public long getOrdineRiga() {
return this.ordineRiga;
}
public void setOrdineRiga(long ordineRiga) {
this.ordineRiga = ordineRiga;
}
public double getQuantitaImpegnataByArticoloVariante(long l_id_articoloVariante) {
RigaDocumentoCR CR = new RigaDocumentoCR(getApFull());
RigaDocumento bean = new RigaDocumento(getApFull());
CR.setFlgTipologia(4L);
CR.setFlgRigaPrelevata(0L);
CR.setFlgStatoPrenotazione(200L);
CR.setId_articoloVariante(l_id_articoloVariante);
CR.setFlgTipoRicerca(0L);
Vectumerator vec = bean.findByCR(CR, 0, 0);
DoubleOperator dop = new DoubleOperator();
while (vec.hasMoreElements()) {
RigaDocumento row = (RigaDocumento)vec.nextElement();
dop.add(row.getQuantita());
dop.subtract(row.getQuantitaPrelevata());
}
return dop.getResult();
}
public double getQuantitaImpegnataByArticoloTaglia(long l_id_articoloTaglia) {
RigaDocumentoCR CR = new RigaDocumentoCR(getApFull());
RigaDocumento bean = new RigaDocumento(getApFull());
CR.setFlgTipologia(4L);
CR.setFlgRigaPrelevata(0L);
CR.setFlgStatoPrenotazione(200L);
CR.setId_articoloTaglia(l_id_articoloTaglia);
CR.setFlgTipoRicerca(0L);
Vectumerator vec = bean.findByCR(CR, 0, 0);
DoubleOperator dop = new DoubleOperator();
while (vec.hasMoreElements()) {
RigaDocumento row = (RigaDocumento)vec.nextElement();
dop.add(row.getQuantita());
dop.subtract(row.getQuantitaPrelevata());
}
return dop.getResult();
}
public double getQuantitaInArrivoByArticoloVariante(ArticoloVariante av) {
MagFisico mf = new MagFisico(getApFull());
mf.findMagazzinoOrdinato();
if (mf.getId_magFisico() > 0L) {
RigaDocumento rd = new RigaDocumento(getApFull());
rd.findMagDisponibilitaPuntuale(av.getId_articolo(), av.getId_articoloVariante(), 0L, null, mf.getId_magFisico(), 0L, 0L);
return rd.getQuantita();
}
return 0.0D;
}
public double getQuantitaInArrivoByArticoloTaglia(ArticoloTaglia at) {
MagFisico mf = new MagFisico(getApFull());
mf.findMagazzinoOrdinato();
if (mf.getId_magFisico() > 0L) {
RigaDocumento rd = new RigaDocumento(getApFull());
rd.findMagDisponibilitaPuntuale(at.getId_articolo(), at.getId_articoloVariante(), at.getId_articoloTaglia(), null,
mf.getId_magFisico(), 0L, 0L);
return rd.getQuantita();
}
return 0.0D;
}
public double getQuantitaInArrivoByArticoloVarianteM(ArticoloVariante av) {
MagFisico mf = new MagFisico(getApFull());
mf.findMagazzinoOrdinato();
Movimento mov = new Movimento(getApFull());
mov.findDisponibilitaPuntuale(av.getId_articolo(), av.getId_articoloVariante(), 0L, null, mf.getId_magFisico(), 0L);
return mov.getQuantita();
}
public String getNotaBarcode() {
return (this.notaBarcode == null) ? "" : this.notaBarcode;
}
public void setNotaBarcode(String notaBarcode) {
this.notaBarcode = notaBarcode;
}
public boolean hasNote() {
if (getNotaBarcode().isEmpty() && getNotaRigaDocumento().isEmpty())
return false;
return true;
}
public long getFlgIgnoraPrenotazione() {
return this.flgIgnoraPrenotazione;
}
public void setFlgIgnoraPrenotazione(long flgIgnoraPrenotazione) {
this.flgIgnoraPrenotazione = flgIgnoraPrenotazione;
}
public Vectumerator<RigaDocumento> findRigheSenzaTelaioByDocumento(long l_id_documento) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A inner join DOCUMENTO AS B ON A.id_documento=B.id_documento";
String s_Sql_order = "";
WcString wc = new WcString();
wc.addWc("B.flgStato =1");
wc.addWc("B.id_documento =" + l_id_documento);
wc.addWc("(A.id_telaio is null or A.id_telaio=0)");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return findRows(stmt);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator<RigaDocumento> findRigheConTelaioByDocumento(long l_id_documento) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A inner join DOCUMENTO AS B ON A.id_documento=B.id_documento";
String s_Sql_order = "";
WcString wc = new WcString();
wc.addWc("B.flgStato =1");
wc.addWc("B.id_documento =" + l_id_documento);
wc.addWc("A.id_telaio >0");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return findRows(stmt);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public double getTotArticoliImpegnati(long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia) {
String s_Sql_Find = "select sum(A.quantita) as _sum from RIGA_DOCUMENTO AS A , DOCUMENTO AS B, TIPO_DOCUMENTO AS C";
String s_Sql_order = "";
WcString wc = new WcString();
wc.addWc("A.id_documento=B.id_documento");
wc.addWc("B.id_tipoDocumento=C.id_tipoDocumento");
wc.addWc("C.flgTipologia =4");
wc.addWc("B.flgStato =1");
wc.addWc("(B.flgStatoPrenotazione is null or B.flgStatoPrenotazione <90)");
wc.addWc("A.flgRigaPrelevata !=1");
wc.addWc("A.id_articolo=" + l_id_articolo);
if (l_id_articoloVariante == 0L) {
wc.addWc("(A.id_articoloVariante is null or A.id_articoloVariante=0)");
} else if (l_id_articoloVariante > 0L) {
wc.addWc("A.id_articoloVariante=" + l_id_articoloVariante);
}
if (l_id_articoloTaglia == 0L) {
wc.addWc("(A.id_articoloTaglia is null or A.id_articoloTaglia=0)");
} else if (l_id_articoloTaglia > 0L) {
wc.addWc("A.id_articoloTaglia=" + l_id_articoloTaglia);
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return getSum(stmt);
} catch (Exception e) {
handleDebug(e, 0);
return 0.0D;
}
}
public double getTotFilatiImpegnati(long l_id_articoloFilatoColore, long l_id_articoloFilato, long l_id_coloreFilato, String l_seriale) {
return 0.0D;
}
public long getId_rigaDocumentoPadre() {
return this.id_rigaDocumentoPadre;
}
public void setId_rigaDocumentoPadre(long id_rigaDocumentoPadre) {
this.id_rigaDocumentoPadre = id_rigaDocumentoPadre;
}
public double getQuantita() {
if (getParm("USA_MAGAZZINO").isFalse()) {
long l_flgUdm = getFlgUdm();
if (l_flgUdm == 1L)
return getNr();
if (l_flgUdm == 3L)
return getMt();
if (l_flgUdm == 2L)
return getKg();
return getNr();
}
return this.quantita;
}
public long findRigheDaPrelevareByDocumento(long l_documento) {
String s_Sql_Find = "select COUNT(*) AS _count from RIGA_DOCUMENTO AS A ";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_documento);
wc.addWc("A.flgRigaPrelevata=0");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
return getCount(stmt, "_count");
} catch (Exception e) {
handleDebug(e, 0);
return 0L;
}
}
public double getImportoSconto() {
if (getSconto() == 0.0D && getPercL1() == 0.0D && getPercL2() == 0.0D && getPercL3() == 0.0D)
return 0.0D;
if (getSconto() > 0.0D) {
DoubleOperator doubleOperator = new DoubleOperator(getImporto());
doubleOperator.setScale(4, 5);
doubleOperator.multiply(getSconto());
doubleOperator.divide(100.0F);
doubleOperator.setScale(2, 5);
return doubleOperator.getResult();
}
DoubleOperator temp = new DoubleOperator(getImporto());
temp.setScale(4, 5);
DoubleOperator sconto = new DoubleOperator();
sconto.setScale(4, 5);
if (getPercL1() > 0.0D) {
temp.multiply(getPercL1());
temp.divide(100.0F);
sconto.add(temp.getResult());
}
if (getPercL2() > 0.0D) {
temp = new DoubleOperator(getImporto());
temp.subtract(sconto);
temp.multiply(getPercL2());
temp.divide(100.0F);
sconto.add(temp.getResult());
}
if (getPercL3() > 0.0D) {
temp = new DoubleOperator(getImporto());
temp.subtract(sconto);
temp.multiply(getPercL3());
temp.divide(100.0F);
sconto.add(temp.getResult());
}
sconto.setScale(2, 5);
return sconto.getResult();
}
public void findFirstByDocumentoArticoloTaglia(long l_id_documento, long l_id_articoloTaglia) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_order = "";
String wc = "";
wc = buildWc(wc, "A.id_documento=" + l_id_documento);
wc = buildWc(wc, "A.id_articoloTaglia=" + l_id_articoloTaglia);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc);
findFirstRecord(stmt);
} catch (Exception e) {
handleDebug(e, 0);
}
}
private static synchronized ResParm delRigaDocumentoPM(RigaDocumento rd, RigaDocumentoPM row) {
RigaDocumentoPM bean = new RigaDocumentoPM(rd.getApFull());
RigaDocumentoPMKey theKey = new RigaDocumentoPMKey(row.getId_rigaDocumento(), row.getId_rigaDocumentoPrelevata());
bean.findByPrimaryKey(theKey);
return bean.delete();
}
private static synchronized ResParm addRigaDocumentoPM(RigaDocumento rd, RigaDocumentoPM row) {
RigaDocumentoPM bean = new RigaDocumentoPM(rd.getApFull());
RigaDocumentoPMKey theKey = new RigaDocumentoPMKey(row.getId_rigaDocumento(), row.getId_rigaDocumentoPrelevata());
bean.findByPrimaryKey(theKey);
if (bean != null) {
row.setDBState(bean.getDBState());
} else {
row.setDBState(0);
}
ResParm rp = row.save();
return rp;
}
private long checkStatoRiga() {
long retVal = 0L;
DoubleOperator qtaEffettiva = new DoubleOperator();
DoubleOperator qtaMagazzino = new DoubleOperator();
if (getQuantita() > 0.0D)
if (getFlgRigaPrelevata() == 1L) {
retVal = 40L;
} else if (getId_articolo() != 0L || getId_articoloVariante() != 0L) {
if (!getSeriale().isEmpty()) {
retVal = 30L;
} else {
RigaDocumentoCR CR = new RigaDocumentoCR();
CR.setFlgTipologia(4L);
CR.setFlgStatoPrenotazione(200L);
CR.setId_articolo(getId_articolo());
CR.setId_articoloVariante(getId_articoloVariante());
CR.setFlgTipoRicerca(0L);
CR.setFlgOrderBy(5L);
CR.setFlgRigaPrelevata(0L);
if (getId_articoloVariante() != 0L) {
qtaEffettiva.add(getArticoloVariante().getQuantitaInArrivoAv());
qtaEffettiva.add(getArticoloVariante().getQuantitaAv());
qtaMagazzino.add(getArticoloVariante().getQuantitaAv());
} else if (getId_articolo() != 0L) {
qtaEffettiva.add(getArticolo().getQuantitaInArrivo());
qtaEffettiva.add(getArticolo().getQuantita());
qtaMagazzino.add(getArticolo().getQuantita());
}
CR.setFlgNoSeriale(2L);
double qtAssociata = getRigheAssociateSeriali(CR);
double qtMagazzino = getQtaPrelevataPrenotazioni();
qtaEffettiva.subtract(qtAssociata);
qtaEffettiva.subtract(getQtaOrdiniApertiPrenotazioni());
qtaEffettiva.subtract(qtMagazzino);
qtaMagazzino.subtract(qtMagazzino);
qtaMagazzino.subtract(qtAssociata);
if (qtaEffettiva.getResult() >= 0.0D) {
CR.setFlgNoSeriale(1L);
Vectumerator vec = findByCR(CR, 0, 0);
while (vec.hasMoreElements()) {
RigaDocumento row = (RigaDocumento)vec.nextElement();
double[] res = row.getQtaOrdinataPrelevataByRigaPrenotazione();
double qtOrd = res[0];
double qtPrel = res[1];
double qtPrenoParziale = row.getQuantita();
if (qtPrel >= qtPrenoParziale) {
retVal = 30L;
qtPrenoParziale = 0.0D;
} else if (qtPrel > 0.0D) {
retVal = 20L;
DoubleOperator dop = new DoubleOperator(qtPrenoParziale);
dop.subtract(qtPrel);
qtPrenoParziale = dop.getResult();
} else if (qtOrd >= qtPrenoParziale) {
retVal = 10L;
qtPrenoParziale = 0.0D;
} else if (qtOrd > 0.0D) {
retVal = 15L;
DoubleOperator dop = new DoubleOperator(qtPrenoParziale);
dop.subtract(qtOrd);
qtPrenoParziale = dop.getResult();
}
if (row.getId_rigaDocumento() == getId_rigaDocumento()) {
if (retVal == 30L || retVal == 10L)
break;
if (qtaMagazzino.getResult() >= qtPrenoParziale) {
if (retVal == 15L || retVal == 10L) {
retVal = 20L;
break;
}
retVal = 30L;
break;
}
if (qtaMagazzino.getResult() > 0.0D) {
retVal = 20L;
break;
}
if (qtaEffettiva.getResult() >= qtPrenoParziale) {
retVal = 10L;
break;
}
if (qtaEffettiva.getResult() > 0.0D) {
retVal = 15L;
break;
}
break;
}
qtaEffettiva.subtract(qtPrenoParziale);
qtaMagazzino.subtract(qtPrenoParziale);
retVal = 0L;
}
}
}
}
return retVal;
}
public void checkStatoPrenotazione() {
Vectumerator vecDoc = findPrenotazioniAperteArrivate(getId_articolo(), getId_articoloVariante());
while (vecDoc.hasMoreElements()) {
RigaDocumento rdoc = (RigaDocumento)vecDoc.nextElement();
ResParm resParm = rdoc.getDocumento().checkStatoPrenotazioneByDocumento();
}
getArticolo().resetCalcoloQuantita();
}
public Vectumerator findPrenotazioniAperteArrivate(long l_id_articolo, long l_id_articoloVariante) {
StringBuffer s_Sql_Find = new StringBuffer("select A.* from DOCUMENTO AS A, RIGA_DOCUMENTO AS B ");
WcString wc = new WcString();
wc.addWc(" A.id_documento = B.id_documento ");
wc.addWc(" B.id_articolo = " + l_id_articolo);
if (l_id_articoloVariante == 0L) {
wc.addWc(" (B.id_articoloVariante =0 or B.id_articoloVariante is null) ");
} else {
wc.addWc(" B.id_articoloVariante = " + l_id_articoloVariante);
}
wc.addWc(" A.id_tipoDocumento = " + getParm("ID_DOC_PRENOTAZIONE").getNumeroLong());
wc.addWc(" (A.flgStatoPrenotazione=200 OR A.flgStatoPrenotazione=20 OR A.flgStatoPrenotazione=0 OR A.flgStatoPrenotazione=10 OR A.flgStatoPrenotazione IS NULL)");
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find));
return findRows(stmt);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public String getStatoRiga(long l_stato) {
String ret = "";
if (l_stato == 0L) {
ret = "Da ordinare";
} else if (l_stato == 15L) {
ret = "Ordinato Parziale";
} else if (l_stato == 10L) {
ret = "Ordinato";
} else if (l_stato == 20L) {
ret = "Arrivato Parziale";
} else if (l_stato == 30L) {
ret = "Arrivato";
} else if (l_stato == 40L) {
ret = "Chiuso";
}
return ret;
}
@Deprecated
private double getQuantitaByCR(RigaDocumentoCR CR) {
String s_Sql_Find = "SELECT Sum(A.quantita-A.quantitaPrelevata) AS _sum FROM RIGA_DOCUMENTO as A, DOCUMENTO AS B, TIPO_DOCUMENTO AS C";
String s_Sql_Order = " ";
WcString wc = new WcString();
wc.addWc("A.id_documento=B.id_documento");
wc.addWc("B.id_tipoDocumento=C.id_tipoDocumento");
if (CR.getId_articolo() != 0L)
wc.addWc("A.id_articolo=" + CR.getId_articolo());
wc.addWc("B.id_articolo=" + CR.getId_articolo());
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
double res = getSum(stmt);
return res;
} catch (SQLException e) {
handleDebug(e);
return 0.0D;
}
}
public long checkStatoRigaOld() {
long retVal = -1L;
DoubleOperator qtaEffettiva = new DoubleOperator();
DoubleOperator qtaOrdiniAssociati = new DoubleOperator();
DoubleOperator qtaMagazzino = new DoubleOperator();
if (getId_articolo() != 0L || getId_articoloVariante() != 0L) {
if (!getSeriale().isEmpty()) {
retVal = 30L;
} else {
RigaDocumentoPM rdpm = new RigaDocumentoPM(getApFull());
rdpm.findByRigaDocumentoPrelevata(getId_rigaDocumento());
if (rdpm.getDBState() == 1) {
RigaDocumento rd = rdpm.getRigaDocumento();
if (rd.getFlgRigaPrelevata() == 1L) {
if (getQuantita() == rd.getQuantita()) {
retVal = 30L;
} else {
retVal = 20L;
}
qtaOrdiniAssociati.add(rd.getQuantita());
} else {
retVal = 10L;
}
} else {
retVal = 0L;
}
}
if (retVal == 0L) {
if (getId_articoloVariante() != 0L) {
qtaEffettiva.add(getArticoloVariante().getQuantitaInArrivoAv());
qtaEffettiva.add(getArticoloVariante().getQuantitaAv());
qtaMagazzino.add(getArticoloVariante().getQuantitaAv());
} else if (getId_articolo() != 0L) {
qtaEffettiva.add(getArticolo().getQuantitaInArrivo());
qtaEffettiva.add(getArticolo().getQuantita());
qtaMagazzino.add(getArticolo().getQuantita());
}
qtaEffettiva.subtract(qtaOrdiniAssociati.getResult());
if (qtaEffettiva.getResult() > 0.0D) {
RigaDocumentoCR CR = new RigaDocumentoCR();
CR.setFlgTipologia(4L);
CR.setFlgStatoPrenotazione(200L);
CR.setId_articolo(getId_articolo());
CR.setId_articoloVariante(getId_articoloVariante());
CR.setFlgTipoRicerca(0L);
CR.setFlgOrderBy(5L);
CR.setFlgRicercaNonOrdinati(true);
Vectumerator vec = findByCR(CR, 0, 0);
while (vec.hasMoreElements()) {
RigaDocumento row = (RigaDocumento)vec.nextElement();
if (row.getId_rigaDocumento() == getId_rigaDocumento()) {
if (qtaMagazzino.getResult() >= getQuantita()) {
retVal = 30L;
break;
}
if (qtaMagazzino.getResult() > 0.0D) {
retVal = 20L;
break;
}
if (qtaEffettiva.getResult() >= getQuantita()) {
retVal = 10L;
break;
}
if (qtaEffettiva.getResult() > 0.0D) {
retVal = 15L;
break;
}
break;
}
qtaEffettiva.subtract(row.getQuantita());
qtaMagazzino.subtract(row.getQuantita());
}
}
}
}
return retVal;
}
public double getQtaPrelevataPrenotazioni() {
String s_Sql_Find = "select SUM(Z.quantitaPrelevata) AS _sum FROM RIGA_DOCUMENTO AS Z INNER JOIN DOCUMENTO AS B ON Z.id_documento = B.id_documento INNER JOIN RIGA_DOCUMENTO_P_M AS C ON Z.id_rigaDocumento = C.id_rigaDocumento ";
String s_Sql_Find1 = " SELECT A.id_rigaDocumento FROM RIGA_DOCUMENTO AS A INNER JOIN DOCUMENTO AS B ON A.id_documento = B.id_documento INNER JOIN RIGA_DOCUMENTO_P_M AS C ON A.id_rigaDocumento = C.id_rigaDocumentoPrelevata ";
WcString wc = new WcString();
wc.addWc(" B.id_tipoDocumento = " + getParm("ID_DOC_ORDINE").getNumeroLong());
wc.addWc(" Z.id_articolo = " + getId_articolo());
if (getId_articoloVariante() != 0L) {
wc.addWc(" Z.id_articoloVariante = " + getId_articoloVariante());
} else {
wc.addWc(" (Z.id_articoloVariante = 0 OR Z.id_articoloVariante IS NULL)");
}
WcString wc1 = new WcString();
wc1.addWc(" B.id_tipoDocumento = " + getParm("ID_DOC_PRENOTAZIONE").getNumeroLong());
wc1.addWc(" A.id_articolo = " + getId_articolo());
if (getId_articoloVariante() != 0L) {
wc1.addWc(" A.id_articoloVariante = " + getId_articoloVariante());
} else {
wc1.addWc(" (A.id_articoloVariante = 0 OR A.id_articoloVariante IS NULL)");
}
wc1.addWc(" (B.flgStatoPrenotazione = 0 OR B.flgStatoPrenotazione = 200 OR B.flgStatoPrenotazione = 20 OR B.flgStatoPrenotazione = 10 OR B.flgStatoPrenotazione IS NULL)");
wc1.addWc("(A.flgRigaPrelevata is null or A.flgRigaPrelevata=0)");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + " AND C.id_rigaDocumentoPrelevata IN (" +
wc.toString() + s_Sql_Find1 + ")");
return getSum(stmt);
} catch (SQLException e) {
handleDebug(e);
return 0.0D;
}
}
public double getQtaOrdiniApertiPrenotazioni() {
String s_Sql_Find = "select SUM(Z.quantita - Z.quantitaPrelevata) AS _sum FROM RIGA_DOCUMENTO AS Z INNER JOIN DOCUMENTO AS B ON Z.id_documento = B.id_documento INNER JOIN RIGA_DOCUMENTO_P_M AS C ON Z.id_rigaDocumento = C.id_rigaDocumento ";
String s_Sql_Find1 = " SELECT A.id_rigaDocumento FROM RIGA_DOCUMENTO AS A INNER JOIN DOCUMENTO AS B ON A.id_documento = B.id_documento INNER JOIN RIGA_DOCUMENTO_P_M AS C ON A.id_rigaDocumento = C.id_rigaDocumentoPrelevata ";
WcString wc = new WcString();
wc.addWc(" B.id_tipoDocumento = " + getParm("ID_DOC_ORDINE").getNumeroLong());
wc.addWc(" Z.id_articolo = " + getId_articolo());
if (getId_articoloVariante() != 0L) {
wc.addWc(" Z.id_articoloVariante = " + getId_articoloVariante());
} else {
wc.addWc(" (Z.id_articoloVariante = 0 OR Z.id_articoloVariante IS NULL)");
}
WcString wc1 = new WcString();
wc1.addWc(" B.id_tipoDocumento = " + getParm("ID_DOC_PRENOTAZIONE").getNumeroLong());
wc1.addWc(" A.id_articolo = " + getId_articolo());
if (getId_articoloVariante() != 0L) {
wc1.addWc(" A.id_articoloVariante = " + getId_articoloVariante());
} else {
wc1.addWc(" (A.id_articoloVariante = 0 OR A.id_articoloVariante IS NULL)");
}
wc1.addWc(" (B.flgStatoPrenotazione = 0 OR B.flgStatoPrenotazione = 200 OR B.flgStatoPrenotazione = 20 OR B.flgStatoPrenotazione = 10 OR B.flgStatoPrenotazione IS NULL)");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + " AND C.id_rigaDocumentoPrelevata IN (" +
wc.toString() + s_Sql_Find1 + ")");
return getSum(stmt);
} catch (SQLException e) {
handleDebug(e);
return 0.0D;
}
}
public boolean hasQtaOrdinata() {
if (getDocumento().getTipoDocumento().getFlgTipologia() == 4L) {
double[] res = getQtaOrdinataPrelevataByRigaPrenotazione();
double qtOrd = res[0];
if (qtOrd > 0.0D)
return true;
return false;
}
return false;
}
public Documento getDocumentoPrenotazione() {
if (getId_rigaDocumento() != 0L && getDocumento().getTipoDocumento().getFlgTipologia() == 3L) {
RigaDocumentoPM rdPm = new RigaDocumentoPM(getApFull());
rdPm.findByRigaDocumento(getId_rigaDocumento());
return rdPm.getRigaDocumentoPrelevata().getDocumento();
}
return new Documento(getApFull());
}
public double getKg() {
return this.kg;
}
public void setKg(double kg) {
this.kg = kg;
}
public double getMt() {
return this.mt;
}
public void setMt(double mt) {
this.mt = mt;
}
public double getNr() {
return this.nr;
}
public void setNr(double nr) {
this.nr = nr;
}
public static synchronized ResParm aggiornaMovimento(RigaDocumento bean) {
ResParm rp = new ResParm(true);
if (bean.getArticolo().getTipo().getFlgTipoMagazzino() == 0L ||
bean.getArticolo().getTipo().getFlgTipoMagazzino() == 9L)
return rp;
if (bean.getId_articolo() != 0L) {
long magPartenza = 0L;
long magArrivo = 0L;
long flgInternoPartenza = 0L;
long flgInternoArrivo = 0L;
if (bean.getDocumento().getId_magFisicoPartenza() == 0L) {
if (bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoPartenza() > 0L) {
magPartenza = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoPartenza();
flgInternoPartenza = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getMagFisicoPartenza().getFlgTipo();
}
} else {
magPartenza = bean.getDocumento().getId_magFisicoPartenza();
flgInternoPartenza = bean.getDocumento().getMagFisicoPartenza().getFlgTipo();
}
if (bean.getDocumento().getId_magFisicoArrivo() == 0L) {
if (bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoArrivo() > 0L) {
magArrivo = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoArrivo();
flgInternoArrivo = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getMagFisicoArrivo().getFlgTipo();
}
} else {
magArrivo = bean.getDocumento().getId_magFisicoArrivo();
flgInternoArrivo = bean.getDocumento().getMagFisicoArrivo().getFlgTipo();
}
cancellaMovimento(bean, magPartenza, magArrivo);
if (magPartenza != 0L || magArrivo != 0L)
Movimento movimento = new Movimento(bean.getApFull());
if (magPartenza != 0L) {
Movimento mov = new Movimento(bean.getApFull());
mov.setId_rigaDocumento(bean.getId_rigaDocumento());
mov.setId_articolo(bean.getId_articolo());
mov.setId_articoloVariante(bean.getId_articoloVariante());
mov.setId_articoloTaglia(bean.getId_articoloTaglia());
mov.setSeriale(bean.getSeriale());
mov.setId_causaleMagazzino(bean.getDocumento().getTipoDocumento().getId_causaleMagazzino());
if (bean.getFlgReso() == 1L) {
mov.setKg(bean.getKg());
mov.setMt(bean.getMt());
mov.setNr(bean.getNr());
} else {
mov.setKg(-1.0D * bean.getKg());
mov.setMt(-1.0D * bean.getMt());
mov.setNr(-1.0D * bean.getNr());
}
mov.setId_magFisico(magPartenza);
if (flgInternoPartenza == 1L) {
mov.setId_clifor(0L);
} else {
mov.setId_clifor(bean.getDocumento().getId_clifor());
}
rp = mov.save();
}
if (magArrivo != 0L) {
Movimento mov = new Movimento(bean.getApFull());
mov.setId_rigaDocumento(bean.getId_rigaDocumento());
mov.setId_articolo(bean.getId_articolo());
mov.setId_articoloVariante(bean.getId_articoloVariante());
mov.setId_articoloTaglia(bean.getId_articoloTaglia());
mov.setSeriale(bean.getSeriale());
mov.setId_causaleMagazzino(bean.getDocumento().getTipoDocumento().getId_causaleMagazzino());
if (bean.getFlgReso() == 0L) {
mov.setKg(bean.getKg());
mov.setMt(bean.getMt());
mov.setNr(bean.getNr());
} else {
mov.setKg(-1.0D * bean.getKg());
mov.setMt(-1.0D * bean.getMt());
mov.setNr(-1.0D * bean.getNr());
}
mov.setId_magFisico(magArrivo);
if (flgInternoArrivo == 1L) {
mov.setId_clifor(0L);
} else {
mov.setId_clifor(bean.getDocumento().getId_clifor());
}
rp.append(mov.save());
}
}
return rp;
}
public static synchronized ResParm cancellaMovimento(RigaDocumento bean, long l_id_magazzinoPartenza, long l_id_magazzinoArrivo) {
ResParm rp = new ResParm(true);
Movimento mov = new Movimento(bean.getApFull());
Vectumerator vec = mov.findByRigaDocumento(bean.getId_rigaDocumento());
if (l_id_magazzinoPartenza == 0L && l_id_magazzinoArrivo == 0L) {
while (vec.hasMoreElements()) {
mov = (Movimento)vec.nextElement();
rp.append(mov.delete());
}
} else {
while (vec.hasMoreElements()) {
mov = (Movimento)vec.nextElement();
if (mov.getId_magFisico() == l_id_magazzinoPartenza || mov.getId_magFisico() == l_id_magazzinoArrivo)
rp.append(mov.delete());
}
}
return rp;
}
public double getQuantitaTotaleByDocumento(long l_id_documento) {
String s_Sql_Find = "select sum(quantita) AS _sum from RIGA_DOCUMENTO AS A";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
return getSum(stmt);
} catch (SQLException e) {
handleDebug(e);
return 0.0D;
}
}
public String getQuantitaMagazzinoMovimentoHtml() {
if (getId_articoloVariante() > 0L)
return getArticoloVariante().getQuantitaMagazzinoMovimentoHtml();
if (getId_articolo() > 0L)
return getArticolo().getQuantitaMagazzinoMovimentoHtml();
if (getId_articoloFilatoColore() > 0L)
return getArticoloFilatoColore().getQuantitaMagazzinoMovimentoHtml();
if (getId_articoloTessutoColore() > 0L)
return getArticoloTessutoColore().getQuantitaMagazzinoMovimentoHtml();
if (getId_articoloTessuto() > 0L)
return getArticoloTessuto().getQuantitaMagazzinoMovimentoHtml();
return "";
}
public double getQuantitaEffettiva() {
if (getId_articoloVariante() > 0L)
return getArticoloVariante().getQuantitaEffettivaAv();
if (getId_articolo() > 0L)
return getArticolo().getQuantitaEffettiva();
if (getId_articoloFilatoColore() > 0L)
return getArticoloFilatoColore().getQuantitaEffettiva();
if (getId_articoloTessutoColore() > 0L)
return getArticoloTessutoColore().getQuantitaEffettiva();
if (getId_articoloTessuto() > 0L)
return getArticoloTessuto().getQuantitaEffettiva();
return 0.0D;
}
public double getQuantitaImpegnata() {
if (getId_articoloVariante() > 0L)
return getArticoloVariante().getQuantitaImpegnataAv();
if (getId_articolo() > 0L)
return getArticolo().getQuantitaImpegnata();
if (getId_articoloFilatoColore() > 0L)
return getArticoloFilatoColore().getQuantitaImpegnata();
if (getId_articoloTessutoColore() > 0L)
return getArticoloTessutoColore().getQuantitaImpegnata();
if (getId_articoloTessuto() > 0L)
return getArticoloTessuto().getQuantitaImpegnata();
return 0.0D;
}
public double getQuantitaInArrivo() {
if (getId_articoloVariante() > 0L)
return getArticoloVariante().getQuantitaInArrivoAv();
if (getId_articolo() > 0L)
return getArticolo().getQuantitaInArrivo();
if (getId_articoloFilatoColore() > 0L)
return getArticoloFilatoColore().getQuantitaInArrivo();
if (getId_articoloTessutoColore() > 0L)
return getArticoloTessutoColore().getQuantitaInArrivo();
if (getId_articoloTessuto() > 0L)
return getArticoloTessuto().getQuantitaInArrivo();
return 0.0D;
}
public ResParm aggiornaMovimentoPareggioRigaPrelevata() {
ResParm rp = new ResParm(true);
try {
RigaDocumento rd = new RigaDocumento(getApFull());
rd.getMagQuantitaPrelevatoByRigaDocumentoPrelevata(getId_rigaDocumento());
double tot = rd.getQuantita();
if (getDocumento().getId_tipoDocumento() == getId_docOrdine() && getQuantita() > tot) {
long id_causale_storno = getParm("STORNO_ORDINE_A_FORNITORE").getNumeroLong();
DoubleOperator dp = new DoubleOperator(getQuantita());
dp.subtract(tot);
double qtaDaPrelevare = dp.getResult();
RigaDocumento rdStorno = new RigaDocumento(getApFull());
rdStorno.findMagByRigaDocumentoCausale(getId_rigaDocumento(), id_causale_storno);
if (rdStorno.getId_rigaDocumento() == 0L) {
rdStorno = (RigaDocumento)clone();
rdStorno.setId_rigaDocumento(0L);
rdStorno.setDBState(0);
}
rdStorno.setId_rigaDocumentoMov(getId_rigaDocumento());
rdStorno.setId_causaleMagazzino(id_causale_storno);
rdStorno.setSegnoMov(getSegnoMov() * -1L);
rdStorno.setSeriale(getSeriale());
if (getArticolo().getTipologiaArticolo().getFlgUdm() == 1L) {
rdStorno.setNr(qtaDaPrelevare);
} else if (getArticolo().getTipologiaArticolo().getFlgUdm() == 3L) {
rdStorno.setMt(qtaDaPrelevare);
} else if (getArticolo().getTipologiaArticolo().getFlgUdm() == 2L) {
rdStorno.setKg(qtaDaPrelevare);
}
rp = rdStorno.saveMov();
}
} catch (Exception e) {
rp.setException(e);
}
return rp;
}
public ResParm aggiornaMovimentoPareggioRigaPrelevataM() {
ResParm rp = new ResParm(true);
RigaDocumentoP rdp = new RigaDocumentoP(getApFull());
double tot = rdp.getQuantitaPrelevatoByRigaDocumentoPrelevata(getId_rigaDocumento());
if (getDocumento().getId_tipoDocumento() == getId_docOrdine() && getQuantita() > tot) {
long id_causale_storno = getParm("STORNO_ORDINE_A_FORNITORE").getNumeroLong();
DoubleOperator dp = new DoubleOperator(getQuantita());
dp.subtract(tot);
dp.multiply(-1);
double qtaDaPrelevare = dp.getResult();
CausaleMagazzino cm = new CausaleMagazzino(getApFull());
cm.findByPrimaryKey(id_causale_storno);
Movimento mov = new Movimento(getApFull());
mov.findByRigaDocumentoCausale(getId_rigaDocumento(), id_causale_storno);
mov.setId_rigaDocumento(getId_rigaDocumento());
mov.setId_articolo(getId_articolo());
mov.setId_articoloVariante(getId_articoloVariante());
mov.setId_articoloTaglia(getId_articoloTaglia());
mov.setId_causaleMagazzino(id_causale_storno);
mov.setSeriale(getSeriale());
if (getArticolo().getTipologiaArticolo().getFlgUdm() == 1L) {
mov.setNr(qtaDaPrelevare);
} else if (getArticolo().getTipologiaArticolo().getFlgUdm() == 3L) {
mov.setMt(qtaDaPrelevare);
} else if (getArticolo().getTipologiaArticolo().getFlgUdm() == 2L) {
mov.setKg(qtaDaPrelevare);
}
mov.setId_magFisico(cm.getId_magFisicoPartenza());
if (cm.getMagFisicoPartenza().getFlgTipo() == 1L) {
mov.setId_clifor(0L);
} else {
mov.setId_clifor(getDocumento().getId_clifor());
}
rp = mov.save();
}
return rp;
}
public Vectumerator findAllPerRiordinoMagazzino(long l_id_articolo, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A, DOCUMENTO AS B, TIPO_DOCUMENTO AS C";
String s_Sql_Order = " order by B.dataDocumento asc,B.id_esercizio, A.id_documento";
WcString wc = new WcString();
wc.addWc("A.id_documento=B.id_documento");
wc.addWc("B.id_tipoDocumento=C.id_tipoDocumento");
wc.addWc("(A.id_rigaDocumentoMov=0 or A.id_rigaDocumentoMov is null)");
if (l_id_articolo != 0L) {
wc.addWc("A.id_articolo=" + l_id_articolo);
} else {
wc.addWc("A.id_articolo >0");
}
wc.addWc("C.id_causaleMagazzino >0");
try {
PreparedStatement stmt;
if (pageRows == 0 && pageNumber == 0) {
stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
} else {
int partenza = pageRows * (pageNumber - 1);
stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + " limit " + s_Sql_Order + " , " + partenza);
}
return findRows(stmt);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public void setQuantitaUdm(double qta) {
if (getArticolo().getTipologiaArticolo().getFlgUdm() == 1L) {
setNr(qta);
} else if (getArticolo().getTipologiaArticolo().getFlgUdm() == 2L) {
setKg(qta);
} else if (getArticolo().getTipologiaArticolo().getFlgUdm() == 3L) {
setMt(qta);
} else {
setNr(qta);
}
}
public double getRigheAssociateSeriali(RigaDocumentoCR CR) {
StringBuffer s_Sql_Find = new StringBuffer("select COUNT(*) as _sum from RIGA_DOCUMENTO AS A INNER JOIN DOCUMENTO AS B ON A.id_documento=B.id_documento ");
s_Sql_Find.append(" INNER JOIN TIPO_DOCUMENTO AS C ON B.id_tipoDocumento=C.id_tipoDocumento ");
WcString wc = new WcString();
findByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find));
findByCRCreateStmtDate(CR, stmt);
return getSum(stmt);
} catch (SQLException e) {
handleDebug(e);
return 0.0D;
}
}
public long getQtaSlipStampate() {
return this.qtaSlipStampate;
}
public void setQtaSlipStampate(long qtaSlipStampate) {
this.qtaSlipStampate = qtaSlipStampate;
}
public void checkStatoRigaQta(double[] stati) {
stati[0] = 0.0D;
stati[1] = 0.0D;
DoubleOperator qtaEffettiva = new DoubleOperator();
DoubleOperator qtaMagazzino = new DoubleOperator();
if (getFlgRigaPrelevata() == 1L) {
stati[0] = 40.0D;
} else if (getId_articolo() != 0L || getId_articoloVariante() != 0L) {
if (!getSeriale().isEmpty()) {
stati[0] = 30.0D;
} else {
RigaDocumentoCR CR = new RigaDocumentoCR();
CR.setFlgTipologia(4L);
CR.setFlgStatoPrenotazione(200L);
CR.setId_articolo(getId_articolo());
CR.setId_articoloVariante(getId_articoloVariante());
CR.setFlgTipoRicerca(0L);
CR.setFlgOrderBy(5L);
CR.setFlgRigaPrelevata(0L);
if (getId_articoloVariante() != 0L) {
qtaEffettiva.add(getArticoloVariante().getQuantitaInArrivoAv());
qtaEffettiva.add(getArticoloVariante().getQuantitaAv());
qtaMagazzino.add(getArticoloVariante().getQuantitaAv());
} else if (getId_articolo() != 0L) {
qtaEffettiva.add(getArticolo().getQuantitaInArrivo());
qtaEffettiva.add(getArticolo().getQuantita());
qtaMagazzino.add(getArticolo().getQuantita());
}
CR.setFlgNoSeriale(2L);
double qtAssociata = getRigheAssociateSeriali(CR);
double qtMagazzino = getQtaPrelevataPrenotazioni();
qtaEffettiva.subtract(qtAssociata);
qtaEffettiva.subtract(getQtaOrdiniApertiPrenotazioni());
qtaEffettiva.subtract(qtMagazzino);
qtaMagazzino.subtract(qtMagazzino);
qtaMagazzino.subtract(qtAssociata);
if (qtaEffettiva.getResult() >= 0.0D) {
CR.setFlgNoSeriale(1L);
Vectumerator vec = findByCR(CR, 0, 0);
while (vec.hasMoreElements()) {
RigaDocumento row = (RigaDocumento)vec.nextElement();
double[] res = row.getQtaOrdinataPrelevataByRigaPrenotazione();
double qtOrd = res[0];
double qtPrel = res[1];
double qtPrenoParziale = row.getQuantita();
if (qtPrel >= qtPrenoParziale) {
stati[0] = 30.0D;
qtPrenoParziale = 0.0D;
} else if (qtPrel > 0.0D) {
stati[0] = 20.0D;
DoubleOperator dop = new DoubleOperator(qtPrenoParziale);
dop.subtract(qtPrel);
qtPrenoParziale = dop.getResult();
} else if (qtOrd >= qtPrenoParziale) {
stati[0] = 10.0D;
qtPrenoParziale = 0.0D;
} else if (qtOrd > 0.0D) {
stati[0] = 15.0D;
DoubleOperator dop = new DoubleOperator(qtPrenoParziale);
dop.subtract(qtOrd);
qtPrenoParziale = dop.getResult();
}
if (row.getId_rigaDocumento() == getId_rigaDocumento()) {
if (stati[0] == 30.0D || stati[0] == 10.0D)
break;
if (qtaMagazzino.getResult() >= qtPrenoParziale) {
if (stati[0] == 15.0D || stati[0] == 10.0D) {
stati[0] = 20.0D;
stati[1] = qtPrenoParziale;
break;
}
stati[0] = 30.0D;
stati[1] = qtPrenoParziale;
break;
}
if (qtaMagazzino.getResult() > 0.0D) {
stati[0] = 20.0D;
stati[1] = qtaMagazzino.getResult();
break;
}
if (qtaEffettiva.getResult() >= qtPrenoParziale) {
stati[0] = 10.0D;
break;
}
if (qtaEffettiva.getResult() > 0.0D) {
stati[0] = 15.0D;
break;
}
break;
}
qtaEffettiva.subtract(qtPrenoParziale);
qtaMagazzino.subtract(qtPrenoParziale);
stati[0] = 0.0D;
}
}
}
}
}
public Vectumerator<RigaDocumento> findByDocumento(long l_id_documento, long l_flgCodiceRiga, String l_search, int pageNumber, int pageRows, int ordinamentoRiga) {
RigaDocumentoCR CR = new RigaDocumentoCR(getApFull());
CR.setId_documento(l_id_documento);
CR.setFlgCodiceRiga(l_flgCodiceRiga);
CR.setSearchTxt(l_search);
return findByDocumento(CR, pageNumber, pageRows, ordinamentoRiga);
}
public Vectumerator<RigaDocumento> findByDocumentoOLD(long l_id_documento, long l_flgCodiceRiga, String l_search, int pageNumber, int pageRows, boolean ordineInverso) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A left join ARTICOLO AS B on A.id_articolo=B.id_articolo ";
String s_Sql_order = " order by A.id_rigaDocumento desc";
if (!ordineInverso)
s_Sql_order = " order by A.id_rigaDocumento asc";
WcString wc = new WcString();
wc.addWc("(A.id_rigaDocumentoMov=0 or A.id_rigaDocumentoMov is null)");
wc.addWc("A.id_documento=" + l_id_documento);
if (l_flgCodiceRiga == 0L) {
wc.addWc("(A.flgCodiceRiga is null or A.flgCodiceRiga=0)");
} else if (l_flgCodiceRiga > 0L) {
wc.addWc("A.flgCodiceRiga=" + l_flgCodiceRiga);
}
if (!l_search.isEmpty()) {
String star = "";
String temp = l_search;
temp = prepareInputMySqlString(temp, true);
temp = temp.replace("*", "%");
StringTokenizer st = new StringTokenizer(temp.trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = star + star;
txt.append("(B.codice like '" + token + "%' or A.seriale like '" + token + "' or A.descrizioneRiga like '" + token + "%' )");
if (st.hasMoreTokens()) {
txt.append(" and ");
star = "%";
}
}
txt.append(")");
wc.addWc(txt.toString());
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return findRows(stmt, pageNumber, pageRows);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator<RigaDocumento> findByDocumento(RigaDocumentoCR CR, int pageNumber, int pageRows, int ordinamentoRiga) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A left join ARTICOLO AS B on A.id_articolo=B.id_articolo ";
String s_Sql_order = " order by A.ordine, A.id_rigaDocumento asc";
if (ordinamentoRiga == 1) {
s_Sql_order = " order by A.ordine desc,A.id_rigaDocumento desc";
} else if (ordinamentoRiga == 2) {
s_Sql_order = " order by A.descrizioneRiga asc";
} else if (ordinamentoRiga == 3) {
s_Sql_order = " order by A.descrizioneRigaRaggruppamento asc, A.descrizioneRigaDettaglio, A.descrizioneRiga";
} else if ((long)ordinamentoRiga == 10L) {
s_Sql_Find = s_Sql_Find + " INNER join DOCUMENTO AS D ON D.id_documento=A.id_documentoPadre";
s_Sql_order = " order by D.riferimento, A.id_rigaDocumentoPadre, A.descrizioneRigaDettaglio, A.descrizioneRiga";
}
WcString wc = new WcString();
wc.addWc("(A.id_rigaDocumentoMov=0 or A.id_rigaDocumentoMov is null)");
wc.addWc("A.id_documento=" + CR.getId_documento());
if (CR.getFlgCodiceRiga() == 0L) {
wc.addWc("(A.flgCodiceRiga is null or A.flgCodiceRiga=0)");
} else if (CR.getFlgCodiceRiga() > 0L) {
wc.addWc("A.flgCodiceRiga=" + CR.getFlgCodiceRiga());
}
if (CR.getFlgStatoLavorazioneRiga() == 0L) {
wc.addWc("(A.flgStatoLavorazioneRiga is null or A.flgStatoLavorazioneRiga=0)");
} else if (CR.getFlgStatoLavorazioneRiga() > 0L) {
wc.addWc("A.flgStatoLavorazioneRiga=" + CR.getFlgStatoLavorazioneRiga());
} else if (CR.getFlgStatoLavorazioneRiga() == -1L) {
wc.addWc("(A.flgStatoLavorazioneRiga=0 is null or A.flgStatoLavorazioneRiga=0 or A.flgStatoLavorazioneRiga=20 or A.flgStatoLavorazioneRiga=10 ) ");
}
if (!CR.getSearchTxt().isEmpty()) {
String star = "";
String temp = CR.getSearchTxt();
temp = prepareInputMySqlString(temp, true);
temp = temp.replace("*", "%");
StringTokenizer st = new StringTokenizer(temp.trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = star + star;
txt.append("(B.codice like '" + token + "%' or A.seriale like '" + token + "' or A.descrizioneRiga like '" + token + "%' )");
if (st.hasMoreTokens()) {
txt.append(" and ");
star = "%";
}
}
txt.append(")");
wc.addWc(txt.toString());
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return findRows(stmt, pageNumber, pageRows);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator<RigaDocumento> findByDocumentoArticoloArticoloVariante(long l_id_documento, long l_id_articolo, long l_id_articoloVariante) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A left join ARTICOLO AS B on A.id_articolo=B.id_articolo ";
String s_Sql_order = " order by A.id_rigaDocumento desc";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
if (l_id_articolo == 0L) {
wc.addWc("(A.id_articolo is null or A.id_articolo=0)");
} else {
wc.addWc("A.id_articolo=" + l_id_articolo);
}
if (l_id_articoloVariante == 0L) {
wc.addWc("(A.id_articoloVariante is null or A.id_articoloVariante=0)");
} else {
wc.addWc("A.id_articoloVariante=" + l_id_articoloVariante);
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return findRows(stmt);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public void findByDocumentoArticoloArticoloVarianteTaglia(long l_id_documento, long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_order = " order by A.id_rigaDocumento desc";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
if (l_id_articolo == 0L) {
wc.addWc("(A.id_articolo is null or A.id_articolo=0)");
} else {
wc.addWc("A.id_articolo=" + l_id_articolo);
}
if (l_id_articoloVariante == 0L) {
wc.addWc("(A.id_articoloVariante is null or A.id_articoloVariante=0)");
} else {
wc.addWc("A.id_articoloVariante=" + l_id_articoloVariante);
}
if (l_id_articoloTaglia == 0L) {
wc.addWc("(A.id_articoloTaglia is null or A.id_articoloTaglia=0)");
} else {
wc.addWc("A.id_articoloTaglia=" + l_id_articoloTaglia);
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
findFirstRecord(stmt);
} catch (Exception e) {
handleDebug(e, 0);
}
}
public void findByDocumentoArticoloTessutoColore(long l_id_documento, long l_id_articoloTessutoColore, long l_flgCodiceRiga) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_order = " order by A.id_rigaDocumento desc";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
wc.addWc("A.flgCodiceRiga=" + l_flgCodiceRiga);
wc.addWc("A.id_articoloTessutoColore=" + l_id_articoloTessutoColore);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
findFirstRecord(stmt);
} catch (Exception e) {
handleDebug(e, 0);
}
}
public void findByDocumentoArticoloTessuto(long l_id_documento, long l_id_articoloTessuto, long l_flgCodiceRiga) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_order = " order by A.id_rigaDocumento desc";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
wc.addWc("A.flgCodiceRiga=" + l_flgCodiceRiga);
wc.addWc("A.id_articoloTessuto=" + l_id_articoloTessuto);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
findFirstRecord(stmt);
} catch (Exception e) {
handleDebug(e, 0);
}
}
public long getStatoPrenotazione() {
if (getDocumento().getId_tipoDocumento() == getId_docPrenotazione())
if (this.statoPrenotazione == -1L) {
this.statoPrenotazione = checkStatoRiga();
super.save();
}
return this.statoPrenotazione;
}
public void setStatoPrenotazione(long statoPrenotazione) {
this.statoPrenotazione = statoPrenotazione;
}
public ResParm resetStatoPrenotazioneByArticolo(long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia) {
String s_sql_update = "update RIGA_DOCUMENTO AS A INNER JOIN DOCUMENTO AS B ON A.id_documento= B.id_documento SET statoPrenotazione=-1 ";
WcString wc = new WcString();
wc.addWc("B.id_tipoDocumento=" + getId_docPrenotazione());
if (l_id_articolo > 0L)
wc.addWc("A.id_articolo=" + l_id_articolo);
if (l_id_articoloVariante > 0L)
wc.addWc("A.id_articoloVariante=" + l_id_articoloVariante);
if (l_id_articoloTaglia > 0L)
wc.addWc("A.id_articoloTaglia=" + l_id_articoloTaglia);
ResParm rp = update(s_sql_update + s_sql_update);
return rp;
}
public String getStatoRiga() {
return getStatoRiga(getStatoPrenotazione());
}
public void findRigaImpegnoBySeriale(long l_id_articolo, long l_id_articoloVariante, String l_seriale) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A , DOCUMENTO AS B ";
WcString wc = new WcString();
wc.addWc("A.id_documento=B.id_documento");
if (l_id_articoloVariante == 0L) {
wc.addWc("(A.id_articoloVariante=0 or A.id_articoloVariante is null)");
} else {
wc.addWc("A.id_articoloVariante=" + l_id_articoloVariante);
}
wc.addWc("A.id_articolo=" + l_id_articolo);
wc.addWc("A.seriale='" + l_seriale + "'");
wc.addWc("B.id_tipoDocumento=" + getId_docPrenotazione());
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
findFirstRecord(stmt);
} catch (Exception e) {
handleDebug(e, 0);
}
}
public double getQuantitaMovimentoMagazzino() {
if (getDocumento().getTipoDocumento().getCausaleMagazzino().getMagFisicoArrivo()
.getFlgTipo() == 3L ||
getDocumento().getTipoDocumento().getCausaleMagazzino().getMagFisicoPartenza()
.getFlgTipo() == 3L)
return 0.0D;
if (getArticolo().getTipo().getFlgTipoMagazzino() > 0L &&
getArticolo().getTipo().getFlgTipoMagazzino() < 9L) {
if (getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoPartenza() > 0L)
return -getQuantita();
if (getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoArrivo() > 0L)
return getQuantita();
return 0.0D;
}
return 0.0D;
}
public long findAllPerRiordinoMagazzinoTot(long l_id_articolo) {
String s_Sql_Find = "select COUNT(*) AS _tot from RIGA_DOCUMENTO AS A, DOCUMENTO AS B, TIPO_DOCUMENTO AS C";
String s_Sql_Order = " order by B.dataDocumento asc,B.id_esercizio, A.id_documento";
WcString wc = new WcString();
wc.addWc("A.id_documento=B.id_documento");
wc.addWc("B.id_tipoDocumento=C.id_tipoDocumento");
wc.addWc("(A.id_rigaDocumentoMov=0 or A.id_rigaDocumentoMov is null)");
if (l_id_articolo != 0L) {
wc.addWc("A.id_articolo=" + l_id_articolo);
} else {
wc.addWc("A.id_articolo >0");
}
wc.addWc("C.id_causaleMagazzino >0");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return getCount(stmt, "_tot");
} catch (SQLException e) {
handleDebug(e);
return 0L;
}
}
public ResParm settaRigaPrelevata() {
if (getId_rigaDocumento() > 0L) {
setFlgRigaPrelevata(1L);
ResParm rp = super.save();
if (rp.getStatus()) {
rp.append(aggiornaMovimentoPareggioRigaPrelevataM());
rp.append(aggiornaMovimentoPareggioRigaPrelevata());
getArticolo().resetCalcoloQuantita();
}
return rp;
}
return new ResParm(false, "ERRORE! Tentativo di annullare una riga prelevata su una rigq inesistente!");
}
public ResParm annullaRigaPrelevata() {
if (getId_rigaDocumento() > 0L) {
setFlgRigaPrelevata(0L);
ResParm rp = synchroSave(this);
if (rp.getStatus()) {
RigaDocumento rdStorno = new RigaDocumento(getApFull());
long id_causale_storno = getParm("STORNO_ORDINE_A_FORNITORE").getNumeroLong();
rdStorno.findMagByRigaDocumentoCausale(getId_rigaDocumento(), id_causale_storno);
if (rdStorno.getId_rigaDocumento() != 0L)
rdStorno.deleteMov();
rp = aggiornaDispo();
}
return rp;
}
return new ResParm(false, "ERRORE! Tentativo di annullare una riga prelevata su una rigq inesistente!");
}
public Vectumerator<RigaDocumento> findRigheNonPrelevateByDocumento(long l_id_documento) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_order = " order by A.id_rigaDocumento";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
wc.addWc("A.flgRigaPrelevata=0");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return findRows(stmt);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator<RigaDocumento> findRigheNonPrelevatePreChiusuraByDocumento(long l_id_documento) {
String s_Sql_Find = "SELECT * FROM RIGA_DOCUMENTO AS A LEFT JOIN RIGA_DOCUMENTO_P AS B ON A.id_rigaDocumento = B.id_rigaDocumentoPrelevata";
String s_Sql_order = " order by A.id_rigaDocumento";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
wc.addWc("B.id_rigaDocumento IS NULL");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return findRows(stmt);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator findOrdiniByArticolo(long l_id_articolo) {
String s_Sql_Find = "SELECT A.id_documento, SUM(B.nr) AS nr FROM DOCUMENTO AS A INNER JOIN RIGA_DOCUMENTO AS B ON A.id_documento = B.id_documento ";
String s_Sql_GroupBy = " GROUP BY A.id_documento";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" B.id_articolo = " + l_id_articolo);
wc.addWc(" A.id_tipoDocumento = 8 ");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Order);
return findRows(stmt, 0, 0);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator findMovimentiDiCaricoByArticoloDocumento(long l_id_articolo, long l_id_documento) {
String s_Sql_Find = "SELECT E.id_documento, D.id_magFisico AS id_magFisico, SUM(D.nr) AS nr FROM RIGA_DOCUMENTO_P AS A LEFT JOIN RIGA_DOCUMENTO AS B ON A.id_rigadocumentoPrelevata = B.id_rigaDocumento LEFT JOIN DOCUMENTO AS C ON B.id_documento = C.id_documento LEFT JOIN MOVIMENTO AS D ON A.id_rigadocumento = D.id_rigaDocumento LEFT JOIN RIGA_DOCUMENTO AS E ON D.id_rigadocumento = E.id_rigadocumento ";
String s_Sql_GroupBy = " GROUP BY E.id_documento, D.id_magFisico";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" B.id_articolo = " + l_id_articolo);
wc.addWc(" C.id_documento = " + l_id_documento);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Order);
return findRows(stmt, 0, 0);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator findDettaglioBollaByArticoloDocumento(long l_id_articolo, long l_id_documento) {
String s_Sql_Find = "SELECT COUNT(B.id_movimento) AS nr, A.id_rigaDocumento, A.id_documento FROM RIGA_DOCUMENTO AS A LEFT JOIN MOVIMENTO AS B ON A.id_rigadocumento = B.id_rigaDocumento ";
String s_Sql_GroupBy = " GROUP BY A.id_rigaDocumento";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" A.id_articolo = " + l_id_articolo);
wc.addWc(" A.id_documento = " + l_id_documento);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Order);
return findRows(stmt, 0, 0);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator findOrdiniAFornitoreAperti() {
return findOrdiniAFornitoreAperti(0L);
}
public Vectumerator findOrdiniAFornitoreAperti(long id_articolo) {
String s_Sql_Find = "SELECT SUM(A.nr) AS nr, A.id_articolo, A.id_articoloVariante, A.id_articoloTaglia FROM RIGA_DOCUMENTO AS A INNER JOIN DOCUMENTO AS B ON A.id_documento = B.id_documento ";
String s_Sql_GroupBy = " GROUP BY A.id_articolo";
String s_Sql_Order = "";
WcString wc = new WcString();
if (id_articolo > 0L)
wc.addWc(" A.id_articolo = " + id_articolo);
wc.addWc(" B.id_tipoDocumento = 8 ");
wc.addWc(" (B.flgDocumentoPrelevato = 0 OR B.flgDocumentoPrelevato IS NULL) ");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Order);
return findRows(stmt, 0, 0);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator findOrdiniAFornitoreChiusi() {
String s_Sql_Find = "SELECT SUM(A.nr) AS nr, A.id_articolo, A.id_articoloVariante, A.id_articoloTaglia FROM RIGA_DOCUMENTO AS A INNER JOIN DOCUMENTO AS B ON A.id_documento = B.id_documento ";
String s_Sql_GroupBy = " GROUP BY A.id_articolo";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" B.id_tipoDocumento = 8 ");
wc.addWc(" B.flgDocumentoPrelevato = 1 ");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Order);
return findRows(stmt, 0, 0);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public double getQtaSaldoMovimento(long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia) {
System.out.println("Rigadocumento.getQtaSaldoMovimento !!!!!!");
if (this.qtaSaldoMovimento == 0.0D) {
Movimento mov = new Movimento(getApFull());
setQtaSaldoMovimento(
mov.getSaldoByArticoloVarianteTagliaMagazzino(l_id_articolo, l_id_articoloVariante, l_id_articoloTaglia, 5L));
}
return this.qtaSaldoMovimento;
}
public void setQtaSaldoMovimento(double qtaSaldoMovimento) {
this.qtaSaldoMovimento = qtaSaldoMovimento;
}
public void importMovimentoOrdiniAFornitore() {
long i = 0L;
String sql = "DELETE FROM MOVIMENTO WHERE id_magFisico = 5";
delete(sql);
sql = "UPDATE ARTICOLO SET quantitaCalcolate=false";
update(sql);
String s_Sql_Find = "SELECT A.* FROM RIGA_DOCUMENTO AS A INNER JOIN DOCUMENTO AS B ON A.id_documento = B.id_documento ";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" B.id_tipoDocumento = 8 ");
wc.addWc(" (B.flgDocumentoPrelevato = 0 OR B.flgDocumentoPrelevato IS NULL) ");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
MagFisico mf = new MagFisico(getApFull());
mf.findMagazzinoOrdinato();
Vectumerator<RigaDocumento> vec = findRows(stmt, 0, 0);
while (vec.hasMoreElements()) {
RigaDocumento rd = (RigaDocumento)vec.nextElement();
Movimento mov = new Movimento(getApFull());
mov.setId_articolo(rd.getId_articolo());
mov.setId_articoloVariante(rd.getId_articoloVariante());
mov.setId_articoloTaglia(rd.getId_articoloTaglia());
mov.setId_clifor(rd.getDocumento().getId_clifor());
mov.setId_magFisico(mf.getId_magFisico());
mov.setId_causaleMagazzino(7L);
mov.setId_rigaDocumento(rd.getId_rigaDocumento());
mov.setNr(rd.getQuantita());
mov.save();
Vectumerator<RigaDocumentoP> vecRdp = new RigaDocumentoP(getApFull()).findByRigaDocumentoPrelevata(rd.getId_rigaDocumento(), 0, 0);
while (vecRdp.hasMoreElements()) {
RigaDocumentoP rdp = (RigaDocumentoP)vecRdp.nextElement();
rd = rdp.getRigaDocumento();
mov = new Movimento(getApFull());
mov.setId_articolo(rd.getId_articolo());
mov.setId_articoloVariante(rd.getId_articoloVariante());
mov.setId_articoloTaglia(rd.getId_articoloTaglia());
mov.setId_clifor(rd.getDocumento().getId_clifor());
mov.setId_magFisico(mf.getId_magFisico());
mov.setId_causaleMagazzino(2L);
mov.setId_rigaDocumento(rd.getId_rigaDocumento());
mov.setNr(-1.0D * rd.getQuantita());
mov.save();
}
i++;
System.out.println("Riga " + i + " di " + vec.size());
}
} catch (SQLException e) {
handleDebug(e);
}
}
public Vectumerator<RigaDocumento> findVenditeServizi(DocumentoCR CR) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A, DOCUMENTO AS B, ARTICOLO AS C, TIPO AS D, REPARTO AS E, TIPO_DOCUMENTO AS ZZ ";
String s_Sql_Order = " order by A.id_articolo, B.dataDocumento, E.descrizione, D.descrizione, A.descrizioneRiga, A.notaBarcode ";
WcString wc = new WcString();
wc.addWc("A.id_documento=B.id_documento");
wc.addWc("A.id_articolo=C.id_articolo");
wc.addWc("C.id_tipo=D.id_tipo");
wc.addWc("A.id_reparto=E.id_reparto");
wc.addWc("B.id_tipoDocumento = ZZ.id_tipoDocumento");
wc.addWc("(B.flgHaDocumentoPadre IS NULL OR B.flgHaDocumentoPadre = 0)");
wc.addWc(" ZZ.id_causaleMagazzino = 1 ");
wc.addWc(" D.flgTipoMagazzino = 9");
if (CR.getId_tipo() > 0L)
wc.addWc("(C.id_tipo=" + CR.getId_tipo() + " or D.indici like'%:" + CR.getId_tipo() + ":%')");
wc.addWc(" B.dataDocumento>=?");
wc.addWc(" B.dataDocumento<=?");
if (CR.getId_articolo() > 0L)
wc.addWc(" A.id_articolo = " + CR.getId_articolo());
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
int dataCount = 1;
stmt.setDate(dataCount, CR.getDataDocumentoDa());
dataCount++;
stmt.setDate(dataCount, CR.getDataDocumentoA());
return findRows(stmt);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public CausaleMagazzino getCausaleMagazzino() {
this.causaleMagazzino = (CausaleMagazzino)getSecondaryObject(this.causaleMagazzino, CausaleMagazzino.class, getId_causaleMagazzino());
return this.causaleMagazzino;
}
public Clifor getClifor() {
this.clifor = (Clifor)getSecondaryObject(this.clifor, Clifor.class, getId_clifor());
return this.clifor;
}
public long getId_causaleMagazzino() {
return this.id_causaleMagazzino;
}
public long getId_clifor() {
return this.id_clifor;
}
public void setCausaleMagazzino(CausaleMagazzino causaleMagazzino) {
this.causaleMagazzino = causaleMagazzino;
}
public void setClifor(Clifor clifor) {
this.clifor = clifor;
}
public void setId_causaleMagazzino(long id_causaleMagazzino) {
this.id_causaleMagazzino = id_causaleMagazzino;
}
public void setId_clifor(long l_id_clifor) {
this.id_clifor = l_id_clifor;
}
public long getSegnoMov() {
return this.segnoMov;
}
public void setSegnoMov(long segnoMov) {
this.segnoMov = segnoMov;
}
public long getId_rigaDocumentoMov() {
return this.id_rigaDocumentoMov;
}
public void setId_rigaDocumentoMov(long id_rigaDocumentoMov) {
this.id_rigaDocumentoMov = id_rigaDocumentoMov;
}
private void findRigaDocumentoMovByRigaDocumento(long l_id_rigaDocumento) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
WcString wc = new WcString();
wc.addWc("A.id_rigaDocumentoMov=" + l_id_rigaDocumento);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
findFirstRecord(stmt);
} catch (Exception e) {
handleDebug(e, 0);
}
}
public void findMagByRigaDocumentoCausale(long l_id_rigaDocumento, long l_id_causaleMagazzino) {
if (l_id_rigaDocumento > 0L && l_id_causaleMagazzino > 0L) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.id_rigaDocumentoMov = " + l_id_rigaDocumento);
wc.addWc("A.id_causaleMagazzino = " + l_id_causaleMagazzino);
wc.addWc("A.id_magFisico >0");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
} else {
initFields();
setDBState(0);
}
}
public void findMagBySerialeDisponibile(String l_seriale) {
String s_Sql_Find = "SELECT A.*, SUM(A.nr*segnoMov) AS nr from RIGA_DOCUMENTO AS A ";
String s_Sql_Having = " HAVING nr > 0 and A.id_magFisico>0";
String s_Sql_Order = " ";
WcString wc = new WcString();
wc.addWc(" A.seriale = '" + l_seriale + "'");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public void findMagBySerialeEsistente(String l_seriale) {
String s_Sql_Find = "SELECT A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_Order = " ";
WcString wc = new WcString();
wc.addWc(" A.seriale = '" + l_seriale + "'");
wc.addWc("A.id_magFisico>0");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public void findMagFilatoDisponibilita(long l_id_articoloFilatoColore, long l_id_articoloFilato, long l_id_coloreFilato, String l_seriale, long l_tipologia_magfisico, long l_id_magFisico, long l_id_clifor, Date dataA) {
String s_Sql_Sum = " SUM(A.kg*segnoMov) as kg, SUM(A.mt*segnoMov) as mt, SUM(A.nr*segnoMov) as nr from RIGA_DOCUMENTO AS A ";
String s_Sql_colonne = "";
String s_Sql_join = "";
WcString wc = new WcString();
if (l_id_articoloFilato > 0L || l_id_coloreFilato > 0L)
s_Sql_Sum = s_Sql_Sum + " inner join ARTICOLO_FILATO_COLORE AS F ON A.id_articoloFilatoColore=F.id_articoloFilatoColore";
if (l_id_magFisico == 0L) {
wc.addWc("A.id_magFisico>0");
} else {
wc.addWc("A.id_magFisico=" + l_id_magFisico);
}
if (l_id_articoloFilatoColore != 0L) {
wc.addWc(" A.id_articoloFilatoColore = " + l_id_articoloFilatoColore);
s_Sql_colonne = s_Sql_colonne + " A.id_articoloFilatoColore,";
}
if (l_id_articoloFilato != 0L) {
wc.addWc(" F.id_articoloFilato = " + l_id_articoloFilato);
s_Sql_colonne = s_Sql_colonne + " F.id_articoloFilato,";
}
if (l_id_coloreFilato != 0L) {
wc.addWc(" F.id_coloreFilato = " + l_id_coloreFilato);
s_Sql_colonne = s_Sql_colonne + " F.id_coloreFilato,";
}
if (l_seriale != null && !l_seriale.isEmpty()) {
wc.addWc(" A.seriale = " + l_seriale);
s_Sql_colonne = s_Sql_colonne + " A.seriale,";
}
if (l_id_clifor != 0L) {
wc.addWc(" A.id_clifor = " + l_id_clifor);
s_Sql_colonne = s_Sql_colonne + " A.id_clifor,";
}
if (dataA != null) {
s_Sql_join = " INNER JOIN DOCUMENTO AS DOC ON A.id_documento=DOC.id_documento ";
wc.addWc(" DOC.dataDocumento <= ?");
s_Sql_Sum = s_Sql_Sum + s_Sql_Sum;
}
if (l_tipologia_magfisico != 0L) {
wc.addWc(" B.flgTipo = " + l_tipologia_magfisico);
s_Sql_colonne = s_Sql_colonne + " A.id_magFisico,";
s_Sql_Sum = s_Sql_Sum + ", MAG_FISICO AS B";
wc.addWc(" A.id_magFisico = B.id_magFisico ");
}
String s_sql_groupby = "";
if (!s_Sql_colonne.isEmpty())
s_sql_groupby = " group by " + s_Sql_colonne.substring(0, s_Sql_colonne.length() - 1);
try {
PreparedStatement stmt = getConn()
.prepareStatement("select " + s_Sql_colonne + s_Sql_Sum + wc.toString() + s_sql_groupby);
if (dataA != null)
stmt.setDate(1, dataA);
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public void findMagDisponibilitaGlobaleMagazziniInterniEsterni(long l_id_articolo, String l_seriale, long l_id_clifor) {
findMagDisponibilitaPuntuale(0L, 0L, 0L, l_seriale, 0L, l_id_clifor, 3L);
setId_articolo(l_id_articolo);
}
public void findMagFilatoDisponibilitaGlobaleMagazziniInterniEsterni(long l_id_articoloFilatoColore, String l_seriale, long l_id_clifor) {
findMagFilatoDisponibilitaPuntuale(0L, 0L, 0L, l_seriale, 0L, l_id_clifor, 3L, "");
}
public void findMagDisponibilitaPuntualeMagazziniInterni(long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia, String l_seriale, long l_id_clifor) {
findMagDisponibilitaPuntuale(l_id_articolo, l_id_articoloVariante, l_id_articoloTaglia, l_seriale, 0L, l_id_clifor, 1L);
}
public void findMagFilatoDisponibilitaPuntualeMagazziniInterni(long l_id_articoloFilatoColore, long l_id_articoloFilato, long l_id_coloreFilato, String l_seriale) {
findMagFilatoDisponibilitaPuntuale(l_id_articoloFilatoColore, l_id_articoloFilato, l_id_coloreFilato, l_seriale, 0L, 0L, 1L, "");
}
public void findMagDisponibilitaPuntualeMagazziniInterniEsterni(long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia, String l_seriale, long l_id_clifor) {
findMagDisponibilitaPuntuale(l_id_articolo, l_id_articoloVariante, l_id_articoloTaglia, l_seriale, 0L, l_id_clifor, 3L);
}
public void findMagFilatoDisponibilitaPuntualeMagazziniInterniEsterni(long l_id_articoloFilatoColore, long l_id_articoloFilato, long l_id_coloreFilato, String l_seriale, long l_id_clifor) {
findMagFilatoDisponibilitaPuntuale(l_id_articoloFilatoColore, l_id_articoloFilato, l_id_coloreFilato, l_seriale, 0L, l_id_clifor, 3L, "");
}
public void findMagDisponibilitaPuntuale(long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia, String l_seriale, long l_id_magfisico, long l_id_clifor, long flgTipoRicerca) {
String s_Sql_Sum = " SUM(segnoMov*kg) as kg, SUM(segnoMov*mt) as mt, SUM(segnoMov*nr) as nr from RIGA_DOCUMENTO AS A";
String s_Sql_colonne = "";
WcString wc = new WcString();
if (flgTipoRicerca == 0L)
wc.addWc("A.id_magFisico>0");
if (l_id_articolo != 0L) {
wc.addWc(" id_articolo = " + l_id_articolo);
s_Sql_colonne = s_Sql_colonne + " id_articolo,";
}
if (l_id_articoloVariante != 0L) {
wc.addWc(" id_articoloVariante = " + l_id_articoloVariante);
s_Sql_colonne = s_Sql_colonne + " id_articoloVariante,";
}
if (l_id_articoloTaglia != 0L) {
wc.addWc(" id_articoloTaglia = " + l_id_articoloTaglia);
s_Sql_colonne = s_Sql_colonne + " id_articoloTaglia,";
}
if (l_id_magfisico != 0L) {
wc.addWc(" id_magFisico = " + l_id_magfisico);
s_Sql_colonne = s_Sql_colonne + " id_magFisico,";
}
StringBuilder mf = new StringBuilder("");
if (flgTipoRicerca > 0L && l_id_magfisico == 0L) {
MagFisico mag = new MagFisico(getApFull());
if (flgTipoRicerca == 1L || flgTipoRicerca == 3L) {
Vectumerator<MagFisico> vecMag = mag.findByTipo(1L);
if (vecMag.hasMoreElements())
while (vecMag.hasMoreElements()) {
mag = (MagFisico)vecMag.nextElement();
if (mf.length() > 0)
mf.append(" OR ");
mf.append(" id_magFisico = " + mag.getId_magFisico());
}
}
if (flgTipoRicerca == 2L || flgTipoRicerca == 3L) {
Vectumerator<MagFisico> vecMag = mag.findByTipo(2L);
if (vecMag.hasMoreElements())
while (vecMag.hasMoreElements()) {
mag = (MagFisico)vecMag.nextElement();
if (mf.length() > 0)
mf.append(" OR ");
mf.append(" id_magFisico = " + mag.getId_magFisico());
}
}
}
if (mf.length() > 0) {
mf.append(")");
wc.addWc("(" + mf.toString());
s_Sql_colonne = s_Sql_colonne + " id_magFisico,";
}
if (l_seriale != null && !l_seriale.isEmpty()) {
wc.addWc(" seriale = '" + l_seriale + "'");
s_Sql_colonne = s_Sql_colonne + " seriale,";
}
if (l_id_clifor != 0L) {
wc.addWc(" id_clifor = " + l_id_clifor);
s_Sql_colonne = s_Sql_colonne + " id_clifor,";
}
String s_sql_groupby = "";
if (!s_Sql_colonne.isEmpty())
s_sql_groupby = " group by " + s_Sql_colonne.substring(0, s_Sql_colonne.length() - 1);
try {
PreparedStatement stmt = getConn()
.prepareStatement("select " + s_Sql_colonne + s_Sql_Sum + wc.toString() + s_sql_groupby);
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public Vectumerator findMagSaldiArticoloByCR(RigaDocumentoCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.id_articolo, A.id_articoloVariante, A.id_articoloTaglia, A.id_magFisico, A.seriale, A.id_clifor, SUM(A.kg*segnoMov) as kg, SUM(A.mt*segnoMov) as mt, SUM(A.nr*segnoMov) as nr from RIGA_DOCUMENTO AS A INNER JOIN ARTICOLO AS B ON A.id_articolo = B.id_articolo ";
String s_Sql_Group = " group by A.id_articolo, id_articoloVariante, id_articoloTaglia, A.id_magFisico, A.seriale, A.id_clifor ";
String s_Sql_Order = " order by B.nome, A.id_magFisico, A.id_clifor ";
String s_Sql_Having = "";
if (CR.getFlgInMagazzino() == 1L) {
s_Sql_Having = " Having SUM(kg*segnoMov) > 0 OR SUM(mt*segnoMov) > 0 OR SUM(nr*segnoMov) > 0 ";
} else if (CR.getFlgInMagazzino() == 2L) {
s_Sql_Having = " Having SUM(kg*segnoMov) < 0 OR SUM(mt*segnoMov) < 0 OR SUM(nr*segnoMov) < 0 ";
} else if (CR.getFlgInMagazzino() == 3L) {
s_Sql_Having = " Having SUM(kg*segnoMov) <> 0 OR SUM(mt*segnoMov) <> 0 OR SUM(nr*segnoMov) <> 0 ";
}
WcString wc = new WcString();
wc.addWc("A.id_magFisico>0");
if (!CR.getSearchTxt().isEmpty() && !CR.getSearchTxt().equals("*")) {
String star = "";
String temp = CR.getSearchTxt();
temp = prepareInputMySqlString(temp, true);
temp = temp.replace("*", "%");
StringTokenizer st = new StringTokenizer(temp.trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = star + star;
txt.append("(B.codice like '" + token + "%' or B.nome like '" + token + "%' or B.codiceProduttore like '" + token + "%' or B.codiciAlternativi like '%," + token + "%')");
if (st.hasMoreTokens()) {
txt.append(" and ");
star = "%";
}
}
txt.append(")");
wc.addWc(txt.toString());
}
if (CR.getId_articolo() > 0L)
wc.addWc(" A.id_articolo = " + CR.getId_articolo());
if (CR.getId_articoloVariante() > 0L)
wc.addWc(" A.id_articoloVariante = " + CR.getId_articoloVariante());
if (CR.getId_magFisico() > 0L)
wc.addWc(" A.id_magFisico = " + CR.getId_magFisico());
if (CR.getId_clifor() > 0L)
wc.addWc(" A.id_clifor = " + CR.getId_clifor());
try {
PreparedStatement stmt = getConn()
.prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Group + s_Sql_Having);
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator findMagFilatoSaldiArticoloFilatoByCR(RigaDocumentoCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select B.id_articoloFilato, C.id_articoloFilatoColore , SUM(A.kg*segnoMov) as kg, SUM(A.mt*segnoMov) as mt, SUM(A.nr*segnoMov) as nr from ARTICOLO_FILATO AS B LEFT JOIN ARTICOLO_FILATO_COLORE AS C ON B.id_articoloFilato=C.id_articoloFilato LEFT JOIN RIGA_DOCUMENTO AS A ON A.id_articoloFilato=B.id_articoloFilato and A.id_articoloFilatoColore=C.id_articoloFilatoColore left JOIN MAG_FISICO AS D ON A.id_magFisico=D.id_magFisico ";
if (CR.getFlgTipoMagazzino() > 0L)
s_Sql_Find = s_Sql_Find + " and D.flgTipo = " + s_Sql_Find;
String s_Sql_Group = " group by B.id_articoloFilato, C.id_articoloFilatoColore";
String s_Sql_Order = " order by B.nome, C.nomeV, A.seriale ";
String s_Sql_Having = "";
if (CR.getFlgInMagazzino() == 1L) {
s_Sql_Having = " Having SUM(A.kg*segnoMov) > 0 OR SUM(A.mt*segnoMov) > 0 OR SUM(A.nr*segnoMov) > 0 ";
} else if (CR.getFlgInMagazzino() == 2L) {
s_Sql_Having = " Having SUM(A.kg*segnoMov) < 0 OR SUM(A.mt*segnoMov) < 0 OR SUM(A.nr*segnoMov) < 0 ";
}
WcString wc = new WcString();
wc.addWc("A.id_magFisico>0");
if (!CR.getSearchTxt().isEmpty() && !CR.getSearchTxt().equals("*")) {
String star = "";
String temp = CR.getSearchTxt();
temp = prepareInputMySqlString(temp, true);
temp = temp.replace("*", "%");
StringTokenizer st = new StringTokenizer(temp.trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = star + star;
txt.append("(B.codice like '" + token + "%' or B.nome like '" + token + "%' or B.codiceProduttore like '" + token + "%' or B.codiciAlternativi like '%," + token + "%')");
if (st.hasMoreTokens()) {
txt.append(" and ");
star = "%";
}
}
txt.append(")");
wc.addWc(txt.toString());
}
if (CR.getId_articolo() > 0L)
wc.addWc("B.id_articolo = " + CR.getId_articolo());
if (CR.getId_magFisico() > 0L)
wc.addWc(" A.id_magFisico = " + CR.getId_magFisico());
if (CR.getId_clifor() > 0L)
wc.addWc(" A.id_clifor = " + CR.getId_clifor());
try {
PreparedStatement stmt = getConn()
.prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Group + s_Sql_Having);
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public ResParm saveMagSuRIgaDocumento() {
RigaDocumento bean = this;
ResParm rp = new ResParm(true);
if (bean.getId_articolo() != 0L) {
long magPartenza = 0L;
long magArrivo = 0L;
long flgInternoPartenza = 0L;
long flgInternoArrivo = 0L;
if (bean.getDocumento().getId_magFisicoPartenza() == 0L) {
if (bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoPartenza() > 0L) {
magPartenza = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoPartenza();
flgInternoPartenza = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getMagFisicoPartenza().getFlgTipo();
}
} else {
magPartenza = bean.getDocumento().getId_magFisicoPartenza();
flgInternoPartenza = bean.getDocumento().getMagFisicoPartenza().getFlgTipo();
}
if (bean.getDocumento().getId_magFisicoArrivo() == 0L) {
if (bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoArrivo() > 0L) {
magArrivo = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoArrivo();
flgInternoArrivo = bean.getDocumento().getTipoDocumento().getCausaleMagazzino().getMagFisicoArrivo().getFlgTipo();
}
} else {
magArrivo = bean.getDocumento().getId_magFisicoArrivo();
flgInternoArrivo = bean.getDocumento().getMagFisicoArrivo().getFlgTipo();
}
if (magPartenza != 0L) {
long segnoMov = -1L;
if (bean.getFlgReso() == 1L)
segnoMov = 1L;
bean.setSegnoMov(segnoMov);
bean.setId_causaleMagazzino(bean.getDocumento().getTipoDocumento().getId_causaleMagazzino());
bean.setId_magFisico(magPartenza);
if (flgInternoPartenza == 1L) {
bean.setId_clifor(0L);
} else {
bean.setId_clifor(bean.getDocumento().getId_clifor());
}
rp = bean.superSave();
}
if (rp.getStatus() && magArrivo != 0L) {
long segnoMov = 1L;
if (bean.getFlgReso() == 1L)
segnoMov = -1L;
if (magPartenza == 0L) {
bean.setSegnoMov(segnoMov);
bean.setId_causaleMagazzino(bean.getDocumento().getTipoDocumento().getId_causaleMagazzino());
bean.setId_magFisico(magArrivo);
if (flgInternoArrivo == 1L) {
bean.setId_clifor(0L);
} else {
bean.setId_clifor(bean.getDocumento().getId_clifor());
}
rp = bean.superSave();
} else {
try {
RigaDocumento rd2 = (RigaDocumento)bean.clone();
rd2.setDBState(0);
rd2.setId_rigaDocumento(0L);
rd2.setId_rigaDocumentoMov(bean.getId_rigaDocumento());
rd2.setSegnoMov(segnoMov);
rd2.setId_magFisico(magArrivo);
if (flgInternoArrivo == 1L) {
rd2.setId_clifor(0L);
} else {
rd2.setId_clifor(bean.getDocumento().getId_clifor());
}
rd2.setId_rigaDocumentoMov(bean.getId_rigaDocumento());
rp = bean.superSave();
} catch (Exception e) {
bean.handleDebug(e, 0);
rp.setException(e);
}
}
}
}
return rp;
}
public Vectumerator findByCRCompatto(RigaDocumentoCR CR, int pageNumber, int pageRows) {
boolean flgOttimizzo = (getParm("OTTIMIZZO").getNumero() == 1.0D);
StringBuffer s_Sql_Find = new StringBuffer("select A.id_articolo, A.id_articoloVariante, A.id_articoloTaglia, sum(A.kg*segnoMov) as Kg,sum(A.mt*segnoMov) as mt, sum(A.nr*segnoMov) as nr, D.nome, D.codice from RIGA_DOCUMENTO AS A, DOCUMENTO AS C, ARTICOLO AS D ");
String s_Sql_Order = " order by D.nome,D.codice";
if (CR.getFlgOrderBy() == 1L)
s_Sql_Order = " order by C.dataDocumento asc, C.id_esercizio asc, C.progDocumento asc";
String s_Sql_groupby = " group by A.id_articolo";
WcString wc = new WcString();
findByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt;
if ((pageNumber == 0 && pageRows == 0) || !flgOttimizzo) {
stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString() + s_Sql_groupby);
} else {
if (pageNumber == 0)
pageNumber = 1;
int start = (pageNumber - 1) * pageRows;
int stop = start + pageRows;
stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString() + s_Sql_groupby + " limit " + s_Sql_Order + "," + start);
}
findByCRCreateStmtDate(CR, stmt);
if ((pageNumber == 0 && pageRows == 0) || !flgOttimizzo)
return findRows(stmt, pageNumber, pageRows);
Vectumerator vec = findRows(stmt, 1, pageRows);
vec.setPageNumber(pageNumber);
vec.setTotNumberOfRecords(findByCRTotRecord(CR));
return vec;
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
protected void findByCRCreateStmtDate(RigaDocumentoCR CR, PreparedStatement stmt) {
try {
int dataCount = 0;
if (CR.getDataDocumentoDa() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataDocumentoDa());
}
if (CR.getDataDocumentoA() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataDocumentoA());
}
if (CR.getDataRiferimentoDa() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataRiferimentoDa());
}
if (CR.getDataRiferimentoA() != null) {
dataCount++;
stmt.setDate(dataCount, CR.getDataRiferimentoA());
}
} catch (SQLException e) {
handleDebug(e);
}
}
private void findByCRCreateWC(RigaDocumentoCR CR, StringBuffer s_Sql_Find, WcString wc) {
wc.addWc("A.id_documento=C.id_documento");
wc.addWc("C.id_tipoDocumento=TD.id_tipoDocumento ");
wc.addWc("TD.id_tipologiaDocumento=T.id_tipologiaDocumento ");
if (CR.getFlgRicercaMag() == RigaDocumentoCR.RICERCA_SOLO_RIGHE_DOC) {
wc.addWc("(A.id_rigaDocumentoMov=0 or A.id_rigaDocumentoMov is null)");
} else if (CR.getFlgRicercaMag() == RigaDocumentoCR.RICERCA_SOLO_MAGAZZINO) {
wc.addWc("A.id_magFisico>0");
}
if (!CR.getSearchTxt().isEmpty()) {
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = prepareSqlString(st.nextToken());
txt.append("(C.nominativoDocumento like '%" + token + "%' or D.nome like '%" + token + "%' )");
if (st.hasMoreTokens())
txt.append(" and ");
}
txt.append(")");
wc.addWc(txt.toString());
}
if (CR.getId_articoloVariante() != 0L) {
wc.addWc("A.id_articoloVariante=" + CR.getId_articoloVariante());
} else if (CR.getId_articolo() != 0L) {
wc.addWc("A.id_articolo=" + CR.getId_articolo());
}
if (CR.getId_tipoDocumento() > 0L)
wc.addWc("C.id_tipoDocumento=" + CR.getId_tipoDocumento());
if (CR.getId_esercizio() > 0L)
wc.addWc("year(C.dataDocumento)=" + CR.getId_esercizio());
if (!CR.getRiferimento().isEmpty())
wc.addWc("C.riferimento like '%" + CR.getRiferimento() + "%'");
if (CR.getId_clifor() > 0L)
wc.addWc("C.id_clifor=" + CR.getId_clifor());
if (CR.getId_magFisico() > 0L)
wc.addWc("A.id_magFisico=" + CR.getId_magFisico());
if (CR.getId_tipo() != 0L) {
s_Sql_Find.append(" , TIPO AS E");
wc.addWc("D.id_tipo=E.id_tipo");
wc.addWc("(D.id_tipo=" + CR.getId_tipo() + " or E.indici like'%:" + CR.getId_tipo() + ":%')");
}
if (CR.getId_marca() != 0L)
wc.addWc("D.id_marca=" + CR.getId_marca());
if (CR.getFlgStatoPrenotazione() == 0L) {
wc.addWc("(C.flgStatoPrenotazione is null or C.flgStatoPrenotazione=0)");
} else if (CR.getFlgStatoPrenotazione() == 200L) {
wc.addWc("(C.flgStatoPrenotazione is null or C.flgStatoPrenotazione=0 or C.flgStatoPrenotazione <90)");
} else if (CR.getFlgStatoPrenotazione() > 0L) {
wc.addWc("C.flgStatoPrenotazione =" + CR.getFlgStatoPrenotazione());
}
if (CR.getFlgTipologia() > 0L)
if (CR.getFlgTipologia() == 100L) {
wc.addWc("C.id_tipoDocumento=1");
} else if (CR.getFlgTipologia() == 20L) {
wc.addWc("(T.codice=1 OR T.codice=2)");
wc.addWc("C.id_tipoDocumento<>1");
} else if (CR.getFlgTipologia() == 1L) {
wc.addWc("T.codice=" + CR.getFlgTipologia());
wc.addWc("C.id_tipoDocumento<>1");
} else {
wc.addWc("T.codice=" + CR.getFlgTipologia());
}
if (CR.getFlgRigaPrelevata() == 0L) {
wc.addWc("(A.flgRigaPrelevata is null or A.flgRigaPrelevata=0)");
} else if (CR.getFlgRigaPrelevata() > 0L) {
wc.addWc("A.flgRigaPrelevata=" + CR.getFlgRigaPrelevata());
}
if (CR.getFlgDaCancellare() == 0L) {
wc.addWc("(A.flgDaCancellare is null or A.flgDaCancellare=0)");
} else if (CR.getFlgDaCancellare() > 0L) {
wc.addWc("A.flgDaCancellare=" + CR.getFlgDaCancellare());
}
if (!CR.getSeriale().isEmpty()) {
String temp = CR.getSeriale();
temp = temp.replace("%", "\\%");
temp = temp.replace("_", "\\_");
temp = temp.replace("*", "%");
wc.addWc("A.seriale like '" + CR.getSeriale() + "'");
}
if (!CR.getRiferimento().isEmpty())
wc.addWc("C.riferimento like '%" + CR.getRiferimento() + "%'");
if (!CR.getDescrizioneCodiceRiga().isEmpty())
wc.addWc("A.descrizioneCodiceRiga like '%" + CR.getDescrizioneCodiceRiga() + "%'");
if (CR.getDataDocumentoDa() != null)
wc.addWc("C.dataDocumento>=?");
if (CR.getDataDocumentoA() != null)
wc.addWc("C.dataDocumento<=?");
if (CR.getDataRiferimentoDa() != null)
wc.addWc("C.dataRiferimento>=?");
if (CR.getDataRiferimentoA() != null)
wc.addWc("C.dataRiferimento<=?");
}
private int findByCRTotRecord(RigaDocumentoCR CR) {
StringBuffer s_Sql_Find = new StringBuffer("select count(*) as tot from RIGA_DOCUMENTO AS A, DOCUMENTO AS C, ARTICOLO AS D ");
WcString wc = new WcString();
findByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find));
findByCRCreateStmtDate(CR, stmt);
return (int)getTots(stmt);
} catch (Exception e) {
handleDebug(e);
return 0;
}
}
public String getCodiceArticolo() {
return getArticolo().getCodice();
}
public String getDescrizioneArticolo() {
if (getId_articoloTaglia() != 0L)
return getArticoloTaglia().getDescrizioneCompleta();
if (getId_articoloVariante() == 0L)
return getArticolo().getDescrizioneCompleta();
return getArticoloVariante().getDescrizioneCompleta();
}
public double getKgS() {
return this.kg * (double)getSegnoMov();
}
public double getMtS() {
return this.mt * (double)getSegnoMov();
}
public double getNrS() {
return this.nr * (double)getSegnoMov();
}
public long getId_rigaDocumentoPrelevata() {
return this.id_rigaDocumentoPrelevata;
}
public RigaDocumento getRigaDocumentoPrelevata() {
this.rigaDocumentoPrelevata = (RigaDocumento)getSecondaryObject(this.rigaDocumentoPrelevata, RigaDocumento.class,
getId_rigaDocumentoPrelevata());
return this.rigaDocumentoPrelevata;
}
public void setId_rigaDocumentoPrelevata(long newId_rigaDocumentoPrelevata) {
this.id_rigaDocumentoPrelevata = newId_rigaDocumentoPrelevata;
setRigaDocumentoPrelevata(null);
}
public void setRigaDocumentoPrelevata(RigaDocumento newRigaDocumentoPrelevata) {
this.rigaDocumentoPrelevata = newRigaDocumentoPrelevata;
}
public ResParm saveMov() {
ResParm rp = superSave();
if (rp.getStatus())
rp = aggiornaDispo();
return rp;
}
public void creaFileCvsMov(RigaDocumentoCR CR) {
if (CR.getFlgReport().equals("S") && CR.getFlgTipoReport() == 1L) {
creaFileCvsCompattoMov(CR);
} else {
try {
Vectumerator<RigaDocumento> list = findByCR(CR, 0, 0);
CR.setFileName(getPathTmp() + "movMagazzino_" + getPathTmp() + ".csv");
String theCvsFile = getDocBase() + getDocBase();
String SEP = ";";
new File(theCvsFile).delete();
FileWr outCvsFile = new FileWr(theCvsFile, false);
String s1 = "Operatore;Documento;Intestazione;Data;Cod. Articolo;Articolo;Seriale;Disp.Art.;Tipo Movimento;Magazzini;Q.ta;Kg;Mt;Nr.";
outCvsFile.writeLine(CR.getDescrizioneCR());
outCvsFile.writeLine(s1);
while (list.hasMoreElements()) {
RigaDocumento row = (RigaDocumento)list.nextElement();
s1 = row.getDocumento().getUsers().getCognomeNome() + row.getDocumento().getUsers().getCognomeNome() + "\"" + SEP + "\"" + row.getDocumento().getNumeroDocumentoCompleto() + SEP + row.getDocumento().getClifor().getDescrizioneCompleta() + SEP + getDataFormat().format(row.getDocumento().getDataDocumento()) + SEP + row.getCodiceArticolo() + SEP + row.getDescrizioneRigaCompleta() + SEP + row.getSeriale() + SEP + getNf().format(row.getArticolo().getQuantita()) + SEP + row.getDocumento().getTipoDocumento().getCausaleMagazzino().getDescrizione() + SEP + row.getMagFisico().getDescrizione() + SEP + getNf().format(row.getQuantita()) + SEP + getNf().format(row.getKg()) + SEP + getNf().format(row.getMt()) + SEP;
s1 = s1.replace("&euro;", "");
s1 = s1.replace("&raquo;", "-->");
outCvsFile.writeLine(s1);
}
outCvsFile.closeFile();
} catch (Exception e) {
handleDebug(e);
}
}
}
public void creaFileCvsCompattoMov(RigaDocumentoCR CR) {
try {
Vectumerator<RigaDocumento> list = findByCRCompatto(CR, 0, 0);
CR.setFileName(getPathTmp() + "movMagazzinoCompatto_" + getPathTmp() + ".csv");
String theCvsFile = getDocBase() + getDocBase();
String SEP = ";";
new File(theCvsFile).delete();
FileWr outCvsFile = new FileWr(theCvsFile, false);
String s1 = "Cod. Articolo;Articolo;Tipo;Disp.Art.;Q.ta;Kg;Mt;Nr.";
outCvsFile.writeLine(CR.getDescrizioneCR());
outCvsFile.writeLine(s1);
while (list.hasMoreElements()) {
RigaDocumento row = (RigaDocumento)list.nextElement();
s1 = row.getCodiceArticolo() + row.getCodiceArticolo() + SEP + row.getDescrizioneArticolo() + SEP + row.getArticolo().getTipo().getDescrizioneCompleta() + SEP + getNf().format(row.getArticolo().getQuantita()) + SEP + getNf().format(row.getQuantita()) + SEP + getNf().format(row.getKg()) + SEP + getNf().format(row.getMt()) + SEP;
s1 = s1.replace("&euro;", "");
s1 = s1.replace("&raquo;", "-->");
outCvsFile.writeLine(s1);
}
outCvsFile.closeFile();
} catch (Exception e) {
handleDebug(e);
}
}
public ResParm deleteM() {
synchronized (this) {
if (getId_articolo() > 0L && getDocumento().getTipoDocumento().getCausaleMagazzino().getFlgCaricoArrivo() > 0L) {
Movimento mov = new Movimento(getApFull());
mov.findDisponibilitaPuntualeMagazziniInterni(getId_articolo(), getId_articoloVariante(), getId_articoloTaglia(),
getSeriale(), 0L);
if (mov.getQuantita() < getQuantita())
return new ResParm(false, "ERRORE! Quantità non più disponibile in magazzino. E' stato effettuato uno scarico!");
RigaDocumento rd = new RigaDocumento(getApFull());
rd.findRigaImpegnoBySeriale(getId_articolo(), getId_articoloVariante(), getSeriale());
if (rd.getDBState() == 1)
return new ResParm(false, "ERRORE! Esiste una prenotazione per questo seriale!");
}
RigaDocumento bean = (RigaDocumento)clone();
Vectumerator vec = new RigaDocumentoP(getApFull()).findByRigaDocumento(getId_rigaDocumento(), 0, 0);
while (vec.hasMoreElements()) {
DbInterface row = (DbInterface)vec.nextElement();
row.delete();
}
if (getDocumento().getTipoDocumento().getFlgTipologia() == 3L) {
RigaDocumentoPM rdPM = new RigaDocumentoPM(getApFull());
rdPM.findByRigaDocumento(getId_rigaDocumento());
if (rdPM.getDBState() == 1)
rdPM.delete();
}
if (getDocumento().getTipoDocumento().getFlgTipologia() == 4L) {
RigaDocumentoPM rdPM = new RigaDocumentoPM(getApFull());
vec = rdPM.findByRigaDocumentoPrelevata(getId_rigaDocumento());
while (vec.hasMoreElements()) {
DbInterface row = (DbInterface)vec.nextElement();
row.delete();
}
}
cancellaMovimento(bean, 0L, 0L);
Movimento.aggiornaDispo(getApFull(), getId_articolo(), getId_articoloVariante(), getId_articoloTaglia(),
getLastUpdId_user());
ResParm rp = super.delete();
if (rp.getStatus()) {
if (bean.getId_rigaDocumentoPadre() != 0L) {
RigaDocumento beanPadre = new RigaDocumento(getApFull());
beanPadre.findByPrimaryKey(bean.getId_rigaDocumentoPadre());
beanPadre.setFlgRigaPrelevata(0L);
rp = beanPadre.save();
Documento doc = new Documento(getApFull());
doc.findByPrimaryKey(beanPadre.getId_documento());
doc.setDataChiusura(null);
doc.setFlgDocumentoPrelevato(0L);
doc.save();
}
if (bean.getDocumento().getTipoDocumento().getId_causaleMagazzino() > 0L ||
bean.getDocumento().getTipoDocumento().getFlgTipologia() == 4L)
bean.checkStatoPrenotazione();
}
return rp;
}
}
public static ResParm aggiornaDispo(ApplParmFull ap, long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia, long l_id_users) {
ResParm rp = new ResParm(true);
if (l_id_articolo != 0L || l_id_articoloVariante != 0L || l_id_articoloTaglia != 0L) {
RigaDocumento rigaDocumento = new RigaDocumento(ap);
rigaDocumento.findMagDisponibilitaPuntualeMagazziniInterni(l_id_articolo, l_id_articoloVariante, l_id_articoloTaglia, "", 0L);
Articolo art = new Articolo(ap);
art.findByPrimaryKey(l_id_articolo);
art.resetCalcoloQuantita();
if (art.getTipo().getFlgTipoMagazzino() == 0L || art.getTipo().getFlgTipoMagazzino() == 9L) {
System.out.println("ATTENZIONE!!!!aggiornaDispo");
art.setFlgDispo(1L);
} else {
if (l_id_articoloTaglia > 0L) {
ArticoloTaglia bean = new ArticoloTaglia(ap);
bean.findByPrimaryKey(l_id_articoloTaglia);
bean.resetCalcoloQuantita();
}
if (l_id_articoloVariante > 0L) {
ArticoloVariante bean = new ArticoloVariante(ap);
bean.findByPrimaryKey(l_id_articoloVariante);
bean.resetCalcoloQuantita();
}
art.setFlgDispo((rigaDocumento.getQuantita() > 0.0D) ? 1L : 0L);
}
art.save();
rigaDocumento.resetStatoPrenotazioneByArticolo(l_id_articolo, l_id_articoloVariante, l_id_articoloTaglia);
}
return rp;
}
public void getMagQuantitaPrelevatoByRigaDocumentoPrelevata(long l_id_rigaDocumento) {
String s_Sql_Find = "select SUM(nr) as nr, SUM(kg) as kg, SUM(mt) as mt from RIGA_DOCUMENTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.id_rigaDocumentoMov>0");
wc.addWc("A.id_rigaDocumentoPrelevata=" + l_id_rigaDocumento);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public void getMagQuantitaPrelevatoByRigaDocumento(long l_id_rigaDocumento) {
String s_Sql_Find = "select SUM(nr) as nr, SUM(kg) as kg, SUM(mt) as mt from RIGA_DOCUMENTO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.id_rigaDocumentoMov>0");
wc.addWc("A.id_rigaDocumento=" + l_id_rigaDocumento);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public Vectumerator<RigaDocumento> findRigheReportArticoliCsv(DocumentoCR CR) {
String s_Sql_Order;
Documento doc = new Documento(getApFull());
StringBuffer s_Sql_Find = new StringBuffer("select B.* from DOCUMENTO AS A ");
if (CR.getTipoDocumento().getFlgClienteFornitore().equals("F") && (
CR.getTipoDocumento().getFlgTipologia() == 1L ||
CR.getTipoDocumento().getFlgTipologia() == 2L)) {
if (CR.getFlgOrderBy() == 1L) {
s_Sql_Order = " order by A.dataRiferimento asc, A.id_esercizio asc, A.progDocumento asc";
} else {
s_Sql_Order = " order by A.dataRiferimento desc, A.id_esercizio desc, A.progDocumento desc";
}
} else if (CR.getFlgOrderBy() == 1L) {
s_Sql_Order = " order by A.dataDocumento asc, A.id_esercizio asc, A.progDocumento asc";
} else {
s_Sql_Order = " order by A.dataDocumento desc, A.id_esercizio desc, A.progDocumento desc";
}
WcString wc = new WcString();
doc.findByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString());
doc.findByCRCreateStmtDate(CR, stmt);
return findRows(stmt);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public ResParm superDelete() {
ResParm rp = getDocumento().checkEMSTA();
if (!rp.getStatus()) {
rp.setInfoMsg(rp.getMsg());
return rp;
}
return super.delete();
}
public long getId_articoloFilatoColore() {
return this.id_articoloFilatoColore;
}
public void setId_articoloFilatoColore(long id_articoloFilatoColore) {
this.id_articoloFilatoColore = id_articoloFilatoColore;
setArticoloFilatoColore(null);
}
public ArticoloFilatoColoreRitorto getArticoloFilatoColoreRitorto() {
this.articoloFilatoColoreRitorto = (ArticoloFilatoColoreRitorto)getSecondaryObject(this.articoloFilatoColoreRitorto, ArticoloFilatoColoreRitorto.class,
getId_articoloFilatoColoreRitorto());
return this.articoloFilatoColoreRitorto;
}
public void setArticoloFilatoColore(ArticoloFilatoColore articoloFilatoColore) {
this.articoloFilatoColore = articoloFilatoColore;
}
public long getId_pezza() {
return this.id_pezza;
}
public void setId_pezza(long id_pezza) {
this.id_pezza = id_pezza;
}
public Pezza getPezza() {
return this.pezza;
}
public void setPezza(Pezza pezza) {
this.pezza = pezza;
}
public long getId_faseLavorazione() {
return this.id_faseLavorazione;
}
public void setId_faseLavorazione(long id_faseLavorazione) {
this.id_faseLavorazione = id_faseLavorazione;
}
public FaseLavorazione getFaseLavorazione() {
return this.faseLavorazione;
}
public void setFaseLavorazione(FaseLavorazione faseLavorazione) {
this.faseLavorazione = faseLavorazione;
}
public void findMagDisponibilita(long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia, String l_seriale, long l_tipologia_magfisico, long l_id_clifor, Date dataA) {
boolean guidoreni = false;
if (!guidoreni) {
String s_Sql_Sum = " SUM(A.kg*segnoMov) as kg, SUM(A.mt*segnoMov) as mt, SUM(A.nr*segnoMov) as nr from RIGA_DOCUMENTO AS A ";
String s_Sql_colonne = "";
String s_Sql_join = "";
WcString wc = new WcString();
wc.addWc("A.id_magFisico>0");
if (l_id_articolo != 0L) {
wc.addWc(" A.id_articolo = " + l_id_articolo);
s_Sql_colonne = s_Sql_colonne + " A.id_articolo,";
}
if (l_id_articoloVariante != 0L) {
wc.addWc(" A.id_articoloVariante = " + l_id_articoloVariante);
s_Sql_colonne = s_Sql_colonne + " A.id_articoloVariante,";
}
if (l_id_articoloTaglia != 0L) {
wc.addWc(" A.id_articoloTaglia = " + l_id_articoloTaglia);
s_Sql_colonne = s_Sql_colonne + " A.id_articoloTaglia,";
}
if (l_seriale != null && !l_seriale.isEmpty()) {
wc.addWc(" A.seriale = " + l_seriale);
s_Sql_colonne = s_Sql_colonne + " A.seriale,";
}
if (l_id_clifor != 0L) {
wc.addWc(" A.id_clifor = " + l_id_clifor);
s_Sql_colonne = s_Sql_colonne + " A.id_clifor,";
}
if (dataA != null) {
s_Sql_join = " INNER JOIN DOCUMENTO AS DOC ON A.id_documento=DOC.id_documento ";
wc.addWc(" DOC.dataDocumento <= ?");
s_Sql_Sum = s_Sql_Sum + s_Sql_Sum;
}
if (l_tipologia_magfisico != 0L) {
wc.addWc(" B.flgTipo = " + l_tipologia_magfisico);
s_Sql_Sum = s_Sql_Sum + " , MAG_FISICO AS B";
wc.addWc(" A.id_magFisico = B.id_magFisico ");
}
String s_sql_groupby = "";
if (!s_Sql_colonne.isEmpty())
s_sql_groupby = " group by " + s_Sql_colonne.substring(0, s_Sql_colonne.length() - 1);
try {
PreparedStatement stmt = getConn()
.prepareStatement("select " + s_Sql_colonne + s_Sql_Sum + wc.toString() + s_sql_groupby);
if (dataA != null)
stmt.setDate(1, dataA);
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
}
public void findMagFilatoDisponibilitaPuntuale(long l_id_articoloFilatoColore, long l_id_articoloFilato, long l_id_coloreFilato, String l_seriale, long l_id_magfisico, long l_id_clifor, long flgTipoRicerca, String l_flgCliFor) {
String s_Sql_Sum = " SUM(segnoMov*kg) as kg, SUM(segnoMov*mt) as mt, SUM(segnoMov*nr) as nr from RIGA_DOCUMENTO AS A";
String s_Sql_colonne = "";
WcString wc = new WcString();
if (flgTipoRicerca == 0L)
wc.addWc("A.id_magFisico>0");
if (l_id_articoloFilato > 0L || l_id_coloreFilato > 0L)
s_Sql_Sum = s_Sql_Sum + " inner join ARTICOLO_FILATO_COLORE AS F ON A.id_articoloFilatoColore=F.id_articoloFilatoColore";
if (!l_flgCliFor.isEmpty())
s_Sql_Sum = s_Sql_Sum + " inner join CLIFOR AS CF ON A.id_clifor=CF.id_clifor";
if (l_id_articoloFilatoColore != 0L) {
wc.addWc(" A.id_articoloFilatoColore = " + l_id_articoloFilatoColore);
s_Sql_colonne = s_Sql_colonne + " A.id_articoloFilatoColore,";
}
if (l_id_articoloFilato != 0L) {
wc.addWc(" F.id_articoloFilato = " + l_id_articoloFilato);
s_Sql_colonne = s_Sql_colonne + " F.id_articoloFilato,";
}
if (l_id_coloreFilato != 0L) {
wc.addWc(" F.id_coloreFilato = " + l_id_coloreFilato);
s_Sql_colonne = s_Sql_colonne + " F.id_coloreFilato,";
}
if (l_id_magfisico != 0L) {
wc.addWc(" id_magFisico = " + l_id_magfisico);
s_Sql_colonne = s_Sql_colonne + " id_magFisico,";
}
if (!l_flgCliFor.isEmpty()) {
wc.addWc(" A.id_clifor='" + l_flgCliFor + "'");
s_Sql_colonne = s_Sql_colonne + " A.id_clifor,";
}
StringBuilder mf = new StringBuilder("");
if (flgTipoRicerca > 0L && l_id_magfisico == 0L) {
MagFisico mag = new MagFisico(getApFull());
if (flgTipoRicerca == 1L || flgTipoRicerca == 3L) {
Vectumerator<MagFisico> vecMag = mag.findByTipo(1L);
if (vecMag.hasMoreElements())
while (vecMag.hasMoreElements()) {
mag = (MagFisico)vecMag.nextElement();
if (mf.length() > 0)
mf.append(" OR ");
mf.append(" id_magFisico = " + mag.getId_magFisico());
}
}
if (flgTipoRicerca == 2L || flgTipoRicerca == 3L) {
Vectumerator<MagFisico> vecMag = mag.findByTipo(2L);
if (vecMag.hasMoreElements())
while (vecMag.hasMoreElements()) {
mag = (MagFisico)vecMag.nextElement();
if (mf.length() > 0)
mf.append(" OR ");
mf.append(" id_magFisico = " + mag.getId_magFisico());
}
}
}
if (mf.length() > 0) {
mf.append(")");
wc.addWc("(" + mf.toString());
s_Sql_colonne = s_Sql_colonne + " id_magFisico,";
}
if (l_seriale != null && !l_seriale.isEmpty()) {
wc.addWc(" seriale = '" + l_seriale + "'");
s_Sql_colonne = s_Sql_colonne + " seriale,";
}
if (l_id_clifor != 0L) {
wc.addWc(" id_clifor = " + l_id_clifor);
s_Sql_colonne = s_Sql_colonne + " id_clifor,";
}
String s_sql_groupby = "";
if (!s_Sql_colonne.isEmpty())
s_sql_groupby = " group by " + s_Sql_colonne.substring(0, s_Sql_colonne.length() - 1);
try {
PreparedStatement stmt = getConn()
.prepareStatement("select " + s_Sql_colonne + s_Sql_Sum + wc.toString() + s_sql_groupby);
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public void findMagFisicoDisponibilita(long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia, String l_seriale, long l_id_magFisico, long l_id_clifor, Date dataA) {
boolean guidoreni = false;
if (!guidoreni) {
String s_Sql_Sum = " SUM(A.kg*segnoMov) as kg, SUM(A.mt*segnoMov) as mt, SUM(A.nr*segnoMov) as nr from RIGA_DOCUMENTO AS A ";
String s_Sql_colonne = "";
String s_Sql_join = "";
WcString wc = new WcString();
if (l_id_articolo != 0L) {
wc.addWc(" A.id_articolo = " + l_id_articolo);
s_Sql_colonne = s_Sql_colonne + " A.id_articolo,";
}
if (l_id_articoloVariante != 0L) {
wc.addWc(" A.id_articoloVariante = " + l_id_articoloVariante);
s_Sql_colonne = s_Sql_colonne + " A.id_articoloVariante,";
}
if (l_id_articoloTaglia != 0L) {
wc.addWc(" A.id_articoloTaglia = " + l_id_articoloTaglia);
s_Sql_colonne = s_Sql_colonne + " A.id_articoloTaglia,";
}
if (l_seriale != null && !l_seriale.isEmpty()) {
wc.addWc(" A.seriale = " + l_seriale);
s_Sql_colonne = s_Sql_colonne + " A.seriale,";
}
if (l_id_clifor != 0L) {
wc.addWc(" A.id_clifor = " + l_id_clifor);
s_Sql_colonne = s_Sql_colonne + " A.id_clifor,";
}
if (dataA != null) {
s_Sql_join = " INNER JOIN DOCUMENTO AS DOC ON A.id_documento=DOC.id_documento ";
wc.addWc(" DOC.dataDocumento <= ?");
s_Sql_Sum = s_Sql_Sum + s_Sql_Sum;
}
if (l_id_magFisico != 0L) {
wc.addWc(" A.id_magFisico = " + l_id_magFisico);
s_Sql_colonne = s_Sql_colonne + " A.id_magFisico,";
} else {
wc.addWc("A.id_magFisico>0");
}
String s_sql_groupby = "";
if (!s_Sql_colonne.isEmpty())
s_sql_groupby = " group by " + s_Sql_colonne.substring(0, s_Sql_colonne.length() - 1);
try {
PreparedStatement stmt = getConn()
.prepareStatement("select " + s_Sql_colonne + s_Sql_Sum + wc.toString() + s_sql_groupby);
if (dataA != null)
stmt.setDate(1, dataA);
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
}
public Vectumerator findMagSaldiArticoloVarianteTagliaByCR(RigaDocumentoCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select B.id_articolo, C.id_articoloVariante,T.id_articoloTaglia , SUM(A.kg*segnoMov) as kg, SUM(A.mt*segnoMov) as mt, SUM(A.nr*segnoMov) as nr from ARTICOLO AS B LEFT JOIN ARTICOLO_VARIANTE AS C ON B.id_articolo=C.id_articolo LEFT JOIN ARTICOLO_TAGLIA AS T ON T.id_articolo=T.id_articolo LEFT JOIN RIGA_DOCUMENTO AS A ON A.id_articolo=B.id_articolo and A.id_articoloVariante=C.id_articoloVariante and A.id_articoloTaglia=T.id_articoloTaglia left JOIN MAG_FISICO AS D ON A.id_magFisico=D.id_magFisico ";
if (CR.getFlgTipoMagazzino() > 0L)
s_Sql_Find = s_Sql_Find + " and D.flgTipo = " + s_Sql_Find;
String s_Sql_Group = " group by B.id_articolo, C.id_articoloVariante,T.id_articoloTaglia";
String s_Sql_Order = " order by B.nome, C.nomeV, A.id_articoloTaglia ";
String s_Sql_Having = "";
if (CR.getFlgInMagazzino() == 1L) {
s_Sql_Having = " Having SUM(A.kg*segnoMov) > 0 OR SUM(A.mt*segnoMov) > 0 OR SUM(A.nr*segnoMov) > 0 ";
} else if (CR.getFlgInMagazzino() == 2L) {
s_Sql_Having = " Having SUM(A.kg*segnoMov) < 0 OR SUM(A.mt*segnoMov) < 0 OR SUM(A.nr*segnoMov) < 0 ";
}
WcString wc = new WcString();
wc.addWc("A.id_magFisico>0");
if (!CR.getSearchTxt().isEmpty() && !CR.getSearchTxt().equals("*")) {
String star = "";
String temp = CR.getSearchTxt();
temp = prepareInputMySqlString(temp, true);
temp = temp.replace("*", "%");
StringTokenizer st = new StringTokenizer(temp.trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = star + star;
txt.append("(B.codice like '" + token + "%' or B.nome like '" + token + "%' or B.codiceProduttore like '" + token + "%' or B.codiciAlternativi like '%," + token + "%')");
if (st.hasMoreTokens()) {
txt.append(" and ");
star = "%";
}
}
txt.append(")");
wc.addWc(txt.toString());
}
if (CR.getId_articolo() > 0L)
wc.addWc("B.id_articolo = " + CR.getId_articolo());
if (CR.getId_articoloVariante() > 0L)
wc.addWc("C.id_articoloVariante = " + CR.getId_articoloVariante());
if (CR.getId_magFisico() > 0L)
wc.addWc(" A.id_magFisico = " + CR.getId_magFisico());
if (CR.getId_clifor() > 0L)
wc.addWc(" A.id_clifor = " + CR.getId_clifor());
try {
PreparedStatement stmt = getConn()
.prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Group + s_Sql_Having);
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator findMagSaldiArticoloVarianteByCR(RigaDocumentoCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select B.id_articolo, C.id_articoloVariante , SUM(A.kg*segnoMov) as kg, SUM(A.mt*segnoMov) as mt, SUM(A.nr*segnoMov) as nr from ARTICOLO AS B LEFT JOIN ARTICOLO_VARIANTE AS C ON B.id_articolo=C.id_articolo LEFT JOIN RIGA_DOCUMENTO AS A ON A.id_articolo=B.id_articolo and A.id_articoloVariante=C.id_articoloVariante left JOIN MAG_FISICO AS D ON A.id_magFisico=D.id_magFisico ";
if (CR.getFlgTipoMagazzino() > 0L)
s_Sql_Find = s_Sql_Find + " and D.flgTipo = " + s_Sql_Find;
String s_Sql_Group = " group by B.id_articolo, C.id_articoloVariante, A.id_articoloTaglia";
String s_Sql_Order = " order by B.nome, C.nomeV, A.id_articoloTaglia ";
String s_Sql_Having = "";
if (CR.getFlgInMagazzino() == 1L) {
s_Sql_Having = " Having SUM(A.kg*segnoMov) > 0 OR SUM(A.mt*segnoMov) > 0 OR SUM(A.nr*segnoMov) > 0 ";
} else if (CR.getFlgInMagazzino() == 2L) {
s_Sql_Having = " Having SUM(A.kg*segnoMov) < 0 OR SUM(A.mt*segnoMov) < 0 OR SUM(A.nr*segnoMov) < 0 ";
}
WcString wc = new WcString();
wc.addWc("A.id_magFisico>0");
if (!CR.getSearchTxt().isEmpty() && !CR.getSearchTxt().equals("*")) {
String star = "";
String temp = CR.getSearchTxt();
temp = prepareInputMySqlString(temp, true);
temp = temp.replace("*", "%");
StringTokenizer st = new StringTokenizer(temp.trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = star + star;
txt.append("(B.codice like '" + token + "%' or B.nome like '" + token + "%' or B.codiceProduttore like '" + token + "%' or B.codiciAlternativi like '%," + token + "%')");
if (st.hasMoreTokens()) {
txt.append(" and ");
star = "%";
}
}
txt.append(")");
wc.addWc(txt.toString());
}
if (CR.getId_articolo() > 0L)
wc.addWc("B.id_articolo = " + CR.getId_articolo());
if (CR.getId_magFisico() > 0L)
wc.addWc(" A.id_magFisico = " + CR.getId_magFisico());
if (CR.getId_clifor() > 0L)
wc.addWc(" A.id_clifor = " + CR.getId_clifor());
try {
PreparedStatement stmt = getConn()
.prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Group + s_Sql_Having);
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator findMagSaldiArticoloTagliaByCR(RigaDocumentoCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select B.id_articolo, T.id_articoloTaglia , SUM(A.kg*segnoMov) as kg, SUM(A.mt*segnoMov) as mt, SUM(A.nr*segnoMov) as nr from ARTICOLO AS B LEFT JOIN ARTICOLO_TAGLIA AS T ON T.id_articolo=T.id_articolo LEFT JOIN RIGA_DOCUMENTO AS A ON A.id_articolo=B.id_articolo and A.id_articoloTaglia=T.id_articoloTaglia left JOIN MAG_FISICO AS D ON A.id_magFisico=D.id_magFisico ";
if (CR.getFlgTipoMagazzino() > 0L)
s_Sql_Find = s_Sql_Find + " and D.flgTipo = " + s_Sql_Find;
String s_Sql_Group = " group by B.id_articolo, T.id_articoloTaglia";
String s_Sql_Order = " order by B.nome, B.nome, A.id_articoloTaglia ";
String s_Sql_Having = "";
if (CR.getFlgInMagazzino() == 1L) {
s_Sql_Having = " Having SUM(A.kg*segnoMov) > 0 OR SUM(A.mt*segnoMov) > 0 OR SUM(A.nr*segnoMov) > 0 ";
} else if (CR.getFlgInMagazzino() == 2L) {
s_Sql_Having = " Having SUM(A.kg*segnoMov) < 0 OR SUM(A.mt*segnoMov) < 0 OR SUM(A.nr*segnoMov) < 0 ";
}
WcString wc = new WcString();
wc.addWc("A.id_magFisico>0");
if (!CR.getSearchTxt().isEmpty() && !CR.getSearchTxt().equals("*")) {
String star = "";
String temp = CR.getSearchTxt();
temp = prepareInputMySqlString(temp, true);
temp = temp.replace("*", "%");
StringTokenizer st = new StringTokenizer(temp.trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = star + star;
txt.append("(B.codice like '" + token + "%' or B.nome like '" + token + "%' or B.codiceProduttore like '" + token + "%' or B.codiciAlternativi like '%," + token + "%')");
if (st.hasMoreTokens()) {
txt.append(" and ");
star = "%";
}
}
txt.append(")");
wc.addWc(txt.toString());
}
if (CR.getId_articolo() > 0L)
wc.addWc("B.id_articolo = " + CR.getId_articolo());
if (CR.getId_magFisico() > 0L)
wc.addWc(" A.id_magFisico = " + CR.getId_magFisico());
if (CR.getId_clifor() > 0L)
wc.addWc(" A.id_clifor = " + CR.getId_clifor());
try {
PreparedStatement stmt = getConn()
.prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Group + s_Sql_Having);
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public static ResParm aggiornaDispoFilato(ApplParmFull ap, long l_id_articoloFilatoColore, long l_id_users) {
ResParm rp = new ResParm(true);
if (l_id_articoloFilatoColore != 0L) {
RigaDocumento rigaDocumento = new RigaDocumento(ap);
rigaDocumento.findMagFilatoDisponibilitaPuntualeMagazziniInterni(l_id_articoloFilatoColore, 0L, 0L, "");
ArticoloFilatoColore art = new ArticoloFilatoColore(ap);
art.findByPrimaryKey(l_id_articoloFilatoColore);
art.resetCalcoloQuantita();
art.setFlgDispo((rigaDocumento.getQuantita() > 0.0D) ? 1L : 0L);
art.setLastUpdId_user(l_id_users);
art.save();
ArticoloFilato af = art.getArticoloFilato();
af.resetCalcoloQuantita();
rigaDocumento.findMagFilatoDisponibilitaPuntualeMagazziniInterni(0L, af.getId_articoloFilato(), 0L, "");
af.setFlgDispo((rigaDocumento.getQuantita() > 0.0D) ? 1L : 0L);
af.setLastUpdId_user(l_id_users);
af.save();
}
return rp;
}
public long getId_articoloTessuto() {
return this.id_articoloTessuto;
}
public void setId_articoloTessuto(long id_articoloTessuto) {
this.id_articoloTessuto = id_articoloTessuto;
setArticoloTessuto(null);
}
public ArticoloTessuto getArticoloTessuto() {
this.articoloTessuto = (ArticoloTessuto)getSecondaryObject(this.articoloTessuto, ArticoloTessuto.class, getId_articoloTessuto());
return this.articoloTessuto;
}
public void setArticoloTessuto(ArticoloTessuto articoloTessuto) {
this.articoloTessuto = articoloTessuto;
}
public long getVolumeCm3ByDocumento(long l_id_documento) {
long volCM3 = 0L;
String s_Sql_Find = "select sum(B.volumeM3*1000000 +B.volumeCm3 )* A.quantita as _sum from RIGA_DOCUMENTO AS A left join ARTICOLO AS B on A.id_articolo=B.id_articolo ";
WcString wc = new WcString();
wc.addWc("(A.id_rigaDocumentoMov=0 or A.id_rigaDocumentoMov is null)");
wc.addWc("A.id_documento=" + l_id_documento);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
volCM3 = (long)getSum(stmt);
return volCM3;
} catch (Exception e) {
handleDebug(e, 0);
return 0L;
}
}
public long getPesoKgByDocumento(long l_id_documento) {
long volCM3 = 0L;
String s_Sql_Find = "select sum(B.pesoKg)* A.quantita as _sum from RIGA_DOCUMENTO AS A left join ARTICOLO AS B on A.id_articolo=B.id_articolo ";
WcString wc = new WcString();
wc.addWc("(A.id_rigaDocumentoMov=0 or A.id_rigaDocumentoMov is null)");
wc.addWc("A.id_documento=" + l_id_documento);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
volCM3 = (long)getSum(stmt);
return volCM3;
} catch (Exception e) {
handleDebug(e, 0);
return 0L;
}
}
public double getVolumeM3ByDocumento(long l_id_documento) {
DoubleOperator dop = new DoubleOperator((float)getVolumeCm3ByDocumento(l_id_documento));
dop.setScale(4, 5);
dop.divide(1000000.0F);
return dop.getResult();
}
public void findMagTessutoDisponibilita(long l_id_articoloTessuto, long l_id_articoloTessutoColore, String l_seriale, long l_id_magFisico, long l_tipologia_magfisico, long l_flgStatoLavorazione, long l_id_clifor, String l_flgCliFor, Date dataA) {
String s_Sql_Sum = " SUM(A.kg*segnoMov) as kg, SUM(A.mt*segnoMov) as mt, SUM(A.nr*segnoMov) as nr from RIGA_DOCUMENTO AS A inner join DOCUMENTO AS DOC ON A.id_documento=DOC.id_documento ";
String s_Sql_colonne = "";
String s_Sql_join = "";
WcString wc = new WcString();
if (l_tipologia_magfisico != 0L) {
s_Sql_Sum = s_Sql_Sum + " inner join MAG_FISICO AS B ON A.id_magFisico=B.id_magFisico";
s_Sql_colonne = s_Sql_colonne + " A.id_magFisico,";
wc.addWc(" B.flgTipo = " + l_tipologia_magfisico);
} else {
wc.addWc("A.id_magFisico>0");
}
if (l_id_articoloTessuto > 0L) {
s_Sql_Sum = s_Sql_Sum + " inner join ARTICOLO_TESSUTO AS F ON A.id_articoloTessuto=F.id_articoloTessuto";
s_Sql_colonne = s_Sql_colonne + " A.id_articoloTessuto,";
}
if (l_id_articoloTessuto != 0L) {
wc.addWc(" A.id_articoloTessuto = " + l_id_articoloTessuto);
s_Sql_colonne = s_Sql_colonne + " A.id_articoloTessuto,";
}
if (l_id_articoloTessutoColore != 0L) {
wc.addWc(" A.id_articoloTessutoColore = " + l_id_articoloTessutoColore);
s_Sql_colonne = s_Sql_colonne + " A.id_articoloTessutoColore,";
}
if (l_seriale != null && !l_seriale.isEmpty()) {
wc.addWc(" A.seriale = '" + l_seriale + "'");
s_Sql_colonne = s_Sql_colonne + " A.seriale,";
}
if (l_id_clifor != 0L) {
wc.addWc(" A.id_clifor = " + l_id_clifor);
s_Sql_colonne = s_Sql_colonne + " A.id_clifor,";
}
if (!l_flgCliFor.isEmpty()) {
wc.addWc(" A.id_clifor='" + l_flgCliFor + "'");
s_Sql_colonne = s_Sql_colonne + " A.id_clifor,";
}
if (l_flgStatoLavorazione == -1L || l_flgStatoLavorazione == 100L) {
wc.addWc("(DOC.flgStatoLavorazione=0 or DOC.flgStatoLavorazione is null or DOC.flgStatoLavorazione=100)");
} else {
wc.addWc("(DOC.flgStatoLavorazione>0 and DOC.flgStatoLavorazione <100)");
}
if (dataA != null) {
wc.addWc(" DOC.dataDocumento <= ?");
s_Sql_Sum = s_Sql_Sum + s_Sql_Sum;
}
String s_sql_groupby = "";
if (!s_Sql_colonne.isEmpty())
s_sql_groupby = " group by " + s_Sql_colonne.substring(0, s_Sql_colonne.length() - 1);
try {
PreparedStatement stmt = getConn()
.prepareStatement("select " + s_Sql_colonne + s_Sql_Sum + wc.toString() + s_sql_groupby);
if (dataA != null)
stmt.setDate(1, dataA);
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public void findMagTessutoDisponibilitaGlobaleMagazziniInterniEsterni(long l_id_articoloTessuto, long l_id_articoloTessutoColore, String l_seriale, long l_id_clifor) {
findMagTessutoDisponibilita(0L, 0L, l_seriale, 0L, 0L, -1L, l_id_clifor, "", DATA_NULL);
}
public void findMagTessutoDisponibilitaPuntualeOLD(long l_id_articoloTessuto, long l_id_articoloTessutoColore, String l_seriale, long l_id_magfisico, long l_flgStatoLavorazione, long l_id_clifor, long flgTipoRicerca, String l_flgCliFor) {
String s_Sql_Sum = " SUM(segnoMov*kg) as kg, SUM(segnoMov*mt) as mt, SUM(segnoMov*nr) as nr from RIGA_DOCUMENTO AS A";
String s_Sql_colonne = "";
WcString wc = new WcString();
if (flgTipoRicerca == 0L)
wc.addWc("A.id_magFisico>0");
if (l_id_articoloTessutoColore > 0L) {
s_Sql_Sum = s_Sql_Sum + " inner join ARTICOLO_TESSUTO_COLORE AS F ON A.id_articoloTessutoColore=F.id_articoloTessutoColore";
} else if (l_id_articoloTessuto > 0L) {
s_Sql_Sum = s_Sql_Sum + " inner join ARTICOLO_TESSUTO AS F ON A.id_articoloTessuto=F.id_articoloTessuto";
}
if (!l_flgCliFor.isEmpty())
s_Sql_Sum = s_Sql_Sum + " inner join CLIFOR AS CF ON A.id_clifor=CF.id_clifor";
if (l_id_articoloTessutoColore > 0L) {
wc.addWc(" A.id_articoloTessutoColore = " + l_id_articoloTessutoColore);
s_Sql_colonne = s_Sql_colonne + " A.id_articoloTessutoColore,";
} else if (l_id_articoloTessuto != 0L) {
wc.addWc(" A.id_articoloTessuto = " + l_id_articoloTessuto);
s_Sql_colonne = s_Sql_colonne + " A.id_articoloTessuto,";
}
if (l_id_magfisico != 0L) {
wc.addWc(" id_magFisico = " + l_id_magfisico);
s_Sql_colonne = s_Sql_colonne + " id_magFisico,";
}
if (!l_flgCliFor.isEmpty()) {
wc.addWc(" A.id_clifor='" + l_flgCliFor + "'");
s_Sql_colonne = s_Sql_colonne + " A.id_clifor,";
}
StringBuilder mf = new StringBuilder("");
if (flgTipoRicerca > 0L && l_id_magfisico == 0L) {
MagFisico mag = new MagFisico(getApFull());
if (flgTipoRicerca == 1L || flgTipoRicerca == 3L) {
Vectumerator<MagFisico> vecMag = mag.findByTipo(1L);
if (vecMag.hasMoreElements())
while (vecMag.hasMoreElements()) {
mag = (MagFisico)vecMag.nextElement();
if (mf.length() > 0)
mf.append(" OR ");
mf.append(" id_magFisico = " + mag.getId_magFisico());
}
}
if (flgTipoRicerca == 2L || flgTipoRicerca == 3L) {
Vectumerator<MagFisico> vecMag = mag.findByTipo(2L);
if (vecMag.hasMoreElements())
while (vecMag.hasMoreElements()) {
mag = (MagFisico)vecMag.nextElement();
if (mf.length() > 0)
mf.append(" OR ");
mf.append(" id_magFisico = " + mag.getId_magFisico());
}
}
}
if (mf.length() > 0) {
mf.append(")");
wc.addWc("(" + mf.toString());
s_Sql_colonne = s_Sql_colonne + " id_magFisico,";
}
if (l_seriale != null && !l_seriale.isEmpty()) {
wc.addWc(" seriale = '" + l_seriale + "'");
s_Sql_colonne = s_Sql_colonne + " seriale,";
}
if (l_id_clifor != 0L) {
wc.addWc(" id_clifor = " + l_id_clifor);
s_Sql_colonne = s_Sql_colonne + " id_clifor,";
}
String s_sql_groupby = "";
if (!s_Sql_colonne.isEmpty())
s_sql_groupby = " group by " + s_Sql_colonne.substring(0, s_Sql_colonne.length() - 1);
try {
PreparedStatement stmt = getConn()
.prepareStatement("select " + s_Sql_colonne + s_Sql_Sum + wc.toString() + s_sql_groupby);
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public void findMagTessutoDisponibilitaPuntualeMagazziniInterni(long l_id_articoloTessuto, long l_id_articoloTessutoColore, String l_seriale, long l_flgStatoLavorazione) {
findMagTessutoDisponibilita(l_id_articoloTessuto, l_id_articoloTessutoColore, l_seriale, 0L, 1L, -1L, 0L, "", DATA_NULL);
}
public void findMagTessutoDisponibilitaPuntualeMagazziniInterniEsterni(long l_id_articoloTessuto, long l_id_articoloTessutoColore, String l_seriale, long l_flgStatoLavorazione, long l_id_clifor) {
findMagTessutoDisponibilita(l_id_articoloTessuto, l_id_articoloTessutoColore, l_seriale, 0L, 0L, -1L, l_id_clifor, "", DATA_NULL);
}
public Vectumerator findMagTessutoSaldiArticoloTessutoByCR(RigaDocumentoCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select B.id_articoloFilato, C.id_articoloFilatoColore , SUM(A.kg*segnoMov) as kg, SUM(A.mt*segnoMov) as mt, SUM(A.nr*segnoMov) as nr from ARTICOLO_FILATO AS B LEFT JOIN ARTICOLO_FILATO_COLORE AS C ON B.id_articoloFilato=C.id_articoloFilato LEFT JOIN RIGA_DOCUMENTO AS A ON A.id_articoloFilato=B.id_articoloFilato and A.id_articoloFilatoColore=C.id_articoloFilatoColore left JOIN MAG_FISICO AS D ON A.id_magFisico=D.id_magFisico ";
if (CR.getFlgTipoMagazzino() > 0L)
s_Sql_Find = s_Sql_Find + " and D.flgTipo = " + s_Sql_Find;
String s_Sql_Group = " group by B.id_articoloFilato, C.id_articoloFilatoColore";
String s_Sql_Order = " order by B.nome, C.nomeV, A.seriale ";
String s_Sql_Having = "";
if (CR.getFlgInMagazzino() == 1L) {
s_Sql_Having = " Having SUM(A.kg*segnoMov) > 0 OR SUM(A.mt*segnoMov) > 0 OR SUM(A.nr*segnoMov) > 0 ";
} else if (CR.getFlgInMagazzino() == 2L) {
s_Sql_Having = " Having SUM(A.kg*segnoMov) < 0 OR SUM(A.mt*segnoMov) < 0 OR SUM(A.nr*segnoMov) < 0 ";
}
WcString wc = new WcString();
wc.addWc("A.id_magFisico>0");
if (!CR.getSearchTxt().isEmpty() && !CR.getSearchTxt().equals("*")) {
String star = "";
String temp = CR.getSearchTxt();
temp = prepareInputMySqlString(temp, true);
temp = temp.replace("*", "%");
StringTokenizer st = new StringTokenizer(temp.trim(), " ");
StringBuffer txt = new StringBuffer("(");
while (st.hasMoreTokens()) {
String token = star + star;
txt.append("(B.codice like '" + token + "%' or B.nome like '" + token + "%' or B.codiceProduttore like '" + token + "%' or B.codiciAlternativi like '%," + token + "%')");
if (st.hasMoreTokens()) {
txt.append(" and ");
star = "%";
}
}
txt.append(")");
wc.addWc(txt.toString());
}
if (CR.getId_articolo() > 0L)
wc.addWc("B.id_articolo = " + CR.getId_articolo());
if (CR.getId_magFisico() > 0L)
wc.addWc(" A.id_magFisico = " + CR.getId_magFisico());
if (CR.getId_clifor() > 0L)
wc.addWc(" A.id_clifor = " + CR.getId_clifor());
try {
PreparedStatement stmt = getConn()
.prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Group + s_Sql_Having);
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public double getTotTessutiImpegnati(long l_id_articoloTessuto, String l_seriale) {
return 0.0D;
}
public static ResParm aggiornaDispoTessuto(ApplParmFull ap, long l_id_articoloTessuto, long l_id_articoloTessutoColore, long l_id_users) {
ResParm rp = new ResParm(true);
if (l_id_articoloTessutoColore != 0L) {
RigaDocumento rigaDocumento = new RigaDocumento(ap);
rigaDocumento.findMagTessutoDisponibilitaPuntualeMagazziniInterni(l_id_articoloTessuto, l_id_articoloTessutoColore, Articolo.SERIALE_NULL, -1L);
ArticoloTessutoColore art = new ArticoloTessutoColore(ap);
art.findByPrimaryKey(l_id_articoloTessutoColore);
art.resetCalcoloQuantita();
art.setFlgDispo((rigaDocumento.getQuantita() > 0.0D) ? 1L : 0L);
art.setLastUpdId_user(l_id_users);
art.save();
ArticoloTessuto af = art.getArticoloTessuto();
af.resetCalcoloQuantita();
rigaDocumento.findMagTessutoDisponibilitaPuntualeMagazziniInterni(l_id_articoloTessuto, 0L, Articolo.SERIALE_NULL, -1L);
af.setFlgDispo((rigaDocumento.getQuantita() > 0.0D) ? 1L : 0L);
af.setLastUpdId_user(l_id_users);
af.save();
}
return rp;
}
private static synchronized ResParm synchroSaveTessuto(RigaDocumento bean) {
long l_id_magFisicoPartenza, l_id_magFisicoArrivo;
MagFisico magFisicoPartenza, magFisicoArrivo;
CausaleMagazzino causaleMagazzino;
ResParm rp = bean.getDocumento().checkEMSTA();
if (!rp.getStatus())
return new ResParm(false, "ATTENZIONE! Tentativo di modificare una riga documento: " + rp.getMsg());
double l_quantitaOld = bean.getQuantitaOld();
RigaDocumento rd = new RigaDocumento(bean.getApFull());
rd.findByPrimaryKey(bean.getId_rigaDocumento());
long l_flgRigaPrelevata = rd.getFlgRigaPrelevata();
if (bean.getDBState() == 1) {
if (bean.getFlgRigaPrelevata() == 1L)
return new ResParm(false, "ERRORE! Non puoi modificare una riga chiusa!");
if (bean.getQuantitaPrelevata() > 0.0D && bean.getQuantita() < bean.getQuantitaPrelevata())
return new ResParm(false, "ERRORE! La quantità prelevata è maggiore della quantità della riga");
}
if (bean.getQuantitaPrelevata() >= bean.getQuantita() && bean.getQuantitaPrelevata() > 0.0D && bean.getQuantita() > 0.0D)
bean.setFlgRigaPrelevata(1L);
double quantitaPrelevata1 = 0.0D;
if (bean.getArticoloTessuto().isUsaMagazzino()) {
rd.getMagQuantitaPrelevatoByRigaDocumento(bean.getId_rigaDocumento());
quantitaPrelevata1 = rd.getQuantita();
if (bean.getQuantita() < quantitaPrelevata1)
return new ResParm(false, "ERRORE! La quantità prelevata è maggiore della quantità della riga");
}
RigaDocumento beanRB = null;
if (bean.getId_rigaDocumento() != 0L) {
beanRB = new RigaDocumento(bean.getApFull());
beanRB.findByPrimaryKey(bean.getId_rigaDocumento());
}
rp = new ResParm(true);
long magPartenza = 0L;
long magArrivo = 0L;
long flgTipoMagFisicoPartenza = 0L;
long flgTipoMagFisicoArrivo = 0L;
if (bean.getFlgCodiceRiga() == 0L) {
l_id_magFisicoPartenza = bean.getDocumento().getId_magFisicoPartenza();
l_id_magFisicoArrivo = bean.getDocumento().getId_magFisicoArrivo();
magFisicoPartenza = bean.getDocumento().getMagFisicoPartenza();
magFisicoArrivo = bean.getDocumento().getMagFisicoArrivo();
causaleMagazzino = bean.getDocumento().getTipoDocumento().getCausaleMagazzino();
} else {
l_id_magFisicoPartenza = bean.getDocumento().getId_magFisicoPartenza2();
l_id_magFisicoArrivo = bean.getDocumento().getId_magFisicoArrivo2();
magFisicoPartenza = bean.getDocumento().getMagFisicoPartenza2();
magFisicoArrivo = bean.getDocumento().getMagFisicoArrivo2();
causaleMagazzino = bean.getDocumento().getTipoDocumento().getCausaleMagazzino2();
}
if (l_id_magFisicoPartenza == 0L) {
if (causaleMagazzino.getId_magFisicoPartenza() > 0L) {
magPartenza = causaleMagazzino.getId_magFisicoPartenza();
flgTipoMagFisicoPartenza = causaleMagazzino.getMagFisicoPartenza().getFlgTipo();
}
} else {
magPartenza = l_id_magFisicoPartenza;
flgTipoMagFisicoPartenza = magFisicoPartenza.getFlgTipo();
}
if (l_id_magFisicoArrivo == 0L) {
if (causaleMagazzino.getId_magFisicoArrivo() > 0L) {
magArrivo = causaleMagazzino.getId_magFisicoArrivo();
flgTipoMagFisicoArrivo = causaleMagazzino.getMagFisicoArrivo().getFlgTipo();
}
} else {
magArrivo = l_id_magFisicoArrivo;
flgTipoMagFisicoArrivo = magFisicoArrivo.getFlgTipo();
}
if (bean.getId_articoloTessuto() != 0L && bean.getArticoloTessuto().usaMagazzino() && (magArrivo > 0L || magPartenza > 0L)) {
if (magPartenza != 0L) {
long segnoMov = -1L;
if (bean.getFlgReso() == 1L)
segnoMov = 1L;
bean.setSegnoMov(segnoMov);
bean.setId_causaleMagazzino(causaleMagazzino.getId_causaleMagazzino());
bean.setId_magFisico(magPartenza);
if (flgTipoMagFisicoPartenza == 1L) {
bean.setId_clifor(0L);
} else {
bean.setId_clifor(bean.getDocumento().getId_clifor());
}
rp = bean.superSave();
}
if (rp.getStatus() && magArrivo != 0L) {
long segnoMov = 1L;
if (bean.getFlgReso() == 1L)
segnoMov = -1L;
if (magPartenza == 0L) {
bean.setSegnoMov(segnoMov);
bean.setId_causaleMagazzino(causaleMagazzino.getId_causaleMagazzino());
bean.setId_magFisico(magArrivo);
if (flgTipoMagFisicoArrivo == 1L) {
bean.setId_clifor(0L);
} else {
bean.setId_clifor(bean.getDocumento().getId_clifor());
}
rp = bean.superSave();
} else {
try {
RigaDocumento rd2 = (RigaDocumento)bean.clone();
rd2.setDBState(0);
rd2.setId_rigaDocumento(0L);
rd2.setId_rigaDocumentoMov(bean.getId_rigaDocumento());
rd2.setSegnoMov(segnoMov);
rd2.setId_magFisico(magArrivo);
if (flgTipoMagFisicoArrivo == 1L) {
rd2.setId_clifor(0L);
} else {
rd2.setId_clifor(bean.getDocumento().getId_clifor());
}
rd2.setId_rigaDocumentoMov(bean.getId_rigaDocumento());
rp = bean.superSave();
} catch (Exception e) {
bean.handleDebug(e, 0);
rp.setException(e);
}
}
}
} else {
bean.setId_clifor(0L);
rp = bean.superSave();
}
if (rp.getStatus()) {
if (bean.getDocumento().getTipoDocumento().getFlgTipologia() == 200L)
if (bean.getDocumento().getFlgBarcodeType() == 100L) {
String pre = zeroLeft(bean.getDocumento().getRiferimento(), 6) + "-" + zeroLeft(bean.getDocumento().getRiferimento(), 6);
long numeroIniziale = 1L;
long numeroFinale = numeroIniziale + bean.getStacchi() - 1L;
bean.setCodiceCartellinoStart(pre + pre);
bean.setCodiceCartellinoStop(pre + pre);
bean.setCodiceCartellinoIniziale("");
bean.superSave();
}
rp.append(bean.getDocumento().save());
rp.append(bean.aggiornaCostoUltimoFornitore());
if (l_flgRigaPrelevata != bean.getFlgRigaPrelevata())
if (bean.getFlgRigaPrelevata() == 0L) {
if (bean.getDocumento().getFlgDocumentoPrelevato() == 1L)
bean.getDocumento().aggiornaFlgDocumentoPrelevato(0L);
} else {
bean.getDocumento().verificaEAggiornaFlgDocumentoPrelevato();
}
}
if (rp.getStatus()) {
rp.setMsg(AbMessages.getMessage("SAVE_OK"));
bean.getArticoloTessuto().setQuantitaCalcolate(false);
bean.getArticoloTessuto().superSave();
}
return rp;
}
public long getId_articoloPrecedente() {
return this.id_articoloPrecedente;
}
public void setId_articoloPrecedente(long id_articoloPrecedente) {
this.id_articoloPrecedente = id_articoloPrecedente;
}
public double getPercL1() {
return this.percL1;
}
public double getPercL2() {
return this.percL2;
}
public double getPercL3() {
return this.percL3;
}
public void setPercL1(double percL1) {
this.percL1 = percL1;
}
public void setPercL2(double percL2) {
this.percL2 = percL2;
}
public void setPercL3(double percL3) {
this.percL3 = percL3;
}
public String getFETipoCessionePrestazione() {
return null;
}
public String getFECodiceArticoloTipo() {
return getArticolo().getTipo().getDescrizione();
}
public String getFECodiceArticoloValore() {
return getCodiceArticolo();
}
public String getFEDescrizione() {
return getDescrizioneRigaCompleta();
}
public double getFEQuantita() {
return getQuantita();
}
public String getFEUnitaMisura() {
return getUdm();
}
public Date getFEDataInizioPeriodo() {
return null;
}
public Date getFEDataFinePeriodo() {
return null;
}
public double getFEPrezzoUnitario() {
return getImponibile();
}
public Vectumerator<FEScontoMaggiorazioneInterface> getFEScontoMaggiorazione() {
if (getSconto() > 0.0D) {
FEScontoMaggiorazione rowSm;
Vectumerator<FEScontoMaggiorazioneInterface> vecSM = new Vectumerator();
if (getQuantita() == 1.0D) {
rowSm = new FEScontoMaggiorazione("SC", getSconto(), 0.0D);
} else {
rowSm = new FEScontoMaggiorazione("SC", getSconto(), 0.0D);
}
vecSM.add(rowSm);
return vecSM;
}
if (getPercL1() > 0.0D || getPercL2() > 0.0D || getPercL3() > 0.0D) {
FEScontoMaggiorazione rowSm;
Vectumerator<FEScontoMaggiorazioneInterface> vecSM = new Vectumerator();
if (getQuantita() == 1.0D) {
rowSm = new FEScontoMaggiorazione("SC", 0.0D, getTotImponibileRigaSconto());
} else {
DoubleOperator dop = new DoubleOperator(getTotImponibileRigaSconto());
dop.setScale(4, 5);
dop.divide(getQuantita());
dop.setScale(2, 5);
rowSm = new FEScontoMaggiorazione("SC", 0.0D, dop.getResult());
}
vecSM.add(rowSm);
return vecSM;
}
return null;
}
public double getFEPrezzoTotale() {
return getTotImponibileRigaConSconto();
}
public double getFEAliquotaIva() {
return (double)getIva().getAliquotaFE();
}
public double getFERitenuta() {
return 0.0D;
}
public String getFENatura() {
return getIva().getFENatura();
}
public String getFERiferimentoAmministrazione() {
return null;
}
public double getTotImponibileRigaSconto() {
if (!getIva().getFlgTipo().equals("R")) {
if (getSconto() == 0.0D && getPercL1() == 0.0D && getPercL2() == 0.0D && getPercL3() == 0.0D)
return 0.0D;
if (getSconto() > 0.0D) {
DoubleOperator doubleOperator = new DoubleOperator(getSconto());
doubleOperator.setScale(4, 5);
doubleOperator.multiply(getTotImponibileRiga());
doubleOperator.divide(100.0F);
doubleOperator.setScale(2, 5);
return doubleOperator.getResult();
}
DoubleOperator temp = new DoubleOperator();
temp.setScale(4, 5);
DoubleOperator imponibile = new DoubleOperator(getTotImponibileRiga());
imponibile.setScale(4, 5);
DoubleOperator scontoTot = new DoubleOperator();
scontoTot.setScale(4, 5);
if (getPercL1() > 0.0D) {
temp = new DoubleOperator(getPercL1());
temp.multiply(imponibile);
temp.divide(100.0F);
scontoTot.add(temp.getResult());
imponibile.subtract(temp.getResult());
}
if (getPercL2() > 0.0D) {
temp = new DoubleOperator(getPercL2());
temp.multiply(imponibile);
temp.divide(100.0F);
scontoTot.add(temp.getResult());
imponibile.subtract(temp.getResult());
}
if (getPercL3() > 0.0D) {
temp = new DoubleOperator(getPercL3());
temp.multiply(imponibile);
temp.divide(100.0F);
scontoTot.add(temp.getResult());
imponibile.subtract(temp.getResult());
}
scontoTot.setScale(2, 5);
return scontoTot.getResult();
}
return 0.0D;
}
public double getTotImponibileRigaConSconto() {
DoubleOperator temp = new DoubleOperator(getTotImponibileRiga());
temp.setScale(4, 5);
temp.subtract(getTotImponibileRigaSconto());
temp.setScale(2, 5);
return temp.getResult();
}
public double getRDITotImponibile() {
return getTotImponibileRigaConSconto();
}
public double getRDITotImposta() {
return getTotIvaRiga4();
}
public double getRDITotCosto() {
return getTotCostoUsato();
}
public boolean isRDIPIva() {
return !getClifor().getpIva().isEmpty();
}
public boolean isRDINotaCredito() {
if (getDocumento().getTipoDocumento().getFlgTipologia() == 1L)
return true;
return false;
}
public double getRDITotImponibileRM() {
return getTotImportoRM();
}
public double getTotImponibileRiga() {
DoubleOperator temp = new DoubleOperator(getImponibile());
temp.multiply(getQuantita());
temp.setScale(3, 5);
return temp.getResult();
}
public double getFECostoArticolo() {
return getArticolo().getCostoAcquisto();
}
public String getFEEsigibilitaIva() {
if (getDocumento().getClifor().getFlgSplitPayment() == 1L)
return "S";
return null;
}
public long getStacchi() {
return this.stacchi;
}
public void setStacchi(long stacchi) {
this.stacchi = stacchi;
}
public double getMetriStacchi() {
return this.metriStacchi;
}
public void setMetriStacchi(double metriStacchi) {
this.metriStacchi = metriStacchi;
}
public long getRifTipoArticolo() {
return (this.rifTipoArticolo == 0L) ? 1L : this.rifTipoArticolo;
}
public void setRifTipoArticolo(long rifTipoArticolo) {
this.rifTipoArticolo = rifTipoArticolo;
}
public String getCodiceCartellinoIniziale() {
return (this.codiceCartellinoIniziale == null) ? "" : this.codiceCartellinoIniziale.trim();
}
public void setCodiceCartellinoIniziale(String codiceCartellinoIniziale) {
this.codiceCartellinoIniziale = codiceCartellinoIniziale;
}
public String getDescrizioneStatoPezze() {
if (getId_rigaDocumento() == 0L)
return "";
StringBuilder sb = new StringBuilder();
LavPezza lavPezza = new LavPezza(getApFull());
Vectumerator<LavPezza> vec = lavPezza.findByRigaDocumento(getId_rigaDocumento());
if (vec.getTotNumberOfRecords() > 0) {
sb.append(vec.getTotNumberOfRecords());
sb.append(" pezze per ");
lavPezza.findLastInserimentoByRigaDocumento(getId_rigaDocumento(), 0L);
sb.append(getNf().format(lavPezza.getMtPezza()));
sb.append(" mt ");
sb.append(lavPezza.getTsInserimentoS());
}
return sb.toString();
}
public String getCodiceCartellinoStart() {
return (this.codiceCartellinoStart == null) ? "" : this.codiceCartellinoStart;
}
public String getCodiceCartellinoStop() {
return (this.codiceCartellinoStop == null) ? "" : this.codiceCartellinoStop;
}
public void setCodiceCartellinoStart(String codiceCartellinoStart) {
this.codiceCartellinoStart = codiceCartellinoStart;
}
public void setCodiceCartellinoStop(String codiceCartellinoStop) {
this.codiceCartellinoStop = codiceCartellinoStop;
}
public long getFlgCodiceRiga() {
return this.flgCodiceRiga;
}
public void setFlgCodiceRiga(long flgCodiceRiga) {
this.flgCodiceRiga = flgCodiceRiga;
}
public long getFlgStatoLavorazioneRiga() {
return this.flgStatoLavorazioneRiga;
}
public void setFlgStatoLavorazioneRiga(long flgStatoLavorazione) {
this.flgStatoLavorazioneRiga = flgStatoLavorazione;
}
public static final String getStatoLavorazione(long l_flgStatoLavorazione) {
return Documento.getStatoLavorazione(l_flgStatoLavorazione);
}
public String getStatoLavorazione() {
return Documento.getStatoLavorazione(getFlgStatoLavorazioneRiga());
}
public Vectumerator findByCR(RigaDocumentoCR CR, int pageNumber, int pageRows) {
if (CR.getFlgReport().equals("S") && CR.getFlgTipoReport() == 1L)
return findByCRCompatto(CR, pageNumber, pageRows);
boolean flgOttimizzo = (getParm("OTTIMIZZO").getNumero() == 1.0D);
StringBuffer s_Sql_Find = new StringBuffer("select A.*, D.nome, D.codice, C.dataDocumento, C.id_esercizio, C.progDocumento from RIGA_DOCUMENTO AS A left join ARTICOLO AS D on A.id_articolo=D.id_articolo, DOCUMENTO AS C ");
s_Sql_Find.append(" ,TIPO_DOCUMENTO AS TD , TIPOLOGIA_DOCUMENTO AS T");
String s_Sql_Order = " order by D.nome,D.codice, A.seriale, C.dataDocumento desc, C.id_esercizio desc, C.progDocumento desc";
if (CR.getFlgOrderBy() == 1L)
s_Sql_Order = " order by C.dataDocumento asc, C.id_esercizio asc, C.progDocumento asc";
WcString wc = new WcString();
findByCRCreateWC(CR, s_Sql_Find, wc);
try {
PreparedStatement stmt;
if ((pageNumber == 0 && pageRows == 0) || !flgOttimizzo) {
stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString());
} else {
if (pageNumber == 0)
pageNumber = 1;
int start = (pageNumber - 1) * pageRows;
int stop = start + pageRows;
stmt = getConn().prepareStatement(String.valueOf(s_Sql_Find) + String.valueOf(s_Sql_Find) + wc.toString() + " limit " + s_Sql_Order + "," + start);
}
findByCRCreateStmtDate(CR, stmt);
if ((pageNumber == 0 && pageRows == 0) || !flgOttimizzo)
return findRows(stmt, pageNumber, pageRows);
Vectumerator vec = findRows(stmt, 1, pageRows);
vec.setPageNumber(pageNumber);
vec.setTotNumberOfRecords(findByCRTotRecord(CR));
return vec;
} catch (SQLException e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator<RigaDocumento> findRigheFilatiByRDTessuto(long l_id_rigaDocumentoTessuto) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_order = " order by A.id_rigaDocumento desc";
WcString wc = new WcString();
wc.addWc("A.id_rigaDocumentoTessutoA=" + l_id_rigaDocumentoTessuto);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return findRows(stmt);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public long getColpoFinaleRiga() {
return this.colpoFinaleRiga;
}
public void setColpoFinaleRiga(long colpoFinale) {
this.colpoFinaleRiga = colpoFinale;
}
public long getColpoInizialeRiga() {
return this.colpoInizialeRiga;
}
public void setColpoInizialeRiga(long colpoIniziale) {
this.colpoInizialeRiga = colpoIniziale;
}
public long getId_articoloTessutoColore() {
return this.id_articoloTessutoColore;
}
public void setId_articoloTessutoColore(long id_articoloTessutoColore) {
this.id_articoloTessutoColore = id_articoloTessutoColore;
setArticoloTessutoColore(null);
}
public ArticoloTessutoColore getArticoloTessutoColore() {
this.articoloTessutoColore = (ArticoloTessutoColore)getSecondaryObject(this.articoloTessutoColore, ArticoloTessutoColore.class,
getId_articoloTessutoColore());
return this.articoloTessutoColore;
}
public void setArticoloTessutoColore(ArticoloTessutoColore articoloTessutoColore) {
this.articoloTessutoColore = articoloTessutoColore;
}
public String getCodiceCartellinoIdx(long idx) {
if (idx == 0L)
return getCodiceCartellinoStart();
int idxPre = (int)((long)getCodiceCartellinoStart().length() - getDocumento().getFlgBarcodeSequenzaNumeri());
String pre = getCodiceCartellinoStart().substring(0, idxPre);
long numIniziale = Long.parseLong(getCodiceCartellinoStart().substring(idxPre));
return pre + pre;
}
public long getTotColpiRiga() {
if (getColpoFinaleRiga() > getColpoInizialeRiga())
return getColpoFinaleRiga() - getColpoInizialeRiga();
return 0L;
}
public long getId_telaio() {
return this.id_telaio;
}
public Telaio getTelaio() {
this.telaio = (Telaio)getSecondaryObject(this.telaio, Telaio.class, getId_telaio());
return this.telaio;
}
public void setId_telaio(long id_telaio) {
this.id_telaio = id_telaio;
setTelaio(null);
}
public void setTelaio(Telaio telaio) {
this.telaio = telaio;
}
public Vectumerator findImpegniByClifor(long l_id_clifor, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A , DOCUMENTO AS B";
String s_Sql_order = "";
WcString wc = new WcString();
wc.addWc("A.id_documento=B.id_documento");
wc.addWc("B.flgStato =1");
wc.addWc("A.flgRigaPrelevata !=1");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return findRows(stmt, pageNumber, pageRows);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public void findByTelaioUltimo(long l_id_telaio) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A";
String s_Sql_Order = " order by A.tsFineLavorazioneRiga desc";
WcString wc = new WcString();
wc.addWc("A.flgStatoLavorazioneRiga=100");
wc.addWc("A.id_telaio=" + l_id_telaio);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public ResParm updateFields(String fieldName, String value) {
if (getId_rigaDocumento() == 0L)
return new ResParm(false, "Errore! Impossibile aggiornare un bean nuovo.");
long valueL = 0L;
try {
valueL = Long.parseLong(value);
} catch (Exception e) {}
if (fieldName.equals("colpoInizialeRiga")) {
setColpoInizialeRiga(valueL);
} else if (fieldName.equals("colpoFinaleRiga")) {
if (valueL > 0L && valueL > getColpoInizialeRiga()) {
setColpoFinaleRiga(valueL);
} else {
setColpoFinaleRiga(0L);
}
} else if (fieldName.equals("id_telaio")) {
setId_telaio(valueL);
}
calcolaStatoLavorazioneRiga();
if (getId_telaio() > 0L && getColpoInizialeRiga() == 0L)
setColpoInizialeRiga(getTelaio().findColpiIniziali());
ResParm rp = super.save();
if (rp.getStatus())
rp = getDocumento().aggiornaStatoLavorazione();
return rp;
}
public Timestamp getTsFineLavorazioneRiga() {
return this.tsFineLavorazioneRiga;
}
public void setTsFineLavorazioneRiga(Timestamp tsFineLavorazioneRiga) {
this.tsFineLavorazioneRiga = tsFineLavorazioneRiga;
}
public Timestamp getTsInizioLavorazioneRiga() {
return this.tsInizioLavorazioneRiga;
}
public void setTsInizioLavorazioneRiga(Timestamp tsInizioLavorazioneRiga) {
this.tsInizioLavorazioneRiga = tsInizioLavorazioneRiga;
}
public boolean isCampoEditabile(String fieldname) {
if (fieldname.equals("id_telaio")) {
if (getFlgStatoLavorazioneRiga() == 0L ||
getFlgStatoLavorazioneRiga() == 10L)
return true;
return false;
}
if (fieldname.equals("colpoInizialeRiga")) {
if ((getFlgStatoLavorazioneRiga() == 10L ||
getFlgStatoLavorazioneRiga() == 20L) && getColpoFinaleRiga() == 0L)
return true;
return false;
}
if (fieldname.equals("colpoFinaleRiga")) {
if ((getFlgStatoLavorazioneRiga() == 10L ||
getFlgStatoLavorazioneRiga() == 20L) && getColpoInizialeRiga() > 0L)
return true;
return false;
}
return true;
}
public RigaDocumento findTelaioOccupato(long l_id_telaio) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A ";
String s_Sql_Order = " order by A.tsInizioLavorazioneRiga desc";
WcString wc = new WcString();
wc.addWc("(A.flgStatoLavorazioneRiga=10 or A.flgStatoLavorazioneRiga=20)");
wc.addWc("A.id_telaio=" + l_id_telaio);
wc.addWc("A.id_rigaDocumento <>" + getId_rigaDocumento());
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
Vectumerator<RigaDocumento> vec = findRows(stmt, 1, 1);
if (vec.hasMoreElements())
return (RigaDocumento)vec.nextElement();
return new RigaDocumento();
} catch (SQLException e) {
handleDebug(e);
return new RigaDocumento();
}
}
public long getNumTeli() {
long totCapi = (long)getDocumento().getTotNr();
return totCapi / getCapiPerTelo();
}
public long getNumTeliRiga(long l_capiPerTelo) {
long totCapi = (long)getNr();
return totCapi / l_capiPerTelo;
}
public boolean isNumeroTeliOk() {
if (getNumTeli() <= getArticoloTessuto().getNumTeliMax())
return true;
return false;
}
public long getNumTeliRiga() {
return this.numTeliRiga;
}
public void setNumTeliRiga(long numTeliRiga) {
this.numTeliRiga = numTeliRiga;
}
public long getFlgDaCancellare() {
return this.flgDaCancellare;
}
public void setFlgDaCancellare(long flgDaCancellare) {
this.flgDaCancellare = flgDaCancellare;
}
public ResParm impostaDaCancellareByDocumentoCodiceriga(long l_id_documento, long l_flgCodiceRiga, boolean daCancellare) {
String s_Sql_Find = "UPDATE RIGA_DOCUMENTO as A SET flgDaCancellare=" + (daCancellare ? "1" : "0");
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
wc.addWc("A.flgCodiceRiga=" + l_flgCodiceRiga);
return update(s_Sql_Find + s_Sql_Find);
}
public NumeroTeliRiga getNumeroTeliRigaByArticolo(long l_id_rigaDocumentoArticolo) {
if (this.numeroTeliRiga == null || this.numeroTeliRiga.getId_rigaDocumentoArticolo() != l_id_rigaDocumentoArticolo) {
this.numeroTeliRiga = new NumeroTeliRiga(getApFull());
this.numeroTeliRiga.findByRDArticoloRDTessuto(l_id_rigaDocumentoArticolo, getId_rigaDocumento());
}
return (this.numeroTeliRiga == null) ? new NumeroTeliRiga(getApFull()) : this.numeroTeliRiga;
}
public long getNumeroCapiByTeliRigaArticolo(long l_id_rigaDocumentoArticolo) {
return getNumeroTeliRigaByArticolo(l_id_rigaDocumentoArticolo).getNumTeliRiga() * getCapiPerTelo();
}
public void setNumeroTeliRiga(NumeroTeliRiga numeroTeliRiga) {
this.numeroTeliRiga = numeroTeliRiga;
}
public String getDescrizioneArticoliCompleta(String lang) {
String star = "", sn = "";
StringBuilder l_descrizioneRiga = new StringBuilder();
if (getId_articoloVariante() != 0L) {
l_descrizioneRiga.append(getArticoloVariante().getDescrizione(lang));
} else if (getId_articolo() != 0L) {
l_descrizioneRiga.append(getArticolo().getDescrizione(lang));
}
if (getId_articoloTessutoColore() != 0L) {
l_descrizioneRiga.append(getArticoloTessutoColore().getDescrizione(lang));
} else if (getId_articoloTessuto() != 0L) {
l_descrizioneRiga.append(getArticoloTessuto().getDescrizione(lang));
}
if (getId_articoloFilatoColore() != 0L)
l_descrizioneRiga.append(getArticoloFilatoColore().getDescrizione(lang));
if (l_descrizioneRiga.length() == 0) {
l_descrizioneRiga.append(getDescrizioneRiga());
star = "*";
}
if (getId_articoloFilatoColore() != 0L) {
sn = translate(" lotto: ", lang);
} else {
sn = translate(" s/n: ", lang);
}
if (getSeriale().isEmpty())
return String.valueOf(l_descrizioneRiga) + String.valueOf(l_descrizioneRiga);
return String.valueOf(l_descrizioneRiga) + String.valueOf(l_descrizioneRiga) + star + sn;
}
public double getDatiTelaioInLavorazione(long l_id_telaio) {
String s_Sql_Find = "select sum(A.quantita) as _sum from RIGA_DOCUMENTO AS A , DOCUMENTO AS B";
String s_Sql_order = "";
WcString wc = new WcString();
wc.addWc("A.id_documento=B.id_documento");
wc.addWc("A.id_telaio=" + l_id_telaio);
wc.addWc("(A.flgStatoLavorazioneRiga =10 or A.flgStatoLavorazioneRiga =20)");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return getSum(stmt);
} catch (Exception e) {
handleDebug(e, 0);
return 0.0D;
}
}
public double getNrOriginale() {
return this.nrOriginale;
}
public void setNrOriginale(double nrOriginale) {
this.nrOriginale = nrOriginale;
}
public boolean isTessutoPrincipale(long l_id_articoloTessuto, long l_id_articoloTessutoColore) {
if (getId_articoloVariante() > 0L)
return getArticoloVariante().isTessutoPrincipale(l_id_articoloTessuto, l_id_articoloTessutoColore);
if (getId_articolo() > 0L)
return getArticolo().isTessutoPrincipale(l_id_articoloTessutoColore, l_id_articoloTessutoColore);
return false;
}
public double getMtTessutoXTaglio() {
if (getFlgCodiceRiga() == 100L) {
long totCapi = (long)getDocumento().getTotNr();
ArticoloArticoloTessuto aat = new ArticoloArticoloTessuto(getApFull());
if (getId_articoloTessutoColore() > 0L) {
aat.findByArticoloArticoloTessutoColoreBase(getDocumento().getId_articolo(), getId_articoloTessutoColore());
} else {
aat.findByArticoloArticoloTessutoBase(getDocumento().getId_articolo(), getId_articoloTessuto());
}
DoubleOperator dop = new DoubleOperator((float)totCapi);
dop.multiply(aat.getMtATT());
return dop.getResult();
}
return 0.0D;
}
public NumeroTeliRiga getNumeroTeliRigaByTessuto(long l_id_rigaDocumentoTessuto) {
if (this.numeroTeliRiga == null || this.numeroTeliRiga.getId_rigaDocumentoTessuto() != l_id_rigaDocumentoTessuto) {
this.numeroTeliRiga = new NumeroTeliRiga(getApFull());
this.numeroTeliRiga.findByRDArticoloRDTessuto(getId_rigaDocumento(), l_id_rigaDocumentoTessuto);
}
return (this.numeroTeliRiga == null) ? new NumeroTeliRiga(getApFull()) : this.numeroTeliRiga;
}
public String getDescrizioneRigaRaggruppamento() {
return (this.descrizioneRigaRaggruppamento == null) ? "" : this.descrizioneRigaRaggruppamento.trim();
}
public void setDescrizioneRigaRaggruppamento(String descrizioneRigaRaggruppamento) {
this.descrizioneRigaRaggruppamento = descrizioneRigaRaggruppamento;
}
public String getDescrizioneRigaDettaglio() {
return (this.descrizioneRigaDettaglio == null) ? "" : this.descrizioneRigaDettaglio.trim();
}
public void setDescrizioneRigaDettaglio(String descrizioneRigaDettaglio) {
this.descrizioneRigaDettaglio = descrizioneRigaDettaglio;
}
public Vectumerator findReportVenditeByArticoloCR(ArticoloCR CR) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO as A inner join DOCUMENTO AS B on A.id_documento=B.id_documento inner join ARTICOLO AS C on A.id_articolo=C.id_articolo inner join TIPO_DOCUMENTO AS TD ON B.id_tipoDocumento=TD.id_tipoDocumento";
String s_Sql_order = " order by C.codice";
if (CR.getFlgEscludiWeb() >= 0L || CR.getId_tipo() != 0L || CR.getFlgNascondi() >= 0L || !CR.getFlgReport().isEmpty())
s_Sql_Find = s_Sql_Find + " inner join TIPO AS T ON T.id_tipo=C.id_tipo";
WcString wc = new WcString();
wc.addWc("TD.flgMovMagazzino =-1");
wc.addWc("(B.flgStatoOrdineWww is null or B.flgStatoOrdineWww <> 99)");
if (!CR.getCodice().isEmpty())
wc.addWc("C.codice like'" + CR.getCodice() + "%'");
if (CR.getId_iva() != 0L)
wc.addWc("C.id_iva=" + CR.getId_iva());
if (CR.getId_clifor() != 0L)
wc.addWc("C.id_fornitore=" + CR.getId_clifor());
if (CR.getFlgQta() == 1L)
if (CR.getQtaDa() == 0L) {
wc.addWc("(C.quantita<=" + CR.getQtaA() + ")");
} else {
wc.addWc("(C.quantita>=" + CR.getQtaDa() + ")");
wc.addWc("(C.quantita<=" + CR.getQtaA() + ")");
}
if (CR.getFlgUsato() >= 0L)
wc.addWc("C.flgUsato=" + CR.getFlgUsato());
if (!CR.getScaffale().isEmpty())
if (CR.getScaffale().indexOf("*") > 0) {
String temp = CR.getScaffale().replace("*", "%");
wc.addWc("C.scaffale like'" + temp + "'");
} else {
wc.addWc("C.scaffale ='" + CR.getScaffale() + "'");
}
if (!CR.getSearchTxt().isEmpty() && !CR.getSearchTxt().equals("*"))
if (CR.getSearchTxt().startsWith(",")) {
wc.addWc("C.codiciAlternativi like'%" + CR.getSearchTxt() + ",%'");
} else {
wc.addWc("(C.codice like'%" + CR.getSearchTxt() + "%' or C.descrizioneSearch like'%" + CR.getSearchTxt() + "%')");
}
if (CR.getId_marca() != 0L)
wc.addWc("C.id_marca=" + CR.getId_marca());
if (!CR.getDescrizione().isEmpty())
wc.addWc("C.descrizione like'%" + CR.getDescrizione() + "%'");
if (CR.getId_tipo() != 0L)
wc.addWc("(T.id_tipo=" + CR.getId_tipo() + " or T.indici like'%:" + CR.getId_tipo() + ":%')");
if (CR.getFlgEscludiWeb() == 0L) {
wc.addWc("(C.flgEscludiWeb=0 or C.flgEscludiWeb is null)");
} else if (CR.getFlgEscludiWeb() > 0L) {
wc.addWc("C.flgEscludiWeb=" + CR.getFlgEscludiWeb());
}
if (CR.getFlgWebNoVendita() == 0L) {
wc.addWc("(C.flgWebNoVendita=0 or C.flgWebNoVendita is null)");
} else if (CR.getFlgWebNoVendita() > 0L) {
wc.addWc("C.flgWebNoVendita=" + CR.getFlgWebNoVendita());
}
if (CR.getFlgStockOfferte() > 0L)
if (CR.getFlgStockOfferte() == 99L) {
wc.addWc("(C.flgStockOfferte=1 and (CdataScadenzaOfferta is null or C.dataScadenzaOfferta>=?))");
} else {
wc.addWc("C.flgStockOfferte=" + CR.getFlgStockOfferte());
}
if (CR.getDataDocumentoDa() != null)
wc.addWc("B.dataDocumento>=?");
if (CR.getDataDocumentoA() != null)
wc.addWc("B.dataDocumento<=? ");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
int dataCount = 1;
if (CR.getDataDocumentoDa() != null) {
stmt.setDate(dataCount, CR.getDataDocumentoDa());
dataCount++;
}
if (CR.getDataDocumentoA() != null) {
stmt.setDate(dataCount, CR.getDataDocumentoA());
dataCount++;
}
Vectumerator vec = findRows(stmt);
return vec;
} catch (Exception e) {
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public long getId_colore() {
return getArticoloTessutoColore().getId_colore();
}
public double getPrezzoIvato() {
return conIva(getImponibile(), (double)getIva().getAliquota());
}
public double getMSQtaCaricataScaricataByArticolo(long l_id_articolo, long l_flgMovMagazzino, Date dataDocumentoDa, Date dataDocumentoA) {
String s_Sql_Find = "select SUM(Z.quantita) AS _sum FROM RIGA_DOCUMENTO AS Z INNER JOIN DOCUMENTO AS B ON Z.id_documento = B.id_documento inner join TIPO_DOCUMENTO AS TD ON B.id_tipoDocumento=TD.id_tipoDocumento";
WcString wc = new WcString();
wc.addWc("TD.flgMovMagazzino =" + l_flgMovMagazzino);
wc.addWc("(B.flgStatoOrdineWww is null or B.flgStatoOrdineWww <> 99)");
wc.addWc(" Z.id_articolo = " + l_id_articolo);
if (dataDocumentoDa != null)
wc.addWc("B.dataDocumento>=?");
if (dataDocumentoA != null)
wc.addWc("B.dataDocumento<=?");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
int dataCount = 0;
if (dataDocumentoDa != null) {
dataCount++;
stmt.setDate(dataCount, dataDocumentoDa);
}
if (dataDocumentoA != null) {
dataCount++;
stmt.setDate(dataCount, dataDocumentoA);
}
return getSum(stmt);
} catch (SQLException e) {
handleDebug(e);
return 0.0D;
}
}
public double getMSQtaCaricataScaricataByArticolo(long l_id_articolo, long l_flgMovMagazzino) {
return getMSQtaCaricataScaricataByArticolo(l_id_articolo, l_flgMovMagazzino, null, null);
}
public double getQtaPrelevabileByDocumento(long l_id_documento) {
String s_Sql_Find = "select sum(A.quantita-A.quantitaAssociata) as _sum from RIGA_DOCUMENTO AS A";
WcString wc = new WcString();
if (l_id_documento == 0L)
return 0.0D;
wc.addWc("A.id_documento=" + l_id_documento);
if (getId_articoloVariante() == 0L) {
wc.addWc("A.id_articolo=" + getId_articolo());
} else {
wc.addWc("A.id_articoloVariante=" + getId_articoloVariante());
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find);
double qdp = getSum(stmt);
return Math.min(qdp, getQuantitaRimanente());
} catch (Exception e) {
handleDebug(e, 0);
return 0.0D;
}
}
protected ResParm checkDeleteCascade() {
LavPezza lp = new LavPezza(this.apFull);
Vectumerator<LavPezza> vecLp = lp.findByRigaDocumento(getId_rigaDocumento());
if (vecLp.getTotNumberOfRecords() > 0)
return new ResParm(false, "Errore! Impossibile cancellare riga " +
getId_rigaDocumento() + ": record legato a 1 o piu' pezze (LAV_PEZZA)");
return super.checkDeleteCascade();
}
public String getCCDescrizioneRigaCompleta() {
return getDescrizioneRigaCompleta().replace("/", "/ ");
}
public boolean isScontoTroppoAlto() {
if (getId_articolo() == 0L)
return false;
Attivita attivita = Attivita.getDefaultInstance(getApFull());
if (attivita.getCheckCartPercScontoMax() <= 0.0D)
return false;
if (Math.abs(getPercScontoRispettoAlPrezzoBarrato()) > attivita.getCheckCartPercScontoMax())
return true;
return false;
}
public double getPercScontoRispettoAlPrezzoBarrato() {
if (getArticolo().getPrezzoIvatoBarrato() == 0.0D)
return 0.0D;
DoubleOperator dop = new DoubleOperator(getPrezzoPubblicoConIva());
dop.setScale(2, 5);
dop.divide(getArticolo().getPrezzoIvatoBarrato());
dop.multiply(100);
dop.subtract(100);
return dop.getResult();
}
public long getOrdine() {
return this.ordine;
}
public void setOrdine(long ordine) {
this.ordine = ordine;
}
public long getId_articoloFilatoColoreRitorto() {
return this.id_articoloFilatoColoreRitorto;
}
public void setId_articoloFilatoColoreRitorto(long id_articoloFilatoColoreRitorto) {
this.id_articoloFilatoColoreRitorto = id_articoloFilatoColoreRitorto;
}
public ArticoloFilatoColore getArticoloFilatoColore() {
this.articoloFilatoColore = (ArticoloFilatoColore)getSecondaryObject(this.articoloFilatoColore, ArticoloFilatoColore.class,
getId_articoloFilatoColore());
return this.articoloFilatoColore;
}
public void setArticoloFilatoColoreRitorto(ArticoloFilatoColoreRitorto articoloFilatoColoreRitorto) {
this.articoloFilatoColoreRitorto = articoloFilatoColoreRitorto;
setArticoloFilatoColoreRitorto(null);
}
public long getId_articoloFilato() {
return this.id_articoloFilato;
}
public void setId_articoloFilato(long id_articoloFilato) {
this.id_articoloFilato = id_articoloFilato;
}
public long getId_rigaDocumentoTessutoA() {
return this.id_rigaDocumentoTessutoA;
}
public void setId_rigaDocumentoTessutoA(long id_rigaDocumentoTessuto) {
this.id_rigaDocumentoTessutoA = id_rigaDocumentoTessuto;
setRigaDocumentoTessutoA(null);
}
public Vectumerator<RigaDocumento> findByDocumentoArticolo(long l_id_documento, long l_id_articolo) {
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO AS A left join ARTICOLO AS B on A.id_articolo=B.id_articolo ";
String s_Sql_order = " order by A.id_rigaDocumento desc";
WcString wc = new WcString();
wc.addWc("A.id_documento=" + l_id_documento);
if (l_id_articolo == 0L) {
wc.addWc("(A.id_articolo is null or A.id_articolo=0)");
} else {
wc.addWc("A.id_articolo=" + l_id_articolo);
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
return findRows(stmt);
} catch (Exception e) {
handleDebug(e, 0);
return AB_EMPTY_VECTUMERATOR;
}
}
public RigaDocumento getRigaDocumentoTessutoA() {
this.rigaDocumentoTessutoA = (RigaDocumento)getSecondaryObject(this.rigaDocumentoTessutoA, RigaDocumento.class,
getId_rigaDocumentoTessutoA());
return this.rigaDocumentoTessutoA;
}
public void setRigaDocumentoTessutoA(RigaDocumento rigaDocumentoTessutoA) {
this.rigaDocumentoTessutoA = rigaDocumentoTessutoA;
}
public void findMagTessutoDisponibilitaOld(long l_id_articoloTessuto, long l_id_articoloTessutoColore, String l_seriale, long l_tipologia_magfisico, long l_id_clifor, Date dataA) {
String s_Sql_Sum = " SUM(A.kg*segnoMov) as kg, SUM(A.mt*segnoMov) as mt, SUM(A.nr*segnoMov) as nr from RIGA_DOCUMENTO AS A ";
String s_Sql_colonne = "";
String s_Sql_join = "";
WcString wc = new WcString();
wc.addWc("A.id_magFisico>0");
if (l_id_articoloTessuto > 0L)
s_Sql_Sum = s_Sql_Sum + " inner join ARTICOLO_TESSUTO AS F ON A.id_articoloTessuto=F.id_articoloTessuto";
if (l_id_articoloTessuto != 0L) {
wc.addWc(" A.id_articoloTessuto = " + l_id_articoloTessuto);
s_Sql_colonne = s_Sql_colonne + " A.id_articoloTessuto,";
}
if (l_id_articoloTessutoColore != 0L) {
wc.addWc(" A.id_articoloTessutoColore = " + l_id_articoloTessutoColore);
s_Sql_colonne = s_Sql_colonne + " A.id_articoloTessutoColore,";
}
if (l_seriale != null && !l_seriale.isEmpty()) {
wc.addWc(" A.seriale = " + l_seriale);
s_Sql_colonne = s_Sql_colonne + " A.seriale,";
}
if (l_id_clifor != 0L) {
wc.addWc(" A.id_clifor = " + l_id_clifor);
s_Sql_colonne = s_Sql_colonne + " A.id_clifor,";
}
if (dataA != null) {
s_Sql_join = " INNER JOIN DOCUMENTO AS DOC ON A.id_documento=DOC.id_documento ";
wc.addWc(" DOC.dataDocumento <= ?");
s_Sql_Sum = s_Sql_Sum + s_Sql_Sum;
}
if (l_tipologia_magfisico != 0L) {
wc.addWc(" B.flgTipo = " + l_tipologia_magfisico);
s_Sql_colonne = s_Sql_colonne + " A.id_magFisico,";
s_Sql_Sum = s_Sql_Sum + ", MAG_FISICO AS B";
wc.addWc(" A.id_magFisico = B.id_magFisico ");
}
String s_sql_groupby = "";
if (!s_Sql_colonne.isEmpty())
s_sql_groupby = " group by " + s_Sql_colonne.substring(0, s_Sql_colonne.length() - 1);
try {
PreparedStatement stmt = getConn()
.prepareStatement("select " + s_Sql_colonne + s_Sql_Sum + wc.toString() + s_sql_groupby);
if (dataA != null)
stmt.setDate(1, dataA);
findFirstRecord(stmt);
} catch (SQLException e) {
handleDebug(e);
}
}
public RigaDocumento() {}
}