Example usage for java.math BigDecimal toString

List of usage examples for java.math BigDecimal toString

Introduction

In this page you can find the example usage for java.math BigDecimal toString.

Prototype

@Override
public String toString() 

Source Link

Document

Returns the string representation of this BigDecimal , using scientific notation if an exponent is needed.

Usage

From source file:autoInsurance.BeiJPiccImpl.java

String round(String num) {
    BigDecimal big = new BigDecimal(num);
    BigDecimal result = big.divide(new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP);
    return result.toString();
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

private static void writeBigDecimal(BigDecimal o, DataOutput out) throws IOException {
    InternalDataSerializer.checkOut(out);

    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
        logger.trace(LogMarker.SERIALIZER, "Writing BigDecimal: {}", o);
    }/*from  ww w.java2 s  . c o  m*/
    DataSerializer.writeString(o.toString(), out);
}

From source file:org.openbravo.erpCommon.ad_forms.DocInvoice.java

/**
 * Create Facts (the accounting logic) for ARI, ARC, ARF, API, APC.
 * //from w ww  . j ava 2s  .co m
 * <pre>
 *  ARI, ARF
 *      Receivables     DR
 *      Charge                  CR
 *      TaxDue                  CR
 *      Revenue                 CR
 *  ARC
 *      Receivables             CR
 *      Charge          DR
 *      TaxDue          DR
 *      Revenue         RR
 *  API
 *      Payables                CR
 *      Charge          DR
 *      TaxCredit       DR
 *      Expense         DR
 *  APC
 *      Payables        DR
 *      Charge                  CR
 *      TaxCredit               CR
 *      Expense                 CR
 * </pre>
 * 
 * @param as
 *          accounting schema
 * @return Fact
 */
