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

(-)a/C4/Acquisition.pm (-1 / +72 lines)
Lines 55-61 BEGIN { Link Here
55
        &GetOrderNumber &GetLateOrders &GetOrderFromItemnumber
55
        &GetOrderNumber &GetLateOrders &GetOrderFromItemnumber
56
        &SearchOrder &GetHistory &GetRecentAcqui
56
        &SearchOrder &GetHistory &GetRecentAcqui
57
        &ModReceiveOrder &ModOrderBiblioitemNumber
57
        &ModReceiveOrder &ModOrderBiblioitemNumber
58
        &GetCancelledOrders
58
        &GetCancelledOrders &TransferOrder
59
59
60
        &NewOrderItem &ModOrderItem &ModItemOrder
60
        &NewOrderItem &ModOrderItem &ModItemOrder
61
61
Lines 1334-1339 sub DelOrder { Link Here
1334
    
1334
    
1335
}
1335
}
1336
1336
1337
=head3 TransferOrder
1338
1339
    my $newordernumber = TransferOrder($ordernumber, $basketno);
1340
1341
Transfer an order line to a basket.
1342
Mark $ordernumber as cancelled with an internal note 'Cancelled and transfered
1343
to BOOKSELLER on DATE' and create new order with internal note
1344
'Transfered from BOOKSELLER on DATE'.
1345
Move all attached items to the new order.
1346
Received orders cannot be transfered.
1347
Return the ordernumber of created order.
1348
1349
=cut
1350
1351
sub TransferOrder {
1352
    my ($ordernumber, $basketno) = @_;
1353
1354
    return unless $ordernumber or $basketno;
1355
1356
    my $order = GetOrder( $ordernumber );
1357
    return if $order->{datereceived};
1358
1359
    my $today = C4::Dates->new()->output("iso");
1360
    my $query = qq{
1361
        SELECT aqbooksellers.name
1362
        FROM aqorders
1363
            LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno
1364
            LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
1365
        WHERE aqorders.ordernumber = ?
1366
    };
1367
    my $dbh = C4::Context->dbh;
1368
    my $sth = $dbh->prepare($query);
1369
    $sth->execute($ordernumber);
1370
    my ($booksellerfromname) = $sth->fetchrow_array;
1371
1372
    $query = qq{
1373
        SELECT aqbooksellers.name
1374
        FROM aqbasket
1375
            LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
1376
        WHERE aqbasket.basketno = ?
1377
    };
1378
    $sth = $dbh->prepare($query);
1379
    $sth->execute($basketno);
1380
    my ($booksellertoname) = $sth->fetchrow_array;
1381
1382
    $query = qq{
1383
        UPDATE aqorders
1384
        SET datecancellationprinted = CAST(NOW() AS date),
1385
            internalnotes = ?
1386
        WHERE ordernumber = ?
1387
    };
1388
    $sth = $dbh->prepare($query);
1389
    $sth->execute("Cancelled and transfered to $booksellertoname on $today", $ordernumber);
1390
1391
    delete $order->{'ordernumber'};
1392
    $order->{'basketno'} = $basketno;
1393
    $order->{'internalnotes'} = "Transfered from $booksellerfromname on $today";
1394
    my $newordernumber;
1395
    (undef, $newordernumber) = NewOrder($order);
1396
1397
    $query = qq{
1398
        UPDATE aqorders_items
1399
        SET ordernumber = ?
1400
        WHERE ordernumber = ?
1401
    };
1402
    $sth = $dbh->prepare($query);
1403
    $sth->execute($newordernumber, $ordernumber);
1404
1405
    return $newordernumber;
1406
}
1407
1337
=head2 FUNCTIONS ABOUT PARCELS
1408
=head2 FUNCTIONS ABOUT PARCELS
1338
1409
1339
=cut
1410
=cut
(-)a/acqui/transferorder.pl (+145 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Script to move an order from a bookseller to another
4
5
# Copyright 2011 BibLibre SARL
6
#
7
# This file is part of Koha.
8
#
9
# Koha is free software; you can redistribute it and/or modify it under the
10
# terms of the GNU General Public License as published by the Free Software
11
# Foundation; either version 2 of the License, or (at your option) any later
12
# version.
13
#
14
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License along
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22
use Modern::Perl;
23
use CGI;
24
25
use C4::Auth;
26
use C4::Output;
27
use C4::Context;
28
use C4::Acquisition;
29
use C4::Bookseller qw/GetBookSellerFromId GetBookSeller/;
30
use C4::Members;
31
use C4::Dates qw/format_date_in_iso/;
32
use Date::Calc qw/Today/;
33
34
my $input = new CGI;
35
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
    {   template_name   => "acqui/transferorder.tmpl",
37
        query           => $input,
38
        type            => "intranet",
39
        authnotrequired => 1,
40
        flagsrequired   => { acquisition => 'order_manage' },
41
        debug           => 1,
42
    }
43
);
44
45
my $dbh = C4::Context->dbh;
46
47
my $bookselleridfrom    = $input->param('bookselleridfrom');
48
my $ordernumber     = $input->param('ordernumber');
49
my $bookselleridto  = $input->param('bookselleridto');
50
my $basketno        = $input->param('basketno');
51
my $op              = $input->param('op');
52
my $query           = $input->param('query');
53
54
my $order = GetOrder($ordernumber);
55
if($order) {
56
    my $basket = GetBasket($order->{basketno});
57
    $bookselleridfrom = $basket->{booksellerid} if $basket;
58
}
59
60
my $booksellerfrom = GetBookSellerFromId($bookselleridfrom);
61
my $booksellerfromname;
62
if($booksellerfrom){
63
    $booksellerfromname = $booksellerfrom->{name};
64
}
65
my $booksellerto = GetBookSellerFromId($bookselleridto);
66
my $booksellertoname;
67
if($booksellerto){
68
    $booksellertoname = $booksellerto->{name};
69
}
70
71
if( $basketno && $ordernumber) {
72
    # Transfer order and exit
73
    my $order = GetOrder( $ordernumber );
74
    my $basket = GetBasket($order->{basketno});
75
    my $booksellerfrom = GetBookSellerFromId($basket->{booksellerid});
76
    my $bookselleridfrom = $booksellerfrom->{id};
77
78
    TransferOrder($ordernumber, $basketno);
79
80
    my $referrer = $input->param('referrer');
81
    print $input->redirect($referrer);
82
    exit;
83
} elsif ( $bookselleridto && $ordernumber) {
84
    # Show open baskets for this bookseller
85
    my $order = GetOrder( $ordernumber );
86
    my $basketfrom = GetBasket( $order->{basketno} );
87
    my $booksellerfrom = GetBookSellerFromId( $basketfrom->{booksellerid} );
88
    $booksellerfromname = $booksellerfrom->{name};
89
    my $baskets = GetBasketsByBookseller( $bookselleridto );
90
    my $basketscount = scalar @$baskets;
91
    my @basketsloop = ();
92
    for( my $i = 0 ; $i < $basketscount ; $i++ ){
93
        my %line;
94
        %line = %{ $baskets->[$i] };
95
        my $createdby = GetMember(borrowernumber => $line{authorisedby});
96
        $line{createdby} = "$createdby->{surname}, $createdby->{firstname}";
97
        push @basketsloop, \%line unless $line{closedate};
98
    }
99
    $template->param(
100
        show_baskets => 1,
101
        basketsloop => \@basketsloop,
102
        basketfromname => $basketfrom->{basketname},
103
    );
104
} elsif ( $bookselleridfrom && !defined $ordernumber) {
105
    # Show pending orders
106
    my $pendingorders = GetPendingOrders($bookselleridfrom);
107
    my $orderscount = scalar @$pendingorders;
108
    my @ordersloop = ();
109
    for( my $i = 0 ; $i < $orderscount ; $i++ ){
110
        my %line;
111
        %line = %{ $pendingorders->[$i] };
112
        push @ordersloop, \%line;
113
    }
114
    $template->param(
115
        ordersloop  => \@ordersloop,
116
    );
117
} else {
118
    # Search for booksellers to transfer from/to
119
    $op = '' unless $op;
120
    if( $op eq "do_search" ) {
121
        my @booksellers = GetBookSeller($query);
122
        $template->param(
123
            query => $query,
124
            do_search => 1,
125
            booksellersloop => \@booksellers,
126
        );
127
    } else {
128
        $template->param(
129
            search_form => 1,
130
        );
131
    }
132
}
133
134
$template->param(
135
    bookselleridfrom    => $bookselleridfrom,
136
    booksellerfromname  => $booksellerfromname,
137
    bookselleridto      => $bookselleridto,
138
    booksellertoname    => $booksellertoname,
139
    ordernumber         => $ordernumber,
140
    basketno            => $basketno,
141
    referrer            => $input->param('referrer')
142
);
143
144
output_html_with_http_headers $input, $cookie, $template->output;
145
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 2728-2733 CREATE TABLE `aqorders` ( Link Here
2728
  `cancelledby` varchar(10) default NULL,
2728
  `cancelledby` varchar(10) default NULL,
2729
  `datecancellationprinted` date default NULL,
2729
  `datecancellationprinted` date default NULL,
2730
  `notes` mediumtext,
2730
  `notes` mediumtext,
2731
  internalnotes mediumtext DEFAULT NULL,
2731
  `supplierreference` mediumtext,
2732
  `supplierreference` mediumtext,
2732
  `purchaseordernumber` mediumtext,
2733
  `purchaseordernumber` mediumtext,
2733
  `subscription` tinyint(1) default NULL,
2734
  `subscription` tinyint(1) default NULL,
(-)a/installer/data/mysql/updatedatabase.pl (+10 lines)
Lines 5307-5312 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
5307
    SetVersion ($DBversion);
5307
    SetVersion ($DBversion);
5308
}
5308
}
5309
5309
5310
$DBversion = "XXX";
5311
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5312
    $dbh->do(qq{
5313
        ALTER TABLE aqorders
5314
        ADD COLUMN internalnotes MEDIUMTEXT DEFAULT NULL AFTER notes
5315
    });
