/** * <p>Get Owner Type if exist e.g. PurchaseInvoice 1.</p> * @return Integer **/ @Override public final Integer getOwnerType() { return new SalesInvoice().constTypeCode(); }
public final void makeFirstPrepareForSave(final Map<String, Object> pAddParam, final SalesInvoice pEntity) throws Exception { if (pEntity.getPrepaymentFrom() != null) { pEntity.setPrepaymentFrom(getSrvOrm().retrieveEntity(pEntity .getPrepaymentFrom())); if (pEntity.getReversedId() == null && pEntity.getPrepaymentFrom() .getSalesInvoiceId() != null && !pEntity.getHasMadeAccEntries()) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "prepayment_already_in_use"); if (pEntity.getReversedId() == null && !pEntity.getPrepaymentFrom() .getCustomer().getItsId().equals(pEntity.getCustomer().getItsId())) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "prepayment_for_different_vendor"); if (pEntity.getReversedId() != null && pEntity.getPrepaymentFrom() != null && pEntity.getPaymentTotal().compareTo(pEntity.getPrepaymentFrom() .getItsTotal()) != 0) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "reverse_payments_first"); if (pEntity.getReversedId() != null && pEntity.getPrepaymentFrom() == null && pEntity.getPaymentTotal().compareTo(BigDecimal.ZERO) != 0) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "reverse_payments_first"); if (pEntity.getReversedId() == null) { calculateTotalPayment(pEntity);
/** * <p>Get for document Date.</p> * @return Date **/ @Override public final Date getDocumentDate() { return this.getItsOwner().getItsDate(); }
/** * <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 SalesInvoice pEntity) throws Exception { pEntity.setTotalTaxes(BigDecimal.ZERO); pEntity.setSubtotal(BigDecimal.ZERO); if (pEntity.getReversedId() == null) { pEntity.setPaymentTotal(BigDecimal.ZERO); pEntity.setPaymentDescription(""); } }
/** * <p>Create entity.</p> * @param pAddParam additional param * @return entity instance * @throws Exception - an exception **/ @Override public final SalesInvoice createEntity( final Map<String, Object> pAddParam) throws Exception { SalesInvoice entity = new SalesInvoice(); entity.setIdDatabaseBirth(getSrvOrm().getIdDatabase()); entity.setItsDate(new Date()); entity.setIsNew(true); addAccSettingsIntoAttrs(pAddParam); return entity; }
updateTaxLines(pReqVars, pItsOwner); String query = lazyGetQuerySalesInvoiceTotals(); 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(
!lang.equals(langDef)); boolean isInvoiceBasis = false; for (SalesInvoiceTaxLine itl : inv.getTaxesLines()) { if (itl.getTaxableInvBas().compareTo(BigDecimal.ZERO) == 1) { isInvoiceBasis = true; if (inv.getForeignCurrency() != null) { currency = inv.getForeignCurrency(); } else { currency = accSet.getCurrency(); if (inv.getPriceIncTax()) { priceName = "priceIncTax"; } else { DocTable<WI> tblTitle = docMaker.addDocTableNoBorder(doc, 1, 1); String invNum; if (inv.getIdBirth() != null) { invNum = inv.getIdDatabaseBirth().toString() + "-" + inv.getIdBirth(); } else { invNum = inv.getIdDatabaseBirth().toString() + "-" + inv.getItsId(); + dateFormat.format(inv.getItsDate()); tblTitle.getItsCells().get(0).setItsContent(title); tblTitle.getItsCells().get(0).setFontNumber(1); if (!lang.equals(langDef)) {
String actionAdd = pRequestData.getParameter("actionAdd"); if ("makeAccEntries".equals(actionAdd)) { if (pEntity.getReversedId() != null) { SalesInvoice reversed = new SalesInvoice(); pEntity.setForeignCurrency(reversed.getForeignCurrency()); pEntity.setForeignSubtotal(reversed.getForeignSubtotal().negate()); pEntity.setForeignTotalTaxes(reversed.getForeignTotalTaxes().negate()); pEntity.setForeignTotal(reversed.getForeignTotal().negate()); reversed.setItsId(pEntity.getReversedId()); sil.setItsOwner(reversed); List<SalesInvoiceLine> reversedLines = getSrvOrm(). getSrvWarehouseEntry().reverseDraw(pReqVars, reversingLine); getSrvCogsEntry().reverseDraw(pReqVars, reversingLine, pEntity.getItsDate(), pEntity.getItsId()); String descr; if (reversedLine.getDescription() == null) { if (pEntity.getPrepaymentFrom() != null) { if (pEntity.getReversedId() != null) { pEntity.getPrepaymentFrom().setSalesInvoiceId(null); } else { pEntity.getPrepaymentFrom().setSalesInvoiceId(pEntity.getItsId()); getSrvOrm().updateEntity(pReqVars, pEntity.getPrepaymentFrom());
DateFormat dateFormat = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.SHORT, new Locale(langDef)); if (pEntity.getPrepaymentFrom() != null) { if (pEntity.getForeignCurrency() != null) { pEntity.setPaymentTotal(pEntity.getPrepaymentFrom().getForeignTotal()); } else { pEntity.setPaymentTotal(pEntity.getPrepaymentFrom().getItsTotal()); pEntity.setPaymentDescription(getSrvI18n().getMsg(PrepaymentFrom .class.getSimpleName() + "short", langDef) + " #" + pEntity .getPrepaymentFrom().getIdDatabaseBirth() + "-" + pEntity.getPrepaymentFrom() .getItsId() + ", " + dateFormat.format(pEntity.getPrepaymentFrom() .getItsDate()) + ", " + pEntity.getPaymentTotal()); } else { pEntity.setPaymentTotal(BigDecimal.ZERO); pEntity.setPaymentDescription(""); if (!pEntity.getIsNew()) { List<PaymentFrom> payments = getSrvOrm() .retrieveListWithConditions(pReqVars, PaymentFrom.class, "where PAYMENTFROM.HASMADEACCENTRIES=1 and PAYMENTFROM.REVERSEDID" + " is null and SALESINVOICE=" + pEntity.getItsId()); for (PaymentFrom payment : payments) { if (pEntity.getForeignCurrency() != null) { pEntity.setPaymentTotal(pEntity.getPaymentTotal() .add(payment.getForeignTotal())); } else { pEntity.setPaymentTotal(pEntity.getPaymentTotal() .add(payment.getItsTotal()));
.retrieveEntity(pReqVars, pEntity.getService())); boolean isTaxable = as.getIsExtractSalesTaxFromSales() && !pEntity .getItsOwner().getOmitTaxes() && !pEntity.getItsOwner().getCustomer() .getIsForeigner(); if (pEntity.getItsOwner().getForeignCurrency() != null) { pEntity.setItsPrice(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().getCustomer().getTaxDestination() != null) { isItemBasis = !pEntity.getItsOwner().getCustomer() .getTaxDestination().getSalTaxIsInvoiceBase(); isAggrOnlyRate = pEntity.getItsOwner().getCustomer() .getTaxDestination().getSalTaxUseAggregItBas(); rm = pEntity.getItsOwner().getCustomer() .getTaxDestination().getSalTaxRoundMode(); pReqVars.put("DestTaxServSelLnitsOwnerdeepLevel", 1);
if (pEntity.getPrepaymentFrom() != null) { pEntity.setPaymentTotal(pEntity.getPrepaymentFrom().getItsTotal()); pEntity.setPaymentDescription(getSrvI18n().getMsg(PrepaymentFrom .class.getSimpleName() + "short") + " #" + pEntity.getPrepaymentFrom() .getIdDatabaseBirth() + "-" + pEntity.getPrepaymentFrom().getItsId() + ", " + getDateFormatter().format(pEntity.getPrepaymentFrom() .getItsDate()) + ", " + pEntity.getPaymentTotal()); } else { pEntity.setPaymentTotal(BigDecimal.ZERO); pEntity.setPaymentDescription(""); + " is null and SALESINVOICE=" + pEntity.getItsId()); for (PaymentFrom payment : payments) { pEntity.setPaymentTotal(pEntity.getPaymentTotal() .add(payment.getItsTotal())); pEntity.setPaymentDescription(pEntity.getPaymentDescription() + " " + getSrvI18n().getMsg(PaymentFrom.class.getSimpleName() + "short") + " #" + payment.getIdDatabaseBirth() + "-" + payment.getItsId()
final SalesInvoice pItsOwner) throws Exception { String query = lazyGetQuerySalesInvoiceTotals(); 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() .getIsExtractSalesTaxFromSales()) { updateTaxLines(pItsOwner.getItsId());
List<SalesInvoiceTaxLine> itls = getSrvOrm().retrieveListWithConditions( pReqVars, SalesInvoiceTaxLine.class, "where ITSOWNER=" + pItsOwner.getItsId()); pReqVars.remove("SalesInvoiceTaxLineitsOwnerdeepLevel"); boolean isShowDebug = getLogger().getIsShowDebugMessagesFor(getClass()); AccSettings as = getSrvAccSettings().lazyGetAccSettings(pReqVars); boolean isTaxable = as.getIsExtractSalesTaxFromSales() && !pItsOwner .getOmitTaxes() && !pItsOwner.getCustomer().getIsForeigner(); if (isTaxable) { boolean isItemBasis = !as.getSalTaxIsInvoiceBase(); boolean isAggrOnlyRate = as.getSalTaxUseAggregItBas(); RoundingMode rm = as.getSalTaxRoundMode(); if (pItsOwner.getCustomer().getTaxDestination() != null) { isItemBasis = !pItsOwner.getCustomer() .getTaxDestination().getSalTaxIsInvoiceBase(); isAggrOnlyRate = pItsOwner.getCustomer() .getTaxDestination().getSalTaxUseAggregItBas(); rm = pItsOwner.getCustomer() .getTaxDestination().getSalTaxRoundMode(); if (pItsOwner.getPriceIncTax() && !isAggrOnlyRate) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "price_inc_tax_multi_not_imp"); getLogger().debug(null, UtlSalesGoodsServiceLine.class, "Updating tax lines for invoice #/date/isItemBasis/isAggrOnlyRate/rm: " + pItsOwner.getItsId() + "/" + pItsOwner.getItsDate() + "/"
if (parameterMap.get("actionAdd") != null && "makeAccEntries".equals(parameterMap.get("actionAdd")[0])) { if (pEntity.getReversedId() != null) { getSrvWarehouseEntry().reverseDraw(pAddParam, reversingLine); getSrvCogsEntry().reverseDraw(pAddParam, reversingLine, pEntity.getItsDate(), pEntity.getItsId()); String descr; if (reversedLine.getDescription() == null) { if (pEntity.getPrepaymentFrom() != null) { if (pEntity.getReversedId() != null) { pEntity.getPrepaymentFrom().setSalesInvoiceId(null); } else { pEntity.getPrepaymentFrom().setSalesInvoiceId(pEntity.getItsId()); getSrvOrm().updateEntity(pEntity.getPrepaymentFrom());
pReqVars.remove("DebtorCreditortaxDestinationdeepLevel"); pReqVars.remove("DebtorCreditorneededFields"); if (pEntity.getItsTotal().compareTo(BigDecimal.ZERO) == 1) { if (!pOldEntity.getCustomer().getItsId() .equals(pEntity.getCustomer().getItsId())) { pEntity.setCustomer(getSrvOrm() .retrieveEntity(pReqVars, pEntity.getCustomer())); if (pOldEntity.getCustomer().getTaxDestination() != null || pEntity.getCustomer().getTaxDestination() != null) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "can_not_cange_customer_with_another_tax_destination"); if (!pOldEntity.getOmitTaxes().equals(pEntity.getOmitTaxes()) || !pOldEntity.getPriceIncTax().equals(pEntity.getPriceIncTax())) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "can_not_change_tax_method");
/** * <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 SalesInvoiceLine createEntityWithOwnerById( final Map<String, Object> pAddParam, final Object pIdEntityItsOwner) throws Exception { SalesInvoiceLine entity = new SalesInvoiceLine(); entity.setIdDatabaseBirth(getSrvOrm().getIdDatabase()); entity.setIsNew(true); SalesInvoice itsOwner = new SalesInvoice(); itsOwner.setItsId(Long.valueOf(pIdEntityItsOwner.toString())); entity.setItsOwner(itsOwner); addAccSettingsIntoAttrs(pAddParam); return entity; }
/** * <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 PaymentFrom 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"); } SalesInvoice purchaseInvoice = getSrvOrm().retrieveEntity(pEntity .getSalesInvoice()); if (!purchaseInvoice.getHasMadeAccEntries() || purchaseInvoice.getReversedId() != null) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "purchase_invoice_must_be_accounted"); } pEntity.setSalesInvoice(purchaseInvoice); }
pReqVars.put("InvItemneededFields", ndFlItUm); pReqVars.put("UnitOfMeasureneededFields", ndFlItUm); inv.setItsLines(getSrvOrm().retrieveListByQuery(pReqVars, SalesInvoiceLine.class, evalSalesInvOverseaseLinesSql(inv.getItsId().toString(), pLang))); pReqVars.remove("SalesInvoiceLineneededFields"); pReqVars.remove("InvItemneededFields"); } else { pReqVars.put("SalesInvoiceLineitsOwnerdeepLevel", 1); //only ID inv.setItsLines(getSrvOrm(). retrieveListWithConditions(pReqVars, SalesInvoiceLine.class, "where REVERSEDID is null and ITSOWNER=" + inv.getItsId())); pReqVars.remove("SalesInvoiceLineitsOwnerdeepLevel"); sitl.setItsOwner(inv); pReqVars.put("SalesInvoiceTaxLineitsOwnerdeepLevel", 1); //only ID inv.setTaxesLines(getSrvOrm(). retrieveListForField(pReqVars, sitl, "itsOwner")); pReqVars.remove("SalesInvoiceTaxLineitsOwnerdeepLevel"); pReqVars.put("ServiceToSaleneededFields", ndFlItUm); pReqVars.put("UnitOfMeasureneededFields", ndFlItUm); inv.setServices(getSrvOrm().retrieveListByQuery(pReqVars, SalesInvoiceServiceLine.class, evalSalesInvOverseaseServiceLinesSql( inv.getItsId().toString(), pLang))); pReqVars.remove("SalesInvoiceServiceLineneededFields"); pReqVars.remove("ServiceToSaleneededFields");
/** * <p>Get for owner's ID.</p> * @return Long **/ @Override public final Long getOwnerId() { return this.getItsOwner().getItsId(); }
getSrvOrm().insertEntity(pEntity); SalesInvoice itsOwner = getSrvOrm().retrieveEntityById( SalesInvoice.class, pEntity.getItsOwner().getItsId()); pEntity.setItsOwner(itsOwner); if (pEntity.getReversedId() != null) { srvWarehouseEntry.reverseDraw(pAddParam, pEntity); srvCogsEntry.reverseDraw(pAddParam, pEntity, pEntity.getItsOwner().getItsDate(), pEntity.getItsOwner().getItsId()); } else { srvWarehouseEntry.withdrawal(pAddParam, pEntity, pEntity.getWarehouseSiteFo()); srvCogsEntry.withdrawal(pAddParam, pEntity, pEntity.getItsOwner().getItsDate(), pEntity.getItsOwner().getItsId());