X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=acqui%2Fbooksellers.pl;h=5a1c2480d189ce07f1337cb0187b0bb6738e75f9;hb=HEAD;hp=2b16fe4bbc4e7f496fd9b39e2db18b4e7dd66702;hpb=0fe43ac28b2a171ac07f82c38347e1b10a0a9fd2;p=koha_gimpoz diff --git a/acqui/booksellers.pl b/acqui/booksellers.pl index 2b16fe4bbc..5a1c2480d1 100755 --- a/acqui/booksellers.pl +++ b/acqui/booksellers.pl @@ -41,7 +41,7 @@ C<$supplier> is the string with which we search for a supplier =back -=item id or supplierid +=item id or booksellerid The id of the supplier whose baskets we will display @@ -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; @@ -74,11 +74,11 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( #parameters my $supplier = $query->param('supplier'); -my $id = $query->param('id') || $query->param('supplierid'); +my $booksellerid = $query->param('booksellerid'); my @suppliers; -if ($id) { - push @suppliers, GetBookSellerFromId($id); +if ($booksellerid) { + push @suppliers, GetBookSellerFromId($booksellerid); } else { @suppliers = GetBookSeller($supplier); } @@ -87,7 +87,7 @@ my $supplier_count = @suppliers; if ( $supplier_count == 1 ) { $template->param( supplier_name => $suppliers[0]->{'name'}, - id => $suppliers[0]->{'id'} + booksellerid => $suppliers[0]->{'booksellerid'} ); } @@ -105,26 +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 = GetMember( borrowernumber => $authorisedby )->{branchcode}; - + my $basketbranch = ''; # set a blank branch to start with + 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; } @@ -132,7 +138,7 @@ for my $vendor (@suppliers) { push @{$loop_suppliers}, { loop_basket => $loop_basket, - supplierid => $vendor->{id}, + booksellerid => $vendor->{id}, name => $vendor->{name}, active => $vendor->{active}, }; @@ -140,23 +146,9 @@ for my $vendor (@suppliers) { } $template->param( loop_suppliers => $loop_suppliers, - supplier => ( $id || $supplier ), + 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 ); -}