5316
    print "Upgrade to $DBversion done (Add internalnotes field in aqorders table)\n";
5317
    SetVersion($DBversion);
5318
}
5319
5310
=head1 FUNCTIONS
5320
=head1 FUNCTIONS
5311
5321
5312
=head2 TableExists($table)
5322
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt (+6 lines)
Lines 312-317 Link Here
312
                                    [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% books_loo.ordernumber %]">Add note</a>]
312
                                    [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% books_loo.ordernumber %]">Add note</a>]
313
                                [% END %]
313
                                [% END %]
314
                            </p>
314
                            </p>
315
                            <p>[% books_loo.internalnotes %]</p>
315
                        </td>
316
                        </td>
316
                        <td class="number [% IF books_loo.rrp.search('^0') %]error[% END %]">[% books_loo.rrp %]</td>
317
                        <td class="number [% IF books_loo.rrp.search('^0') %]error[% END %]">[% books_loo.rrp %]</td>
317
                        <td class="number [% IF books_loo.ecost.search('^0') %]error[% END %]">[% books_loo.ecost %]</td>
318
                        <td class="number [% IF books_loo.ecost.search('^0') %]error[% END %]">[% books_loo.ecost %]</td>
Lines 322-327 Link Here
322
                            [% UNLESS ( closedate ) %]
