summaryrefslogtreecommitdiff
path: root/scripts/vouchers.pl
blob: f847455608644071f805f6662a81733472bc4256 (plain)
  1. #!/usr/bin/perl
  2. # This file is copyright (C) 2007the LedgerSMB core team and licensed under
  3. # the GNU General Public License. For more information please see the included
  4. # LICENSE and COPYRIGHT files
  5. package LedgerSMB::Scripts::vouchers;
  6. our $VERSION = '0.1';
  7. $menufile = "menu.ini";
  8. use LedgerSMB::Batch;
  9. use LedgerSMB::Voucher;
  10. use LedgerSMB::Template;
  11. use strict;
  12. sub create_batch {
  13. my ($request) = @_;
  14. $request->{hidden} = [
  15. {name => "batch_type", value => $request->{batch_type}},
  16. ];
  17. my $template = LedgerSMB::Template->new(
  18. user =>$request->{_user},
  19. locale => $request->{_locale},
  20. path => 'UI',
  21. template => 'create_batch',
  22. format => 'HTML'
  23. );
  24. $template->render($request);
  25. }
  26. sub create_vouchers {
  27. # This function is not safe for caching as long as the scripts are in bin.
  28. # This is because these scripts import all functions into the *current*
  29. # namespace. People using fastcgi and modperl should *not* cache this
  30. # module at the moment. -- CT
  31. # Also-- request is in 'our' scope here due to the redirect logic.
  32. our ($request) = shift @_;
  33. use LedgerSMB::Form;
  34. my $batch = LedgerSMB::Batch->new({base => $request});
  35. $batch->{batch_class} = $request->{batch_type};
  36. $batch->create;
  37. our $vouchers_dispatch =
  38. {
  39. payable => {script => 'bin/ap.pl', function => sub {add()}},
  40. receivable => {script => 'bin/ar.pl', function => sub {add()}},
  41. gl => {script => 'bin/gl.pl', function => sub {add()}},
  42. receipt => {script => 'scripts/payment.pl',
  43. function => sub {
  44. my ($request) = @_;
  45. $request->{account_class} = 2;
  46. LedgerSMB::Scripts::payment::payments($request);
  47. }},
  48. payment => {script => 'scripts/payment.pl',
  49. function => sub {
  50. my ($request) = @_;
  51. $request->{account_class} = 1;
  52. LedgerSMB::Scripts::payment::payments($request);
  53. }},
  54. };
  55. # Note that the line below is generally considered incredibly bad form.
  56. # However, the code we are including is going to require it for now. -- CT
  57. our $form = new Form;
  58. our $locale = $request->{_locale};
  59. for (keys %$request){
  60. $form->{$_} = $request->{$_};
  61. }
  62. $form->{batch_id} = $batch->{id};
  63. $form->{approved} = 0;
  64. $form->{transdate} = $request->{batch_date};
  65. $request->{batch_id} = $batch->{id};
  66. $request->{approved} = 0;
  67. $request->{transdate} = $request->{batch_date};
  68. my $script = $vouchers_dispatch->{$request->{batch_type}}{script};
  69. $form->{script} = $script;
  70. $form->{script} =~ s|.*/||;
  71. if ($script =~ /^bin/){
  72. { no strict; no warnings 'redefine'; do $script; }
  73. } elsif ($script =~ /scripts/) {
  74. { do $script }
  75. }
  76. $vouchers_dispatch->{$request->{batch_type}}{function}($request);
  77. }
  78. sub get_batch {
  79. }
  80. sub list_vouchers {
  81. }
  82. sub add_vouchers {
  83. }
  84. sub approve_batch {
  85. }
  86. sub delete_batch {
  87. }
  88. eval { do "scripts/custom/Voucher.pl"};
  89. 1;