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

(-)a/C4/Budgets.pm (-4 / +119 lines)
Lines 33-38 BEGIN { Link Here
33
        &GetBudgetByOrderNumber
33
        &GetBudgetByOrderNumber
34
        &GetBudgetByCode
34
        &GetBudgetByCode
35
        &GetBudgets
35
        &GetBudgets
36
        &BudgetsByActivity
37
        &GetBudgetsReport
38
        &GetBudgetReport
36
        &GetBudgetHierarchy
39
        &GetBudgetHierarchy
37
	    &AddBudget
40
	    &AddBudget
38
        &ModBudget
41
        &ModBudget
Lines 53-58 BEGIN { Link Here
53
        &GetBudgetPeriods
56
        &GetBudgetPeriods
54
        &ModBudgetPeriod
57
        &ModBudgetPeriod
55
        &AddBudgetPeriod
58
        &AddBudgetPeriod
59
        &GetBudgetPeriodDescription
56
	    &DelBudgetPeriod
60
	    &DelBudgetPeriod
57
61
58
        &ModBudgetPlan
62
        &ModBudgetPlan
Lines 71-77 BEGIN { Link Here
71
75
72
# ----------------------------BUDGETS.PM-----------------------------";
76
# ----------------------------BUDGETS.PM-----------------------------";
73
77
74
75
=head1 FUNCTIONS ABOUT BUDGETS
78
=head1 FUNCTIONS ABOUT BUDGETS
76
79
77
=cut
80
=cut
Lines 451-457 sub GetBudgetPeriod { Link Here
451
	return $data;
454
	return $data;
452
}
455
}
453
456
454
# -------------------------------------------------------------------
455
sub DelBudgetPeriod{
457
sub DelBudgetPeriod{
456
	my ($budget_period_id) = @_;
458
	my ($budget_period_id) = @_;
457
	my $dbh = C4::Context->dbh;
459
	my $dbh = C4::Context->dbh;
Lines 595-600 sub DelBudget { Link Here
595
}
597
}
596
598
597
599
600
# -------------------------------------------------------------------
601
598
=head2 GetBudget
602
=head2 GetBudget
599
603
600
  &GetBudget($budget_id);
604
  &GetBudget($budget_id);
Lines 603-609 get a specific budget Link Here
603
607
604
=cut
608
=cut
605
609
606
# -------------------------------------------------------------------
607
sub GetBudget {
610
sub GetBudget {
608
    my ( $budget_id ) = @_;
611
    my ( $budget_id ) = @_;
609
    my $dbh = C4::Context->dbh;
612
    my $dbh = C4::Context->dbh;
Lines 618-623 sub GetBudget { Link Here
618
    return $result;
621
    return $result;
619
}
622
}
620
623
624
# -------------------------------------------------------------------
625
621
=head2 GetBudgetByOrderNumber
626
=head2 GetBudgetByOrderNumber
622
627
623
  &GetBudgetByOrderNumber($ordernumber);
628
  &GetBudgetByOrderNumber($ordernumber);
Lines 626-632 get a specific budget by order number Link Here
626
631
627
=cut
632
=cut
628
633
629
# -------------------------------------------------------------------
630
sub GetBudgetByOrderNumber {
634
sub GetBudgetByOrderNumber {
631
    my ( $ordernumber ) = @_;
635
    my ( $ordernumber ) = @_;
632
    my $dbh = C4::Context->dbh;
636
    my $dbh = C4::Context->dbh;
Lines 642-647 sub GetBudgetByOrderNumber { Link Here
642
    return $result;
646
    return $result;
643
}
647
}
644
648
649
=head2 GetBudgetReport
650
651
  &GetBudgetReport( [$budget_id] );
652
653
Get all orders for a specific budget, without cancelled orders.
654
655
Returns an array of hashrefs.
656
657
=cut
658
659
# --------------------------------------------------------------------
660
sub GetBudgetReport {
661
    my ( $budget_id ) = @_;
662
    my $dbh = C4::Context->dbh;
663
    my $query = '
664
        SELECT o.*, b.budget_name
665
        FROM   aqbudgets b
666
        INNER JOIN aqorders o
667
        ON b.budget_id = o.budget_id
668
        WHERE  b.budget_id=?
669
        AND (o.orderstatus != "cancelled")
670
        ORDER BY b.budget_name';
671
672
    my $sth = $dbh->prepare($query);
673
    $sth->execute( $budget_id );
674
675
    my @results = ();
676
    while ( my $data = $sth->fetchrow_hashref ) {
677
        push( @results, $data );
678
    }
679
    return @results;
680
}
681
682
=head2 GetBudgetsByActivity
683
684
  &GetBudgetsByActivity( $budget_period_active );
685
686
Get all active or inactive budgets, depending of the value
687
of the parameter.
688
689
1 = active
690
0 = inactive
691
692
=cut
693
694
# --------------------------------------------------------------------
695
sub GetBudgetsByActivity {
696
    my ( $budget_period_active ) = @_;
697
    my $dbh = C4::Context->dbh;
698
    my $query = "
699
        SELECT DISTINCT b.*
700
        FROM   aqbudgetperiods bp
701
        INNER JOIN aqbudgets b
702
        ON bp.budget_period_id = b.budget_period_id
703
        WHERE  bp.budget_period_active=?
704
        ";
705
    my $sth = $dbh->prepare($query);
706
    $sth->execute( $budget_period_active );
707
    my @results = ();
708
    while ( my $data = $sth->fetchrow_hashref ) {
709
        push( @results, $data );
710
    }
711
    return @results;
712
}
713
# --------------------------------------------------------------------
714
715
=head2 GetBudgetsReport
716
717
  &GetBudgetsReport( [$activity] );
718
719
Get all but cancelled orders for all funds.
720
721
If the optionnal activity parameter is passed, returns orders for active/inactive budgets only.
722
723
active = 1
724
inactive = 0
725
726
Returns an array of hashrefs.
727
728
=cut
729
730
sub GetBudgetsReport {
731
    my ($activity) = @_;
732
    my $dbh = C4::Context->dbh;
733
    my $query = '
734
        SELECT o.*, b.budget_name
735
        FROM   aqbudgetperiods bp
736
        INNER JOIN aqbudgets b
737
        ON bp.budget_period_id = b.budget_period_id
738
        INNER JOIN aqorders o
739
        ON b.budget_id = o.budget_id ';
740
    if($activity ne ''){
741
        $query .= 'WHERE  bp.budget_period_active=? ';
742
    }
743
    $query .= 'AND (o.orderstatus != "cancelled")
744
               ORDER BY b.budget_name';
745
746
    my $sth = $dbh->prepare($query);
747
    if($activity ne ''){
748
        $sth->execute($activity);
749
    }
750
    else{
751
        $sth->execute;
752
    }
753
    my @results = ();
754
    while ( my $data = $sth->fetchrow_hashref ) {
755
        push( @results, $data );
756
    }
757
    return @results;
758
}
759
645
=head2 GetBudgetByCode
760
=head2 GetBudgetByCode
646
761
647
    my $budget = &GetBudgetByCode($budget_code);
762
    my $budget = &GetBudgetByCode($budget_code);
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/orders_by_budget.tt (+1 lines)
Line 0 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 %]"Internal note"[% sep %]"Vendor note"
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/csv/orders_by_budget.tt (+12 lines)
Line 0 Link Here
1
[% INCLUDE csv_headers/reports/orders_by_budget.tt %]
2
[%- FOREACH row IN rows %]
3
    [%- FOREACH field IN row;
4
       field;
5
       sep IF !loop.last;
6
    END %]
7
[% END -%]
8
TOTAL
9
[%- FOREACH field IN totalrow;
10
    field;
11
    sep IF !loop.last;
12
END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt (+161 lines)
Line 0 Link Here
1
[% USE Price %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
<title>Koha &rsaquo; Reports &rsaquo; Orders by fund</title>
4
[% INCLUDE 'doc-head-close.inc' %]
5
</head>
6
<body>
7
[% INCLUDE 'header.inc' %]
8
[% INCLUDE 'cat-search.inc' %]
9
10
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
11
[% INCLUDE 'datatables.inc' %]
12
<script type="text/javascript">
13
    $(document).ready( function () {
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
        });
25
    } );
26
</script>
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>
28
29
<div id="doc3" class="yui-t2">
30
31
<div id="bd">
32
        <div id="yui-main">
33
        <div class="yui-b">
34
35
[% IF ( current_budget_name ) %]<h1>Orders for fund '[% current_budget_name %]'</h1>
36
[% ELSE %]<h1>Orders by fund</h1>
37
[% END %]
38
39
[% IF ( get_orders ) %]
40
    <div class="results">
41
        [% IF ( total ) %]
42
            Orders found: [% total %]
43
        [% ELSE %]
44
            No order found
45
        [% END %]
46
    </div>
47
48
    [% IF ( ordersloop ) %]<table id="funds">
49
        <thead>
50
        <tr>
51
        <th>Fund</th>
52
        <th>Basket</th>
53
        <th>Basket name</th>
54
        <th>Basket by</th>
55
        <th>Title</th>
56
        <th>Currency</th>
57
        <th>List price</th>
58
        <th>RRP</th>
59
        <th>Budgeted cost</th>
60
        <th>Quantity</th>
61
        <th>Total RRP</th>
62
        <th>Total cost</th>
63
        <th>Entry date</th>
64
        <th>Date deceived</th>
65
        <th>Internal note</th>
66
        <th>Vendor note</th>
67
        </tr>
68
        </thead>
69
        <tbody>
70
        [% FOREACH ordersloo IN ordersloop %]
71
            [% UNLESS ( loop.odd ) %]<tr class="highlight">
72
            [% ELSE %] <tr>
73
            [% END %]
74
            <td>[% ordersloo.budget_name |html %]</td>
75
            <td><a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% ordersloo.basketno %]"> [% ordersloo.basketno |html %]</a></td>
76
            <td>[% ordersloo.basketname |html %]</td>
77
            <td>[% ordersloo.authorisedbyname %]</td>
78
            <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% ordersloo.biblionumber %]"> [% ordersloo.title |html %]</a></td>
79
            <td>[% ordersloo.currency %]</td>
80
            <td>[% ordersloo.listprice | $Price %]</td>
81
            <td>[% ordersloo.rrp | $Price %]</td>
82
            <td>[% ordersloo.ecost | $Price %]</td>
83
            <td>[% ordersloo.quantity %]</td>
84
            <td>[% ordersloo.total_rrp | $Price %]</td>
85
            <td>[% ordersloo.total_ecost | $Price %]</td>
86
            <td>[% ordersloo.entrydate %]</td>
87
            <td>[% ordersloo.datereceived %]</td>
88
            <td>[% ordersloo.order_internalnote |html %]</td>
89
            <td>[% ordersloo.order_vendornote |html %]</td>
90
            </tr>
91
        [% END %]
92
        </tbody>
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>
94
        </table>
95
    [% END %]
96
    [% ELSE %]
97
        <form name="f" action="/cgi-bin/koha/reports/orders_by_fund.pl" method="post">
98
        <fieldset class="rows">
99
        <legend>Filters</legend>
100
        <ol><li><label for="budgetfilter">Fund (Budget): </label>
101
        <select name="budgetfilter" id="budgetfilter">
102
            <option value="">All funds</option>
103
            <option value="activebudgets">All active funds</option>
104
        [% FOREACH budgetsloo IN budgetsloop %]
105
            [% IF ( budgetsloo.selected ) %]
106
                <option value="[% budgetsloo.value %]" selected="selected">
107
            [% ELSE %]
108
                [% bdgclass=budgetsloo.active? "": "b_inactive" %]
109
                    <option class="[% bdgclass %]" value="[% budgetsloo.value %]">
110
            [% END %]
111
            [% budgetsloo.description %] [% IF !budgetsloo.active %](inactive)[% END %]
112
            </option>
113
        [% END %]
114
        </select>
115
        <label for="showallbudgets" style="float:none;">&nbsp;Show inactive:</label>
116
        <input type="checkbox" id="showbudgets" />
117
        </li></ol>
118
        </fieldset>
119
120
        <fieldset class="rows">
121
        <legend>Output</legend>
122
        <ol><li><label for="outputscreen">To screen into the browser: </label><input type="radio" checked="checked" name="output" id="outputscreen" value="screen" /> </li>
123
            <li><label for="outputfile">To a file:</label>
124
                <input type="radio" name="output" value="file" id="outputfile" />
125
                <label class="inline" for="basename">Named: </label>
126
                <input type="text" name="basename" id="basename" value="Export" />
127
                <label class="inline" for="MIME">Into an application </label>
128
                <select id='MIME' name='MIME' size='1'>
129
                [% FOREACH outputFormatloo IN outputFormatloop %]
130
                    <option value="[% outputFormatloo %]">[% outputFormatloo %]</option>
131
                [% END %]
132
                </select>
133
                <select id='sep' name='sep' size='1'>
134
                [% FOREACH delimiterloo IN delimiterloop %]
135
                    [% IF delimiterloo == delimiterPreference %]
136
                        <option value="[% delimiterloo %]">[% delimiterloo %]</option>
137
                    [% END %]
138
                [% END %]
139
                [% FOREACH delimiterloo IN delimiterloop %]
140
                    [% IF delimiterloo != delimiterPreference %]
141
                        <option value="[% delimiterloo %]">[% delimiterloo %]</option>
142
                    [% END %]
143
                [% END %]
144
                </select>
145
        </li></ol>
146
        </fieldset>
147
148
        <fieldset class="action">
149
        <input type="submit" value="Submit" />
150
        <input type="hidden" name="get_orders" value="1" /></fieldset>
151
        </form>
152
153
    [% END %]
154
155
</div>
156
</div>
157
<div class="yui-b">
158
[% INCLUDE 'reports-menu.inc' %]
159
</div>
160
</div>
161
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt (-39 / +40 lines)
Lines 13-42 Link Here
13
   <div id="bd">
13
   <div id="bd">
14
    <div id="yui-main">
14
    <div id="yui-main">
15
15
16
	<div class="yui-g">
16
    <div class="yui-g">
17
	<h1>Reports</h1>
17
    <h1>Reports</h1>
18
    <div class="yui-u first"><h2>Guided reports</h2>
18
    <div class="yui-u first"><h2>Guided reports</h2>
19
	<ul>
19
        <ul>
20
        <li><a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a></li>
20
            <li><a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a></li>
21
        [% IF ( CAN_user_reports_create_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build new</a></li>[% END %]
21
            [% IF ( CAN_user_reports_create_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build new</a></li>[% END %]
22
        [% IF ( CAN_user_reports_execute_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Use saved</a></li>[% END %]
22
            [% IF ( CAN_user_reports_execute_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Use saved</a></li>[% END %]
23
		[% IF ( CAN_user_reports_create_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create%20report%20from%20SQL">Create from SQL</a></li>[% END %]
23
            [% IF ( CAN_user_reports_create_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create%20report%20from%20SQL">Create from SQL</a></li>[% END %]
24
	</ul>
24
        </ul>
25
	
26
    <h5>Reports dictionary</h5>
27
	<ul>
28
        <li><a href="/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary">View dictionary</a></li>
29
	</ul>
30
25
31
	<h2>Statistics wizards</h2>
26
        <h5>Reports dictionary</h5>
32
	<ul>
27
        <ul>
33
		<li><a href="/cgi-bin/koha/reports/acquisitions_stats.pl">Acquisitions</a></li>
28
            <li><a href="/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary">View dictionary</a></li>
34
		<li><a href="/cgi-bin/koha/reports/borrowers_stats.pl">Patrons</a></li>
29
        </ul>
35
		<li><a href="/cgi-bin/koha/reports/catalogue_stats.pl">Catalog</a></li>
30
36
		<li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li>
31
        <h2>Statistics wizards</h2>
37
		<li><a href="/cgi-bin/koha/reports/serials_stats.pl">Serials</a></li>
32
        <ul>
38
		<li><a href="/cgi-bin/koha/reports/reserves_stats.pl">Holds</a></li>
33
            <li><a href="/cgi-bin/koha/reports/acquisitions_stats.pl">Acquisitions</a></li>
39
      </ul>
34
            <li><a href="/cgi-bin/koha/reports/borrowers_stats.pl">Patrons</a></li>
35
            <li><a href="/cgi-bin/koha/reports/catalogue_stats.pl">Catalog</a></li>
36
            <li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li>
37
            <li><a href="/cgi-bin/koha/reports/serials_stats.pl">Serials</a></li>
38
            <li><a href="/cgi-bin/koha/reports/reserves_stats.pl">Holds</a></li>
39
        </ul>
40
40
41
        [% IF UseKohaPlugins %]
41
        [% IF UseKohaPlugins %]
42
        <h2>Report Plugins</h2>
42
        <h2>Report Plugins</h2>
Lines 51-73 Link Here
51
	<ul>
51
	<ul>
52
        <li><a href="/cgi-bin/koha/reports/bor_issues_top.pl">Patrons with the most checkouts</a></li>
52
        <li><a href="/cgi-bin/koha/reports/bor_issues_top.pl">Patrons with the most checkouts</a></li>
53
        <li><a href="/cgi-bin/koha/reports/cat_issues_top.pl">Most-circulated items</a></li>
53
        <li><a href="/cgi-bin/koha/reports/cat_issues_top.pl">Most-circulated items</a></li>
54
	</ul>	
54
    </ul>
55
	
55
56
	<h2>Inactive</h2>
56
    <h2>Inactive</h2>
57
	<ul>
57
    <ul>
58
		<li><a href="/cgi-bin/koha/reports/borrowers_out.pl">Patrons who haven't checked out</a></li>
58
        <li><a href="/cgi-bin/koha/reports/borrowers_out.pl">Patrons who haven't checked out</a></li>
59
		<li><a href="/cgi-bin/koha/reports/catalogue_out.pl">Items with no checkouts</a></li>
59
        <li><a href="/cgi-bin/koha/reports/catalogue_out.pl">Items with no checkouts</a></li>
60
	</ul>
60
    </ul>
61
	
61
62
	<h2>Other</h2>
62
    <h2>Other</h2>
63
	<ul>
63
    <ul>
64
		<li><a href="/cgi-bin/koha/reports/itemslost.pl">Items lost</a></li>
64
        <li><a href="/cgi-bin/koha/reports/itemslost.pl">Items lost</a></li>
65
        <li><a href="/cgi-bin/koha/reports/manager.pl?report_name=itemtypes">Catalog by item type</a></li>
65
                <li><a href="/cgi-bin/koha/reports/orders_by_fund.pl">Orders by fund</a></li>
66
		<li><a href="/cgi-bin/koha/reports/issues_avg_stats.pl">Average loan time</a></li>
66
        <li><a href="/cgi-bin/koha/reports/manager.pl?report_name=itemtypes">Catalog by itemtype</a></li>
67
        <li><a href="http://schema.koha-community.org/" target="blank">Koha database schema</a></li>
67
        <li><a href="/cgi-bin/koha/reports/issues_avg_stats.pl">Average loan time</a></li>
68
        <li><a href="http://wiki.koha-community.org/wiki/SQL_Reports_Library" target="blank">Koha reports library</a></li>
68
                <li><a href="http://schema.koha-community.org/" target="blank">Koha database schema</a></li>
69
        <!--<li><a href="/cgi-bin/koha/reports/stats.screen.pl">Till reconciliation</a></li> -->
69
                <li><a href="http://wiki.koha-community.org/wiki/SQL_Reports_Library" target="blank">Koha reports library</a></li>
70
	</ul></div>
70
                <!--<li><a href="/cgi-bin/koha/reports/stats.screen.pl">Till reconciliation</a></li> -->
71
</ul></div>
71
</div>
72
</div>
72
73
73
74
(-)a/reports/orders_by_fund.pl (+216 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Author : Frédérick Capovilla, 2011 - SYS-TECH
6
# Modified by : Élyse Morin, 2012 - Libéo
7
#
8
# Koha is free software; you can redistribute it and/or modify it under the
9
# terms of the GNU General Public License as published by the Free Software
10
# Foundation; either version 3 of the License, or (at your option) any later
11
# version.
12
#
13
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License along with
18
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19
# Suite 330, Boston, MA  02111-1307 USA
20
21
22
=head1 orders_by_budget
23
24
This script displays all orders associated to a selected budget.
25
26
=cut
27
28
use strict;
29
use warnings;
30
use Modern::Perl;
31
32
use CGI;
33
use C4::Auth;
34
use C4::Output;
35
use C4::Budgets;
36
use C4::Biblio;
37
use C4::Reports;
38
use C4::Acquisition; #GetBasket()
39
40
my $query = new CGI;
41
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
42
    {
43
        template_name   => "reports/orders_by_budget.tt",
44
        query           => $query,
45
        type            => "intranet",
46
        authnotrequired => 0,
47
        flagsrequired   => { reports => '*' },
48
        debug           => 1,
49
    }
50
);
51
52
my $params = $query->Vars;
53
my $get_orders = $params->{'get_orders'};
54
55
if ( $get_orders ) {
56
    my $budgetfilter     = $params->{'budgetfilter'}    || undef;
57
    my $total_quantity = 0;
58
    my $total_rrp = 0;
59
    my $total_ecost = 0;
60
    my %budget_name;
61
62
    # Fetch the orders
63
    my @orders;
64
    unless($budgetfilter) {
65
        # If no budget filter was selected, get the orders of all budgets
66
        my @budgets = C4::Budgets::GetBudgetsReport();
67
        foreach my $budget (@budgets) {
68
            push(@orders, $budget);
69
            $budget_name{$budget->{'budget_id'}} = $budget->{'budget_name'};
70
        }
71
    }
72
    else {
73
        if ($budgetfilter eq 'activebudgets') {
74
           # If all active budgets's option was selected, get the orders of all active budgets
75
           my @active_budgets = C4::Budgets::GetBudgetsReport(1);
76
           foreach my $active_budget (@active_budgets)
77
           {
78
               push(@orders, $active_budget);
79
               $budget_name{$active_budget->{'budget_id'}} = $active_budget->{'budget_name'};
80
           }
81
        }
82
        else {
83
            # A budget filter was selected, only get the orders for the selected budget
84
            my @filtered_budgets = C4::Budgets::GetBudgetReport($budgetfilter);
85
            foreach my $budget (@filtered_budgets)
86
            {
87
                push(@orders, $budget);
88
                $budget_name{$budget->{'budget_id'}} = $budget->{'budget_name'};
89
            }
90
            if ($filtered_budgets[0]) {
91
                $template->param(
92
                    current_budget_name => $filtered_budgets[0]->{'budget_name'},
93
                );
94
            }
95
        }
96
    }
97
98
    # Format the order's informations
99
    foreach my $order (@orders) {
100
        # Get the title of the ordered item
101
        my $biblio = C4::Biblio::GetBiblio($order->{'biblionumber'});
102
        my $basket = C4::Acquisition::GetBasket($order->{'basketno'});
103
104
        $order->{'basketname'} = $basket->{'basketname'};
105
        $order->{'authorisedbyname'} = $basket->{'authorisedbyname'};
106
107
        $order->{'title'} = $biblio->{'title'} || $order->{'biblionumber'};
108
109
        $order->{'total_rrp'} = $order->{'quantity'} * $order->{'rrp'};
110
        $order->{'total_ecost'} = $order->{'quantity'} * $order->{'ecost'};
111
112
        # Format the dates and currencies correctly
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'}));
115
        $total_quantity += $order->{'quantity'};
116
        $total_rrp += $order->{'total_rrp'};
117
        $total_ecost += $order->{'total_ecost'};
118
119
        # Get the budget's name
120
        $order->{'budget_name'} = $budget_name{$order->{'budget_id'}};
121
    }
122
123
    # If we are outputting to screen, output to the template.
124
    if($params->{"output"} eq 'screen') {
125
        $template->param(
126
            total       => scalar @orders,
127
            ordersloop   => \@orders,
128
            get_orders   => $get_orders,
129
            total_quantity => $total_quantity,
130
            total_rrp => $total_rrp,
131
            total_ecost => $total_ecost,
132
        );
133
    }
134
    # If we are outputting to a file, create it and exit.
135
    else {
136
        my $basename = $params->{"basename"};
137
        my $sep = $params->{"sep"};
138
        $sep = "\t" if ($sep eq 'tabulation');
139
140
        print $query->header(
141
           -type       => 'application/vnd.sun.xml.calc',
142
           -encoding    => 'utf-8',
143
           -attachment => "$basename.csv",
144
           -name       => "$basename.csv"
145
        );
146
147
        #binmode STDOUT, ":encoding(UTF-8)";
148
149
        # Surrounds a string with double-quotes and escape the double-quotes inside
150
        sub _surround {
151
            my $string = shift || "";
152
            $string =~ s/"/""/g;
153
            return "\"$string\"";
154
        }
155
        my @rows;
156
        foreach my $order (@orders) {
157
            my @row;
158
            push(@row, _surround($order->{'budget_name'}));
159
            push(@row, _surround($order->{'basketno'}));
160
            push(@row, _surround($order->{'basketname'}));
161
            push(@row, _surround($order->{'authorisedbyname'}));
162
            push(@row, _surround($order->{'biblionumber'}));
163
            push(@row, _surround($order->{'title'}));
164
            push(@row, _surround($order->{'currency'}));
165
            push(@row, _surround($order->{'listprice'}));
166
            push(@row, _surround($order->{'rrp'}));
167
            push(@row, _surround($order->{'ecost'}));
168
            push(@row, _surround($order->{'quantity'}));
169
            push(@row, _surround($order->{'total_rrp'}));
170
            push(@row, _surround($order->{'total_ecost'}));
171
            push(@row, _surround($order->{'entrydate'}));
172
            push(@row, _surround($order->{'datereceived'}));
173
            push(@row, _surround($order->{'order_internalnote'}));
174
            push(@row, _surround($order->{'order_vendornote'}));
175
            push(@rows, \@row);
176
        }
177
178
        my @totalrow;
179
        for(1..9){push(@totalrow, "")};
180
        push(@totalrow, _surround($total_quantity));
181
        push(@totalrow, _surround($total_rrp));
182
        push(@totalrow, _surround($total_ecost));
183
184
        my $csvTemplate = C4::Templates::gettemplate('reports/csv/orders_by_budget.tt', 'intranet', $query);
185
        $csvTemplate->param(sep => $sep, rows => \@rows, totalrow => \@totalrow);
186
        print $csvTemplate->output;
187
188
        exit(0);
189
    }
190
}
191
else {
192
    # Set file export choices
193
    my @outputFormats = ('CSV');
194
    my @CSVdelimiters =(',','#',qw(; tabulation \\ /));
195
196
    # getting all budgets
197
    my $budgets = GetBudgetHierarchy;
198
    my $budgetloop = [];
199
    foreach my $budget  (@{$budgets}) {
200
        push @{$budgetloop},{
201
            value    => $budget->{budget_id},
202
            description  => $budget->{budget_name},
203
            period       => $budget->{budget_period_description},
204
            active       => $budget->{budget_period_active},
205
        };
206
    }
207
    @{$budgetloop} =sort { uc( $a->{description}) cmp uc( $b->{description}) } @{$budgetloop};
208
    $template->param(   budgetsloop   => \@{$budgetloop},
209
        outputFormatloop => \@outputFormats,
210
        delimiterloop => \@CSVdelimiters,
211
        delimiterPreference => C4::Context->preference('delimiter')
212
    );
213
}
214
215
# writing the template
216
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/t/db_dependent/Acquisition.t (-1 / +21 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use POSIX qw(strftime);
20
use POSIX qw(strftime);
21
21
22
use Test::More tests => 87;
22
use Test::More tests => 91;
23
use Koha::Database;
23
use Koha::Database;
24
24
25
BEGIN {
25
BEGIN {
Lines 147-156 ok( Link Here
147
);
147
);
148
ok( $basket = GetBasket($basketno), "GetBasket($basketno) returns $basket" );
148
ok( $basket = GetBasket($basketno), "GetBasket($basketno) returns $basket" );
149
149
150
my $bpid=AddBudgetPeriod({
151
        budget_period_startdate => '2008-01-01'
152
        , budget_period_enddate => '2008-12-31'
153
        , budget_period_active  => 1
154
        , budget_period_description    => "MAPERI"
155
});
156
150
my $budgetid = C4::Budgets::AddBudget(
157
my $budgetid = C4::Budgets::AddBudget(
151
    {
158
    {
152
        budget_code => "budget_code_test_getordersbybib",
159
        budget_code => "budget_code_test_getordersbybib",
153
        budget_name => "budget_name_test_getordersbybib",
160
        budget_name => "budget_name_test_getordersbybib",
161
        budget_period_id => $bpid,
154
    }
162
    }
155
);
163
);
156
my $budget = C4::Budgets::GetBudget($budgetid);
164
my $budget = C4::Budgets::GetBudget($budgetid);
Lines 934-936 ok((not defined GetBiblio($order4->{biblionumber})), "biblio does not exist anym Link Here
934
# End of tests for DelOrder
942
# End of tests for DelOrder
935
943
936
$schema->storage->txn_rollback();
944
$schema->storage->txn_rollback();
945
# Budget reports
946
#my @report = GetBudgetReport(1);
947
#ok(@report >= 1, "GetBudgetReport OK");
948
949
my $all_count = scalar GetBudgetsReport();
950
ok($all_count >= 1, "GetBudgetReport OK");
951
952
my $active_count = scalar GetBudgetsReport(1);
953
ok($active_count >= 1 , "GetBudgetsReport(1) OK");
954
955
ok($all_count == scalar GetBudgetsReport(), "GetBudgetReport returns inactive budget period acquisitions.");
956
ok($active_count >= scalar GetBudgetsReport(1), "GetBudgetReport doesn't return inactive budget period acquisitions.");
(-)a/t/db_dependent/Budgets.t (-3 / +11 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
use Modern::Perl;
2
use Modern::Perl;
2
use Test::More tests => 130;
3
use Test::More tests => 129;
3
4
BEGIN {
4
BEGIN {
5
    use_ok('C4::Budgets')
5
    use_ok('C4::Budgets')
6
}
6
}
Lines 468-473 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
#GetBudgetsByActivity
472
my $result=C4::Budgets::GetBudgetsByActivity(1);
473
isnt( $result, undef ,'GetBudgetsByActivity return correct value with parameter 1');
474
$result=C4::Budgets::GetBudgetsByActivity(0);
475
 isnt( $result, undef ,'GetBudgetsByActivity return correct value with parameter 0');
476
$result=C4::Budgets::GetBudgetsByActivity();
477
 is( $result, 0 , 'GetBudgetsByActivity return 0 with none parameter or other 0 or 1' );
478
DelBudget($budget_id);
479
DelBudgetPeriod($bpid);
471
480
472
# CloneBudgetPeriod with param amount_change_*
481
# CloneBudgetPeriod with param amount_change_*
473
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
482
$budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod(
474
- 

Return to bug 11371