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

(-)a/C4/Acquisition.pm (+26 lines)
Lines 72-77 BEGIN { Link Here
72
        &CloseInvoice
72
        &CloseInvoice
73
        &ReopenInvoice
73
        &ReopenInvoice
74
        &DelInvoice
74
        &DelInvoice
75
        &MergeInvoices
75
76
76
        &GetItemnumbersFromOrder
77
        &GetItemnumbersFromOrder
77
78
Lines 2584-2589 sub DelInvoice { Link Here
2584
    return;
2585
    return;
2585
}
2586
}
2586
2587
2588
=head3 MergeInvoices
2589
2590
    MergeInvoices($invoiceid, \@sourceids);
2591
2592
Merge the invoices identified by the IDs in \@sourceids into
2593
the invoice identified by $invoiceid.
2594
2595
=cut
2596
2597
sub MergeInvoices {
2598
    my ($invoiceid, $sourceids) = @_;
2599
2600
    return unless $invoiceid;
2601
    foreach my $sourceid (@$sourceids) {
2602
        next if $sourceid == $invoiceid;
2603
        my $source = GetInvoiceDetails($sourceid);
2604
        foreach my $order (@{$source->{'orders'}}) {
2605
            $order->{'invoiceid'} = $invoiceid;
2606
            ModOrder($order);
2607
        }
2608
        DelInvoice($source->{'invoiceid'});
2609
    }
2610
    return;
2611
}
2612
2587
1;
2613
1;
2588
__END__
2614
__END__
2589
2615
(-)a/acqui/invoice.pl (+3 lines)
Lines 83-88 elsif ( $op && $op eq 'mod' ) { Link Here
83
        ReopenInvoice($invoiceid);
83
        ReopenInvoice($invoiceid);
84
    } elsif ($input->param('close')) {
84
    } elsif ($input->param('close')) {
85
        CloseInvoice($invoiceid);
85
        CloseInvoice($invoiceid);
86
    } elsif ($input->param('merge')) {
87
        my @sources = $input->param('merge');
88
        MergeInvoices($invoiceid, \@sources);
86
    }
89
    }
87
    $template->param( modified => 1 );
90
    $template->param( modified => 1 );
88
}
91
}
(-)a/acqui/invoices.pl (+9 lines)
Lines 36-41 use C4::Output; Link Here
36
use C4::Acquisition qw/GetInvoices/;
36
use C4::Acquisition qw/GetInvoices/;
37
use C4::Bookseller qw/GetBookSeller/;
37
use C4::Bookseller qw/GetBookSeller/;
38
use C4::Branch qw/GetBranches/;
38
use C4::Branch qw/GetBranches/;
39
use C4::Budgets;
39
40
40
my $input = CGI->new;
41
my $input = CGI->new;
41
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
42
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
Lines 121-126 foreach ( sort keys %$branches ) { Link Here
121
      };
122
      };
