@Override public void process(final I_C_OLCand olCand) throws Exception { if (olCand.isProcessed()) { result.incSkipped(); return; } final IParams params = processorCtx.getParams(); Check.errorIf(params == null, "Given processorCtx {0} needs to contain params", processorCtx); // Partner final int bpartnerId = params.getParameterAsInt(I_C_OLCand.COLUMNNAME_C_BPartner_Override_ID); olCand.setC_BPartner_Override_ID(bpartnerId); // Location final int bpartnerLocationId = params.getParameterAsInt(I_C_OLCand.COLUMNNAME_C_BP_Location_Override_ID); olCand.setC_BP_Location_Override_ID(bpartnerLocationId); // DatePrommissed final Timestamp datePromissed = params.getParameterAsTimestamp(I_C_OLCand.COLUMNNAME_DatePromised_Override); olCand.setDatePromised_Override(datePromissed); InterfaceWrapperHelper.save(olCand); result.incUpdated(); }
@ModelChange( timings = ModelValidator.TYPE_BEFORE_CHANGE, ifColumnsChanged = I_C_Payment.COLUMNNAME_IsAutoAllocateAvailableAmt) public void onChangePayment(final I_C_Payment payment) { if (payment.isAutoAllocateAvailableAmt()) { Check.errorIf( !(payment.isReceipt()), " Payment {} with IsAutoAllocateAvailableAmt=Y is not a receipt.", payment); } }
public final Collector setParameter(final String parameterName, final Object parameterValue) { assertNotProcessed(); Check.assumeNotEmpty(parameterName, "parameterName not empty"); final Object oldValue = parameters.put(parameterName, parameterValue); Check.errorIf( oldValue != null // gh #409: it's ok if an equal value is added more than once. This for example // happens if an inout is reversed, because there the counter doc's model interceptor // is fired twice within the same transaction. && !oldValue.equals(parameterValue), "Illegal attempt to overwrite parameter name={} with newValue={}; it was already set to oldValue={}", parameterName, parameterValue, oldValue); return this; }
private AllocationLineCandidate(final Builder builder) { super(); amount = builder.amount; discountAmt = builder.discountAmt; writeOffAmt = builder.writeOffAmt; payableOverUnderAmt = builder.payableOverUnderAmt; paymentOverUnderAmt = builder.paymentOverUnderAmt; C_BPartner_ID = builder.C_BPartner_ID > 0 ? builder.C_BPartner_ID : -1; payableDocumentRef = builder.getPayableDocumentRef(); paymentDocumentRef = builder.getPaymentDocumentRef(); Check.errorIf( Check.equals(payableDocumentRef, paymentDocumentRef), "payable and payment shall not be the same but there are: {}", payableDocumentRef); if (amount.signum() != 0) { Check.assumeNotNull( paymentDocumentRef, "paymentDocumentRef not null when amount is not zero"); } }
@Override public DBException wrapIfNeededOrReturnNull(final Throwable t) { final Boolean referencingTableHasDLMLevel; if (DBException.isSQLState(t, PG_SQLSTATE_Referencing_Record_Has_Wrong_DLM_Level)) { referencingTableHasDLMLevel = true; } else if (DBException.isSQLState(t, PG_SQLSTATE_Referencing_Table_Has_No_DLM_LEvel)) { referencingTableHasDLMLevel = false; } else { return null; } // // parse the exception detail and extract the infos final SQLException sqlException = DBException.extractSQLExceptionOrNull(t); Check.errorUnless( sqlException instanceof PSQLException, "exception={} needs to be a PSQLExcetion", sqlException); final PSQLException psqlException = (PSQLException) sqlException; final ServerErrorMessage serverErrorMessage = psqlException.getServerErrorMessage(); Check.errorIf( serverErrorMessage == null, "ServerErrorMessage of PSQLException={} may not be null", psqlException); final String detail = serverErrorMessage.getDetail(); Check.errorIf( Check.isEmpty(detail, true), "DETAIL ServerErrorMessage={} from of PSQLException={} may not be null", serverErrorMessage, psqlException); final String[] infos = extractInfos(detail); // // the the "real" tables and column from the extracted lowercase infos final IADTableDAO adTableDAO = Services.get(IADTableDAO.class); final I_AD_Table referencedTable = adTableDAO.retrieveTable(infos[0]); Check.errorIf( referencedTable == null, "Unable to retrieve an AD_Table for referencedTable name={}", infos[0]); final I_AD_Table referencingTable = adTableDAO.retrieveTable(infos[2]); Check.errorIf( referencingTable == null, "Unable to retrieve an AD_Table for referencingTable name={}", infos[2]); final I_AD_Column referencingColumn = adTableDAO.retrieveColumn(referencingTable.getTableName(), infos[3]); Check.errorIf( referencingTable == null, "Unable to retrieve an AD_Column for referencingTable name={} and referencingColumn name={}", infos[2], infos[3]); return new DLMReferenceException( t, TableReferenceDescriptor.of( referencingTable.getTableName(), referencingColumn.getColumnName(), referencedTable.getTableName(), Integer.parseInt(infos[1])), referencingTableHasDLMLevel); }
@Override public int getC_TaxCategory_ID(final org.compiere.model.I_C_InvoiceLine invoiceLine) { // FIXME: we need to retrieve the C_TaxCategory_ID by using Pricing Engine if (invoiceLine.getC_Charge_ID() > 0) { return invoiceLine.getC_Charge().getC_TaxCategory_ID(); } final I_C_Invoice invoice = invoiceLine.getC_Invoice(); final IPriceListDAO priceListDAO = Services.get(IPriceListDAO.class); final Boolean processedPLVFiltering = null; // task 09533: the user doesn't know about PLV's processed flag, so we can't filter by // it if (invoice.getM_PriceList_ID() != 100) // FIXME use PriceList_None constant { final I_M_PriceList priceList = invoice.getM_PriceList(); final I_M_PriceList_Version priceListVersion = priceListDAO.retrievePriceListVersionOrNull( priceList, invoice.getDateInvoiced(), processedPLVFiltering); Check.errorIf( priceListVersion == null, "Missing PLV for M_PriceList and DateInvoiced of {}", invoice); final int m_Product_ID = invoiceLine.getM_Product_ID(); Check.assume(m_Product_ID > 0, "M_Product_ID > 0 for {}", invoiceLine); final I_M_ProductPrice productPrice = priceListDAO.retrieveProductPrice(priceListVersion, m_Product_ID); return productPrice.getC_TaxCategory_ID(); } // Fallback: try getting from Order Line if (invoiceLine.getC_OrderLine_ID() > 0) { return invoiceLine.getC_OrderLine().getC_TaxCategory_ID(); } // Fallback: try getting from Invoice -> Order if (invoiceLine.getC_Invoice().getC_Order_ID() > 0) { final Properties ctx = InterfaceWrapperHelper.getCtx(invoiceLine); final String trxName = InterfaceWrapperHelper.getTrxName(invoiceLine); final I_C_Order order = InterfaceWrapperHelper.create( ctx, invoiceLine.getC_Invoice().getC_Order_ID(), I_C_Order.class, trxName); final I_M_PriceList priceList = order.getM_PriceList(); final I_M_PriceList_Version priceListVersion = priceListDAO.retrievePriceListVersionOrNull( priceList, invoice.getDateInvoiced(), processedPLVFiltering); Check.errorIf( priceListVersion == null, "Missing PLV for M_PriceList and DateInvoiced of {}", invoice); final int m_Product_ID = invoiceLine.getM_Product_ID(); Check.assume(m_Product_ID > 0, "M_Product_ID > 0 for {}", invoiceLine); final I_M_ProductPrice productPrice = priceListDAO.retrieveProductPrice(priceListVersion, m_Product_ID); return productPrice.getC_TaxCategory_ID(); } throw new AdempiereException( "@NotFound@ @C_TaxCategory_ID@ (" + "@C_InvoiceLine_ID@:" + invoiceLine + ")"); }
@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); } }