ig3tool 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ig3tool +1 -1
- data/lib/glade/sales.glade +84 -84
- data/lib/ui/{internewindow.rb → OLD_internewindow.rb} +0 -0
- data/lib/ui/{memberswindow.rb → OLD_memberswindow.rb} +0 -0
- data/lib/ui/{productswindow.rb → OLD_productswindow.rb} +0 -0
- data/lib/ui/gladehelper.rb +3 -2
- data/lib/ui/{newinterne.rb → interne.rb} +2 -1
- data/lib/ui/peoplewindow.rb +1 -1
- data/lib/ui/printingwindow.rb +6 -6
- data/lib/ui/protjes.rb +6 -0
- data/lib/ui/saleswindow.rb +72 -25
- data/lib/ui/toolwindow.rb +3 -3
- metadata +70 -95
- data/lib/actions/bib.rb +0 -295
- data/lib/actions/bitching.rb +0 -19
- data/lib/actions/cultuur.rb +0 -3
- data/lib/actions/interne.rb +0 -98
- data/lib/actions/kaching.rb +0 -90
- data/lib/actions/people.rb +0 -178
- data/lib/actions/printing.rb +0 -125
- data/lib/actions/product.rb +0 -154
- data/lib/bib.rb +0 -94
- data/lib/billing.rb +0 -112
- data/lib/bitching.rb +0 -49
- data/lib/config.rb +0 -19
- data/lib/horrible_hack.rb +0 -15
- data/lib/interne.rb +0 -111
- data/lib/ldap.rb +0 -104
- data/lib/log.rb +0 -25
- data/lib/membership.rb +0 -32
- data/lib/mymd5.rb +0 -95
- data/lib/people.rb +0 -143
- data/lib/printing.rb +0 -238
- data/lib/request.rb +0 -14
- data/lib/sales.rb +0 -158
- data/lib/utils.rb +0 -106
- data/lib/web.rb +0 -98
data/lib/actions/product.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
require 'sales'
|
2
|
-
module Ig3tool
|
3
|
-
class Actions
|
4
|
-
|
5
|
-
# Geeft alle categorieen terug.
|
6
|
-
def self.product_categories(params)
|
7
|
-
Category.find(:all)
|
8
|
-
end
|
9
|
-
|
10
|
-
# Geeft alle producten uit een categorie terug
|
11
|
-
def self.product_category(params)
|
12
|
-
raise Needed, "Category" if params[:given_uri] != 1
|
13
|
-
Category.find(params[:from_uri].first).products
|
14
|
-
end
|
15
|
-
|
16
|
-
# Verwacht een barcode in de URL
|
17
|
-
# Geeft het product terug
|
18
|
-
def self.product_lookup(params)
|
19
|
-
raise Needed, "Barcode" if params[:given_uri] != 1
|
20
|
-
|
21
|
-
p = params[:from_uri].first
|
22
|
-
_product(p)
|
23
|
-
end
|
24
|
-
|
25
|
-
# Verwacht geen parameters
|
26
|
-
# Geeft alle producten in de stock terug
|
27
|
-
def self.product_all(params)
|
28
|
-
#Product.find :all, :conditions => { 'stock_gt' => 0 } # Stock Greater than
|
29
|
-
Product.find :all, :include => [:purchases]
|
30
|
-
end
|
31
|
-
|
32
|
-
# Verwacht een barcode in de URL
|
33
|
-
# Geeft de stock terug
|
34
|
-
def self.product_stock(params)
|
35
|
-
raise Needed, "Barcode" if params[:given_uri] != 1
|
36
|
-
|
37
|
-
prod = _product(params[:from_uri].first)
|
38
|
-
prod.stock
|
39
|
-
end
|
40
|
-
|
41
|
-
# Verwacht een barcode en de stock in de URL
|
42
|
-
# Geeft de diff stock terug
|
43
|
-
# Verwijdert de oudste items indien newstock < oldstock
|
44
|
-
# Voegt items toe met de nieuwste prijs indien newstock > oldstock
|
45
|
-
def self.product_diff!(params)
|
46
|
-
barcode = params["barcode"] or raise Needed, "Barcode"
|
47
|
-
newstock = params["stock"] or raise Needed, "Stock"
|
48
|
-
p = _product(barcode)
|
49
|
-
oldstock = p.stock
|
50
|
-
|
51
|
-
if oldstock < newstock
|
52
|
-
# TODO XXX Set Price!
|
53
|
-
else
|
54
|
-
# TODO remove from stock!
|
55
|
-
end
|
56
|
-
|
57
|
-
Logger::log :stock, :diff, "%s stock changed from %d to %d" %
|
58
|
-
[ p.name, oldstock, p.stock ]
|
59
|
-
end
|
60
|
-
|
61
|
-
# Voegt een product toe aan de DB
|
62
|
-
# Verwacht 'barcode', 'name', 'category', 'nmprice', 'mprice' en 'dprice'
|
63
|
-
def self.product_add!(params)
|
64
|
-
notfound = []
|
65
|
-
|
66
|
-
[:barcode, :name, :category, :nmprice, :mprice, :dprice].each do |k|
|
67
|
-
notfound << k unless params.include? k.to_s and !params[k.to_s].nil?
|
68
|
-
end
|
69
|
-
|
70
|
-
raise Needed, notfound unless notfound.empty?
|
71
|
-
|
72
|
-
p = \
|
73
|
-
Product.create(:barcode => params["barcode"],
|
74
|
-
:name => params["name"],
|
75
|
-
:category => Category.find_by_name(params["category"].capitalize),
|
76
|
-
:nmprice => params["nmprice"],
|
77
|
-
:mprice => params["mprice"],
|
78
|
-
:dprice => params["dprice"],
|
79
|
-
:stock => 0) # XXX of params["amount"] ?
|
80
|
-
|
81
|
-
Logger::log :product, :add, "Added %d (%s)" % [ params["barcode"], params["name"] ]
|
82
|
-
|
83
|
-
"OK"
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.product_remove!(params)
|
87
|
-
barcode = params["barcode"] or raise Needed, "Barcode"
|
88
|
-
p = _product(barcode)
|
89
|
-
|
90
|
-
raise "still in stock, won't delete!" if p.stock > 0
|
91
|
-
|
92
|
-
p.destroy
|
93
|
-
|
94
|
-
"OK"
|
95
|
-
end
|
96
|
-
|
97
|
-
# Laat een 'debugger' een aankoop ingeven, met factuurnummer 'reference'.
|
98
|
-
# Verwacht een hash barcode => [amount, cost] in 'items'.
|
99
|
-
def self.product_purchase!(params)
|
100
|
-
name = params["debugger"] or raise NeedDebugger
|
101
|
-
debugger = Person.find_by_username(name)
|
102
|
-
raise NotADebugger.new(name) unless !debugger.nil? && debugger.debugger?
|
103
|
-
|
104
|
-
notfound = []
|
105
|
-
params["items"].each do |barcode, item|
|
106
|
-
_product(barcode, false) or notfound << barcode
|
107
|
-
item[0] = item[0].to_i
|
108
|
-
item[1] = item[1].to_i
|
109
|
-
amount, cost = item
|
110
|
-
raise "You're funny." unless amount.integer?
|
111
|
-
end
|
112
|
-
|
113
|
-
raise ProductNotFound.new(notfound.join(', ')) unless notfound.empty?
|
114
|
-
|
115
|
-
Product.transaction do
|
116
|
-
params["items"].each do |barcode, data|
|
117
|
-
amount, cost = data
|
118
|
-
p = _product(barcode)
|
119
|
-
p.stock += amount
|
120
|
-
p.save
|
121
|
-
|
122
|
-
Purchase.create(:time => Time.now,
|
123
|
-
:debugger => debugger,
|
124
|
-
:product => p,
|
125
|
-
:count => amount,
|
126
|
-
:cost => cost)
|
127
|
-
|
128
|
-
Logger::log :purchase, :add, "%s purchased %d x '%s' for %0.2f" %
|
129
|
-
[ debugger.username, amount, p.name, cost ]
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
"OK"
|
134
|
-
end
|
135
|
-
|
136
|
-
def self.product_purchases(params)
|
137
|
-
p = params[:from_uri].first
|
138
|
-
if p.nil? or p == "all"
|
139
|
-
Purchase.find :all, :order => "product, time desc"
|
140
|
-
else
|
141
|
-
Purchase.find_all_by_barcode(p, :order => "product, time desc")
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
private
|
146
|
-
def self._product(barcode, complain=true)
|
147
|
-
Product.find(barcode, :include => [:purchases])
|
148
|
-
rescue
|
149
|
-
raise NotFound, "Product" if complain
|
150
|
-
nil
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
end
|
data/lib/bib.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
module Ig3tool
|
2
|
-
|
3
|
-
class BibSection < ActiveRecord::Base
|
4
|
-
|
5
|
-
set_table_name "bib_sections"
|
6
|
-
set_nonauto_primary_key :name
|
7
|
-
|
8
|
-
validates_presence_of :name, :full_name
|
9
|
-
|
10
|
-
validates_uniqueness_of :name
|
11
|
-
|
12
|
-
has_many :books,
|
13
|
-
:class_name => "BibBook",
|
14
|
-
:foreign_key => "section"
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
class BibBook < ActiveRecord::Base
|
19
|
-
|
20
|
-
set_table_name "bib_books"
|
21
|
-
set_nonauto_primary_key :isbn
|
22
|
-
|
23
|
-
validates_presence_of :isbn,
|
24
|
-
:title,
|
25
|
-
:author,
|
26
|
-
:publisher,
|
27
|
-
:section
|
28
|
-
|
29
|
-
validates_each :section do |record, attr, value|
|
30
|
-
begin
|
31
|
-
BibSection.find(value)
|
32
|
-
rescue
|
33
|
-
record.errors.add attr, "Invalid section: '#{value}'"
|
34
|
-
false
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
has_many :loans,
|
39
|
-
:class_name => "BibLoan",
|
40
|
-
:foreign_key => "isbn"
|
41
|
-
|
42
|
-
def available?
|
43
|
-
available > 0
|
44
|
-
end
|
45
|
-
|
46
|
-
def available
|
47
|
-
copies - loans.length
|
48
|
-
end
|
49
|
-
|
50
|
-
# ISBN-13 -> ISBN-10
|
51
|
-
def self._isbn13(code)
|
52
|
-
raise "Invalid ISBN-10 number!" if code.length != 10
|
53
|
-
code.chop!
|
54
|
-
code = "978" + code
|
55
|
-
|
56
|
-
sum = 0
|
57
|
-
code.split(//).each_with_index do |c, i|
|
58
|
-
sum += c.to_i * ( i % 2 == 0 ? 1 : 3 )
|
59
|
-
end
|
60
|
-
|
61
|
-
rem = sum % 10
|
62
|
-
check = (rem == 0) ? 0 : 10 - rem
|
63
|
-
|
64
|
-
code = code + check.to_s
|
65
|
-
end
|
66
|
-
|
67
|
-
# ISBN-10 -> ISBN-13
|
68
|
-
def self._isbn10(code)
|
69
|
-
raise "Invalid ISBN-13 number!" if code.length != 13
|
70
|
-
code = code[3..11]
|
71
|
-
|
72
|
-
sum = 0
|
73
|
-
9.times {|i| sum += code[i].chr.to_i * (10 - i) }
|
74
|
-
|
75
|
-
check = 11 - sum % 11
|
76
|
-
check = 0 if sum == 0
|
77
|
-
check = 'X' if check == 10
|
78
|
-
code = code + check.to_s
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
class BibLoan < ActiveRecord::Base
|
84
|
-
|
85
|
-
set_table_name "bib_loans"
|
86
|
-
|
87
|
-
validates_presence_of :isbn,
|
88
|
-
:member_id,
|
89
|
-
:warranty,
|
90
|
-
:loan_date
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
data/lib/billing.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
module Ig3tool
|
2
|
-
|
3
|
-
#
|
4
|
-
# Handige documentatie:
|
5
|
-
#
|
6
|
-
# Lesk, M.E.: "TBL -- A Program to Format Tables"
|
7
|
-
# http://www.cs.bell-labs.com/10thEdMan/tbl.pdf
|
8
|
-
#
|
9
|
-
# PIC -- A Graphics Language for Typesetting, Brian Kernighan
|
10
|
-
# http://www.cs.bell-labs.com/cm/cs/cstr/116.ps.gz
|
11
|
-
#
|
12
|
-
|
13
|
-
# dit is het billing gedoe
|
14
|
-
# om een fancy factuur uit te printen
|
15
|
-
# again thx to Peter
|
16
|
-
|
17
|
-
|
18
|
-
CONFIG = { 'groff' => 'groff -ma4 -p -t | gv -',
|
19
|
-
'groff_alt' => 'groff -ma4 -p -t -l -L-Pigprint@igwe' }
|
20
|
-
|
21
|
-
|
22
|
-
class Sales
|
23
|
-
|
24
|
-
def printout debugger
|
25
|
-
return if @sales.empty?
|
26
|
-
|
27
|
-
p = Person.find(:first, :conditions => ['username=?', debugger])
|
28
|
-
return unless p
|
29
|
-
debugger = p.firstname + " " + p.lastname
|
30
|
-
date = dutch_date
|
31
|
-
|
32
|
-
def to_groff (str)
|
33
|
-
gr = ''
|
34
|
-
str.unpack('U*').each do |c|
|
35
|
-
gr += c < 256 ? c.chr : sprintf('\[u%04X]', c)
|
36
|
-
end
|
37
|
-
return gr
|
38
|
-
end
|
39
|
-
|
40
|
-
groff = IO.popen(CONFIG["groff"], "w")
|
41
|
-
groff.print <<EOF
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
.TS
|
48
|
-
box, expand ;
|
49
|
-
l r
|
50
|
-
^ r .
|
51
|
-
T{
|
52
|
-
Infogroep
|
53
|
-
p/a Faculteit Wetenschappen
|
54
|
-
lokaal 1E8, tel. 02/629 33 56
|
55
|
-
Vrije Universiteit Brussel
|
56
|
-
T}\tBrussel, #{date}
|
57
|
-
\tT{
|
58
|
-
.PS
|
59
|
-
B: box height 1 width 3.3
|
60
|
-
.ps 8
|
61
|
-
" stempel" at B.sw above ljust
|
62
|
-
.ps 10
|
63
|
-
.PE
|
64
|
-
T}
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
.TE
|
69
|
-
.TS
|
70
|
-
box, expand ;
|
71
|
-
l | c | c
|
72
|
-
l | n | n .
|
73
|
-
Omschrijving artikels\tAantal\tPrijs
|
74
|
-
_
|
75
|
-
EOF
|
76
|
-
|
77
|
-
each do |s|
|
78
|
-
groff.printf("%s\t%d\t%.2f\n", to_groff(s.product.name), s.count, s.price)
|
79
|
-
end
|
80
|
-
|
81
|
-
groff.print <<EOF
|
82
|
-
_
|
83
|
-
.T&
|
84
|
-
l s nB .
|
85
|
-
T{
|
86
|
-
|
87
|
-
|
88
|
-
Voor Infogroep,
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
#{to_groff(debugger)}
|
93
|
-
T}\t#{sprintf '%.2f', total_price}
|
94
|
-
.TE
|
95
|
-
EOF
|
96
|
-
|
97
|
-
groff.close
|
98
|
-
end
|
99
|
-
|
100
|
-
def dutch_date
|
101
|
-
months = %w(_ januari februari maart april mei juni juli
|
102
|
-
augustus september oktober november december)
|
103
|
-
days = %w(zondag maandag dinsdag woensdag donderdag
|
104
|
-
vrijdag zaterdag zondag)
|
105
|
-
t = Time.now
|
106
|
-
"#{days[t.wday]} #{t.day} #{months[t.month]} #{t.year}"
|
107
|
-
end
|
108
|
-
private :dutch_date
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
data/lib/bitching.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'digest/md5'
|
2
|
-
|
3
|
-
module Ig3tool
|
4
|
-
|
5
|
-
class Bitch < ActiveRecord::Base
|
6
|
-
|
7
|
-
set_table_name "bitches"
|
8
|
-
|
9
|
-
validates_presence_of :crap, :bitch
|
10
|
-
|
11
|
-
validates_uniqueness_of :crap
|
12
|
-
|
13
|
-
def self.lookup(crap)
|
14
|
-
Bitch.find(:first, :conditions => ["crap = ?", crap])
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.bitch(crap)
|
18
|
-
Bitch.lookup(crap).bitch
|
19
|
-
end
|
20
|
-
|
21
|
-
def log_request(request)
|
22
|
-
r = Request.new
|
23
|
-
r.bitch = self.bitch
|
24
|
-
r.request = request
|
25
|
-
r.save
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.can_request?(crap)
|
29
|
-
not Bitch.lookup(crap).nil?
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.wannabe(user, pass)
|
33
|
-
# check if user isa ldap user
|
34
|
-
# generate some sort of token to auth with
|
35
|
-
raise Token, "you don't know the magic word..." unless IGLDAP.bitchke?(user, pass)
|
36
|
-
b = Bitch.new
|
37
|
-
b.bitch = user
|
38
|
-
#b.crap = user.crypt("$1$" + Time.now.strftime("%S%M"))
|
39
|
-
b.crap = Digest::MD5.hexdigest(user + Time.now.to_s)
|
40
|
-
b.save!
|
41
|
-
b.crap
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
|
data/lib/config.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Ig3tool
|
2
|
-
|
3
|
-
require 'yaml'
|
4
|
-
|
5
|
-
class Config
|
6
|
-
def Config.load(file)
|
7
|
-
begin
|
8
|
-
@@file = YAML.load_file(file)
|
9
|
-
rescue SystemCallError => boom
|
10
|
-
abort "Kon config file niet laden: #{boom.message}"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def Config.[](attribute)
|
15
|
-
@@file[attribute]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
data/lib/horrible_hack.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
class Base
|
3
|
-
# Deze methode laat toe TOCH primary keys te hebben.
|
4
|
-
def self.set_nonauto_primary_key(field)
|
5
|
-
set_primary_key field
|
6
|
-
define_method (field.to_s+"_before_type_cast").to_sym do; end
|
7
|
-
alias_method field.to_s+"=", :id=
|
8
|
-
end
|
9
|
-
|
10
|
-
def attributes_protected_by_default
|
11
|
-
[] # STERF.
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|