Esempio n. 1
0
        /// <summary>
        /// GetAcctSchema Detail
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public Dictionary <String, String> GetAcctSchema(Ctx ctx, string fields)
        {
            string[] paramValue = fields.Split(',');
            int      C_AcctSchema_ID;
            Dictionary <String, String> retDic = new Dictionary <string, string>();

            //Assign parameter value
            C_AcctSchema_ID = Util.GetValueOfInt(paramValue[0].ToString());
            //End Assign parameter value
            MAcctSchema aas = MAcctSchema.Get(ctx, C_AcctSchema_ID);

            retDic["StdPrecision"]  = aas.GetStdPrecision().ToString();
            retDic["C_Currency_ID"] = aas.GetC_Currency_ID().ToString();
            return(retDic);
        }
Esempio n. 2
0
        /// <summary>
        /// Load Invoice Line
        /// </summary>
        /// <param name="journal"></param>
        /// <returns>DocLine Array</returns>
        private DocLine[] LoadLines(MJournal journal)
        {
            MAcctSchema    mSc  = new MAcctSchema(GetCtx(), _C_AcctSchema_ID, null);
            List <DocLine> list = new List <DocLine>();

            MJournalLine[] lines = journal.GetLines(false);
            record_Id = lines[0].GetGL_Journal_ID();

            for (int i = 0; i < lines.Length; i++)
            {
                MJournalLine line = lines[i];

                if (line.GetElementType() == null)
                {
                    DocLine docLine = new DocLine(line, this);
                    //  --  Source Amounts
                    docLine.SetAmount(line.GetAmtAcctDr(), line.GetAmtAcctCr());
                    //  --  Converted Amounts
                    // no need to update converted amount here
                    //docLine.SetConvertedAmt(_C_AcctSchema_ID, line.GetAmtAcctDr(), line.GetAmtAcctCr());
                    //  --  Account
                    MAccount account = line.GetAccount();
                    docLine.SetAccount(account);
                    //  -- Quantity
                    docLine.SetQty(line.GetQty(), false);
                    // -- Date
                    docLine.SetDateAcct(journal.GetDateAcct());
                    //	--	Organization of Line was set to Org of Account
                    list.Add(docLine);
                }
                else
                {
                    string  sql = "SELECT * FROM GL_LineDimension WHERE GL_JournalLine_ID=" + line.Get_ID();
                    DataSet ds  = DB.ExecuteDataset(sql);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        for (int m = 0; m < ds.Tables[0].Rows.Count; m++)
                        {
                            DataRow            dr   = ds.Tables[0].Rows[m];
                            X_GL_LineDimension lDim = new X_GL_LineDimension(GetCtx(), dr, null);

                            DocLine docLine = new DocLine(lDim, this);
                            //  --  Source Amounts


                            decimal cRate = line.GetCurrencyRate();
                            if (cRate == 0)
                            {
                                cRate = 1;
                            }
                            decimal amtAcctCr = 0;
                            decimal amtAcctDr = 0;

                            //MAcctSchema mSc = new MAcctSchema(GetCtx(), _C_AcctSchema_ID, null);


                            if (line.GetAmtSourceDr() != 0)
                            {
                                amtAcctDr = lDim.GetAmount() * cRate;
                                docLine.SetAmount(amtAcctDr, 0);
                                amtAcctDr = Decimal.Round(amtAcctDr, mSc.GetStdPrecision());
                            }
                            else
                            {
                                amtAcctCr = lDim.GetAmount() * cRate;
                                docLine.SetAmount(0, amtAcctCr);
                                amtAcctCr = Decimal.Round(amtAcctCr, mSc.GetStdPrecision());
                            }
                            //  --  Converted Amounts
                            // no need to update converted amount here
                            //docLine.SetConvertedAmt(_C_AcctSchema_ID, amtAcctDr, amtAcctCr);
                            //  --  Account
                            MAccount account = line.GetAccount();


                            docLine.SetAccount(account);
                            //  -- Quantity
                            docLine.SetQty(lDim.GetQty(), false);
                            // -- Date
                            docLine.SetDateAcct(journal.GetDateAcct());

                            // -- User Dimension
                            docLine = SetUserDimension(lDim, docLine);

                            //	--	Organization of Line was set to Org of Account
                            list.Add(docLine);
                        }
                    }
                }
            }
            //	Return Array
            int size = list.Count;

            DocLine[] dls = new DocLine[size];
            dls = list.ToArray();
            return(dls);
        }