public Fact createFact(AcctSchema as, ConnectionProvider conn, Connection con, VariablesSecureApp vars)
        throws ServletException {
    // Select specific definition
    String strClassname = AcctServerData.selectTemplateDoc(conn, as.m_C_AcctSchema_ID, DocumentType);
    if (strClassname.equals(""))
        strClassname = AcctServerData.selectTemplate(conn, as.m_C_AcctSchema_ID, AD_Table_ID);
    if (!strClassname.equals("")) {
        try {
            DocInvoiceTemplate newTemplate = (DocInvoiceTemplate) Class.forName(strClassname).newInstance();
            return newTemplate.createFact(this, as, conn, con, vars);
        } catch (Exception e) {
            log4j.error("Error while creating new instance for DocInvoiceTemplate - " + e);
        }
    }
    log4jDocInvoice.debug("Starting create fact");
    // create Fact Header
    Fact fact = new Fact(this, as, Fact.POST_Actual);
    String Fact_Acct_Group_ID = SequenceIdData.getUUID();
    // Cash based accounting
    if (!as.isAccrual())
        return null;

    /** @todo Assumes TaxIncluded = N */

    // ARI, ARF, ARI_RM
    if (DocumentType.equals(AcctServer.DOCTYPE_ARInvoice) || DocumentType.equals(AcctServer.DOCTYPE_ARProForma)
            || DocumentType.equals(AcctServer.DOCTYPE_RMSalesInvoice)) {
        log4jDocInvoice.debug("Point 1");
        // Receivables DR
        if (m_payments == null || m_payments.length == 0)
            for (int i = 0; m_debt_payments != null && i < m_debt_payments.length; i++) {
                if (m_debt_payments[i].isReceipt.equals("Y"))
                    fact.createLine(m_debt_payments[i],
                            getAccountBPartner(C_BPartner_ID, as, true, m_debt_payments[i].dpStatus, conn),
                            this.C_Currency_ID,
                            getConvertedAmt(m_debt_payments[i].Amount, m_debt_payments[i].C_Currency_ID_From,
                                    this.C_Currency_ID, DateAcct, "", AD_Client_ID, AD_Org_ID, conn),
                            "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
                else
                    fact.createLine(m_debt_payments[i],
                            getAccountBPartner(C_BPartner_ID, as, false, m_debt_payments[i].dpStatus, conn),
                            this.C_Currency_ID, "",
                            getConvertedAmt(m_debt_payments[i].Amount, m_debt_payments[i].C_Currency_ID_From,
                                    this.C_Currency_ID, DateAcct, "", AD_Client_ID, AD_Org_ID, conn),
                            Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
            }
        else
            for (int i = 0; m_payments != null && i < m_payments.length; i++) {
                fact.createLine(m_payments[i], getAccountBPartner(C_BPartner_ID, as, true, false, conn),
                        this.C_Currency_ID, m_payments[i].Amount, "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                        DocumentType, conn);
                if (m_payments[i].C_Currency_ID_From.equals(as.m_C_Currency_ID)
                        && new BigDecimal(m_payments[i].PrepaidAmount).compareTo(ZERO) != 0) {
                    fact.createLine(m_payments[i], getAccountBPartner(C_BPartner_ID, as, true, true, conn),
                            this.C_Currency_ID, m_payments[i].PrepaidAmount, "", Fact_Acct_Group_ID,
                            nextSeqNo(SeqNo), DocumentType, conn);
                } else if (!m_payments[i].C_Currency_ID_From.equals(as.m_C_Currency_ID)) {
                    try {
                        DocInvoiceData[] prepayments = DocInvoiceData.selectPrepayments(connectionProvider,
                                m_payments[i].Line_ID);
                        for (int j = 0; j < prepayments.length; j++) {
                            BigDecimal prePaymentAmt = convertAmount(new BigDecimal(prepayments[j].prepaidamt),
                                    true, DateAcct, TABLEID_Payment, prepayments[j].finPaymentId,
                                    m_payments[i].C_Currency_ID_From, as.m_C_Currency_ID, m_payments[i], as,
                                    fact, Fact_Acct_Group_ID, nextSeqNo(SeqNo), conn);
                            fact.createLine(m_payments[i],
                                    getAccountBPartner(C_BPartner_ID, as, true, true, conn),
                                    m_payments[i].C_Currency_ID_From, prePaymentAmt.toString(), "",
                                    Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
                        }
                    } catch (ServletException e) {
                        log4jDocInvoice.warn(e);
                    }
                }
            }
        if ((m_payments == null || m_payments.length == 0)
                && (m_debt_payments == null || m_debt_payments.length == 0)) {
            BigDecimal grossamt = new BigDecimal(Amounts[AMTTYPE_Gross]);
            BigDecimal prepayment = new BigDecimal(prepaymentamt);
            BigDecimal difference = grossamt.abs().subtract(prepayment.abs());
            if (!prepaymentamt.equals("0")) {
                if (grossamt.abs().compareTo(prepayment.abs()) > 0) {
                    if (IsReturn.equals("Y")) {
                        fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, true, true, conn),
                                this.C_Currency_ID, "", prepaymentamt, Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                                DocumentType, conn);
                        fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, true, false, conn),
                                this.C_Currency_ID, "", difference.toString(), Fact_Acct_Group_ID,
                                nextSeqNo(SeqNo), DocumentType, conn);
                    } else {
                        fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, true, true, conn),
                                this.C_Currency_ID, prepaymentamt, "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                                DocumentType, conn);
                        fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, true, false, conn),
                                this.C_Currency_ID, difference.toString(), "", Fact_Acct_Group_ID,
                                nextSeqNo(SeqNo), DocumentType, conn);
                    }
                } else {
                    if (IsReturn.equals("Y")) {
                        fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, true, true, conn),
                                this.C_Currency_ID, "", prepaymentamt, Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                                DocumentType, conn);
                    } else {
                        fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, true, true, conn),
                                this.C_Currency_ID, prepaymentamt, "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                                DocumentType, conn);
                    }
                }
            } else {
                fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, true, false, conn),
                        this.C_Currency_ID, Amounts[AMTTYPE_Gross], "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                        DocumentType, conn);
            }

        }
        // Charge CR
        log4jDocInvoice.debug("The first create line");
        fact.createLine(null, getAccount(AcctServer.ACCTTYPE_Charge, as, conn), C_Currency_ID, "",
                getAmount(AcctServer.AMTTYPE_Charge), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
        // TaxDue CR
        log4jDocInvoice.debug("m_taxes.length: " + m_taxes);
        BigDecimal grossamt = new BigDecimal(Amounts[AMTTYPE_Gross]);
        BigDecimal prepayment = new BigDecimal(prepaymentamt);

        for (int i = 0; m_taxes != null && i < m_taxes.length; i++) {
            // New docLine created to assign C_Tax_ID value to the entry
            DocLine docLine = new DocLine(DocumentType, Record_ID, "");
            docLine.m_C_Tax_ID = m_taxes[i].m_C_Tax_ID;

            BigDecimal percentageFinalAccount = CashVATUtil._100;
            final BigDecimal taxesAmountTotal = new BigDecimal(
                    StringUtils.isBlank(m_taxes[i].m_amount) ? "0" : m_taxes[i].m_amount);
            BigDecimal taxToTransAccount = BigDecimal.ZERO;
            int precission = 0;
            OBContext.setAdminMode(true);
            try {
                Currency currency = OBDal.getInstance().get(Currency.class, C_Currency_ID);
                precission = currency.getStandardPrecision().intValue();
            } finally {
                OBContext.restorePreviousMode();
            }
            if (IsReversal.equals("Y")) {
                if (isCashVAT && m_taxes[i].m_isCashVAT) {
                    if ((m_payments == null || m_payments.length == 0)
                            && (m_debt_payments == null || m_debt_payments.length == 0)
                            && (!prepaymentamt.equals("0"))) {
                        percentageFinalAccount = ((prepayment.multiply(new BigDecimal(100)))
                                .divide(grossamt.abs(), precission, RoundingMode.HALF_UP));
                        taxToTransAccount = CashVATUtil.calculatePercentageAmount(
                                CashVATUtil._100.subtract(percentageFinalAccount), taxesAmountTotal,
                                C_Currency_ID);
                    } else {
                        percentageFinalAccount = CashVATUtil
                                .calculatePrepaidPercentageForCashVATTax(m_taxes[i].m_C_Tax_ID, Record_ID);
                        taxToTransAccount = CashVATUtil.calculatePercentageAmount(
                                CashVATUtil._100.subtract(percentageFinalAccount), taxesAmountTotal,
                                C_Currency_ID);
                    }
                    fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxDue_Trans, as, conn),
                            C_Currency_ID, taxToTransAccount.toString(), "", Fact_Acct_Group_ID,
                            nextSeqNo(SeqNo), DocumentType, conn);
                }
                final BigDecimal taxToFinalAccount = taxesAmountTotal.subtract(taxToTransAccount);
                fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxDue, as, conn), C_Currency_ID,
                        taxToFinalAccount.toString(), "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
                        conn);
            } else {
                if (isCashVAT && m_taxes[i].m_isCashVAT) {
                    if ((m_payments == null || m_payments.length == 0)
                            && (m_debt_payments == null || m_debt_payments.length == 0)
                            && (!prepaymentamt.equals("0"))) {
                        percentageFinalAccount = ((prepayment.multiply(new BigDecimal(100)))
                                .divide(grossamt.abs(), precission, RoundingMode.HALF_UP));
                        taxToTransAccount = CashVATUtil.calculatePercentageAmount(
                                CashVATUtil._100.subtract(percentageFinalAccount), taxesAmountTotal,
                                C_Currency_ID);
                    } else {
                        percentageFinalAccount = CashVATUtil
                                .calculatePrepaidPercentageForCashVATTax(m_taxes[i].m_C_Tax_ID, Record_ID);
                        taxToTransAccount = CashVATUtil.calculatePercentageAmount(
                                CashVATUtil._100.subtract(percentageFinalAccount), taxesAmountTotal,
                                C_Currency_ID);
                    }
                    fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxDue_Trans, as, conn),
                            C_Currency_ID, "", taxToTransAccount.toString(), Fact_Acct_Group_ID,
                            nextSeqNo(SeqNo), DocumentType, conn);
                }
                final BigDecimal taxToFinalAccount = taxesAmountTotal.subtract(taxToTransAccount);
                fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxDue, as, conn), C_Currency_ID,
                        "", taxToFinalAccount.toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
                        conn);
            }
        }
        // Revenue CR
        if (p_lines != null && p_lines.length > 0) {
            for (int i = 0; i < p_lines.length; i++) {
                Account account = ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_Revenue, as,
                        conn);
                if (DocumentType.equals(AcctServer.DOCTYPE_RMSalesInvoice)) {
                    Account accountReturnMaterial = ((DocLine_Invoice) p_lines[i])
                            .getAccount(ProductInfo.ACCTTYPE_P_RevenueReturn, as, conn);
                    if (accountReturnMaterial != null) {
                        account = accountReturnMaterial;
                    }
                }
                String amount = p_lines[i].getAmount();
                String amountConverted = "";
                ConversionRateDoc conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Invoice, Record_ID,
                        C_Currency_ID, as.m_C_Currency_ID);
                if (conversionRateCurrentDoc != null) {
                    amountConverted = applyRate(new BigDecimal(p_lines[i].getAmount()),
                            conversionRateCurrentDoc, true).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
                } else {
                    amountConverted = getConvertedAmt(p_lines[i].getAmount(), C_Currency_ID, as.m_C_Currency_ID,
                            DateAcct, "", AD_Client_ID, AD_Org_ID, conn);
                }
                if (((DocLine_Invoice) p_lines[i]).isDeferred()) {
                    amount = createAccDefRevenueFact(
                            fact, (DocLine_Invoice) p_lines[i], account, ((DocLine_Invoice) p_lines[i])
                                    .getAccount(ProductInfo.ACCTTYPE_P_DefRevenue, as, conn),
                            amountConverted, as.m_C_Currency_ID, conn);
                    if (IsReversal.equals("Y")) {
                        fact.createLine(p_lines[i], account, as.m_C_Currency_ID, amount, "", Fact_Acct_Group_ID,
                                nextSeqNo(SeqNo), DocumentType, conn);
                    } else {
                        fact.createLine(p_lines[i], account, as.m_C_Currency_ID, "", amount, Fact_Acct_Group_ID,
                                nextSeqNo(SeqNo), DocumentType, conn);
                    }
                } else {
                    if (IsReversal.equals("Y")) {
                        fact.createLine(p_lines[i], account, this.C_Currency_ID, amount, "", Fact_Acct_Group_ID,
                                nextSeqNo(SeqNo), DocumentType, conn);
                    } else {
                        fact.createLine(p_lines[i], account, this.C_Currency_ID, "", amount, Fact_Acct_Group_ID,
                                nextSeqNo(SeqNo), DocumentType, conn);
                    }
                }
                // If revenue has been deferred
                if (((DocLine_Invoice) p_lines[i]).isDeferred() && !amount.equals(amountConverted)) {
                    amount = new BigDecimal(amountConverted).subtract(new BigDecimal(amount)).toString();
                    if (IsReversal.equals("Y")) {
                        fact.createLine(p_lines[i],
                                ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_DefRevenue, as,
                                        conn),
                                as.m_C_Currency_ID, amount, "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                                DocumentType, conn);
                    } else {
                        fact.createLine(p_lines[i],
                                ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_DefRevenue, as,
                                        conn),
                                as.m_C_Currency_ID, "", amount, Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                                DocumentType, conn);
                    }
                }
            }
        }
        // Set Locations
        FactLine[] fLines = fact.getLines();
        for (int i = 0; i < fLines.length; i++) {
            if (fLines[i] != null) {
                fLines[i].setLocationFromOrg(fLines[i].getAD_Org_ID(conn), true, conn); // from Loc
                fLines[i].setLocationFromBPartner(C_BPartner_Location_ID, false, conn); // to Loc
            }
        }
    }
    // ARC
    else if (this.DocumentType.equals(AcctServer.DOCTYPE_ARCredit)) {
        log4jDocInvoice.debug("Point 2");
        // Receivables CR
        if (m_payments == null || m_payments.length == 0)
            for (int i = 0; m_debt_payments != null && i < m_debt_payments.length; i++) {
                BigDecimal amount = new BigDecimal(m_debt_payments[i].Amount);
                // BigDecimal ZERO = BigDecimal.ZERO;
                fact.createLine(m_debt_payments[i],
                        getAccountBPartner(C_BPartner_ID, as, true, m_debt_payments[i].dpStatus, conn),
                        this.C_Currency_ID, "",
                        getConvertedAmt(((amount.negate())).toPlainString(),
                                m_debt_payments[i].C_Currency_ID_From, this.C_Currency_ID, DateAcct, "",
                                AD_Client_ID, AD_Org_ID, conn),
                        Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
            }
        else
            for (int i = 0; m_payments != null && i < m_payments.length; i++) {
                BigDecimal amount = new BigDecimal(m_payments[i].Amount);
                BigDecimal prepaidAmount = new BigDecimal(m_payments[i].PrepaidAmount);
                fact.createLine(m_payments[i], getAccountBPartner(C_BPartner_ID, as, true, false, conn),
                        this.C_Currency_ID, "", amount.negate().toString(), Fact_Acct_Group_ID,
                        nextSeqNo(SeqNo), DocumentType, conn);
                // Pre-payment: Probably not needed as at this point we can not generate pre-payments
                // against ARC. Amount is negated
                if (m_payments[i].C_Currency_ID_From.equals(as.m_C_Currency_ID)
                        && prepaidAmount.compareTo(ZERO) != 0) {
                    fact.createLine(m_payments[i], getAccountBPartner(C_BPartner_ID, as, true, true, conn),
                            this.C_Currency_ID, "", prepaidAmount.negate().toString(), Fact_Acct_Group_ID,
                            nextSeqNo(SeqNo), DocumentType, conn);
                } else if (!m_payments[i].C_Currency_ID_From.equals(as.m_C_Currency_ID)) {
                    try {
                        DocInvoiceData[] prepayments = DocInvoiceData.selectPrepayments(connectionProvider,
                                m_payments[i].Line_ID);
                        for (int j = 0; j < prepayments.length; j++) {
                            BigDecimal prePaymentAmt = convertAmount(
                                    new BigDecimal(prepayments[j].prepaidamt).negate(), true, DateAcct,
                                    TABLEID_Payment, prepayments[j].finPaymentId,
                                    m_payments[i].C_Currency_ID_From, as.m_C_Currency_ID, m_payments[i], as,
                                    fact, Fact_Acct_Group_ID, nextSeqNo(SeqNo), conn);
                            fact.createLine(m_payments[i],
                                    getAccountBPartner(C_BPartner_ID, as, true, true, conn),
                                    m_payments[i].C_Currency_ID_From, "", prePaymentAmt.toString(),
                                    Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
                        }
                    } catch (ServletException e) {
                        log4jDocInvoice.warn(e);
                    }
                }
            }
        if ((m_payments == null || m_payments.length == 0)
                && (m_debt_payments == null || m_debt_payments.length == 0)) {
            fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, true, false, conn), this.C_Currency_ID,
                    "", Amounts[AMTTYPE_Gross], Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
        }
        // Charge DR
        fact.createLine(null, getAccount(AcctServer.ACCTTYPE_Charge, as, conn), this.C_Currency_ID,
                getAmount(AcctServer.AMTTYPE_Charge), "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
                conn);
        // TaxDue DR
        for (int i = 0; m_taxes != null && i < m_taxes.length; i++) {
            // New docLine created to assign C_Tax_ID value to the entry
            DocLine docLine = new DocLine(DocumentType, Record_ID, "");
            docLine.m_C_Tax_ID = m_taxes[i].m_C_Tax_ID;

            BigDecimal percentageFinalAccount = CashVATUtil._100;
            final BigDecimal taxesAmountTotal = new BigDecimal(
                    StringUtils.isBlank(m_taxes[i].getAmount()) ? "0" : m_taxes[i].getAmount());
            BigDecimal taxToTransAccount = BigDecimal.ZERO;
            if (isCashVAT && m_taxes[i].m_isCashVAT) {
                percentageFinalAccount = CashVATUtil
                        .calculatePrepaidPercentageForCashVATTax(m_taxes[i].m_C_Tax_ID, Record_ID);
                taxToTransAccount = CashVATUtil.calculatePercentageAmount(
                        CashVATUtil._100.subtract(percentageFinalAccount), taxesAmountTotal, C_Currency_ID);
                fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxDue_Trans, as, conn),
                        this.C_Currency_ID, taxToTransAccount.toString(), "", Fact_Acct_Group_ID,
                        nextSeqNo(SeqNo), DocumentType, conn);
            }
            final BigDecimal taxToFinalAccount = taxesAmountTotal.subtract(taxToTransAccount);
            fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxDue, as, conn),
                    this.C_Currency_ID, taxToFinalAccount.toString(), "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                    DocumentType, conn);
        }
        // Revenue CR
        for (int i = 0; p_lines != null && i < p_lines.length; i++) {
            String amount = p_lines[i].getAmount();
            String amountCoverted = "";
            ConversionRateDoc conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Invoice, Record_ID,
                    C_Currency_ID, as.m_C_Currency_ID);
            if (conversionRateCurrentDoc != null) {
                amountCoverted = applyRate(new BigDecimal(p_lines[i].getAmount()), conversionRateCurrentDoc,
                        true).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
            } else {
                amountCoverted = getConvertedAmt(p_lines[i].getAmount(), C_Currency_ID, as.m_C_Currency_ID,
                        DateAcct, "", AD_Client_ID, AD_Org_ID, conn);
            }
            Account account = ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_Revenue, as,
                    conn);
            if (((DocLine_Invoice) p_lines[i]).isDeferred()) {
                amount = createAccDefRevenueFact(fact, (DocLine_Invoice) p_lines[i], account,
                        ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_DefRevenue, as, conn),
                        amountCoverted, as.m_C_Currency_ID, conn);
                fact.createLine(p_lines[i], account, as.m_C_Currency_ID, amount, "", Fact_Acct_Group_ID,
                        nextSeqNo(SeqNo), DocumentType, conn);
            } else {
                fact.createLine(p_lines[i], account, this.C_Currency_ID, amount, "", Fact_Acct_Group_ID,
                        nextSeqNo(SeqNo), DocumentType, conn);
            }
            // If revenue has been deferred
            if (((DocLine_Invoice) p_lines[i]).isDeferred() && !amount.equals(amountCoverted)) {
                amount = new BigDecimal(amountCoverted).subtract(new BigDecimal(amount)).toString();
                fact.createLine(p_lines[i],
                        ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_DefRevenue, as, conn),
                        as.m_C_Currency_ID, amount, "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
                        conn);
            }
        }
        // Set Locations
        FactLine[] fLines = fact.getLines();
        for (int i = 0; fLines != null && i < fLines.length; i++) {
            if (fLines[i] != null) {
                fLines[i].setLocationFromOrg(fLines[i].getAD_Org_ID(conn), true, conn); // from Loc
                fLines[i].setLocationFromBPartner(C_BPartner_Location_ID, false, conn); // to Loc
            }
        }
    }
    // API
    else if (this.DocumentType.equals(AcctServer.DOCTYPE_APInvoice)) {
        log4jDocInvoice.debug("Point 3");
        // Liability CR
        if (m_payments == null || m_payments.length == 0)
            for (int i = 0; m_debt_payments != null && i < m_debt_payments.length; i++) {
                if (m_debt_payments[i].isReceipt.equals("Y"))
                    fact.createLine(m_debt_payments[i],
                            getAccountBPartner(C_BPartner_ID, as, true, m_debt_payments[i].dpStatus, conn),
                            this.C_Currency_ID,
                            getConvertedAmt(m_debt_payments[i].Amount, m_debt_payments[i].C_Currency_ID_From,
                                    this.C_Currency_ID, DateAcct, "", AD_Client_ID, AD_Org_ID, conn),
                            "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
                else
                    fact.createLine(m_debt_payments[i],
                            getAccountBPartner(C_BPartner_ID, as, false, m_debt_payments[i].dpStatus, conn),
                            this.C_Currency_ID, "",
                            getConvertedAmt(m_debt_payments[i].Amount, m_debt_payments[i].C_Currency_ID_From,
                                    this.C_Currency_ID, DateAcct, "", AD_Client_ID, AD_Org_ID, conn),
                            Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
            }
        else
            for (int i = 0; m_payments != null && i < m_payments.length; i++) {
                fact.createLine(m_payments[i], getAccountBPartner(C_BPartner_ID, as, false, false, conn),
                        this.C_Currency_ID, "", m_payments[i].Amount, Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                        DocumentType, conn);
                if (m_payments[i].C_Currency_ID_From.equals(as.m_C_Currency_ID)
                        && new BigDecimal(m_payments[i].PrepaidAmount).compareTo(ZERO) != 0) {
                    fact.createLine(m_payments[i], getAccountBPartner(C_BPartner_ID, as, false, true, conn),
                            this.C_Currency_ID, "", m_payments[i].PrepaidAmount, Fact_Acct_Group_ID,
                            nextSeqNo(SeqNo), DocumentType, conn);
                } else if (!m_payments[i].C_Currency_ID_From.equals(as.m_C_Currency_ID)) {
                    try {
                        DocInvoiceData[] prepayments = DocInvoiceData.selectPrepayments(connectionProvider,
                                m_payments[i].Line_ID);
                        for (int j = 0; j < prepayments.length; j++) {
                            BigDecimal prePaymentAmt = convertAmount(new BigDecimal(prepayments[j].prepaidamt),
                                    false, DateAcct, TABLEID_Payment, prepayments[j].finPaymentId,
                                    m_payments[i].C_Currency_ID_From, as.m_C_Currency_ID, m_payments[i], as,
                                    fact, Fact_Acct_Group_ID, nextSeqNo(SeqNo), conn);
                            fact.createLine(m_payments[i],
                                    getAccountBPartner(C_BPartner_ID, as, false, true, conn),
                                    m_payments[i].C_Currency_ID_From, "", prePaymentAmt.toString(),
                                    Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
                        }
                    } catch (ServletException e) {
                        log4jDocInvoice.warn(e);
                    }
                }
            }
        if ((m_payments == null || m_payments.length == 0)
                && (m_debt_payments == null || m_debt_payments.length == 0)) {
            BigDecimal grossamt = new BigDecimal(Amounts[AMTTYPE_Gross]);
            BigDecimal prepayment = new BigDecimal(prepaymentamt);
            BigDecimal difference = grossamt.abs().subtract(prepayment.abs());
            if (!prepaymentamt.equals("0")) {
                if (grossamt.abs().compareTo(prepayment.abs()) > 0) {
                    if (IsReturn.equals("Y")) {
                        fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, false, true, conn),
                                this.C_Currency_ID, prepaymentamt, "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                                DocumentType, conn);
                        fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, false, false, conn),
                                this.C_Currency_ID, difference.toString(), "", Fact_Acct_Group_ID,
                                nextSeqNo(SeqNo), DocumentType, conn);
                    } else {
                        fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, false, true, conn),
                                this.C_Currency_ID, "", prepaymentamt, Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                                DocumentType, conn);
                        fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, false, false, conn),
                                this.C_Currency_ID, "", difference.toString(), Fact_Acct_Group_ID,
                                nextSeqNo(SeqNo), DocumentType, conn);
                    }
                } else {
                    if (IsReturn.equals("Y")) {
                        fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, false, true, conn),
                                this.C_Currency_ID, prepaymentamt, "", Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                                DocumentType, conn);
                    } else {
                        fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, false, true, conn),
                                this.C_Currency_ID, "", prepaymentamt, Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                                DocumentType, conn);
                    }
                }
            } else {
                fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, false, false, conn),
                        this.C_Currency_ID, "", Amounts[AMTTYPE_Gross], Fact_Acct_Group_ID, nextSeqNo(SeqNo),
                        DocumentType, conn);
            }

        }
        // Charge DR
        fact.createLine(null, getAccount(AcctServer.ACCTTYPE_Charge, as, conn), this.C_Currency_ID,
                getAmount(AcctServer.AMTTYPE_Charge), "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
                conn);
        BigDecimal grossamt = new BigDecimal(Amounts[AMTTYPE_Gross]);
        BigDecimal prepayment = new BigDecimal(prepaymentamt);
        // TaxCredit DR
        for (int i = 0; m_taxes != null && i < m_taxes.length; i++) {
            // New docLine created to assign C_Tax_ID value to the entry
            DocLine docLine = new DocLine(DocumentType, Record_ID, "");
            docLine.m_C_Tax_ID = m_taxes[i].m_C_Tax_ID;
            OBContext.setAdminMode(true);
            int precission = 0;
            try {
                Currency currency = OBDal.getInstance().get(Currency.class, C_Currency_ID);
                precission = currency.getStandardPrecision().intValue();
            } finally {
                OBContext.restorePreviousMode();
            }
            if (!m_taxes[i].m_isTaxUndeductable) {
                BigDecimal percentageFinalAccount = CashVATUtil._100;
                final BigDecimal taxesAmountTotal = new BigDecimal(
                        StringUtils.isBlank(m_taxes[i].getAmount()) ? "0" : m_taxes[i].getAmount());
                BigDecimal taxToTransAccount = BigDecimal.ZERO;
                if (IsReversal.equals("Y")) {
                    if (isCashVAT && m_taxes[i].m_isCashVAT) {
                        if ((m_payments == null || m_payments.length == 0)
                                && (m_debt_payments == null || m_debt_payments.length == 0)
                                && (!prepaymentamt.equals("0"))) {
                            percentageFinalAccount = ((prepayment.multiply(new BigDecimal(100)))
                                    .divide(grossamt.abs(), precission, RoundingMode.HALF_UP));
                            taxToTransAccount = CashVATUtil.calculatePercentageAmount(
                                    CashVATUtil._100.subtract(percentageFinalAccount), taxesAmountTotal,
                                    C_Currency_ID);
                        } else {
                            percentageFinalAccount = CashVATUtil
                                    .calculatePrepaidPercentageForCashVATTax(m_taxes[i].m_C_Tax_ID, Record_ID);
                            taxToTransAccount = CashVATUtil.calculatePercentageAmount(
                                    CashVATUtil._100.subtract(percentageFinalAccount), taxesAmountTotal,
                                    C_Currency_ID);
                        }
                        fact.createLine(docLine,
                                m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxCredit_Trans, as, conn),
                                this.C_Currency_ID, "", taxToTransAccount.toString(), Fact_Acct_Group_ID,
                                nextSeqNo(SeqNo), DocumentType, conn);
                    }
                    final BigDecimal taxToFinalAccount = taxesAmountTotal.subtract(taxToTransAccount);
                    fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxCredit, as, conn),
                            this.C_Currency_ID, "", taxToFinalAccount.toString(), Fact_Acct_Group_ID,
                            nextSeqNo(SeqNo), DocumentType, conn);
                } else {
                    if (isCashVAT && m_taxes[i].m_isCashVAT) {
                        if ((m_payments == null || m_payments.length == 0)
                                && (m_debt_payments == null || m_debt_payments.length == 0)
                                && (!prepaymentamt.equals("0"))) {
                            percentageFinalAccount = ((prepayment.multiply(new BigDecimal(100)))
                                    .divide(grossamt.abs(), precission, RoundingMode.HALF_UP));
                            taxToTransAccount = CashVATUtil.calculatePercentageAmount(
                                    CashVATUtil._100.subtract(percentageFinalAccount), taxesAmountTotal,
                                    C_Currency_ID);
                        } else {
                            percentageFinalAccount = CashVATUtil
                                    .calculatePrepaidPercentageForCashVATTax(m_taxes[i].m_C_Tax_ID, Record_ID);
                            taxToTransAccount = CashVATUtil.calculatePercentageAmount(
                                    CashVATUtil._100.subtract(percentageFinalAccount), taxesAmountTotal,
                                    C_Currency_ID);
                        }
                        fact.createLine(docLine,
                                m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxCredit_Trans, as, conn),
                                this.C_Currency_ID, taxToTransAccount.toString(), "", Fact_Acct_Group_ID,
                                nextSeqNo(SeqNo), DocumentType, conn);
                    }
                    final BigDecimal taxToFinalAccount = taxesAmountTotal.subtract(taxToTransAccount);
                    fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxCredit, as, conn),
                            this.C_Currency_ID, taxToFinalAccount.toString(), "", Fact_Acct_Group_ID,
                            nextSeqNo(SeqNo), DocumentType, conn);
                }

            } else {
                DocLineInvoiceData[] data = null;
                try {
                    data = DocLineInvoiceData.selectUndeductable(connectionProvider, Record_ID);
                } catch (ServletException e) {
                    log4jDocInvoice.warn(e);
                }

                BigDecimal cumulativeTaxLineAmount = new BigDecimal(0);
                BigDecimal taxAmount = new BigDecimal(0);
                for (int j = 0; data != null && j < data.length; j++) {
                    DocLine docLine1 = new DocLine(DocumentType, Record_ID, "");
                    docLine1.m_C_Tax_ID = data[j].cTaxId;
                    docLine1.m_C_BPartner_ID = data[j].cBpartnerId;
                    docLine1.m_M_Product_ID = data[j].mProductId;
                    docLine1.m_C_Costcenter_ID = data[j].cCostcenterId;
                    docLine1.m_C_Project_ID = data[j].cProjectId;
                    docLine1.m_User1_ID = data[j].user1id;
                    docLine1.m_User2_ID = data[j].user2id;
                    docLine1.m_C_Activity_ID = data[j].cActivityId;
                    docLine1.m_C_Campaign_ID = data[j].cCampaignId;
                    docLine1.m_A_Asset_ID = data[j].aAssetId;
                    String strtaxAmount = null;

                    try {

                        DocInvoiceData[] dataEx = DocInvoiceData.selectProductAcct(conn,
                                as.getC_AcctSchema_ID(), m_taxes[i].m_C_Tax_ID, Record_ID);
                        if (dataEx.length == 0) {
                            dataEx = DocInvoiceData.selectGLItemAcctForTaxLine(conn, as.getC_AcctSchema_ID(),
                                    m_taxes[i].m_C_Tax_ID, Record_ID);
                        }
                        strtaxAmount = m_taxes[i].getAmount();
                        taxAmount = new BigDecimal(strtaxAmount.equals("") ? "0.00" : strtaxAmount);
                        if (j == data.length - 1) {
                            data[j].taxamt = taxAmount.subtract(cumulativeTaxLineAmount).toPlainString();
                        }
                        try {

                            if (this.DocumentType.equals(AcctServer.DOCTYPE_APInvoice)) {
                                if (IsReversal.equals("Y")) {
                                    fact.createLine(docLine1, Account.getAccount(conn, dataEx[0].pExpenseAcct),
                                            this.C_Currency_ID, "", data[j].taxamt, Fact_Acct_Group_ID,
                                            nextSeqNo(SeqNo), DocumentType, conn);

                                } else {
                                    fact.createLine(docLine1, Account.getAccount(conn, dataEx[0].pExpenseAcct),
                                            this.C_Currency_ID, data[j].taxamt, "", Fact_Acct_Group_ID,
                                            nextSeqNo(SeqNo), DocumentType, conn);
                                }
                            } else if (this.DocumentType.equals(AcctServer.DOCTYPE_APCredit)) {
                                fact.createLine(docLine1, Account.getAccount(conn, dataEx[0].pExpenseAcct),
                                        this.C_Currency_ID, "", data[j].taxamt, Fact_Acct_Group_ID,
                                        nextSeqNo(SeqNo), DocumentType, conn);
                            }
                            cumulativeTaxLineAmount = cumulativeTaxLineAmount
                                    .add(new BigDecimal(data[j].taxamt));
                        } catch (ServletException e) {
                            log4jDocInvoice.error("Exception in createLineForTaxUndeductable method: " + e);
                        }
                    } catch (ServletException e) {
                        log4jDocInvoice.warn(e);
                    }
                }
            }
        }
        // Expense DR
        for (int i = 0; p_lines != null && i < p_lines.length; i++) {
            String amount = p_lines[i].getAmount();
            String amountConverted = "";
            ConversionRateDoc conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Invoice, Record_ID,
                    C_Currency_ID, as.m_C_Currency_ID);
            if (conversionRateCurrentDoc != null) {
                amountConverted = applyRate(new BigDecimal(p_lines[i].getAmount()), conversionRateCurrentDoc,
                        true).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
            } else {
                amountConverted = getConvertedAmt(p_lines[i].getAmount(), C_Currency_ID, as.m_C_Currency_ID,
                        DateAcct, "", AD_Client_ID, AD_Org_ID, conn);
            }
            if (((DocLine_Invoice) p_lines[i]).isDeferred()) {
                amount = createAccDefExpenseFact(fact, (DocLine_Invoice) p_lines[i],
                        ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_Expense, as, conn),
                        ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_DefExpense, as, conn),
                        amountConverted, as.m_C_Currency_ID, conn);
                if (IsReversal.equals("Y")) {
                    fact.createLine(p_lines[i],
                            ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_Expense, as, conn),
                            as.m_C_Currency_ID, "", amount, Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
                            conn);
                } else {
                    fact.createLine(p_lines[i],
                            ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_Expense, as, conn),
                            as.m_C_Currency_ID, amount, "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
                            conn);
                }
            } else {
                if (IsReversal.equals("Y")) {
                    fact.createLine(p_lines[i],
                            ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_Expense, as, conn),
                            this.C_Currency_ID, "", amount, Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
                            conn);
                } else {
                    fact.createLine(p_lines[i],
                            ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_Expense, as, conn),
                            this.C_Currency_ID, amount, "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
                            conn);
                }
            }
            // If expense has been deferred
            if (((DocLine_Invoice) p_lines[i]).isDeferred() && !amount.equals(amountConverted)) {
                amount = new BigDecimal(amountConverted).subtract(new BigDecimal(amount)).toString();
                if (IsReversal.equals("Y")) {
                    fact.createLine(p_lines[i],
                            ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_DefExpense, as,
                                    conn),
                            as.m_C_Currency_ID, "", amount, Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
                            conn);
                } else {
                    fact.createLine(p_lines[i],
                            ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_DefExpense, as,
                                    conn),
                            as.m_C_Currency_ID, amount, "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
                            conn);
                }
            }
        }
        // Set Locations
        FactLine[] fLines = fact.getLines();
        for (int i = 0; fLines != null && i < fLines.length; i++) {
            if (fLines[i] != null) {
                fLines[i].setLocationFromBPartner(C_BPartner_Location_ID, true, conn); // from Loc
                fLines[i].setLocationFromOrg(fLines[i].getAD_Org_ID(conn), false, conn); // to Loc
            }
        }
        updateProductInfo(as.getC_AcctSchema_ID(), conn, con); // only API
    }
    // APC
    else if (this.DocumentType.equals(AcctServer.DOCTYPE_APCredit)) {
        log4jDocInvoice.debug("Point 4");
        // Liability DR
        if (m_payments == null || m_payments.length == 0)
            for (int i = 0; m_debt_payments != null && i < m_debt_payments.length; i++) {
                BigDecimal amount = new BigDecimal(m_debt_payments[i].Amount);
                // BigDecimal ZERO = BigDecimal.ZERO;
                fact.createLine(m_debt_payments[i],
                        getAccountBPartner(C_BPartner_ID, as, false, m_debt_payments[i].dpStatus, conn),
                        this.C_Currency_ID,
                        getConvertedAmt(((amount.negate())).toPlainString(),
                                m_debt_payments[i].C_Currency_ID_From, this.C_Currency_ID, DateAcct, "",
                                AD_Client_ID, AD_Org_ID, conn),
                        "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
            }
        else
            for (int i = 0; m_payments != null && i < m_payments.length; i++) {
                BigDecimal amount = new BigDecimal(m_payments[i].Amount);
                BigDecimal prepaidAmount = new BigDecimal(m_payments[i].PrepaidAmount);
                fact.createLine(m_payments[i], getAccountBPartner(C_BPartner_ID, as, false, false, conn),
                        this.C_Currency_ID, amount.negate().toString(), "", Fact_Acct_Group_ID,
                        nextSeqNo(SeqNo), DocumentType, conn);
                // Pre-payment: Probably not needed as at this point we can not generate pre-payments
                // against APC. Amount is negated
                if (m_payments[i].C_Currency_ID_From.equals(as.m_C_Currency_ID)
                        && prepaidAmount.compareTo(ZERO) != 0) {
                    fact.createLine(m_payments[i], getAccountBPartner(C_BPartner_ID, as, false, true, conn),
                            this.C_Currency_ID, prepaidAmount.negate().toString(), "", Fact_Acct_Group_ID,
                            nextSeqNo(SeqNo), DocumentType, conn);
                } else if (!m_payments[i].C_Currency_ID_From.equals(as.m_C_Currency_ID)) {
                    try {
                        DocInvoiceData[] prepayments = DocInvoiceData.selectPrepayments(connectionProvider,
                                m_payments[i].Line_ID);
                        for (int j = 0; j < prepayments.length; j++) {
                            BigDecimal prePaymentAmt = convertAmount(
                                    new BigDecimal(prepayments[j].prepaidamt).negate(), false, DateAcct,
                                    TABLEID_Payment, prepayments[j].finPaymentId,
                                    m_payments[i].C_Currency_ID_From, as.m_C_Currency_ID, m_payments[i], as,
                                    fact, Fact_Acct_Group_ID, nextSeqNo(SeqNo), conn);
                            fact.createLine(m_payments[i],
                                    getAccountBPartner(C_BPartner_ID, as, false, true, conn),
                                    m_payments[i].C_Currency_ID_From, prePaymentAmt.toString(), "",
                                    Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
                        }
                    } catch (ServletException e) {
                        log4jDocInvoice.warn(e);
                    }
                }
            }
        if ((m_payments == null || m_payments.length == 0)
                && (m_debt_payments == null || m_debt_payments.length == 0)) {
            fact.createLine(null, getAccountBPartner(C_BPartner_ID, as, false, false, conn), this.C_Currency_ID,
                    Amounts[AMTTYPE_Gross], "", Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
        }
        // Charge CR
        fact.createLine(null, getAccount(AcctServer.ACCTTYPE_Charge, as, conn), this.C_Currency_ID, "",
                getAmount(AcctServer.AMTTYPE_Charge), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
        // TaxCredit CR
        for (int i = 0; m_taxes != null && i < m_taxes.length; i++) {
            // New docLine created to assign C_Tax_ID value to the entry
            DocLine docLine = new DocLine(DocumentType, Record_ID, "");
            docLine.m_C_Tax_ID = m_taxes[i].m_C_Tax_ID;
            if (m_taxes[i].m_isTaxUndeductable) {
                computeTaxUndeductableLine(conn, as, fact, docLine, Fact_Acct_Group_ID, m_taxes[i].m_C_Tax_ID,
                        m_taxes[i].getAmount());

            } else {
                BigDecimal percentageFinalAccount = CashVATUtil._100;
                final BigDecimal taxesAmountTotal = new BigDecimal(
                        StringUtils.isBlank(m_taxes[i].getAmount()) ? "0" : m_taxes[i].getAmount());
                BigDecimal taxToTransAccount = BigDecimal.ZERO;
                if (isCashVAT && m_taxes[i].m_isCashVAT) {
                    percentageFinalAccount = CashVATUtil
                            .calculatePrepaidPercentageForCashVATTax(m_taxes[i].m_C_Tax_ID, Record_ID);
                    taxToTransAccount = CashVATUtil.calculatePercentageAmount(
                            CashVATUtil._100.subtract(percentageFinalAccount), taxesAmountTotal, C_Currency_ID);
                    fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxCredit_Trans, as, conn),
                            this.C_Currency_ID, "", taxToTransAccount.toString(), Fact_Acct_Group_ID,
                            nextSeqNo(SeqNo), DocumentType, conn);
                }
                final BigDecimal taxToFinalAccount = taxesAmountTotal.subtract(taxToTransAccount);
                fact.createLine(docLine, m_taxes[i].getAccount(DocTax.ACCTTYPE_TaxCredit, as, conn),
                        this.C_Currency_ID, "", taxToFinalAccount.toString(), Fact_Acct_Group_ID,
                        nextSeqNo(SeqNo), DocumentType, conn);
            }
        }
        // Expense CR
        for (int i = 0; p_lines != null && i < p_lines.length; i++) {
            String amount = p_lines[i].getAmount();
            String amountConverted = "";
            ConversionRateDoc conversionRateCurrentDoc = getConversionRateDoc(TABLEID_Invoice, Record_ID,
                    C_Currency_ID, as.m_C_Currency_ID);
            if (conversionRateCurrentDoc != null) {
                amountConverted = applyRate(new BigDecimal(p_lines[i].getAmount()), conversionRateCurrentDoc,
                        true).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
            } else {
                amountConverted = getConvertedAmt(p_lines[i].getAmount(), C_Currency_ID, as.m_C_Currency_ID,
                        DateAcct, "", AD_Client_ID, AD_Org_ID, conn);
            }
            Account account = ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_Expense, as,
                    conn);
            if (((DocLine_Invoice) p_lines[i]).isDeferred()) {
                amount = createAccDefExpenseFact(fact, (DocLine_Invoice) p_lines[i], account,
                        ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_DefExpense, as, conn),
                        amountConverted, as.m_C_Currency_ID, conn);
                fact.createLine(p_lines[i], account, as.m_C_Currency_ID, "", amount, Fact_Acct_Group_ID,
                        nextSeqNo(SeqNo), DocumentType, conn);
            } else {
                fact.createLine(p_lines[i], account, this.C_Currency_ID, "", amount, Fact_Acct_Group_ID,
                        nextSeqNo(SeqNo), DocumentType, conn);
            }
            // If expense has been deferred
            if (((DocLine_Invoice) p_lines[i]).isDeferred() && !amount.equals(amountConverted)) {
                amount = new BigDecimal(amountConverted).subtract(new BigDecimal(amount)).toString();
                fact.createLine(p_lines[i],
                        ((DocLine_Invoice) p_lines[i]).getAccount(ProductInfo.ACCTTYPE_P_DefExpense, as, conn),
                        as.m_C_Currency_ID, "", amount, Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType,
                        conn);
            }

        }
        // Set Locations
        FactLine[] fLines = fact.getLines();
        for (int i = 0; fLines != null && i < fLines.length; i++) {
            if (fLines[i] != null) {
                fLines[i].setLocationFromBPartner(C_BPartner_Location_ID, true, conn); // from Loc
                fLines[i].setLocationFromOrg(fLines[i].getAD_Org_ID(conn), false, conn); // to Loc
            }
        }
    } else {
        log4jDocInvoice.warn("Doc_Invoice - DocumentType unknown: " + this.DocumentType);
        fact = null;
    }
    SeqNo = "0";
    return fact;
}

