ig3tool 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. data/bin/ig3tool +17 -21
  2. data/lib/actions/bib.rb +295 -0
  3. data/lib/actions/bitching.rb +19 -0
  4. data/lib/actions/cultuur.rb +3 -0
  5. data/lib/actions/interne.rb +98 -0
  6. data/lib/actions/kaching.rb +90 -0
  7. data/lib/actions/people.rb +178 -0
  8. data/lib/actions/printing.rb +125 -0
  9. data/lib/actions/product.rb +154 -0
  10. data/lib/bib.rb +94 -0
  11. data/lib/billing.rb +112 -0
  12. data/lib/bitching.rb +49 -0
  13. data/lib/config.rb +19 -0
  14. data/lib/glade/cola_light_small.png +0 -0
  15. data/lib/glade/cola_light_xsmall.png +0 -0
  16. data/lib/glade/cola_small.png +0 -0
  17. data/lib/glade/cola_xsmall.png +0 -0
  18. data/lib/glade/doos_small.png +0 -0
  19. data/lib/glade/doos_xsmall.png +0 -0
  20. data/lib/glade/icons/cola_light_small.png +0 -0
  21. data/lib/glade/icons/cola_light_xsmall.png +0 -0
  22. data/lib/glade/icons/cola_small.png +0 -0
  23. data/lib/glade/icons/cola_xsmall.png +0 -0
  24. data/lib/glade/icons/doos_small.png +0 -0
  25. data/lib/glade/icons/doos_xsmall.png +0 -0
  26. data/lib/glade/icons/piggy_small.png +0 -0
  27. data/lib/glade/icons/piggy_xsmall.png +0 -0
  28. data/lib/glade/money_small.png +0 -0
  29. data/lib/glade/money_xsmall.png +0 -0
  30. data/lib/glade/newinterne.glade +504 -0
  31. data/lib/glade/piggy_small.png +0 -0
  32. data/lib/glade/piggy_xsmall.png +0 -0
  33. data/lib/glade/sales.glade +89 -87
  34. data/lib/horrible_hack.rb +15 -0
  35. data/lib/interne.rb +111 -0
  36. data/lib/ldap.rb +104 -0
  37. data/lib/log.rb +25 -0
  38. data/lib/membership.rb +32 -0
  39. data/lib/mymd5.rb +95 -0
  40. data/lib/people.rb +143 -0
  41. data/lib/printing.rb +238 -0
  42. data/lib/request.rb +14 -0
  43. data/lib/sales.rb +158 -0
  44. data/lib/ui/automaatwindow.rb +2 -2
  45. data/lib/ui/bibliotheekwindow.rb +16 -17
  46. data/lib/ui/bibwindow.rb +15 -15
  47. data/lib/ui/gladehelper.rb +20 -6
  48. data/lib/ui/internewindow.rb +12 -9
  49. data/lib/ui/loginwindow.rb +2 -4
  50. data/lib/ui/memberswindow.rb +9 -9
  51. data/lib/ui/newinterne.rb +258 -0
  52. data/lib/ui/peoplewindow.rb +14 -16
  53. data/lib/ui/printenwindow.rb +11 -11
  54. data/lib/ui/printingwindow.rb +19 -20
  55. data/lib/ui/productswindow.rb +27 -15
  56. data/lib/ui/saleswindow.rb +21 -8
  57. data/lib/ui/toolwindow.rb +5 -3
  58. data/lib/utils.rb +106 -0
  59. data/lib/web.rb +98 -0
  60. metadata +48 -3