323
                            [% UNLESS ( closedate ) %]
323
                            <td>
324
                            <td>
324
                                <a href="neworderempty.pl?ordernumber=[% books_loo.ordernumber %]&amp;booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">Modify</a>
325
                                <a href="neworderempty.pl?ordernumber=[% books_loo.ordernumber %]&amp;booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]">Modify</a>
326
                                [% UNLESS (books_loo.order_received) %]
327
                                    <br />
328
                                    <a href="/cgi-bin/koha/acqui/transferorder.pl?ordernumber=[% books_loo.ordernumber %]&referrer=[% "/cgi-bin/koha/acqui/basket.pl?basketno=$basketno" | uri %]">Transfer</a>
329
                                [% END %]
325
                            </td>
330
                            </td>
326
                            <td>
331
                            <td>
327
                            [% IF ( books_loo.left_holds_on_order ) %]
332
                            [% IF ( books_loo.left_holds_on_order ) %]
Lines 393-398 Link Here
393
                        [% IF ( order.publicationyear ) %], [% order.publicationyear %][% END %]
398
                        [% IF ( order.publicationyear ) %], [% order.publicationyear %][% END %]
394
                        [% IF ( books_loo.editionstatement ) %], [% books_loo.editionstatement %][% END %]
399
                        [% IF ( books_loo.editionstatement ) %], [% books_loo.editionstatement %][% END %]
395
                      </p>
400
                      </p>
401
                      <p>[% order.internalnotes %]</p>
396
                    </td>
402
                    </td>
397
                    <td><p>[% order.rrp %]</p></td>
403
                    <td><p>[% order.rrp %]</p></td>
398
                    <td><p>[% order.ecost %]</p></td>
404
                    <td><p>[% order.ecost %]</p></td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt (-3 / +6 lines)
Lines 106-114 Link Here
106
                       + '<td>' + order.ecost + '</td>'
106
                       + '<td>' + order.ecost + '</td>'
