backporting transit date filtering code to 1_0 and latest branch
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 3 Jul 2007 11:22:41 +0000 (11:22 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 3 Jul 2007 11:22:41 +0000 (11:22 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_0_6@7509 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Circ/Transit.pm

index 89812c7..ff3ad4e 100644 (file)
@@ -317,33 +317,34 @@ __PACKAGE__->register_method(
 );
 
 
+# start_date and end_date are optional endpoints for the transit creation date
 sub transits_by_lib {
-       my( $self, $conn, $auth, $orgid ) = @_;
+       my( $self, $conn, $auth, $orgid, $start_date, $end_date ) = @_;
        my $e = new_editor(authtoken=>$auth);
        return $e->event unless $e->checkauth;
        return $e->event unless $e->allowed('VIEW_CIRCULATIONS'); # eh.. basically the same permission
 
-       my $tos = $e->search_action_transit_copy(
-               [{
-                       dest => $orgid,
-                       dest_recv_time => undef,
-               },
-               {
-                       order_by => { atc => 'source_send_time' }
-               }],
-               { idlist => 1 }
-       );
-
-       my $froms = $e->search_action_transit_copy(
-               [{
-                       source => $orgid,
-                       dest_recv_time => undef,
-               },
-               {
-                       order_by => { atc => 'source_send_time' }
-               }],
-               { idlist => 1 }
-       );
+    my $order_by = {order_by => { atc => 'source_send_time' }};
+    my $search = { dest_recv_time => undef };
+
+    if($end_date) {
+        if($start_date) {
+            $search->{source_send_time} = {between => [$start_date, $end_date]};
+        } else {
+            $search->{source_send_time} = {'<=' => $end_date};
+        }
+    } elsif($start_date) {
+        $search->{source_send_time} = {'>=' => $start_date};
+    }
+
+    $search->{dest} = $orgid;
+
+       my $tos = $e->search_action_transit_copy([ $search, $order_by ], {idlist=>1});
+
+    delete $$search{dest};
+    $search->{source} = $orgid;
+
+       my $froms = $e->search_action_transit_copy([ $search, $order_by ], {idlist=>1});
 
        return { from => $froms, to => $tos };
 }