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

(-)a/C4/Acquisition.pm (+34 lines)
Lines 71-76 BEGIN { Link Here
71
        &ModInvoice
71
        &ModInvoice
72
        &CloseInvoice
72
        &CloseInvoice
73
        &ReopenInvoice
73
        &ReopenInvoice
74
        &DelInvoice
74
75
75
        &GetItemnumbersFromOrder
76
        &GetItemnumbersFromOrder
76
77
Lines 2607-2612 sub ReopenInvoice { Link Here
2607
    $sth->execute($invoiceid);
2608
    $sth->execute($invoiceid);
2608
}
2609
}
2609
2610
2611
=head3 DelInvoice
2612
2613
    DelInvoice($invoiceid);
2614
2615
Delete an invoice if there are no items attached to it.
2616
2617
=cut
2618
2619
sub DelInvoice {
2620
    my ($invoiceid) = @_;
2621
2622
    return unless $invoiceid;
2623
2624
    my $dbh   = C4::Context->dbh;
2625
    my $query = qq{
2626
        SELECT COUNT(*)
2627
        FROM aqorders
2628
        WHERE invoiceid = ?
2629
    };
2630
    my $sth = $dbh->prepare($query);
2631
    $sth->execute($invoiceid);
2632
    my $res = $sth->fetchrow_arrayref;
2633
    if ( $res && $res->[0] == 0 ) {
2634
        $query = qq{
2635
            DELETE FROM aqinvoices
2636
            WHERE invoiceid = ?
2637
        };
2638
        my $sth = $dbh->prepare($query);
2639
        return ( $sth->execute($invoiceid) > 0 );
2640
    }
2641
    return;
2642
}
2643
2610
1;
2644
1;
2611
__END__
2645
__END__
2612
2646
(-)a/acqui/invoice.pl (+8 lines)
Lines 86-91 elsif ( $op && $op eq 'mod' ) { Link Here
86
    }
86
    }
87
    $template->param( modified => 1 );
87
    $template->param( modified => 1 );
88
}
88
}
89
elsif ( $op && $op eq 'delete' ) {
90
    DelInvoice($invoiceid);
91
    my $referer = $input->param('referer') || 'invoices.pl';
92
    if ($referer) {
93
        print $input->redirect($referer);
94
        exit 0;
95
    }
96
}
89
97
90
my $details     = GetInvoiceDetails($invoiceid);
98
my $details     = GetInvoiceDetails($invoiceid);
91
my $bookseller  = GetBookSellerFromId( $details->{booksellerid} );
99
my $bookseller  = GetBookSellerFromId( $details->{booksellerid} );
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt (+3 lines)
Lines 84-89 Link Here
84
        </fieldset>
84
        </fieldset>
85
        <fieldset class="action">
85
        <fieldset class="action">
86
            <input type="submit" value="Save" />
86
            <input type="submit" value="Save" />
87
            [% UNLESS orders_loop.size %]
88
            <a href="invoice.pl?op=delete&invoiceid=[% invoiceid %]">Delete</a>
89
            [% END %]
87
        </fieldset>
90
        </fieldset>
88
      </form>
91
      </form>
89
      <p>
92
      <p>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt (+3 lines)
Lines 80-85 $(document).ready(function() { Link Here
80
                    [% ELSE %]
80
                    [% ELSE %]
81
                      <a href="invoice.pl?op=close&amp;invoiceid=[% invoice.invoiceid %]&amp;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>
81
                      <a href="invoice.pl?op=close&amp;invoiceid=[% invoice.invoiceid %]&amp;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>
82
                    [% END %]
82
                    [% END %]
83
                    [% UNLESS invoice.receivedbiblios || invoice.receiveditems %]
84
                      / <a href="invoice.pl?op=delete&amp;invoiceid=[% invoice.invoiceid %]&amp;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>
85
                    [% END %]
83
                  </td>
86
                  </td>
84
                </tr>
87
                </tr>
85
              [% END %]
88
              [% END %]
(-)a/t/Acquisition/Invoice.t (-2 / +22 lines)
Lines 3-9 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 => 47;
6
use Test::More tests => 49;
7
use Test::MockModule;
7
use Test::MockModule;
8
8
9
use_ok('C4::Acquisition');
9
use_ok('C4::Acquisition');
Lines 129-131 is(scalar(@$history), 1); Link Here
129
@bound_params = @{ $history->[0]->{bound_params} };
129
@bound_params = @{ $history->[0]->{bound_params} };
130
is(scalar(@bound_params), 1);
130
is(scalar(@bound_params), 1);
131
is($bound_params[0], 42);
131
is($bound_params[0], 42);
132
- 
132
my $checkordersrs = [
133
    [qw(COUNT)],
134
    [2]
135
];
136
137
$dbh->{mock_add_resultset} = $checkordersrs;
138
is(DelInvoice(42), undef, "Invoices with items don't get deleted");
139
140
$checkordersrs = [
141
    [qw(COUNT)],
142
    [0]
143
];
144
145
my $deleters = [
146
    [qw(COUNT)],
147
    [1]
148
];
149
150
$dbh->{mock_add_resultset} = $checkordersrs;
151
$dbh->{mock_add_resultset} = $deleters;
152
ok(DelInvoice(42), "Invoices with items do get deleted");

Return to bug 10390