1725 lines
75 KiB
Java
1725 lines
75 KiB
Java
|
|
package it.acxent.cc.servlet;
|
||
|
|
|
||
|
|
import it.acxent.anag.Cliente;
|
||
|
|
import it.acxent.anag.Clifor;
|
||
|
|
import it.acxent.anag.DestinazioneDiversa;
|
||
|
|
import it.acxent.anag.Iva;
|
||
|
|
import it.acxent.anag.Nazione;
|
||
|
|
import it.acxent.anag.TipoPagamento;
|
||
|
|
import it.acxent.anag.Users;
|
||
|
|
import it.acxent.art.Articolo;
|
||
|
|
import it.acxent.art.ArticoloCR;
|
||
|
|
import it.acxent.art.ArticoloTaglia;
|
||
|
|
import it.acxent.art.ArticoloVariante;
|
||
|
|
import it.acxent.cart.AcCartObject;
|
||
|
|
import it.acxent.cart.Cart;
|
||
|
|
import it.acxent.cart.CartItem;
|
||
|
|
import it.acxent.cart.CartItemId;
|
||
|
|
import it.acxent.cart.CartStatus;
|
||
|
|
import it.acxent.cart.servlet.AcCartSvlt;
|
||
|
|
import it.acxent.cc.Attivita;
|
||
|
|
import it.acxent.cloudmsg.MsgJson;
|
||
|
|
import it.acxent.cloudmsg.PushNotificationService;
|
||
|
|
import it.acxent.contab.Documento;
|
||
|
|
import it.acxent.contab.DocumentoCR;
|
||
|
|
import it.acxent.contab.RigaDocumento;
|
||
|
|
import it.acxent.db.ApplParmFull;
|
||
|
|
import it.acxent.db.ResParm;
|
||
|
|
import it.acxent.gtm.GoogleDataLayer;
|
||
|
|
import it.acxent.gtm.GoogleDataLayerBuilder;
|
||
|
|
import it.acxent.log.Log;
|
||
|
|
import it.acxent.rd.RemoteDevice;
|
||
|
|
import it.acxent.servlet.SavedHttpRequest;
|
||
|
|
import it.acxent.util.AbMessages;
|
||
|
|
import it.acxent.util.CodiceFiscale;
|
||
|
|
import it.acxent.util.DoubleOperator;
|
||
|
|
import it.acxent.util.RandomString;
|
||
|
|
import it.acxent.util.Vectumerator;
|
||
|
|
import it.acxent.www.Promozione;
|
||
|
|
import java.sql.Date;
|
||
|
|
import java.util.ArrayList;
|
||
|
|
import java.util.Enumeration;
|
||
|
|
import java.util.List;
|
||
|
|
import javax.servlet.RequestDispatcher;
|
||
|
|
import javax.servlet.ServletRequest;
|
||
|
|
import javax.servlet.ServletResponse;
|
||
|
|
import javax.servlet.http.HttpServletRequest;
|
||
|
|
import javax.servlet.http.HttpServletResponse;
|
||
|
|
import javax.servlet.http.HttpSession;
|
||
|
|
|
||
|
|
public class CartSvlt extends it.acxent.www.servlet.CartSvlt {
|
||
|
|
private static final long serialVersionUID = -1138852541424484366L;
|
||
|
|
|
||
|
|
private Iva deliveryIva;
|
||
|
|
|
||
|
|
protected void afterAddItem(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
try {
|
||
|
|
AcCartObject aco = getCartObject(req);
|
||
|
|
CartItem cartItem = new CartItem(aco, apFull, aco.getQuantity());
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
if (attivita.isTagManagerAttivo()) {
|
||
|
|
GoogleDataLayer gdl = new GoogleDataLayer(GoogleDataLayerBuilder.addItemToCart("eec.add", cartItem));
|
||
|
|
req.setAttribute("_gdl", gdl);
|
||
|
|
}
|
||
|
|
if (getCal(req).equals("list")) {
|
||
|
|
req.setAttribute("cmd", "search");
|
||
|
|
req.setAttribute("act", "listaArticoli");
|
||
|
|
RequestDispatcher rd = getServletContext().getRequestDispatcher("/Catalogo.abl");
|
||
|
|
rd.forward((ServletRequest)req, (ServletResponse)res);
|
||
|
|
} else if (getCal(req).equals("wl")) {
|
||
|
|
req.setAttribute("cmd", "search");
|
||
|
|
req.setAttribute("act", "");
|
||
|
|
RequestDispatcher rd = getServletContext().getRequestDispatcher("/Wishlist.abl");
|
||
|
|
rd.forward((ServletRequest)req, (ServletResponse)res);
|
||
|
|
} else {
|
||
|
|
req.setAttribute("cmd", "md");
|
||
|
|
Articolo bean = (Articolo)req.getAttribute("bean");
|
||
|
|
req.setAttribute("id_articolo", Long.valueOf(bean.getId_articolo()));
|
||
|
|
req.setAttribute("id_articoloVariante", Long.valueOf(bean.getId_articoloVariante()));
|
||
|
|
req.setAttribute("id_articoloVarianteKit", Long.valueOf(bean.getId_articoloVarianteKit()));
|
||
|
|
req.setAttribute("id_articoloTaglia", Long.valueOf(bean.getId_articoloTaglia()));
|
||
|
|
req.setAttribute("id_taglia", Long.valueOf(bean.getArticoloTaglia().getId_taglia()));
|
||
|
|
req.setAttribute("id_articoloTagliaKit", Long.valueOf(bean.getId_articoloTagliaKit()));
|
||
|
|
RequestDispatcher rd = getServletContext().getRequestDispatcher("/Catalogo.abl");
|
||
|
|
rd.forward((ServletRequest)req, (ServletResponse)res);
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void afterCheckCart(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
Cart cart = getCart(req);
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
if (attivita.isTagManagerAttivo()) {
|
||
|
|
GoogleDataLayer gdl = new GoogleDataLayer(GoogleDataLayerBuilder.showCart("eec.checkout", "1", cart));
|
||
|
|
req.setAttribute("_gdl", gdl);
|
||
|
|
}
|
||
|
|
gestionePromozioni(cart, req);
|
||
|
|
String callingJsp = getRequestParameter(req, "callingJsp");
|
||
|
|
if (!callingJsp.isEmpty()) {
|
||
|
|
setJspPageRelative(callingJsp, req);
|
||
|
|
} else {
|
||
|
|
setJspPageRelative("cart.jsp", req);
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
callJsp(req, res);
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void afterCheckOut(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
if (getAct(req).equals(ACT_LOGIN) && getLoginUserId(req) > 0L) {
|
||
|
|
GoogleDataLayer gdl = new GoogleDataLayer(GoogleDataLayerBuilder.eventStep("eec.checkout", "2"));
|
||
|
|
req.setAttribute("_gdl", gdl);
|
||
|
|
}
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
String l_lang = getLang(req);
|
||
|
|
Cart cart = getCart(req);
|
||
|
|
gestionePromozioni(cart, req);
|
||
|
|
String callingJsp = getRequestParameter(req, "callingJsp");
|
||
|
|
if (callingJsp.equals("checkOut.jsp")) {
|
||
|
|
cart.setNote(getRequestParameter(req, "note"));
|
||
|
|
cart.setFlgPayment(getRequestLongParameter(req, "flgPayment"));
|
||
|
|
}
|
||
|
|
if (cart.getFlgPayment() > 0L) {
|
||
|
|
TipoPagamento tp = new TipoPagamento(apFull);
|
||
|
|
tp.findByPrimaryKey(cart.getFlgPayment());
|
||
|
|
cart.setDescPayment(tp.getDescrizioneWww(getLang(req)));
|
||
|
|
}
|
||
|
|
setCart(req, cart);
|
||
|
|
gestioneScontiCommissioniTipoPagamento(cart, req);
|
||
|
|
req.setAttribute("listaNazioni", new Nazione(apFull).findAllAttive(getLang(req)));
|
||
|
|
Users user = (Users)getLoginUser(req);
|
||
|
|
req.setAttribute("listaTipoPagamento", getListaTipiPagamento(req, cart));
|
||
|
|
setJspPageRelative("checkOut.jsp", req);
|
||
|
|
if (user.isProfileNoReg()) {
|
||
|
|
req.getSession().removeAttribute("loginUser_id");
|
||
|
|
req.getSession().removeAttribute("utenteLogon");
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
callJsp(req, res);
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void afterDeleteCart(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
setJspPageRelative("index.jsp", req);
|
||
|
|
try {
|
||
|
|
RequestDispatcher rd = getServletContext().getRequestDispatcher(getJspPage(req));
|
||
|
|
rd.forward((ServletRequest)req, (ServletResponse)res);
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void afterDeleteItem(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
Cart cart = getCart(req);
|
||
|
|
String l_codicePromozione = cart.getCodPromo();
|
||
|
|
if (l_codicePromozione != null && !l_codicePromozione.isEmpty()) {
|
||
|
|
Promozione promozione = new Promozione(getApFull(req));
|
||
|
|
promozione.findByCodicePromozione(l_codicePromozione);
|
||
|
|
if (promozione.getDBState() == 1) {
|
||
|
|
Users utente = (Users)getLoginUser(req);
|
||
|
|
long resPromo = promozione.isValid(utente, cart);
|
||
|
|
if (resPromo != Promozione.PROMOZIONE_VALIDA) {
|
||
|
|
cart.setDiscountPerc(0L);
|
||
|
|
cart.setDescDiscountPerc("");
|
||
|
|
cart.setDescDiscount("");
|
||
|
|
cart.setCodPromo("");
|
||
|
|
setCart(req, cart);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
checkCart(req, res);
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void afterModifyItems(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
try {
|
||
|
|
updateDeliveryCost(getCart(req), req);
|
||
|
|
checkCart(req, res);
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected String getCheckCartJspPage(HttpServletRequest req) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected String getCheckOutJspPage(HttpServletRequest req) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected String getDeleteItemJspPage(HttpServletRequest req) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected String getModifyItemJspPage(HttpServletRequest req) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected it.acxent.common.Users getUser(HttpServletRequest req) {
|
||
|
|
ApplParmFull apFull = getApFull();
|
||
|
|
return new Users(apFull);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void afterOrderRecorded(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
long id_clifor = getRequestLongParameter(req, "id_clifor");
|
||
|
|
forceJspPageRelative("documento.jsp", req);
|
||
|
|
callJsp(req, res);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ResParm sendLostPasswordMessage(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
String lostEmail = getRequestParameter(req, AcCartSvlt.ATTR_LOSTPWDEMAIL);
|
||
|
|
if (lostEmail.isEmpty())
|
||
|
|
return new ResParm(false, attivita.translate("Email errata", getLang(req)));
|
||
|
|
return attivita.sendLostPasswordMailMessage(lostEmail, getLang(req), req);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected boolean checkAvailability(HttpServletRequest req) {
|
||
|
|
return getParm("CC_CHECK_AVAIL").isTrue();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void logOn(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
try {
|
||
|
|
String jspPage = "/checkOut.jsp";
|
||
|
|
if (jspPage.isEmpty())
|
||
|
|
jspPage = getJspHomePage(req);
|
||
|
|
if (!getLogin(req).isEmpty())
|
||
|
|
if (checkLoginName(req, res) == 5L) {
|
||
|
|
setDeliveryIva(null);
|
||
|
|
if (isFirstAccess(req)) {
|
||
|
|
SavedHttpRequest shr = (SavedHttpRequest)req.getSession().getAttribute("savedHttpRequest");
|
||
|
|
if (shr == null) {
|
||
|
|
shr = new SavedHttpRequest();
|
||
|
|
shr.setCompleteRequestedURI(req.getRequestURI());
|
||
|
|
shr.setServletPath(req.getServletPath());
|
||
|
|
shr.setAllParametersNAttributes(req);
|
||
|
|
req.getSession().setAttribute("savedHttpRequest", shr);
|
||
|
|
}
|
||
|
|
forceJspPageRelative(getCheckCCPage(), req);
|
||
|
|
RequestDispatcher rd = getServletContext().getRequestDispatcher(getJspPage(req));
|
||
|
|
rd.forward((ServletRequest)req, (ServletResponse)res);
|
||
|
|
} else {
|
||
|
|
String idCryptParm = "idcrypt";
|
||
|
|
String l_id_ordineCript = (String)req.getSession().getAttribute(idCryptParm);
|
||
|
|
if (l_id_ordineCript != null && !l_id_ordineCript.isEmpty()) {
|
||
|
|
System.out.println("aaa");
|
||
|
|
if (!getCal(req).isEmpty()) {
|
||
|
|
setJspPageRelative(getCal(req), req);
|
||
|
|
} else {
|
||
|
|
setJspPageRelative("ShowOrdine.abl", req);
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
RequestDispatcher rd = getServletContext().getRequestDispatcher(getJspPage(req));
|
||
|
|
rd.forward((ServletRequest)req, (ServletResponse)res);
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
String thePage = getRequestParameter(req, "thePage");
|
||
|
|
if (getCart(req).getNumberOfItems() > 0L || thePage.isEmpty()) {
|
||
|
|
setJspPageRelative(jspPage, req);
|
||
|
|
} else {
|
||
|
|
setJspPageRelative(thePage, req);
|
||
|
|
HttpSession session = req.getSession();
|
||
|
|
Users users = (Users)session.getAttribute("utenteLogon");
|
||
|
|
if (users.getId_clifor() != 0L) {
|
||
|
|
DocumentoCR CR = new DocumentoCR();
|
||
|
|
CR.setId_clifor(users.getId_clifor());
|
||
|
|
req.setAttribute("list", new Documento(apFull).findByCR(CR, 0, 0));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
req.setAttribute("listaNazioni", new Nazione(apFull).findAllAttive(getLang(req)));
|
||
|
|
req.setAttribute("listaTipoPagamento", getListaTipiPagamento(req, getCart(req)));
|
||
|
|
callJsp(req, res);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
sendMessage(req, AbMessages.getMessage(getLang(req), "LOGIN_FAIL"));
|
||
|
|
String thePage = getRequestParameter(req, "thePage");
|
||
|
|
if (thePage.isEmpty()) {
|
||
|
|
setJspPageRelative(jspPage, req);
|
||
|
|
} else {
|
||
|
|
setJspPageRelative(thePage, req);
|
||
|
|
}
|
||
|
|
callJsp(req, res);
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
sendMessage(req, e.getMessage());
|
||
|
|
setJspPageRelative(getCal(req), req);
|
||
|
|
callJsp(req, res);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public AcCartObject getCartObject(HttpServletRequest req) throws Exception {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
String l_lang = getLang(req);
|
||
|
|
double l_quantity = getRequestDoubleParameter(req, "qt");
|
||
|
|
if (l_quantity == 0.0D)
|
||
|
|
l_quantity = 1.0D;
|
||
|
|
CartItemId articoloID = scomponiIdSuRequest(req);
|
||
|
|
Articolo bean = new Articolo(apFull);
|
||
|
|
bean.findByCartitemId(articoloID);
|
||
|
|
req.setAttribute("bean", bean);
|
||
|
|
AcCartObject aco = new AcCartObject(Articolo.class, articoloID, l_quantity);
|
||
|
|
aco.setCodPromo(bean.getCodicePromozione());
|
||
|
|
aco.setLang(l_lang);
|
||
|
|
return aco;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ResParm recordOrder(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
String lang = getLang(req);
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
synchronized (this) {
|
||
|
|
try {
|
||
|
|
System.out.println("record ORDINE ----------------------------");
|
||
|
|
Cart cart = getCart(req);
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
Users utente = (Users)getLoginUser(req);
|
||
|
|
long l_id_tipoOrdine = getParm("ID_DOC_ORDINE_WWW").getNumeroLong();
|
||
|
|
Documento ordine = new Documento(apFull);
|
||
|
|
ordine.setId_tipoDocumento(l_id_tipoOrdine);
|
||
|
|
ordine.setFlgStato(1L);
|
||
|
|
ordine.setId_clifor(utente.getId_clifor());
|
||
|
|
ordine.setDataDocumento(new Date(new java.util.Date().getTime()));
|
||
|
|
ordine.setNominativoDocumento(utente.getDescrizione());
|
||
|
|
ordine.setId_tipoPagamento(cart.getFlgPayment());
|
||
|
|
ordine.setFlgRitiroNegozio(cart.getFlgPickup());
|
||
|
|
ordine.setNotaAggiuntiva(cart.getNote());
|
||
|
|
ordine.setFlgDeliveryType(cart.getFlgDeliveryType());
|
||
|
|
ordine.setPudoId(cart.getPudoId());
|
||
|
|
ordine.setPudoDesc(cart.getPudoDesc());
|
||
|
|
ordine.setKgLordo(0.5D);
|
||
|
|
ordine.setFlgTrasporto(1L);
|
||
|
|
if (cart.getDiscountPerc() > 0L)
|
||
|
|
ordine.setPercScontoIncondizionato((double)cart.getDiscountPerc());
|
||
|
|
DoubleOperator spese = new DoubleOperator(cart.getMoreCost());
|
||
|
|
spese.add(cart.getDeliveryCost());
|
||
|
|
if (cart.getDeliveryWarnCost() > 0.0D) {
|
||
|
|
spese.add(cart.getDeliveryWarnCost());
|
||
|
|
ordine.setFlgAvvisoConsegna(1L);
|
||
|
|
}
|
||
|
|
ordine.setSpeseTrasporto(spese.getResult());
|
||
|
|
ordine.setId_ivaDoc(cart.getId_ivaDelivery());
|
||
|
|
ordine.setFlgStatoOrdineWww(0L);
|
||
|
|
ordine.setFlgPagata(0L);
|
||
|
|
ordine.setFlgWwwRichiedeFattura(1L);
|
||
|
|
long ckDestinazioneDiversa = getRequestLongParameter(req, "ckDestinazioneDiversa");
|
||
|
|
ckDestinazioneDiversa = 1L;
|
||
|
|
DestinazioneDiversa dd = utente.getClifor().getDestinazioneDiversa(0);
|
||
|
|
if (ckDestinazioneDiversa == 1L && dd.getId_destinazioneDiversa() > 0L) {
|
||
|
|
ordine.setPresso(dd.getPressoDD());
|
||
|
|
ordine.setIndirizzoSped(dd.getIndirizzoDD());
|
||
|
|
ordine.setNumeroCivicoSped(dd.getNumeroCivicoDD());
|
||
|
|
ordine.setCittaSped(dd.getDescrizioneComuneDD());
|
||
|
|
ordine.setProvinciaSped(dd.getProvinciaComuneDD());
|
||
|
|
ordine.setCapSped(dd.getCapComuneDD());
|
||
|
|
ordine.setId_nazioneSped(dd.getId_nazioneDD());
|
||
|
|
System.out.println("Destinazione diversa :" + ordine.getPresso());
|
||
|
|
}
|
||
|
|
if (isCostoSpedizioneFull()) {
|
||
|
|
if (getParm(Cart.P_PROCEDI_PAGAMENTO).isTrue()) {
|
||
|
|
if (cart.isCostoSpedizionePreventivo()) {
|
||
|
|
ordine.setFlgProcediPagamento(0L);
|
||
|
|
} else {
|
||
|
|
ordine.setFlgProcediPagamento(1L);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
ordine.setFlgProcediPagamento(0L);
|
||
|
|
}
|
||
|
|
} else if (getParm(Cart.P_PROCEDI_PAGAMENTO).isTrue()) {
|
||
|
|
if (!ordine.getId_nazioneSped().isEmpty()) {
|
||
|
|
if (ordine.getNazioneSped().getFlgPreventivoWww() == 0L)
|
||
|
|
ordine.setFlgProcediPagamento(1L);
|
||
|
|
} else if (ordine.getClifor().getNazione().getFlgPreventivoWww() == 0L) {
|
||
|
|
ordine.setFlgProcediPagamento(1L);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (cart.hasItemConScontoTroppoAlto())
|
||
|
|
ordine.setFlgProcediPagamento(0L);
|
||
|
|
rp = ordine.save();
|
||
|
|
boolean ebayUpdate = false;
|
||
|
|
boolean amzUpdate = false;
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
Enumeration<CartItem> enu = cart.getItems();
|
||
|
|
while (enu.hasMoreElements()) {
|
||
|
|
CartItem ci = enu.nextElement();
|
||
|
|
if (ci.getQuantity() > 0.0D) {
|
||
|
|
RigaDocumento rigaOrdine = new RigaDocumento(apFull);
|
||
|
|
Articolo articolo = (Articolo)ci.getDbItem();
|
||
|
|
if (articolo.getCartItemType() == 0L) {
|
||
|
|
rigaOrdine.setId_articolo(articolo.getId_articolo());
|
||
|
|
rigaOrdine.setQuantita(ci.getQuantity());
|
||
|
|
rigaOrdine.setNr(ci.getQuantity());
|
||
|
|
rigaOrdine.setPrezzoPubblicoConIva(ci.getPriceWVat(utente.getId_users()));
|
||
|
|
rigaOrdine.setImponibile(ci.getPrice());
|
||
|
|
if (cart.getDiscountPercTot() > 0.0D) {
|
||
|
|
rigaOrdine.setSconto(cart.getDiscountPercTot());
|
||
|
|
} else {
|
||
|
|
rigaOrdine.setSconto(articolo.getPrezzoArticolo(ordine.getClifor()).getPercSconto());
|
||
|
|
}
|
||
|
|
rigaOrdine.setDescrizioneRiga(rigaOrdine.getArticolo().getDescrizioneCompleta(lang));
|
||
|
|
rigaOrdine.setId_iva(articolo.getIvaByClifor(utente.getClifor()).getId_iva());
|
||
|
|
rp = Documento.addRigaDocumento(ordine, rigaOrdine);
|
||
|
|
if (rp.getStatus())
|
||
|
|
Articolo.aggiornaDispoEPrezzoArticoloFornitore(rigaOrdine.getArticolo(), (long)-rigaOrdine.getNr(), 0L, true);
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
if (attivita.isEbay() &&
|
||
|
|
!rigaOrdine.getArticolo().isEbayPrezzoQtaAllineati())
|
||
|
|
ebayUpdate = true;
|
||
|
|
if (attivita.isAmz() &&
|
||
|
|
!rigaOrdine.getArticolo().isAmazonPrezzoQtaAllineati())
|
||
|
|
amzUpdate = true;
|
||
|
|
}
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (articolo.getCartItemType() == 3L) {
|
||
|
|
rigaOrdine.setId_articolo(articolo.getId_articolo());
|
||
|
|
rigaOrdine.setId_articoloVariante(articolo.getId_articoloVariante());
|
||
|
|
rigaOrdine.setId_articoloTaglia(articolo.getId_articoloTaglia());
|
||
|
|
rigaOrdine.setQuantita(ci.getQuantity());
|
||
|
|
rigaOrdine.setNr(ci.getQuantity());
|
||
|
|
rigaOrdine.setPrezzoPubblicoConIva(ci.getPriceWVat(utente.getId_users()));
|
||
|
|
rigaOrdine.setImponibile(ci.getPrice());
|
||
|
|
if (cart.getDiscountPercTot() > 0.0D) {
|
||
|
|
rigaOrdine.setSconto(cart.getDiscountPercTot());
|
||
|
|
} else {
|
||
|
|
rigaOrdine.setSconto(articolo.getPrezzoArticolo(ordine.getClifor()).getPercSconto());
|
||
|
|
}
|
||
|
|
rigaOrdine.setDescrizioneRiga(rigaOrdine.getArticolo().getDescrizioneCompleta(lang));
|
||
|
|
rigaOrdine.setId_iva(articolo.getId_iva());
|
||
|
|
rigaOrdine.setId_iva(articolo.getIvaByClifor(utente.getClifor()).getId_iva());
|
||
|
|
rp = Documento.addRigaDocumento(ordine, rigaOrdine);
|
||
|
|
if (rp.getStatus());
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (articolo.getCartItemType() == 5L) {
|
||
|
|
rigaOrdine.setId_articolo(articolo.getId_articolo());
|
||
|
|
rigaOrdine.setId_articoloVariante(articolo.getId_articoloVariante());
|
||
|
|
rigaOrdine.setId_articoloTaglia(articolo.getId_articoloTaglia());
|
||
|
|
rigaOrdine.setQuantita(ci.getQuantity());
|
||
|
|
rigaOrdine.setNr(ci.getQuantity());
|
||
|
|
rigaOrdine.setPrezzoPubblicoConIva(ci.getPriceWVat(utente.getId_users()));
|
||
|
|
rigaOrdine.setImponibile(ci.getPrice());
|
||
|
|
if (cart.getDiscountPercTot() > 0.0D) {
|
||
|
|
rigaOrdine.setSconto(cart.getDiscountPercTot());
|
||
|
|
} else {
|
||
|
|
rigaOrdine.setSconto(articolo.getPrezzoArticolo(ordine.getClifor()).getPercSconto());
|
||
|
|
}
|
||
|
|
rigaOrdine.setDescrizioneRiga(rigaOrdine.getArticolo().getDescrizioneCompleta(lang));
|
||
|
|
rigaOrdine.setId_iva(articolo.getId_iva());
|
||
|
|
rp = Documento.addRigaDocumento(ordine, rigaOrdine);
|
||
|
|
rigaOrdine = new RigaDocumento(apFull);
|
||
|
|
rigaOrdine.setId_articolo(articolo.getArticoloVarianteKit().getId_articolo());
|
||
|
|
rigaOrdine.setId_articoloVariante(articolo.getArticoloVarianteKit().getId_articoloVariante());
|
||
|
|
rigaOrdine.setId_articoloTaglia(articolo.getId_articoloTagliaKit());
|
||
|
|
rigaOrdine.setQuantita(ci.getQuantity());
|
||
|
|
rigaOrdine.setNr(ci.getQuantity());
|
||
|
|
rigaOrdine.setDescrizioneRiga(rigaOrdine.getArticolo().getDescrizioneCompleta(lang));
|
||
|
|
rigaOrdine.setId_iva(articolo.getIvaByClifor(utente.getClifor()).getId_iva());
|
||
|
|
rp = Documento.addRigaDocumento(ordine, rigaOrdine);
|
||
|
|
if (rp.getStatus());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
ordine.setFlgStato(1L);
|
||
|
|
ordine.setFlgStatoOrdineWww(0L);
|
||
|
|
ordine.setFlgStatoPrenotazione(0L);
|
||
|
|
rp = ordine.save();
|
||
|
|
if (rp.getStatus())
|
||
|
|
if (!cart.getCodPromo().isEmpty()) {
|
||
|
|
Promozione promo = new Promozione(apFull);
|
||
|
|
promo.findByCodicePromozione(cart.getCodPromo());
|
||
|
|
if (promo.getDBState() == 1) {
|
||
|
|
rp = Promozione.addUtilizzo(promo, utente.getId_users(), ordine.getId_documento());
|
||
|
|
Log.addAltro(apFull, req.getRemoteAddr(), utente.getId_users(), "Promo " +
|
||
|
|
promo.getDescrizione() + " codice: " + promo.getCodicePromozione() + " utilizzata in data " +
|
||
|
|
String.valueOf(promo.getDataUtilizzoPromozione()) + " su ordine " +
|
||
|
|
ordine.getNumeroDocumentoCompleto());
|
||
|
|
} else {
|
||
|
|
handleDebug("Attenzione! recordOrder: promozione " + cart.getCodPromo() + " non trovata!!", 0);
|
||
|
|
}
|
||
|
|
if (!rp.getStatus())
|
||
|
|
handleDebug("ATTENZIONE! Promozione " + promo.getId_promozione() + " relativa all'ordine " +
|
||
|
|
ordine.getNumeroDocumentoCompleto() + " Non aggiornata!", 0);
|
||
|
|
}
|
||
|
|
if (ebayUpdate && attivita.isEbay()) {
|
||
|
|
Articolo art = new Articolo(getApFull());
|
||
|
|
System.out.println("recordorder: avvio thread allinemento ebay");
|
||
|
|
art.startThreadAllineaEbay(apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
if (amzUpdate && attivita.isAmz()) {
|
||
|
|
Articolo art = new Articolo(getApFull());
|
||
|
|
System.out.println("recordorder: avvio thread allinemento amz");
|
||
|
|
art.startThreadAllineaAmz(apFull, new ArticoloCR());
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
sendMessage(req, "Ordine registrato ma non è stato possibile inviare email di conferma: " + rp.getMsg());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg("Ordine registrato ma non è stato possibile inviare email di conferma: " + rp.getMsg());
|
||
|
|
}
|
||
|
|
ordine.setFlgOrdineWwwAppenaCreato(1L);
|
||
|
|
req.setAttribute(PROP_ORDER, ordine);
|
||
|
|
int ordineInverso = (ordine.getTipoDocumento().getFlgOrdinamentoRigheStampa() == 1L) ? 1 : 0;
|
||
|
|
req.setAttribute("righeDocumento", ordine.findRigheDocumento(0, 0, ordineInverso));
|
||
|
|
req.setAttribute("listaTipoPagamento", getListaTipiPagamento(req, cart));
|
||
|
|
forceJspPageRelative("documento.jsp", req);
|
||
|
|
} else {
|
||
|
|
handleDebug(rp.getMsg(), 1);
|
||
|
|
forceJspPageRelative("checkOut.jsp", req);
|
||
|
|
forceMessage(req, "Attenzione! Impossibile registrare l'ordine: " + rp.getMsg());
|
||
|
|
}
|
||
|
|
if (rp.getStatus())
|
||
|
|
if (attivita.isTagManagerAttivo()) {
|
||
|
|
GoogleDataLayer gdl = new GoogleDataLayer(GoogleDataLayerBuilder.eventStep("eec.checkout", "4"));
|
||
|
|
req.setAttribute("_gdl", gdl);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
req.setAttribute("listaNazioni", new Nazione(apFull).findAllAttive(getLang(req)));
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
sendMessage(req, "CheckOut: record order error: " + e.getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected String getJspHomePage(HttpServletRequest req) {
|
||
|
|
return "index.jsp";
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ResParm sendCheckOutMessage(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
Documento ordine = (Documento)req.getAttribute(PROP_ORDER);
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
Users utente = (Users)getLoginUser(req);
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
rp = attivita.sendOrderMailMessageCC(ordine, utente, utente.getLang(), true, true, false, false, req);
|
||
|
|
inviaNotificaOrdineAdmin(req, res, ordine);
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected double getDeliveryCost(HttpServletRequest req, Cart cart) {
|
||
|
|
if (isCostoSpedizioneFull())
|
||
|
|
return getDeliveryCostPercentile(req, cart);
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
double totCart = cart.getTotPriceVAT();
|
||
|
|
if (getParm(Cart.P_DELIVERY_FREE_ABOVE).getNumeroDouble() >= 0.0D && totCart >=
|
||
|
|
getParm(Cart.P_DELIVERY_FREE_ABOVE).getNumeroDouble()) {
|
||
|
|
System.out.println("free above: " + getParm(Cart.P_DELIVERY_FREE_ABOVE).getNumeroDouble() + " totCart:" + totCart);
|
||
|
|
return 0.0D;
|
||
|
|
}
|
||
|
|
double delivCost = 0.0D;
|
||
|
|
long l_flgTipoPagamento = cart.getFlgPayment();
|
||
|
|
TipoPagamento tp = new TipoPagamento(getApFull());
|
||
|
|
tp.findByPrimaryKey(l_flgTipoPagamento);
|
||
|
|
if (tp.getFlgAbilitatoNegozio() == 0L) {
|
||
|
|
if (getAct2(req).startsWith("changePudo"))
|
||
|
|
if (getAct2(req).equals("changePudoOn")) {
|
||
|
|
cart.setFlgDeliveryType(2L);
|
||
|
|
} else if (getAct2(req).equals("changePudoOff")) {
|
||
|
|
cart.setFlgDeliveryType(0L);
|
||
|
|
}
|
||
|
|
Users user = (Users)getLoginUser(req);
|
||
|
|
if (user != null && user.isProfileNoReg()) {
|
||
|
|
long l_id_clifor = user.getId_clifor();
|
||
|
|
if (user.getApFull() == null)
|
||
|
|
user = new Users(apFull);
|
||
|
|
fillObject(req, user);
|
||
|
|
user.setId_clifor(l_id_clifor);
|
||
|
|
fillObject(req, user.getClifor());
|
||
|
|
DestinazioneDiversa dd = new DestinazioneDiversa(apFull);
|
||
|
|
fillObject(req, dd);
|
||
|
|
user.getClifor().setCurrentDD(dd);
|
||
|
|
}
|
||
|
|
if (user != null)
|
||
|
|
if (cart.getFlgDeliveryType() == 2L) {
|
||
|
|
delivCost = getParm(Cart.P_DELIVERY_COST_PUDO).getNumeroDouble();
|
||
|
|
} else {
|
||
|
|
DestinazioneDiversa dd = user.getClifor().getCurrentDD();
|
||
|
|
boolean preventivoSpedizione = false;
|
||
|
|
if (!dd.getId_nazioneDD().isEmpty()) {
|
||
|
|
if (dd.getNazioneDD().getFlgPreventivoWww() == 0L) {
|
||
|
|
delivCost = dd.getNazioneDD().getCostoSpedizione();
|
||
|
|
} else {
|
||
|
|
delivCost = 0.0D;
|
||
|
|
preventivoSpedizione = true;
|
||
|
|
}
|
||
|
|
} else if (user.getClifor().getNazione().getFlgPreventivoWww() == 0L) {
|
||
|
|
delivCost = user.getClifor().getNazione().getCostoSpedizione();
|
||
|
|
} else {
|
||
|
|
delivCost = 0.0D;
|
||
|
|
preventivoSpedizione = true;
|
||
|
|
}
|
||
|
|
if (delivCost == 0.0D && !preventivoSpedizione) {
|
||
|
|
delivCost = getParm(Cart.P_DELIVERY_COST).getNumeroDouble();
|
||
|
|
} else {
|
||
|
|
delivCost = getParm(Cart.P_DELIVERY_COST).getNumeroDouble();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (tp.getFlgAbilitatoNegozio() == 1L) {
|
||
|
|
delivCost = 0.0D;
|
||
|
|
} else if (tp.getFlgAbilitatoCorriere() == 1L) {
|
||
|
|
cart.setMoreCost(getMoreCost(req));
|
||
|
|
cart.setDescMoreCost(tp.getDescrizione(getLang(req)));
|
||
|
|
} else {
|
||
|
|
cart.setMoreCost(0.0D);
|
||
|
|
cart.setDescMoreCost("");
|
||
|
|
}
|
||
|
|
if (getAct2(req).startsWith("changePudo"))
|
||
|
|
if (getAct2(req).equals("changePudoOn")) {
|
||
|
|
cart.setFlgDeliveryType(2L);
|
||
|
|
} else {
|
||
|
|
cart.setFlgDeliveryType(0L);
|
||
|
|
}
|
||
|
|
if (getAct2(req).startsWith("changeDWC"))
|
||
|
|
if (getAct2(req).equals("changeDWC0")) {
|
||
|
|
cart.setDeliveryWarnCost(0.0D);
|
||
|
|
} else {
|
||
|
|
cart.setDeliveryWarnCost(getDeliveryWarnCost(req));
|
||
|
|
}
|
||
|
|
System.out.println("deliv cost no above: " + delivCost);
|
||
|
|
return delivCost;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected double getDeliveryCostFull(HttpServletRequest req, Cart cart) {
|
||
|
|
boolean debug = false;
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
double totCart = cart.getTotPriceVAT();
|
||
|
|
if (getParm(Cart.P_DELIVERY_FREE_ABOVE).getNumeroDouble() >= 0.0D && totCart >=
|
||
|
|
getParm(Cart.P_DELIVERY_FREE_ABOVE).getNumeroDouble()) {
|
||
|
|
System.out.println("getDeliveryCostFull: free above: " +
|
||
|
|
getParm(Cart.P_DELIVERY_FREE_ABOVE).getNumeroDouble() + " totCart:" + totCart);
|
||
|
|
return 0.0D;
|
||
|
|
}
|
||
|
|
String l_id_nazione = "I";
|
||
|
|
double delivCost = 0.0D;
|
||
|
|
long l_flgTipoPagamento = cart.getFlgPayment();
|
||
|
|
TipoPagamento tp = new TipoPagamento(getApFull());
|
||
|
|
tp.findByPrimaryKey(l_flgTipoPagamento);
|
||
|
|
if (tp.getFlgAbilitatoNegozio() == 0L) {
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
boolean isPreventivoSuPercentile = (attivita.getPercentileMaxPerPreventivo() <= 0L);
|
||
|
|
Users user = (Users)getLoginUser(req);
|
||
|
|
if (user != null && user.isProfileNoReg()) {
|
||
|
|
long l_id_clifor = user.getId_clifor();
|
||
|
|
if (user.getApFull() == null)
|
||
|
|
user = new Users(apFull);
|
||
|
|
fillObject(req, user);
|
||
|
|
user.setId_clifor(l_id_clifor);
|
||
|
|
fillObject(req, user.getClifor());
|
||
|
|
DestinazioneDiversa dd = new DestinazioneDiversa(apFull);
|
||
|
|
fillObject(req, dd);
|
||
|
|
user.getClifor().setCurrentDD(dd);
|
||
|
|
}
|
||
|
|
if (user != null) {
|
||
|
|
DestinazioneDiversa dd = user.getClifor().getCurrentDD();
|
||
|
|
if (!dd.getId_nazioneDD().isEmpty())
|
||
|
|
l_id_nazione = dd.getId_nazioneDD();
|
||
|
|
}
|
||
|
|
double maxCostoSpedizione = 0.0D;
|
||
|
|
double minCostoSpedizione = 9999.0D;
|
||
|
|
long totPercentile = 0L;
|
||
|
|
Enumeration<CartItem> enu = cart.getItems();
|
||
|
|
cart.setCostoSpedizionePreventivo(false);
|
||
|
|
while (enu.hasMoreElements()) {
|
||
|
|
CartItem row = enu.nextElement();
|
||
|
|
if (row.isCostoSpedizionePreventivo(l_id_nazione))
|
||
|
|
cart.setCostoSpedizionePreventivo(true);
|
||
|
|
double temp = row.getDeliveryCost(l_id_nazione);
|
||
|
|
if (maxCostoSpedizione < temp)
|
||
|
|
maxCostoSpedizione = temp;
|
||
|
|
if (minCostoSpedizione > temp)
|
||
|
|
minCostoSpedizione = temp;
|
||
|
|
totPercentile += row.getPercentileSpedizione() * (long)row.getQuantity();
|
||
|
|
}
|
||
|
|
if (cart.isCostoSpedizionePreventivo()) {
|
||
|
|
delivCost = 0.0D;
|
||
|
|
} else if (totPercentile >= 100L) {
|
||
|
|
if (isPreventivoSuPercentile) {
|
||
|
|
cart.setCostoSpedizionePreventivo(true);
|
||
|
|
delivCost = 0.0D;
|
||
|
|
} else {
|
||
|
|
DoubleOperator dop = new DoubleOperator((float)(totPercentile - 100L));
|
||
|
|
dop.multiply(minCostoSpedizione);
|
||
|
|
dop.divide(100.0F);
|
||
|
|
dop.setScale(2, 4);
|
||
|
|
dop.add(maxCostoSpedizione);
|
||
|
|
delivCost = dop.getResult();
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
delivCost = maxCostoSpedizione;
|
||
|
|
}
|
||
|
|
if (debug) {
|
||
|
|
System.out.println("--------------------------------");
|
||
|
|
System.out.println("percentile : " + totPercentile);
|
||
|
|
System.out.println("max deliv cost : " + maxCostoSpedizione);
|
||
|
|
System.out.println("min deliv cost : " + minCostoSpedizione);
|
||
|
|
System.out.println("PREVENTIVO: " + cart.isCostoSpedizionePreventivo());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (tp.getFlgAbilitatoNegozio() == 1L) {
|
||
|
|
delivCost = 0.0D;
|
||
|
|
cart.setCostoSpedizionePreventivo(false);
|
||
|
|
} else if (tp.getFlgAbilitatoCorriere() == 1L) {
|
||
|
|
cart.setMoreCost(getMoreCost(req));
|
||
|
|
cart.setDescMoreCost(tp.getDescrizione(getLang(req)));
|
||
|
|
} else {
|
||
|
|
cart.setMoreCost(0.0D);
|
||
|
|
cart.setDescMoreCost("");
|
||
|
|
}
|
||
|
|
if (getAct2(req).startsWith("changeDWC"))
|
||
|
|
if (getAct2(req).equals("changeDWC0")) {
|
||
|
|
cart.setDeliveryWarnCost(0.0D);
|
||
|
|
} else {
|
||
|
|
cart.setDeliveryWarnCost(getDeliveryWarnCost(req));
|
||
|
|
}
|
||
|
|
if (debug) {
|
||
|
|
System.out.println("deliv cost : " + delivCost);
|
||
|
|
System.out.println("--------------------------------");
|
||
|
|
}
|
||
|
|
return delivCost;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void _aggiornaNazione(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
Users user = (Users)getLoginUser(req);
|
||
|
|
if (user != null && user.getDBState() == 1) {
|
||
|
|
Clifor clifor = user.getClifor();
|
||
|
|
clifor.setId_nazione(getRequestParameter(req, "id_nazione"));
|
||
|
|
clifor.save();
|
||
|
|
req.setAttribute("cmd", CMD_CHECKOUT);
|
||
|
|
req.setAttribute("act", ATTR_CART);
|
||
|
|
checkOut(req, res);
|
||
|
|
} else {
|
||
|
|
forceJspPage("/index.jsp", req);
|
||
|
|
callJsp(req, res);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void otherCommands(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
if (getCmd(req).equals("aggiornaNazione")) {
|
||
|
|
_aggiornaNazione(req, res);
|
||
|
|
} else if (getCmd(req).equals("saveNotaCart")) {
|
||
|
|
_saveNotaCart(req, res);
|
||
|
|
} else {
|
||
|
|
super.otherCommands(req, res);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ResParm saveUser(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
Users bean = (Users)getLoginUser(req);
|
||
|
|
fillObject(req, bean);
|
||
|
|
Cliente cli = new Cliente(apFull);
|
||
|
|
fillObject(req, cli);
|
||
|
|
bean.setClifor(cli);
|
||
|
|
String msg = "Impossibile Registrare un nuovo utente:";
|
||
|
|
if (bean.isLogonDuplicated()) {
|
||
|
|
msg = msg + " Login già presente in archivio";
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg(msg);
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
if (bean.isEmailDuplicated()) {
|
||
|
|
Users userMl = new Users(apFull);
|
||
|
|
userMl.findUsersByEmail(bean.getEMail());
|
||
|
|
if (userMl.getId_userProfile() == bean.getIdUserProfileMailingList()) {
|
||
|
|
req.setAttribute("id_users", String.valueOf(userMl.getId_users()));
|
||
|
|
req.setAttribute("flgValido", "S");
|
||
|
|
req.setAttribute("id_userProfile", Long.valueOf(bean.getIdUserProfileWww()));
|
||
|
|
rp = saveUserAndClifor(req, res);
|
||
|
|
} else {
|
||
|
|
msg = msg + " Email già presente in archivio";
|
||
|
|
forceMessage(req, msg);
|
||
|
|
req.setAttribute("bean", bean);
|
||
|
|
callJsp(req, res);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if (cli.isCodFiscDuplicated()) {
|
||
|
|
msg = msg + " Codice Fiscale già presente in archivio";
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg(msg);
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
if (cli.isPIvaDuplicated()) {
|
||
|
|
msg = msg + " Partita Iva già presente in archivio";
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg(msg);
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
if (!cli.getCodFisc().isEmpty() && !CodiceFiscale.controlloFormale(cli.getCodFisc())) {
|
||
|
|
msg = msg + " Il codice fiscale non è valido:";
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg(msg);
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
if (!cli.getPIva().isEmpty() && cli.getPIva().length() != 11) {
|
||
|
|
msg = msg + " Partita iva non valida:";
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg(msg);
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
req.setAttribute("flgValido", "S");
|
||
|
|
req.setAttribute("id_userProfile", Long.valueOf(bean.getIdUserProfileWww()));
|
||
|
|
rp = saveUserAndClifor(req, res);
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ResParm saveUserAndClifor(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
Users user = (Users)getLoginUser(req);
|
||
|
|
long l_id_users = getLoginUserId(req);
|
||
|
|
fillObject(req, user);
|
||
|
|
Clifor cliente = user.getClifor();
|
||
|
|
fillObject(req, cliente);
|
||
|
|
String nominativo = getRequestParameter(req, "nominativo");
|
||
|
|
if (!nominativo.isEmpty()) {
|
||
|
|
cliente.setFlgAzienda(1L);
|
||
|
|
cliente.setCognome(nominativo);
|
||
|
|
cliente.setNome("");
|
||
|
|
}
|
||
|
|
cliente.setFlgTipo("C");
|
||
|
|
rp = cliente.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
long ckDestinazioneDiversa = getRequestLongParameter(req, "ckDestinazioneDiversa");
|
||
|
|
if (ckDestinazioneDiversa == 1L) {
|
||
|
|
DestinazioneDiversa dd = cliente.getCurrentDD();
|
||
|
|
fillObject(req, dd);
|
||
|
|
if (!dd.getIndirizzoDD().isEmpty()) {
|
||
|
|
if (dd.getId_destinazioneDiversa() > 0L) {
|
||
|
|
dd.findByPrimaryKey(dd.getId_destinazioneDiversa());
|
||
|
|
fillObject(req, dd);
|
||
|
|
}
|
||
|
|
dd.setId_clifor(cliente.getId_clifor());
|
||
|
|
dd.setId_nazioneDD(cliente.getId_nazione());
|
||
|
|
dd.setFlgDDDefault(1L);
|
||
|
|
dd.setDescrizioneDD("Sped. WWW");
|
||
|
|
rp.append(dd.save());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
user.setId_clifor(cliente.getId_clifor());
|
||
|
|
if (user.getId_userProfile() == 0L)
|
||
|
|
user.setId_userProfile(10L);
|
||
|
|
user.setFlgValido("S");
|
||
|
|
rp.append(user.save());
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
sendMessage(req, "Impossibile salvare: " + rp.getMsg());
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("Impossibile salvare: " + rp.getMsg());
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected boolean useDeliveryCostOnUser() {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void _saveNotaCart(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
Cart cart = getCart(req);
|
||
|
|
cart.setNote(getRequestParameter(req, "note"));
|
||
|
|
setCart(req, cart);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void afterCheckOutNoReg(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
if (attivita.isTagManagerAttivo()) {
|
||
|
|
GoogleDataLayer gdl = new GoogleDataLayer(GoogleDataLayerBuilder.eventStep("eec.checkout", "3"));
|
||
|
|
req.setAttribute("_gdl", gdl);
|
||
|
|
}
|
||
|
|
Cart cart = getCart(req);
|
||
|
|
gestionePromozioni(cart, req);
|
||
|
|
String callingJsp = getRequestParameter(req, "callingJsp");
|
||
|
|
if (callingJsp.equals("checkOut.jsp")) {
|
||
|
|
cart.setNote(getRequestParameter(req, "note"));
|
||
|
|
cart.setFlgPayment(getRequestLongParameter(req, "flgPayment"));
|
||
|
|
setCart(req, cart);
|
||
|
|
}
|
||
|
|
gestioneScontiCommissioniTipoPagamento(cart, req);
|
||
|
|
req.setAttribute("listaNazioni", new Nazione(apFull).findAllAttive(getLang(req)));
|
||
|
|
Users user = (Users)getLoginUser(req);
|
||
|
|
if (user.getApFull() == null)
|
||
|
|
user = new Users(apFull);
|
||
|
|
fillObject(req, user);
|
||
|
|
fillObject(req, user.getClifor());
|
||
|
|
DestinazioneDiversa dd = new DestinazioneDiversa(apFull);
|
||
|
|
fillObject(req, dd);
|
||
|
|
user.getClifor().setCurrentDD(dd);
|
||
|
|
req.setAttribute("beanUser", user);
|
||
|
|
req.setAttribute("listaTipoPagamento", getListaTipiPagamento(req, cart));
|
||
|
|
super.afterCheckOutNoReg(req, res);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ResParm recordOrderNoRegOLD(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ResParm rp = saveNoRegUser(req, res);
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
try {
|
||
|
|
Users utente = (Users)rp.getReturnObj();
|
||
|
|
req.getSession(true).setAttribute("loginUser_id", new Long(utente.getId_users()));
|
||
|
|
req.getSession(true).setAttribute("utenteLogon", utente);
|
||
|
|
Cart cart = getCart(req);
|
||
|
|
long l_id_tipoOrdine = getParm("ID_DOC_ORDINE_WWW").getNumeroLong();
|
||
|
|
Documento ordine = new Documento(apFull);
|
||
|
|
ordine.setId_tipoDocumento(l_id_tipoOrdine);
|
||
|
|
ordine.setFlgStato(1L);
|
||
|
|
ordine.setId_clifor(utente.getId_clifor());
|
||
|
|
ordine.setDataDocumento(new Date(new java.util.Date().getTime()));
|
||
|
|
ordine.setNominativoDocumento(utente.getDescrizione());
|
||
|
|
ordine.setId_tipoPagamento(cart.getFlgPayment());
|
||
|
|
ordine.setFlgRitiroNegozio(cart.getFlgPickup());
|
||
|
|
ordine.setNotaAggiuntiva(cart.getNote());
|
||
|
|
ordine.setKgLordo(0.5D);
|
||
|
|
ordine.setFlgTrasporto(1L);
|
||
|
|
if (cart.getDiscountPerc() > 0L)
|
||
|
|
ordine.setPercScontoIncondizionato((double)cart.getDiscountPerc());
|
||
|
|
DoubleOperator spese = new DoubleOperator(cart.getMoreCost());
|
||
|
|
spese.add(cart.getDeliveryCost());
|
||
|
|
if (cart.getDeliveryWarnCost() > 0.0D) {
|
||
|
|
spese.add(cart.getDeliveryWarnCost());
|
||
|
|
ordine.setFlgAvvisoConsegna(1L);
|
||
|
|
}
|
||
|
|
ordine.setSpeseTrasporto(spese.getResult());
|
||
|
|
if (ordine.getClifor().isPrezzoWebEsente())
|
||
|
|
if (ordine.getClifor().getNazione().getFlgCee() == 1L) {
|
||
|
|
ordine.setId_ivaDoc(ordine.getCodiceIvaCeeAziendaArt41());
|
||
|
|
} else {
|
||
|
|
ordine.setId_ivaDoc(ordine.getCodiceIvaArt8_A());
|
||
|
|
}
|
||
|
|
if (req.getParameter("note") != null && !req.getParameter("note").equals(""))
|
||
|
|
ordine.setNote(req.getParameter("note"));
|
||
|
|
ordine.setFlgStatoOrdineWww(0L);
|
||
|
|
ordine.setFlgPagata(0L);
|
||
|
|
ordine.setFlgWwwRichiedeFattura(1L);
|
||
|
|
long l_rbflgPayment = getRequestLongParameter(req, "rbflgPayment");
|
||
|
|
if (l_rbflgPayment == 0L)
|
||
|
|
l_rbflgPayment = 1L;
|
||
|
|
ordine.setId_tipoPagamento(l_rbflgPayment);
|
||
|
|
long ckDestinazioneDiversa = getRequestLongParameter(req, "ckDestinazioneDiversa");
|
||
|
|
ckDestinazioneDiversa = 1L;
|
||
|
|
DestinazioneDiversa dd = utente.getClifor().getDestinazioneDiversa(0);
|
||
|
|
if (ckDestinazioneDiversa == 1L && dd.getId_destinazioneDiversa() > 0L) {
|
||
|
|
ordine.setPresso(dd.getPressoDD());
|
||
|
|
ordine.setIndirizzoSped(dd.getIndirizzoDD());
|
||
|
|
ordine.setNumeroCivicoSped(dd.getNumeroCivicoDD());
|
||
|
|
ordine.setCittaSped(dd.getDescrizioneComuneDD());
|
||
|
|
ordine.setProvinciaSped(dd.getProvinciaComuneDD());
|
||
|
|
ordine.setCapSped(dd.getCapComuneDD());
|
||
|
|
ordine.setId_nazioneSped(dd.getId_nazioneDD());
|
||
|
|
System.out.println("Destinazione diversa :" + ordine.getPresso());
|
||
|
|
}
|
||
|
|
if (getParm(Cart.P_PROCEDI_PAGAMENTO).isTrue())
|
||
|
|
if (!ordine.getId_nazioneSped().isEmpty()) {
|
||
|
|
if (ordine.getNazioneSped().getFlgPreventivoWww() == 0L)
|
||
|
|
ordine.setFlgProcediPagamento(1L);
|
||
|
|
} else if (ordine.getClifor().getNazione().getFlgPreventivoWww() == 0L) {
|
||
|
|
ordine.setFlgProcediPagamento(1L);
|
||
|
|
}
|
||
|
|
rp = ordine.save();
|
||
|
|
boolean ebayUpdate = false;
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
Enumeration<CartItem> enu = cart.getItems();
|
||
|
|
String lang = getLang(req);
|
||
|
|
while (enu.hasMoreElements()) {
|
||
|
|
CartItem ci = enu.nextElement();
|
||
|
|
if (ci.getQuantity() > 0.0D) {
|
||
|
|
RigaDocumento rigaOrdine = new RigaDocumento(apFull);
|
||
|
|
Articolo articolo = (Articolo)ci.getDbItem();
|
||
|
|
if (articolo.getCartItemType() == 0L) {
|
||
|
|
rigaOrdine.setId_articolo(articolo.getId_articolo());
|
||
|
|
rigaOrdine.setQuantita(ci.getQuantity());
|
||
|
|
rigaOrdine.setNr(ci.getQuantity());
|
||
|
|
rigaOrdine.setPrezzoPubblicoConIva(ci.getPriceWVat(utente.getId_users()));
|
||
|
|
rigaOrdine.setImponibile(ci.getPrice());
|
||
|
|
if (cart.getDiscountPercTot() > 0.0D) {
|
||
|
|
rigaOrdine.setSconto(cart.getDiscountPercTot());
|
||
|
|
} else {
|
||
|
|
rigaOrdine.setSconto(articolo.getPrezzoArticolo(ordine.getClifor()).getPercSconto());
|
||
|
|
}
|
||
|
|
rigaOrdine.setDescrizioneRiga(rigaOrdine.getArticolo().getDescrizioneCompleta(lang));
|
||
|
|
rp = Documento.addRigaDocumento(ordine, rigaOrdine);
|
||
|
|
if (rp.getStatus())
|
||
|
|
Articolo.aggiornaDispoEPrezzoArticoloFornitore(rigaOrdine.getArticolo(), (long)-rigaOrdine.getNr(), 0L, true);
|
||
|
|
if (rp.getStatus() &&
|
||
|
|
!rigaOrdine.getArticolo().isEbayPrezzoQtaAllineati())
|
||
|
|
ebayUpdate = true;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (articolo.getCartItemType() == 3L) {
|
||
|
|
rigaOrdine.setId_articolo(articolo.getId_articolo());
|
||
|
|
rigaOrdine.setId_articoloVariante(articolo.getId_articoloVariante());
|
||
|
|
rigaOrdine.setId_articoloTaglia(articolo.getId_articoloTaglia());
|
||
|
|
rigaOrdine.setQuantita(ci.getQuantity());
|
||
|
|
rigaOrdine.setNr(ci.getQuantity());
|
||
|
|
rigaOrdine.setPrezzoPubblicoConIva(ci.getPriceWVat(utente.getId_users()));
|
||
|
|
rigaOrdine.setImponibile(ci.getPrice());
|
||
|
|
if (cart.getDiscountPercTot() > 0.0D) {
|
||
|
|
rigaOrdine.setSconto(cart.getDiscountPercTot());
|
||
|
|
} else {
|
||
|
|
rigaOrdine.setSconto(articolo.getPrezzoArticolo(ordine.getClifor()).getPercSconto());
|
||
|
|
}
|
||
|
|
rigaOrdine.setDescrizioneRiga(rigaOrdine.getArticolo().getDescrizioneCompleta(lang));
|
||
|
|
rigaOrdine.setId_iva(articolo.getId_iva());
|
||
|
|
rp = Documento.addRigaDocumento(ordine, rigaOrdine);
|
||
|
|
if (rp.getStatus());
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (articolo.getCartItemType() == 5L) {
|
||
|
|
rigaOrdine.setId_articolo(articolo.getId_articolo());
|
||
|
|
rigaOrdine.setId_articoloVariante(articolo.getId_articoloVariante());
|
||
|
|
rigaOrdine.setId_articoloTaglia(articolo.getId_articoloTaglia());
|
||
|
|
rigaOrdine.setQuantita(ci.getQuantity());
|
||
|
|
rigaOrdine.setNr(ci.getQuantity());
|
||
|
|
rigaOrdine.setPrezzoPubblicoConIva(ci.getPriceWVat(utente.getId_users()));
|
||
|
|
rigaOrdine.setImponibile(ci.getPrice());
|
||
|
|
if (cart.getDiscountPercTot() > 0.0D) {
|
||
|
|
rigaOrdine.setSconto(cart.getDiscountPercTot());
|
||
|
|
} else {
|
||
|
|
rigaOrdine.setSconto(articolo.getPrezzoArticolo(ordine.getClifor()).getPercSconto());
|
||
|
|
}
|
||
|
|
rigaOrdine.setDescrizioneRiga(rigaOrdine.getArticolo().getDescrizioneCompleta(lang));
|
||
|
|
rigaOrdine.setId_iva(articolo.getId_iva());
|
||
|
|
rp = Documento.addRigaDocumento(ordine, rigaOrdine);
|
||
|
|
rigaOrdine = new RigaDocumento(apFull);
|
||
|
|
rigaOrdine.setId_articolo(articolo.getArticoloVarianteKit().getId_articolo());
|
||
|
|
rigaOrdine.setId_articoloVariante(articolo.getArticoloVarianteKit().getId_articoloVariante());
|
||
|
|
rigaOrdine.setId_articoloTaglia(articolo.getId_articoloTagliaKit());
|
||
|
|
rigaOrdine.setQuantita(ci.getQuantity());
|
||
|
|
rigaOrdine.setNr(ci.getQuantity());
|
||
|
|
rigaOrdine.setDescrizioneRiga(rigaOrdine.getArticolo().getDescrizioneCompleta(lang));
|
||
|
|
rp = Documento.addRigaDocumento(ordine, rigaOrdine);
|
||
|
|
if (rp.getStatus());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
ordine.setFlgStato(1L);
|
||
|
|
ordine.setFlgStatoOrdineWww(0L);
|
||
|
|
ordine.setFlgStatoPrenotazione(0L);
|
||
|
|
ordine.setNote("Tel. :" + ordine.getClifor().getTelefono() + " - Email: " + ordine.getClifor().getEMail());
|
||
|
|
Promozione promo = new Promozione(apFull);
|
||
|
|
if (!cart.getDescDiscount().isEmpty()) {
|
||
|
|
promo.findByCodicePromozione(cart.getDescDiscount());
|
||
|
|
if (promo.getDBState() == 1)
|
||
|
|
ordine.setNotePagamento("Promo: " + promo.getDescrizioneCompleta(lang));
|
||
|
|
}
|
||
|
|
rp = ordine.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
if (promo.getDBState() == 1) {
|
||
|
|
rp = Promozione.addUtilizzo(promo, utente.getId_users(), ordine.getId_documento());
|
||
|
|
Log.addAltro(apFull, req.getRemoteAddr(), utente.getId_users(), "Promo " +
|
||
|
|
promo.getDescrizione() + " codice: " + promo.getCodicePromozione() + " utilizzata in data " +
|
||
|
|
String.valueOf(promo.getDataUtilizzoPromozione()) + " su ordine " + ordine.getNumeroDocumentoCompleto());
|
||
|
|
} else {
|
||
|
|
handleDebug("Attenzione! recordOrder: promozione " + cart.getDescDiscountPerc() + " non trovata!!", 0);
|
||
|
|
}
|
||
|
|
if (!rp.getStatus())
|
||
|
|
handleDebug("ATTENZIONE! Promozione " + promo.getId_promozione() + " relativa all'ordine " +
|
||
|
|
ordine.getNumeroDocumentoCompleto() + " Non aggiornata!", 0);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
handleDebug(rp.getMsg(), 1);
|
||
|
|
forceJspPageRelative("checkOut.jsp", req);
|
||
|
|
forceMessage(req, "Attenzione! Impossibile registrare l'ordine: " + rp.getMsg());
|
||
|
|
}
|
||
|
|
System.out.println("fine record ORDINE ############");
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
sendMessage(req, "Ordine registrato ma non è stato possibile inviare email di conferma: " + rp.getMsg());
|
||
|
|
rp.setStatus(true);
|
||
|
|
rp.setMsg("Ordine registrato ma non è stato possibile inviare email di conferma: " + rp.getMsg());
|
||
|
|
}
|
||
|
|
req.setAttribute(PROP_ORDER, ordine);
|
||
|
|
int ordineInverso = (ordine.getTipoDocumento().getFlgOrdinamentoRigheStampa() == 1L) ? 1 : 0;
|
||
|
|
req.setAttribute("righeDocumento", ordine.findRigheDocumento(0, 0, ordineInverso));
|
||
|
|
TipoPagamento tp = new TipoPagamento(apFull);
|
||
|
|
Vectumerator<TipoPagamento> vec = tp.findPagamentiWww((ordine.getFlgRitiroNegozio() == 1L), (ordine.getFlgDeliveryType() > 0L));
|
||
|
|
req.setAttribute("listaTipoPagamento", vec);
|
||
|
|
forceJspPageRelative("documento.jsp", req);
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
sendMessage(req, e.getMessage());
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg(e.getMessage());
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
Users user = new Users(getApFull());
|
||
|
|
fillObject(req, user);
|
||
|
|
req.setAttribute("bean", user);
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("Impossibile salvare l'ordine: " + rp.getMsg());
|
||
|
|
}
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
GoogleDataLayer gdl = new GoogleDataLayer(GoogleDataLayerBuilder.eventStep("eec.checkout", "4"));
|
||
|
|
req.setAttribute("_gdl", gdl);
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ResParm saveNoRegUser(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
Users bean = new Users(apFull);
|
||
|
|
fillObject(req, bean);
|
||
|
|
bean.setEMail(bean.getLogin());
|
||
|
|
Cliente cli = new Cliente(apFull);
|
||
|
|
req.setAttribute("eMail", bean.getLogin());
|
||
|
|
fillObject(req, cli);
|
||
|
|
bean.setClifor(cli);
|
||
|
|
String msg = "";
|
||
|
|
boolean pivaOk = true;
|
||
|
|
String l_pIva = bean.getPIva();
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
if (!l_pIva.isEmpty())
|
||
|
|
pivaOk = true;
|
||
|
|
Users userMl = new Users(getApFull(req));
|
||
|
|
Users userCF = new Users(getApFull(req));
|
||
|
|
if (bean.isEmailDuplicated()) {
|
||
|
|
userMl.findUsersByEmail(bean.getEMail());
|
||
|
|
if (userMl.getId_userProfile() == bean.getIdUserProfileMailingList()) {
|
||
|
|
fillObject(req, userMl);
|
||
|
|
userMl.setId_userProfile(bean.getIdUserProfileNoReg());
|
||
|
|
userMl.setFlgValido("S");
|
||
|
|
rp = userMl.save();
|
||
|
|
req.setAttribute("id_users", Long.valueOf(userMl.getId_users()));
|
||
|
|
rp = saveNoRegUserAndClifor(req, res);
|
||
|
|
} else if (userMl.getId_userProfile() == bean.getIdUserProfileNoReg()) {
|
||
|
|
if (userMl.getCodFisc().equals(bean.getCodFisc())) {
|
||
|
|
long l_id_clifor = userMl.getId_clifor();
|
||
|
|
long l_id_user = userMl.getId_users();
|
||
|
|
fillObject(req, userMl);
|
||
|
|
userMl.setId_users(l_id_user);
|
||
|
|
userMl.setId_clifor(l_id_clifor);
|
||
|
|
rp = userMl.save();
|
||
|
|
req.setAttribute("id_users", Long.valueOf(userMl.getId_users()));
|
||
|
|
rp = saveNoRegUserAndClifor(req, res);
|
||
|
|
} else {
|
||
|
|
msg = msg + " Codice Fiscale associata a questa email diverso!!!!!";
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg(msg);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
msg = msg + " Email già presente in archivio perché ti sei già registrato. Effettua il login";
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg(msg);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (!rp.getStatus())
|
||
|
|
return rp;
|
||
|
|
if (bean.isCodFiscDuplicated()) {
|
||
|
|
userCF.findUsersByCodiceFiscale(bean.getCodFisc());
|
||
|
|
if (userCF.getId_userProfile() == bean.getIdUserProfileNoReg()) {
|
||
|
|
if (userCF.getEMail().equals(bean.getEMail())) {
|
||
|
|
long l_id_user = userCF.getId_users();
|
||
|
|
fillObject(req, userCF);
|
||
|
|
userCF.setId_users(l_id_user);
|
||
|
|
rp = userCF.save();
|
||
|
|
req.setAttribute("id_users", Long.valueOf(userCF.getId_users()));
|
||
|
|
rp = saveNoRegUserAndClifor(req, res);
|
||
|
|
} else {
|
||
|
|
msg = msg + " Codice Fiscale già utilizzato con un indirizzo email diverso!!!!!";
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg(msg);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
msg = msg + " Codice Fiscale già presente in archivio perché ti sei già registrato. Effettua il login";
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg(msg);
|
||
|
|
}
|
||
|
|
} else if (!bean.getCodFisc().isEmpty() && bean.getId_nazione().equals("I") && !CodiceFiscale.controlloFormale(bean.getCodFisc())) {
|
||
|
|
msg = msg + " Il codice fiscale non è valido:";
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg(msg);
|
||
|
|
} else {
|
||
|
|
req.setAttribute("flgValido", "S");
|
||
|
|
req.setAttribute("id_userProfile", Long.valueOf(bean.getIdUserProfileNoReg()));
|
||
|
|
rp = saveNoRegUserAndClifor(req, res);
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ResParm saveNoRegUserAndClifor(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ResParm rp = new ResParm(true);
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
Users user = new Users(apFull);
|
||
|
|
long l_id_users = getRequestLongParameter(req, "id_users");
|
||
|
|
user.findByPrimaryKey(l_id_users);
|
||
|
|
long l_id_clifor = user.getId_clifor();
|
||
|
|
fillObject(req, user);
|
||
|
|
user.setId_clifor(l_id_clifor);
|
||
|
|
if (user.getId_nazione().toLowerCase().equals("i")) {
|
||
|
|
user.setLangMl("it");
|
||
|
|
user.setLang("it");
|
||
|
|
} else {
|
||
|
|
user.setLangMl("en");
|
||
|
|
user.setLang("en");
|
||
|
|
}
|
||
|
|
Clifor cliente = user.getClifor();
|
||
|
|
fillObject(req, cliente);
|
||
|
|
cliente.setId_clifor(l_id_clifor);
|
||
|
|
cliente.setFlgTipo("C");
|
||
|
|
rp = cliente.save();
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
DestinazioneDiversa dd = cliente.getCurrentDD();
|
||
|
|
fillObject(req, dd);
|
||
|
|
if (dd.getIndirizzoDD().isEmpty()) {
|
||
|
|
if (dd.getId_destinazioneDiversa() != 0L)
|
||
|
|
rp.append(dd.delete());
|
||
|
|
} else {
|
||
|
|
dd.setId_clifor(cliente.getId_clifor());
|
||
|
|
dd.setFlgDDDefault(1L);
|
||
|
|
dd.setDescrizioneDD("Sped. WWW");
|
||
|
|
rp.append(dd.save());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
user.setId_clifor(cliente.getId_clifor());
|
||
|
|
if (user.getId_userProfile() == 0L)
|
||
|
|
user.setId_userProfile(user.getIdUserProfileNoReg());
|
||
|
|
user.setFlgValido("S");
|
||
|
|
if (user.getPwd().isEmpty()) {
|
||
|
|
RandomString randomString = new RandomString(8);
|
||
|
|
user.setPwd(randomString.nextString());
|
||
|
|
}
|
||
|
|
rp.append(user.save());
|
||
|
|
}
|
||
|
|
if (!rp.getStatus()) {
|
||
|
|
sendMessage(req, "Impossibile salvare: " + rp.getMsg());
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("Impossibile salvare: " + rp.getMsg());
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
rp.setReturnObj(user);
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public AcCartObject getCartObjectOld(HttpServletRequest req) throws Exception {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
String l_id = getRequestParameter(req, "id");
|
||
|
|
long l_id_articolo = 0L, l_id_articoloVariante = 0L, l_id_articoloTaglia = 0L;
|
||
|
|
if (!l_id.isEmpty()) {
|
||
|
|
if (l_id.indexOf("av_") >= 0) {
|
||
|
|
l_id_articoloVariante = Long.parseLong(l_id.substring(3));
|
||
|
|
req.setAttribute("id_articoloVariante", Long.valueOf(l_id_articoloVariante));
|
||
|
|
} else {
|
||
|
|
l_id_articolo = Long.parseLong(l_id);
|
||
|
|
req.setAttribute("id_articolo", Long.valueOf(l_id_articolo));
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
l_id_articolo = getRequestLongParameter(req, "id_articolo");
|
||
|
|
l_id_articoloVariante = getRequestLongParameter(req, "id_articoloVariante");
|
||
|
|
l_id_articoloTaglia = getRequestLongParameter(req, "id_articoloTaglia");
|
||
|
|
}
|
||
|
|
double l_quantity = getRequestDoubleParameter(req, "qt");
|
||
|
|
if (l_quantity == 0.0D)
|
||
|
|
l_quantity = 1.0D;
|
||
|
|
if (l_id_articoloTaglia > 0L) {
|
||
|
|
ArticoloTaglia at = new ArticoloTaglia(apFull);
|
||
|
|
at.findByPrimaryKey(l_id_articoloTaglia);
|
||
|
|
if (at.getQuantitaAtByMagFisico(1L) > 0.0D) {
|
||
|
|
req.setAttribute("bean", at.getArticoloVariante());
|
||
|
|
AcCartObject acCartObject = new AcCartObject(ArticoloTaglia.class, at.getItemId(), l_quantity);
|
||
|
|
acCartObject.setCodPromo(at.getCodicePromozione());
|
||
|
|
return acCartObject;
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
if (l_id_articoloVariante > 0L) {
|
||
|
|
ArticoloVariante av = new ArticoloVariante(apFull);
|
||
|
|
av.findByPrimaryKey(l_id_articoloVariante);
|
||
|
|
if (av.getQuantitaAvByMagFisico(1L) > 0.0D) {
|
||
|
|
req.setAttribute("bean", av);
|
||
|
|
AcCartObject acCartObject = new AcCartObject(ArticoloVariante.class, av.getItemId(), l_quantity);
|
||
|
|
acCartObject.setCodPromo(av.getCodicePromozione());
|
||
|
|
return acCartObject;
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
Articolo bean = new Articolo(apFull);
|
||
|
|
bean.findByPrimaryKey(l_id_articolo);
|
||
|
|
req.setAttribute("bean", bean);
|
||
|
|
AcCartObject aco = new AcCartObject(Articolo.class, bean.getItemId(), l_quantity);
|
||
|
|
aco.setCodPromo(bean.getCodicePromozione());
|
||
|
|
return aco;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected CartItemId scomponiIdSuRequest(HttpServletRequest req) throws Exception {
|
||
|
|
String l_id = getRequestParameter(req, "id");
|
||
|
|
CartItemId articoloID = new CartItemId();
|
||
|
|
articoloID.caricaCartItemIdFromReqId(l_id);
|
||
|
|
if (articoloID.getId_articoloTaglia() > 0L)
|
||
|
|
req.setAttribute("id_articoloTaglia", Long.valueOf(articoloID.getId_articoloTaglia()));
|
||
|
|
if (articoloID.getId_articoloTagliaKit() > 0L)
|
||
|
|
req.setAttribute("id_articoloTagliaKit", Long.valueOf(articoloID.getId_articoloTagliaKit()));
|
||
|
|
if (articoloID.getId_articoloVarianteKit() > 0L)
|
||
|
|
req.setAttribute("id_articoloVarianteKit", Long.valueOf(articoloID.getId_articoloVarianteKit()));
|
||
|
|
if (articoloID.getId_articoloVariante() > 0L)
|
||
|
|
req.setAttribute("id_articoloVariante", Long.valueOf(articoloID.getId_articoloVariante()));
|
||
|
|
if (articoloID.getId_articolo() > 0L)
|
||
|
|
req.setAttribute("id_articolo", Long.valueOf(articoloID.getId_articolo()));
|
||
|
|
return articoloID;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected CartItemId getRequestParameterCartItemId(HttpServletRequest req, String parmName) {
|
||
|
|
if (req.getAttribute(parmName) != null && req.getAttribute(parmName) instanceof CartItemId)
|
||
|
|
return (CartItemId)req.getAttribute(parmName);
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void gestionePromozioni(Cart cart, HttpServletRequest req) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
String l_lang = getLang(req);
|
||
|
|
String l_codicePromozione = getRequestParameter(req, "codicePromozione");
|
||
|
|
if (l_codicePromozione.isEmpty())
|
||
|
|
l_codicePromozione = getRequestParameter(req, "codicePromozioneXs");
|
||
|
|
if (!l_codicePromozione.isEmpty()) {
|
||
|
|
CartStatus cs = (CartStatus)req.getAttribute(ATTR_CART_STATUS);
|
||
|
|
Promozione promozione = new Promozione(getApFull(req));
|
||
|
|
promozione.findByCodicePromozione(l_codicePromozione);
|
||
|
|
if (promozione.getDBState() == 0) {
|
||
|
|
sendMessage(req, attivita.translate("Codice Promozione non valido.", l_lang));
|
||
|
|
} else {
|
||
|
|
Users utente = (Users)getLoginUser(req);
|
||
|
|
long resPromo = promozione.isValid(utente);
|
||
|
|
if (resPromo == Promozione.PROMOZIONE_VALIDA) {
|
||
|
|
cart.setDiscountPerc(promozione.getPercSconto());
|
||
|
|
cart.setDescDiscountPerc(promozione.getDescrizione(l_lang));
|
||
|
|
cart.setCodPromo(promozione.getCodicePromozione());
|
||
|
|
setCart(req, cart);
|
||
|
|
} else if (resPromo == Promozione.PROMOZIONE_SCADUTA) {
|
||
|
|
sendMessage(req, attivita.translate("Codice Promozione scaduta.", l_lang));
|
||
|
|
} else if (resPromo == Promozione.PROMOZIONE_NON_VALIDA) {
|
||
|
|
sendMessage(req, attivita.translate("Codice Promozione Non Valida.", l_lang));
|
||
|
|
} else if (resPromo == Promozione.PROMOZIONE_UTENTE_NULL) {
|
||
|
|
sendMessage(req,
|
||
|
|
attivita.translate("Codice Promozione per Utente. Devi fare il login per poterla utilizzare.", l_lang));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void afterCheckCartOLD(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
String l_lang = getLang(req);
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
String l_codicePromozione = getRequestParameter(req, "codicePromozione");
|
||
|
|
if (l_codicePromozione.isEmpty())
|
||
|
|
l_codicePromozione = getRequestParameter(req, "codicePromozioneXs");
|
||
|
|
Cart cart = getCart(req);
|
||
|
|
if (!l_codicePromozione.isEmpty()) {
|
||
|
|
CartStatus cs = (CartStatus)req.getAttribute(ATTR_CART_STATUS);
|
||
|
|
Promozione promozione = new Promozione(getApFull(req));
|
||
|
|
promozione.findByCodicePromozione(l_codicePromozione);
|
||
|
|
if (promozione.getDBState() == 0) {
|
||
|
|
sendMessage(req, attivita.translate("Codice Promozione non valido.", l_lang));
|
||
|
|
} else {
|
||
|
|
Users utente = (Users)getLoginUser(req);
|
||
|
|
long resPromo = promozione.isValid(utente);
|
||
|
|
if (resPromo == Promozione.PROMOZIONE_VALIDA) {
|
||
|
|
cart.setDiscountPerc(promozione.getPercSconto());
|
||
|
|
cart.setDescDiscountPerc(promozione.getDescrizione(l_lang));
|
||
|
|
cart.setDescDiscount(promozione.getCodicePromozione());
|
||
|
|
setCart(req, cart);
|
||
|
|
} else if (resPromo == Promozione.PROMOZIONE_SCADUTA) {
|
||
|
|
sendMessage(req, attivita.translate("Codice Promozione scaduta.", l_lang));
|
||
|
|
} else if (resPromo == Promozione.PROMOZIONE_NON_VALIDA) {
|
||
|
|
sendMessage(req, attivita.translate("Codice Promozione Non Valida.", l_lang));
|
||
|
|
} else if (resPromo == Promozione.PROMOZIONE_UTENTE_NULL) {
|
||
|
|
sendMessage(req,
|
||
|
|
attivita.translate("Codice Promozione per Utente. Devi fare il login per poterla utilizzare.", l_lang));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
String callingJsp = getRequestParameter(req, "callingJsp");
|
||
|
|
if (!callingJsp.isEmpty()) {
|
||
|
|
setJspPageRelative(callingJsp, req);
|
||
|
|
} else {
|
||
|
|
setJspPageRelative("cart.jsp", req);
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
callJsp(req, res);
|
||
|
|
} catch (Exception e) {
|
||
|
|
handleDebug(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void afterCheckOutNoRegOLD(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
String l_lang = getLang(req);
|
||
|
|
String l_codicePromozione = getRequestParameter(req, "codicePromozione");
|
||
|
|
if (l_codicePromozione.isEmpty())
|
||
|
|
l_codicePromozione = getRequestParameter(req, "codicePromozioneXs");
|
||
|
|
Cart cart = getCart(req);
|
||
|
|
if (!l_codicePromozione.isEmpty()) {
|
||
|
|
CartStatus cs = (CartStatus)req.getAttribute(ATTR_CART_STATUS);
|
||
|
|
Promozione promozione = new Promozione(getApFull(req));
|
||
|
|
promozione.findByCodicePromozione(l_codicePromozione);
|
||
|
|
if (promozione.getDBState() == 0) {
|
||
|
|
sendMessage(req, "Codice Promozione non valido.");
|
||
|
|
} else {
|
||
|
|
Users utente = (Users)getLoginUser(req);
|
||
|
|
long resPromo = promozione.isValid(utente);
|
||
|
|
if (resPromo == Promozione.PROMOZIONE_VALIDA) {
|
||
|
|
cart.setDiscountPerc(promozione.getPercSconto());
|
||
|
|
cart.setDescDiscountPerc(promozione.getDescrizione(l_lang));
|
||
|
|
cart.setCodPromo(promozione.getCodicePromozione());
|
||
|
|
setCart(req, cart);
|
||
|
|
} else if (resPromo == Promozione.PROMOZIONE_SCADUTA) {
|
||
|
|
sendMessage(req, attivita.translate("Codice Promozione scaduta.", l_lang));
|
||
|
|
} else if (resPromo == Promozione.PROMOZIONE_NON_VALIDA) {
|
||
|
|
sendMessage(req, attivita.translate("Codice Promozione Non Valida.", l_lang));
|
||
|
|
} else if (resPromo == Promozione.PROMOZIONE_UTENTE_NULL) {
|
||
|
|
sendMessage(req,
|
||
|
|
attivita.translate("Codice Promozione per Utente. Devi fare il login per poterla utilizzare.", l_lang));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
cart.setNote(getRequestParameter(req, "note"));
|
||
|
|
cart.setFlgPayment(getRequestLongParameter(req, "flgPayment"));
|
||
|
|
setCart(req, cart);
|
||
|
|
req.setAttribute("listaNazioni", new Nazione(apFull).findAllAttive(getLang(req)));
|
||
|
|
Users user = (Users)getLoginUser(req);
|
||
|
|
boolean isTipoPagEstero = false;
|
||
|
|
if (user.getApFull() == null)
|
||
|
|
user = new Users(apFull);
|
||
|
|
fillObject(req, user);
|
||
|
|
fillObject(req, user.getClifor());
|
||
|
|
DestinazioneDiversa dd = new DestinazioneDiversa(apFull);
|
||
|
|
fillObject(req, dd);
|
||
|
|
user.getClifor().setCurrentDD(dd);
|
||
|
|
if (user != null)
|
||
|
|
isTipoPagEstero = !user.getClifor().getId_nazione().equals("I");
|
||
|
|
req.setAttribute("beanUser", user);
|
||
|
|
req.setAttribute("listaTipoPagamento", new TipoPagamento(getApFull(req)).findPagamentiWww(isTipoPagEstero, false));
|
||
|
|
super.afterCheckOutNoReg(req, res);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void gestioneScontiCommissioniTipoPagamento(Cart cart, HttpServletRequest req) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
String l_lang = getLang(req);
|
||
|
|
TipoPagamento tp = new TipoPagamento(apFull);
|
||
|
|
tp.findByPrimaryKey(cart.getFlgPayment());
|
||
|
|
if (tp.getPercWwwSconto() > 0.0D) {
|
||
|
|
cart.setPercDiscountPay(tp.getPercWwwSconto());
|
||
|
|
cart.setDescDiscountPay(attivita.translate("Sconto per ", l_lang) + " " + attivita.translate("Sconto per ", l_lang));
|
||
|
|
} else {
|
||
|
|
cart.setPercDiscountPay(0.0D);
|
||
|
|
cart.setDescDiscountPay("");
|
||
|
|
}
|
||
|
|
if (tp.getPercWwwSconto() == 0.0D && tp.getPercWwwCommissione() > 0.0D) {
|
||
|
|
cart.setPercCommissionPay(tp.getPercWwwSconto());
|
||
|
|
cart.setDescCommissionPay(attivita.translate("Contributo pratiche elettroniche", l_lang));
|
||
|
|
} else {
|
||
|
|
cart.setPercCommissionPay(0.0D);
|
||
|
|
cart.setDescCommissionPay("");
|
||
|
|
}
|
||
|
|
setCart(req, cart);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected double getDeliveryCostPercentile(HttpServletRequest req, Cart cart) {
|
||
|
|
boolean debug = false;
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
double totCart = cart.getTotPriceVAT();
|
||
|
|
if (getParm(Cart.P_DELIVERY_FREE_ABOVE).getNumeroDouble() >= 0.0D && totCart >=
|
||
|
|
getParm(Cart.P_DELIVERY_FREE_ABOVE).getNumeroDouble()) {
|
||
|
|
System.out.println("getDeliveryCostFull: free above: " +
|
||
|
|
getParm(Cart.P_DELIVERY_FREE_ABOVE).getNumeroDouble() + " totCart:" + totCart);
|
||
|
|
return 0.0D;
|
||
|
|
}
|
||
|
|
String l_id_nazione = "I";
|
||
|
|
Nazione nazione = null;
|
||
|
|
double delivCost = 0.0D;
|
||
|
|
long l_flgTipoPagamento = cart.getFlgPayment();
|
||
|
|
TipoPagamento tp = new TipoPagamento(getApFull());
|
||
|
|
tp.findByPrimaryKey(l_flgTipoPagamento);
|
||
|
|
if (tp.getFlgAbilitatoNegozio() == 0L) {
|
||
|
|
Attivita attivita = Attivita.getDefaultInstance(apFull);
|
||
|
|
long percentileMax = attivita.getPercentileMaxPerPreventivo();
|
||
|
|
Users user = (Users)getLoginUser(req);
|
||
|
|
if (user != null && user.isProfileNoReg()) {
|
||
|
|
long l_id_clifor = user.getId_clifor();
|
||
|
|
if (user.getApFull() == null)
|
||
|
|
user = new Users(apFull);
|
||
|
|
fillObject(req, user);
|
||
|
|
user.setId_clifor(l_id_clifor);
|
||
|
|
fillObject(req, user.getClifor());
|
||
|
|
DestinazioneDiversa dd = new DestinazioneDiversa(apFull);
|
||
|
|
fillObject(req, dd);
|
||
|
|
user.getClifor().setCurrentDD(dd);
|
||
|
|
}
|
||
|
|
if (user != null) {
|
||
|
|
DestinazioneDiversa dd = user.getClifor().getCurrentDD();
|
||
|
|
if (!dd.getId_nazioneDD().isEmpty()) {
|
||
|
|
l_id_nazione = dd.getId_nazioneDD();
|
||
|
|
nazione = new Nazione(apFull);
|
||
|
|
nazione.findByPrimaryKey(l_id_nazione);
|
||
|
|
} else {
|
||
|
|
l_id_nazione = user.getClifor().getId_nazione();
|
||
|
|
nazione = user.getClifor().getNazione();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (nazione == null) {
|
||
|
|
nazione = new Nazione(apFull);
|
||
|
|
nazione.findByPrimaryKey(l_id_nazione);
|
||
|
|
}
|
||
|
|
double maxCostoSpedizione = 0.0D;
|
||
|
|
long totPercentile = 0L;
|
||
|
|
Enumeration<CartItem> enu = cart.getItems();
|
||
|
|
cart.setCostoSpedizionePreventivo((nazione.getFlgPreventivoWww() == 1L));
|
||
|
|
while (enu.hasMoreElements()) {
|
||
|
|
CartItem row = enu.nextElement();
|
||
|
|
if (row.isCostoSpedizionePreventivo(l_id_nazione))
|
||
|
|
cart.setCostoSpedizionePreventivo(true);
|
||
|
|
double temp = row.getDeliveryCost(l_id_nazione);
|
||
|
|
if (maxCostoSpedizione < temp)
|
||
|
|
maxCostoSpedizione = temp;
|
||
|
|
totPercentile += row.getPercentileSpedizione() * (long)row.getQuantity();
|
||
|
|
}
|
||
|
|
if (cart.isCostoSpedizionePreventivo()) {
|
||
|
|
delivCost = 0.0D;
|
||
|
|
} else if (totPercentile >= 100L) {
|
||
|
|
if (totPercentile >= percentileMax) {
|
||
|
|
cart.setCostoSpedizionePreventivo(true);
|
||
|
|
delivCost = 0.0D;
|
||
|
|
} else {
|
||
|
|
DoubleOperator dop = new DoubleOperator((float)(totPercentile - 100L));
|
||
|
|
dop.multiply(maxCostoSpedizione);
|
||
|
|
dop.divide(100.0F);
|
||
|
|
dop.setScale(2, 4);
|
||
|
|
dop.add(maxCostoSpedizione);
|
||
|
|
delivCost = dop.getResult();
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
delivCost = maxCostoSpedizione;
|
||
|
|
}
|
||
|
|
if (debug) {
|
||
|
|
System.out.println("--------------------------------");
|
||
|
|
System.out.println("percentile : " + totPercentile + " max percentile: " + percentileMax);
|
||
|
|
System.out.println("max deliv cost: " + maxCostoSpedizione);
|
||
|
|
System.out.println("PREVENTIVO: " + cart.isCostoSpedizionePreventivo());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (tp.getFlgAbilitatoNegozio() == 1L) {
|
||
|
|
delivCost = 0.0D;
|
||
|
|
cart.setCostoSpedizionePreventivo(false);
|
||
|
|
} else if (tp.getFlgAbilitatoCorriere() == 1L) {
|
||
|
|
cart.setMoreCost(getMoreCost(req));
|
||
|
|
cart.setDescMoreCost(tp.getDescrizione(getLang(req)));
|
||
|
|
} else {
|
||
|
|
cart.setMoreCost(0.0D);
|
||
|
|
cart.setDescMoreCost("");
|
||
|
|
}
|
||
|
|
if (getAct2(req).startsWith("changeDWC"))
|
||
|
|
if (getAct2(req).equals("changeDWC0")) {
|
||
|
|
cart.setDeliveryWarnCost(0.0D);
|
||
|
|
} else {
|
||
|
|
cart.setDeliveryWarnCost(getDeliveryWarnCost(req));
|
||
|
|
}
|
||
|
|
if (debug) {
|
||
|
|
System.out.println("deliv cost : " + delivCost);
|
||
|
|
System.out.println("--------------------------------");
|
||
|
|
}
|
||
|
|
return delivCost;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ResParm recordOrderNoReg(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
ResParm rp = saveNoRegUser(req, res);
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
String lang = getLang(req);
|
||
|
|
if (rp.getStatus()) {
|
||
|
|
Users utente = (Users)rp.getReturnObj();
|
||
|
|
req.getSession(true).setAttribute("loginUser_id", new Long(utente.getId_users()));
|
||
|
|
req.getSession(true).setAttribute("utenteLogon", utente);
|
||
|
|
return recordOrder(req, res);
|
||
|
|
}
|
||
|
|
Users user = new Users(getApFull());
|
||
|
|
fillObject(req, user);
|
||
|
|
req.setAttribute("bean", user);
|
||
|
|
rp.setStatus(false);
|
||
|
|
rp.setMsg("Impossibile salvare l'ordine: " + rp.getMsg());
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected long getDeliveryIvaId(HttpServletRequest req) {
|
||
|
|
return getDeliveryIva(req).getId_iva();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected double getDeliveryIvaAliquota(HttpServletRequest req) {
|
||
|
|
return (double)getDeliveryIva(req).getAliquota();
|
||
|
|
}
|
||
|
|
|
||
|
|
private Iva getDeliveryIva(HttpServletRequest req) {
|
||
|
|
if (this.deliveryIva == null)
|
||
|
|
if (getLoginUserId(req) > 0L) {
|
||
|
|
Users user = new Users(getApFull(req));
|
||
|
|
user.findByPrimaryKey(getLoginUserId(req));
|
||
|
|
if (user.getClifor().getId_clifor() > 0L) {
|
||
|
|
DestinazioneDiversa dd = user.getClifor().getCurrentDD();
|
||
|
|
if (user.getClifor().isPrezzoWebEsente()) {
|
||
|
|
if (dd.getId_destinazioneDiversa() > 0L) {
|
||
|
|
if (user.getClifor().getNazione().getCodice().equals("IT") &&
|
||
|
|
user.getClifor().getFlgAzienda() == 1L &&
|
||
|
|
dd.getNazioneDD().getFlgCee() == 1L) {
|
||
|
|
this.deliveryIva = user.getClifor().getIvaArt58();
|
||
|
|
} else if (user.getClifor().getNazione().getFlgCee() == 1L &&
|
||
|
|
!user.getClifor().getNazione().getCodice().equals("IT") &&
|
||
|
|
user.getClifor().getFlgAzienda() == 1L &&
|
||
|
|
dd.getNazioneDD().getFlgCee() == 1L) {
|
||
|
|
this.deliveryIva = user.getClifor().getIvaArt41();
|
||
|
|
} else {
|
||
|
|
this.deliveryIva = user.getClifor().getIvaArt8A();
|
||
|
|
}
|
||
|
|
} else if (user.getClifor().getNazione().getFlgCee() == 1L) {
|
||
|
|
this.deliveryIva = user.getClifor().getIvaArt41();
|
||
|
|
} else {
|
||
|
|
this.deliveryIva = user.getClifor().getIvaArt8A();
|
||
|
|
}
|
||
|
|
} else if (user.getClifor().isIvaCeeOneStopShop()) {
|
||
|
|
boolean oss = false;
|
||
|
|
if (user.getClifor().getFlgAzienda() == 0L &&
|
||
|
|
user.getClifor().getNazione().getFlgCee() == 1L &&
|
||
|
|
!user.getClifor().getNazione().getCodice().equals("IT"))
|
||
|
|
if (dd.getId_destinazioneDiversa() > 0L) {
|
||
|
|
if (dd.getNazioneDD().getFlgCee() == 1L &&
|
||
|
|
!dd.getNazioneDD().getCodice().equals("IT")) {
|
||
|
|
oss = true;
|
||
|
|
} else {
|
||
|
|
oss = false;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
oss = true;
|
||
|
|
}
|
||
|
|
if (oss) {
|
||
|
|
Nazione nazioneOss;
|
||
|
|
if (dd.getId_destinazioneDiversa() > 0L) {
|
||
|
|
nazioneOss = dd.getNazioneDD();
|
||
|
|
} else {
|
||
|
|
nazioneOss = user.getClifor().getNazione();
|
||
|
|
}
|
||
|
|
if (nazioneOss.getId_iva() != 0L) {
|
||
|
|
this.deliveryIva = nazioneOss.getIva();
|
||
|
|
} else {
|
||
|
|
handleDebug("ERRORE! CartSvlt.getDeliveryIva Aliquota iva OSS per " + nazioneOss.getDescrizione() + " non impostata!!!!", 1);
|
||
|
|
this.deliveryIva = new Iva(getApFull(req));
|
||
|
|
this.deliveryIva.findByPrimaryKey(getParm(Cart.P_DELIVERY_IVA_ID).getNumeroLong());
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
this.deliveryIva = new Iva(getApFull(req));
|
||
|
|
this.deliveryIva.findByPrimaryKey(getParm(Cart.P_DELIVERY_IVA_ID).getNumeroLong());
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
this.deliveryIva = new Iva(getApFull(req));
|
||
|
|
this.deliveryIva.findByPrimaryKey(getParm(Cart.P_DELIVERY_IVA_ID).getNumeroLong());
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
this.deliveryIva = new Iva(getApFull(req));
|
||
|
|
this.deliveryIva.findByPrimaryKey(getParm(Cart.P_DELIVERY_IVA_ID).getNumeroLong());
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
this.deliveryIva = new Iva(getApFull(req));
|
||
|
|
this.deliveryIva.findByPrimaryKey(getParm(Cart.P_DELIVERY_IVA_ID).getNumeroLong());
|
||
|
|
}
|
||
|
|
return (this.deliveryIva == null) ? new Iva(getApFull(req)) : this.deliveryIva;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setDeliveryIva(Iva deliveryIva) {
|
||
|
|
this.deliveryIva = deliveryIva;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void logOut(HttpServletRequest req, HttpServletResponse res) {
|
||
|
|
super.logOut(req, res);
|
||
|
|
setDeliveryIva(null);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void resetDeliveryIva() {
|
||
|
|
setDeliveryIva(null);
|
||
|
|
}
|
||
|
|
|
||
|
|
private ResParm inviaNotificaOrdineAdmin(HttpServletRequest req, HttpServletResponse res, Documento ordine) {
|
||
|
|
ApplParmFull apFull = getApFull(req);
|
||
|
|
ResParm rp = new ResParm();
|
||
|
|
ordine.calcolaCostiWww();
|
||
|
|
RemoteDevice bean = new RemoteDevice(apFull);
|
||
|
|
bean.findFirstAvailable();
|
||
|
|
if (bean.getId_remoteDevice() > 0L) {
|
||
|
|
String messaggio = "Cliente: " + ordine.getClifor().getCognomeNome() + " tot ordine: " +
|
||
|
|
getNf().format(ordine.getTotaleDocumento()) + " Netto: " + getNf().format(ordine.getWwwNettoOrdine()) + " " +
|
||
|
|
getNf().format(ordine.getWwwNettoOrdinePerc()) + "%\n" + ordine.getDescrizioneRighe();
|
||
|
|
String filejsonAuth = getParm("FIREBASE_JSON_AUTH_PRIVATE_KEY").getTesto();
|
||
|
|
PushNotificationService pns = new PushNotificationService(filejsonAuth);
|
||
|
|
MsgJson notifica = new MsgJson("notification", "Ordine Web " + ordine.getProgOrdineWww(), messaggio);
|
||
|
|
MsgJson data = new MsgJson("notification", "Ordine Web", "Ordine Web " +
|
||
|
|
ordine.getProgOrdineWww() + messaggio);
|
||
|
|
List<String> list = new ArrayList<>();
|
||
|
|
list.add(bean.getFcmToken());
|
||
|
|
pns.sendPushNotification(list, notifica, data, "smsgateway-f05ec");
|
||
|
|
}
|
||
|
|
return rp;
|
||
|
|
}
|
||
|
|
}
|