X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=acqui%2Fbasketheader.pl;h=202f6b907959d1b72ef0c5bdf1aa8539680c5b49;hb=6d3136c7e893011bd7cdfd0b6415d20929b6a66b;hp=47f210e2f562abae40afb2a0c32c95782112b1f3;hpb=6247c38600da4effba9f847a7ae7c8f1d6d9563d;p=koha.git diff --git a/acqui/basketheader.pl b/acqui/basketheader.pl index 47f210e2f5..202f6b9079 100755 --- a/acqui/basketheader.pl +++ b/acqui/basketheader.pl @@ -7,18 +7,18 @@ # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along with -# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . =head1 NAME @@ -33,9 +33,9 @@ notes to the supplier, local notes, and the contractnumber, which identifies the =over 4 -=item supplierid +=item booksellerid -C<$supplierid> is the id of the supplier we add the basket to. +C<$booksellerid> is the id of the supplier we add the basket to. =item basketid @@ -45,20 +45,22 @@ If it exists, C<$basketno> is the basket we edit =cut -use strict; -use warnings; -use CGI; +use Modern::Perl; +use CGI qw ( -utf8 ); use C4::Context; use C4::Auth; use C4::Output; -use C4::Acquisition qw/GetBasket NewBasket GetContracts ModBasketHeader/; -use C4::Bookseller qw/GetBookSellerFromId/; +use C4::Acquisition qw/GetBasket NewBasket ModBasketHeader/; +use C4::Contract qw/GetContracts/; +use Koha::Acquisition::Booksellers; +use Koha::Acquisition::Baskets; +use Koha::AdditionalFields; my $input = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { - template_name => "acqui/basketheader.tmpl", + template_name => "acqui/basketheader.tt", query => $input, type => "intranet", authnotrequired => 0, @@ -68,12 +70,13 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( ); #parameters: -my $booksellerid; -$booksellerid = $input->param('booksellerid'); +my $booksellerid = $input->param('booksellerid'); my $basketno = $input->param('basketno'); my $basket; -my $op = $input ->param('op'); -my $is_an_edit= $input ->param('is_an_edit'); +my $op = $input->param('op'); +my $is_an_edit = $input->param('is_an_edit'); + +$template->param( available_additional_fields => [ Koha::AdditionalFields->search( { tablename => 'aqbasket' } ) ] ); if ( $op eq 'add_form' ) { my @contractloop; @@ -83,42 +86,101 @@ if ( $op eq 'add_form' ) { if (! $booksellerid) { $booksellerid=$basket->{'booksellerid'}; } - @contractloop = &GetContracts($booksellerid, 1); + my $contracts = GetContracts({ + booksellerid => $booksellerid, + activeonly => 1, + }); + + @contractloop = @$contracts; for (@contractloop) { if ( $basket->{'contractnumber'} eq $_->{'contractnumber'} ) { $_->{'selected'} = 1; } } $template->param( is_an_edit => 1); + $template->param( + additional_field_values => { map { + $_->field->id => $_->value + } Koha::Acquisition::Baskets->find($basketno)->additional_field_values->as_list }, + ); } else { #new basket my $basket; - push(@contractloop, &GetContracts($booksellerid, 1)); + my $contracts = GetContracts({ + booksellerid => $booksellerid, + activeonly => 1, + }); + push(@contractloop, @$contracts); } - my $bookseller = GetBookSellerFromId($booksellerid); + my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my $count = scalar @contractloop; if ( $count > 0) { $template->param(contractloop => \@contractloop, basketcontractnumber => $basket->{'contractnumber'}); } + my @booksellers = Koha::Acquisition::Booksellers->search( + undef, + { order_by => { -asc => 'name' } } ); + $template->param( add_form => 1, basketname => $basket->{'basketname'}, basketnote => $basket->{'note'}, basketbooksellernote => $basket->{'booksellernote'}, - booksellername => $bookseller->{'name'}, + booksellername => $bookseller->name, booksellerid => $booksellerid, - basketno => $basketno - ); + basketno => $basketno, + booksellers => \@booksellers, + is_standing => $basket->{is_standing}, + ); + + my $billingplace = $basket->{'billingplace'} || C4::Context->userenv->{"branch"}; + my $deliveryplace = $basket->{'deliveryplace'} || C4::Context->userenv->{"branch"}; + + $template->param( billingplace => $billingplace ); + $template->param( deliveryplace => $deliveryplace ); + #End Edit } elsif ( $op eq 'add_validate' ) { #we are confirming the changes, save the basket - my $basketno; if ( $is_an_edit ) { - $basketno = $input->param('basketno'); - ModBasketHeader($input->param('basketno'),$input->param('basketname'),$input->param('basketnote'),$input->param('basketbooksellernote'),$input->param('basketcontractnumber')); + ModBasketHeader( + $basketno, + scalar $input->param('basketname'), + scalar $input->param('basketnote'), + scalar $input->param('basketbooksellernote'), + scalar $input->param('basketcontractnumber') || undef, + scalar $input->param('basketbooksellerid'), + scalar $input->param('deliveryplace'), + scalar $input->param('billingplace'), + scalar $input->param('is_standing') ? 1 : undef, + scalar $input->param('create_items') + ); } else { #New basket - $basketno = NewBasket($booksellerid, $loggedinuser, $input->param('basketname'), $input->param('basketnote'), $input->param('basketbooksellernote'), $input->param('basketcontractnumber')); + $basketno = NewBasket( + $booksellerid, + $loggedinuser, + scalar $input->param('basketname'), + scalar $input->param('basketnote'), + scalar $input->param('basketbooksellernote'), + scalar $input->param('basketcontractnumber') || undef, + scalar $input->param('deliveryplace'), + scalar $input->param('billingplace'), + scalar $input->param('is_standing') ? 1 : undef, + scalar $input->param('create_items') + ); + } + + my @additional_fields; + my $basket_fields = Koha::AdditionalFields->search({ tablename => 'aqbasket' }); + while ( my $field = $basket_fields->next ) { + my $value = $input->param('additional_field_' . $field->id); + push @additional_fields, { + id => $field->id, + value => $value, + }; } + Koha::Acquisition::Baskets->find($basketno)->set_additional_fields(\@additional_fields); + print $input->redirect('basket.pl?basketno='.$basketno); exit 0; }