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

(-)a/Koha/Item.pm (-3 / +13 lines)
Lines 264-277 sub delete { Link Here
264
    my $self   = shift;
264
    my $self   = shift;
265
    my $params = @_ ? shift : {};
265
    my $params = @_ ? shift : {};
266
266
267
    # FIXME check the item has no current issues
268
    # i.e. raise the appropriate exception
269
270
    # Get the item group so we can delete it later if it has no items left
267
    # Get the item group so we can delete it later if it has no items left
271
    my $item_group = C4::Context->preference('EnableItemGroups') ? $self->item_group : undef;
268
    my $item_group = C4::Context->preference('EnableItemGroups') ? $self->item_group : undef;
272
269
270
    my $serial_item = $self->serial_item;
271
273
    my $result = $self->SUPER::delete;
272
    my $result = $self->SUPER::delete;
274
273
274
    # Delete the serial linked to the item if required
275
    if ( $result && $params->{delete_serial_issues} ) {
276
        if ($serial_item) {
277
            my $serial = Koha::Serials->find( $serial_item->serialid );
278
279
            # The serial_item is deleted by cascade when the item is deleted
280
            # so we don't need to delete it here
281
            $serial->delete;
282
        }
283
    }
284
275
    # Delete the item group if it has no items left
285
    # Delete the item group if it has no items left
276
    $item_group->delete if ( $item_group && $item_group->items->count == 0 );
286
    $item_group->delete if ( $item_group && $item_group->items->count == 0 );
277
287
(-)a/Koha/Template/Plugin/Item.pm (+43 lines)
Line 0 Link Here
1
package Koha::Template::Plugin::Item;
2
3
# Copyright PTFS EUROPE 2024
4
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Template::Plugin;
23
use base qw( Template::Plugin );
24
25
use Koha::Items;
26
27
=head1 METHODS
28
29
=head2 HasSerialItem
30
31
Checks whether a particular item has an associated serial item
32
33
=cut
34
35
sub HasSerialItem {
36
    my ( $self, $itemnumber ) = @_;
37
38
    my $serial_item = Koha::Items->find($itemnumber)->serial_item;
39
40
    return $serial_item ? 1 : 0;
41
}
42
43
1;
(-)a/cataloguing/additem.pl (-1 / +2 lines)
Lines 532-538 if ( $op eq "cud-additem" ) { Link Here
532
    my $item = Koha::Items->find($itemnumber);
532
    my $item = Koha::Items->find($itemnumber);
533
    my $deleted;
533
    my $deleted;
534
    if ($item) {
534
    if ($item) {
535
        $deleted = $item->safe_delete;
535
        my $delete_serial_issues = $input->param('delete-serial-issues');
536
        $deleted = $item->safe_delete( { delete_serial_issues => $delete_serial_issues } );
536
    } else {
537
    } else {
537
        $deleted = Koha::Result::Boolean->new(0)->add_message( { message => 'item_not_found' } );
538
        $deleted = Koha::Result::Boolean->new(0)->add_message( { message => 'item_not_found' } );
538
    }
539
    }
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/delete_item_confirmation.inc (+30 lines)
Line 0 Link Here
1
[% USE Item %]
2
3
<!-- delete_item_confirmation.inc -->
4
<!-- Item deletion confirmation dialog -->
5
<div class="modal fade" id="delete-item-modal" tabindex="-1" role="dialog" aria-labelledby="claims-returned-modal-label">
6
    <div class="modal-dialog" role="document">
7
        <div class="modal-content">
8
            <div class="modal-header">
9
                <h4 class="modal-title" id="delete-item-modal-label">Delete item</h4>
10
            </div>
11
            <div class="modal-body">
12
                <h5 style="margin-bottom: 15px;">Are you sure you want to delete this item?</h5>
13
14
                <div class="form-group">
15
                    <div class="checkbox">
16
                        <label for="delete_associated_serial_issues">
17
                            <input id="delete_associated_serial_issues" type="checkbox" value="1" />
18
                            Delete serial issues linked to item
19
                        </label>
20
                    </div>
21
                </div>
22
                <input type="hidden" id="delete-item-itemnumber" />
23
            </div>
24
            <div class="modal-footer">
25
                <button id="delete-item-modal-btn-submit" type="button" class="btn btn-primary"><i class="fa fa-exclamation-circle"></i> Delete item</button>
26
                <button class="btn btn-default deny cancel" href="#" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i> Cancel</button>
27
            </div>
28
        </div>
29
    </div>
30
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt (-1 / +4 lines)
Lines 4-9 Link Here
4
[% USE Branches %]
4
[% USE Branches %]
5
[% USE KohaDates %]
5
[% USE KohaDates %]
6
[% USE Price %]
6
[% USE Price %]
7
[% USE Item %]
7
[% USE TablesSettings %]
8
[% USE TablesSettings %]
8
[% PROCESS 'i18n.inc' %]
9
[% PROCESS 'i18n.inc' %]
9
[% INCLUDE 'doc-head-open.inc' %]
10
[% INCLUDE 'doc-head-open.inc' %]
Lines 183-190 Link Here
183
                                                                <input type="hidden" name="biblionumber" value="[% item.biblionumber | html %]" />
184
                                                                <input type="hidden" name="biblionumber" value="[% item.biblionumber | html %]" />
184
                                                                <input type="hidden" name="itemnumber" value="[% item.itemnumber | html %]" />
185
                                                                <input type="hidden" name="itemnumber" value="[% item.itemnumber | html %]" />
185
                                                                <input type="hidden" name="searchid" value="[% searchid | html %]" />
186
                                                                <input type="hidden" name="searchid" value="[% searchid | html %]" />
187
                                                                <input type="hidden" name="delete-serial-issues" id="[% item.itemnumber | html %]-delete-serial-issues" value="" />
186
                                                            </form>
188
                                                            </form>
187
                                                            <a class="dropdown-item delete" data-item="[% item.itemnumber | html %]" href="#">Delete</a>
189
                                                            <a class="dropdown-item delete" data-itemnumber="[% item.itemnumber | html %]" data-has-serial-item="[% Item.HasSerialItem(item.itemnumber) | html %]" href="#">Delete</a>
188
                                                        </li>
190
                                                        </li>
189
                                                    [% END %]
191
                                                    [% END %]
190
                                                [% END %]
192
                                                [% END %]
Lines 422-427 Link Here
422
                    </form>
424
                    </form>
423
425
424
                    [% INCLUDE 'modals/cataloguing_create_av.inc' %]
426
                    [% INCLUDE 'modals/cataloguing_create_av.inc' %]
427
                    [% INCLUDE 'modals/delete_item_confirmation.inc' %]
425
                </div>
428
                </div>
426
                <!-- /#cataloguing_additem_newitem -->
429
                <!-- /#cataloguing_additem_newitem -->
427
            </div>
430
            </div>
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js (-2 / +24 lines)
Lines 154-161 $(document).ready(function () { Link Here
154
    $(document).on("click", ".delete", function (e) {
154
    $(document).on("click", ".delete", function (e) {
155
        e.preventDefault();
155
        e.preventDefault();
156
        if (confirmDelete(MSG_CONFIRM_DELETE_ITEM)) {
156
        if (confirmDelete(MSG_CONFIRM_DELETE_ITEM)) {
157
            return $("#" + $(this).data("item") + "-delete-item-form").submit();
157
            var itemnumber = $(this).data("itemnumber");
158
            var hasSerialItem = $(this).data("has-serial-item");
159
160
            $("#delete-item-itemnumber").val(itemnumber);
161
            $("#delete_associated_serial_issues").attr("checked", false);
162
            $("#delete-item-modal-btn-submit").data("item", itemnumber);
163
            if (!hasSerialItem) {
164
                $(".form-group").hide();
165
            }
166
            $("#delete-item-modal").modal("show");
167
        }
168
    });
169
    $(document).on("click", "#delete-item-modal-btn-submit", function (e) {
170
        e.preventDefault();
171
        var itemnumber = $("#delete-item-itemnumber").val();
172
        var deleteSerialIssues = $("#delete_associated_serial_issues").prop(
173
            "checked"
174
        )
175
            ? true
176
            : false;
177
        $("#delete-item-modal").modal("hide");
178
        if (deleteSerialIssues) {
179
            $("#" + itemnumber + "-delete-serial-issues").val("1");
158
        }
180
        }
181
        return $("#" + $(this).data("item") + "-delete-item-form").submit();
159
    });
182
    });
160
183
161
    /* On page load, check for location.hash in the page URL */
184
    /* On page load, check for location.hash in the page URL */
162
- 

Return to bug 37115