Esempio n. 3
0
        /// <summary>
        /// Create Accounting Entries
        /// </summary>
        /// <param name="as1">account schema</param>
        /// <param name="fact">fact to add lines</param>
        /// <param name="line">line</param>
        /// <returns>true if created</returns>
        public bool CreateEntries(MAcctSchema as1, Fact fact, DocLine line)
        {
            //	get total index (the Receivables/Liabilities line)
            Decimal total = Env.ZERO;

            for (int i = 0; i < _facts.Count; i++)
            {
                MFactAcct factAcct = (MFactAcct)_facts[i];
                if (factAcct.GetAmtSourceDr().CompareTo(total) > 0)
                {
                    total       = factAcct.GetAmtSourceDr();
                    _totalIndex = i;
                }
                if (factAcct.GetAmtSourceCr().CompareTo(total) > 0)
                {
                    total       = factAcct.GetAmtSourceCr();
                    _totalIndex = i;
                }
            }

            MFactAcct factAcct1 = (MFactAcct)_facts[_totalIndex];

            log.Info("Total Invoice = " + total + " - " + factAcct1);
            int precision = as1.GetStdPrecision();

            for (int i = 0; i < _facts.Count; i++)
            {
                //	No Tax Line
                if (i == _totalIndex)
                {
                    continue;
                }

                factAcct1 = (MFactAcct)_facts[i];
                log.Info(i + ": " + factAcct1);

                //	Create Tax Account
                MAccount taxAcct = factAcct1.GetMAccount();
                if (taxAcct == null || taxAcct.Get_ID() == 0)
                {
                    log.Severe("Tax Account not found/created");
                    return(false);
                }


                //	Discount Amount
                if (Env.Signum(_DiscountAmt) != 0)
                {
                    //	Original Tax is DR - need to correct it CR
                    if (Env.ZERO.CompareTo(factAcct1.GetAmtSourceDr()) != 0)
                    {
                        Decimal amount = CalcAmount(factAcct1.GetAmtSourceDr(),
                                                    total, _DiscountAmt, precision);
                        if (Env.Signum(amount) != 0)
                        {
                            fact.CreateLine(line, _DiscountAccount,
                                            as1.GetC_Currency_ID(), amount, null);
                            fact.CreateLine(line, taxAcct,
                                            as1.GetC_Currency_ID(), null, amount);
                        }
                    }
                    //	Original Tax is CR - need to correct it DR
                    else
                    {
                        Decimal amount = CalcAmount(factAcct1.GetAmtSourceCr(),
                                                    total, _DiscountAmt, precision);
                        if (Env.Signum(amount) != 0)
                        {
                            fact.CreateLine(line, taxAcct,
                                            as1.GetC_Currency_ID(), amount, null);
                            fact.CreateLine(line, _DiscountAccount,
                                            as1.GetC_Currency_ID(), null, amount);
                        }
                    }
                }       //	Discount

                //	WriteOff Amount
                if (Env.Signum(_WriteOffAmt) != 0)
                {
                    //	Original Tax is DR - need to correct it CR
                    if (Env.ZERO.CompareTo(factAcct1.GetAmtSourceDr()) != 0)
                    {
                        Decimal amount = CalcAmount(factAcct1.GetAmtSourceDr(),
                                                    total, _WriteOffAmt, precision);
                        if (Env.Signum(amount) != 0)
                        {
                            fact.CreateLine(line, _WriteOffAccount,
                                            as1.GetC_Currency_ID(), amount, null);
                            fact.CreateLine(line, taxAcct,
                                            as1.GetC_Currency_ID(), null, amount);
                        }
                    }
                    //	Original Tax is CR - need to correct it DR
                    else
                    {
                        Decimal amount = CalcAmount(factAcct1.GetAmtSourceCr(),
                                                    total, _WriteOffAmt, precision);
                        if (Env.Signum(amount) != 0)
                        {
                            fact.CreateLine(line, taxAcct,
                                            as1.GetC_Currency_ID(), amount, null);
                            fact.CreateLine(line, _WriteOffAccount,
                                            as1.GetC_Currency_ID(), null, amount);
                        }
                    }
                } //	WriteOff
            }     //	for all lines
            return(true);
        }