<p>Saves S.E. orders.</p>
@param pRqVs request scoped vars
@param pPur purchase
@param pCart cart
@throws Exception - an exception
350958
public final void saveSords(final Map<String, Object> pRqVs,
    final Purch pPur, final Cart pCart) throws Exception {
    List<CuOrSe> dels = null;
    for (CuOrSe co : pPur.getSords()) {
      if (co.getCurr() == null) { //stored unused order
        //remove it and all its lines:
        for (CuOrSeGdLn gl : co.getGoods()) {
          for (CuOrSeGdTxLn gtl : gl.getItTxs()) {
            getSrvOrm().deleteEntity(pRqVs, gtl);
          }
          getSrvOrm().deleteEntity(pRqVs, gl);
        }
        for (CuOrSeSrLn sl : co.getServs()) {
          for (CuOrSeSrTxLn stl : sl.getItTxs()) {
            getSrvOrm().deleteEntity(pRqVs, stl);
          }
          getSrvOrm().deleteEntity(pRqVs, sl);
        }
        for (CuOrSeTxLn otlt : co.getTaxes()) {
          getSrvOrm().deleteEntity(pRqVs, otlt);
        }
        getSrvOrm().deleteEntity(pRqVs, co);
        if (dels == null) {
          dels = new ArrayList<CuOrSe>();
        }
        dels.add(co);
        continue;
      }
      if (co.getIsNew()) {
        getSrvOrm().insertEntity(pRqVs, co);
      }
      BigDecimal tot = BigDecimal.ZERO;
      BigDecimal subt = BigDecimal.ZERO;
      List<CuOrSeGdLn> delsGd = null;
      for (CuOrSeGdLn gl : co.getGoods()) {
        gl.setItsOwner(co);
        if (gl.getIsNew()) {
          getSrvOrm().insertEntity(pRqVs, gl);
        }
        if (gl.getItTxs() != null && gl.getItTxs().size() > 0) {
          for (CuOrSeGdTxLn gtl : gl.getItTxs()) {
            gtl.setItsOwner(gl);
            if (gtl.getIsNew()) {
              getSrvOrm().insertEntity(pRqVs, gtl);
            } else if (gl.getGood() == null || gtl.getTax() == null) {
              getSrvOrm().deleteEntity(pRqVs, gtl);
            } else {
              getSrvOrm().updateEntity(pRqVs, gtl);
            }
          }
        }
        if (!gl.getIsNew() && gl.getGood() == null) {
          getSrvOrm().deleteEntity(pRqVs, gl);
          if (delsGd == null) {
            delsGd = new ArrayList<CuOrSeGdLn>();
          }
          delsGd.add(gl);
        } else {
          tot = tot.add(gl.getTot());
          subt = subt.add(gl.getSubt());
          if (!gl.getIsNew()) {
            getSrvOrm().updateEntity(pRqVs, gl);
          }
        }
      }
      if (delsGd != null) {
        for (CuOrSeGdLn gl : delsGd) {
          co.getGoods().remove(gl);
        }
      }
      List<CuOrSeSrLn> delsSr = null;
      for (CuOrSeSrLn sl : co.getServs()) {
        sl.setItsOwner(co);
        if (sl.getIsNew()) {
          getSrvOrm().insertEntity(pRqVs, sl);
        }
        if (sl.getItTxs() != null && sl.getItTxs().size() > 0) {
          for (CuOrSeSrTxLn stl : sl.getItTxs()) {
            stl.setItsOwner(sl);
            if (stl.getIsNew()) {
              getSrvOrm().insertEntity(pRqVs, stl);
            } else if (sl.getService() == null || stl.getTax() == null) {
              getSrvOrm().deleteEntity(pRqVs, stl);
            } else {
              getSrvOrm().updateEntity(pRqVs, stl);
            }
          }
        }
        if (!sl.getIsNew() && sl.getService() == null) {
          getSrvOrm().deleteEntity(pRqVs, sl);
          if (delsSr == null) {
            delsSr = new ArrayList<CuOrSeSrLn>();
          }
          delsSr.add(sl);
        } else {
          tot = tot.add(sl.getTot());
          subt = subt.add(sl.getSubt());
          if (!sl.getIsNew()) {
            getSrvOrm().updateEntity(pRqVs, sl);
          }
        }
      }
      if (delsSr != null) {
        for (CuOrSeSrLn sl : delsSr) {
          co.getServs().remove(sl);
        }
      }
      BigDecimal totTx = BigDecimal.ZERO;
      for (CartTxLn ctl : pCart.getTaxes()) {
        if (ctl.getDisab() || ctl.getSeller() == null
          || !ctl.getSeller().getSeller().getItsId()
            .equals(co.getSel().getSeller().getItsId())) {
          continue;
        }
        CuOrSeTxLn otl = null;
        if (!co.getIsNew()) {
          for (CuOrSeTxLn otlt : co.getTaxes()) {
            if (otlt.getTax() == null) {
              otl = otlt;
              break;
            }
          }
        }
        if (otl == null) {
          otl = new CuOrSeTxLn();
          otl.setIsNew(true);
          co.getTaxes().add(otl);
        }
        otl.setItsOwner(co);
        Tax tx = new Tax();
        tx.setItsId(ctl.getTax().getItsId());
        tx.setItsName(ctl.getTax().getItsName());
        otl.setTax(tx);
        otl.setTot(ctl.getTot());
        otl.setTaxab(ctl.getTaxab());
        totTx = totTx.add(otl.getTot());
        if (otl.getIsNew()) {
          getSrvOrm().insertEntity(pRqVs, otl);
        } else {
          getSrvOrm().updateEntity(pRqVs, otl);
        }
      }
      if (!co.getIsNew()) {
        List<CuOrSeTxLn> delsTx = null;
        for (CuOrSeTxLn otlt : co.getTaxes()) {
          if (otlt.getTax() == null) {
            getSrvOrm().deleteEntity(pRqVs, otlt);
            if (delsTx == null) {
              delsTx = new ArrayList<CuOrSeTxLn>();
            }
            delsTx.add(otlt);
          }
        }
        if (delsTx != null) {
          for (CuOrSeTxLn tl : delsTx) {
            co.getTaxes().remove(tl);
          }
        }
      }
      co.setTot(tot);
      co.setSubt(subt);
      co.setTotTx(totTx);
      getSrvOrm().updateEntity(pRqVs, co);
    }
    if (dels != null) {
      for (CuOrSe co : dels) {
        pPur.getSords().remove(co);
      }
    }
  }
591552
protected final PrcGoodsAdviseCategoriesSave<RS> lazyGetPrcGoodsAdviseCategoriesSave(final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrcGoodsAdviseCategoriesSave.class.getSimpleName();
    @SuppressWarnings("unchecked")
    PrcGoodsAdviseCategoriesSave<RS> proc = (PrcGoodsAdviseCategoriesSave<RS>) this.processorsMap.get(beanName);
    if (proc == null) {
      proc = new PrcGoodsAdviseCategoriesSave<RS>();
      proc.setSrvOrm(getSrvOrm());
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnTradeEntitiesProcessors.class, beanName + " has been created.");
    }
    return proc;
  }
561950
public final void processService(final Map<String, Object> pRqVs,
    final IRequestData pRqDt, final TradingSettings pTs,
      final OnlineBuyer pBuyer, final Long pItemId) throws Exception {
    List<ServiceSpecifics> itemSpecLst;
    List<ServicePlace> itemPlaceLst;
    itemSpecLst = retrieveItemSpecificsList(pRqVs, pTs, pItemId,
      ServiceSpecifics.class, ServiceToSale.class.getSimpleName());
    //extract main image if exist:
    int miIdx = -1;
    for (int i = 0; i < itemSpecLst.size(); i++) {
      if (itemSpecLst.get(i).getSpecifics().getItsType()
        .equals(ESpecificsItemType.IMAGE)) {
        pRqDt.setAttribute("itemImage", itemSpecLst.get(i));
        miIdx = i;
        break;
      }
    }
    if (miIdx != -1) {
      itemSpecLst.remove(miIdx);
    }
    AItemPrice<?, ?> itemPrice = getSrvCart().revealItemPrice(pRqVs, pTs,
      pBuyer, EShopItemType.SERVICE, pItemId);
    itemPlaceLst = getSrvOrm().retrieveListWithConditions(pRqVs,
        ServicePlace.class, " where ITEM=" + pItemId);
    pRqDt.setAttribute("itemSpecLst", itemSpecLst);
    pRqDt.setAttribute("itemPlaceLst", itemPlaceLst);
    pRqDt.setAttribute("itemPrice", itemPrice);
  }
1224571
@Override
  public final void process(final Map<String, Object> pRqVs,
    final IRequestData pRqDt) throws Exception {
    Cart cart = this.srvCart.getShoppingCart(pRqVs, pRqDt, false, true);
    if (cart == null) {
      redir(pRqVs, pRqDt);
      return;
    }
    if (EPaymentMethod.PAYPAL.equals(cart.getPayMeth())) {
      //TODO partially online, SE
      List<PayMd> payMds = this.srvOrm.retrieveListWithConditions(pRqVs,
        PayMd.class, "where ITSNAME='PAYPAL'");
      if (payMds.size() != 1) {
        throw new Exception("There is no properly PPL PayMd");
      } else {
        pRqDt.setAttribute("pmde", payMds.get(0).getMde());
      }
    }
    TradingSettings ts = (TradingSettings) pRqVs.get("tradSet");
    AccSettings as = (AccSettings) pRqVs.get("accSet");
    TaxDestination txRules = this.srvCart.revealTaxRules(pRqVs, cart, as);
    //redo prices and taxes:
    for (CartLn cl : cart.getItems()) {
      if (!cl.getDisab() && !cl.getForc()) {
        this.srvCart.makeCartLine(pRqVs, cl, as, ts, txRules, true, true);
        this.srvCart.makeCartTotals(pRqVs, ts, cl, as, txRules);
      }
    }
    boolean isCompl = true;
    Purch pur = retNewOrds(pRqVs, cart.getBuyer());
    String cond;
    for (CartLn cl : cart.getItems()) {
      if (cl.getDisab()) {
        continue;
      }
      Class<?> itPlCl;
      String serBus = null;
      if (cl.getItTyp().equals(EShopItemType.GOODS)) {
        itPlCl = GoodsPlace.class;
      } else if (cl.getItTyp().equals(EShopItemType.SERVICE)) {
        itPlCl = ServicePlace.class;
        serBus = SerBus.class.getSimpleName();
      } else if (cl.getItTyp().equals(EShopItemType.SESERVICE)) {
        itPlCl = SeServicePlace.class;
        serBus = SeSerBus.class.getSimpleName();
      } else {
        itPlCl = SeGoodsPlace.class;
      }
      if (serBus == null || cl.getDt1() == null) {
        // good or non-bookable service
        cond = "where ITSQUANTITY>0 and ITEM=" + cl.getItId();
      } else {
        cond = "left join (select distinct SERV from " + serBus + " where SERV="
      + cl.getItId() + " and FRTM>=" + cl.getDt1().getTime() + " and TITM<"
    + cl.getDt2().getTime() + ") as " + serBus + " on " + serBus + ".SERV="
  + itPlCl.getSimpleName() + ".ITEM where ITEM=" + cl.getItId()
+ " and ITSQUANTITY>0 and " + serBus + ".SERV is null";
      }
      Set<String> ndFlNm = new HashSet<String>();
      ndFlNm.add("itsId");
      ndFlNm.add("itsName");
      pRqVs.put("PickUpPlaceneededFields", ndFlNm);
      pRqVs.put(itPlCl.getSimpleName() + "itemdeepLevel", 1); //only ID
      @SuppressWarnings("unchecked")
      List<AItemPlace<?, ?>> places = (List<AItemPlace<?, ?>>) getSrvOrm()
        .retrieveListWithConditions(pRqVs, itPlCl, cond);
      pRqVs.remove(itPlCl.getSimpleName() + "itemdeepLevel");
      pRqVs.remove("PickUpPlaceneededFields");
      if (places.size() > 1 && serBus != null && cl.getDt1() != null) {
        //for bookable service it's ambiguous - same service (e.g. appointment
        //to DR.Jonson) is available at same time in two different places)
        //for non-bookable service, e.g. for delivering place means
        //starting-point, but it should be selected automatically TODO
        //for goods: TODO
        //1. buyer chooses place (in filter), so use this place
        //2. buyer will pickups by yourself from different places,
        // but it must chooses them (in filter) in this case.
        // As a result places should ordered by itsQuantity and removed items
        // that are out of filter.
        isCompl = false;
        String errs = "!Wrong places for item name/ID/type: " + cl.getItsName()
          + "/" + cl.getItId() + "/" + cl.getItTyp();
        if (cart.getDescr() == null) {
          cart.setDescr(errs);
        } else {
          cart.setDescr(cart.getDescr() + errs);
        }
        cart.setErr(true);
        getSrvOrm().updateEntity(pRqVs, cart);
        this.log.warn(pRqVs, PrcCheckOut.class, errs);
        break;
      } else { //only/multiply place/s with non-zero availability
        BigDecimal avQu = BigDecimal.ZERO;
        for (AItemPlace<?, ?> pl : places) {
          avQu = avQu.add(pl.getItsQuantity());
        }
        if (avQu.compareTo(cl.getQuant()) == -1) {
          isCompl = false;
          cl.setAvQuan(avQu);
          String errs = "!Not available item name/ID/type/quant/avail: "
            + cl.getItsName() + "/" + cl.getItId() + "/" + cl.getItTyp()
              + "/" + cl.getQuant() + "/" + avQu;
          this.log.warn(pRqVs, PrcCheckOut.class, errs);
        }
      }
      if (isCompl && cl.getPrice().compareTo(BigDecimal.ZERO) == 1) {
        //without free delivering:
        if (cl.getSeller() == null) {
          makeOrdLn(pRqVs, pur.getOrds(), null, cl, ts);
        } else {
          makeSeOrdLn(pRqVs, pur.getSords(), cl.getSeller(), null, cl, ts);
        }
      } else {
        getSrvOrm().updateEntity(pRqVs, cl);
      }
    }
    pRqDt.setAttribute("cart", cart);
    if (txRules != null) {
      pRqDt.setAttribute("txRules", txRules);
    }
    if (!isCompl) {
      redir(pRqVs, pRqDt);
    } else {
      saveOrds(pRqVs, pur, cart);
      saveSords(pRqVs, pur, cart);
      pRqDt.setAttribute("orders", pur.getOrds());
      pRqDt.setAttribute("sorders", pur.getSords());
    }
  }
132141
public final void makeOrdLn(final Map<String, Object> pRqVs,
    final List<CustOrder> pOrders, final AItemPlace<?, ?> pItPl,
      final CartLn pCartLn, final TradingSettings pTs) throws Exception {
    CustOrder cuOr = null;
    boolean isNdOrInit = true;
    for (CustOrder co : pOrders) {
      if (co.getCurr() != null) {
        cuOr = co;
        isNdOrInit = false;
        break;
      }
    }
    if (cuOr == null) {
      cuOr = new CustOrder();
      cuOr.setIsNew(true);
      cuOr.setTaxes(new ArrayList<CustOrderTxLn>());
      cuOr.setGoods(new ArrayList<CustOrderGdLn>());
      cuOr.setServs(new ArrayList<CustOrderSrvLn>());
      pOrders.add(cuOr);
    }
    if (isNdOrInit) {
      cuOr.setDat(new Date());
      cuOr.setStat(EOrdStat.NEW);
      cuOr.setDeliv(pCartLn.getItsOwner().getDeliv());
      cuOr.setPayMeth(pCartLn.getItsOwner().getPayMeth());
      cuOr.setBuyer(pCartLn.getItsOwner().getBuyer());
      //TODO method "pickup by buyer from several places"
      //cuOr.setPlace(pItPl.getPickUpPlace());
      cuOr.setPur(pCartLn.getItsOwner().getItsVersion());
      cuOr.setCurr(pCartLn.getItsOwner().getCurr());
      cuOr.setExcRt(pCartLn.getItsOwner().getExcRt());
      cuOr.setDescr(pCartLn.getItsOwner().getDescr());
    }
    pRqVs.put(CartItTxLn.class.getSimpleName() + "itsOwnerdeepLevel", 1);
    pRqVs.put(CartItTxLn.class.getSimpleName() + "taxdeepLevel", 1);
    List<CartItTxLn> citls = getSrvOrm().retrieveListWithConditions(pRqVs,
      CartItTxLn.class, "where DISAB=0 and ITSOWNER=" + pCartLn.getItsId());
    pRqVs.remove(CartItTxLn.class.getSimpleName() + "itsOwnerdeepLevel");
    pRqVs.remove(CartItTxLn.class.getSimpleName() + "taxdeepLevel");
    ACustOrderLn ol;
    if (pCartLn.getItTyp().equals(EShopItemType.GOODS)) {
      CustOrderGdLn ogl = null;
      if (!cuOr.getIsNew()) {
        for (CustOrderGdLn gl : cuOr.getGoods()) {
          if (gl.getGood() == null) {
            ogl = gl;
            break;
          }
        }
      }
      if (ogl == null) {
        ogl = new CustOrderGdLn();
        ogl.setIsNew(true);
        cuOr.getGoods().add(ogl);
      }
      InvItem gd = new InvItem();
      gd.setItsId(pCartLn.getItId());
      gd.setItsName(pCartLn.getItsName());
      ogl.setGood(gd);
      if (citls.size() > 0) {
        if (ogl.getIsNew()) {
          ogl.setItTxs(new ArrayList<CuOrGdTxLn>());
        }
        for (CartItTxLn citl : citls) {
          CuOrGdTxLn oitl = null;
          if (!cuOr.getIsNew()) {
            for (CuOrGdTxLn itl : ogl.getItTxs()) {
              if (itl.getTax() == null) {
                oitl = itl;
                break;
              }
            }
          }
          if (oitl == null) {
            oitl = new CuOrGdTxLn();
            oitl.setIsNew(true);
            ogl.getItTxs().add(oitl);
          }
          oitl.setItsOwner(ogl);
          Tax tx = new Tax();
          tx.setItsId(citl.getTax().getItsId());
          tx.setItsName(citl.getTax().getItsName());
          oitl.setTax(tx);
          oitl.setTot(citl.getTot());
        }
      }
      ol = ogl;
    } else {
      CustOrderSrvLn osl = null;
      if (!cuOr.getIsNew()) {
        for (CustOrderSrvLn sl : cuOr.getServs()) {
          if (sl.getService() == null) {
            osl = sl;
            break;
          }
        }
      }
      if (osl == null) {
        osl = new CustOrderSrvLn();
        osl.setIsNew(true);
        cuOr.getServs().add(osl);
      }
      ServiceToSale sr = new ServiceToSale();
      sr.setItsId(pCartLn.getItId());
      sr.setItsName(pCartLn.getItsName());
      osl.setService(sr);
      osl.setDt1(pCartLn.getDt1());
      osl.setDt2(pCartLn.getDt2());
      if (citls.size() > 0) {
        if (osl.getIsNew()) {
          osl.setItTxs(new ArrayList<CuOrSrTxLn>());
        }
        for (CartItTxLn citl : citls) {
          CuOrSrTxLn oitl = null;
          if (!cuOr.getIsNew()) {
            for (CuOrSrTxLn itl : osl.getItTxs()) {
              if (itl.getTax() == null) {
                oitl = itl;
                break;
              }
            }
          }
          if (oitl == null) {
            oitl = new CuOrSrTxLn();
            oitl.setIsNew(true);
            osl.getItTxs().add(oitl);
          }
          oitl.setItsOwner(osl);
          Tax tx = new Tax();
          tx.setItsId(citl.getTax().getItsId());
          tx.setItsName(citl.getTax().getItsName());
          oitl.setTax(tx);
          oitl.setTot(citl.getTot());
        }
      }
      ol = osl;
    }
    ol.setItsName(pCartLn.getItsName());
    ol.setDescr(pCartLn.getDescr());
    ol.setUom(pCartLn.getUom());
    ol.setPrice(pCartLn.getPrice());
    ol.setQuant(pCartLn.getQuant());
    ol.setSubt(pCartLn.getSubt());
    ol.setTot(pCartLn.getTot());
    ol.setTotTx(pCartLn.getTotTx());
    ol.setTxCat(pCartLn.getTxCat());
    ol.setTxDsc(pCartLn.getTxDsc());
  }
