/** * <p>Retrieve Accounting settings from database.</p> * @param pAddParam additional param * @throws Exception - an exception **/ public final synchronized void retrieveAccSettings( final Map<String, Object> pAddParam) throws Exception { this.accSettings = new AccSettings(); this.accSettings.setItsId(1L); this.accSettings = getSrvOrm().retrieveEntity(pAddParam, this.accSettings); if (this.accSettings == null) { throw new ExceptionWithCode(ExceptionWithCode.CONFIGURATION_MISTAKE, "There is no accounting settings!!!"); } DrawMaterialSourcesLine dmsl = new DrawMaterialSourcesLine(); dmsl.setItsOwner(this.accSettings); List<DrawMaterialSourcesLine> drawMaterialSources = getSrvOrm() .retrieveListForField(pAddParam, dmsl, "itsOwner"); this.accSettings.setDrawMaterialSources(drawMaterialSources); CogsItemSourcesLine cisl = new CogsItemSourcesLine(); cisl.setItsOwner(this.accSettings); List<CogsItemSourcesLine> cogsItemSources = getSrvOrm() .retrieveListForField(pAddParam, cisl, "itsOwner"); this.accSettings.setCogsItemSources(cogsItemSources); AccEntriesSourcesLine aesl = new AccEntriesSourcesLine(); aesl.setItsOwner(this.accSettings); List<AccEntriesSourcesLine> accEntriesSources = getSrvOrm() .retrieveListForField(pAddParam, aesl, "itsOwner"); this.accSettings.setAccEntriesSources(accEntriesSources); }
final IRequestData pRequestData) throws Exception { AccSettings as = srvAccSettings.lazyGetAccSettings(pReqVars); Boolean rSisUsePrecision0 = as.getPricePrecision() == 0 || as.getCostPrecision() == 0 || as.getBalancePrecision() == 0 || as.getQuantityPrecision() == 0 || as.getTaxPrecision() == 0; Boolean rSisUsePrecision1 = as.getPricePrecision() == 1 || as.getCostPrecision() == 1 || as.getBalancePrecision() == 1 || as.getQuantityPrecision() == 1 || as.getTaxPrecision() == 1; Boolean rSisUsePrecision2 = as.getPricePrecision() == 2 || as.getCostPrecision() == 2 || as.getBalancePrecision() == 2 || as.getQuantityPrecision() == 2 || as.getTaxPrecision() == 2; Boolean rSisUsePrecision3 = as.getPricePrecision() == 3 || as.getCostPrecision() == 3 || as.getBalancePrecision() == 3 || as.getQuantityPrecision() == 3 || as.getTaxPrecision() == 3; Boolean rSisUsePrecision4 = as.getPricePrecision() == 4 || as.getCostPrecision() == 4 || as.getBalancePrecision() == 4 || as.getQuantityPrecision() == 4 || as.getTaxPrecision() == 4; String rSmRound; if (as.getRoundingMode().equals(RoundingMode.HALF_UP)) { rSmRound = "S"; } else if (as.getRoundingMode().equals(RoundingMode.HALF_DOWN)) { rSmRound = "s"; } else if (as.getRoundingMode().equals(RoundingMode.UP)) { rSmRound = "U"; } else if (as.getRoundingMode().equals(RoundingMode.DOWN)) { rSmRound = "D"; } else if (as.getRoundingMode().equals(RoundingMode.HALF_EVEN)) { rSmRound = "B"; } else if (as.getRoundingMode().equals(RoundingMode.CEILING)) {
/** * <p>Get draw item sources.</p> * @return draw item sources * @throws Exception - an exception **/ @Override public final List<? extends ADrawItemSourcesLine> getDrawItemSources() throws Exception { return getSrvAccSettings().lazyGetAccSettings() .getCogsItemSources(); } }
/** * <p>Create entity.</p> * @param pAddParam additional param * @return entity instance * @throws Exception - an exception **/ @Override public final AccSettings createEntity( final Map<String, Object> pAddParam) throws Exception { AccSettings lAccSettings = new AccSettings(); lAccSettings.setIsNew(true); return lAccSettings; }
final Map<String, Object> pAddParam, final AccSettings pEntity) throws Exception { if (pEntity.getIsNew()) { throw new ExceptionWithCode(ExceptionWithCode.FORBIDDEN, "Attempt to insert accounting settings by " + pAddParam.get("user")); } else { if (pEntity.getCostPrecision() < 0 || pEntity.getCostPrecision() > 4) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "precision_must_be_from_0_to_4"); if (pEntity.getPricePrecision() < 0 || pEntity.getPricePrecision() > 4) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "precision_must_be_from_0_to_4"); if (pEntity.getQuantityPrecision() < 0 || pEntity.getQuantityPrecision() > 4) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "precision_must_be_from_0_to_4"); if (pEntity.getBalancePrecision() < 0 || pEntity.getBalancePrecision() > 4) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "precision_must_be_from_0_to_4");
pReqVars.remove("DebtorCreditorneededFields"); pReqVars.remove("DebtorCreditortaxDestinationdeepLevel"); boolean isTaxable = as.getIsExtractSalesTaxFromPurchase() && !pEntity .getItsOwner().getOmitTaxes() && !pEntity.getItsOwner().getVendor() .getIsForeigner(); pEntity.setTaxableInvBas(oldEntity.getTaxableInvBas()); pEntity.setTaxableInvBasFc(oldEntity.getTaxableInvBasFc()); boolean isItemBasis = !as.getSalTaxIsInvoiceBase(); RoundingMode rm = as.getSalTaxRoundMode(); if (pEntity.getItsOwner().getVendor().getTaxDestination() != null) { .getPricePrecision(), rm)); BigDecimal totalTaxes; BigDecimal bd100 = new BigDecimal("100.00"); totalTaxes = pEntity.getTaxableInvBas().subtract(pEntity .getTaxableInvBas().divide(BigDecimal.ONE.add(pEntity.getTax() .getItsPercentage().divide(bd100)), as.getPricePrecision(), rm)); } else { totalTaxes = pEntity.getTaxableInvBas().multiply(pEntity.getTax() .getItsPercentage()).divide(bd100, as.getPricePrecision(), rm);
.getQuantityPrecision(), getSrvAccSettings() .lazyGetAccSettings(pAddParam).getRoundingMode())); pEntity.setItsCost(pEntity.getItsTotal().divide( pEntity.getItsQuantity(), getSrvAccSettings() .lazyGetAccSettings(pAddParam).getCostPrecision(), getSrvAccSettings().lazyGetAccSettings(pAddParam).getRoundingMode()));
.lazyGetAccSettings().getCostPrecision(), getSrvAccSettings() .lazyGetAccSettings().getRoundingMode())); BigDecimal totalTaxes = BigDecimal.ZERO; String taxesDescription = ""; if (getSrvAccSettings().lazyGetAccSettings() .getIsExtractSalesTaxFromPurchase() && pEntity.getService().getTaxCategory() != null) { List<InvItemTaxCategoryLine> pstl = getSrvOrm() BigDecimal addTx = pEntity.getItsCost().multiply(pst .getItsPercentage()).divide(bigDecimal100, getSrvAccSettings() .lazyGetAccSettings().getPricePrecision(), getSrvAccSettings().lazyGetAccSettings().getRoundingMode()); totalTaxes = totalTaxes.add(addTx); if (i++ > 0) {
/** * <p>Insert immutable line into DB.</p> * @param pAddParam additional param * @param pEntity entity * @throws Exception - an exception **/ public final void updateOwner(final Map<String, Object> pAddParam, final AdditionCostLine pEntity) throws Exception { String query = "select sum(ITSTOTAL) as ITSTOTAL from" + " ADDITIONCOSTLINE where ITSOWNER=" + pEntity.getItsOwner().getItsId(); Double total = getSrvDatabase().evalDoubleResult(query, "ITSTOTAL"); pEntity.getItsOwner().setTotalAdditionCost(BigDecimal.valueOf(total) .setScale(getSrvAccSettings().lazyGetAccSettings(pAddParam).getCostPrecision(), getSrvAccSettings().lazyGetAccSettings(pAddParam).getRoundingMode())); pEntity.getItsOwner().setItsTotal(pEntity.getItsOwner() .getTotalMaterialsCost().add(pEntity.getItsOwner() .getTotalAdditionCost()).setScale(getSrvAccSettings() .lazyGetAccSettings(pAddParam).getCostPrecision(), getSrvAccSettings().lazyGetAccSettings(pAddParam).getRoundingMode())); pEntity.getItsOwner().setItsCost(pEntity.getItsOwner().getItsTotal() .divide(pEntity.getItsOwner().getItsQuantity(), getSrvAccSettings().lazyGetAccSettings(pAddParam).getCostPrecision(), getSrvAccSettings().lazyGetAccSettings(pAddParam).getRoundingMode())); getSrvOrm().updateEntity(pAddParam, pEntity.getItsOwner()); }
Calendar calCurrYear = Calendar.getInstance(new Locale("en", "US")); calCurrYear.setTime(getSrvAccSettings().lazyGetAccSettings(pAddParam) .getCurrentAccYear()); calCurrYear.set(Calendar.MONTH, 0); calCurrYear.set(Calendar.DAY_OF_MONTH, 1); .lazyGetAccSettings(pAddParam).getAccEntriesSources(); java.util.Collections.sort(sourcesLines, this.cmprAccSourcesByType); int i = 0; accEntry.setDebit(BigDecimal.valueOf(recordSet.getDouble("DEBIT")) .setScale(getSrvAccSettings().lazyGetAccSettings(pAddParam) .getCostPrecision(), getSrvAccSettings() .lazyGetAccSettings(pAddParam).getRoundingMode())); String accCreditId = recordSet.getString("ACCCREDIT"); Account accCredit = new Account(); .valueOf(recordSet.getDouble("CREDIT")).setScale( getSrvAccSettings().lazyGetAccSettings(pAddParam) .getCostPrecision(), getSrvAccSettings() .lazyGetAccSettings(pAddParam).getRoundingMode())); String docId = pEntity.getItsId().toString(); if (pEntity.getIdBirth() != null) {
getSrvAccSettings().lazyGetAccSettings().getQuantityPrecision(), getSrvAccSettings().lazyGetAccSettings().getRoundingMode())); pEntity.setSubtotal(pEntity.getItsQuantity().multiply(pEntity .getPurchaseInvoiceLine().getItsCost()).setScale(getSrvAccSettings() .lazyGetAccSettings().getPricePrecision(), getSrvAccSettings() .lazyGetAccSettings().getRoundingMode())); BigDecimal totalTaxes = BigDecimal.ZERO; if (getSrvAccSettings().lazyGetAccSettings() .getIsExtractSalesTaxFromPurchase()) { String taxesDescription = ""; if (pEntity.getPurchaseInvoiceLine().getInvItem() BigDecimal addTx = pEntity.getSubtotal().multiply(pst .getItsPercentage()).divide(bigDecimal100, getSrvAccSettings() .lazyGetAccSettings().getPricePrecision(), getSrvAccSettings().lazyGetAccSettings().getRoundingMode()); totalTaxes = totalTaxes.add(addTx); if (i++ > 0) { Double[] totals = getSrvDatabase().evalDoubleResults(query, columns); itsOwner.setSubtotal(BigDecimal.valueOf(totals[0]).setScale( getSrvAccSettings().lazyGetAccSettings().getPricePrecision(), getSrvAccSettings().lazyGetAccSettings().getRoundingMode())); itsOwner.setTotalTaxes(BigDecimal.valueOf(totals[1]).setScale( getSrvAccSettings().lazyGetAccSettings().getPricePrecision(), getSrvAccSettings().lazyGetAccSettings().getRoundingMode())); itsOwner.setItsTotal(itsOwner.getSubtotal(). add(itsOwner.getTotalTaxes()));
.lazyGetAccSettings(pAddParam); Calendar calCurrYear = Calendar.getInstance(new Locale("en", "US")); calCurrYear.setTime(accSettings.getCurrentAccYear()); calCurrYear.set(Calendar.MONTH, 0); calCurrYear.set(Calendar.DAY_OF_MONTH, 1); Double[] totals = getSrvDatabase().evalDoubleResults(query, columns); itsOwner.setTotalDebit(BigDecimal.valueOf(totals[0]).setScale( accSettings.getCostPrecision(), accSettings.getRoundingMode())); itsOwner.setTotalCredit(BigDecimal.valueOf(totals[1]).setScale( accSettings.getCostPrecision(), accSettings.getRoundingMode())); getSrvOrm().updateEntity(pAddParam, itsOwner); getSrvBalance().handleNewAccountEntry(pAddParam, null, null,
tbl.setDebit(BigDecimal.valueOf(debit).setScale( getSrvAccSettings().lazyGetAccSettings(pAddParam) .getBalancePrecision(), getSrvAccSettings() .lazyGetAccSettings(pAddParam).getRoundingMode())); tbl.setCredit(BigDecimal.valueOf(credit).setScale( getSrvAccSettings().lazyGetAccSettings(pAddParam) .getBalancePrecision(), getSrvAccSettings() .lazyGetAccSettings(pAddParam).getRoundingMode())); if (tbl.getDebit().doubleValue() != 0 || tbl.getCredit().doubleValue() != 0) {
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());
if (pItsOwner.getPriceIncTax()) { taxTot = ttl.getTotalTaxes().multiply(ilnt.get(i).getItsTotal()) .divide(ttl.getItsTotal(), pAs.getPricePrecision(), RoundingMode.HALF_UP); ilnt.get(i).setSubtotal(ilnt.get(i).getItsTotal().subtract(taxTot)); } else { taxTot = ttl.getTotalTaxes().multiply(ilnt.get(i).getSubtotal()) .divide(ttl.getSubtotal(), pAs.getPricePrecision(), RoundingMode.HALF_UP); ilnt.get(i).setItsTotal(ilnt.get(i).getSubtotal().add(taxTot)); PurchaseInvoiceLine pil = (PurchaseInvoiceLine) ilnt.get(i); pil.setItsCost(ilnt.get(i).getSubtotal().divide(ilnt.get(i) .getItsQuantity(), pAs.getCostPrecision(), pAs.getRoundingMode()));
getLogger().info(SrvBalanceStd.class, SrvBalanceStd.class.getSimpleName() + ": changing period from " + lazyGetBalanceAtAllDirtyCheck() .getBalanceStorePeriod() + " to " + pPeriod); lazyGetBalanceAtAllDirtyCheck().setBalanceStorePeriod(pPeriod); if (!getSrvAccSettings().lazyGetAccSettings() .getBalanceStorePeriod().equals(pPeriod)) { getSrvAccSettings().lazyGetAccSettings() .setBalanceStorePeriod(pPeriod); getSrvAccSettings().saveEntity(null, getSrvAccSettings() .lazyGetAccSettings(), false);
/** * <p>Get draw item sources.</p> * @return draw item sources * @throws Exception - an exception **/ @Override public final List<? extends ADrawItemSourcesLine> getDrawItemSources() throws Exception { return getSrvAccSettings().lazyGetAccSettings() .getDrawMaterialSources(); } }
/** * <p>Evaluate period of stored balances according settings, * if it's changed then it switch on "current balances are dirty".</p> * @return pPeriod EPeriod e.g. MONTHLY * @throws Exception - an exception **/ @Override public final synchronized EPeriod evalBalanceStorePeriod() throws Exception { if (!lazyGetBalanceAtAllDirtyCheck().getBalanceStorePeriod() .equals(getSrvAccSettings().lazyGetAccSettings() .getBalanceStorePeriod())) { getLogger().info(SrvBalanceStd.class, SrvBalanceStd.class.getSimpleName() + ": changing period from " + lazyGetBalanceAtAllDirtyCheck() .getBalanceStorePeriod() + " to " + getSrvAccSettings() .lazyGetAccSettings().getBalanceStorePeriod()); lazyGetBalanceAtAllDirtyCheck() .setBalanceStorePeriod(getSrvAccSettings().lazyGetAccSettings() .getBalanceStorePeriod()); lazyGetBalanceAtAllDirtyCheck().setIsPeriodChanged(true); lazyGetBalanceAtAllDirtyCheck() .setCurrentBalanceDate(new Date(157766400000L)); } return lazyGetBalanceAtAllDirtyCheck().getBalanceStorePeriod(); }
Calendar calCurrYear = Calendar.getInstance(new Locale("en", "US")); calCurrYear.setTime(getSrvAccSettings().lazyGetAccSettings(pAddParam) .getCurrentAccYear()); calCurrYear.set(Calendar.MONTH, 0); calCurrYear.set(Calendar.DAY_OF_MONTH, 1);
.lazyGetAccSettings(pAddParam).getCogsMethod().getFileName()); StringBuffer sb = new StringBuffer(); int i = 0;