1#===================================================================== 2# 3# Simple Tax support module for LedgerSMB 4# Taxes::Simple 5# Default simple tax application 6# 7# LedgerSMB 8# Small Medium Business Accounting software 9# http://www.ledgersmb.org/ 10# 11# 12# Copyright (C) 2006 13# This work contains copyrighted information from a number of sources all used 14# with permission. It is released under the GNU General Public License 15# Version 2 or, at your option, any later version. See COPYRIGHT file for 16# details. 17# 18# 19#====================================================================== 20# This package contains tax related functions: 21# 22# calculate_tax - calculates tax on subtotal 23# apply_tax - sets $value to the tax value for the subtotal 24# extract_tax - sets $value to the tax value on a tax-included subtotal 25# 26#==================================================================== 27package Taxes::Simple; 28 29use Class::Struct; 30use Math::BigFloat; 31 32struct Taxes::Simple => { 33 taxnumber => '$', 34 description => '$', 35 rate => 'Math::BigFloat', 36 chart => '$', 37 account => '$', 38 value => 'Math::BigFloat', 39 pass => '$' 40}; 41 42sub calculate_tax { 43 my ( $self, $form, $subtotal, $extract, $passrate ) = @_; 44 my $rate = $self->rate; 45 my $tax = $subtotal * $rate / ( Math::BigFloat->bone() + $passrate ); 46 $tax = $subtotal * $rate if not $extract; 47 return $tax; 48} 49 50sub apply_tax { 51 my ( $self, $form, $subtotal ) = @_; 52 my $tax = $self->calculate_tax( $form, $subtotal, 0 ); 53 $self->value($tax); 54 return $tax; 55} 56 57sub extract_tax { 58 my ( $self, $form, $subtotal, $passrate ) = @_; 59 my $tax = $self->calculate_tax( $form, $subtotal, 1, $passrate ); 60 $self->value($tax); 61 return $tax; 62} 63 641; 65