X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=acqui%2Fbooksellers.pl;h=5a1c2480d189ce07f1337cb0187b0bb6738e75f9;hb=bc9cb5b47828f9920a9485ca2c97cc292bbb30dd;hp=d7c64dbda7ac580bbbe96ddff3847dbceff42c51;hpb=803095a7989bd1cd4357ebe9736a19284d97b2db;p=koha_fer diff --git a/acqui/booksellers.pl b/acqui/booksellers.pl index d7c64dbda7..5a1c2480d1 100755 --- a/acqui/booksellers.pl +++ b/acqui/booksellers.pl @@ -56,7 +56,7 @@ use C4::Biblio; use C4::Output; use CGI; -use C4::Dates qw/format_date/; +use C4::Acquisition qw/ GetBasketsInfosByBookseller /; use C4::Bookseller qw/ GetBookSellerFromId GetBookSeller /; use C4::Members qw/GetMember/; use C4::Context; @@ -105,30 +105,32 @@ my $userbranch = $userenv->{branch}; my $loop_suppliers = []; for my $vendor (@suppliers) { - my $baskets = get_vendors_baskets( $vendor->{id} ); + my $baskets = GetBasketsInfosByBookseller( $vendor->{id} ); my $loop_basket = []; - + for my $basket ( @{$baskets} ) { my $authorisedby = $basket->{authorisedby}; my $basketbranch = ''; # set a blank branch to start with - if ( GetMember( borrowernumber => $authorisedby ) ) { - # authorisedby may not be a valid borrowernumber; it's not foreign-key constrained! - $basketbranch = GetMember( borrowernumber => $authorisedby )->{branchcode}; + my $member = GetMember( borrowernumber => $authorisedby ); + if ( $member ) { + $basketbranch = $member->{branchcode}; } - + if ($userenv->{'flags'} & 1 || #user is superlibrarian (haspermission( $uid, { acquisition => q{*} } ) && #user has acq permissions and ($viewbaskets eq 'all' || #user is allowed to see all baskets ($viewbaskets eq 'branch' && $authorisedby && $userbranch eq $basketbranch) || #basket belongs to user's branch - ($basket->{authorisedby} && $viewbaskets == 'user' && $authorisedby == $loggedinuser) #user created this basket + ($basket->{authorisedby} && $viewbaskets eq 'user' && $authorisedby == $loggedinuser) #user created this basket ) ) ) { - for my $date_field (qw( creationdate closedate)) { - if ( $basket->{$date_field} ) { - $basket->{$date_field} = format_date( $basket->{$date_field} ); - } + foreach (qw(total_items total_biblios expected_items)) { + $basket->{$_} ||= 0; + } + if($member) { + $basket->{authorisedby_firstname} = $member->{firstname}; + $basket->{authorisedby_surname} = $member->{surname}; } push @{$loop_basket}, $basket; } @@ -146,21 +148,7 @@ $template->param( loop_suppliers => $loop_suppliers, supplier => ( $booksellerid || $supplier ), count => $supplier_count, + dateformat => C4::Context->preference('dateformat'), ); output_html_with_http_headers $query, $cookie, $template->output; - -sub get_vendors_baskets { - my $supplier_id = shift; - my $dbh = C4::Context->dbh; - my $sql = <<'ENDSQL'; -select aqbasket.*, count(*) as total, borrowers.firstname, borrowers.surname -from aqbasket left join aqorders on aqorders.basketno = aqbasket.basketno -left join borrowers on aqbasket.authorisedby = borrowers.borrowernumber -where booksellerid = ? -AND ( aqorders.quantity > aqorders.quantityreceived OR quantityreceived IS NULL) -AND datecancellationprinted IS NULL -group by basketno -ENDSQL - return $dbh->selectall_arrayref( $sql, { Slice => {} }, $supplier_id ); -}