Пример #1
0
        private FinancialPrepaidExpenseSummary_Fact CreateFinancialPrepaidExpenseSummaryFact(Session session,
                                                                                             Guid OwnerOrgId,
                                                                                             DateTime IssueDate,
                                                                                             string FinancialAccountCode,
                                                                                             bool IsBalanceForward)
        {
            FinancialPrepaidExpenseSummary_Fact result = new FinancialPrepaidExpenseSummary_Fact(session);

            try
            {
                ETLAccountingBO accountingBO = new ETLAccountingBO();
                DimBO           dimBO        = new DimBO();
                result.BeginCreditBalance    = 0;
                result.BeginDebitBalance     = 0;
                result.CreditSum             = 0;
                result.DebitSum              = 0;
                result.EndCreditBalance      = 0;
                result.EndDebitBalance       = 0;
                result.FinancialAccountDimId = accountingBO.GetFinancialAccountDim(session, FinancialAccountCode);
                result.MonthDimId            = dimBO.GetMonthDim(session, (short)IssueDate.Month);
                result.YearDimId             = dimBO.GetYearDim(session, (short)IssueDate.Year);
                result.OwnerOrgDimId         = dimBO.GetOwnerOrgDim(session, OwnerOrgId);
                result.RowStatus             = Constant.ROWSTATUS_ACTIVE;
                if (result.FinancialAccountDimId == null ||
                    result.MonthDimId == null ||
                    result.YearDimId == null ||
                    result.OwnerOrgDimId == null)
                {
                    return(null);
                }

                var date = new DateTime(IssueDate.Year, IssueDate.Month, 1);
                FinancialPrepaidExpenseSummary_Fact previousSummary = GetFinancialPrepaidExpenseSummaryFact(session,
                                                                                                            OwnerOrgId, date.AddMonths(-1), FinancialAccountCode);

                if (previousSummary != null)
                {
                    result.BeginDebitBalance  = previousSummary.EndDebitBalance;
                    result.BeginCreditBalance = previousSummary.EndCreditBalance;
                }

                result.Save();
                return(result);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Пример #2
0
        private FinancialPrepaidExpenseSummary_Fact GetFinancialPrepaidExpenseSummaryFact(
            Session session,
            Guid OwnerOrgId,
            DateTime IssueDate,
            string FinancialAccountCode)
        {
            FinancialPrepaidExpenseSummary_Fact result = null;

            try
            {
                Util                util                = new Util();
                OwnerOrgDim         ownerOrgDim         = util.GetXpoObjectByFieldName <OwnerOrgDim, Guid>(session, "RefId", OwnerOrgId, BinaryOperatorType.Equal);
                MonthDim            monthDim            = util.GetXpoObjectByFieldName <MonthDim, string>(session, "Name", IssueDate.Month.ToString(), BinaryOperatorType.Equal);
                YearDim             yearDim             = util.GetXpoObjectByFieldName <YearDim, string>(session, "Name", IssueDate.Year.ToString(), BinaryOperatorType.Equal);
                FinancialAccountDim financialAccountDim = util.GetXpoObjectByFieldName <FinancialAccountDim, string>(session, "Code", FinancialAccountCode, BinaryOperatorType.Equal);

                if (ownerOrgDim == null || monthDim == null || yearDim == null || financialAccountDim == null)
                {
                    return(null);
                }
                else
                {
                    FinancialPrepaidExpenseSummary_Fact a = null;
                    CriteriaOperator criteria_RowStatus   = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual);
                    CriteriaOperator criteria_OwnerOrg    = new BinaryOperator("OwnerOrgDimId", ownerOrgDim, BinaryOperatorType.Equal);
                    CriteriaOperator criteria_Month       = new BinaryOperator("MonthDimId", monthDim, BinaryOperatorType.Equal);
                    CriteriaOperator criteria_Year        = new BinaryOperator("YearDimId", yearDim, BinaryOperatorType.Equal);
                    CriteriaOperator criteria_AccountCode = new BinaryOperator("FinancialAccountDimId", financialAccountDim, BinaryOperatorType.Equal);
                    CriteriaOperator criteria             = CriteriaOperator.And(criteria_RowStatus, criteria_OwnerOrg, criteria_Month, criteria_Year, criteria_AccountCode);

                    FinancialPrepaidExpenseSummary_Fact fact = session.FindObject <FinancialPrepaidExpenseSummary_Fact>(criteria);

                    if (fact == null)
                    {
                        return(null);
                    }
                    {
                        result = fact;
                    }
                }
            }
            catch (Exception)
            {
                return(result);
            }
            return(result);
        }
Пример #3
0
        public void FixInvokedBussinessObjects(Session session, XPCollection <DAL.System.Log.BusinessObject> invokedBussinessObjects)
        {
            if (invokedBussinessObjects == null || invokedBussinessObjects.Count == 0)
            {
                return;
            }

            CriteriaOperator criteria_0 = CriteriaOperator.Parse("not(IsNull(FinancialTransactionDimId))");
            CriteriaOperator criteria_1 = new InOperator("FinancialTransactionDimId.RefId", invokedBussinessObjects.Select(i => i.RefId));
            CriteriaOperator criteria_2 = new BinaryOperator("RowStatus", 0, BinaryOperatorType.Greater);
            CriteriaOperator criteria   = new GroupOperator(GroupOperatorType.And, criteria_0, criteria_1, criteria_2);
            CorrespondFinancialAccountDim defaultAccDim = CorrespondFinancialAccountDim.GetDefault(session, CorrespondFinancialAccountDimEnum.NAAN_DEFAULT);

            XPCollection <FinancialPrepaidExpenseDetail> neededToBeFixList = new XPCollection <FinancialPrepaidExpenseDetail>(session, criteria);
            FinancialPrepaidExpenseSummary_Fact          fact = null;

            if (neededToBeFixList != null && neededToBeFixList.Count > 0)
            {
                foreach (FinancialPrepaidExpenseDetail detail in neededToBeFixList)
                {
                    fact             = detail.FinancialPrepaidExpenseSummary_FactId;
                    detail.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                    detail.Save();
                    //if (defaultAccDim != null && detail.CorrespondFinancialAccountDimId != null
                    //    && detail.CorrespondFinancialAccountDimId.Code.Equals(defaultAccDim.Code))
                    //{
                    //    fact.CreditSum -= detail.Credit;
                    //    fact.DebitSum -= detail.Debit;
                    //}

                    //fact.EndCreditBalance
                    //        = fact.BeginCreditBalance +
                    //        fact.CreditSum -
                    //        fact.DebitSum;

                    //fact.EndDebitBalance
                    //    = fact.BeginDebitBalance +
                    //    fact.DebitSum -
                    //    fact.CreditSum;

                    //fact.Save();
                }
            }
        }
Пример #4
0
        public List <string> header_debit_correspond()
        {
            List <string> debit_correspond = new List <string>();

            #region tham số
            int    month    = Int32.Parse(this.hS04b6DN_month.Get("month_id").ToString());
            int    year     = Int32.Parse(this.hS04b6DN_year.Get("year_id").ToString());
            string owner    = "QUASAPHARCO";
            string fAccount = this.hS04b6dnAccount.Get("account_id").ToString();
            #endregion

            #region object
            MonthDim    md  = session.FindObject <MonthDim>(CriteriaOperator.Parse(String.Format("Name='{0}'", month)));
            YearDim     yd  = session.FindObject <YearDim>(CriteriaOperator.Parse(String.Format("Name='{0}'", year)));
            OwnerOrgDim ood = session.FindObject <OwnerOrgDim>(CriteriaOperator.Parse(String.Format("Code='{0}'",
                                                                                                    owner)));
            int CorrespondFinancialAccountDimId_default = CorrespondFinancialAccountDim.GetDefault(session,
                                                                                                   CorrespondFinancialAccountDimEnum.NAAN_DEFAULT).CorrespondFinancialAccountDimId;
            string rowStatusActive = Utility.Constant.ROWSTATUS_ACTIVE.ToString();
            #endregion

            //// tk 142
            XPCollection <FinancialAccountDim> f_c_FinancialAccountDim = new XPCollection <FinancialAccountDim>(session,
                                                                                                                CriteriaOperator.Parse(String.Format("Code like '{0}%' AND RowStatus='{1}'", fAccount, rowStatusActive)));
            if (f_c_FinancialAccountDim.Count != 0)
            {
                foreach (FinancialAccountDim each_tk in f_c_FinancialAccountDim)
                {
                    if (md != null && yd != null && ood != null)
                    {
                        FinancialPrepaidExpenseSummary_Fact FinancialSummary_Fact =
                            session.FindObject <FinancialPrepaidExpenseSummary_Fact>(CriteriaOperator.Parse(
                                                                                         String.Format("MonthDimId='{0}' AND "
                                                                                                       + "YearDimId='{1}' AND "
                                                                                                       + "OwnerOrgDimId='{2}' AND "
                                                                                                       + "FinancialAccountDimId='{3}' AND "
                                                                                                       + "RowStatus='{4}'",
                                                                                                       md.MonthDimId,
                                                                                                       yd.YearDimId,
                                                                                                       ood.OwnerOrgDimId,
                                                                                                       each_tk.FinancialAccountDimId,
                                                                                                       rowStatusActive
                                                                                                       )));
                        if (FinancialSummary_Fact != null)
                        {
                            XPCollection <FinancialPrepaidExpenseDetail> collec_detail =
                                new XPCollection <FinancialPrepaidExpenseDetail>(session, CriteriaOperator.Parse(
                                                                                     String.Format("FinancialPrepaidExpenseSummary_FactId='{0}' AND "
                                                                                                   + "Debit>0 AND "
                                                                                                   + "CorrespondFinancialAccountDimId!='{1}' AND "
                                                                                                   + "RowStatus='{2}'",
                                                                                                   FinancialSummary_Fact.FinancialPrepaidExpenseSummary_FactId,
                                                                                                   CorrespondFinancialAccountDimId_default,
                                                                                                   rowStatusActive
                                                                                                   )));
                            if (collec_detail.Count != 0)
                            {
                                foreach (FinancialPrepaidExpenseDetail each_detail in collec_detail)
                                {
                                    if (!debit_correspond.Contains(each_detail.CorrespondFinancialAccountDimId.Code))
                                    {
                                        debit_correspond.Add(each_detail.CorrespondFinancialAccountDimId.Code);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            ////
            debit_correspond.Sort();
            return(debit_correspond);
        }
Пример #5
0
        public void load_data()
        {
            WebModule.Accounting.Report.S04b6_DN s04b6_dn = new Report.S04b6_DN();
            #region tham số truyền
            int    month    = Int32.Parse(this.hS04b6DN_month.Get("month_id").ToString());
            int    year     = Int32.Parse(this.hS04b6DN_year.Get("year_id").ToString());
            string owner    = "QUASAPHARCO";
            string fAccount = this.hS04b6dnAccount.Get("account_id").ToString();
            //string asset = "";
            #endregion

            if (fAccount != "142" && fAccount != "242" && fAccount != "335")
            {
                return;
            }

            s04b6_dn.xrMonth.Text = month.ToString();
            s04b6_dn.xrYear.Text  = year.ToString();
            if (fAccount == "142" || fAccount == "242")
            {
                s04b6_dn.xrTitle.Text = String.Format("Tập hợp chi phí trả trước (TK {0})", fAccount);
            }
            if (fAccount == "335")
            {
                s04b6_dn.xrTitle.Text = String.Format("Tập hợp chi phí phải trả (TK {0})", fAccount);
            }

            try
            {
                #region object
                MonthDim    md  = session.FindObject <MonthDim>(CriteriaOperator.Parse(String.Format("Name='{0}'", month)));
                YearDim     yd  = session.FindObject <YearDim>(CriteriaOperator.Parse(String.Format("Name='{0}'", year)));
                OwnerOrgDim ood = session.FindObject <OwnerOrgDim>(CriteriaOperator.Parse(String.Format("Code='{0}'",
                                                                                                        owner)));
                int CorrespondFinancialAccountDimId_default = CorrespondFinancialAccountDim.GetDefault(session,
                                                                                                       CorrespondFinancialAccountDimEnum.NAAN_DEFAULT).CorrespondFinancialAccountDimId;
                string rowStatusActive = Utility.Constant.ROWSTATUS_ACTIVE.ToString();
                XPCollection <FinancialAccountDim> f_c_FinancialAccountDim = new XPCollection <FinancialAccountDim>(session,
                                                                                                                    CriteriaOperator.Parse(String.Format("Code like '{0}%' AND RowStatus='{1}'", fAccount, rowStatusActive)));

                #endregion

                #region header và table báo cáo
                grid_header();
                DataTable datatable = table_pri();
                #endregion

                #region all row list_transaction
                List <int> list_transaction = new List <int>();
                if (f_c_FinancialAccountDim.Count != 0)
                {
                    foreach (FinancialAccountDim each_tk in f_c_FinancialAccountDim)
                    {
                        if (md != null && yd != null && ood != null)
                        {
                            FinancialPrepaidExpenseSummary_Fact FinancialSummary_Fact =
                                session.FindObject <FinancialPrepaidExpenseSummary_Fact>(CriteriaOperator.Parse(
                                                                                             String.Format("MonthDimId='{0}' AND "
                                                                                                           + "YearDimId='{1}' AND "
                                                                                                           + "OwnerOrgDimId='{2}' AND "
                                                                                                           + "FinancialAccountDimId='{3}' AND "
                                                                                                           + "RowStatus='{4}'",
                                                                                                           md.MonthDimId,
                                                                                                           yd.YearDimId,
                                                                                                           ood.OwnerOrgDimId,
                                                                                                           each_tk.FinancialAccountDimId,
                                                                                                           rowStatusActive
                                                                                                           )));
                            if (FinancialSummary_Fact != null)
                            {
                                ////
                                XPCollection <FinancialPrepaidExpenseDetail> collec_detail_credit =
                                    new XPCollection <FinancialPrepaidExpenseDetail>(session, CriteriaOperator.Parse(
                                                                                         String.Format("FinancialPrepaidExpenseSummary_FactId='{0}' AND "
                                                                                                       + "Credit>0 AND "
                                                                                                       + "CorrespondFinancialAccountDimId!='{1}' AND "
                                                                                                       + "RowStatus='{2}'",
                                                                                                       FinancialSummary_Fact.FinancialPrepaidExpenseSummary_FactId,
                                                                                                       CorrespondFinancialAccountDimId_default,
                                                                                                       rowStatusActive
                                                                                                       )));
                                if (collec_detail_credit.Count != 0)
                                {
                                    foreach (FinancialPrepaidExpenseDetail each_detail in collec_detail_credit)
                                    {
                                        if (!list_transaction.Contains(each_detail.FinancialTransactionDimId.FinancialTransactionDimId))
                                        {
                                            list_transaction.Add(each_detail.FinancialTransactionDimId.FinancialTransactionDimId);
                                        }
                                    }
                                }
                                ////
                                XPCollection <FinancialPrepaidExpenseDetail> collec_detail_debit =
                                    new XPCollection <FinancialPrepaidExpenseDetail>(session, CriteriaOperator.Parse(
                                                                                         String.Format("FinancialPrepaidExpenseSummary_FactId='{0}' AND "
                                                                                                       + "Debit>0 AND "
                                                                                                       + "CorrespondFinancialAccountDimId!='{1}' AND "
                                                                                                       + "RowStatus='{2}'",
                                                                                                       FinancialSummary_Fact.FinancialPrepaidExpenseSummary_FactId,
                                                                                                       CorrespondFinancialAccountDimId_default,
                                                                                                       rowStatusActive
                                                                                                       )));
                                if (collec_detail_debit.Count != 0)
                                {
                                    foreach (FinancialPrepaidExpenseDetail each_detail in collec_detail_debit)
                                    {
                                        if (!list_transaction.Contains(each_detail.FinancialTransactionDimId.FinancialTransactionDimId))
                                        {
                                            list_transaction.Add(each_detail.FinancialTransactionDimId.FinancialTransactionDimId);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion

                #region đổ dữ liệu
                #region dòng số dư đầu tháng
                DataRow dr = datatable.NewRow();
                dr["dien_giai"] = "Kỳ trước chuyển sang";
                double no_dau = 0, co_dau = 0;
                if (f_c_FinancialAccountDim.Count != 0)
                {
                    foreach (FinancialAccountDim each_tk in f_c_FinancialAccountDim)
                    {
                        if (md != null && yd != null && ood != null)
                        {
                            FinancialPrepaidExpenseSummary_Fact FinancialSummary_Fact =
                                session.FindObject <FinancialPrepaidExpenseSummary_Fact>(CriteriaOperator.Parse(
                                                                                             String.Format("MonthDimId='{0}' AND "
                                                                                                           + "YearDimId='{1}' AND "
                                                                                                           + "OwnerOrgDimId='{2}' AND "
                                                                                                           + "FinancialAccountDimId='{3}' AND "
                                                                                                           + "RowStatus='{4}'",
                                                                                                           md.MonthDimId,
                                                                                                           yd.YearDimId,
                                                                                                           ood.OwnerOrgDimId,
                                                                                                           each_tk.FinancialAccountDimId,
                                                                                                           rowStatusActive
                                                                                                           )));
                            if (FinancialSummary_Fact != null)
                            {
                                no_dau += (double)FinancialSummary_Fact.BeginDebitBalance;
                                co_dau += (double)FinancialSummary_Fact.BeginCreditBalance;
                            }
                        }
                    }
                }
                dr["no_dau"] = no_dau;
                dr["co_dau"] = co_dau;
                datatable.Rows.Add(dr);
                #endregion

                int STTu = 1;
                // từng dòng
                foreach (int each_row in list_transaction)
                {
                    #region
                    FinancialTransactionDim transaction = session.FindObject <FinancialTransactionDim>(
                        CriteriaOperator.Parse(String.Format("FinancialTransactionDimId='{0}' AND "
                                                             + "RowStatus='{1}'",
                                                             each_row,
                                                             rowStatusActive
                                                             )));
                    //
                    dr              = datatable.NewRow();
                    dr["stt"]       = STTu++;
                    dr["dien_giai"] = transaction.Description;
                    #endregion

                    //từng cột
                    #region credit correspond
                    double cong_no = 0;
                    foreach (string header_column in header_credit_correspond())
                    {
                        double cell = 0;
                        //
                        CorrespondFinancialAccountDim CorrespondId = session.FindObject <CorrespondFinancialAccountDim>(
                            CriteriaOperator.Parse(String.Format("Code='{0}'", header_column)));
                        //
                        if (f_c_FinancialAccountDim.Count != 0)
                        {
                            foreach (FinancialAccountDim each_tk in f_c_FinancialAccountDim)
                            {
                                if (md != null && yd != null && ood != null)
                                {
                                    FinancialPrepaidExpenseSummary_Fact FinancialSummary_Fact =
                                        session.FindObject <FinancialPrepaidExpenseSummary_Fact>(CriteriaOperator.Parse(
                                                                                                     String.Format("MonthDimId='{0}' AND "
                                                                                                                   + "YearDimId='{1}' AND "
                                                                                                                   + "OwnerOrgDimId='{2}' AND "
                                                                                                                   + "FinancialAccountDimId='{3}' AND "
                                                                                                                   + "RowStatus='{4}'",
                                                                                                                   md.MonthDimId,
                                                                                                                   yd.YearDimId,
                                                                                                                   ood.OwnerOrgDimId,
                                                                                                                   each_tk.FinancialAccountDimId,
                                                                                                                   rowStatusActive
                                                                                                                   )));
                                    if (FinancialSummary_Fact != null)
                                    {
                                        XPCollection <FinancialPrepaidExpenseDetail> collec_detail_credit =
                                            new XPCollection <FinancialPrepaidExpenseDetail>(session, CriteriaOperator.Parse(
                                                                                                 String.Format("FinancialPrepaidExpenseSummary_FactId='{0}' AND "
                                                                                                               + "Credit>0 AND "
                                                                                                               + "CorrespondFinancialAccountDimId!='{1}' AND "
                                                                                                               + "RowStatus='{2}' AND "
                                                                                                               + "FinancialTransactionDimId='{3}' AND "
                                                                                                               + "CorrespondFinancialAccountDimId='{4}'",
                                                                                                               FinancialSummary_Fact.FinancialPrepaidExpenseSummary_FactId,
                                                                                                               CorrespondFinancialAccountDimId_default,
                                                                                                               rowStatusActive,
                                                                                                               each_row,
                                                                                                               CorrespondId.CorrespondFinancialAccountDimId
                                                                                                               )));
                                        if (collec_detail_credit.Count != 0)
                                        {
                                            foreach (FinancialPrepaidExpenseDetail each_detail in collec_detail_credit)
                                            {
                                                cell    += (double)each_detail.Credit;
                                                cong_no += (double)each_detail.Credit;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        //
                        dr[header_column + "_co"] = cell;
                    }
                    dr["cong_no"] = cong_no;
                    #endregion

                    // từng cột
                    #region debit correspond
                    double cong_co = 0;
                    foreach (string header_column in header_debit_correspond())
                    {
                        double cell = 0;
                        //
                        CorrespondFinancialAccountDim CorrespondId = session.FindObject <CorrespondFinancialAccountDim>(
                            CriteriaOperator.Parse(String.Format("Code='{0}'", header_column)));
                        //
                        if (f_c_FinancialAccountDim.Count != 0)
                        {
                            foreach (FinancialAccountDim each_tk in f_c_FinancialAccountDim)
                            {
                                if (md != null && yd != null && ood != null)
                                {
                                    FinancialPrepaidExpenseSummary_Fact FinancialSummary_Fact =
                                        session.FindObject <FinancialPrepaidExpenseSummary_Fact>(CriteriaOperator.Parse(
                                                                                                     String.Format("MonthDimId='{0}' AND "
                                                                                                                   + "YearDimId='{1}' AND "
                                                                                                                   + "OwnerOrgDimId='{2}' AND "
                                                                                                                   + "FinancialAccountDimId='{3}' AND "
                                                                                                                   + "RowStatus='{4}'",
                                                                                                                   md.MonthDimId,
                                                                                                                   yd.YearDimId,
                                                                                                                   ood.OwnerOrgDimId,
                                                                                                                   each_tk.FinancialAccountDimId,
                                                                                                                   rowStatusActive
                                                                                                                   )));
                                    if (FinancialSummary_Fact != null)
                                    {
                                        XPCollection <FinancialPrepaidExpenseDetail> collec_detail_debit =
                                            new XPCollection <FinancialPrepaidExpenseDetail>(session, CriteriaOperator.Parse(
                                                                                                 String.Format("FinancialPrepaidExpenseSummary_FactId='{0}' AND "
                                                                                                               + "Debit>0 AND "
                                                                                                               + "CorrespondFinancialAccountDimId!='{1}' AND "
                                                                                                               + "RowStatus='{2}' AND "
                                                                                                               + "FinancialTransactionDimId='{3}' AND "
                                                                                                               + "CorrespondFinancialAccountDimId='{4}'",
                                                                                                               FinancialSummary_Fact.FinancialPrepaidExpenseSummary_FactId,
                                                                                                               CorrespondFinancialAccountDimId_default,
                                                                                                               rowStatusActive,
                                                                                                               each_row,
                                                                                                               CorrespondId.CorrespondFinancialAccountDimId
                                                                                                               )));
                                        if (collec_detail_debit.Count != 0)
                                        {
                                            foreach (FinancialPrepaidExpenseDetail each_detail in collec_detail_debit)
                                            {
                                                cell    += (double)each_detail.Debit;
                                                cong_co += (double)each_detail.Debit;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        dr[header_column + "_no"] = cell;
                    }
                    dr["cong_co"] = cong_co;
                    #endregion

                    datatable.Rows.Add(dr);
                }
                #endregion

                #region dòng cộng
                dr = datatable.NewRow();
                dr["dien_giai"] = "Tổng cộng";

                int column_count = datatable.Columns.Count - 3;
                int row_count    = datatable.Rows.Count - 1;
                for (int c = 2; c <= column_count; c++)
                {
                    double sumT = 0;
                    for (int r = 1; r <= row_count; r++)
                    {
                        double tt;
                        double.TryParse(datatable.Rows[r][c].ToString(), out tt);
                        sumT += tt;
                    }
                    dr[datatable.Columns[c]] = sumT;
                }
                //
                double no_cuoi = 0;
                if (f_c_FinancialAccountDim.Count != 0)
                {
                    foreach (FinancialAccountDim each_tk in f_c_FinancialAccountDim)
                    {
                        if (md != null && yd != null && ood != null)
                        {
                            FinancialPrepaidExpenseSummary_Fact FinancialSummary_Fact =
                                session.FindObject <FinancialPrepaidExpenseSummary_Fact>(CriteriaOperator.Parse(
                                                                                             String.Format("MonthDimId='{0}' AND "
                                                                                                           + "YearDimId='{1}' AND "
                                                                                                           + "OwnerOrgDimId='{2}' AND "
                                                                                                           + "FinancialAccountDimId='{3}' AND "
                                                                                                           + "RowStatus='{4}'",
                                                                                                           md.MonthDimId,
                                                                                                           yd.YearDimId,
                                                                                                           ood.OwnerOrgDimId,
                                                                                                           each_tk.FinancialAccountDimId,
                                                                                                           rowStatusActive
                                                                                                           )));
                            no_cuoi += (double)FinancialSummary_Fact.EndDebitBalance;
                        }
                    }
                }
                //
                dr["no_cuoi"] = no_cuoi;
                datatable.Rows.Add(dr);
                #endregion

                #region out gridview
                GridView_S04b6DN.DataSource = datatable;
                GridView_S04b6DN.DataBind();
                #endregion
            }
            catch { }

            #region export report
            s04b6_dn.printableCC_S04b6DN.PrintableComponent = new PrintableComponentLinkBase()
            {
                Component = GridViewExporter_S04b6DN
            };
            ReportViewer_S04b6DN.Report = s04b6_dn;
            #endregion
        }
Пример #6
0
        public void CreateFinancialPrepaidExpenseDetail(
            Session session,
            ETL_FinancialPrepaidExpenseDetail Detail,
            string MainAccountCode)
        {
            try
            {
                Util util = new Util();
                CorrespondFinancialAccountDim defaultCorrespondindAcc = CorrespondFinancialAccountDim.GetDefault(session, CorrespondFinancialAccountDimEnum.NAAN_DEFAULT);
                FinancialAccountDim           defaultFinancialAcc     = FinancialAccountDim.GetDefault(session, FinancialAccountDimEnum.NAAN_DEFAULT);
                ETLAccountingBO accountingBO                  = new ETLAccountingBO();
                FinancialPrepaidExpenseSummary_Fact Fact      = GetFinancialPrepaidExpenseSummaryFact(session, Detail.OwnerOrgId, Detail.IssueDate, MainAccountCode);
                FinancialPrepaidExpenseDetail       newDetail = new FinancialPrepaidExpenseDetail(session);
                if (Fact == null)
                {
                    Fact = CreateFinancialPrepaidExpenseSummaryFact(session, Detail.OwnerOrgId, Detail.IssueDate, MainAccountCode, Detail.IsBalanceForward);
                    if (Fact == null)
                    {
                        return;
                    }
                }
                else
                {
                    var date = new DateTime(Detail.IssueDate.Year, Detail.IssueDate.Month, 1);
                    FinancialPrepaidExpenseSummary_Fact previousSummary = GetFinancialPrepaidExpenseSummaryFact(session,
                                                                                                                Detail.OwnerOrgId, date.AddMonths(-1), MainAccountCode);

                    if (previousSummary != null)
                    {
                        Fact.BeginCreditBalance = previousSummary.EndCreditBalance;
                        Fact.BeginDebitBalance  = previousSummary.EndDebitBalance;
                    }
                }
                CorrespondFinancialAccountDim correspondFinancialAccountDim = null;
                FinancialAccountDim           financialAccountDim           = null;

                if (!Detail.CorrespondAccountCode.Equals(string.Empty))
                {
                    correspondFinancialAccountDim = util.GetXpoObjectByFieldName <CorrespondFinancialAccountDim, string>(session, "Code", Detail.CorrespondAccountCode, BinaryOperatorType.Equal);
                }
                if (!MainAccountCode.Equals(string.Empty))
                {
                    financialAccountDim = util.GetXpoObjectByFieldName <FinancialAccountDim, string>(session, "Code", MainAccountCode, BinaryOperatorType.Equal);
                }

                FinancialTransactionDim financialTransactionDim = util.GetXpoObjectByFieldName <FinancialTransactionDim, Guid>(session, "RefId", Detail.TransactionId, BinaryOperatorType.Equal);

                CurrencyDim currencyDim = util.GetXpoObjectByFieldName <CurrencyDim, string>(session, "Code", Detail.CurrencyCode, BinaryOperatorType.Equal);
                if (financialTransactionDim == null)
                {
                    financialTransactionDim = accountingBO.CreateFinancialTransactionDim(session, Detail.TransactionId);
                    if (financialTransactionDim == null)
                    {
                        return;
                    }
                }

                if (financialAccountDim == null && !MainAccountCode.Equals(string.Empty))
                {
                    financialAccountDim = accountingBO.CreateFinancialAccountDim(session, MainAccountCode);
                }
                if (correspondFinancialAccountDim == null && !Detail.CorrespondAccountCode.Equals(string.Empty))
                {
                    correspondFinancialAccountDim = accountingBO.CreateCorrespondFinancialAccountDim(session, Detail.CorrespondAccountCode);
                }

                if (currencyDim == null && !Detail.CurrencyCode.Equals(string.Empty))
                {
                    currencyDim = accountingBO.CreateCurrencyDim(session, Detail.CurrencyCode);
                }

                newDetail.CorrespondFinancialAccountDimId = correspondFinancialAccountDim;
                newDetail.Credit                = Detail.Credit;
                newDetail.Debit                 = Detail.Debit;
                newDetail.CurrencyDimId         = currencyDim;
                newDetail.FinancialAccountDimId = financialAccountDim;
                newDetail.FinancialPrepaidExpenseSummary_FactId = Fact;
                newDetail.FinancialTransactionDimId             = financialTransactionDim;

                if (newDetail.FinancialAccountDimId == null)
                {
                    newDetail.FinancialAccountDimId = defaultFinancialAcc;
                }
                if (newDetail.CorrespondFinancialAccountDimId == null)
                {
                    newDetail.CorrespondFinancialAccountDimId = defaultCorrespondindAcc;
                }

                newDetail.RowStatus = Constant.ROWSTATUS_ACTIVE;
                newDetail.Save();

                if (Detail.IsBalanceForward)
                {
                    Fact.BeginCreditBalance = Fact.EndCreditBalance = Detail.Credit;
                    Fact.BeginDebitBalance  = Fact.EndDebitBalance = Detail.Debit;
                    Fact.CreditSum          = 0;
                    Fact.DebitSum           = 0;
                }
                else
                {
                    Fact.CreditSum = Fact.FinancialPrepaidExpenseDetails.Where(i => i.RowStatus == 1 &&
                                                                               i.Credit > 0 && i.CorrespondFinancialAccountDimId == defaultCorrespondindAcc).Sum(d => d.Credit);

                    Fact.DebitSum = Fact.FinancialPrepaidExpenseDetails.Where(i => i.RowStatus == 1 &&
                                                                              i.Debit > 0 && i.CorrespondFinancialAccountDimId == defaultCorrespondindAcc).Sum(d => d.Debit);

                    Fact.EndCreditBalance = Fact.BeginCreditBalance + Fact.CreditSum - Fact.DebitSum;
                    Fact.EndDebitBalance  = Fact.BeginDebitBalance + Fact.DebitSum - Fact.CreditSum;
                }
                Fact.Save();
            }
            catch (Exception)
            {
                return;
            }
        }