data/lib/request.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Ig3tool
2
+
3
+ class Request < ActiveRecord::Base
4
+
5
+ set_table_name "requests"
6
+
7
+ validates_presence_of :request, :bitch
8
+
9
+ end
10
+
11
+ end
12
+
13
+
14
+
data/lib/sales.rb ADDED
@@ -0,0 +1,158 @@
1
+ module Ig3tool
2
+
3
+ class Category < ActiveRecord::Base
4
+
5
+ set_table_name "categories"
6
+
7
+ set_nonauto_primary_key :name
8
+
9
+ validates_uniqueness_of :name
10
+
11
+ validates_presence_of :name
12
+
13
+ has_many :products,
14
+ :class_name => "Product",
15
+ :foreign_key => "category"
16
+
17
+ end
18
+
19
+
20
+ class Product < ActiveRecord::Base
21
+
22
+ set_table_name "products"
23
+
24
+ set_nonauto_primary_key :barcode
25
+
26
+ validates_uniqueness_of :barcode
27
+
28
+ validates_presence_of :barcode,
29
+ :stock,
30
+ :category,
31
+ :nmprice,
32
+ :mprice,
33
+ :dprice,
34
+ :name
35
+
36
+ # validates_inclusion_of :category, :in => Category.find(:all)
37
+
38
+ # attr_protected :stock
39
+
40
+ has_many :sales,
41
+ :class_name => "Sale",
42
+ :foreign_key => "product"
43
+
44
+ has_many :purchases,
45
+ :class_name => "Purchase",
46
+ :foreign_key => "product"
47
+
48
+ # has_one :category,
49
+ # :class_name => "Category",
50
+ # :foreign_key => "category"
51
+
52
+ validate :nmprice,
53
+ :mprice,
54
+ :dprice
55
+ # XXX dit borkt :(
56
+ #, { :nmprice < :mprice and :mprice < :dprice}
57
+
58
+ before_save do |obj|
59
+ m = obj.mprice
60
+ nm = obj.nmprice
61
+ d = obj.dprice
62
+ obj.mprice = m = [m, d].max
63
+ obj.nmprice = [m, nm].max
64
+ end
65
+
66
+ def price(status, count = 1)
67
+ count *
68
+ case status
69
+ when "member"
70
+ mprice
71
+ when "debugger"
72
+ dprice
73
+ when "plebs", "non-member", "non member"
74
+ nmprice
75
+ else
76
+ # XXX of willen we hier een exception gooien?
77
+ warn "Invalid status: '#{status}'"
78
+ nmprice
79
+ end
80
+ end
81
+
82
+ def decrement_stock(amount)
83
+ transaction do
84
+ if stock >= amount
85
+ update_attribute("stock", stock - amount)
86
+ save
87
+ else
88
+ # XXX handle this bitch
89
+ # we willen niet onder 0 gaan :)
90
+ update_attribute("stock", 0)
91
+ end
92
+
93
+ purchases = Purchase.find_all_by_product(barcode,
94
+ :conditions => [ "current > 0"],
95
+ :order => "time")
96
+
97
+ while amount > 0
98
+ if purchases.empty?
99
+ warn "stock corrupt: #{amount} items of #{barcode} - #{name} missing"
100
+ break
101
+ else
102
+ p = purchases.shift
103
+
104
+ amt = p.current - amount
105
+ if amt < 0
106
+ amount = amt.abs
107
+ amt = 0
108
+ else
109
+ amount = 0
110
+ end
111
+
112
+ p.current = amt
113
+ p.save
114
+ end
115
+ end
116
+ reload
117
+ end
118
+ end
119
+
120
+ def increase_stock(amount)
121
+ # XXX mag enkel gebruikt worden bij de purchases?
122
+ end
123
+
124
+ end
125
+
126
+ class Sale < ActiveRecord::Base
127
+ # een verkoop
128
+
129
+ set_table_name "sales"
130
+
131
+ end
132
+
133
+ class Purchase < ActiveRecord::Base
134
+ # een aankoop
135
+
136
+ set_table_name "purchases"
137
+
138
+ belongs_to :product, :class_name => "Product", :foreign_key => "product"
139
+ belongs_to :debugger, :class_name => "Person", :foreign_key => "debugger"
140
+
141
+ validates_presence_of :debugger, :product, :count, :cost
142
+ validates_numericality_of :count, :cost
143
+
144
+ before_save do |obj|
145
+ obj.current = [obj.count, 0].max if obj.current.nil?
146
+ obj.time = Time.now if obj.time.nil?
147
+ end
148
+
149
+ after_create do |obj|
150
+ p = obj.product
151
+ p.stock += current
152
+ p.save
153
+ # p.recalculate_price # XXX wishful thinking :)
154
+ end
155
+
156
+ end
157
+
158
+ end
@@ -2,7 +2,7 @@ module Ig3tool
2
2
 
