Bug 5549 : GetPendingIssues now returns DateTime objects
[koha.git] / members / readingrec.pl
index 24fc15b..05ade6a 100755 (executable)
@@ -29,9 +29,11 @@ use C4::Auth;
 use C4::Output;
 use C4::Members;
 use C4::Branch;
-use List::MoreUtils qw/any/;
+use List::MoreUtils qw/any uniq/;
+use Koha::DateUtils;
 
 use C4::Dates qw/format_date/;
+use C4::Members::Attributes qw(GetBorrowerAttributes);
 
 my $input = CGI->new;
 
@@ -40,6 +42,14 @@ my $data = undef;
 my $borrowernumber = undef;
 my $cardnumber = undef;
 
+my ($template, $loggedinuser, $cookie)= get_template_and_user({template_name => "members/readingrec.tmpl",
+                               query => $input,
+                               type => "intranet",
+                               authnotrequired => 0,
+                               flagsrequired => {borrowers => 1},
+                               debug => 1,
+                               });
+
 if ($input->param('cardnumber')) {
     $cardnumber = $input->param('cardnumber');
     $data = GetMember(cardnumber => $cardnumber);
@@ -50,30 +60,14 @@ if ($input->param('borrowernumber')) {
     $data = GetMember(borrowernumber => $borrowernumber);
 }
 
-my $order=$input->param('order') || 'date_due desc';
-my $limit=$input->param('limit');
-
-if ($limit){
-    if ($limit eq 'full'){
-               $limit=0;
-    }
-}
-else {
-  $limit=50;
-}
+my $order = 'date_due desc';
+my $limit = 0;
 my ( $issues ) = GetAllIssues($borrowernumber,$order,$limit);
-warn "BORR : $borrowernumber = ".Data::Dumper::Dumper($issues);
-
-my ($template, $loggedinuser, $cookie)
-= get_template_and_user({template_name => "members/readingrec.tmpl",
-                               query => $input,
-                               type => "intranet",
-                               authnotrequired => 0,
-                               flagsrequired => {borrowers => 1},
-                               debug => 1,
-                               });
 
 my @loop_reading;
+my @barcodes;
+my $today = C4::Dates->new();
+$today = $today->output("iso");
 
 foreach my $issue (@{$issues}){
        my %line;
@@ -82,14 +76,32 @@ foreach my $issue (@{$issues}){
        $line{title}           = $issue->{'title'};
        $line{author}          = $issue->{'author'};
        $line{classification}  = $issue->{'classification'} || $issue->{'itemcallnumber'};
-       $line{date_due}        = format_date($issue->{'date_due'});
+    my $dt = dt_from_string($issue->{date_due}, 'sql');
+       $line{date_due}        = output_pref($dt);
        $line{returndate}      = format_date($issue->{'returndate'});
        $line{issuedate}       = format_date($issue->{'issuedate'});
-       $line{issuingbranch}   = GetBranchName($issue->{'issuingbranch'});
+       $line{issuingbranch}   = GetBranchName($issue->{'branchcode'});
        $line{renewals}        = $issue->{'renewals'};
        $line{barcode}         = $issue->{'barcode'};
        $line{volumeddesc}     = $issue->{'volumeddesc'};
        push(@loop_reading,\%line);
+    if (($input->param('op') eq 'export_barcodes') and ($today eq $issue->{'returndate'})) {
+        push( @barcodes, $issue->{'barcode'} );
+    }
+}
+
+if ($input->param('op') eq 'export_barcodes') {
+    my $borrowercardnumber = GetMember( borrowernumber => $borrowernumber )->{'cardnumber'} ;
+    my $delimiter = "\n";
+    binmode( STDOUT, ":encoding(UTF-8)");
+    print $input->header(
+        -type       => 'application/octet-stream',
+        -charset    => 'utf-8',
+        -attachment => "$today-$borrowercardnumber-checkinexport.txt"
+    );
+    my $content = join($delimiter, uniq(@barcodes));
+    print $content;
+    exit;
 }
 
 if ( $data->{'category_type'} eq 'C') {
@@ -107,12 +119,21 @@ if (! $limit){
 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
 $template->param( picture => 1 ) if $picture;
 
+if (C4::Context->preference('ExtendedPatronAttributes')) {
+    my $attributes = GetBorrowerAttributes($borrowernumber);
+    $template->param(
+        ExtendedPatronAttributes => 1,
+        extendedattributes => $attributes
+    );
+}
+
 $template->param(
                                                readingrecordview => 1,
                                                biblionumber => $data->{'biblionumber'},
                                                title => $data->{'title'},
                                                initials => $data->{'initials'},
                                                surname => $data->{'surname'},
+                                               othernames => $data->{'othernames'},
                                                borrowernumber => $borrowernumber,
                                                limit => $limit,
                                                firstname => $data->{'firstname'},
@@ -124,6 +145,7 @@ $template->param(
                                            address => $data->{'address'},
                                                address2 => $data->{'address2'},
                                            city => $data->{'city'},
+                                           state => $data->{'state'},
                                                zipcode => $data->{'zipcode'},
                                                country => $data->{'country'},
                                                phone => $data->{'phone'},
@@ -132,7 +154,9 @@ $template->param(
                                                is_child        => ($data->{'category_type'} eq 'C'),
                                                branchname => GetBranchName($data->{'branchcode'}),
                                                showfulllink => (scalar @loop_reading > 50),                                    
-                                               loop_reading => \@loop_reading);
+                                               loop_reading => \@loop_reading,
+                                               activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
+);
 output_html_with_http_headers $input, $cookie, $template->output;