summaryrefslogtreecommitdiff
path: root/scripts/vouchers.pl
blob: c779e8870bed1e4fa14d1404c6096327fe2917c1 (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. gl => {script => 'bin/gl.pl', function => sub {add()}},
  41. receipts => {script => 'scripts/payments.pl',
  42. function => sub {
  43. my ($request) = @_;
  44. $request->{account_class} = 2;
  45. LedgerSMB::Scripts::payment::payments($request);
  46. }},
  47. payments => {script => 'scripts/payments.pl',
  48. function => sub {
  49. my ($request) = @_;
  50. $request->{account_class} = 1;
  51. LedgerSMB::Scripts::payment::payments($request);
  52. }},
  53. };
  54. # Note that the line below is generally considered incredibly bad form.
  55. # However, the code we are including is going to require it for now. -- CT
  56. our $form = new Form;
  57. our $locale = $request->{_locale};
  58. for (keys %$request){
  59. $form->{$_} = $request->{$_};
  60. }
  61. $form->{batch_id} = $batch->{id};
  62. $form->{approved} = 0;
  63. $form->{transdate} = $request->{batch_date};
  64. my $script = $vouchers_dispatch->{$request->{batch_type}}{script};
  65. { no strict; no warnings 'redefine'; do $script; }
  66. $script =~ s|.*/||;
  67. $form->{script} = $script;
  68. $vouchers_dispatch->{$request->{batch_type}}{function}();
  69. }
  70. sub get_batch {
  71. }
  72. sub list_vouchers {
  73. }
  74. sub add_vouchers {
  75. }
  76. sub approve_batch {
  77. }
  78. sub delete_batch {
  79. }
  80. 1;