Ejemplo n.º 1
0
        private void btnADD_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Payed_ = Convert.ToDecimal(this.txtToPay.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Error:  Payed Quantyty is not numeric. Please, review entered data.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                goto ExitMethod;
            }

            EntitiesClass.InvoiceDet a = new EntitiesClass.InvoiceDet();
            if (LoadDetailsData(ref a))
            {
                InvDet.Add(a);

                var qry = from i in InvDet
                          select new { Wh       = i.WhID, i.WhName, Prod = i.ProdNo, Name = i.ProdName, i.Units,
                                       Price    = i.ProdPrice, UwOff = i.UnitsWithOffers, NewPrice = i.ProdNewPrice,
                                       Sales    = Math.Round(i.TotalSales, 2), Discount = Math.Round(i.Discount, 2),
                                       SalesTax = Math.Round(i.SalesTax, 2) };


                dtgridDetails.AutoGenerateColumns = true;
                dtgridDetails.ItemsSource         = qry;
                dtgridDetails.Items.Refresh();
                ResetInvoiceDetailToBeAdded();

                decimal SummarySales = 0; decimal SummarySalesTax = 0; decimal SummaryPendingPayment = 0;


                foreach (var item in InvDet)
                {
                    SummarySales          = SummarySales + item.TotalSales;
                    SummarySalesTax       = SummarySalesTax + item.SalesTax;
                    SummaryPendingPayment = (SummarySales + SummarySalesTax) - Payed_;
                }

                this.txtSales.Text          = string.Format("{0:C}", SummarySales);
                this.txtSalesTax.Text       = string.Format("{0:C}", SummarySalesTax);
                this.txtPendingPayment.Text = string.Format("{0:C}", SummaryPendingPayment);
            }

            ExitMethod :;
        }
Ejemplo n.º 2
0
        //Add details of Invoice and verify if can be added; Developer: Dennis Vélez ; Date: 06-30-18
        private bool LoadDetailsData(ref EntitiesClass.InvoiceDet a)
        {
            ProdName = cmbProd.Text; WhName = cmbWH.Text;


            try
            {
                try
                {
                    NewPrice          = Convert.ToDecimal(this.txtNewPrice.Text);
                    Price             = Convert.ToDecimal(this.txtPrice.Text);
                    a.Units           = Convert.ToDecimal(txtUnits.Text);
                    a.UnitsWithOffers = Convert.ToDecimal(txtOffUnits.Text);
                    a.TotalUnits      = a.Units + a.UnitsWithOffers;
                }
                catch (Exception)
                {
                    MessageBox.Show("Error: Some value entered is not numeric. Please, review entered data.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }



                if (qty < (a.Units + a.UnitsWithOffers))
                {
                    MessageBox.Show("Error: There are not enough products in the warehouse! ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }

                if (!(a.UnitsWithOffers == 0))
                {
                    if (NewPrice > Price)
                    {
                        MessageBox.Show("Error: New Price is greater than the Product Price! ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return(false);
                    }
                }

                a.ProdNo = ProdNo; a.WhID = WhID; a.ProdPrice = Price; a.ProdNewPrice = NewPrice;

                if (ReviewIfDetailsWasAdded(WhID, ProdNo))
                {
                    MessageBox.Show("Error: A product was added previously from the same warehouse! ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }

                a.Sales    = a.Units * Price; a.SalesWithOffers = a.UnitsWithOffers * NewPrice; a.TotalSales = a.Sales + a.SalesWithOffers;
                a.Discount = (a.UnitsWithOffers * Price); a.Discount = a.Discount - a.SalesWithOffers;
                a.ProdName = ProdName; a.WhName = WhName; a.IVU = Ivu;

                try { a.SalesTax = a.TotalSales * (Ivu / 100); }
                catch (Exception) { a.SalesTax = 0; }

                return(true);
            }
            catch (Exception)
            {
                MessageBox.Show("Error: Please, fill all information with the correct Data type! ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }