summaryrefslogtreecommitdiff
path: root/LedgerSMB/Batch.pm
blob: 8c4e397bcd8510dad5eb5d8ce1821a087d4ba0a0 (plain)
  1. package LedgerSMB::Batch;
  2. use base qw(LedgerSMB::DBObject);
  3. sub create {
  4. $self = shift @_;
  5. my ($ref) = $self->exec_method(funcname => 'batch_create');
  6. $self->{id} = $ref->{batch_create};
  7. $self->{dbh}->commit;
  8. return $ref->{id};
  9. }
  10. sub delete_voucher {
  11. my ($self, $voucher_id) = @_;
  12. $self->call_procedure(procname => 'voucher__delete', args => [$voucher_id]);
  13. $self->{dbh}->commit;
  14. }
  15. sub get_search_criteria {
  16. $self = shift @_;
  17. my ($custom_types) = @_;
  18. @{$self->{batch_classes}} = $self->exec_method(
  19. funcname => 'batch_list_classes'
  20. );
  21. for (keys %$custom_types){
  22. if ($custom_types->{$_}->{map_to}){
  23. push @{$self->{batch_classes}}, {id => $_, class => $_};
  24. }
  25. }
  26. @{$self->{batch_users}} = $self->exec_method(
  27. funcname => 'batch_get_users'
  28. );
  29. unshift @{$self->{batch_users}}, {username => $self->{_locale}->text('Any'), id => '0', entity_id => '0'};
  30. }
  31. sub get_search_results {
  32. my ($self, $args) = @_;
  33. if ($args->{mini}){
  34. $search_proc = "batch_search_mini";
  35. } else {
  36. $search_proc = "batch_search";
  37. }
  38. if ($self->{created_by_eid} == 0){
  39. delete $self->{created_by_eid};
  40. }
  41. if ($args->{custom_types}->{$self->{class_id}}->{select_method}){
  42. $search_proc
  43. = $args->{custom_types}->{$self->{class_id}}->{select_method};
  44. } elsif ($self->{class_id} =~ /[\D]/){
  45. $self->error("Invalid Batch Type");
  46. }
  47. @{$self->{search_results}} = $self->exec_method(funcname => $search_proc);
  48. return @{$self->{search_results}};
  49. }
  50. sub get_class_id {
  51. my ($self, $type) = @_;
  52. @results = $self->call_procedure(
  53. procname => 'batch_get_class_id',
  54. args => [$type]
  55. );
  56. my $result = pop @results;
  57. return $result->{batch_get_class_id};
  58. }
  59. sub post {
  60. my ($self) = @_;
  61. ($self->{post_return_ref}) = $self->exec_method(funcname => 'batch_post');
  62. $self->{dbh}->commit;
  63. return $self->{post_return_ref};
  64. }
  65. sub delete {
  66. my ($self) = @_;
  67. ($self->{delete_ref}) = $self->exec_method(funcname => 'batch_delete');
  68. $self->{dbh}->commit;
  69. return $self->{delete_ref};
  70. }
  71. sub list_vouchers {
  72. my ($self) = @_;
  73. @{$self->{vouchers}} = $self->exec_method(funcname => 'voucher_list');
  74. return @{$self->{vouchers}};
  75. }
  76. sub get {
  77. my ($self) = @_;
  78. my ($ref) = $self->exec_method(funcname => 'voucher_get_batch');
  79. $self->merge($ref);
  80. }
  81. 1;