Beispiel #1
0
        /// <summary>
        /// Create and convert Fact Line.
        /// Used to create a DR and/or CR entry
        /// </summary>
        /// <param name="docLine">the document line or null</param>
        /// <param name="account">if null, line is not created</param>
        /// <param name="C_Currency_ID">the currency</param>
        /// <param name="debitAmt">debit amount, can be null</param>
        /// <param name="creditAmt">credit amount, can be null</param>
        /// <returns>Fact Line</returns>
        public FactLine CreateLine(DocLine docLine, MAccount account, int C_Currency_ID, Decimal?debitAmt, Decimal?creditAmt)
        {
            //  Data Check
            if (account == null)
            {
                log.Info("No account for " + docLine + ": Amt=" + debitAmt + "/" + creditAmt
                         + " - " + ToString());
                return(null);
            }

            //Added By Bharat to Handle -ve entry

            if (debitAmt < 0)
            {
                creditAmt = Decimal.Negate(debitAmt.Value);
                debitAmt  = 0;
            }
            else if (creditAmt < 0)
            {
                debitAmt  = Decimal.Negate(creditAmt.Value);
                creditAmt = 0;
            }

            //
            FactLine line = new FactLine(_doc.GetCtx(), _doc.Get_Table_ID(),
                                         _doc.Get_ID(),
                                         docLine == null ? 0 : docLine.Get_ID(), _trx);

            // set accounting schema reference
            line.SetC_AcctSchema_ID(_acctSchema.GetC_AcctSchema_ID());
            //  Set Info & Account
            line.SetDocumentInfo(_doc, docLine);
            line.SetPostingType(_postingType);
            line.SetAccount(_acctSchema, account);
            //  Amounts - one needs to not zero
            if (!line.SetAmtSource(C_Currency_ID, debitAmt, creditAmt))
            {
                if (docLine == null || docLine.GetQty() == null || Env.Signum(Utility.Util.GetValueOfDecimal(docLine.GetQty())) == 0)
                {
                    log.Fine("Both amounts & qty = 0/Null - " + docLine
                             + " - " + ToString());
                    return(null);
                }
                log.Fine("Both amounts = 0/Null, Qty=" + docLine.GetQty() + " - " + docLine
                         + " - " + ToString());
            }
            //  Convert
            line.Convert();
            //  Optionally overwrite Acct Amount
            if (docLine != null &&
                (docLine.GetAmtAcctDr() != null || docLine.GetAmtAcctCr() != null))
            {
                line.SetAmtAcct(docLine.GetAmtAcctDr(), docLine.GetAmtAcctCr());
            }
            //
            log.Fine(line.ToString());
            Add(line);
            return(line);
        }
        /// <summary>
        /// Create and convert Fact Line.
        /// Used to create a DR and/or CR entry
        /// </summary>
        /// <param name="docLine">the document line or null</param>
        /// <param name="account">if null, line is not created</param>
        /// <param name="C_Currency_ID">the currency</param>
        /// <param name="debitAmt">debit amount, can be null</param>
        /// <param name="creditAmt">credit amount, can be null</param>
        /// <returns>Fact Line</returns>
        public FactLine CreateLine(DocLine docLine, MAccount account, int C_Currency_ID, Decimal?debitAmt, Decimal?creditAmt, int AD_Org_ID)
        {
            //  Data Check
            if (account == null)
            {
                log.Info("No account for " + docLine + ": Amt=" + debitAmt + "/" + creditAmt
                         + " - " + ToString());
                return(null);
            }
            //
            FactLine line = new FactLine(_doc.GetCtx(), _doc.Get_Table_ID(),
                                         _doc.Get_ID(),
                                         docLine == null ? 0 : (docLine.GetPrimaryKeyValue != 0 ? docLine.GetPrimaryKeyValue : docLine.Get_ID()), _trx);

            //  Set Info & Account
            line.SetDocumentInfo(_doc, docLine);
            line.SetPostingType(_postingType);
            line.SetAccount(_acctSchema, account);
            if (AD_Org_ID > 0)
            {
                line.SetAD_Org_ID(AD_Org_ID);
            }
            //  Amounts - one needs to not zero
            if (!line.SetAmtSource(C_Currency_ID, debitAmt, creditAmt))
            {
                if (docLine == null || docLine.GetQty() == null || Env.Signum(Utility.Util.GetValueOfDecimal(docLine.GetQty())) == 0)
                {
                    log.Fine("Both amounts & qty = 0/Null - " + docLine
                             + " - " + ToString());
                    return(null);
                }
                log.Fine("Both amounts = 0/Null, Qty=" + docLine.GetQty() + " - " + docLine
                         + " - " + ToString());
            }
            //  Convert
            line.Convert();
            //  Optionally overwrite Acct Amount
            if (docLine != null &&
                (docLine.GetAmtAcctDr() != null || docLine.GetAmtAcctCr() != null))
            {
                line.SetAmtAcct(docLine.GetAmtAcctDr(), docLine.GetAmtAcctCr());
            }
            //
            log.Fine(line.ToString());
            Add(line);
            return(line);
        }