public List <DiaryJournalTemplate> TransformTransactionToTemplateArea(Session session, ETL_Transaction transaction, string AccountCode) { Util util = new Util(); Account account = util.GetXpoObjectByFieldName <Account, string>(session, "Code", AccountCode, BinaryOperatorType.Equal); if (account == null) { return(null); } if (transaction == null) { return(null); } ETL_Transaction etlTransaction = transaction; List <DiaryJournalTemplate> detail = new List <DiaryJournalTemplate>(); try { ETLAccountingBO accountingBO = new ETLAccountingBO(); List <ETL_GeneralJournal> JournalListJoined = JoinJournal(session, etlTransaction.GeneralJournalList); List <ETL_GeneralJournal> FinishJournalList = ClearJournalList(session, JournalListJoined, account.AccountId); foreach (ETL_GeneralJournal journal in FinishJournalList) { DiaryJournalTemplate temp = new DiaryJournalTemplate(); temp.FinancialAccountDimCode = ""; temp.CorrespondFinancialAccountDimCode = ""; if (accountingBO.IsRelateAccount(session, account.AccountId, journal.AccountId)) { temp.FinancialAccountDimCode = session.GetObjectByKey <Account>(journal.AccountId).Code; } else { temp.CorrespondFinancialAccountDimCode = session.GetObjectByKey <Account>(journal.AccountId).Code; } temp.CurrencyDimCode = session.GetObjectByKey <Currency>(journal.CurrencyId).Code; temp.IssueDate = etlTransaction.IssuedDate; temp.OwnerOrgId = etlTransaction.OwnerOrgId; temp.TransactionId = etlTransaction.TransactionId; temp.Credit = (double)journal.Credit; temp.Debit = (double)journal.Debit; detail.Add(temp); } } catch (Exception) { return(null); } return(detail); }
// Create public DiaryJournal_Fact CreateDiaryJournalFact(Session session, Guid OwnerOrgId, DateTime IssueDate, DiaryJournalTemplate diaryJournal, string accountCode) { DiaryJournal_Fact result = new DiaryJournal_Fact(session); try { ETLAccountingBO accountingBO = new ETLAccountingBO(); DimBO dimBO = new DimBO(); result.FinancialAccountDimId = accountingBO.GetFinancialAccountDim(session, accountCode); result.MonthDimId = dimBO.GetMonthDim(session, (short)IssueDate.Month); result.YearDimId = dimBO.GetYearDim(session, (short)IssueDate.Year); result.OwnerOrgDimId = dimBO.GetOwnerOrgDim(session, OwnerOrgId); //result.CreditSum = 0; //result.DebitSum = 0; //result.BeginCreditBalance = 0; //result.BeginDebitBalance = 0; //result.EndCreditBalance = 0; //result.EndDebitBalance = 0; if (result.FinancialAccountDimId == null || result.MonthDimId == null || result.YearDimId == null || result.OwnerOrgDimId == null) { return(null); } result.Save(); } catch (Exception) { return(null); } return(result); }
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; } }