示例#1
0
        private void UpdateProductRowInTable(DataGridViewRow row, BillProductDetails productDetails)
        {
            var product = productDetails.Product;

            var  checkBoxCell      = row.Cells["BillTable_useWholeSalePrice"] as DataGridViewCheckBoxCell;
            bool useWholeSalePrice = checkBoxCell.Value != null && (bool)checkBoxCell.Value;

            double productPrice = useWholeSalePrice ? product.WholeSalePrice : product.RetailPrice;

            var newQuantity = Convert.ToInt32(row.Cells["BillTable_Quantity"].Value) + 1; // add 1 to the existing quantity

            row.Cells["BillTable_Quantity"].Value = newQuantity;
            productDetails.Quantity = newQuantity;

            double discount = (productPrice * product.Discount / 100);

            row.Cells["BillTable_Discount"].Value = discount * newQuantity;

            var totalTax = CalculateTotalTax(productPrice, product.CGST, product.SGST, productDetails.Quantity);

            row.Cells["BillTable_Tax"].Value = totalTax;

            double finalPrice = CalculateFinalPrice(productPrice, product.Discount, newQuantity, totalTax);

            row.Cells["BillTable_FinalPrice"].Value = finalPrice;
            productDetails.FinalPrice = finalPrice;

            m_transactionSession.AddRowEntry(productDetails);
        }
示例#2
0
        public void OnAddProduct(BillProductDetails productDetails)
        {
            if (!IsStockAvailable(productDetails))
            {
                DialogResult dialogResult = MessageBox.Show("Not Enough Stock Available? Do you still want to add", "Transaction successful !", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.No)
                {
                    return;
                }
            }

            // check if this product is already added
            var             product = productDetails.Product;
            DataGridViewRow row     = CheckIfProductExistInTable(product.ID);

            if (row != null)
            {
                UpdateProductRowInTable(row, productDetails);
            }
            else
            {
                AddProductRowToTable(productDetails);
            }

            UpdateUILabels();
        }
示例#3
0
        public void AddProductRowToTable(BillProductDetails productDetails)
        {
            var GridView = m_UIControl.Bill_ProductsDataView;
            var product  = productDetails.Product;

            int Index = GridView.Rows.Add();

            DataGridViewRow newRow = GridView.Rows[Index];

            newRow.Cells["BillTable_ProductId"].Value = product.ID;
            newRow.Cells["BillTable_Name"].Value      = product.Name;

            newRow.Cells["BillTable_Price"].Value = product.RetailPrice;
            double discountInRupees = (product.RetailPrice * product.Discount / 100);

            newRow.Cells["BillTable_Discount"].Value = discountInRupees * productDetails.Quantity;
            newRow.Cells["BillTable_Quantity"].Value = productDetails.Quantity;

            var tax = CalculateTotalTax(product.RetailPrice, product.CGST, product.SGST, productDetails.Quantity);

            newRow.Cells["BillTable_Tax"].Value = tax;

            int    priceToUse    = product.RetailPrice;
            double newFinalPrice = CalculateFinalPrice(priceToUse, product.Discount, productDetails.Quantity, tax);

            newRow.Cells["BillTable_FinalPrice"].Value = newFinalPrice;
            productDetails.FinalPrice = newFinalPrice;

            m_transactionSession.AddRowEntry(productDetails);
        }
示例#4
0
        public void UpdateBillProductsDataRow(bool useWholeSalePrice, bool checkStock)
        {
            if (m_UIControl.Bill_ProductsDataView.SelectedRows.Count <= 0)
            {
                return;
            }

            var currentRow = m_UIControl.Bill_ProductsDataView.CurrentRow;
            var productId  = Convert.ToInt32(currentRow.Cells["BillTable_ProductId"].Value);
            var productGet = DataService.GetProductDataController().Get(productId);

            double productPrice = useWholeSalePrice ? productGet.WholeSalePrice : productGet.RetailPrice;

            currentRow.Cells["BillTable_Price"].Value = productPrice;

            var newQuantity = currentRow.Cells["BillTable_Quantity"].Value.ToString();

            if (!Validator.IsInteger(newQuantity))
            {
                currentRow.Cells["BillTable_Quantity"].Value = m_transactionSession.GetRowEntry(productId).Quantity;
                return;
            }

            BillProductDetails productDetails = new BillProductDetails(productGet);

            productDetails.Quantity = Convert.ToInt32(currentRow.Cells["BillTable_Quantity"].Value);
            if (productDetails.Quantity == 0)
            {
                currentRow.Cells["BillTable_Quantity"].Value = m_transactionSession.GetRowEntry(productId).Quantity;
                return;
            }

            // check stock availability
            if (checkStock && !IsStockAvailable(productDetails))
            {
                DialogResult dialogResult = MessageBox.Show("Not Enough Stock Available? Do you still want to add?", "Transaction successful !", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.No)
                {
                    return;
                }
            }

            double discountInRupees = (productPrice * productGet.Discount / 100);

            currentRow.Cells["BillTable_Discount"].Value = discountInRupees * productDetails.Quantity;

            var tax = CalculateTotalTax(productPrice, productGet.CGST, productGet.SGST, productDetails.Quantity);

            currentRow.Cells["BillTable_Tax"].Value = tax;

            var finalPrice = CalculateFinalPrice(productPrice, productGet.Discount, productDetails.Quantity, tax);

            currentRow.Cells["BillTable_FinalPrice"].Value = finalPrice;
            productDetails.FinalPrice = finalPrice;

            m_transactionSession.UpdateRowEntry(productDetails);
            UpdateUILabels();
        }
        private void AddRowToViewBillTable(BillProductDetails productDetails)
        {
            var             product = productDetails.Product;
            var             Table   = GetViewBillTable();
            int             Index   = Table.Rows.Add();
            DataGridViewRow NewRow  = Table.Rows[Index];

            NewRow.Cells["ViewBillTable_ProductId"].Value   = product.ID;
            NewRow.Cells["ViewBillTable_ProductName"].Value = product.Name;
            NewRow.Cells["ViewBillTable_Quantity"].Value    = productDetails.Quantity;
            NewRow.Cells["ViewBillTable_FinalPrice"].Value  = productDetails.FinalPrice;
        }
示例#6
0
        private bool IsStockAvailable(BillProductDetails productDetails)
        {
            // check if stock is available
            int      productID = productDetails.Product.ID;
            StockGet stock     = DataService.GetStockDataController().GetByProductID(productID);

            if (stock.AvailableQuantity < productDetails.Quantity)
            {
                return(false);
            }
            return(true);
        }
示例#7
0
        public void UpdateRowEntry(BillProductDetails productDetails)
        {
            var product = productDetails.Product;

            foreach (var p in m_RowEntries)
            {
                if (p.Product.ID == product.ID)
                {
                    p.Quantity   = productDetails.Quantity;
                    p.FinalPrice = productDetails.FinalPrice;
                    return;
                }
            }
        }