class Vatcalc::Bill
Constants
- RoundPrecision
- Tolerance
will only be used in rspec for test
Attributes
base[R]
base_elements[R]
currency[R]
service_elements[R]
services[R]
Public Class Methods
new(elements: [],currency: nil)
click to toggle source
# File lib/vatcalc/bill.rb, line 17 def initialize(elements: [],currency: nil) @base = Base.new #defined at the bottom @services = Services.new #defined at the bottom @currency = currency insert(elements) end
Public Instance Methods
all()
click to toggle source
# File lib/vatcalc/bill.rb, line 64 def all (base + services) end
Also aliased as: elements
insert(obj, quantity = 1)
click to toggle source
inserts one or more element which included the Vatcalc::ActsAsBillElement
module @param obj = [Array,Object] @result = [Vatcalc::Bill]
# File lib/vatcalc/bill.rb, line 28 def insert(obj, quantity = 1) case obj when Array return (obj.each { |obj, quantity| insert(obj, quantity)}.last || self) when Vatcalc.acts_as_bill_element? gnv = obj.as_vatcalc_bill_element else raise ArgumentError.new ("Can't insert a #{obj.class} into #{self}. #{obj.class} must include Vatcalc::ActsAsBillElement") end if (quantity ||= 1) > 0 gnv.source = obj @currency = gnv.currency case gnv when BaseElement @base.insert(gnv,quantity) # if an base element is inserted after services already in here. @services.rates_changed!(@base.rates) if @services.length > 0 when ServiceElement @services.insert(gnv,quantity) # the service gets now the rates of the base gnv.change_rates(@base.rates) end @base.currency = @currency @services.currency = @currency end self end
vat_splitted()
click to toggle source
# File lib/vatcalc/bill.rb, line 60 def vat_splitted all.vat_splitted end