/
uscgenerica.rb
executable file
·366 lines (334 loc) · 13.6 KB
/
uscgenerica.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# Inserimento dei dati di uscita dei capi
def uscgenerica(finestra, muscite, listasel, combousc, modo)
mdatiuscita = Gtk::Window.new("Compravendita o altro")
mdatiuscita.window_position=(Gtk::Window::POS_CENTER_ALWAYS)
boxuscv = Gtk::VBox.new(false, 0)
boxusc1 = Gtk::HBox.new(false, 5)
boxusc2 = Gtk::HBox.new(false, 5)
boxusc3 = Gtk::HBox.new(false, 5)
boxusc4 = Gtk::HBox.new(false, 5)
boxusc5 = Gtk::HBox.new(false, 5)
boxusc6 = Gtk::HBox.new(false, 5)
boxusc7 = Gtk::HBox.new(false, 5)
boxusc8 = Gtk::HBox.new(false, 5)
boxusc9 = Gtk::HBox.new(false, 5)
boxusc10 = Gtk::HBox.new(false, 5)
boxuscv.pack_start(boxusc1, false, false, 5)
boxuscv.pack_start(boxusc2, false, false, 5)
boxuscv.pack_start(boxusc3, false, false, 5)
boxuscv.pack_start(boxusc4, false, false, 5)
boxuscv.pack_start(boxusc5, false, false, 5)
boxuscv.pack_start(boxusc6, false, false, 5)
boxuscv.pack_start(boxusc7, false, false, 5)
boxuscv.pack_start(boxusc8, false, false, 5)
boxuscv.pack_start(boxusc9, false, false, 5)
boxuscv.pack_start(boxusc10, false, false, 5)
mdatiuscita.add(boxuscv)
stringacapi = ""
#Data uscita
labeldatausc = Gtk::Label.new("Data uscita (GGMMAA):")
boxusc2.pack_start(labeldatausc, false, false, 5)
datausc = Gtk::Entry.new()
datausc.max_length =(6)
boxusc2.pack_start(datausc, false, false, 5)
#Allevamento / mercato di destinazione
labelallevdest = Gtk::Label.new("Codice allevamento / mercato di destinazione:")
boxusc3.pack_start(labelallevdest, false, false, 5)
listall = Gtk::ListStore.new(Integer, String, String, String, String, String, String)
selalldest = Allevamentis.find(:all, :order => "ragsoc")
selalldest.each do |alldest|
iteralldest = listall.append
iteralldest[0] = alldest.id
iteralldest[1] = alldest.ragsoc
iteralldest[2] = alldest.idfisc
iteralldest[3] = alldest.cod317
iteralldest[4] = alldest.via
iteralldest[5] = alldest.comune
iteralldest[6] = alldest.provincia
end
comboalldest = Gtk::ComboBox.new(listall)
renderusc = Gtk::CellRendererText.new
renderusc.visible=(false)
comboalldest.pack_start(renderusc,false)
comboalldest.set_attributes(renderusc, :text => 0)
renderusc = Gtk::CellRendererText.new
comboalldest.pack_start(renderusc,false)
comboalldest.set_attributes(renderusc, :text => 1)
renderusc = Gtk::CellRendererText.new
renderusc.visible=(false)
comboalldest.pack_start(renderusc,false)
comboalldest.set_attributes(renderusc, :text => 2)
renderusc = Gtk::CellRendererText.new
comboalldest.pack_start(renderusc,false)
comboalldest.set_attributes(renderusc, :text => 3)
boxusc3.pack_start(comboalldest, false, false, 5)
#Inserimento nuovo allevamento
nallev = Gtk::Button.new("Nuovo allevamento")
nallev.signal_connect( "released" ) { mascallevam(listall) }
boxusc3.pack_start(nallev, false, false, 5)
#Nazione destinazione
labelnazdest = Gtk::Label.new("Nazione di destinazione:")
boxusc4.pack_start(labelnazdest, false, false, 5)
listanazdest = Gtk::ListStore.new(Integer, String, String)
selnazdest = Nations.find(:all, :order => "nome")
selnazdest.each do |nd|
iter1 = listanazdest.append
iter1[0] = nd.id.to_i
iter1[1] = nd.nome
iter1[2] = nd.codice
end
combonazdest = Gtk::ComboBox.new(listanazdest)
renderer1 = Gtk::CellRendererText.new
renderer1.visible=(false)
combonazdest.pack_start(renderer1,false)
combonazdest.set_attributes(renderer1, :text => 0)
renderer1 = Gtk::CellRendererText.new
combonazdest.pack_start(renderer1,false)
combonazdest.set_attributes(renderer1, :text => 1)
renderer1 = Gtk::CellRendererText.new
renderer1.visible=(false)
combonazdest.pack_start(renderer1,false)
combonazdest.set_attributes(renderer1, :text => 2)
boxusc4.pack_start(combonazdest, false, false, 0)
combonazdest.set_active(0)
z = -1
while combonazdest.active_iter[0] != 24
z+=1
combonazdest.set_active(z)
end
# Nome trasportatore
labeltrasp = Gtk::Label.new("Nome trasportatore:")
boxusc6.pack_start(labeltrasp, false, false, 5)
listatrasp = Gtk::ListStore.new(Integer, String)
seltrasp = Trasportatoris.find(:all, :order => "nometrasp")
seltrasp.each do |trasp|
itertrasp = listatrasp.append
itertrasp[0] = trasp.id
itertrasp[1] = trasp.nometrasp
end
combotrasp = Gtk::ComboBox.new(listatrasp)
rendertrasp = Gtk::CellRendererText.new
rendertrasp.visible=(false)
combotrasp.pack_start(rendertrasp,false)
combotrasp.set_attributes(rendertrasp, :text => 0)
rendertrasp = Gtk::CellRendererText.new
combotrasp.pack_start(rendertrasp,false)
combotrasp.set_attributes(rendertrasp, :text => 1)
boxusc6.pack_start(combotrasp, false, false, 5)
#Inserimento nuovo trasportatore
ntrasp = Gtk::Button.new("Nuovo trasportatore")
ntrasp.signal_connect( "released" ) {
require "nuovotrasportatore"
nuovotrasportatore(listatrasp)
}
boxusc6.pack_start(ntrasp, false, false, 5)
#Marca sostitutiva
labelmarcasost = Gtk::Label.new("Marca sostitutiva:")
boxusc7.pack_start(labelmarcasost, false, false, 5)
marcasost = Gtk::Entry.new()
boxusc7.pack_start(marcasost, false, false, 5)
# Modello 4
labelmod4usc = Gtk::Label.new("Modello 4:")
boxusc8.pack_start(labelmod4usc, false, false, 5)
mod4usc = Gtk::Entry.new()
progmod4 = @stallaoper.mod4usc.split("/")
progmod41 = progmod4[0].to_i
# anno = @giorno.strftime("%y")
# if progmod4[1].to_i == anno.to_i
# progmod41 += 1
# #annoreg = progmod4[1]
# else
# progmod41 = 1
# #annoreg = anno
# end
# mod4usc.text = ("#{progmod41}")
boxusc8.pack_start(mod4usc, false, false, 5)
# Data modello 4
labeldatamod4usc = Gtk::Label.new("Data Modello 4 (GGMMAA):")
boxusc8.pack_start(labeldatamod4usc, false, false, 5)
datamod4usc = Gtk::Entry.new()
datamod4usc.max_length=(6)
boxusc8.pack_start(datamod4usc, false, false, 5)
datausc.signal_connect("changed") {
datamod4usc.text =("#{datausc.text}")
if datausc.cursor_position == 5
if datausc.text[4,2] == progmod4[1]
nmod4 = progmod41 + 1
else
nmod4 = 1
end
mod4usc.text = ("#{nmod4}")
end
}
unless @mod4provv == ""
#puts "id mod4provv"
#puts @mod4provv[10]
datausc.text = @mod4provv[4].strftime("%d%m%y")
unless @mod4provv[5].to_i == 0
comboalldest.set_active(0)
combotrasp.set_active(0)
z = -1
while comboalldest.active_iter[0] != @mod4provv[5].to_i
z+=1
comboalldest.set_active(z)
end
end
z = -1
while combotrasp.active_iter[1] != @mod4provv[9]
z+=1
combotrasp.set_active(z)
end
mod4usc.text = @mod4provv[0].split("/")[2]
end
#Bottone di inserimento uscite
bottmovusc = Gtk::Button.new( "Inserisci" )
bottmovusc.signal_connect("clicked") {
errore = nil
if datausc.text == ""
Errore.avviso(mdatiuscita, "Mancano dati.")
errore = 1
elsif combousc.active_iter[0] == 3 or 10 or 11 or 16 or 20 or 28 or 29 or 30 # and comboalldest.active == -1 or combotrasp.active == -1 or combonazdest.active == -1 or mod4usc.text == nil or datamod4usc.text == nil
if comboalldest.active == -1 or combotrasp.active == -1 or combonazdest.active == -1 or mod4usc.text == "" or datamod4usc.text == ""
Errore.avviso(mdatiuscita, "Mancano dati: altri casi.")
errore = 1
else
end
else
end
if errore == nil
begin
if datausc.text.to_i != 0
datauscingl = @giorno.strftime("%Y")[0,2] + datausc.text[4,2] + datausc.text[2,2] + datausc.text[0,2]
Time.parse("#{datauscingl}")
else
Errore.avviso(mdatiuscita, "Data uscita errata.")
errore = 1
end
if datamod4usc.text != ""
if datamod4usc.text.to_i != 0
datamod4uscingl = @giorno.strftime("%Y")[0,2] + datamod4usc.text[4,2] + datamod4usc.text[2,2] + datamod4usc.text[0,2]
Time.parse("#{datamod4uscingl}")
else
Errore.avviso(mdatiuscita, "Data mod4 errata.")
errore = 1
end
else
end
rescue Exception => errore
Errore.avviso(mdatiuscita, "Controllare le date")
end
end
if errore == nil
if comboalldest.active == -1 or comboalldest.sensitive? == false
valcomboalldest = ""
else
mod4 = "#{@stallaoper.stalle.cod317}/#{Time.parse("#{datamod4uscingl}").strftime("%Y")}/#{mod4usc.text}"
#puts mod4
idalldest = comboalldest.active_iter[0]
valcomboalldest = comboalldest.active_iter[1]
alldestidfisc = comboalldest.active_iter[2]
alldest317 = comboalldest.active_iter[3]
#provaunione = Relazs.joins(:stalle, :ragsoc)
# alldir = Relazs.find(:first, :from => "relazs, stalles, ragsocs", :conditions => ["stalles.cod317 = ? and ragsocs.ragsoc = ?", "#{alldest317}", "#{valcomboalldest}"])
#alldir = Relazs.find(:all, :from => "relazs, stalles, ragsocs", :conditions => ["stalles.cod317= ? and ragsocs.ragsoc= ?", "#{alldest317}", "#{valcomboalldest}"])
alldir = Relazs.find(:all, :include => [:stalle, :ragsoc], :conditions => ["stalles.cod317= ? and ragsocs.ragsoc= ?", "#{alldest317}", "#{valcomboalldest}"])
# puts alldir.length
# puts "alldir = #{alldir.id}"
# alldir.each do|a|
# puts a.ragsoc.ragsoc
# puts a.stalle.cod317
# end
end
if combonazdest.active == -1 or combonazdest.sensitive? == false
valcombonazdest = ""
else
valcombonazdest = combonazdest.active_iter[2]
end
if combotrasp.active == -1 or combotrasp.sensitive? == false
valcombotrasp = ""
else
valcombotrasp = combotrasp.active_iter[1]
end
listasel.each do |model,path,iter|
marcauscid = iter[0]
if modo == 0
marcausc = iter[2]
specieusc = iter[3]
razzausc = iter[4]
nascitausc = iter[5]
cod317nasusc = iter[6]
sessousc = iter[7]
nazorigusc = iter[8]
nazprimimpusc = iter[9]
datamarcausc = iter[10]
ilgusc = iter[11]
marcaprecedenteusc = iter[12]
madreusc = iter[13]
padreusc = iter[14]
Animals.create(:relaz_id => "#{@stallaoper.id.to_i}", :tipo => "U", :cm_usc => "#{combousc.active_iter[0]}", :marca => "#{marcausc}", :specie => "#{specieusc}", :razza_id => "#{razzausc}", :data_nas => "#{nascitausc}", :stalla_nas => "#{cod317nasusc}", :sesso => "#{sessousc}", :naz_orig => "#{nazorigusc}", :naz_nasprimimp => "#{nazprimimpusc}", :data_applm => "#{datamarcausc}", :ilg => "#{ilgusc}", :marca_prec => "#{marcaprecedenteusc}", :marca_madre => "#{madreusc}", :marca_padre => "#{padreusc}", :uscita => "#{datauscingl}", :allevamenti_id => "#{idalldest}", :naz_dest => "#{valcombonazdest}", :trasp => "#{valcombotrasp}", :mod4 => "#{mod4}", :data_mod4 => "#{datamod4uscingl.to_i}", :marcasost => "#{marcasost.text}", :idcoll => "#{marcauscid}")
usc = Animals.find(:first, :conditions => ["idcoll = ?", "#{marcauscid}"])
Animals.update(marcauscid, { :uscito => "1", :idcoll => "#{usc.id}"})
else
stringacapi << "#{marcauscid}" +","
end
end
if modo == 0
Relazs.update(@stallaoper.id, { :mod4usc => "#{mod4usc.text}/#{Time.parse("#{datamod4uscingl}").strftime("%y")}"})
@stallaoper.mod4usc = mod4usc.text + "/" + Time.parse("#{datamod4uscingl}").strftime("%y")
Mod4temps.delete(@mod4provv[10]) unless @mod4provv == ""
ActiveRecord::Base.connection.execute('alter table mod4temps auto_increment=1')
@mod4provv == ""
Conferma.conferma(mdatiuscita, "Capi usciti correttamente.")
if alldir.length > 0
#puts "Trasf. diretto"
avviso = Gtk::MessageDialog.new(finestra, Gtk::Dialog::DESTROY_WITH_PARENT, Gtk::MessageDialog::QUESTION, Gtk::MessageDialog::BUTTONS_YES_NO, "L'allevamento di destinazione è tra le stalle gestite; procedo con il caricamento automatico?")
risposta = avviso.run
avviso.destroy
if risposta == Gtk::Dialog::RESPONSE_YES
#puts "Sì"
require 'insautomatico'
insautomatico(finestra, listasel, valcomboalldest, alldest317, alldir, combousc.active_iter[0], datausc.text, mod4, datamod4usc.text)
else
Conferma.conferma(finestra, "Operazione annullata.")
end
end
mdatiuscita.destroy
muscite.destroy
else
# errore = 0
# if comboalldest.active_iter[4].to_s == "" or comboalldest.active_iter[5].to_s == "" or comboalldest.active_iter[6].to_s == ""
# Errore.avviso(finestra, "Manca l'indirizzo dell'allevamento, inseriscilo.")
# modallevamenti(comboalldest.active_iter[0])
# errore = 1
# end
# if errore == 0
if @mod4provv == ""
Mod4temps.create(:relaz_id => "#{@stallaoper.id.to_i}", :mod4 => "#{@stallaoper.stalle.cod317}/#{Time.parse("#{datamod4uscingl}").strftime("%Y")}/#{mod4usc.text}", :capi => "#{stringacapi.chop}", :datamod4 => "#{datamod4uscingl.to_i}", :datausc => "#{datauscingl}", :allevamenti_id => "#{idalldest}",:uscite_id => "#{combousc.active_iter[0]}", :naz_dest => "#{valcombonazdest}", :trasportatore => "#{valcombotrasp}")
else
Mod4temps.update(@mod4provv[10], {:mod4 => "#{@stallaoper.stalle.cod317}/#{Time.parse("#{datamod4uscingl}").strftime("%Y")}/#{mod4usc.text}", :capi => "#{stringacapi.chop}", :datamod4 => "#{datamod4uscingl.to_i}", :datausc => "#{datauscingl}", :allevamenti_id => "#{idalldest}",:uscite_id => "#{combousc.active_iter[0]}", :naz_dest => "#{valcombonazdest}", :trasportatore => "#{valcombotrasp}"})
end
Conferma.conferma(mdatiuscita, "Modello 4 provvisorio creato, ora puoi stamparlo.")
arrmarche = []
listasel.each do |model,path,iter|
arrmarche << iter[2]
end
require 'stampamod4provv'
stampamod4provv(mdatiuscita, arrmarche, combousc.active_iter, nil, comboalldest.active_iter, combotrasp.active_iter, @stallaoper.stalle.cod317 + "/" + Time.parse("#{datamod4uscingl}").strftime("%Y") + "/" + mod4usc.text, Time.parse("#{datauscingl}").strftime("%d/%m/%Y"))
mdatiuscita.destroy
muscite.destroy
#end
end
#mdatiuscita.destroy
#muscite.destroy
#finestra.present
end
}
boxusc10.pack_start(bottmovusc, false, false, 0)
bottchiudi = Gtk::Button.new( "Chiudi" )
bottchiudi.signal_connect("clicked") {
mdatiuscita.destroy
muscite.present
}
boxusc10.pack_start(bottchiudi, false, false, 0)
mdatiuscita.show_all
end