simple_inventory 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/simple_inventory.rb +158 -0
- data/lib/simple_inventory_cl.rb +141 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e1e03d50c006361c80047cbe732a7b2e949e6816
|
4
|
+
data.tar.gz: 7df91ba86624670aeb8d7389a6659568a28f7141
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1804e0563aba2b1a8f10a0298e2b40ae1b23935434af66ce99d87f97d981a626cf46b77ff46d5d30e6bd42ee1f923aa06c9deac1c4de42f6cd7cedbf7476b4d
|
7
|
+
data.tar.gz: e905fbb585ee2833f6b44aff9cdcf67081d84b8218e34de914dcf611a1a68134bbe618d7d50b5358a13c37e3cae4a6ad3766351f605cbcdf34f22a6cd1f51012
|
@@ -0,0 +1,158 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#simple_inventory.rb
|
3
|
+
|
4
|
+
require './simple_inventory_cl.rb'
|
5
|
+
|
6
|
+
go = true
|
7
|
+
|
8
|
+
while go
|
9
|
+
puts "::SIMPLE Inventory:: Collaborate => https://github.com/mepyyeti/simple_inv"
|
10
|
+
puts
|
11
|
+
puts "enter [1] to ADD an item\nenter [2] to DELETE an item"
|
12
|
+
puts "enter [3] to SUBTRACT an amount\nenter [4] to REPLENISH"
|
13
|
+
puts "enter [5] to VIEW INVENTORY \nenter [6] to EXIT"
|
14
|
+
choice = gets.chomp
|
15
|
+
|
16
|
+
unless choice.empty? == false
|
17
|
+
next
|
18
|
+
end
|
19
|
+
|
20
|
+
choice = Integer(choice)
|
21
|
+
|
22
|
+
if choice == 1
|
23
|
+
print "enter item: "
|
24
|
+
item = gets.chomp
|
25
|
+
|
26
|
+
if item.empty? then next end
|
27
|
+
|
28
|
+
puts "item: empty? #{item.empty?} nil? #{item.nil?} string? #{item.is_a?(String)}"
|
29
|
+
print "amount: "
|
30
|
+
stock = Integer(gets.chomp)
|
31
|
+
puts stock.class
|
32
|
+
|
33
|
+
while stock < 1
|
34
|
+
print "amount: "
|
35
|
+
stock = Integer(gets.chomp)
|
36
|
+
end
|
37
|
+
|
38
|
+
stock = Integer(stock)
|
39
|
+
rl = true
|
40
|
+
|
41
|
+
while rl
|
42
|
+
print "set a reorder level: "
|
43
|
+
reorder_lvl = gets.chomp
|
44
|
+
|
45
|
+
while reorder_lvl.empty? || reorder_lvl.nil?
|
46
|
+
print "set a NUMERIC reorder level: "
|
47
|
+
reorder_lvl = gets.chomp
|
48
|
+
end
|
49
|
+
|
50
|
+
reorder_lvl = Integer(reorder_lvl)
|
51
|
+
furthermore = {reorder_lvl: reorder_lvl}
|
52
|
+
|
53
|
+
unless reorder_lvl >= 1
|
54
|
+
puts "reorder level must be greater than 1"
|
55
|
+
next
|
56
|
+
end
|
57
|
+
|
58
|
+
rl = false
|
59
|
+
end
|
60
|
+
|
61
|
+
print "want to enter an item description? [y/n]: "
|
62
|
+
choice = gets.chomp.downcase
|
63
|
+
|
64
|
+
unless choice == 'n' || choice =='no' || choice == '' || choice == ' '
|
65
|
+
puts "enter a description of 20 char or less: "
|
66
|
+
extra = gets.chomp
|
67
|
+
|
68
|
+
if extra.size > 20
|
69
|
+
"description is too long."
|
70
|
+
next
|
71
|
+
else
|
72
|
+
"acceptable."
|
73
|
+
end
|
74
|
+
|
75
|
+
furthermore = {stock: stock, reorder_lvl: reorder_lvl, desc: extra}
|
76
|
+
else
|
77
|
+
furthermore = {stock: stock, reorder_lvl: reorder_lvl}
|
78
|
+
end
|
79
|
+
|
80
|
+
x = Inv.new(item, furthermore)
|
81
|
+
x.run(item,furthermore)
|
82
|
+
|
83
|
+
elsif choice == 2
|
84
|
+
id_prod_hash = {stock: 1, desc: 'just viewing'}
|
85
|
+
x = Inv.new(id_prod_hash)
|
86
|
+
summary = x.summary
|
87
|
+
|
88
|
+
if summary == false then next end
|
89
|
+
|
90
|
+
print "type id number OR product name to delete item: "
|
91
|
+
id_or_prod = gets.chomp.downcase
|
92
|
+
print "Confirm deletion? [y/n]? :"
|
93
|
+
confirm = gets.chomp.downcase
|
94
|
+
|
95
|
+
unless confirm == 'y' || confirm == 'yes'
|
96
|
+
puts "deletion aborted...returned to main screen options"
|
97
|
+
next
|
98
|
+
else
|
99
|
+
x.delete(id_or_prod)
|
100
|
+
end
|
101
|
+
|
102
|
+
elsif choice == 3 || choice == 4
|
103
|
+
id_prod_hash = {stock: 1, desc: 'just viewing'}
|
104
|
+
y = Inv.new(id_prod_hash)
|
105
|
+
summary = y.summary
|
106
|
+
|
107
|
+
if summary == false then next end
|
108
|
+
|
109
|
+
direct = "type id number OR product name: "
|
110
|
+
print " #{direct}"
|
111
|
+
id_or_prod = gets.chomp.downcase
|
112
|
+
|
113
|
+
while id_or_prod.empty? || id_or_prod.nil?
|
114
|
+
print " #{direct}"
|
115
|
+
id_or_prod = gets.chomp.downcase
|
116
|
+
end
|
117
|
+
|
118
|
+
pulled = y.find_to_change(id_or_prod)
|
119
|
+
pulled = Integer(pulled)
|
120
|
+
|
121
|
+
if choice == 3
|
122
|
+
add_subtract = "sold"
|
123
|
+
print "How many #{add_subtract}? "
|
124
|
+
sold = Integer(gets.chomp)
|
125
|
+
|
126
|
+
if sold < 0
|
127
|
+
sold = abs(sold)
|
128
|
+
end
|
129
|
+
|
130
|
+
new_quant = pulled - sold
|
131
|
+
|
132
|
+
else
|
133
|
+
add_subtract = "do you want to replenish"
|
134
|
+
print "How many #{add_subtract}? "
|
135
|
+
sold = Integer(gets.chomp)
|
136
|
+
|
137
|
+
if sold < 0
|
138
|
+
sold = abs(sold)
|
139
|
+
end
|
140
|
+
|
141
|
+
new_quant = pulled + sold
|
142
|
+
end
|
143
|
+
|
144
|
+
y.sell_replenish(new_quant, id_or_prod)
|
145
|
+
y.reorder(id_or_prod)
|
146
|
+
|
147
|
+
elsif choice == 5
|
148
|
+
id_prod_hash = {stock: 1, desc: 'just viewing'}
|
149
|
+
z = Inv.new(id_prod_hash)
|
150
|
+
z.summary
|
151
|
+
|
152
|
+
elsif choice == 6
|
153
|
+
go = false
|
154
|
+
|
155
|
+
else
|
156
|
+
next
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#simple_inventory_cl.rb
|
3
|
+
|
4
|
+
require 'sqlite3'
|
5
|
+
|
6
|
+
class Inv
|
7
|
+
attr_reader :item, :stock, :desc
|
8
|
+
|
9
|
+
def item=(item)
|
10
|
+
@item = item
|
11
|
+
end
|
12
|
+
|
13
|
+
def stock=(stock=1)
|
14
|
+
@stock = Integer(stock)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(item='nothing',**specs)
|
18
|
+
self.item = item
|
19
|
+
self.stock = specs[:stock]
|
20
|
+
@desc = specs[:desc]
|
21
|
+
end
|
22
|
+
|
23
|
+
def run(item, furthermore)
|
24
|
+
begin
|
25
|
+
db = SQLite3::Database.open('inventory.db')
|
26
|
+
puts db.get_first_value "select SQLite_VERSION()"
|
27
|
+
db.transaction
|
28
|
+
#db.execute2 "drop table stock"
|
29
|
+
db.execute2 "create table if not exists stock(Id INTEGER PRIMARY KEY, Product TEXT, RO TEXT, Level INTEGER, RO_at INTEGER, Description TEXT)"
|
30
|
+
puts "foo"
|
31
|
+
db.execute2 "insert into stock(Product, Level, RO_at, Description) values(:Product, :Level, :RO_at, :Description)", item, furthermore[:stock], furthermore[:reorder_lvl], furthermore[:desc]
|
32
|
+
db.commit
|
33
|
+
puts db.changes.to_s + " change"
|
34
|
+
puts "You added #{item}, with stock level #{stock}"
|
35
|
+
puts "#{item} is described as: #{desc}."
|
36
|
+
puts
|
37
|
+
print_me = db.execute2 "select * from stock where Product = :item" , item
|
38
|
+
print_me.each { |p| puts "%3s %-10s -%-3s- [%5s] %-5s %20s" % [p[0],p[1],p[2],p[3],p[4],p[5]] }
|
39
|
+
puts
|
40
|
+
rescue SQLite3::Exception => e
|
41
|
+
print "error in run " , e
|
42
|
+
db.rollback
|
43
|
+
ensure
|
44
|
+
db.close if db
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def summary
|
49
|
+
begin
|
50
|
+
db = SQLite3::Database.open('inventory.db')
|
51
|
+
return "no match" unless File.exists?('inventory.db')
|
52
|
+
all = db.execute2 "SELECT * from stock"
|
53
|
+
puts
|
54
|
+
puts "this is your current inventory"
|
55
|
+
all.each { |p| puts "%3s %-10s -%-3s- [%5s] %-5s %20s " % [p[0],p[1],p[2],p[3],p[4],p[5]]}
|
56
|
+
puts
|
57
|
+
rescue SQLite3::Exception => e
|
58
|
+
puts "error in summary " , e
|
59
|
+
ensure
|
60
|
+
db.close if db
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def delete(id_prod)
|
65
|
+
begin
|
66
|
+
db = SQLite3::Database.open('inventory.db')
|
67
|
+
db.transaction
|
68
|
+
db.execute2 "DELETE from stock WHERE Id = :id_prod OR Product = :id_prod", id_prod
|
69
|
+
db.commit
|
70
|
+
puts db.changes.to_s + " deletion"
|
71
|
+
rescue SQLite3::Exception => e
|
72
|
+
puts "error in delete " , e
|
73
|
+
db.rollback
|
74
|
+
ensure
|
75
|
+
db.close if db
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def find_to_change(id_prod)
|
81
|
+
begin
|
82
|
+
db = SQLite3::Database.open('inventory.db')
|
83
|
+
print_out = db.execute2 "Select * from stock where Id = :id_prod OR Product = :id_prod" ,id_prod
|
84
|
+
puts
|
85
|
+
print_out.each { |line| puts "%3s %-10s -%-3s- [%5s] %-5s %20s" % [line[0], line[1], line[2], line[3], line[4], line[5]]}
|
86
|
+
puts
|
87
|
+
pull = db.execute2 "Select Level from stock where Id = :id_prod OR Product = :id_prod" ,id_prod
|
88
|
+
@pull = Integer(pull[1][0])
|
89
|
+
rescue SQLite3::Exception => e
|
90
|
+
puts "error in find_to_change " , e
|
91
|
+
ensure
|
92
|
+
db.close if db
|
93
|
+
end
|
94
|
+
@pull
|
95
|
+
end
|
96
|
+
|
97
|
+
def sell_replenish(new_quant, id_prod)
|
98
|
+
begin
|
99
|
+
db = SQLite3::Database.open('inventory.db')
|
100
|
+
puts new_quant.class
|
101
|
+
db.transaction
|
102
|
+
db.execute2 "UPDATE stock SET Level = :new_quant WHERE Id = :id_prod OR Product = :id_prod" , new_quant, id_prod
|
103
|
+
db.commit
|
104
|
+
puts db.changes.to_s + " change"
|
105
|
+
rescue SQLite3::Exception => e
|
106
|
+
puts "error in sell_replenish ", e
|
107
|
+
db.rollback
|
108
|
+
ensure
|
109
|
+
db.close if db
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def reorder(id_prod)
|
114
|
+
begin
|
115
|
+
db = SQLite3::Database.open('inventory.db')
|
116
|
+
current_level = db.execute2 "SELECT Level from stock WHERE Id = :id_prod OR Product = :id_prod", id_prod
|
117
|
+
@current_level = Integer(current_level[1][0])
|
118
|
+
reorder_level = db.execute2 "SELECT RO_at from stock WHERE Id = :id_prod OR Product = :id_prod", id_prod
|
119
|
+
@reorder_level = Integer(reorder_level[1][0])
|
120
|
+
if @current_level <= @reorder_level
|
121
|
+
replenish = "YES"
|
122
|
+
else
|
123
|
+
replenish = ''
|
124
|
+
end
|
125
|
+
db.transaction
|
126
|
+
db.execute2 "UPDATE stock SET RO = :replenish WHERE Id = :id_prod OR Product = :id_prod", replenish, id_prod
|
127
|
+
db.commit
|
128
|
+
puts db.changes.to_s + " change"
|
129
|
+
print_out = db.execute2 "SELECT * from stock WHERE Id = :id_prod OR Product = :id_prod", id_prod
|
130
|
+
puts
|
131
|
+
print_out.each { |p| puts "%3s %-10s -%-3s- [%5s] %-5s %20s" % [p[0],p[1],p[2],p[3],p[4],p[5]]}
|
132
|
+
puts
|
133
|
+
rescue SQLite3::Exception => e
|
134
|
+
puts "error in reorder method " , e
|
135
|
+
db.rollback
|
136
|
+
ensure
|
137
|
+
db.close if db
|
138
|
+
end
|
139
|
+
@replenish = replenish
|
140
|
+
end
|
141
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_inventory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- fookh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A lightweight inventory system utilizing SQLite3. Allows user to add/delete
|
14
|
+
items, subtract/replenish quantities, view inventory contents. sqlite3 based
|
15
|
+
email: foo@yetispeak.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/simple_inventory.rb
|
21
|
+
- lib/simple_inventory_cl.rb
|
22
|
+
homepage:
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.5.2.1
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: a lightweight inventory system
|
46
|
+
test_files: []
|