public final void saveOrds(final Map<String, Object> pRqVs,
    final Purch pPur, final Cart pCart) throws Exception {
    List<CustOrder> dels = null;
    for (CustOrder co : pPur.getOrds()) {
      if (co.getCurr() == null) { //stored unused order
        //remove it and all its lines:
        for (CustOrderGdLn gl : co.getGoods()) {
          for (CuOrGdTxLn gtl : gl.getItTxs()) {
            getSrvOrm().deleteEntity(pRqVs, gtl);
          }
          getSrvOrm().deleteEntity(pRqVs, gl);
        }
        for (CustOrderSrvLn sl : co.getServs()) {
          for (CuOrSrTxLn stl : sl.getItTxs()) {
            getSrvOrm().deleteEntity(pRqVs, stl);
          }
          getSrvOrm().deleteEntity(pRqVs, sl);
        }
        for (CustOrderTxLn otlt : co.getTaxes()) {
          getSrvOrm().deleteEntity(pRqVs, otlt);
        }
        getSrvOrm().deleteEntity(pRqVs, co);
        if (dels == null) {
          dels = new ArrayList<CustOrder>();
        }
        dels.add(co);
        continue;
      }
      if (co.getIsNew()) {
        getSrvOrm().insertEntity(pRqVs, co);
      }
      BigDecimal tot = BigDecimal.ZERO;
      BigDecimal subt = BigDecimal.ZERO;
      List<CustOrderGdLn> delsGd = null;
      for (CustOrderGdLn gl : co.getGoods()) {
        gl.setItsOwner(co);
        if (gl.getIsNew()) {
          getSrvOrm().insertEntity(pRqVs, gl);
        }
        if (gl.getItTxs() != null && gl.getItTxs().size() > 0) {
          for (CuOrGdTxLn 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<CustOrderGdLn>();
          }
          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 (CustOrderGdLn gl : delsGd) {
          co.getGoods().remove(gl);
        }
      }
      List<CustOrderSrvLn> delsSr = null;
      for (CustOrderSrvLn sl : co.getServs()) {
        sl.setItsOwner(co);
        if (sl.getIsNew()) {
          getSrvOrm().insertEntity(pRqVs, sl);
        }
        if (sl.getItTxs() != null && sl.getItTxs().size() > 0) {
          for (CuOrSrTxLn 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<CustOrderSrvLn>();
          }
          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 (CustOrderSrvLn sl : delsSr) {
          co.getServs().remove(sl);
        }
      }
      List<CustOrderTxLn> delsTx = null;
      BigDecimal totTx = BigDecimal.ZERO;
      for (CartTxLn ctl : pCart.getTaxes()) {
        if (ctl.getDisab() || ctl.getSeller() != null) {
          continue;
        }
        CustOrderTxLn otl = null;
        if (!co.getIsNew()) {
          for (CustOrderTxLn otlt : co.getTaxes()) {
            if (otlt.getTax() == null) {
              otl = otlt;
              break;
            }
          }
        }
        if (otl == null) {
          otl = new CustOrderTxLn();
          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()) {
        for (CustOrderTxLn otlt : co.getTaxes()) {
          if (otlt.getTax() == null) {
            getSrvOrm().deleteEntity(pRqVs, otlt);
            if (delsTx == null) {
              delsTx = new ArrayList<CustOrderTxLn>();
            }
            delsTx.add(otlt);
          }
        }
      }
      if (delsTx != null) {
        for (CustOrderTxLn tl : delsTx) {
          co.getTaxes().remove(tl);
        }
      }
      co.setTot(tot);
      co.setSubt(subt);
      co.setTotTx(totTx);
      getSrvOrm().updateEntity(pRqVs, co);
    }
    if (dels != null) {
      for (CustOrder co : dels) {
        pPur.getOrds().remove(co);
      }
    }
  }
public final void saveOrds ( final Map < String , Object > pRqVs , final Purch pPur , final Cart pCart ) throws Exception { List < CustOrder > dels = null ; for ( CustOrder co : pPur . getOrds ( ) ) { if ( co . getCurr ( ) == null ) { for ( CustOrderGdLn gl : co . getGoods ( ) ) { for ( CuOrGdTxLn gtl : gl . getItTxs ( ) ) { getSrvOrm ( ) . deleteEntity ( pRqVs , gtl ) ; } getSrvOrm ( ) . deleteEntity ( pRqVs , gl ) ; } for ( CustOrderSrvLn sl : co . getServs ( ) ) { for ( CuOrSrTxLn stl : sl . getItTxs ( ) ) { getSrvOrm ( ) . deleteEntity ( pRqVs , stl ) ; } getSrvOrm ( ) . deleteEntity ( pRqVs , sl ) ; } for ( CustOrderTxLn otlt : co . getTaxes ( ) ) { getSrvOrm ( ) . deleteEntity ( pRqVs , otlt ) ; } getSrvOrm ( ) . deleteEntity ( pRqVs , co ) ; if ( dels == null ) { dels = new ArrayList < CustOrder > ( ) ; } dels . add ( co ) ; continue ; } if ( co . getIsNew ( ) ) { getSrvOrm ( ) . insertEntity ( pRqVs , co ) ; } BigDecimal tot = BigDecimal . ZERO ; BigDecimal subt = BigDecimal . ZERO ; List < CustOrderGdLn > delsGd = null ; for ( CustOrderGdLn gl : co . getGoods ( ) ) { gl . setItsOwner ( co ) ; if ( gl . getIsNew ( ) ) { getSrvOrm ( ) . insertEntity ( pRqVs , gl ) ; } if ( gl . getItTxs ( ) != null && gl . getItTxs ( ) . size ( ) > 0 ) { for ( CuOrGdTxLn 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 < CustOrderGdLn > ( ) ; } 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 ( CustOrderGdLn gl : delsGd ) { co . getGoods ( ) . remove ( gl ) ; } } List < CustOrderSrvLn > delsSr = null ; for ( CustOrderSrvLn sl : co . getServs ( ) ) { sl . setItsOwner ( co ) ; if ( sl . getIsNew ( ) ) { getSrvOrm ( ) . insertEntity ( pRqVs , sl ) ; } if ( sl . getItTxs ( ) != null && sl . getItTxs ( ) . size ( ) > 0 ) { for ( CuOrSrTxLn 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 < CustOrderSrvLn > ( ) ; } 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 ( CustOrderSrvLn sl : delsSr ) { co . getServs ( ) . remove ( sl ) ; } } List < CustOrderTxLn > delsTx = null ; BigDecimal totTx = BigDecimal . ZERO ; for ( CartTxLn ctl : pCart . getTaxes ( ) ) { if ( ctl . getDisab ( ) || ctl . getSeller ( ) != null ) { continue ; } CustOrderTxLn otl = null ; if ( ! co . getIsNew ( ) ) { for ( CustOrderTxLn otlt : co . getTaxes ( ) ) { if ( otlt . getTax ( ) == null ) { otl = otlt ; break ; } } } if ( otl == null ) { otl = new CustOrderTxLn ( ) ; 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 ( ) ) { for ( CustOrderTxLn otlt : co . getTaxes ( ) ) { if ( otlt . getTax ( ) == null ) { getSrvOrm ( ) . deleteEntity ( pRqVs , otlt ) ; if ( delsTx == null ) { delsTx = new ArrayList < CustOrderTxLn > ( ) ; } delsTx . add ( otlt ) ; } } } if ( delsTx != null ) { for ( CustOrderTxLn tl : delsTx ) { co . getTaxes ( ) . remove ( tl ) ; } } co . setTot ( tot ) ; co . setSubt ( subt ) ; co . setTotTx ( totTx ) ; getSrvOrm ( ) . updateEntity ( pRqVs , co ) ; } if ( dels != null ) { for ( CustOrder co : dels ) { pPur . getOrds ( ) . remove ( co ) ; } } }
<p>Saves orders.</p>
@param pRqVs request scoped vars
@param pPur purchase
@param pCart cart
@throws Exception - an exception