From source file:org.openbravo.erpCommon.ad_forms.AcctServer.java

/**
 * Matching/*from   w  w w  .j  a  v a 2  s. c  om*/
 * 
 * <pre>
 *  Derive Invoice-Receipt Match from PO-Invoice and PO-Receipt
 *  Purchase Order (20)
 *  - Invoice1 (10)
 *  - Invoice2 (10)
 *  - Receipt1 (5)
 *  - Receipt2 (15)
 *  (a) Creates Directs
 *      - Invoice1 - Receipt1 (5)
 *      - Invoice2 - Receipt2 (10)
 *  (b) Creates Indirects
 *      - Invoice1 - Receipt2 (5)
 *  (Not imlemented)
 * 
 * 
 * </pre>
 * 
 * @return number of records created
 */
public int match(VariablesSecureApp vars, ConnectionProvider conn, Connection con) {
    // if (log4j.isDebugEnabled())
    // log4j.debug("AcctServer - Match--Starting");
    int counter = 0;
    // (a) Direct Matches
    AcctServerData[] data = null;
    try {
        data = AcctServerData.selectMatch(conn, AD_Client_ID);
        for (int i = 0; i < data.length; i++) {
            BigDecimal qty1 = new BigDecimal(data[i].qty1);
            BigDecimal qty2 = new BigDecimal(data[i].qty2);
            BigDecimal Qty = qty1.min(qty2);
            if (Qty.toString().equals("0"))
                continue;
            // if (log4j.isDebugEnabled())
            // log4j.debug("AcctServer - Match--dateTrx1 :->" + data[i].datetrx1
            // + "Match--dateTrx2: ->" + data[i].datetrx2);
            String dateTrx1 = data[i].datetrx1;
            String dateTrx2 = data[i].datetrx2;
            String compare = "";
            try {
                compare = DateTimeData.compare(conn, dateTrx1, dateTrx2);
            } catch (ServletException e) {
                log4j.warn(e);
                e.printStackTrace();
            }
            String DateTrx = dateTrx1;
            if (compare.equals("-1"))
                DateTrx = dateTrx2;
            //
            String strQty = Qty.toString();
            String strDateTrx = DateTrx;
            String AD_Client_ID = data[i].adClientId;
            String AD_Org_ID = data[i].adOrgId;
            String C_InvoiceLine_ID = data[i].cInvoicelineId;
            String M_InOutLine_ID = data[i].mInoutlineId;
            String M_Product_ID = data[i].mProductId;
            //
            if (createMatchInv(AD_Client_ID, AD_Org_ID, M_InOutLine_ID, C_InvoiceLine_ID, M_Product_ID,
                    strDateTrx, strQty, vars, conn, con) == 1)
                counter++;
        }
    } catch (ServletException e) {
        log4j.warn(e);
        e.printStackTrace();
    }
    // if (log4j.isDebugEnabled())
    // log4j.debug("AcctServer - Matcher.match - Client_ID=" + AD_Client_ID
    // + ", Records created=" + counter);
    return counter;
}

