Merge remote-tracking branch 'origin/new/bug_5339'

This commit is contained in:
Paul Poulain 2012-09-20 10:19:44 +02:00
commit a42e5e6d3e
6 changed files with 188 additions and 47 deletions

View file

@ -2204,11 +2204,11 @@ sub GetInvoices {
}
if($args{shipmentdatefrom}) {
push @bind_strs, " aqinvoices.shipementdate >= ? ";
push @bind_args, $args{shipementdatefrom};
push @bind_args, $args{shipmentdatefrom};
}
if($args{shipmentdateto}) {
push @bind_strs, " aqinvoices.shipementdate <= ? ";
push @bind_args, $args{shipementdateto};
push @bind_args, $args{shipmentdateto};
}
if($args{billingdatefrom}) {
push @bind_strs, " aqinvoices.billingdate >= ? ";

View file

@ -79,6 +79,11 @@ elsif ( $op && $op eq 'mod' ) {
shipmentcost => $shipmentcost,
shipmentcost_budgetid => $shipment_budget_id
);
if ($input->param('reopen')) {
ReopenInvoice($invoiceid);
} elsif ($input->param('close')) {
CloseInvoice($invoiceid);
}
$template->param( modified => 1 );
}

View file

@ -42,46 +42,48 @@
<p>Supplier: [% suppliername %]</p>
<form action="" method="post">
<label for="shipmentdate">Shipment date:</label>
<input type="text" size="10" id="shipmentdate" name="shipmentdate" value="[% shipmentdate | $KohaDates %]" readonly="readonly" class="datepicker" />
<p></p>
<label for="billingdate">Billing date:</label>
<input type="text" size="10" id="billingdate" name="billingdate" value="[% billingdate | $KohaDates %]" readonly="readonly" class="datepicker" />
<p></p>
<label for="shipmentcost">Shipment cost:</label>
<input type="text" size="10" id="shipmentcost" name="shipmentcost" value="[% shipmentcost %]" />
<label for="shipment_budget_id">Budget:</label>
<select id="shipment_budget_id" name="shipment_budget_id">
<option value="">No budget</option>
[% FOREACH budget IN budgets_loop %]
[% IF ( budget.selected ) %]
<option selected="selected" value="[% budget.budget_id %]">
[% ELSE %]
<option value="[% budget.budget_id %]">
<fieldset>
<label for="shipmentdate">Shipment date:</label>
<input type="text" size="10" id="shipmentdate" name="shipmentdate" value="[% shipmentdate | $KohaDates %]" readonly="readonly" class="datepicker" />
<p></p>
<label for="billingdate">Billing date:</label>
<input type="text" size="10" id="billingdate" name="billingdate" value="[% billingdate | $KohaDates %]" readonly="readonly" class="datepicker" />
<p></p>
<label for="shipmentcost">Shipment cost:</label>
<input type="text" size="10" id="shipmentcost" name="shipmentcost" value="[% shipmentcost %]" />
<label for="shipment_budget_id">Budget:</label>
<select id="shipment_budget_id" name="shipment_budget_id">
<option value="">No budget</option>
[% FOREACH budget IN budgets_loop %]
[% IF ( budget.selected ) %]
<option selected="selected" value="[% budget.budget_id %]">
[% ELSE %]
<option value="[% budget.budget_id %]">
[% END %]
[% budget.budget_name %]
</option>
[% END %]
[% budget.budget_name %]
</option>
</select>
<p></p>
<label>Status:</label>
[% IF ( invoiceclosedate ) %]
Closed on [% invoiceclosedate | $KohaDates %].
<p></p>
<input type="checkbox" name="reopen" id="reopen" />
<label for="reopen">Reopen</label>
[% ELSE %]
Open.
<p></p>
<input type="checkbox" name="close" id="close" />
<label for="close">Close</label>
[% END %]
</select>
<input type="hidden" name="op" value="mod" />
<input type="hidden" name="invoiceid" value="[% invoiceid %]" />
<fieldset class="action">
<input type="submit" value="Save">
<input type="hidden" name="op" value="mod" />
<input type="hidden" name="invoiceid" value="[% invoiceid %]" />
<fieldset class="action">
<input type="submit" value="Save">
</fieldset>
</fieldset>
</form>
<p>Status:
[% IF ( invoiceclosedate ) %]
Closed on [% invoiceclosedate | $KohaDates %].
<a href="/cgi-bin/koha/acqui/invoice.pl?op=reopen&invoiceid=[% invoiceid %]">
Reopen
</a>
[% ELSE %]
Open.
<a href="/cgi-bin/koha/acqui/invoice.pl?op=close&invoiceid=[% invoiceid %]">
Close
</a>
[% END %]
</p>
<p>
<a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid %]">Go to receipt page</a>
</p>

View file

@ -192,7 +192,6 @@
<div id="acqui_receive_summary">
<p><strong>Invoice number:</strong> [% invoice %] <strong>Received by:</strong> [% loggedinusername %] <strong>On:</strong> [% formatteddatereceived %]</p>
<p><a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoiceid %]">Go to invoice details</a></p>
</div>
[% UNLESS (invoiceclosedate) %]
<div id="acqui_receive_search">
@ -298,7 +297,7 @@
</div>
[% ELSE %]
<p>
Invoice is close, so you can't receive orders.
Invoice is closed, so you can't receive orders anymore.
<a href="/cgi-bin/koha/acqui/invoice.pl?op=reopen&invoiceid=[% invoiceid %]&referer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid %]">Reopen it</a>.
</p>
[% END %]
@ -405,12 +404,16 @@
</div>
<!--<form action="/cgi-bin/koha/acqui/parcels.pl?booksellerid=[% booksellerid %]" method="post">-->
<form action="parcels.pl?booksellerid=[% booksellerid %]" method="post">
<input type="hidden" name="booksellerid" value="[% booksellerid %]" />
<fieldset class="action">
<input type="submit" value="Finish receiving" />
</fieldset>
</form>
[% IF (invoiceclosedate) %]
<a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoiceid %]">View invoice</a>
[% ELSE %]
<form action="/cgi-bin/koha/acqui/invoice.pl" method="get">
<input type="hidden" name="invoiceid" value="[% invoiceid %]" />
<fieldset class="action">
<input type="submit" value="Finish receiving" />
</fieldset>
</form>
[% END %]
</div>
</div>

