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

(-)a/C4/Budgets.pm (-34 lines)
Lines 454-493 sub GetBudgetPeriod { Link Here
454
	return $data;
454
	return $data;
455
}
455
}
456
456
457
# -------------------------------------------------------------------
458
459
=head2 GetBudgetPeriodDescription
460
461
       $description = GetBudgetPeriodDescription($budget_id);
462
463
    Return value: hashref
464
465
    Returns the budget period description for a given budget id.
466
467
    Description is fetched from aqbudgetperiods, id is compared aqbudgets. (INNER JOIN on budget_period_id)
468
469
=cut
470
471
sub GetBudgetPeriodDescription {
472
    my ($budget_id) = @_;
473
    my $dbh = C4::Context->dbh;
474
    my $sth;
475
    if ($budget_id) {
476
        $sth = $dbh->prepare(
477
        "SELECT budget_period_description
478
        FROM aqbudgetperiods bp
479
        INNER JOIN aqbudgets b
480
        ON bp.budget_period_id = b.budget_period_id
481
        WHERE b.budget_id=?
482
        "
483
        );
484
        $sth->execute($budget_id);
485
    }
486
    my $data = $sth->fetchrow_hashref;
487
    return $data;
488
}
489
490
# -------------------------------------------------------------------
491
sub DelBudgetPeriod{
457
sub DelBudgetPeriod{
492
	my ($budget_period_id) = @_;
458
	my ($budget_period_id) = @_;
493
	my $dbh = C4::Context->dbh;
459
	my $dbh = C4::Context->dbh;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/orders_by_budget.tt (-1 / +1 lines)
Line 1 Link Here
1
Fund[% sep %]"Basket Num"[% sep %]"Basket Name"[% sep %]"authorised By"[% sep %]"Biblio Number"[% sep %]Title[% sep %]Currency[% sep %]"Vendor Price"[% sep %]RRP[% sep %]"Budgeted Cost"[% sep %]Quantity[% sep %]"Total RRP"[% sep %]"Total Cost"[% sep %]"Entry Date"[% sep %]"Date Received"[% sep %]Notes
1
Fund[% sep %]"Basket num"[% sep %]"Basket name"[% sep %]"Authorised by"[% sep %]"Biblio number"[% sep %]Title[% sep %]Currency[% sep %]"Vendor price"[% sep %]RRP[% sep %]"Budgeted cost"[% sep %]Quantity[% sep %]"Total RRP"[% sep %]"Total cost"[% sep %]"Entry date"[% sep %]"Date received"[% sep %]"Internal note"[% sep %]"Vendor note"
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt (-16 / +34 lines)
Lines 1-3 Link Here
1
[% USE Price %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Reports &rsaquo; Orders by fund</title>
3
<title>Koha &rsaquo; Reports &rsaquo; Orders by fund</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'doc-head-close.inc' %]
Lines 11-16 Link Here
11
<script type="text/javascript">
12
<script type="text/javascript">
12
    $(document).ready( function () {
13
    $(document).ready( function () {
13
        $('#funds').DataTable($.extend(true, {}, dataTablesDefaults,{"sPaginationType": "full_numbers"}));
14
        $('#funds').DataTable($.extend(true, {}, dataTablesDefaults,{"sPaginationType": "full_numbers"}));
15
16
        showallbudgets = $('#budgetfilter').html();
17
        $('#budgetfilter .b_inactive').remove();
18
19
        $('#showbudgets').click(function(){
20
            if ($(this).is(":checked"))
21
                $('#budgetfilter').html(showallbudgets);
22
            else
23
                $('#budgetfilter .b_inactive').remove();
24
        });
14
    } );
25
    } );
15
</script>
26
</script>
16
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a>[% IF ( get_orders ) %] &rsaquo; <a href="/cgi-bin/koha/reports/orders_by_fund.pl">Orders by fund</a> &rsaquo; Results[% ELSE %] &rsaquo; Orders by fund[% END %]</div>
27
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a>[% IF ( get_orders ) %] &rsaquo; <a href="/cgi-bin/koha/reports/orders_by_fund.pl">Orders by fund</a> &rsaquo; Results[% ELSE %] &rsaquo; Orders by fund[% END %]</div>
Lines 39-57 Link Here
39
        <tr>
50
        <tr>
40
        <th>Fund</th>
51
        <th>Fund</th>
41
        <th>Basket</th>
52
        <th>Basket</th>
42
        <th>Basket Name</th>
53
        <th>Basket name</th>
43
        <th>Basket By</th>
54
        <th>Basket by</th>
44
        <th>Title</th>
55
        <th>Title</th>
45
        <th>Currency</th>
56
        <th>Currency</th>
46
        <th>Vendor Price</th>
57
        <th>List price</th>
47
        <th>RRP</th>
58
        <th>RRP</th>
48
        <th>Budgeted Cost</th>
59
        <th>Budgeted cost</th>
49
        <th>Quantity</th>
60
        <th>Quantity</th>
50
        <th>Total RRP</th>
61
        <th>Total RRP</th>
51
        <th>Total Cost</th>
62
        <th>Total cost</th>
52
        <th>Entry Date</th>
63
        <th>Entry date</th>
53
        <th>Date Received</th>
64
        <th>Date deceived</th>
54
        <th>Notes</th>
65
        <th>Internal note</th>
66
        <th>Vendor note</th>
55
        </tr>
67
        </tr>
56
        </thead>
68
        </thead>
57
        <tbody>
69
        <tbody>
Lines 65-83 Link Here
65
            <td>[% ordersloo.authorisedbyname %]</td>
77
            <td>[% ordersloo.authorisedbyname %]</td>
66
            <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% ordersloo.biblionumber %]"> [% ordersloo.title |html %]</a></td>
78
            <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% ordersloo.biblionumber %]"> [% ordersloo.title |html %]</a></td>
67
            <td>[% ordersloo.currency %]</td>
79
            <td>[% ordersloo.currency %]</td>
68
            <td>[% ordersloo.listprice %]</td>
80
            <td>[% ordersloo.listprice | $Price %]</td>
69
            <td>[% ordersloo.rrp %]</td>
81
            <td>[% ordersloo.rrp | $Price %]</td>
70
            <td>[% ordersloo.ecost %]</td>
82
            <td>[% ordersloo.ecost | $Price %]</td>
71
            <td>[% ordersloo.quantity %]</td>
83
            <td>[% ordersloo.quantity %]</td>
72
            <td>[% ordersloo.total_rrp %]</td>
84
            <td>[% ordersloo.total_rrp | $Price %]</td>
73
            <td>[% ordersloo.total_ecost %]</td>
85
            <td>[% ordersloo.total_ecost | $Price %]</td>
74
            <td>[% ordersloo.entrydate %]</td>
86
            <td>[% ordersloo.entrydate %]</td>
75
            <td>[% ordersloo.datereceived %]</td>
87
            <td>[% ordersloo.datereceived %]</td>
76
            <td>[% ordersloo.order_internalnote |html %]</td>
88
            <td>[% ordersloo.order_internalnote |html %]</td>
89
            <td>[% ordersloo.order_vendornote |html %]</td>
77
            </tr>
90
            </tr>
78
        [% END %]
91
        [% END %]
79
        </tbody>
92
        </tbody>
80
        <tfoot><tr><th>TOTAL</th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th>[% total_quantity %]</th><th>[% total_rrp %]</th><th>[% total_ecost %]</th><th></th><th></th><th></th></tr></tfoot>
93
        <tfoot><tr><th>TOTAL</th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th>[% total_quantity  %]</th><th>[% total_rrp | $Price %]</th><th>[% total_ecost | $Price %]</th><th></th><th></th><th></th></tr></tfoot>
81
        </table>
94
        </table>
82
    [% END %]
95
    [% END %]
83
    [% ELSE %]
96
    [% ELSE %]
Lines 90-101 Link Here
90
            <option value="activebudgets">All active funds</option>
103
            <option value="activebudgets">All active funds</option>
91
        [% FOREACH budgetsloo IN budgetsloop %]
104
        [% FOREACH budgetsloo IN budgetsloop %]
92
            [% IF ( budgetsloo.selected ) %]
105
            [% IF ( budgetsloo.selected ) %]
93
                <option value="[% budgetsloo.value %]" selected="selected">[% budgetsloo.description %] [% budgetsloo.period %]</option>
106
                <option value="[% budgetsloo.value %]" selected="selected">
94
            [% ELSE %]
107
            [% ELSE %]
95
                <option value="[% budgetsloo.value %]">[% budgetsloo.description %] [% budgetsloo.period %]</option>
108
                [% bdgclass=budgetsloo.active? "": "b_inactive" %]
109
                    <option class="[% bdgclass %]" value="[% budgetsloo.value %]">
96
            [% END %]
110
            [% END %]
111
            [% budgetsloo.description %] [% IF !budgetsloo.active %](inactive)[% END %]
112
            </option>
97
        [% END %]
113
        [% END %]
98
        </select>
114
        </select>
