public IEditablePricingContext createPricingContext( I_C_InvoiceLine invoiceLine, final int priceListId, final BigDecimal priceQty) { final org.compiere.model.I_C_Invoice invoice = invoiceLine.getC_Invoice(); final boolean isSOTrx = invoice.isSOTrx(); final int productId = invoiceLine.getM_Product_ID(); int bPartnerId = invoice.getC_BPartner_ID(); final Timestamp date = invoice.getDateInvoiced(); final IEditablePricingContext pricingCtx = Services.get(IPricingBL.class) .createInitialContext( productId, bPartnerId, invoiceLine.getPrice_UOM_ID(), priceQty, isSOTrx); pricingCtx.setPriceDate(date); // 03152: setting the 'ol' to allow the subscription system to compute the right price pricingCtx.setReferencedObject(invoiceLine); pricingCtx.setM_PriceList_ID(priceListId); // PLV is only accurate if PL selected in header // metas: relay on M_PriceList_ID only, don't use M_PriceList_Version_ID // pricingCtx.setM_PriceList_Version_ID(orderLine.getM_PriceList_Version_ID()); return pricingCtx; }
private final I_C_TaxDeclarationLine createTaxDeclarationLine( final I_C_Invoice invoice, final I_C_InvoiceTax invoiceTax) { final I_C_TaxDeclarationLine taxDeclarationLine = newTaxDeclarationLine(); taxDeclarationLine.setAD_Org_ID(invoice.getAD_Org_ID()); taxDeclarationLine.setIsManual(false); // taxDeclarationLine.setC_Invoice(invoice); taxDeclarationLine.setIsSOTrx(invoice.isSOTrx()); taxDeclarationLine.setC_BPartner_ID(invoice.getC_BPartner_ID()); taxDeclarationLine.setC_Currency_ID(invoice.getC_Currency_ID()); taxDeclarationLine.setDateAcct(invoice.getDateAcct()); taxDeclarationLine.setC_DocType_ID(invoice.getC_DocType_ID()); taxDeclarationLine.setDocumentNo(invoice.getDocumentNo()); // taxDeclarationLine.setC_Tax_ID(invoiceTax.getC_Tax_ID()); taxDeclarationLine.setTaxBaseAmt(invoiceTax.getTaxBaseAmt()); taxDeclarationLine.setTaxAmt(invoiceTax.getTaxAmt()); save(taxDeclarationLine); return taxDeclarationLine; }
@Override public void createBankStatementLines( final I_C_BankStatement bankStatement, final I_C_PaySelection paySelection) { Check.errorIf( bankStatement.getC_BP_BankAccount_ID() != paySelection.getC_BP_BankAccount_ID(), "C_BankStatement {} with C_BP_BankAccount_ID={} and C_PaySelection {} with C_BP_BankAccount_ID={} need to have the same C_BP_BankAccount_ID", bankStatement, bankStatement.getC_BP_BankAccount_ID(), paySelection, paySelection.getC_BP_BankAccount_ID()); // services final IPaySelectionDAO paySelectionDAO = Services.get(IPaySelectionDAO.class); final IInvoiceBL invoiceBL = Services.get(IInvoiceBL.class); final IBankStatementBL bankStatementBL = Services.get(IBankStatementBL.class); I_C_BankStatementLine bankStatementLine = null; int nextReferenceLineNo = 10; final List<I_C_PaySelectionLine> paySelectionLines = paySelectionDAO.retrievePaySelectionLines(paySelection, I_C_PaySelectionLine.class); for (final I_C_PaySelectionLine psl : paySelectionLines) { // Skip if already in a bank statement if (isInBankStatement(psl)) { continue; } // Skip if no invoice if (psl.getC_Invoice_ID() <= 0) { continue; } // // Create the bank statement line (if not already created) if (bankStatementLine == null) { bankStatementLine = InterfaceWrapperHelper.newInstance(I_C_BankStatementLine.class, paySelection); bankStatementLine.setAD_Org_ID(paySelection.getAD_Org_ID()); bankStatementLine.setC_BankStatement(bankStatement); bankStatementLine.setIsMultiplePaymentOrInvoice( true); // we have a reference line for each invoice bankStatementLine.setIsMultiplePayment(true); // each invoice shall have it's own payment bankStatementLine.setC_Currency_ID(bankStatement.getC_BP_BankAccount().getC_Currency_ID()); bankStatementLine.setValutaDate(paySelection.getPayDate()); bankStatementLine.setDateAcct(paySelection.getPayDate()); bankStatementLine.setStatementLineDate(paySelection.getPayDate()); bankStatementLine.setReferenceNo(null); // no ReferenceNo at this level bankStatementLine.setC_BPartner( null); // no partner because we will have it on "line reference" level bankStatementLine.setStmtAmt(BigDecimal.ZERO); // will be updated at the end bankStatementLine.setTrxAmt(BigDecimal.ZERO); // will be updated at the end bankStatementLine.setChargeAmt(BigDecimal.ZERO); bankStatementLine.setInterestAmt(BigDecimal.ZERO); InterfaceWrapperHelper.save(bankStatementLine); } // // Create new bank statement line reference for our current pay selection line. final I_C_BankStatementLine_Ref bankStatementLineRef = InterfaceWrapperHelper.newInstance(I_C_BankStatementLine_Ref.class, bankStatementLine); bankStatementLineRef.setAD_Org_ID(bankStatementLine.getAD_Org_ID()); bankStatementLineRef.setC_BankStatementLine(bankStatementLine); IBankStatementBL.DYNATTR_DisableBankStatementLineRecalculateFromReferences.setValue( bankStatementLineRef, true); // disable recalculation. we will do it at the end // // Set Invoice from pay selection line bankStatementLineRef.setC_BPartner_ID(psl.getC_BPartner_ID()); final I_C_Invoice invoice = psl.getC_Invoice(); bankStatementLineRef.setC_Invoice(invoice); bankStatementLineRef.setC_Currency_ID(invoice.getC_Currency_ID()); // // Get pay schedule line amounts: final boolean isReceipt; if (invoiceBL.isCreditMemo(invoice)) { // SOTrx=Y, but credit memo => receipt=N isReceipt = !invoice.isSOTrx(); } else { // SOTrx=Y => receipt=Y isReceipt = invoice.isSOTrx(); } final BigDecimal factor = isReceipt ? BigDecimal.ONE : BigDecimal.ONE.negate(); final BigDecimal linePayAmt = psl.getPayAmt().multiply(factor); final BigDecimal lineDiscountAmt = psl.getDiscountAmt().multiply(factor); // we store the psl's discount amount, because if we create a payment from this line, then we // don't want the psl's Discount to end up as a mere underpayment. bankStatementLineRef.setDiscountAmt(lineDiscountAmt); bankStatementLineRef.setTrxAmt(linePayAmt); bankStatementLineRef.setReferenceNo(psl.getReference()); bankStatementLineRef.setLine(nextReferenceLineNo); // // Set Payment from pay selection line. // NOTE: In case the pay selection line does not already have a payment generated, // we are generating it now because it's the most convenient for the user. createPaymentIfNeeded(psl); bankStatementLineRef.setC_Payment_ID(psl.getC_Payment_ID()); // // Save the bank statement line reference InterfaceWrapperHelper.save(bankStatementLineRef); nextReferenceLineNo += 10; // // Update pay selection line => mark it as reconciled linkBankStatementLine(psl, bankStatementLine, bankStatementLineRef); } // // Update Bank Statement Line's totals: if (bankStatementLine != null) { bankStatementBL.recalculateStatementLineAmounts(bankStatementLine); } }