public void Save() { if (CheckDouble(txtTaxtype.Text) == "false") { lblcheckDoubleError.Text = String.Empty; tbl_taxtype type = new tbl_taxtype(); type.branch_id = branchId; //Convert.ToInt32(Session["branch_id"]); type.company_id = companyId; //Convert.ToInt32(Session["company_id"]); type.type_name = txtTaxtype.Text; type.created_by = User_id; //Convert.ToString(Session["UserID"]); type.created_date = DateTime.Today; type.modified_by = ""; type.modified_date = null; type.status = true; context.tbl_taxtype.Add(type); context.SaveChanges(); loadDataTable(); divalert.Visible = true; lblAlert.Text = "Saved Successfully"; txtTaxtype.Text = string.Empty; } else { divalert.Visible = false; lblcheckDoubleError.ForeColor = System.Drawing.Color.Red; lblcheckDoubleError.Text = "This type name already Exists"; return; } }
protected void btnSubmit_Click(object sender, EventArgs e) { int userId = Convert.ToInt32(Session["UserID"]); string otp = string.Empty; if (txtOtp.Value == null || txtOtp.Value == "") { lblWrongOTP.InnerText = "Please enter OTP"; return; } else { lblWrongOTP.InnerText = ""; } var userdata = context.tbl_User.Where(u => u.user_id == userId).FirstOrDefault(); if (txtOtp.Value == userdata.OTP) { lblWrongOTP.InnerText = ""; userdata.IsVerified = true; context.SaveChanges(); Response.Redirect("~/Registration/Login.aspx"); } else { lblWrongOTP.InnerText = "Wrong OTP"; return; } }
protected void Update() { try { lblError.Text = string.Empty; if (ValidCalculation()) { var purchasePaymentDetails = context.tbl_PurchasePaymentDetials.FirstOrDefault(w => w.PurchaseId == purchase_Id); if (purchasePaymentDetails != null) { purchasePaymentDetails.PaidAmnt = Convert.ToDecimal(txtPaidAmnt.Text); purchasePaymentDetails.GivenAmnt = Convert.ToDecimal(txtPaidAmnt.Text) + purchasePaymentDetails.GivenAmnt; purchasePaymentDetails.BalanceAmnt = Convert.ToDecimal(txtBalanceAmnt.Text); purchasePaymentDetails.FromTable = "Purchase Pay Balance"; } context.SaveChanges(); int?order = purchasePaymentDetails.PurchaseId; ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('Saved successfully, Your order number is " + order + "');", true); } else { ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('Calculation doesn't match, please check calculation.');", true); } } catch (Exception ex) { ErrorLog.saveerror(ex); } }
protected void Update() { try { lblError.Text = string.Empty; if (ValidCalculation()) { sale_Id = Convert.ToInt32(hdnSaleId.Value); var salePaymentDetails = context.tbl_SalePaymentDetails.Where(w => w.SaleId == sale_Id).FirstOrDefault(); if (salePaymentDetails != null) { salePaymentDetails.PaidAmnt = Convert.ToDecimal(txtPaidAmnt.Text); salePaymentDetails.GivenAmnt = Convert.ToDecimal(txtPaidAmnt.Text) + salePaymentDetails.GivenAmnt; salePaymentDetails.BalanceAmnt = Convert.ToDecimal(txtBalanceAmnt.Text); salePaymentDetails.FromTable = Constants.SalePayBalance; salePaymentDetails.ModifiedDate = DateTime.Now; salePaymentDetails.ModifiedBy = user_id; } context.SaveChanges(); int?order = salePaymentDetails.SaleId; ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('Saved successfully, Your order number is " + order + "');", true); } else { ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('Calculation doesn't match, please check calculation.');", true); } } catch (Exception ex) { ErrorLog.saveerror(ex); } }
public void savedcode() { try { tbl_paymentmode paymentmode = new tbl_paymentmode(); paymentmode.branch_id = companyId; paymentmode.company_id = branchId; paymentmode.paymentmode_name = txtName.Text; paymentmode.created_by = User_id; paymentmode.created_date = DateTime.Today; paymentmode.modified_by = ""; paymentmode.modified_date = null; paymentmode.status = true; ////Shakeeb ////pad.Insert(pad); //Entity Framework Saving Awais context.tbl_paymentmode.Add(paymentmode); context.SaveChanges(); loadDataTable(); } catch (Exception ex) { ErrorLog.saveerror(ex); //Do Logging } }
protected void btnPay_Click(object sender, EventArgs e) { try { string userName = Session["username"].ToString(); foreach (GridViewRow row in gvPartyInvoiceDetails.Rows) { var chb = row.FindControl("chbCheck") as CheckBox; if (chb.Checked) { dynamic tblPaymentDetails = ""; var id = 0; if (rbtnVender.Checked == true) { id = Convert.ToInt32(row.Cells[2].Text); tblPaymentDetails = (from ppd in context.tbl_PurchasePaymentDetials join p in context.tbl_purchase on ppd.PurchaseId equals p.purchase_id where p.purchase_id == id select ppd).ToList().FirstOrDefault(); tblPaymentDetails.FromTable = Constants.VendorPayBalance; } else { id = Convert.ToInt32(row.Cells[2].Text); tblPaymentDetails = (from spd in context.tbl_SalePaymentDetails join s in context.tbl_sale on spd.SaleId equals s.sale_id where s.sale_id == id select spd).ToList().FirstOrDefault(); tblPaymentDetails.FromTable = Constants.CustomerPayBalance; } decimal BalAmnt = tblPaymentDetails.BalanceAmnt; decimal GivenAmnt = tblPaymentDetails.GivenAmnt; GivenAmnt = GivenAmnt + BalAmnt; tblPaymentDetails.BalanceAmnt = 0; tblPaymentDetails.GivenAmnt = GivenAmnt; tblPaymentDetails.ModifiedDate = DateTime.Now; tblPaymentDetails.ModifiedBy = userName; context.SaveChanges(); dvpartyInvoiceDetails.Visible = false; if (rbtnVender.Checked == true) { gridBind("v"); } else { gridBind("c"); } } } } catch (Exception ex) { ErrorLog.saveerror(ex); } }
public void savedlogic() { try { int a = Convert.ToInt32(Session["company_id"]); int s = Convert.ToInt32(ddlState.SelectedValue); string user = Session["UserID"].ToString(); SqlCommand cmd = new SqlCommand(); if (fileuplogo.HasFile) { HttpPostedFile postedFile = fileuplogo.PostedFile; string filename = Path.GetFileName(postedFile.FileName); string fileExtension = Path.GetExtension(filename); int fileSize = postedFile.ContentLength; if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".png") { //Stream stream = postedFile.InputStream; //BinaryReader binaryReader = new BinaryReader(stream); //Byte[] bytes = binaryReader.ReadBytes((int)stream.Length); fileuplogo.SaveAs(Server.MapPath("~/Uploads/" + filename)); string imagepath = "~/Uploads/" + filename; tbl_company company = new tbl_company(); company.company_id = a; company.company_name = txtName.Text; company.company_address = txtAddress.Text; company.state_id = s; company.city = txtCity.Text; company.telephone_no = txttelephoneno.Text; company.fax_no = txtFaxno.Text; company.website = txtwebsite.Text; company.logo = imagepath; company.logo_name = filename; company.GSTIN = txtGSTIN.Text; company.modified_by = user; company.modified_date = DateTime.Now; context.Entry(company).State = EntityState.Modified; context.SaveChanges(); //context.tbl_company.(company); //context.SaveChanges(); } } } catch (Exception ex) { ErrorLog.saveerror(ex); } }
protected void btnSave_Click(object sender, EventArgs e) { try { bool tax; string reportname = "", papersize = ""; if (rbinvoicetax.Checked) { tax = true; } else { tax = false; } if (rbPurchaseSaleReturnReport1.Checked) { reportname = "PurchaseSaleReturnReport1.rdlc"; } else if (rbPurchaseSaleReturnReport2.Checked) { reportname = "PurchaseSaleReturnReport2.rdlc"; } else { reportname = "PurchaseSaleReturnReport3.rdlc"; } if (rbA4.Checked) { papersize = rbA4.Text; } else { papersize = rbA5.Text; } var set = context.tbl_setting.Where(w => w.company_id == companyId).FirstOrDefault(); // tbl_setting set = new tbl_setting(); set.modify_by = Convert.ToString(Session["UserID"]); set.modifydate = DateTime.Today; set.Enable_Invoice_Tax = tax; set.Print_Tin_on_Invoice = Convert.ToBoolean(chbPrintTin.Checked); set.currency_id = Convert.ToInt32(ddlCurrency.SelectedValue); set.Decimal_Places = Convert.ToInt32(txtdecimalplaces.Text); set.Print_address = Convert.ToBoolean(chbprintaddress.Checked); set.InvoiceTemplateName = reportname; set.PaperSize = papersize; context.SaveChanges(); divalert.Visible = true; lblAlert.Text = "Setting Saved"; } catch (Exception ex) { ErrorLog.saveerror(ex); } }
public void Save() { if (!GetAllDataForValidation()) { tbl_taxgroup taxGroup = new tbl_taxgroup(); taxGroup.company_id = companyId; taxGroup.branch_id = branchId; taxGroup.group_name = txtGrouphName.Text; taxGroup.status = true; taxGroup.created_by = User_id; taxGroup.created_date = DateTime.Now; taxGroup.modified_by = ""; taxGroup.modified_date = null; for (int i = 0; i <= gvtaxdetails.Rows.Count - 1; i++) { string txtpercentage = gvtaxdetails.Rows[i].Cells[2].Text; tbl_taxdetails taxDetailes = new tbl_taxdetails(); taxDetailes.type_id = Convert.ToInt32(gvtaxdetails.Rows[i].Cells[2].Text); taxDetailes.tax_percentage = Convert.ToDecimal(gvtaxdetails.Rows[i].Cells[1].Text); taxDetailes.status = true; taxDetailes.created_by = User_id; taxDetailes.created_date = DateTime.Now; taxDetailes.modified_by = ""; taxDetailes.modified_date = null; taxGroup.tbl_taxdetails.Add(taxDetailes); } context.tbl_taxgroup.Add(taxGroup); context.SaveChanges(); loadDataTable(); ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('Saved successfully');", true); } else { divalert.Visible = true; lblAlert.Text = "There is already a tax group created with the selected type."; } }
private void savedlogic() { try { if (hde.Value != "true") { if (hd2.Value != "true") { lblcheckDoubleError.Text = String.Empty; tbl_party p = new tbl_party(); p.company_id = companyId; p.branch_id = branchId; p.party_name = txtPartyName.Text; p.party_address = txtPartyAddress.Text; p.contact_no = txtContactNo.Text; p.gstin_no = txtGSTIN.Text; p.party_type = ddlPartyType.SelectedValue; p.state_id = Convert.ToInt32(ddlState.SelectedValue); //p.created_by = "admin"; p.created_by = User_id; p.created_date = DateTime.Today; p.status = true; ////Shakeeb ////p.Insert(p); //Entity Framework Saving Awais context.tbl_party.Add(p); context.SaveChanges(); loadDataTable(); divalert.Visible = true; lblAlert.Text = "Party Saved Successfully "; CLR(); } else { divalert.Visible = false; lblgstinerror.Text = "GSTIN No Must be 15 digit alphanumeric only"; } } else { divalert.Visible = false; lblcheckDoubleError.ForeColor = System.Drawing.Color.Red; lblcheckDoubleError.Text = "Party Name is already exists "; } } catch (Exception ex) { ErrorLog.saveerror(ex); //Do Logging } }
public void savedlogic() { string User_id = Convert.ToString(Session["UserID"]); try { if (CheckDouble(txtGodownName.Text) == "false") { lblcheckDoubleError.Text = String.Empty; tbl_godown g = new tbl_godown(); g.company_id = companyId; g.branch_id = branchId; g.godown_name = txtGodownName.Text; g.godown_address = txtGodownAddress.Text; g.contact_no = txtContactNo.Text; g.contact_person = txtContactPerson.Text; //g.created_by = "admin"; g.created_by = User_id; g.created_date = DateTime.Today; g.status = true; g.modified_by = ""; g.modified_date = null; ////Shakeeb ////g.AddGodown(g); //Entity Framework Saving Awais context.tbl_godown.Add(g); context.SaveChanges(); clr(); divalert.Visible = true; lblAlert.Text = "Godown Saved Successfully"; ((Godown)this.Page).loadDataTable(); List <tbl_godown> gd = context.tbl_godown.Where(x => x.status == true && x.company_id == companyId).ToList(); UC_Rack r = new UC_Rack(); r.fillgodown(gd); } else { divalert.Visible = false; lblcheckDoubleError.ForeColor = System.Drawing.Color.Red; lblcheckDoubleError.Text = "This Godown name already Exists"; return; } } catch (Exception ex) { ErrorLog.saveerror(ex); //Do Logging } }
protected void gvStockDetails_RowUpdating(object sender, GridViewUpdateEventArgs e) { //Finding the controls from Gridview for the row which is going to update Label lblStockId = gvStockDetails.Rows[e.RowIndex].FindControl("lblStockId") as Label; TextBox txtqty = gvStockDetails.Rows[e.RowIndex].FindControl("txtqty") as TextBox; var _stockId = Convert.ToUInt32(lblStockId.Text); var stockDetails = context.tbl_stock.Where(w => w.stock_id == _stockId).FirstOrDefault(); stockDetails.qty = Convert.ToInt32(txtqty.Text); context.SaveChanges(); gvStockDetails.EditIndex = -1; BindStock(); }
public void UpdateIsLogin(int userid) { try { context.tbl_User.FirstOrDefault(); var userdata = context.tbl_User.SingleOrDefault(u => u.user_id == userid); if (userdata != null) { userdata.Islogin = false; context.SaveChanges(); } } catch (Exception ex) { ErrorLog.saveerror(ex); } }
private void savecode() { try { if (hd.Value != "true") { lblcheckDoubleError.Text = String.Empty; tbl_rack rack = new tbl_rack(); rack.company_id = companyId; rack.branch_id = branchId; rack.godown_id = Int32.Parse(ddlGodownName.SelectedValue); rack.rack_name = txtRackName.Text; rack.created_by = User_id; rack.created_date = DateTime.Today; rack.status = true; rack.modified_by = ""; rack.modified_date = null; ////Shakeeb ////rd.Insert(rd); //Entity Framework Saving Awais context.tbl_rack.Add(rack); context.SaveChanges(); loadDataTable(); divalert.Visible = true; lblAlert.Text = "Rack Saved Successfully"; clr(); //lblError.Text = string.Empty; } else { divalert.Visible = false; lblcheckDoubleError.ForeColor = System.Drawing.Color.Red; lblcheckDoubleError.Text = "This Rack name already Exists"; return; } } catch (Exception ex) { ErrorLog.saveerror(ex); //Do Logging } }
/// <summary> /// All The Methods That are used in coding /// </summary> #region Methods //code done by ather for reset password changed from email to mobile no. public void SendLink() { try { Guid uniqueid = Guid.NewGuid(); string MobileNo = txtMobile.Value; int userId = context.tbl_User.Where(u => u.user_mobieno == MobileNo && u.status == true).Select(x => x.user_id).FirstOrDefault(); if (userId > 0) { Tbl_VerifyResetPass vrpass = new Tbl_VerifyResetPass(); vrpass.user_id = userId.ToString(); vrpass.uniqueidentifier = uniqueid.ToString(); vrpass.created_date = DateTime.Now; vrpass.status = true; context.Tbl_VerifyResetPass.Add(vrpass); context.SaveChanges(); var userData = (from u in context.tbl_User join vrp in context.Tbl_VerifyResetPass on u.user_id.ToString() equals vrp.user_id where u.user_mobieno == MobileNo && u.status == true && vrp.uniqueidentifier == uniqueid.ToString() select new clsData { uniqueidentifier = vrp.uniqueidentifier, user_id = vrp.user_id, Passverify_ID = vrp.Passverify_ID.ToString(), UserMobile = u.user_mobieno }).ToList().FirstOrDefault(); ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('We have sent link on your registered mobile no. to reset your password','False');", true); SendLink(userData); } else { ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('This Mobile No. is not register with IMSbizz','False');", true); return; } } catch (Exception ex) { ErrorLog.saveerror(ex); } }
public void savedlogic() { try { if (CheckDouble(txtBatchName.Text) == "false") { lblcheckDoubleError.Text = String.Empty; tbl_batch bat = new tbl_batch(); bat.branch_id = branchId;//Convert.ToInt32(Session["branch_id"]); bat.company_id = companyId;//Convert.ToInt32(Session["company_id"]); bat.batch_name = txtBatchName.Text; bat.created_by = User_id; //Convert.ToString(Session["UserID"]); bat.created_date = DateTime.Today; bat.modified_by = ""; bat.modified_date = null; bat.status = true; context.tbl_batch.Add(bat); context.SaveChanges(); divalert.Visible = true; lblAlert.Text = "Saved Successfully"; txtBatchName.Text = string.Empty; ((Batch)this.Page).loadDataTable(); } else { divalert.Visible = false; lblcheckDoubleError.ForeColor = System.Drawing.Color.Red; lblcheckDoubleError.Text = "This Batch name already Exists"; return; } } catch (Exception ex) { ErrorLog.saveerror(ex); //Do Logging } }
private void savecode() { try { if (CheckDouble(txtTaxName.Text) != "true") { lblcheckDoubleError.Text = String.Empty; tbl_tax cat = new tbl_tax(); cat.branch_id = branchId; cat.company_id = companyId; cat.tax_name = txtTaxName.Text; cat.tax_percentage = decimal.Parse(txtTaxPercent.Text); cat.created_by = User_id; cat.created_date = DateTime.Today; cat.modified_by = ""; cat.modified_date = null; cat.status = true; ////Shakeeb ////cat.Insert(cat); //Entity Framework Saving Awais context.tbl_tax.Add(cat); context.SaveChanges(); loadDataTable(); clr(); divalert.Visible = true; lblAlert.Text = "Tax Saved Successfully "; } else { divalert.Visible = false; lblcheckDoubleError.ForeColor = System.Drawing.Color.Red; lblcheckDoubleError.Text = "This Tax name already Exists"; } } catch (Exception ex) { ErrorLog.saveerror(ex); //Do Logging } }
private void savedcode() { try { if (CheckDouble(txtUnitName.Text) == "false") { lblcheckDoubleError.Text = string.Empty; tbl_unit u = new tbl_unit(); u.branch_id = branchId; u.company_id = companyId; u.unit_name = txtUnitName.Text; u.created_by = User_id; u.created_date = DateTime.Today; u.modified_by = ""; u.modified_date = null; u.status = true; ////Shakeeb ////u.AddUnit(u); //Entity Framework Saving Awais context.tbl_unit.Add(u); context.SaveChanges(); loadDataTable(); divalert.Visible = true; lblAlert.Text = "Unit Saved Successfully "; txtUnitName.Text = string.Empty; } else { divalert.Visible = false; lblcheckDoubleError.Text = "This unit name already Exists"; lblcheckDoubleError.ForeColor = System.Drawing.Color.Red; return; } } catch (Exception ex) { ErrorLog.saveerror(ex); //Do Logging } }
public void savedlogic() { try { if (hd.Value == "false" && hd12.Value == "false") { string User_id = Convert.ToString(Session["UserID"]); tbl_financialyear financialyear = new tbl_financialyear(); financialyear.branch_id = branchId; financialyear.company_id = companyId; financialyear.start_date = txtStartdate.Text; financialyear.end_date = txtEndDate.Text; //cat.created_by = "admin"; financialyear.created_by = User_id; financialyear.created_date = DateTime.Today; ////Shakeeb ////cat.Insert(cat); context.tbl_financialyear.Add(financialyear); context.SaveChanges(); //loadDataTable(); divalert.Visible = true; lblAlert.Text = "Financial year Saved Successfully "; } else { divalert.Visible = true; lblAlert.ForeColor = System.Drawing.Color.Red; lblAlert.Text = "Please Choose Another Date"; } } catch (Exception ex) { ErrorLog.saveerror(ex); //Do Logging } }
public void Save() { try { if (CheckDouble_category(txtCategoryName.Text) == false) { tbl_category cat = new tbl_category(); cat.branch_id = branchId; cat.company_id = companyId; cat.category_name = txtCategoryName.Text; cat.created_by = Convert.ToString(Session["UserID"]); cat.created_date = DateTime.Today; cat.modified_by = ""; cat.modified_date = null; cat.status = true; context.tbl_category.Add(cat); context.SaveChanges(); // loadDataTable(); txtCategoryName.Text = string.Empty; divalert.Visible = true; lblAlert.Text = "Category Saved"; lblcheckDoubleError.Text = string.Empty; ((Category)this.Page).loadDataTable(); } else { divalert.Visible = false; lblcheckDoubleError.Text = "Category Already Exists."; lblcheckDoubleError.ForeColor = System.Drawing.Color.Red; return; } } catch (Exception ex) { ErrorLog.saveerror(ex); //Do Logging } }
private void savedlogic() { try { if (CheckDouble(txtExpenseName.Text) != "true") { lblcheckDoubleError.Text = String.Empty; tbl_expense et = new tbl_expense(); et.company_id = companyId; et.branch_id = branchId; et.expense_name = txtExpenseName.Text; et.created_by = User_id; et.created_date = DateTime.Today; et.status = true; et.modified_by = ""; et.modified_date = null; context.tbl_expense.Add(et); context.SaveChanges(); loadDataTable(); divalert.Visible = true; lblAlert.Text = "Expense Saved Successfully "; txtExpenseName.Text = string.Empty; } else { divalert.Visible = false; lblcheckDoubleError.ForeColor = System.Drawing.Color.Red; lblcheckDoubleError.Text = "Expense Name is already exists "; } } catch (Exception ex) { ErrorLog.saveerror(ex); //Do Logging } }
protected void Save() { try { //added by ather for file attachment url string path = "~/Uploads/AttachedFiles/Sale/"; //path without filename to save file bool fileupMsg = uploadFile(fuAttacheFile, path, ""); decimal balanceAmt = 0; // Convert.ToDecimal(txtBalanceAmt.Text); decimal paidAmnt = 0; if (!string.IsNullOrEmpty(txtGivenAmt.Text)) { paidAmnt = Convert.ToDecimal(txtGivenAmt.Text); } if (!string.IsNullOrEmpty(txtBalanceAmt.Text)) { balanceAmt = Convert.ToDecimal(txtBalanceAmt.Text); } tbl_sale sale = new tbl_sale(); if (fileupMsg) { path = path + Path.GetFileName(fuAttacheFile.PostedFile.FileName); //path with filename to save in DB sale.attachmentUrl = path; } sale.company_id = companyId; sale.branch_id = branchId; sale.financialyear_id = financialYearId; sale.paymentmode_id = Convert.ToInt32(ddlPaymentMode.SelectedValue); sale.status = true; sale.party_id = Convert.ToInt32(ddlVendor.SelectedValue); sale.InvoiceNumber = txtSONo.Text; sale.sale_date = DateTime.Parse(txtdate.Text, new CultureInfo("en-US")); sale.created_by = User_id; sale.created_date = DateTime.Now; sale.Note = txtSaleNote.Text; //sale.OtherExpLabel = txtOtherExpLabel.Text; //sale.other_expenses = Convert.ToDecimal(txtotherexpence.Text); //insert into Sale Payment Details tbl_SalePaymentDetails salePaymentDetails = new tbl_SalePaymentDetails(); salePaymentDetails.TaxAmount = Convert.ToDecimal(lblTaxAmount.Text); salePaymentDetails.SubTotal = Convert.ToDecimal(lblsubtotal.Text); salePaymentDetails.GrandTotal = Convert.ToDecimal(lblGrandTotal.Text); salePaymentDetails.PaidAmnt = paidAmnt; salePaymentDetails.GivenAmnt = paidAmnt; salePaymentDetails.BalanceAmnt = balanceAmt; salePaymentDetails.FromTable = "Sale"; salePaymentDetails.CreatedBy = User_id; salePaymentDetails.CreatedDate = DateTime.Now; salePaymentDetails.OtherExpLabel = txtOtherExpLabel.Text; salePaymentDetails.OtherExp = Convert.ToDecimal(txtotherexpence.Text); //string otherExp = txtotherexpence.Text; //if (otherExp.Contains("-")) //{ // var calculatedDiscount = Convert.ToDecimal(lblDiscountAmt.Text); // var overAllDisc = Convert.ToDecimal(otherExp.Substring(otherExp.LastIndexOf('-') + 0)); // var totalDiscount = calculatedDiscount - overAllDisc; // salePaymentDetails.DiscountAmount = totalDiscount; //} //else //{ // salePaymentDetails.DiscountAmount = Convert.ToDecimal(lblDiscountAmt.Text); //} salePaymentDetails.DiscountAmount = Convert.ToDecimal(lblDiscountAmt.Text); sale.tbl_SalePaymentDetails.Add(salePaymentDetails); for (int i = 0; i <= gvSalesdetails.Rows.Count - 1; i++) { int productId = Convert.ToInt32(gvSalesdetails.Rows[i].Cells[3].Text); int batchId = Convert.ToInt32(gvSalesdetails.Rows[i].Cells[8].Text); decimal qty = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[4].Text); tbl_product product = context.tbl_product.Where(w => w.product_id == productId).FirstOrDefault(); //Add into sale Details table for each product tbl_saledetails saleDetails = new tbl_saledetails(); saleDetails.product_id = productId; saleDetails.batch_id = batchId; saleDetails.unit_id = product.unit_id; saleDetails.tax_amt = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[10].Text); saleDetails.dicount_amt = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[7].Text); saleDetails.quantity = qty; saleDetails.amount = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[11].Text); saleDetails.created_by = Convert.ToString(User_id); saleDetails.created_date = Convert.ToDateTime(DateTime.Now); saleDetails.status = true; int groupId = Convert.ToInt32(gvSalesdetails.Rows[i].Cells[12].Text); //var PurchasegroupId = Convert.ToInt32(gvSalesdetails.Rows[i].Cells[10].Text); DataTable taxgroupTypes1 = helper.LINQToDataTable(context.SelectPurcahseProductTaxGroup(batchId, productId, qty, groupId)); ViewState["TotalTaxPercent"] = null; for (int j = 0; j <= taxgroupTypes1.Rows.Count - 1; j++) { ViewState["TotalTaxPercent"] = taxgroupTypes1.Rows[j].Field <decimal>("totalTaxPercetage"); } //insert into tax group Sale tbl_saleTaxGroup saleTaxGroup = new tbl_saleTaxGroup(); saleTaxGroup.group_id = groupId; saleTaxGroup.product_id = productId; saleTaxGroup.totalTaxPercentage = (Decimal)ViewState["TotalTaxPercent"]; saleTaxGroup.group_name = gvSalesdetails.Rows[i].Cells[9].Text; sale.tbl_saleTaxGroup.Add(saleTaxGroup); //Get the Tax type saved from db //insert into tax group detailes for (int j = 0; j <= taxgroupTypes1.Rows.Count - 1; j++) { tbl_saleTaxGroupDetailes saleTaxDetails = new tbl_saleTaxGroupDetailes(); saleTaxDetails.type_id = taxgroupTypes1.Rows[j].Field <int>("type_id"); saleTaxDetails.tax_percentage = taxgroupTypes1.Rows[j].Field <decimal>("tax_percentage"); saleTaxGroup.tbl_saleTaxGroupDetailes.Add(saleTaxDetails); } //Enter Details In tbl_ActualsaleTaxAndPrice : to get the original Values at the time of sale Return tbl_ActualSalesTaxAndPrice actualSale = new tbl_ActualSalesTaxAndPrice(); actualSale.product_id = productId; actualSale.status = true; actualSale.discount_percent = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[6].Text); actualSale.sale_rate = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[5].Text); actualSale.discount_amnt = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[7].Text); actualSale.created_by = Convert.ToString(User_id); actualSale.created_date = Convert.ToDateTime(DateTime.Now); //Add into Actual sale Tax And Return Table sale.tbl_ActualSalesTaxAndPrice.Add(actualSale); //update the Stock against the product tbl_stock stock = new tbl_stock(); stock = context.tbl_stock.Where(w => w.company_id == companyId && w.branch_id == branchId && w.product_id == productId && w.batch_id == batchId).FirstOrDefault(); stock.qty = stock.qty - Convert.ToInt32(gvSalesdetails.Rows[i].Cells[4].Text); stock.modified_by = Convert.ToString(User_id); stock.modified_date = Convert.ToDateTime(DateTime.Now); sale.tbl_saledetails.Add(saleDetails); } context.tbl_sale.Add(sale); context.SaveChanges(); Session["sale_id"] = sale.sale_id; string order = sale.InvoiceNumber; ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('Saved successfully, Your order number is " + order + "');", true); } catch (Exception ex) { ErrorLog.saveerror(ex); } }
protected void Save() { try { tbl_sale sale = new tbl_sale(); sale.company_id = companyId; sale.branch_id = branchId; sale.financialyear_id = financialYearId; sale.paymentmode_id = Convert.ToInt32(ddlPaymentMode.SelectedValue); sale.status = true; sale.party_id = Convert.ToInt32(ddlVendor.SelectedValue); sale.InvoiceNumber = txtSONo.Text; sale.sale_date = DateTime.Parse(txtdate.Text, new CultureInfo("en-US")); sale.created_by = User_id; sale.created_date = DateTime.Now; //insert into Sale Payment Details tbl_SalePaymentDetails salePaymentDetails = new tbl_SalePaymentDetails(); salePaymentDetails.TaxAmount = Convert.ToDecimal(lblTaxAmount.Text); salePaymentDetails.DiscountAmount = Convert.ToDecimal(lblDiscountAmt.Text); salePaymentDetails.SubTotal = Convert.ToDecimal(lblsubtotal.Text); salePaymentDetails.GrandTotal = Convert.ToDecimal(lblGrandTotal.Text); salePaymentDetails.PaidAmnt = Convert.ToDecimal(txtGivenAmt.Text); salePaymentDetails.GivenAmnt = Convert.ToDecimal(txtGivenAmt.Text); salePaymentDetails.BalanceAmnt = Convert.ToDecimal(txtBalanceAmt.Text); salePaymentDetails.FromTable = "Sale"; sale.tbl_SalePaymentDetails.Add(salePaymentDetails); for (int i = 0; i <= gvSalesdetails.Rows.Count - 1; i++) { int productId = Convert.ToInt32(gvSalesdetails.Rows[i].Cells[3].Text); int batchId = Convert.ToInt32(gvSalesdetails.Rows[i].Cells[11].Text); tbl_product product = context.tbl_product.Where(w => w.product_id == productId).FirstOrDefault(); //Add into sale Details table for each product tbl_saledetails saleDetails = new tbl_saledetails(); saleDetails.product_id = productId; saleDetails.batch_id = batchId; saleDetails.tax_id = product.tax_id; saleDetails.unit_id = product.unit_id; saleDetails.tax_amt = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[9].Text); saleDetails.dicount_amt = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[7].Text); saleDetails.quantity = Convert.ToInt32(gvSalesdetails.Rows[i].Cells[4].Text); saleDetails.amount = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[10].Text); saleDetails.created_by = Convert.ToString(User_id); saleDetails.created_date = Convert.ToDateTime(DateTime.Now); saleDetails.status = true; //Enter Details In tbl_ActualsaleTaxAndPrice : to get the original Values at the time of sale Return tbl_ActualSalesTaxAndPrice actualSale = new tbl_ActualSalesTaxAndPrice(); actualSale.product_id = productId; actualSale.status = true; actualSale.discount_percent = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[6].Text); actualSale.tax_percent = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[8].Text); actualSale.sale_rate = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[5].Text); actualSale.discount_amnt = Convert.ToDecimal(gvSalesdetails.Rows[i].Cells[7].Text); actualSale.created_by = Convert.ToString(User_id); actualSale.created_date = Convert.ToDateTime(DateTime.Now); //Add into Actual sale Tax And Return Table sale.tbl_ActualSalesTaxAndPrice.Add(actualSale); //update the Stock against the product tbl_stock stock = new tbl_stock(); stock = context.tbl_stock.Where(w => w.company_id == companyId && w.branch_id == branchId && w.product_id == productId && w.batch_id == batchId).FirstOrDefault(); stock.qty = stock.qty - Convert.ToInt32(gvSalesdetails.Rows[i].Cells[4].Text); stock.modified_by = Convert.ToString(User_id); stock.modified_date = Convert.ToDateTime(DateTime.Now); sale.tbl_saledetails.Add(saleDetails); } context.tbl_sale.Add(sale); context.SaveChanges(); Session["sale_id"] = sale.sale_id; string order = sale.InvoiceNumber; ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('Saved successfully, Your order number is " + order + "');", true); } catch (Exception ex) { ErrorLog.saveerror(ex); } }
private void savedcode() { try { if (hd.Value == "false") { if (hde.Value == "false") { Label1.Text = String.Empty; lblcheckDoubleError.Text = String.Empty; tbl_product product = new tbl_product(); product.company_id = companyId; product.branch_id = branchId; product.category_id = Int32.Parse(ddlCategory.SelectedValue); product.unit_id = Int32.Parse(ddlUnit.SelectedValue); product.godown_id = Int32.Parse(ddlGodown.SelectedValue); product.rack_id = Int32.Parse(ddlRack.SelectedValue); // product.tax_id = Int32.Parse(ddlTax.SelectedValue); product.product_name = txtProductName.Text; product.product_code = txtProductCode.Text; product.hsn_code = txtHSNCode.Text; product.reorder_level = Int32.Parse(txtReorderqty.Text); product.purchas_price = decimal.Parse(txtPurchasePrice.Text); product.sales_price = decimal.Parse(txtSalesPrice.Text); product.created_by = User_id; product.created_date = DateTime.Today; product.status = true; product.modified_by = ""; product.modified_date = null; ////Shakeeb ////pd.Insert(pd); //Entity Framework Saving Awais context.tbl_product.Add(product); context.SaveChanges(); clr(); divalert.Visible = true; lblAlert.Text = "Product Saved Successfully "; //context.tbl_product.Add(pd); //context.SaveChanges(); } else { divalert.Visible = false; lblcheckDoubleError.ForeColor = System.Drawing.Color.Red; lblcheckDoubleError.Text = "This Product Code name already Exists"; } } else { divalert.Visible = false; Label1.ForeColor = System.Drawing.Color.Red; Label1.Text = "This Product name already Exists"; } } catch (Exception ex) { ErrorLog.saveerror(ex); //Do Logging } }
protected void Save() { try { int purchaseId = Convert.ToInt32(hdnPurchaseId.Value); if (purchaseId == 0) { ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('Please Enter Purchase No','False');", true); return; } //Get Origianl Purchase Details tbl_purchase purchase = new tbl_purchase(); purchase = context.tbl_purchase.Where(pd => pd.purchase_id == purchaseId && pd.company_id == companyId && pd.branch_id == branchId).FirstOrDefault(); tbl_purchasereturn purchaseReturn = new tbl_purchasereturn(); purchaseReturn.purchase_id = purchaseId; purchaseReturn.company_id = companyId; purchaseReturn.branch_id = branchId; purchaseReturn.financialyear_id = financialYearId; purchaseReturn.InvoiceNumber = txtPoNo.Text; purchaseReturn.paymentmode_id = Convert.ToInt32(ddlPaymentMode.SelectedValue); purchaseReturn.status = true; purchaseReturn.party_id = Convert.ToInt32(purchase.party_id); purchaseReturn.created_by = user_id; purchaseReturn.created_date = DateTime.Now; //Update into Purchase Payment Details tbl_PurchasePaymentDetials purchasePaymentDetail = context.tbl_PurchasePaymentDetials.Where(w => w.PurchaseId == purchaseId).FirstOrDefault(); purchasePaymentDetail.PaidAmnt = Convert.ToDecimal(txtPaidAmt.Text); purchasePaymentDetail.GivenAmnt = Convert.ToDecimal(lblGivenAmnt.Text) - Convert.ToDecimal(txtPaidAmt.Text); purchasePaymentDetail.BalanceAmnt = Convert.ToDecimal(txtBalanceAmt.Text); purchasePaymentDetail.TaxAmount = Convert.ToDecimal(lblResultTotalTaxAmnt.Text); purchasePaymentDetail.DiscountAmount = Convert.ToDecimal(lblResultTotalDiscount.Text); purchasePaymentDetail.SubTotal = Convert.ToDecimal(lblResultSubTotal.Text); purchasePaymentDetail.GrandTotal = Convert.ToDecimal(lblResultGrndTotal.Text); purchasePaymentDetail.FromTable = "Return"; purchase.tbl_PurchasePaymentDetials.Add(purchasePaymentDetail); for (int i = 0; i <= gvpurchasedetails.Rows.Count - 1; i++) { int productId = Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[2].Text); int batchId = Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[4].Text); tbl_product product = context.tbl_product.Where(w => w.product_id == productId).FirstOrDefault(); tbl_purchasereturndetails purchaseReturnDetails = new tbl_purchasereturndetails(); purchaseReturnDetails.product_id = productId; purchaseReturnDetails.batch_id = batchId; purchaseReturnDetails.tax_id = product.tax_id; purchaseReturnDetails.unit_id = product.unit_id; purchaseReturnDetails.discount_amnt = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[7].Text); purchaseReturnDetails.tax_amt = gvpurchasedetails.Rows[i].Cells[9].Text; purchaseReturnDetails.quantity = Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[5].Text); purchaseReturnDetails.amount = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[10].Text); purchaseReturnDetails.created_by = Convert.ToString(user_id); purchaseReturnDetails.created_date = Convert.ToDateTime(DateTime.Now); purchaseReturnDetails.status = true; tbl_stock stock = new tbl_stock(); stock = context.tbl_stock.Where(w => w.company_id == companyId && w.branch_id == branchId && w.product_id == productId && w.batch_id == batchId).FirstOrDefault(); stock.qty = stock.qty - Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[5].Text); stock.modified_by = Convert.ToString(user_id); stock.modified_date = Convert.ToDateTime(DateTime.Now); purchaseReturn.tbl_purchasereturndetails.Add(purchaseReturnDetails); } context.tbl_purchasereturn.Add(purchaseReturn); context.SaveChanges(); string invoiceNumber = purchaseReturn.InvoiceNumber; ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('saved Successfully, You order number is " + invoiceNumber + "','True');", true); } catch (Exception ex) { ErrorLog.saveerror(ex); } }
//Methods------------------ protected void Save() { try { tbl_purchase purchase = new tbl_purchase(); purchase.company_id = companyId; purchase.branch_id = branchId; purchase.financialyear_id = financialYearId; purchase.InvoiceNumber = lblInvoice.Text; purchase.PaymentMode_id = Convert.ToInt32(ddlPaymentMode.SelectedValue); purchase.status = true; purchase.party_id = Convert.ToInt32(ddlVendor.SelectedValue); purchase.Po_Date = DateTime.Parse(txtdate.Text, new CultureInfo("en-US")); purchase.po_no = txtPONo.Text; purchase.created_by = user_id; purchase.created_date = DateTime.Now; //insert into Purchase Payment Details tbl_PurchasePaymentDetials purchasePaymentDetail = new tbl_PurchasePaymentDetials(); purchasePaymentDetail.TaxAmount = Convert.ToDecimal(lblTaxAmount.Text); purchasePaymentDetail.DiscountAmount = Convert.ToDecimal(lblDiscountAmt.Text); purchasePaymentDetail.SubTotal = Convert.ToDecimal(lblsubtotal.Text); purchasePaymentDetail.GrandTotal = Convert.ToDecimal(lblGrandTotal.Text); purchasePaymentDetail.PaidAmnt = Convert.ToDecimal(txtPaidAmt.Text); purchasePaymentDetail.GivenAmnt = Convert.ToDecimal(txtPaidAmt.Text); purchasePaymentDetail.BalanceAmnt = Convert.ToDecimal(txtBalanceAmt.Text); purchasePaymentDetail.FromTable = "Purchase"; purchase.tbl_PurchasePaymentDetials.Add(purchasePaymentDetail); for (int i = 0; i <= gvpurchasedetails.Rows.Count - 1; i++) { int productId = Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[2].Text); int batchId = Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[4].Text); tbl_product product = context.tbl_product.Where(w => w.product_id == productId).FirstOrDefault(); //Add into Purchase Details table for each product tbl_purchasedetails purchaseDetails = new tbl_purchasedetails(); purchaseDetails.product_id = productId; purchaseDetails.batch_id = batchId; purchaseDetails.tax_id = product.tax_id; purchaseDetails.unit_id = product.unit_id; purchaseDetails.tax_amt = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[11].Text); purchaseDetails.dicount_amt = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[9].Text); purchaseDetails.quantity = Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[5].Text); purchaseDetails.amount = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[12].Text); purchaseDetails.created_by = Convert.ToString(user_id); purchaseDetails.created_date = DateTime.Now; purchaseDetails.status = true; //Enter Details In tbl_ActualPurchaseTaxAndPrice : to get the original Values at the time of Purchase Return tbl_ActualPurchaseTaxAndPrice actualPurchase = new tbl_ActualPurchaseTaxAndPrice(); actualPurchase.product_id = productId; actualPurchase.status = true; actualPurchase.tax_percent = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[10].Text); actualPurchase.purchase_rate = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[6].Text); actualPurchase.discount_percent = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[8].Text); actualPurchase.discount_amnt = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[9].Text); actualPurchase.batch_id = batchId; actualPurchase.sale_price = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[7].Text); actualPurchase.created_by = Convert.ToString(user_id); actualPurchase.created_date = DateTime.Now; //Add into Actual Purchase Tax And Return Table purchase.tbl_ActualPurchaseTaxAndPrice.Add(actualPurchase); //Add Stock if not exist or update the Stock against the product tbl_stock stock = new tbl_stock(); if (!IsProductStockExists(companyId, branchId, productId, batchId)) { stock.company_id = companyId; stock.branch_id = branchId; stock.product_id = productId; stock.batch_id = batchId; stock.qty = Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[5].Text); stock.status = true; stock.created_by = Convert.ToString(user_id); stock.created_date = DateTime.Now; context.tbl_stock.Add(stock); } else { stock = context.tbl_stock.Where(w => w.company_id == companyId && w.branch_id == branchId && w.product_id == productId && w.batch_id == batchId).FirstOrDefault(); stock.qty = stock.qty + Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[5].Text); stock.modified_by = Convert.ToString(user_id); stock.modified_date = DateTime.Now; } purchase.tbl_purchasedetails.Add(purchaseDetails); } context.tbl_purchase.Add(purchase); context.SaveChanges(); string order = purchase.InvoiceNumber; Session["p_id"] = purchase.purchase_id; ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('Saved successfully, Your order number is " + order + "');", true); } catch (Exception ex) { ErrorLog.saveerror(ex); } }
//Methods------------------ protected void Save() { try { //added by ather for file attachment url string path = "~/Uploads/AttachedFiles/Purchase/"; //path without filename to save file bool fileupMsg = uploadFile(fuAttacheFile, path, ""); decimal balanceAmt = 0; // Convert.ToDecimal(txtBalanceAmt.Text); decimal paidAmnt = 0; if (!string.IsNullOrEmpty(txtPaidAmt.Text)) { paidAmnt = Convert.ToDecimal(txtPaidAmt.Text); } if (!string.IsNullOrEmpty(txtBalanceAmt.Text)) { balanceAmt = Convert.ToDecimal(txtBalanceAmt.Text); } tbl_purchase purchase = new tbl_purchase(); if (fileupMsg) { path = path + Path.GetFileName(fuAttacheFile.PostedFile.FileName); //path with filename to save in DB purchase.attachmentUrl = path; } purchase.company_id = companyId; purchase.branch_id = branchId; purchase.financialyear_id = financialYearId; purchase.InvoiceNumber = lblInvoice.Text; purchase.PaymentMode_id = Convert.ToInt32(ddlPaymentMode.SelectedValue); purchase.status = true; purchase.party_id = Convert.ToInt32(ddlVendor.SelectedValue); purchase.Po_Date = DateTime.ParseExact(txtdate.Text, "dd/MM/yyyy", new CultureInfo("en-US")); purchase.po_no = txtPONo.Text; purchase.Note = txtNotePurchase.Text; purchase.OtherExpLabel = txtOtherExpLabel.Text; purchase.other_expenses = Convert.ToDecimal(txtotherexpence.Text); purchase.created_by = user_id; purchase.created_date = DateTime.Now; //insert into Purchase Payment Details tbl_PurchasePaymentDetials purchasePaymentDetail = new tbl_PurchasePaymentDetials(); purchasePaymentDetail.TaxAmount = Convert.ToDecimal(lblTaxAmount.Text); purchasePaymentDetail.DiscountAmount = Convert.ToDecimal(lblDiscountAmt.Text); purchasePaymentDetail.SubTotal = Convert.ToDecimal(lblsubtotal.Text); purchasePaymentDetail.GrandTotal = Convert.ToDecimal(lblGrandTotal.Text); purchasePaymentDetail.PaidAmnt = paidAmnt; purchasePaymentDetail.GivenAmnt = paidAmnt; purchasePaymentDetail.BalanceAmnt = balanceAmt; purchasePaymentDetail.CreatedDate = DateTime.Now; purchasePaymentDetail.CreatedBy = user_id; purchasePaymentDetail.FromTable = "Purchase"; purchasePaymentDetail.OtherExpLabel = txtOtherExpLabel.Text; purchasePaymentDetail.OtherExp = Convert.ToDecimal(txtotherexpence.Text); //string otherExp = txtotherexpence.Text; //if (otherExp.Contains("-")) //{ // var calculatedDiscount = Convert.ToDecimal(lblDiscountAmt.Text); // var overAllDisc = Convert.ToDecimal(otherExp.Substring(otherExp.LastIndexOf('-') + 0)); // var totalDiscount = calculatedDiscount - overAllDisc; // purchasePaymentDetail.DiscountAmount = totalDiscount; //} //else //{ // purchasePaymentDetail.DiscountAmount = Convert.ToDecimal(lblDiscountAmt.Text); //} purchasePaymentDetail.DiscountAmount = Convert.ToDecimal(lblDiscountAmt.Text); purchase.tbl_PurchasePaymentDetials.Add(purchasePaymentDetail); for (int i = 0; i <= gvpurchasedetails.Rows.Count - 1; i++) { int productId = Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[2].Text); int batchId = Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[4].Text); tbl_product product = context.tbl_product.Where(w => w.product_id == productId).FirstOrDefault(); var qty = Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[5].Text); //Add into Purchase Details table for each product tbl_purchasedetails purchaseDetails = new tbl_purchasedetails(); purchaseDetails.product_id = productId; purchaseDetails.batch_id = batchId; // purchaseDetails.tax_id = product.tax_id; purchaseDetails.unit_id = product.unit_id; purchaseDetails.tax_amt = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[13].Text); purchaseDetails.dicount_amt = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[9].Text); purchaseDetails.quantity = qty; purchaseDetails.amount = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[14].Text); purchaseDetails.created_by = Convert.ToString(user_id); purchaseDetails.created_date = DateTime.Now; purchaseDetails.status = true; var groupId = Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[10].Text); DataTable taxgroupTypes = helper.LINQToDataTable(context.SelectProductTaxGroup(groupId, productId, qty)); ViewState["TotalTaxPercent"] = null; for (int j = 0; j <= taxgroupTypes.Rows.Count - 1; j++) { ViewState["TotalTaxPercent"] = taxgroupTypes.Rows[j].Field <decimal>("totalTaxPercetage"); } //insert into tax group purchase tbl_purchasetaxgroup purchaseTaxGroup = new tbl_purchasetaxgroup(); purchaseTaxGroup.group_id = groupId; purchaseTaxGroup.product_id = productId; purchaseTaxGroup.batchId = batchId; purchaseTaxGroup.totalTaxPercentage = (Decimal)ViewState["TotalTaxPercent"]; purchaseTaxGroup.group_name = gvpurchasedetails.Rows[i].Cells[11].Text; //Get the Tax type saved from db //insert into tax group detailes // var taxGroupTypes = context.tbl_productTaxGroup.Join(context.tbl_taxgroup, t => t.group_id, pt => pt.group_id, (t, pt) => new { t.group_id, pt.group_name, t.product_id }).Where(t => t.product_id == productId).ToList(); for (int j = 0; j <= taxgroupTypes.Rows.Count - 1; j++) { tbl_purchasetaxgroupdetails purchaseTaxDetails = new tbl_purchasetaxgroupdetails(); purchaseTaxDetails.type_id = taxgroupTypes.Rows[j].Field <int>("type_id"); purchaseTaxDetails.tax_percentage = taxgroupTypes.Rows[j].Field <decimal>("tax_percentage"); purchaseTaxGroup.tbl_purchasetaxgroupdetails.Add(purchaseTaxDetails); } purchase.tbl_purchasetaxgroup.Add(purchaseTaxGroup); //Enter Details In tbl_ActualPurchaseTaxAndPrice : to get the original Values at the time of Purchase Return tbl_ActualPurchaseTaxAndPrice actualPurchase = new tbl_ActualPurchaseTaxAndPrice(); actualPurchase.product_id = productId; actualPurchase.status = true; //actualPurchase.tax_percent = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[10].Text); actualPurchase.purchase_rate = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[6].Text); actualPurchase.discount_percent = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[8].Text); actualPurchase.discount_amnt = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[9].Text); actualPurchase.batch_id = batchId; actualPurchase.sale_price = Convert.ToDecimal(gvpurchasedetails.Rows[i].Cells[7].Text); actualPurchase.created_by = Convert.ToString(user_id); actualPurchase.created_date = DateTime.Now; //Add into Actual Purchase Tax And Return Table purchase.tbl_ActualPurchaseTaxAndPrice.Add(actualPurchase); //Add Stock if not exist or update the Stock against the product tbl_stock stock = new tbl_stock(); if (!IsProductStockExists(companyId, branchId, productId, batchId)) { stock.company_id = companyId; stock.branch_id = branchId; stock.product_id = productId; stock.batch_id = batchId; stock.qty = Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[5].Text); stock.status = true; stock.created_by = Convert.ToString(user_id); stock.created_date = DateTime.Now; context.tbl_stock.Add(stock); } else { stock = context.tbl_stock.Where(w => w.company_id == companyId && w.branch_id == branchId && w.product_id == productId && w.batch_id == batchId).FirstOrDefault(); stock.qty = stock.qty + Convert.ToInt32(gvpurchasedetails.Rows[i].Cells[5].Text); stock.modified_by = Convert.ToString(user_id); stock.modified_date = DateTime.Now; } purchase.tbl_purchasedetails.Add(purchaseDetails); } context.tbl_purchase.Add(purchase); context.SaveChanges(); string order = purchase.InvoiceNumber; Session["p_id"] = purchase.purchase_id; ClientScript.RegisterStartupScript(this.GetType(), "Pop", "openalert('Saved successfully, Your order number is " + order + "');", true); } catch (Exception ex) { ErrorLog.saveerror(ex); } }