@Override
  public final void makeOtherEntries(final Map<String, Object> pReqVars,
    final PurchaseInvoice pEntity, final IRequestData pRequestData,
      final boolean pIsNew) throws Exception {
    String actionAdd = pRequestData.getParameter("actionAdd");
    if ("makeAccEntries".equals(actionAdd)) {
      if (pEntity.getReversedId() != null) {
        //reverse none-reversed lines:
        PurchaseInvoiceLine pil = new PurchaseInvoiceLine();
        PurchaseInvoice reversed = new PurchaseInvoice();
        reversed.setItsId(pEntity.getReversedId());
        pil.setItsOwner(reversed);
        List<PurchaseInvoiceLine> reversedLines = getSrvOrm().
          retrieveListForField(pReqVars, pil, "itsOwner");
        String langDef = (String) pReqVars.get("langDef");
        for (PurchaseInvoiceLine reversedLine : reversedLines) {
          if (reversedLine.getReversedId() == null) {
            if (!reversedLine.getItsQuantity()
              .equals(reversedLine.getTheRest())) {
              throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
                "where_is_withdrawals_from_this_source");
            }
            PurchaseInvoiceLine reversingLine = new PurchaseInvoiceLine();
            reversingLine.setIdDatabaseBirth(getSrvOrm().getIdDatabase());
            reversingLine.setReversedId(reversedLine.getItsId());
            reversingLine.setWarehouseSite(reversedLine.getWarehouseSite());
            reversingLine.setInvItem(reversedLine.getInvItem());
            reversingLine.setUnitOfMeasure(reversedLine.getUnitOfMeasure());
            reversingLine.setItsCost(reversedLine.getItsCost());
            reversingLine.setItsQuantity(reversedLine.getItsQuantity()
              .negate());
            reversingLine.setItsTotal(reversedLine.getItsTotal().negate());
            reversingLine.setSubtotal(reversedLine.getSubtotal().negate());
            reversingLine.setTotalTaxes(reversedLine.getTotalTaxes().negate());
            reversingLine.setTaxesDescription(reversedLine
              .getTaxesDescription());
            reversingLine.setForeignPrice(reversedLine.getForeignPrice());
            reversingLine.setForeignSubtotal(reversedLine.getForeignSubtotal()
              .negate());
            reversingLine.setForeignTotalTaxes(reversedLine
              .getForeignTotalTaxes().negate());
            reversingLine.setForeignTotal(reversedLine.getForeignTotal()
              .negate());
            reversingLine.setIsNew(true);
            reversingLine.setItsOwner(pEntity);
            reversingLine.setDescription(getSrvI18n()
              .getMsg("reversed_entry_n", langDef) + reversedLine
                .getIdDatabaseBirth() + "-" + reversedLine.getItsId()); //local
            getSrvOrm().insertEntity(pReqVars, reversingLine);
            reversingLine.setIsNew(false);
            getSrvWarehouseEntry().load(pReqVars, reversingLine,
              reversingLine.getWarehouseSite());
            String descr;
            if (reversedLine.getDescription() == null) {
              descr = "";
            } else {
              descr = reversedLine.getDescription();
            }
            reversedLine.setDescription(descr + " " + getSrvI18n().getMsg(
              "reversing_entry_n", langDef) + reversingLine.getIdDatabaseBirth()
                + "-" + reversingLine.getItsId()); //only local
            reversedLine.setReversedId(reversingLine.getItsId());
            reversedLine.setTheRest(BigDecimal.ZERO);
            getSrvOrm().updateEntity(pReqVars, reversedLine);
            PurchaseInvoiceGoodsTaxLine pigtlt =
              new PurchaseInvoiceGoodsTaxLine();
            pigtlt.setItsOwner(reversedLine);
            List<PurchaseInvoiceGoodsTaxLine> tls = getSrvOrm()
              .retrieveListForField(pReqVars, pigtlt, "itsOwner");
            for (PurchaseInvoiceGoodsTaxLine pigtl : tls) {
              getSrvOrm().deleteEntity(pReqVars, pigtl);
            }
          }
        }
        PurchaseInvoiceServiceLine pisl = new PurchaseInvoiceServiceLine();
        pisl.setItsOwner(reversed);
        List<PurchaseInvoiceServiceLine> revServLines = getSrvOrm().
          retrieveListForField(pReqVars, pisl, "itsOwner");
        for (PurchaseInvoiceServiceLine reversedLine : revServLines) {
          if (reversedLine.getReversedId() == null) {
            PurchaseInvoiceServiceLine reversingLine =
              new PurchaseInvoiceServiceLine();
            reversingLine.setIdDatabaseBirth(getSrvOrm().getIdDatabase());
            reversingLine.setReversedId(reversedLine.getItsId());
            reversingLine.setService(reversedLine.getService());
            reversingLine.setAccExpense(reversedLine.getAccExpense());
            reversingLine.setItsCost(reversedLine.getItsCost().negate());
            reversingLine.setUnitOfMeasure(reversedLine.getUnitOfMeasure());
            reversingLine.setItsCost(reversedLine.getItsCost());
            reversingLine.setItsQuantity(reversedLine.getItsQuantity()
              .negate());
            reversingLine.setItsTotal(reversedLine.getItsTotal().negate());
            reversingLine.setSubtotal(reversedLine.getSubtotal().negate());
            reversingLine.setTotalTaxes(reversedLine.getTotalTaxes().negate());
            reversingLine.setTaxesDescription(reversedLine
              .getTaxesDescription());
            reversingLine.setForeignPrice(reversedLine.getForeignPrice());
            reversingLine.setForeignSubtotal(reversedLine.getForeignSubtotal()
              .negate());
            reversingLine.setForeignTotalTaxes(reversedLine
              .getForeignTotalTaxes().negate());
            reversingLine.setForeignTotal(reversedLine.getForeignTotal()
              .negate());
            reversingLine.setIsNew(true);
            reversingLine.setItsOwner(pEntity);
            getSrvOrm().insertEntity(pReqVars, reversingLine);
            reversingLine.setIsNew(false);
            reversedLine.setReversedId(reversingLine.getItsId());
            getSrvOrm().updateEntity(pReqVars, reversedLine);
            PurchaseInvoiceServiceTaxLine pigtlt =
              new PurchaseInvoiceServiceTaxLine();
            pigtlt.setItsOwner(reversedLine);
            List<PurchaseInvoiceServiceTaxLine> tls = getSrvOrm()
              .retrieveListForField(pReqVars, pigtlt, "itsOwner");
            for (PurchaseInvoiceServiceTaxLine pigtl : tls) {
              getSrvOrm().deleteEntity(pReqVars, pigtl);
            }
          }
        }
        PurchaseInvoiceTaxLine pitl = new PurchaseInvoiceTaxLine();
        pitl.setItsOwner(reversed);
        List<PurchaseInvoiceTaxLine> reversedTaxLines = getSrvOrm().
          retrieveListForField(pReqVars, pitl, "itsOwner");
        for (PurchaseInvoiceTaxLine reversedLine : reversedTaxLines) {
          if (reversedLine.getReversedId() == null) {
            PurchaseInvoiceTaxLine reversingLine = new PurchaseInvoiceTaxLine();
            reversingLine.setIdDatabaseBirth(getSrvOrm().getIdDatabase());
            reversingLine.setReversedId(reversedLine.getItsId());
            reversingLine.setItsTotal(reversedLine.getItsTotal().negate());
            reversingLine.setForeignTotalTaxes(reversedLine
              .getForeignTotalTaxes().negate());
            reversingLine.setTax(reversedLine.getTax());
            reversingLine.setIsNew(true);
            reversingLine.setItsOwner(pEntity);
            getSrvOrm().insertEntity(pReqVars, reversingLine);
            reversingLine.setIsNew(false);
            reversedLine.setReversedId(reversingLine.getItsId());
            getSrvOrm().updateEntity(pReqVars, reversedLine);
          }
        }
      }
      if (pEntity.getPrepaymentTo() != null) {
        if (pEntity.getReversedId() != null) {
          pEntity.getPrepaymentTo().setPurchaseInvoiceId(null);
        } else {
          pEntity.getPrepaymentTo().setPurchaseInvoiceId(pEntity.getItsId());
        }
        getSrvOrm().updateEntity(pReqVars, pEntity.getPrepaymentTo());
      }
    }
  }