115
        <label for="showallbudgets" style="float:none;">&nbsp;Show inactive:</label>
116
        <input type="checkbox" id="showbudgets" />
99
        </li></ol>
117
        </li></ol>
100
        </fieldset>
118
        </fieldset>
101
119
(-)a/reports/orders_by_fund.pl (-37 / +15 lines)
Lines 27-32 This script displays all orders associated to a selected budget. Link Here
27
27
28
use strict;
28
use strict;
29
use warnings;
29
use warnings;
30
use Modern::Perl;
30
31
31
use CGI;
32
use CGI;
32
use C4::Auth;
33
use C4::Auth;
Lines 36-42 use C4::Biblio; Link Here
36
use C4::Reports;
37
use C4::Reports;
37
use C4::Acquisition; #GetBasket()
38
use C4::Acquisition; #GetBasket()
38
39
39
40
my $query = new CGI;
40
my $query = new CGI;
41
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
42
    {
42
    {
Lines 112-123 if ( $get_orders ) { Link Here
112
        # Format the dates and currencies correctly
112
        # Format the dates and currencies correctly
113
        $order->{'datereceived'} = Koha::DateUtils::output_pref(Koha::DateUtils::dt_from_string($order->{'datereceived'}));
113
        $order->{'datereceived'} = Koha::DateUtils::output_pref(Koha::DateUtils::dt_from_string($order->{'datereceived'}));
114
        $order->{'entrydate'} = Koha::DateUtils::output_pref(Koha::DateUtils::dt_from_string($order->{'entrydate'}));
114
        $order->{'entrydate'} = Koha::DateUtils::output_pref(Koha::DateUtils::dt_from_string($order->{'entrydate'}));
115
        $order->{'listprice'} = sprintf( "%.2f", $order->{'listprice'} );
116
        $order->{'rrp'} = sprintf( "%.2f", $order->{'rrp'} );
117
        $order->{'ecost'} = sprintf( "%.2f", $order->{'ecost'});
118
        $order->{'total_rrp'} = sprintf( "%.2f", $order->{'total_rrp'});
119
        $order->{'total_ecost'} = sprintf( "%.2f", $order->{'total_ecost'});
120
121
        $total_quantity += $order->{'quantity'};
115
        $total_quantity += $order->{'quantity'};
122
        $total_rrp += $order->{'total_rrp'};
116
        $total_rrp += $order->{'total_rrp'};
123
        $total_ecost += $order->{'total_ecost'};
117
        $total_ecost += $order->{'total_ecost'};
Lines 133-140 if ( $get_orders ) { Link Here
133
            ordersloop   => \@orders,
127
            ordersloop   => \@orders,
134
            get_orders   => $get_orders,
128
            get_orders   => $get_orders,
135
            total_quantity => $total_quantity,
129
            total_quantity => $total_quantity,
136
            total_rrp => sprintf( "%.2f", $total_rrp ),
130
            total_rrp => $total_rrp,
137
            total_ecost => sprintf( "%.2f", $total_ecost ),
131
            total_ecost => $total_ecost,
138
        );
132
        );
139
    }
133
    }
140
    # If we are outputting to a file, create it and exit.
134
    # If we are outputting to a file, create it and exit.