475877
protected final PrcPurchaseInvoiceServiceLineSave<RS>
    lazyGetPrcPurchaseInvoiceServiceLineSave(
      final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcPurchaseInvoiceServiceLineSave<RS> proc =
      (PrcPurchaseInvoiceServiceLineSave<RS>)
      this.processorsMap
        .get(PrcPurchaseInvoiceServiceLineSave.class.getSimpleName());
    if (proc == null) {
      proc = new PrcPurchaseInvoiceServiceLineSave<RS>();
      proc.setSrvAccSettings(getSrvAccSettings());
      proc.setSrvOrm(getSrvOrm());
      proc.setUtlInvLine(lazyGetUtlPurSrLn(pAddParam));
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcPurchaseInvoiceServiceLineSave.class.getSimpleName(), proc);
    }
    return proc;
  }
795456
@Override
  public final T process(final Map<String, Object> pReqVars,
    final T pEntity, final IRequestData pRequestData) throws Exception {
    SeSeller ses = findSeSeller.find(pReqVars, pRequestData.getUserName());
    pEntity.setSeller(ses);
    if (pEntity.getIsNew()) {
      this.srvOrm.insertEntity(pReqVars, pEntity);
      pEntity.setIsNew(false);
    } else {
      T entOld = this.srvOrm.retrieveEntity(pReqVars, pEntity);
      if (!entOld.getSeller().getItsId().getItsId()
        .equals(pEntity.getSeller().getItsId().getItsId())) {
        throw new ExceptionWithCode(ExceptionWithCode.FORBIDDEN,
        "Attempt to update smb. else's entity: user/entity/EID/SEOLDID/SEID - "
          + pRequestData.getUserName() + "/" + pEntity.getClass()
           .getSimpleName() + "/" + pEntity.getItsId() + "/" + entOld
            .getSeller().getItsId().getItsId() + "/" + pEntity.getSeller()
              .getItsId().getItsId());
      }
      this.srvOrm.updateEntity(pReqVars, pEntity);
    }
    return pEntity;
  }
