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; } }
protected ETL_GoodsInInventoryTransformData TransformTransaction ( Session session, ETL_GoodsInInventoryTransaction transaction, string AccountCode) { Util util = new Util(); ETL_GoodsInInventoryTransformData result = new ETL_GoodsInInventoryTransformData(); Account account = util.GetXpoObjectByFieldName <Account, string>(session, "Code", AccountCode, BinaryOperatorType.Equal); if (account == null) { return(null); } if (transaction == null) { return(null); } ETL_GoodsInInventoryTransaction etlTransaction = transaction; string subMainAccount = string.Empty; List <ETL_GoodsInInventoryDetail> detail = new List <ETL_GoodsInInventoryDetail>(); try { ETLAccountingBO accountingBO = new ETLAccountingBO(); FinancialLiabilityBO liabilityBO = new FinancialLiabilityBO(); List <ETL_GeneralJournal> JournalListJoined = JoinJournal(session, etlTransaction.GeneralJournalList); List <ETL_GeneralJournal> FinishJournalList = liabilityBO.ClearJournalList(session, JournalListJoined, account.AccountId); foreach (ETL_GeneralJournal journal in etlTransaction.GeneralJournalList) { ETL_GoodsInInventoryDetail temp = new ETL_GoodsInInventoryDetail(); temp.AccountCode = string.Empty; temp.CorrespondAccountCode = string.Empty; if (accountingBO.IsRelateAccount(session, account.AccountId, journal.AccountId)) { temp.AccountCode = subMainAccount = session.GetObjectByKey <Account>(journal.AccountId).Code; } else { temp.CorrespondAccountCode = session.GetObjectByKey <Account>(journal.AccountId).Code; } temp.CurrencyCode = session.GetObjectByKey <Currency>(journal.CurrencyId).Code; temp.IsBalanceForward = etlTransaction.IsBalanceForward; temp.IssueDate = etlTransaction.IssuedDate; temp.OwnerOrgId = etlTransaction.OwnerOrgId; temp.TransactionId = etlTransaction.TransactionId; temp.Credit = (decimal)journal.Credit; temp.Debit = (decimal)journal.Debit; temp.ArtifactId = transaction.ArtifactId; if (etlTransaction.Price > 0) { temp.Quantity = temp.Debit == 0 ? (double)temp.Credit / (double)etlTransaction.Price : (double)temp.Debit / (double)etlTransaction.Price; } else { temp.Quantity = 0; } detail.Add(temp); } result.MainAccountCode = subMainAccount; result.ETL_DetailList = detail; } catch (Exception) { return(null); } return(result); }