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

(-)a/C4/Acquisition.pm (-141 / +93 lines)
Lines 53-61 BEGIN { Link Here
53
        &ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup
53
        &ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup
54
        &GetBasketgroups &ReOpenBasketgroup
54
        &GetBasketgroups &ReOpenBasketgroup
55
55
56
        &NewOrder &DelOrder &ModOrder &GetPendingOrders &GetOrder &GetOrders
56
        &NewOrder &DelOrder &ModOrder &GetOrder &GetOrders
57
        &GetOrderNumber &GetLateOrders &GetOrderFromItemnumber
57
        &GetOrderNumber &GetLateOrders &GetOrderFromItemnumber
58
        &SearchOrder &GetHistory &GetRecentAcqui
58
        &SearchOrders &GetHistory &GetRecentAcqui
59
        &ModReceiveOrder &CancelReceipt &ModOrderBiblioitemNumber
59
        &ModReceiveOrder &CancelReceipt &ModOrderBiblioitemNumber
60
        &GetCancelledOrders
60
        &GetCancelledOrders
61
        &GetLastOrderNotReceivedFromSubscriptionid &GetLastOrderReceivedFromSubscriptionid
61
        &GetLastOrderNotReceivedFromSubscriptionid &GetLastOrderReceivedFromSubscriptionid
Lines 819-914 sub GetBasketgroups { Link Here
819
819
820
=head2 FUNCTIONS ABOUT ORDERS
820
=head2 FUNCTIONS ABOUT ORDERS
821
821
822
=cut
823
824
#------------------------------------------------------------#
825
826
=head3 GetPendingOrders
827
828
$orders = &GetPendingOrders($supplierid,$grouped,$owner,$basketno,$ordernumber,$search,$ean);
829
830
Finds pending orders from the bookseller with the given ID. Ignores
831
completed and cancelled orders.
832
833
C<$booksellerid> contains the bookseller identifier
834
C<$owner> contains 0 or 1. 0 means any owner. 1 means only the list of orders entered by the user itself.
835
C<$grouped> is a boolean that, if set to 1 will group all order lines of the same basket
836
in a single result line
837
C<$orders> is a reference-to-array; each element is a reference-to-hash.
838
839
Used also by the filter in parcel.pl
840
I have added:
841
842
C<$ordernumber>
843
C<$search>
844
C<$ean>
845
846
These give the value of the corresponding field in the aqorders table
847
of the Koha database.
848
849
Results are ordered from most to least recent.
850
851
=cut
852
853
sub GetPendingOrders {
854
    my ($supplierid,$grouped,$owner,$basketno,$ordernumber,$search,$ean) = @_;
855
    my $dbh = C4::Context->dbh;
856
    my $strsth = "
857
        SELECT ".($grouped?"count(*),":"")."aqbasket.basketno,
858
               surname,firstname,biblio.*,biblioitems.isbn,
859
               aqbasket.closedate, aqbasket.creationdate, aqbasket.basketname,
860
               aqorders.*
861
        FROM aqorders
862
        LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
863
        LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
864
        LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber
865
        LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
866
        WHERE (quantity > quantityreceived OR quantityreceived is NULL)
867
        AND datecancellationprinted IS NULL";
868
    my @query_params;
869
    my $userenv = C4::Context->userenv;
870
    if ( C4::Context->preference("IndependantBranches") ) {
871
        if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
872
            $strsth .= " AND (borrowers.branchcode = ?
873
                        or borrowers.branchcode  = '')";
874
            push @query_params, $userenv->{branch};
875
        }
876
    }
877
    if ($supplierid) {
878
        $strsth .= " AND aqbasket.booksellerid = ?";
879
        push @query_params, $supplierid;
880
    }
881
    if($ordernumber){
882
        $strsth .= " AND (aqorders.ordernumber=?)";
883
        push @query_params, $ordernumber;
884
    }
885
    if($search){
886
        $strsth .= " AND (biblio.title like ? OR biblio.author LIKE ? OR biblioitems.isbn like ?)";
887
        push @query_params, ("%$search%","%$search%","%$search%");
888
    }
889
    if ($ean) {
890
        $strsth .= " AND biblioitems.ean = ?";
891
        push @query_params, $ean;
892
    }
893
    if ($basketno) {
894
        $strsth .= " AND aqbasket.basketno=? ";
895
        push @query_params, $basketno;
896
    }
897
    if ($owner) {
898
        $strsth .= " AND aqbasket.authorisedby=? ";
899
        push @query_params, $userenv->{'number'};
900
    }
901
    $strsth .= " group by aqbasket.basketno" if $grouped;
902
    $strsth .= " order by aqbasket.basketno";
903
    my $sth = $dbh->prepare($strsth);
904
    $sth->execute( @query_params );
905
    my $results = $sth->fetchall_arrayref({});
906
    $sth->finish;
907
    return $results;
908
}
909
910
#------------------------------------------------------------#
911
912
=head3 GetOrders
822
=head3 GetOrders
913
823
914
  @orders = &GetOrders($basketnumber, $orderby);
