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

(-)a/C4/Acquisition.pm (-5 / +42 lines)
Lines 1553-1573 cancelled. Link Here
1553
=cut
1553
=cut
1554
1554
1555
sub DelOrder {
1555
sub DelOrder {
1556
    my ( $bibnum, $ordernumber ) = @_;
1556
    my ( $bibnum, $ordernumber, $delete_biblio, $reason ) = @_;
1557
1558
    my $error;
1557
    my $dbh = C4::Context->dbh;
1559
    my $dbh = C4::Context->dbh;
1558
    my $query = "
1560
    my $query = "
1559
        UPDATE aqorders
1561
        UPDATE aqorders
1560
        SET    datecancellationprinted=now()
1562
        SET    datecancellationprinted=now()
1561
        WHERE  biblionumber=? AND ordernumber=?
1563
    ";
1564
    if($reason) {
1565
        $query .= "
1566
            , notes = IF(notes IS NULL,
1567
                CONCAT('Cancellation reason: ', ?),
1568
                CONCAT(notes, ' - Cancellation reason: ', ?)
1569
            )
1570
        ";
1571
    }
1572
    $query .= "
1573
        WHERE biblionumber=? AND ordernumber=?
1562
    ";
1574
    ";
1563
    my $sth = $dbh->prepare($query);
1575
    my $sth = $dbh->prepare($query);
1564
    $sth->execute( $bibnum, $ordernumber );
1576
    if($reason) {
1577
        $sth->execute($reason, $reason, $bibnum, $ordernumber);
1578
    } else {
1579
        $sth->execute( $bibnum, $ordernumber );
1580
    }
1565
    $sth->finish;
1581
    $sth->finish;
1582
1566
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1583
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1567
    foreach my $itemnumber (@itemnumbers){
1584
    foreach my $itemnumber (@itemnumbers){
1568
    	C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
1585
        my $delcheck = C4::Items::DelItemCheck( $dbh, $bibnum, $itemnumber );
1586
1587
        if($delcheck != 1) {
1588
            $error->{'delitem'} = 1;
1589
        }
1590
    }
1591
1592
    if($delete_biblio) {
1593
        # We get the number of remaining items
1594
        my $itemcount = C4::Items::GetItemsCount($bibnum);
1595
1596
        # If there are no items left,
1597
        if ( $itemcount == 0 ) {
1598
            # We delete the record
1599
            my $delcheck = DelBiblio($bibnum);
1600
1601
            if($delcheck) {
1602
                $error->{'delbiblio'} = 1;
1603
            }
1604
        }
1569
    }
1605
    }
1570
    
1606
1607
    return $error;
1571
}
1608
}
1572
1609
1573
=head2 FUNCTIONS ABOUT PARCELS
1610
=head2 FUNCTIONS ABOUT PARCELS
(-)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::Items;
129
use C4::Items;
Lines 157-166 $orderinfo->{'uncertainprice'} ||= 0; Link Here
157
my $user = $input->remote_user;
157
my $user = $input->remote_user;
158
158
159
# create, modify or delete biblio
159
# create, modify or delete biblio
160
# create if $quantity>=0 and $existing='no'
160
# create if $quantity>0 and $existing='no'
161
# modify if $quantity>=0 and $existing='yes'
161
# modify if $quantity>0 and $existing='yes'
162
# delete if $quantity has been set to 0 by the librarian
163
# delete biblio if delbiblio has been set to 1 by the librarian
164
my $bibitemnum;
162
my $bibitemnum;
165
if ( $orderinfo->{quantity} ne '0' ) {
163
if ( $orderinfo->{quantity} ne '0' ) {
166
    #TODO:check to see if biblio exists
164
    #TODO:check to see if biblio exists
Lines 250-262 if ( $orderinfo->{quantity} ne '0' ) { Link Here
250
248
251
}
249
}
252
250
253
else { # qty=0, delete the line
254
    my $biblionumber = $input->param('biblionumber');
255
    DelOrder( $biblionumber, $$orderinfo{ordernumber} );
256
    if ($orderinfo->{delbiblio} == 1){
257
     DelBiblio($biblionumber);
258
    }
259
}
260
my $basketno=$$orderinfo{basketno};
251
my $basketno=$$orderinfo{basketno};
261
my $booksellerid=$$orderinfo{booksellerid};
252
my $booksellerid=$$orderinfo{booksellerid};
262
if (my $import_batch_id=$$orderinfo{import_batch_id}) {
253
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 47-65 Link Here
47
                    window.location = "[% script_name %]?op=delete_confirm&basketno=[% basketno %]&booksellerid=[% booksellerid %]";
47
                    window.location = "[% script_name %]?op=delete_confirm&basketno=[% basketno %]&booksellerid=[% booksellerid %]";
48
                }
48
                }
