Don't rely on the sequence like this, using xact_start to find preceding circ renewal...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 26 Apr 2010 16:21:45 +0000 (16:21 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 26 Apr 2010 16:21:45 +0000 (16:21 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@16305 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 3f4901a..bd25981 100644 (file)
@@ -1537,17 +1537,14 @@ sub retrieve_prev_circ_chain {
         my $target_copy = $$first_circ{'target_copy'};
         my $usr = $$first_circ{'usr'};
         my $last_circ_from_prev_chain = $e->json_query({
-            'select' => {
-                'circ' => [{
-                    'column' => 'id',
-                    'transform' => 'max'
-                }]
-            },
+            'select' => { 'circ' => ['id'] },
             'from' => 'circ', 
             'where' => {
                 target_copy => $target_copy,
-                id => { '<' => $$first_circ{'id'} }
-            }
+                xact_start => { '<' => $$first_circ{'xact_start'} }
+            },
+            'order_by' => [{ 'class'=>'circ', 'field'=>'xact_start', 'direction'=>'desc' }],
+            'limit' => 1
         })->[0];
         return undef unless $last_circ_from_prev_chain;
         return undef unless $$last_circ_from_prev_chain{'id'};
@@ -1562,17 +1559,14 @@ sub retrieve_prev_circ_chain {
         my $first_circ = $e->json_query({from => ['action.circ_chain', $circ_id]})->[0];
         my $target_copy = $$first_circ{'target_copy'};
         my $last_circ_from_prev_chain = $e->json_query({
-            'select' => {
-                'circ' => [{
-                    'column' => 'id',
-                    'transform' => 'max'
-                }]
-            },
+            'select' => { 'circ' => ['id'] },
             'from' => 'circ', 
             'where' => {
                 target_copy => $target_copy,
-                id => { '<' => $$first_circ{'id'} }
-            }
+                xact_start => { '<' => $$first_circ{'xact_start'} }
+            },
+            'order_by' => [{ 'class'=>'circ', 'field'=>'xact_start', 'direction'=>'desc' }],
+            'limit' => 1
         })->[0];
         return undef unless $last_circ_from_prev_chain;
         return undef unless $$last_circ_from_prev_chain{'id'};