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

(-)a/C4/Acquisition.pm (-5 / +42 lines)
Lines 1759-1779 cancelled. Link Here
1759
=cut
1759
=cut
1760
1760
1761
sub DelOrder {
1761
sub DelOrder {
1762
    my ( $bibnum, $ordernumber ) = @_;
1762
    my ( $bibnum, $ordernumber, $delete_biblio, $reason ) = @_;
1763
1764
    my $error;
1763
    my $dbh = C4::Context->dbh;
1765
    my $dbh = C4::Context->dbh;
1764
    my $query = "
1766
    my $query = "
1765
        UPDATE aqorders
1767
        UPDATE aqorders
1766
        SET    datecancellationprinted=now(), orderstatus='cancelled'
1768
        SET    datecancellationprinted=now(), orderstatus='cancelled'
1767
        WHERE  biblionumber=? AND ordernumber=?
1769
    ";
1770
    if($reason) {
1771
        $query .= "
1772
            , notes = IF(notes IS NULL,
1773
                CONCAT('Cancellation reason: ', ?),
1774
                CONCAT(notes, ' - Cancellation reason: ', ?)
1775
            )
1776
        ";
1777
    }
1778
    $query .= "
1779
        WHERE biblionumber=? AND ordernumber=?
1768
    ";
1780
    ";
1769
    my $sth = $dbh->prepare($query);
1781
    my $sth = $dbh->prepare($query);
1770
    $sth->execute( $bibnum, $ordernumber );
1782
    if($reason) {
1783
        $sth->execute($reason, $reason, $bibnum, $ordernumber);
1784
    } else {
1785
        $sth->execute( $bibnum, $ordernumber );
1786
    }
1771
    $sth->finish;
1787
    $sth->finish;
1788
1772
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1789
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1773
    foreach my $itemnumber (@itemnumbers){
1790
    foreach my $itemnumber (@itemnumbers){
1774
    	C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
1791
        my $delcheck = C4::Items::DelItemCheck( $dbh, $bibnum, $itemnumber );
1792
1793
        if($delcheck != 1) {
1794
            $error->{'delitem'} = 1;
1795
        }
1775
    }
1796
    }
1776
    
1797
1798
    if($delete_biblio) {
1799
        # We get the number of remaining items
1800
        my $itemcount = C4::Items::GetItemsCount($bibnum);
1801
1802
        # If there are no items left,
1803
        if ( $itemcount == 0 ) {
1804
            # We delete the record
1805
            my $delcheck = DelBiblio($bibnum);
1806
1807
            if($delcheck) {
1808
                $error->{'delbiblio'} = 1;
1809
            }
1810
        }
1811
    }
1812
1813
    return $error;
1777
}
1814
}
1778
1815
1779
=head3 TransferOrder
1816
=head3 TransferOrder
(-)a/acqui/addorder.pl (-12 / +3 lines)
Lines 123-129 use strict; Link Here
123
use warnings;
123
use warnings;
124
use CGI;
124
use CGI;
125
use C4::Auth;			# get_template_and_user
125
use C4::Auth;			# get_template_and_user
126
use C4::Acquisition;	# NewOrder DelOrder ModOrder
126
use C4::Acquisition;	# NewOrder ModOrder
127
use C4::Suggestions;	# ModStatus
127
use C4::Suggestions;	# ModStatus
128
use C4::Biblio;			# AddBiblio TransformKohaToMarc
128
use C4::Biblio;			# AddBiblio TransformKohaToMarc
129
use C4::Budgets;
129
use C4::Budgets;
Lines 230-239 $orderinfo->{subscriptionid} ||= undef; Link Here
230
my $user = $input->remote_user;
230
my $user = $input->remote_user;
231
231
232
# create, modify or delete biblio
232
# create, modify or delete biblio
233
# create if $quantity>=0 and $existing='no'
233
# create if $quantity>0 and $existing='no'
234
# modify if $quantity>=0 and $existing='yes'
234
# modify if $quantity>0 and $existing='yes'
235
# delete if $quantity has been set to 0 by the librarian
236
# delete biblio if delbiblio has been set to 1 by the librarian
237
if ( $orderinfo->{quantity} ne '0' ) {
235
if ( $orderinfo->{quantity} ne '0' ) {
238
    #TODO:check to see if biblio exists
236
    #TODO:check to see if biblio exists
239
    unless ( $$orderinfo{biblionumber} ) {
237
    unless ( $$orderinfo{biblionumber} ) {
Lines 321-333 if ( $orderinfo->{quantity} ne '0' ) { Link Here
321
319
322
}
320
}
323
321
324
else { # qty=0, delete the line
325
    my $biblionumber = $input->param('biblionumber');
326
    DelOrder( $biblionumber, $$orderinfo{ordernumber} );
327
    if ($orderinfo->{delbiblio} == 1){
328
     DelBiblio($biblionumber);
329
    }
330
}
331
my $basketno=$$orderinfo{basketno};
322
my $basketno=$$orderinfo{basketno};
332
my $booksellerid=$$orderinfo{booksellerid};
323
my $booksellerid=$$orderinfo{booksellerid};
333
if (my $import_batch_id=$$orderinfo{import_batch_id}) {
324
if (my $import_batch_id=$$orderinfo{import_batch_id}) {
(-)a/acqui/cancelorder.pl (+79 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 BibLibre SARL
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it under the
7
# terms of the GNU General Public License as published by the Free Software
8
# Foundation; either version 2 of the License, or (at your option) any later
9
# version.
10
#
11
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along
16
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
=head1 NAME
20
21
cancelorder.pl
22
23
=head1 DESCRIPTION
24
25
Ask confirmation for cancelling an order line
26
and add possibility to indicate a reason for cancellation
27
(saved in aqorders.notes)
28
29
=cut
30
31
use Modern::Perl;
32
33
use CGI;
34
use C4::Auth;
35
use C4::Output;
36
# FIXME: C4::Search is needed by C4::Items::GetAnalyticsCount, which is called
37
# by C4::Acquisition::DelOrder. But C4::Search is not imported by C4::Items.
38
# Once this problem is resolved, the following line can be removed.
39
# See Bug 7847.
40
use C4::Search;
41
use C4::Acquisition;
42
43
my $input = new CGI;
44
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
45
    template_name   => 'acqui/cancelorder.tt',
46
    query           => $input,
47
    type            => 'intranet',
48
    authnotrequired => 0,
49
    flagsrequired   => { 'acquisition' => 'order_manage' },
50
    debug           => 1,
51
} );
52
53
my $action = $input->param('action');
54
my $ordernumber = $input->param('ordernumber');
55
my $biblionumber = $input->param('biblionumber');
56
my $referrer = $input->param('referrer') || $input->referer;
57
my $del_biblio = $input->param('del_biblio') ? 1 : 0;
58
59
if($action and $action eq "confirmcancel") {
60
    my $reason = $input->param('reason');
61
    my $error = DelOrder($biblionumber, $ordernumber, $del_biblio, $reason);
62
63
    if($error) {
64
        $template->param(error_delitem => 1) if $error->{'delitem'};
65
        $template->param(error_delbiblio => 1) if $error->{'delbiblio'};
66
    } else {
67
        $template->param(success_cancelorder => 1);
68
    }
69
    $template->param(confirmcancel => 1);
70
}
71
72
$template->param(
73
    ordernumber => $ordernumber,
74
    biblionumber => $biblionumber,
75
    referrer => $referrer,
76
    del_biblio => $del_biblio,
77
);
78
79
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt (-15 / +2 lines)
Lines 49-67 Link Here
49
                    window.location = "[% script_name %]?op=delete_confirm&basketno=[% basketno %]&booksellerid=[% booksellerid %]";
49
                    window.location = "[% script_name %]?op=delete_confirm&basketno=[% basketno %]&booksellerid=[% booksellerid %]";
50
                }
50
                }
51
            }
51
            }
