public ActionResult Index(int id) { ViewBag.Title = "Redigera"; var model = new EditBillViewModel(); var bill = EconomyBusiness.GetBillById(id); if (bill == null) { return(HttpNotFound("Finns ingen faktura med id: " + id.ToString())); } model.BillId = bill.BillID; model.DueDate = bill.DueDate; model.Amount = Math.Round(bill.Amount, 2); model.SelectedCategoryId = bill.CategoryID; model.SelectedSubCategoryId = bill.SubCategoryID; model.SelectedPayerId = bill.PayerID; model.Description = bill.Description; model.Categories = EconomyBusiness.GetAllCategories(); model.SubCategories = EconomyBusiness.GetAllSubCategories(); model.Payers = EconomyBusiness.GetAllPayers(); return(View("Index", model)); }
public ActionResult Edit(int id) { Guid userGuid = new Guid(User.Identity.GetUserId()); EditBillViewModel vm = new EditBillViewModel(id); return(View(vm)); }
public ActionResult Create() { ViewBag.Title = "Skapa"; var model = new EditBillViewModel(); model.Categories = EconomyBusiness.GetAllCategories(); model.SubCategories = EconomyBusiness.GetAllSubCategories(); model.Payers = EconomyBusiness.GetAllPayers(); return(View("Edit", model)); }
public ActionResult Edit_bill(int Bill_Id) { EditBillViewModel model = new EditBillViewModel(); model.products = new List <Product_quantity>(); Dictionary <string, int> m = new Dictionary <string, int>(); List <int> l = new List <int>(); model.bill = DbContext.Bills.Where(x => x.Id == Bill_Id).FirstOrDefault(); string[] ids = model.bill.products_ids.Split(' '); foreach (var p in ids) { if (p == "") { continue; } Product product = (DbContext.Store.Where(x => x.Id == Convert.ToInt32(p)).FirstOrDefault()); string name = product.Name; if (m.ContainsKey(name)) { m[name] += 1; } else { m[name] = 1; l.Add((int)product.Id); } } int i = -1; foreach (var x in m) { i++; Product_quantity product_q = new Product_quantity(); product_q.Id = l[i]; product_q.name = x.Key; product_q.Quantity = x.Value; model.products.Add(product_q); } model.products_ids = l; return(View(model)); }
public ActionResult Edit(EditBillViewModel model) { if (!ModelState.IsValid) { model.Currency = this.currencyService.GetAll() .Where(x => x.OrganisationId == model.OrganisationId).ToList() .ConvertAll(x => new CurrencyViewModel { Code = x.Code, Id = x.Id }).ToList(); return(View(model)); } //Validate iban if (!StaticFunctions.ValidateBankAccount(model.IBAN)) { model.Currency = this.currencyService.GetAll() .Where(x => x.OrganisationId == model.OrganisationId).ToList() .ConvertAll(x => new CurrencyViewModel { Code = x.Code, Id = x.Id }).ToList(); this.ModelState.AddModelError("", BillTr.IBANIsNotCorrect); return(View(model)); } //Update bill data this.billService.Update(new Bill { IBAN = model.IBAN, Id = model.BillId, CurrencyId = model.SelectedCurrency }); return(Redirect("/Admin/Organisation/Details/" + model.OrganisationId)); }
public ActionResult Edit(EditBillViewModel model) { if (!ModelState.IsValid) { return(View(model)); } Guid userGuid = new Guid(User.Identity.GetUserId()); model.Bill.UserId = userGuid; Bill bill = Mapper.Map <BillViewModel, Bill>(model.Bill); bill.BackgroundColor = bill.BackgroundColor.Replace("#", ""); bill.ForeColor = bill.ForeColor.Replace("#", ""); db.Entry(bill).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(int id) { ViewBag.Title = "Redigera"; var model = new EditBillViewModel(); var bill = EconomyBusiness.GetMonthlyBillById(id); model.BillId = bill.MonthlyBillID; model.Amount = bill.Amount; model.SelectedCategoryId = bill.CategoryID; model.SelectedSubCategoryId = bill.SubCategoryID; model.SelectedPayerId = bill.PayerID; model.Description = bill.Description; model.Categories = EconomyBusiness.GetAllCategories(); model.SubCategories = EconomyBusiness.GetAllSubCategories(); model.Payers = EconomyBusiness.GetAllPayers(); return(View("Edit", model)); }
public ActionResult Edit(int id) { var bill = this.billService.GetBill(id); var viewModel = new EditBillViewModel { OrganisationId = id, SelectedCurrency = bill.CurrencyId, BillId = bill.Id, IBAN = bill.IBAN }; viewModel.Currency = this.currencyService.GetAll() .Where(x => x.OrganisationId == id).ToList() .ConvertAll(x => new CurrencyViewModel { Code = x.Code, Id = x.Id }).ToList(); return(View(viewModel)); }
public ActionResult Edit_bill(EditBillViewModel model) { // var b = DbContext.ProductBills.Where(x => x.code == _UserManager.GetUserId(HttpContext.User) && x.code == "").ToList(); string ids = ""; float totalcost = 0; int id = model.products_ids[0]; Bills bill = new Bills(); bill.date = model.bill.date; bill.Discount = model.bill.Discount; bill.Taxes = model.bill.Taxes; bill.Id = model.bill.Id; bill.user = model.bill.user; // bill.cost = totalcost; bill.date = DateTime.UtcNow.ToString(); bill.Taxes = Convert.ToInt32(model.bill.Taxes); string UserId = DbContext.ProductBills.Where(u => u.ProductCode == id).FirstOrDefault().UserId; var removed_product = DbContext.ProductBills.Where(u => u.code == bill.Id.ToString()).ToList(); foreach (var p in removed_product) { DbContext.ProductBills.Remove(p); } DbContext.SaveChanges(); int j = 0; foreach (var p in model.products_ids) { for (int i = 0; i < model.products[j].Quantity; i++) { ids += p + " "; ProductBills pr = new ProductBills(); pr.code = model.bill.Id.ToString(); pr.UserId = UserId; pr.ProductCode = p; DbContext.ProductBills.Add(pr); } DbContext.SaveChanges(); j++; } bill.products_ids = ids; string[] b = ids.Split(' '); foreach (var p in b) { if (p == "") { continue; } Product p1 = DbContext.Store.Where(x => x.Id.ToString() == p).ToList()[0]; totalcost += p1.SellingPrice; } float z = 100; float tt = totalcost; int y1 = (Convert.ToInt32(model.bill.Discount)); float t = y1 / z; float m = (totalcost * t); totalcost -= m; y1 = Convert.ToInt32(model.bill.Taxes); t = y1 / z; m = (tt * t); totalcost += m; bill.cost = totalcost; DbContext.Bills.Update(bill); DbContext.SaveChanges(); return(RedirectToAction("Bill", new { Bill_Id = bill.Id })); }
public async Task <IActionResult> Put(long typeId, long id, [FromBody] EditBillViewModel model) { if (model == null) { return(BadRequest()); } if (model.Id != id) { return(BadRequest()); } var billType = await _billTypeRepo.GetAsync(typeId); if (billType == null) { return(NotFound(Resources.Bills.BillResource.BillTypeNotFound)); } var bill = await _billRepo.GetAsync(billType.Id, id); if (bill == null) { return(NotFound(Resources.Bills.BillResource.BillNotFound)); } #region checks Guid currencyId; var currency = await _currencyRepo.GetAsync(model.CurrencyId); if (currency != null) { currencyId = currency.Id; if (!model.CurrencyValue.HasValue) { model.CurrencyValue = currency.Value; } } else { currencyId = _defaultKeysOptions.Value.CurrencyId; model.CurrencyValue = 1; } Guid cashAccountId; var cashAccount = await _accountRepo.GetAsync(model.AccountId); if (cashAccount == null) { return(NotFound("Cash account not found")); } cashAccountId = cashAccount.Id; Guid?customerAccountId = null; if (model.CustomerAccountId.HasValue) { var customerAccount = await _accountRepo.GetAsync(model.CustomerAccountId.Value); if (customerAccount == null) { return(NotFound("Customer account not found")); } if (customerAccount.CustomerId == null) { ModelState.AddModelError("CustomerAccountId", "account not related to customer or supplier"); return(BadRequest(ModelState.GetWithErrorsKey())); } customerAccountId = customerAccount.Id; } Guid?storeId = null; if (model.StoreId.HasValue) { var store = await _storeRepo.GetAsync(model.StoreId.Value); if (store == null) { return(NotFound(Resources.Stores.StoreResource.StoreNotFound)); } storeId = store.Id; } Guid?costCenterId = null; if (model.CostCenterId.HasValue) { var costCenter = await _costCenterRepo.GetAsync(model.CostCenterId.Value); if (costCenter == null) { return(NotFound(Resources.CostCenters.CostCenterResource.CostCenterNotFound)); } costCenterId = costCenter.Id; } Guid?branchId = null; if (model.BranchId.HasValue) { var branch = await _branchRepo.GetAsync(model.BranchId.Value); if (branch == null) { return(NotFound(Resources.Branchs.BranchResource.BranchNotFound)); } branchId = branch.Id; } #endregion #region undo bill posting to stores if (bill.IsPosted) { foreach (var billItem in bill.BillItems) { await PostToStore(bill, bill.BillType, billItem, billItem.ItemUnit, true); } } #endregion bill.AccountId = cashAccountId; bill.CurrencyId = currencyId; bill.CurrencyValue = model.CurrencyValue.Value; bill.CustomerAccountId = customerAccountId; bill.CustomerName = model.CustomerAccountCodeName; bill.Date = model.Date; bill.PayType = model.PayType; bill.StoreId = storeId; bill.CostCenterId = costCenterId; bill.BranchId = branchId; bill.Extra = model.Extra; bill.Disc = model.Disc; bill.TotalPaid = model.TotalPaid; bill.Note = model.Note; bill.BillItems = new HashSet <BillItem>(); var itemsIndex = 0; // check form items if not found foreach (var item in model.Items) { itemsIndex++; Guid itemStoreId; if (model.StoreId.HasValue && model.StoreId.Value == item.StoreId) { itemStoreId = storeId.Value; } else { var itemStore = await _storeRepo.GetAsync(item.StoreId.Value); if (itemStore == null) { return(NotFound($"store in item {itemsIndex} not found")); } itemStoreId = itemStore.Id; } Guid?itemCostCenterId = null; if (model.CostCenterId.HasValue && item.CostCenterId.HasValue && model.CostCenterId == item.CostCenterId) { itemCostCenterId = costCenterId; } else { if (item.CostCenterId.HasValue) { var itemCostCenter = await _storeRepo.GetAsync(item.CostCenterId.Value); if (itemCostCenter == null) { return(NotFound($"costCenter in item {0} not found")); } } } var itemUnit = _itemUnitRepo.Get(item.ItemId, item.UnitId); if (itemUnit == null) { ModelState.AddModelError($"Items[{itemsIndex}].ItemId", "المادة غير موجودة"); return(BadRequest(ModelState.GetWithErrorsKey())); } var billItem = new BillItem(itemUnit.Id, itemStoreId, itemCostCenterId, item.Quantity, item.Price, item.Extra, item.Disc, model.Note); bill.BillItems.Add(billItem); if (bill.BillType.AutoPostToStores) { if (!await PostToStore(bill, bill.BillType, billItem, itemUnit)) { ModelState.AddModelError($"Items[{itemsIndex}].Quantity", "لا يوجد كل هذه الكمية في المستودع"); return(BadRequest(ModelState.GetWithErrorsKey())); } } } bill.CalcTotal(); #region billEntryItem if (bill.Extra + bill.TotalItemsExtra > 0 && bill.BillType.DefaultExtraAccountId.HasValue) { var extraEntryItem = new BillEntryItem(bill.Date, bill.BillType.DefaultExtraAccountId.Value, bill.CurrencyId, bill.CurrencyValue, bill.CostCenterId, BillEntryItemType.ExtraDisc, 0, bill.Extra + bill.TotalItemsExtra, bill.Note); bill.BillEntryItems.Add(extraEntryItem); } if (bill.Disc + bill.TotalItemsDisc > 0 && bill.BillType.DefaultDiscAccountId.HasValue) { var discEntryItem = new BillEntryItem(bill.Date, bill.BillType.DefaultDiscAccountId.Value, bill.CurrencyId, bill.CurrencyValue, bill.CostCenterId, BillEntryItemType.ExtraDisc, bill.Disc + bill.TotalItemsDisc, 0, bill.Note); bill.BillEntryItems.Add(discEntryItem); } foreach (var pay in model.Pays) { var payEntryItem = new BillEntryItem(pay.Date, pay.AccountId, pay.CurrencyId, pay.CurrencyValue, pay.CostCenterId, BillEntryItemType.Pay, pay.Debit, pay.Credit, pay.Note); } #endregion if (bill.IsEntryGenerated) { var entry = bill.BillEntry.Entry; if (entry.IsPosted) { // rolback await _accountBalanceService.PostEntryToAccounts(entry, true); //await PostEntryToAccounts(entry,true); } if (bill.PayType == PaysType.Cash) { bill.AccountId = cashAccountId; } else { bill.AccountId = customerAccountId; } entry = GenerateEntry(bill, bill.BillType); _entryRepo.Edit(entry, false); if (entry.IsPosted) { // Post to Account await _accountBalanceService.PostEntryToAccounts(entry); //await PostEntryToAccounts(entry); } } var affectedRows = await _billRepo.EditAsync(bill); if (affectedRows > 0) { var viewModel = AutoMapper.Mapper.Map <BillViewModel>(bill); return(CreatedAtRoute("GetBill", new { id = bill.Number }, viewModel)); } return(BadRequest()); }