From source file:pe.gob.mef.gescon.web.ui.BaseLegalMB.java

public void handleChangeValue(AjaxBehaviorEvent event) {
    try {/*  w ww  .  j a  v a  2s . co  m*/
        if (event != null) {
            BigDecimal id = (BigDecimal) ((SelectOneMenu) event.getSource()).getValue();
            if (id != null) {
                HttpSession session = JSFUtils.getSession();
                ListaSessionMB listasSession = session.getAttribute("listaSessionMB") != null
                        ? (ListaSessionMB) session.getAttribute("listaSessionMB")
                        : new ListaSessionMB();
                List<SelectItem> lista = listasSession.getListaTipoRango();
                for (SelectItem item : lista) {
                    if (id.toString().equals(item.getValue().toString())) {
                        this.setTipoNorma(item.getLabel());
                    }
                }
                RangoService service = (RangoService) ServiceFinder.findBean("RangoService");
                this.setListaRangos(
                        new Items(service.getRangosActivosByTipo(id), null, "nrangoid", "vnombre").getItems());
            } else {
                this.setTipoNorma(StringUtils.EMPTY);
                this.setListaRangos(new ArrayList());
            }

        }
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}

From source file:org.kawanfw.test.api.client.InsertAndUpdatePrepStatementTest.java

/**
 * Test that the values were correclty inserted
 * /*www.j  a  v a2 s. c  o m*/
 * @param connection
 */
@SuppressWarnings("deprecation")
public void selectPrepStatementTest(Connection connection, int customerId, int orderId) throws Exception {
    int customer_id;
    int item_id;
    String description;
    BigDecimal cost_price;
    BigDecimal cost_price_scale;
    Date date_placed;
    Timestamp date_shipped;
    byte[] jpeg_image = null;
    boolean is_delivered;
    int quantity;

    String sql = "select * from orderlog where  customer_id = ? and item_id = ? ";

    PreparedStatement prepStatement = connection.prepareStatement(sql);

    int i = 1;
    prepStatement.setInt(i++, customerId);
    prepStatement.setInt(i++, orderId);

    ResultSet rs = prepStatement.executeQuery();

    MessageDisplayer.display("");

    SqlUtil sqlUtil = new SqlUtil(connection);

    while (rs.next()) {

        customer_id = rs.getInt("customer_id");
        item_id = rs.getInt("item_id");
        description = rs.getString("description");
        cost_price = rs.getBigDecimal("cost_price");
        cost_price_scale = rs.getBigDecimal("cost_price", 5);
        date_placed = rs.getDate("date_placed");
        date_shipped = rs.getTimestamp("date_shipped");
        jpeg_image = rs.getBytes("jpeg_image");

        if (sqlUtil.isIngres()) {
            is_delivered = (rs.getInt("is_delivered") == 1) ? true : false;
        } else {
            is_delivered = rs.getBoolean("is_delivered");
        }

        quantity = rs.getInt("quantity");

        MessageDisplayer.display("customer_id     : " + customer_id);
        MessageDisplayer.display("item_id         : " + item_id);
        MessageDisplayer.display("description     : " + description);
        MessageDisplayer.display("cost_price      : " + cost_price);
        MessageDisplayer.display("cost_price_scale: " + cost_price_scale);
        MessageDisplayer.display("date_placed     : " + date_placed);
        MessageDisplayer.display("date_shipped    : " + date_shipped);
        MessageDisplayer.display("jpeg_image      : " + jpeg_image);
        MessageDisplayer.display("is_delivered    : " + is_delivered);
        MessageDisplayer.display("quantity        : " + quantity);

        // Assert done on first 18 chars (ex: 2011-11-02 16:26:14), because
        // MySql Truncs
        // the remaining milliseconds
        Assert.assertEquals(dateShippedUpdated.toString().substring(0, 19),
                date_shipped.toString().substring(0, 19));

        if (new SqlUtil(connection).isSQLAnywhere()) {
            // Because SQLK Anywhere stores 5000.0000 instead of 5000 in db
            Assert.assertEquals(new BigDecimal(customer_id * increaseFactor).toString(),
                    cost_price.toString().substring(0, 4));
        } else {
            Assert.assertEquals(new BigDecimal(customer_id * increaseFactor).toString(), cost_price.toString());
        }

        Assert.assertEquals(true, is_delivered);

        Assert.assertEquals(customer_id * increaseFactor * 2, quantity);

        i = 1;
        customer_id = rs.getInt(i++);
        item_id = rs.getInt(i++);
        description = rs.getString(i++);
        int iForCostPrice = i;
        cost_price = rs.getBigDecimal(i++);
        cost_price_scale = rs.getBigDecimal(iForCostPrice, 5);
        date_placed = rs.getDate(i++);
        date_shipped = rs.getTimestamp(i++);

        // NO! do not read twice the same file ==> has been delete at first
        // read
        // jpeg_image = rs.getBytes(i++);
        i++;

        is_delivered = rs.getBoolean(i++);
        quantity = rs.getInt(i++);

        MessageDisplayer.display("");
        MessageDisplayer.display("customer_id     : " + customer_id);
        MessageDisplayer.display("item_id         : " + item_id);
        MessageDisplayer.display("description     : " + description);
        MessageDisplayer.display("cost_price      : " + cost_price);
        MessageDisplayer.display("cost_price_scale: " + cost_price_scale);
        MessageDisplayer.display("date_placed     : " + date_placed);
        MessageDisplayer.display("date_shipped    : " + date_shipped);
        MessageDisplayer.display("jpeg_image      : " + jpeg_image);
        MessageDisplayer.display("is_delivered    : " + is_delivered);
        MessageDisplayer.display("quantity        : " + quantity);

        // Assert done on first 18 chars (ex: 2011-11-02 16:26:14), because
        // MySql Truncs
        // the remaining milliseconds
        Assert.assertEquals(date_shipped.toString().substring(0, 18),
                dateShippedUpdated.toString().substring(0, 18));

        if (new SqlUtil(connection).isSQLAnywhere()) {
            // Because SQLK Anywhere stores 5000.0000 instead of 5000 in db
            Assert.assertEquals(new BigDecimal(customer_id * increaseFactor).toString(),
                    cost_price.toString().substring(0, 4));
        } else {
            Assert.assertEquals(new BigDecimal(customer_id * increaseFactor).toString(), cost_price.toString());
        }

        Assert.assertEquals(true, is_delivered);
        Assert.assertEquals(new Integer(customer_id * increaseFactor * 2), new Integer(quantity));
    }

    prepStatement.close();
    rs.close();

    MessageDisplayer.display("Select done!");

}

From source file:org.kuali.ole.select.document.OleInvoiceDocument.java

@Override
public void prepareForSave(KualiDocumentEvent event) {
    // TODO Auto-generated method stub
    // first populate, then call super
    if (event instanceof AttributedContinuePurapEvent) {
        SpringContext.getBean(OleInvoiceService.class).populateInvoice(this);
    }//from   w w  w. j  a v  a 2 s  .  c  om
    if (this.getVendorPaymentTermsCode() != null && this.getVendorPaymentTermsCode().isEmpty()) {
        this.setVendorPaymentTermsCode(null);
    }
    super.prepareForSave(event);
    try {
        if (this.proformaIndicator && !this.immediatePaymentIndicator) {
            this.setImmediatePaymentIndicator(true);
        }
        LOG.debug("###########Inside OleInvoiceDocument " + "repareForSave###########");
        List<OleInvoiceItem> items = new ArrayList<OleInvoiceItem>();
        items = this.getItems();
        Iterator iterator = items.iterator();
        HashMap dataMap = new HashMap();
        String titleId;
        while (iterator.hasNext()) {
            LOG.debug("###########inside prepareForSave item loop###########");
            Object object = iterator.next();
            if (object instanceof OleInvoiceItem) {
                LOG.debug("###########inside prepareForSave ole payment request item###########");
                OleInvoiceItem singleItem = (OleInvoiceItem) object;
                if (StringUtils.isNotBlank(this.invoiceCurrencyType)) {
                    this.setInvoiceCurrencyTypeId(new Long(this.getInvoiceCurrencyType()));
                    String currencyType = SpringContext.getBean(OleInvoiceService.class)
                            .getCurrencyType(this.getInvoiceCurrencyType());
                    if (StringUtils.isNotBlank(currencyType)) {
                        if (!currencyType.equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)) {
                            if (StringUtils.isNotBlank(this.getInvoiceCurrencyExchangeRate())) {
                                try {
                                    Double.parseDouble(this.getInvoiceCurrencyExchangeRate());
                                    singleItem.setItemExchangeRate(
                                            new KualiDecimal(this.getInvoiceCurrencyExchangeRate()));
                                    singleItem.setExchangeRate(this.getInvoiceCurrencyExchangeRate());
                                } catch (NumberFormatException nfe) {
                                    throw new RuntimeException("Invalid Exchange Rate", nfe);
                                }
                            } else {
                                BigDecimal exchangeRate = SpringContext.getBean(OleInvoiceService.class)
                                        .getExchangeRate(this.getInvoiceCurrencyType()).getExchangeRate();
                                this.setInvoiceCurrencyExchangeRate(exchangeRate.toString());
                                singleItem.setItemExchangeRate(new KualiDecimal(exchangeRate));
                                singleItem.setExchangeRate(exchangeRate.toString());
                            }
                            this.setVendorInvoiceAmount(this.getForeignVendorInvoiceAmount() != null
                                    ? new KualiDecimal(this.getForeignVendorInvoiceAmount().divide(
                                            new BigDecimal(singleItem.getExchangeRate()), 4,
                                            RoundingMode.HALF_UP))
                                    : null);
                        }
                    }
                }
                setItemDescription(singleItem);
                Map<String, String> copyCriteria = new HashMap<String, String>();
                if (singleItem.getPaidCopies().size() <= 0 && singleItem.getPoItemIdentifier() != null
                        && (this.getPurapDocumentIdentifier() != null
                                && singleItem.getItemIdentifier() != null)) {
                    copyCriteria.put("poItemId", singleItem.getPoItemIdentifier().toString());
                    List<OleCopy> copies = (List<OleCopy>) getBusinessObjectService()
                            .findMatching(OleCopy.class, copyCriteria);
                    if (copies.size() > 0) {
                        List<OLEPaidCopy> paidCopies = new ArrayList<OLEPaidCopy>();
                        for (OleCopy copy : copies) {
                            OLEPaidCopy paidCopy = new OLEPaidCopy();
                            paidCopy.setCopyId(copy.getCopyId());
                            paidCopy.setInvoiceItemId(this.getPurapDocumentIdentifier());
                            paidCopy.setInvoiceIdentifier(singleItem.getItemIdentifier());
                            //copy.getOlePaidCopies().add(paidCopy);
                            paidCopies.add(paidCopy);
                        }
                        getBusinessObjectService().save(paidCopies);
                        singleItem.setPaidCopies(paidCopies);
                    }
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Exception during prepareForSave() in OleInvoiceDocument", e);
        throw new RuntimeException(e);
    }
}

From source file:com.cloud.storage.StorageManagerImpl.java

private boolean checkPoolforSpace(StoragePool pool, long allocatedSizeWithTemplate, long totalAskingSize) {
    // allocated space includes templates
    StoragePoolVO poolVO = _storagePoolDao.findById(pool.getId());

    long totalOverProvCapacity;

    if (pool.getPoolType().supportsOverProvisioning()) {
        BigDecimal overProvFactor = getStorageOverProvisioningFactor(pool.getId());

        totalOverProvCapacity = overProvFactor.multiply(new BigDecimal(pool.getCapacityBytes())).longValue();

        s_logger.debug("Found storage pool " + poolVO.getName() + " of type " + pool.getPoolType().toString()
                + " with over-provisioning factor " + overProvFactor.toString());
        s_logger.debug("Total over-provisioned capacity calculated is " + overProvFactor + " * "
                + pool.getCapacityBytes());
    } else {/*from www .  ja  va  2s . c  om*/
        totalOverProvCapacity = pool.getCapacityBytes();

        s_logger.debug("Found storage pool " + poolVO.getName() + " of type " + pool.getPoolType().toString());
    }

    s_logger.debug("Total capacity of the pool " + poolVO.getName() + " with ID " + pool.getId() + " is "
            + totalOverProvCapacity);

    double storageAllocatedThreshold = CapacityManager.StorageAllocatedCapacityDisableThreshold
            .valueIn(pool.getDataCenterId());

    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Checking pool: " + pool.getId() + " for storage allocation , maxSize : "
                + totalOverProvCapacity + ", totalAllocatedSize : " + allocatedSizeWithTemplate
                + ", askingSize : " + totalAskingSize + ", allocated disable threshold: "
                + storageAllocatedThreshold);
    }

    double usedPercentage = (allocatedSizeWithTemplate + totalAskingSize) / (double) (totalOverProvCapacity);

    if (usedPercentage > storageAllocatedThreshold) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Insufficient un-allocated capacity on: " + pool.getId()
                    + " for storage allocation since its allocated percentage: " + usedPercentage
                    + " has crossed the allocated pool.storage.allocated.capacity.disablethreshold: "
                    + storageAllocatedThreshold + ", skipping this pool");
        }

        return false;
    }

    if (totalOverProvCapacity < (allocatedSizeWithTemplate + totalAskingSize)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Insufficient un-allocated capacity on: " + pool.getId()
                    + " for storage allocation, not enough storage, maxSize : " + totalOverProvCapacity
                    + ", totalAllocatedSize : " + allocatedSizeWithTemplate + ", askingSize : "
                    + totalAskingSize);
        }

        return false;
    }

    return true;
}

