bug 2787 : Fix Global Due date
authorRyan Higgins <rch@liblime.com>
Wed, 19 Nov 2008 15:56:12 +0000 (09:56 -0600)
committerGalen Charlton <galen.charlton@liblime.com>
Thu, 20 Nov 2008 13:22:18 +0000 (07:22 -0600)
This patch also lightly refactors the conditional structure wrapping the
call to AddItem, renaming a couple variables to remove double-negatives and
abstruse logic.  If SpecifyDueDate is ON, then the input box is used to pass
GlobalDueDate, allowing modification by circ staff, resulting in a default
'sticky' due date of the global due date in that mode.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
circ/circulation.pl
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl

index aec1b29..15eb8e7 100755 (executable)
@@ -136,21 +136,37 @@ my $debt_confirmed = $query->param('debt_confirmed') || 0; # Don't show the debt
 # }
 #
 
-my ($datedue,$invalidduedate);
-if ($duedatespec) {
-       if ($duedatespec =~ C4::Dates->regexp('syspref')) {
-               my $tempdate = C4::Dates->new($duedatespec);
-               if ($tempdate and $tempdate->output('iso') gt C4::Dates->new()->output('iso')) {
-                       # i.e., it has to be later than today/now
-                       $datedue = $tempdate;
-               } else {
-                       $invalidduedate = 1;
-                       $template->param(IMPOSSIBLE=>1, INVALID_DATE=>$duedatespec);
-               }
-       } else {
-               $invalidduedate = 1;
-               $template->param(IMPOSSIBLE=>1, INVALID_DATE=>$duedatespec);
-       }
+my ($datedue,$invalidduedate,$globalduedate);
+
+if(C4::Context->preference('globalDueDate') && (C4::Context->preference('globalDueDate') =~ C4::Dates->regexp('syspref'))){
+        $globalduedate = C4::Dates->new(C4::Context->preference('globalDueDate'));
+}
+my $duedatespec_allow = C4::Context->preference('SpecifyDueDate');
+if($duedatespec_allow){
+    if ($duedatespec) {
+       if ($duedatespec =~ C4::Dates->regexp('syspref')) {
+               my $tempdate = C4::Dates->new($duedatespec);
+               if ($tempdate and $tempdate->output('iso') gt C4::Dates->new()->output('iso')) {
+                       # i.e., it has to be later than today/now
+                       $datedue = $tempdate;
+               } else {
+                       $invalidduedate = 1;
+                       $template->param(IMPOSSIBLE=>1, INVALID_DATE=>$duedatespec);
+               }
+       } else {
+               $invalidduedate = 1;
+               $template->param(IMPOSSIBLE=>1, INVALID_DATE=>$duedatespec);
+       }
+    } else {
+        # pass global due date to tmpl if specifyduedate is true 
+        # and we have no barcode (loading circ page but not checking out)
+        if($globalduedate &&  ! $barcode ){
+            $duedatespec = $globalduedate->output();
+            $stickyduedate = 1;
+        }
+    }
+} else {
+    $datedue = $globalduedate if($globalduedate);
 }
 
 my $todaysdate = C4::Dates->new->output('iso');
@@ -161,7 +177,6 @@ if ( $barcode eq '' && $print eq 'maybe' ) {
 }
 
 my $inprocess = ($barcode eq '') ? '' : $query->param('inprocess');
-
 if ( $barcode eq '' && $query->param('charges') eq 'yes' ) {
     $template->param(
         PAYCHARGES     => 'yes',
@@ -256,7 +271,7 @@ if ($barcode) {
   # always check for blockers on issuing
   my ( $error, $question ) =
     CanBookBeIssued( $borrower, $barcode, $datedue , $inprocess );
-  my $noerror = $invalidduedate ? 0 : 1;
+  my $blocker = $invalidduedate ? 1 : 0;
 
   delete $question->{'DEBT'} if ($debt_confirmed);
   foreach my $impossible ( keys %$error ) {
@@ -264,51 +279,38 @@ if ($barcode) {
                 $impossible => $$error{$impossible},
                 IMPOSSIBLE  => 1
             );
-            $noerror = 0;
+            $blocker = 1;
         }
-    
-  if ($issueconfirmed && $noerror) {
-    # we have no blockers for issuing and any issues needing confirmation have been resolved
-        AddIssue( $borrower, $barcode, $datedue, $cancelreserve );
-        $inprocess = 1;
-    }
-  elsif ($issueconfirmed){     # FIXME: Do something? Or is this to *intentionally* do nothing?
-  }
-  else {
-        my $noquestion = 1;
-#         Get the item title for more information
-       my $getmessageiteminfo  = GetBiblioFromItemNumber(undef,$barcode);
-               if ($noerror) {
-                       # only pass needsconfirmation to template if issuing is possible 
-               foreach my $needsconfirmation ( keys %$question ) {
-                   $template->param(
-                       $needsconfirmation => $$question{$needsconfirmation},
-                       getTitleMessageIteminfo => $getmessageiteminfo->{'title'},
-                       NEEDSCONFIRMATION  => 1
-                   );
-                   $noquestion = 0;
-               }
-                       # Because of the weird conditional structure (empty elsif block),
-                       # if we reached here, $issueconfirmed must be false.
-                       # Also, since we moved inside the if ($noerror) conditional,
-                       # this old chunky conditional can be simplified:
-                   # if ( $noerror && ( $noquestion || $issueconfirmed ) ) {
-                       if ($noquestion) {
-                               AddIssue( $borrower, $barcode, $datedue );
-                               $inprocess = 1;
-                       }
-           }
-               $template->param(
-                        itemhomebranch => $getmessageiteminfo->{'homebranch'} ,                     
-                        duedatespec => $duedatespec,
-        );
+    if( !$blocker ){
+        my $confirm_required = 0;
+       unless($issueconfirmed){
+            #  Get the item title for more information
+            my $getmessageiteminfo  = GetBiblioFromItemNumber(undef,$barcode);
+                   $template->param( itemhomebranch => $getmessageiteminfo->{'homebranch'} );
+
+                   # pass needsconfirmation to template if issuing is possible and user hasn't yet confirmed.
+                   foreach my $needsconfirmation ( keys %$question ) {
+                       $template->param(
+                           $needsconfirmation => $$question{$needsconfirmation},
+                           getTitleMessageIteminfo => $getmessageiteminfo->{'title'},
+                           NEEDSCONFIRMATION  => 1
+                       );
+                       $confirm_required = 1;
+                   }
+               }
+        unless($confirm_required) {
+            AddIssue( $borrower, $barcode, $datedue, $cancelreserve );
+                       $inprocess = 1;
+            if($globalduedate && ! $stickyduedate && $duedatespec_allow ){
+                $duedatespec = $globalduedate->output();
+                $stickyduedate = 1;
+            }
+               }
     }
     
-# FIXME If the issue is confirmed, we launch another time borrdata2, now display the issue count after issue 
-        my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
-        $template->param(
-        issuecount   => $issue,
-        );
+    # FIXME If the issue is confirmed, we launch another time GetMemberIssuesAndFines, now display the issue count after issue 
+    my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
+    $template->param( issuecount   => $issue );
 }
 
 # reload the borrower info for the sake of reseting the flags.....
@@ -674,6 +676,7 @@ $template->param(
     amountold         => $amountold,
     barcode           => $barcode,
     stickyduedate     => $stickyduedate,
+    duedatespec       => $duedatespec,
     message           => $message,
     CGIselectborrower => $CGIselectborrower,
     todayissues       => \@todaysissues,
@@ -685,12 +688,6 @@ $template->param(
     circview => 1,
 );
 
-# set return date if stickyduedate
-if ($stickyduedate) {
-    $template->param(
-        duedatespec => $duedatespec,
-    );
-}
 
 #if ($branchcookie) {
 #$cookie=[$cookie, $branchcookie, $printercookie];
@@ -702,7 +699,7 @@ $template->param( picture => 1 ) if $picture;
 
 $template->param(
     debt_confirmed            => $debt_confirmed,
-    SpecifyDueDate            => C4::Context->preference("SpecifyDueDate"),
+    SpecifyDueDate            => $duedatespec_allow,
     CircAutocompl             => C4::Context->preference("CircAutocompl"),
        AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
     dateformat                => C4::Context->preference("dateformat"),
index 7ddf91b..a41e0f2 100644 (file)
@@ -254,7 +254,7 @@ No patron matched <span class="ex"><!-- TMPL_VAR name="message" --></span>
 
     <!-- TMPL_IF NAME="SpecifyDueDate" --><div class="date-select">
         <div class="hint">Specify Due Date:</div>
-               <!-- TMPL_IF NAME="stickyduedate" --><input type="text" size="10" id="duedatespec" name="duedatespec" value="<!-- TMPL_VAR NAME="duedatespec" -->" /><!-- TMPL_ELSE --><input type="text" size="10" id="duedatespec" name="duedatespec" value="" />
+               <!-- TMPL_IF NAME="duedatespec" --><input type="text" size="10" id="duedatespec" name="duedatespec" value="<!-- TMPL_VAR NAME="duedatespec" -->" /><!-- TMPL_ELSE --><input type="text" size="10" id="duedatespec" name="duedatespec" value="" />
 <!-- /TMPL_IF -->
                <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" alt="Show Calendar"  border="0" id="CalendarDueDate" style="cursor: pointer;" />
              <script language="JavaScript" type="text/javascript">