public InventoryCommandDim CreateInventoryCommandDim(Session session, Guid RefId) { try { NAS.DAL.Inventory.Command.InventoryCommand command = session.GetObjectByKey <NAS.DAL.Inventory.Command.InventoryCommand>(RefId); if (command == null) { return(null); } InventoryCommandDim commandDim = new InventoryCommandDim(session); commandDim.Code = command.Code; commandDim.Description = command.Description; commandDim.RefId = RefId; commandDim.Name = command.Name; commandDim.IssueDate = command.IssueDate; commandDim.CommandType = command.CommandType; commandDim.RowStatus = Constant.ROWSTATUS_ACTIVE; commandDim.Save(); return(commandDim); } catch (Exception) { return(null); } }
public InventoryCommandDim GetInventoryCommandDim(Session session, Guid RefId) { try { CriteriaOperator criteria_RowStaus = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.Equal); CriteriaOperator criteria_RefId = new BinaryOperator("RefId", RefId, BinaryOperatorType.Equal); CriteriaOperator criteria = CriteriaOperator.And(criteria_RefId, criteria_RowStaus); InventoryCommandDim inventoryCommand = session.FindObject <InventoryCommandDim>(criteria); if (inventoryCommand == null) { return(CreateInventoryCommandDim(session, RefId)); } return(inventoryCommand); } catch { return(null); } }
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 }
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; } }