// Income // Transaction // Invoice public async Task <WrapperIncomeListVM> Add(IncomeVM vm) { var invoiceToAdd = _utilService.GetMapper().Map <IncomeVM, Invoice>(vm); var incomeToAdd = _utilService.GetMapper().Map <IncomeVM, Income>(vm); var transactionToAdd = _utilService.GetMapper().Map <IncomeVM, TblTransaction>(vm); //string uniqueIdTask =await _repositoryWrapper.Income.GetUniqueId(); //// Todo need to aandle unique id from db //entityToAdd.UniqueId = uniqueIdTask; _repositoryWrapper.Invoice.Create(invoiceToAdd); incomeToAdd.InvoiceId = invoiceToAdd.Id; _repositoryWrapper.Income.Create(incomeToAdd); transactionToAdd.InvoiceId = invoiceToAdd.Id; _repositoryWrapper.Transaction.Create(transactionToAdd); Task <int> t1 = _repositoryWrapper.Income.SaveChangesAsync(); Task <int> t2 = _repositoryWrapper.Invoice.SaveChangesAsync(); Task <int> t3 = _repositoryWrapper.Transaction.SaveChangesAsync(); await Task.WhenAll(t1, t2, t3); var dataParam = new GetDataListVM() { FactoryId = vm.FactoryId, PageNumber = 1, PageSize = 10, TotalRows = 0 }; WrapperIncomeListVM data = await GetListPaged(dataParam); return(data); }
public IActionResult SubmitOrder(int orderID) { Order currentOrder = Context.Order.Find(orderID); IncomeVM incomeVM = new IncomeVM(Context); if (currentOrder != null) { incomeVM.OrderTotalCost(orderID); Context.SaveChanges(); } //CompanyIncome companyIncome = Context.CompanyIncome.FirstOrDefault(i=>i.DateFrom.Month == currentOrder.Date.Month && i.DateFrom.Year == currentOrder.Date.Year); //if (companyIncome != null) //{ // companyIncome.Income += currentOrder.TotalPrice; // companyIncome.DelivarymenCost += currentOrder.DelivarymanCost; // companyIncome.Profit = companyIncome.Income - companyIncome.DelivarymenCost; // Context.SaveChanges(); //} //else //{ // incomeVM.AddCompanyIncome(currentOrder.Date); //} return(RedirectToAction("Index", "Home")); }
public IActionResult DeliveredOrder(int orderID) { Order deliveredOrder = Context.Order.Find(orderID); IncomeVM incomeVM = new IncomeVM(Context); deliveredOrder.Status = true; Context.SaveChanges(); // add company income : CompanyIncome companyIncome = Context.CompanyIncome.FirstOrDefault(i => i.DateFrom.Month == deliveredOrder.Date.Month && i.DateFrom.Year == deliveredOrder.Date.Year); if (companyIncome != null) { companyIncome.Income += deliveredOrder.TotalPrice; companyIncome.DelivarymenCost += deliveredOrder.DelivarymanCost; companyIncome.Profit = companyIncome.Income - companyIncome.DelivarymenCost; Context.SaveChanges(); } else { incomeVM.AddCompanyIncome(deliveredOrder.Date); } return(RedirectToAction("GetNotDeliveredOrders")); }
public IActionResult GetAllPharmacytsbyArea(OrderInfoVM orderInfoVM) { IncomeVM vM = new IncomeVM(this.Context); if (ModelState.IsValid) { Order checkExistOrder = Context.Order.FirstOrDefault(o => o.Date.Hour == DateTime.Now.Hour && o.CustomerID == GetLoginCustomer()); string uniqueFileName = null; if (checkExistOrder != null) { OrderInformation checkExistOrderInfo = Context.OrderInformation.FirstOrDefault(o => o.PlaceID == orderInfoVM.PlaceID && o.OrderID == checkExistOrder.ID); if (checkExistOrderInfo == null) { if (orderInfoVM.Image != null) { string uploadsFolder = Path.Combine(_environment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + orderInfoVM.Image.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); orderInfoVM.Image.CopyTo(new FileStream(filePath, FileMode.Create)); } OrderInformation newOrder = new OrderInformation(); newOrder.PlaceID = orderInfoVM.PlaceID; newOrder.OrderImage = uniqueFileName; newOrder.DelivaryCost = vM.DelivaryPlaceCost(newOrder.PlaceID, vM.GetCustomerArea(GetLoginCustomer()).ID); newOrder.OrderID = checkExistOrder.ID; Context.OrderInformation.Add(newOrder); Context.SaveChanges(); } } else { if (orderInfoVM.Image != null) { string uploadsFolder = Path.Combine(_environment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + orderInfoVM.Image.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); orderInfoVM.Image.CopyTo(new FileStream(filePath, FileMode.Create)); } checkExistOrder = SetNewOrder(); Context.Order.Add(checkExistOrder); Context.SaveChanges(); OrderInformation newOrderInfo = SetNewOrderInfo(orderInfoVM.PlaceID, checkExistOrder.ID, uniqueFileName); Context.OrderInformation.Add(newOrderInfo); Context.SaveChanges(); } //updateTotalcost(checkExistOrder.ID); return(RedirectToAction("ShoppingCard", "Customer")); } return(View()); }
private OrderInformation SetNewOrderInfo(int placeID, int orderID) { IncomeVM vM = new IncomeVM(Context); OrderInformation newOrderInfo = new OrderInformation(); newOrderInfo.PlaceID = placeID; newOrderInfo.DelivaryCost = vM.DelivaryPlaceCost(placeID, vM.GetCustomerArea(GetLoginCustomer()).ID); newOrderInfo.OrderID = orderID; return(newOrderInfo); }
public IActionResult BuyItem(int menuID, int itemQuantity, int supermarketID) { IncomeVM vM = new IncomeVM(Context); Order checkExistOrder = Context.Order.FirstOrDefault(o => o.Date.Hour == DateTime.Now.Hour && o.CustomerID == GetLoginCustomer()); if (checkExistOrder != null) { OrderInformation checkExistOrderInfo = Context.OrderInformation.FirstOrDefault(o => o.PlaceID == supermarketID && o.OrderID == checkExistOrder.ID); if (checkExistOrderInfo == null) { OrderInformation newOrderInfo = new OrderInformation(); newOrderInfo.PlaceID = supermarketID; newOrderInfo.DelivaryCost = vM.DelivaryPlaceCost(supermarketID, vM.GetCustomerArea(GetLoginCustomer()).ID); newOrderInfo.OrderID = checkExistOrder.ID; Context.OrderInformation.Add(newOrderInfo); Context.SaveChanges(); OrderMenuItems menuItem = new OrderMenuItems(); menuItem.MenuID = menuID; menuItem.MenuItemQuantity = itemQuantity; menuItem.OrderInformationID = newOrderInfo.ID; Context.OrderMenuItems.Add(menuItem); Context.SaveChanges(); } else { OrderMenuItems menuItem = new OrderMenuItems(); menuItem.MenuID = menuID; menuItem.MenuItemQuantity = itemQuantity; menuItem.OrderInformationID = checkExistOrderInfo.ID; Context.OrderMenuItems.Add(menuItem); Context.SaveChanges(); } } else { checkExistOrder = SetNewOrder(); Context.Order.Add(checkExistOrder); Context.SaveChanges(); OrderInformation newOrderInfo = SetNewOrderInfo(supermarketID, checkExistOrder.ID); Context.OrderInformation.Add(newOrderInfo); Context.SaveChanges(); OrderMenuItems newOrderMenuItems = SetNewMenuItem(menuID, newOrderInfo.ID, itemQuantity); Context.OrderMenuItems.Add(newOrderMenuItems); Context.SaveChanges(); } return(Content("Added to Shopping Card")); }
public void updateTotalcost(int orderID) { Order currentOrder = Context.Order.Find(orderID); IncomeVM incomeVM = new IncomeVM(Context); if (currentOrder != null) { incomeVM.OrderTotalCost(orderID); Context.SaveChanges(); } }
public IActionResult GetIncome(DateTime startDate, DateTime endDate) { IncomeVM incomeVM = new IncomeVM(Context); ViewBag.monthFrom = startDate.Month; ViewBag.monthTo = endDate.Month; ViewBag.year = startDate.Year; ViewBag.totalIncome = incomeVM.CompanyIncome(startDate, endDate); ViewBag.delivarymenCost = incomeVM.DelivarymenPrice(startDate, endDate); ViewBag.Profit = ViewBag.totalIncome - ViewBag.delivarymenCost; return(View()); }
public async Task <WrapperIncomeListVM> Delete(IncomeVM itemTemp) { Task <IEnumerable <Income> > incomeTask = _repositoryWrapper.Income.FindByConditionAsync(x => x.Id == itemTemp.Id && x.FactoryId == itemTemp.FactoryId); Task <IEnumerable <TblTransaction> > transactionTask = _repositoryWrapper.Transaction.FindByConditionAsync(x => x.InvoiceId == itemTemp.InvoiceId && x.FactoryId == itemTemp.FactoryId); Task <IEnumerable <Invoice> > invoiceTask = _repositoryWrapper.Invoice.FindByConditionAsync(x => x.Id == itemTemp.InvoiceId && x.FactoryId == itemTemp.FactoryId); await Task.WhenAll(incomeTask, transactionTask, invoiceTask); var incomeToDelete = incomeTask.Result.ToList().FirstOrDefault(); var transactionToDelete = transactionTask.Result.ToList().FirstOrDefault(); var invoiceToDelete = invoiceTask.Result.ToList().FirstOrDefault(); //if (item == null) //{ // return new WrapperIncomeListVM(); //} _repositoryWrapper.Income.Delete(incomeToDelete); _repositoryWrapper.Transaction.Delete(transactionToDelete); _repositoryWrapper.Invoice.Delete(invoiceToDelete); await _repositoryWrapper.Income.SaveChangesAsync(); await _repositoryWrapper.Transaction.SaveChangesAsync(); await _repositoryWrapper.Invoice.SaveChangesAsync(); var dataParam = new GetDataListVM() { FactoryId = itemTemp.FactoryId, PageNumber = 1, PageSize = 10, TotalRows = 0 }; WrapperIncomeListVM data = await GetListPaged(dataParam); return(data); }
// not used public async Task <WrapperIncomeListVM> Update(string id, IncomeVM vm) { IEnumerable <Income> ItemDB = await _repositoryWrapper.Income.FindByConditionAsync(x => x.Id == id && x.FactoryId == vm.FactoryId); var ItemUpdated = _utilService.GetMapper().Map <IncomeVM, Income>(vm, ItemDB.ToList().FirstOrDefault()); _repositoryWrapper.Income.Update(ItemUpdated); await _repositoryWrapper.Income.SaveChangesAsync(); this._utilService.LogInfo("Successful In Updating Item Cateory"); var dataParam = new GetDataListVM() { FactoryId = vm.FactoryId, PageNumber = 1, PageSize = 10, TotalRows = 0 }; WrapperIncomeListVM data = await GetListPaged(dataParam); return(data); }
public async Task <ActionResult <WrapperIncomeListVM> > DeleteIncome([FromBody] IncomeVM IncomeVM) { return(Ok(await _serviceWrapper.IncomeService.Delete(IncomeVM))); }
public async Task <ActionResult <WrapperIncomeListVM> > AddIncome([FromBody] IncomeVM Income) { return(Ok(await _serviceWrapper.IncomeService.Add(Income))); }
public IncomeVM GetListIncome(DateTime DateSearch) { var ObjectIncome = _db.OrderDetails.Include(o => o.OrderHeader).Where(o => o.OrderId == o.OrderHeader.Id && o.OrderHeader.OrderDate.Date == DateSearch.Date && o.OrderHeader.Status != SD.StatusCancelled && o.OrderHeader.PaymentStatus == SD.PaymentStatusApproved).ToList(); List <string> tempName = new List <string>(); List <double> tempPrice = new List <double>(); List <int> tempQuan = new List <int>(); IncomeVM objIncome = new IncomeVM(); objIncome.DisplayDate = DateSearch.Date; var OrderHeaderItem = _db.OrderHeader.Where(o => o.Status != SD.StatusCancelled && o.PaymentStatus == SD.PaymentStatusApproved).Select(o => o.OrderDate); if (OrderHeaderItem.Any()) { objIncome.EarliestDay = OrderHeaderItem.Min().Date; } else { objIncome.EarliestDay = SharedMethods.GetDateTime().Date; } if (ObjectIncome.Any()) { foreach (var item in ObjectIncome) { tempName.Add(item.Name); tempPrice.Add(item.Price); tempQuan.Add(item.Count); objIncome.IncomeMade += item.Price * item.Count; objIncome.ItemSoldDay += item.Count; } var tempDup = FindDuplicates(tempName).ToList(); if (tempDup.Count() > 0) { for (int x = 0; x < tempDup.Count(); x++) { for (int y = 0; y < tempName.Count(); y++) { if (tempName[y] == tempDup[x].Item1 && tempPrice[y] == tempPrice[tempDup[x].Item2] && tempDup[x].Item2 != y) { tempQuan[y] += tempQuan[tempDup[x].Item2]; tempName[tempDup[x].Item2] = ""; tempPrice[tempDup[x].Item2] = 0; tempQuan[tempDup[x].Item2] = 0; } } } tempName.RemoveAll(item => item == ""); tempPrice.RemoveAll(item => item == 0); tempQuan.RemoveAll(item => item == 0); } List <ItemVM> objItemVM = new List <ItemVM>(); for (int x = 0; x < tempName.Count(); x++) { objItemVM.Add(new ItemVM { ItemName = tempName[x], ItemPrice = tempPrice[x], ItemQuan = tempQuan[x] }); } objIncome.IncomeList = objItemVM.OrderBy(x => x.ItemName); } else { objIncome.IncomeList = new List <ItemVM>(0); } objIncome.CurrentDate = SharedMethods.GetDateTime().Date; return(objIncome); }