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

(-)a/C4/Acquisition.pm (-1 / +3 lines)
Lines 30-35 use C4::Templates qw(gettemplate); Link Here
30
use Koha::DateUtils qw( dt_from_string output_pref );
30
use Koha::DateUtils qw( dt_from_string output_pref );
31
use Koha::Acquisition::Orders;
31
use Koha::Acquisition::Orders;
32
use Koha::Acquisition::Booksellers;
32
use Koha::Acquisition::Booksellers;
33
use Koha::Biblios;
33
use Koha::Number::Price;
34
use Koha::Number::Price;
34
use Koha::Libraries;
35
use Koha::Libraries;
35
36
Lines 1873-1879 sub DelOrder { Link Here
1873
1874
1874
    if($delete_biblio) {
1875
    if($delete_biblio) {
1875
        # We get the number of remaining items
1876
        # We get the number of remaining items
1876
        my $itemcount = C4::Items::GetItemsCount($bibnum);
1877
        my $biblio = Koha::Biblios->find( $bibnum );
1878
        my $itemcount = $biblio->items->count;
1877
1879
1878
        # If there are no items left,
1880
        # If there are no items left,
1879
        if ( $itemcount == 0 ) {
1881
        if ( $itemcount == 0 ) {
(-)a/C4/Items.pm (-21 lines)
Lines 71-77 BEGIN { Link Here
71
        GetItemLocation
71
        GetItemLocation
72
        GetLostItems
72
        GetLostItems
73
        GetItemsForInventory
73
        GetItemsForInventory
74
        GetItemsCount
75
        GetItemInfosOf
74
        GetItemInfosOf
76
        GetItemsByBiblioitemnumber
75
        GetItemsByBiblioitemnumber
77
        GetItemsInfo
76
        GetItemsInfo
Lines 1169-1194 sub GetItemsForInventory { Link Here
1169
    return (\@results, $iTotalRecords);
1168
    return (\@results, $iTotalRecords);
1170
}
1169
}
1171
1170
1172
=head2 GetItemsCount
1173
1174
  $count = &GetItemsCount( $biblionumber);
1175
1176
This function return count of item with $biblionumber
1177
1178
=cut
1179
1180
sub GetItemsCount {
1181
    my ( $biblionumber ) = @_;
1182
    my $dbh = C4::Context->dbh;
1183
    my $query = "SELECT count(*)
1184
          FROM  items 
1185
          WHERE biblionumber=?";
1186
    my $sth = $dbh->prepare($query);
1187
    $sth->execute($biblionumber);
1188
    my $count = $sth->fetchrow;  
1189
    return ($count);
1190
}
1191
1192
=head2 GetItemInfosOf
1171
=head2 GetItemInfosOf
1193
1172
1194
  GetItemInfosOf(@itemnumbers);
1173
  GetItemInfosOf(@itemnumbers);
(-)a/acqui/basket.pl (-2 / +3 lines)
Lines 130-139 if ( $op eq 'delete_confirm' ) { Link Here
130
        my @cannotdelbiblios ;
130
        my @cannotdelbiblios ;
131
        foreach my $myorder (@orders){
131
        foreach my $myorder (@orders){
132
            my $biblionumber = $myorder->{'biblionumber'};
132
            my $biblionumber = $myorder->{'biblionumber'};
133
            my $biblio = Koha::Biblios->find( $biblionumber );
133
            my $countbiblio = CountBiblioInOrders($biblionumber);
134
            my $countbiblio = CountBiblioInOrders($biblionumber);
134
            my $ordernumber = $myorder->{'ordernumber'};
135
            my $ordernumber = $myorder->{'ordernumber'};
135
            my $subscriptions = scalar GetSubscriptionsId ($biblionumber);
136
            my $subscriptions = scalar GetSubscriptionsId ($biblionumber);
136
            my $itemcount = GetItemsCount($biblionumber);
137
            my $itemcount = $biblio->items->count;
137
            my $error;
138
            my $error;
138
            if ($countbiblio == 0 && $itemcount == 0 && $subscriptions == 0) {
139
            if ($countbiblio == 0 && $itemcount == 0 && $subscriptions == 0) {
139
                $error = DelBiblio($myorder->{biblionumber}) }
140
                $error = DelBiblio($myorder->{biblionumber}) }
Lines 466-472 sub get_order_infos { Link Here
466
    my $countbiblio = CountBiblioInOrders($biblionumber);
467
    my $countbiblio = CountBiblioInOrders($biblionumber);
467
    my $ordernumber = $order->{'ordernumber'};
468
    my $ordernumber = $order->{'ordernumber'};
468
    my @subscriptions = GetSubscriptionsId ($biblionumber);
469
    my @subscriptions = GetSubscriptionsId ($biblionumber);
469
    my $itemcount = GetItemsCount($biblionumber);
470
    my $itemcount   = $biblio->items->count;
470
    my $holds_count = $biblio->holds->count;
471
    my $holds_count = $biblio->holds->count;
471
    my @items = GetItemnumbersFromOrder( $ordernumber );
472
    my @items = GetItemnumbersFromOrder( $ordernumber );
472
    my $itemholds;
473
    my $itemholds;
(-)a/acqui/parcel.pl (-1 / +1 lines)
Lines 240-246 unless( defined $invoice->{closedate} ) { Link Here
240
        my $countbiblio = CountBiblioInOrders($biblionumber);
240
        my $countbiblio = CountBiblioInOrders($biblionumber);
241
        my $ordernumber = $line{'ordernumber'};
241
        my $ordernumber = $line{'ordernumber'};
242
        my @subscriptions = GetSubscriptionsId ($biblionumber);
242
        my @subscriptions = GetSubscriptionsId ($biblionumber);
243
        my $itemcount = GetItemsCount($biblionumber);
243
        my $itemcount   = $biblio->items->count;
244
        my $holds_count = $biblio->holds->count;
244
        my $holds_count = $biblio->holds->count;
245
        my @items = GetItemnumbersFromOrder( $ordernumber );
245
        my @items = GetItemnumbersFromOrder( $ordernumber );
246
        my $itemholds;
246
        my $itemholds;
(-)a/catalogue/ISBDdetail.pl (-1 / +4 lines)
Lines 47-52 use C4::Members; # to use GetMember Link Here
47
use C4::Serials;    # CountSubscriptionFromBiblionumber
47
use C4::Serials;    # CountSubscriptionFromBiblionumber
48
use C4::Search;		# enabled_staff_search_views
48
use C4::Search;		# enabled_staff_search_views
49
use C4::Acquisition qw(GetOrdersByBiblionumber);
49
use C4::Acquisition qw(GetOrdersByBiblionumber);
50
51
use Koha::Biblios;
50
use Koha::RecordProcessor;
52
use Koha::RecordProcessor;
51
53
52
54
Lines 87-92 if ( not defined $record ) { Link Here
87
       exit;
89
       exit;
88
}
90
}
89
91
92
my $biblio = Koha::Biblios->find( $biblionumber );
90
my $framework = GetFrameworkCode( $biblionumber );
93
my $framework = GetFrameworkCode( $biblionumber );
91
my $record_processor = Koha::RecordProcessor->new({
94
my $record_processor = Koha::RecordProcessor->new({
92
    filters => 'ViewPolicy',
95
    filters => 'ViewPolicy',
Lines 114-120 if($query->cookie("holdfor")){ Link Here
114
}
117
}
115
118
116
# count of item linked with biblio
119
# count of item linked with biblio
117
my $itemcount = GetItemsCount($biblionumber);
120
my $itemcount = $biblio->items->count;
118
$template->param( count => $itemcount);
121
$template->param( count => $itemcount);
119
my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
122
my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
120
 
123
 
(-)a/catalogue/MARCdetail.pl (-1 / +4 lines)
Lines 59-64 use C4::Acquisition; Link Here
59
use C4::Members; # to use GetMember
59
use C4::Members; # to use GetMember
60
use C4::Serials;    #uses getsubscriptionsfrombiblionumber GetSubscriptionsFromBiblionumber
60
use C4::Serials;    #uses getsubscriptionsfrombiblionumber GetSubscriptionsFromBiblionumber
61
use C4::Search;		# enabled_staff_search_views
61
use C4::Search;		# enabled_staff_search_views
62
63
use Koha::Biblios;
62
use Koha::BiblioFrameworks;
64
use Koha::BiblioFrameworks;
63
65
64
use List::MoreUtils qw( uniq );
66
use List::MoreUtils qw( uniq );
Lines 98-103 if ( not defined $record ) { Link Here
98
    exit;
100
    exit;
99
}
101
}
100
102
103
my $biblio_object = Koha::Biblios->find( $biblionumber ); # FIXME Should replace $biblio
101
my $tagslib = &GetMarcStructure(1,$frameworkcode);
104
my $tagslib = &GetMarcStructure(1,$frameworkcode);
102
my $biblio = GetBiblioData($biblionumber);
105
my $biblio = GetBiblioData($biblionumber);
103
106
Lines 112-118 if($query->cookie("holdfor")){ Link Here
112
}
115
}
113
116
114
#count of item linked
117
#count of item linked
115
my $itemcount = GetItemsCount($biblionumber);
118
my $itemcount = $biblio_object->items->count;
116
$template->param( count => $itemcount,
119
$template->param( count => $itemcount,
117
					bibliotitle => $biblio->{title}, );
120
					bibliotitle => $biblio->{title}, );
118
121
(-)a/catalogue/imageviewer.pl (-1 / +4 lines)
Lines 29-34 use C4::Images; Link Here
29
use C4::Search;
29
use C4::Search;
30
use C4::Acquisition qw(GetOrdersByBiblionumber);
30
use C4::Acquisition qw(GetOrdersByBiblionumber);
31
31
32
use Koha::Biblios;
33
32
my $query = new CGI;
34
my $query = new CGI;
33
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
35
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
34
    {
36
    {
Lines 43-49 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
43
my $biblionumber = $query->param('biblionumber') || $query->param('bib');
45
my $biblionumber = $query->param('biblionumber') || $query->param('bib');
44
my $imagenumber = $query->param('imagenumber');
46
my $imagenumber = $query->param('imagenumber');
45
my $biblio = GetBiblio($biblionumber);
47
my $biblio = GetBiblio($biblionumber);
46
my $itemcount = GetItemsCount($biblionumber);
48
my $biblio_object = Koha::Biblios->find( $biblionumber ); # This should replace $biblio
49
my $itemcount = $biblio_object->items->count;;
47
50
48
my @items = GetItemsInfo($biblionumber);
51
my @items = GetItemsInfo($biblionumber);
49
52
(-)a/catalogue/labeledMARCdetail.pl (-1 / +3 lines)
Lines 31-36 use C4::Members; # to use GetMember Link Here
31
use C4::Search;		# enabled_staff_search_views
31
use C4::Search;		# enabled_staff_search_views
32
use C4::Acquisition qw(GetOrdersByBiblionumber);
32
use C4::Acquisition qw(GetOrdersByBiblionumber);
33
33
34
use Koha::Biblios;
34
use Koha::BiblioFrameworks;
35
use Koha::BiblioFrameworks;
35
36
36
my $query        = new CGI;
37
my $query        = new CGI;
Lines 65-70 if ( not defined $record ) { Link Here
65
    exit;
66
    exit;
66
}
67
}
67
68
69
my $biblio_object = Koha::Biblios->find( $biblionumber ); # FIXME Should replace $biblio
68
my $tagslib = GetMarcStructure(1,$frameworkcode);
70
my $tagslib = GetMarcStructure(1,$frameworkcode);
69
my $biblio = GetBiblioData($biblionumber);
71
my $biblio = GetBiblioData($biblionumber);
70
72
Lines 79-85 if($query->cookie("holdfor")){ Link Here
79
}
81
}
80
82
81
#count of item linked
83
#count of item linked
82
my $itemcount = GetItemsCount($biblionumber);
84
my $itemcount = $biblio_object->items->count;
83
$template->param( count => $itemcount,
85
$template->param( count => $itemcount,
84
					bibliotitle => $biblio->{title}, );
86
					bibliotitle => $biblio->{title}, );
85
87
(-)a/t/db_dependent/Acquisition.t (-6 / +35 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use POSIX qw(strftime);
20
use POSIX qw(strftime);
21
21
22
use Test::More tests => 63;
22
use Test::More tests => 65;
23
use Koha::Database;
23
use Koha::Database;
24
24
25
BEGIN {
25
BEGIN {
Lines 166-171 my ( $biblionumber1, $biblioitemnumber1 ) = AddBiblio( MARC::Record->new, '' ); Link Here
166
my ( $biblionumber2, $biblioitemnumber2 ) = AddBiblio( MARC::Record->new, '' );
166
my ( $biblionumber2, $biblioitemnumber2 ) = AddBiblio( MARC::Record->new, '' );
167
my ( $biblionumber3, $biblioitemnumber3 ) = AddBiblio( MARC::Record->new, '' );
167
my ( $biblionumber3, $biblioitemnumber3 ) = AddBiblio( MARC::Record->new, '' );
168
my ( $biblionumber4, $biblioitemnumber4 ) = AddBiblio( MARC::Record->new, '' );
168
my ( $biblionumber4, $biblioitemnumber4 ) = AddBiblio( MARC::Record->new, '' );
169
my ( $biblionumber5, $biblioitemnumber5 ) = AddBiblio( MARC::Record->new, '' );
169
170
170
# Prepare 5 orders, and make distinction beween fields to be tested with eq and with ==
171
# Prepare 5 orders, and make distinction beween fields to be tested with eq and with ==
171
# Ex : a price of 50.1 will be stored internally as 5.100000
172
# Ex : a price of 50.1 will be stored internally as 5.100000
Lines 256-266 my @order_content = ( Link Here
256
            uncertainprice => 0,
257
            uncertainprice => 0,
257
            tax_rate_on_ordering        => 0
258
            tax_rate_on_ordering        => 0
258
        }
259
        }
260
    },
261
    {
262
        str => {
263
            basketno     => $basketno,
264
            biblionumber => $biblionumber5,
265
            budget_id    => $budget->{budget_id},
266
            order_internalnote => "internal note",
267
            order_vendornote   => "vendor note"
268
        },
269
        num => {
270
            quantity       => 1,
271
            ecost          => 10,
272
            rrp            => 10,
273
            listprice      => 10,
274
            ecost          => 10,
275
            rrp            => 10,
276
            discount       => 0,
277
            uncertainprice => 0,
278
            tax_rate        => 0
279
        }
259
    }
280
    }
260
);
281
);
261
282
262
# Create 4 orders in database
283
# Create 5 orders in database
263
for ( 0 .. 4 ) {
284
for ( 0 .. 5 ) {
264
    my %ocontent;
285
    my %ocontent;
265
    @ocontent{ keys %{ $order_content[$_]->{num} } } =
286
    @ocontent{ keys %{ $order_content[$_]->{num} } } =
266
      values %{ $order_content[$_]->{num} };
287
      values %{ $order_content[$_]->{num} };
Lines 297-303 my $search_orders = SearchOrders({ Link Here
297
isa_ok( $search_orders, 'ARRAY' );
318
isa_ok( $search_orders, 'ARRAY' );
298
ok(
319
ok(
299
    (
320
    (
300
        ( scalar @$search_orders == 4 )
321
        ( scalar @$search_orders == 5 )
301
          and !grep ( $_->{ordernumber} eq $ordernumbers[3], @$search_orders )
322
          and !grep ( $_->{ordernumber} eq $ordernumbers[3], @$search_orders )
302
    ),
323
    ),
303
    "SearchOrders only gets non-cancelled orders"
324
    "SearchOrders only gets non-cancelled orders"
Lines 310-316 $search_orders = SearchOrders({ Link Here
310
});
331
});
311
ok(
332
ok(
312
    (
333
    (
313
        ( scalar @$search_orders == 3 ) and !grep ( (
334
        ( scalar @$search_orders == 4 ) and !grep ( (
314
                     ( $_->{ordernumber} eq $ordernumbers[3] )
335
                     ( $_->{ordernumber} eq $ordernumbers[3] )
315
                  or ( $_->{ordernumber} eq $ordernumbers[4] )
336
                  or ( $_->{ordernumber} eq $ordernumbers[4] )
316
            ),
337
            ),
Lines 367-373 $search_orders = SearchOrders({ Link Here
367
    pending      => 1,
388
    pending      => 1,
368
    ordered      => 1,
389
    ordered      => 1,
369
});
390
});
370
is( scalar (@$search_orders), 3, "SearchOrders with pending and ordered params gets only pending ordered orders. After closing the basket, orders are marked as 'ordered' (bug 11170)" );
391
is( scalar (@$search_orders), 4, "SearchOrders with pending and ordered params gets only pending ordered orders. After closing the basket, orders are marked as 'ordered' (bug 11170)" );
371
392
372
#
393
#
373
# Test AddClaim
394
# Test AddClaim
Lines 497-502 $order4 = GetOrder($order4->{ordernumber}); Link Here
497
ok((defined $order4->{datecancellationprinted}), "order is cancelled");
518
ok((defined $order4->{datecancellationprinted}), "order is cancelled");
498
ok(($order4->{cancellationreason} eq "foobar"), "order has cancellation reason \"foobar\"");
519
ok(($order4->{cancellationreason} eq "foobar"), "order has cancellation reason \"foobar\"");
499
ok((not defined GetBiblio($order4->{biblionumber})), "biblio does not exist anymore");
520
ok((not defined GetBiblio($order4->{biblionumber})), "biblio does not exist anymore");
521
522
my $order5 = GetOrder($ordernumbers[4]);
523
C4::Items::AddItem( { barcode => '0102030405' }, $order5->{biblionumber} );
524
$error = DelOrder($order5->{biblionumber}, $order5->{ordernumber}, 1);
525
$order5 = GetOrder($order5->{ordernumber});
526
ok((defined $order5->{datecancellationprinted}), "order is cancelled");
527
ok(GetBiblio($order5->{biblionumber}), "biblio still exists");
528
500
# End of tests for DelOrder
529
# End of tests for DelOrder
501
530
502
subtest 'ModOrder' => sub {
531
subtest 'ModOrder' => sub {
(-)a/tools/batchMod.pl (-2 / +3 lines)
Lines 34-39 use C4::Debug; Link Here
34
use C4::Members;
34
use C4::Members;
35
use MARC::File::XML;
35
use MARC::File::XML;
36
use List::MoreUtils qw/uniq/;
36
use List::MoreUtils qw/uniq/;
37
38
use Koha::Biblios;
37
use Koha::DateUtils;
39
use Koha::DateUtils;
38
40
39
my $input = new CGI;
41
my $input = new CGI;
Lines 181-187 if ($op eq "action") { Link Here
181
183
182
			# If there are no items left, delete the biblio
184
			# If there are no items left, delete the biblio
183
			if ( $del_records ) {
185
			if ( $del_records ) {
184
                            my $itemscount = GetItemsCount($itemdata->{'biblionumber'});
186
                            my $itemscount = Koha::Biblios->find( $itemdata->{'biblionumber'} )->items->count;
185
                            if ( $itemscount == 0 ) {
187
                            if ( $itemscount == 0 ) {
186
			        my $error = DelBiblio($itemdata->{'biblionumber'});
188
			        my $error = DelBiblio($itemdata->{'biblionumber'});
187
			        $deleted_records++ unless ( $error );
189
			        $deleted_records++ unless ( $error );
188
- 

Return to bug 18256