Esempio n. 1
0
        public void OpenForm_ViewBill()
        {
            m_UIControl.lbl_errorAmountPaid.Text = string.Empty;
            if (m_UIControl.Bill_ProductsDataView.Rows.Count <= 0)
            {
                return;
            }

            if (string.IsNullOrEmpty(m_UIControl.tb_amountPaid.Text))
            {
                m_UIControl.lbl_errorAmountPaid.Text = "Please enter amount paid";
                return;
            }
            if (!Validator.IsValidDouble(m_UIControl.tb_amountPaid.Text.Trim()))
            {
                m_UIControl.lbl_errorAmountPaid.Text = "Enter valid amount!";
                return;
            }

            double amountPaid    = double.Parse(m_UIControl.tb_amountPaid.Text);
            double amountDue     = double.Parse(m_UIControl.tb_amountDue.Text);
            double pendingAmount = 0.0;

            if (amountDue != amountPaid)
            {
                var customer = m_transactionSession.GetCustomer();
                if (customer == null || customer.ID == 0)
                {
                    m_UIControl.lbl_errorAmountPaid.Text = "Please add customer details";
                    return;
                }
            }

            pendingAmount = amountDue - amountPaid;

            m_transactionSession.pendingAmount = pendingAmount.ToString();
            m_transactionSession.amountPaid    = amountPaid.ToString();

            Form_ViewBill viewBill = new Form_ViewBill(m_transactionSession);
            var           result   = viewBill.ShowDialog();

            if (result == DialogResult.Yes)
            {
                DialogResult dialogResult = MessageBox.Show("Do you want to print bill?", "Transaction successful !", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                }
                ResetTransaction();
            }
        }
        public void SaveTransaction()
        {
            TransactionPost transactionPost = new TransactionPost
            {
                CustomerID          = m_TransactionSession.GetCustomer().ID,
                TransactionDateTime = DateTime.Now,
                TotalPrice          = double.Parse(m_TransactionSession.amountDue),
                TotalTax            = double.Parse(m_TransactionSession.totalTax)
            };
            string productIds      = string.Empty;
            string productQuantity = string.Empty;
            string buyingPrices    = string.Empty;
            string discounts       = string.Empty;

            foreach (var entry in m_TransactionSession.GetRowEntries())
            {
                var product = entry.Product;
                productIds      += product.ID + ",";
                productQuantity += entry.Quantity + ",";
                buyingPrices    += product.RetailPrice + ",";
                discounts       += product.Discount + ",";
            }

            //Removing last comma
            transactionPost.ProductIDs      = productIds.Substring(0, productIds.Length - 1);
            transactionPost.ProductQuantity = productQuantity.Substring(0, productQuantity.Length - 1);
            transactionPost.BuyingPrices    = buyingPrices.Substring(0, buyingPrices.Length - 1);
            transactionPost.Discounts       = discounts.Substring(0, discounts.Length - 1);

            var transaction = DataService.GetTransactionDataController().Post(transactionPost);

            UpdateCustomerDetails();
            UpdateStockDetails();

            // fire new transaction added event
            Event_NewEntryAdded e = new Event_NewEntryAdded(DBEntityType.TRANSACTION, transaction.ID);

            EventBroadcaster.Get().BroadcastEvent(e);
        }