3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2002 Paul Poulain
5 # Copyright Koha Development Team
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
28 use Koha
::Acquisition
::Booksellers
;
29 use Koha
::Acquisition
::Currencies
;
30 use Koha
::Acquisition
::Orders
;
33 my $searchfield = $input->param('searchfield') || $input->param('description') || q{};
34 my $currency_code = $input->param('currency_code');
35 my $op = $input->param('op') || 'list';
38 our ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
39 { template_name
=> 'admin/currency.tt',
43 flagsrequired
=> { acquisition
=> 'currencies_manage' },
47 if ( $op eq 'add_form' ) {
50 $currency = Koha
::Acquisition
::Currencies
->find($currency_code);
53 $template->param( currency
=> $currency, );
54 } elsif ( $op eq 'add_validate' ) {
55 my $currency_code = $input->param('currency_code');
56 my $symbol = $input->param('symbol');
57 my $isocode = $input->param('isocode');
58 my $rate = $input->param('rate');
59 my $active = $input->param('active');
60 my $p_sep_by_space = $input->param('p_sep_by_space');
61 my $is_a_modif = $input->param('is_a_modif');
64 my $currency = Koha
::Acquisition
::Currencies
->find($currency_code);
65 $currency->symbol($symbol);
66 $currency->isocode($isocode);
67 $currency->rate($rate);
68 $currency->active($active);
69 $currency->p_sep_by_space($p_sep_by_space);
70 eval { $currency->store; };
72 push @messages, { type
=> 'error', code
=> 'error_on_update' };
74 push @messages, { type
=> 'message', code
=> 'success_on_update' };
77 my $currency = Koha
::Acquisition
::Currency
->new(
78 { currency
=> $currency_code,
83 p_sep_by_space
=> $p_sep_by_space,
86 eval { $currency->store; };
88 push @messages, { type
=> 'error', code
=> 'error_on_insert' };
90 push @messages, { type
=> 'message', code
=> 'success_on_insert' };
95 } elsif ( $op eq 'delete_confirm' ) {
96 my $currency = Koha
::Acquisition
::Currencies
->find($currency_code);
98 my $nb_of_orders = Koha
::Acquisition
::Orders
->search( { currency
=> $currency->currency } )->count;
99 my $nb_of_vendors = Koha
::Acquisition
::Booksellers
->search( { -or => { listprice
=> $currency->currency, invoiceprice
=> $currency->currency } })->count;
101 currency
=> $currency,
102 nb_of_orders
=> $nb_of_orders,
103 nb_of_vendors
=> $nb_of_vendors,
105 } elsif ( $op eq 'delete_confirmed' ) {
106 my $currency = Koha
::Acquisition
::Currencies
->find($currency_code);
107 my $deleted = eval { $currency->delete; };
109 if ( $@
or not $deleted ) {
110 push @messages, { type
=> 'error', code
=> 'error_on_delete' };
112 push @messages, { type
=> 'message', code
=> 'success_on_delete' };
117 if ( $op eq 'list' ) {
118 $searchfield =~ s/\,//g;
119 my $currencies = Koha
::Acquisition
::Currencies
->search( { currency
=> { -like
=> "$searchfield%" } } );
121 my $no_active_currency = not Koha
::Acquisition
::Currencies
->search( { active
=> 1 } )->count;
123 currencies
=> $currencies,
124 no_active_currency
=> $no_active_currency,
129 searchfield
=> $searchfield,
130 messages
=> \
@messages,
134 output_html_with_http_headers
$input, $cookie, $template->output;