/// <summary> /// Adds the account balance for debit. /// </summary> /// <param name="buPlanReceipt">The bu plan receipt.</param> /// <param name="buPlanReceiptDetail">The bu plan receipt detail.</param> /// <returns></returns> public AccountBalanceEntity AddAccountBalanceForDebit(BUBudgetReserveEntity buPlanReceipt, BUBudgetReserveDetailEntity buPlanReceiptDetail) { return(new AccountBalanceEntity { AccountBalanceId = Guid.NewGuid().ToString(), //AccountNumber = buPlanReceiptDetail.DebitAccount, CurrencyCode = buPlanReceipt.CurrencyCode, ExchangeRate = buPlanReceipt.ExchangeRate, BalanceDate = buPlanReceipt.PostedDate, MovementDebitAmountOC = buPlanReceiptDetail.AmountOC, MovementDebitAmount = buPlanReceiptDetail.Amount, MovementCreditAmountOC = 0, MovementCreditAmount = 0, BudgetSourceId = buPlanReceiptDetail.BudgetSourceId, BudgetChapterCode = buPlanReceipt.BudgetChapterCode, BudgetKindItemCode = buPlanReceiptDetail.BudgetKindItemCode, BudgetSubKindItemCode = buPlanReceiptDetail.BudgetSubKindItemCode, BudgetItemCode = buPlanReceiptDetail.BudgetItemCode, BudgetSubItemCode = buPlanReceiptDetail.BudgetSubItemCode, ProjectId = buPlanReceiptDetail.ProjectId, //BankAccount = buPlanReceiptDetail.BankId, FundStructureId = buPlanReceiptDetail.FundStructureId, BudgetDetailItemCode = buPlanReceiptDetail.BudgetDetailItemCode }); }
/// <summary> /// Deletes the bu plan receipt. /// </summary> /// <param name="buBudgetReserve">The bu budget reserve.</param> /// <returns></returns> public string DeleteBUBudgetReserve(BUBudgetReserveEntity buBudgetReserve) { const string procedures = @"uspDelete_BUBudgetReserve"; object[] parms = { "@RefId", buBudgetReserve.RefId }; return(Db.Delete(procedures, true, parms)); }
public List <BUBudgetReserveEntity> GetBUBudgetReserves(string connectionString) { List <BUBudgetReserveEntity> buentity = new List <BUBudgetReserveEntity>(); using (var context = new MISAEntity(connectionString)) { var querry = context.BUBudgetReserveDetails.ToList(); var projects = context.Projects.ToList(); var currencys = context.CCies.ToList(); var budgetsource = context.BudgetSources.ToList(); var listitems = context.ListItems.ToList(); var funds = context.Funds.ToList(); var fundstructures = context.FundStructures.ToList(); var budgetproviders = context.BudgetProvidences.ToList(); var accountingobject = context.AccountingObjects.ToList(); var projectexpenses = context.ProjectExpenses.ToList(); var activity = context.Activities.ToList(); var tasks = context.Tasks.ToList(); var topics = context.Topics.ToList(); banks = context.BankInfoes.ToList(); var department = context.Departments.ToList(); var resultcontext = context.BUBudgetReserves.ToList(); var fixedasset = context.FixedAssets.ToList(); var inventoryitems = context.InventoryItems.ToList(); var stocks = context.Stocks.ToList(); var invoiceformnumber = context.InvoiceFormNumbers.ToList(); foreach (var result in resultcontext) { var newresult = new BUBudgetReserveEntity(); newresult.RefId = result.RefID.ToString(); newresult.RefDate = result.RefDate; newresult.PostedDate = result.PostedDate; newresult.RefNo = result.RefNo; newresult.RefType = ConvRefType.ConvRefType(result.RefType); newresult.BudgetChapterCode = result.BudgetChapterCode; newresult.BudgetChapterName = result.BudgetChapterName; newresult.JournalMemo = result.JournalMemo; newresult.CurrencyCode = result.CCY == null ? null : result.CCY.CurrencyID; newresult.ExchangeRate = result.ExchangeRate; newresult.TotalAmount = result.TotalAmount; newresult.TotalAmountOC = result.TotalAmountOC; newresult.Posted = result.Posted; newresult.EditVersion = result.EditVersion; newresult.PostVersion = result.PostVersion; newresult.BudgetReserveDetails = result.BUBudgetReserveDetails.Count <= 0 ? null : BUBudgetReserveDetails(result.BUBudgetReserveDetails.ToList(), result.RefID.ToString()); buentity.Add(newresult); } } return(buentity); }
/// <summary> /// Inserts the account balance. /// </summary> /// <param name="buPlanReceipt">The bu plan receipt.</param> /// <param name="buPlanReceiptDetail">The bu plan receipt detail.</param> public void InsertAccountBalance(BUBudgetReserveEntity buPlanReceipt, BUBudgetReserveDetailEntity buPlanReceiptDetail) { //insert AccountBalance for debit account var accountBalanceForDebit = AddAccountBalanceForDebit(buPlanReceipt, buPlanReceiptDetail); var accountBalanceForDebitExit = AccountBalanceDao.GetExitsAccountBalance(accountBalanceForDebit); if (accountBalanceForDebitExit != null) { UpdateAccountBalance(accountBalanceForDebitExit, accountBalanceForDebit.MovementDebitAmountOC, accountBalanceForDebit.MovementDebitAmount, true, 1); } else { AccountBalanceDao.InsertAccountBalance(accountBalanceForDebit); } }
/// <summary> /// Takes the specified b u budget reserve entity. /// </summary> /// <param name="bUBudgetReserveEntity">The b u budget reserve entity.</param> /// <returns></returns> private object[] Take(BUBudgetReserveEntity bUBudgetReserveEntity) { return(new object[] { "@RefID", bUBudgetReserveEntity.RefId, "@RefDate", bUBudgetReserveEntity.RefDate, "@PostedDate", bUBudgetReserveEntity.PostedDate, "@RefNo", bUBudgetReserveEntity.RefNo, "@RefType", bUBudgetReserveEntity.RefType, "@BudgetChapterCode", bUBudgetReserveEntity.BudgetChapterCode, "@BudgetChapterName", bUBudgetReserveEntity.BudgetChapterName, "@JournalMemo", bUBudgetReserveEntity.JournalMemo, "@CurrencyCode", bUBudgetReserveEntity.CurrencyCode, "@ExchangeRate", bUBudgetReserveEntity.ExchangeRate, "@TotalAmount", bUBudgetReserveEntity.TotalAmount, "@TotalAmountOC", bUBudgetReserveEntity.TotalAmountOC, "@Posted", bUBudgetReserveEntity.Posted, "@EditVersion", bUBudgetReserveEntity.EditVersion, "@PostVersion", bUBudgetReserveEntity.PostVersion }); }
/// <summary> /// Updates the account balance. /// </summary> /// <param name="buPlanReceipt">The bu plan receipt.</param> /// <returns></returns> public string UpdateAccountBalance(BUBudgetReserveEntity buPlanReceipt) { var buPlanReceiptDetails = BUBudgetReserveDetailDao.GetBUBudgetReserveDetailsByRefId(buPlanReceipt.RefId); foreach (var buPlanReceiptDetail in buPlanReceiptDetails) { string message; var accountBalanceForDebit = AddAccountBalanceForDebit(buPlanReceipt, buPlanReceiptDetail); var accountBalanceForDebitExit = AccountBalanceDao.GetExitsAccountBalance(accountBalanceForDebit); if (accountBalanceForDebitExit != null) { message = UpdateAccountBalance(accountBalanceForDebitExit, accountBalanceForDebit.MovementDebitAmountOC, accountBalanceForDebit.MovementDebitAmount, false, 1); if (message != null) { return(message); } } } return(null); }
/// <summary> /// Updates the bu plan receipt. /// </summary> /// <param name="buBudgetReserve">The bu budget reserve.</param> /// <returns></returns> public string UpdateBUBudgetReserve(BUBudgetReserveEntity buBudgetReserve) { const string procedures = @"uspUpdate_BUBudgetReserve"; return(Db.Update(procedures, true, Take(buBudgetReserve))); }
/// <summary> /// Inserts the bu plan receipt. /// </summary> /// <param name="buBudgetReserve">The bu budget reserve.</param> /// <returns></returns> public string InsertBUBudgetReserve(BUBudgetReserveEntity buBudgetReserve) { const string procedures = @"uspInsert_BUBudgetReserve"; return(Db.Insert(procedures, true, Take(buBudgetReserve))); }
/// <summary> /// Updates the ca payment. /// </summary> /// <param name="buPlanReceiptEntity">The bu plan receipt entity.</param> /// <returns> /// CAPaymentResponse. /// </returns> public BUBudgetReserveResponse UpdateBUBudgetReservet(BUBudgetReserveEntity buPlanReceiptEntity) { var buPlanReceiptResponse = new BUBudgetReserveResponse { Acknowledge = AcknowledgeType.Success }; try { if (buPlanReceiptEntity != null && !buPlanReceiptEntity.Validate()) { foreach (var error in buPlanReceiptEntity.ValidationErrors) { buPlanReceiptResponse.Message += error + Environment.NewLine; } buPlanReceiptResponse.Acknowledge = AcknowledgeType.Failure; return(buPlanReceiptResponse); } using (var scope = new TransactionScope()) { if (buPlanReceiptEntity != null) { var buPlanReceiptForExisting = BUBudgetReserveDao.GetBUBudgetReserve(buPlanReceiptEntity.RefNo.Trim(), buPlanReceiptEntity.PostedDate); if (buPlanReceiptForExisting != null && buPlanReceiptForExisting.PostedDate.Year == buPlanReceiptEntity.PostedDate.Year) { if (buPlanReceiptForExisting.RefId != buPlanReceiptEntity.RefId) { buPlanReceiptResponse.Acknowledge = AcknowledgeType.Failure; buPlanReceiptResponse.Message = @"Số chứng từ '" + buPlanReceiptEntity.RefNo.Trim() + @"' đã tồn tại!"; return(buPlanReceiptResponse); } } buPlanReceiptResponse.Message = BUBudgetReserveDao.UpdateBUBudgetReserve(buPlanReceiptEntity); if (buPlanReceiptResponse.Message != null) { buPlanReceiptResponse.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(buPlanReceiptResponse); } #region Update account balance //Trừ đi số tiền của chứng từ cũ trước khi cộng thêm số tiền mới UpdateAccountBalance(buPlanReceiptEntity); if (buPlanReceiptResponse.Message != null) { buPlanReceiptResponse.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(buPlanReceiptResponse); } #endregion // Xóa bảng BUBudgetReservetDetail buPlanReceiptResponse.Message = BUBudgetReserveDetailDao.DeleteBUBudgetReserveDetail(buPlanReceiptEntity.RefId); if (buPlanReceiptResponse.Message != null) { buPlanReceiptResponse.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(buPlanReceiptResponse); } // Xóa bảng GeneralLedger buPlanReceiptResponse.Message = GeneralLedgerDao.DeleteGeneralLedger(buPlanReceiptEntity.RefId); if (buPlanReceiptResponse.Message != null) { buPlanReceiptResponse.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(buPlanReceiptResponse); } // Xóa bảng OriginalGeneralLedger buPlanReceiptResponse.Message = OriginalGeneralLedgerDao.DeleteOriginalGeneralLedger(buPlanReceiptEntity.RefId); if (buPlanReceiptResponse.Message != null) { buPlanReceiptResponse.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(buPlanReceiptResponse); } foreach (var buPlanReceiptDetail in buPlanReceiptEntity.BudgetReserveDetails) { buPlanReceiptDetail.RefId = buPlanReceiptEntity.RefId; buPlanReceiptDetail.RefDetailId = Guid.NewGuid().ToString(); if (!buPlanReceiptDetail.Validate()) { foreach (string error in buPlanReceiptDetail.ValidationErrors) { buPlanReceiptResponse.Message += error + Environment.NewLine; } buPlanReceiptResponse.Acknowledge = AcknowledgeType.Failure; return(buPlanReceiptResponse); } buPlanReceiptResponse.Message = BUBudgetReserveDetailDao.InsertBUBudgetReserveDetail(buPlanReceiptDetail); if (!string.IsNullOrEmpty(buPlanReceiptResponse.Message)) { buPlanReceiptResponse.Acknowledge = AcknowledgeType.Failure; return(buPlanReceiptResponse); } #region Insert into AccountBalance // Cộng thêm số tiền mới sau khi sửa chứng từ InsertAccountBalance(buPlanReceiptEntity, buPlanReceiptDetail); if (buPlanReceiptResponse.Message != null) { buPlanReceiptResponse.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(buPlanReceiptResponse); } #endregion #region Insert into GeneralLedger if (buPlanReceiptDetail.BankAccount != null) { var generalLedgerEntity = new GeneralLedgerEntity { RefType = buPlanReceiptEntity.RefType, RefNo = buPlanReceiptEntity.RefNo, ProjectId = buPlanReceiptDetail.ProjectId, BudgetSourceId = buPlanReceiptDetail.BudgetSourceId, Description = buPlanReceiptDetail.Description, RefDetailId = buPlanReceiptDetail.RefDetailId, ExchangeRate = buPlanReceiptEntity.ExchangeRate, BudgetSubKindItemCode = buPlanReceiptDetail.BudgetSubKindItemCode, CurrencyCode = buPlanReceiptEntity.CurrencyCode, BudgetKindItemCode = buPlanReceiptDetail.BudgetKindItemCode, RefId = buPlanReceiptEntity.RefId, PostedDate = buPlanReceiptEntity.PostedDate, BudgetItemCode = buPlanReceiptDetail.BudgetItemCode, ListItemId = buPlanReceiptDetail.ListItemId, BudgetSubItemCode = buPlanReceiptDetail.BudgetSubItemCode, BudgetDetailItemCode = buPlanReceiptDetail.BudgetDetailItemCode, //AccountNumber = buPlanReceiptDetail.DebitAccount, //DebitAmount = buPlanReceiptDetail.DebitAccount == null ? 0 : buPlanReceiptDetail.Amount, //DebitAmountOC = buPlanReceiptDetail.DebitAccount == null ? 0 : buPlanReceiptDetail.AmountOC, CreditAmount = 0, CreditAmountOC = 0, FundStructureId = buPlanReceiptDetail.FundStructureId, GeneralLedgerId = Guid.NewGuid().ToString(), JournalMemo = buPlanReceiptEntity.JournalMemo, RefDate = buPlanReceiptEntity.RefDate, SortOrder = buPlanReceiptDetail.SortOrder }; buPlanReceiptResponse.Message = GeneralLedgerDao.InsertGeneralLedger(generalLedgerEntity); if (!string.IsNullOrEmpty(buPlanReceiptResponse.Message)) { buPlanReceiptResponse.Acknowledge = AcknowledgeType.Failure; return(buPlanReceiptResponse); } } #endregion #region Insert OriginalGeneralLedger var originalGeneralLedgerEntity = new OriginalGeneralLedgerEntity { OriginalGeneralLedgerId = Guid.NewGuid().ToString(), RefType = buPlanReceiptEntity.RefType, RefId = buPlanReceiptEntity.RefId, RefDetailId = buPlanReceiptDetail.RefDetailId, RefDate = buPlanReceiptEntity.RefDate, RefNo = buPlanReceiptEntity.RefNo, Amount = buPlanReceiptDetail.Amount, AmountOC = buPlanReceiptDetail.AmountOC, //BankId = buPlanReceiptDetail.BankId, BudgetChapterCode = buPlanReceiptEntity.BudgetChapterCode, BudgetDetailItemCode = buPlanReceiptDetail.BudgetDetailItemCode, BudgetItemCode = buPlanReceiptDetail.BudgetItemCode, BudgetKindItemCode = buPlanReceiptDetail.BudgetKindItemCode, BudgetSourceId = buPlanReceiptDetail.BudgetSourceId, BudgetSubItemCode = buPlanReceiptDetail.BudgetSubItemCode, BudgetSubKindItemCode = buPlanReceiptDetail.BudgetSubKindItemCode, //DebitAccount = buPlanReceiptDetail.DebitAccount, Description = buPlanReceiptDetail.Description, FundStructureId = buPlanReceiptDetail.FundStructureId, JournalMemo = buPlanReceiptEntity.JournalMemo, ProjectId = buPlanReceiptDetail.ProjectId, //ToBankId = buPlanReceiptDetail.BankId, SortOrder = buPlanReceiptDetail.SortOrder, PostedDate = buPlanReceiptEntity.PostedDate, CurrencyCode = buPlanReceiptEntity.CurrencyCode, ExchangeRate = buPlanReceiptEntity.ExchangeRate, }; buPlanReceiptResponse.Message = OriginalGeneralLedgerDao.InsertOriginalGeneralLedger(originalGeneralLedgerEntity); if (!string.IsNullOrEmpty(buPlanReceiptResponse.Message)) { buPlanReceiptResponse.Acknowledge = AcknowledgeType.Failure; return(buPlanReceiptResponse); } #endregion } if (buPlanReceiptResponse.Message != null) { buPlanReceiptResponse.Acknowledge = AcknowledgeType.Failure; scope.Dispose(); return(buPlanReceiptResponse); } buPlanReceiptResponse.RefId = buPlanReceiptEntity.RefId; } scope.Complete(); } return(buPlanReceiptResponse); } catch (Exception ex) { buPlanReceiptResponse.Message = ex.Message; return(buPlanReceiptResponse); } }