extface 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86eeadecf20a2ea8daa39cb2ba6ebdbe73a34412
4
- data.tar.gz: 382850d445c1c6b67deea928c4721f3c64010603
3
+ metadata.gz: 905561e9d8179ca1ad66c6677a6a63be78cd5d40
4
+ data.tar.gz: 0f152bcf718ee7d6386fa53460c6c5a71b307d4d
5
5
  SHA512:
6
- metadata.gz: a106262ddd387f6952e355fbf55dad497171295d7c02f9c0701c829d3bd26e0db74829663df377fb7a429b489265f96c254d8e30485b4afec9fe322f5cecba6e
7
- data.tar.gz: a1fb0ba140eb33919fcf1119004df102335e66d101820b2d9f340af7eb43a9e5a3e795990b6e78e16e6781a117bb097b3a8dd847cf205427cd5f6d60284ead55
6
+ metadata.gz: bbe9348d5e1d1419cf55014638705fe61dc61de9ab19d16f3db420ae7b25f7e690c3a217e38d85609a680dfd5aeb143f246aa132ac96257abe9595be9b280355
7
+ data.tar.gz: 51ac47fac3046fa4bd6b9dba3f3a2a3ea5a676f35fcfe78548b2090a460d292571e2c0b0d91e0c7804edc9db277e3deea76fda2dbbcbd4dfa9737a5158f77719
@@ -119,17 +119,24 @@ module Extface
119
119
  s.notify "Fiscal Doc Start"
120
120
  s.open_fiscal_doc(operator_mapping.try(:mapping), operator_mapping.try(:pwd))
121
121
  s.notify "Register Sale"
122
+ total_modifier = nil # send payments sum, so modifier make no sence! think
123
+ # if global_modifier_value = bill.global_modifier_value
124
+ # s.notify "Register Global Modifier"
125
+ # total_modifier = global_modifier_value.to_f
126
+ # end
122
127
  s.add_sale(
123
128
  SaleItem.new(
124
129
  price: bill.payments_sum.to_f,
125
- text1: bill.name,
130
+ #text1: bill.name,
131
+ text1: '',
126
132
  tax_group: bill.charges.first.find_tax_group_mapping_for(self), #find tax group mapping by ratio , not nice
133
+ neto: total_modifier
127
134
  )
128
135
  )
129
- if global_modifier_value = bill.global_modifier_value
130
- s.notify "Register Global Modifier"
131
- s.add_total_modifier global_modifier_value.to_f
132
- end
136
+ # if global_modifier_value = bill.global_modifier_value
137
+ # s.notify "Register Global Modifier"
138
+ # s.add_total_modifier global_modifier_value.to_f
139
+ # end
133
140
  s.notify "Register Payment"
134
141
  bill.payments.each do |payment|
135
142
  s.add_payment payment.value.to_f, payment.find_payment_type_mapping_for(self)
@@ -224,7 +224,7 @@ module Extface
224
224
  end
225
225
  elsif !resp.ack?
226
226
  invalid_frames += 1
227
- if nak_messages > INVALID_FRAME_RETRIES
227
+ if invalid_frames > INVALID_FRAME_RETRIES
228
228
  errors.add :base, "#{INVALID_FRAME_RETRIES} Broken Packets Received. Abort!"
229
229
  break
230
230
  end
@@ -256,7 +256,7 @@ module Extface
256
256
  data << ("%.2f" % item.price)
257
257
  data << "*#{item.qty.to_s}" unless item.qty.blank?
258
258
  data << ",#{item.percent}" unless item.percent.blank?
259
- data << "$#{neto}" unless item.neto.blank?
259
+ data << "$#{'%.2f' % item.neto}" unless item.neto.blank?
260
260
  end
261
261
  end
262
262
 
@@ -283,7 +283,7 @@ module Extface
283
283
  errors.add :base, "Fiscal Device General Error" unless (status[0].ord & 0x20).zero?
284
284
  errors.add :base, "Invalid Command" unless (status[0].ord & 0x02).zero?
285
285
  errors.add :base, "Date & Time Not Set" unless (status[0].ord & 0x04).zero?
