Koha/admin/currency.pl
Jonathan Druart 3aeb1fc7e8 Bug 19256: Make Koha::Acq::Order using Koha::Object
At the moment we have 2 different modules for acquisition orders:
Koha::Tmp::Order[s] and Koha::Acquisition::Order
The later has been added before the creation of Koha::Object.
Koha::Tmp::Order[s] has been created to make the TT syntax for notices
works with acquisition order data.

This patch removes the temporary packages Koha::Tmp::Order[s] and adapt
the code of Koha::Acquisition::Order[s] to be based on Koha::Object[s].

It also overloads Koha::Object->new to add the trick that was done in
Koha::Acquisition::Order->insert. This is needed because acqui/addorder.pl
is called from several places and CGI->Vars is used to retrieved order's
attributes (and so much more). To avoid regression, the easiest (but not
cleanest) way to do is to filter on aqorders column's names.
This is *not* a pattern to follow!

Test plan:
Create basket and add orders from different ways, then continue a whole
acquisition process

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-09-07 15:03:04 -03:00

131 lines
4.5 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2000-2002 Katipo Communications
# Copyright 2002 Paul Poulain
# Copyright Koha Development Team
#
# 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 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.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth;
use C4::Context;
use C4::Output;
use Koha::Acquisition::Booksellers;
use Koha::Acquisition::Currencies;
use Koha::Acquisition::Orders;
my $input = CGI->new;
my $searchfield = $input->param('searchfield') || $input->param('description') || q{};
my $currency_code = $input->param('currency_code');
my $op = $input->param('op') || 'list';
my @messages;
our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{ template_name => 'admin/currency.tt',
query => $input,
type => 'intranet',
authnotrequired => 0,
flagsrequired => { parameters => 'parameters_remaining_permissions' },
}
);
if ( $op eq 'add_form' ) {
my $currency;
if ($currency_code) {
$currency = Koha::Acquisition::Currencies->find($currency_code);
}
$template->param( currency => $currency, );
} elsif ( $op eq 'add_validate' ) {
my $currency_code = $input->param('currency_code');
my $symbol = $input->param('symbol');
my $isocode = $input->param('isocode');
my $rate = $input->param('rate');
my $active = $input->param('active');
my $is_a_modif = $input->param('is_a_modif');
if ($is_a_modif) {
my $currency = Koha::Acquisition::Currencies->find($currency_code);
$currency->symbol($symbol);
$currency->isocode($isocode);
$currency->rate($rate);
$currency->active($active);
eval { $currency->store; };
if ($@) {
push @messages, { type => 'error', code => 'error_on_update' };
} else {
push @messages, { type => 'message', code => 'success_on_update' };
}
} else {
my $currency = Koha::Acquisition::Currency->new(
{ currency => $currency_code,
symbol => $symbol,
isocode => $isocode,
rate => $rate,
active => $active,
}
);
eval { $currency->store; };
if ($@) {
push @messages, { type => 'error', code => 'error_on_insert' };
} else {
push @messages, { type => 'message', code => 'success_on_insert' };
}
}
$searchfield = q||;
$op = 'list';
} elsif ( $op eq 'delete_confirm' ) {
my $currency = Koha::Acquisition::Currencies->find($currency_code);
my $nb_of_orders = Koha::Acquisition::Orders->search( { currency => $currency->currency } )->count;
my $nb_of_vendors = Koha::Acquisition::Booksellers->search( { -or => { listprice => $currency->currency, invoiceprice => $currency->currency } })->count;
$template->param(
currency => $currency,
nb_of_orders => $nb_of_orders,
nb_of_vendors => $nb_of_vendors,
);
} elsif ( $op eq 'delete_confirmed' ) {
my $currency = Koha::Acquisition::Currencies->find($currency_code);
my $deleted = eval { $currency->delete; };
if ( $@ or not $deleted ) {
push @messages, { type => 'error', code => 'error_on_delete' };
} else {
push @messages, { type => 'message', code => 'success_on_delete' };
}
$op = 'list';
}
if ( $op eq 'list' ) {
$searchfield =~ s/\,//g;
my $currencies = Koha::Acquisition::Currencies->search( { currency => { -like => "$searchfield%" } } );
my $no_active_currency = not Koha::Acquisition::Currencies->search( { active => 1 } )->count;
$template->param(
currencies => $currencies,
no_active_currency => $no_active_currency,
);
}
$template->param(
searchfield => $searchfield,
messages => \@messages,
op => $op,
);
output_html_with_http_headers $input, $cookie, $template->output;