131
t/Acquisition/Invoice.t Executable file
View file

@ -0,0 +1,131 @@
#!/usr/bin/perl
use Modern::Perl;
use C4::Context;
use Test::More tests => 47;
use Test::MockModule;
use_ok('C4::Acquisition');
my $module = new Test::MockModule('C4::Context');
$module->mock('_new_dbh', sub {
my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
|| die "Cannot create handle: $DBI::errstr\n";
return $dbh;
});
my $dbh = C4::Context->dbh;
# We need to add a resultset to avoid DBI fail
# ("DBI bind_columns: invalid number of arguments...")
my $rs = [
[qw(one two three four)],
[1, 2, 3, 4]
];
$dbh->{mock_add_resultset} = $rs;
my @invoices = C4::Acquisition::GetInvoices(
supplierid => "supplierid",
invoicenumber => "invoicenumber",
suppliername => "suppliername",
shipmentdatefrom => "shipmentdatefrom",
shipmentdateto => "shipmentdateto",
billingdatefrom => "billingdatefrom",
billingdateto => "billingdateto",
isbneanissn => "isbneanissn",
title => "title",
author => "author",
publisher => "publisher",
publicationyear => "publicationyear",
branchcode => "branchcode",
);
my $history = $dbh->{mock_all_history};
is(scalar(@$history), 1);
my @bound_params = @{ $history->[0]->{bound_params} };
is(scalar(@bound_params), 15);
is($bound_params[0], 'supplierid');
is($bound_params[1], '%invoicenumber%');
is($bound_params[2], '%suppliername%');
is($bound_params[3], 'shipmentdatefrom');
is($bound_params[4], 'shipmentdateto');
is($bound_params[5], 'billingdatefrom');
is($bound_params[6], 'billingdateto');
is($bound_params[7], 'isbneanissn');
is($bound_params[8], 'isbneanissn');
is($bound_params[9], 'isbneanissn');
is($bound_params[10], 'title');
is($bound_params[11], 'author');
is($bound_params[12], 'publisher');
is($bound_params[13], 'publicationyear');
is($bound_params[14], 'branchcode');
$dbh->{mock_clear_history} = 1;
$dbh->{mock_add_resultset} = $rs;
GetInvoice(42);
$history = $dbh->{mock_all_history};
is(scalar(@$history), 1);
@bound_params = @{ $history->[0]->{bound_params} };
is(scalar(@bound_params), 1);
is($bound_params[0], 42);
$dbh->{mock_clear_history} = 1;
$dbh->{mock_add_resultset} = $rs;
$dbh->{mock_add_resultset} = $rs;
my $invoice = GetInvoiceDetails(42);
$history = $dbh->{mock_all_history};
is(scalar(@$history), 2);
@bound_params = @{ $history->[0]->{bound_params} };
is(scalar(@bound_params), 1);
is($bound_params[0], 42);
@bound_params = @{ $history->[1]->{bound_params} };
is(scalar(@bound_params), 1);
is($bound_params[0], 42);
ok(exists $invoice->{orders});
$dbh->{mock_clear_history} = 1;
is(AddInvoice(booksellerid => 1), undef); # Fails because of a missing parameter
$history = $dbh->{mock_all_history};
is(scalar(@$history), 0);
$dbh->{mock_clear_history} = 1;
AddInvoice(invoicenumber => 'invoice', booksellerid => 1, unknown => "unknown");
$history = $dbh->{mock_all_history};
is(scalar(@$history), 1);
@bound_params = @{ $history->[0]->{bound_params} };
is(scalar(@bound_params), 2);
ok(grep /^1$/, @bound_params);
ok(grep /^invoice$/, @bound_params);
ok(not grep /unknown/, @bound_params);
$dbh->{mock_clear_history} = 1;
is(ModInvoice(booksellerid => 1), undef); # Fails because of a missing parameter
$history = $dbh->{mock_all_history};
is(scalar(@$history), 0);
$dbh->{mock_clear_history} = 1;
ModInvoice(invoiceid => 3, invoicenumber => 'invoice', unknown => "unknown");
$history = $dbh->{mock_all_history};
is(scalar(@$history), 1);
@bound_params = @{ $history->[0]->{bound_params} };
is(scalar(@bound_params), 2);
ok(grep /^3$/, @bound_params);
ok(grep /^invoice$/, @bound_params);
ok(not grep /unknown/, @bound_params);
$dbh->{mock_clear_history} = 1;
CloseInvoice(42);
$history = $dbh->{mock_all_history};
is(scalar(@$history), 1);
@bound_params = @{ $history->[0]->{bound_params} };
is(scalar(@bound_params), 1);
is($bound_params[0], 42);
$dbh->{mock_clear_history} = 1;
ReopenInvoice(42);
$history = $dbh->{mock_all_history};
is(scalar(@$history), 1);
@bound_params = @{ $history->[0]->{bound_params} };
is(scalar(@bound_params), 1);
is($bound_params[0], 42);

View file

@ -47,7 +47,7 @@ SKIP: {
my @expectedfields = qw( basketno
biblioitemnumber
biblionumber
booksellerinvoicenumber
invoiceid
budgetdate
cancelledby
closedate