107
                       + '<td>' + order.ordertotal + '</td>'
107
                       + '<td>' + order.ordertotal + '</td>'
108
                       + '<td>'
108
                       + '<td>'
109
                       + '<a href="orderreceive.pl?ordernumber=' + order.ordernumber + '&amp;datereceived=[% invoicedatereceived %]&amp;invoice=[% invoice %]&amp;gst=' + gst + '&amp;freight=' + order.freight + '&amp;booksellerid=[% booksellerid %]">Receive</a> /'
109
                       + '<a href="orderreceive.pl?ordernumber=' + order.ordernumber + '&amp;datereceived=[% invoicedatereceived %]&amp;invoice=[% invoice %]&amp;gst=' + gst + '&amp;freight=' + order.freight + '&amp;booksellerid=[% booksellerid %]">Receive</a>'
110
                       + '<a href="parcel.pl?type=intra&amp;ordernumber=' + order.ordernumber + '&amp;biblionumber=' + order.biblionumber + '&amp;action=cancelorder&amp;booksellerid=[% booksellerid %]&amp;datereceived=[% invoicedatereceived %]&amp;invoice=[% invoice %]" onclick="return confirm(\'' + _('Are you sure you want to cancel this order?') + '\');">Cancel</a>'
110
                       + '<br />'
111
                       + '</td></tr>').appendTo("table#pendingt");
111
                       + '<a href="/cgi-bin/koha/acqui/transferorder.pl?ordernumber=[% loop_order.ordernumber %]&amp;referrer=[% "/cgi-bin/koha/acqui/parcel.pl?booksellerid=$booksellerid&datereceived=$invoicedatereceived&invoice=$invoice" | uri %]">Transfer</a>'
112
                       + '</td><td></td></tr>').appendTo("table#pendingt");
112
				}
113
				}
113
114
114
				// If nothing has been found, we tell the user so
115
				// If nothing has been found, we tell the user so
Lines 259-264 Link Here
259
                <td>[% loop_order.ordertotal %]</td>
260
                <td>[% loop_order.ordertotal %]</td>
260
				<td>
261
				<td>
261
				    <a href="orderreceive.pl?ordernumber=[% loop_order.ordernumber %]&amp;datereceived=[% loop_order.invoicedatereceived %]&amp;invoice=[% loop_order.invoice %]&amp;gst=[% loop_order.gst %]&amp;freight=[% loop_order.freight %]&amp;booksellerid=[% loop_order.booksellerid %]">Receive</a>
262
				    <a href="orderreceive.pl?ordernumber=[% loop_order.ordernumber %]&amp;datereceived=[% loop_order.invoicedatereceived %]&amp;invoice=[% loop_order.invoice %]&amp;gst=[% loop_order.gst %]&amp;freight=[% loop_order.freight %]&amp;booksellerid=[% loop_order.booksellerid %]">Receive</a>
263
                    <br />
264
                    <a href="/cgi-bin/koha/acqui/transferorder.pl?ordernumber=[% loop_order.ordernumber %]&amp;referrer=[% "/cgi-bin/koha/acqui/parcel.pl?booksellerid=$booksellerid&datereceived=$invoicedatereceived&invoice=$invoice" | uri %]">Transfer</a>
262
				    
265
				    
263
				</td>
266
				</td>
264
				<td>
267
				<td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/transferorder.tt (-1 / +121 lines)
Line 0 Link Here
0
- 
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Acquisitions &rsaquo; Transfer order</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
</head>
5
<body>
6
[% INCLUDE 'header.inc' %]
7
[% INCLUDE 'acquisitions-search.inc' %]
8
9
<div id="breadcrumbs">
10
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
11
    &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a>
12
    &rsaquo; Transfer order
13
</div>
14
15
<div id="doc3" class="yui-t2">
16
<div id="bd">
17
<div id="yui-main">
18
    <div class="yui-b">
19
        [% IF ( show_baskets ) %]
20
            <h1>Baskets for [% booksellertoname %]</h1>
21
            [% IF ( basketsloop ) %]
22
                <table>
23
                    <thead>
