X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=inline;f=acqui%2Fbasket.pl;h=e8b4199d5902dc6c974d972d7629021e186b9344;hb=7c521a8cf20d73e7435d43450ba887689e60841b;hp=ace6b63a06477c5b70a4aa643d49be2255aa10c5;hpb=1b4b78a136c769075f6ce796cbd763de7feb95c6;p=koha.git diff --git a/acqui/basket.pl b/acqui/basket.pl index ace6b63a06..e8b4199d59 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -28,6 +28,7 @@ use C4::Output; use CGI; use C4::Acquisition; use C4::Budgets; +use C4::Branch; use C4::Bookseller qw( GetBookSellerFromId); use C4::Debug; use C4::Biblio; @@ -65,7 +66,7 @@ the supplier this script have to display the basket. =cut my $query = new CGI; -my $basketno = $query->param('basketno'); +our $basketno = $query->param('basketno'); my $booksellerid = $query->param('booksellerid'); my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( @@ -80,13 +81,25 @@ my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( ); my $basket = GetBasket($basketno); +$booksellerid = $basket->{booksellerid} unless $booksellerid; +my ($bookseller) = GetBookSellerFromId($booksellerid); + +unless (CanUserManageBasket($loggedinuser, $basket, $userflags)) { + $template->param( + cannot_manage_basket => 1, + basketno => $basketno, + basketname => $basket->{basketname}, + booksellerid => $booksellerid, + name => $bookseller->{name} + ); + output_html_with_http_headers $query, $cookie, $template->output; + exit; +} # FIXME : what about the "discount" percentage? # FIXME : the query->param('booksellerid') below is probably useless. The bookseller is always known from the basket # if no booksellerid in parameter, get it from basket # warn "=>".$basket->{booksellerid}; -$booksellerid = $basket->{booksellerid} unless $booksellerid; -my ($bookseller) = GetBookSellerFromId($booksellerid); my $op = $query->param('op'); if (!defined $op) { $op = q{}; @@ -103,7 +116,7 @@ if ( $op eq 'delete_confirm' ) { $template->param( NO_BOOKSELLER => 1 ); } elsif ( $op eq 'del_basket') { $template->param( delete_confirm => 1 ); - if ( C4::Context->preference("IndependantBranches") ) { + if ( C4::Context->preference("IndependentBranches") ) { my $userenv = C4::Context->userenv; unless ( $userenv->{flags} == 1 ) { my $validtest = ( $basket->{creationdate} eq '' ) @@ -177,22 +190,36 @@ if ( $op eq 'delete_confirm' ) { } exit; } else { - $template->param(confirm_close => "1", - booksellerid => $booksellerid, - basketno => $basket->{'basketno'}, - basketname => $basket->{'basketname'}, - basketgroupname => $basket->{'basketname'}); - + $template->param( + confirm_close => "1", + booksellerid => $booksellerid, + basketno => $basket->{'basketno'}, + basketname => $basket->{'basketname'}, + basketgroupname => $basket->{'basketname'}, + ); } } elsif ($op eq 'reopen') { - my $basket; - $basket->{basketno} = $query->param('basketno'); - $basket->{closedate} = undef; - ModBasket($basket); + ReopenBasket($query->param('basketno')); print $query->redirect('/cgi-bin/koha/acqui/basket.pl?basketno='.$basket->{'basketno'}) +} elsif ( $op eq 'mod_users' ) { + my $basketusers_ids = $query->param('basketusers_ids'); + my @basketusers = split( /:/, $basketusers_ids ); + ModBasketUsers($basketno, @basketusers); + print $query->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno"); + exit; +} elsif ( $op eq 'mod_branch' ) { + my $branch = $query->param('branch'); + $branch = undef if(defined $branch and $branch eq ''); + ModBasket({ + basketno => $basket->{basketno}, + branch => $branch + }); + print $query->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno"); + exit; } else { + my @branches_loop; # get librarian branch... - if ( C4::Context->preference("IndependantBranches") ) { + if ( C4::Context->preference("IndependentBranches") ) { my $userenv = C4::Context->userenv; unless ( $userenv->{flags} == 1 ) { my $validtest = ( $basket->{creationdate} eq '' ) @@ -204,15 +231,43 @@ if ( $op eq 'delete_confirm' ) { exit 1; } } + if (!defined $basket->{branch} or $basket->{branch} eq $userenv->{branch}) { + push @branches_loop, { + branchcode => $userenv->{branch}, + branchname => $userenv->{branchname}, + selected => 1, + }; + } + } else { + # get branches + my $branches = C4::Branch::GetBranches; + my @branchcodes = sort { + $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} + } keys %$branches; + foreach my $branch (@branchcodes) { + my $selected = 0; + if (defined $basket->{branch}) { + $selected = 1 if $branch eq $basket->{branch}; + } else { + $selected = 1 if $branch eq C4::Context->userenv->{branch}; + } + push @branches_loop, { + branchcode => $branch, + branchname => $branches->{$branch}->{branchname}, + selected => $selected + }; + } } + #if the basket is closed,and the user has the permission to edit basketgroups, display a list of basketgroups - my $basketgroups; - my $member = GetMember(borrowernumber => $loggedinuser); - if ($basket->{closedate} && haspermission({ acquisition => 'group_manage'} )) { + my ($basketgroup, $basketgroups); + my $staffuser = GetMember(borrowernumber => $loggedinuser); + if ($basket->{closedate} && haspermission($staffuser->{userid}, { acquisition => 'group_manage'} )) { $basketgroups = GetBasketgroups($basket->{booksellerid}); for my $bg ( @{$basketgroups} ) { if ($basket->{basketgroupid} && $basket->{basketgroupid} == $bg->{id}){ $bg->{default} = 1; + $basketgroup = $bg; } } my %emptygroup = ( id => undef, @@ -240,6 +295,13 @@ if ( $op eq 'delete_confirm' ) { "loggedinuser: $loggedinuser; creationdate: %s; authorisedby: %s", $basket->{creationdate}, $basket->{authorisedby}; + my @basketusers_ids = GetBasketUsers($basketno); + my @basketusers; + foreach my $basketuser_id (@basketusers_ids) { + my $basketuser = GetMember(borrowernumber => $basketuser_id); + push @basketusers, $basketuser if $basketuser; + } + #to get active currency my $cur = GetCurrency(); @@ -286,13 +348,9 @@ if ( $op eq 'delete_confirm' ) { my @orders = GetOrders($basketno); if ($basket->{basketgroupid}){ - my $basketgroup = GetBasketgroup($basket->{basketgroupid}); - for my $key (keys %$basketgroup ){ - $basketgroup->{"basketgroup$key"} = delete $basketgroup->{$key}; - } - $basketgroup->{basketgroupdeliveryplace} = C4::Branch::GetBranchName( $basketgroup->{basketgroupdeliveryplace} ); - $basketgroup->{basketgroupbillingplace} = C4::Branch::GetBranchName( $basketgroup->{basketgroupbillingplace} ); - $template->param(%$basketgroup); + $basketgroup = GetBasketgroup($basket->{basketgroupid}); + $basketgroup->{deliveryplacename} = C4::Branch::GetBranchName( $basketgroup->{deliveryplace} ); + $basketgroup->{billingplacename} = C4::Branch::GetBranchName( $basketgroup->{billingplace} ); } my $borrower= GetMember('borrowernumber' => $loggedinuser); my $budgets = GetBudgetHierarchy; @@ -307,21 +365,20 @@ if ( $op eq 'delete_confirm' ) { last; } - my @cancelledorders = GetCancelledOrders($basketno); - foreach (@cancelledorders) { - $_->{'line_total'} = sprintf("%.2f", $_->{'ecost'} * $_->{'quantity'}); - } - $template->param( basketno => $basketno, basketname => $basket->{'basketname'}, + basketbranchname => C4::Branch::GetBranchName($basket->{branch}), basketnote => $basket->{note}, basketbooksellernote => $basket->{booksellernote}, basketcontractno => $basket->{contractnumber}, basketcontractname => $contract->{contractname}, + branches_loop => \@branches_loop, creationdate => $basket->{creationdate}, authorisedby => $basket->{authorisedby}, authorisedbyname => $basket->{authorisedbyname}, + basketusers_ids => join(':', @basketusers_ids), + basketusers => \@basketusers, closedate => $basket->{closedate}, estimateddeliverydate=> $estimateddeliverydate, deliveryplace => C4::Branch::GetBranchName( $basket->{deliveryplace} ), @@ -331,7 +388,7 @@ if ( $op eq 'delete_confirm' ) { name => $bookseller->{'name'}, books_loop => \@books_loop, book_foot_loop => \@book_foot_loop, - cancelledorders_loop => \@cancelledorders, + cancelledorders_loop => \@cancelledorders_loop, total_quantity => $total_quantity, total_gste => sprintf( "%.2f", $total_gste ), total_gsti => sprintf( "%.2f", $total_gsti ), @@ -339,6 +396,7 @@ if ( $op eq 'delete_confirm' ) { currency => $cur->{'currency'}, listincgst => $bookseller->{listincgst}, basketgroups => $basketgroups, + basketgroup => $basketgroup, grouped => $basket->{basketgroupid}, unclosable => @orders ? 0 : 1, has_budgets => $has_budgets, @@ -426,6 +484,20 @@ sub get_order_infos { $line{surnamesuggestedby} = $$suggestion{surnamesuggestedby}; $line{firstnamesuggestedby} = $$suggestion{firstnamesuggestedby}; + foreach my $key (qw(transferred_from transferred_to)) { + if ($line{$key}) { + my $order = GetOrder($line{$key}); + my $basket = GetBasket($order->{basketno}); + my $bookseller = GetBookSellerFromId($basket->{booksellerid}); + $line{$key} = { + order => $order, + basket => $basket, + bookseller => $bookseller, + timestamp => $line{$key . '_timestamp'}, + }; + } + } + return \%line; }