View | Details | Raw Unified | Return to bug 17944
Collapse All | Expand All

(-)a/Koha/ItemType.pm (+14 lines)
Lines 81-86 sub translated_descriptions { Link Here
81
    } @translated_descriptions ];
81
    } @translated_descriptions ];
82
}
82
}
83
83
84
85
=head3 get_items_and_biblioitems
86
87
=cut
88
89
sub get_items_and_biblioitems {
90
    my $itemtype_code = $_[1];
91
    my $schema = Koha::Database->new()->schema();
92
    my $itemtotal = $schema->resultset('Item')->search({ 'itype' => $itemtype_code})->count;
93
    my $bibliototal = $schema->resultset('Biblioitem')->search({ 'itemtype' => $itemtype_code})->count;
94
    my $overalltotal = $itemtotal + $bibliototal;
95
    return $overalltotal;
96
}
97
84
=head3 type
98
=head3 type
85
99
86
=cut
100
=cut
(-)a/admin/itemtypes.pl (-9 / +3 lines)
Lines 32-38 use C4::Context; Link Here
32
use C4::Auth;
32
use C4::Auth;
33
use C4::Output;
33
use C4::Output;
34
34
35
use Koha::ItemTypes;
35
use Koha::ItemType;
36
use Koha::Localizations;
36
use Koha::Localizations;
37
37
38
my $input         = new CGI;
38
my $input         = new CGI;
Lines 140-151 if ( $op eq 'add_form' ) { Link Here
140
140
141
 } elsif ( $op eq 'delete_confirm' ) {
141
 } elsif ( $op eq 'delete_confirm' ) {
142
142
143
    my $schema = Koha::Database->new()->schema();
143
    my $overalltotal = Koha::ItemType->get_items_and_biblioitems($itemtype_code);
144
    my $itemtotal = $schema->resultset('Item')->search({ 'itype' => $itemtype_code})->count;
145
    my $bibliototal = $schema->resultset('Biblioitem')->search({ 'itemtype' => $itemtype_code})->count;
146
147
    my $overalltotal = $itemtotal + $bibliototal;
148
149
    if ($overalltotal) {
144
    if ($overalltotal) {
150
        push @messages, { type => 'error', code => 'cannot_be_deleted', total => $overalltotal };
145
        push @messages, { type => 'error', code => 'cannot_be_deleted', total => $overalltotal };
151
        $op = 'list';
146
        $op = 'list';
Lines 156-162 if ( $op eq 'add_form' ) { Link Here
156
151
157
} elsif ( $op eq 'delete_confirmed' ) {
152
} elsif ( $op eq 'delete_confirmed' ) {
158
153
159
    my $itemtype = Koha::ItemTypes->find($itemtype_code);
154
    my $itemtype = Koha::ItemType->get_items_and_biblioitems($itemtype_code);
160
    my $deleted = eval { $itemtype->delete };
155
    my $deleted = eval { $itemtype->delete };
161
    if ( $@ or not $deleted ) {
156
    if ( $@ or not $deleted ) {
162
        push @messages, { type => 'error', code => 'error_on_delete' };
157
        push @messages, { type => 'error', code => 'error_on_delete' };
163
- 

Return to bug 17944