einvoice 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,43 +0,0 @@
1
- module Einvoice
2
- module Neweb
3
- module Validator
4
- class QuantityValidator < ActiveModel::EachValidator
5
- include Einvoice::Neweb::Validator
6
-
7
- def validate_each(record, attribute, value)
8
- unless valid_float?(value)
9
- record.errors.add attribute, options[:message] || :invalid
10
- end
11
- end
12
- end
13
-
14
- class UnitPriceValidator < ActiveModel::EachValidator
15
- include Einvoice::Neweb::Validator
16
-
17
- def validate_each(record, attribute, value)
18
- unless valid_float?(value)
19
- record.errors.add attribute, options[:message] || :invalid
20
- end
21
- end
22
- end
23
-
24
- class AmountValidator < ActiveModel::EachValidator
25
- include Einvoice::Neweb::Validator
26
-
27
- def validate_each(record, attribute, value)
28
- unless valid_float?(value)
29
- record.errors.add attribute, options[:message] || :invalid
30
- end
31
- end
32
- end
33
-
34
- def valid_float?(value)
35
- integer, digit = value.to_s.split(".")[0..1]
36
- float_value = value.to_f.to_s
37
-
38
- return false if integer.nil? || digit.nil? || integer.delete("-").size > 12 || digit.try(:size) > 4
39
- return false if integer != float_value.split(".")[0] || digit != float_value.split(".")[1]
40
- end
41
- end
42
- end
43
- end
@@ -1,54 +0,0 @@
1
- module Einvoice
2
- module Neweb
3
- module Validator
4
- class BuyerNameValidator < ActiveModel::EachValidator
5
- def validate_each(record, attribute, value)
6
- if record.buyer_id.to_s == "0000000000" &&
7
- value.present? && (value.ascii_only? ? value.size > 4 : value.size > 2)
8
- record.errors.add attribute, options[:message] || :invalid
9
- end
10
- end
11
- end
12
-
13
- class DonateMarkValidator < ActiveModel::EachValidator
14
- def validate_each(record, attribute, value)
15
- if value == "1" && record.n_p_o_b_a_n.blank?
16
- record.errors.add attribute, options[:message] || :invalid
17
- end
18
- end
19
- end
20
-
21
- class CarrierId1Validator < ActiveModel::EachValidator
22
- def validate_each(record, attribute, value)
23
- if (record.print_mark.to_s == "Y" && value.present?) || (record.print_mark.to_s == "N" && value.blank?)
24
- record.errors.add attribute, options[:message] || :invalid
25
- end
26
- end
27
- end
28
-
29
- class CarrierId2Validator < ActiveModel::EachValidator
30
- def validate_each(record, attribute, value)
31
- if (record.print_mark.to_s == "Y" && value.present?) || (record.print_mark.to_s == "N" && value.blank?)
32
- record.errors.add attribute, options[:message] || :invalid
33
- end
34
- end
35
- end
36
-
37
- class PrintMarkValidator < ActiveModel::EachValidator
38
- def validate_each(record, attribute, value)
39
- if value == "Y" && (record.carrier_id1.present? || record.carrier_id2.present? || record.donate_mark == "Y")
40
- record.errors.add attribute, options[:message] || :invalid
41
- end
42
- end
43
- end
44
-
45
- class TotalAmountValidator < ActiveModel::EachValidator
46
- def validate_each(record, attribute, value)
47
- unless value != record.attributes.values_at("sales_amount", "free_tax_sales_amount", "zero_tax_sales_amount", "tax_amount").map(&:to_i).inject(&:+)
48
- record.errors.add attribute, options[:message] || :invalid
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,22 +0,0 @@
1
- require 'faraday'
2
-
3
- module Faraday
4
- class Request::DigestNeweb < Faraday::Middleware
5
- dependency do
6
- require 'digest' unless defined?(::Digest)
7
- end
8
-
9
- def initialize(app, secret)
10
- super(app)
11
- @secret = secret
12
- end
13
-
14
- def call(env)
15
- xmldata = env[:body][:xmldata]
16
- env[:body][:hash] = Digest::MD5.hexdigest(xmldata + @secret)
17
- @app.call env
18
- end
19
- end
20
- end
21
-
22
- Faraday::Request.register_middleware digest_neweb: Faraday::Request::DigestNeweb