X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;ds=sidebyside;f=acqui%2Finvoices.pl;h=5cf2e338aae099dcee195f357e4d73d0b7d21347;hb=7d31f77ae6d1f136c58e55fa06139ac366fc6b85;hp=44589ab22d3fef663867d614035e1c9d60d2563c;hpb=18c513d45020c00c5c95284d41529038bbe307ff;p=koha-ffzg.git diff --git a/acqui/invoices.pl b/acqui/invoices.pl index 44589ab22d..5cf2e338aa 100755 --- a/acqui/invoices.pl +++ b/acqui/invoices.pl @@ -3,18 +3,18 @@ # Copyright 2011 BibLibre SARL # 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 . =head1 NAME @@ -26,26 +26,25 @@ Search for invoices =cut -use strict; -use warnings; +use Modern::Perl; -use CGI; -use C4::Auth; -use C4::Output; +use CGI qw ( -utf8 ); +use C4::Auth qw( get_template_and_user ); +use C4::Output qw( output_html_with_http_headers ); -use C4::Acquisition; -use C4::Bookseller qw/GetBookSeller/; -use C4::Branch; +use C4::Acquisition qw( GetInvoices GetInvoice ); +use C4::Budgets qw( GetBudget GetBudgets CanUserUseBudget ); +use Koha::DateUtils qw( dt_from_string ); +use Koha::Acquisition::Booksellers; +use Koha::AdditionalFields; -my $input = new CGI; +my $input = CGI->new; my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( { - template_name => 'acqui/invoices.tmpl', + template_name => 'acqui/invoices.tt', query => $input, type => 'intranet', - authnotrequired => 0, flagsrequired => { 'acquisition' => '*' }, - debug => 1, } ); @@ -61,97 +60,104 @@ my $author = $input->param('author'); my $publisher = $input->param('publisher'); my $publicationyear = $input->param('publicationyear'); my $branch = $input->param('branch'); +my $message_id = $input->param('message_id'); my $op = $input->param('op'); -my @results_loop = (); -if ( $op and $op eq "do_search" ) { - my $shipmentdatefrom_iso = C4::Dates->new($shipmentdatefrom)->output("iso"); - my $shipmentdateto_iso = C4::Dates->new($shipmentdateto)->output("iso"); - my $billingdatefrom_iso = C4::Dates->new($billingdatefrom)->output("iso"); - my $billingdateto_iso = C4::Dates->new($billingdateto)->output("iso"); - my @invoices = GetInvoices( - invoicenumber => $invoicenumber, - supplierid => $supplierid, - shipmentdatefrom => $shipmentdatefrom_iso, - shipmentdateto => $shipmentdateto_iso, - billingdatefrom => $billingdatefrom_iso, - billingdateto => $billingdateto_iso, - isbneanissn => $isbneanissn, - title => $title, - author => $author, - publisher => $publisher, - publicationyear => $publicationyear, - branchcode => $branch - ); - foreach (@invoices) { - my %row = ( - invoiceid => $_->{invoiceid}, - billingdate => $_->{billingdate}, - invoicenumber => $_->{invoicenumber}, - suppliername => $_->{suppliername}, - booksellerid => $_->{booksellerid}, - receivedbiblios => $_->{receivedbiblios}, - receiveditems => $_->{receiveditems}, - subscriptionid => $_->{subscriptionid}, - closedate => $_->{closedate}, - ); - push @results_loop, \%row; +my @additional_fields = Koha::AdditionalFields->search( + { tablename => 'aqinvoices', + searchable => 1 + } +)->as_list; +my @additional_field_filters; +for my $field (@additional_fields) { + my $value = $input->param( 'additional_field_' . $field->id ); + if ( defined $value and $value ne '' ) { + push @additional_field_filters, + { id => $field->id, + value => $value, + }; } } +my $invoices = []; +if ( $op and $op eq 'do_search' ) { + @{$invoices} = GetInvoices( + invoicenumber => $invoicenumber, + supplierid => $supplierid, + shipmentdatefrom => $shipmentdatefrom, + shipmentdateto => $shipmentdateto, + billingdatefrom => $billingdatefrom, + billingdateto => $billingdateto, + isbneanissn => $isbneanissn, + title => $title, + author => $author, + publisher => $publisher, + publicationyear => $publicationyear, + branchcode => $branch, + message_id => $message_id, + additional_fields => \@additional_field_filters, + ); +} + +$template->param( + additional_field_filters => { map { $_->{id} => $_->{value} } @additional_field_filters }, + additional_fields_for_invoice => \@additional_fields, +); + # Build suppliers list -my @suppliers = GetBookSeller(undef); -my @suppliers_loop = (); +my @suppliers = Koha::Acquisition::Booksellers->search( undef, { order_by => { -asc => 'name' } } )->as_list; +my $suppliers_loop = []; my $suppliername; foreach (@suppliers) { my $selected = 0; - if ( $supplierid && $supplierid == $_->{'id'} ) { - $selected = 1; - $suppliername = $_->{'name'}; + if ($supplierid && $supplierid == $_->id ) { + $selected = 1; + $suppliername = $_->name; } - my %row = ( - suppliername => $_->{'name'}, - booksellerid => $_->{'id'}, + push @{$suppliers_loop}, + { + suppliername => $_->name, + booksellerid => $_->id, selected => $selected, - ); - push @suppliers_loop, \%row; + }; } -# Build branches list -my $branches = GetBranches(); -my @branches_loop = (); -my $branchname; -foreach ( sort keys %$branches ) { - my $selected = 0; - if ( $branch && $branch eq $_ ) { - $selected = 1; - $branchname = $branches->{$_}->{'branchname'}; +my $budgets = GetBudgets(); +my @budgets_loop; +foreach my $budget (@$budgets) { + push @budgets_loop, $budget if CanUserUseBudget( $loggedinuser, $budget, $flags ); +} + +my (@openedinvoices, @closedinvoices); +for my $sub ( @{$invoices} ) { + unless ( $sub->{closedate} ) { + push @openedinvoices, $sub + } else { + push @closedinvoices, $sub } - my %row = ( - branchcode => $_, - branchname => $branches->{$_}->{'branchname'}, - selected => $selected, - ); - push @branches_loop, \%row; } +$template->{'VARS'}->{'budgets_loop'} = \@budgets_loop; + $template->param( - do_search => ( $op and $op eq "do_search" ) ? 1 : 0, - results_loop => \@results_loop, - invoicenumber => $invoicenumber, - booksellerid => $supplierid, - suppliername => $suppliername, - billingdatefrom => $billingdatefrom, - billingdateto => $billingdateto, - isbneanissn => $isbneanissn, - title => $title, - author => $author, - publisher => $publisher, - publicationyear => $publicationyear, - branch => $branch, - branchname => $branchname, - suppliers_loop => \@suppliers_loop, - branches_loop => \@branches_loop, + openedinvoices => \@openedinvoices, + closedinvoices => \@closedinvoices, + do_search => ( $op and $op eq 'do_search' ) ? 1 : 0, + invoices => $invoices, + invoicenumber => $invoicenumber, + booksellerid => $supplierid, + suppliername => $suppliername, + shipmentdatefrom => $shipmentdatefrom, + shipmentdateto => $shipmentdateto, + billingdatefrom => $billingdatefrom, + billingdateto => $billingdateto, + isbneanissn => $isbneanissn, + title => $title, + author => $author, + publisher => $publisher, + publicationyear => $publicationyear, + branch => $branch, + suppliers_loop => $suppliers_loop, ); output_html_with_http_headers $input, $cookie, $template->output;