public void Insert_sales(FormCollection form) { var js = new JavaScriptSerializer(); decimal Recieved_Amount = Convert.ToDecimal(form["RecievedAmount"]); decimal NetTotal = Convert.ToDecimal(form["NetTotal"]); try { List <int> remaining_rsp_id = js.Deserialize <List <int> >(form["remaining_rsp_id"]); for (int i = 0; i < remaining_rsp_id.Count; i++) { var RawRice_Sales_pt = db.RawRice_Sales_pt.Find(remaining_rsp_id[i]); decimal recieved = db.Transaction.Where( m => m.status && m.Transaction_item_id == RawRice_Sales_pt.rsp_id && m.Transaction_item_type == SellingCategory.RawRice_Sales || m.Transaction_item_type == SellingCategory.RawRice_Sales_Remaining ).Sum(m => m.Credit); var Remaining = RawRice_Sales_pt.rsp_Total_Amount - recieved; Transaction trans = new Transaction(); 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) { if (item.Date.ToShortDateString() == DateTime.Now.ToShortDateString() && !item.isClosed) { trans.Opening_ClosingDays_id = item.Opening_ClosingDays_id; break; } } trans.Transaction_DateTime = DateTime.Now; trans.Transaction_Description = "Received Remaining from " + db.Parties.Find(RawRice_Sales_pt.Party_Id).Party_Name; trans.Transaction_item_id = remaining_rsp_id[i]; trans.Transaction_item_type = SellingCategory.RawRice_Sales_Remaining; trans.Debit = 0; trans.Credit = Remaining; trans.status = true; db.Transaction.Add(trans); db.SaveChanges(); Recieved_Amount -= Remaining; } } catch (Exception ex) { } RawRice_Sales_pt RawRiceSales = js.Deserialize <RawRice_Sales_pt>(form["rawRice_Sales_pt"]); RawRiceSales.rsp_Total_Amount = NetTotal; if (RawRiceSales.Party.Party_Id > 0) { RawRiceSales.Party_Id = RawRiceSales.Party.Party_Id; RawRiceSales.Party = null; } else { // string idd = Convert.ToString(Session["UserId"]); string idd = User.Identity.GetUserId(); RawRiceSales.Party.Id = idd; RawRiceSales.Party.Status = true; db.Parties.Add(RawRiceSales.Party); db.SaveChanges(); RawRiceSales.Party_Id = db.Parties.Max(m => m.Party_Id); RawRiceSales.Party = null; } RawRiceSales.rsp_Title = RawRiceSales.rsp_Title + " to Party " + db.Parties.Find(RawRiceSales.Party_Id).Party_Name; RawRiceSales.rsp_status = true; RawRiceSales.rsp_date = DateTime.Now; db.RawRice_Sales_pt.Add(RawRiceSales); db.SaveChanges(); int rsp_id = db.RawRice_Sales_pt.Max(m => m.rsp_id); List <RawRice_Sales_ch> RawRice_Sales_ch = js.Deserialize <RawRice_Sales_ch[]>(form["RawRice_Sales_ch"].ToString()).ToList(); foreach (var item in RawRice_Sales_ch) { item.rsp_id = rsp_id; item.rsc_status = true; db.RawRice_Sales_ch.Add(item); db.SaveChanges(); var RawRice = db.RarRices.Find(item.RawRice_id); RawRice.Bags_Sold_qty += item.rsc_qty; db.Entry(RawRice).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } Transaction trans_this = new Transaction(); 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) { if (item.Date.ToShortDateString() == DateTime.Now.ToShortDateString() && !item.isClosed) { trans_this.Opening_ClosingDays_id = item.Opening_ClosingDays_id; break; } } trans_this.Transaction_DateTime = DateTime.Now; trans_this.Transaction_Description = RawRiceSales.rsp_Title; trans_this.Transaction_item_id = rsp_id; trans_this.Transaction_item_type = SellingCategory.RawRice_Sales; trans_this.Debit = 0; trans_this.Credit = Recieved_Amount; trans_this.status = true; db.Transaction.Add(trans_this); db.SaveChanges(); SaleInvoiceType mSaleInvoiceType = new SaleInvoiceType(); SaleInvoice saleInvoice = new SaleInvoice() { SaleInvoice_no = mSaleInvoiceType.GenerateInvoiceNo(SaleInvoiceType.FactoryRiceSales), SaleInvoice_type = SaleInvoiceType.FactoryRiceSales, Sale_id = db.RawRice_Sales_pt.Max(m => m.rsp_id) }; db.SaleInvoice.Add(saleInvoice); 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(); }
public void Insert_sales(FormCollection form) { var js = new JavaScriptSerializer(); decimal Recieved_Amount = Convert.ToDecimal(form["RecievedAmount"]); decimal NetTotal = Convert.ToDecimal(form["NetTotal"]); try { List <int> remaining_rsp_id = js.Deserialize <List <int> >(form["remaining_prsp_id"]); for (int i = 0; i < remaining_rsp_id.Count; i++) { var RawRice_Sales_pt = db.ProducedRiceSales_pt.Find(remaining_rsp_id[i]); decimal rec = db.Transaction.Where(m => m.status && m.Transaction_item_id == RawRice_Sales_pt.prsp_id && m.Transaction_item_type == SellingCategory.Worth_Rice_Sales || m.Transaction_item_type == SellingCategory.Worth_Rice_Sales_Remaining ).Sum(m => m.Credit); var Remaining = RawRice_Sales_pt.prsp_Total_Amount - rec; Transaction trans = new Transaction(); 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) { if (item.Date.ToShortDateString() == DateTime.Now.ToShortDateString() && !item.isClosed) { trans.Opening_ClosingDays_id = item.Opening_ClosingDays_id; break; } } trans.Transaction_DateTime = DateTime.Now; trans.Transaction_Description = "Received Remaining from " + db.Parties.Find(RawRice_Sales_pt.Party_Id).Party_Name; trans.Transaction_item_id = remaining_rsp_id[i]; trans.Transaction_item_type = SellingCategory.Worth_Rice_Sales_Remaining; trans.Debit = 0; trans.Credit = Remaining; trans.status = true; db.Transaction.Add(trans); db.SaveChanges(); Recieved_Amount -= Remaining; } } catch (Exception ex) { } BpRiceSales_pt ProducedRiceSales_pt = js.Deserialize <BpRiceSales_pt>(form["ProducedRiceSales_pt"]); ProducedRiceSales_pt.bprsp_Total_Amount = NetTotal; if (ProducedRiceSales_pt.Party.Party_Id > 0) { ProducedRiceSales_pt.Party_Id = ProducedRiceSales_pt.Party.Party_Id; ProducedRiceSales_pt.Party = null; } else { //string idd = Convert.ToString(Session["UserId"]); string idd = User.Identity.GetUserId(); ProducedRiceSales_pt.Party.Id = idd; ProducedRiceSales_pt.Party.Status = true; db.Parties.Add(ProducedRiceSales_pt.Party); db.SaveChanges(); ProducedRiceSales_pt.Party_Id = db.Parties.Max(m => m.Party_Id); ProducedRiceSales_pt.Party = null; } ProducedRiceSales_pt.bprsp_Title = ProducedRiceSales_pt.bprsp_Title + " to Party " + db.Parties.Find(ProducedRiceSales_pt.Party_Id).Party_Name; ProducedRiceSales_pt.bprsp_status = true; ProducedRiceSales_pt.bprsp_date = DateTime.Now; db.BpRiceSales_pts.Add(ProducedRiceSales_pt); db.SaveChanges(); int prsp_id = db.BpRiceSales_pts.Max(m => m.bprsp_id); List <BpRiceSales_ch> ProducedRiceSales_ch = js.Deserialize <BpRiceSales_ch[]>(form["ProducedRiceSales_ch"].ToString()).ToList(); foreach (var item in ProducedRiceSales_ch) { item.bprsp_id = prsp_id; item.bprsc_status = true; db.BpRiceSales_chs.Add(item); db.SaveChanges(); var Rice_Produce_Bags = db.Rice_Production_ProductWorths.Where(m => m.Rice_Production_ProductWorth_id == item.Rice_Production_ProductWorth_id).ToList(); decimal qty = item.bprsc_qty; foreach (var obj in Rice_Produce_Bags) { decimal diff = obj.Rice_Production_ProductWorth_Qty - obj.Rice_Production_ProductWorth_SoldQty; if (diff > qty && qty > 0) { obj.Rice_Production_ProductWorth_SoldQty += Convert.ToInt32(qty); //obj.Rice_Produce_RemainingBags = obj.Rice_Production_ProductWorth_Qty - obj.Rice_Production_ProductWorth_SoldQty; db.Entry(obj).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); qty = 0; } else if (diff <= qty && qty > 0 && diff != 0) { obj.Rice_Production_ProductWorth_SoldQty += Convert.ToInt32(diff); //obj.Rice_Produce_RemainingBags = obj.Rice_Produce_TotalBagsProduce - obj.Rice_Produce_BagsSold; db.Entry(obj).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); qty -= diff; } } } Transaction trans_this = new Transaction(); 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) { if (item.Date.ToShortDateString() == DateTime.Now.ToShortDateString() && !item.isClosed) { trans_this.Opening_ClosingDays_id = item.Opening_ClosingDays_id; break; } } trans_this.Transaction_DateTime = DateTime.Now; trans_this.Transaction_Description = ProducedRiceSales_pt.bprsp_Title; trans_this.Transaction_item_id = prsp_id; trans_this.Transaction_item_type = SellingCategory.Worth_Rice_Sales; trans_this.Debit = 0; trans_this.Credit = Recieved_Amount; trans_this.status = true; db.Transaction.Add(trans_this); db.SaveChanges(); SaleInvoiceType mSaleInvoiceType = new SaleInvoiceType(); SaleInvoice saleInvoice = new SaleInvoice() { SaleInvoice_no = mSaleInvoiceType.GenerateInvoiceNo(SaleInvoiceType.FactoryRiceSales), SaleInvoice_type = SaleInvoiceType.FactoryRiceSales, Sale_id = db.BpRiceSales_pts.Max(m => m.bprsp_id) }; db.SaleInvoice.Add(saleInvoice); db.SaveChanges(); }