Bug 29672: Clear cache of enabled plugins when a plugin's state change
[koha-ffzg.git] / circ / overdue.pl
index 941458d..e2bb848 100755 (executable)
@@ -25,7 +25,8 @@ use C4::Output qw( output_html_with_http_headers );
 use CGI qw(-oldstyle_urls -utf8);
 use C4::Auth qw( get_template_and_user );
 use Text::CSV_XS;
-use Koha::DateUtils qw( dt_from_string output_pref );
+use Koha::DateUtils qw( dt_from_string );
+use Koha::Patron::Attribute::Types;
 use DateTime;
 use DateTime::Format::MySQL;
 
@@ -60,6 +61,7 @@ my $filters = {
     holdingbranch => $holdingbranchfilter,
     dateduefrom   => $dateduefrom,
     datedueto     => $datedueto,
+    showall       => $showall,
 };
 
 my $isfiltered      = $op =~ /apply/i && $op =~ /filter/i;
@@ -117,13 +119,22 @@ my $have_pattr_filter_data = keys(%cgi_attrcode_to_attrvalues) > 0;
 
 my @patron_attr_filter_loop;   # array of [ domid cgivalue ismany isclone ordinal code description repeatable authorised_value_category ]
 
-my $sth = $dbh->prepare('SELECT code,description,repeatable,authorised_value_category
-    FROM borrower_attribute_types
-    WHERE staff_searchable <> 0
-    ORDER BY description');
-$sth->execute();
+my $patron_attrs = Koha::Patron::Attribute::Types->search_with_library_limits(
+    {
+        staff_searchable => 1,
+    },
+    {},
+    C4::Context->userenv->{'branch'}
+);
+
 my $ordinal = 0;
-while (my $row = $sth->fetchrow_hashref) {
+while (my $attr = $patron_attrs->next ) {
+    my $row = {
+        code => $attr->code,
+        description => $attr->description,
+        repeatable => $attr->repeatable,
+        authorised_value_category => $attr->authorised_value_category,
+    };
     $row->{ordinal} = $ordinal;
     my $code = $row->{code};
     my $cgivalues = $cgi_attrcode_to_attrvalues{$code} || [ '' ];
@@ -146,17 +157,19 @@ if (@patron_attr_filter_loop) {
     #              too resource intensive, MySQL can be used to do the filtering, i.e. rewire the
     #              SQL below to select only those attribute values that match the filters.
 
-    my $sql = q(SELECT borrowernumber AS bn, b.code, attribute AS val, category AS avcategory, lib AS avdescription
+    my $sql = q{
+        SELECT b.borrowernumber AS bn, b.code AS attrcode, b.attribute AS attrval, a.lib AS avdescription
         FROM borrower_attributes b
         JOIN borrower_attribute_types bt ON (b.code = bt.code)
-        LEFT JOIN authorised_values a ON (a.category = bt.authorised_value_category AND a.authorised_value = b.attribute));
+        LEFT JOIN authorised_values a ON (a.category = bt.authorised_value_category AND a.authorised_value = b.attribute)
+    };
     my $sth = $dbh->prepare($sql);
     $sth->execute();
     while (my $row = $sth->fetchrow_hashref) {
         my $pattrs = $borrowernumber_to_attributes{$row->{bn}} ||= { };
-        push @{ $pattrs->{$row->{code}} }, [
-            $row->{val},
-            defined $row->{avdescription} ? $row->{avdescription} : $row->{val},
+        push @{ $pattrs->{$row->{attrcode}} }, [
+            $row->{attrval},
+            defined $row->{avdescription} ? $row->{avdescription} : $row->{attrval},
         ];
     }
 
@@ -167,8 +180,7 @@ if (@patron_attr_filter_loop) {
             # discard patrons that do not match (case insensitive) at least one of each attribute filter value
             my $discard = 1;
             for my $attrval (map { lc $_ } @{ $cgi_attrcode_to_attrvalues{$code} }) {
-                ## if (grep { $attrval eq lc($_->[0]) } @{ $pattrs->{$code} })
-                if (grep { $attrval eq lc($_->[1]) } @{ $pattrs->{$code} }) {
+                if (grep { $attrval eq lc($_->[0]) } @{ $pattrs->{$code} }) {
                     $discard = 0;
                     last;
                 }
@@ -234,21 +246,27 @@ if ($noreport) {
         items.holdingbranch,
         items.location,
         biblio.title,
+        biblio.subtitle,
+        biblio.part_number,
+        biblio.part_name,
         biblio.author,
         biblio.biblionumber,
         items.itemcallnumber,
         items.replacementprice,
         items.enumchron,
         items.itemnotes_nonpublic,
-        items.itype
+        items.itype,
+        return_claims.created_on AS return_claim_created_on,
+        return_claims.id AS return_claim_id
       FROM issues
     LEFT JOIN borrowers   ON (issues.borrowernumber=borrowers.borrowernumber )
     LEFT JOIN items       ON (issues.itemnumber=items.itemnumber)
     LEFT JOIN biblioitems ON (biblioitems.biblioitemnumber=items.biblioitemnumber)
     LEFT JOIN biblio      ON (biblio.biblionumber=items.biblionumber )
+    LEFT JOIN return_claims ON (return_claims.borrowernumber=borrowers.borrowernumber AND return_claims.itemnumber=items.itemnumber)
     WHERE 1=1 "; # placeholder, since it is possible that none of the additional
                  # conditions will be selected by user
-    $strsth.=" AND date_due               < '" . $todaysdate     . "' " unless ($showall);
+    $strsth.=" AND date_due               < '" . $todaysdate     . "' " unless ($showall or $datedueto);
     $strsth.=" AND (borrowers.firstname like '".$bornamefilter."%' or borrowers.surname like '".$bornamefilter."%' or borrowers.cardnumber like '".$bornamefilter."%')" if($bornamefilter) ;
     $strsth.=" AND borrowers.categorycode = '" . $borcatfilter   . "' " if $borcatfilter;
     if( $itemtypefilter ){
@@ -319,9 +337,12 @@ if ($noreport) {
             branchcode             => $data->{branchcode},
             barcode                => $data->{barcode},
             itemnum                => $data->{itemnumber},
-            issuedate              => output_pref({ dt => dt_from_string( $data->{issuedate} ), dateonly => 1 }),
+            issuedate              => $data->{issuedate},
             biblionumber           => $data->{biblionumber},
             title                  => $data->{title},
+            subtitle               => $data->{subtitle},
+            part_number            => $data->{part_number},
+            part_name              => $data->{part_name},
             author                 => $data->{author},
             homebranchcode         => $data->{homebranch},
             holdingbranchcode      => $data->{holdingbranch},
@@ -329,6 +350,8 @@ if ($noreport) {
             itemcallnumber         => $data->{itemcallnumber},
             replacementprice       => $data->{replacementprice},
             itemnotes_nonpublic    => $data->{itemnotes_nonpublic},
+            return_claim_created_on => $data->{return_claim_created_on},
+            return_claim_id        => $data->{return_claim_id},
             enumchron              => $data->{enumchron},
             itemtype               => $data->{itype},
             patron_attr_value_loop => \@patron_attr_value_loop,
@@ -351,7 +374,7 @@ if ($noreport) {
     $new_cgi->delete('op');
 
     $template->param(
-        todaysdate              => output_pref($today_dt),
+        todaysdate              => $today_dt,
         overdueloop             => \@overduedata,
         nnoverdue               => scalar(@overduedata),
         noverdue_is_plural      => scalar(@overduedata) != 1,