1135921
public final void retLines(final Map<String, Object> pRqVs,
    final OnlineBuyer pBur, final List<CustOrder> pOrds,
      final List<CuOrSe> pSords) throws Exception {
    StringBuffer ordIds = null;
    for (CustOrder co : pOrds) {
      co.setGoods(new ArrayList<CustOrderGdLn>());
      co.setServs(new ArrayList<CustOrderSrvLn>());
      if (ordIds == null) {
        ordIds = new StringBuffer();
        ordIds.append(co.getItsId().toString());
      } else {
        ordIds.append("," + co.getItsId());
      }
    }
    Set<String> ndFlNm = new HashSet<String>();
    ndFlNm.add("itsId");
    ndFlNm.add("itsName");
    Set<String> ndFl = new HashSet<String>();
    ndFl.add("itsId");
    ndFl.add("itsOwner");
    ndFl.add("itsName");
    ndFl.add("uom");
    ndFl.add("quant");
    ndFl.add("price");
    ndFl.add("tot");
    ndFl.add("totTx");
    String tbn;
    if (ordIds != null) {
      tbn = CustOrderGdLn.class.getSimpleName();
      pRqVs.put(tbn + "neededFields", ndFl);
      pRqVs.put(tbn + "itsOwnerdeepLevel", 1);
      pRqVs.put("UnitOfMeasureneededFields", ndFlNm);
      List<CustOrderGdLn> allGds = this.srvOrm.retrieveListWithConditions(pRqVs,
        CustOrderGdLn.class, "where ITSOWNER in (" + ordIds + ")");
      pRqVs.remove(tbn + "neededFields");
      pRqVs.remove(tbn + "itsOwnerdeepLevel");
      pRqVs.remove("UnitOfMeasureneededFields");
      for (CustOrderGdLn il : allGds) {
        for (CustOrder co : pOrds) {
          if (co.getItsId().equals(il.getItsOwner().getItsId())) {
            co.getGoods().add(il);
            break;
          }
        }
      }
      tbn = CustOrderSrvLn.class.getSimpleName();
      pRqVs.put(tbn + "neededFields", ndFl);
      pRqVs.put(tbn + "itsOwnerdeepLevel", 1);
      pRqVs.put("UnitOfMeasureneededFields", ndFlNm);
      List<CustOrderSrvLn> allSrs = this.srvOrm.retrieveListWithConditions(
        pRqVs, CustOrderSrvLn.class, "where ITSOWNER in (" + ordIds + ")");
      pRqVs.remove(tbn + "neededFields");
      pRqVs.remove(tbn + "itsOwnerdeepLevel");
      pRqVs.remove("UnitOfMeasureneededFields");
      for (CustOrderSrvLn il : allSrs) {
        for (CustOrder co : pOrds) {
          if (co.getItsId().equals(il.getItsOwner().getItsId())) {
            co.getServs().add(il);
            break;
          }
        }
      }
    }
    ordIds = null;
    for (CuOrSe co : pSords) {
      co.setGoods(new ArrayList<CuOrSeGdLn>());
      co.setServs(new ArrayList<CuOrSeSrLn>());
      if (ordIds == null) {
        ordIds = new StringBuffer();
        ordIds.append(co.getItsId().toString());
      } else {
        ordIds.append("," + co.getItsId());
      }
    }
    if (ordIds != null) {
      tbn = CuOrSeGdLn.class.getSimpleName();
      pRqVs.put(tbn + "neededFields", ndFl);
      pRqVs.put(tbn + "itsOwnerdeepLevel", 1);
      pRqVs.put("UnitOfMeasureneededFields", ndFlNm);
      List<CuOrSeGdLn> allGds = this.srvOrm.retrieveListWithConditions(pRqVs,
        CuOrSeGdLn.class, "where ITSOWNER in (" + ordIds + ")");
      pRqVs.remove(tbn + "neededFields");
      pRqVs.remove(tbn + "itsOwnerdeepLevel");
      pRqVs.remove("UnitOfMeasureneededFields");
      for (CuOrSeGdLn il : allGds) {
        for (CuOrSe co : pSords) {
          if (co.getItsId().equals(il.getItsOwner().getItsId())) {
            co.getGoods().add(il);
            break;
          }
        }
      }
      tbn = CuOrSeSrLn.class.getSimpleName();
      pRqVs.put(tbn + "neededFields", ndFl);
      pRqVs.put(tbn + "itsOwnerdeepLevel", 1);
      pRqVs.put("UnitOfMeasureneededFields", ndFlNm);
      List<CuOrSeSrLn> allSrs = this.srvOrm.retrieveListWithConditions(
        pRqVs, CuOrSeSrLn.class, "where ITSOWNER in (" + ordIds + ")");
      pRqVs.remove(tbn + "neededFields");
      pRqVs.remove(tbn + "itsOwnerdeepLevel");
      pRqVs.remove("UnitOfMeasureneededFields");
      for (CuOrSeSrLn il : allSrs) {
        for (CuOrSe co : pSords) {
          if (co.getItsId().equals(il.getItsOwner().getItsId())) {
            co.getServs().add(il);
            break;
          }
        }
      }
    }
  }
311783
protected final PrcSalesInvoiceLineSave<RS> lazyGetPrcSalesInvoiceLineSave(
    final Map<String, Object> pAddParam) throws Exception {
    @SuppressWarnings("unchecked")
    PrcSalesInvoiceLineSave<RS> proc = (PrcSalesInvoiceLineSave<RS>)
      this.processorsMap.get(PrcSalesInvoiceLineSave.class.getSimpleName());
    if (proc == null) {
      proc = new PrcSalesInvoiceLineSave<RS>();
      proc.setSrvAccSettings(getSrvAccSettings());
      proc.setSrvOrm(getSrvOrm());
      proc.setSrvWarehouseEntry(getSrvWarehouseEntry());
      proc.setSrvCogsEntry(getSrvCogsEntry());
      proc.setUtlInvLine(lazyGetUtlSalGdLn(pAddParam));
      //assigning fully initialized object:
      this.processorsMap
        .put(PrcSalesInvoiceLineSave.class.getSimpleName(), proc);
    }
    return proc;
  }
