From d3faa9cc532630f7f2b0b2022579834d117ce5ed Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 14 Apr 2016 14:29:38 +0200 Subject: [PATCH] Bug 15962: Block the currency deletion if used MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit A currency should not be deleted if used by a vendor or a basket. Test plan: 1/ Add a new currency 2/ Create a vendor using this currency 3/ Create a basket using this currency 4/ Try to delete the currency 5/ Delete the basket 6/ Try to delete the currency 7/ Delete the vendor 8/ Delete the currency Signed-off-by: Julian Maurice (cherry picked from commit c20496aea938e1faaa53daff5e2cf3d697b0eac9) Signed-off-by: Frédéric Demians --- admin/currency.pl | 18 ++++++++++-------- .../prog/en/modules/admin/currency.tt | 11 +++++++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/admin/currency.pl b/admin/currency.pl index f62f761994..d0c4be32c0 100755 --- a/admin/currency.pl +++ b/admin/currency.pl @@ -132,21 +132,23 @@ sub delete_confirm { my $curr = shift; $template->param( delete_confirm => 1 ); - my $total_row = $dbh->selectrow_hashref( - 'select count(*) as total from aqbooksellers where currency=?', - {}, $curr ); + my ($nb_of_vendors) = $dbh->selectrow_array(q{ + select count(*) from aqbooksellers + where listprice = ? or invoiceprice = ? + }, {}, $curr, $curr); + my ($nb_of_orders) = $dbh->selectrow_array(q{ + select count(*) from aqorders + where currency = ? + }, {}, $curr); my $curr_ref = $dbh->selectrow_hashref( 'select currency,rate from currency where currency=?', {}, $curr ); - if ( $total_row->{total} ) { - $template->param( totalgtzero => 1 ); - } - $template->param( rate => $curr_ref->{rate}, - total => $total_row->{total} + nb_of_orders => $nb_of_orders, + nb_of_vendors => $nb_of_vendors, ); return; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt index 57c38cfde9..45ba3fd59e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt @@ -125,10 +125,17 @@ [% END %] [% IF ( delete_confirm ) %] - [% IF ( totalgtzero ) %] + [% IF ( nb_of_orders or nb_of_vendors ) %]

Cannot delete currency '[% searchfield %]'

-

This currency is used [% total %] times. Deletion not possible

+

+ [% IF nb_of_orders %] + This currency is used by [% nb_of_orders %] orders. + [% ELSIF nb_of_vendors %] + This currency is used by [% nb_of_vendors %] vendors. + [% END %] + Deletion not possible +

-- 2.39.5