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

(-)a/C4/Acquisition.pm (-9 / +12 lines)
Lines 2450-2455 sub AddClaim { Link Here
2450
2450
2451
    my @invoices = GetInvoices(
2451
    my @invoices = GetInvoices(
2452
        invoicenumber => $invoicenumber,
2452
        invoicenumber => $invoicenumber,
2453
        supplierid => $supplierid,
2453
        suppliername => $suppliername,
2454
        suppliername => $suppliername,
2454
        shipmentdatefrom => $shipmentdatefrom, # ISO format
2455
        shipmentdatefrom => $shipmentdatefrom, # ISO format
2455
        shipmentdateto => $shipmentdateto, # ISO format
2456
        shipmentdateto => $shipmentdateto, # ISO format
Lines 2494-2499 sub GetInvoices { Link Here
2494
        FROM aqinvoices
2495
        FROM aqinvoices
2495
          LEFT JOIN aqbooksellers ON aqbooksellers.id = aqinvoices.booksellerid
2496
          LEFT JOIN aqbooksellers ON aqbooksellers.id = aqinvoices.booksellerid
2496
          LEFT JOIN aqorders ON aqorders.invoiceid = aqinvoices.invoiceid
2497
          LEFT JOIN aqorders ON aqorders.invoiceid = aqinvoices.invoiceid
2498
          LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
2499
          LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
2497
          LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber
2500
          LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber
2498
          LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
2501
          LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
2499
          LEFT JOIN subscription ON biblio.biblionumber = subscription.biblionumber
2502
          LEFT JOIN subscription ON biblio.biblionumber = subscription.biblionumber
Lines 2514-2524 sub GetInvoices { Link Here
2514
        push @bind_args, "%$args{suppliername}%";
2517
        push @bind_args, "%$args{suppliername}%";
2515
    }
2518
    }
2516
    if($args{shipmentdatefrom}) {
2519
    if($args{shipmentdatefrom}) {
2517
        push @bind_strs, " aqinvoices.shipementdate >= ? ";
2520
        push @bind_strs, " aqinvoices.shipmentdate >= ? ";
2518
        push @bind_args, $args{shipmentdatefrom};
2521
        push @bind_args, $args{shipmentdatefrom};
2519
    }
2522
    }
2520
    if($args{shipmentdateto}) {
2523
    if($args{shipmentdateto}) {
2521
        push @bind_strs, " aqinvoices.shipementdate <= ? ";
2524
        push @bind_strs, " aqinvoices.shipmentdate <= ? ";
2522
        push @bind_args, $args{shipmentdateto};
2525
        push @bind_args, $args{shipmentdateto};
2523
    }
2526
    }
2524
    if($args{billingdatefrom}) {
2527
    if($args{billingdatefrom}) {
Lines 2530-2556 sub GetInvoices { Link Here
2530
        push @bind_args, $args{billingdateto};
2533
        push @bind_args, $args{billingdateto};
2531
    }
2534
    }
2532
    if($args{isbneanissn}) {
2535
    if($args{isbneanissn}) {
2533
        push @bind_strs, " (biblioitems.isbn LIKE ? OR biblioitems.ean LIKE ? OR biblioitems.issn LIKE ? ) ";
2536
        push @bind_strs, " (biblioitems.isbn LIKE CONCAT('%', ?, '%') OR biblioitems.ean LIKE CONCAT('%', ?, '%') OR biblioitems.issn LIKE CONCAT('%', ?, '%') ) ";
2534
        push @bind_args, $args{isbneanissn}, $args{isbneanissn}, $args{isbneanissn};
2537
        push @bind_args, $args{isbneanissn}, $args{isbneanissn}, $args{isbneanissn};
2535
    }
2538
    }
2536
    if($args{title}) {
2539
    if($args{title}) {
2537
        push @bind_strs, " biblio.title LIKE ? ";
2540
        push @bind_strs, " biblio.title LIKE CONCAT('%', ?, '%') ";
2538
        push @bind_args, $args{title};
2541
        push @bind_args, $args{title};
2539
    }
2542
    }
2540
    if($args{author}) {
2543
    if($args{author}) {
2541
        push @bind_strs, " biblio.author LIKE ? ";
2544
        push @bind_strs, " biblio.author LIKE CONCAT('%', ?, '%') ";
2542
        push @bind_args, $args{author};
2545
        push @bind_args, $args{author};
2543
    }
2546
    }
2544
    if($args{publisher}) {
2547
    if($args{publisher}) {
2545
        push @bind_strs, " biblioitems.publishercode LIKE ? ";
2548
        push @bind_strs, " biblioitems.publishercode LIKE CONCAT('%', ?, '%') ";
2546
        push @bind_args, $args{publisher};
2549
        push @bind_args, $args{publisher};
2547
    }
2550
    }
2548
    if($args{publicationyear}) {
2551
    if($args{publicationyear}) {
2549
        push @bind_strs, " biblioitems.publicationyear = ? ";
2552
        push @bind_strs, " ((biblioitems.publicationyear LIKE CONCAT('%', ?, '%')) OR (biblio.copyrightdate LIKE CONCAT('%', ?, '%'))) ";
2550
        push @bind_args, $args{publicationyear};
2553
        push @bind_args, $args{publicationyear}, $args{publicationyear};
2551
    }
2554
    }
2552
    if($args{branchcode}) {
2555
    if($args{branchcode}) {
2553
        push @bind_strs, " aqorders.branchcode = ? ";
2556
        push @bind_strs, " borrowers.branchcode = ? ";
2554
        push @bind_args, $args{branchcode};
2557
        push @bind_args, $args{branchcode};
2555
    }
2558
    }
2556
2559
(-)a/t/Acquisition/Invoice.t (-7 / +8 lines)
Lines 3-13 Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
use C4::Context;
4
use C4::Context;
5
5
6
use Test::More tests => 49;
6
use Test::More tests => 50;
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-50 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), 16);
48
is($bound_params[0], 'supplierid');
48
is($bound_params[0], 'supplierid');
49
is($bound_params[1], '%invoicenumber%');
49
is($bound_params[1], '%invoicenumber%');
50
is($bound_params[2], '%suppliername%');
50
is($bound_params[2], '%suppliername%');
Lines 59-65 is($bound_params[10], 'title'); Link Here
59
is($bound_params[11], 'author');
59
is($bound_params[11], 'author');
60
is($bound_params[12], 'publisher');
60
is($bound_params[12], 'publisher');
61
is($bound_params[13], 'publicationyear');
61
is($bound_params[13], 'publicationyear');
62
is($bound_params[14], 'branchcode');
62
is($bound_params[14], 'publicationyear');
63
is($bound_params[15], 'branchcode');
63
64
64
$dbh->{mock_clear_history} = 1;
65
$dbh->{mock_clear_history} = 1;
65
$dbh->{mock_add_resultset} = $rs;
66
$dbh->{mock_add_resultset} = $rs;
(-)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