545190
@Override
  public final void hndCartChan(final Map<String, Object> pRqVs,
    final Cart pCart, final TaxDestination pTxRules) throws Exception {
    @SuppressWarnings("unchecked")
    List<Deliv> dlvMts = (List<Deliv>) pRqVs.get("dlvMts");
    Deliv cdl = null;
    for (Deliv dl : dlvMts) {
      if (dl.getItsId().equals(pCart.getDeliv())) {
        cdl = dl;
        break;
      }
    }
    if (cdl == null) {
      throw new Exception("wrong delivering!");
    }
    //it must be at least one item to add forced service:
    boolean crtEmpty = true;
    CartLn clFrc = null;
    CartLn clEm = null;
    for (CartLn cl : pCart.getItems()) {
      if (cl.getDisab()) {
        clEm = cl;
      } else if (!cl.getDisab() && cl.getForc()) {
        clFrc = cl;
      } else if (!cl.getDisab() && !cl.getForc()) {
        crtEmpty = false;
      }
    }
    if (clFrc == null && cdl.getFrcSr() == null || cdl.getApMt() == null) {
      return;
    }
    if (crtEmpty) {
      if (clFrc != null) {
        delLine(pRqVs, clFrc, pTxRules);
      }
      return;
    }
    int cartTot;
    AccSettings as = (AccSettings) pRqVs.get("accSet");
    TradingSettings ts = (TradingSettings) pRqVs.get("tradSet");
    BigDecimal ct = pCart.getTot();
    if (clFrc != null && clFrc.getTot().compareTo(BigDecimal.ZERO) == 1) {
      ct = ct.subtract(clFrc.getTot());
    }
    if (pCart.getExcRt().compareTo(BigDecimal.ONE) == 0) {
      cartTot = ct.intValue();
    } else {
      cartTot = ct.divide(pCart.getExcRt(), as.getPricePrecision(),
        as.getRoundingMode()).intValue();
    }
    if (cartTot >= cdl.getApMt()) {
      if (clFrc != null && clFrc.getTot().compareTo(BigDecimal.ZERO) == 1) {
        clFrc.setPrice(BigDecimal.ZERO);
        clFrc.setTot(BigDecimal.ZERO);
        clFrc.setTotTx(BigDecimal.ZERO);
        clFrc.setSubt(BigDecimal.ZERO);
        clFrc.setTxDsc(null);
        clFrc.setTxCat(null);
        this.srvOrm.updateEntity(pRqVs, clFrc);
        makeCartTotals(pRqVs, ts, clFrc, as, pTxRules);
      }
    } else {
      if (clFrc == null) {
        if (clEm == null) {
          clFrc = new CartLn();
          clFrc.setIsNew(true);
          clFrc.setItsOwner(pCart);
          pCart.getItems().add(clFrc);
        } else {
          clFrc = clEm;
        }
        clFrc.setSel(null);
        clFrc.setForc(true);
        clFrc.setDisab(false);
        clFrc.setItTyp(EShopItemType.SERVICE);
        clFrc.setItId(cdl.getFrcSr().getItsId());
        clFrc.setItsName(cdl.getFrcSr().getItsName());
        clFrc.setUom(cdl.getFrcSr().getDefUnitOfMeasure());
        clFrc.setAvQuan(BigDecimal.ONE);
        clFrc.setQuant(BigDecimal.ONE);
        clFrc.setUnStep(BigDecimal.ONE);
        makeCartLine(pRqVs, clFrc, as, ts, pTxRules, true, true);
        makeCartTotals(pRqVs, ts, clFrc, as, pTxRules);
      } else if (clFrc.getTot().compareTo(BigDecimal.ZERO) == 0) {
        makeCartLine(pRqVs, clFrc, as, ts, pTxRules, true, true);
        makeCartTotals(pRqVs, ts, clFrc, as, pTxRules);
      }
    }
  }
608778
public final void emptyCart(final Map<String, Object> pRqVs,
    final Cart pCart) throws Exception {
    String[] fieldsNames = new String[] {"itsId", "itsVersion", "disab"};
    pRqVs.put("fieldsNames", fieldsNames);
    for (CartLn l : pCart.getItems()) {
      if (!l.getDisab()) {
        l.setDisab(true);
        getSrvOrm().updateEntity(pRqVs, l);
      }
    }
    for (CartTxLn l : pCart.getTaxes()) {
      if (!l.getDisab()) {
        l.setDisab(true);
        getSrvOrm().updateEntity(pRqVs, l);
      }
    }
    for (CartTot l : pCart.getTotals()) {
      if (!l.getDisab()) {
        l.setDisab(true);
        getSrvOrm().updateEntity(pRqVs, l);
      }
    }
    pRqVs.remove("fieldsNames");
    if (pCart.getTot().compareTo(BigDecimal.ZERO) == 1) {
      pCart.setTot(BigDecimal.ZERO);
      getSrvOrm().updateEntity(pRqVs, pCart);
    }
  }
353449
def post(self, request, *args, **kwargs):
        
        POST = json.loads(request.body.decode('utf-8'))

        if 'product_pk' in POST and 'quantity' in POST:
            cart = ShoppingCartProxy(request)
            cart.add(
                product_pk=int(POST['product_pk']),
                quantity=int(POST['quantity'])
            )
            return JsonResponse(cart.products)

        return HttpResponseBadRequest()
