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

(-)a/C4/Acquisition.pm (-9 / +12 lines)
Lines 2278-2283 sub AddClaim { Link Here
2278
2278
2279
    my @invoices = GetInvoices(
2279
    my @invoices = GetInvoices(
2280
        invoicenumber => $invoicenumber,
2280
        invoicenumber => $invoicenumber,
2281
        supplierid => $supplierid,
2281
        suppliername => $suppliername,
2282
        suppliername => $suppliername,
2282
        shipmentdatefrom => $shipmentdatefrom, # ISO format
2283
        shipmentdatefrom => $shipmentdatefrom, # ISO format
2283
        shipmentdateto => $shipmentdateto, # ISO format
2284
        shipmentdateto => $shipmentdateto, # ISO format
Lines 2322-2327 sub GetInvoices { Link Here
2322
        FROM aqinvoices
2323
        FROM aqinvoices
2323
          LEFT JOIN aqbooksellers ON aqbooksellers.id = aqinvoices.booksellerid
2324
          LEFT JOIN aqbooksellers ON aqbooksellers.id = aqinvoices.booksellerid
2324
          LEFT JOIN aqorders ON aqorders.invoiceid = aqinvoices.invoiceid
2325
          LEFT JOIN aqorders ON aqorders.invoiceid = aqinvoices.invoiceid
2326
          LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
2327
          LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
2325
          LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber
2328
          LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber
2326
          LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
2329
          LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
2327
          LEFT JOIN subscription ON biblio.biblionumber = subscription.biblionumber
2330
          LEFT JOIN subscription ON biblio.biblionumber = subscription.biblionumber
Lines 2342-2352 sub GetInvoices { Link Here
2342
        push @bind_args, "%$args{suppliername}%";
2345
        push @bind_args, "%$args{suppliername}%";
2343
    }
2346
    }
2344
    if($args{shipmentdatefrom}) {
2347
    if($args{shipmentdatefrom}) {
2345
        push @bind_strs, " aqinvoices.shipementdate >= ? ";
2348
        push @bind_strs, " aqinvoices.shipmentdate >= ? ";
2346
        push @bind_args, $args{shipmentdatefrom};
2349
        push @bind_args, $args{shipmentdatefrom};
2347
    }
2350
    }
2348
    if($args{shipmentdateto}) {
2351
    if($args{shipmentdateto}) {
2349
        push @bind_strs, " aqinvoices.shipementdate <= ? ";
2352
        push @bind_strs, " aqinvoices.shipmentdate <= ? ";
2350
        push @bind_args, $args{shipmentdateto};
2353
        push @bind_args, $args{shipmentdateto};
2351
    }
2354
    }
2352
    if($args{billingdatefrom}) {
2355
    if($args{billingdatefrom}) {
Lines 2358-2384 sub GetInvoices { Link Here
2358
        push @bind_args, $args{billingdateto};
2361
        push @bind_args, $args{billingdateto};
2359
    }
2362
    }
2360
    if($args{isbneanissn}) {
2363
    if($args{isbneanissn}) {
2361
        push @bind_strs, " (biblioitems.isbn LIKE ? OR biblioitems.ean LIKE ? OR biblioitems.issn LIKE ? ) ";
2364
        push @bind_strs, " (biblioitems.isbn LIKE CONCAT('%', ?, '%') OR biblioitems.ean LIKE CONCAT('%', ?, '%') OR biblioitems.issn LIKE CONCAT('%', ?, '%') ) ";
2362
        push @bind_args, $args{isbneanissn}, $args{isbneanissn}, $args{isbneanissn};
2365
        push @bind_args, $args{isbneanissn}, $args{isbneanissn}, $args{isbneanissn};
2363
    }
2366
    }
2364
    if($args{title}) {
2367
    if($args{title}) {
2365
        push @bind_strs, " biblio.title LIKE ? ";
2368
        push @bind_strs, " biblio.title LIKE CONCAT('%', ?, '%') ";
2366
        push @bind_args, $args{title};
2369
        push @bind_args, $args{title};
2367
    }
2370
    }
2368
    if($args{author}) {
2371
    if($args{author}) {
2369
        push @bind_strs, " biblio.author LIKE ? ";
2372
        push @bind_strs, " biblio.author LIKE CONCAT('%', ?, '%') ";
2370
        push @bind_args, $args{author};
2373
        push @bind_args, $args{author};
2371
    }
2374
    }
2372
    if($args{publisher}) {
2375
    if($args{publisher}) {
2373
        push @bind_strs, " biblioitems.publishercode LIKE ? ";
2376
        push @bind_strs, " biblioitems.publishercode LIKE CONCAT('%', ?, '%') ";
2374
        push @bind_args, $args{publisher};
2377
        push @bind_args, $args{publisher};
2375
    }
2378
    }
2376
    if($args{publicationyear}) {
2379
    if($args{publicationyear}) {
2377
        push @bind_strs, " biblioitems.publicationyear = ? ";
2380
        push @bind_strs, " ((biblioitems.publicationyear LIKE CONCAT('%', ?, '%')) OR (biblio.copyrightdate LIKE CONCAT('%', ?, '%'))) ";
2378
        push @bind_args, $args{publicationyear};
2381
        push @bind_args, $args{publicationyear}, $args{publicationyear};
2379
    }
2382
    }
2380
    if($args{branchcode}) {
2383
    if($args{branchcode}) {
2381
        push @bind_strs, " aqorders.branchcode = ? ";
2384
        push @bind_strs, " borrowers.branchcode = ? ";
2382
        push @bind_args, $args{branchcode};
2385
        push @bind_args, $args{branchcode};
2383
    }
2386
    }
2384
2387
(-)a/t/Acquisition/Invoice.t (-4 / +4 lines)
Lines 6-13 use C4::Context; Link Here
6
use Test::More tests => 49;
6
use Test::More tests => 49;
7
use Test::MockModule;
7
use Test::MockModule;
8
8
9
use_ok('C4::Acquisition');
10
11
my $module = new Test::MockModule('C4::Context');
9
my $module = new Test::MockModule('C4::Context');
12
$module->mock('_new_dbh', sub {
10
$module->mock('_new_dbh', sub {
13
    my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
11
    my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
Lines 17-22 $module->mock('_new_dbh', sub { Link Here
17
15
18
my $dbh = C4::Context->dbh;
16
my $dbh = C4::Context->dbh;
19
17
18
use_ok('C4::Acquisition');
19
20
# We need to add a resultset to avoid DBI fail
20
# We need to add a resultset to avoid DBI fail
21
# ("DBI bind_columns: invalid number of arguments...")
21
# ("DBI bind_columns: invalid number of arguments...")
22
my $rs = [
22
my $rs = [
Lines 42-49 my @invoices = C4::Acquisition::GetInvoices( Link Here
42
);
42
);
43
my $history = $dbh->{mock_all_history};
43
my $history = $dbh->{mock_all_history};
44
44
45
is(scalar(@$history), 1);
45
ok(scalar(@$history) > 0);
46
my @bound_params = @{ $history->[0]->{bound_params} };
46
my @bound_params = @{ $history->[-1]->{bound_params} };
47
is(scalar(@bound_params), 15);
47
is(scalar(@bound_params), 15);
48
is($bound_params[0], 'supplierid');
48
is($bound_params[0], 'supplierid');
49
is($bound_params[1], '%invoicenumber%');
49
is($bound_params[1], '%invoicenumber%');
(-)a/t/db_dependent/Acquisition/Invoices.t (-4 / +29 lines)
Lines 9-15 use warnings; Link Here
9
use C4::Bookseller qw( GetBookSellerFromId );
9
use C4::Bookseller qw( GetBookSellerFromId );
10
use C4::Biblio qw( AddBiblio );
10
use C4::Biblio qw( AddBiblio );
11
11
12
use Test::More tests => 14;
12
use Test::More tests => 21;
13
13
14
BEGIN {
14
BEGIN {
15
    use_ok('C4::Acquisition');
15
    use_ok('C4::Acquisition');
Lines 19-24 my $dbh = C4::Context->dbh; Link Here
19
$dbh->{AutoCommit} = 0;
19
$dbh->{AutoCommit} = 0;
20
$dbh->{RaiseError} = 1;
20
$dbh->{RaiseError} = 1;
21
21
22
$dbh->do(q{DELETE FROM aqinvoices});
23
22
my $booksellerid = C4::Bookseller::AddBookseller(
24
my $booksellerid = C4::Bookseller::AddBookseller(
23
    {
25
    {
24
        name => "my vendor",
26
        name => "my vendor",
Lines 41-47 my $budgetid = C4::Budgets::AddBudget( Link Here
41
my $budget = C4::Budgets::GetBudget( $budgetid );
43
my $budget = C4::Budgets::GetBudget( $budgetid );
42
44
43
my ($ordernumber1, $ordernumber2, $ordernumber3);
45
my ($ordernumber1, $ordernumber2, $ordernumber3);
44
my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, '');
46
my $bibrec1 = MARC::Record->new();
47
$bibrec1->append_fields(
48
    MARC::Field->new('020', '', '', 'a' => '1234567890'),
49
    MARC::Field->new('100', '', '', 'a' => 'Shakespeare,  Billy'),
50
    MARC::Field->new('245', '', '', 'a' => 'Bug 8854'),
51
    MARC::Field->new('260', '', '', 'b' => 'Scholastic Publishing', c => 'c2012'),
52
);
53
my ($biblionumber1, $biblioitemnumber1) = AddBiblio($bibrec1, '');
45
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, '');
54
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, '');
46
my ($biblionumber3, $biblioitemnumber3) = AddBiblio(MARC::Record->new, '');
55
my ($biblionumber3, $biblioitemnumber3) = AddBiblio(MARC::Record->new, '');
47
( undef, $ordernumber1 ) = C4::Acquisition::NewOrder(
56
( undef, $ordernumber1 ) = C4::Acquisition::NewOrder(
Lines 74-80 my ($biblionumber3, $biblioitemnumber3) = AddBiblio(MARC::Record->new, ''); Link Here
74
);
83
);
75
84
76
my $invoiceid1 = AddInvoice(invoicenumber => 'invoice1', booksellerid => $booksellerid, unknown => "unknown");
85
my $invoiceid1 = AddInvoice(invoicenumber => 'invoice1', booksellerid => $booksellerid, unknown => "unknown");
77
my $invoiceid2 = AddInvoice(invoicenumber => 'invoice2', booksellerid => $booksellerid, unknown => "unknown");
86
my $invoiceid2 = AddInvoice(invoicenumber => 'invoice2', booksellerid => $booksellerid, unknown => "unknown",
87
                            shipmentdate => '2012-12-24',
88
                           );
78
89
79
my ($datereceived, $new_ordernumber) = ModReceiveOrder(
90
my ($datereceived, $new_ordernumber) = ModReceiveOrder(
80
    $biblionumber1,
91
    $biblionumber1,
Lines 122-127 cmp_ok(scalar @invoices, '>=', 2, 'GetInvoices returns at least two invoices'); Link Here
122
@invoices = GetInvoices(invoicenumber => 'invoice2');
133
@invoices = GetInvoices(invoicenumber => 'invoice2');
123
cmp_ok(scalar @invoices, '>=', 1, 'GetInvoices returns at least one invoice when a specific invoice is requested');
134
cmp_ok(scalar @invoices, '>=', 1, 'GetInvoices returns at least one invoice when a specific invoice is requested');
124
135
136
@invoices = GetInvoices(shipmentdateto => '2012-12-24', shipmentdatefrom => '2012-12-24');
137
is($invoices[0]->{invoicenumber}, 'invoice2', 'GetInvoices() to search by shipmentdate works (bug 8854)');
138
@invoices = GetInvoices(title => 'Bug');
139
is($invoices[0]->{invoicenumber}, 'invoice1', 'GetInvoices() to search by title works (bug 8854)');
140
@invoices = GetInvoices(author => 'Billy');
141
is($invoices[0]->{invoicenumber}, 'invoice1', 'GetInvoices() to search by author works (bug 8854)');
142
@invoices = GetInvoices(publisher => 'Scholastic');
143
is($invoices[0]->{invoicenumber}, 'invoice1', 'GetInvoices() to search by publisher works (bug 8854)');
144
@invoices = GetInvoices(publicationyear => '2012');
145
is($invoices[0]->{invoicenumber}, 'invoice1', 'GetInvoices() to search by publication/copyright year works (bug 8854)');
146
@invoices = GetInvoices(isbneanissn => '1234567890');
147
is($invoices[0]->{invoicenumber}, 'invoice1', 'GetInvoices() to search by ISBN works (bug 8854)');
148
@invoices = GetInvoices(isbneanissn => '123456789');
149
is($invoices[0]->{invoicenumber}, 'invoice1', 'GetInvoices() to search by partial ISBN works (bug 8854)');
150
125
my $invoicesummary1 = GetInvoice($invoiceid1);
151
my $invoicesummary1 = GetInvoice($invoiceid1);
126
is($invoicesummary1->{'invoicenumber'}, 'invoice1', 'GetInvoice retrieves correct invoice');
152
is($invoicesummary1->{'invoicenumber'}, 'invoice1', 'GetInvoice retrieves correct invoice');
127
is($invoicesummary1->{'invoicenumber'}, $invoice1->{'invoicenumber'}, 'GetInvoice and GetInvoiceDetails retrieve same information');
153
is($invoicesummary1->{'invoicenumber'}, $invoice1->{'invoicenumber'}, 'GetInvoice and GetInvoiceDetails retrieve same information');
128
- 

Return to bug 8854