public JsonResult AjaxMethod(string name) { //var rol = User.Identity.Name; //if (rol == "1") //{ Total_cash_made person = new Total_cash_made { total = name }; return(Json(person)); //} }
public JsonResult setTempData(string name) { //ViewData.Remove("calculated"); //var a = "'"; //var b = "'"; var c = name; Total_cash_made person = new Total_cash_made { total = c }; //ViewData["calculated"] = name; return(Json(person)); }
public IActionResult sell_Item(int id_finish, float quantity_sold, float submit_price, float Total_cash_made, string date) { DateTime date_ = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, E_Africa_standard_time); var check_if_exists = _context.sold_items.FirstOrDefault(x => x.Item_id.ToString() == id_finish.ToString() && x.DateTime == today); var shop_itemss = _context.Shop_items.FirstOrDefault(x => x.id == id_finish); //LETS CHECK IF WE SOLD SIMILAR ITEM TODAY if (check_if_exists != null) { //WE HAVE SOLD SIMILAR ITEM TODAY var initial_quantity = shop_itemss.Quantity; var initial_sold_quantity = check_if_exists.quantity_sold; if (initial_quantity <= 0) { Total_cash_made person = new Total_cash_made { total = "Unable to sell the item.Stock running low" }; return(Json(person)); } else { //LETS FIND TOTAL COST PRICE PER ITEM float initial_cost_price_total = check_if_exists.Total_Cost_cash; float total_cost_price = shop_itemss.Cost_price * quantity_sold; float final_cost_price = initial_cost_price_total + total_cost_price; // //LETS SUBTRACT ITEMS float new_quantity = initial_quantity + quantity_sold; //LETS ADD SOLD ITEMS float new_sold_quantity = initial_sold_quantity + quantity_sold; //LETS GET INITIAL TOTAL CAS float initial_total_cash = check_if_exists.Total_cash_made; //LETS ADD TOTAL CASH var new_total_cash = initial_total_cash + Total_cash_made; //LETS UPDATE FIELDS check_if_exists.DateTime = today; check_if_exists.Total_cash_made = new_total_cash; check_if_exists.quantity_sold = new_sold_quantity; check_if_exists.Total_Cost_cash = final_cost_price; _context.Entry(check_if_exists).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); //LETS UPDATE REMAINING QUANTITY var change_r = _context.Shop_items.FirstOrDefault(x => x.id == id_finish); float initial_q = change_r.Quantity; float new_Q = initial_q - quantity_sold; change_r.Quantity = new_Q; _context.Entry(change_r).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); Total_cash_made person = new Total_cash_made { total = new_sold_quantity.ToString() }; return(Json(person)); } } else { //WE HAVENT SOLD ANY ITEM //LETS UPDATE QUANTITY //LETS UPDATE REMAINING QUANTITY var change_r = _context.Shop_items.FirstOrDefault(x => x.id == id_finish); float initial_q = change_r.Quantity; float new_Q = initial_q - quantity_sold; change_r.Quantity = new_Q; _context.Entry(change_r).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); Total_cash_made person = new Total_cash_made { total = "Sales have been done successfully sent to your printer." }; //LETS FIND TOTAL COST PRICE PER ITEM var check_if_exists1 = _context.sold_items.FirstOrDefault(x => x.Item_id.ToString() == id_finish.ToString() && x.DateTime == date); float final_cost_price; if (check_if_exists1 == null) { float initial_cost_price_total = 0; float total_cost_price = shop_itemss.Cost_price * quantity_sold; final_cost_price = initial_cost_price_total + total_cost_price; } else { float initial_cost_price_total = check_if_exists1.Total_Cost_cash; float total_cost_price = shop_itemss.Cost_price * quantity_sold; final_cost_price = initial_cost_price_total + total_cost_price; } //LETS CREATE NEW DOCUMENT FOR NEW DATES sold_items x = new sold_items { Item_id = id_finish, quantity_sold = quantity_sold, Total_cash_made = Total_cash_made, Total_Cost_cash = final_cost_price, DateTime = today }; _context.Add(x); _context.SaveChanges(); return(Json(person)); } }