Example #1
0
        private GoodsInInventorySummary_Fact CreateGoodsInInventorySummaryFact(Session session,
                                                                               Guid OwnerOrgId,
                                                                               DateTime IssueDate,
                                                                               string FinancialAccountCode,
                                                                               bool IsBalanceForward)
        {
            GoodsInInventorySummary_Fact result = new GoodsInInventorySummary_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);
                GoodsInInventorySummary_Fact previousSummary = GetGoodsInInventorySummaryFact(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);
            }
        }
Example #2
0
        private GoodsInInventorySummary_Fact GetGoodsInInventorySummaryFact(
            Session session,
            Guid OwnerOrgId,
            DateTime IssueDate,
            string FinancialAccountCode)
        {
            GoodsInInventorySummary_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
                {
                    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);

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

                    if (fact == null)
                    {
                        return(null);
                    }
                    {
                        result = fact;
                    }
                }
            }
            catch (Exception)
            {
                return(result);
            }
            return(result);
        }
Example #3
0
        public override void FixInvokedBussinessObjects(DevExpress.Xpo.Session session, DevExpress.Xpo.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 defaultCorrespondAccDim = CorrespondFinancialAccountDim.GetDefault(session, CorrespondFinancialAccountDimEnum.NAAN_DEFAULT);

            XPCollection <GoodsInInventoryDetail> neededToBeFixList = new XPCollection <GoodsInInventoryDetail>(session, criteria);
            GoodsInInventorySummary_Fact          fact = null;

            if (neededToBeFixList != null && neededToBeFixList.Count > 0)
            {
                foreach (GoodsInInventoryDetail detail in neededToBeFixList)
                {
                    fact             = detail.GoodsInInventorySummary_FacftId;
                    detail.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                    detail.Save();

                    //fact.CreditSum = fact.GoodsInInventoryDetails.Where(i => i.RowStatus == 1
                    //    && i.Credit > 0 && i.CorrespondFinancialAccountDimId == defaultCorrespondAccDim).Sum(d => d.Credit);

                    //fact.DebitSum = fact.GoodsInInventoryDetails.Where(i => i.RowStatus == 1
                    //    && i.Debit > 0 && i.CorrespondFinancialAccountDimId == defaultCorrespondAccDim).Sum(d => d.Debit);

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

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

                    //fact.Save();
                }
            }
        }
