summaryrefslogtreecommitdiff
path: root/scripts/payment.pl
blob: f36b0b91fc4ed306b691bd2f7dffea9331fd95cb (plain)
  1. =pod
  2. =head1 NAME
  3. LedgerSMB::Scripts::payment - LedgerSMB class defining the Controller functions for payment handling.
  4. =head1 SYNOPSIS
  5. Defines the controller functions and workflow logic for payment processing.
  6. =head1 COPYRIGHT
  7. Copyright (c) 2007, David Mora R and Christian Ceballos B.
  8. Licensed to the public under the terms of the GNU GPL version 2 or later.
  9. Original copyright notice below.
  10. #=====================================================================
  11. # PLAXIS
  12. # Copyright (c) 2007
  13. #
  14. # Author: David Mora R
  15. # Christian Ceballos B
  16. #
  17. #
  18. #
  19. #
  20. #
  21. # This program is free software; you can redistribute it and/or modify
  22. # it under the terms of the GNU General Public License as published by
  23. # the Free Software Foundation; either version 2 of the License, or
  24. # (at your option) any later version.
  25. #
  26. # This program is distributed in the hope that it will be useful,
  27. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. # GNU General Public License for more details.
  30. # You should have received a copy of the GNU General Public License
  31. # along with this program; if not, write to the Free Software
  32. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  33. =head1 METHODS
  34. =cut
  35. package LedgerSMB::Scripts::payment;
  36. use LedgerSMB::Template;
  37. use LedgerSMB::DBObject::Payment;
  38. use LedgerSMB::DBObject::Date;
  39. use strict;
  40. =pod
  41. =item payment
  42. This method is used to set the filter screen and prints it, using the
  43. TT2 system. (hopefully it will... )
  44. =back
  45. =cut
  46. sub payment {
  47. my ($request) = @_;
  48. my $locale = $request->{_locale};
  49. my $templateData;
  50. my $dbPayment = LedgerSMB::DBObject::Payment->new({'base' => $request});
  51. # Lets get the project data...
  52. my @projectOptions;
  53. my @arrayOptions = $dbPayment->list_open_projects();
  54. push @projectOptions, {}; #A blank field on the select box
  55. for my $ref (0 .. $#arrayOptions) {
  56. push @projectOptions, { value => $arrayOptions[$ref]->{id},
  57. text => $arrayOptions[$ref]->{projectnumber}."--".$arrayOptions[$ref]->{description}};
  58. }
  59. # Lets get the departments data...
  60. my @departmentOptions;
  61. my $role = $request->{type} eq 'receipt' ? 'P' : 'C';
  62. @arrayOptions = $dbPayment->list_departments($role);
  63. push @departmentOptions, {}; # A blank field on the select box
  64. for my $ref (0 .. $#arrayOptions) {
  65. push @departmentOptions, { value => $arrayOptions[$ref]->{id},
  66. text => $arrayOptions[$ref]->{description}};
  67. }
  68. # Lets get the customer or vendor :)
  69. my @vcOptions;
  70. $dbPayment->{account_class} = $request->{type} eq 'receipt' ? 2 : 1;
  71. @arrayOptions = $dbPayment->get_open_accounts();
  72. for my $ref (0 .. $#arrayOptions) {
  73. push @vcOptions, { value => $arrayOptions[$ref]->{id},
  74. text => $arrayOptions[$ref]->{description}};
  75. }
  76. # Lets get the open currencies (this uses the $dbPayment->{account_class} property)
  77. my @currOptions;
  78. @arrayOptions = $dbPayment->get_open_currencies();
  79. for my $ref (0 .. $#arrayOptions) {
  80. push @arrayOptions, { value => $arrayOptions[$ref]->{id},
  81. text => $arrayOptions[$ref]->{description}};
  82. }
  83. # Lets build filter by period
  84. my $date = LedgerSMB::DBObject::Date->new({base => $request});
  85. $date->build_filter_by_period($locale);
  86. # Lets set the data in a hash for the template system. :)
  87. my $select = {
  88. stylesheet => $request->{_user}->{stylesheet},
  89. projects => {
  90. name => 'projects',
  91. options => \@projectOptions
  92. },
  93. department => {
  94. name => 'department',
  95. options => \@departmentOptions
  96. },
  97. customer => {
  98. name => 'customer',
  99. options => \@vcOptions
  100. },
  101. curr => {
  102. name => 'curr',
  103. options => \@currOptions
  104. },
  105. month => {
  106. name => 'month',
  107. options => $date->{monthsOptions}
  108. },
  109. year => {
  110. name => 'year',
  111. options => $date->{yearsOptions}
  112. },
  113. interval_radios => $date->{radioOptions},
  114. amountfrom => {
  115. type => 'text',
  116. name => 'amountfrom',
  117. size => '10',
  118. maxlength => '10'
  119. },
  120. amountto => {
  121. type => 'text',
  122. name => 'amountto',
  123. size => '10',
  124. maxlength => '10'
  125. },
  126. sort => {
  127. type => 'hidden',
  128. value => 'sort_value'
  129. },
  130. action => {
  131. name => 'action',
  132. value => 'continue',
  133. text => $locale->text("Continue"),
  134. },
  135. };
  136. # Lets call upon the template system
  137. my $template;
  138. $template = LedgerSMB::Template->new(
  139. user => $request->{_user},
  140. locale => $request->{_locale},
  141. path => 'UI',
  142. template => 'payment1',
  143. format => 'HTML', );
  144. $template->render($select);# And finally, Lets print the screen :)
  145. }
  146. 1;