824
  @orders = &GetOrders($basketnumber, $orderby);
Lines 1531-1610 sub CancelReceipt { Link Here
1531
1441
1532
#------------------------------------------------------------#
1442
#------------------------------------------------------------#
1533
1443
1534
=head3 SearchOrder
1444
=head3 SearchOrders
1535
1445
1536
@results = &SearchOrder($search, $biblionumber, $complete);
1446
@results = &SearchOrders({
1447
    ordernumber => $ordernumber,
1448
    search => $search,
1449
    biblionumber => $biblionumber,
1450
    ean => $ean,
1451
    booksellerid => $booksellerid,
1452
    basketno => $basketno,
1453
    owner => $owner,
1454
    pending => $pending
1455
});
1537
1456
1538
Searches for orders.
1457
Searches for orders.
1539
1458
1540
C<$search> may take one of several forms: if it is an ISBN,
1459
C<$owner> Finds order for the logged in user.
1541
C<&ordersearch> returns orders with that ISBN. If C<$search> is an
1460
C<$pending> Finds pending orders. Ignores completed and cancelled orders.
1542
order number, C<&ordersearch> returns orders with that order number
1543
and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
1544
to be a space-separated list of search terms; in this case, all of the
1545
terms must appear in the title (matching the beginning of title
1546
words).
1547
1548
If C<$complete> is C<yes>, the results will include only completed
1549
orders. In any case, C<&ordersearch> ignores cancelled orders.
1550
1551
C<&ordersearch> returns an array.
1552
C<@results> is an array of references-to-hash with the following keys:
1553
1554
=over 4
1555
1556
=item C<author>
1557
1461
1558
=item C<seriestitle>
1559
1462
1560
=item C<branchcode>
1463
C<@results> is an array of references-to-hash with the keys are fields
1561
1464
from aqorders, biblio, biblioitems and aqbasket tables.
1562
=item C<budget_id>
1563
1564
=back
1565
1465
1566
=cut
1466
=cut
1567
1467
1568
sub SearchOrder {
1468
sub SearchOrders {
1569
#### -------- SearchOrder-------------------------------
1469
    my ( $params ) = @_;
1570
    my ( $ordernumber, $search, $ean, $supplierid, $basket ) = @_;
1470
    my $ordernumber = $params->{ordernumber};
1471
    my $search = $params->{search};
1472
    my $ean = $params->{ean};
1473
    my $booksellerid = $params->{booksellerid};
1474
    my $basketno = $params->{basketno};
1475
    my $basketname = $params->{basketname};
1476
    my $basketgroupname = $params->{basketgroupname};
1477
    my $owner = $params->{owner};
1478
    my $pending = $params->{pending};
1571
1479
1572
    my $dbh = C4::Context->dbh;
1480
    my $dbh = C4::Context->dbh;
1573
    my @args = ();
1481
    my @args = ();
1574
    my $query =
1482
    my $query = q{
1575
            "SELECT *
1483
        SELECT aqbasket.basketno,
1576
            FROM aqorders
1484
               borrowers.surname,
1485
               borrowers.firstname,
1486
               biblio.*,
1487
               biblioitems.isbn,
1488
               biblioitems.biblioitemnumber,
1489
               aqbasket.closedate,
1490
               aqbasket.creationdate,
1491
               aqbasket.basketname,
1492
               aqorders.*
1493
        FROM aqorders
1494
            LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno
1495
            LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid = aqbasketgroups.id
1496
            LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
1577
            LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber
1497
            LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber
1578
            LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
1498
            LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
1579
            LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno
1499
        WHERE (datecancellationprinted is NULL)
1580
                WHERE  (datecancellationprinted is NULL)";
1500
    };
1501
1502
    $query .= q{
1503
        AND (quantity > quantityreceived OR quantityreceived is NULL)
1504
    };
1505
1506
    my $userenv = C4::Context->userenv;
1507
    if ( C4::Context->preference("IndependantBranches") ) {
1508
        if ( ( $userenv ) and ( $userenv->{flags} != 1 ) ) {
1509
            $query .= q{
1510
                AND (
1511
                    borrowers.branchcode = ?
1512
                    OR borrowers.branchcode  = ''
1513
                )
1514
            };
1515
            push @args, $userenv->{branch};
1516
        }
1517
    }
1581
1518
1582
    if($ordernumber){
1519
    if ( $ordernumber ) {
1583
        $query .= " AND (aqorders.ordernumber=?)";
1520
        $query .= ' AND (aqorders.ordernumber=?)';
1584
        push @args, $ordernumber;
1521
        push @args, $ordernumber;
1585
    }
1522
    }
1586
    if($search){
1523
    if( $search ) {
1587
        $query .= " AND (biblio.title like ? OR biblio.author LIKE ? OR biblioitems.isbn like ?)";
1524
        $query .= ' AND (biblio.title LIKE ? OR biblio.author LIKE ? OR biblioitems.isbn LIKE ?)';
1588
        push @args, ("%$search%","%$search%","%$search%");
1525
        push @args, ("%$search%","%$search%","%$search%");
1589
    }
1526
    }
1590
    if ($ean) {
1527
    if ( $ean ) {
1591
        $query .= " AND biblioitems.ean = ?";
1528
        $query .= ' AND biblioitems.ean = ?';
1592
        push @args, $ean;
1529
        push @args, $ean;
1593
    }
1530
    }
1594
    if ($supplierid) {
1531
    if ( $booksellerid ) {
1595
        $query .= "AND aqbasket.booksellerid = ?";
1532
        $query .= 'AND aqbasket.booksellerid = ?';
1596
        push @args, $supplierid;
1533
        push @args, $booksellerid;
1597
    }
1534
    }
1598
    if($basket){
1535
    if( $basketno ) {
1599
        $query .= "AND aqorders.basketno = ?";
1536
        $query .= 'AND aqbasket.basketno = ?';
1600
        push @args, $basket;
1537
        push @args, $basketno;
1601
    }
1538
    }
1539
    if( $basketname ) {
1540
        $query .= 'AND aqbasket.basketname LIKE ?';
1541
        push @args, "%$basketname%";
1542
    }
1543
    if( $basketgroupname ) {
1544
        $query .= ' AND aqbasketgroups.name LIKE ?';
1545
        push @args, "%$basketgroupname%";
1546
    }
1547
1548
    if ( $owner ) {
1549
        $query .= ' AND aqbasket.authorisedby=? ';
1550
        push @args, $userenv->{'number'};
1551
    }
1552
1553
    $query .= ' ORDER BY aqbasket.basketno';
1602
1554
1603
    my $sth = $dbh->prepare($query);
1555
    my $sth = $dbh->prepare($query);
1604
    $sth->execute(@args);
1556
    $sth->execute(@args);
1605
    my $results = $sth->fetchall_arrayref({});
1557
    return $sth->fetchall_arrayref({});
1606
    $sth->finish;
1607
    return $results;
1608
}
1558
}
1609
1559
1610
#------------------------------------------------------------#
1560
#------------------------------------------------------------#
Lines 2406-2413 sub GetInvoiceDetails { Link Here
2406
    my $invoice = $sth->fetchrow_hashref;
2356
    my $invoice = $sth->fetchrow_hashref;
2407
2357
2408
    $query = qq{
2358
    $query = qq{
2409
        SELECT aqorders.*, biblio.*
2359
        SELECT aqorders.*, biblio.*,
2360
        aqbasket.basketname
2410
        FROM aqorders
2361
        FROM aqorders
2362
          LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno
2411
          LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber
2363
          LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber
2412
        WHERE invoiceid = ?
2364
        WHERE invoiceid = ?
2413
    };
2365
    };
(-)a/acqui/orderreceive.pl (-1 / +3 lines)
Lines 91-97 $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates Link Here
91
91
92
my $bookseller = GetBookSellerFromId($booksellerid);
92
my $bookseller = GetBookSellerFromId($booksellerid);
93
my $results;
93
my $results;
94
$results = SearchOrder($ordernumber) if $ordernumber;
94
$results = SearchOrders({
95
    ordernumber => $ordernumber
96
}) if $ordernumber;
95
97
96
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
98
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
97
    {
99
    {
(-)a/acqui/parcel.pl (-7 / +20 lines)
Lines 173-180 for my $item ( @parcelitems ) { Link Here
173
    $item->{unitprice} = get_value_with_gst_params( $item->{unitprice}, $item->{gstrate}, $bookseller );
173
    $item->{unitprice} = get_value_with_gst_params( $item->{unitprice}, $item->{gstrate}, $bookseller );
174
    $total = ( $item->{'unitprice'} ) * $item->{'quantityreceived'};
174
    $total = ( $item->{'unitprice'} ) * $item->{'quantityreceived'};
175
    $item->{'unitprice'} += 0;
175
    $item->{'unitprice'} += 0;
176
    my %line;
176
    my %line = %{ $item };
177
    %line          = %{ $item };
178
    my $ecost = get_value_with_gst_params( $line{ecost}, $line{gstrate}, $bookseller );
177
    my $ecost = get_value_with_gst_params( $line{ecost}, $line{gstrate}, $bookseller );
179
    $line{ecost} = sprintf( "%.2f", $ecost );
178
    $line{ecost} = sprintf( "%.2f", $ecost );
180
    $line{invoice} = $invoice->{invoicenumber};
179
    $line{invoice} = $invoice->{invoicenumber};
Lines 218-230 if(!defined $invoice->{closedate}) { Link Here
218
    if($input->param('op') eq "search"){
217
    if($input->param('op') eq "search"){
219
        my $search   = $input->param('summaryfilter') || '';
218
        my $search   = $input->param('summaryfilter') || '';
220
        my $ean      = $input->param('eanfilter') || '';
219
        my $ean      = $input->param('eanfilter') || '';
221
        my $basketno = $input->param('basketfilter') || '';
220
        my $basketname = $input->param('basketfilter') || '';
222
        my $orderno  = $input->param('orderfilter') || '';
221
        my $orderno  = $input->param('orderfilter') || '';
223
        my $grouped;
222
        $pendingorders = SearchOrders({
224
        my $owner;
223
            booksellerid => $booksellerid,
225
        $pendingorders = GetPendingOrders($booksellerid,$grouped,$owner,$basketno,$orderno,$search,$ean);
224
            basketname => $basketname,
225
            ordernumber => $orderno,
226
            search => $search,
227
            ean => $ean,
228
            pending => 1,
229
        });
230
        $template->param(
231
            summaryfilter => $search,
232
            eanfilter => $ean,
233
            basketfilter => $basketname,
234
            orderfilter => $orderno,
235
        );
226
    }else{
236
    }else{
227
        $pendingorders = GetPendingOrders($booksellerid);
237
        $pendingorders = SearchOrders({
238
            booksellerid => $booksellerid,
239
            pending => 1
240
        });
228
    }
241
    }
229
    my $countpendings = scalar @$pendingorders;
242
    my $countpendings = scalar @$pendingorders;
230
243
(-)a/acqui/uncertainprice.pl (-2 / +7 lines)
Lines 52-58 use C4::Output; Link Here
52
use CGI;
52
use CGI;
53
53
54
use C4::Bookseller qw/GetBookSellerFromId/;
54
use C4::Bookseller qw/GetBookSellerFromId/;
55
use C4::Acquisition qw/GetPendingOrders GetOrder ModOrder/;
55
use C4::Acquisition qw/SearchOrders GetOrder ModOrder/;
56
use C4::Biblio qw/GetBiblioData/;
56
use C4::Biblio qw/GetBiblioData/;
57
57
58
my $input=new CGI;
58
my $input=new CGI;
Lines 73-79 my $owner = $input->param('owner') || 0 ; # flag to see only "my" orders, or eve Link Here
73
my $bookseller = &GetBookSellerFromId($booksellerid);
73
my $bookseller = &GetBookSellerFromId($booksellerid);
74
74
75
#show all orders that have uncertain price for the bookseller
75
#show all orders that have uncertain price for the bookseller
76
my $pendingorders = &GetPendingOrders($booksellerid,0,$owner,$basketno);
76
my $pendingorders = SearchOrders({
77
    booksellerid => $booksellerid,
78
    owner => $owner,
79
    basketno => $basketno,
80
    pending => 1,
81
});
77
my @orders;
82
my @orders;
78
83
79
foreach my $order (@{$pendingorders}) {
84
foreach my $order (@{$pendingorders}) {
(-)a/serials/acqui-search-result.pl (-2 / +5 lines)
Lines 45-51 use C4::Auth; Link Here
45
use C4::Biblio;
45
use C4::Biblio;
46
use C4::Output;
46
use C4::Output;
47
use CGI;
47
use CGI;
48
use C4::Acquisition;
48
use C4::Acquisition qw( SearchOrders );
49
use C4::Dates qw/format_date/;
49
use C4::Dates qw/format_date/;
50
use C4::Bookseller qw( GetBookSeller );
50
use C4::Bookseller qw( GetBookSeller );
51
51
Lines 66-72 my @suppliers = GetBookSeller($supplier); Link Here
66
#build result page
66
#build result page
67
my $loop_suppliers = [];
67
my $loop_suppliers = [];
68
for my $s (@suppliers) {
68
for my $s (@suppliers) {
69
    my $orders = GetPendingOrders($s->{'id'});
69
    my $orders = SearchOrders({
70
        booksellerid => $s->{'id'},
71
        pending => 1
72
    });
70
73
71
    my $loop_basket = [];
74
    my $loop_basket = [];
72
    for my $ord ( @{$orders} ) {
75
    for my $ord ( @{$orders} ) {
(-)a/t/db_dependent/Acquisition.t (-2 / +4 lines)
Lines 28-35 SKIP: { Link Here
28
28
29
29
30
my $supplierid = 1;
30
my $supplierid = 1;
31
my $grouped    = 0;
31
my $orders = SearchOrders({
32
my $orders = GetPendingOrders( $supplierid, $grouped );
32
    booksellerid => $supplierid,
33
    pending => 1
34
});
33
isa_ok( $orders, 'ARRAY' );
35
isa_ok( $orders, 'ARRAY' );
34
36
35
my @lateorders = GetLateOrders(0);
37
my @lateorders = GetLateOrders(0);
(-)a/t/db_dependent/lib/KohaTest/Acquisition.pm (-1 / +1 lines)
Lines 20-26 sub methods : Test( 1 ) { Link Here
20
    my @methods = qw(  GetBasket 
20
    my @methods = qw(  GetBasket 
21
                       NewBasket 
21
                       NewBasket 
22
                       CloseBasket 
22
                       CloseBasket 
23
                       GetPendingOrders 
23
                       SearchOrders
24
                       GetOrders 
24
                       GetOrders 
25
                       GetOrderNumber 
25
                       GetOrderNumber 
26
                       GetOrder 
26
                       GetOrder 
(-)a/t/db_dependent/lib/KohaTest/Acquisition/GetPendingOrders.pm (-5 / +10 lines)
Lines 1-4 Link Here
1
package KohaTest::Acquisition::GetPendingOrders;
1
package KohaTest::Acquisition::SearchOrders;
2
use base qw( KohaTest::Acquisition );
2
use base qw( KohaTest::Acquisition );
3
3
4
use strict;
4
use strict;
Lines 17-23 at first, there should be no orders for our bookseller. Link Here
17
sub no_orders : Test( 1 ) {
17
sub no_orders : Test( 1 ) {
18
    my $self = shift;
18
    my $self = shift;
19
19
20
    my $orders = GetPendingOrders( $self->{'booksellerid'} );
20
    my $orders = SearchOrders({
21
        booksellerid => $self->{booksellerid},
22
        pending => 1
23
    });
21
    is( scalar @$orders, 0, 'our new bookseller has no pending orders' )
24
    is( scalar @$orders, 0, 'our new bookseller has no pending orders' )
22
      or diag( Data::Dumper->Dump( [ $orders ], [ 'orders' ] ) );
25
      or diag( Data::Dumper->Dump( [ $orders ], [ 'orders' ] ) );
23
}
26
}
Lines 35-42 sub one_new_order : Test( 49 ) { Link Here
35
38
36
    ok( $basketno, "basketno is $basketno" );
39
    ok( $basketno, "basketno is $basketno" );
37
    ok( $ordernumber, "ordernumber is $ordernumber" );
40
    ok( $ordernumber, "ordernumber is $ordernumber" );
38
    
41
39
    my $orders = GetPendingOrders( $self->{'booksellerid'} );
42
    my $orders = Searchorders({
43
        booksellerid => $self->{booksellerid},
44
        pending => 1
45
    });
40
    is( scalar @$orders, 1, 'we successfully entered one order.' );
46
    is( scalar @$orders, 1, 'we successfully entered one order.' );
41
47
42
    my @expectedfields = qw( basketno
48
    my @expectedfields = qw( basketno
43
- 

Return to bug 10124