122
}
123
}
123
124
125
my $budgets = GetBudgets();
126
my @budgets_loop;
127
foreach my $budget (@$budgets) {
128
    push @budgets_loop, $budget if CanUserUseBudget( $loggedinuser, $budget, $flags );
129
}
130
131
$template->{'VARS'}->{'budgets_loop'} = \@budgets_loop;
132
124
$template->param(
133
$template->param(
125
    do_search => ( $op and $op eq 'do_search' ) ? 1 : 0,
134
    do_search => ( $op and $op eq 'do_search' ) ? 1 : 0,
126
    invoices => $invoices,
135
    invoices => $invoices,
(-)a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css (-4 / +22 lines)
Lines 1556-1566 div#header_search input.submit { Link Here
1556
	padding : .1em;
1556
	padding : .1em;
1557
}
1557
}
1558
1558
1559
input[type=submit]:active, input[type=button]:active, button.submit:active {
1559
input[type=submit]:active, input[type=button]:active, button.submit:active, a.submit:active {
1560
	border : 1px inset #999999;
1560
	border : 1px inset #999999;
1561
}
1561
}
1562
1562
1563
input[type=submit], input[type=reset], input[type=button], input.submit, button.submit {
1563
input[type=submit], input[type=reset], input[type=button], input.submit, button.submit, a.submit {
1564
	border: 1px outset #999999;
1564
	border: 1px outset #999999;
1565
	border-top-color: #666;
1565
	border-top-color: #666;
1566
	border-left-color: #666;
1566
	border-left-color: #666;
Lines 1581-1596 input[type=submit]:disabled, Link Here
1581
input[type=reset]:disabled,
1581
input[type=reset]:disabled,
1582
input[type=button]:disabled,
1582
input[type=button]:disabled,
1583
input.submit:disabled,
1583
input.submit:disabled,
1584
button.submit:disabled {
1584
button.submit:disabled,
1585
a.submit:disabled {
1585
    color : #999;
1586
    color : #999;
1586
    border : 1px solid #C0C0C0;
1587
    border : 1px solid #C0C0C0;
1587
    background : #EEE none;
1588
    background : #EEE none;
1588
}
1589
}
1589
1590
1590
input[type=reset]:active, input[type=button]:active, input.submit:active, button.submit:active {
1591
input[type=reset]:active, input[type=button]:active, input.submit:active, button.submit:active, a.submit:active {
1591
	border : 1px inset #999999;
1592
	border : 1px inset #999999;
1592
}
1593
}
1593
1594
1595
a.submit {
1596
    display: inline-block;
1597
}
1598
1594
ul li input.submit {
1599
ul li input.submit {
1595
	font-size : 87%;
1600
	font-size : 87%;
1596
	padding : 2px;
1601
	padding : 2px;
Lines 2582-2584 fieldset.rows table.mceListBox { Link Here
2582
    -webkit-box-shadow: 0px 3px 2px 0px rgba(0, 0, 0, .5);
2587
    -webkit-box-shadow: 0px 3px 2px 0px rgba(0, 0, 0, .5);
2583
    box-shadow: 0px 3px 2px 0px rgba(0, 0, 0, .5);
2588
    box-shadow: 0px 3px 2px 0px rgba(0, 0, 0, .5);
2584
}
2589
}
2590
2591
#merge_invoices {
2592
    display: none;
2593
    margin: 1em auto;
2594
}
2595
2596
#merge {
2597
    margin: 0.5em 0 0 0;
2598
}
2599
2600
#merge_table tr.active td {
2601
    background-color: #FFFFCC;
2602
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt (-2 / +91 lines)
Lines 20-28 $(document).ready(function() { Link Here
20
        bFilter: false,
20
        bFilter: false,
21
        sDom: "t",
21
        sDom: "t",
22
        aoColumnDefs: [
22
        aoColumnDefs: [
23
            { "bSortable": false, "aTargets": [6] }
23
            { "bSortable": false, "aTargets": [0, 7] }
24
        ]
24
        ]
25
    }));
25
    }));
