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::Order;
31
use Koha::Acquisition::Order;
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 1851-1857 sub DelOrder { Link Here
1851
1852
1852
    if($delete_biblio) {
1853
    if($delete_biblio) {
1853
        # We get the number of remaining items
1854
        # We get the number of remaining items
1854
        my $itemcount = C4::Items::GetItemsCount($bibnum);
1855
        my $biblio = Koha::Biblios->find( $bibnum );
1856
        my $itemcount = $biblio->items->count;
1855
1857
1856
        # If there are no items left,
1858
        # If there are no items left,
1857
        if ( $itemcount == 0 ) {
1859
        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->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 257-267 my @order_content = ( Link Here
257
            uncertainprice => 0,
258
            uncertainprice => 0,
258
            tax_rate        => 0
259
            tax_rate        => 0
259
        }
260
        }
261
    },
262
    {
263
        str => {
264
            basketno     => $basketno,
265
            biblionumber => $biblionumber5,
266
            budget_id    => $budget->{budget_id},
267
            order_internalnote => "internal note",
268
            order_vendornote   => "vendor note"
269
        },
270
        num => {
271
            quantity       => 1,
272
            ecost          => 10,
273
            rrp            => 10,
274
            listprice      => 10,
275
            ecost          => 10,
276
            rrp            => 10,
277
            discount       => 0,
278
            uncertainprice => 0,
279
            tax_rate        => 0
280
        }
260
    }
281
    }
261
);
282
);
262
283
263
# Create 4 orders in database
284
# Create 5 orders in database
264
for ( 0 .. 4 ) {
285
for ( 0 .. 5 ) {
265
    my %ocontent;
286
    my %ocontent;
266
    @ocontent{ keys %{ $order_content[$_]->{num} } } =
287
    @ocontent{ keys %{ $order_content[$_]->{num} } } =
267
      values %{ $order_content[$_]->{num} };
288
      values %{ $order_content[$_]->{num} };
Lines 298-304 my $search_orders = SearchOrders({ Link Here
298
isa_ok( $search_orders, 'ARRAY' );
319
isa_ok( $search_orders, 'ARRAY' );
299
ok(
320
ok(
300
    (
321
    (
301
        ( scalar @$search_orders == 4 )
322
        ( scalar @$search_orders == 5 )
302
          and !grep ( $_->{ordernumber} eq $ordernumbers[3], @$search_orders )
323
          and !grep ( $_->{ordernumber} eq $ordernumbers[3], @$search_orders )
303
    ),
324
    ),
304
    "SearchOrders only gets non-cancelled orders"
325
    "SearchOrders only gets non-cancelled orders"
Lines 311-317 $search_orders = SearchOrders({ Link Here
311
});
332
});
312
ok(
333
ok(
313
    (
334
    (
314
        ( scalar @$search_orders == 3 ) and !grep ( (
335
        ( scalar @$search_orders == 4 ) and !grep ( (
315
                     ( $_->{ordernumber} eq $ordernumbers[3] )
336
                     ( $_->{ordernumber} eq $ordernumbers[3] )
316
                  or ( $_->{ordernumber} eq $ordernumbers[4] )
337
                  or ( $_->{ordernumber} eq $ordernumbers[4] )
317
            ),
338
            ),
Lines 368-374 $search_orders = SearchOrders({ Link Here
368
    pending      => 1,
389
    pending      => 1,
369
    ordered      => 1,
390
    ordered      => 1,
370
});
391
});
371
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)" );
392
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)" );
372
393
373
#
394
#
374
# Test AddClaim
395
# Test AddClaim
Lines 498-503 $order4 = GetOrder($order4->{ordernumber}); Link Here
498
ok((defined $order4->{datecancellationprinted}), "order is cancelled");
519
ok((defined $order4->{datecancellationprinted}), "order is cancelled");
499
ok(($order4->{cancellationreason} eq "foobar"), "order has cancellation reason \"foobar\"");
520
ok(($order4->{cancellationreason} eq "foobar"), "order has cancellation reason \"foobar\"");
500
ok((not defined GetBiblio($order4->{biblionumber})), "biblio does not exist anymore");
521
ok((not defined GetBiblio($order4->{biblionumber})), "biblio does not exist anymore");
522
523
my $order5 = GetOrder($ordernumbers[4]);
524
C4::Items::AddItem( { barcode => '0102030405' }, $order5->{biblionumber} );
525
$error = DelOrder($order5->{biblionumber}, $order5->{ordernumber}, 1);
526
$order5 = GetOrder($order5->{ordernumber});
527
ok((defined $order5->{datecancellationprinted}), "order is cancelled");
528
ok(GetBiblio($order5->{biblionumber}), "biblio still exists");
529
501
# End of tests for DelOrder
530
# End of tests for DelOrder
502
531
503
subtest 'ModOrder' => sub {
532
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