summaryrefslogtreecommitdiff
path: root/LedgerSMB/Batch.pm
blob: 7d25fffa752d61d072ff0c029a85776e2b2ca9bc (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 => ''};
  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 ($args->{custom_types}->{$self->{class_id}}->{select_method}){
  39. $search_proc
  40. = $args->{custom_types}->{$self->{class_id}}->{select_method};
  41. } elsif ($self->{class_id} =~ /[\D]/){
  42. $self->error("Invalid Batch Type");
  43. }
  44. @{$self->{search_results}} = $self->exec_method(funcname => $search_proc);
  45. return @{$self->{search_results}};
  46. }
  47. sub get_class_id {
  48. my ($self, $type) = @_;
  49. @results = $self->call_procedure(
  50. procname => 'batch_get_class_id',
  51. args => [$type]
  52. );
  53. my $result = pop @results;
  54. return $result->{batch_get_class_id};
  55. }
  56. sub post {
  57. my ($self) = @_;
  58. ($self->{post_return_ref}) = $self->exec_method(funcname => 'batch_post');
  59. $self->{dbh}->commit;
  60. return $self->{post_return_ref};
  61. }
  62. sub delete {
  63. my ($self) = @_;
  64. ($self->{delete_ref}) = $self->exec_method(funcname => 'batch_delete');
  65. $self->{dbh}->commit;
  66. return $self->{delete_ref};
  67. }
  68. sub list_vouchers {
  69. my ($self) = @_;
  70. @{$self->{vouchers}} = $self->exec_method(funcname => 'voucher_list');
  71. return @{$self->{vouchers}};
  72. }
  73. sub get {
  74. my ($self) = @_;
  75. my ($ref) = $self->exec_method(funcname => 'voucher_get_batch');
  76. $self->merge($ref);
  77. }
  78. 1;