Backport changesets 14820, 15063, 15064, 15066: duedate virtual field for non-cat...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 11 Jan 2010 23:22:52 +0000 (23:22 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 11 Jan 2010 23:22:52 +0000 (23:22 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6@15300 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/OpenILS/Application/Circ/NonCat.pm
Open-ILS/xul/staff_client/server/circ/checkout.js
Open-ILS/xul/staff_client/server/patron/items.js

index cafd130..aa28b28 100644 (file)
@@ -3317,6 +3317,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Non-cat Item Type" name="item_type" reporter:datatype="link"/>
                        <field reporter:label="Patron" name="patron" reporter:datatype="link"/>
                        <field reporter:label="Circulating Staff" name="staff" reporter:datatype="link"/>
+                       <field reporter:label="Virtual Due Date/Time" name="duedate" reporter:datatype="timestamp" oils_persist:virtual="true"/>
                </fields>
                <links>
                        <link field="item_type" reltype="has_a" key="id" map="" class="cnct"/>
index 4c1226b..c8c1978 100644 (file)
@@ -3,6 +3,9 @@ use base 'OpenILS::Application';
 use strict; use warnings;
 use OpenSRF::EX qw(:try);
 use Data::Dumper;
+use DateTime;
+use DateTime::Format::ISO8601;
+use OpenSRF::Utils qw/:datetime/;
 use OpenSRF::Utils::Logger qw(:logger);
 use OpenILS::Application::AppUtils;
 use OpenILS::Utils::Fieldmapper;
@@ -11,6 +14,7 @@ use OpenILS::Utils::CStoreEditor qw/:funcs/;
 $Data::Dumper::Indent = 0;
 
 my $U = "OpenILS::Application::AppUtils";
+my $_dt_parser = DateTime::Format::ISO8601->new;
 
 
 # returns ( $newid, $evt ).  If $evt, then there was an error
@@ -34,6 +38,7 @@ sub create_non_cat_circ {
                $evt = $editor->event unless
                        $circ = $editor->create_action_non_cataloged_circulation( $circ )
 
+
        } else {
                $id = $U->simplereq(
                        'open-ils.storage',
@@ -42,6 +47,11 @@ sub create_non_cat_circ {
                $circ->id($id);
        }
 
+    if($circ) {
+        my $e = ($editor) ? $editor : new_editor();
+        $circ = noncat_due_date($e, $circ);
+    }
+
        return( $circ, $evt );
 }
 
@@ -145,16 +155,40 @@ __PACKAGE__->register_method(
        /
 );
 
+
 sub fetch_noncat {
        my( $self, $conn, $auth, $circid ) = @_;
-       my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
+       my $e = new_editor( authtoken => $auth );
        return $e->event unless $e->checkauth;
        my $c = $e->retrieve_action_non_cataloged_circulation($circid)
                or return $e->event;
        if( $c->patron ne $e->requestor->id ) {
                return $e->event unless $e->allowed('VIEW_CIRCULATIONS'); # XXX rely on editor perm
        }
-       return $c;
+    return noncat_due_date($e, $c);
+}
+
+sub noncat_due_date {
+    my($e, $circ) = @_;
+
+       my $otype = $e->retrieve_config_non_cataloged_type($circ->item_type) 
+               or return $e->die_event;
+
+       my $duedate = $_dt_parser->parse_datetime( clense_ISO8601($circ->circ_time) );
+       $duedate = $duedate
+               ->add( seconds => interval_to_seconds($otype->circ_duration) )
+               ->strftime('%FT%T%z');
+
+       my $offset = $U->storagereq(
+               'open-ils.storage.actor.org_unit.closed_date.overlap',
+               $circ->circ_lib,
+               $duedate
+       );
+
+       $duedate = $offset->{end} if ($offset);
+       $circ->duedate($duedate);
+
+       return $circ;
 }
 
 
index c64586a..a8e8723 100644 (file)
@@ -378,16 +378,7 @@ circ.checkout.prototype = {
                                 checkout.payload.circ.circ_lib( checkout.payload.noncat_circ.circ_lib() );
                                 checkout.payload.circ.circ_staff( checkout.payload.noncat_circ.staff() );
                                 checkout.payload.circ.usr( checkout.payload.noncat_circ.patron() );
-                        
-                                JSAN.use('util.date');
-                                var c = checkout.payload.noncat_circ.circ_time();
-                                var d = c == "now" ? new Date() : util.date.db_date2Date( c );
-                                var t =obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ];
-                                var cd = t.circ_duration() || "14 days";
-                                var i = util.date.interval_to_seconds( cd ) * 1000;
-                                d.setTime( Date.parse(d) + i );
-                                checkout.payload.circ.due_date( util.date.formatted_date(d,'%F') );
-            
+                                checkout.payload.circ.due_date( checkout.payload.noncat_circ.duedate() );
                             }
                         }
     
index 848e146..c0088a3 100644 (file)
@@ -156,12 +156,9 @@ patron.items.prototype = {
                     fake_circ.xact_start( nc_circ.circ_time() );
                     fake_circ.renewal_remaining(0);
                     fake_circ.stop_fines('Non-Cataloged');
+                    fake_circ.due_date( nc_circ.duedate() );
                         
-                    JSAN.use('util.date');
-                    var c = nc_circ.circ_time();
-                    var d = c == "now" ? new Date() : util.date.db_date2Date( c );
-                    var t = obj.data.hash.cnct[ nc_circ.item_type() ];
-                    if (!t) {
+                    if (!obj.data.hash.cnct[ nc_circ.item_type() ]) {
                         var robj2 = obj.network.simple_request('FM_CNCT_RETRIEVE',[ nc_circ.circ_lib() ]);
                         if (typeof robj2.ilsevent != 'undefined') throw(robj);
                         obj.data.stash_retrieve();
@@ -172,12 +169,7 @@ patron.items.prototype = {
                             }
                         }
                         obj.data.stash('hash','list');
-                        t = obj.data.hash.cnct[ nc_circ.item_type() ];
                     }
-                    var cd = t.circ_duration() || $("patronStrings").getString('staff.patron.items.show_noncats.14_days');
-                    var i = util.date.interval_to_seconds( cd ) * 1000;
-                    d.setTime( Date.parse(d) + i );
-                    fake_circ.due_date( util.date.formatted_date(d,'%F') );
     
                     var fake_record = new mvr();
                     fake_record.title( obj.data.hash.cnct[ nc_circ.item_type() ].name());