Ejemplo n.º 1
0
        public IActionResult SaveBill(CreatePayableView viewModel)
        {
            if (ModelState.IsValid)
            {
                viewModel.LineItemList = _itemManager.PayableList();

                viewModel.BankAccountList = _bankAccountManager.GetBankAccounts();

                if (_payableManager.GetLineItemBudget(viewModel.Economic) == 0)
                {
                    ModelState.AddModelError("Economic", CreatePayableView.EconomicConfigError);

                    return(View("CreateBill", viewModel));
                }


                if (!_payableManager.IsBelowBudgetLimit(decimal.Parse(viewModel.Amount), viewModel.Economic))
                {
                    ModelState.AddModelError("Amount", CreatePayableView.AmountLimitError);

                    return(View("CreateBill", viewModel));
                }


                var payable = _payableManager.Save(viewModel);

                TempData["AlertMessage"] = $"Your bill was created successfully. Your bill number is BP-{payable.BillNumber}";


                return(RedirectToAction("Index"));
            }

            return(View("CreateBill", viewModel));
        }
Ejemplo n.º 2
0
        public BillPayable Save(CreatePayableView viewModel)
        {
            int counter = _unitOfWork.BillPayablesRepository.Items.ToList().Count;

            var payable = new BillPayable()
            {
                Id              = viewModel.Id,
                PayerId         = viewModel.PayerId,
                Description     = viewModel.Description,
                Organisation    = viewModel.Organisation,
                EconomicId      = viewModel.Economic,
                GeoCode         = viewModel.GeoCode,
                FundId          = viewModel.Fund,
                Function        = viewModel.Function,
                Quantity        = viewModel.Quantity,
                Rate            = viewModel.Rate,
                Amount          = decimal.Parse(viewModel.Amount),
                TransactionDate = viewModel.TransactionDate,
                Status          = BillStatusType.DRAFT,
            };

            //Random random = new Random();
            //int randomNumber = random.Next(0, 10000);

            int billNumber = ++counter;

            payable.BillNumber = Convert.ToString(billNumber);

            _unitOfWork.BillPayablesRepository.Insert(payable);

            _unitOfWork.SaveChanges();

            return(payable);
        }
Ejemplo n.º 3
0
        public IActionResult CreateBill()
        {
            var viewModel = new CreatePayableView
            {
                TransactionDate = DateTime.Now.ToString(DateFormatKey.Default),
                LineItemList    = _itemManager.PayableList(),
                BankAccountList = _bankAccountManager.GetBankAccounts()
            };

            return(View(viewModel));
        }