52
            function confirm_delete_item(ordernumber, biblionumber) {
53
                var is_confirmed = confirm(_("Are you sure you want to delete this order ?"));
54
                if (is_confirmed) {
55
                    window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno=[% basketno %]&quantity=0&biblionumber="+biblionumber;
56
                }
57
            }
58
59
            function confirm_delete_biblio(ordernumber, biblionumber) {
60
                var is_confirmed = confirm(_("Are you sure you want to delete this catalog record and order ?"));
61
                if (is_confirmed) {
62
                    window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno=[% basketno %]&quantity=0&biblionumber="+biblionumber+"&delbiblio=1";
63
                    }
64
            }
65
52
66
            function transfer_order_popup(ordernumber) {
53
            function transfer_order_popup(ordernumber) {
67
                var url = "/cgi-bin/koha/acqui/transferorder.pl?"
54
                var url = "/cgi-bin/koha/acqui/transferorder.pl?"
Lines 475-484 Link Here
475
                            [% IF ( books_loo.left_holds_on_order ) %]
462
                            [% IF ( books_loo.left_holds_on_order ) %]
476
                            <span class="button" title="Can't delete order, ([% books_loo.holds_on_order %]) holds are linked with this order cancel holds first">Can't delete order</span><br>
463
                            <span class="button" title="Can't delete order, ([% books_loo.holds_on_order %]) holds are linked with this order cancel holds first">Can't delete order</span><br>
477
                            [% ELSE %]
464
                            [% ELSE %]
478
                            <a href="javascript:confirm_delete_item([% books_loo.ordernumber %],[% books_loo.biblionumber %])" class="button">Delete order</a><br>
465
                            <a href="/cgi-bin/koha/acqui/cancelorder.pl?ordernumber=[% books_loo.ordernumber %]&biblionumber=[% books_loo.biblionumber %]&referrer=/cgi-bin/koha/acqui/basket.pl%3Fbasketno=[% basketno %]" class="button">Delete order</a><br>
479
                            [% END %]
466
                            [% END %]
480
                            [% IF ( books_loo.can_del_bib ) %]
467
                            [% IF ( books_loo.can_del_bib ) %]
481
                            <a href="javascript:confirm_delete_biblio([% books_loo.ordernumber %],[% books_loo.biblionumber %])" class="button">Delete order and catalog record</a><br>
468
                            <a href="/cgi-bin/koha/acqui/cancelorder.pl?ordernumber=[% books_loo.ordernumber %]&biblionumber=[% books_loo.biblionumber %]&del_biblio=1&referrer=/cgi-bin/koha/acqui/basket.pl%3Fbasketno=[% basketno %]" class="button">Delete order and catalog record</a><br>
482
                            [% ELSE %]
469
                            [% ELSE %]
483
                            <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
470
                            <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
484
                            [% END %]
471
                            [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/cancelorder.tt (+62 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Acquisition &rsaquo; Cancel order</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
</head>
5
6
<body>
7
[% INCLUDE 'header.inc' %]
8
9
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisition</a> &rsaquo; Cancel order</div>
10
11
<div id="doc3" class="yui-t2">
12
13
<div id="bd">
14
  <div id="yui-main">
15
    <div class="yui-b">
16
      [% UNLESS ( confirmcancel ) %]
17
      <form method="post" action="">
18
        <div class="dialog alert">
19
          <h3>Are you sure you want to cancel this order ([% ordernumber %])</h3>
20
          <p>
21
            [% IF (del_biblio) %]
22
              Bibliographic record will be deleted too.
23
            [% ELSE %]
24
              Bibliographic record will not be deleted.
25
            [% END %]
26
          </p>
27
          <p>
28
            <textarea name="reason" placeholder="Reason of cancellation"></textarea>
29
          </p>
30
          <input type="hidden" name="action" value="confirmcancel" />
31
          <input type="hidden" value="[% ordernumber %]" name="ordernumber" />
32
          <input type="hidden" value="[% biblionumber %]" name="biblionumber" />
33
          <input type="hidden" value="[% referrer %]" name="referrer" />
34
          [% IF (del_biblio) %]
35
            <input type="hidden" value="1" name="del_biblio" />
36
          [% END %]
37
          <input type="submit" class="approve" value="Yes, Cancel (Y)" accesskey="y" />
38
          <input type="submit" class="deny" value="No, Don't Cancel (N)" accesskey="n" onclick="window.location='[% referrer %]';return false;" />
39
        </div>
40
      </form>
41
      [% ELSE %]
42
        [% IF ( success_cancelorder ) %]
43
            <div class="dialog message">
44
                The order has been successfully canceled
45
        [% ELSE %]
46
            <div class="dialog alert">
47
                An error has occured.
48
                [% IF ( error_delitem ) %]
49
                    <p>The order has been canceled, although one or more items could not have been deleted.</p>
50
                [% END %]
51
                [% IF ( error_delbiblio ) %]
52
                <p>The order has been canceled, although the record has not been deleted.</p>
53
                [% END %]
54
        [% END %]
55
                <p>Click <a href="[% referrer %]">here</a> to return to previous page</p>
56
            </div>
57
      [% END %]
58
59
    </div>
60
  </div>
61
</div>
62
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt (-17 / +2 lines)
Lines 94-113 Link Here
94
</script>
94
</script>
95
<script type="text/javascript">
95
<script type="text/javascript">
96
//<![CDATA[
96
//<![CDATA[
97
            function confirm_delete_item(ordernumber, basketno, biblionumber) {
98
                var is_confirmed = confirm(_("Are you sure you want to delete this order ?"));
99
                if (is_confirmed) {
100
                    window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno="+basketno+"&quantity=0&biblionumber="+biblionumber+"&invoiceid=[% invoiceid %]";
101
                }
102
            }
103
            
104
            function confirm_delete_biblio(ordernumber, basketno, biblionumber) {
105
                var is_confirmed = confirm(_("Are you sure you want to delete this catalog record and order ?"));
106
                if (is_confirmed) {
107
                    window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno="+basketno+"&quantity=0&biblionumber="+biblionumber+"&delbiblio=1&invoiceid=[% invoiceid %]";
108
                    }
109
            }
110
111
            function transfer_order_popup(ordernumber) {
97
            function transfer_order_popup(ordernumber) {
112
                var url = "/cgi-bin/koha/acqui/transferorder.pl?"
98
                var url = "/cgi-bin/koha/acqui/transferorder.pl?"
113
                    + "ordernumber=" + ordernumber
99
                    + "ordernumber=" + ordernumber
Lines 263-272 Link Here
263
                        [% IF ( loop_order.left_holds_on_order ) %]
249
                        [% IF ( loop_order.left_holds_on_order ) %]
264
                        <span class="button" title="Can't delete order, ([% loop_order.holds_on_order %]) holds are linked with this order cancel holds first">Can't delete order</span><br>
250
                        <span class="button" title="Can't delete order, ([% loop_order.holds_on_order %]) holds are linked with this order cancel holds first">Can't delete order</span><br>
265
                        [% ELSE %]
251
                        [% ELSE %]
266
                        <a href="javascript:confirm_delete_item([% loop_order.ordernumber %], [% loop_order.basketno %], [% loop_order.biblionumber %])" class="button">Delete order</a><br>
252
                        <a href="/cgi-bin/koha/acqui/cancelorder.pl?ordernumber=[% loop_order.ordernumber %]&biblionumber=[% loop_order.biblionumber %]&referrer=[% "/cgi-bin/koha/acqui/parcel.pl?booksellerid=$booksellerid&datereceived=$datereceived&invoice=$invoice" | uri %]">Delete order</a><br />
267
                        [% END %]
253
                        [% END %]
268
                        [% IF ( loop_order.can_del_bib ) %]
254
                        [% IF ( loop_order.can_del_bib ) %]
269
                        <a href="javascript:confirm_delete_biblio([% loop_order.ordernumber %], [% loop_order.basketno %], [% loop_order.biblionumber %])" class="button">Delete order and catalog record</a><br>
255
                        <a href="/cgi-bin/koha/acqui/cancelorder.pl?ordernumber=[% loop_order.ordernumber %]&biblionumber=[% loop_order.biblionumber %]&del_biblio=1&referrer=[% "/cgi-bin/koha/acqui/parcel.pl?booksellerid=$booksellerid&datereceived=$datereceived&invoice=$invoice" | uri %]">Delete order and catalog record</a><br />
270
                        [% ELSE %]
256
                        [% ELSE %]
271
                        <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
257
                        <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
272
                        [% END %]
258
                        [% END %]
273
- 

Return to bug 7162