china_bank-payroll_text_file 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6cc594d65bfd78ce8a6b3d251f591cbe5f58c1e5
4
+ data.tar.gz: cbe63b5572f57a9d389ed558ac1f6b4413ccff3a
5
+ SHA512:
6
+ metadata.gz: 3b9f428189caefca67dfa23f03af00e5d0f82a793e8ff1980d8865a4eb10e741412c4990a7a87d38979d34bf25ec1ceb76db582ee0f054cc53eebb038e1c46dc
7
+ data.tar.gz: abf297f6a758e51b71802d1800ae57906211473445fbdc040ba224afe4e67bd5ddcc13e14c03bbfbddc46951823301ad688e0b1e9655265e46038596fc7b34c4
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.6
4
+ - 2.2.3
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in china_bank-payroll_text_file.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014, PayrollHero PTE. Ltd. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that
4
+ the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7
+ following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10
+ following disclaimer in the documentation and/or other materials provided with the distribution.
11
+
12
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
13
+ promote products derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
18
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
21
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
22
+ DAMAGE.
@@ -0,0 +1,56 @@
1
+ # ChinaBank::PayrollTextFile
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/china_bank-payroll_text_file.svg)](http://badge.fury.io/rb/china_bank-payroll_text_file)
4
+ [![Code Climate](https://codeclimate.com/github/payrollhero/china_bank-payroll_text_file/badges/gpa.svg)](https://codeclimate.com/github/payrollhero/china_bank-payroll_text_file)
5
+ [![Build Status](https://travis-ci.org/payrollhero/china_bank-payroll_text_file.svg)](https://travis-ci.org/payrollhero/china_bank-payroll_text_file)
6
+
7
+ A payroll text file generator for China Bank. This specifically supports the format [China Bank Auto
8
+ Credit Arrangement (ACA)](http://www.chinabank.ph/business.aspx?title=China+Bank+Auto+Credit+Arrangement+%28ACA%29) requires.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'china_bank-payroll_text_file'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install china_bank-payroll_text_file
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ file = ChinaBank::PayrollTextFile.generate account_type: "SA",
30
+ account_number: "1850889513",
31
+ bank_code: "102",
32
+ transactions: [
33
+ {
34
+ account_type: "CA",
35
+ account_number: "2030347812",
36
+ bank_code: "102",
37
+ amount: BigDecimal("12965.50")
38
+ }
39
+ ]
40
+
41
+ file.content #=> "*CA2030347812 00000012965.50 C102*\r\n*SA1850889513 00000012965.50 D102*"
42
+ ```
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it ( https://github.com/[my-github-username]/china_bank-payroll_text_file/fork )
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require "rspec/core/rake_task"
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task default: :spec
7
+ rescue LoadError
8
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "china_bank/payroll_text_file"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'china_bank/payroll_text_file/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "china_bank-payroll_text_file"
8
+ spec.version = ChinaBank::PayrollTextFile::VERSION
9
+ spec.authors = ["Ronald Maravilla"]
10
+ spec.email = ["rmaravilla@payrollhero.com"]
11
+
12
+ spec.summary = %q{A payroll text file generator for China Bank}
13
+ spec.description = %q{A payroll text file generator for China Bank}
14
+ spec.homepage = "https://github.com/payrollhero/china_bank-payroll_text_file"
15
+ spec.license = "BSD-3-Clause"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+
27
+ spec.add_dependency "activesupport"
28
+ spec.add_dependency "activemodel"
29
+ end
@@ -0,0 +1,36 @@
1
+ require "china_bank/payroll_text_file/version"
2
+ require "bigdecimal"
3
+ require "active_support"
4
+
5
+ module ChinaBank
6
+ # Generates a payroll text file compatible with China Bank Auto Credit Arrangement (ACA).
7
+ #
8
+ # @example:
9
+ # ChinaBank::PayrollTextFile.generate account_number: ,
10
+ # account_type: ,
11
+ # branch_code: ,
12
+ # transaction_type: ,
13
+ # transactions: [
14
+ # {
15
+ # amount: ,
16
+ # account_number: ,
17
+ # account_type: ,
18
+ # branch_code: ,
19
+ # transaction_type:
20
+ # }
21
+ # ]
22
+ module PayrollTextFile
23
+ extend ActiveSupport::Autoload
24
+
25
+ autoload :File
26
+ autoload :Line
27
+
28
+ class << self
29
+ # @param [Hash] options
30
+ # @return [ChinaBank::PayrollTextFile::File]
31
+ def generate(**options)
32
+ File.new options
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,54 @@
1
+ require "active_support/core_ext/enumerable"
2
+
3
+ module ChinaBank
4
+ module PayrollTextFile
5
+ # Describes the payroll text file's content including the lines that builds it.
6
+ class File
7
+ # @param [String] account_number
8
+ # @param [String] account_type
9
+ # @param [String] bank_code
10
+ # @param [Array<Hash>] transactions
11
+ def initialize(account_number:, account_type: "00", bank_code: "888", transactions: [])
12
+ @account_number = account_number
13
+ @account_type = account_type
14
+ @bank_code = bank_code
15
+ @transactions = transactions
16
+ end
17
+
18
+ # @return [String]
19
+ def content
20
+ (credit_lines + [debit_line]).join(new_line) + new_line
21
+ end
22
+
23
+ # @return [Array<ChinaBank::PayrollTextFile::Line>
24
+ def credit_lines
25
+ transactions.map { |transaction| Line.new transaction.merge(transaction_type: Line::TYPES[:credit]) }
26
+ end
27
+
28
+ # @return [ChinaBank::PayrollTextFile::Line]
29
+ def debit_line
30
+ Line.new account_number: account_number,
31
+ account_type: account_type,
32
+ bank_code: bank_code,
33
+ transaction_type: Line::TYPES[:debit],
34
+ amount: total
35
+ end
36
+
37
+ private
38
+
39
+ attr_reader :account_number,
40
+ :account_type,
41
+ :bank_code,
42
+ :transaction_type,
43
+ :transactions
44
+
45
+ def total
46
+ transactions.sum(BigDecimal 0) { |transaction| transaction.fetch :amount }
47
+ end
48
+
49
+ def new_line
50
+ "\r\n"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,78 @@
1
+ require "active_model"
2
+
3
+ module ChinaBank
4
+ module PayrollTextFile
5
+ # Describes each line on China Bank's payroll text file.
6
+ class Line
7
+ include ActiveModel::Model
8
+
9
+ AMOUNT_RANGE = BigDecimal("0").. BigDecimal("99999999999.99")
10
+ TYPES = {
11
+ credit: "C",
12
+ debit: "D"
13
+ }
14
+
15
+ attr_accessor :account_type,
16
+ :account_number,
17
+ :amount,
18
+ :transaction_type,
19
+ :bank_code
20
+
21
+ validates :account_type, inclusion: { in: ["CA", "SA", "00"], message: "must be either CA, SA, or 00" }
22
+ validates :account_number, length: { in: 10..12 }, numericality: { only_integer: true }
23
+ validates :amount, inclusion: { in: AMOUNT_RANGE, message: "must be between 0.00 to 99,999,999,999.99" }
24
+ validates :transaction_type, inclusion: { in: TYPES.values, message: "must be either C or D" }
25
+ validates :bank_code, length: { is: 3 }, numericality: { only_integer: true }
26
+ validates :account_type, :account_number, :amount, :transaction_type, :bank_code, presence: true
27
+
28
+ # @param [String] account_type
29
+ # @param [String] account_number
30
+ # @param [BigDecimal] amount
31
+ # @param [String] transaction_type
32
+ # @param [String] bank_code
33
+ def initialize(account_type: "00", account_number:, amount:, transaction_type:, bank_code: "888")
34
+ @account_number = account_number
35
+ @account_type = account_type
36
+ @bank_code = bank_code
37
+ @transaction_type = transaction_type
38
+ @amount = BigDecimal(amount.to_s)
39
+
40
+ raise ArgumentError, errors.full_messages.to_sentence unless valid?
41
+ end
42
+
43
+ # @example: "*SA1850889513 00000053931.70 D102*"
44
+ # @return [String]
45
+ def to_s
46
+ [
47
+ terminator_character, # "*"
48
+ account_type, # "SA"
49
+ formatted_account_number, # "1850889513 "
50
+ spacer, # " "
51
+ formatted_amount, # 00000053931.70
52
+ spacer, # " "
53
+ transaction_type, # "D"
54
+ bank_code, # "102"
55
+ terminator_character # "*"
56
+ ].join
57
+ end
58
+
59
+ private
60
+
61
+ def terminator_character
62
+ "*"
63
+ end
64
+
65
+ def spacer
66
+ " "
67
+ end
68
+
69
+ def formatted_account_number
70
+ account_number.ljust(12)
71
+ end
72
+
73
+ def formatted_amount
74
+ "%014.2f" % amount
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,5 @@
1
+ module ChinaBank
2
+ module PayrollTextFile
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: china_bank-payroll_text_file
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ronald Maravilla
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activemodel
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A payroll text file generator for China Bank
84
+ email:
85
+ - rmaravilla@payrollhero.com
86
+ executables:
87
+ - console
88
+ - setup
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - CODE_OF_CONDUCT.md
96
+ - Gemfile
97
+ - LICENSE
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - china_bank-payroll_text_file.gemspec
103
+ - lib/china_bank/payroll_text_file.rb
104
+ - lib/china_bank/payroll_text_file/file.rb
105
+ - lib/china_bank/payroll_text_file/line.rb
106
+ - lib/china_bank/payroll_text_file/version.rb
107
+ - lib/references/China Bank ACA File Structure Specs.xlsx
108
+ homepage: https://github.com/payrollhero/china_bank-payroll_text_file
109
+ licenses:
110
+ - BSD-3-Clause
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.2.3
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A payroll text file generator for China Bank
132
+ test_files: []
133
+ has_rdoc: