コード例 #1
0
  @Override
  public void setTaxAmtInfo(
      final Properties ctx, final I_C_InvoiceLine il, final String getTrxName) {
    final IInvoiceBL invoiceBL = Services.get(IInvoiceBL.class);
    final ITaxBL taxBL = Services.get(ITaxBL.class);

    final int taxId = il.getC_Tax_ID();

    final boolean taxIncluded = invoiceBL.isTaxIncluded(il);
    final BigDecimal lineNetAmt = il.getLineNetAmt();
    final int taxPrecision = invoiceBL.getPrecision(il);

    final I_C_Tax tax = MTax.get(ctx, taxId);
    final BigDecimal taxAmtInfo = taxBL.calculateTax(tax, lineNetAmt, taxIncluded, taxPrecision);

    il.setTaxAmtInfo(taxAmtInfo);
  }
コード例 #2
0
  private boolean addInvoice0(final I_C_Invoice invoice) {
    //
    // Skip not posted invoices, but warn the user
    if (!invoice.isPosted()) {
      loggable.addLog("@Error@: @C_Invoice_ID@ @Posted@=@N@: " + invoiceBL.getSummary(invoice));
      return false;
    }

    //
    // Tax declaration lines (one for each invoice tax record)
    final List<I_C_InvoiceTax> invoiceTaxes = invoiceDAO.retrieveTaxes(invoice);
    final Map<Integer, I_C_TaxDeclarationLine> taxId2taxDeclarationLine =
        new HashMap<>(invoiceTaxes.size());
    for (final I_C_InvoiceTax invoiceTax : invoiceTaxes) {
      final int taxId = invoiceTax.getC_Tax_ID();
      final I_C_TaxDeclarationLine taxDeclarationLine =
          createTaxDeclarationLine(invoice, invoiceTax);
      final I_C_TaxDeclarationLine taxDeclarationLineOld =
          taxId2taxDeclarationLine.put(taxId, taxDeclarationLine);
      Check.assumeNull(
          taxDeclarationLineOld,
          "More than one invoice tax line for {0}, taxId={1}",
          invoice,
          taxId);
    }

    //
    // Tax declaration accounting records
    final List<I_Fact_Acct> factAcctRecords =
        factAcctDAO
            .retrieveQueryForDocument(invoice)
            // fetch only those Fact_Acct records which are about taxes, i.e.
            .addNotEqualsFilter(I_Fact_Acct.COLUMN_C_Tax_ID, null) // C_Tax_ID is set
            .addEqualsFilter(I_Fact_Acct.COLUMN_Line_ID, null) // Line_ID is NOT set
            //
            .create()
            .list();
    for (final I_Fact_Acct factAcctRecord : factAcctRecords) {
      //
      // Link to Tax Declaration Line only if this Fact_Acct is about tax bookings. Which means:
      // * it's document level booking (Line_ID <= 0)
      // * we have a C_TaxDeclarationLine which has the same tax as this booking
      I_C_TaxDeclarationLine taxDeclarationLine = null;
      if (factAcctRecord.getLine_ID() <= 0) {
        final int taxId = factAcctRecord.getC_Tax_ID();
        taxDeclarationLine = taxId2taxDeclarationLine.get(taxId);
      }

      createTaxDeclarationAcct(taxDeclarationLine, factAcctRecord);
    }

    return true;
  }
コード例 #3
0
  @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);
    }
  }