&ModInvoice
&CloseInvoice
&ReopenInvoice
+ &DelInvoice
&GetItemnumbersFromOrder
$sth->execute($invoiceid);
}
+=head3 DelInvoice
+
+ DelInvoice($invoiceid);
+
+Delete an invoice if there are no items attached to it.
+
+=cut
+
+sub DelInvoice {
+ my ($invoiceid) = @_;
+
+ return unless $invoiceid;
+
+ my $dbh = C4::Context->dbh;
+ my $query = qq{
+ SELECT COUNT(*)
+ FROM aqorders
+ WHERE invoiceid = ?
+ };
+ my $sth = $dbh->prepare($query);
+ $sth->execute($invoiceid);
+ my $res = $sth->fetchrow_arrayref;
+ if ( $res && $res->[0] == 0 ) {
+ $query = qq{
+ DELETE FROM aqinvoices
+ WHERE invoiceid = ?
+ };
+ my $sth = $dbh->prepare($query);
+ return ( $sth->execute($invoiceid) > 0 );
+ }
+ return;
+}
+
1;
__END__
}
$template->param( modified => 1 );
}
+elsif ( $op && $op eq 'delete' ) {
+ DelInvoice($invoiceid);
+ my $referer = $input->param('referer') || 'invoices.pl';
+ if ($referer) {
+ print $input->redirect($referer);
+ exit 0;
+ }
+}
my $details = GetInvoiceDetails($invoiceid);
my $bookseller = GetBookSellerFromId( $details->{booksellerid} );
</fieldset>
<fieldset class="action">
<input type="submit" value="Save" />
+ [% UNLESS orders_loop.size %]
+ <a href="invoice.pl?op=delete&invoiceid=[% invoiceid %]">Delete</a>
+ [% END %]
</fieldset>
</form>
<p>
[% ELSE %]
<a href="invoice.pl?op=close&invoiceid=[% invoice.invoiceid %]&referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% booksellerid %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]">Close</a>
[% END %]
+ [% UNLESS invoice.receivedbiblios || invoice.receiveditems %]
+ / <a href="invoice.pl?op=delete&invoiceid=[% invoice.invoiceid %]&referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% booksellerid %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]">Delete</a>
+ [% END %]
</td>
</tr>
[% END %]
use Modern::Perl;
use C4::Context;
-use Test::More tests => 47;
+use Test::More tests => 49;
use Test::MockModule;
use_ok('C4::Acquisition');
@bound_params = @{ $history->[0]->{bound_params} };
is(scalar(@bound_params), 1);
is($bound_params[0], 42);
+my $checkordersrs = [
+ [qw(COUNT)],
+ [2]
+];
+
+$dbh->{mock_add_resultset} = $checkordersrs;
+is(DelInvoice(42), undef, "Invoices with items don't get deleted");
+
+$checkordersrs = [
+ [qw(COUNT)],
+ [0]
+];
+
+my $deleters = [
+ [qw(COUNT)],
+ [1]
+];
+
+$dbh->{mock_add_resultset} = $checkordersrs;
+$dbh->{mock_add_resultset} = $deleters;
+ok(DelInvoice(42), "Invoices with items do get deleted");