[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[2224] trunk



Revision: 2224
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2224&view=rev
Author:   einhverfr
Date:     2008-07-30 20:26:15 +0000 (Wed, 30 Jul 2008)

Log Message:
-----------
Adding custom batch type handles

Modified Paths:
--------------
    trunk/LedgerSMB/Batch.pm
    trunk/scripts/vouchers.pl

Modified: trunk/LedgerSMB/Batch.pm
===================================================================
--- trunk/LedgerSMB/Batch.pm	2008-07-29 22:39:50 UTC (rev 2223)
+++ trunk/LedgerSMB/Batch.pm	2008-07-30 20:26:15 UTC (rev 2224)
@@ -20,9 +20,15 @@
 
 sub get_search_criteria {
     $self = shift @_;
+    my ($custom_types) = @_;
     @{$self->{batch_classes}} = $self->exec_method(
          funcname => 'batch_list_classes'
     );
+    for (keys %$custom_types){
+        if ($custom_types->{$_}->{map_to}){
+            push @{$self->{batch_classes}}, {id => $_, class => $_};
+        }
+    }
 
     @{$self->{batch_users}} = $self->exec_method(
          funcname => 'batch_get_users'
@@ -37,6 +43,12 @@
     } else {
         $search_proc = "batch_search";
     }
+    if ($args->{custom_types}->{$self->{class_id}}->{select_method}){
+        $search_proc 
+             = $args->{custom_types}->{$self->{class_id}}->{select_method}; 
+    } elsif ($self->{class_id} =~ /[\D]/){
+          $self->error("Invalid Batch Type");
+    }
     @{$self->{search_results}} = $self->exec_method(funcname => $search_proc);
     return @{$self->{search_results}};
 }

Modified: trunk/scripts/vouchers.pl
===================================================================
--- trunk/scripts/vouchers.pl	2008-07-29 22:39:50 UTC (rev 2223)
+++ trunk/scripts/vouchers.pl	2008-07-30 20:26:15 UTC (rev 2224)
@@ -15,6 +15,24 @@
 use LedgerSMB::Template;
 use strict;
 
+# custom_batch_types hash provides hooks for handling additional batch types
+# beyond the default types.  Entries can be added in a custom file.
+# Each entry is a hash, keyed by name, with the following keys:
+#  * map_to int (maps to another type, not needed for new types in batch_class 
+#                table)
+#  * select_method (maps to the selection stored proc)
+#
+#  for example:
+#  $custom_batch_types->{ap_sample} = 
+#      {map_to       => 1, 
+#      select_method => 'custom_sample_ap_select'};
+#
+#      --CT
+
+our $custom_batch_types = {};
+
+eval { do "scripts/custom/vouchers.pl"};
+
 sub create_batch {
     my ($request) = @_;
     $request->{hidden} = [
@@ -74,14 +92,14 @@
                     function => sub {
 				my ($request) = @_;
 				$request->{account_class} = 1;
-				LedgerSMB::Scripts::payment::get_search_criteria($request);
+				LedgerSMB::Scripts::payment::get_search_criteria($request, $custom_batch_types);
 				}},
         receipt_reversal => {
                       script => 'scripts/payment.pl',
                     function => sub {
 				my ($request) = @_;
 				$request->{account_class} = 2;
-				LedgerSMB::Scripts::payment::get_search_criteria($request);
+				LedgerSMB::Scripts::payment::get_search_criteria($request, $custom_batch_types);
 				}},
      
 	
@@ -125,7 +143,7 @@
 sub search_batch {
     my ($request) = @_;
     my $batch_request = LedgerSMB::Batch->new(base => $request);
-    $batch_request->get_search_criteria();
+    $batch_request->get_search_criteria($custom_batch_types);
     my $template = LedgerSMB::Template->new(
         user     => $request->{_user},
         locale   => $request->{_locale},
@@ -139,7 +157,7 @@
 sub list_batches {
     my ($request) = @_;
     my $batch = LedgerSMB::Batch->new(base => $request);
-    my @search_results = $batch->get_search_results;
+    my @search_results = $batch->get_search_results({custom_types => $custom_batch_types});
     $batch->{script} = "vouchers.pl";
 
     my @columns = 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.