49
            }
49
            }
50
            function confirm_delete_item(ordernumber, biblionumber) {
51
                var is_confirmed = confirm(_("Are you sure you want to delete this order ?"));
52
                if (is_confirmed) {
53
                    window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno=[% basketno %]&quantity=0&biblionumber="+biblionumber;
54
                }
55
            }
56
            
57
            function confirm_delete_biblio(ordernumber, biblionumber) {
58
                var is_confirmed = confirm(_("Are you sure you want to delete this catalog record and order ?"));
59
                if (is_confirmed) {
60
                    window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno=[% basketno %]&quantity=0&biblionumber="+biblionumber+"&delbiblio=1";
61
                    }
62
            }
63
50
64
//]]>
51
//]]>
65
</script>
52
</script>
Lines 382-391 Link Here
382
                            [% IF ( books_loo.left_holds_on_order ) %]
369
                            [% IF ( books_loo.left_holds_on_order ) %]
383
                            <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>
370
                            <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>
384
                            [% ELSE %]
371
                            [% ELSE %]
385
                            <a href="javascript:confirm_delete_item([% books_loo.ordernumber %],[% books_loo.biblionumber %])" class="button">Delete order</a><br>
372
                            <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>
386
                            [% END %]
373
                            [% END %]
387
                            [% IF ( books_loo.can_del_bib ) %]
374
                            [% IF ( books_loo.can_del_bib ) %]
388
                            <a href="javascript:confirm_delete_biblio([% books_loo.ordernumber %],[% books_loo.biblionumber %])" class="button">Delete order and catalog record</a><br>
375
                            <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>
389
                            [% ELSE %]
376
                            [% ELSE %]
390
                            <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
377
                            <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
391
                            [% END %]
378
                            [% 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 (-20 / +3 lines)
Lines 75-97 Link Here
75
75
76
//]]>
76
//]]>
77
</script>
77
</script>
78
<script type="text/javascript">
78
79
//<![CDATA[
80
            function confirm_delete_item(ordernumber, basketno, biblionumber) {
81
                var is_confirmed = confirm(_("Are you sure you want to delete this order ?"));
82
                if (is_confirmed) {
83
                    window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno="+basketno+"&quantity=0&biblionumber="+biblionumber+"&invoiceid=[% invoiceid %]";
84
                }
85
            }
86
            
87
            function confirm_delete_biblio(ordernumber, basketno, biblionumber) {
88
                var is_confirmed = confirm(_("Are you sure you want to delete this catalog record and order ?"));
89
                if (is_confirmed) {
90
                    window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno="+basketno+"&quantity=0&biblionumber="+biblionumber+"&delbiblio=1&invoiceid=[% invoiceid %]";
91
                    }
92
            }
93
//]]>
94
</script>
95
</head>
79
</head>
96
<body id="acq_parcel" class="acq">
80
<body id="acq_parcel" class="acq">
97
[% INCLUDE 'header.inc' %]
81
[% INCLUDE 'header.inc' %]
Lines 217-226 Link Here
217
                        [% IF ( loop_order.left_holds_on_order ) %]
201
                        [% IF ( loop_order.left_holds_on_order ) %]
218
                        <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>
202
                        <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>
219
                        [% ELSE %]
203
                        [% ELSE %]
220
                        <a href="javascript:confirm_delete_item([% loop_order.ordernumber %], [% loop_order.basketno %], [% loop_order.biblionumber %])" class="button">Delete order</a><br>
204
                        <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 />
221
                        [% END %]
205
                        [% END %]
222
                        [% IF ( loop_order.can_del_bib ) %]
206
                        [% IF ( loop_order.can_del_bib ) %]
223
                        <a href="javascript:confirm_delete_biblio([% loop_order.ordernumber %], [% loop_order.basketno %], [% loop_order.biblionumber %])" class="button">Delete order and catalog record</a><br>
207
                        <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 />
224
                        [% ELSE %]
208
                        [% ELSE %]
225
                        <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
209
                        <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
226
                        [% END %]
210
                        [% END %]
227
- 

Return to bug 7162