コード例 #1
0
        public void CreateFromRow(Row Table)
        {
            ID = Convert.ToInt32(Table.Values[0]);
            NumberOfProducts = Convert.ToInt32(Table.Values[1]);
            TotalPrice       = Math.Round(Convert.ToDecimal(Table.Values[2]), 2);
            //PaidPrice = Convert.ToDecimal(Table.Values[3]);
            string      sql     = $"SELECT * FROM `sale_transactions` WHERE `receipt_id` = '{ID}' AND `amount` != 0";
            TableDecode Results = Mysql.RunQueryWithReturn(sql);

            Transactions = new List <SaleTransaction>();
            foreach (var item in Results.RowData)
            {
                SaleTransaction newSaleTransaction = new SaleTransaction(item);
                Transactions.Add(newSaleTransaction);
            }
            sql = $"SELECT * FROM `payments` WHERE `receipt_id` = '{ID}'";
            TableDecode Pays = Mysql.RunQueryWithReturn(sql);

            Payments = new List <Payment>();
            foreach (var item in Pays.RowData)
            {
                Payment NewPayment = new Payment(item);
                Payments.Add(NewPayment);
            }
            Date = Convert.ToDateTime(Table.Values[3]);
        }
コード例 #2
0
        public void DiscountOnSingleTransaction(int transID, string inputDiscount)
        {
            SaleTransaction currentSaleTransaction = Transactions.Where(x => x.GetID() == transID).First();
            decimal         customDiscount         = 0;
            decimal         percentage             = 0m;

            if (inputDiscount.Contains('%'))
            {
                percentage = Convert.ToDecimal(inputDiscount.Replace("%", string.Empty));
                decimal priceInDiscountPrProduct = currentSaleTransaction.Price * (percentage / 100m);
                currentSaleTransaction.DiscountPrice = currentSaleTransaction.Price - priceInDiscountPrProduct;

                //currentSaleTransaction.Product.DiscountPrice = currentSaleTransaction.Product.SalePrice - priceInDiscountPrProduct;
            }
            else
            {
                if (inputDiscount.Length > 0)
                {
                    customDiscount = Convert.ToDecimal(inputDiscount);
                }
                if (customDiscount > 0m)
                {
                    currentSaleTransaction.DiscountPrice = currentSaleTransaction.Price - (customDiscount / currentSaleTransaction.Amount);
                }
            }
            if (customDiscount > 0m || percentage > 0m)
            {
                currentSaleTransaction.DiscountBool = true;
            }
            UpdateTotalPrice();
        }
コード例 #3
0
        public void RemoveTransaction(int productID)
        {
            SaleTransaction placeholderTransaction = FindTransactionFromProductID(productID);

            Transactions.Remove(placeholderTransaction);
            UpdateTotalPrice();
            UpdateNumberOfProducts();
        }
コード例 #4
0
        public void RemoveTransaction(string tempID)
        {
            int             ID = int.Parse(tempID.Remove(0, 1));
            SaleTransaction placeholderTransaction = Transactions.Where(x => x.Product is TempProduct && x.Product.ID == ID).First();

            Transactions.Remove(placeholderTransaction);
            UpdateTotalPrice();
            UpdateNumberOfProducts();
        }
コード例 #5
0
ファイル: TempProduct.cs プロジェクト: msimon16/P4
 public SaleTransaction GetTempProductsSaleTransaction()
 {
     if (Resolved)
     {
         string          sql            = $"SELECT * FROM `sale_transactions` WHERE `product_type` = 'temp_product' AND `product_id` = '{this.ID}'";
         TableDecode     getTransaction = Mysql.RunQueryWithReturn(sql);
         SaleTransaction saleTrans      = new SaleTransaction(getTransaction.RowData[0]);
         return(saleTrans);
     }
     throw new TempProductResolvedException("Dette tempproduct er ikke resolved");
 }
コード例 #6
0
        public void AddTransaction(SaleTransaction transaction)
        {
            //Checks if product is already in receipt//
            if (Transactions.Any(x => x.Product == transaction.Product) && transaction.Product.GetName() != "Is")
            {
                Transaction placeholderTransaction = Transactions.First(x => x.Product == transaction.Product);
                placeholderTransaction.Edit(placeholderTransaction.Amount += transaction.Amount);
            }
            else
            {
                Transactions.Add(transaction);
            }

            TotalPrice += transaction.TotalPrice;
            UpdateNumberOfProducts();

            RemoveDiscountFromDiscount(transaction);

            UpdateTotalPrice();
        }
コード例 #7
0
 public void RemoveDiscountFromDiscount(SaleTransaction transaction)
 {
     DiscountOnFullReceipt = 0m;
     Transactions.Where(x => x.Product == transaction.Product).First().DiscountBool = false;
 }