summaryrefslogtreecommitdiff
path: root/scripts/vouchers.pl
blob: 7e131bc2ec90fe5cd4b2c0998f820d0d2acca0ab (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. my ($request) = shift @_;
  32. use LedgerSMB::Form;
  33. my $batch = LedgerSMB::Batch->new({base => $request});
  34. $batch->create;
  35. my $vouchers_dispatch =
  36. {
  37. payable => {script => 'bin/ap.pl', function => sub {add()}},
  38. receivable => {script => 'bin/ar.pl', function => sub {add()}},
  39. payments => {script => 'bin/cp.pl', function => sub {payments()}},
  40. receipts => {script => 'bin/cp.pl', function => sub {receipts()}},
  41. gl => {script => 'bin/gl.pl', function => sub {add()}},
  42. };
  43. # Note that the line below is generally considered incredibly bad form.
  44. # However, the code we are including is going to require it for now.
  45. no strict;
  46. our $form = new Form;
  47. our $locale = $request->{_locale};
  48. for (keys %$request){
  49. $form->{$_} = $request->{$_};
  50. }
  51. $form->{approved} = 0;
  52. $form->{transdate} = $request->{batch_date};
  53. print STDERR "$request->{batch_type}\n";
  54. require $vouchers_dispatch->{$request->{batch_type}}{script};
  55. my $script = $vouchers_dispatch->{$request->{batch_type}}{script};
  56. $script =~ s|.*/||;
  57. $form->{script} = $script;
  58. \ $vouchers_dispatch->{$request->{batch_type}}{function}();
  59. }
  60. sub list_vouchers {
  61. }
  62. sub approve_batch {
  63. }
  64. sub delete_batch {
  65. }
  66. 1;