Lines 137-148
if ( $op eq 'add_form' ) {
Link Here
|
137 |
|
137 |
|
138 |
$searchfield = ''; |
138 |
$searchfield = ''; |
139 |
$op = 'list'; |
139 |
$op = 'list'; |
140 |
} elsif ( $op eq 'delete_confirm' ) { |
|
|
141 |
|
140 |
|
142 |
my $total = Koha::ItemTypes->check_items_and_biblioitems($itemtype_code); |
141 |
} elsif ( $op eq 'delete_confirm' ) { |
143 |
|
142 |
|
144 |
if ($total) { |
143 |
my $context = C4::Context->new; |
145 |
push @messages, { type => 'error', code => 'cannot_be_deleted', total => $total }; |
144 |
my $schema = Koha::Database->new()->schema(); |
|
|
145 |
my $itemtotal = $schema->resultset('Item')->search({ 'itype' => $itemtype_code} ); |
146 |
my $bibliototal = $schema->resultset('Biblioitem')->search({ 'itemtype' => $itemtype_code} ); |
147 |
|
148 |
$itemtotal->count; |
149 |
$bibliototal->count; |
150 |
my $overalltotal = $itemtotal + $bibliototal; |
151 |
|
152 |
if ($overalltotal) { |
153 |
push @messages, { type => 'error', code => 'cannot_be_deleted', total => $overalltotal }; |
146 |
$op = 'list'; |
154 |
$op = 'list'; |
147 |
} else { |
155 |
} else { |
148 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
156 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
Lines 150-155
if ( $op eq 'add_form' ) {
Link Here
|
150 |
} |
158 |
} |
151 |
|
159 |
|
152 |
} elsif ( $op eq 'delete_confirmed' ) { |
160 |
} elsif ( $op eq 'delete_confirmed' ) { |
|
|
161 |
|
153 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
162 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
154 |
my $deleted = eval { $itemtype->delete }; |
163 |
my $deleted = eval { $itemtype->delete }; |
155 |
if ( $@ or not $deleted ) { |
164 |
if ( $@ or not $deleted ) { |
156 |
- |
|
|