24
                        <th>Basket (#)</th>
25
                        <th>Created by</th>
26
                        <th>Date</th>
27
                        <th>&nbsp;</th>
28
                    </thead>
29
                    <tbody>
30
                        [% FOREACH basket IN basketsloop %]
31
                          <tr>
32
                            <td>[% basket.basketname %] (#[% basket.basketno %])</td>
33
                            <td>[% basket.createdby %]</td>
34
                            <td>[% basket.creationdate %]</td>
35
                            <td><a href="transferorder.pl?basketno=[% basket.basketno %]&ordernumber=[% ordernumber %][% IF (referrer) %]&referrer=[% referrer | uri %][% END %]" onclick="return confirm('Do you want to transfer order [% ordernumber %] from basket [% basketfromname %] ([% booksellerfromname %]) to basket [% basket.basketname %] ([% booksellertoname %]) ?');">Choose</a>
36
                          </tr>
37
                        [% END %]
38
                    </tbody>
39
                </table>
40
            [% ELSE %]
41
                <p>There is no open baskets for this supplier.</p>
42
            [% END %]
43
        [% END %]
44
        [% IF ( ordersloop ) %]
45
            <h1>Orders for [% booksellerfromname %]</h1>
46
            <table>
47
                <thead>
48
                    <th>Order</th>
49
                    <th>Summary</th>
50
                    <th>&nbsp;</th>
51
                </thead>
52
                <tbody>
53
                    [% FOREACH ordersloo IN ordersloop %]
54
                      <tr>
55
                        <td><a href="neworderempty.pl?ordernumber=[% ordersloo.ordernumber %]">[% ordersloo.ordernumber %]</a></td>
56
                        <td>
57
                            <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% ordersloo.biblionumber %]">[% ordersloo.title |html %]</a>
58
                            [% IF ( ordersloo.author ) %] by [% ordersloo.author %][% END %]
59
                            [% IF ( ordersloo.isbn ) %] &ndash; [% ordersloo.isbn %][% END %]
60
                            [% IF ( ordersloo.publishercode ) %]<br />Publisher :[% ordersloo.publishercode %][% END %]
61
                        </td>
62
                        <td><a href="transferorder.pl?bookselleridfrom=[% ordersloo.bookselleridfrom %]&ordernumber=[% ordersloo.ordernumber %][% IF (referrer) %]&referrer=[% referrer | uri %][% END %]">Transfer</a></td>
63
                      </tr>
64
                    [% END %]
65
                </tbody>
66
            </table>
67
        [% END %]
68
        [% IF ( do_search ) %]
69
            [% IF ( bookselleridfrom ) %]
70
                <h1>Choose a vendor to transfer to</h1>
71
            [% ELSE %]
72
                <h1>Choose a vendor to transfer from</h1>
73
            [% END %]
74
            [% IF ( booksellersloop ) %]
75
                <table>
76
                    <thead>
77
                        <th>Name</th>
78
                        <th>&nbsp;</th>
79
                    </thead>
80
                    <tbody>
81
                        [% FOREACH bookseller IN booksellersloop %]
82
                          <tr>
83
                            <td>[% bookseller.name %]</td>
84
                            <td><a href="transferorder.pl?[% IF (bookselleridfrom) %]bookselleridto[% ELSE %]bookselleridfrom[% END %]=[% bookseller.id %][% IF (ordernumber) %]&ordernumber=[% ordernumber %][% END %][% IF (referrer) %]&referrer=[% referrer | uri %][% END %]">Choose</a></td>
85
                          </tr>
86
                        [% END %]
87
                    </tbody>
88
                 </table>
89
            [% ELSE %]
90
                <p>No results found.</p>
91
            [% END %]
92
        [% END %]
93
        [% IF ( search_form ) %]
94
            [% IF ( bookselleridfrom ) %]
95
                <h1>Search for a vendor to transfer to</h1>
96
            [% ELSE %]
97
                <h1>Search for a vendor to transfer from</h1>
98
            [% END %]
99
            <form method="get" action="transferorder.pl">
100
                <input type="hidden" name="op" value="do_search" />
101
                <input type="hidden" name="referrer" value="[% referrer %]" />
102
                [% IF ( ordernumber ) %]
103
                    <input type="hidden" name="ordernumber" value="[% ordernumber %]" />
104
                [% END %]
105
                [% IF ( bookselleridfrom ) %]
106
                    <input type="hidden" name="bookselleridfrom" value="[% bookselleridfrom %]" />
107
                [% END %]
108
                <label for="query">Vendor:</label>
109
                <input type="text" name="query" />
110
                <input type="submit" value="Search" />
111
            </form>
112
        [% END %]
113
    </div>
114
</div>
115
116
<div class="yui-b">
117
    [% INCLUDE 'acquisitions-menu.inc' %]
118
</div>
119
</div>
120
</div>
121
[% INCLUDE 'intranet-bottom.inc' %]

Return to bug 5349