286
- errors.add :base, "Syntax Error" unless (status[0].ord & 0x02).zero?
286
+ errors.add :base, "Syntax Error" unless (status[0].ord & 0x01).zero?
287
287
 
288
288
  errors.add :base, "Wrong Password" unless (status[1].ord & 0x40).zero?
289
289
  errors.add :base, "Cutter Error" unless (status[1].ord & 0x20).zero?
@@ -317,7 +317,38 @@ module Extface
317
317
  when 22 then errors.add :base, "Disabled operation"
318
318
  when 23 then errors.add :base, "Deep void after discount"
319
319
  when 24 then errors.add :base, "Deep void for not existing record"
320
- when 24 then errors.add :base, "Payment without sale"
320
+ when 25 then errors.add :base, "Payment without sale"
321
+ when 26 then errors.add :base, "Qty more than stock"
322
+ when 41 then errors.add :base, "Invalid barcode"
323
+ when 42 then errors.add :base, "Sale with null barcode"
324
+ when 43 then errors.add :base, "Wight barcode attempt"
325
+ when 44 then errors.add :base, "Missing barcode sale"
326
+ when 45 then errors.add :base, "Duplicate barcode"
327
+ when 66 then errors.add :base, "Invalid password"
328
+ when 71 then errors.add :base, "!!!Invalid FP data!!!"
329
+ when 72 then errors.add :base, "!!!Error writing FP!!!"
330
+ when 76 then errors.add :base, "NAP server info required"
331
+ when 90 then errors.add :base, "Non zero period report"
332
+ when 91 then errors.add :base, "Non zero daily report"
333
+ when 92 then errors.add :base, "Non zero operator report"
334
+ when 93 then errors.add :base, "Non zero items report"
335
+ when 94 then errors.add :base, "Field can not be programmed"
336
+ when 81 then errors.add :base, "Daily report overflow"
337
+ when 82 then errors.add :base, "24 without daily report"
338
+ when 83 then errors.add :base, "Oerators report overflow"
339
+ when 84 then errors.add :base, "Items report overflow"
340
+ when 85 then errors.add :base, "Period report overflow"
341
+ when 88 then errors.add :base, "KLEN overflow"
342
+ when 102 then errors.add :base, "TAX terminal connection missing"
343
+ when 104 then errors.add :base, "TAX terminal connection error"
344
+ when 108 then errors.add :base, "3 attempts wrong password"
345
+ when 110 then errors.add :base, "SIM card changed"
346
+ when 111 then errors.add :base, "TAX terminal - NAP server error"
347
+ when 113 then errors.add :base, "NAP rejected data"
348
+ when 117 then errors.add :base, "Unable to register TAX terminal into mobile network"
349
+ when 118 then errors.add :base, "Forbidden operation"
350
+ when 119 then errors.add :base, "Invalid value"
351
+ when 120 then errors.add :base, "Missing value"
321
352
  end
322
353
 
323
354
  errors.add :base, "General Fiscal Memory Error" unless (status[4].ord & 0x20).zero?
@@ -6,11 +6,31 @@ module Extface
6
6
  INVALID_FRAME_RETRIES = 6 #count (bad length, bad checksum)
7
7
  ACKS_MAX_WAIT = 60 #count / nothing is forever
8
8
  NAKS_MAX_COUNT = 3 #count
9
+
10
+ TAX_GROUPS_MAP = {
11
+ 1 => "\xc0",
12
+ 2 => "\xc1",
13
+ 3 => "\xc2",
14
+ 4 => "\xc3",
15
+ 5 => "\xc4",
16
+ 6 => "\xc5",
17
+ 7 => "\xc6",
18
+ 8 => "\xc7"
19
+ }
20
+
21
+ PAYMENT_TYPE_MAP = {
22
+ 1 => "P",
23
+ 2 => "N",
24
+ 3 => "C",
25
+ 4 => "D",
26
+ 5 => "B"
27
+ }
9
28
 
10
29
  include Extface::Driver::Datecs::CommandsV1
11
30
 
12
31
  def handle(buffer)
