package it.acxent.anag; import it.acxent.cart.Cart; import it.acxent.db.ApplParmFull; 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.Locale; public class Nazione extends _AnagAdapter implements Serializable { private static final String MESSAGGIO_IMPORTO_MINIMO = "messaggioImportoMinimo"; private static final long serialVersionUID = 1282454814109856597L; public static final String CODICE_IT = "IT"; private String id_nazione; private String lang; private String descrizione_en; private String descrizione_it; private String codiceIstat; private long flgCee; private double costoSpedizione; private long flgAttiva; private String codice; private String descrizioneInLingua; private long flgGoogleMerchant; private long flgPreventivoWww; private long id_iva; private Iva iva; private double importoMinimoWww; private String tag; private String prefissoTel; public Nazione(ApplParmFull newApplParmFull) { super(newApplParmFull); } public Nazione() {} public void setId_nazione(String newId_nazione) { this.id_nazione = newId_nazione; } public void setLang(String newId_lingua) { this.lang = newId_lingua; } public void setFlgCee(long newFlgCee) { this.flgCee = newFlgCee; } public String getId_nazione() { return (this.id_nazione == null) ? "" : this.id_nazione.trim(); } public String getLang() { return (this.lang == null) ? "" : this.lang.trim(); } public String getDescrizioneCompleta() { return getDescrizione_it().trim(); } public long getFlgCee() { return this.flgCee; } protected void deleteCascade() {} public Vectumerator findByCR(NazioneCR CR, int pageNumber, int pageRows) { String s_Sql_Find = "select A.* from NAZIONE AS A"; String s_Sql_Order = " order by descrizione_it"; if (CR.getLang().equals("en")) { s_Sql_Order = " order by descrizione_en"; } else { s_Sql_Order = " order by descrizione_it"; } 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.descrizione_it like '%" + token + "%' or A.descrizione_en like '%" + token + "%')"); if (st.hasMoreTokens()) txt.append(" and "); } txt.append(")"); wc.addWc(txt.toString()); } if (CR.getFlgAttivaS() == 0L) { wc.addWc("(A.flgAttiva is null or A.flgAttiva=0)"); } else if (CR.getFlgAttivaS() == 1L) { wc.addWc("A.flgAttiva = 1"); } if (CR.getFlgCeeS() == 0L) { wc.addWc("(A.flgCee is null or A.flgCee=0)"); } else if (CR.getFlgCeeS() == 1L) { wc.addWc("A.flgCee = 1"); } if (CR.getFlgGoogleMerchantS() == 0L) { wc.addWc("(A.flgGoogleMerchant is null or A.flgGoogleMerchant=0)"); } else if (CR.getFlgGoogleMerchantS() == 1L) { wc.addWc("A.flgGoogleMerchant = 1"); } if (CR.getFlgPreventivoWwwS() == 0L) { wc.addWc("(A.flgPreventivoWww is null or A.flgPreventivoWww=0)"); } else if (CR.getFlgPreventivoWwwS() == 1L) { wc.addWc("A.flgPreventivoWww = 1"); } 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 getCee(long l_flgCee) { switch ((int)l_flgCee) { case -1: return " "; case 0: return "Extra Cee"; case 1: return "Cee"; } return "??"; } public String getCee() { return getCee(getFlgCee()); } public String getAttiva() { return (this.flgAttiva == 0L) ? "N" : "S"; } public double getCostoSpedizione() { return this.costoSpedizione; } public void setCostoSpedizione(double costoSpedizione) { this.costoSpedizione = costoSpedizione; } public long getFlgAttiva() { return this.flgAttiva; } public void setFlgAttiva(long flgAttiva) { this.flgAttiva = flgAttiva; } public String getCodice() { return (this.codice == null) ? getId_nazione() : this.codice.trim(); } public void setCodice(String codice) { this.codice = codice; } public String getCodiceIstat() { return (this.codiceIstat == null) ? "" : this.codiceIstat.trim(); } public void setCodiceIstat(String codiceIstat) { this.codiceIstat = codiceIstat; } public String getDescrizione(String lang) { if (lang.equals(Locale.ITALIAN.getLanguage())) return getDescrizione_it(); return getDescrizione_en(); } public boolean useDescLangTables() { return false; } public void findByCodice(String l_codice) { String s_Sql_Find = "select A.* from NAZIONE AS A"; String s_Sql_Order = ""; WcString wc = new WcString(); wc.addWc("A.codice='" + l_codice + "'"); try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString()); findFirstRecord(stmt); } catch (SQLException e) { handleDebug(e); } } public Vectumerator findAllAttiveGoogle(String lang) { String s_Sql_Find = "select A.* from NAZIONE AS A"; String s_Sql_Order = ""; if (lang.equals("en")) { s_Sql_Order = " order by descrizione_en"; } else { s_Sql_Order = " order by descrizione_it"; } WcString wc = new WcString(); wc.addWc("A.flgAttiva=1"); wc.addWc("A.flgGoogleMerchant=1"); wc.addWc("(A.flgPreventivoWww is null or A.flgPreventivoWww=0)"); 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 Vectumerator findAll(String lang) { String s_Sql_Find = "select A.* from NAZIONE AS A"; String s_Sql_Order = ""; if (lang.equals("en")) { s_Sql_Order = " order by descrizione_en"; } else { s_Sql_Order = " order by descrizione_it"; } WcString wc = new WcString(); 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 String getDescrizioneCompleta(String lang) { if (getFlgPreventivoWww() == 0L) return getDescrizione(lang); return getDescrizione(lang) + " *"; } protected String sqlStringfindAll() { return "select * from NAZIONE order by descrizione_it"; } public String getDescrizioneInLingua() { return (this.descrizioneInLingua == null || this.descrizioneInLingua.isEmpty()) ? getDescrizione_it() : this.descrizioneInLingua.trim(); } public void setDescrizioneInLingua(String descrizioneInLingua) { this.descrizioneInLingua = descrizioneInLingua; } public double getCostoSpedizioneConIva() { return conIva(getCostoSpedizione(), getParm(Cart.P_DELIVERY_IVA_ALIQUOTA).getNumeroDouble()); } public long getFlgGoogleMerchant() { return this.flgGoogleMerchant; } public void setFlgGoogleMerchant(long flgGoogleMerchant) { this.flgGoogleMerchant = flgGoogleMerchant; } public long getFlgPreventivoWww() { return this.flgPreventivoWww; } public void setFlgPreventivoWww(long flgPreventivoWww) { this.flgPreventivoWww = flgPreventivoWww; } public long getId_iva() { return this.id_iva; } public void setId_iva(long id_iva) { this.id_iva = id_iva; setIva(null); } public Iva getIva() { this.iva = (Iva)getSecondaryObject(this.iva, Iva.class, new Long(getId_iva())); return this.iva; } public void setIva(Iva iva) { this.iva = iva; } protected void prepareSave(PreparedStatement ps) throws SQLException { System.out.println(getDescTxtLang("descrizione", Locale.ITALIAN.getLanguage()) + " - " + getDescTxtLang("descrizione", Locale.ITALIAN.getLanguage())); super.prepareSave(ps); if (getFlgCee() == 0L) setId_iva(0L); } public double getImportoMinimoWww() { return this.importoMinimoWww; } public void setImportoMinimoWww(double importoMinimoWww) { this.importoMinimoWww = importoMinimoWww; } public String getMessaggioImportoMinimo(String l_lang) { if (l_lang.isEmpty()) l_lang = "it"; return getDescTxtLang("messaggioImportoMinimo", l_lang); } public boolean checkCart(Cart cart) { if (getImportoMinimoWww() <= 0.0D) return true; if (cart.getTotCartVAT() < getImportoMinimoWww()) return false; return true; } public String getTag() { if (this.tag == null) return ""; this.tag = this.tag.trim(); if (!this.tag.startsWith(",")) this.tag = "," + this.tag; if (!this.tag.endsWith(",")) this.tag += ","; if (this.tag.equals(",")) return ""; return this.tag; } public void setTag(String tag) { this.tag = tag; } public String getDescrizione_en() { return (this.descrizione_en == null) ? "" : this.descrizione_en; } public void setDescrizione_en(String descrizioneEn) { this.descrizione_en = descrizioneEn; } public String getDescrizione_it() { return (this.descrizione_it == null) ? "" : this.descrizione_it.trim(); } public void setDescrizione_it(String descrizioneIt) { this.descrizione_it = descrizioneIt; } public String getPrefissoTel() { if (this.prefissoTel == null) return ""; if (!this.prefissoTel.trim().startsWith("+")) return "+" + this.prefissoTel.trim(); return this.prefissoTel.trim(); } public void setPrefissoTel(String prefissoTel) { this.prefissoTel = prefissoTel; } public Vectumerator findAllAttive(String lang) { String s_Sql_Find = "select A.* from NAZIONE AS A"; String s_Sql_Order = ""; if (lang.equals("en")) { s_Sql_Order = " order by descrizione_en"; } else { s_Sql_Order = " order by descrizione_it"; } WcString wc = new WcString(); wc.addWc("A.flgAttiva=1"); 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; } } }