public static CashRepository GetCashRepository(int?cashRepositoryId) { CashRepository cashRepository = new CashRepository(); if (cashRepositoryId != null && cashRepositoryId != 0) { const string sql = "SELECT * FROM office.cash_repositories WHERE cash_repository_id=@CashRepositoryId;"; using (NpgsqlCommand command = new NpgsqlCommand(sql)) { command.Parameters.AddWithValue("@CashRepositoryId", cashRepositoryId); using (DataTable table = DbOperations.GetDataTable(command)) { if (table != null) { if (table.Rows.Count.Equals(1)) { cashRepository = GetCashRepository(table.Rows[0]); } } } } } return(cashRepository); }
public CashRequestJournalViewModel( CashRequestJournalFilterViewModel filterViewModel, IUnitOfWorkFactory unitOfWorkFactory, ICommonServices commonServices, IFileChooserProvider fileChooserProvider, IEmployeeRepository employeeRepository, CashRepository cashRepository, ConsoleInteractiveService consoleInteractiveService ) : base(filterViewModel, unitOfWorkFactory, commonServices) { this.unitOfWorkFactory = unitOfWorkFactory ?? throw new ArgumentNullException(nameof(unitOfWorkFactory)); this.fileChooserProvider = fileChooserProvider ?? throw new ArgumentNullException(nameof(fileChooserProvider)); this.employeeRepository = employeeRepository ?? throw new ArgumentNullException(nameof(employeeRepository)); this.cashRepository = cashRepository ?? throw new ArgumentNullException(nameof(cashRepository)); this.consoleInteractiveService = consoleInteractiveService ?? throw new ArgumentNullException(nameof(consoleInteractiveService)); TabName = "Журнал заявок ДС"; UpdateOnChanges( typeof(CashRequest), typeof(CashRequestSumItem), typeof(Subdivision), typeof(Employee) ); }
public async Task <IActionResult> Edit(string id, [Bind("CashRepositoryId,Balance,CashRepositoryName,Description,EmployeeId,TotalPayments,TotalReceipts,createdAt,TotalCashflowIn,TotalCashflowOut,MainRepository,TotalEmployeePayments")] CashRepository cashRepository) { if (id != cashRepository.CashRepositoryId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cashRepository); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CashRepositoryExists(cashRepository.CashRepositoryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["EmployeeId"] = new SelectList(_context.Employee, "EmployeeId", "DisplayName", cashRepository.EmployeeId); return(View(cashRepository)); }
public async Task <IActionResult> Create([Bind("CashRepositoryId,Balance,CashRepositoryName,Description,EmployeeId,TotalPayments,TotalReceipts,createdAt,TotalCashflowIn,TotalCashflowOut,MainRepository,TotalEmployeePayments")] CashRepository cashRepository) { if (ModelState.IsValid) { _context.Add(cashRepository); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["EmployeeId"] = new SelectList(_context.Employee, "EmployeeId", "DisplayName", cashRepository.EmployeeId); return(View(cashRepository)); }
private static CashRepository GetCashRepository(DataRow row) { CashRepository cashRepository = new CashRepository(); cashRepository.CashRepositoryId = Conversion.TryCastInteger(DataRowHelper.GetColumnValue(row, "cash_repository_id")); cashRepository.OfficeId = Conversion.TryCastInteger(DataRowHelper.GetColumnValue(row, "office_id")); cashRepository.Office = GetOffice(cashRepository.OfficeId); cashRepository.CashRepositoryCode = Conversion.TryCastString(DataRowHelper.GetColumnValue(row, "cash_repository_code")); cashRepository.CashRepositoryName = Conversion.TryCastString(DataRowHelper.GetColumnValue(row, "cash_repository_name")); cashRepository.ParentCashRepositoryId = Conversion.TryCastInteger(DataRowHelper.GetColumnValue(row, "parent_cash_repository_id")); cashRepository.ParentCashRepository = GetCashRepository(cashRepository.ParentCashRepositoryId); cashRepository.Description = Conversion.TryCastString(DataRowHelper.GetColumnValue(row, "description")); return(cashRepository); }
// GET: MoneyTransferOrder/Create public IActionResult Create(string id) { ViewData["StatusMessage"] = TempData["StatusMessage"]; ViewData["CashRepositoryIdFrom"] = new SelectList(_context.CashRepository, "CashRepositoryId", "CashRepositoryName"); ViewData["CashRepositoryIdTo"] = new SelectList(_context.CashRepository, "CashRepositoryId", "CashRepositoryName"); MoneyTransferOrder obj = new MoneyTransferOrder(); CashRepository cr = _context.CashRepository.Where(x => x.CashRepositoryId == id).FirstOrDefault(); if (id != null) { obj.CashRepositoryIdFrom = id; obj.CashRepositoryIdTo = _context.CashRepository.Where(x => x.MainRepository == true).FirstOrDefault().CashRepositoryId; obj.MoneyTransferOrderStatus = MoneyTransferOrderStatus.Open; obj.PaymentAmount = cr.Balance; } return(View(obj)); }
private static Collection <CashRepository> GetCashRepositories(DataTable table) { Collection <CashRepository> cashRepositoryCollection = new Collection <CashRepository>(); if (table == null || table.Rows.Count.Equals(0)) { return(cashRepositoryCollection); } foreach (DataRow row in table.Rows) { if (row != null) { CashRepository cashRepository = GetCashRepository(row); cashRepositoryCollection.Add(cashRepository); } } return(cashRepositoryCollection); }
public CashService(CashRepository repo) { _repo = repo; }
public async Task <IActionResult> Create([Bind("CashflowOutId,MoneyTransferOrderId,CashflowOutNumber,CashflowOutDate,Description,CashRepositoryIdFrom,CashRepositoryIdTo,HasChild,createdAt")] CashflowOut cashflowOut) { if (ModelState.IsValid) { //check MoneyTransferOrder CashflowOut check = await _context.CashflowOut .Include(x => x.MoneyTransferOrder) .SingleOrDefaultAsync(x => x.MoneyTransferOrderId.Equals(cashflowOut.MoneyTransferOrderId)); if (check != null) { ViewData["StatusMessage"] = "Σφάλμα. Η εντολή εκροής έχει ήδη εκδοθεί. " + check.CashflowOutNumber; ViewData["MoneyTransferOrderId"] = new SelectList(_context.MoneyTransferOrder.ToList(), "MoneyTransferOrderId", "MoneyTransferOrderNumber"); ViewData["CashRepositoryIdFrom"] = new SelectList(_context.CashRepository, "CashRepositoryId", "CashRepositoryName"); ViewData["CashRepositoryIdTo"] = new SelectList(_context.CashRepository, "CashRepositoryId", "CashRepositoryName"); return(View(cashflowOut)); } //check Balance bool isBalanceOK = true; MoneyTransferOrder mto = _context.MoneyTransferOrder.Where(x => x.MoneyTransferOrderId == cashflowOut.MoneyTransferOrderId).FirstOrDefault(); MoneyTransferOrder to = await _context.MoneyTransferOrder.Where(x => x.MoneyTransferOrderId.Equals(cashflowOut.MoneyTransferOrderId)).FirstOrDefaultAsync(); cashflowOut.CashRepositoryIdFrom = to.CashRepositoryIdFrom; cashflowOut.CashRepositoryIdTo = to.CashRepositoryIdTo; cashflowOut.CashRepositoryFrom = await _context.CashRepository.Include(x => x.Employee).SingleOrDefaultAsync(x => x.CashRepositoryId.Equals(cashflowOut.CashRepositoryIdFrom)); cashflowOut.CashRepositoryTo = await _context.CashRepository.Include(x => x.Employee).SingleOrDefaultAsync(x => x.CashRepositoryId.Equals(cashflowOut.CashRepositoryIdTo)); to.isIssued = true; CashRepository cashrepository = await _context.CashRepository.Where(x => x.CashRepositoryId == cashflowOut.CashRepositoryIdFrom).FirstAsync(); if (mto != null && cashrepository != null) { if (cashrepository.Balance < mto.PaymentAmount) { isBalanceOK = false; } } else { isBalanceOK = false; } if (!isBalanceOK) { TempData["StatusMessage"] = "Σφάλμα. Υπάρχει πρόβλημα στα ταμειακά διαθέσιμα, το ταμείο σας έχει " + cashrepository.Balance + " €"; return(RedirectToAction(nameof(Create))); } _context.Add(cashflowOut); await _context.SaveChangesAsync(); TempData["TransMessage"] = "Η ταμειακή εκροή " + cashflowOut.CashflowOutNumber + " έγινε με Επιτυχία!"; return(RedirectToAction("Details", "CashRepository", new { id = cashflowOut.CashRepositoryIdTo })); } ViewData["MoneyTransferOrderId"] = new SelectList(_context.MoneyTransferOrder, "MoneyTransferOrderId", "MoneyTransferOrderNumber", cashflowOut.MoneyTransferOrderId); return(View(cashflowOut)); }