Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
 private decimal CalculateTax(decimal totalSaleSubTotal, decimal taxAmt)
 {
     return(Math.Round(totalSaleSubTotal, 2) + _sale.CalculateTax(totalSaleSubTotal, taxAmt));
 }