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