public void LoadFormObjects()
 {
     DateLabel.Text              = DateTime.Now.Date.ToShortDateString();
     currentSaleObject           = new SaleClass();
     currentSaleObject.SaleItems = new List <SaleItemClass>();
     OrderIDField.Text           = generateID();
 }
        public void refreshSalesItems()
        {
            currentSaleObject           = new SaleClass();
            currentSaleObject.SaleItems = new List <SaleItemClass>();
            SaleItemsList.DataSource    = null;
            SaleItemsList.Refresh();

            clearFields();
        }
 public void PostSale(SaleClass sale)
 {
     if (sale.Id == 0)
     {
         long newId = Sales.Select(@class => @class.Id).Max() + 1;
         sale.Id = newId;
         Sales.Add(sale);
     }
     else
     {
         Sales = Sales.Where(@class => @class.Id != sale.Id).ToList();
         Sales.Add(sale);
     }
     Utils.SaveToFile();
 }
Example #4
0
        private void BuyBtm_MouseDown(object sender, MouseButtonEventArgs e)
        {
            int i;

            ChangeInfo[] changeInfo = new ChangeInfo[Court.Length];
            for (i = 0; i < Court.Length; i++)
            {
                changeInfo[i]        = new ChangeInfo();
                changeInfo[i].Id     = Court[i].GetProductId();
                changeInfo[i].Amount = Court[i].GetAmount();
            }
            SaleClass.SaleWork(changeInfo, ManagerId, SectionId);

            CourtViewer.Children.Clear();
            Court = new PositionBlank[0];

            StorageViewer.Children.Clear();
            Storage = new PositionBlank[0];

            ReadStorage();
        }
 public void PostSale(SaleClass sale)
 {
     dataAccess.PostSale(sale);
 }
