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