Regalamiunsorriso/decompiled-libs/www/acxent-common-1.0.1/it/acxent/art/ArticoloUsato.java

413 lines
12 KiB
Java

package it.acxent.art;
import it.acxent.anag.Clifor;
import it.acxent.contab.RigaDocumento;
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.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class ArticoloUsato extends _ArtAdapter implements Serializable {
private static final long serialVersionUID = 7574534452131775388L;
private long id_articoloUsato;
private long id_articolo;
private Articolo articolo;
private Date dataDocumento;
private String numeroDocumento;
private long flgTipoDocumento;
private double importo;
private long id_fornitore;
private Clifor fornitore;
private long id_cliente;
private Clifor cliente;
private long id_rigaDocumento;
private RigaDocumento rigaDocumento;
private String descrizioneRigaDocumento;
private String tmstStampa;
private long codiceAlt;
public static final long USATO_TIPO_DOCUMENTO_ACQUISTO = 1L;
public static final long USATO_TIPO_DOCUMENTO_VENDITA = 2L;
public static final long USATO_TIPO_DOCUMENTO_RESO = 3L;
public ArticoloUsato(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public ArticoloUsato() {}
protected void deleteCascade() {}
public static final String getTipoDocumento(long l_flgTipoDocumento) {
switch ((int)l_flgTipoDocumento) {
case 1:
return "ACQUISTO";
case 2:
return "VENDITA";
case 3:
return "RESO";
}
return "";
}
public final String getTipoDocumento() {
return getTipoDocumento(getFlgTipoDocumento());
}
public Vectumerator findByCR(ArticoloUsatoCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from ARTICOLO_USATO 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) {
removeCPConnection();
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator findByArticolo(long l_id_articolo, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from ARTICOLO_USATO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.id_articolo=" + l_id_articolo);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator findByArticoloOrdineManuale(long l_id_articolo) {
String s_Sql_Find = "select A.* from ARTICOLO_USATO AS A";
String s_Sql_Order = " order by A.dataDocumento asc,A.flgTipoDocumento asc";
WcString wc = new WcString();
wc.addWc("A.id_articolo=" + l_id_articolo);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return findRows(stmt);
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Clifor getFornitoreByArticolo(long l_id_articolo) {
if (l_id_articolo == 0L)
return new Clifor(getApFull());
String s_Sql_Find = "select A.* from ARTICOLO_USATO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.id_articolo=" + l_id_articolo);
wc.addWc("A.flgTipoDocumento=1");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
return getFornitore();
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return new Clifor(getApFull());
}
}
public boolean isArticoloAcquistato(long l_id_articolo) {
String s_Sql_Find = "select COUNT(*) as _count from ARTICOLO_USATO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.id_articolo=" + l_id_articolo);
wc.addWc("A.flgTipoDocumento=1");
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
long tot = getCount(stmt, "_count");
if (tot != 0L)
return true;
return false;
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return false;
}
}
public boolean isArticoloVenduto(long l_id_articolo) {
String s_Sql_Find = "select A.* from ARTICOLO_USATO AS A";
String s_Sql_Order = " ORDER BY A.id_articoloUsato DESC ";
WcString wc = new WcString();
wc.addWc("A.id_articolo=" + l_id_articolo);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
if (getFlgTipoDocumento() == 2L)
return true;
return false;
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return false;
}
}
public boolean isArticoloReso(long l_id_articolo) {
String s_Sql_Find = "select A.* from ARTICOLO_USATO AS A";
String s_Sql_Order = " ORDER BY A.id_articoloUsato DESC ";
WcString wc = new WcString();
wc.addWc("A.id_articolo=" + l_id_articolo);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
if (getFlgTipoDocumento() == 3L)
return true;
return false;
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return false;
}
}
public long getId_articoloUsato() {
return this.id_articoloUsato;
}
public void setId_articoloUsato(long id_articoloUsato) {
this.id_articoloUsato = id_articoloUsato;
}
public long getId_articolo() {
return this.id_articolo;
}
public void setId_articolo(long id_articolo) {
this.id_articolo = id_articolo;
setArticolo(null);
}
public Date getDataDocumento() {
if (getId_rigaDocumento() == 0L)
return this.dataDocumento;
return getRigaDocumento().getDocumento().getDataDocumento();
}
public void setDataDocumento(Date dataDocumento) {
this.dataDocumento = dataDocumento;
}
public String getIntestazione() {
if (getFlgTipoDocumento() == 1L)
return getFornitore().getCognomeNome().trim();
if (getFlgTipoDocumento() == 2L)
return getCliente().getCognomeNome().trim();
if (getFlgTipoDocumento() == 3L)
return getCliente().getCognomeNome().trim();
return "??";
}
public void setNumeroDocumento(String numeroDocumento) {
this.numeroDocumento = numeroDocumento;
}
public long getFlgTipoDocumento() {
return this.flgTipoDocumento;
}
public void setFlgTipoDocumento(long flgTipoDocumento) {
this.flgTipoDocumento = flgTipoDocumento;
}
public double getImporto() {
return this.importo;
}
public void setImporto(double importo) {
this.importo = importo;
}
public long getId_fornitore() {
return this.id_fornitore;
}
public Clifor getFornitore() {
this.fornitore = (Clifor)getSecondaryObject(this.fornitore, Clifor.class, getId_fornitore());
return this.fornitore;
}
public long getId_cliente() {
return this.id_cliente;
}
public Clifor getCliente() {
this.cliente = (Clifor)getSecondaryObject(this.cliente, Clifor.class, getId_cliente());
return this.cliente;
}
public long getId_rigaDocumento() {
return this.id_rigaDocumento;
}
public void setId_rigaDocumento(long id_rigaDocumento) {
this.id_rigaDocumento = id_rigaDocumento;
}
public RigaDocumento getRigaDocumento() {
this.rigaDocumento = (RigaDocumento)getSecondaryObject(this.rigaDocumento, RigaDocumento.class, new Long(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 Vectumerator findByRigaDocumento(long l_id_rigaDocumento) {
String s_Sql_Find = "select A.* from ARTICOLO_USATO 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);
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Date getDataUltimoMovimento(long l_id_articolo) {
String s_Sql_Find = "select A.* from ARTICOLO_USATO AS A";
String s_Sql_Order = " order by dataDocumento desc";
WcString wc = new WcString();
wc.addWc("A.id_articolo=" + l_id_articolo);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
Vectumerator vec = findRows(stmt, 1, 1);
if (vec.hasMoreElements()) {
ArticoloUsato row = (ArticoloUsato)vec.nextElement();
return row.getDataDocumento();
}
return null;
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return null;
}
}
public String getTmstStampa() {
return this.tmstStampa;
}
public void setTmstStampa(String tmstStampa) {
this.tmstStampa = tmstStampa;
}
public ResParm save() {
if (getArticolo().getFlgUsato() == 0L)
return new ResParm(false, "ERRORE! non posso registrare un acquisto o vendita usato su articoli non usati!!!");
return super.save();
}
public String getNumeroDocumento() {
if (getId_rigaDocumento() == 0L)
return (this.numeroDocumento == null) ? "" : this.numeroDocumento.trim();
return getRigaDocumento().getDocumento().getNumeroDocumento();
}
public void setId_fornitore(long id_fornitore) {
this.id_fornitore = id_fornitore;
setFornitore(null);
}
public void setFornitore(Clifor fornitore) {
this.fornitore = fornitore;
}
public void setId_cliente(long id_cliente) {
this.id_cliente = id_cliente;
setCliente(null);
}
public void setCliente(Clifor cliente) {
this.cliente = cliente;
}
public String getDescrizioneRigaDocumento() {
return (this.descrizioneRigaDocumento == null) ? "" : this.descrizioneRigaDocumento.trim();
}
public void setDescrizioneRigaDocumento(String descrizioneRigaDocumento) {
this.descrizioneRigaDocumento = descrizioneRigaDocumento;
}
public long getCodiceAlt() {
return this.codiceAlt;
}
public void setCodiceAlt(long codiceAlt) {
this.codiceAlt = codiceAlt;
}
public void findByCodiceAlt(long l_codiceAlt) {
String s_Sql_Find = "select A.* from ARTICOLO_USATO AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.codiceAlt=" + l_codiceAlt);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
}
}
}