/** * <p>Create entity.</p> * @param pAddParam additional param * @return entity instance * @throws Exception - an exception **/ @Override public final PurchaseInvoice createEntity( final Map<String, Object> pAddParam) throws Exception { PurchaseInvoice entity = new PurchaseInvoice(); entity.setIdDatabaseBirth(getSrvOrm().getIdDatabase()); entity.setItsDate(new Date()); entity.setIsNew(true); addAccSettingsIntoAttrs(pAddParam); return entity; }
/** * <p>Get Owner Type if exist e.g. PurchaseInvoice 1.</p> * @return Integer **/ @Override public final Integer getOwnerType() { return this.getItsOwner().constTypeCode(); }
public final void makeFirstPrepareForSave(final Map<String, Object> pAddParam, final PurchaseInvoice pEntity) throws Exception { if (pEntity.getPrepaymentTo() != null) { pEntity.setPrepaymentTo(getSrvOrm().retrieveEntity(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");
/** * <p>Make additional preparations on entity copy.</p> * @param pAddParam additional param * @param pEntity entity * @throws Exception - an exception **/ @Override public final void makeAddPrepareForCopy(final Map<String, Object> pAddParam, final PurchaseInvoice pEntity) throws Exception { pEntity.setTotalTaxes(BigDecimal.ZERO); pEntity.setSubtotal(BigDecimal.ZERO); if (pEntity.getReversedId() == null) { pEntity.setPaymentTotal(BigDecimal.ZERO); pEntity.setPaymentDescription(""); } }
final PurchaseInvoice pItsOwner) throws Exception { String query = lazyGetQueryPurchaseInvoiceTotals(); query = query.replace(":ITSOWNER", pItsOwner.getItsId().toString()); String[] columns = new String[] {"SUBTOTAL", "ITSTOTAL", "TOTALTAXES", "FOREIGNSUBTOTAL", "FOREIGNTOTAL", "FOREIGNTOTALTAXES"}; if (pItsOwner.getPriceIncTax()) { pItsOwner.setItsTotal(BigDecimal.valueOf(totals[1]).setScale( as.getPricePrecision(), as.getRoundingMode())); pItsOwner.setTotalTaxes(BigDecimal.valueOf(totals[2]).setScale( as.getPricePrecision(), as.getSalTaxRoundMode())); pItsOwner.setSubtotal(pItsOwner.getItsTotal(). subtract(pItsOwner.getTotalTaxes())); pItsOwner.setForeignTotal(BigDecimal.valueOf(totals[4]).setScale( as.getPricePrecision(), as.getRoundingMode())); pItsOwner.setForeignTotalTaxes(BigDecimal.valueOf(totals[5]).setScale( as.getPricePrecision(), as.getSalTaxRoundMode())); pItsOwner.setForeignSubtotal(pItsOwner.getForeignTotal(). subtract(pItsOwner.getForeignTotalTaxes())); } else { pItsOwner.setSubtotal(BigDecimal.valueOf(totals[0]).setScale( as.getPricePrecision(), as.getRoundingMode())); pItsOwner.setTotalTaxes(BigDecimal.valueOf(totals[2]).setScale( as.getPricePrecision(), as.getSalTaxRoundMode())); pItsOwner.setItsTotal(pItsOwner.getSubtotal(). add(pItsOwner.getTotalTaxes())); pItsOwner.setForeignSubtotal(BigDecimal.valueOf(totals[3]).setScale( as.getPricePrecision(), as.getRoundingMode())); pItsOwner.setForeignTotalTaxes(BigDecimal.valueOf(totals[5]).setScale(
DateFormat dateFormat = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.SHORT, new Locale(langDef)); if (pEntity.getPrepaymentTo() != null) { if (pEntity.getForeignCurrency() != null) { pEntity.setPaymentTotal(pEntity.getPrepaymentTo().getForeignTotal()); } else { pEntity.setPaymentTotal(pEntity.getPrepaymentTo().getItsTotal()); pEntity.setPaymentDescription(getSrvI18n().getMsg(PrepaymentTo .class.getSimpleName() + "short", langDef) + " #" + pEntity .getPrepaymentTo().getIdDatabaseBirth() + "-" + pEntity.getPrepaymentTo().getItsId() + ", " //local + dateFormat.format(pEntity.getPrepaymentTo().getItsDate()) + ", " + pEntity.getPaymentTotal()); } else { pEntity.setPaymentTotal(BigDecimal.ZERO); pEntity.setPaymentDescription(""); + " is null and PURCHASEINVOICE=" + pEntity.getItsId()); for (PaymentTo payment : payments) { if (pEntity.getForeignCurrency() != null) { pEntity.setPaymentTotal(pEntity.getPaymentTotal() .add(payment.getForeignTotal())); } else { pEntity.setPaymentTotal(pEntity.getPaymentTotal() .add(payment.getItsTotal())); pEntity.setPaymentDescription(pEntity.getPaymentDescription() + " " + getSrvI18n().getMsg(PaymentTo.class.getSimpleName() + "short", langDef)
final PurchaseInvoice pItsOwner) throws Exception { String query = lazyGetQueryPurchaseInvoiceTotals(); query = query.replace(":ITSOWNER", pItsOwner.getItsId().toString()); String[] columns = new String[]{"SUBTOTAL", "TOTALTAXES"}; Double[] totals = getSrvDatabase().evalDoubleResults(query, columns); totals[1] = 0d; pItsOwner.setSubtotal(BigDecimal.valueOf(totals[0]).setScale( getSrvAccSettings().lazyGetAccSettings().getPricePrecision(), getSrvAccSettings().lazyGetAccSettings().getRoundingMode())); pItsOwner.setTotalTaxes(BigDecimal.valueOf(totals[1]).setScale( getSrvAccSettings().lazyGetAccSettings().getPricePrecision(), getSrvAccSettings().lazyGetAccSettings().getRoundingMode())); pItsOwner.setItsTotal(pItsOwner.getSubtotal(). add(pItsOwner.getTotalTaxes())); getSrvOrm().updateEntity(pItsOwner); if (getSrvAccSettings().lazyGetAccSettings() .getIsExtractSalesTaxFromPurchase()) { updateTaxLines(pItsOwner.getItsId());
.retrieveEntity(pReqVars, pEntity.getService())); boolean isTaxable = as.getIsExtractSalesTaxFromPurchase() && !pEntity .getItsOwner().getOmitTaxes() && !pEntity.getItsOwner().getVendor() .getIsForeigner(); if (pEntity.getItsOwner().getForeignCurrency() != null) { pEntity.setItsCost(pEntity.getForeignPrice().multiply(pEntity .getItsOwner().getExchangeRate()).setScale(as .getPricePrecision(), as.getRoundingMode())); if (!isTaxable || pEntity.getItsOwner().getPriceIncTax()) { pEntity.setItsTotal(pEntity.getForeignTotal().multiply(pEntity .getItsOwner().getExchangeRate()).setScale(as .getPricePrecision(), as.getRoundingMode())); } else { pEntity.setSubtotal(pEntity.getForeignSubtotal().multiply(pEntity .getItsOwner().getExchangeRate()).setScale(as .getPricePrecision(), as.getRoundingMode())); pEntity.setTaxCategory(pEntity.getService().getTaxCategory()); RoundingMode rm = as.getSalTaxRoundMode(); if (pEntity.getItsOwner().getVendor().getTaxDestination() != null) { isItemBasis = !pEntity.getItsOwner().getVendor() .getTaxDestination().getSalTaxIsInvoiceBase(); isAggrOnlyRate = pEntity.getItsOwner().getVendor() .getTaxDestination().getSalTaxUseAggregItBas(); rm = pEntity.getItsOwner().getVendor() .getTaxDestination().getSalTaxRoundMode(); pReqVars.put("DestTaxServPurchLnitsOwnerdeepLevel", 1);
String actionAdd = pRequestData.getParameter("actionAdd"); if ("makeAccEntries".equals(actionAdd)) { if (pEntity.getReversedId() != null) { PurchaseInvoice reversed = new PurchaseInvoice(); reversed.setItsId(pEntity.getReversedId()); pil.setItsOwner(reversed); List<PurchaseInvoiceLine> reversedLines = getSrvOrm(). if (pEntity.getPrepaymentTo() != null) { if (pEntity.getReversedId() != null) { pEntity.getPrepaymentTo().setPurchaseInvoiceId(null); } else { pEntity.getPrepaymentTo().setPurchaseInvoiceId(pEntity.getItsId()); getSrvOrm().updateEntity(pReqVars, pEntity.getPrepaymentTo());
List<PurchaseInvoiceTaxLine> itls = getSrvOrm().retrieveListWithConditions( pReqVars, PurchaseInvoiceTaxLine.class, "where ITSOWNER=" + pItsOwner.getItsId()); pReqVars.remove("PurchaseInvoiceTaxLineitsOwnerdeepLevel"); boolean isShowDebug = getLogger().getIsShowDebugMessagesFor(getClass()); AccSettings as = getSrvAccSettings().lazyGetAccSettings(pReqVars); boolean isTaxable = as.getIsExtractSalesTaxFromPurchase() && !pItsOwner .getOmitTaxes() && !pItsOwner.getVendor().getIsForeigner(); if (isTaxable) { boolean isItemBasis = !as.getSalTaxIsInvoiceBase(); boolean isAggrOnlyRate = as.getSalTaxUseAggregItBas(); RoundingMode rm = as.getSalTaxRoundMode(); if (pItsOwner.getVendor().getTaxDestination() != null) { isItemBasis = !pItsOwner.getVendor() .getTaxDestination().getSalTaxIsInvoiceBase(); isAggrOnlyRate = pItsOwner.getVendor() .getTaxDestination().getSalTaxUseAggregItBas(); rm = pItsOwner.getVendor() .getTaxDestination().getSalTaxRoundMode(); if (pItsOwner.getPriceIncTax() && !isAggrOnlyRate) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "price_inc_tax_multi_not_imp"); getLogger().debug(null, UtlPurchaseGoodsServiceLine.class, "Updating tax lines for invoice #/date/isItemBasis/isAggrOnlyRate/rm: " + pItsOwner.getItsId() + "/" + pItsOwner.getItsDate() + "/"
/** * <p>Create entity with its itsOwner e.g. invoice line * for invoice.</p> * @param pAddParam additional param * @param pIdEntityItsOwner entity itsOwner ID * @return entity instance * @throws Exception - an exception **/ @Override public final PurchaseInvoiceLine createEntityWithOwnerById( final Map<String, Object> pAddParam, final Object pIdEntityItsOwner) throws Exception { PurchaseInvoiceLine entity = new PurchaseInvoiceLine(); entity.setIdDatabaseBirth(getSrvOrm().getIdDatabase()); entity.setIsNew(true); PurchaseInvoice itsOwner = new PurchaseInvoice(); itsOwner.setItsId(Long.valueOf(pIdEntityItsOwner.toString())); entity.setItsOwner(itsOwner); addAccSettingsIntoAttrs(pAddParam); return entity; }
if (parameterMap.get("actionAdd") != null && "makeAccEntries".equals(parameterMap.get("actionAdd")[0])) { if (pEntity.getReversedId() != null) { if (pEntity.getPrepaymentTo() != null) { if (pEntity.getReversedId() != null) { pEntity.getPrepaymentTo().setPurchaseInvoiceId(null); } else { pEntity.getPrepaymentTo().setPurchaseInvoiceId(pEntity.getItsId()); getSrvOrm().updateEntity(pEntity.getPrepaymentTo());
/** * <p>Make save preparations before insert/update block if it's need.</p> * @param pAddParam additional param * @param pEntity entity * @throws Exception - an exception **/ @Override public final void makeFirstPrepareForSave(final Map<String, Object> pAddParam, final PaymentTo pEntity) throws Exception { //BeigeORM refresh: pEntity.setAccCash(getSrvOrm() .retrieveEntity(pEntity.getAccCash())); if (pEntity.getAccCash().getSubaccType() != null && pEntity.getSubaccCashId() == null) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "select_subaccount"); } PurchaseInvoice purchaseInvoice = getSrvOrm().retrieveEntity(pEntity .getPurchaseInvoice()); if (!purchaseInvoice.getHasMadeAccEntries() || purchaseInvoice.getReversedId() != null) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "purchase_invoice_must_be_accounted"); } pEntity.setPurchaseInvoice(purchaseInvoice); }
typeCodeMap.put(new PurchaseInvoiceLine().constTypeCode(), PurchaseInvoiceLine.class); typeCodeMap.put(new PurchaseInvoice().constTypeCode(), PurchaseInvoice.class); typeCodeMap.put(new SalesInvoiceLine().constTypeCode(),
/** * <p>Get for owner's ID.</p> * @return Long **/ @Override public final Long getOwnerId() { return this.getItsOwner().getItsId(); }
.retrieveListWithConditions(pReqVars, PurchaseInvoiceServiceLine.class, "where PURCHASEINVOICESERVICELINE.TAXCATEGORY is not null and ITSOWNER=" + pItsOwner.getItsId()); pReqVars.remove("PurchaseInvoiceServiceLineitsOwnerdeepLevel"); pReqVars.put("PurchaseInvoiceLineitsOwnerdeepLevel", 1); pReqVars, PurchaseInvoiceLine.class, "where PURCHASEINVOICELINE.TAXCATEGORY is not null" + " and REVERSEDID is null and ITSOWNER=" + pItsOwner.getItsId()); pReqVars.remove("PurchaseInvoiceLineitsOwnerdeepLevel"); List<IInvoiceLine<?>> ilnt = new ArrayList<IInvoiceLine<?>>(); for (int i = 0; i < ilnt.size(); i++) { if (i + 1 == ilnt.size()) { if (pItsOwner.getPriceIncTax()) { ilnt.get(i).setSubtotal(ilnt.get(i).getItsTotal().subtract(txRest)); } else { } else { BigDecimal taxTot; if (pItsOwner.getPriceIncTax()) { taxTot = ttl.getTotalTaxes().multiply(ilnt.get(i).getItsTotal()) .divide(ttl.getItsTotal(), pAs.getPricePrecision(), RoundingMode.HALF_UP); if (pItsOwner.getPriceIncTax() && ilnt.get(i).getClass() == PurchaseInvoiceLine.class) { PurchaseInvoiceLine pil = (PurchaseInvoiceLine) ilnt.get(i);
/** * <p>Get for document Date.</p> * @return Date **/ @Override public final Date getDocumentDate() { return this.getItsOwner().getItsDate(); }
/** * <p>Create entity.</p> * @param pAddParam additional param * @return entity instance * @throws Exception - an exception **/ @Override public final PurchaseInvoiceLine createEntity( final Map<String, Object> pAddParam) throws Exception { PurchaseInvoiceLine entity = new PurchaseInvoiceLine(); entity.setIdDatabaseBirth(getSrvOrm().getIdDatabase()); entity.setIsNew(true); PurchaseInvoice itsOwner = new PurchaseInvoice(); entity.setItsOwner(itsOwner); addAccSettingsIntoAttrs(pAddParam); return entity; }
if (pEntity.getPrepaymentTo() != null) { pEntity.setPaymentTotal(pEntity.getPrepaymentTo().getItsTotal()); pEntity.setPaymentDescription(getSrvI18n().getMsg(PrepaymentTo .class.getSimpleName() + "short") + " #" + pEntity.getPrepaymentTo() .getIdDatabaseBirth() + "-" + pEntity.getPrepaymentTo().getItsId() + ", " //local + getDateFormatter().format(pEntity.getPrepaymentTo().getItsDate()) + ", " + pEntity.getPaymentTotal()); } else { pEntity.setPaymentTotal(BigDecimal.ZERO); pEntity.setPaymentDescription(""); + " is null and PURCHASEINVOICE=" + pEntity.getItsId()); for (PaymentTo payment : payments) { pEntity.setPaymentTotal(pEntity.getPaymentTotal() .add(payment.getItsTotal())); pEntity.setPaymentDescription(pEntity.getPaymentDescription() + " " + getSrvI18n().getMsg(PaymentTo.class.getSimpleName() + "short") + " #" + payment.getIdDatabaseBirth() + "-" + payment.getItsId()
pEntity.setTheRest(pEntity.getItsQuantity()); boolean isTaxable = as.getIsExtractSalesTaxFromPurchase() && !pEntity .getItsOwner().getOmitTaxes() && !pEntity.getItsOwner().getVendor() .getIsForeigner(); if (pEntity.getInvItem().getKnownCost() != null) { if (pEntity.getItsOwner().getForeignCurrency() != null) { pEntity.setForeignPrice(pEntity.getInvItem().getKnownCost()); if (!isTaxable || pEntity.getItsOwner().getPriceIncTax()) { pEntity.setForeignTotal(pEntity.getItsQuantity().multiply(pEntity .getForeignPrice()).setScale(as.getPricePrecision(), as.getRoundingMode())); .getItsOwner().getExchangeRate()).setScale(as .getPricePrecision(), as.getRoundingMode())); } else { pEntity.setItsCost(pEntity.getInvItem().getKnownCost()); if (!isTaxable || pEntity.getItsOwner().getPriceIncTax()) { pEntity.setItsTotal(pEntity.getItsQuantity().multiply(pEntity .getItsCost()).setScale(as.getPricePrecision(), as.getRoundingMode())); if (pEntity.getItsOwner().getForeignCurrency() != null) { pEntity.setItsCost(pEntity.getForeignPrice().multiply(pEntity .getItsOwner().getExchangeRate()).setScale(as .getPricePrecision(), as.getRoundingMode())); if (!isTaxable || pEntity.getItsOwner().getPriceIncTax()) { pEntity.setItsTotal(pEntity.getForeignTotal().multiply(pEntity .getItsOwner().getExchangeRate()).setScale(as .getPricePrecision(), as.getRoundingMode())); } else {