Class: RS::InvoiceRequest
Overview
Constant Summary
Constants inherited
from BaseRequest
BaseRequest::DEFAULTS, BaseRequest::INVOICE_SERVICE_URL, BaseRequest::WAYBILL_SERVICE_URL
Instance Attribute Summary
Attributes inherited from BaseRequest
#last_error_code
Instance Method Summary
collapse
Methods inherited from BaseRequest
#format_date, #invoice_client, #validate_presence_of, #waybill_client
Instance Method Details
#delete_factura_item(opts = {}) ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/rs/requests/factura.rb', line 91
def delete_factura_item(opts = {})
validate_presence_of(opts, :id, :factura_id, :su, :sp, :user_id)
response = invoice_client.request 'delete_invoice_desc' do
soap.body = { 'user_id' => opts[:user_id], 'id' => opts[:id], 'inv_id' => opts[:factura_id], 'su' => opts[:su], 'sp' => opts[:sp] }
end.to_hash
response[:delete_invoice_desc_response][:delete_invoice_desc_result]
end
|
#get_factura(opts = {}) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/rs/requests/factura.rb', line 50
def get_factura(opts = {})
validate_presence_of(opts, :id, :user_id, :su, :sp)
response = invoice_client.request 'get_invoice' do
soap.body = {'user_id' => opts[:user_id], 'invois_id' => opts[:id], 'su' => opts[:su], 'sp' => opts[:sp]}
end.to_hash
if response[:get_invoice_response][:get_invoice_result]
hash = response[:get_invoice_response]
factura = RS::Factura.new
factura.id = opts[:id]
factura.index = hash[:f_series]
factura.number = hash[:f_number].to_i unless hash[:f_number].to_i == -1
factura.operation_date = hash[:operation_dt]
factura.registration_date = hash[:reg_dt]
factura.seller_id = hash[:seller_un_id].to_i unless hash[:seller_un_id] == -1
factura.buyer_id = hash[:buyer_un_id].to_i unless hash[:buyer_un_id] == -1
factura.status = hash[:status].to_i
factura.waybill_number = hash[:overhead_no]
factura.waybill_date = hash[:overhead_dt]
factura.correction_of = hash[:k_id].to_i unless hash[:k_id].to_i == -1
factura.correction_type = hash[:k_type].to_i unless hash[:k_type].to_i == -1
factura
end
end
|
#get_factura_items(opts = {}) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/rs/requests/factura.rb', line 74
def get_factura_items(opts = {})
validate_presence_of(opts, :id, :user_id, :su, :sp)
response = invoice_client.request 'get_invoice_desc' do
soap.body = { 'user_id' => opts[:user_id], 'invois_id' => opts[:id], 'su' => opts[:su], 'sp' => opts[:sp] }
end.to_hash
h_items = response[:get_invoice_desc_response][:get_invoice_desc_result][:diffgram][:document_element][:invoices_descs]
items = []
if h_items.kind_of?(Array)
h_items.each do |item|
items << factura_item_from_hash(item)
end
elsif h_items.kind_of?(Hash)
items << factura_item_from_hash(h_items)
end
items
end
|
#save_factura(factura, opts = {}) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/rs/requests/factura.rb', line 10
def save_factura(factura, opts = {})
validate_presence_of(opts, :user_id, :su, :sp)
response = invoice_client.request 'save_invoice' do
soap.body = {
'user_id' => opts[:user_id],
'invois_id' => factura.id || 0,
'operation_date' => format_date(factura.operation_date || Time.now),
'seller_un_id' => factura.seller_id || 0,
'buyer_un_id' => factura.buyer_id || 0,
'overhead_no' => '', 'overhead_dt' => format_date(Time.now), 'b_s_user_id' => factura.buyer_su_id || 0,
'su' => opts[:su], 'sp' => opts[:sp]}
end.to_hash
resp = response[:save_invoice_response][:save_invoice_result]
factura.id = response[:save_invoice_response][:invois_id].to_i if resp
resp
end
|
#save_factura_item(item, opts = {}) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/rs/requests/factura.rb', line 28
def save_factura_item(item, opts = {})
validate_presence_of(opts, :user_id, :su, :sp)
response = invoice_client.request 'save_invoice_desc' do
soap.body = {
'user_id' => opts[:user_id],
'id' => item.id || 0,
'su' => opts[:su], 'sp' => opts[:sp],
'invois_id' => item.factura_id,
'goods' => item.name,
'g_unit' => item.unit,
'g_number' => item.quantity || 1,
'full_amount' => item.total || 0,
'drg_amount' => item.vat || 0,
'aqcizi_amount' => item.excise || 0,
'akciz_id' => item.excise_id || 0
}
end.to_hash
resp = response[:save_invoice_desc_response][:save_invoice_desc_result]
item.id = response[:save_invoice_desc_response][:id].to_i if resp
resp
end
|
#send_factura(opts = {}) ⇒ Object
99
100
101
102
|
# File 'lib/rs/requests/factura.rb', line 99
def send_factura(opts = {})
change_factura_status(RS::Factura::STATUS_SENT, opts)
end
|