From source file:com.cloud.storage.StorageManagerImpl.java

@Override
public void createCapacityEntry(StoragePoolVO storagePool, short capacityType, long allocated) {
    SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
    capacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, storagePool.getId());
    capacitySC.addAnd("dataCenterId", SearchCriteria.Op.EQ, storagePool.getDataCenterId());
    capacitySC.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType);

    List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);

    long totalOverProvCapacity;
    if (storagePool.getPoolType().supportsOverProvisioning()) {
        // All this is for the inaccuracy of floats for big number multiplication.
        BigDecimal overProvFactor = getStorageOverProvisioningFactor(storagePool.getId());
        totalOverProvCapacity = overProvFactor.multiply(new BigDecimal(storagePool.getCapacityBytes()))
                .longValue();// ww w.  jav  a2  s .c o m
        s_logger.debug("Found storage pool " + storagePool.getName() + " of type "
                + storagePool.getPoolType().toString() + " with overprovisioning factor "
                + overProvFactor.toString());
        s_logger.debug("Total over provisioned capacity calculated is " + overProvFactor + " * "
                + storagePool.getCapacityBytes());
    } else {
        s_logger.debug("Found storage pool " + storagePool.getName() + " of type "
                + storagePool.getPoolType().toString());
        totalOverProvCapacity = storagePool.getCapacityBytes();
    }

    s_logger.debug("Total over provisioned capacity of the pool " + storagePool.getName() + " id: "
            + storagePool.getId() + " is " + totalOverProvCapacity);
    CapacityState capacityState = CapacityState.Enabled;
    if (storagePool.getScope() == ScopeType.ZONE) {
        DataCenterVO dc = ApiDBUtils.findZoneById(storagePool.getDataCenterId());
        AllocationState allocationState = dc.getAllocationState();
        capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled
                : CapacityState.Enabled;
    } else {
        if (storagePool.getClusterId() != null) {
            ClusterVO cluster = ApiDBUtils.findClusterById(storagePool.getClusterId());
            if (cluster != null) {
                AllocationState allocationState = _configMgr.findClusterAllocationState(cluster);
                capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled
                        : CapacityState.Enabled;
            }
        }
    }

    if (storagePool.getScope() == ScopeType.HOST) {
        List<StoragePoolHostVO> stoargePoolHostVO = _storagePoolHostDao.listByPoolId(storagePool.getId());

        if (stoargePoolHostVO != null && !stoargePoolHostVO.isEmpty()) {
            HostVO host = _hostDao.findById(stoargePoolHostVO.get(0).getHostId());

            if (host != null) {
                capacityState = (host.getResourceState() == ResourceState.Disabled) ? CapacityState.Disabled
                        : CapacityState.Enabled;
            }
        }
    }

    if (capacities.size() == 0) {
        CapacityVO capacity = new CapacityVO(storagePool.getId(), storagePool.getDataCenterId(),
                storagePool.getPodId(), storagePool.getClusterId(), allocated, totalOverProvCapacity,
                capacityType);
        capacity.setCapacityState(capacityState);
        _capacityDao.persist(capacity);
    } else {
        CapacityVO capacity = capacities.get(0);
        if (capacity.getTotalCapacity() != totalOverProvCapacity || allocated != capacity.getUsedCapacity()
                || capacity.getCapacityState() != capacityState) {
            capacity.setTotalCapacity(totalOverProvCapacity);
            capacity.setUsedCapacity(allocated);
            capacity.setCapacityState(capacityState);
            _capacityDao.update(capacity.getId(), capacity);
        }
    }
    s_logger.debug("Successfully set Capacity - " + totalOverProvCapacity + " for capacity type - "
            + capacityType + " , DataCenterId - " + storagePool.getDataCenterId() + ", HostOrPoolId - "
            + storagePool.getId() + ", PodId " + storagePool.getPodId());
}

