// GET: AccountAdjust/Create public IActionResult Create() { ViewBag.AccountBankAccount = new SelectList(_context.AccountBankAccount.OrderBy(m => m.AccountName).ToList(), "id", "AccountName"); AccountAdjust accountAdjust = new AccountAdjust(); accountAdjust.ReferenceNo = "A" + Utility.GetLocalDateTime().ToString("yyyyMMddHHmmss"); return(View(accountAdjust)); }
public async Task <IActionResult> Edit(int id, [Bind("id,ReferenceNo,AccountBankAccountID,Amount,ActualDate,Reference,DateTimeModified,DateTimeAdded")] AccountAdjust accountAdjust) { if (id != accountAdjust.id) { return(NotFound()); } if (ModelState.IsValid) { try { accountAdjust.DateTimeModified = Utility.GetLocalDateTime(); _context.Update(accountAdjust); ///////////////////////////////////////////////////////////////////////////// //update AccountTxn var accountTxn = await _context.AccountTxn.AsNoTracking().SingleOrDefaultAsync(m => m.Type == "A" && m.ReferenceID == id); if (accountTxn != null) { accountTxn.AccountBankAccountID = accountAdjust.AccountBankAccountID; if (accountAdjust.Amount >= 0) { accountTxn.AmountCredit = accountAdjust.Amount; accountTxn.AmountDebit = null; } else { accountTxn.AmountCredit = null; accountTxn.AmountDebit = Math.Abs(accountAdjust.Amount); } accountTxn.DateTimeModified = Utility.GetLocalDateTime(); _context.Update(accountTxn); } ///////////////////////////////////////////////////////////////////////////// await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AccountAdjustExists(accountAdjust.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewBag.AccountBankAccount = new SelectList(_context.AccountBankAccount.OrderBy(m => m.AccountName).ToList(), "id", "AccountName"); return(View(accountAdjust)); }
public async Task <IActionResult> Create([Bind("id,ReferenceNo,AccountBankAccountID,Amount,ActualDate,Reference,DateTimeModified,DateTimeAdded")] AccountAdjust accountAdjust) { if (ModelState.IsValid) { accountAdjust.DateTimeModified = Utility.GetLocalDateTime();// Utility.GetLocalDateTime(); accountAdjust.DateTimeAdded = Utility.GetLocalDateTime(); _context.Add(accountAdjust); await _context.SaveChangesAsync(); ///////////////////////////////////////////////////////////////////////////// //update AccountTxn AccountTxn accountTxn = new AccountTxn(); accountTxn.Type = "A"; accountTxn.ReferenceID = accountAdjust.id; accountTxn.AccountBankAccountID = accountAdjust.AccountBankAccountID; if (accountAdjust.Amount >= 0) { accountTxn.AmountCredit = accountAdjust.Amount; } else { accountTxn.AmountDebit = Math.Abs(accountAdjust.Amount); } accountTxn.DateTimeModified = Utility.GetLocalDateTime(); accountTxn.DateTimeAdded = Utility.GetLocalDateTime(); _context.Add(accountTxn); ///////////////////////////////////////////////////////////////////////////// await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.AccountBankAccount = new SelectList(_context.AccountBankAccount.OrderBy(m => m.AccountName).ToList(), "id", "AccountName"); return(View(accountAdjust)); }