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