Sha256: 13647782aa4b4ea67f4a7aff003b44b85b5c922d92b1a2d77adedc808e8a51fd

Contents?: true

Size: 1.8 KB

Versions: 3

Compression:

Stored size: 1.8 KB

Contents

require 'bootstrap-sass'
require 'kaminari'
require 'prawn'
require 'prawnto'
require 'jquery-rails'
require 'jquery-ui-rails'
require 'sorcery'
require 'nested_form'

# ARES
require 'xml'
require 'ruby-ares'

require 'formatted-money'

# Concerns
require File.expand_path("../../../app/concerns/invoice_bar/searchable.rb",  __FILE__)
require File.expand_path("../../../app/concerns/invoice_bar/billable.rb",  __FILE__)

I18n.available_locales = [:cs, :en]
I18n.locale = :cs

module InvoiceBar
  class Engine < ::Rails::Engine
    isolate_namespace InvoiceBar
  end

  module Generators
    # Document numbers generators defaults
    @@issued_invoice_number = Proc.new do |n|
      "VF#{self.default_number(n)}"
    end unless defined? @@issued_invoice_number

    @@received_invoice_number = Proc.new do |n|
      "PF#{self.default_number(n)}"
    end unless defined? @@received_invoice_number

    @@expense_receipt_number = Proc.new do |n|
      "VD#{self.default_number(n)}"
    end unless defined? @@expense_receipt_number

    @@income_receipt_number = Proc.new do |n|
      "PD#{self.default_number(n)}"
    end unless defined? @@income_receipt_number

    def self.issued_invoice_number(n)
      @@issued_invoice_number.call(n)
    end

    def self.received_invoice_number(n)
      @@received_invoice_number.call(n)
    end

    def self.income_receipt_number(n)
      @@income_receipt_number.call(n)
    end

    def self.expense_receipt_number(n)
      @@expense_receipt_number.call(n)
    end

    def self.default_number(n)
      number = "#{Time.now.strftime("%Y%m")}#{self.with_zeros(n)}"
      number
    end

    def self.with_zeros(n)
      length = n.to_s.length
      number_of_zeros = Integer(4-length)
      zeros = ''

      number_of_zeros.times do
        zeros += '0'
      end

      "#{zeros}#{n}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
invoice_bar-0.0.11 lib/invoice_bar/engine.rb
invoice_bar-0.0.10 lib/invoice_bar/engine.rb
invoice_bar-0.0.9 lib/invoice_bar/engine.rb