From source file:it.govpay.web.rs.dars.monitoraggio.pagamenti.PagamentiHandler.java

public Map<String, Voce<String>> getVociRevoca(Pagamento entry, BasicBD bd) throws ConsoleException {
    Map<String, Voce<String>> valori = new HashMap<String, Voce<String>>();

    String statoPagamento = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".statoPagamento.ok");
    String statoPagamentoLabel = Utils.getInstance(this.getLanguage())
            .getMessageFromResourceBundle(this.nomeServizio + ".statoPagamento.ok");
    BigDecimal importo = entry.getImportoRevocato() != null ? entry.getImportoRevocato() : BigDecimal.ZERO;

    Date dataAcquisizioneRevoca = entry.getDataAcquisizioneRevoca();
    String dataRevocaFormat = dataAcquisizioneRevoca != null ? this.sdf.format(dataAcquisizioneRevoca) : "--";
    if (entry.getIdRr() != null) {
        statoPagamento = Utils.getInstance(this.getLanguage())
                .getMessageFromResourceBundle(this.nomeServizio + ".statoPagamento.revocato");
        statoPagamentoLabel = Utils.getInstance(this.getLanguage()).getMessageWithParamsFromResourceBundle(
                this.nomeServizio + ".label.sottotitolo.revocato", dataRevocaFormat);
    }//from w ww  .ja  va  2 s.  co  m

    valori.put(
            Utils.getInstance(this.getLanguage())
                    .getMessageFromResourceBundle(this.nomeServizio + ".statoPagamento.id"),
            new Voce<String>(statoPagamentoLabel, statoPagamento));

    valori.put(
            Utils.getInstance(this.getLanguage())
                    .getMessageFromResourceBundle(this.nomeServizio + ".importoPagato.id"),
            new Voce<String>(Utils.getInstance(this.getLanguage()).getMessageFromResourceBundle(
                    this.nomeServizio + ".importoRevocato.label"), importo.toString() + ""));

    if (dataAcquisizioneRevoca != null) {
        valori.put(
                Utils.getInstance(this.getLanguage())
                        .getMessageFromResourceBundle(this.nomeServizio + ".dataPagamento.id"),
                new Voce<String>(Utils.getInstance(this.getLanguage()).getMessageFromResourceBundle(
                        this.nomeServizio + ".dataAcquisizioneRevoca.label"), dataRevocaFormat));
    }

    if (entry.getIur() != null) {
        valori.put(
                Utils.getInstance(this.getLanguage())
                        .getMessageFromResourceBundle(this.nomeServizio + ".iur.id"),
                new Voce<String>(Utils.getInstance(this.getLanguage())
                        .getMessageFromResourceBundle(this.nomeServizio + ".iur.label"), entry.getIur()));
    }

    try {
        SingoloVersamento singoloVersamento = entry.getSingoloVersamento(bd);
        if (singoloVersamento != null) {
            valori.put(
                    Utils.getInstance(this.getLanguage())
                            .getMessageFromResourceBundle(this.nomeServizio + ".codSingoloVersamentoEnte.id"),
                    new Voce<String>(
                            Utils.getInstance(this.getLanguage()).getMessageFromResourceBundle(
                                    this.nomeServizio + ".codSingoloVersamentoEnte.label"),
                            singoloVersamento.getCodSingoloVersamentoEnte()));
        }
    } catch (ServiceException e) {
        throw new ConsoleException(e);
    }
    return valori;
}