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;
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;
}
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 );
-}