summaryrefslogtreecommitdiff
path: root/scripts/drafts.pl
blob: 741b5fede5a40e53cd9f111402f7c156da73dbde (plain)
  1. package LedgerSMB::Scripts::vouchers;
  2. our $VERSION = '0.1';
  3. use LedgerSMB::DBObject::Draft;
  4. use LedgerSMB::Template;
  5. use strict;
  6. sub search {
  7. my ($request) = @_;
  8. my $template = LedgerSMB::Template->new(
  9. user =>$request->{_user},
  10. locale => $request->{_locale},
  11. path => 'UI',
  12. template => 'batch/search_transactions',
  13. format => 'HTML'
  14. );
  15. $template->render($request);
  16. }
  17. sub list_drafts {
  18. my ($request) = @_;
  19. my $draft= LedgerSMB::Draft->new(base => $request);
  20. my @search_results = $draft->search;
  21. $draft->{script} = "drafts.pl";
  22. my @columns =
  23. qw(select id transdate reference description, amount);
  24. my $base_href = "drafts.pl";
  25. my $search_href = "$base_href?action=list_transactions";
  26. my $draft_href= "$base_href?action=get_transaction";
  27. for my $key (
  28. qw(class_id approved created_by description amount_gt amount_lt)
  29. ){
  30. $search_href .= "&$key=$draft->{key}";
  31. }
  32. my %column_heading = (
  33. 'select' => $draft->{_locale}->text('Select'),
  34. transaction_total => {
  35. text => $draft->{_locale}->text('AR/AP/GL Total'),
  36. href => "$search_href&order_by=transaction_total"
  37. },
  38. payment_total => {
  39. text => $draft->{_locale}->text('Paid/Received Total'),
  40. href => "$search_href&order_by=payment_total"
  41. },
  42. description => {
  43. text => $draft->{_locale}->text('Description'),
  44. href => "$search_href&order_by=description"
  45. },
  46. control_code => {
  47. text => $draft->{_locale}->text('Batch Number'),
  48. href => "$search_href&order_by=control_code"
  49. },
  50. id => {
  51. text => $draft->{_locale}->text('ID'),
  52. href => "$search_href&order_by=control_code"
  53. },
  54. );
  55. my $count = 0;
  56. my @rows;
  57. for my $result (@search_results){
  58. ++$count;
  59. $draft->{"row_$count"} = $result->{id};
  60. push @rows, {
  61. 'select' => {
  62. input => {
  63. type => 'checkbox',
  64. value => 1,
  65. name => "draft_$result->{id}"
  66. }
  67. },
  68. transaction_total => $draft->format_amount(
  69. amount => $result->{transaction_total}
  70. ),
  71. payment_total => $draft->format_amount (
  72. amount => $result->{payment_total}
  73. ),
  74. description => $result->{description},
  75. control_code => {
  76. text => $result->{control_code},
  77. href => "$draft_href&draft_id=$result->{id}",
  78. },
  79. id => $result->{id},
  80. };
  81. }
  82. $draft->{rowcount} = $count;
  83. my $template = LedgerSMB::Template->new(
  84. user => $request->{_user},
  85. locale => $request->{_locale},
  86. path => 'UI',
  87. template => 'form-dynatable',
  88. format => ($draft->{format}) ? $draft->{format} : 'HTML',
  89. );
  90. my $hiddens = $draft->take_top_level();
  91. $draft->{rowcount} = "$count";
  92. delete $draft->{search_results};
  93. $template->render({
  94. form => $draft,
  95. columns => \@columns,
  96. heading => \%column_heading,
  97. rows => \@rows,
  98. hiddens => $hiddens,
  99. buttons => [{
  100. name => 'action',
  101. type => 'submit',
  102. text => $request->{_locale}->text('Post'),
  103. value => 'draft_approve',
  104. class => 'submit',
  105. },{
  106. name => 'action',
  107. type => 'submit',
  108. text => $request->{_locale}->text('Delete'),
  109. value => 'draft_delete',
  110. class => 'submit',
  111. }]
  112. });
  113. }
  114. sub delete_drafts {
  115. my ($request) = @_;
  116. }