ig3tool 0.2.1 → 0.3.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.
data/lib/ui/protjes.rb ADDED
@@ -0,0 +1,850 @@
1
+ require 'time'
2
+
3
+
4
+ module Ig3tool
5
+
6
+ class ProtjesGlade < GladeHelper
7
+
8
+ MENU_PATH = ["Producten", "Producten"]
9
+ ICON = "doos_xsmall.png"
10
+
11
+ attr :glade
12
+
13
+ def initialize
14
+ super("protjes.glade")
15
+ @tabs = @glade.get_widget("tabs")
16
+
17
+ # MANAGE TAB
18
+ @manage_debuggers = @glade.get_widget("add_debuggers")
19
+ @manage_plebs = @glade.get_widget("add_plebs")
20
+ @manage_members = @glade.get_widget("add_members")
21
+ @manage_edit = @glade.get_widget("add_edit")
22
+ @add_notification = @glade.get_widget("add_notification")
23
+ @add_barcode = @glade.get_widget("add_barcode")
24
+ @add_name = @glade.get_widget("add_name")
25
+ @add_stock = @glade.get_widget("add_stock")
26
+ @add_prodcat = @glade.get_widget("add_prodcat")
27
+ @add_categories = @glade.get_widget("add_categories")
28
+
29
+ @categories = $client.product_categories.collect {|x| x.name}.sort
30
+
31
+
32
+ @add_products = @glade.get_widget("add_products")
33
+ @add_products.model = @add_products_store = Gtk::ListStore.new(Object, String)
34
+ l = Gtk::CellRendererText.new
35
+ @add_products.insert_column(-1, "product", l, :text => 1)
36
+ @add_products.enable_search = true
37
+
38
+
39
+
40
+ # PURCHASE TAB
41
+ @purchase_debuggers_orig = @glade.get_widget("purchase_debuggers_orig")
42
+ @purchase_plebs_orig = @glade.get_widget("purchase_plebs_orig")
43
+ @purchase_members_orig = @glade.get_widget("purchase_members_orig")
44
+ @purchase_debugger = @glade.get_widget("purchase_debugger")
45
+ @purchase_debuggers = @glade.get_widget("purchase_debuggers")
46
+ @purchase_plebs = @glade.get_widget("purchase_plebs")
47
+ @purchase_members = @glade.get_widget("purchase_members")
48
+ @purchase_barcode = @glade.get_widget("purchase_barcode")
49
+ @purchase_name = @glade.get_widget("purchase_name")
50
+ @purchase_stock = @glade.get_widget("purchase_stock")
51
+ @purchase_category = @glade.get_widget("purchase_category")
52
+ @purchase_categories = @glade.get_widget("purchase_categories")
53
+ @purchase_notification = @glade.get_widget("purchase_notification")
54
+ @purchase_amount = @glade.get_widget("purchase_amount")
55
+ @purchase_price = @glade.get_widget("purchase_price")
56
+ @purchase_date = @glade.get_widget("purchase_date")
57
+ @purchase_accept = @glade.get_widget("purchase_accept")
58
+
59
+ @purchase_products = @glade.get_widget("purchase_products")
60
+ @purchase_products.model = @purchase_products_store = Gtk::ListStore.new(Object, String)
61
+ l = Gtk::CellRendererText.new
62
+ @purchase_products.insert_column(-1, "product", l, :text => 1)
63
+ @purchase_products.enable_search = true
64
+
65
+ # STOCK TAB
66
+ @stock_notification = @glade.get_widget("stock_notification")
67
+ @stock_categories = @glade.get_widget("stock_categories")
68
+ @stock_barcode = @glade.get_widget("stock_barcode")
69
+ @stock_stock = @glade.get_widget("stock_stock")
70
+ @stock_category = @glade.get_widget("stock_category")
71
+ @stock_name = @glade.get_widget("stock_name")
72
+ @stock_debugger = @glade.get_widget("stock_debugger")
73
+ @stock_stock_new = @glade.get_widget("stock_stock_new")
74
+ @stock_apply = @glade.get_widget("stock_apply")
75
+
76
+ @stock_products = @glade.get_widget("stock_products")
77
+ @stock_products.model = @stock_products_store = Gtk::ListStore.new(Object, String)
78
+ l = Gtk::CellRendererText.new
79
+ @stock_products.insert_column(-1, "product", l, :text => 1)
80
+ @stock_products.enable_search = true
81
+
82
+ # LOG TAB
83
+ @log_notification = @glade.get_widget("log_notification")
84
+ @log_categories = @glade.get_widget("log_categories")
85
+ @log_barcode = @glade.get_widget("log_barcode")
86
+ @log_name = @glade.get_widget("log_name")
87
+ @log_products = @glade.get_widget("log_products")
88
+ @log_products.model = @log_products_store = Gtk::ListStore.new(Object, String)
89
+ l = Gtk::CellRendererText.new
90
+ @log_products.insert_column(-1, "product", l, :text => 1)
91
+ @log_products.enable_search = true
92
+
93
+
94
+ @purchase_log = @glade.get_widget("purchase_log")
95
+ @purchase_log.model = @purchase_log_store = Gtk::ListStore.new(Object, String, String, String, String, String)
96
+ l = Gtk::CellRendererText.new
97
+ @purchase_log.insert_column(-1, "time", l) do |tvc, cell, m, iter|
98
+ cell.text = Time.parse(iter[0].time).strftime("%d/%m/%y")
99
+ end
100
+ @purchase_log.insert_column(-1, "barcode", l) do |tvc, cell, m, iter|
101
+ cell.text = iter[0].product
102
+ end
103
+ @purchase_log.insert_column(-1, "debugger", l) do |tvc, cell, m, iter|
104
+ cell.text = iter[0].debugger
105
+ end
106
+ @purchase_log.insert_column(-1, "amount", l) do |tvc, cell, m, iter|
107
+ cell.text = iter[0].count
108
+ end
109
+ @purchase_log.insert_column(-1, "price", l) do |tvc, cell, m, iter|
110
+ cell.text = iter[0].cost
111
+ end
112
+
113
+ # sales LOG TAB
114
+ @slog_notification = @glade.get_widget("slog_notification")
115
+ @slog_categories = @glade.get_widget("slog_categories")
116
+ @slog_barcode = @glade.get_widget("slog_barcode")
117
+ @slog_name = @glade.get_widget("slog_name")
118
+ @slog_products = @glade.get_widget("slog_products")
119
+ @slog_products.model = @slog_products_store = Gtk::ListStore.new(Object, String)
120
+ l = Gtk::CellRendererText.new
121
+ @slog_products.insert_column(-1, "product", l, :text => 1)
122
+ @slog_products.enable_search = true
123
+
124
+
125
+ @spurchase_log = @glade.get_widget("spurchase_log")
126
+ @spurchase_log.model = @spurchase_log_store = Gtk::ListStore.new(Object, String, String, String, String, String, String)
127
+ l = Gtk::CellRendererText.new
128
+ @spurchase_log.insert_column(-1, "time", l) do |tvc, cell, m, iter|
129
+ cell.text = Time.parse(iter[0].time).strftime("%d/%m/%y")
130
+ end
131
+ @spurchase_log.insert_column(-1, "barcode", l) do |tvc, cell, m, iter|
132
+ cell.text = iter[0].product
133
+ end
134
+ @spurchase_log.insert_column(-1, "debugger", l) do |tvc, cell, m, iter|
135
+ cell.text = iter[0].debugger
136
+ end
137
+ @spurchase_log.insert_column(-1, "status", l) do |tvc, cell, m, iter|
138
+ cell.text = iter[0].status
139
+ end
140
+ @spurchase_log.insert_column(-1, "amount", l) do |tvc, cell, m, iter|
141
+ cell.text = iter[0].count
142
+ end
143
+ @spurchase_log.insert_column(-1, "price", l) do |tvc, cell, m, iter|
144
+ cell.text = iter[0].price
145
+ end
146
+
147
+
148
+
149
+
150
+
151
+ # ALL
152
+
153
+ cat_model = Gtk::ListStore.new(String)
154
+ cat2_model = Gtk::ListStore.new(String)
155
+ cat3_model = Gtk::ListStore.new(String)
156
+ cat4_model = Gtk::ListStore.new(String)
157
+ cat5_model = Gtk::ListStore.new(String)
158
+ cat6_model = Gtk::ListStore.new(String)
159
+ cat_model.prepend[0] = "all products"
160
+ cat3_model.prepend[0] = "all products"
161
+ cat4_model.prepend[0] = "all products"
162
+ cat5_model.prepend[0] = "all products"
163
+ cat6_model.prepend[0] = "all products"
164
+ @categories.each do |cat|
165
+ r = cat_model.append
166
+ r[0] = cat
167
+ r2 = cat2_model.append
168
+ r2[0] = cat
169
+ r3 = cat3_model.append
170
+ r3[0] = cat
171
+ r4 = cat4_model.append
172
+ r4[0] = cat
173
+ r5 = cat5_model.append
174
+ r5[0] = cat
175
+ r6 = cat6_model.append
176
+ r6[0] = cat
177
+ end
178
+ @add_categories.model = cat_model
179
+ @add_categories.active = 0
180
+ @add_prodcat.model = cat2_model
181
+ @add_prodcat.active = -1
182
+ @purchase_categories.model = cat3_model
183
+ @purchase_categories.active = 0
184
+ @stock_categories.model = cat4_model
185
+ @stock_categories.active = 0
186
+ @log_categories.model = cat5_model
187
+ @log_categories.active = 0
188
+ @slog_categories.model = cat6_model
189
+ @slog_categories.active = 0
190
+
191
+ toggle_purchase_fields(false)
192
+ _add_clear
193
+ _purchase_clear
194
+
195
+ #signal handlers
196
+ @handler1 = @add_barcode.signal_connect("changed"){ barcode_changed }
197
+ @handler2 = @purchase_barcode.signal_connect("changed"){ barcode_changed }
198
+ @handler3 = @stock_barcode.signal_connect("changed"){ barcode_changed }
199
+ @handler6 = @log_barcode.signal_connect("changed"){ barcode_changed }
200
+ @handler7 = @log_barcode.signal_connect("activate"){ _log_show(@log_barcode.text.strip) ; _update_log(@log_barcode.text.strip) }
201
+
202
+ @handler4 = @purchase_price.signal_connect("changed"){ price_amount_changed }
203
+ @handler5 = @purchase_amount.signal_connect("changed"){ price_amount_changed }
204
+
205
+ #@handler8 = @add_categories.signal_connect("changed"){ refresh }
206
+ @handler9 = @purchase_categories.signal_connect("changed"){ refresh }
207
+ @handler10 = @stock_categories.signal_connect("changed"){ refresh }
208
+ @handler11 = @log_categories.signal_connect("changed"){ refresh }
209
+ @handler12 = @slog_categories.signal_connect("changed"){ refresh }
210
+
211
+ @handler15 = @slog_barcode.signal_connect("changed"){ barcode_changed }
212
+ @handler16 = @slog_barcode.signal_connect("activate"){ _slog_show(@log_barcode.text.strip) ; _update_slog(@log_barcode.text.strip) }
213
+
214
+ make_debugger_combo(@purchase_debugger)
215
+ make_debugger_combo(@stock_debugger)
216
+
217
+ end
218
+
219
+ def get_debugger(widget)
220
+ widget.active_iter[0]
221
+ end
222
+
223
+ def price_amount_changed
224
+ amount = @purchase_amount.text.strip.to_i
225
+ price = @purchase_price.text.strip.to_c
226
+ amount = @purchase_amount.text.strip.to_i
227
+ @purchase_notification.text = "please enter a valid amount" if amount == 0
228
+ @purchase_notification.text = "please enter a valid price (in euro's)" if price == 0
229
+ if amount != 0 and price != 0
230
+ begin
231
+ @purchase_notification.text = ""
232
+ old = @purchase_debuggers_orig.text
233
+ oldm = @purchase_members_orig.text
234
+ oldp = @purchase_plebs_orig.text
235
+ new = price.to_f / amount.to_f
236
+ memb_ratio = (oldm.to_f / old.to_f)
237
+ plebs_ratio = (oldp.to_f / old.to_f)
238
+ newp = (new.to_f * plebs_ratio).to_i
239
+ newm = (new.to_f * memb_ratio).to_i
240
+ @purchase_debuggers.text = new.to_i.from_c.to_s
241
+ @purchase_members.text = afronden(newm).from_c.to_s
242
+ @purchase_plebs.text = afronden(newp).from_c.to_s
243
+ @purchase_accept.active = true
244
+ rescue Exception => e
245
+ @purchase_debuggers.text = new.to_i.from_c.to_s
246
+ @purchase_members.text = afronden(new.to_i).from_c.to_s
247
+ @purchase_plebs.text = afronden(new.to_i).from_c.to_s
248
+ @purchase_notification.text = "no (smart) price suggestions could be made"
249
+ end
250
+ end
251
+ end
252
+
253
+ def afronden(i)
254
+ m = i % 5
255
+ case m
256
+ when 0
257
+ i
258
+ when 1
259
+ i - 1
260
+ when 2
261
+ i - 2
262
+ when 3
263
+ i + 2
264
+ when 4
265
+ i + 1
266
+ end
267
+ end
268
+
269
+
270
+
271
+ def purchase
272
+ begin
273
+ if @purchase_accept.active?
274
+ barcode = @purchase_barcode.text.strip
275
+ $client.product_save!("barcode" => barcode, "dprice" => @purchase_debuggers.text.strip.to_c, "mprice" => @purchase_members.text.strip.to_c, "nmprice" => @purchase_plebs.text.strip.to_c)
276
+ end
277
+
278
+ $client.product_purchase!("debugger" => get_debugger(@purchase_debugger).username, "date" => @purchase_date.text.strip, "barcode" => @purchase_barcode.text.strip, "amount" => @purchase_amount.text.strip.to_i, "price" => @purchase_price.text.strip.to_c)
279
+ _purchase_clear
280
+ @purchase_notification.text = "the imps noted this purchase..."
281
+ rescue Exception => e
282
+ @purchase_notification.text = e.message
283
+ end
284
+ end
285
+
286
+ def members_act(widget)
287
+ end
288
+
289
+ def barcode_ins(widget, arg0, arg1, arg2)
290
+ end
291
+
292
+ def barcode_del(widget, arg0, arg1)
293
+ end
294
+
295
+ def barcode_changed()
296
+ case @tabs.page
297
+ when 0
298
+ _purchase_clear(false)
299
+ toggle_purchase_fields(false)
300
+ when 1
301
+ _purchase_clear(false)
302
+ toggle_purchase_fields(false)
303
+ when 2
304
+ _stock_clear(false)
305
+ toggle_stock_field(false)
306
+ when 3
307
+ _log_clear(false)
308
+ when 4
309
+ _slog_clear(false)
310
+ end
311
+ end
312
+
313
+ def toggle_price_fields(from_save, bool=nil)
314
+ bool = (not @manage_debuggers.sensitive?) if bool.nil?
315
+ @manage_debuggers.sensitive = bool
316
+ @manage_debuggers.editable = bool
317
+ @manage_plebs.sensitive = bool
318
+ @manage_plebs.editable = bool
319
+ @manage_members.sensitive = bool
320
+ @manage_members.editable = bool
321
+ if bool
322
+ @manage_edit.image = Gtk::Image.new(Gtk::Stock::SAVE, Gtk::IconSize::BUTTON)
323
+ @manage_edit.label = Gtk::Stock::SAVE
324
+ else
325
+ unless from_save
326
+ begin
327
+ barcode = @add_barcode.text.strip
328
+ $client.product_save!("barcode" => barcode, "dprice" => @manage_debuggers.text.strip.to_c, "mprice" => @manage_members.text.strip.to_c, "nmprice" => @manage_plebs.text.strip.to_c)
329
+
330
+ @add_notification.text = "prices saved!"
331
+ _add_show(barcode)
332
+ rescue Exception => e
333
+ puts e.backtrace
334
+ @add_notification.text = e.message
335
+ end
336
+ end
337
+ @manage_edit.image = Gtk::Image.new(Gtk::Stock::EDIT, Gtk::IconSize::BUTTON)
338
+ @manage_edit.label = Gtk::Stock::EDIT
339
+ end
340
+ end
341
+
342
+ def toggle_purchase_fields(bool)
343
+ @purchase_debuggers.sensitive = bool
344
+ @purchase_debuggers.editable = bool
345
+ @purchase_plebs.sensitive = bool
346
+ @purchase_plebs.editable = bool
347
+ @purchase_members.sensitive = bool
348
+ @purchase_members.editable = bool
349
+ #@purchase_date.sensitive = bool
350
+ #@purchase_date.editable = bool
351
+ @purchase_amount.sensitive = bool
352
+ @purchase_amount.editable = bool
353
+ @purchase_price.sensitive = bool
354
+ @purchase_price.editable = bool
355
+ end
356
+
357
+ def toggle_stock_field(bool)
358
+ @stock_stock_new.sensitive = bool
359
+ @stock_stock_new.editable = bool
360
+ end
361
+
362
+ def add_edit(widget)
363
+ toggle_price_fields(false)
364
+ end
365
+
366
+ def smart_search(widget)
367
+ case @tabs.page
368
+ when 0
369
+ barcode = @add_barcode.text.strip
370
+ _add_show(barcode)
371
+ _purchase_show(barcode)
372
+ when 1
373
+ barcode = @purchase_barcode.text.strip
374
+ _add_show(barcode)
375
+ _purchase_show(barcode)
376
+ when 2
377
+ barcode = @stock_barcode.text.strip
378
+ _stock_show(barcode)
379
+ when 3
380
+ barcode = @stock_barcode.text.strip
381
+ _log_show(barcode)
382
+ when 4
383
+ barcode = @stock_barcode.text.strip
384
+ _slog_show(barcode)
385
+ end
386
+ end
387
+
388
+ def plebs_act(widget)
389
+ end
390
+
391
+ def add_cancel(widget)
392
+ toggle_price_fields(false, false)
393
+ _add_clear
394
+ end
395
+ def log_cancel(w)
396
+ _log_clear
397
+ end
398
+ def slog_cancel(w)
399
+ _slog_clear
400
+ end
401
+ def to_purchase(w)
402
+ @tabs.page = 1
403
+ end
404
+ def refreshlog(w)
405
+ barcode = @log_barcode.text.strip
406
+ begin
407
+ p = $client.product_lookup(barcode)
408
+ _update_log(barcode)
409
+ rescue
410
+ _update_log
411
+ end
412
+ end
413
+ def refresh_slog(w)
414
+ barcode = @slog_barcode.text.strip
415
+ begin
416
+ p = $client.product_lookup(barcode)
417
+ _update_slog(barcode)
418
+ rescue
419
+ _update_slog
420
+ end
421
+ end
422
+
423
+ def changed(widget)
424
+ #puts "changed() is not implemented yet."
425
+ end
426
+
427
+ def stock_cancel(widget)
428
+ _stock_clear
429
+ end
430
+
431
+ def price_del(widget, arg0, arg1)
432
+ end
433
+
434
+ def stock_apply(widget)
435
+ begin
436
+ raise IG3Error, "select a debugger please!" if @stock_debugger.active == -1
437
+ bar = @stock_barcode.text.strip
438
+ $client.product_adjust_stock!("barcode" => bar, "stock" => @stock_stock_new.text.strip.to_i, "debugger" => get_debugger(@stock_debugger).username)
439
+ _stock_clear
440
+ @stock_notification.text = "stock update saved!"
441
+ _stock_show(bar)
442
+ rescue Exception => e
443
+ @stock_notification.text = e.message
444
+ end
445
+ end
446
+
447
+ def add_delete(w)
448
+ begin
449
+ barcode = @add_barcode.text.strip
450
+ $client.product_remove!(barcode)
451
+ _add_clear
452
+ rescue Exception => e
453
+ @add_notification.text = e.message
454
+ end
455
+ end
456
+
457
+ def refresh(widget=nil)
458
+ case @tabs.page
459
+ when 0
460
+ _update_add_products(false)
461
+ when 1
462
+ _update_purchase_products(false)
463
+ when 2
464
+ _update_stock_products(false)
465
+ when 3
466
+ _update_log_products(false)
467
+ when 4
468
+ _update_slog_products(false)
469
+ end
470
+ end
471
+
472
+ def debuggers_act(widget)
473
+ end
474
+
475
+ def accept_toogled(widget)
476
+ end
477
+
478
+ def purchase_cancel(widget)
479
+ _purchase_clear
480
+ end
481
+
482
+ def price_ins(widget, arg0, arg1, arg2)
483
+ end
484
+
485
+ def tabfocus(widget, a, b)
486
+ case b
487
+ when 0
488
+ _update_add_products
489
+ when 1
490
+ _update_purchase_products
491
+ when 2
492
+ _update_stock_products
493
+ when 3
494
+ _update_log_products
495
+ _update_log
496
+ when 4
497
+ _update_slog_products
498
+ _update_slog
499
+ end
500
+ end
501
+
502
+ def notification_focus_in_event_cb(widget, arg0)
503
+ end
504
+
505
+ def stock_to_apply(widget)
506
+ @stock_apply.grab_focus
507
+ end
508
+
509
+ def add_apply(widget)
510
+ begin
511
+ @add_notification.text = "saving product..."
512
+ toggle_price_fields(true, false)
513
+ raise Needed, "please scan a barcode" if @add_barcode.text.strip.empty?
514
+ raise Needed, "please enter a descriptive name" if @add_name.text.strip.empty?
515
+ raise Needed, "please select a category" if @add_prodcat.active == -1
516
+ $client.product_save!("barcode" => @add_barcode.text.strip, "name" => @add_name.text.strip, "dprice" => @manage_debuggers.text.strip.to_c, "mprice" => @manage_members.text.strip.to_c, "nmprice" => @manage_plebs.text.strip.to_c, "category" => @categories[@add_prodcat.active])
517
+ _update_add_products(false)
518
+ @add_notification.text = "the imps saved the product!"
519
+ _add_clear(false)
520
+ rescue Exception => e
521
+ @add_notification.text = e.message
522
+ end
523
+ end
524
+
525
+ def select(widget, path, column)
526
+ prodentry = widget.model.get_iter(path)
527
+ _add_show(prodentry[0].barcode)
528
+ _purchase_show(prodentry[0].barcode)
529
+ end
530
+ def purchase_select(widget, path, column)
531
+ prodentry = widget.model.get_iter(path)
532
+ _add_show(prodentry[0].barcode)
533
+ _purchase_show(prodentry[0].barcode)
534
+ end
535
+ def stock_select(widget, path, column)
536
+ prodentry = widget.model.get_iter(path)
537
+ _stock_show(prodentry[0].barcode)
538
+ end
539
+ def log_select(widget, path, column)
540
+ prodentry = widget.model.get_iter(path)
541
+ barcode = prodentry[0].barcode
542
+ _log_show(barcode)
543
+ _update_log(barcode)
544
+ end
545
+ def select_from_log(widget, path, column)
546
+ prodentry = widget.model.get_iter(path)
547
+ barcode = prodentry[0].product
548
+ _log_show(barcode)
549
+ _update_log(barcode)
550
+ end
551
+ def slog_select(widget, path, column)
552
+ prodentry = widget.model.get_iter(path)
553
+ barcode = prodentry[0].barcode
554
+ _slog_show(barcode)
555
+ _update_slog(barcode)
556
+ end
557
+ def select_from_slog(widget, path, column)
558
+ prodentry = widget.model.get_iter(path)
559
+ barcode = prodentry[0].product
560
+ _slog_show(barcode)
561
+ _update_slog(barcode)
562
+ end
563
+
564
+
565
+
566
+
567
+ private
568
+
569
+ def _add_show(barcode)
570
+ begin
571
+ @add_barcode.signal_handler_block(@handler1)
572
+ prod = $client.product_lookup(barcode)
573
+ @manage_members.text = prod.mprice.from_c.to_s
574
+ @manage_debuggers.text = prod.dprice.from_c.to_s
575
+ @manage_plebs.text = prod.nmprice.from_c.to_s
576
+ @add_barcode.text = prod.barcode
577
+ @add_stock.text = prod.stock
578
+ @add_name.text = prod.name
579
+ @add_prodcat.active = @categories.index(prod.category)
580
+ rescue Exception => e
581
+ @add_notification.text = e.message
582
+ ensure
583
+ @add_barcode.signal_handler_unblock(@handler1)
584
+ end
585
+ end
586
+
587
+ def _purchase_show(barcode)
588
+ begin
589
+ @purchase_barcode.signal_handler_block(@handler2)
590
+ prod = $client.product_lookup(barcode)
591
+ @purchase_members_orig.text = prod.mprice.from_c.to_s
592
+ @purchase_debuggers_orig.text = prod.dprice.from_c.to_s
593
+ @purchase_plebs_orig.text = prod.nmprice.from_c.to_s
594
+ @purchase_barcode.text = prod.barcode
595
+ @purchase_stock.text = prod.stock
596
+ @purchase_name.text = prod.name
597
+ @purchase_category.text = prod.category
598
+ price_amount_changed
599
+ toggle_purchase_fields(true)
600
+ rescue Exception => e
601
+ @purchase_notification.text = e.message
602
+ ensure
603
+ @purchase_barcode.signal_handler_unblock(@handler2)
604
+ end
605
+ end
606
+ def _stock_show(barcode)
607
+ begin
608
+ @stock_barcode.signal_handler_block(@handler3)
609
+ prod = $client.product_lookup(barcode)
610
+ @stock_barcode.text = prod.barcode
611
+ @stock_stock.text = prod.stock
612
+ @stock_name.text = prod.name
613
+ @stock_category.text = prod.category
614
+ toggle_stock_field(true)
615
+ rescue Exception => e
616
+ @stock_notification.text = e.message
617
+ ensure
618
+ @stock_barcode.signal_handler_unblock(@handler3)
619
+ end
620
+ end
621
+ def _log_show(barcode)
622
+ begin
623
+ @log_barcode.signal_handler_block(@handler6)
624
+ prod = $client.product_lookup(barcode)
625
+ @log_barcode.text = prod.barcode
626
+ @log_name.text = prod.name
627
+ rescue Exception => e
628
+ @log_notification.text = e.message
629
+ ensure
630
+ @log_barcode.signal_handler_unblock(@handler6)
631
+ end
632
+ end
633
+ def _slog_show(barcode)
634
+ begin
635
+ @slog_barcode.signal_handler_block(@handler15)
636
+ prod = $client.product_lookup(barcode)
637
+ @slog_barcode.text = prod.barcode
638
+ @slog_name.text = prod.name
639
+ rescue Exception => e
640
+ @slog_notification.text = e.message
641
+ ensure
642
+ @slog_barcode.signal_handler_unblock(@handler15)
643
+ end
644
+ end
645
+
646
+ def _update_add_products(verbose=true)
647
+ Thread.new do
648
+ begin
649
+ category = @add_categories.active_iter[0]
650
+ @add_notification.text = "loading products..." if verbose
651
+ @add_products.model = nil
652
+ @add_products_store.clear
653
+ prods = $client.product_all.sort{|x,y| x.name.downcase <=> y.name.downcase}
654
+ prods.delete_if{|p| p.category != category} unless category == "all products"
655
+ prods.each do |p|
656
+ row = @add_products_store.append
657
+ row[1] = p.name
658
+ row[0] = p
659
+ end
660
+ @add_products.model = @add_products_store
661
+ #@add_notification.text = "products loaded..." if verbose
662
+ @add_notification.text = ""
663
+ rescue Exception => e
664
+ @add_notification.text = e.message
665
+ end
666
+ end
667
+ end
668
+
669
+ def _update_purchase_products(verbose=true)
670
+ Thread.new do
671
+ begin
672
+ category = @add_categories.active_iter[0]
673
+ @purchase_notification.text = "loading products..." if verbose
674
+ @purchase_products.model = nil
675
+ @purchase_products_store.clear
676
+ prods = $client.product_all.sort{|x,y| x.name.downcase <=> y.name.downcase}
677
+ prods.delete_if{|p| p.category != category} unless category == "all products"
678
+ prods.each do |p|
679
+ row = @purchase_products_store.append
680
+ row[1] = p.name
681
+ row[0] = p
682
+ end
683
+ @purchase_products.model = @purchase_products_store
684
+ #@purchase_notification.text = "products loaded..." if verbose
685
+ @purchase_notification.text = "" if verbose
686
+ rescue Exception => e
687
+ @purchase_notification.text = e.message
688
+ end
689
+ end
690
+ end
691
+
692
+ def _update_stock_products(verbose=true)
693
+ Thread.new do
694
+ begin
695
+ category = @stock_categories.active_iter[0]
696
+ @stock_notification.text = "loading products..." if verbose
697
+ @stock_products.model = nil
698
+ @stock_products_store.clear
699
+ prods = $client.product_all.sort{|x,y| x.name.downcase <=> y.name.downcase}
700
+ prods.delete_if{|p| p.category != category} unless category == "all products"
701
+ prods.each do |p|
702
+ row = @stock_products_store.append
703
+ row[1] = p.name
704
+ row[0] = p
705
+ end
706
+ @stock_products.model = @stock_products_store
707
+ #@stock_notification.text = "products loaded..." if verbose
708
+ @stock_notification.text = "" if verbose
709
+ rescue Exception => e
710
+ @stock_notification.text = e.message
711
+ end
712
+ end
713
+ end
714
+
715
+ def _update_log_products(verbose=true)
716
+ Thread.new do
717
+ begin
718
+ category = @log_categories.active_iter[0]
719
+ @log_notification.text = "loading products..." if verbose
720
+ @log_products.model = nil
721
+ @log_products_store.clear
722
+ prods = $client.product_all.sort{|x,y| x.name.downcase <=> y.name.downcase}
723
+ prods.delete_if{|p| p.category != category} unless category == "all products"
724
+ prods.each do |p|
725
+ row = @log_products_store.append
726
+ row[1] = p.name
727
+ row[0] = p
728
+ end
729
+ @log_products.model = @log_products_store
730
+ #@log_notification.text = "products loaded..." if verbose
731
+ @log_notification.text = "" if verbose
732
+ rescue Exception => e
733
+ @log_notification.text = e.message
734
+ end
735
+ end
736
+ end
737
+ def _update_slog_products(verbose=true)
738
+ Thread.new do
739
+ begin
740
+ category = @slog_categories.active_iter[0]
741
+ @slog_notification.text = "loading products..." if verbose
742
+ @slog_products.model = nil
743
+ @slog_products_store.clear
744
+ prods = $client.product_all.sort{|x,y| x.name.downcase <=> y.name.downcase}
745
+ prods.delete_if{|p| p.category != category} unless category == "all products"
746
+ prods.each do |p|
747
+ row = @slog_products_store.append
748
+ row[1] = p.name
749
+ row[0] = p
750
+ end
751
+ @slog_products.model = @slog_products_store
752
+ #@log_notification.text = "products loaded..." if verbose
753
+ @slog_notification.text = "" if verbose
754
+ rescue Exception => e
755
+ @slog_notification.text = e.message
756
+ end
757
+ end
758
+ end
759
+
760
+ def _add_clear(all=true)
761
+ @manage_members.text = "0.0"
762
+ @manage_debuggers.text = "0.0"
763
+ @manage_plebs.text = "0.0"
764
+ @add_barcode.text = "" if all
765
+ @add_stock.text = ""
766
+ @add_name.text = ""
767
+ @add_prodcat.active = -1
768
+ @add_notification.text = "" if all
769
+ end
770
+ def _purchase_clear(all=true)
771
+ @purchase_members_orig.text = "0.0"
772
+ @purchase_debuggers_orig.text = "0.0"
773
+ @purchase_plebs_orig.text = "0.0"
774
+ @purchase_members.text = ""
775
+ @purchase_debuggers.text = ""
776
+ @purchase_debugger.active = -1
777
+ @purchase_plebs.text = ""
778
+ @purchase_barcode.text = "" if all
779
+ @purchase_stock.text = ""
780
+ @purchase_amount.text = ""
781
+ @purchase_price.text = ""
782
+ @purchase_date.text = Time.now.strftime("%Y-%m-%d")
783
+ @purchase_name.text = ""
784
+ @purchase_category.text = ""
785
+ @purchase_notification.text = "" if all
786
+ end
787
+ def _stock_clear(all=true)
788
+ @stock_barcode.text = "" if all
789
+ @stock_stock.text = ""
790
+ @stock_stock_new.text = ""
791
+ @stock_name.text = ""
792
+ @stock_category.text = ""
793
+ @stock_notification.text = "" if all
794
+ end
795
+ def _log_clear(all=true)
796
+ @log_barcode.text = "" if all
797
+ @log_name.text = ""
798
+ @log_notification.text = "" if all
799
+ end
800
+ def _slog_clear(all=true)
801
+ @slog_barcode.text = "" if all
802
+ @slog_name.text = ""
803
+ @slog_notification.text = "" if all
804
+ end
805
+
806
+
807
+ def _update_log(barcode=nil)
808
+ @purchase_log_store.clear
809
+ Thread.new do
810
+ begin
811
+ ps = $client.product_purchases
812
+ if not barcode.nil?
813
+ ps.delete_if{|p| p.product != barcode}
814
+ end
815
+ ps.each do |ll|
816
+ @purchase_log_store.append[0] = ll
817
+ end
818
+ rescue Exception => e
819
+ @log_notification.text = e.message
820
+ end
821
+ end
822
+ end
823
+ def _update_slog(barcode=nil)
824
+ @spurchase_log_store.clear
825
+ Thread.new do
826
+ begin
827
+ ps = $client.product_sales
828
+ if not barcode.nil?
829
+ ps.delete_if{|p| p.product != barcode}
830
+ end
831
+ ps.each do |ll|
832
+ @spurchase_log_store.append[0] = ll
833
+ end
834
+ rescue Exception => e
835
+ @slog_notification.text = e.message
836
+ end
837
+ end
838
+ end
839
+
840
+
841
+
842
+
843
+
844
+
845
+
846
+ end
847
+
848
+ register_window(ProtjesGlade)
849
+
850
+ end