26
27
    $('#merge').click(function (ev) {
28
        var booksellerid;
29
        var mismatch;
30
        var invoices = [ ];
31
        if ($('.select-invoice:checked').size() < 2) {
32
            alert(_("You must select at least two invoices to merge."));
33
            return false;
34
        }
35
        $('.select-invoice:checked').each(function () {
36
            var row = $(this).parents('tr');
37
            booksellerid = booksellerid || $(row).attr('data-booksellerid');
38
            if (booksellerid !== $(row).attr('data-booksellerid')) {
39
                mismatch = true;
40
            }
41
            invoices.push({ 'invoiceid': $(row).attr('data-invoiceid'),
42
                            'invoicenumber': $(row).find('td:nth-child(2) a').text(),
43
                            'shipmentdate': $(row).attr('data-shipmentdate'),
44
                            'billingdate': $(row).attr('data-billingdate'),
45
                            'shipmentcost': $(row).attr('data-shipmentcost'),
46
                            'shipment_budgetid': $(row).attr('data-shipment_budgetid'),
47
                            'closedate': $(row).attr('data-closedate'), });
48
            $('#merge_invoice_form').append('<input type="hidden" name="merge" value="' + $(row).attr('data-invoiceid') + '" />');
49
        });
50
        if (mismatch) {
51
            alert(_("All invoices for merging must be from the same vendor"));
52
        } else {
53
            $('#merge_table tbody').empty();
54
            $.each(invoices, function (idx, invoice) {
55
                var row = $('<tr data-invoiceid="' + invoice.invoiceid + '"><td>' + invoice.invoicenumber + '</td><td>' + invoice.shipmentdate + '</td><td>' + invoice.billingdate + '</td><td>' + invoice.shipmentcost + '</td></tr>');
56
                $(row).appendTo('#merge_table tbody');
57
                $(row).click(function () {
58
                    $('#merge_table tbody tr').removeClass('active');
59
                    $(this).addClass('active');
60
                    $('#merge_invoicenumber').text(invoice.invoicenumber);
61
                    $.each(['invoiceid', 'shipmentdate', 'billingdate', 'shipmentcost', 'shipment_budgetid'], function (idx, prop) {
62
                        $('#merge_' + prop).val(invoice[prop]);
63
                    });
64
                    if (invoice.closedate) {
65
                        $('#merge_status').text(_("Closed on " + invoice.closedate + ""));
66
                    } else {
67
                        $('#merge_status').text(_("Open"));
68
                    }
69
                });
70
            });
71
            $('#merge_table tbody tr:first').click();
72
            $('#merge_invoices').show();
73
        }
74
    });
26
});
75
});
27
//]]>
76
//]]>
28
</script>
77
</script>
Lines 45-50 $(document).ready(function() { Link Here
45
          <table id="resultst">
94
          <table id="resultst">
46
            <thead>
95
            <thead>
47
              <tr>
96
              <tr>
97
                <th>&nbsp;</th>
48
                <th>Invoice no.</th>
98
                <th>Invoice no.</th>
49
                <th>Vendor</th>
99
                <th>Vendor</th>
50
                <th>Billing date</th>
100
                <th>Billing date</th>
Lines 56-62 $(document).ready(function() { Link Here
56
            </thead>
106
            </thead>
57
            <tbody>
107
            <tbody>
58
              [% FOREACH invoice IN invoices %]
108
              [% FOREACH invoice IN invoices %]
59
                <tr>
109
                <tr data-invoiceid="[% invoice.invoiceid %]" data-booksellerid="[% invoice.booksellerid %]" data-shipmentdate="[% invoice.shipmentdate | $KohaDates %]" data-billingdate="[% invoice.billingdate | $KohaDates %]" data-shipmentcost="[% invoice.shipmentcost %]" data-shipment_budgetid="[% invoice.shipmentcost_budgetid %]" data-closedate="[% invoice.closedate | $KohaDates %]">
110
                  <td><input type="checkbox" class="select-invoice" value="[% invoice.invoiceid %]"></input></td>
60
                  <td><a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoice.invoiceid %]">[% invoice.invoicenumber %]</a></td>
111
                  <td><a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoice.invoiceid %]">[% invoice.invoicenumber %]</a></td>
61
                  <td><a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% invoice.booksellerid %]">[% invoice.suppliername %]</a></td>
112
                  <td><a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% invoice.booksellerid %]">[% invoice.suppliername %]</a></td>
62
                  <td>
113
                  <td>
