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

(-)a/C4/Acquisition.pm (-5 / +43 lines)
Lines 1837-1856 cancelled. Link Here
1837
=cut
1837
=cut
1838
1838
1839
sub DelOrder {
1839
sub DelOrder {
1840
    my ( $bibnum, $ordernumber ) = @_;
1840
    my ( $bibnum, $ordernumber, $delete_biblio, $reason ) = @_;
1841
1842
    my $error;
1841
    my $dbh = C4::Context->dbh;
1843
    my $dbh = C4::Context->dbh;
1842
    my $query = "
1844
    my $query = "
1843
        UPDATE aqorders
1845
        UPDATE aqorders
1844
        SET    datecancellationprinted=now(), orderstatus='cancelled'
1846
        SET    datecancellationprinted=now(), orderstatus='cancelled'
1845
        WHERE  biblionumber=? AND ordernumber=?
1847
    ";
1848
    if($reason) {
1849
        $query .= "
1850
            , notes = IF(notes IS NULL,
1851
                CONCAT('Cancellation reason: ', ?),
1852
                CONCAT(notes, ' - Cancellation reason: ', ?)
1853
            )
1854
        ";
1855
    }
1856
    $query .= "
1857
        WHERE biblionumber=? AND ordernumber=?
1846
    ";
1858
    ";
1847
    my $sth = $dbh->prepare($query);
1859
    my $sth = $dbh->prepare($query);
1848
    $sth->execute( $bibnum, $ordernumber );
1860
    if($reason) {
1861
        $sth->execute($reason, $reason, $bibnum, $ordernumber);
1862
    } else {
1863
        $sth->execute( $bibnum, $ordernumber );
1864
    }
1865
    $sth->finish;
1866
1849
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1867
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1850
    foreach my $itemnumber (@itemnumbers){
1868
    foreach my $itemnumber (@itemnumbers){
1851
        C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
1869
        my $delcheck = C4::Items::DelItemCheck( $dbh, $bibnum, $itemnumber );
1870
1871
        if($delcheck != 1) {
1872
            $error->{'delitem'} = 1;
1873
        }
1852
    }
1874
    }
1853
    return;
1875
1876
    if($delete_biblio) {
1877
        # We get the number of remaining items
1878
        my $itemcount = C4::Items::GetItemsCount($bibnum);
1879
1880
        # If there are no items left,
1881
        if ( $itemcount == 0 ) {
1882
            # We delete the record
1883
            my $delcheck = DelBiblio($bibnum);
1884
1885
            if($delcheck) {
1886
                $error->{'delbiblio'} = 1;
1887
            }
1888
        }
1889
    }
1890
1891
    return $error;
1854
}
1892
}
1855
1893
1856
=head3 TransferOrder
1894
=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 (-16 / +2 lines)
Lines 48-67 Link Here
48
                window.location = "[% script_name %]?op=delete_confirm&delbiblio="+delbiblio+"&basketno="+basketno+"&booksellerid="+booksellerid;
48
                window.location = "[% script_name %]?op=delete_confirm&delbiblio="+delbiblio+"&basketno="+basketno+"&booksellerid="+booksellerid;
49
            }
49
            }
50
50
51
            function confirm_delete_item(ordernumber, biblionumber) {
52
                var is_confirmed = confirm(_("Are you sure you want to delete this order ?"));
53
                if (is_confirmed) {
54
                    window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno=[% basketno %]&quantity=0&biblionumber="+biblionumber;
55
                }
56
            }
57
58
            function confirm_delete_biblio(ordernumber, biblionumber) {
59
                var is_confirmed = confirm(_("Are you sure you want to delete this catalog record and order ?"));
60
                if (is_confirmed) {
61
                    window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno=[% basketno %]&quantity=0&biblionumber="+biblionumber+"&delbiblio=1";
62
                    }
63
            }
64
65
            function transfer_order_popup(ordernumber) {
51
            function transfer_order_popup(ordernumber) {
66
                var url = "/cgi-bin/koha/acqui/transferorder.pl?"
52
                var url = "/cgi-bin/koha/acqui/transferorder.pl?"
67
                    + "ordernumber=" + ordernumber
53
                    + "ordernumber=" + ordernumber
Lines 539-548 Link Here
539
                            [% IF ( books_loo.left_holds_on_order ) %]
525
                            [% IF ( books_loo.left_holds_on_order ) %]
540
                            <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>
526
                            <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>
541
                            [% ELSE %]
527
                            [% ELSE %]
542
                            <a href="javascript:confirm_delete_item([% books_loo.ordernumber %],[% books_loo.biblionumber %])" class="button">Delete order</a><br>
528
                            <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>
543
                            [% END %]
529
                            [% END %]
544
                            [% IF ( books_loo.can_del_bib ) %]
530
                            [% IF ( books_loo.can_del_bib ) %]
545
                            <a href="javascript:confirm_delete_biblio([% books_loo.ordernumber %],[% books_loo.biblionumber %])" class="button">Delete order and catalog record</a><br>
531
                            <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>
546
                            [% ELSE %]
532
                            [% ELSE %]
547
                            <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
533
                            <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
548
                            [% END %]
534
                            [% 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 117-136 Link Here
117
</script>
117
</script>
118
<script type="text/javascript">
118
<script type="text/javascript">
119
//<![CDATA[
119
//<![CDATA[
120
            function confirm_delete_item(ordernumber, basketno, biblionumber) {
121
                var is_confirmed = confirm(_("Are you sure you want to delete this order ?"));
122
                if (is_confirmed) {
123
                    window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno="+basketno+"&quantity=0&biblionumber="+biblionumber+"&invoiceid=[% invoiceid %]";
124
                }
125
            }
126
            
127
            function confirm_delete_biblio(ordernumber, basketno, biblionumber) {
128
                var is_confirmed = confirm(_("Are you sure you want to delete this catalog record and order ?"));
129
                if (is_confirmed) {
130
                    window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno="+basketno+"&quantity=0&biblionumber="+biblionumber+"&delbiblio=1&invoiceid=[% invoiceid %]";
131
                    }
132
            }
133
134
            function transfer_order_popup(ordernumber) {
120
            function transfer_order_popup(ordernumber) {
135
                var url = "/cgi-bin/koha/acqui/transferorder.pl?"
121
                var url = "/cgi-bin/koha/acqui/transferorder.pl?"
136
                    + "ordernumber=" + ordernumber
122
                    + "ordernumber=" + ordernumber
Lines 300-309 Link Here
300
                        [% IF ( loop_order.left_holds_on_order ) %]
286
                        [% IF ( loop_order.left_holds_on_order ) %]
301
                        <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>
287
                        <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>
302
                        [% ELSE %]
288
                        [% ELSE %]
303
                        <a href="javascript:confirm_delete_item([% loop_order.ordernumber %], [% loop_order.basketno %], [% loop_order.biblionumber %])" class="button">Delete order</a><br>
289
                        <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 />
304
                        [% END %]
290
                        [% END %]
305
                        [% IF ( loop_order.can_del_bib ) %]
291
                        [% IF ( loop_order.can_del_bib ) %]
306
                        <a href="javascript:confirm_delete_biblio([% loop_order.ordernumber %], [% loop_order.basketno %], [% loop_order.biblionumber %])" class="button">Delete order and catalog record</a><br>
292
                        <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 />
307
                        [% ELSE %]
293
                        [% ELSE %]
308
                        <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
294
                        <span class="button" title="Can't delete catalog record, see constraints below">Can't delete order and catalog record</span><br>
309
                        [% END %]
295
                        [% END %]
310
- 

Return to bug 7162