338 lines
12 KiB
Java
338 lines
12 KiB
Java
package it.acxent.contab;
|
|
|
|
import it.acxent.anag.MagFisico;
|
|
import it.acxent.db.ApplParmFull;
|
|
import it.acxent.db.ResParm;
|
|
import it.acxent.db.WcString;
|
|
import it.acxent.util.StringTokenizer;
|
|
import it.acxent.util.Vectumerator;
|
|
import java.io.Serializable;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.SQLException;
|
|
import java.util.HashMap;
|
|
|
|
public class RigaDocumentoP extends _ContabAdapter implements Serializable {
|
|
private static final long serialVersionUID = 1068781847344225625L;
|
|
|
|
private long id_documento;
|
|
|
|
private long id_rigaDocumento;
|
|
|
|
private long id_rigaDocumentoPrelevata;
|
|
|
|
private double quantitaPrelevata;
|
|
|
|
private Documento documento;
|
|
|
|
private RigaDocumento rigaDocumento;
|
|
|
|
private RigaDocumento rigaDocumentoPrelevata;
|
|
|
|
private long id_rigaDocumentoP;
|
|
|
|
public RigaDocumentoP(ApplParmFull newApplParmFull) {
|
|
super(newApplParmFull);
|
|
}
|
|
|
|
public RigaDocumentoP() {}
|
|
|
|
public void setId_documento(long newId_documento) {
|
|
this.id_documento = newId_documento;
|
|
setDocumento(null);
|
|
}
|
|
|
|
public void setId_rigaDocumento(long newId_rigaDocumento) {
|
|
this.id_rigaDocumento = newId_rigaDocumento;
|
|
setRigaDocumento(null);
|
|
}
|
|
|
|
public void setId_rigaDocumentoPrelevata(long newId_rigaDocumentoPrelevata) {
|
|
this.id_rigaDocumentoPrelevata = newId_rigaDocumentoPrelevata;
|
|
setRigaDocumentoPrelevata(null);
|
|
}
|
|
|
|
public void setQuantitaPrelevata(double newQuantitaPrelevata) {
|
|
this.quantitaPrelevata = newQuantitaPrelevata;
|
|
}
|
|
|
|
public long getId_documento() {
|
|
return this.id_documento;
|
|
}
|
|
|
|
public long getId_rigaDocumento() {
|
|
return this.id_rigaDocumento;
|
|
}
|
|
|
|
public long getId_rigaDocumentoPrelevata() {
|
|
return this.id_rigaDocumentoPrelevata;
|
|
}
|
|
|
|
public double getQuantitaPrelevata() {
|
|
return this.quantitaPrelevata;
|
|
}
|
|
|
|
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 setRigaDocumento(RigaDocumento newRigaDocumento) {
|
|
this.rigaDocumento = newRigaDocumento;
|
|
}
|
|
|
|
public RigaDocumento getRigaDocumento() {
|
|
this.rigaDocumento = (RigaDocumento)getSecondaryObject(this.rigaDocumento, RigaDocumento.class, getId_rigaDocumento());
|
|
return this.rigaDocumento;
|
|
}
|
|
|
|
public void setRigaDocumentoPrelevata(RigaDocumento newRigaDocumentoPrelevata) {
|
|
this.rigaDocumentoPrelevata = newRigaDocumentoPrelevata;
|
|
}
|
|
|
|
public RigaDocumento getRigaDocumentoPrelevata() {
|
|
this.rigaDocumentoPrelevata = (RigaDocumento)getSecondaryObject(this.rigaDocumentoPrelevata, RigaDocumento.class,
|
|
getId_rigaDocumentoPrelevata());
|
|
return this.rigaDocumentoPrelevata;
|
|
}
|
|
|
|
protected void deleteCascade() {}
|
|
|
|
public Vectumerator findByCR(RigaDocumentoPCR CR, int pageNumber, int pageRows) {
|
|
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO_P AS A";
|
|
String s_Sql_Order = "";
|
|
WcString wc = new WcString();
|
|
if (!CR.getSearchTxt().trim().isEmpty()) {
|
|
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
|
StringBuffer txt = new StringBuffer("(");
|
|
while (st.hasMoreTokens()) {
|
|
String token = st.nextToken();
|
|
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
|
if (st.hasMoreTokens())
|
|
txt.append(" and ");
|
|
}
|
|
txt.append(")");
|
|
wc.addWc(txt.toString());
|
|
}
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
return findRows(stmt, pageNumber, pageRows);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public ResParm delete() {
|
|
RigaDocumento rd = getRigaDocumento();
|
|
RigaDocumento rdP = getRigaDocumentoPrelevata();
|
|
long id_rigaDocumentoP = getId_rigaDocumentoP();
|
|
ResParm rp = super.delete();
|
|
if (rp.getStatus()) {
|
|
rdP.setFlgRigaPrelevata(0L);
|
|
rdP.aggiornaQuantitaPrelevata();
|
|
rdP.getDocumento().aggiornaFlgDocumentoPrelevato(0L);
|
|
rd.aggiornaQuantitaAssociata();
|
|
RigaDocumento.cancellaMovimento(rd, rdP.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoPartenza(),
|
|
rdP.getDocumento().getTipoDocumento().getCausaleMagazzino().getId_magFisicoArrivo());
|
|
rdP.getArticolo().resetCalcoloQuantita();
|
|
}
|
|
return rp;
|
|
}
|
|
|
|
public ResParm superDelete() {
|
|
ResParm rp = super.delete();
|
|
return rp;
|
|
}
|
|
|
|
public ResParm save() {
|
|
ResParm rp = super.save();
|
|
if (rp.getStatus()) {
|
|
getRigaDocumentoPrelevata().aggiornaQuantitaPrelevata();
|
|
getRigaDocumento().aggiornaQuantitaAssociata();
|
|
}
|
|
return rp;
|
|
}
|
|
|
|
public Vectumerator findByDocumento(long l_id_documento, int pageNumber, int pageRows) {
|
|
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO_P AS A";
|
|
String s_Sql_Order = "";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.id_documento=" + l_id_documento);
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
return findRows(stmt, pageNumber, pageRows);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public Vectumerator findByRigaDocumento(long l_id_rigaDocumento, int pageNumber, int pageRows) {
|
|
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO_P 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, pageNumber, pageRows);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public Vectumerator findByRigaDocumentoPrelevata(long l_id_rigaDocumentoPrelevata, int pageNumber, int pageRows) {
|
|
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO_P AS A";
|
|
String s_Sql_Order = "";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.id_rigaDocumentoPrelevata=" + l_id_rigaDocumentoPrelevata);
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
return findRows(stmt, pageNumber, pageRows);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public void findByKey(RigaDocumentoPKey rdpK) {
|
|
String s_Sql_Find = "select A.* from RIGA_DOCUMENTO_P AS A";
|
|
String s_Sql_Order = "";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.id_rigaDocumento=" + rdpK.getId_rigaDocumento());
|
|
wc.addWc("A.id_rigaDocumentoPrelevata=" + rdpK.getId_rigaDocumentoPrelevata());
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
findFirstRecord(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
}
|
|
}
|
|
|
|
public long getId_rigaDocumentoP() {
|
|
return this.id_rigaDocumentoP;
|
|
}
|
|
|
|
public void setId_rigaDocumentoP(long id_rigaDocumentoP) {
|
|
this.id_rigaDocumentoP = id_rigaDocumentoP;
|
|
}
|
|
|
|
public double getQuantitaPrelevatoByRigaDocumentoPrelevata(long l_id_rigaDocumento) {
|
|
String s_Sql_Find = "select SUM(quantitaPrelevata) as _tot from RIGA_DOCUMENTO_P AS A";
|
|
String s_Sql_Order = "";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.id_rigaDocumentoPrelevata=" + l_id_rigaDocumento);
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
|
return (double)getCount(stmt, "_tot");
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return 0.0D;
|
|
}
|
|
}
|
|
|
|
public void aggiustaOrdiniSuMovimenti() {
|
|
try {
|
|
HashMap<Long, Long> ht = new HashMap<>();
|
|
String s_Sql_Find = "SELECT A.* FROM RIGA_DOCUMENTO_P AS A WHERE A.id_rigaDocumentoPrelevata NOT IN (SELECT id_rigaDocumento FROM RIGA_DOCUMENTO)";
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find);
|
|
Vectumerator<RigaDocumentoP> vec = findRows(stmt, 0, 0);
|
|
while (vec.hasMoreElements()) {
|
|
RigaDocumentoP rdp = (RigaDocumentoP)vec.nextElement();
|
|
long id_articolo = rdp.getRigaDocumento().getId_articolo();
|
|
Movimento mov = new Movimento(getApFull());
|
|
mov.deleteP(rdp.getId_rigaDocumentoPrelevata());
|
|
mov.setId_articolo(id_articolo);
|
|
mov.setId_articoloVariante(rdp.getRigaDocumento().getId_articoloVariante());
|
|
mov.setId_articoloTaglia(rdp.getRigaDocumento().getId_articoloTaglia());
|
|
mov.setId_clifor(rdp.getRigaDocumento().getDocumento().getId_clifor());
|
|
mov.setId_causaleMagazzino(rdp.getRigaDocumento().getDocumento().getTipoDocumento().getId_causaleMagazzino());
|
|
MagFisico mag = new MagFisico(getApFull());
|
|
mag.findMagazzinoOrdinato();
|
|
mov.setId_magFisico(mag.getId_magFisico());
|
|
mov.setId_rigaDocumento(rdp.getId_rigaDocumento());
|
|
if (rdp.getRigaDocumento().getArticolo().getTipo().getTipologiaArticolo().getFlgUdm() == 1L) {
|
|
mov.setNr(-1.0D * rdp.getQuantitaPrelevata());
|
|
} else if (rdp.getRigaDocumento().getArticolo().getTipo().getTipologiaArticolo().getFlgUdm() == 2L) {
|
|
mov.setKg(-1.0D * rdp.getQuantitaPrelevata());
|
|
} else if (rdp.getRigaDocumento().getArticolo().getTipo().getTipologiaArticolo().getFlgUdm() == 3L) {
|
|
mov.setMt(-1.0D * rdp.getQuantitaPrelevata());
|
|
}
|
|
mov.save();
|
|
if (ht.containsKey(Long.valueOf(id_articolo))) {
|
|
long qta = ht.get(Long.valueOf(id_articolo));
|
|
qta = (long)((double)qta + rdp.getQuantitaPrelevata());
|
|
ht.put(Long.valueOf(id_articolo), Long.valueOf(qta));
|
|
continue;
|
|
}
|
|
ht.put(Long.valueOf(id_articolo), Long.valueOf((long)rdp.getQuantitaPrelevata()));
|
|
}
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
}
|
|
}
|
|
|
|
public double getQuantitaPrelevatoByRigaDocumento(long l_id_rigaDocumento) {
|
|
String s_Sql_Find = "select SUM(quantitaPrelevata) as _tot from RIGA_DOCUMENTO_P 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 (double)getCount(stmt, "_tot");
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return 0.0D;
|
|
}
|
|
}
|
|
|
|
public void aggiustaOrdiniSuRD() {
|
|
try {
|
|
int i = 0, j = 0;
|
|
int se1 = 10;
|
|
int se2 = 100;
|
|
String s_Sql_Find = "SELECT A.* FROM RIGA_DOCUMENTO_P AS A ";
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find);
|
|
Vectumerator<RigaDocumentoP> vec = findRows(stmt, 0, 0);
|
|
while (vec.hasMoreElements()) {
|
|
RigaDocumentoP row = (RigaDocumentoP)vec.nextElement();
|
|
if (row.getRigaDocumento().getId_rigaDocumento() == 0L || row.getRigaDocumentoPrelevata().getId_rigaDocumento() == 0L) {
|
|
row.delete();
|
|
System.out.println("x");
|
|
} else {
|
|
RigaDocumento rd = (RigaDocumento)row.getRigaDocumento().clone();
|
|
rd.setId_rigaDocumento(0L);
|
|
rd.setDBState(0);
|
|
rd.setId_rigaDocumentoMov(row.getId_rigaDocumento());
|
|
rd.setId_rigaDocumentoPrelevata(row.getId_rigaDocumentoPrelevata());
|
|
MagFisico mag = new MagFisico(getApFull());
|
|
mag.findMagazzinoOrdinato();
|
|
rd.setId_magFisico(mag.getId_magFisico());
|
|
rd.setSegnoMov(-1L);
|
|
if (row.getRigaDocumento().getArticolo().getTipo().getTipologiaArticolo().getFlgUdm() == 1L) {
|
|
rd.setNr(row.getQuantitaPrelevata());
|
|
} else if (row.getRigaDocumento().getArticolo().getTipo().getTipologiaArticolo().getFlgUdm() == 2L) {
|
|
rd.setKg(row.getQuantitaPrelevata());
|
|
} else if (row.getRigaDocumento().getArticolo().getTipo().getTipologiaArticolo().getFlgUdm() == 3L) {
|
|
rd.setMt(row.getQuantitaPrelevata());
|
|
}
|
|
rd.setQuantitaPrelevata(row.getQuantitaPrelevata());
|
|
rd.superSave();
|
|
}
|
|
i++;
|
|
if (se1 > 0 && i % se1 == 0)
|
|
System.out.print(".");
|
|
if (se2 > 0 && i % se2 == 0)
|
|
System.out.println("" + i + " su " + i);
|
|
}
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
} catch (Exception e) {
|
|
handleDebug(e);
|
|
}
|
|
}
|
|
}
|