3
3
  class VendingMachineWindow < GladeHelper
4
4
  MENU_PATH = ["Automaat"]
5
- ICON = "cola.png"
5
+ ICON = "cola_xsmall.png"
6
6
 
7
7
  BLIKJES = [
8
8
  [ "Coca Cola", "5449000000996" ],
@@ -83,7 +83,7 @@ module Ig3tool
83
83
  end
84
84
 
85
85
  begin
86
- total = $global['client'].product_restock!( :debugger => debugger.username,
86
+ total = $client.product_restock!( :debugger => debugger.username,
87
87
  :items => items)
88
88
  rescue Exception => e
89
89
  _print_msg "Fout: Verkopen: #{$!}"
@@ -2,7 +2,7 @@ require 'time'
2
2
 
3
3
  begin
4
4
  require "amazon/search"
5
- $global['amazon_loaded'] = true
5
+ $amazon_loaded = 1
6
6
  rescue Exception => e
7
7
  STDERR.puts "Ruby/Amazon kon niet geladen worden: " + e.to_s
8
8
  end
@@ -27,8 +27,7 @@ module Ig3tool
27
27
 
28
28
  super("bibliotheek.glade")
29
29
 
30
- # @c = Client.new("infogroep.be")
31
- @c = $global["client"]
30
+ # $client = Client.new("infogroep.be")
32
31
 
33
32
  @tabs = @glade.get_widget("tabs")
34
33
 
@@ -124,7 +123,7 @@ module Ig3tool
124
123
  # if @books_section.active_iter[0].nil?
125
124
  # books = nil
126
125
  # else
127
- # books = @c.bib_lookup({"section" => @books_section.active_iter[0].name})
126
+ # books = $client.bib_lookup({"section" => @books_section.active_iter[0].name})
128
127
  # end
129
128
  # _update_books_list(books)
130
129
  #end
@@ -152,7 +151,7 @@ module Ig3tool
152
151
  def books_save(widget)
153
152
  puts "-> books_save"
154
153
  begin
155
- @c.bib_add!(get_fields)
154
+ $client.bib_add!(get_fields)
156
155
  _update_books_list
157
156
  #books_clear
158
157
  @books_notification.text = "changes saved to book!"
@@ -165,7 +164,7 @@ module Ig3tool
165
164
  def loan_extend(widget)
166
165
  puts "-> loan_extend"
167
166
  begin
168
- @c.bib_extend!(get_loan_fields)
167
+ $client.bib_extend!(get_loan_fields)
169
168
  _update_loan_list
170
169
  loan_clear(nil)
171
170
  @loan_notification.text = "the ig3tool imps extend the book for 3 weeks..."
@@ -182,7 +181,7 @@ module Ig3tool
182
181
  def loan_return(widget)
183
182
  puts "-> loan_return"
184
183
  begin
185
- @c.bib_return!(get_loan_fields)
184
+ $client.bib_return!(get_loan_fields)
186
185
  _update_loan_list
187
186
  loan_clear(nil)
188
187
  @loan_notification.text = "book returned to the ig3tool imps..."
@@ -195,7 +194,7 @@ module Ig3tool
195
194
  def books_delete(widget)
196
195
  puts "-> books_delete"
197
196
  begin
198
- @c.bib_remove!(get_fields)
197
+ $client.bib_remove!(get_fields)
199
198
  _update_books_list
200
199
  reset_books_fields
201
200
  @books_notification.text = "the ig3tool imps trashed the book..."
@@ -244,7 +243,7 @@ module Ig3tool
244
243
  def loan_isbn_set(widget)
245
244
  puts "-> loan_isbn_set"
246
245
  begin
247
- book = @c.bib_info(@loan_isbn.text)
246
+ book = $client.bib_info(@loan_isbn.text)
248
247
  raise Exception, "the ig3tool imps found no such book..." if book.nil?
249
248
  _show(book)
250
249
  #@loan_title.text = book.title
@@ -260,7 +259,7 @@ module Ig3tool
260
259
  puts "start find"
261
260
  Thread.new do
262
261
  begin
263
- books = @c.bib_lookup(get_fields)
262
+ books = $client.bib_lookup(get_fields)
264
263
  if books.size == 1
265
264
  puts "find 1"
266
265
  _show(books.first)
@@ -312,7 +311,7 @@ module Ig3tool
312
311
  puts "-> loan_loan"
313
312
  @loan_notification.text = ""
314
313
  begin
315
- @c.bib_loan!(get_loan_fields)
314
+ $client.bib_loan!(get_loan_fields)
316
315
  _update_loan_list
317
316
  loan_clear(nil)
318
317
  rescue Exception => e
@@ -334,7 +333,7 @@ module Ig3tool
334
333
 
335
334
 
336
335
  def _lookup_amazon_isbn (isbn)
337
- return false unless $global['amazon_loaded'] # Indien de amazon gem niet geladen is, return
336
+ return false unless $amazon_loaded # Indien de amazon gem niet geladen is, return
338
337
  return false unless _isbn?(true,isbn) # Indien strenge test faalt
339
338
 
340
339
  if isbn.length == 13 # indien in de nieuwe vorm, maak er een oude van
@@ -351,7 +350,7 @@ module Ig3tool
351
350
 
352
351
  # You need a amazon-dev-token in client.rb
353
352
  token = CONFIG['amazon-dev-token']
354
- return unless $global['amazon_loaded'] and token.instance_of?(String) and not token.empty?
353
+ return unless $amazon_loaded and token.instance_of?(String) and not token.empty?
355
354
 
356
355
  begin
357
356
  req = Amazon::Search::Request.new(CONFIG["amazon-dev-token"],CONFIG["amazon-associates-id"])
@@ -382,7 +381,7 @@ module Ig3tool
382
381
  @books_year.text = book["year"]
383
382
  @books_copies.text = book["copies"]
384
383
  _update_sections
385
- sections = @c.bib_sections.collect{|b| b.name}
384
+ sections = $client.bib_sections.collect{|b| b.name}
386
385
  index = sections.index book.section
387
386
  @books_section.active = index+1
388
387
  end
@@ -392,7 +391,7 @@ module Ig3tool
392
391
  @books_notification.text = "loading books..."
393
392
  @books_list_store.clear if clear
394
393
  Thread.new do
395
- books = @c.bib_books if books.nil?
394
+ books = $client.bib_books if books.nil?
396
395
  unless books.empty?
397
396
  books.each do |b|
398
397
  @books_list_store.append[0] = b
@@ -411,7 +410,7 @@ module Ig3tool
411
410
  puts "-> _update_loan_list"
412
411
  @loan_list_store.clear if clear
413
412
  Thread.new do
414
- loans = @c.bib_loans
413
+ loans = $client.bib_loans
415
414
  loans.each do |b|
416
415
  @loan_list_store.append[0] = b
417
416
  end
@@ -422,7 +421,7 @@ module Ig3tool
422
421
 
423
422
  def _update_sections
424
423
  puts "-> _update_sections"
425
- sections = @c.bib_sections
424
+ sections = $client.bib_sections
426
425
  sections_model = Gtk::ListStore.new(Object, String)
427
426
 
428
427
  empty = sections_model.append
data/lib/ui/bibwindow.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  begin
2
2
  require "amazon/search"
3
- $global['amazon_loaded'] = true
3
+ $amazon_loaded = 1
4
4
  rescue Exception => e
5
5
  STDERR.puts "Ruby/Amazon kon niet geladen worden: " + e.to_s
6
6
  end
@@ -156,7 +156,7 @@ module Ig3tool
156
156
  _fill_booklist
157
157
  else
158
158
  begin
159
- books = $global["client"].bib_lookup attrs
159
+ books = $client.bib_lookup attrs
160
160
  _set_booklist(books)
161
161
  rescue Exception => e
162
162
  _print_msg "Fout: Lookup Clicked: #{$!}"
@@ -186,7 +186,7 @@ module Ig3tool
186
186
  end
187
187
 
188
188
  begin
189
- answer = $global['client'].bib_add! _get_book
189
+ answer = $client.bib_add! _get_book
190
190
  rescue Exception => e
191
191
  _print_msg "Fout: Toevoegen: #{$!}"
192
192
  else
@@ -219,7 +219,7 @@ module Ig3tool
219
219
  end
220
220
 
221
221
  begin
222
- answer = $global['client'].bib_loan!({:isbn => @loan_isbn_entry.text,
222
+ answer = $client.bib_loan!({:isbn => @loan_isbn_entry.text,
223
223
  :member => @loan_memberid_entry.text,
224
224
  :warranty => @loan_warranty_entry.text })
225
225
  rescue Exception => e
@@ -303,7 +303,7 @@ module Ig3tool
303
303
  end
304
304
 
305
305
  def _lookup_amazon_isbn (isbn)
306
- return false unless $global['amazon_loaded'] # Indien de amazon gem niet geladen is, return
306
+ return false unless $amazon_loaded # Indien de amazon gem niet geladen is, return
307
307
  return false unless _isbn?(true,isbn) # Indien strenge test faalt
308
308
 
309
309
  if isbn.length == 13 # indien in de nieuwe vorm, maak er een oude van
@@ -320,7 +320,7 @@ module Ig3tool
320
320
 
321
321
  # You need a amazon-dev-token in client.rb
322
322
  token = CONFIG['amazon-dev-token']
323
- return unless $global['amazon_loaded'] and token.instance_of?(String) and not token.empty?
323
+ return unless $amazon_loaded and token.instance_of?(String) and not token.empty?
324
324
 
325
325
  begin
326
326
  req = Amazon::Search::Request.new(CONFIG["amazon-dev-token"],CONFIG["amazon-associates-id"])
@@ -340,7 +340,7 @@ module Ig3tool
340
340
 
341
341
  def _lookup_database_isbn(isbn)
342
342
  begin
343
- answer = $global['client'].bib_books( [ isbn ] )
343
+ answer = $client.bib_books( [ isbn ] )
344
344
  rescue Exception => e
345
345
  _print_msg "Fout: Lookup: #{$!}", "ISBN: #{isbn}"
346
346
  nil
@@ -425,7 +425,7 @@ module Ig3tool
425
425
 
426
426
  # Haal de boeken op van de server
427
427
  begin
428
- answer = $global['client'].bib_books
428
+ answer = $client.bib_books
429
429
  _set_booklist(answer)
430
430
  rescue Exception => e
431
431
  _print_msg "Fout: Fill-Booklist: #{$!}"
@@ -455,9 +455,9 @@ module Ig3tool
455
455
  # Haal de uitgeleende boeken op van de server
456
456
  begin
457
457
  if memberid
458
- answer = $global['client'].bib_loans( [ memberid ] ) # Indien een memberid geselecteerd
458
+ answer = $client.bib_loans( [ memberid ] ) # Indien een memberid geselecteerd
459
459
  else
460
- answer = $global['client'].bib_loans # Alle loans weergeven indien niet
460
+ answer = $client.bib_loans # Alle loans weergeven indien niet
461
461
  end
462
462
  rescue Exception => e
463
463
  _print_msg "Fout: Fill-Loan-Booklist: #{$!}", "Memberid: #{memberid}"
@@ -467,8 +467,8 @@ module Ig3tool
467
467
  # Answer is een BookLoan
468
468
  @books_loan_view.model = nil # Performance issues
469
469
  for bookloan in answer
470
- book = $global['client'].bib_info( [bookloan.isbn] ) # Haal de info op over het boek
471
- person = $global['client'].person_member( [bookloan.member_id] ) # Haal de persoon op
470
+ book = $client.bib_info( [bookloan.isbn] ) # Haal de info op over het boek
471
+ person = $client.person_member( [bookloan.member_id] ) # Haal de persoon op
472
472
  if person.nil? or book.nil?
473
473
  _print_msg "Fout: Fill-Loan-Booklist: #{$!}", "BookLoan: #{bookloan}, Book: #{book}, Person: #{person}"
474
474
  return
@@ -492,7 +492,7 @@ module Ig3tool
492
492
  def _delete_book(isbn)
493
493
  return unless isbn.nil?
494
494
  begin
495
- answer = $global['client'].bib_remove!( { :isbn => @isbn } )
495
+ answer = $client.bib_remove!( { :isbn => @isbn } )
496
496
  rescue Exception => e
497
497
  _print_msg "Fout: Verwijderen: #{$!}"
498
498
  else
@@ -504,7 +504,7 @@ module Ig3tool
504
504
 
505
505
  def _loan_verlengen(isbn, memberid)
506
506
  begin
507
- answer = $global['client'].bib_extend!({ :isbn => isbn,
507
+ answer = $client.bib_extend!({ :isbn => isbn,
508
508
  :member => memberid })
509
509
  returndate = Time.at(answer.return_date).to_s
510
510
  rescue Exception => e
@@ -516,7 +516,7 @@ module Ig3tool
516
516
 
517
517
  def _loan_terugbrengen(isbn, memberid)
518
518
  begin
519
- answer = $global['client'].bib_return!( { :isbn => isbn,
519
+ answer = $client.bib_return!( { :isbn => isbn,
520
520
  :member => memberid })
521
521
  rescue Exception => e
522
522
  _print_msg "Fout: Return: #{$!}", "#{isbn},#{memberid}"
@@ -31,7 +31,7 @@ module Ig3tool
31
31
 
32
32
  # Debugger combobox invullen
33
33
  def make_debugger_combo (combo, window = nil)
34
- debuggers = $global["client"].person_debuggers
34
+ debuggers = $client.person_debuggers
35
35
  debuggers.sort! {|a,b| a.username <=> b.username }
36
36
 
37
37
  debugger_model = Gtk::ListStore.new(Object, String)
@@ -42,7 +42,6 @@ module Ig3tool
42
42
  end
43
43
 
44
44
  combo.model = debugger_model
45
- combo.active = 0
46
45
  combo.clear
47
46
  renderer = Gtk::CellRendererText.new
48
47
  combo.pack_start(renderer, true)
@@ -50,12 +49,20 @@ module Ig3tool
50
49
 
51
50
  # Indien het window gekleurd moet worden adhv zijn 'interne' status
52
51
  add_window_colorer(combo, window) if window
52
+
53
+ username = $client.username
54
+ debugger_model.each do |m, p, i|
55
+ if i[1] == username
56
+ combo.active_iter = i
57
+ break
58
+ end
59
+ end
53
60
  end
54
61
 
55
62
  # Status combobox invullen
56
63
  def make_status_combo (combo,statussen = nil)
57
64
  begin
58
- statussen = $global["client"].person_statussen unless statussen
65
+ statussen = $client.person_statussen unless statussen
59
66
  statussen_model = Gtk::ListStore.new(Object, String)
60
67
  statussen.each do |key, value|
61
68
  row = statussen_model.append
@@ -75,12 +82,19 @@ module Ig3tool
75
82
 
76
83
  def add_window_colorer(combo, window)
77
84
  combo.signal_connect("changed") do
85
+ saldo = 0
78
86
  if combo.active_iter
79
87
  debugger = combo.active_iter[1]
80
- saldo = $global["client"].interne(debugger)
81
- else
82
- saldo = 0
88
+ if debugger != "kas"
89
+ begin
90
+ saldo = $client.interne(debugger).saldo.to_i
91
+ rescue Exception => e
92
+ # ignore
93
+ puts e.to_s + " - " + e.message
94
+ end
95
+ end
83
96
  end
97
+
84
98
  if saldo < 0
85
99
  shade = [65535, 0, 0]
86
100
  ratio = (saldo < -7500) ? 1 : Rational(saldo,(-75 * 100)) # In cent + Need rational!