private void CalculateItemsCost() { decimal discount = 0; decimal subTotal = 0; decimal total = 0; decimal tax = 0; decimal saleSubTotal = 0; int lineItemQty = 0; decimal lineItemPrice = 0; if (gridViewItemLayout.Rows.Count > 0) { foreach (DataGridViewRow gr in gridViewItemLayout.Rows) { lineItemQty = int.Parse(gr.Cells[0].Value.ToString()); lineItemPrice = decimal.Parse(gr.Cells[3].Value.ToString()); discount = gr.Cells[4].Value.ToString() == "" ? 0 : (decimal.Parse(gr.Cells[4].Value.ToString())); tax = gr.Cells[5].Value.ToString() == "" ? 0 : decimal.Parse(gr.Cells[5].Value.ToString()); _sale.CalculateLineTotal(lineItemQty, lineItemPrice, tax, discount, out subTotal, out total); saleSubTotal += subTotal; } } decimal taxAmt = txtSalTax.Text == "" ? 0 : txtSalTax.Text.ToDecimal(); decimal discountamt = txtSaleDiscount.Text == "" ? 0 : txtSaleDiscount.Text.ToDecimal(); txtSubTotal.Text = Math.Round(saleSubTotal, 2).ToString(); txtTotalAmt.Text = (CalculateTax((saleSubTotal - discountamt), taxAmt)).ToString(); }
private void CalculateSaleCost() { try { decimal discount = 0; decimal subTotal = 0; decimal total = 0; decimal saleSubTotal = 0; int lineItemQty = 0; decimal lineItemPrice = 0; if (dgvOrderItems.Rows.Count > 0) { foreach (GridViewRowInfo gr in dgvOrderItems.Rows) { lineItemQty = int.Parse(gr.Cells[1].Value.ToString()); lineItemPrice = decimal.Parse(gr.Cells[2].Value.ToString()); discount = gr.Cells[3].Value.ToString() == "" ? 0 : (decimal.Parse(gr.Cells[3].Value.ToString())); _sale.CalculateLineTotal(lineItemQty, lineItemPrice, 0, discount, out subTotal, out total); saleSubTotal += subTotal; } } decimal discountamt = txtSaleDiscount.Text == "" ? 0 : txtSaleDiscount.Text.ToDecimal(); decimal calculatedTax = Math.Round(_sale.CalculateTax((saleSubTotal), _taxRate), 2); decimal totalAmount = (saleSubTotal + calculatedTax) - discountamt; txtSubTotal.Text = Math.Round(saleSubTotal, 2).ToString(); txtTax.Text = calculatedTax.ToString(); txtTotalAmt.Text = totalAmount.ToString(); } catch (Exception ex) { _logger.LogError(ex, "An error occurred", "ucSale", "CalculateItemsCost"); Helper.ShowMessage("An error occured " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CalculateItemsCost() { try { decimal discount = 0; decimal subTotal = 0; decimal total = 0; decimal saleSubTotal = 0; int lineItemQty = 0; decimal lineItemPrice = 0; if (gridViewItemLayout.Rows.Count > 0) { foreach (DataGridViewRow gr in gridViewItemLayout.Rows) { lineItemQty = int.Parse(gr.Cells[0].Value.ToString()); lineItemPrice = decimal.Parse(gr.Cells[3].Value.ToString()); discount = gr.Cells[4].Value.ToString() == "" ? 0 : (decimal.Parse(gr.Cells[4].Value.ToString())); _sale.CalculateLineTotal(lineItemQty, lineItemPrice, 0, discount, out subTotal, out total); saleSubTotal += subTotal; } } decimal taxAmt = txtSalTax.Text == "" ? 0 : txtSalTax.Text.ToDecimal(); decimal discountamt = txtSaleDiscount.Text == "" ? 0 : txtSaleDiscount.Text.ToDecimal(); txtSubTotal.Text = Math.Round(saleSubTotal, 2).ToString(); txtTotalAmt.Text = (Math.Round(CalculateTax((saleSubTotal - discountamt), taxAmt), 2)).ToString(); lblSaleTotalBig.Text = txtTotalAmt.Text.ToDecimal().ToString("0.00"); } catch (Exception ex) { _logger.LogError(ex, "An error occurred", "ucSale", "CalculateItemsCost"); Helper.ShowMessage("An error occured " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }