public OpeningAccountEntryReponse DeleteOpeningAccountEntryConvert(string accountNumber, int refType) { var openingAccountEntryResponse = new OpeningAccountEntryReponse { Acknowledge = AcknowledgeType.Success }; try { using (var scope = new TransactionScope()) { var openingAccountEntryDelete = OpeningAccountEntryDao.GetOpeningAccountEntriesByAccountNumber(accountNumber); //.Xóa bảng OpeningAccountEntry openingAccountEntryResponse.Message = OpeningAccountEntryDao.DeleteOpeningAccountEntryByAccountNumber(accountNumber); if (openingAccountEntryResponse.Message != null) { openingAccountEntryResponse.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(openingAccountEntryResponse); } //.Xóa bảng GeneralLedger openingAccountEntryResponse.Message = GeneralLedgerDao.DeleteGeneralLedger(accountNumber, refType); if (openingAccountEntryResponse.Message != null) { openingAccountEntryResponse.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(openingAccountEntryResponse); } if (openingAccountEntryDelete == null || openingAccountEntryDelete.Count <= 0) { openingAccountEntryResponse.RefId = "0"; } else { openingAccountEntryResponse.RefId = openingAccountEntryDelete.First().RefId; } scope.Complete(); } return(openingAccountEntryResponse); } catch (Exception ex) { openingAccountEntryResponse.Message = ex.Message; return(openingAccountEntryResponse); } }
public OpeningAccountEntryReponse UpdateOpeningAccountEntry( IList <OpeningAccountEntryEntity> openingAccountEntryDetails) { var openingAccountEntryResponse = new OpeningAccountEntryReponse { Acknowledge = AcknowledgeType.Success }; try { using (var scope = new TransactionScope()) { if (openingAccountEntryDetails != null && openingAccountEntryDetails.Count > 0) { openingAccountEntryResponse.Message = OpeningAccountEntryDao.DeleteOpeningAccountEntryByAccountNumber( openingAccountEntryDetails.First().AccountNumber); // Xóa bảng GeneralLedger openingAccountEntryResponse.Message = //GeneralLedgerDao.DeleteGeneralLedger(openingAccountEntry.AccountNumber, openingAccountEntry.RefType); GeneralLedgerDao.DeleteGeneralLedger(openingAccountEntryDetails.First().AccountNumber, openingAccountEntryDetails.First().RefType); if (openingAccountEntryResponse.Message != null) { openingAccountEntryResponse.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(openingAccountEntryResponse); } foreach (var openingAccountEntry in openingAccountEntryDetails) { openingAccountEntry.RefId = Guid.NewGuid().ToString(); openingAccountEntry.BudgetChapterCode = openingAccountEntry.BudgetChapterCode == null ? null : openingAccountEntry.BudgetChapterCode; if (!openingAccountEntry.Validate()) { foreach (string error in openingAccountEntry.ValidationErrors) { openingAccountEntryResponse.Message += error + Environment.NewLine; } openingAccountEntryResponse.Acknowledge = AcknowledgeType.Failure; return(openingAccountEntryResponse); } openingAccountEntryResponse.Message = OpeningAccountEntryDao.InsertOpeningAccountEntry(openingAccountEntry); if (!string.IsNullOrEmpty(openingAccountEntryResponse.Message)) { openingAccountEntryResponse.Acknowledge = AcknowledgeType.Failure; return(openingAccountEntryResponse); } #region Insert Ledger // Insert số tiền theo tính chất của tài khoản // Nếu tài khoản có tính chất dư nợ: Insert số tiền vào cột DebitAmount // Nếu tài khoản có tính chất dư có: Insert số tiền vào cột CreditAmount var account = AccountDao.GetAccountByAccountNumber(openingAccountEntry.AccountNumber); var accountCategoryKind = account.AccountCategoryKind; // insert bang GeneralLedger if (openingAccountEntry.AccountNumber != null) { var generalLedgerEntity = new GeneralLedgerEntity { RefType = openingAccountEntry.RefType, RefNo = "OPN", CurrencyCode = String.IsNullOrEmpty(openingAccountEntry.CurrencyCode)? "VND" :openingAccountEntry.CurrencyCode, ExchangeRate = openingAccountEntry.ExchangeRate, AccountingObjectId = openingAccountEntry.AccountingObjectId, BudgetChapterCode = openingAccountEntry.BudgetChapterCode, ProjectId = openingAccountEntry.ProjectId, BudgetSourceId = openingAccountEntry.BudgetSourceId, RefDetailId = openingAccountEntry.RefId, ActivityId = openingAccountEntry.ActivityId, BudgetSubKindItemCode = openingAccountEntry.BudgetSubKindItemCode, BudgetKindItemCode = openingAccountEntry.BudgetKindItemCode, RefId = openingAccountEntry.RefId, PostedDate = openingAccountEntry.PostedDate, MethodDistributeId = openingAccountEntry.MethodDistributeId, BudgetItemCode = openingAccountEntry.BudgetItemCode, BudgetSubItemCode = openingAccountEntry.BudgetSubItemCode, BudgetDetailItemCode = openingAccountEntry.BudgetDetailItemCode, CashWithDrawTypeId = openingAccountEntry.CashWithdrawTypeId, AccountNumber = openingAccountEntry.AccountNumber, DebitAmount = openingAccountEntry.DebitAmount, DebitAmountOC = openingAccountEntry.DebitAmountOC, CreditAmount = openingAccountEntry.CreditAmount, CreditAmountOC = openingAccountEntry.CreditAmountOC, FundStructureId = openingAccountEntry.FundStructureId, GeneralLedgerId = Guid.NewGuid().ToString(), RefDate = openingAccountEntry.PostedDate, BudgetExpenseId = openingAccountEntry.BudgetExpenseId, BankId = openingAccountEntry.BankId, ContractId = openingAccountEntry.ContractId, CapitalPlanId = openingAccountEntry.CapitalPlanId }; openingAccountEntryResponse.Message = GeneralLedgerDao.InsertGeneralLedger(generalLedgerEntity); if (!string.IsNullOrEmpty(openingAccountEntryResponse.Message)) { openingAccountEntryResponse.Acknowledge = AcknowledgeType.Failure; return(openingAccountEntryResponse); } #endregion #region Insert OriginalGeneralLedger // Tạm thời chưa dùng đến đoạn insert vào bảng này //var originalGeneralLedgerEntity = new OriginalGeneralLedgerEntity //{ // OriginalGeneralLedgerId = Guid.NewGuid().ToString(), // RefType = openingAccountEntry.RefType, // RefId = openingAccountEntry.RefId, // CurrencyCode = openingAccountEntry.CurrencyId, // ExchangeRate = openingAccountEntry.ExchangeRate, // RefDetailId = openingAccountEntry.RefId, // RefDate = openingAccountEntry.PostedDate, // RefNo = "OPN", // AccountingObjectId = openingAccountEntry.AccountingObjectId, // ActivityId = openingAccountEntry.ActivityId, // Amount = openingAccountEntry.DebitAmount, // AmountOC = openingAccountEntry.DebitAmountOC, // Approved = openingAccountEntry.Approved, // BudgetChapterCode = openingAccountEntry.BudgetChapterCode, // BudgetDetailItemCode = openingAccountEntry.BudgetDetailItemCode, // BudgetItemCode = openingAccountEntry.BudgetItemCode, // BudgetKindItemCode = openingAccountEntry.BudgetKindItemCode, // BudgetSourceId = openingAccountEntry.BudgetSourceId, // BudgetSubItemCode = openingAccountEntry.BudgetSubItemCode, // BudgetSubKindItemCode = openingAccountEntry.BudgetSubKindItemCode, // CashWithDrawTypeId = openingAccountEntry.CashWithdrawTypeId, // DebitAccount = openingAccountEntry.AccountNumber, // FundStructureId = openingAccountEntry.FundStructureId, // ProjectActivityId = openingAccountEntry.ProjectActivityId, // MethodDistributeId = openingAccountEntry.MethodDistributeId, // ProjectId = openingAccountEntry.ProjectId, // PostedDate = openingAccountEntry.PostedDate, //}; //openingAccountEntryResponse.Message = // OriginalGeneralLedgerDao.InsertOriginalGeneralLedger(originalGeneralLedgerEntity); //if (!string.IsNullOrEmpty(openingAccountEntryResponse.Message)) //{ // openingAccountEntryResponse.Acknowledge = AcknowledgeType.Failure; // return openingAccountEntryResponse; //} #endregion } openingAccountEntryResponse.RefId = openingAccountEntryDetails.First().RefId; } scope.Complete(); } } return(openingAccountEntryResponse); } catch (Exception ex) { openingAccountEntryResponse.Message = ex.Message; return(openingAccountEntryResponse); } }