Example #6
0
 public void PostSale(SaleClass sale)
 {
     throw new NotImplementedException();
 }
 public void PostSale(SaleClass sale)
 {
     throw new NotImplementedException();
 }
 public void PostSale(SaleClass sale)
 {
     dataAccess.PostSale(sale);
 }
 public void PostSale(SaleClass sale)
 {
     if (sale.Id == 0)
     {
         long newId = Sales.Select(@class => @class.Id).Max() + 1;
         sale.Id = newId;
         Sales.Add(sale);
     }
     else
     {
         Sales = Sales.Where(@class => @class.Id != sale.Id).ToList();
         Sales.Add(sale);
     }
     Utils.SaveToFile();
 }
        public void RecordSale(int checkoutOrHold, string modeOfPayment)
        {
            decimal discount   = 0;
            decimal taxapplied = 0;

            if (AmountPaidField.Text.Length > 0)
            {
                try
                {
                    var amountpaid = Decimal.Parse(AmountPaidField.Text);
                    var total      = Decimal.Parse(TotalSaleField.Text);
                    BalanceField.Text = decimal.Round(amountpaid - total, 2).ToString();
                    if (total <= amountpaid)
                    {
                        decimal balance = amountpaid - total;

                        //start creating db records
                        using (var db = new POSApplication.Model.posdbEntities())
                        {
                            if (TotalDiscountField.Text.Length > 0)
                            {
                                try
                                {
                                    discount = Decimal.Parse(TotalDiscountField.Text);
                                }
                                catch (Exception e1)
                                {
                                    MessageBox.Show(@"Enter numeric value for Discount");
                                }
                            }
                            if (TaxAppliedField.Text.Length > 0)
                            {
                                try
                                {
                                    taxapplied = Decimal.Parse(TaxAppliedField.Text);
                                }
                                catch (Exception e1)
                                {
                                    MessageBox.Show(@"Enter numeric value for Tax");
                                }
                            }
                            total = total + (total * (taxapplied / 100));
                            total = total - (total * (discount / 100));

                            BalanceField.Text = balance.ToString();
                            var so = new purchasesorder {
                                AmountPaid = amountpaid
                            };
                            currentSaleObject.AmountPaid = amountpaid;
                            so.Balance = balance;
                            currentSaleObject.Balance = decimal.Round((decimal)balance, 2);
                            so.Discount = discount;
                            currentSaleObject.Discount   = discount;
                            so.ModeOfPayment             = modeOfPayment;
                            so.PurchaseAmount            = Decimal.Parse(TotalSaleField.Text);
                            currentSaleObject.SaleAmount = decimal.Round((decimal)so.PurchaseAmount, 2);

                            //so.SaleDate = DateTime.Now.Date;
                            so.PurchaseDate = dateTimePicker1.Value.Date;
                            //so.Date_dateofmonth_int = DateTime.Now.Day;
                            so.Date_dateofmonth_int = dateTimePicker1.Value.Day;
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
                            {
                                so.Date_Dayofweek_int = 7;
                            }
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
                            {
                                so.Date_Dayofweek_int = 1;
                            }
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Tuesday)
                            {
                                so.Date_Dayofweek_int = 2;
                            }
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Wednesday)
                            {
                                so.Date_Dayofweek_int = 3;
                            }
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Thursday)
                            {
                                so.Date_Dayofweek_int = 4;
                            }
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Friday)
                            {
                                so.Date_Dayofweek_int = 5;
                            }
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday)
                            {
                                so.Date_Dayofweek_int = 6;
                            }
                            //so.Date_DayofWeek_string = DateTime.Now.DayOfWeek.ToString();
                            so.Date_DayofWeek_string = dateTimePicker1.Value.DayOfWeek.ToString();
                            //so.date_month_int = DateTime.Now.Month;
                            so.date_month_int = dateTimePicker1.Value.Month;

                            if (DateTime.Now.Month == 1)
                            {
                                so.date_month_string = "January";
                            }
                            if (DateTime.Now.Month == 2)
                            {
                                so.date_month_string = "February";
                            }
                            if (DateTime.Now.Month == 3)
                            {
                                so.date_month_string = "March";
                            }
                            if (DateTime.Now.Month == 4)
                            {
                                so.date_month_string = "April";
                            }
                            if (DateTime.Now.Month == 5)
                            {
                                so.date_month_string = "May";
                            }
                            if (DateTime.Now.Month == 6)
                            {
                                so.date_month_string = "June";
                            }
                            if (DateTime.Now.Month == 7)
                            {
                                so.date_month_string = "July";
                            }
                            if (DateTime.Now.Month == 8)
                            {
                                so.date_month_string = "August";
                            }
                            if (DateTime.Now.Month == 9)
                            {
                                so.date_month_string = "September";
                            }
                            if (DateTime.Now.Month == 10)
                            {
                                so.date_month_string = "October";
                            }
                            if (DateTime.Now.Month == 11)
                            {
                                so.date_month_string = "November";
                            }
                            if (DateTime.Now.Month == 12)
                            {
                                so.date_month_string = "December";
                            }

                            so.date_year_int = dateTimePicker1.Value.Year;
                            so.time_hour     = int.Parse(dateTimePicker1.Value.Hour.ToString());

                            so.PurchaseTime = dateTimePicker1.Value.TimeOfDay;
                            so.UserName     = AppConfig.loggedInUserName;

                            //setting the status to checkout or hold sale.
                            so.PurchaseStatus = checkoutOrHold;
                            so.TaxPercentage  = taxapplied;
                            currentSaleObject.TaxPercentage = taxapplied;
                            so.TerminalID = AppConfig.TerminalID;

                            //recording the purchase as purchase on hold
                            if (checkoutOrHold == 1)
                            {
                                so.HoldInvoice = 1;
                            }
                            else
                            {
                                so.HoldInvoice = 0;
                            }

                            so.InvoiceID = OrderIDField.Text;

                            db.purchasesorders.Add(so);
                            db.SaveChanges();
                            //Adding purchase Items
                            int orderid = so.OrderID;
                            foreach (var item in currentSaleObject.SaleItems)
                            {
                                decimal tax           = item.TaxPercentage / 100;
                                decimal purchaseprice = (item.PriceApplied * tax) + item.PriceApplied;
                                decimal itemdiscount  = item.Discount / 100;
                                purchaseprice = (purchaseprice * itemdiscount) + purchaseprice;
                                var s = new purchasesorderdetail
                                {
                                    ProductID     = item.ProductID,
                                    InvoiceID     = OrderIDField.Text,
                                    Discount      = item.Discount,
                                    PurchasePrice = item.PriceApplied,
                                    Quantity      = item.Quantity
                                };
                                s.PurchasePrice = purchaseprice;
                                s.TaxPercentage = item.TaxPercentage;
                                db.purchasesorderdetails.Add(s);
                                db.SaveChanges();

                                //////////////////////////////////////////////////////////////////////////////////
                                //closing previous inventory record.
                                //////////////////////////////////////////////////////////////////////////////////
                                Model.inventory c = (from x in db.inventories
                                                     where (x.ProductID == item.ProductID && x.UpdateDt == null && x.PurchasePrice == purchaseprice || (x.ProductID == item.ProductID && x.UpdateDt == null && x.PurchasePrice == 0 && x.SalePrice == 0))
                                                     select x).SingleOrDefault();

                                if (c != null)
                                {
                                    c.UpdateDt = dateTimePicker1.Value;
                                    db.SaveChanges();

                                    decimal existingQuantity;
                                    if (c.SumQuantity != null)
                                    {
                                        existingQuantity = (decimal)c.SumQuantity;
                                    }
                                    else
                                    {
                                        existingQuantity = 0;
                                    }

                                    var inv = new inventory
                                    {
                                        ProductID     = item.ProductID,
                                        CreateDt      = dateTimePicker1.Value,
                                        PurchaseDate  = dateTimePicker1.Value,
                                        PurchasePrice = purchaseprice,
                                        Quantity      = item.Quantity,
                                        //TaxPaid = item.TaxPercentage,
                                        //ReorderValue = c.ReorderValue,
                                        UpdateDt      = null,
                                        PackingTypeID = null,
                                        SumQuantity   = existingQuantity + item.Quantity,
                                        SalePrice     = c.SalePrice,
                                        InvoiceID     = so.InvoiceID
                                    };
                                    db.inventories.Add(inv);
                                    db.SaveChanges();
                                }
                                else
                                {
                                    decimal existingQuantity = 0;
                                    var     d = (from x in db.inventories
                                                 where x.ProductID == item.ProductID && x.UpdateDt == null
                                                 select x).FirstOrDefault();


                                    var inv = new inventory
                                    {
                                        ProductID     = item.ProductID,
                                        CreateDt      = dateTimePicker1.Value,
                                        PurchaseDate  = dateTimePicker1.Value,
                                        PurchasePrice = purchaseprice,
                                        Quantity      = item.Quantity,
                                        UpdateDt      = null,
                                        PackingTypeID = null,
                                        SumQuantity   = existingQuantity + item.Quantity,
                                        SalePrice     = 0,
                                        InvoiceID     = so.InvoiceID
                                    };
                                    db.inventories.Add(inv);
                                    db.SaveChanges();
                                }
                            }
                            /////////////////////////////////////////////////////////////////////

                            /////////////////////////////////////////////////////////////////////


                            if (checkoutOrHold == 1)
                            {
                                MessageBox.Show(@"Purchase is put on HOLD. You can open the Purchases on hold again from Invoices Form.");
                            }
                            else
                            {
                                PrintPage();

                                currentSaleObject           = new SaleClass();
                                currentSaleObject.SaleItems = new List <SaleItemClass>();
                                SaleItemsList.DataSource    = null;
                                SaleItemsList.Refresh();
                                clearFields();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(@"Amount Paid Value should be larger or equal to Total");
                    }
                }
                catch (Exception e1)
                {
                    MessageBox.Show(@"Enter numeric value for Amount Paid");
                }
            }
            else
            {
                MessageBox.Show(@"Enter value for Amount Paid");
            }
        }