854105
protected final PrcPrepaymentFromSave<RS> createPutPrcPrepaymentFromSave(
    final Map<String, Object> pAddParam) throws Exception {
    PrcPrepaymentFromSave<RS> proc = new PrcPrepaymentFromSave<RS>();
    proc.setSrvAccSettings(getSrvAccSettings());
    proc.setSrvAccEntry(getSrvAccEntry());
    proc.setSrvOrm(getSrvOrm());
    proc.setSrvI18n(getSrvI18n());
    //assigning fully initialized object:
    this.processorsMap.put(PrcPrepaymentFromSave.class.getSimpleName(), proc);
    return proc;
  }
1140392
@RequestMapping(value = "/qrpay")
    public void qrPay(
            @RequestParam("orderNumber") String orderNumber,
            HttpServletResponse response){
        try {
            String qrUrl = wepaySupport.qrPay(orderNumber);
            response.sendRedirect(qrUrl);
        } catch (IOException e) {
            log.error("failed to qr pay(orderNumber={}), cause: {}",
                    orderNumber, e.getMessage());
        }
    }
914973
protected final PrcSalesInvoiceServiceLineDelete
    createPutPrcSalesInvoiceServiceLineDelete(
      final Map<String, Object> pAddParam) throws Exception {
    PrcSalesInvoiceServiceLineDelete<RS> proc =
      new PrcSalesInvoiceServiceLineDelete<RS>();
    @SuppressWarnings("unchecked")
    IEntityProcessor<SalesInvoiceServiceLine, Long> procDlg =
      (IEntityProcessor<SalesInvoiceServiceLine, Long>)
        this.fctBnEntitiesProcessors
          .lazyGet(pAddParam, PrcEntityPbDelete.class.getSimpleName());
    proc.setSrvOrm(getSrvOrm());
    proc.setPrcAccEntityPbDelete(procDlg);
    proc.setSrvAccSettings(getSrvAccSettings());
    proc.setUtlInvLine(lazyGetUtlSalSrLn(pAddParam));
    //assigning fully initialized object:
    this.processorsMap
      .put(PrcSalesInvoiceServiceLineDelete.class.getSimpleName(), proc);
    return proc;
  }
17154
@Override
  public final void makeFirstPrepareForSave(final Map<String, Object> pReqVars,
    final PurchaseInvoice pEntity,
      final IRequestData pRequestData) throws Exception {
    if (pEntity.getPrepaymentTo() != null) {
      pEntity.setPrepaymentTo(getSrvOrm()
        .retrieveEntity(pReqVars, pEntity.getPrepaymentTo()));
      if (pEntity.getReversedId() == null && pEntity.getPrepaymentTo()
        .getPurchaseInvoiceId() != null && !pEntity.getHasMadeAccEntries()) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "prepayment_already_in_use");
      }
      if (pEntity.getReversedId() == null && !pEntity.getPrepaymentTo()
        .getVendor().getItsId().equals(pEntity.getVendor().getItsId())) {
        throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
          "prepayment_for_different_vendor");
      }
    }
    if (pEntity.getReversedId() != null && pEntity.getPrepaymentTo() != null
      && pEntity.getPaymentTotal().compareTo(pEntity.getPrepaymentTo()
        .getItsTotal()) != 0) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "reverse_payments_first");
    }
    if (pEntity.getReversedId() != null && pEntity.getPrepaymentTo() == null
      && pEntity.getPaymentTotal().compareTo(BigDecimal.ZERO) != 0) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "reverse_payments_first");
    }
    if (pEntity.getReversedId() == null) {
      calculateTotalPayment(pReqVars, pEntity);
    }
    if (!pEntity.getIsNew()) {
      pReqVars.put("DebtorCreditortaxDestinationdeepLevel", 2);
      Set<String> ndFlDc = new HashSet<String>();
      ndFlDc.add("itsId");
      ndFlDc.add("isForeigner");
      ndFlDc.add("taxDestination");
      pReqVars.put("DebtorCreditorneededFields", ndFlDc);
    }
  }
487705
@Override
  public final void fill(final Map<String, Object> pAddParam,
    final Object pEntity, final String pFieldName,
      final String pFieldStrValue) throws Exception {
    try {
      @SuppressWarnings("unchecked")
      IOwned<Cart> cartItem = (IOwned<Cart>) pEntity;
      Cart ownedEntity = new Cart();
      OnlineBuyer buyer = new OnlineBuyer();
      buyer.setItsId(Long.valueOf(pFieldStrValue));
      ownedEntity.setBuyer(buyer);
      cartItem.setItsOwner(ownedEntity);
    } catch (Exception ex) {
      throw new ExceptionWithCode(ExceptionWithCode
        .WRONG_PARAMETER, "Can not fill field: " + pEntity + "/" + pFieldName
          + "/" + pFieldStrValue + ", " + ex.getMessage(), ex);
    }
  }