Lines 161-171 if ( $get_orders ) { Link Here
161
        my @rows;
155
        my @rows;
162
        foreach my $order (@orders) {
156
        foreach my $order (@orders) {
163
            my @row;
157
            my @row;
164
            my $sep='';
165
            if ($order->{'order_vendornote'}){
166
            $sep='. Note2:'
167
            }
168
            $order->{'order_internalnote'} .= $sep .$order->{'order_vendornote'};
169
            push(@row, _surround($order->{'budget_name'}));
158
            push(@row, _surround($order->{'budget_name'}));
170
            push(@row, _surround($order->{'basketno'}));
159
            push(@row, _surround($order->{'basketno'}));
171
            push(@row, _surround($order->{'basketname'}));
160
            push(@row, _surround($order->{'basketname'}));
Lines 182-187 if ( $get_orders ) { Link Here
182
            push(@row, _surround($order->{'entrydate'}));
171
            push(@row, _surround($order->{'entrydate'}));
183
            push(@row, _surround($order->{'datereceived'}));
172
            push(@row, _surround($order->{'datereceived'}));
184
            push(@row, _surround($order->{'order_internalnote'}));
173
            push(@row, _surround($order->{'order_internalnote'}));
174
            push(@row, _surround($order->{'order_vendornote'}));
185
            push(@rows, \@row);
175
            push(@rows, \@row);
186
        }
176
        }
187
177
Lines 204-233 else { Link Here
204
    my @CSVdelimiters =(',','#',qw(; tabulation \\ /));
194
    my @CSVdelimiters =(',','#',qw(; tabulation \\ /));
205
195
206
    # getting all budgets
196
    # getting all budgets
207
    # active budgets
197
    my $budgets = GetBudgetHierarchy;
208
    my @active_budgets = C4::Budgets::GetBudgetsByActivity(1);
198
    my $budgetloop = [];
209
    # non active budgets
199
    foreach my $budget  (@{$budgets}) {
210
    my @non_active_budgets = C4::Budgets::GetBudgetsByActivity(0);
200
        push @{$budgetloop},{
211
    my @budgetsloop;
201
            value    => $budget->{budget_id},
212
    foreach my $thisbudget ( sort {$a->{budget_name} cmp $b->{budget_name}} @active_budgets ) {
202
            description  => $budget->{budget_name},
213
        my $budget_period_desc = C4::Budgets::GetBudgetPeriodDescription($thisbudget->{budget_id});
203
            period       => $budget->{budget_period_description},
214
        my %row = (
204
            active       => $budget->{budget_period_active},
215
            value       => $thisbudget->{budget_id},
205
        };
216
            description => $thisbudget->{budget_name},
217
            period      => "(" . $budget_period_desc->{budget_period_description} . ")",
218
        );
219
        push @budgetsloop, \%row;
220
    }
221
    foreach my $thisbudget ( sort {$a->{budget_name} cmp $b->{budget_name}} @non_active_budgets ) {
222
        my $budget_period_desc = C4::Budgets::GetBudgetPeriodDescription($thisbudget->{budget_id});
223
        my %row = (
224
            value       => $thisbudget->{budget_id},
225
            description => "[i] ". $thisbudget->{budget_name},
226
            period      => "(" . $budget_period_desc->{budget_period_description} . ")",
227
        );
228
        push @budgetsloop, \%row;
229
    }
206
    }
230
    $template->param(   budgetsloop   => \@budgetsloop,
207
    @{$budgetloop} =sort { uc( $a->{description}) cmp uc( $b->{description}) } @{$budgetloop};
208
    $template->param(   budgetsloop   => \@{$budgetloop},
231
        outputFormatloop => \@outputFormats,
209
        outputFormatloop => \@outputFormats,
232
        delimiterloop => \@CSVdelimiters,
210
        delimiterloop => \@CSVdelimiters,
233
        delimiterPreference => C4::Context->preference('delimiter')
211
        delimiterPreference => C4::Context->preference('delimiter')
(-)a/t/db_dependent/Budgets.t (-21 / +1 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
use Modern::Perl;
2
use Modern::Perl;
3
use Test::More tests => 130;
3
use Test::More tests => 129;
4
BEGIN {
4
BEGIN {
5
    use_ok('C4::Budgets')
5
    use_ok('C4::Budgets')
6
}
6
}
Lines 468-492 for my $budget (@$budget_hierarchy_cloned) { Link Here
468
is( $number_of_budgets_not_reset, 0,
468
is( $number_of_budgets_not_reset, 0,
469
    'CloneBudgetPeriod has reset all budgets (funds)' );
469
    'CloneBudgetPeriod has reset all budgets (funds)' );
470
470
471
#GetBudgetPeriodDescription
472
$my_budgetperiod = {
473
     budget_period_startdate   => '2008-01-01',
474
     budget_period_enddate     => '2008-12-31',
475
     budget_period_description => 'MAPERI',
476
     budget_period_active      => 0,
477
};
478
$bpid = AddBudgetPeriod($my_budgetperiod);
479
$my_budget = {
480
     budget_code      => 'ABCD',
481
     budget_amount    => '123.132000',
482
     budget_name      => 'Periodiques',
483
     budget_notes     => 'This is a note',
484
     budget_period_id => $bpid,
485
};
486
$budget_id = AddBudget($my_budget);
487
my $data=GetBudgetPeriodDescription($budget_id);
488
is( $data->{budget_period_description}, 'MAPERI' ,'GetBudgetPeriodDescription return right value');
489
490
#GetBudgetsByActivity
471
#GetBudgetsByActivity
491
my $result=C4::Budgets::GetBudgetsByActivity(1);
472
my $result=C4::Budgets::GetBudgetsByActivity(1);
492
isnt( $result, undef ,'GetBudgetsByActivity return correct value with parameter 1');
473
isnt( $result, undef ,'GetBudgetsByActivity return correct value with parameter 1');
493
- 

Return to bug 11371