Bug 22588: (follow-up) Simplify getting accounts even more
[koha-ffzg.git] / opac / sco / sco-main.pl
index 16e598d..bbaaf70 100755 (executable)
@@ -45,6 +45,7 @@ use C4::Biblio;
 use C4::Items;
 use Koha::DateUtils qw( dt_from_string );
 use Koha::Acquisition::Currencies;
+use Koha::Items;
 use Koha::Patrons;
 use Koha::Patron::Images;
 use Koha::Patron::Messages;
@@ -102,10 +103,11 @@ my ($op, $patronid, $patronlogin, $patronpw, $barcode, $confirmed, $newissues) =
     $query->param("confirmed")  || '',
     $query->param("newissues")  || '',
 );
+
 my @newissueslist = split /,/, $newissues;
 my $issuenoconfirm = 1; #don't need to confirm on issue.
 my $issuer   = Koha::Patrons->find( $issuerid )->unblessed;
-my $item     = GetItem(undef,$barcode);
+my $item     = Koha::Items->find({ barcode => $barcode });
 if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) {
     my $dbh = C4::Context->dbh;
     my $resval;
@@ -124,12 +126,14 @@ my $return_only = 0;
 #warn "issuer cardnumber: " .   $issuer->{cardnumber};
 #warn "patron cardnumber: " . $borrower->{cardnumber};
 if ($op eq "logout") {
+    $template->param( loggedout => 1 );
     $query->param( patronid => undef, patronlogin => undef, patronpw => undef );
 }
 elsif ( $op eq "returnbook" && $allowselfcheckreturns ) {
     my ($doreturn) = AddReturn( $barcode, $branch );
+    $template->param( returned => $doreturn );
 }
-elsif ( $patron and $op eq "checkout" ) {
+elsif ( $patron && ( $op eq 'checkout' || $op eq 'renew' ) ) {
     my $impossible  = {};
     my $needconfirm = {};
     ( $impossible, $needconfirm ) = CanBookBeIssued(
@@ -154,11 +158,12 @@ elsif ( $patron and $op eq "checkout" ) {
     if (scalar keys %$impossible) {
 
         my $issue_error = (keys %$impossible)[0]; # FIXME This is wrong, we assume only one error and keys are not ordered
+        my $title = ( $item ) ? $item->biblio->title : '';
 
         $template->param(
             impossible                => $issue_error,
             "circ_error_$issue_error" => 1,
-            title                     => $item->{title},
+            title                     => $title,
             hide_main                 => 1,
         );
         if ($issue_error eq 'DEBT') {
@@ -172,11 +177,12 @@ elsif ( $patron and $op eq "checkout" ) {
                 barcode    => $barcode,
             );
         }
-    } elsif ( $needconfirm->{RENEW_ISSUE} ) {
+    } elsif ( $needconfirm->{RENEW_ISSUE} || $op eq 'renew' ) {
         if ($confirmed) {
             #warn "renewing";
-            AddRenewal( $borrower->{borrowernumber}, $item->{itemnumber} );
+            AddRenewal( $borrower->{borrowernumber}, $item->itemnumber );
             push @newissueslist, $barcode;
+            $template->param( renewed => 1 );
         } else {
             #warn "renew confirmation";
             $template->param(
@@ -218,19 +224,19 @@ elsif ( $patron and $op eq "checkout" ) {
             }
 
             AddIssue( $borrower, $barcode );
+            $template->param( issued => 1 );
             push @newissueslist, $barcode;
 
             if ( $hold_existed ) {
                 my $dtf = Koha::Database->new->schema->storage->datetime_parser;
                 $template->param(
-                    issued => 1,
                     # If the hold existed before the check in, let's confirm that the charge line exists
                     # Note that this should not be needed but since we do not have proper exception handling here we do it this way
                     patron_has_hold_fee => Koha::Account::Lines->search(
                         {
                             borrowernumber => $borrower->{borrowernumber},
                             accounttype    => 'Res',
-                            description    => 'Reserve Charge - ' . $item->biblio->title,
+                            description    => $item->biblio->title,
                             date           => $dtf->format_date(dt_from_string)
                         }
                       )->count,
@@ -240,7 +246,7 @@ elsif ( $patron and $op eq "checkout" ) {
             $confirm_required = 1;
             #warn "issue confirmation";
             $template->param(
-                confirm    => "Issuing title: " . $item->{title},
+                confirm    => "Issuing title: " . $item->biblio->title,
                 barcode    => $barcode,
                 hide_main  => 1,
                 inputfocus => 'confirm',
@@ -267,17 +273,34 @@ if ($borrower) {
         push @checkouts, $checkout;
     }
 
+    my $show_priority;
+    for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
+        m/priority/ and $show_priority = 1;
+    }
+
+    my $account = $patron->account;
+    my $total = $account->balance;
+    my $accountlines = $account->lines;
+
+    my $holds = $patron->holds;
+
     $template->param(
         validuser => 1,
         borrowername => $borrowername,
         issues_count => scalar(@checkouts),
         ISSUES => \@checkouts,
+        HOLDS => $holds,
         newissues => join(',',@newissueslist),
         patronid => $patronid,
         patronlogin => $patronlogin,
         patronpw => $patronpw,
         noitemlinks => 1 ,
         borrowernumber => $borrower->{'borrowernumber'},
+        SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'),
+        AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
+        howpriority   => $show_priority,
+        ACCOUNT_LINES => $accountlines,
+        total => $total,
     );
 
     my $patron_messages = Koha::Patron::Messages->search(