Lines 88-93 $(document).ready(function() { Link Here
88
              [% END %]
139
              [% END %]
89
            </tbody>
140
            </tbody>
90
          </table>
141
          </table>
142
          <a class="submit" id="merge" href="#merge_invoices">Merge selected invoices</a>
143
            <div id="merge_invoices">
144
                <form id="merge_invoice_form" action="/cgi-bin/koha/acqui/invoice.pl" method="post">
145
                <fieldset class="rows">
146
                    <ol>
147
                    <li><h2>Merge invoices</h2></li>
148
                    <li><table id="merge_table">
149
                        <thead><tr><th>Invoice no.</th><th>Shipment date</th><th>Billing date</th><th>Shipment cost</th></tr></thead>
150
                        <tbody>
151
                        </tbody>
152
                    </table></li>
153
                    <li><label for="merge_invoicenumber">Invoice number:</label><span id="merge_invoicenumber"></span></li>
154
                    <li><label for="merge_shipmentdate">Shipment date:</label>
155
                            <input type="text" size="10" id="merge_shipmentdate" name="shipmentdate" value="" readonly="readonly" class="datepicker" /></li>
156
157
                    <li><label for="merge_billingdate">Billing date:</label>
158
                            <input type="text" size="10" id="merge_billingdate" name="billingdate" value="" readonly="readonly" class="datepicker" /></li>
159
160
                    <li><label for="merge_shipmentcost">Shipment cost:</label>
161
                            <input type="text" size="10" id="merge_shipmentcost" name="shipmentcost" value="" /></li>
162
                    <li><label for="merge_shipment_budgetid">Fund:</label>
163
                            <select id="merge_shipment_budgetid" name="shipment_budget_id">
164
                                <option value="">No fund</option>
165
                              [% FOREACH budget IN budgets_loop %]
166
                                  <option value="[% budget.budget_id %]">
167
                                  [% budget.budget_name %]
168
                                  </option>
169
                              [% END %]
170
                            </select></li>
171
172
                    <li><span class="label">Status:</span> <span id="merge_status"></span></li>
173
                    <li><input type="submit" value="Merge" /></li>
174
                    </ol>
175
                    <input type="hidden" name="op" value="mod" />
176
                    <input type="hidden" id="merge_invoiceid" name="invoiceid" value="" />
177
                </fieldset>
178
                </form>
179
            </div>
91
        [% ELSE %]
180
        [% ELSE %]
92
          <p>Sorry, but there is no results for your search.</p>
181
          <p>Sorry, but there is no results for your search.</p>
93
          <p>Search was:
182
          <p>Search was:
(-)a/t/db_dependent/Acquisition/Invoices.t (-1 / +156 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# This Koha test module is a stub!
4
# Add more tests here!!!
5
6
use strict;
7
use warnings;
8
9
use C4::Bookseller qw( GetBookSellerFromId );
10
use C4::Biblio qw( AddBiblio );
11
12
use Test::More tests => 14;
13
14
BEGIN {
15
    use_ok('C4::Acquisition');
16
}
17
18
my $dbh = C4::Context->dbh;
19
$dbh->{AutoCommit} = 0;
20
$dbh->{RaiseError} = 1;
21
22
my $booksellerid = C4::Bookseller::AddBookseller(
23
    {
24
        name => "my vendor",
25
        address1 => "bookseller's address",
26
        phone => "0123456",
27
        active => 1
28
    }
29
);
30
31
my $booksellerinfo = GetBookSellerFromId( $booksellerid );
32
my $basketno = NewBasket($booksellerid, 1);
33
my $basket   = GetBasket($basketno);
34
35
my $budgetid = C4::Budgets::AddBudget(
36
    {
37
        budget_code => "budget_code_test_getordersbybib",
38
        budget_name => "budget_name_test_getordersbybib",
39
    }
40
);
41
my $budget = C4::Budgets::GetBudget( $budgetid );
42
43
my ($ordernumber1, $ordernumber2, $ordernumber3);
44
my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, '');
45
my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, '');
46
my ($biblionumber3, $biblioitemnumber3) = AddBiblio(MARC::Record->new, '');
47
( undef, $ordernumber1 ) = C4::Acquisition::NewOrder(
48
    {
49
        basketno => $basketno,
50
        quantity => 2,
51
        biblionumber => $biblionumber1,
52
        budget_id => $budget->{budget_id},
53
    }
54
);
55
56
( undef, $ordernumber2 ) = C4::Acquisition::NewOrder(
57
    {
58
        basketno => $basketno,
59
        quantity => 1,
60
        biblionumber => $biblionumber2,
61
        budget_id => $budget->{budget_id},
62
    }
63
);
64
65
( undef, $ordernumber3 ) = C4::Acquisition::NewOrder(
66
    {
67
        basketno => $basketno,
68
        quantity => 1,
69
        biblionumber => $biblionumber3,
70
        budget_id => $budget->{budget_id},
71
        ecost => 42,
72
        rrp => 42,
73
    }
74
);
75
76
my $invoiceid1 = AddInvoice(invoicenumber => 'invoice1', booksellerid => $booksellerid, unknown => "unknown");
77
my $invoiceid2 = AddInvoice(invoicenumber => 'invoice2', booksellerid => $booksellerid, unknown => "unknown");
78
79
my ($datereceived, $new_ordernumber) = ModReceiveOrder(
80
    $biblionumber1,
81
    $ordernumber1,
82
    2,
83
    undef,
84
    12,
85
    12,
86
    $invoiceid1,
87
    42
88
    );
89
90
($datereceived, $new_ordernumber) = ModReceiveOrder(
91
    $biblionumber2,
92
    $ordernumber2,
93
    1,
94
    undef,
95
    5,
96
    5,
97
    $invoiceid2,
98
    42
99
    );
100
101
($datereceived, $new_ordernumber) = ModReceiveOrder(
102
    $biblionumber3,
103
    $ordernumber3,
104
    1,
105
    undef,
106
    12,
107
    12,
108
    $invoiceid2,
109
    42
110
    );
111
112
113
my $invoice1 = GetInvoiceDetails($invoiceid1);
114
my $invoice2 = GetInvoiceDetails($invoiceid2);
115
116
is(scalar @{$invoice1->{'orders'}}, 1, 'Invoice1 has only one order');
117
is(scalar @{$invoice2->{'orders'}}, 2, 'Invoice2 has only two orders');
118
119
my @invoices = GetInvoices();
120
cmp_ok(scalar @invoices, '>=', 2, 'GetInvoices returns at least two invoices');
121
122
@invoices = GetInvoices(invoicenumber => 'invoice2');
123
cmp_ok(scalar @invoices, '>=', 1, 'GetInvoices returns at least one invoice when a specific invoice is requested');
124
125
my $invoicesummary1 = GetInvoice($invoiceid1);
126
is($invoicesummary1->{'invoicenumber'}, 'invoice1', 'GetInvoice retrieves correct invoice');
127
is($invoicesummary1->{'invoicenumber'}, $invoice1->{'invoicenumber'}, 'GetInvoice and GetInvoiceDetails retrieve same information');
128
129
ModInvoice(invoiceid => $invoiceid1, invoicenumber => 'invoice11');
130
$invoice1 = GetInvoiceDetails($invoiceid1);
131
is($invoice1->{'invoicenumber'}, 'invoice11', 'ModInvoice changed invoice number');
132
133
is($invoice1->{'closedate'}, undef, 'Invoice is not closed before CloseInvoice call');
134
CloseInvoice($invoiceid1);
135
$invoice1 = GetInvoiceDetails($invoiceid1);
136
isnt($invoice1->{'closedate'}, undef, 'Invoice is closed after CloseInvoice call');
137
ReopenInvoice($invoiceid1);
138
$invoice1 = GetInvoiceDetails($invoiceid1);
139
is($invoice1->{'closedate'}, undef, 'Invoice is open after ReopenInvoice call');
140
141
142
MergeInvoices($invoiceid1, [ $invoiceid2 ]);
143
144
my $mergedinvoice = GetInvoiceDetails($invoiceid1);
145
is(scalar @{$mergedinvoice->{'orders'}}, 3, 'Merged invoice has three orders');
146
147
my $invoiceid3 = AddInvoice(invoicenumber => 'invoice3', booksellerid => $booksellerid, unknown => "unknown");
148
my $invoicecount = GetInvoices();
149
DelInvoice($invoiceid3);
150
@invoices = GetInvoices();
151
is(scalar @invoices, $invoicecount - 1, 'DelInvoice deletes invoice');
152
is(GetInvoice($invoiceid3), undef, 'DelInvoice deleted correct invoice');
153
154
END {
155
    $dbh and $dbh->rollback;
156
}

Return to bug 10401