274 lines
7.5 KiB
Java
274 lines
7.5 KiB
Java
package it.acxent.anag;
|
|
|
|
import it.acxent.db.ApplParmFull;
|
|
import it.acxent.db.ResParm;
|
|
import it.acxent.db.WcString;
|
|
import it.acxent.mail.MailMessage;
|
|
import it.acxent.newsletter.CodaMessaggi;
|
|
import it.acxent.newsletter.TemplateMsg;
|
|
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;
|
|
import java.util.Calendar;
|
|
|
|
public class Contratto extends _AnagAdapter implements Serializable {
|
|
private long id_contratto;
|
|
|
|
private long id_tipoContratto;
|
|
|
|
private long id_clifor;
|
|
|
|
private String telefoniAssociati;
|
|
|
|
private Date dataInizioContratto;
|
|
|
|
private Date dataInvioAvvisoSms;
|
|
|
|
private long flgStato;
|
|
|
|
private TipoContratto tipoContratto;
|
|
|
|
private Clifor clifor;
|
|
|
|
private String descrizione;
|
|
|
|
private String logContratto;
|
|
|
|
private String notaContratto;
|
|
|
|
private Date dataScadenzaContratto;
|
|
|
|
public static final long ST_ATTIVO = 1L;
|
|
|
|
public static final long ST_NON_ATTIVO = 0L;
|
|
|
|
public Contratto(ApplParmFull newApplParmFull) {
|
|
super(newApplParmFull);
|
|
}
|
|
|
|
public Contratto() {}
|
|
|
|
public void setId_contratto(long newId_contratto) {
|
|
this.id_contratto = newId_contratto;
|
|
}
|
|
|
|
public void setId_tipoContratto(long newId_tipoContratto) {
|
|
this.id_tipoContratto = newId_tipoContratto;
|
|
setTipoContratto(null);
|
|
}
|
|
|
|
public void setId_clifor(long newId_clifor) {
|
|
this.id_clifor = newId_clifor;
|
|
setClifor(null);
|
|
}
|
|
|
|
public void setDescrizione(String newDescrizione) {
|
|
this.descrizione = newDescrizione;
|
|
}
|
|
|
|
public void setDataInizioContratto(Date newDataInizioContratto) {
|
|
this.dataInizioContratto = newDataInizioContratto;
|
|
}
|
|
|
|
public void setDataScadenzaContratto(Date newDataScadenzaContratto) {
|
|
this.dataScadenzaContratto = newDataScadenzaContratto;
|
|
}
|
|
|
|
public void setFlgStato(long newFlgStato) {
|
|
this.flgStato = newFlgStato;
|
|
}
|
|
|
|
public long getId_contratto() {
|
|
return this.id_contratto;
|
|
}
|
|
|
|
public long getId_tipoContratto() {
|
|
return this.id_tipoContratto;
|
|
}
|
|
|
|
public long getId_clifor() {
|
|
return this.id_clifor;
|
|
}
|
|
|
|
public String getDescrizione() {
|
|
return (this.descrizione == null) ? "" :
|
|
this.descrizione.trim();
|
|
}
|
|
|
|
public Date getDataInizioContratto() {
|
|
return this.dataInizioContratto;
|
|
}
|
|
|
|
public Date getDataScadenzaContratto() {
|
|
return this.dataScadenzaContratto;
|
|
}
|
|
|
|
public long getFlgStato() {
|
|
return this.flgStato;
|
|
}
|
|
|
|
public void setTipoContratto(TipoContratto newTipoContratto) {
|
|
this.tipoContratto = newTipoContratto;
|
|
}
|
|
|
|
public TipoContratto getTipoContratto() {
|
|
this.tipoContratto = (TipoContratto)getSecondaryObject(this.tipoContratto, TipoContratto.class,
|
|
getId_tipoContratto());
|
|
return this.tipoContratto;
|
|
}
|
|
|
|
public void setClifor(Clifor newClifor) {
|
|
this.clifor = newClifor;
|
|
}
|
|
|
|
public ResParm creaCodaMessaggiSms(ContrattoCR CR) {
|
|
ResParm rp = new ResParm();
|
|
Vectumerator vec = findByCR(CR, 0, 0);
|
|
int numMsg = 0;
|
|
while (vec.hasMoreElements()) {
|
|
TemplateMsg tm = new TemplateMsg(getApFull());
|
|
tm.findByPrimaryKey(CR.getId_templateMsg());
|
|
Contratto row = (Contratto)vec.nextElement();
|
|
rp = row.creaCodaMessaggio();
|
|
if (rp.getStatus())
|
|
numMsg++;
|
|
}
|
|
rp.setMsg("Numero messaggi in coda: " + numMsg);
|
|
return rp;
|
|
}
|
|
|
|
protected void deleteCascade() {}
|
|
|
|
public Vectumerator findByCR(ContrattoCR CR, int pageNumber, int pageRows) {
|
|
String s_Sql_Find = "select A.* from CONTRATTO 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 String getTelefoniAssociati() {
|
|
return (this.telefoniAssociati == null) ? "" :
|
|
this.telefoniAssociati.trim();
|
|
}
|
|
|
|
public void setTelefoniAssociati(String telefoniAssociati) {
|
|
this.telefoniAssociati = telefoniAssociati;
|
|
}
|
|
|
|
public Vectumerator findByClifor(long l_id_clifor, int pageNumber, int pageRows) {
|
|
String s_Sql_Find = "select A.* from CONTRATTO AS A";
|
|
String s_Sql_Order = " order by A.flgStato desc, A.dataScadenzaContratto desc";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.id_clifor=" + l_id_clifor);
|
|
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 static final String getStato(long l_flgStato) {
|
|
if (l_flgStato == 1L)
|
|
return "Attivo";
|
|
if (l_flgStato == 0L)
|
|
return "Non Attivo";
|
|
return "??";
|
|
}
|
|
|
|
public String getStato() {
|
|
return getStato(getFlgStato());
|
|
}
|
|
|
|
public Clifor getClifor() {
|
|
this.clifor = (Clifor)getSecondaryObject(this.clifor, Clifor.class,
|
|
getId_clifor());
|
|
return this.clifor;
|
|
}
|
|
|
|
public String getLogContratto() {
|
|
return (this.logContratto == null) ? "" : this.logContratto;
|
|
}
|
|
|
|
public void setLogContratto(String logContratto) {
|
|
this.logContratto = logContratto;
|
|
}
|
|
|
|
public String getNotaContratto() {
|
|
return (this.notaContratto == null) ? "" : this.notaContratto;
|
|
}
|
|
|
|
public void setNotaContratto(String notaContratto) {
|
|
this.notaContratto = notaContratto;
|
|
}
|
|
|
|
public ResParm save() {
|
|
if (getDataScadenzaContratto() == null) {
|
|
Calendar cal = Calendar.getInstance();
|
|
cal.setTime(getDataInizioContratto());
|
|
int durata = (int)getTipoContratto().getDurataMesi();
|
|
if (getTipoContratto().getFlgPrepagato() == 1L) {
|
|
cal.add(6, durata * 30);
|
|
} else {
|
|
cal.add(2, durata);
|
|
cal.add(6, -1);
|
|
}
|
|
setDataScadenzaContratto(new Date(cal.getTimeInMillis()));
|
|
}
|
|
return super.save();
|
|
}
|
|
|
|
public Date getDataInvioAvvisoSms() {
|
|
return this.dataInvioAvvisoSms;
|
|
}
|
|
|
|
public void setDataInvioAvvisoSms(Date dataInvioAvvisoSms) {
|
|
this.dataInvioAvvisoSms = dataInvioAvvisoSms;
|
|
}
|
|
|
|
public ResParm creaCodaMessaggio() {
|
|
ResParm rp = new ResParm();
|
|
if (getId_contratto() > 0L) {
|
|
MailMessage mm = new MailMessage(getApFull());
|
|
mm.setTextMessage(getTipoContratto().getMessaggioSms());
|
|
mm.setString("cliente", getClifor().getDescrizioneCompleta());
|
|
mm.setString("contratto", getTipoContratto().getDescrizione());
|
|
mm.setDate("dataScadenza", getDataScadenzaContratto());
|
|
CodaMessaggi cm = new CodaMessaggi(getApFull());
|
|
cm.setDataCreazione(getToday());
|
|
cm.setCellulare(getTelefoniAssociati());
|
|
cm.setTestoMessaggio(mm.getMessage());
|
|
cm.setFlgTipo(2L);
|
|
cm.setFlgStatoInvio(0L);
|
|
rp = cm.save();
|
|
setDataInvioAvvisoSms(getToday());
|
|
rp.append(save());
|
|
}
|
|
return rp;
|
|
}
|
|
}
|