13
- if i = buffer.index(/[\x03\x16\x15]/) # find position of frame possible delimiter
32
+ #if i = buffer.index(/[\x03\x16\x15]/) # find position of frame possible delimiter
33
+ if i = buffer.index("\x03") || buffer.index("\x16") || buffer.index("\x15")
14
34
  rpush buffer[0..i] # this will make data available for #pull(timeout) method
15
35
  return i+1 # return number of bytes processed
16
36
  end
@@ -77,8 +97,8 @@ module Extface
77
97
  end
78
98
 
79
99
  #fiscal
80
- def open_fiscal_doc(operator = "1", password = "1")
81
- fsend Sales::START_FISCAL_DOC, "#{operator.presence || "1"},#{password.presence || "1"},00001"
100
+ def open_fiscal_doc(operator = "1", password = "000000")
101
+ fsend Sales::START_FISCAL_DOC, "#{operator.presence || "1"},#{password.presence || "000000"},00001"
82
102
  @fiscal_session = true
83
103
  end
84
104
 
@@ -132,7 +152,7 @@ module Extface
132
152
  def cancel_doc_session
133
153
  device.session("Doc cancel") do |s|
134
154
  s.notify "Doc Cancel Start"
135
- s.fsend Sales::CANCEL_DOC
155
+ s.fsend Sales::CANCEL_FISCAL_DOC
136
156
  s.paper_cut
137
157
  s.notify "Doc Cancel End"
138
158
  end
@@ -165,7 +185,7 @@ module Extface
165
185
  end
166
186
  elsif !resp.ack?
167
187
  invalid_frames += 1
168
- if nak_messages > INVALID_FRAME_RETRIES
188
+ if invalid_frames > INVALID_FRAME_RETRIES
169
189
  errors.add :base, "#{INVALID_FRAME_RETRIES} Broken Packets Received. Abort!"
170
190
  break
171
191
  end
@@ -211,11 +231,25 @@ module Extface
211
231
  errors.add :base, "Fiscal Device General Error" unless (status_0 & 0x20).zero?
212
232
  errors.add :base, "Invalid Command" unless (status_0 & 0x02).zero?
213
233
  errors.add :base, "Date & Time Not Set" unless (status_0 & 0x04).zero?
214
- errors.add :base, "Syntax Error" unless (status_0 & 0x02).zero?
234
+ errors.add :base, "Syntax Error" unless (status_0 & 0x01).zero?
215
235
  status_1 = status[1].ord
236
+ errors.add :base, "Unpermitted Command In This Mode" unless (status_1 & 0x02).zero?
237
+ errors.add :base, "Field Overflow" unless (status_1 & 0x01).zero?
216
238
  end
217
239
 
218
240
  private
241
+ def build_sale_data(item)
242
+ "".tap() do |data|
243
+ data << item.text1 unless item.text1.blank?
244
+ data << "\x0a#{text2}" unless item.text2.blank?
245
+ data << "\t"
246
+ data << TAX_GROUPS_MAP[item.tax_group || 2]
247
+ data << ("%.2f" % item.price)
248
+ data << "*#{item.qty.to_s}" unless item.qty.blank?
249
+ data << ",#{item.percent}" unless item.percent.blank?
250
+ data << ",;#{'%.2f' % item.neto}" unless item.neto.blank?
251
+ end
252
+ end
219
253
 
220
254
  def sequence_number
221
255
  @seq ||= 0x1f
@@ -228,7 +262,7 @@ module Extface
228
262
  include ActiveModel::Validations
229
263
  attr_reader :frame, :len, :seq, :cmd, :data, :status, :bcc
230
264
 
231
- validates_presence_of :frame, unless: :unpacked?
265
+ validates_presence_of :frame#, unless: :unpacked?
232
266
  validate :bcc_validation
233
267
  validate :len_validation
234
268
 
@@ -250,6 +284,7 @@ module Extface
250
284
  def nak?; !!@nak; end #should retry command with same seq
251
285
 
252
286
  private
287
+
253
288
  def unpacked? # is it packed or unpacked message?
254
289
  @ack || @nak
255
290
  end
@@ -1,3 +1,3 @@
1
1
  module Extface
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extface
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Vangelov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-03 00:00:00.000000000 Z
11
+ date: 2015-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails