public void ReceivedRemaining(FormCollection form) { var ShopRiceSales_pt = db.ShopRiceSales_pt.Find(Convert.ToInt32(form["id"])); // var rec = db.Transaction_Shop_Shop.Where(m => m.Transaction_Shop_Shop_item_id == ShopRiceSales_pt.srsp_id && m.Transaction_Shop_Shop_item_type == "Shop Rice Sales").Sum(m => m.Credit); // var Remaining = ShopRiceSales_pt.srsp_Total_Amount - rec; Transaction_Shop trans = new Transaction_Shop(); trans.isByCash = true; trans.BankAccountNo = ""; foreach (var item in db.Opening_ClosingDays_Shop) { if (item.Date.ToShortDateString() == DateTime.Now.ToShortDateString() && !item.isClosed) { trans.Opening_ClosingDays_Shop_id = item.Opening_ClosingDays_Shop_id; break; } } trans.Transaction_Shop_DateTime = DateTime.Now; trans.Transaction_Shop_Description = "Received Remaining from " + db.Customers.Find(ShopRiceSales_pt.Customer_Id).Customer_Name; trans.Transaction_Shop_item_id = Convert.ToInt32(form["id"]); trans.Transaction_Shop_item_type = SellingCategory.Shop_Rice_Sales; trans.Debit = 0; trans.Credit = Convert.ToInt32(form["Remaining"]); trans.status = true; db.Transaction_Shop.Add(trans); db.SaveChanges(); }
public ActionResult Edit(Transaction_Shop trans1, FormCollection form) { Transaction_Shop trans = db.Transaction_Shop.Find(trans1.Transaction_Shop_id); if (form["isBankAccount"] != null) { trans.BankAccountNo = form["BankAccNo"]; } else if (form["isCheckbook"] != null) { trans.BankAccountNo = form["BankAccNo"]; trans.checkno = Convert.ToInt32(form["CheckNo"]); } else if (form["isCash"] != null) { trans.isByCash = true; } trans.Transaction_Shop_item_type = "Manual"; trans.Transaction_Shop_Description = trans1.Transaction_Shop_Description; trans.Debit = trans1.Debit; trans.Credit = trans1.Credit; db.Entry(trans).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("ViewToday")); }
public ActionResult Add(Transaction_Shop trans, FormCollection form) { if (form["isBankAccount"] != null) { trans.BankAccountNo = form["BankAccNo"]; } else if (form["isCheckbook"] != null) { trans.BankAccountNo = form["BankAccNo"]; trans.checkno = Convert.ToInt32(form["CheckNo"]); } else if (form["isCash"] != null) { trans.isByCash = true; } trans.Transaction_Shop_DateTime = DateTime.Now; foreach (var item in db.Opening_ClosingDays_Shop.Where(m => m.Shop_Id == 2)) { if (item.Date.ToShortDateString() == DateTime.Now.ToShortDateString() && !item.isClosed) { trans.Opening_ClosingDays_Shop_id = item.Opening_ClosingDays_Shop_id; break; } } trans.Transaction_Shop_item_id = 0; trans.Transaction_Shop_item_type = "Manual"; trans.Transaction_Shop_Description = form["Transaction_Shop_Description"]; trans.status = true; db.Transaction_Shop.Add(trans); db.SaveChanges(); return(RedirectToAction("ViewToday")); }
public JsonResult Return(int srsp_id) { ShopRiceSales_pt mShopRiceSales_pt = db.ShopRiceSales_pt.Where(m => m.srsp_id == srsp_id && m.srsp_status).SingleOrDefault(); if (mShopRiceSales_pt != null) { foreach (var item in db.ShopRiceSales_ch.Where(m => m.srsp_id == mShopRiceSales_pt.srsp_id && m.srsc_status).ToList()) { //Again add in stock var mstock = db.ShopStock.Find(item.ShopStockId); mstock.SoldQty -= item.srsc_qty; db.Entry(mstock).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } var Receivedtrans = db.Transaction.Where( m => m.status && m.Transaction_item_id == mShopRiceSales_pt.srsp_id && (m.Transaction_item_type == SellingCategory.RawRice_Sales || m.Transaction_item_type == SellingCategory.RawRice_Sales_Remaining) ).SingleOrDefault(); decimal recieved = (Receivedtrans != null) ? Receivedtrans.Credit : 0; Transaction_Shop trans = new Transaction_Shop(); trans.isByCash = true; trans.BankAccountNo = ""; foreach (var item in db.Opening_ClosingDays_Shop) { if (item.Date.ToShortDateString() == DateTime.Now.ToShortDateString() && !item.isClosed) { trans.Opening_ClosingDays_Shop_id = item.Opening_ClosingDays_Shop_id; break; } } trans.Transaction_Shop_DateTime = DateTime.Now; trans.Transaction_Shop_Description = "RawRice Return from " + db.Customers.Find(mShopRiceSales_pt.Customer_Id).Customer_Name; trans.Transaction_Shop_item_id = srsp_id; trans.Transaction_Shop_item_type = SellingCategory.Shop_Rice_Sales_Return; trans.Debit = recieved; trans.Credit = 0; trans.status = (recieved > 0) ? true : false; db.Transaction_Shop.Add(trans); db.SaveChanges(); } return(Json(1, JsonRequestBehavior.AllowGet)); }
public void Update_sales(FormCollection form) { var js = new JavaScriptSerializer(); decimal Recieved_Amount = Convert.ToDecimal(form["RecievedAmount"]); try { List <int> remaining_srsp_id = js.Deserialize <List <int> >(form["remaining_srsp_id"]); for (int i = 0; i < remaining_srsp_id.Count; i++) { var ShopRiceSales_pt1 = db.ShopRiceSales_pt.Find(remaining_srsp_id[i]); var rec = db.Transaction_Shop.Where(m => m.status && m.Transaction_Shop_item_id == ShopRiceSales_pt1.srsp_id && m.Transaction_Shop_item_type == SellingCategory.Shop_Rice_Sales || m.Transaction_Shop_item_type == SellingCategory.Shop_Rice_Sales_Remaining ).Sum(m => m.Credit); var Remaining = ShopRiceSales_pt1.srsp_Total_Amount - rec; Transaction_Shop trans = new Transaction_Shop(); if (form["isBankAccount"] == "true") { trans.BankAccountNo = form["BankAccountNo"]; } else if (form["isCheckbook"] == "true") { trans.checkno = Convert.ToInt32(form["CheckNo"]); trans.BankAccountNo = form["BankAccountNo"]; } else if (form["isCash"] == "true") { trans.isByCash = true; trans.BankAccountNo = ""; } foreach (var item in db.Opening_ClosingDays_Shop) { if (item.Date.ToShortDateString() == DateTime.Now.ToShortDateString() && !item.isClosed) { trans.Opening_ClosingDays_Shop_id = item.Opening_ClosingDays_Shop_id; break; } } trans.Transaction_Shop_DateTime = DateTime.Now; trans.Transaction_Shop_Description = "Received Remaining from " + db.Customers.Find(ShopRiceSales_pt1.Customer_Id).Customer_Name; trans.Transaction_Shop_item_id = remaining_srsp_id[i]; trans.Transaction_Shop_item_type = SellingCategory.Shop_Rice_Sales_Remaining; trans.Debit = 0; trans.Credit = Remaining; trans.status = true; db.Transaction_Shop.Add(trans); db.SaveChanges(); Recieved_Amount -= Remaining; } } catch (Exception ex) { } ShopRiceSales_pt ShopRiceSales_pt_view = js.Deserialize <ShopRiceSales_pt>(form["ShopRiceSales_pt"]); var ShopRiceSales_pt = db.ShopRiceSales_pt.Find(ShopRiceSales_pt_view.srsp_id); if (ShopRiceSales_pt_view.Customer.Customer_Id > 0) { ShopRiceSales_pt.Customer_Id = ShopRiceSales_pt_view.Customer.Customer_Id; ShopRiceSales_pt.Customer = null; } else { // string idd = Convert.ToString(Session["UserId"]); string idd = User.Identity.GetUserId(); ShopRiceSales_pt_view.Customer.Id = idd; ShopRiceSales_pt.Customer.Status = true; db.Customers.Add(ShopRiceSales_pt_view.Customer); db.SaveChanges(); ShopRiceSales_pt.Customer_Id = db.Customers.Max(m => m.Customer_Id); ShopRiceSales_pt.Customer = null; } //ShopRiceSales_pt.Customer_Id = ShopRiceSales_pt_view.Customer_Id; ShopRiceSales_pt.srsp_TotalWeight_KG = ShopRiceSales_pt_view.srsp_TotalWeight_KG; ShopRiceSales_pt.srsp_TotalWeight_Mann = ShopRiceSales_pt_view.srsp_TotalWeight_Mann; ShopRiceSales_pt.srsp_Total_Amount = ShopRiceSales_pt_view.srsp_Total_Amount; ShopRiceSales_pt.srsp_Title = ShopRiceSales_pt_view.srsp_Title + " to Customer " + db.Customers.Find(ShopRiceSales_pt_view.Customer_Id).Customer_Name; ShopRiceSales_pt.srsp_status = true; ShopRiceSales_pt.srsp_date = DateTime.Now; ShopRiceSales_pt.Shop_Id = 2; db.Entry(ShopRiceSales_pt).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); int srsp_id = ShopRiceSales_pt.srsp_id; var obj = js.DeserializeObject(form["ShopRiceSales_ch"].ToString()); List <ShopRiceSales_ch> ShopRiceSales_ch = js.Deserialize <ShopRiceSales_ch[]>(form["ShopRiceSales_ch"].ToString()).ToList(); foreach (var item in ShopRiceSales_ch) { var rsc = db.ShopRiceSales_ch.Find(item.srsc_id); if (rsc == null) { rsc = new ShopRiceSales_ch(); } rsc.ShopStockId = item.ShopStockId; rsc.srsc_price = item.srsc_price; rsc.srsc_qty = item.srsc_qty; rsc.srsc_status = item.srsc_status; rsc.srsc_title = item.srsc_title; rsc.srsc_Weight_kg = item.srsc_Weight_kg; rsc.srsc_Weight_mann = item.srsc_Weight_mann; rsc.srsp_id = srsp_id; rsc.srsc_status = true; if (item.srsc_id == 0) { db.ShopRiceSales_ch.Add(rsc); db.SaveChanges(); var mstock = db.ShopStock.Find(item.ShopStockId); mstock.SoldQty += item.srsc_qty; db.Entry(mstock).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } else { int srsc_qty = 0; using (var newdb = new ApplicationDbContext()) { srsc_qty = newdb.ShopRiceSales_ch.Where(m => m.srsc_id == item.srsc_id).First().srsc_qty; } var mstock = db.ShopStock.Find(rsc.ShopStockId); mstock.SoldQty -= srsc_qty; db.Entry(mstock).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); db.Entry(rsc).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); mstock = db.ShopStock.Find(item.ShopStockId); mstock.SoldQty += item.srsc_qty; db.Entry(mstock).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } List <ShopRiceSales_ch> Deleted_ShopRice_Sales_ch = js.Deserialize <ShopRiceSales_ch[]>(form["Deleted_ShopRiceSales_ch"].ToString()).ToList(); foreach (var item in Deleted_ShopRice_Sales_ch) { var mstock = db.ShopStock.Find(item.ShopStockId); mstock.SoldQty -= item.srsc_qty; db.Entry(mstock).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); var srsc = db.ShopRiceSales_ch.Find(item.srsc_id); srsc.srsc_status = false; db.Entry(srsc).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } foreach (var item in db.Transaction_Shop.Where(m => m.Transaction_Shop_item_id == ShopRiceSales_pt.srsp_id && m.Transaction_Shop_item_type == SellingCategory.Shop_Rice_Sales && m.status)) { db.Transaction_Shop.Remove(item); } db.SaveChanges(); Transaction_Shop trans_this = new Transaction_Shop(); if (form["isBankAccount"] == "true") { trans_this.BankAccountNo = form["BankAccountNo"]; } else if (form["isCheckbook"] == "true") { trans_this.checkno = Convert.ToInt32(form["CheckNo"]); trans_this.BankAccountNo = form["BankAccountNo"]; } else if (form["isCash"] == "true") { trans_this.isByCash = true; trans_this.BankAccountNo = ""; } foreach (var item in db.Opening_ClosingDays_Shop) { if (item.Date.ToShortDateString() == DateTime.Now.ToShortDateString() && !item.isClosed) { trans_this.Opening_ClosingDays_Shop_id = item.Opening_ClosingDays_Shop_id; break; } } trans_this.Transaction_Shop_DateTime = DateTime.Now; trans_this.Transaction_Shop_Description = ShopRiceSales_pt.srsp_Title; trans_this.Transaction_Shop_item_id = srsp_id; trans_this.Transaction_Shop_item_type = SellingCategory.Shop_Rice_Sales; trans_this.Debit = 0; trans_this.Credit = Recieved_Amount; trans_this.status = true; db.Transaction_Shop.Add(trans_this); db.SaveChanges(); }
public void Insert_sales(FormCollection form) { var js = new JavaScriptSerializer(); decimal Recieved_Amount = Convert.ToDecimal(form["RecievedAmount"]); try { List <int> remaining_rsp_id = js.Deserialize <List <int> >(form["remaining_srsp_id"]); for (int i = 0; i < remaining_rsp_id.Count; i++) { var mShopRiceSales_pt = db.ShopRiceSales_pt.Find(remaining_rsp_id[i]); var rec = db.Transaction_Shop.Where(m => m.status && m.Transaction_Shop_item_id == mShopRiceSales_pt.srsp_id && m.Transaction_Shop_item_type == SellingCategory.Shop_Rice_Sales || m.Transaction_Shop_item_type == SellingCategory.Shop_Rice_Sales_Remaining ).Sum(m => m.Credit); var Remaining = mShopRiceSales_pt.srsp_Total_Amount - rec; Transaction_Shop trans = new Transaction_Shop(); if (form["isBankAccount"] == "true") { trans.BankAccountNo = form["BankAccountNo"]; } else if (form["isCheckbook"] == "true") { trans.checkno = Convert.ToInt32(form["CheckNo"]); trans.BankAccountNo = form["BankAccountNo"]; } else if (form["isCash"] == "true") { trans.isByCash = true; trans.BankAccountNo = ""; } foreach (var item in db.Opening_ClosingDays_Shop) { if (item.Date.ToShortDateString() == DateTime.Now.ToShortDateString() && !item.isClosed) { trans.Opening_ClosingDays_Shop_id = item.Opening_ClosingDays_Shop_id; break; } } trans.Transaction_Shop_DateTime = DateTime.Now; trans.Transaction_Shop_Description = "Received Remaining from " + db.Customers.Find(mShopRiceSales_pt.Customer_Id).Customer_Name; trans.Transaction_Shop_item_id = remaining_rsp_id[i]; trans.Transaction_Shop_item_type = SellingCategory.Shop_Rice_Sales_Remaining; trans.Debit = 0; trans.Credit = Remaining; trans.status = true; db.Transaction_Shop.Add(trans); db.SaveChanges(); Recieved_Amount -= Remaining; } } catch (Exception ex) { } ShopRiceSales_pt ShopRiceSales_pt = js.Deserialize <ShopRiceSales_pt>(form["ShopRiceSales_pt"]); if (ShopRiceSales_pt.Customer.Customer_Id > 0) { ShopRiceSales_pt.Customer_Id = ShopRiceSales_pt.Customer.Customer_Id; ShopRiceSales_pt.Customer = null; } else { // string idd = Convert.ToString(Session["UserId"]); string idd = User.Identity.GetUserId(); ShopRiceSales_pt.Customer.Id = idd; ShopRiceSales_pt.Customer.Status = true; db.Customers.Add(ShopRiceSales_pt.Customer); db.SaveChanges(); ShopRiceSales_pt.Customer_Id = db.Customers.Max(m => m.Customer_Id); ShopRiceSales_pt.Customer = null; } ShopRiceSales_pt.srsp_Title = ShopRiceSales_pt.srsp_Title + " to Customer " + db.Customers.Find(ShopRiceSales_pt.Customer_Id).Customer_Name; ShopRiceSales_pt.srsp_status = true; ShopRiceSales_pt.srsp_date = DateTime.Now; ShopRiceSales_pt.Shop_Id = 2; db.ShopRiceSales_pt.Add(ShopRiceSales_pt); db.SaveChanges(); int srsp_id = db.ShopRiceSales_pt.Max(m => m.srsp_id); List <ShopRiceSales_ch> ShopRiceSales_ch = js.Deserialize <ShopRiceSales_ch[]>(form["ShopRiceSales_ch"].ToString()).ToList(); foreach (var item in ShopRiceSales_ch) { item.srsp_id = srsp_id; item.srsc_status = true; db.ShopRiceSales_ch.Add(item); db.SaveChanges(); var mstock = db.ShopStock.Find(item.ShopStockId); mstock.SoldQty += item.srsc_qty; db.Entry(mstock).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } Transaction_Shop trans_this = new Transaction_Shop(); if (form["isBankAccount"] == "true") { trans_this.BankAccountNo = form["BankAccountNo"]; } else if (form["isCheckbook"] == "true") { trans_this.checkno = Convert.ToInt32(form["CheckNo"]); trans_this.BankAccountNo = form["BankAccountNo"]; } else if (form["isCash"] == "true") { trans_this.isByCash = true; trans_this.BankAccountNo = ""; } foreach (var item in db.Opening_ClosingDays_Shop) { if (item.Date.ToShortDateString() == DateTime.Now.ToShortDateString() && !item.isClosed) { trans_this.Opening_ClosingDays_Shop_id = item.Opening_ClosingDays_Shop_id; break; } } trans_this.Transaction_Shop_DateTime = DateTime.Now; trans_this.Transaction_Shop_Description = ShopRiceSales_pt.srsp_Title; trans_this.Transaction_Shop_item_id = srsp_id; trans_this.Transaction_Shop_item_type = SellingCategory.Shop_Rice_Sales; trans_this.Debit = 0; trans_this.Credit = Recieved_Amount; trans_this.status = true; db.Transaction_Shop.Add(trans_this); db.SaveChanges(); SaleInvoiceType mSaleInvoiceType = new SaleInvoiceType(); SaleInvoice saleInvoice = new SaleInvoice() { SaleInvoice_no = mSaleInvoiceType.GenerateInvoiceNo(SaleInvoiceType.ShopRiceSales), SaleInvoice_type = SaleInvoiceType.ShopRiceSales, Sale_id = db.ShopRiceSales_pt.Max(m => m.srsp_id) }; db.SaleInvoice.Add(saleInvoice); db.SaveChanges(); }