X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Faqcontract.pl;h=e35b0570738e6a69a24209d7c53afa948bb7590e;hb=c6e488f4af72a2629fd86ee040a6973e2a6c73f4;hp=7126c9952f8331490140406076460d7c1e05b423;hpb=aef1dd15fbe37a8a9c30ba4b38f7ecd6c1fea54d;p=koha.git diff --git a/admin/aqcontract.pl b/admin/aqcontract.pl index 7126c9952f..e35b057073 100755 --- a/admin/aqcontract.pl +++ b/admin/aqcontract.pl @@ -7,38 +7,39 @@ # # 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., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use strict; use warnings; -use CGI; +use CGI qw ( -utf8 ); use C4::Context; use C4::Auth; use C4::Output; -use C4::Dates qw/format_date format_date_in_iso/; -use C4::Bookseller qw/GetBookSellerFromId/; use C4::Contract; +use Koha::DateUtils; + +use Koha::Acquisition::Booksellers; my $input = new CGI; my $contractnumber = $input->param('contractnumber'); my $booksellerid = $input->param('booksellerid'); -my $op = $input->param('op') || ''; +my $op = $input->param('op') || 'list'; -my $bookseller = GetBookSellerFromId($booksellerid); +my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { template_name => "admin/aqcontract.tmpl", + { template_name => "admin/aqcontract.tt", query => $input, type => "intranet", authnotrequired => 0, @@ -50,9 +51,10 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( $template->param( contractnumber => $contractnumber, booksellerid => $booksellerid, - booksellername => $bookseller->{name}, - DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), - dateformat => C4::Context->preference("dateformat"), + booksellername => $bookseller->name, + basketcount => $bookseller->baskets->count, + active => $bookseller->active, + subscriptioncount => $bookseller->subscriptions->count, ); #ADD_FORM: called if $op is 'add_form'. Used to create form to add or modify a record @@ -61,16 +63,16 @@ if ( $op eq 'add_form' ) { # if contractnumber exists, it's a modify action, so read values to modify... if ($contractnumber) { - my $contract = - @{ GetContract( { contractnumber => $contractnumber } ) }[0]; + my $contract = GetContract({ + contractnumber => $contractnumber + }); $template->param( contractnumber => $contract->{contractnumber}, contractname => $contract->{contractname}, contractdescription => $contract->{contractdescription}, - contractstartdate => format_date( $contract->{contractstartdate} ), - contractenddate => format_date( $contract->{contractenddate} ), - DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar, + contractstartdate => $contract->{contractstartdate}, + contractenddate => $contract->{contractenddate}, ); } else { $template->param( @@ -79,7 +81,6 @@ if ( $op eq 'add_form' ) { contractdescription => undef, contractstartdate => undef, contractenddate => undef, - DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar, ); } @@ -92,26 +93,34 @@ elsif ( $op eq 'add_validate' ) { my $is_a_modif = $input->param("is_a_modif"); + my $contractstart_dt = eval { dt_from_string( scalar $input->param('contractstartdate') ); }; + my $contractend_dt = eval { dt_from_string( scalar $input->param('contractenddate') ); }; + unless ( $contractstart_dt and $contractend_dt ) { + my $today = dt_from_string; + $contractstart_dt ||= $today; + $contractend_dt ||= $today; + } + if ( $is_a_modif ) { ModContract({ - contractstartdate => format_date_in_iso( $input->param('contractstartdate') ), - contractenddate => format_date_in_iso( $input->param('contractenddate') ), - contractname => $input->param('contractname'), - contractdescription => $input->param('contractdescription'), - booksellerid => $input->param('booksellerid'), - contractnumber => $input->param('contractnumber'), + contractstartdate => eval { output_pref({ dt => dt_from_string( $contractstart_dt ), dateformat => 'iso', dateonly => 1 } ); }, + contractenddate => eval { output_pref({ dt => dt_from_string( $contractend_dt ), dateformat => 'iso', dateonly => 1 } ); }, + contractname => scalar $input->param('contractname'), + contractdescription => scalar $input->param('contractdescription'), + booksellerid => scalar $input->param('booksellerid'), + contractnumber => scalar $input->param('contractnumber'), }); } else { AddContract({ - contractname => $input->param('contractname'), - contractdescription => $input->param('contractdescription'), - booksellerid => $input->param('booksellerid'), - contractstartdate => format_date_in_iso( $input->param('contractstartdate') ), - contractenddate => format_date_in_iso( $input->param('contractenddate') ), + contractname => scalar $input->param('contractname'), + contractdescription => scalar $input->param('contractdescription'), + booksellerid => scalar $input->param('booksellerid'), + contractstartdate => eval { output_pref({ dt => dt_from_string( scalar $input->param('contractstartdate') ), dateformat => 'iso', dateonly => 1 } ); }, + contractenddate => eval { output_pref({ dt => dt_from_string( scalar $input->param('contractenddate') ), dateformat => 'iso', dateonly => 1 } ); }, }); } - print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?supplierid=$booksellerid"); + print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?booksellerid=$booksellerid"); exit; # END $OP eq ADD_VALIDATE @@ -120,40 +129,43 @@ elsif ( $op eq 'add_validate' ) { elsif ( $op eq 'delete_confirm' ) { $template->param( delete_confirm => 1 ); - my $contract = @{GetContract( { contractnumber => $contractnumber } )}[0]; + my $contract = GetContract( { contractnumber => $contractnumber } ); $template->param( contractnumber => $$contract{contractnumber}, contractname => $$contract{contractname}, contractdescription => $$contract{contractdescription}, - contractstartdate => format_date( $$contract{contractstartdate} ), - contractenddate => format_date( $$contract{contractenddate} ), + contractstartdate => $$contract{contractstartdate}, + contractenddate => $$contract{contractenddate}, ); # END $OP eq DELETE_CONFIRM } #DELETE_CONFIRMED: called by delete_confirm, used to effectively confirm deletion of data in DB elsif ( $op eq 'delete_confirmed' ) { - $template->param( delete_confirmed => 1 ); + my $deleted = DelContract( { contractnumber => $contractnumber } ); - DelContract( { contractnumber => $contractnumber } ); - - print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?supplierid=$booksellerid"); - exit; + if ( $deleted ) { + print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?booksellerid=$booksellerid"); + exit; + } else { + $template->param( error => 'not_deleted' ); + $op = 'list'; + } - # END $OP eq DELETE_CONFIRMED + # END $OP eq LIST } # DEFAULT: Builds a list of contracts and displays them -else { +if ( $op eq 'list' ) { $template->param(else => 1); # get contracts - my @contracts = @{GetContract( { booksellerid => $booksellerid } )}; + my @contracts = @{GetContracts( { booksellerid => $booksellerid } )}; # format dates - for ( @contracts ) { - $$_{contractstartdate} = format_date($$_{contractstartdate}); - $$_{contractenddate} = format_date($$_{contractenddate}); + for my $contract ( @contracts ) { + $contract->{contractstartdate} = output_pref({ dt => dt_from_string( $contract->{contractstartdate} ), dateonly => 1 }); + $contract->{contractenddate} = output_pref({ dt => dt_from_string( $contract->{contractenddate} ), dateonly => 1 }), } $template->param(loop => \@contracts);