aub-payroll 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.scss-lint.yml ADDED
@@ -0,0 +1,25 @@
1
+ exclude:
2
+ - '*.min.css'
3
+ - 'vendor/assets/**/*'
4
+ - 'node_modules/**/*'
5
+ - 'coverage/**/*'
6
+
7
+ linters:
8
+ ColorKeyword:
9
+ enabled: false
10
+ Indentation:
11
+ width: 2
12
+ character: "space"
13
+ LeadingZero:
14
+ style: "include_zero"
15
+ ColorVariable:
16
+ enabled: false
17
+ Comment:
18
+ enabled: false
19
+ SelectorDepth:
20
+ max_depth: 5
21
+ NestingDepth:
22
+ max_depth: 5
23
+ QualifyingElement:
24
+ allow_element_with_attribute: true
25
+ allow_element_with_class: true
data/.travis.yml CHANGED
@@ -1,3 +1,18 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.1.6
4
+
5
+ env:
6
+ - CI=true
7
+
8
+ before_install:
9
+ - PWD=`pwd`
10
+ - "echo '## Installing dependencies'"
11
+ - "sudo apt-get update"
12
+ - "sudo apt-get install -y openssl build-essential xorg libssl-dev xfonts-75dpi"
13
+ - "echo '## Downloading wkhtmltopdf'"
14
+ - "wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-wheezy-amd64.deb"
15
+ - "echo '## Installing wkhtmltox'"
16
+ - "sudo dpkg -i wkhtmltox-0.12.2.1_linux-wheezy-amd64.deb"
17
+ - WHICH_WK=`which wkhtmltopdf`
18
+ - "export WKHTMLTOPDF_CMD=$WHICH_WK"
data/DEPLOYING.md ADDED
@@ -0,0 +1,25 @@
1
+ ## Setup
2
+
3
+ In order to deploy a new version of the gem into the wild ...
4
+
5
+ You will need to configure your github api token for the changelog.
6
+
7
+ Generate a new token for changelogs [here](https://github.com/settings/tokens/new).
8
+
9
+ add:
10
+
11
+ ```bash
12
+ export CHANGELOG_GITHUB_TOKEN=YOUR_CHANGELOG_API_TOKEN
13
+ ```
14
+
15
+ somewhere in your shell init. (ie .zshrc or simillar)
16
+
17
+ ## Deploying
18
+
19
+ 1. Update `lib/aub-payroll/version.rb`
20
+ 2. Commit the changed files with the version number eg: `1.8.0`
21
+ 3. Push this to git
22
+ 4. Run `rake release`
23
+ 5. Run `rake changelog` (has to be ran after release since its based on github tagging)
24
+ 6. Commit the changed changelog named something like `changelog for 1.8.0`
25
+ 7. Push this to git
data/README.md CHANGED
@@ -24,23 +24,72 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
+ ### Configuration
28
+
29
+ This gem uses wkhtmltopdf, it has been tested against version 0.12.3
30
+
31
+ If you'r wkhtmltopdf binary is different from the default, you can set it in the gem confuguration as follows:
32
+
27
33
  ```ruby
28
- file = AUB::Payroll::File.new company_name: "StyroPrints",
29
- date: Date.new(2000, 6, 2),
30
- transactions: [
31
- { account_number: "001120001146", amount: 540.00 },
32
- { account_number: "001120001146", amount: 921.00 },
33
- { account_number: "001120001146", amount: 816.25 },
34
- { account_number: "001120001146", amount: 500.00 },
35
- { account_number: "001120001146", amount: 882.50 },
36
- { account_number: "001120001146", amount: 857.50 },
37
- { account_number: "001120001146", amount: 1_044.00 },
38
- { account_number: "001120001146", amount: 1_612.50 }
39
- ]
34
+ AUB::Payroll.configure do |c|
35
+ c.wkhtmltopdf_bin = 'wkhtmltopdf-0.12.3'
36
+ end
37
+ ```
38
+
39
+ ### EPF Bank File
40
40
 
41
+ ```ruby
42
+ file = AUB::Payroll::EPFFile.new company_name: "StyroPrints",
43
+ date: Date.new(2000, 6, 2),
44
+ transactions: [
45
+ { account_number: "001120001146", amount: 540.00 },
46
+ { account_number: "001120001146", amount: 921.00 },
47
+ { account_number: "001120001146", amount: 816.25 },
48
+ { account_number: "001120001146", amount: 500.00 },
49
+ { account_number: "001120001146", amount: 882.50 },
50
+ { account_number: "001120001146", amount: 857.50 },
51
+ { account_number: "001120001146", amount: 1_044.00 },
52
+ { account_number: "001120001146", amount: 1_612.50 }
53
+ ]
54
+
41
55
  File.write "payroll.epf", file.content
42
56
  ```
43
57
 
58
+ ### Summary PDF File
59
+
60
+ ```ruby
61
+ company_info = {
62
+ name: 'SomeCorp',
63
+ account_number: '12345678',
64
+ bank_branch: 'SomeBranch',
65
+ address1: '123 some address',
66
+ address2: '543 some more addresss',
67
+ prepared_by_name_1: 'William Samson',
68
+ prepared_by_name_2: 'Junior P. Santos',
69
+ checked_by_name_1: 'Winnie Po',
70
+ checked_by_name_2: 'Paul Sen',
71
+ }
72
+
73
+ transactions = [
74
+ {
75
+ employee_name: 'John Doe',
76
+ account_number: '12345678',
77
+ amount: 1235.45,
78
+ }
79
+ ] * 47 # ok fine, this is a repeating example, but you'd have real data here :)
80
+
81
+ payroll_info = {
82
+ period_start: Date.new(2010, 1, 1),
83
+ period_end: Date.new(2010, 1, 31),
84
+ pay_date: Date.new(2010, 2, 5),
85
+ total: transactions.sum { |t| t[:amount] },
86
+ }
87
+
88
+ pdf = AUB::Payroll::SummaryFile.generate(company_info: company_info, payroll_info: payroll_info, transactions: transactions)
89
+
90
+ File.write "summary.pdf", pdf
91
+ ```
92
+
44
93
  ## Development
45
94
 
46
95
  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.
data/aub-payroll.gemspec CHANGED
@@ -4,25 +4,35 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'aub/payroll/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "aub-payroll"
7
+ spec.name = 'aub-payroll'
8
8
  spec.version = AUB::Payroll::VERSION
9
- spec.authors = ["Ronald Maravilla"]
10
- spec.email = ["rmaravilla@payrollhero.com"]
9
+ spec.authors = ['Ronald Maravilla']
10
+ spec.email = ['rmaravilla@payrollhero.com']
11
11
 
12
- spec.summary = %q{An AUB Payroll File Generator.}
13
- spec.description = %q{An AUB Payroll File Generator.}
14
- spec.homepage = "https://github.com/payrollhero/aub-payroll"
15
- spec.license = "BSD-3-Clause"
12
+ spec.summary = 'An AUB Payroll File Generator.'
13
+ spec.description = 'An AUB Payroll File Generator.'
14
+ spec.homepage = 'https://github.com/payrollhero/aub-payroll'
15
+ spec.license = 'BSD-3-Clause'
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
18
+ spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.9"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency 'bundler', '~> 1.9'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'pry'
26
+ spec.add_development_dependency 'shotgun'
27
+ spec.add_development_dependency 'pdf_spec'
28
+ spec.add_development_dependency 'github_changelog_generator'
25
29
 
26
- spec.add_dependency "activesupport"
27
- spec.add_dependency "activemodel"
30
+ spec.add_dependency 'activesupport'
31
+ spec.add_dependency 'activemodel'
32
+ spec.add_dependency 'pdfkit'
33
+ spec.add_dependency 'ph_model'
34
+ spec.add_dependency 'tilt'
35
+ spec.add_dependency 'slim'
36
+ spec.add_dependency 'sass'
37
+ spec.add_dependency 'configurations', '~> 2.2.0'
28
38
  end
data/lib/aub/payroll.rb CHANGED
@@ -3,11 +3,26 @@ require "active_support"
3
3
  require "active_support/dependencies/autoload"
4
4
  require "active_support/core_ext/enumerable"
5
5
 
6
+ require 'pdfkit'
7
+ require 'ph_model'
8
+ require 'tilt'
9
+ require 'configurations'
10
+
6
11
  module AUB
7
12
  module Payroll
8
13
  extend ActiveSupport::Autoload
14
+ include Configurations
15
+
16
+ configurable :wkhtmltopdf_bin
17
+
18
+ configuration_defaults do |c|
19
+ c.wkhtmltopdf_bin = 'wkhtmltopdf'
20
+ end
9
21
 
10
22
  autoload :Errors
11
- autoload :File
23
+ autoload :EPFFile
24
+ autoload :SummaryFile
25
+
26
+ GEM_ROOT = File.expand_path(File.dirname(__FILE__) + '/../..')
12
27
  end
13
28
  end
@@ -2,7 +2,7 @@ require "active_model"
2
2
 
3
3
  module AUB
4
4
  module Payroll
5
- class File
5
+ class EPFFile
6
6
  extend ActiveSupport::Autoload
7
7
 
8
8
  autoload :Header
@@ -1,8 +1,8 @@
1
- require "active_model"
1
+ require 'active_model'
2
2
 
3
3
  module AUB
4
4
  module Payroll
5
- class File::Footer
5
+ class EPFFile::Footer
6
6
  include ActiveModel::Model
7
7
 
8
8
  attr_accessor :number_of_records, :total_amount
@@ -17,24 +17,23 @@ module AUB
17
17
  raise Errors::Invalid, errors.full_messages.to_sentence unless valid?
18
18
  end
19
19
 
20
-
21
20
  def to_s
22
21
  [
23
- "EF", # marks the end of file
22
+ 'EF', # marks the end of file
24
23
  formatted_number_of_records,
25
24
  formatted_total_amount,
26
- "0" * 27,
25
+ '0' * 27,
27
26
  ].join
28
27
  end
29
28
 
30
29
  private
31
30
 
32
31
  def formatted_number_of_records
33
- "%06d" % number_of_records
32
+ format '%06d', number_of_records
34
33
  end
35
34
 
36
35
  def formatted_total_amount
37
- "%015.2f" % total_amount
36
+ format '%015.2f', total_amount
38
37
  end
39
38
  end
40
39
  end
@@ -1,8 +1,8 @@
1
- require "active_model"
1
+ require 'active_model'
2
2
 
3
3
  module AUB
4
4
  module Payroll
5
- class File::Header
5
+ class EPFFile::Header
6
6
  include ActiveModel::Model
7
7
 
8
8
  attr_accessor :company_name, :date
@@ -17,10 +17,9 @@ module AUB
17
17
  raise Errors::Invalid, errors.full_messages.to_sentence unless valid?
18
18
  end
19
19
 
20
-
21
20
  def to_s
22
21
  [
23
- "BF", # marks the beginning of file
22
+ 'BF', # marks the beginning of file
24
23
  formatted_company_name,
25
24
  formatted_date,
26
25
  ].join
@@ -33,7 +32,7 @@ module AUB
33
32
  end
34
33
 
35
34
  def formatted_date
36
- date.strftime "%Y%m%d"
35
+ date.strftime '%Y%m%d'
37
36
  end
38
37
  end
39
38
  end
@@ -1,8 +1,8 @@
1
- require "active_model"
1
+ require 'active_model'
2
2
 
3
3
  module AUB
4
4
  module Payroll
5
- class File::Row
5
+ class EPFFile::Row
6
6
  include ActiveModel::Model
7
7
 
8
8
  attr_accessor :account_number, :amount
@@ -17,20 +17,19 @@ module AUB
17
17
  raise Errors::Invalid, errors.full_messages.to_sentence unless valid?
18
18
  end
19
19
 
20
-
21
20
  def to_s
22
21
  [
23
- "01",
22
+ '01',
24
23
  account_number,
25
24
  formatted_amount,
26
- "0" * 22
25
+ '0' * 22
27
26
  ].join
28
27
  end
29
28
 
30
29
  private
31
30
 
32
31
  def formatted_amount
33
- "%014.2f" % amount
32
+ format '%014.2f', amount
34
33
  end
35
34
  end
36
35
  end
@@ -0,0 +1,19 @@
1
+ module AUB
2
+ module Payroll
3
+ module SummaryFile
4
+ extend ActiveSupport::Autoload
5
+
6
+ autoload :Generator
7
+ autoload :HTMLGenerator
8
+ autoload :CompanyInfo
9
+ autoload :PayrollInfo
10
+ autoload :Transaction
11
+ autoload :CustomPDFKit
12
+
13
+ def self.generate(*args)
14
+ Generator.new(*args).generate
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module AUB
2
+ module Payroll
3
+ module SummaryFile
4
+ class CompanyInfo
5
+ include PhModel
6
+
7
+ attribute :name
8
+ attribute :account_number
9
+ attribute :address1
10
+ attribute :address2
11
+ attribute :bank_branch
12
+
13
+ attribute :prepared_by_name_1
14
+ attribute :prepared_by_name_2
15
+ attribute :checked_by_name_1
16
+ attribute :checked_by_name_2
17
+
18
+ validates :name, :account_number, :bank_branch, presence: true
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module AUB
2
+ module Payroll
3
+ module SummaryFile
4
+
5
+ # just overriding executable so its easy to configure this for the gem directly
6
+ class CustomPDFKit < PDFKit
7
+ def executable
8
+ AUB::Payroll.configuration.wkhtmltopdf_bin
9
+ end
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,36 @@
1
+ module AUB
2
+ module Payroll
3
+ module SummaryFile
4
+ class Generator
5
+
6
+ def initialize(company_info:, payroll_info:, transactions:)
7
+ @company_info = CompanyInfo.build(company_info)
8
+ @payroll_info = PayrollInfo.build(payroll_info)
9
+ @transactions = transactions.map { |transaction| Transaction.build(transaction) }
10
+ end
11
+
12
+ def generate
13
+ html_generator.generate do
14
+ kit = File.open('body.html', 'r') do |body_file|
15
+ options = {
16
+ page_size: 'Letter',
17
+ header_html: 'header.html',
18
+ footer_html: 'footer.html',
19
+ margin_top: 38,
20
+ margin_bottom: 5,
21
+ margin_left: 0,
22
+ margin_right: 0,
23
+ }
24
+ CustomPDFKit.new(body_file, options)
25
+ end
26
+ kit.to_pdf
27
+ end
28
+ end
29
+
30
+ def html_generator
31
+ HTMLGenerator.new(company_info: @company_info, payroll_info: @payroll_info, transactions: @transactions)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end