From 4283cb47572da2c78e53f99e35c486eb6993eb81 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 5 Apr 2012 11:24:40 +0200 Subject: [PATCH 1/1] Bug 5342: Followup : DataTables server-side processing original author is Julian Maurice --- C4/Letters.pm | 6 +- koha-tmpl/intranet-tmpl/prog/en/js/datatables.js | 2 +- .../prog/en/modules/serials/claims.tt | 486 ++++++++------------ .../prog/en/modules/serials/tables/claims.tt | 38 ++ serials/claims.pl | 57 +-- serials/tables/claims.pl | 107 +++++ 6 files changed, 354 insertions(+), 342 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/serials/tables/claims.tt create mode 100755 serials/tables/claims.pl diff --git a/C4/Letters.pm b/C4/Letters.pm index 5a929d0..3e021df 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -330,14 +330,14 @@ sub SendAlerts { my $sthbookseller = $dbh->prepare("select * from aqbooksellers where id=?"); - $sthbookseller->execute( $dataorders->[0]->{booksellerid} ); + $sthbookseller->execute( $dataorders->[0]->{aqbooksellerid} ); my $databookseller = $sthbookseller->fetchrow_hashref; my @email; push @email, $databookseller->{bookselleremail} if $databookseller->{bookselleremail}; push @email, $databookseller->{contemail} if $databookseller->{contemail}; unless (@email) { - warn "Bookseller $dataorders->[0]->{booksellerid} without emails"; + warn "Bookseller $dataorders->[0]->{aqbooksellerid} without emails"; return { error => "no_email" }; } @@ -356,7 +356,7 @@ sub SendAlerts { # ... then send mail my %mail = ( - To => join( ','. @email), + To => join( ',', @email), From => $userenv->{emailaddress}, Subject => Encode::encode( "utf8", "" . $letter->{title} ), Message => Encode::encode( "utf8", "" . $letter->{content} ), diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js index e0cc888..21e03e1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js @@ -23,7 +23,7 @@ var dataTablesDefaults = { "sSearch" : window.MSG_DT_SEARCH || "Search:", "sZeroRecords" : window.MSG_DT_ZERO_RECORDS || "No matching records found" }, - "sDom": '<"top pager"ilpf>t<"bottom pager"ip>' + "sDom": '<"top pager"ilpf>rt<"bottom pager"ip>' }; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt index 78b8eb9..1ab14d5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt @@ -1,337 +1,223 @@ [% INCLUDE 'doc-head-open.inc' %] - Koha › Serials › Claims - [% INCLUDE 'doc-head-close.inc' %] - - - + - // Checkboxes : Select All / None - $("span.checkall").html(" "+_("Check All")+""); - $("span.exportSelected").html(" "+_("Export selected items data") +"<\/a>"); + -[% INCLUDE 'calendar.inc' %] - + [% INCLUDE 'header.inc' %] [% INCLUDE 'serials-search.inc' %]
- -
-
-
-

Claims

+
+
+
- [% IF error_claim %] - [% IF ( error_claim == "no_email" ) %] -
This vendor has no email
- [% ELSE %] -
[% error_claim %]
- [% END %] +

Claims

+ [% IF ( error_claim ) %] +
[% error_claim %]
[% END %] - [% IF info_claim %] + [% IF ( info_claim ) %]
Email has been sent.
[% END %] + [% UNLESS ( letter ) %] +
No claims notice defined. Please define one
+ [% END %] -[% IF ( letter ) %][% UNLESS ( missingissues ) %][% IF ( supplierid ) %]
No missing issues found.
[% ELSE %]
Please choose a vendor.
[% END %][% END %][% END %] - - [% IF ( SHOWCONFIRMATION ) %] -
Your notification has been sent.
- [% END %] -[% UNLESS ( letter ) %]
No claims notice defined. Please define one.
[% END %] -
-
- - - - [% IF ( phone ) %]Phone: [% phone %][% END %] - [% IF ( booksellerfax ) %]Fax: [% booksellerfax %][% END %] - [% IF ( bookselleremail ) %]

[% bookselleremail %][% END %] -

-
- - [% IF ( missingissues ) %]

Missing Issues

-
-
- Filters : - -
    -
  1. - - -
  2. - -
  3. - - - - -
  4. - -
  5. - - Show Calendar - - - - Show Calendar - - [% INCLUDE 'date-format.inc' %] - -
  6. - -
  7. - -
  8. -
-
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
VendorBranchTitleIssue numberStatusSinceClaims countClaim Date
+ + + +
+ +
+

+ + [% IF ( letter ) %] +
+ + +
+
+ [% END %] +
-
-
- - - - - [% IF ( letter ) %] - - [% END %] - - - - - - - - - - - [% FOREACH missingissue IN missingissues %] - - [% IF ( letter ) %] - - [% END %] - - - - - - - - - - [% END %] -
VendorLibraryTitleIssue numberStatusSinceClaims countClaim date
- - [% missingissue.name %][% missingissue.branchcode %] - [% missingissue.title |html %] - [% missingissue.serialseq %] - [% IF ( missingissue.status1 ) %]Expected[% END %] - [% IF ( missingissue.status2 ) %]Arrived[% END %] - [% IF ( missingissue.status3 ) %]Late[% END %] - [% IF ( missingissue.status4 ) %]Missing[% END %] - [% IF ( missingissue.status7 ) %]Claimed[% END %] - [% missingissue.planneddate %][% missingissue.claims_count %][% missingissue.claimdate %]
-

- - [% IF ( letter ) %] -
- - - - -
- [% END %] -
-
-[% END %] - -
-
- -
+
+
+
[% INCLUDE 'serials-menu.inc' %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/tables/claims.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/tables/claims.tt new file mode 100644 index 0000000..f9778d4 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/tables/claims.tt @@ -0,0 +1,38 @@ +[% USE KohaDates %] +{ + 'sEcho': '[% sEcho %]', + 'iTotalRecords': '[% iTotalRecords %]', + 'iTotalDisplayRecords': '[% iTotalDisplayRecords %]', + 'aaData': [ + [% FOREACH data IN aaData %] + { + 'dt_checkbox': + '[% UNLESS ( data.cannot_claim ) %][% END %]', + + 'dt_suppliername': + '[% data.suppliername |html %]', + + 'dt_title': + '[% data.title |html %]', + + 'dt_branchname': + '[% data.branchname %]', + + 'dt_serialseq': + '[% data.serialseq %]', + + 'dt_status': + '[% IF ( data.status == 1 ) %]Expected[% END %][% IF ( data.status == 2 ) %]Arrived[% END %][% IF ( data.status == 3 ) %]Late[% END %][% IF ( data.status == 4 ) %]Missing[% END %][% IF ( data.status == 7 ) %]Claimed[% END %]', + + 'dt_planneddate': + '[% data.planneddate|$KohaDates %]', + + 'dt_claims_count': + '[% data.claims_count %]', + + 'dt_claimdate': + '[% data.claimdate|$KohaDates %]' + }, + [% END %] + ] +} diff --git a/serials/claims.pl b/serials/claims.pl index e65d827..2ea2fe1 100755 --- a/serials/claims.pl +++ b/serials/claims.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Parts Copyright 2010 Biblibre +# Parts Copyright 2012 Biblibre # This file is part of Koha. # @@ -17,8 +17,7 @@ # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -use strict; -use warnings; +use Modern::Perl; use CGI; use C4::Auth; use C4::Serials; @@ -50,58 +49,40 @@ my ($template, $loggedinuser, $cookie) # supplierlist is returned in name order my $supplierlist = GetSuppliersWithLateIssues(); -for my $s (@{$supplierlist} ) { - $s->{count} = scalar GetLateOrMissingIssues($s->{id}, q{}, $order); - if ($supplierid && $s->{id} == $supplierid) { - $s->{selected} = 1; - } -} -my $letters = GetLetters('claimissues'); -my @letters; -foreach (keys %{$letters}){ - push @letters ,{code=>$_,name=> $letters->{$_}}; +my @suploop; +foreach my $s ( @{$supplierlist} ) { + push @suploop, { %$s }; } -my $letter=((scalar(@letters)>1) || ($letters[0]->{name}||$letters[0]->{code})); -my @missingissues; -my @supplierinfo; -if ($supplierid) { - @missingissues = GetLateOrMissingIssues($supplierid,$serialid,$order); - @supplierinfo=GetBookSeller($supplierid); +my $letters = GetLetters("claimissues"); +my @letters; +foreach ( keys %{$letters} ) { + push @letters, { code => $_, name => $letters->{$_} }; } -my $branchloop = GetBranchesLoop(); -unshift @$branchloop, {value=> 'all',name=>''}; +my $letter = ( ( scalar(@letters) > 1 ) || ( $letters[0]->{name} || $letters[0]->{code} ) ); my @serialnums=$input->param('serialid'); if (@serialnums) { # i.e. they have been flagged to generate claims my $err; eval { - SendAlerts('claimissues',\@serialnums,$input->param("letter_code")); + $err = SendAlerts('claimissues',\@serialnums,$input->param("letter_code")); UpdateClaimdateIssues(\@serialnums); }; if ( $@ ) { - $template->param(error_claim => $@); - } elsif ( defined $err->{error} and $err->{error} eq "no_email" ) { + $template->{VARS}->{'error_claim'} = $@; + } elsif ( ref $err and exists $err->{error} and $err->{error} eq "no_email" ) { $template->{VARS}->{'error_claim'} = "no_email"; } else { $template->{VARS}->{'info_claim'} = 1; } } -$template->param('letters'=>\@letters,'letter'=>$letter); + $template->param( - order =>$order, - suploop => $supplierlist, - phone => $supplierinfo[0]->{phone}, - booksellerfax => $supplierinfo[0]->{booksellerfax}, - bookselleremail => $supplierinfo[0]->{bookselleremail}, - missingissues => \@missingissues, - supplierid => $supplierid, - claimletter => $claimletter, - supplierloop => \@supplierinfo, - branchloop => $branchloop, - dateformat => C4::Context->preference("dateformat"), - DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), - ); + letters => \@letters, + letter => $letter, + order => $order, + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), +); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/serials/tables/claims.pl b/serials/tables/claims.pl new file mode 100755 index 0000000..c5fa521 --- /dev/null +++ b/serials/tables/claims.pl @@ -0,0 +1,107 @@ +#!/usr/bin/perl + +use Modern::Perl; + +use CGI; +use JSON; + +use C4::Auth; +use C4::Circulation qw/CanBookBeRenewed/; +use C4::Context; +use C4::Koha qw/getitemtypeimagelocation/; +use C4::Reserves qw/CheckReserves/; +use C4::Utils::DataTables; +use C4::Output; + +my $input = new CGI; + +my $planneddate_to = $input->param('planneddate_to'); +my $planneddate_from = $input->param('planneddate_from'); +my $claimdatefrom = $input->param('claimdatefrom'); +my $claimdateto = $input->param('claimdateto'); + + +my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user({ + template_name => 'serials/tables/claims.tmpl', + query => $input, + type => 'intranet', + authnotrequired => 0, + flagsrequired => { circulate => 'circulate_remaining_permission' }, +}); + +# Fetch DataTables parameters +my %dtparam = dt_get_params( $input ); + +while ( my ( $k, $v ) = each %dtparam ) { + $v =~ s/^dt_(.+)/$1/; + $dtparam{$k} = $v; +} + +my $branchcode; +unless( $flags->{'superlibrarian'} == 1 + || $template->{'param_map'}->{'CAN_user_serials_superserials'} ){ + $branchcode = C4::Context->userenv->{'branch'}; +} + +my $dbh = C4::Context->dbh; + +# Build the query +my $select = < 0 ? @$planneddate_f : (); + +$where_filters .= ( $claimdate_q ? $claimdate_q : '' ); +push @bind_params, scalar( @$claimdate_f ) > 0 ? @$claimdate_f : (); + +my ($filters, $filter_params) = dt_build_having(\%dtparam); +my $having = @$filters ? " HAVING ". join(" AND ", @$filters) : ''; +my $order_by = dt_build_orderby(\%dtparam); +my $limit .= " LIMIT ?,? "; + +my $query = $select . $from . $where . $where_filters . ( $having || '' ) . $order_by . $limit; +push @bind_params, @$filter_params, $dtparam{'iDisplayStart'}, $dtparam{'iDisplayLength'}; +my $sth = $dbh->prepare($query); +$sth->execute(@bind_params); +my $results = $sth->fetchall_arrayref({}); + +$sth = $dbh->prepare("SELECT FOUND_ROWS()"); +$sth->execute; +my ($iTotalDisplayRecords) = $sth->fetchrow_array; + +# This is mandatory for DataTables to show the total number of results +my $select_total_count = "SELECT COUNT(*) "; +$sth = $dbh->prepare($select_total_count.$from.$where); +$sth->execute($branchcode ? $branchcode : ()); +my ($iTotalRecords) = $sth->fetchrow_array; + +$template->param( + sEcho => $dtparam{'sEcho'}, + iTotalRecords => $iTotalRecords, + iTotalDisplayRecords => $iTotalDisplayRecords, + aaData => $results, +); + +output_with_http_headers $input, $cookie, $template->output, "json"; -- 1.7.7.3