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

(-)a/Koha/Acquisition/Fund.pm (+15 lines)
Lines 18-23 package Koha::Acquisition::Fund; Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Database;
20
use Koha::Database;
21
use Koha::Acquisition::Budgets;
21
22
22
use base qw(Koha::Object);
23
use base qw(Koha::Object);
23
24
Lines 37-40 sub _type { Link Here
37
    return 'Aqbudget';
38
    return 'Aqbudget';
38
}
39
}
39
40
41
=head3 budget
42
43
my $budget = $fund->budget;
44
45
Return the budget this fund belongs to
46
47
=cut
48
49
sub budget {
50
    my ( $self ) = @_;
51
    my $budget = Koha::Acquisition::Budgets->find( $self->budget_period_id);
52
    return $budget;
53
}
54
40
1;
55
1;
(-)a/acqui/invoice.pl (-9 / +16 lines)
Lines 36-41 use C4::Budgets; Link Here
36
36
37
use Koha::Acquisition::Booksellers;
37
use Koha::Acquisition::Booksellers;
38
use Koha::Acquisition::Currencies;
38
use Koha::Acquisition::Currencies;
39
use Koha::Acquisition::Funds;
39
use Koha::DateUtils;
40
use Koha::DateUtils;
40
use Koha::Misc::Files;
41
use Koha::Misc::Files;
41
use Koha::Acquisition::Invoice::Adjustments;
42
use Koha::Acquisition::Invoice::Adjustments;
Lines 187-204 foreach my $order (@$orders) { Link Here
187
188
188
push @foot_loop, map {$_} values %foot;
189
push @foot_loop, map {$_} values %foot;
189
190
190
my $budgets = GetBudgets();
191
my @funds = Koha::Acquisition::Funds->search();
191
my @budgets_loop;
192
my @active_funds_loop;
193
my @inactive_funds_loop;
192
my $shipmentcost_budgetid = $details->{shipmentcost_budgetid};
194
my $shipmentcost_budgetid = $details->{shipmentcost_budgetid};
193
foreach my $budget (@$budgets) {
195
foreach my $fund (@funds) {
194
    next unless CanUserUseBudget( $loggedinuser, $budget, $flags );
196
    my $line = $fund->unblessed;
195
    my %line = %{$budget};
197
    next unless CanUserUseBudget( $loggedinuser, $fund, $flags );
196
    if (    $shipmentcost_budgetid
198
    if (    $shipmentcost_budgetid
197
        and $budget->{budget_id} == $shipmentcost_budgetid )
199
        and $fund->budget_id == $shipmentcost_budgetid )
198
    {
200
    {
199
        $line{selected} = 1;
201
        $line->{selected} = 1;
202
    }
203
    if ( $fund->budget->budget_period_active ){
204
        push @active_funds_loop, \%$line;
205
    } else {
206
        push @inactive_funds_loop, \%$line;
200
    }
207
    }
201
    push @budgets_loop, \%line;
202
}
208
}
203
209
204
my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({ invoiceid => $details->{'invoiceid'} });
210
my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({ invoiceid => $details->{'invoiceid'} });
Lines 223-229 $template->param( Link Here
223
    total_tax_included_shipment => $total_tax_included + $shipmentcost,
229
    total_tax_included_shipment => $total_tax_included + $shipmentcost,
224
    invoiceincgst    => $bookseller->invoiceincgst,
230
    invoiceincgst    => $bookseller->invoiceincgst,
225
    currency         => Koha::Acquisition::Currencies->get_active,
231
    currency         => Koha::Acquisition::Currencies->get_active,
226
    budgets_loop     => \@budgets_loop,
232
    active_funds_loop     => \@active_funds_loop,
233
    inactive_funds_loop     => \@inactive_funds_loop,
227
);
234
);
228
235
229
defined( $invoice_files ) && $template->param( files => $invoice_files->GetFilesInfo() );
236
defined( $invoice_files ) && $template->param( files => $invoice_files->GetFilesInfo() );
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt (-22 / +65 lines)
Lines 50-64 Link Here
50
            <li><label for="shipment_budget_id">Shipping fund:</label>
50
            <li><label for="shipment_budget_id">Shipping fund:</label>
51
                    <select id="shipment_budget_id" name="shipment_budget_id">
51
                    <select id="shipment_budget_id" name="shipment_budget_id">
52
                        <option value="">No fund</option>
52
                        <option value="">No fund</option>
53
                      [% FOREACH budget IN budgets_loop %]
53
                        <optgroup label="Active budgets">
54
                        [% IF ( budget.selected ) %]
54
                          [% FOREACH fund IN active_funds_loop %]
55
                          <option selected="selected" value="[% budget.budget_id %]">
55
                            [% IF ( fund.selected ) %]
56
                        [% ELSE %]
56
                              <option selected="selected" value="[% fund.budget_id %]">
57
                          <option value="[% budget.budget_id %]">
57
                            [% ELSE %]
58
                        [% END %]
58
                              <option value="[% fund.budget_id %]">
59
                          [% budget.budget_name %]
59
                            [% END %]
60
                        </option>
60
                              [% fund.budget_name %]
61
                      [% END %]
61
                            </option>
62
                          [% END %]
63
                        </optgroup>
64
                        <optgroup label="Inactive budgets">
65
                          [% FOREACH fund IN inactive_funds_loop %]
66
                            [% IF ( fund.selected ) %]
67
                              <option selected="selected" value="[% fund.budget_id %]">
68
                            [% ELSE %]
69
                              <option value="[% fund.budget_id %]">
70
                            [% END %]
71
                              [% fund.budget_name %]
72
                            </option>
73
                          [% END %]
74
                        </optgroup>
62
                    </select></li>
75
                    </select></li>
63
76
64
            [% IF ( invoiceclosedate ) %]
77
            [% IF ( invoiceclosedate ) %]
Lines 132-147 Link Here
132
                                  <td><input type="text" name="note" id="note_new" value="[% adjustment.note %]"/></td>
145
                                  <td><input type="text" name="note" id="note_new" value="[% adjustment.note %]"/></td>
133
                                  <td>
146
                                  <td>
134
                                      <select id="budget_id_[% adjustment.adjustment_id %]" name="budget_id">
147
                                      <select id="budget_id_[% adjustment.adjustment_id %]" name="budget_id">
135
                                              <option value="">No fund</option>
148
                                          <option value="">No fund</option>
136
                                          [% FOREACH budget IN budgets_loop %]
149
                                          <optgroup label="Active budgets">
137
                                              [% IF ( budget.budget_id == adjustment.budget_id ) %]
150
                                          [% FOREACH fund IN active_funds_loop %]
138
                                                  <option selected="selected" value="[% budget.budget_id %]">
151
                                            [% IF ( fund.selected ) %]
139
                                              [% ELSE %]
152
                                              <option selected="selected" value="[% fund.budget_id %]">
140
                                                  <option value="[% budget.budget_id %]">
153
                                            [% ELSE %]
141
                                              [% END %]
154
                                              <option value="[% fund.budget_id %]">
142
                                              [% budget.budget_name %]
155
                                            [% END %]
143
                                              </option>
156
                                              [% fund.budget_name %]
157
                                            </option>
158
                                          [% END %]
159
                                          </optgroup>
160
                                          <optgroup label="Inactive budgets">
161
                                          [% FOREACH fund IN inactive_funds_loop %]
162
                                            [% IF ( fund.selected ) %]
163
                                              <option selected="selected" value="[% fund.budget_id %]">
164
                                            [% ELSE %]
165
                                              <option value="[% fund.budget_id %]">
166
                                            [% END %]
167
                                              [% fund.budget_name %]
168
                                            </option>
144
                                          [% END %]
169
                                          [% END %]
170
                                          </optgroup>
145
                                      </select>
171
                                      </select>
146
                                  </td>
172
                                  </td>
147
                                  [% IF adjustment.encumber_open %]
173
                                  [% IF adjustment.encumber_open %]
Lines 201-211 Link Here
201
                                  <label for="budget_id_new">Fund: </label>
227
                                  <label for="budget_id_new">Fund: </label>
202
                                  <select id="budget_id_new" name="budget_id">
228
                                  <select id="budget_id_new" name="budget_id">
203
                                      <option selected="selected" value="">No fund</option>
229
                                      <option selected="selected" value="">No fund</option>
204
                                      [% FOREACH budget IN budgets_loop %]
230
                                      <optgroup label="Active budgets">
205
                                          <option value="[% budget.budget_id %]">
231
                                      [% FOREACH fund IN active_funds_loop %]
206
                                          [% budget.budget_name %]
232
                                        [% IF ( fund.selected ) %]
207
                                          </option>
233
                                          <option selected="selected" value="[% fund.budget_id %]">
234
                                        [% ELSE %]
235
                                          <option value="[% fund.budget_id %]">
236
                                        [% END %]
237
                                          [% fund.budget_name %]
238
                                        </option>
239
                                      [% END %]
240
                                      </optgroup>
241
                                      <optgroup label="Inactive budgets">
242
                                      [% FOREACH fund IN inactive_funds_loop %]
243
                                        [% IF ( fund.selected ) %]
244
                                          <option selected="selected" value="[% fund.budget_id %]">
245
                                        [% ELSE %]
246
                                          <option value="[% fund.budget_id %]">
247
                                        [% END %]
248
                                          [% fund.budget_name %]
249
                                        </option>
208
                                      [% END %]
250
                                      [% END %]
251
                                      </optgroup>
209
                                  </select>
252
                                  </select>
210
                              </li>
253
                              </li>
211
                              <li>
254
                              <li>
(-)a/t/db_dependent/Koha/Acquisition/Funds.t (-2 / +18 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 5;
23
23
24
use Koha::Acquisition::Funds;
24
use Koha::Acquisition::Funds;
25
use Koha::Database;
25
use Koha::Database;
Lines 45-49 is( $retrieved_fund_1->budget_name, $new_fund->budget_name, 'Find a fund by budg Link Here
45
$retrieved_fund_1->delete;
45
$retrieved_fund_1->delete;
46
is( Koha::Acquisition::Funds->search->count, $nb_of_funds, 'Delete should have deleted the fund' );
46
is( Koha::Acquisition::Funds->search->count, $nb_of_funds, 'Delete should have deleted the fund' );
47
47
48
subtest 'budget method tests' => sub {
49
50
    plan tests => 1;
51
52
    my $budget = $builder->build({
53
        source => 'Aqbudgetperiod'
54
    });
55
    my $fund = $builder->build({
56
        source => 'Aqbudget',
57
        value  => { budget_period_id => $budget->{budget_period_id} }
58
    });
59
    my $retrieved_fund = Koha::Acquisition::Funds->find( $fund->{budget_id} );
60
61
    is( $retrieved_fund->budget->budget_period_id, $budget->{budget_period_id},"The budget retrieved is the same as the one created");
62
63
};
64
48
$schema->storage->txn_rollback;
65
$schema->storage->txn_rollback;
49
66
50
- 

Return to bug 14850