public static void DepositFund(int invId, int fundAmount, string mode, int acc, string madeby) { int tempRemAm = 0; int tempCusId; try { using (AdvInvSystemEntities dbobj = new AdvInvSystemEntities()) { SaleInvoice si = new SaleInvoice(); si = (from s in dbobj.SaleInvoices where s.SaleInvoicId == invId select s).FirstOrDefault(); tempCusId = si.CustomerId; Customer cu = new Customer(); cu = (from c in dbobj.Customers where c.CustomerId == tempCusId select c).FirstOrDefault(); cu.Balance += fundAmount; dbobj.SaveChanges(); CustomersAccount ca = new CustomersAccount(); ca.CustomerId = tempCusId; ca.Date = System.DateTime.Now; ca.Debit = fundAmount; ca.Credit = 0; dbobj.CustomersAccounts.Add(ca); dbobj.SaveChanges(); if (si.Paid != si.Amount) { tempRemAm = si.Payable - si.Paid; fundAmount = fundAmount - tempRemAm; if (fundAmount == si.Payable) { si.Paid = si.Payable; si.Status = "Cleared"; } else { si.Paid = fundAmount; si.Status = "Pending"; } si.PaymentMode = mode; si.AccountId = acc; dbobj.SaveChanges(); AccountDetail ac = new AccountDetail(); ac.Particular = "Sale inv# " + si.SaleInvoicId; ac.Amount = si.Paid; ac.Mode = "Inward"; ac.DateTime = System.DateTime.Now; ac.AccountId = acc; ac.UserId = Convert.ToInt32(HttpContext.Current.Session["UserId"]); dbobj.AccountDetails.Add(ac); dbobj.SaveChanges(); if (si.PaymentMode == "Cash") { CashTran ct = new CashTran(); ct.Particular = "Sale inv# " + si.SaleInvoicId; ct.Amount = si.Paid; ct.AccountDetailId = ac.AccountsDetailId; dbobj.CashTrans.Add(ct); dbobj.SaveChanges(); } else if (si.PaymentMode == "Bank") { BnkTan bkt = new BnkTan(); bkt.Particular = "Sale inv# " + si.SaleInvoicId; bkt.Amount = si.Paid; bkt.AccountDetailId = ac.AccountsDetailId; bkt.MadeBy = madeby; bkt.DueDate = System.DateTime.Now; dbobj.BnkTans.Add(bkt); dbobj.SaveChanges(); } } } } catch (Exception) { } }
protected void Button2_Click(object sender, EventArgs e) { if (GridView1.Rows.Count >= 1) { CurBalance = Convert.ToInt32(paidTxt.Text) + Convert.ToInt32(PreBal.Text); prevBal = Convert.ToInt32(PreBal.Text); int temppayable = (Convert.ToInt32(ViewState["gt"]) - Convert.ToInt32(TotaldiscTxt.Text)); if (Convert.ToInt32(paidTxt.Text) <= temppayable) { Button2.Enabled = false; try { using (AdvInvSystemEntities dbobj = new AdvInvSystemEntities()) { if (cuscellTxt.Text != "") { string cuscell = cuscellTxt.Text; Customer cu = new Customer(); cu = (from cust in dbobj.Customers where cust.CellNumber == cuscell select cust).FirstOrDefault(); if (cu == null) { Customer cu1 = new Customer(); cu1.CustomerName = cusTxt.Text; cu1.CellNumber = cuscellTxt.Text; cu1.Address = addTxt.Text; cu1.Type = custTypeTxt.Text; cu1.BadDebt = "Non-Defaulter"; cu1.Balance = CurBalance; cu1.Cnic = cnicTxt.Text; dbobj.Customers.Add(cu1); dbobj.SaveChanges(); ViewState["cusId"] = cu1.CustomerId; } else { cu.Balance = CurBalance; dbobj.SaveChanges(); cuId = cu.CustomerId; ViewState["cusId"] = cu.CustomerId; } } else { Customer cu = new Customer(); cu = (from cust in dbobj.Customers where cust.CustomerId == 1 select cust).FirstOrDefault(); cu.Balance = CurBalance; ViewState["cusId"] = 1; } SaleInvoice si = new SaleInvoice(); si.CustomerId = Convert.ToInt32(ViewState["cusId"]); si.Date = System.DateTime.Now; si.BranchId = Convert.ToInt32(Session["BranchId"]); si.Amount = Convert.ToInt32(ViewState["gt"]); si.Discount = Convert.ToInt32(TotaldiscTxt.Text); si.Payable = Convert.ToInt32(ViewState["gt"]) - Convert.ToInt32(TotaldiscTxt.Text); ViewState["payable"] = si.Payable; int tempcu2Id = Convert.ToInt32(ViewState["cusId"]); Customer cu2 = new Customer(); cu2 = (from cust in dbobj.Customers where cust.CustomerId == tempcu2Id select cust).FirstOrDefault(); /* if (Convert.ToInt32(paidTxt.Text) == 0 && prevBal <= 0) * { * cu2.Balance = cu2.Balance - si.Payable; * si.Paid = 0; * si.ChangeReturn = si.Paid - si.Payable; * dbobj.SaveChanges(); * } */ if (CurBalance != 0) { if (CurBalance >= si.Payable) { si.Paid = si.Payable; si.ChangeReturn = Convert.ToInt32(paidTxt.Text) - si.Payable; si.Status = "Cleared"; cu2.Balance = cu2.Balance - si.Payable; dbobj.SaveChanges(); } else { si.Paid = Convert.ToInt32(paidTxt.Text); si.ChangeReturn = Convert.ToInt32(paidTxt.Text) - si.Payable; si.Status = "Pending"; cu2.Balance = CurBalance - si.Payable; dbobj.SaveChanges(); } } else { si.Paid = 0; si.ChangeReturn = 0; si.Status = "Pending"; cu2.Balance = cu2.Balance - si.Payable; } if (Convert.ToInt32(Session["BranchId"]) == 1) { accId = 1; } else { accId = 2; } TimeZoneInfo tzi; DateTime dtTz; tzi = TimeZoneInfo.FindSystemTimeZoneById("Pakistan Standard Time"); dtTz = TimeZoneInfo.ConvertTime(DateTime.Now, tzi); si.Time = dtTz.ToString("h:mm:ss tt"); si.AccountId = accId; si.PaymentMode = "Cash"; si.UserId = Convert.ToInt32(Session["UserId"]); dbobj.SaleInvoices.Add(si); dbobj.SaveChanges(); ViewState["sInvId"] = si.SaleInvoicId; Session["sInvId"] = ViewState["sInvId"]; // if (PMDropdownlist.SelectedItem.Value == "Cheque") // { // ChequeList chql = new ChequeList(); // chql.Mode = "Inward"; // chql.ChequeNumber = chqTxt.Text; // chql.Bank = bnkTxt.Text; // chql.Amount = Convert.ToInt32(ammTxt.Text); // chql.MadeBy = mbTxt.Text; // chql.Date = System.DateTime.Now; // chql.Status = "Pending"; // chql.AccountId = Convert.ToInt32(AccDropDownlist.SelectedItem.Value); // dbobj.ChequeLists.Add(chql); // dbobj.SaveChanges(); // } CustomersAccount cusA = new CustomersAccount(); cusA.CustomerId = Convert.ToInt32(ViewState["cusId"]); cusA.Date = System.DateTime.Now; cusA.Particular = "Sale Invoice# " + si.SaleInvoicId; cusA.Amount = si.Payable; if (Convert.ToInt32(paidTxt.Text) == 0 && prevBal <= 0) { cusA.Credit = cusA.Amount; cusA.Debit = 0; } if (Convert.ToInt32(paidTxt.Text) == 0 && prevBal > 0) { if (prevBal < cusA.Amount) { cusA.Debit = prevBal; cusA.Credit = cusA.Amount - prevBal; } if (prevBal >= cusA.Amount) { cusA.Credit = 0; cusA.Debit = cusA.Amount; } } if (Convert.ToInt32(paidTxt.Text) < cusA.Amount && prevBal < 0) { cusA.Credit = cusA.Amount - Convert.ToInt32(paidTxt.Text); cusA.Debit = Convert.ToInt32(paidTxt.Text); } if (Convert.ToInt32(paidTxt.Text) < cusA.Amount && prevBal == 0) { cusA.Credit = cusA.Amount - Convert.ToInt32(paidTxt.Text); cusA.Debit = Convert.ToInt32(paidTxt.Text); } if (Convert.ToInt32(paidTxt.Text) < cusA.Amount && prevBal > 0) { if (prevBal + Convert.ToInt32(paidTxt.Text) < cusA.Amount) { cusA.Debit = prevBal + Convert.ToInt32(paidTxt.Text); cusA.Credit = cusA.Amount - (prevBal + Convert.ToInt32(paidTxt.Text)); } if (prevBal + Convert.ToInt32(paidTxt.Text) >= cusA.Amount) { cusA.Credit = 0; cusA.Debit = cusA.Amount; } } if (Convert.ToInt32(paidTxt.Text) == cusA.Amount) { cusA.Credit = 0; cusA.Debit = cusA.Amount; } dbobj.CustomersAccounts.Add(cusA); dbobj.SaveChanges(); int tempCuId = Convert.ToInt32(ViewState["cusId"]); SaleDetail sd = new SaleDetail(); for (int i = 0; i < GridView1.Rows.Count; i++) { sd.ProductId = Convert.ToInt32(GridView1.Rows[i].Cells[2].Text); sd.Quatity = Convert.ToInt32(GridView1.Rows[i].Cells[4].Text); sd.Rate = Convert.ToInt32(GridView1.Rows[i].Cells[5].Text); sd.DiscountedRate = Convert.ToInt32(GridView1.Rows[i].Cells[6].Text); sd.SaleInvoiceId = Convert.ToInt32(ViewState["sInvId"]); dbobj.SaleDetails.Add(sd); dbobj.SaveChanges(); Stock st = new Stock(); int tempbranchId = Convert.ToInt32(Session["BranchId"]); st = (from sup in dbobj.Stocks where sup.ProductId == sd.ProductId && sup.LocationId == tempbranchId select sup).FirstOrDefault(); if (st != null) { st.ProductId = sd.ProductId; st.Quantity -= sd.Quatity; dbobj.SaveChanges(); } } if (CurBalance != 0) { int tempAccId = accId; Account ac = new Account(); ac = (from act in dbobj.Accounts where act.AccountId == tempAccId select act).FirstOrDefault(); if (ac != null) { ac.CurrentBalance = (Convert.ToInt32(ac.CurrentBalance) + si.Paid).ToString(); dbobj.SaveChanges(); } AccountDetail acd = new AccountDetail(); acd.Particular = "Sale inv # " + ViewState["sInvId"]; acd.Amount = si.Paid; //acd.Amount = 0; acd.Mode = "Inward"; acd.DateTime = System.DateTime.Now; acd.AccountId = accId; acd.UserId = Convert.ToInt32(Session["UserId"]); acd.Type = "Cash"; acd.SaleInvId = si.SaleInvoicId; dbobj.AccountDetails.Add(acd); dbobj.SaveChanges(); int acdId = acd.AccountsDetailId; if (acd.Type == "Cash") { CashTran ct = new CashTran(); ct.Particular = "Sale inv# " + ViewState["sInvId"]; ct.Amount = si.Paid; ct.AccountDetailId = acd.AccountsDetailId; dbobj.CashTrans.Add(ct); dbobj.SaveChanges(); } else if (acd.Type == "Cheque") { BnkTan bkt = new BnkTan(); bkt.Particular = "Sale inv# " + ViewState["sInvId"]; bkt.Amount = si.Paid; bkt.AccountDetailId = acd.AccountsDetailId; if (chqTxt.Text != "") { bkt.ChequeId = Convert.ToInt32(ViewState["chequeId"]); } bkt.MadeBy = mbTxt.Text; bkt.DueDate = System.DateTime.Now; dbobj.BnkTans.Add(bkt); dbobj.SaveChanges(); } } } Session["sInvId"] = ViewState["sInvId"]; string pageurl = "InvoicePrint.aspx"; Response.Write("<script> window.open('" + pageurl + "','_blank'); </script>"); // Session["sInvId"] = Convert.ToInt32(ViewState["sInvId"]); Response.Redirect("InvoicePrint.aspx"); } catch (Exception) { } } else { Afail.Visible = true; } //int sid = Convert.ToInt32(Session["sInvId"]); // Response.Redirect(Request.RawUrl); // string pageurl1 = "InvoicePrint.aspx"; // Response.Write("<script> window.open('" + pageurl1 + "','_blank'); </script>"); } else { Afail.Visible = true; } }
protected void Deposit_btn_Click(object sender, EventArgs e) { fund = Convert.ToInt32(fundTxt.Text); AccId = Convert.ToInt32(DropDownList2.SelectedItem.Value); SupId = Convert.ToInt32(ViewState["SupId"]); if (fundTxt.Text != "" && fund != 0) { using (dbobj) { Supplier sp = new Supplier(); sp = (from s in dbobj.Suppliers where s.SupplierId == SupId select s).FirstOrDefault(); sp.Balance += fund; dbobj.SaveChanges(); SupplierAccount spa = new SupplierAccount(); spa.SupplierId = sp.SupplierId; spa.Particular = "Fund Deposit"; spa.Credit = 0; spa.Amount = fund; spa.Debit = fund; spa.Date = System.DateTime.Now; spa.AccountId = AccId; spa.UserId = Convert.ToInt32(Session["UserId"]); dbobj.SupplierAccounts.Add(spa); dbobj.SaveChanges(); //fund = sp.Balance; Account ac = new Account(); ac = (from a in dbobj.Accounts where a.AccountId == AccId select a).FirstOrDefault(); if (GridView3.Rows.Count >= 1) { for (int i = 0; i < GridView3.Rows.Count; i++) { PurcInv = Convert.ToInt32(GridView3.Rows[i].Cells[0].Text); PurchaseInvoice pi = new PurchaseInvoice(); pi = (from p in dbobj.PurchaseInvoices where p.PurchaseInvoiceId == PurcInv select p).FirstOrDefault(); if (fund > 0) { if (fund >= pi.Balance) { /* SupplierAccount spa1 = new SupplierAccount(); * spa1.SupplierId = sp.SupplierId; * spa1.Particular = "Payment for Purchase#" + PurcInv; * spa1.Credit = pi.Balance; * spa1.Debit = 0; * spa1.Date = System.DateTime.Now; * spa1.AccountId = AccId; * spa1.UserId = Convert.ToInt32(Session["UserId"]); * * dbobj.SupplierAccounts.Add(spa); * dbobj.SaveChanges(); */ int accb = Convert.ToInt32(ac.CurrentBalance); int newbal = accb - fund; ac.CurrentBalance = newbal.ToString(); dbobj.SaveChanges(); AccountDetail acd = new AccountDetail(); acd.Particular = "Purchase Inv# " + PurcInv; acd.Amount = fund; acd.Mode = "Outward"; acd.DateTime = System.DateTime.Now; acd.AccountId = AccId; acd.UserId = Convert.ToInt32(Session["UserId"]); acd.Type = "Cash"; acd.PurchInvId = PurcInv; dbobj.AccountDetails.Add(acd); dbobj.SaveChanges(); //sp.Balance -= pi.Balance; //dbobj.SaveChanges(); CashTran ct = new CashTran(); ct.Particular = "Purchase Inv# " + PurcInv; ct.Amount = pi.Balance; ct.AccountDetailId = acd.AccountsDetailId; dbobj.CashTrans.Add(ct); dbobj.SaveChanges(); fund = fund - pi.Balance; pi.Paid = pi.Amount; pi.Balance = 0; pi.Status = "Cleared"; dbobj.SaveChanges(); } else if (fund < pi.Balance) { pi.Paid = pi.Paid + fund; pi.Balance = pi.Balance - fund; dbobj.SaveChanges(); /* SupplierAccount spa1 = new SupplierAccount(); * spa1.SupplierId = sp.SupplierId; * spa1.Particular = "Payment for Purchase#" + PurcInv; * spa1.Credit = fund; * spa1.Debit = 0; * spa1.Date = System.DateTime.Now; * spa1.AccountId = AccId; * spa1.UserId = Convert.ToInt32(Session["UserId"]); * * dbobj.SupplierAccounts.Add(spa); * dbobj.SaveChanges(); */ int accb = Convert.ToInt32(ac.CurrentBalance); int newbal = accb - fund; ac.CurrentBalance = newbal.ToString(); dbobj.SaveChanges(); AccountDetail acd = new AccountDetail(); acd.Particular = "Purchase Inv# " + PurcInv; acd.Amount = fund; acd.Mode = "Outward"; acd.DateTime = System.DateTime.Now; acd.AccountId = AccId; acd.UserId = Convert.ToInt32(Session["UserId"]); acd.Type = "Cash"; acd.PurchInvId = PurcInv; dbobj.AccountDetails.Add(acd); dbobj.SaveChanges(); //sp.Balance -= fund; //dbobj.SaveChanges(); CashTran ct = new CashTran(); ct.Particular = "Purchase Inv# " + PurcInv; ct.Amount = fund; ct.AccountDetailId = acd.AccountsDetailId; dbobj.CashTrans.Add(ct); dbobj.SaveChanges(); fund = 0; break; } } else { break; } } } } } Response.Redirect(Request.RawUrl); }
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e) { int tempId = (Int32)ViewState["tempId"]; int id = Convert.ToInt32(GridView2.Rows[e.RowIndex].Cells[0].Text); TextBox qn = (TextBox)GridView2.Rows[e.RowIndex].FindControl("qntyTxt"); TextBox rt = (TextBox)GridView2.Rows[e.RowIndex].FindControl("rateTxt"); TextBox dr = (TextBox)GridView2.Rows[e.RowIndex].FindControl("drTxt"); int prvBal = Convert.ToInt32(dr.Text); int prvQnty = 0; int proId; int stLoc; //int qn = Convert.ToInt32(GridView2.Rows[e.RowIndex].Cells[3].Text); try { using (AdvInvSystemEntities dbobj = new AdvInvSystemEntities()) { var saleDetail = (from sd in dbobj.SaleDetails where sd.SaleInvoiceDetailId == id select sd).FirstOrDefault(); prvQnty = saleDetail.Quatity; proId = saleDetail.ProductId; if (Convert.ToInt32(qn.Text) > 0) { saleDetail.Quatity = Convert.ToInt32(qn.Text); saleDetail.Rate = Convert.ToInt32(rt.Text); saleDetail.DiscountedRate = Convert.ToInt32(qn.Text) * Convert.ToInt32(rt.Text); dbobj.SaveChanges(); } else if (Convert.ToInt32(qn.Text) < 0) { dbobj.SaleDetails.Remove(saleDetail); dbobj.SaveChanges(); } if (saleDetail.DiscountedRate > prvBal) { diff = saleDetail.DiscountedRate - prvBal; } if (saleDetail.DiscountedRate < prvBal) { diff = saleDetail.DiscountedRate - prvBal; } CustomersAccount ca = new CustomersAccount(); SaleInvoice si = new SaleInvoice(); si = (from s in dbobj.SaleInvoices where s.SaleInvoicId == tempId select s).FirstOrDefault(); stLoc = si.BranchId; si.Payable = si.Payable + diff; si.Amount = si.Amount + diff; if (si.Status == "Cleared") { si.Paid = si.Payable; } dbobj.SaveChanges(); var stl = (from st in dbobj.Stocks where st.ProductId == proId && st.LocationId == stLoc select st).FirstOrDefault(); if (Convert.ToInt32(qn.Text) > 0) { if (prvQnty > Convert.ToInt32(qn.Text)) { diff = prvQnty - Convert.ToInt32(qn.Text); stl.Quantity += diff; dbobj.SaveChanges(); } else if (Convert.ToInt32(qn.Text) > prvQnty) { diff = Convert.ToInt32(qn.Text) - prvQnty; stl.Quantity -= diff; dbobj.SaveChanges(); } } else if (Convert.ToInt32(qn.Text) <= 0) { var st2 = (from st in dbobj.Stocks where st.ProductId == proId && st.LocationId == stLoc select st).FirstOrDefault(); st2.Quantity += prvQnty; dbobj.SaveChanges(); } /* Customer cu = new Customer(); * cu = (from cust in dbobj.Customers * where cust.CustomerId == si.CustomerId * select cust).FirstOrDefault(); * if (cu.Balance != 0) * { * cu.Balance += diff; * dbobj.SaveChanges(); * } */ CustomersAccount cusA = new CustomersAccount(); cusA.CustomerId = si.CustomerId; cusA.Date = System.DateTime.Now; cusA.Credit = diff; cusA.Debit = diff; cusA.Status = "Cleared"; dbobj.CustomersAccounts.Add(cusA); dbobj.SaveChanges(); Account ac = new Account(); ac = (from act in dbobj.Accounts where act.AccountId == si.AccountId select act).FirstOrDefault(); ac.CurrentBalance = (Convert.ToInt32(ac.CurrentBalance) + diff).ToString(); dbobj.SaveChanges(); AccountDetail acd = new AccountDetail(); acd.Particular = "Sale Return inv# " + si.SaleInvoicId; acd.Amount = diff; acd.Mode = "Outward"; acd.DateTime = System.DateTime.Now; acd.AccountId = (Int32)si.AccountId; acd.UserId = Convert.ToInt32(Session["UserId"]); acd.Type = "Cash"; acd.SaleInvId = si.SaleInvoicId; dbobj.AccountDetails.Add(acd); dbobj.SaveChanges(); CashTran ct = new CashTran(); ct.Particular = "Sale Return inv# " + si.SaleInvoicId; ct.Amount = diff; ct.AccountDetailId = acd.AccountsDetailId; dbobj.CashTrans.Add(ct); dbobj.SaveChanges(); GridView2.EditIndex = -1; loadGrid(tempId); DataBind(); Response.Redirect(Request.RawUrl); } } catch (Exception) { } }
protected void Deposit_btn_Click(object sender, EventArgs e) { int acId = Convert.ToInt32(DropDownList2.SelectedItem.Value); fund = Convert.ToInt32(fundTxt.Text); if (fundTxt.Text != "" || Convert.ToInt32(fundTxt.Text) != 0) { int tempCustId = Convert.ToInt32(GridView1.Rows[0].Cells[0].Text); fund = Convert.ToInt32(fundTxt.Text); try { using (AdvInvSystemEntities dbobj = new AdvInvSystemEntities()) { Customer cu = new Customer(); cu = (from c in dbobj.Customers where c.CustomerId == tempCustId select c).FirstOrDefault(); cu.Balance = cu.Balance + fund; dbobj.SaveChanges(); CustomersAccount ca = new CustomersAccount(); ca.CustomerId = tempCustId; ca.Date = System.DateTime.Now; ca.Particular = "Fund Deposit"; ca.Amount = fund; ca.Debit = fund; ca.Credit = 0; ca.Status = "Cleared"; dbobj.CustomersAccounts.Add(ca); dbobj.SaveChanges(); //fund = (Int32)cu.Balance; if (GridView2.Rows.Count >= 1) { for (int i = 0; i <= GridView2.Rows.Count; i++) { if (fund != 0) { int tempSInv = Convert.ToInt32(GridView2.Rows[i].Cells[0].Text); SaleInvoice si = new SaleInvoice(); si = (from s in dbobj.SaleInvoices where s.SaleInvoicId == tempSInv select s).FirstOrDefault(); int tempBal = si.Payable - si.Paid; if (fund >= tempBal) { si.Paid = si.Payable; si.Status = "Cleared"; dbobj.SaveChanges(); //cu.Balance = cu.Balance - tempBal; //dbobj.SaveChanges(); AccountDetail acd = new AccountDetail(); acd.Particular = "Sale inv# " + si.SaleInvoicId; acd.Amount = tempBal; acd.Mode = "Inward"; acd.DateTime = System.DateTime.Now; acd.UserId = Convert.ToInt32(Session["UserId"]); acd.SaleInvId = si.SaleInvoicId; acd.Type = "Cash"; acd.AccountId = Convert.ToInt32(DropDownList2.SelectedItem.Value); dbobj.AccountDetails.Add(acd); dbobj.SaveChanges(); Account ac = new Account(); ac = (from a in dbobj.Accounts where a.AccountId == acId select a).FirstOrDefault(); ac.CurrentBalance = (Convert.ToInt32(ac.CurrentBalance) + tempBal).ToString(); dbobj.SaveChanges(); CashTran ct = new CashTran(); ct.Particular = "Sale inv# " + si.SaleInvoicId; ct.Amount = tempBal; ct.AccountDetailId = acd.AccountsDetailId; dbobj.CashTrans.Add(ct); dbobj.SaveChanges(); fund = fund - tempBal; } else if (fund > 0 && fund < tempBal) { int tempremBal = Convert.ToInt32(fund); si.Paid = si.Paid + Convert.ToInt32(fund); dbobj.SaveChanges(); //cu.Balance = cu.Balance - Convert.ToInt32(fund); //dbobj.SaveChanges(); AccountDetail acd = new AccountDetail(); acd.Particular = "Sale inv# " + si.SaleInvoicId; acd.Amount = tempremBal; acd.Mode = "Inward"; acd.DateTime = System.DateTime.Now; acd.UserId = Convert.ToInt32(Session["UserId"]); acd.SaleInvId = si.SaleInvoicId; acd.Type = "Cash"; acd.AccountId = Convert.ToInt32(DropDownList2.SelectedItem.Value); dbobj.AccountDetails.Add(acd); dbobj.SaveChanges(); Account ac = new Account(); ac = (from a in dbobj.Accounts where a.AccountId == acId select a).FirstOrDefault(); ac.CurrentBalance = (Convert.ToInt32(ac.CurrentBalance) + tempremBal).ToString(); dbobj.SaveChanges(); CashTran ct = new CashTran(); ct.Particular = "Sale inv# " + si.SaleInvoicId; ct.Amount = tempremBal; ct.AccountDetailId = acd.AccountsDetailId; dbobj.CashTrans.Add(ct); dbobj.SaveChanges(); fund = 0; break; } } } } Response.Redirect(Request.RawUrl); } } catch (Exception) { } } }
protected void Button2_Click(object sender, EventArgs e) { qntyTxt.Focus(); using (AdvInvSystemEntities dbobj = new AdvInvSystemEntities()) { if (GridView1.Rows.Count != 0) { if (Convert.ToInt32(paidTxt.Text) <= Convert.ToInt32(amountTxt.Text)) { if (spcellTxt.Text != "") { Supplier sp = new Supplier(); sp = (from sup in dbobj.Suppliers where sup.CellNumber == spcellTxt.Text select sup).FirstOrDefault(); if (sp == null) { Supplier spn = new Supplier(); spn.Name = spnmTxt.Text; spn.CellNumber = spcellTxt.Text; spn.Company = spcomTxt.Text; spn.Address = spaddTxt.Text; bal = Convert.ToInt32(paidTxt.Text) - Convert.ToInt32(amountTxt.Text); spn.Balance = bal; dbobj.Suppliers.Add(spn); dbobj.SaveChanges(); supId = spn.SupplierId; } else { bal = Convert.ToInt32(paidTxt.Text) - Convert.ToInt32(amountTxt.Text); sp.Balance = sp.Balance + bal; dbobj.SaveChanges(); supId = sp.SupplierId; } } else { supId = 1; } PurchaseInvoice pi = new PurchaseInvoice(); pi.BrandId = Convert.ToInt32(brdDropDown.SelectedItem.Value); pi.Date = System.DateTime.Now; pi.ReferenceId = refTxt.Text; pi.Amount = Convert.ToInt32(amountTxt.Text); pi.Paid = Convert.ToInt32(paidTxt.Text); pi.Balance = Convert.ToInt32(amountTxt.Text) - Convert.ToInt32(paidTxt.Text); if (pi.Balance != 0) { pi.Status = "Pending"; } else { pi.Status = "Cleared"; } pi.UserId = Convert.ToInt32(Session["UserId"]); pi.AccountCredit = Convert.ToInt32(AccDropDownlist.SelectedItem.Value); pi.StockLocId = Convert.ToInt32(brnchDownList.SelectedItem.Value); locId = pi.StockLocId; pi.SupplierId = supId; if (PMDropdownlist.SelectedIndex != -1) { pi.PaymentMode = PMDropdownlist.SelectedItem.Value; } dbobj.PurchaseInvoices.Add(pi); dbobj.SaveChanges(); ViewState["purInvId"] = pi.PurchaseInvoiceId; SupplierAccount spa = new SupplierAccount(); spa.SupplierId = supId; spa.Particular = "Purchash inv#" + pi.PurchaseInvoiceId; spa.Amount = Convert.ToInt32(amountTxt.Text); spa.Debit = pi.Paid; spa.Credit = Convert.ToInt32(amountTxt.Text) - pi.Paid; spa.Date = System.DateTime.Now; spa.AccountId = pi.AccountCredit; spa.UserId = 1; dbobj.SupplierAccounts.Add(spa); dbobj.SaveChanges(); ChequeList cql = new ChequeList(); if (PMDropdownlist.SelectedItem.Value == "Cheque") { cql.Mode = "Outward"; cql.ChequeNumber = chqTxt.Text; cql.Bank = bnkTxt.Text; cql.MadeBy = mbTxt.Text; cql.Amount = Convert.ToInt32(ammTxt.Text); cql.Date = System.DateTime.Now; cql.Status = "Pending"; cql.AccountId = 1; dbobj.ChequeLists.Add(cql); dbobj.SaveChanges(); } ViewState["chequeId"] = cql.ChequeId; PurchaseDetail purD = new PurchaseDetail(); for (int i = 0; i < GridView1.Rows.Count; i++) { purD.ProductId = Convert.ToInt32(GridView1.Rows[i].Cells[2].Text); purD.Quantity = Convert.ToInt32(GridView1.Rows[i].Cells[4].Text); purD.Price = Convert.ToInt32(GridView1.Rows[i].Cells[5].Text); purD.PurchaseInvoice = Convert.ToInt32(ViewState["purInvId"]); dbobj.PurchaseDetails.Add(purD); dbobj.SaveChanges(); Product pd = new Product(); pd = (from prod in dbobj.Products where prod.ProductId == purD.ProductId select prod).SingleOrDefault(); if (pd != null) { pd.PurchasePrice = Convert.ToInt32(GridView1.Rows[i].Cells[6].Text); pd.SalePrice = Convert.ToInt32(GridView1.Rows[i].Cells[7].Text); dbobj.SaveChanges(); } Stock st = new Stock(); st = (from sup in dbobj.Stocks where sup.ProductId == purD.ProductId && sup.LocationId == locId select sup).FirstOrDefault(); if (st != null) { //st.ProductId = purD.ProductId; st.Quantity += purD.Quantity; //st.LocationId = locId; //dbobj.sp_Add_Stock(st.ProductId, st.LocationId, st.Quantity); dbobj.SaveChanges(); } else { Stock st1 = new Stock(); st1.ProductId = purD.ProductId; st1.Quantity = purD.Quantity; st1.LocationId = locId; dbobj.Stocks.Add(st1); dbobj.SaveChanges(); } } if (paidTxt.Text != "" || paidTxt.Text != "0") { int tempAccId = Convert.ToInt32(AccDropDownlist.SelectedItem.Value); Account ac = new Account(); ac = (from act in dbobj.Accounts where act.AccountId == tempAccId select act).FirstOrDefault(); if (ac != null) { ac.CurrentBalance = (Convert.ToInt32(ac.CurrentBalance) - Convert.ToInt32(paidTxt.Text)).ToString(); dbobj.SaveChanges(); } AccountDetail acd = new AccountDetail(); acd.Particular = "Payment inv# " + ViewState["purInvId"]; acd.Amount = Convert.ToInt32(paidTxt.Text); acd.Mode = "Outward"; acd.DateTime = System.DateTime.Now; acd.AccountId = Convert.ToInt32(AccDropDownlist.SelectedItem.Value); acd.UserId = Convert.ToInt32(Session["UserId"]); acd.Type = PMDropdownlist.SelectedItem.Text; acd.PurchInvId = Convert.ToInt32(ViewState["purInvId"]); dbobj.AccountDetails.Add(acd); dbobj.SaveChanges(); //pi.TransactionId = acd.AccountsDetailId; ViewState["transId"] = acd.AccountsDetailId; if (PMDropdownlist.SelectedItem.Text == "Cash") { CashTran ct = new CashTran(); ct.Particular = "Purchase inv# " + ViewState["purInvId"]; ct.Amount = Convert.ToInt32(paidTxt.Text); ct.AccountDetailId = acd.AccountsDetailId; dbobj.CashTrans.Add(ct); dbobj.SaveChanges(); } else if (PMDropdownlist.SelectedItem.Text == "Cheque") { BnkTan bkt = new BnkTan(); bkt.Particular = "Purchase inv# " + ViewState["purInvId"]; bkt.Amount = Convert.ToInt32(paidTxt.Text); bkt.AccountDetailId = acd.AccountsDetailId; if (chqTxt.Text != "") { bkt.ChequeId = Convert.ToInt32(ViewState["chequeId"]); } bkt.MadeBy = mbTxt.Text; bkt.DueDate = System.DateTime.Now; dbobj.BnkTans.Add(bkt); dbobj.SaveChanges(); } } Div2.Visible = true; Response.Redirect(Request.RawUrl); } // end of row count condition for checkout else { Div1.Visible = true; } } else { Div1.Visible = true; } } // end of dbobj }