Example #4
0
        public List <string> header_debit_correspond()
        {
            List <string> debit_correspond = new List <string>();

            #region tham số
            int    month    = Int32.Parse(this.hS04b8DN_month.Get("month_id").ToString());
            int    year     = Int32.Parse(this.hS04b8DN_year.Get("year_id").ToString());
            string owner    = "QUASAPHARCO";
            string fAccount = this.hS04b8dnAccount.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

            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)
                    {
                        GoodsInInventorySummary_Fact GoodsSummary_Fact = session.FindObject <GoodsInInventorySummary_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 (GoodsSummary_Fact != null)
                        {
                            XPCollection <GoodsInInventoryDetail> collec_detail =
                                new XPCollection <GoodsInInventoryDetail>(session, CriteriaOperator.Parse(
                                                                              String.Format("GoodsInInventorySummary_FacftId='{0}' AND "
                                                                                            + "Debit>0 AND "
                                                                                            + "CorrespondFinancialAccountDimId!='{1}' AND "
                                                                                            + "RowStatus='{2}'",
                                                                                            GoodsSummary_Fact.GoodsInInventorySummary_FactId,
                                                                                            CorrespondFinancialAccountDimId_default,
                                                                                            rowStatusActive
                                                                                            )));
                            if (collec_detail.Count != 0)
                            {
                                foreach (GoodsInInventoryDetail 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);
        }
Example #5
0
        public void load_data()
        {
            WebModule.Accounting.Report.S04b8_DN s04b8_dn = new Report.S04b8_DN();

            #region tham số truyền
            int    month    = Int32.Parse(this.hS04b8DN_month.Get("month_id").ToString());
            int    year     = Int32.Parse(this.hS04b8DN_year.Get("year_id").ToString());
            string owner    = "QUASAPHARCO";
            string fAccount = this.hS04b8dnAccount.Get("account_id").ToString();
            //string asset = "";
            #endregion

            if (fAccount != "155" && fAccount != "156" && fAccount != "158")
            {
                return;
            }

            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 display label report
                s04b8_dn.xrMonth.Text = month.ToString();
                s04b8_dn.xrYear.Text  = year.ToString();
                if (fAccount == "155")
                {
                    s04b8_dn.xrTitle.Text = String.Format("Thành phẩm (TK {0})", fAccount);
                }
                if (fAccount == "156")
                {
                    s04b8_dn.xrTitle.Text = String.Format("Hàng hóa (TK {0})", fAccount);
                }
                if (fAccount == "158")
                {
                    s04b8_dn.xrTitle.Text = String.Format("Hàng hóa kho bảo thuế (TK {0})", fAccount);
                }

                // số dư đẩu và cuối kì
                double no_dau_ki = 0, no_cuoi_ki = 0;
                if (f_c_FinancialAccountDim.Count != 0)
                {
                    foreach (FinancialAccountDim each_tk in f_c_FinancialAccountDim)
                    {
                        if (md != null && yd != null && ood != null)
                        {
                            GoodsInInventorySummary_Fact FinancialSummary_Fact =
                                session.FindObject <GoodsInInventorySummary_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_ki  += (double)FinancialSummary_Fact.BeginDebitBalance;
                                no_cuoi_ki += (double)FinancialSummary_Fact.EndDebitBalance;
                            }
                        }
                    }
                }

                s04b8_dn.xrdauki.Text  = String.Format("{0:#,#}", no_dau_ki);
                s04b8_dn.xrCuoiKi.Text = String.Format("{0:#,#}", no_cuoi_ki);
                #endregion

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

                #region all row list_inventory
                List <int> list_inventory = new List <int>();
                if (f_c_FinancialAccountDim.Count != 0)
                {
                    foreach (FinancialAccountDim each_tk in f_c_FinancialAccountDim)
                    {
                        if (md != null && yd != null && ood != null)
                        {
                            GoodsInInventorySummary_Fact GoodsSummary_Fact =
                                session.FindObject <GoodsInInventorySummary_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 (GoodsSummary_Fact != null)
                            {
                                ////
                                XPCollection <GoodsInInventoryDetail> collec_detail =
                                    new XPCollection <GoodsInInventoryDetail>(session, CriteriaOperator.Parse(
                                                                                  String.Format("GoodsInInventorySummary_FacftId='{0}' AND "
                                                                                                + "Credit>0 AND "
                                                                                                + "CorrespondFinancialAccountDimId!='{1}' AND "
                                                                                                + "RowStatus='{2}'",
                                                                                                GoodsSummary_Fact.GoodsInInventorySummary_FactId,
                                                                                                CorrespondFinancialAccountDimId_default,
                                                                                                rowStatusActive
                                                                                                )));
                                if (collec_detail.Count != 0)
                                {
                                    foreach (GoodsInInventoryDetail each_detail in collec_detail)
                                    {
                                        if (!list_inventory.Contains(each_detail.InventoryCommandDimId.InventoryCommandDimId))
                                        {
                                            list_inventory.Add(each_detail.InventoryCommandDimId.InventoryCommandDimId);
                                        }
                                    }
                                }
                                ////
                                collec_detail =
                                    new XPCollection <GoodsInInventoryDetail>(session, CriteriaOperator.Parse(
                                                                                  String.Format("GoodsInInventorySummary_FacftId='{0}' AND "
                                                                                                + "Debit>0 AND "
                                                                                                + "CorrespondFinancialAccountDimId!='{1}' AND "
                                                                                                + "RowStatus='{2}'",
                                                                                                GoodsSummary_Fact.GoodsInInventorySummary_FactId,
                                                                                                CorrespondFinancialAccountDimId_default,
                                                                                                rowStatusActive
                                                                                                )));
                                if (collec_detail.Count != 0)
                                {
                                    foreach (GoodsInInventoryDetail each_detail in collec_detail)
                                    {
                                        if (!list_inventory.Contains(each_detail.InventoryCommandDimId.InventoryCommandDimId))
                                        {
                                            list_inventory.Add(each_detail.InventoryCommandDimId.InventoryCommandDimId);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion

                #region đổ dữ liệu
                DataRow dr;
                int     STTu = 1;
                // từng dòng
                foreach (int each_row in list_inventory)
                {
                    #region object Inventory
                    InventoryCommandDim inventory = session.FindObject <InventoryCommandDim>(
                        CriteriaOperator.Parse(String.Format("InventoryCommandDimId='{0}' AND "
                                                             + "RowStatus='{1}'",
                                                             each_row,
                                                             rowStatusActive
                                                             )));
                    #endregion

                    dr               = datatable.NewRow();
                    dr["stt"]        = STTu++;
                    dr["so_hieu"]    = inventory.Code;
                    dr["ngay_thang"] = String.Format("{0:dd/MM/yyyy}", inventory.IssueDate);
                    dr["dien_giai"]  = inventory.Description;

                    // từng cột
                    #region credit correspond
                    double cong_no_TT = 0;
                    foreach (string header_column in header_credit_correspond())
                    {
                        double cell = 0, quantity = 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)
                                {
                                    GoodsInInventorySummary_Fact GoodsSummary_Fact =
                                        session.FindObject <GoodsInInventorySummary_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 (GoodsSummary_Fact != null)
                                    {
                                        XPCollection <GoodsInInventoryDetail> collec_detail_credit =
                                            new XPCollection <GoodsInInventoryDetail>(session, CriteriaOperator.Parse(
                                                                                          String.Format("GoodsInInventorySummary_FacftId='{0}' AND "
                                                                                                        + "Credit>0 AND "
                                                                                                        + "CorrespondFinancialAccountDimId!='{1}' AND "
                                                                                                        + "RowStatus='{2}' AND "
                                                                                                        + "InventoryCommandDimId='{3}' AND "
                                                                                                        + "CorrespondFinancialAccountDimId='{4}'",
                                                                                                        GoodsSummary_Fact.GoodsInInventorySummary_FactId,
                                                                                                        CorrespondFinancialAccountDimId_default,
                                                                                                        rowStatusActive,
                                                                                                        each_row,
                                                                                                        CorrespondId.CorrespondFinancialAccountDimId
                                                                                                        )));
                                        if (collec_detail_credit.Count != 0)
                                        {
                                            foreach (GoodsInInventoryDetail each_detail in collec_detail_credit)
                                            {
                                                cell       += (double)each_detail.Credit;
                                                cong_no_TT += (double)each_detail.Credit;
                                                quantity   += each_detail.Quantity;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        //
                        dr[header_column + "_SL_co"] = quantity;
                        dr[header_column + "_TT_co"] = cell;
                    }
                    dr["cong_no_TT"] = cong_no_TT;
                    #endregion

                    // từng cột
                    #region debit correspond
                    double cong_co_TT = 0;
                    foreach (string header_column in header_debit_correspond())
                    {
                        double cell = 0, quantity = 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)
                                {
                                    GoodsInInventorySummary_Fact GoodsSummary_Fact =
                                        session.FindObject <GoodsInInventorySummary_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 (GoodsSummary_Fact != null)
                                    {
                                        XPCollection <GoodsInInventoryDetail> collec_detail_debit =
                                            new XPCollection <GoodsInInventoryDetail>(session, CriteriaOperator.Parse(
                                                                                          String.Format("GoodsInInventorySummary_FacftId='{0}' AND "
                                                                                                        + "Debit>0 AND "
                                                                                                        + "CorrespondFinancialAccountDimId!='{1}' AND "
                                                                                                        + "RowStatus='{2}' AND "
                                                                                                        + "InventoryCommandDimId='{3}' AND "
                                                                                                        + "CorrespondFinancialAccountDimId='{4}'",
                                                                                                        GoodsSummary_Fact.GoodsInInventorySummary_FactId,
                                                                                                        CorrespondFinancialAccountDimId_default,
                                                                                                        rowStatusActive,
                                                                                                        each_row,
                                                                                                        CorrespondId.CorrespondFinancialAccountDimId
                                                                                                        )));
                                        if (collec_detail_debit.Count != 0)
                                        {
                                            foreach (GoodsInInventoryDetail each_detail in collec_detail_debit)
                                            {
                                                cell       += (double)each_detail.Debit;
                                                cong_co_TT += (double)each_detail.Debit;
                                                quantity   += each_detail.Quantity;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        dr[header_column + "_SL_no"] = quantity;
                        dr[header_column + "_TT_no"] = cell;
                    }
                    dr["cong_co_TT"] = cong_co_TT;
                    #endregion

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

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

                int column_count = datatable.Columns.Count - 1;
                int row_count    = datatable.Rows.Count - 1;
                for (int c = 4; 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;
                }
                datatable.Rows.Add(dr);
                #endregion

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

            #region export report
            s04b8_dn.printableCC_S04b8DN.PrintableComponent = new PrintableComponentLinkBase()
            {
                Component = GridViewExporter_S04b8DN
            };
            ReportViewer_S04b8DN.Report = s04b8_dn;
            #endregion
        }
Example #6
0
        public void CreateGoodsInInventoryDetail(
            Session session,
            ETL_GoodsInInventoryDetail 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();
                GoodsInInventorySummary_Fact Fact      = GetGoodsInInventorySummaryFact(session, Detail.OwnerOrgId, Detail.IssueDate, MainAccountCode);
                GoodsInInventoryDetail       newDetail = new GoodsInInventoryDetail(session);
                if (Fact == null)
                {
                    Fact = CreateGoodsInInventorySummaryFact(session, Detail.OwnerOrgId, Detail.IssueDate, MainAccountCode, Detail.IsBalanceForward);
                    if (Fact == null)
                    {
                        return;
                    }
                }
                else
                {
                    var date = new DateTime(Detail.IssueDate.Year, Detail.IssueDate.Month, 1);
                    GoodsInInventorySummary_Fact previousSummary = GetGoodsInInventorySummaryFact(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);

                InventoryCommandDim inventoryCommandDim = null;
                if (!Detail.ArtifactId.Equals(Guid.Empty))
                {
                    inventoryCommandDim = util.GetXpoObjectByFieldName <InventoryCommandDim, Guid>(session, "RefId", Detail.ArtifactId, BinaryOperatorType.Equal);
                    if (inventoryCommandDim == null)
                    {
                        DimBO dimBO = new DimBO();
                        inventoryCommandDim = dimBO.GetInventoryCommandDim(session, Detail.ArtifactId);
                    }
                }
                else
                {
                    inventoryCommandDim = InventoryCommandDim.GetDefault(session, InventoryCommandDimEnum.UNKNOWN);
                }

                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);
                }

                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.GoodsInInventoryDetails.Where(i => i.RowStatus == 1 &&
                                                                        i.Credit > 0 && i.CorrespondFinancialAccountDimId == defaultCorrespondindAcc).Sum(d => d.Credit);

                    Fact.DebitSum = Fact.GoodsInInventoryDetails.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();
                newDetail.CorrespondFinancialAccountDimId = correspondFinancialAccountDim;
                newDetail.Credit                          = Detail.Credit;
                newDetail.Debit                           = Detail.Debit;
                newDetail.Quantity                        = Detail.Quantity;
                newDetail.CurrencyDimId                   = currencyDim;
                newDetail.FinancialAccountDimId           = financialAccountDim;
                newDetail.GoodsInInventorySummary_FacftId = Fact;
                newDetail.FinancialTransactionDimId       = financialTransactionDim;
                newDetail.InventoryCommandDimId           = inventoryCommandDim;

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

                newDetail.RowStatus = Constant.ROWSTATUS_ACTIVE;
                newDetail.Save();
            }
            catch (Exception)
            {
                return;
            }
        }