public FinancialTransactionDim get_FinancialTransactionDimId(Session session, string Name, short RowStatus) { try { FinancialTransactionDim FTD_id = session.FindObject <FinancialTransactionDim>( CriteriaOperator.And( new BinaryOperator("Name", Name, BinaryOperatorType.Equal), new BinaryOperator("RowStatus", RowStatus, BinaryOperatorType.Equal) )); if (FTD_id == null) { return(null); } return(FTD_id); } catch (Exception) { throw; } }
public FinancialTransactionDim get_FinancialTransactionDim(Session session, Guid FinancialTransactionDimId, short RowStatus) { try { FinancialTransactionDim FTD = session.FindObject <FinancialTransactionDim>( CriteriaOperator.And( new BinaryOperator("FinancialTransactionDimId", FinancialTransactionDimId, BinaryOperatorType.Equal), new BinaryOperator("RowStatus", RowStatus, BinaryOperatorType.Equal) )); if (FTD == null) { return(null); } return(FTD); } catch (Exception) { throw; } }
public FinancialTransactionDim CreateFinancialTransactionDim(Session session, Guid RefId) { try { Transaction transaction = session.GetObjectByKey <Transaction>(RefId); if (transaction == null) { return(null); } FinancialTransactionDim transactionDim = new FinancialTransactionDim(session); transactionDim.Description = transaction.Description; transactionDim.RefId = RefId; transactionDim.RowStatus = Constant.ROWSTATUS_ACTIVE; transactionDim.Name = transaction.Code; transactionDim.IssueDate = transaction.IssueDate; transactionDim.Save(); return(transactionDim); } catch (Exception) { return(null); } }
private void CreateFinancialActualPriceDetail( Session session, ETL_FinanciaActualPriceDetail 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(); FinancialActualPriceSummary_Fact Fact = GetFinancialActualPriceSummaryFact(session, Detail.OwnerOrgId, Detail.IssueDate, MainAccountCode); FinancialActualPriceDetail newDetail = new FinancialActualPriceDetail(session); if (Fact == null) { Fact = CreateFinancialActualPriceSummaryFact(session, Detail.OwnerOrgId, Detail.IssueDate, MainAccountCode, Detail.IsBalanceForward); if (Fact == null) { return; } } else { var date = new DateTime(Detail.IssueDate.Year, Detail.IssueDate.Month, 1); FinancialActualPriceSummary_Fact previousSummary = GetFinancialActualPriceSummaryFact(session, Detail.OwnerOrgId, date.AddMonths(-1), MainAccountCode); if (previousSummary != null) { Fact.BeginDebitBalance = previousSummary.EndDebitBalance; Fact.BeginCreditBalance = previousSummary.EndCreditBalance; } } 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.FinancialTransactionDimId = financialTransactionDim; newDetail.FinancialActualPriceSummary_FactId = Fact; /*2014-02-22 ERP-1417 Duc.Vo INS START*/ if (newDetail.FinancialAccountDimId == null) { newDetail.FinancialAccountDimId = defaultFinancialAcc; } if (newDetail.CorrespondFinancialAccountDimId == null) { newDetail.CorrespondFinancialAccountDimId = defaultCorrespondindAcc; } /*2014-02-22 ERP-1417 Duc.Vo INS END*/ 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.FinancialActualPriceDetails.Where(i => i.RowStatus == 1 && i.Credit > 0 && i.CorrespondFinancialAccountDimId == defaultCorrespondindAcc).Sum(d => d.Credit); Fact.DebitSum = Fact.FinancialActualPriceDetails.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; } }
public void CreateDiaryJournalDetail(Session session, DiaryJournalTemplate diaryJournal, string accountCode, char debitOrCredit) { try { Util util = new Util(); ETLAccountingBO accountingBO = new ETLAccountingBO(); DiaryJournal_Fact Fact = GetDiaryJournalFact(session, diaryJournal.OwnerOrgId, diaryJournal.IssueDate, accountCode); DiaryJournal_Detail newDetail = new DiaryJournal_Detail(session); if (Fact == null) { Fact = CreateDiaryJournalFact(session, diaryJournal.OwnerOrgId, diaryJournal.IssueDate, diaryJournal, accountCode); if (Fact == null) { return; } } CorrespondFinancialAccountDim correspondFinancialAccountDim = util.GetXpoObjectByFieldName <CorrespondFinancialAccountDim, string>(session, "Code", diaryJournal.CorrespondFinancialAccountDimCode, BinaryOperatorType.Equal); FinancialAccountDim financialAccountDim = util.GetXpoObjectByFieldName <FinancialAccountDim, string>(session, "Code", accountCode, BinaryOperatorType.Equal); FinancialTransactionDim financialTransactionDim = util.GetXpoObjectByFieldName <FinancialTransactionDim, Guid>(session, "RefId", diaryJournal.TransactionId, BinaryOperatorType.Equal); CurrencyDim currencyDim = util.GetXpoObjectByFieldName <CurrencyDim, string>(session, "Code", diaryJournal.CurrencyDimCode, BinaryOperatorType.Equal); if (financialTransactionDim == null) { financialTransactionDim = accountingBO.CreateFinancialTransactionDim(session, diaryJournal.TransactionId); if (financialTransactionDim == null) { return; } } if (financialAccountDim == null) { financialAccountDim = accountingBO.CreateFinancialAccountDim(session, accountCode); } if (correspondFinancialAccountDim == null) { correspondFinancialAccountDim = accountingBO.CreateCorrespondFinancialAccountDim(session, diaryJournal.CorrespondFinancialAccountDimCode); } if (currencyDim == null) { currencyDim = accountingBO.CreateCurrencyDim(session, diaryJournal.CurrencyDimCode); } Fact.Save(); if (correspondFinancialAccountDim.Code == "131") { newDetail.Credit = diaryJournal.Credit; } if (correspondFinancialAccountDim != null) { if (correspondFinancialAccountDim.Code == "") { if (debitOrCredit == 'C') { newDetail.Credit = diaryJournal.Credit; } else { newDetail.Debit = diaryJournal.Debit; } newDetail.FinancialAccountDimId = financialAccountDim; } else { if (debitOrCredit == 'C') { newDetail.Debit = diaryJournal.Debit; } else { newDetail.Credit = diaryJournal.Credit; } newDetail.CorrespondFinancialAccountDimId = correspondFinancialAccountDim; } } newDetail.CurrencyDimId = currencyDim; newDetail.DiaryJournal_FactId = Fact; newDetail.FinancialTransactionDimId = financialTransactionDim; newDetail.Save(); } catch (Exception) { return; } }
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 }
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; } }
public void CreateFinancialSalesOrManufacturerExpenseDetail( Session session, ETL_SalesOrManufacturerExpenseDetail Detail, string MainAccountCode, string HighestAccountCode) { try { if (Detail == null || MainAccountCode.Equals(string.Empty) || Detail.OwnerOrgId.Equals(Guid.Empty) || Detail.IssueDate == null) { return; } #region prepare Summary header data Util util = new Util(); ETLAccountingBO accountingBO = new ETLAccountingBO(); FinancialSalesOrManufactureExpenseSummary_Fact summary = GetFinancialSalesOrManufactureExpenseSummary( session, Detail.OwnerOrgId, Detail.IssueDate); FinancialSalesOrManufactureExpenseDetail newDetail = new FinancialSalesOrManufactureExpenseDetail(session); if (summary == null) { summary = CreateFinancialSalesOrManufactureExpenseSummary( session, Detail.OwnerOrgId, Detail.IssueDate, Detail.IsBalanceForward); if (summary == null) { return; } } #endregion #region prepare group data CorrespondFinancialAccountDim correspondFinancialAccountDim = null; FinancialAccountDim financialAccountDim = null; FinancialAccountDim GroupAccountDim = null; if (!HighestAccountCode.Equals(string.Empty)) { GroupAccountDim = util.GetXpoObjectByFieldName <FinancialAccountDim, string>( session, "Code", HighestAccountCode, BinaryOperatorType.Equal); } if (!MainAccountCode.Equals(string.Empty)) { financialAccountDim = util.GetXpoObjectByFieldName <FinancialAccountDim, string>( session, "Code", MainAccountCode, BinaryOperatorType.Equal); } if (!Detail.CorrespondAccountCode.Equals(string.Empty)) { correspondFinancialAccountDim = util.GetXpoObjectByFieldName <CorrespondFinancialAccountDim, string>( session, "Code", Detail.CorrespondAccountCode, BinaryOperatorType.Equal); } if (GroupAccountDim == null && !HighestAccountCode.Equals(string.Empty)) { GroupAccountDim = accountingBO.CreateFinancialAccountDim(session, HighestAccountCode); } 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); } SalesOrManufactureExpenseByGroup group = GetSalesOrManufactureExpenseByGroup( session, summary.FinancialSalesOrManufactureExpenseSummary_FactId, HighestAccountCode); if (group == null) { group = CreateSalesOrManufactureExpenseByGroup( session, summary.FinancialSalesOrManufactureExpenseSummary_FactId, HighestAccountCode); if (group == null) { return; } } #endregion #region prepare Detail CurrencyDim currencyDim = util.GetXpoObjectByFieldName <CurrencyDim, string>( session, "Code", Detail.CurrencyCode, BinaryOperatorType.Equal); if (currencyDim == null && !Detail.CurrencyCode.Equals(string.Empty)) { currencyDim = accountingBO.CreateCurrencyDim(session, Detail.CurrencyCode); } FinancialTransactionDim financialTransactionDim = util.GetXpoObjectByFieldName <FinancialTransactionDim, Guid>( session, "RefId", Detail.TransactionId, BinaryOperatorType.Equal); if (financialTransactionDim == null) { financialTransactionDim = accountingBO.CreateFinancialTransactionDim(session, Detail.TransactionId); if (financialTransactionDim == null) { return; } } newDetail.Credit = Detail.Credit; newDetail.Debit = Detail.Debit; newDetail.CurrencyDimId = currencyDim; newDetail.FinancialTransactionDimId = financialTransactionDim; newDetail.FinancialAccountDimId = financialAccountDim; newDetail.CorrespondFinancialAccountDimId = correspondFinancialAccountDim; newDetail.SalesOrManufactureExpenseByGroupId = group; CorrespondFinancialAccountDim defaultCorrespondindAcc = CorrespondFinancialAccountDim.GetDefault(session, CorrespondFinancialAccountDimEnum.NAAN_DEFAULT); FinancialAccountDim defaultFinancialAcc = FinancialAccountDim.GetDefault(session, FinancialAccountDimEnum.NAAN_DEFAULT); if (newDetail.FinancialAccountDimId == null) { newDetail.FinancialAccountDimId = defaultFinancialAcc; } if (newDetail.CorrespondFinancialAccountDimId == null) { newDetail.CorrespondFinancialAccountDimId = defaultCorrespondindAcc; } newDetail.RowStatus = Constant.ROWSTATUS_ACTIVE; newDetail.Save(); #endregion if (Detail.IsBalanceForward) { group.SumExpense = Detail.Credit; } else { group.SumExpense = group.FinancialSalesOrManufactureExpenseDetails.Where(i => i.RowStatus >= 1 && i.Debit > 0). Sum(r => r.Debit); group.Save(); } group.Save(); summary.Save(); } catch (Exception) { return; } }
public void CreateFinancialOnTheWayBuyingGoodDetail(Session session, ETL_FinancialOnTheWayBuyingGoodDetail Detail, string MainAccountCode) { try { if (Detail == null || MainAccountCode.Equals(string.Empty) || Detail.PurchaseInvoiceId.Equals(Guid.Empty) || Detail.InputInventoryCommandId.Equals(Guid.Empty) || Detail.OwnerOrgId.Equals(Guid.Empty) || Detail.IssueDate == null) { return; } //bool flgNewSummary = false; Util util = new Util(); CorrespondFinancialAccountDim defaultCorrespondindAcc = CorrespondFinancialAccountDim.GetDefault(session, CorrespondFinancialAccountDimEnum.NAAN_DEFAULT); FinancialAccountDim defaultFinancialAcc = FinancialAccountDim.GetDefault(session, FinancialAccountDimEnum.NAAN_DEFAULT); ETLAccountingBO accountingBO = new ETLAccountingBO(); FinancialOnTheWayBuyingGoodSummary summary = GetFinancialOnTheWayBuyingGoodSummary(session, Detail.OwnerOrgId, Detail.IssueDate, MainAccountCode); FinancialOnTheWayBuyingGoodDetail newDetail = new FinancialOnTheWayBuyingGoodDetail(session); if (summary == null) { summary = CreateFinancialOnTheWayBuyingGoodSummary(session, Detail.OwnerOrgId, Detail.IssueDate, MainAccountCode); if (summary == null) { return; } } else { var date = new DateTime(Detail.IssueDate.Year, Detail.IssueDate.Month, 1); FinancialOnTheWayBuyingGoodSummary previousSummary = GetFinancialOnTheWayBuyingGoodSummary(session, Detail.OwnerOrgId, date.AddMonths(-1), MainAccountCode); if (previousSummary != null) { summary.BeginBalance = previousSummary.EndBalance; } } /*2014/02/22 Duc.Vo MOD START*/ CorrespondFinancialAccountDim correspondFinancialAccountDim = null; FinancialAccountDim financialAccountDim = null; InventoryCommand InputCommand = null; NAS.DAL.Invoice.PurchaseInvoice PurchaseInvoice = 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); } if (!Detail.InputInventoryCommandId.Equals(Guid.Empty)) { InputCommand = util.GetXpoObjectByFieldName <InventoryCommand, Guid>(session, "InventoryCommandId", Detail.InputInventoryCommandId, BinaryOperatorType.Equal); if (InputCommand == null) { return; } } if (!Detail.PurchaseInvoiceId.Equals(Guid.Empty)) { PurchaseInvoice = util.GetXpoObjectByFieldName <NAS.DAL.Invoice.PurchaseInvoice, Guid>(session, "BillId", Detail.PurchaseInvoiceId, BinaryOperatorType.Equal); if (PurchaseInvoice == null) { return; } } OnTheWayBuyingGoodArtifact artifact = GetOnTheWayBuyingGoodArtifact( session, summary.FinancialOnTheWayBuyingGoodSummaryId, PurchaseInvoice.BillId, InputCommand.InventoryCommandId); if (artifact == null) { artifact = CreateOnTheWayBuyingGoodArtifact( session, summary.FinancialOnTheWayBuyingGoodSummaryId, PurchaseInvoice.BillId, InputCommand.InventoryCommandId); if (artifact == null) { return; } } /*2014/02/22 Duc.Vo INS START*/ 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); } CurrencyDim currencyDim = util.GetXpoObjectByFieldName <CurrencyDim, string>( session, "Code", Detail.CurrencyCode, BinaryOperatorType.Equal); if (currencyDim == null && !Detail.CurrencyCode.Equals(string.Empty)) { currencyDim = accountingBO.CreateCurrencyDim(session, Detail.CurrencyCode); } FinancialTransactionDim financialTransactionDim = util.GetXpoObjectByFieldName <FinancialTransactionDim, Guid>( session, "RefId", Detail.TransactionId, BinaryOperatorType.Equal); if (financialTransactionDim == null) { financialTransactionDim = accountingBO.CreateFinancialTransactionDim(session, Detail.TransactionId); if (financialTransactionDim == null) { return; } } newDetail.CorrespondFinancialAccountDimId = correspondFinancialAccountDim; newDetail.Credit = Detail.Credit; newDetail.Debit = Detail.Debit; newDetail.ActuaPrice = Detail.ActualPrice; newDetail.BookingPrice = Detail.BookedPrice; newDetail.FinancialAccountDimId = financialAccountDim; newDetail.OnTheWayBuyingGoodArtifactId = artifact; newDetail.FinancialTransactionDimId = financialTransactionDim; newDetail.CurrencyDimId = currencyDim; /*2014-02-22 ERP-1417 Duc.Vo INS START*/ if (newDetail.FinancialAccountDimId == null) { newDetail.FinancialAccountDimId = defaultFinancialAcc; } if (newDetail.CorrespondFinancialAccountDimId == null) { newDetail.CorrespondFinancialAccountDimId = defaultCorrespondindAcc; } /*2014-02-22 ERP-1417 Duc.Vo INS END*/ newDetail.RowStatus = Constant.ROWSTATUS_ACTIVE; newDetail.Save(); if (Detail.IsBalanceForward) { summary.BeginBalance = summary.EndBalance = (decimal)Detail.Debit; summary.CreditSum = summary.DebitSum = 0; } else { CorrespondFinancialAccountDim defaultAccDim = CorrespondFinancialAccountDim.GetDefault(session, CorrespondFinancialAccountDimEnum.NAAN_DEFAULT); summary.CreditSum = (decimal)summary.OnTheWayBuyingGoodArtifacts.SelectMany(t => t.FinancialOnTheWayBuyingGoodDetails). Where(i => i.RowStatus == 1 && i.Credit > 0 && i.CorrespondFinancialAccountDimId == defaultCorrespondindAcc).Sum(i => i.Credit); summary.DebitSum = (decimal)summary.OnTheWayBuyingGoodArtifacts.SelectMany(t => t.FinancialOnTheWayBuyingGoodDetails). Where(i => i.RowStatus == 1 && i.Debit > 0 && i.CorrespondFinancialAccountDimId == defaultCorrespondindAcc).Sum(i => i.Debit); summary.BeginBalance = summary.BeginBalance + summary.DebitSum - summary.CreditSum; } summary.Save(); } catch (Exception) { return; } }