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

(-)a/Koha/Item.pm (-3 / +12 lines)
Lines 259-272 sub delete { Link Here
259
    my $self = shift;
259
    my $self = shift;
260
    my $params = @_ ? shift : {};
260
    my $params = @_ ? shift : {};
261
261
262
    # FIXME check the item has no current issues
263
    # i.e. raise the appropriate exception
264
265
    # Get the item group so we can delete it later if it has no items left
262
    # Get the item group so we can delete it later if it has no items left
266
    my $item_group = C4::Context->preference('EnableItemGroups') ? $self->item_group : undef;
263
    my $item_group = C4::Context->preference('EnableItemGroups') ? $self->item_group : undef;
267
264
265
    my $serial_item = $self->serial_item;
266
268
    my $result = $self->SUPER::delete;
267
    my $result = $self->SUPER::delete;
269
268
269
    # Delete the serial linked to the item if required
270
    if ( $result && $params->{delete_serial_issues} ) {
271
        if ($serial_item) {
272
            my $serial = Koha::Serials->find( $serial_item->serialid );
273
            # The serial_item is deleted by cascade when the item is deleted
274
            # so we don't need to delete it here
275
            $serial->delete;
276
        }
277
    }
278
270
    # Delete the item group if it has no items left
279
    # Delete the item group if it has no items left
271
    $item_group->delete if ( $item_group && $item_group->items->count == 0 );
280
    $item_group->delete if ( $item_group && $item_group->items->count == 0 );
272
281
(-)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 146-153 Link Here
146
                                            <input type="hidden" name="biblionumber" value="[% item.biblionumber | html %]" />
147
                                            <input type="hidden" name="biblionumber" value="[% item.biblionumber | html %]" />
147
                                            <input type="hidden" name="itemnumber" value="[% item.itemnumber | html %]" />
148
                                            <input type="hidden" name="itemnumber" value="[% item.itemnumber | html %]" />
148
                                            <input type="hidden" name="searchid" value="[% searchid | html %]" />
149
                                            <input type="hidden" name="searchid" value="[% searchid | html %]" />
150
                                            <input type="hidden" name="delete-serial-issues" id="[% item.itemnumber | html %]-delete-serial-issues" value="" />
149
                                        </form>
151
                                        </form>
150
                                        <a class="dropdown-item delete" data-item="[% item.itemnumber | html %]" href="#">Delete</a>
152
                                        <a class="dropdown-item delete" data-itemnumber="[% item.itemnumber | html %]" data-has-serial-item="[% Item.HasSerialItem(item.itemnumber) | html %]" href="#">Delete</a>
151
                                    </li>
153
                                    </li>
152
                                [% END %]
154
                                [% END %]
153
                            [% END %]
155
                            [% END %]
Lines 386-391 Link Here
386
    </form>
388
    </form>
387
389
388
    [% INCLUDE 'modals/cataloguing_create_av.inc' %]
390
    [% INCLUDE 'modals/cataloguing_create_av.inc' %]
391
    [% INCLUDE 'modals/delete_item_confirmation.inc' %]
389
392
390
                            </div> <!-- /#cataloguing_additem_newitem -->
393
                            </div> <!-- /#cataloguing_additem_newitem -->
391
                        </div> <!-- /.col-sm-10 -->
394
                        </div> <!-- /.col-sm-10 -->
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js (-4 / +20 lines)
Lines 134-143 $(document).ready(function(){ Link Here
134
134
135
    $(document).on('click', '.delete', function(e) {
135
    $(document).on('click', '.delete', function(e) {
136
        e.preventDefault();
136
        e.preventDefault();
137
        if (confirmDelete(MSG_CONFIRM_DELETE_ITEM)) {
137
        var itemnumber = $(this).data('itemnumber');
138
            return $("#" + $(this).data("item") + "-delete-item-form").submit();
138
        var hasSerialItem = $(this).data('has-serial-item');
139
140
        $('#delete-item-itemnumber').val(itemnumber);
141
        $('#delete_associated_serial_issues').attr('checked', false);
142
        $('#delete-item-modal-btn-submit').data("item", itemnumber);
143
        if(!hasSerialItem) {
144
            $('.form-group').hide()
139
        }
145
        }
140
    }) ;
146
        $('#delete-item-modal').modal('show');
147
    });
148
    $(document).on('click', '#delete-item-modal-btn-submit', function(e) {
149
        e.preventDefault();
150
        var itemnumber = $('#delete-item-itemnumber').val();
151
        var deleteSerialIssues = $('#delete_associated_serial_issues').prop('checked') ? true : false;
152
        $('#delete-item-modal').modal('hide');
153
        if(deleteSerialIssues) {
154
            $('#' + itemnumber + '-delete-serial-issues').val('1');
155
        }
156
        return $("#" + $(this).data("item") + "-delete-item-form").submit();
157
    });
141
});
158
});
142
159
143
function CheckTemplateForm(f) {
160
function CheckTemplateForm(f) {
144
- 

Return to bug 37115