protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var productId = Convert.ToInt32(Request.QueryString["id"].ToString()); var context = new NemisisBillingEntities(); var productObject = context.Products.Where(p => p.Id == productId).FirstOrDefault(); // setting the screens. if (productObject != null) { pId.Text = productObject.Id.ToString(); pName.Text = productObject.Name; pDescription.Text = productObject.Description; measure.Text = productObject.Measurements; pCostPrice.Text = productObject.CostPrice.ToString(); cgst.Text = productObject.CGST.ToString(); sgdt.Text = productObject.SGST.ToString(); pSellingPrice.Text = productObject.SellPrice.ToString(); } } }
protected void AddProductItem(object sender, EventArgs e) { var context = new NemisisBillingEntities(); var productPrefix = string.Empty; if (category.SelectedValue == "E") { productPrefix = "E-"; } else if (category.SelectedValue == "P") { productPrefix = "P-"; } var product = new Product { Name = productPrefix + pName.Text, Description = pDescription.Text, Quantity = Convert.ToInt32(pQuantity.Text), SellPrice = Convert.ToDecimal(pSellingPrice.Text), CostPrice = Convert.ToDecimal(pCostPrice.Text), SGST = Convert.ToDecimal(sgdt.Text), CGST = Convert.ToDecimal(cgst.Text), Measurements = measure.Text, }; context.Products.AddObject(product); context.SaveChanges(); Response.Redirect("ProductCreated.aspx?id=" + product.Id); }
protected void AddProductItem(object sender, EventArgs e) { var context = new NemisisBillingEntities(); var productId = Convert.ToInt32(pId.Text); var productObject = context.Products.Where(p => p.Id == productId).FirstOrDefault(); productObject.Name = pName.Text; productObject.Description = pDescription.Text; productObject.Quantity = Convert.ToInt32(pQuantity.Text); productObject.SellPrice = Convert.ToDecimal(pSellingPrice.Text); productObject.CostPrice = Convert.ToDecimal(pCostPrice.Text); productObject.SGST = Convert.ToDecimal(sgdt.Text); productObject.CGST = Convert.ToDecimal(cgst.Text); productObject.Measurements = measure.Text; productObject.PofitPercent = Convert.ToDecimal(profit.Text); context.SaveChanges(); Response.Redirect("Products.aspx"); }
protected void P(object sender, EventArgs e) { // create customer model //create InvoiceItems // create customerInvoice // map customerInvoice and InvoiceItems // Create Customer var customer = new Customer { Name = cName.Text, Address = cAddress.Text, MobileNumber = cContactNo.Text, }; var context = new NemisisBillingEntities(); context.Customers.AddObject(customer); context.SaveChanges(); // get auto generated customerId // Create InvoiceItems List <InvoiceItem> invoiceItemsList = new List <InvoiceItem>(); TextBox NetDiscountAmount = (TextBox)GridView1.FooterRow.Cells[1].FindControl("fDiscountedAmount"); TextBox NetAmountAfterDiscount = (TextBox)GridView1.FooterRow.Cells[1].FindControl("beforeDiscount"); Label NetTaxAmount = (Label)GridView1.FooterRow.Cells[1].FindControl("NetTaxAmount"); TextBox NetFinalPrice = (TextBox)GridView1.FooterRow.Cells[1].FindControl("fAmount"); // pull records from GridView if (ViewState["currentTable"] != null) { // var dataTable = GridView1.Rows[0].Cells[2].ToString(); // refresh calculation DataTable currentTable = (DataTable)ViewState["currentTable"]; for (var i = 0; i < currentTable.Rows.Count; i++) { TextBox pName = (TextBox)GridView1.Rows[i].Cells[1].FindControl("ProductName"); TextBox cPrice = (TextBox)GridView1.Rows[i].Cells[1].FindControl("CostPrice"); TextBox sPrice = (TextBox)GridView1.Rows[i].Cells[1].FindControl("SellPrice"); TextBox quantity = (TextBox)GridView1.Rows[i].Cells[1].FindControl("Quantity");; TextBox measurements = (TextBox)GridView1.Rows[i].Cells[1].FindControl("Measurements"); TextBox discountAmount = (TextBox)GridView1.Rows[i].Cells[1].FindControl("DiscountAmount"); TextBox amountAfterDiscount = (TextBox)GridView1.Rows[i].Cells[1].FindControl("amountAfterDiscount"); TextBox taxAmount = (TextBox)GridView1.Rows[i].Cells[1].FindControl("TaxAmount"); TextBox FinalPrice = (TextBox)GridView1.Rows[i].Cells[1].FindControl("FinalPrice"); var invoiceItem = new InvoiceItem { Name = pName.Text, ProductId = Convert.ToInt32(currentTable.Rows[i]["ProductId"]), Quantity = Convert.ToInt32(quantity.Text), SellPrice = Convert.ToDecimal(sPrice.Text), TotalDiscount = Convert.ToDecimal(discountAmount.Text), TotalTaxAmount = Convert.ToDecimal(taxAmount.Text), TotalAmountAfterDiscount = Convert.ToDecimal(amountAfterDiscount.Text), TotalCalculatedAmount = Convert.ToDecimal(FinalPrice.Text), Measurement = measurements.Text, }; invoiceItemsList.Add(invoiceItem); } } foreach (var invoice in invoiceItemsList) { context.InvoiceItems.AddObject(invoice); } context.SaveChanges(); // build customerInvoice - holds total sum details of InVoice var customerInVoice = new CustomerInvoice { CustomerId = customer.Id, DateOfCreation = DateTime.Now, TotalAmountPaidByCustomer = Convert.ToDecimal(NetFinalPrice.Text), TotalAmountWithoutTax = Convert.ToDecimal(NetAmountAfterDiscount.Text), TotalDiscountInAmount = Convert.ToDecimal(NetDiscountAmount.Text), TotalTaxAmount = Convert.ToDecimal(NetTaxAmount.Text), }; context.CustomerInvoices.AddObject(customerInVoice); context.SaveChanges(); customerInVoice.InvoiceTIN = "IN" + customerInVoice.Id.ToString(); context.SaveChanges(); // map customerInvoice and InvoiceItems var customerAndCustomerInvoiceItems = new List <CustomerInVoiceAndInVoiceItem>(); foreach (var invoiceItem in invoiceItemsList) { customerAndCustomerInvoiceItems.Add( new CustomerInVoiceAndInVoiceItem { CustomerInvoiceId = customerInVoice.Id, InvoiceItemsId = invoiceItem.Id, } ); } foreach (var mappingObj in customerAndCustomerInvoiceItems) { context.CustomerInVoiceAndInVoiceItems.AddObject(mappingObj); } context.SaveChanges(); Response.Redirect("ViewInvoice.aspx?invoiceId=" + customerInVoice.InvoiceTIN); }
public SalesService() { this.context = new NemisisBillingEntities(); }
protected void Page_Load(object sender, EventArgs e) { var invoiceTin = Request.QueryString["invoiceId"]; if (invoiceTin == null) { // no invoice tin return; } var context = new NemisisBillingEntities(); var getCustomerInvoice = context.CustomerInvoices .Where(ci => ci.InvoiceTIN.ToLower().Trim() == invoiceTin.ToLower().Trim()) .FirstOrDefault(); if (getCustomerInvoice == null) { // no invoice found for gien invoice id. return; } var customerAndInvoiceRefId = context.CustomerInVoiceAndInVoiceItems.Where(itemsRef => itemsRef.CustomerInvoiceId == getCustomerInvoice.Id).ToList(); var invoicedItems = new List <InvoiceItem>(); // load invoicedItems foreach (var invoiceRef in customerAndInvoiceRefId) { invoicedItems.Add(context.InvoiceItems.Where(i => i.Id == invoiceRef.InvoiceItemsId).FirstOrDefault()); } // Bind Cutomer info var customer = context.Customers.Where(c => c.Id == getCustomerInvoice.CustomerId).FirstOrDefault(); customerName.Text = customer.Name; customerAddress.Text = customer.Address; customerContact.Text = customer.MobileNumber; InvoiceTIN.Text = invoiceTin; var cultureInfo = CultureInfo.CurrentCulture; InvoiceDate.Text = getCustomerInvoice.DateOfCreation.GetValueOrDefault().ToString(cultureInfo); // build companyProfile var companyProfile = context.CompanyProfiles.FirstOrDefault(); // companyName.Text = companyProfile.CompanyName; //companyAddress.Text = companyProfile.Address; //companyContact.Text = companyProfile.ContactNumber; // build the data table and fill the grid view. DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("RowNumber", typeof(int))); dt.Columns.Add(new DataColumn("ItemId", typeof(int))); dt.Columns.Add(new DataColumn("Item", typeof(string))); dt.Columns.Add(new DataColumn("Qty", typeof(int))); dt.Columns.Add(new DataColumn("Measurements", typeof(string))); dt.Columns.Add(new DataColumn("TaxAmount", typeof(string))); dt.Columns.Add(new DataColumn("TotalAmount", typeof(string))); dt.Columns.Add(new DataColumn("DiscountAmount", typeof(string))); dt.Columns.Add(new DataColumn("NetRate", typeof(decimal))); dt.Columns.Add(new DataColumn("RatePerItem", typeof(decimal))); int counter = 0; foreach (var iItem in invoicedItems) { DataRow dr = null; dr = dt.NewRow(); dr["RowNumber"] = counter + 1; dr["ItemId"] = iItem.Id; dr["Item"] = iItem.Name; dr["Qty"] = iItem.Quantity; dr["Measurements"] = iItem.Measurement; dr["TaxAmount"] = Math.Round(iItem.TotalTaxAmount.GetValueOrDefault()).ToString("C"); dr["TotalAmount"] = Math.Round(iItem.TotalCalculatedAmount.GetValueOrDefault()).ToString("C"); dr["DiscountAmount"] = Math.Round(iItem.TotalDiscount.GetValueOrDefault()).ToString("C"); dr["NetRate"] = iItem.SellPrice * iItem.Quantity; // dislay net rate without any discount and tax dr["RatePerItem"] = iItem.SellPrice; dt.Rows.Add(dr); counter++; } DataRow footerRow = null; footerRow = dt.NewRow(); var amountBeforeDiscount = getCustomerInvoice.TotalAmountPaidByCustomer.GetValueOrDefault() + getCustomerInvoice.TotalDiscountInAmount.GetValueOrDefault(); var currencyCultureInfo = new CultureInfo("hi-IN"); if (getCustomerInvoice.TotalDiscountInAmount.GetValueOrDefault() != 0) { footerRow["TotalAmount"] = "<fieldset class='register'><p><label>Total Amount:</label>" + amountBeforeDiscount.ToString("C") + "</p>" + "<p><label>Discount: </label>" + getCustomerInvoice.TotalDiscountInAmount.GetValueOrDefault().ToString("C") + "</p>" + "<p><strong><label>Net Total: </label>" + getCustomerInvoice.TotalAmountPaidByCustomer.GetValueOrDefault().ToString("C") + "</strong></p></fieldset>"; } else { footerRow["TotalAmount"] = "<fieldset class='register'><p><strong><label>Net Total: </label>" + getCustomerInvoice.TotalAmountPaidByCustomer.GetValueOrDefault().ToString("C") + "</strong></p></fieldset>"; } // footerRow["NetRate"] = "Total"; dt.Rows.Add(footerRow); GridView1.DataSource = dt; GridView1.DataBind(); }
public ProductService() { this.context = new NemisisBillingEntities(); }