summaryrefslogtreecommitdiff
path: root/LedgerSMB/Taxes/Simple.pm
blob: bbcf539b0b0b9b0ace35298a0221dee717dd8817 (plain)
  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. #====================================================================
  27. package Taxes::Simple;
  28. use Class::Struct;
  29. use Math::BigFloat;
  30. struct Taxes::Simple => {
  31. taxnumber => '$',
  32. description => '$',
  33. rate => 'Math::BigFloat',
  34. chart => '$',
  35. account => '$',
  36. value => 'Math::BigFloat',
  37. pass => '$'
  38. };
  39. sub calculate_tax {
  40. my ( $self, $form, $subtotal, $extract, $passrate ) = @_;
  41. my $rate = $self->rate;
  42. my $tax = $subtotal * $rate / ( Math::BigFloat->bone() + $passrate );
  43. $tax = $subtotal * $rate if not $extract;
  44. return $tax;
  45. }
  46. sub apply_tax {
  47. my ( $self, $form, $subtotal ) = @_;
  48. my $tax = $self->calculate_tax( $form, $subtotal, 0 );
  49. $self->value($tax);
  50. return $tax;
  51. }
  52. sub extract_tax {
  53. my ( $self, $form, $subtotal, $passrate ) = @_;
  54. my $tax = $self->calculate_tax( $form, $subtotal, 1, $passrate );
  55. $self->value($tax);
  56. return $tax;
  57. }
  58. 1;