Class: Elms::Export

Inherits:
Object
  • Object
show all
Defined in:
lib/elms/export.rb

Constant Summary collapse

CURRENCY_CZK =
'1'
CURRENCY_EUR =
'2'

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Export

Returns a new instance of Export.



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
# File 'lib/elms/export.rb', line 59

def initialize(source)

  @data = {
      :products => [],
      :cod => true,
      :order_number => nil,
      :total => 0,
      :customer => {
          :company => '',
          :name => '',
          :surname => '',
          :email => '',
          :street => '',
          :city => '',
          :country => '',
          :postal_code => '',
          :phone => '',
          :ic => '',
          :dic => '',
          :del_company => '',
          :del_name => '',
          :del_surname => '',
          :del_street => '',
          :del_city => '',
          :del_postal_code => '',
          :del_country => '',
          :del_phone => '',
          :del_email => ''
      },
      :source => source,
      :order_date => '',
      :currency_id => 1,
      :invoice_number => ''
  }


  @cod = false
  @order_number = nil
  @total = 0.0
  @customer = {}
  @invoice_number = nil
end

Instance Method Details

#add_product(product_name, product_price, peaces, tax) ⇒ Object

Parameters:

  • product_name (String)

    PLU in ELMS

  • product_price (Float)

    price with VAT

  • peaces (Integer)

    How many

  • tax (Integer)

    DPH in %



138
139
140
141
142
# File 'lib/elms/export.rb', line 138

def add_product(product_name, product_price, peaces, tax)
  @data[:products]<< {:product => product_name, :price => product_price, :pcs => peaces, :tax => tax}
  @data[:total] += product_price*peaces
  self
end

#cod=(cod) ⇒ Object

Parameters:

  • cod (Boolean)
    • cash on delivery



113
114
115
116
# File 'lib/elms/export.rb', line 113

def cod=(cod)
  @data[:cod] = cod
  self
end

#currency(currency) ⇒ Object

Parameters:

  • currency (Integer)

    One of CURRENCY_CZK - 1 or CURRENCY_EUR - 2



194
195
196
197
198
199
200
# File 'lib/elms/export.rb', line 194

def currency(currency)
  if (currency != CURRENCY_CZK and currency != CURRENCY_EUR)
    throw 'Invalid currency :'+currency
  end
  @data[:currency_id] = currency
  self
end

#customer(company, name, surname, email, street, city, country, postal_code, phone, ic = nil, dic = nil) ⇒ Object

Parameters:

  • company (String)
  • name (String)
  • surname (String)
  • email (String)
  • street (String)
  • city (String)
  • country (String)
  • postal_code (String)
  • phone (String)
  • ic (String) (defaults to: nil)
  • dic (String) (defaults to: nil)


155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/elms/export.rb', line 155

def customer(company, name, surname, email, street, city, country, postal_code, phone, ic = nil, dic = nil)
  @data[:customer][:company] = company
  @data[:customer][:name] = name
  @data[:customer][:surname] = surname
  @data[:customer][:email] = email
  @data[:customer][:street] = street
  @data[:customer][:city] = city
  @data[:customer][:country] = country
  @data[:customer][:postal_code] = postal_code
  @data[:customer][:phone] = phone
  @data[:customer][:ic] = ic
  @data[:customer][:dic] = dic
  self
end

#delivery(company, name, surname, email, street, city, country, postal_code, phone) ⇒ Object

Parameters:

  • company (String)
  • name (String)
  • surname (String)
  • email (String)
  • street (String)
  • city (String)
  • country (String)
  • postal_code (String)
  • phone (String)


179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/elms/export.rb', line 179

def delivery(company, name, surname, email, street, city, country, postal_code, phone)
  @data[:customer][:del_company] = company
  @data[:customer][:del_name] = name
  @data[:customer][:del_surname] = surname
  @data[:customer][:del_email] = email
  @data[:customer][:del_street] = street
  @data[:customer][:del_city] = city
  @data[:customer][:del_country] = country
  @data[:customer][:del_postal_code] = postal_code
  @data[:customer][:del_phone] = phone
  self
end

#invoice_number=(number) ⇒ Object



128
129
130
131
# File 'lib/elms/export.rb', line 128

def invoice_number=(number)
  @data[:invoice_number] = number
  self
end

#order_date=(date) ⇒ Object



123
124
125
126
# File 'lib/elms/export.rb', line 123

def order_date=(date)
  @data[:order_date] = date
  self
end

#order_numberObject



107
108
109
# File 'lib/elms/export.rb', line 107

def order_number
  @data[:order_number]
end

#order_number=(order_number) ⇒ Object



102
103
104
105
# File 'lib/elms/export.rb', line 102

def order_number=(order_number)
  @data[:order_number] = order_number
  self
end

#sendToElmsObject



203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/elms/export.rb', line 203

def sendToElms
  require 'base64'
  require 'json'
  require 'net/http'
  require 'curl'

  encoded = Base64.strict_encode64(@data.to_json.to_s)

  # http://fulfillment.elmsservice.cz/orders/import?data=
  send_to_url = "http://fulfillment.elmsservice.cz/orders/import?data=#{encoded}"
  res = ::Curl.get(send_to_url)
  res.body_str

end

#total=(total) ⇒ Object



118
119
120
121
# File 'lib/elms/export.rb', line 118

def total=(total)
  @data[:total] = total
  self
end