Class: YDIM::Html::State::Invoice
Defined Under Namespace
Classes: SortableInvoice
Constant Summary
collapse
- VIEW =
Html::View::Invoice
Constants inherited
from Global
Global::EVENT_MAP
Instance Attribute Summary collapse
Attributes inherited from Global
#sort_reverse, #sortby
Instance Method Summary
collapse
#invoice_key, #invoice_keys, #invoice_mandatory
Methods inherited from Global
#_create_invoice, #autoinvoice, #create_autoinvoice, #create_debitor, #create_invoice, #debitor, #invoice, #logout
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
79
80
81
|
# File 'lib/ydim/html/state/invoice.rb', line 79
def model
@model
end
|
Instance Method Details
#_do_update ⇒ Object
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
|
# File 'lib/ydim/html/state/invoice.rb', line 141
def _do_update
if((id = @session.user_input(:unique_id)) \
&& @model.unique_id == id.to_i)
keys = [:text, :quantity, :unit, :price]
data = {}
user_input(keys).each { |key, hash|
hash.each { |idx, value|
(data[idx] ||= {}).store(key, value)
} unless hash.nil?
}
target = origin = nil
converter = if((target = @session.user_input(:currency)) \
&& (origin = @model.currency) \
&& origin != target)
@session.currency_converter
end
data.each { |idx, item|
if(converter)
item[:price] = converter.convert(item[:price], origin, target)
end
@session.update_item(id.to_i, idx.to_i, item, invoice_key)
}
_do_update_invoice(user_input(invoice_keys, invoice_mandatory))
@model.update! @model.odba_store
end
end
|
#_do_update_invoice(input) ⇒ Object
170
171
172
173
174
175
|
# File 'lib/ydim/html/state/invoice.rb', line 170
def _do_update_invoice(input)
input[:precision] = (input[:precision] || 2).to_i
input.each { |key, val|
@model.send("#{key}=", val)
}
end
|
#ajax_create_item ⇒ Object
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/ydim/html/state/invoice.rb', line 84
def ajax_create_item
if(id = @session.user_input(:unique_id))
begin
@session.add_items(id.to_i, [{:time => Time.now}], invoice_key)
rescue IndexError
end
@model.update! end
AjaxItems.new(@session, @model.items)
end
|
#ajax_delete_item ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/ydim/html/state/invoice.rb', line 94
def ajax_delete_item
if((id = @session.user_input(:unique_id)) \
&& (idx = @session.user_input(:index)))
begin
@session.delete_item(id.to_i, idx.to_i, invoice_key)
rescue IndexError
end
@model.update! end
AjaxItems.new(@session, @model.items)
end
|
#ajax_invoice ⇒ Object
124
125
126
127
|
# File 'lib/ydim/html/state/invoice.rb', line 124
def ajax_invoice
_do_update
AjaxInvoice.new(@session, @model)
end
|
#ajax_item ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/ydim/html/state/invoice.rb', line 105
def ajax_item
data = {}
if((id = @session.user_input(:unique_id)) \
&& (idx = @session.user_input(:index)))
begin
keys = [:text, :quantity, :unit, :price]
input = user_input(keys).delete_if { |key, val| val.nil? }
item = @session.update_item(id.to_i, idx.to_i, input,
invoice_key)
input.each { |key, val| data.store("#{key}[#{item.index}]", val) }
data.store("total_netto#{item.index}", item.total_netto)
rescue IndexError
end
end
[:total_netto, :vat, :total_brutto].each { |key|
data.store(key, @model.send(key))
}
AjaxValues.new(@session, data)
end
|
#init ⇒ Object
80
81
82
83
|
# File 'lib/ydim/html/state/invoice.rb', line 80
def init
@model = SortableInvoice.new @model
super
end
|
#pdf ⇒ Object
128
129
130
131
132
|
# File 'lib/ydim/html/state/invoice.rb', line 128
def pdf
newstate = super
newstate.sortby, newstate.sort_reverse = @sortby, @sort_reverse
newstate
end
|
#send_invoice ⇒ Object
133
134
135
136
|
# File 'lib/ydim/html/state/invoice.rb', line 133
def send_invoice
_do_update
super
end
|
#update ⇒ Object
137
138
139
140
|
# File 'lib/ydim/html/state/invoice.rb', line 137
def update
_do_update
self
end
|