X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=svc%2Fcheckouts;h=9a1b3a5648c23df43c2237a871847d111090e1c0;hb=refs%2Fheads%2Fkoha_ffzg;hp=51fd861cb90996e80e7b9661ff7e9586fc8d92b9;hpb=13fda8378337388e0bf353eacfb26ac3d3511dc8;p=koha.git diff --git a/svc/checkouts b/svc/checkouts index 51fd861cb9..9a1b3a5648 100755 --- a/svc/checkouts +++ b/svc/checkouts @@ -17,33 +17,37 @@ # 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 JSON qw(to_json); -use C4::Auth qw(check_cookie_auth); +use C4::Auth qw(check_cookie_auth haspermission get_session); use C4::Biblio qw(GetMarcBiblio GetFrameworkCode GetRecordValue ); use C4::Circulation qw(GetIssuingCharges CanBookBeRenewed GetRenewCount GetSoonestRenewDate); -use C4::Koha qw(GetAuthorisedValueByCode); +use C4::Overdues qw(GetFine); use C4::Context; +use Koha::AuthorisedValues; use Koha::DateUtils; +use Koha::ItemTypes; my $input = new CGI; my ( $auth_status, $sessionID ) = - check_cookie_auth( $input->cookie('CGISESSID'), - { circulate => 'circulate_remaining_permissions' } ); + check_cookie_auth( $input->cookie('CGISESSID')); -if ( $auth_status ne "ok" ) { +my $session = get_session($sessionID); +my $userid = $session->param('id'); + +unless (haspermission($userid, { circulate => 'circulate_remaining_permissions' }) + || haspermission($userid, { borrowers => 'edit_borrowers' })) { exit 0; } my @sort_columns = qw/date_due title itype issuedate branchcode itemcallnumber/; -my @borrowernumber = $input->param('borrowernumber'); +my @borrowernumber = $input->multi_param('borrowernumber'); my $offset = $input->param('iDisplayStart'); my $results_per_page = $input->param('iDisplayLength') || -1; @@ -74,17 +78,19 @@ my $sql = ' itemnumber, barcode, + branches2.branchname AS homebranch, itemnotes, + itemnotes_nonpublic, itemcallnumber, replacementprice, issues.branchcode, - branchname, + branches.branchname, items.itype, - itemtype_item.description AS itype_description, biblioitems.itemtype, - itemtype_bib.description AS itemtype_description, + + items.ccode AS collection, borrowernumber, surname, @@ -93,6 +99,8 @@ my $sql = ' itemlost, damaged, + location, + items.enumchron, DATEDIFF( issuedate, CURRENT_DATE() ) AS not_issued_today FROM issues @@ -101,8 +109,7 @@ my $sql = ' LEFT JOIN biblioitems USING ( biblionumber ) LEFT JOIN borrowers USING ( borrowernumber ) LEFT JOIN branches ON ( issues.branchcode = branches.branchcode ) - LEFT JOIN itemtypes itemtype_bib ON ( biblioitems.itemtype = itemtype_bib.itemtype ) - LEFT JOIN itemtypes itemtype_item ON ( items.itype = itemtype_item.itemtype ) + LEFT JOIN branches branches2 ON ( items.homebranch = branches2.branchcode ) WHERE borrowernumber '; @@ -126,6 +133,7 @@ my @checkouts_today; my @checkouts_previous; while ( my $c = $sth->fetchrow_hashref() ) { my ($charge) = GetIssuingCharges( $c->{itemnumber}, $c->{borrowernumber} ); + my $fine = GetFine( $c->{itemnumber}, $c->{borrowernumber} ); my ( $can_renew, $can_renew_error ) = CanBookBeRenewed( $c->{borrowernumber}, $c->{itemnumber} ); @@ -142,18 +150,44 @@ while ( my $c = $sth->fetchrow_hashref() ) { my ( $renewals_count, $renewals_allowed, $renewals_remaining ) = GetRenewCount( $c->{borrowernumber}, $c->{itemnumber} ); + my $itemtype = Koha::ItemTypes->find( $item_level_itypes ? $c->{itype} : $c->{itemtype} ); + my $location; + if ( $c->{location} ) { + my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $c->{location} }); + $location = $av->count ? $av->next->lib : ''; + } + my $collection; + if ( $c->{collection} ) { + my $av = Koha::AuthorisedValues->search({ category => 'CCODE', authorised_value => $c->{collection} }); + $collection = $av->count ? $av->next->lib : ''; + } + my $lost; + if ( $c->{itemlost} ) { + my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $c->{itemlost} }); + $lost = $av->count ? $av->next->lib : ''; + } + my $damaged; + if ( $c->{damaged} ) { + my $av = Koha::AuthorisedValues->search({ category => 'DAMAGED', authorised_value => $c->{damaged} }); + $damaged = $av->count ? $av->next->lib : ''; + } my $checkout = { - DT_RowId => $c->{itemnumber} . '-' . $c->{borrowernumber}, - title => $c->{title}, - author => $c->{author}, - barcode => $c->{barcode}, - itemtype => $item_level_itypes ? $c->{itype} : $c->{itemtype}, - itemtype_description => $item_level_itypes ? $c->{itype_description} : $c->{itemtype_description}, - itemnotes => $c->{itemnotes}, - branchcode => $c->{branchcode}, - branchname => $c->{branchname}, + DT_RowId => $c->{itemnumber} . '-' . $c->{borrowernumber}, + title => $c->{title}, + author => $c->{author}, + barcode => $c->{barcode}, + itemtype => $item_level_itypes ? $c->{itype} : $c->{itemtype}, + itemtype_description => $itemtype ? $itemtype->translated_description : q{}, + collection => $collection, + location => $location, + homebranch => $c->{homebranch}, + itemnotes => $c->{itemnotes}, + itemnotes_nonpublic => $c->{itemnotes_nonpublic}, + branchcode => $c->{branchcode}, + branchname => $c->{branchname}, itemcallnumber => $c->{itemcallnumber} || q{}, charge => $charge, + fine => $fine, price => $c->{replacementprice} || q{}, can_renew => $can_renew, can_renew_error => $can_renew_error, @@ -165,7 +199,8 @@ while ( my $c = $sth->fetchrow_hashref() ) { date_due => $c->{date_due}, date_due_overdue => $c->{date_due_overdue} ? JSON::true : JSON::false, timestamp => $c->{timestamp}, - onsite_checkout => $c->{onsite_checkout}, + onsite_checkout => $c->{onsite_checkout}, + enumchron => $c->{enumchron}, renewals_count => $renewals_count, renewals_allowed => $renewals_allowed, renewals_remaining => $renewals_remaining, @@ -183,11 +218,10 @@ while ( my $c = $sth->fetchrow_hashref() ) { ), subtitle => GetRecordValue( 'subtitle', - GetMarcBiblio( $c->{biblionumber} ), - GetFrameworkCode( $c->{biblionumber} ) - ), - lost => $c->{itemlost} ? GetAuthorisedValueByCode( 'LOST', $c->{itemlost} ) : undef, - damaged => $c->{damaged} ? GetAuthorisedValueByCode( 'DAMAGED', $c->{damaged} ) : undef, + GetMarcBiblio({ biblionumber => $c->{biblionumber} }), + GetFrameworkCode( $c->{biblionumber} ) ), + lost => $lost, + damaged => $damaged, borrower => { surname => $c->{surname}, firstname => $c->{firstname}, @@ -204,13 +238,21 @@ while ( my $c = $sth->fetchrow_hashref() ) { } } + +@checkouts_today = sort { $a->{timestamp} cmp $b->{timestamp} } @checkouts_today; @checkouts_today = reverse(@checkouts_today) - if ( C4::Context->preference('todaysIssuesDefaultSortOrder') eq 'desc' ); + unless ( C4::Context->preference('todaysIssuesDefaultSortOrder') eq 'desc' ); + +@checkouts_previous = sort { $a->{date_due} cmp $b->{date_due} } @checkouts_previous; @checkouts_previous = reverse(@checkouts_previous) if ( C4::Context->preference('previousIssuesDefaultSortOrder') eq 'desc' ); my @checkouts = ( @checkouts_today, @checkouts_previous ); +my $i = 1; +map { $_->{sort_order} = $i++ } @checkouts; + + my $data; $data->{'iTotalRecords'} = scalar @checkouts; $data->{'iTotalDisplayRecords'} = scalar @checkouts;