Created
November 22, 2013 15:05
-
-
Save justuseapen/7601337 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pry' | |
require 'csv' | |
# class Product | |
# @@all = [] | |
# def initialize (item, price) | |
# @item = item | |
# @price = price | |
# end | |
# def name | |
# @item | |
# end | |
# def price | |
# @price | |
# end | |
# def self.create(name, price) | |
# product = Product.new(name, price) | |
# @@all << product | |
# product | |
# end | |
# def self.all | |
# @@all | |
# end | |
# end | |
# def inventory | |
# name = "go" | |
# while name != "" do | |
# puts "Enter product name (leave blank to continue):" | |
# name = gets.chomp | |
# if name != "" | |
# puts "Enter product price:" | |
# price = gets.chomp | |
# Product.create(name, price) | |
# end | |
# end | |
# total | |
# end | |
def prompt(query,value) | |
puts query | |
value = gets.chomp | |
end | |
def show_inventory | |
#Sorry John. I had to do it to 'em | |
stock = Hash.new | |
CSV.foreach("Inventory.csv", headers: true) do |line| | |
stock.store(line["item"], line["price"]) | |
end | |
puts stock | |
end | |
def get_data | |
prompt "What is the name of the item?",item | |
prompt "What is the SKU",sku | |
prompt "What do we sell it for?",sell_price | |
prompt "What do we buy it for", buy_price | |
write_to_inventory(item,sku,sell_price,buy_price) | |
end | |
def write_to_inventory (item, sku, sell_price, buy_price) | |
File.open("Inventory.csv", 'a+') {|f| f.write(item, sku, sell_price, buy_price)} | |
end | |
puts "Would you like to add an item to the inventory?" | |
reply = gets.chomp.downcase | |
if reply == "yes" | |
get_data | |
end | |
binding.pry | |
$amount_due = 0.0 | |
def total | |
#Probably delete | |
stock = Hash.new | |
CSV.foreach("Inventory.csv", headers: true) do |line| | |
stock.store(line["item"], line["sell_price"]) | |
end | |
#List inventory | |
#select from inventory | |
#select quantity | |
#pyotr | |
stock.each_with_index do |item, index| | |
puts "#{index+1} #{item}" | |
end | |
binding.pry | |
stock.each_with_index do |product,index| | |
puts "What product would you like to buy?" | |
selection = gets.chomp | |
stock[selection] | |
quantity = gets.chomp.to_f | |
item_total = quantity * product.price.to_f | |
$amount_due = $amount_due + item_total | |
end | |
end | |
def transaction | |
puts "The customer owes you $#{"%.2f" % $amount_due}." | |
puts "How much money did the customer give you?" | |
tendered = gets.chomp.to_f | |
if tendered >= $amount_due | |
change = tendered-$amount_due | |
change = change.to_f | |
puts "Please return $#{"%.2f" % change} in change to the customer." | |
else | |
"The customer did not give you enough cash." | |
end | |
end | |
total | |
transaction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment