971 lines
37 KiB
Java
971 lines
37 KiB
Java
|
|
package it.acxent.contab;
|
||
|
|
|
||
|
|
import it.acxent.anag.Clifor;
|
||
|
|
import it.acxent.anag.MagFisico;
|
||
|
|
import it.acxent.art.Articolo;
|
||
|
|
import it.acxent.art.ArticoloTaglia;
|
||
|
|
import it.acxent.art.ArticoloVariante;
|
||
|
|
import it.acxent.art.TipologiaArticolo;
|
||
|
|
import it.acxent.db.ApplParmFull;
|
||
|
|
import it.acxent.db.ResParm;
|
||
|
|
import it.acxent.db.WcString;
|
||
|
|
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.SQLException;
|
||
|
|
|
||
|
|
public class Movimento extends _ContabAdapter implements Serializable {
|
||
|
|
private static final long serialVersionUID = -5378446506644250769L;
|
||
|
|
|
||
|
|
private long id_movimento;
|
||
|
|
|
||
|
|
private long id_rigaDocumento;
|
||
|
|
|
||
|
|
private long id_articoloVariante;
|
||
|
|
|
||
|
|
private long id_articoloTaglia;
|
||
|
|
|
||
|
|
private long id_magFisico;
|
||
|
|
|
||
|
|
private long id_clifor;
|
||
|
|
|
||
|
|
private String seriale;
|
||
|
|
|
||
|
|
private double kg;
|
||
|
|
|
||
|
|
private double mt;
|
||
|
|
|
||
|
|
private double nr;
|
||
|
|
|
||
|
|
private RigaDocumento rigaDocumento;
|
||
|
|
|
||
|
|
private Articolo articolo;
|
||
|
|
|
||
|
|
private ArticoloVariante articoloVariante;
|
||
|
|
|
||
|
|
private ArticoloTaglia articoloTaglia;
|
||
|
|
|
||
|
|
private MagFisico magFisico;
|
||
|
|
|
||
|
|
private Clifor clifor;
|
||
|
|
|
||
|
|
private long id_articolo;
|
||
|
|
|
||
|
|
private long id_rigaDocumentoP;
|
||
|
|
|
||
|
|
private long id_causaleMagazzino;
|
||
|
|
|
||
|
|
private CausaleMagazzino causaleMagazzino;
|
||
|
|
|
||
|
|
private Date dataMovimento;
|
||
|
|
|
||
|
|
public Movimento(ApplParmFull newApplParmFull) {
|
||
|
|
super(newApplParmFull);
|
||
|
|
}
|
||
|
|
|
||
|
|
public Movimento() {}
|
||
|
|
|
||
|
|
protected void deleteCascade() {}
|
||
|
|
|
||
|
|
public Vectumerator xxfindByCR(MovimentoCR CR, int pageNumber, int pageRows) {
|
||
|
|
return findSaldiArticoloByCR(CR, pageNumber, pageRows);
|
||
|
|
}
|
||
|
|
|
||
|
|
public Vectumerator findSaldiArticoloByCR(MovimentoCR 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) as kg, SUM(A.mt) as mt, SUM(A.nr) as nr from MOVIMENTO 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) > 0 OR SUM(mt) > 0 OR SUM(nr) > 0 ";
|
||
|
|
} else if (CR.getFlgInMagazzino() == 2L) {
|
||
|
|
s_Sql_Having = " Having SUM(kg) < 0 OR SUM(mt) < 0 OR SUM(nr) < 0 ";
|
||
|
|
} else if (CR.getFlgInMagazzino() == 3L) {
|
||
|
|
s_Sql_Having = " Having SUM(kg) <> 0 OR SUM(mt) <> 0 OR SUM(nr) <> 0 ";
|
||
|
|
}
|
||
|
|
WcString wc = new WcString();
|
||
|
|
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_articoloTaglia() > 0L)
|
||
|
|
wc.addWc(" A.id_articoloTaglia = " + CR.getId_articoloTaglia());
|
||
|
|
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 long getId_movimento() {
|
||
|
|
return this.id_movimento;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setId_movimento(long id_movimento) {
|
||
|
|
this.id_movimento = id_movimento;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getId_rigaDocumento() {
|
||
|
|
return this.id_rigaDocumento;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setId_rigaDocumento(long id_rigaDocumento) {
|
||
|
|
this.id_rigaDocumento = id_rigaDocumento;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getId_articolo() {
|
||
|
|
return this.id_articolo;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setId_articolo(long id_articolo) {
|
||
|
|
this.id_articolo = id_articolo;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getId_articoloVariante() {
|
||
|
|
return this.id_articoloVariante;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setId_articoloVariante(long id_articoloVariante) {
|
||
|
|
this.id_articoloVariante = id_articoloVariante;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getId_articoloTaglia() {
|
||
|
|
return this.id_articoloTaglia;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setId_articoloTaglia(long id_articoloTaglia) {
|
||
|
|
this.id_articoloTaglia = id_articoloTaglia;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getId_magFisico() {
|
||
|
|
return this.id_magFisico;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setId_magFisico(long id_magFisico) {
|
||
|
|
this.id_magFisico = id_magFisico;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getId_clifor() {
|
||
|
|
return this.id_clifor;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setId_clifor(long id_clifor) {
|
||
|
|
this.id_clifor = id_clifor;
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getSeriale() {
|
||
|
|
return (this.seriale == null) ? "" : this.seriale;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setSeriale(String seriale) {
|
||
|
|
this.seriale = seriale;
|
||
|
|
}
|
||
|
|
|
||
|
|
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 RigaDocumento getRigaDocumento() {
|
||
|
|
this.rigaDocumento = (RigaDocumento)getSecondaryObject(this.rigaDocumento, RigaDocumento.class, getId_rigaDocumento());
|
||
|
|
return this.rigaDocumento;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setRigaDocumento(RigaDocumento rigaDocumento) {
|
||
|
|
this.rigaDocumento = rigaDocumento;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Articolo getArticolo() {
|
||
|
|
this.articolo = (Articolo)getSecondaryObject(this.articolo, Articolo.class, getId_articolo());
|
||
|
|
return this.articolo;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setArticolo(Articolo articolo) {
|
||
|
|
this.articolo = articolo;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ArticoloVariante getArticoloVariante() {
|
||
|
|
this.articoloVariante = (ArticoloVariante)getSecondaryObject(this.articoloVariante, ArticoloVariante.class, getId_articoloVariante());
|
||
|
|
return this.articoloVariante;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setArticoloVariante(ArticoloVariante articoloVariante) {
|
||
|
|
this.articoloVariante = articoloVariante;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ArticoloTaglia getArticoloTaglia() {
|
||
|
|
this.articoloTaglia = (ArticoloTaglia)getSecondaryObject(this.articoloTaglia, ArticoloTaglia.class, getId_articoloTaglia());
|
||
|
|
return this.articoloTaglia;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setArticoloTaglia(ArticoloTaglia articoloTaglia) {
|
||
|
|
this.articoloTaglia = articoloTaglia;
|
||
|
|
}
|
||
|
|
|
||
|
|
public MagFisico getMagFisico() {
|
||
|
|
this.magFisico = (MagFisico)getSecondaryObject(this.magFisico, MagFisico.class, getId_magFisico());
|
||
|
|
return this.magFisico;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setMagFisico(MagFisico magFisico) {
|
||
|
|
this.magFisico = magFisico;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Clifor getClifor() {
|
||
|
|
this.clifor = (Clifor)getSecondaryObject(this.clifor, Clifor.class, getId_clifor());
|
||
|
|
return this.clifor;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setClifor(Clifor clifor) {
|
||
|
|
this.clifor = clifor;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Vectumerator findByRigaDocumento(long l_id_rigaDocumento) {
|
||
|
|
String s_Sql_Find = "select A.* from MOVIMENTO AS A ";
|
||
|
|
String s_Sql_Order = "";
|
||
|
|
WcString wc = new WcString();
|
||
|
|
wc.addWc(" A.id_rigaDocumento = " + l_id_rigaDocumento);
|
||
|
|
try {
|
||
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||
|
|
return findRows(stmt, 0, 0);
|
||
|
|
} catch (SQLException e) {
|
||
|
|
handleDebug(e);
|
||
|
|
return AB_EMPTY_VECTUMERATOR;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void findDisponibilita(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) {
|
||
|
|
String s_Sql_Sum = " SUM(A.kg) as kg, SUM(A.mt) as mt, SUM(A.nr) as nr from MOVIMENTO AS A ";
|
||
|
|
String s_Sql_colonne = "";
|
||
|
|
String s_Sql_join = "";
|
||
|
|
WcString wc = new WcString();
|
||
|
|
wc.addWc(" A.id_magFisico = B.id_magFisico ");
|
||
|
|
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_tipologia_magfisico != 0L) {
|
||
|
|
wc.addWc(" B.flgTipo = " + l_tipologia_magfisico);
|
||
|
|
s_Sql_colonne = s_Sql_colonne + " A.id_magFisico,";
|
||
|
|
}
|
||
|
|
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 RIGA_DOCUMENTO AS RD ON A.id_rigaDocumento=RD.id_rigaDocumento INNER JOIN DOCUMENTO AS DOC ON RD.id_documento=DOC.id_documento ";
|
||
|
|
wc.addWc(" DOC.dataDocumento <= ?");
|
||
|
|
}
|
||
|
|
String s_sql_groupby = "";
|
||
|
|
if (!s_Sql_colonne.isEmpty())
|
||
|
|
s_sql_groupby = " group by " + s_Sql_colonne.substring(0, s_Sql_colonne.length() - 1);
|
||
|
|
s_Sql_Sum = s_Sql_Sum + s_Sql_Sum + ", MAG_FISICO AS B";
|
||
|
|
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 findSaldiArticoloVarianteTagliaByCR(MovimentoCR CR, int pageNumber, int pageRows) {
|
||
|
|
String s_Sql_Find = "select B.id_articolo, C.id_articoloVariante , SUM(A.kg) as kg, SUM(A.mt) as mt, SUM(A.nr) as nr from ARTICOLO AS B LEFT JOIN ARTICOLO_VARIANTE AS C ON B.id_articolo=C.id_articolo LEFT JOIN MOVIMENTO 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";
|
||
|
|
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) > 0 OR SUM(A.mt) > 0 OR SUM(A.nr) > 0 ";
|
||
|
|
} else if (CR.getFlgInMagazzino() == 2L) {
|
||
|
|
s_Sql_Having = " Having SUM(A.kg) < 0 OR SUM(A.mt) < 0 OR SUM(A.nr) < 0 ";
|
||
|
|
}
|
||
|
|
WcString wc = new WcString();
|
||
|
|
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 boolean isArticoloDisponibile(long l_id_articolo, long l_id_articoloVariante, long l_id_taglia, String l_seriale, long l_id_magazzino) {
|
||
|
|
return (getQuantita() > 0.0D);
|
||
|
|
}
|
||
|
|
|
||
|
|
public double getQuantita() {
|
||
|
|
TipologiaArticolo ta = getArticolo().getTipologiaArticolo();
|
||
|
|
if (ta.getFlgUdm() == 1L)
|
||
|
|
return getNr();
|
||
|
|
if (ta.getFlgUdm() == 3L)
|
||
|
|
return getMt();
|
||
|
|
if (ta.getFlgUdm() == 2L)
|
||
|
|
return getKg();
|
||
|
|
return 0.0D;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getId_rigaDocumentoP() {
|
||
|
|
return this.id_rigaDocumentoP;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setId_rigaDocumentoP(long id_rigaDocumentoP) {
|
||
|
|
this.id_rigaDocumentoP = id_rigaDocumentoP;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void findDisponibilitaPuntuale(long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia, String l_seriale, long l_id_magfisico, long l_id_clifor) {
|
||
|
|
String s_Sql_Sum = " SUM(kg) as kg, SUM(mt) as mt, SUM(nr) as nr from MOVIMENTO AS A";
|
||
|
|
String s_Sql_colonne = "";
|
||
|
|
WcString wc = new WcString();
|
||
|
|
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,";
|
||
|
|
}
|
||
|
|
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 ResParm deleteP(long l_id_rigaDocumentoP) {
|
||
|
|
return delete("DELETE FROM MOVIMENTO WHERE id_rigaDocumentoP = " + l_id_rigaDocumentoP);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void findDisponibilitaPuntualeMagazziniInterni(long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia, String l_seriale, long l_id_clifor) {
|
||
|
|
String s_Sql_Sum = " SUM(kg) as kg, SUM(mt) as mt, SUM(nr) as nr from MOVIMENTO AS A";
|
||
|
|
String s_Sql_colonne = "";
|
||
|
|
WcString wc = new WcString();
|
||
|
|
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,";
|
||
|
|
}
|
||
|
|
MagFisico mag = new MagFisico(getApFull());
|
||
|
|
Vectumerator<MagFisico> vecMag = mag.findByTipo(1L);
|
||
|
|
if (vecMag.hasMoreElements()) {
|
||
|
|
StringBuilder mf = new StringBuilder("");
|
||
|
|
s_Sql_colonne = s_Sql_colonne + " id_magFisico,";
|
||
|
|
while (vecMag.hasMoreElements()) {
|
||
|
|
mag = (MagFisico)vecMag.nextElement();
|
||
|
|
if (mf.length() > 0)
|
||
|
|
mf.append(" OR ");
|
||
|
|
mf.append(" id_magFisico = " + mag.getId_magFisico());
|
||
|
|
}
|
||
|
|
mf.append(")");
|
||
|
|
wc.addWc("(" + mf.toString());
|
||
|
|
}
|
||
|
|
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 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) {
|
||
|
|
Movimento mov = new Movimento(ap);
|
||
|
|
mov.findDisponibilitaPuntualeMagazziniInterni(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.setFlgDispo((mov.getQuantita() > 0.0D) ? 1L : 0L);
|
||
|
|
bean.save();
|
||
|
|
}
|
||
|
|
if (l_id_articoloVariante > 0L) {
|
||
|
|
ArticoloVariante bean = new ArticoloVariante(ap);
|
||
|
|
bean.resetCalcoloQuantita();
|
||
|
|
bean.save();
|
||
|
|
}
|
||
|
|
art.setFlgDispo((mov.getQuantita() > 0.0D) ? 1L : 0L);
|
||
|
|
}
|
||
|
|
art.save();
|
||
|
|
RigaDocumento rd = new RigaDocumento(ap);
|
||
|
|
rd.resetStatoPrenotazioneByArticolo(l_id_articolo, l_id_articoloVariante, l_id_articoloTaglia);
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm save() {
|
||
|
|
setDataMovimento(getRigaDocumento().getDocumento().getDataDocumento());
|
||
|
|
ResParm rp = super.save();
|
||
|
|
if (rp.getStatus())
|
||
|
|
rp = aggiornaDispo(getApFull(), getId_articolo(), getId_articoloVariante(), getId_articoloTaglia(), getLastUpdId_user());
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public ResParm delete(String sqlString) {
|
||
|
|
ResParm rp = new ResParm(false);
|
||
|
|
try {
|
||
|
|
Movimento mov = (Movimento)clone();
|
||
|
|
rp = super.delete(sqlString);
|
||
|
|
aggiornaDispo(getApFull(), mov.getId_articolo(), mov.getId_articoloVariante(), mov.getId_articoloTaglia(), getLastInsertId());
|
||
|
|
} catch (Exception e) {
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setException(e);
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public long getId_causaleMagazzino() {
|
||
|
|
return this.id_causaleMagazzino;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setId_causaleMagazzino(long id_causaleMagazzino) {
|
||
|
|
this.id_causaleMagazzino = id_causaleMagazzino;
|
||
|
|
}
|
||
|
|
|
||
|
|
public CausaleMagazzino getCausaleMagazzino() {
|
||
|
|
this.causaleMagazzino = (CausaleMagazzino)getSecondaryObject(this.causaleMagazzino, CausaleMagazzino.class, getId_causaleMagazzino());
|
||
|
|
return this.causaleMagazzino;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setCausaleMagazzino(CausaleMagazzino causaleMagazzino) {
|
||
|
|
this.causaleMagazzino = causaleMagazzino;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void findByRigaDocumentoCausale(long l_id_rigaDocumento, long l_id_causaleMagazzino) {
|
||
|
|
String s_Sql_Find = "select A.* from MOVIMENTO AS A ";
|
||
|
|
String s_Sql_Order = "";
|
||
|
|
WcString wc = new WcString();
|
||
|
|
wc.addWc(" A.id_rigaDocumento = " + l_id_rigaDocumento);
|
||
|
|
wc.addWc(" A.id_causaleMagazzino = " + l_id_causaleMagazzino);
|
||
|
|
try {
|
||
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||
|
|
findFirstRecord(stmt);
|
||
|
|
} catch (SQLException e) {
|
||
|
|
handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void findBySerialeDisponibile(String l_seriale) {
|
||
|
|
String s_Sql_Find = "SELECT A.*, SUM(A.nr) AS nr from MOVIMENTO AS A ";
|
||
|
|
String s_Sql_Having = " HAVING nr > 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 findBySerialeEsistente(String l_seriale) {
|
||
|
|
String s_Sql_Find = "SELECT A.* from MOVIMENTO AS A ";
|
||
|
|
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 Date getDataMovimento() {
|
||
|
|
return this.dataMovimento;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setDataMovimento(Date dataMovimento) {
|
||
|
|
this.dataMovimento = dataMovimento;
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getDescrizioneArticolo() {
|
||
|
|
if (getId_articoloTaglia() != 0L)
|
||
|
|
return getArticoloTaglia().getDescrizioneCompleta();
|
||
|
|
if (getId_articoloVariante() == 0L)
|
||
|
|
return getArticolo().getDescrizioneCompleta();
|
||
|
|
return getArticoloVariante().getDescrizioneCompleta();
|
||
|
|
}
|
||
|
|
|
||
|
|
public Vectumerator findByCR(MovimentoCR 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.* from MOVIMENTO AS A, RIGA_DOCUMENTO AS B, DOCUMENTO AS C, ARTICOLO AS D ");
|
||
|
|
String s_Sql_Order = " order by D.nome,D.codice, A.seriale, C.dataDocumento, 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;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void findByCRCreateStmtDate(MovimentoCR 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);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void findByCRCreateWC(MovimentoCR CR, StringBuffer s_Sql_Find, WcString wc) {
|
||
|
|
wc.addWc("A.id_rigaDocumento=B.id_rigaDocumento");
|
||
|
|
wc.addWc("B.id_documento=C.id_documento");
|
||
|
|
wc.addWc("B.id_articolo=D.id_articolo");
|
||
|
|
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.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.getSeriale().isEmpty()) {
|
||
|
|
String temp = CR.getSeriale();
|
||
|
|
temp = temp.replace("%", "\\%");
|
||
|
|
temp = temp.replace("_", "\\_");
|
||
|
|
temp = temp.replace("*", "%");
|
||
|
|
wc.addWc("A.seriale like '" + CR.getSeriale() + "'");
|
||
|
|
}
|
||
|
|
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(MovimentoCR CR) {
|
||
|
|
StringBuffer s_Sql_Find = new StringBuffer("select count(*) as tot from MOVIMENTO AS A, RIGA_DOCUMENTO AS B, 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 double getSaldoByArticoloVarianteTagliaMagazzino(long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia, long l_id_magFisico) {
|
||
|
|
String s_Sql_Find = "select SUM(A.kg) as kg, SUM(A.mt) as mt, SUM(A.nr) as nr from MOVIMENTO AS A ";
|
||
|
|
String s_Sql_Group = " group by A.id_articolo, A.id_articoloVariante, A.id_articoloTaglia ";
|
||
|
|
String s_Sql_Order = " ";
|
||
|
|
WcString wc = new WcString();
|
||
|
|
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);
|
||
|
|
wc.addWc(" A.id_magFisico = " + l_id_magFisico);
|
||
|
|
try {
|
||
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString() + s_Sql_Group);
|
||
|
|
findFirstRecord(stmt);
|
||
|
|
return getNr();
|
||
|
|
} catch (SQLException e) {
|
||
|
|
handleDebug(e);
|
||
|
|
return 0.0D;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void creaFileCvs(MovimentoCR CR) {
|
||
|
|
try {
|
||
|
|
if (CR.getFlgReport().equals("S") && CR.getFlgTipoReport() == 1L) {
|
||
|
|
creaFileCvsCompatto(CR);
|
||
|
|
} else {
|
||
|
|
Vectumerator 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()) {
|
||
|
|
Movimento row = (Movimento)list.nextElement();
|
||
|
|
s1 = row.getRigaDocumento().getDocumento().getUsers().getCognomeNome() + row.getRigaDocumento().getDocumento().getUsers().getCognomeNome() + "\"" + SEP + "\"" + row.getRigaDocumento().getDocumento().getNumeroDocumentoCompleto() + SEP + row.getRigaDocumento().getDocumento().getClifor().getDescrizioneCompleta() + SEP + getDataFormat().format(row.getRigaDocumento().getDocumento().getDataDocumento()) + SEP + row.getCodiceArticolo() + SEP + row.getRigaDocumento().getDescrizioneRigaCompleta() + SEP + row.getSeriale() + SEP + getNf().format(row.getArticolo().getQuantita()) + SEP + row.getRigaDocumento().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("€", "€");
|
||
|
|
s1 = s1.replace("»", "-->");
|
||
|
|
outCvsFile.writeLine(s1);
|
||
|
|
}
|
||
|
|
outCvsFile.closeFile();
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public Vectumerator findSaldiArticoloVarianteTagliaByCR_OLD(MovimentoCR CR, int pageNumber, int pageRows) {
|
||
|
|
String s_Sql_Find = "select A.id_articolo, A.id_articoloVariante, A.id_articoloTaglia, SUM(A.kg) as kg, SUM(A.mt) as mt, SUM(A.nr) as nr from MOVIMENTO AS A INNER JOIN ARTICOLO AS B ON A.id_articolo=B.id_articolo LEFT JOIN ARTICOLO_VARIANTE AS C ON A.id_articoloVariante=C.id_articoloVariante INNER JOIN MAG_FISICO AS D ON A.id_magFisico=D.id_magFisico ";
|
||
|
|
String s_Sql_Group = " group by A.id_articolo, A.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(kg) > 0 OR SUM(mt) > 0 OR SUM(nr) > 0 ";
|
||
|
|
} else if (CR.getFlgInMagazzino() == 2L) {
|
||
|
|
s_Sql_Having = " Having SUM(kg) < 0 OR SUM(mt) < 0 OR SUM(nr) < 0 ";
|
||
|
|
}
|
||
|
|
WcString wc = new WcString();
|
||
|
|
if (!CR.getSearchTxt().isEmpty() && !CR.getSearchTxt().equals("*")) {
|
||
|
|
s_Sql_Find = s_Sql_Find + " LEFT JOIN ARTICOLO AS B ON A.id_articolo = B.id_articolo ";
|
||
|
|
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_magFisico() > 0L)
|
||
|
|
wc.addWc(" A.id_magFisico = " + CR.getId_magFisico());
|
||
|
|
if (CR.getFlgTipoMagazzino() > 0L)
|
||
|
|
wc.addWc(" D.flgTipo = " + CR.getFlgTipoMagazzino());
|
||
|
|
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 void findDisponibilitaPuntualeMagazziniInterniEsterni(long l_id_articolo, long l_id_articoloVariante, long l_id_articoloTaglia, String l_seriale, long l_id_clifor) {
|
||
|
|
String s_Sql_Sum = " SUM(kg) as kg, SUM(mt) as mt, SUM(nr) as nr from MOVIMENTO AS A";
|
||
|
|
String s_Sql_colonne = "";
|
||
|
|
WcString wc = new WcString();
|
||
|
|
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,";
|
||
|
|
}
|
||
|
|
MagFisico mag = new MagFisico(getApFull());
|
||
|
|
StringBuilder mf = new StringBuilder("");
|
||
|
|
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());
|
||
|
|
}
|
||
|
|
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 findDisponibilitaGlobaleMagazziniInterniEsterni(long l_id_articolo, String l_seriale, long l_id_clifor) {
|
||
|
|
findDisponibilitaPuntualeMagazziniInterniEsterni(0L, 0L, 0L, l_seriale, l_id_clifor);
|
||
|
|
setId_articolo(l_id_articolo);
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getCodiceArticolo() {
|
||
|
|
return getArticolo().getCodice();
|
||
|
|
}
|
||
|
|
|
||
|
|
public Vectumerator findByCRCompatto(MovimentoCR 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) as Kg,sum(A.mt) as mt, sum(A.nr) as nr, D.nome, D.codice from MOVIMENTO AS A, RIGA_DOCUMENTO AS B, 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;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void creaFileCvsCompatto(MovimentoCR CR) {
|
||
|
|
try {
|
||
|
|
Vectumerator 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()) {
|
||
|
|
Movimento row = (Movimento)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("€", "€");
|
||
|
|
s1 = s1.replace("»", "-->");
|
||
|
|
outCvsFile.writeLine(s1);
|
||
|
|
}
|
||
|
|
outCvsFile.closeFile();
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|