@ Override public final void makeOtherEntries ( final Map < String , Object > pReqVars , final PurchaseInvoice pEntity , final IRequestData pRequestData , final boolean pIsNew ) throws Exception { String actionAdd = pRequestData . getParameter ( "actionAdd" ) ; if ( "makeAccEntries" . equals ( actionAdd ) ) { if ( pEntity . getReversedId ( ) != null ) { PurchaseInvoiceLine pil = new PurchaseInvoiceLine ( ) ; PurchaseInvoice reversed = new PurchaseInvoice ( ) ; reversed . setItsId ( pEntity . getReversedId ( ) ) ; pil . setItsOwner ( reversed ) ; List < PurchaseInvoiceLine > reversedLines = getSrvOrm ( ) . retrieveListForField ( pReqVars , pil , "itsOwner" ) ; String langDef = ( String ) pReqVars . get ( "langDef" ) ; for ( PurchaseInvoiceLine reversedLine : reversedLines ) { if ( reversedLine . getReversedId ( ) == null ) { if ( ! reversedLine . getItsQuantity ( ) . equals ( reversedLine . getTheRest ( ) ) ) { throw new ExceptionWithCode ( ExceptionWithCode . WRONG_PARAMETER , "where_is_withdrawals_from_this_source" ) ; } PurchaseInvoiceLine reversingLine = new PurchaseInvoiceLine ( ) ; reversingLine . setIdDatabaseBirth ( getSrvOrm ( ) . getIdDatabase ( ) ) ; reversingLine . setReversedId ( reversedLine . getItsId ( ) ) ; reversingLine . setWarehouseSite ( reversedLine . getWarehouseSite ( ) ) ; reversingLine . setInvItem ( reversedLine . getInvItem ( ) ) ; reversingLine . setUnitOfMeasure ( reversedLine . getUnitOfMeasure ( ) ) ; reversingLine . setItsCost ( reversedLine . getItsCost ( ) ) ; reversingLine . setItsQuantity ( reversedLine . getItsQuantity ( ) . negate ( ) ) ; reversingLine . setItsTotal ( reversedLine . getItsTotal ( ) . negate ( ) ) ; reversingLine . setSubtotal ( reversedLine . getSubtotal ( ) . negate ( ) ) ; reversingLine . setTotalTaxes ( reversedLine . getTotalTaxes ( ) . negate ( ) ) ; reversingLine . setTaxesDescription ( reversedLine . getTaxesDescription ( ) ) ; reversingLine . setForeignPrice ( reversedLine . getForeignPrice ( ) ) ; reversingLine . setForeignSubtotal ( reversedLine . getForeignSubtotal ( ) . negate ( ) ) ; reversingLine . setForeignTotalTaxes ( reversedLine . getForeignTotalTaxes ( ) . negate ( ) ) ; reversingLine . setForeignTotal ( reversedLine . getForeignTotal ( ) . negate ( ) ) ; reversingLine . setIsNew ( true ) ; reversingLine . setItsOwner ( pEntity ) ; reversingLine . setDescription ( getSrvI18n ( ) . getMsg ( "reversed_entry_n" , langDef ) + reversedLine . getIdDatabaseBirth ( ) + "-" + reversedLine . getItsId ( ) ) ; getSrvOrm ( ) . insertEntity ( pReqVars , reversingLine ) ; reversingLine . setIsNew ( false ) ; getSrvWarehouseEntry ( ) . load ( pReqVars , reversingLine , reversingLine . getWarehouseSite ( ) ) ; String descr ; if ( reversedLine . getDescription ( ) == null ) { descr = "" ; } else { descr = reversedLine . getDescription ( ) ; } reversedLine . setDescription ( descr + " " + getSrvI18n ( ) . getMsg ( "reversing_entry_n" , langDef ) + reversingLine . getIdDatabaseBirth ( ) + "-" + reversingLine . getItsId ( ) ) ; reversedLine . setReversedId ( reversingLine . getItsId ( ) ) ; reversedLine . setTheRest ( BigDecimal . ZERO ) ; getSrvOrm ( ) . updateEntity ( pReqVars , reversedLine ) ; PurchaseInvoiceGoodsTaxLine pigtlt = new PurchaseInvoiceGoodsTaxLine ( ) ; pigtlt . setItsOwner ( reversedLine ) ; List < PurchaseInvoiceGoodsTaxLine > tls = getSrvOrm ( ) . retrieveListForField ( pReqVars , pigtlt , "itsOwner" ) ; for ( PurchaseInvoiceGoodsTaxLine pigtl : tls ) { getSrvOrm ( ) . deleteEntity ( pReqVars , pigtl ) ; } } } PurchaseInvoiceServiceLine pisl = new PurchaseInvoiceServiceLine ( ) ; pisl . setItsOwner ( reversed ) ; List < PurchaseInvoiceServiceLine > revServLines = getSrvOrm ( ) . retrieveListForField ( pReqVars , pisl , "itsOwner" ) ; for ( PurchaseInvoiceServiceLine reversedLine : revServLines ) { if ( reversedLine . getReversedId ( ) == null ) { PurchaseInvoiceServiceLine reversingLine = new PurchaseInvoiceServiceLine ( ) ; reversingLine . setIdDatabaseBirth ( getSrvOrm ( ) . getIdDatabase ( ) ) ; reversingLine . setReversedId ( reversedLine . getItsId ( ) ) ; reversingLine . setService ( reversedLine . getService ( ) ) ; reversingLine . setAccExpense ( reversedLine . getAccExpense ( ) ) ; reversingLine . setItsCost ( reversedLine . getItsCost ( ) . negate ( ) ) ; reversingLine . setUnitOfMeasure ( reversedLine . getUnitOfMeasure ( ) ) ; reversingLine . setItsCost ( reversedLine . getItsCost ( ) ) ; reversingLine . setItsQuantity ( reversedLine . getItsQuantity ( ) . negate ( ) ) ; reversingLine . setItsTotal ( reversedLine . getItsTotal ( ) . negate ( ) ) ; reversingLine . setSubtotal ( reversedLine . getSubtotal ( ) . negate ( ) ) ; reversingLine . setTotalTaxes ( reversedLine . getTotalTaxes ( ) . negate ( ) ) ; reversingLine . setTaxesDescription ( reversedLine . getTaxesDescription ( ) ) ; reversingLine . setForeignPrice ( reversedLine . getForeignPrice ( ) ) ; reversingLine . setForeignSubtotal ( reversedLine . getForeignSubtotal ( ) . negate ( ) ) ; reversingLine . setForeignTotalTaxes ( reversedLine . getForeignTotalTaxes ( ) . negate ( ) ) ; reversingLine . setForeignTotal ( reversedLine . getForeignTotal ( ) . negate ( ) ) ; reversingLine . setIsNew ( true ) ; reversingLine . setItsOwner ( pEntity ) ; getSrvOrm ( ) . insertEntity ( pReqVars , reversingLine ) ; reversingLine . setIsNew ( false ) ; reversedLine . setReversedId ( reversingLine . getItsId ( ) ) ; getSrvOrm ( ) . updateEntity ( pReqVars , reversedLine ) ; PurchaseInvoiceServiceTaxLine pigtlt = new PurchaseInvoiceServiceTaxLine ( ) ; pigtlt . setItsOwner ( reversedLine ) ; List < PurchaseInvoiceServiceTaxLine > tls = getSrvOrm ( ) . retrieveListForField ( pReqVars , pigtlt , "itsOwner" ) ; for ( PurchaseInvoiceServiceTaxLine pigtl : tls ) { getSrvOrm ( ) . deleteEntity ( pReqVars , pigtl ) ; } } } PurchaseInvoiceTaxLine pitl = new PurchaseInvoiceTaxLine ( ) ; pitl . setItsOwner ( reversed ) ; List < PurchaseInvoiceTaxLine > reversedTaxLines = getSrvOrm ( ) . retrieveListForField ( pReqVars , pitl , "itsOwner" ) ; for ( PurchaseInvoiceTaxLine reversedLine : reversedTaxLines ) { if ( reversedLine . getReversedId ( ) == null ) { PurchaseInvoiceTaxLine reversingLine = new PurchaseInvoiceTaxLine ( ) ; reversingLine . setIdDatabaseBirth ( getSrvOrm ( ) . getIdDatabase ( ) ) ; reversingLine . setReversedId ( reversedLine . getItsId ( ) ) ; reversingLine . setItsTotal ( reversedLine . getItsTotal ( ) . negate ( ) ) ; reversingLine . setForeignTotalTaxes ( reversedLine . getForeignTotalTaxes ( ) . negate ( ) ) ; reversingLine . setTax ( reversedLine . getTax ( ) ) ; reversingLine . setIsNew ( true ) ; reversingLine . setItsOwner ( pEntity ) ; getSrvOrm ( ) . insertEntity ( pReqVars , reversingLine ) ; reversingLine . setIsNew ( false ) ; reversedLine . setReversedId ( reversingLine . getItsId ( ) ) ; getSrvOrm ( ) . updateEntity ( pReqVars , reversedLine ) ; } } } if ( pEntity . getPrepaymentTo ( ) != null ) { if ( pEntity . getReversedId ( ) != null ) { pEntity . getPrepaymentTo ( ) . setPurchaseInvoiceId ( null ) ; } else { pEntity . getPrepaymentTo ( ) . setPurchaseInvoiceId ( pEntity . getItsId ( ) ) ; } getSrvOrm ( ) . updateEntity ( pReqVars , pEntity . getPrepaymentTo ( ) ) ; } } }
<p>Make other entries include reversing if it's need when save.</p>
@param pReqVars additional param
@param pEntity entity
@param pRequestData Request Data
@param pIsNew if entity was new
@throws Exception - an exception