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

(-)a/C4/Budgets.pm (+146 lines)
Lines 35-40 BEGIN { Link Here
35
        &GetBudgetByOrderNumber
35
        &GetBudgetByOrderNumber
36
        &GetBudgetByCode
36
        &GetBudgetByCode
37
        &GetBudgets
37
        &GetBudgets
38
        &GetActiveBudgets
39
        &GetBudgetReport
40
        &GetBudgetsReport
41
        &GetActiveBudgetsReport
38
        &GetBudgetHierarchy
42
        &GetBudgetHierarchy
39
	    &AddBudget
43
	    &AddBudget
40
        &ModBudget
44
        &ModBudget
Lines 55-60 BEGIN { Link Here
55
        &GetBudgetPeriods
59
        &GetBudgetPeriods
56
        &ModBudgetPeriod
60
        &ModBudgetPeriod
57
        &AddBudgetPeriod
61
        &AddBudgetPeriod
62
        &GetBudgetPeriodDescription
58
	    &DelBudgetPeriod
63
	    &DelBudgetPeriod
59
64
60
        &ModBudgetPlan
65
        &ModBudgetPlan
Lines 438-443 sub GetBudgetPeriod { Link Here
438
}
443
}
439
444
440
# -------------------------------------------------------------------
445
# -------------------------------------------------------------------
446
sub GetBudgetPeriodDescription {
447
    my ($budget_id) = @_;
448
    my $dbh = C4::Context->dbh;
449
    my $sth;
450
    if ($budget_id) {
451
        $sth = $dbh->prepare(
452
        "SELECT budget_period_description
453
        FROM aqbudgetperiods bp
454
        INNER JOIN aqbudgets b
455
        ON bp.budget_period_id = b.budget_period_id
456
        WHERE b.budget_id=?
457
        "
458
        );
459
        $sth->execute($budget_id);
460
    }
461
    my $data = $sth->fetchrow_hashref;
462
    return $data;
463
}
464
465
# -------------------------------------------------------------------
441
sub DelBudgetPeriod{
466
sub DelBudgetPeriod{
442
	my ($budget_period_id) = @_;
467
	my ($budget_period_id) = @_;
443
	my $dbh = C4::Context->dbh;
468
	my $dbh = C4::Context->dbh;
Lines 652-657 sub GetBudgetByOrderNumber { Link Here
652
    return $result;
677
    return $result;
653
}
678
}
654
679
680
=head2 GetBudgetReport
681
682
  &GetBudgetReport();
683
684
Get one specific budget for reports without cancelled baskets.
685
686
=cut
687
688
# --------------------------------------------------------------------
689
sub GetBudgetReport {
690
    my ( $budget_id ) = @_;
691
    my $dbh = C4::Context->dbh;
692
    my $query = "
693
        SELECT o.*, b.budget_name
694
        FROM   aqbudgets b
695
        INNER JOIN aqorders o
696
        ON b.budget_id = o.budget_id
697
        WHERE  b.budget_id=?
698
        AND (o.datecancellationprinted IS NULL OR o.datecancellationprinted='0000-00-00')
699
        ORDER BY b.budget_name
700
        ";
701
    my $sth = $dbh->prepare($query);
702
    $sth->execute( $budget_id );
703
    my @results = ();
704
    while ( my $data = $sth->fetchrow_hashref ) {
705
        push( @results, $data );
706
    }
707
    return @results;
708
}
709
710
=head2 GetBudgetsReport
711
712
  &GetBudgetsReport();
713
714
Get all budgets for reports without cancelled baskets.
715
716
=cut
717
718
# --------------------------------------------------------------------
719
sub GetBudgetsReport {
720
    my $dbh = C4::Context->dbh;
721
    my $query = "
722
        SELECT o.*, b.budget_name
723
        FROM   aqbudgets b
724
        INNER JOIN aqorders o
725
        ON b.budget_id = o.budget_id
726
        WHERE (o.datecancellationprinted IS NULL OR o.datecancellationprinted='0000-00-00')
727
        ORDER BY b.budget_name
728
        ";
729
    my $sth = $dbh->prepare($query);
730
    $sth->execute;
731
    my @results = ();
732
    while ( my $data = $sth->fetchrow_hashref ) {
733
        push( @results, $data );
734
    }
735
    return @results;
736
}
737
738
=head2 GetActiveBudgets
739
740
  &GetActiveBudgets( $budget_period_active );
741
742
Get all active budgets or all inactive budgets, depending of the value
743
of the parameter.
744
745
1 = active
746
0 = inactive
747
748
=cut
749
750
# --------------------------------------------------------------------
751
sub GetActiveBudgets {
752
    my ( $budget_period_active ) = @_;
753
    my $dbh = C4::Context->dbh;
754
    my $query = "
755
        SELECT DISTINCT b.*
756
        FROM   aqbudgetperiods bp
757
        INNER JOIN aqbudgets b
758
        ON bp.budget_period_id = b.budget_period_id
759
        WHERE  bp.budget_period_active=?
760
        ";
761
    my $sth = $dbh->prepare($query);
762
    $sth->execute( $budget_period_active );
763
    my @results = ();
764
    while ( my $data = $sth->fetchrow_hashref ) {
765
        push( @results, $data );
766
    }
767
    return @results;
768
}
769
770
=head2 GetActiveBudgetsReport
771
772
  &GetActiveBudgetsReport();
773
774
Get all active budgets for reports without cancelled baskets.
775
776
=cut
777
778
# --------------------------------------------------------------------
779
sub GetActiveBudgetsReport {
780
    my $dbh = C4::Context->dbh;
781
    my $query = "
782
        SELECT o.*, b.budget_name
783
        FROM   aqbudgetperiods bp
784
        INNER JOIN aqbudgets b
785
        ON bp.budget_period_id = b.budget_period_id
786
        INNER JOIN aqorders o
787
        ON b.budget_id = o.budget_id
788
        WHERE  bp.budget_period_active=1
789
        AND (o.datecancellationprinted IS NULL OR o.datecancellationprinted='0000-00-00')
790
        ORDER BY b.budget_name
791
        ";
792
    my $sth = $dbh->prepare($query);
793
    $sth->execute;
794
    my @results = ();
795
    while ( my $data = $sth->fetchrow_hashref ) {
796
        push( @results, $data );
797
    }
798
    return @results;
799
}
800
655
=head2 GetBudgetByCode
801
=head2 GetBudgetByCode
656
802
657
    my $budget = &GetBudgetByCode($budget_code);
803
    my $budget = &GetBudgetByCode($budget_code);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt (+115 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Reports &rsaquo; Orders by budget</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
</head>
5
<body>
6
[% INCLUDE 'header.inc' %]
7
[% INCLUDE 'cat-search.inc' %]
8
9
<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_budget.pl">Orders by budget</a> &rsaquo; Results[% ELSE %] &rsaquo; Orders by budget[% END %]</div>
10
11
<div id="doc3" class="yui-t2">
12
13
   <div id="bd">
14
    <div id="yui-main">
15
    <div class="yui-b">
16
[% IF ( current_budget_name ) %]
17
<h1>Orders for budget '[% current_budget_name %]'</h1>
18
[% ELSE %]
19
<h1>Orders by budget</h1>
20
[% END %]
21
22
[% IF ( get_orders ) %]
23
24
<div class="results">
25
    [% IF ( total ) %]
26
        Orders found: [% total %]
27
    [% ELSE %]
28
        No order found
29
    [% END %]
30
</div>
31
32
    [% IF ( ordersloop ) %]<table>
33
    <tr>
34
        <th>Budget</th>
35
        <th>Basket</th>
36
    <th>Basket by</th>
37
        <th>Title</th>
38
        <th>Currency</th>
39
        <th>Vendor Price</th>
40
        <th>RRP</th>
41
        <th>Budgeted cost</th>
42
        <th>Quantity</th>
43
        <th>Total RRP</th>
44
        <th>Total cost</th>
45
        <th>Entry date</th>
46
        <th>Date received</th>
47
        <th>Notes</th>
48
    </tr>
49
     [% FOREACH ordersloo IN ordersloop %]
50
        [% UNLESS ( loop.odd ) %]
51
        <tr class="highlight">
52
        [% ELSE %]
53
        <tr>
54
        [% END %]
55
            <td>[% ordersloo.budget_name |html %]</td>
56
            <td><a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% ordersloo.basketno %]">
57
                [% ordersloo.basketno |html %]
58
            </a></td>
59
        <td>[% ordersloo.authorisedbyname %]</td>
60
            <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% ordersloo.biblionumber %]">
61
            [% ordersloo.title |html %]
62
            </a></td>
63
            <td>[% ordersloo.currency %]</td>
64
            <td>[% ordersloo.listprice %]</td>
65
            <td>[% ordersloo.rrp %]</td>
66
            <td>[% ordersloo.ecost %]</td>
67
            <td>[% ordersloo.quantity %]</td>
68
            <td>[% ordersloo.total_rrp %]</td>
69
            <td>[% ordersloo.total_ecost %]</td>
70
            <td>[% ordersloo.entrydate %]</td>
71
            <td>[% ordersloo.datereceived %]</td>
72
            <td>[% ordersloo.notes |html %]</td>
73
        </tr>
74
    [% END %]
75
    <tr><th>TOTAL</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>
76
    </table>
77
    [% END %]
78
    [% ELSE %]
79
80
    <form name="f" action="/cgi-bin/koha/reports/orders_by_budget.pl" method="post">
81
<fieldset class="rows"><ol>
82
    <legend>Filters</legend>
83
    <li><label for="budgetfilter">Budget: </label><select name="budgetfilter" id="budgetfilter">
84
        <option value="">All budgets</option>
85
        <option value="activebudgets">All active budgets</option>
86
            [% FOREACH budgetsloo IN budgetsloop %]
87
                [% IF ( budgetsloo.selected ) %]<option value="[% budgetsloo.value %]" selected="selected">[% budgetsloo.description %] [% budgetsloo.period %]</option>
88
        [% ELSE %]
89
        <option value="[% budgetsloo.value %]">[% budgetsloo.description %] [% budgetsloo.period %]</option>
90
        [% END %]
91
            [% END %]
92
            </select></li>
93
</ol></fieldset>
94
95
    <fieldset class="rows">
96
    <legend>Output</legend>
97
<ol><li><label for="outputscreen">To screen into the browser: </label><input type="radio" checked="checked" name="output" id="outputscreen" value="screen" /> </li>
98
<li><label for="outputfile">To a file:</label>      <input type="radio" name="output" value="file" id="outputfile" /> <label class="inline" for="basename">Named: </label><input type="text" name="basename" id="basename" value="Export" /> <label class="inline" for="MIME">Into an application
99
    </label>[% CGIextChoice %]
100
    [% CGIsepChoice %]</li></ol>
101
    </fieldset>
102
103
<fieldset class="action">    <input type="submit" value="Submit" />
104
    <input type="hidden" name="get_orders" value="1" /></fieldset>
105
</form>
106
107
    [% END %]
108
109
</div>
110
</div>
111
<div class="yui-b">
112
[% INCLUDE 'reports-menu.inc' %]
113
</div>
114
</div>
115
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt (-41 / +42 lines)
Lines 12-41 Link Here
12
   <div id="bd">
12
   <div id="bd">
13
    <div id="yui-main">
13
    <div id="yui-main">
14
14
15
	<div class="yui-g">
15
    <div class="yui-g">
16
	<h1>Reports</h1>
16
    <h1>Reports</h1>
17
    <div class="yui-u first"><h2>Guided reports</h2>
17
    <div class="yui-u first"><h2>Guided reports</h2>
18
	<ul>
18
        <ul>
19
        <li><a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a></li>
19
            <li><a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a></li>
20
        [% IF ( CAN_user_reports_create_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build new</a></li>[% END %]
20
            [% 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_execute_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Use saved</a></li>[% END %]
21
            [% 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_create_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create%20report%20from%20SQL">Create from SQL</a></li>[% END %]
22
            [% 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
	</ul>
23
        </ul>
24
	
25
    <h5>Reports dictionary</h5>
26
	<ul>
27
        <li><a href="/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary">View dictionary</a></li>
28
	</ul>
29
24
30
	<h2>Statistics wizards</h2>
25
        <h5>Reports dictionary</h5>
31
	<ul>
26
        <ul>
32
		<li><a href="/cgi-bin/koha/reports/acquisitions_stats.pl">Acquisitions</a></li>
27
            <li><a href="/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary">View dictionary</a></li>
33
		<li><a href="/cgi-bin/koha/reports/borrowers_stats.pl">Patrons</a></li>
28
        </ul>
34
		<li><a href="/cgi-bin/koha/reports/catalogue_stats.pl">Catalog</a></li>
29
35
		<li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li>
30
        <h2>Statistics wizards</h2>
36
		<li><a href="/cgi-bin/koha/reports/serials_stats.pl">Serials</a></li>
31
        <ul>
37
		<li><a href="/cgi-bin/koha/reports/reserves_stats.pl">Holds</a></li>
32
            <li><a href="/cgi-bin/koha/reports/acquisitions_stats.pl">Acquisitions</a></li>
38
      </ul>
33
            <li><a href="/cgi-bin/koha/reports/borrowers_stats.pl">Patrons</a></li>
34
            <li><a href="/cgi-bin/koha/reports/catalogue_stats.pl">Catalog</a></li>
35
            <li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li>
36
            <li><a href="/cgi-bin/koha/reports/serials_stats.pl">Serials</a></li>
37
            <li><a href="/cgi-bin/koha/reports/reserves_stats.pl">Holds</a></li>
38
        </ul>
39
39
40
        [% IF UseKohaPlugins %]
40
        [% IF UseKohaPlugins %]
41
        <h2>Report Plugins</h2>
41
        <h2>Report Plugins</h2>
Lines 47-72 Link Here
47
    </div>
47
    </div>
48
48
49
    <div class="yui-u"><h2>Top lists</h2>
49
    <div class="yui-u"><h2>Top lists</h2>
50
	<ul>
50
    <ul>
51
		<li><a href="/cgi-bin/koha/reports/bor_issues_top.pl">Patrons checking out the most</a></li>
51
        <li><a href="/cgi-bin/koha/reports/bor_issues_top.pl">Patrons checking out the most</a></li>
52
        <li><a href="/cgi-bin/koha/reports/cat_issues_top.pl">Most-circulated items</a></li>
52
        <li><a href="/cgi-bin/koha/reports/cat_issues_top.pl">Most-circulated items</a></li>
53
	</ul>	
53
    </ul>
54
	
54
55
	<h2>Inactive</h2>
55
    <h2>Inactive</h2>
56
	<ul>
56
    <ul>
57
		<li><a href="/cgi-bin/koha/reports/borrowers_out.pl">Patrons who haven't checked out</a></li>
57
        <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/catalogue_out.pl">Items with no checkouts</a></li>
58
        <li><a href="/cgi-bin/koha/reports/catalogue_out.pl">Items with no checkouts</a></li>
59
	</ul>
59
    </ul>
60
	
60
61
	<h2>Other</h2>
61
    <h2>Other</h2>
62
	<ul>
62
    <ul>
63
		<li><a href="/cgi-bin/koha/reports/itemslost.pl">Items lost</a></li>
63
        <li><a href="/cgi-bin/koha/reports/itemslost.pl">Items lost</a></li>
64
        <li><a href="/cgi-bin/koha/reports/manager.pl?report_name=itemtypes">Catalog by item type</a></li>
64
                <li><a href="/cgi-bin/koha/reports/orders_by_budget.pl">Orders by budget</a></li>
65
		<li><a href="/cgi-bin/koha/reports/issues_avg_stats.pl">Average loan time</a></li>
65
        <li><a href="/cgi-bin/koha/reports/manager.pl?report_name=itemtypes">Catalog by itemtype</a></li>
66
        <li><a href="http://schema.koha-community.org/" target="blank">Koha database schema</a></li>
66
        <li><a href="/cgi-bin/koha/reports/issues_avg_stats.pl">Average loan time</a></li>
67
        <li><a href="http://wiki.koha-community.org/wiki/SQL_Reports_Library" target="blank">Koha reports library</a></li>
67
                <li><a href="http://schema.koha-community.org/" target="blank">Koha database schema</a></li>
68
        <!--<li><a href="/cgi-bin/koha/reports/stats.screen.pl">Till reconciliation</a></li> -->
68
                <li><a href="http://wiki.koha-community.org/wiki/SQL_Reports_Library" target="blank">Koha reports library</a></li>
69
	</ul></div>
69
                <!--<li><a href="/cgi-bin/koha/reports/stats.screen.pl">Till reconciliation</a></li> -->
70
</ul></div>
70
</div>
71
</div>
71
72
72
</div>
73
</div>
(-)a/reports/orders_by_budget.pl (+250 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
31
use CGI;
32
use C4::Auth;
33
use C4::Output;
34
use C4::Budgets;
35
use C4::Biblio;
36
use C4::Reports;
37
use C4::Dates qw/format_date/;
38
use C4::SQLHelper qw<:all>;
39
use C4::Acquisition; #GetBasket()
40
41
42
my $query = new CGI;
43
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
44
    {
45
        template_name   => "reports/orders_by_budget.tt",
46
        query           => $query,
47
        type            => "intranet",
48
        authnotrequired => 0,
49
        flagsrequired   => { reports => '*' },
50
        debug           => 1,
51
    }
52
);
53
54
my $params = $query->Vars;
55
my $get_orders = $params->{'get_orders'};
56
57
if ( $get_orders ) {
58
    my $budgetfilter     = $params->{'budgetfilter'}    || undef;
59
    my $total_quantity = 0;
60
    my $total_rrp = 0;
61
    my $total_ecost = 0;
62
    my %budget_name;
63
64
    # Fetch the orders
65
    my @orders;
66
    unless($budgetfilter) {
67
        # If no budget filter was selected, get the orders of all budgets
68
        my @budgets = C4::Budgets::GetBudgetsReport();
69
        foreach my $budget (@budgets) {
70
            push(@orders, $budget);
71
            $budget_name{$budget->{'budget_id'}} = $budget->{'budget_name'};
72
        }
73
    }
74
    else {
75
        if ($budgetfilter eq 'activebudgets') {
76
           # If all active budgets's option was selected, get the orders of all active budgets
77
           my @active_budgets = C4::Budgets::GetActiveBudgetsReport();
78
           foreach my $active_budget (@active_budgets)
79
           {
80
               push(@orders, $active_budget);
81
               $budget_name{$active_budget->{'budget_id'}} = $active_budget->{'budget_name'};
82
           }
83
        }
84
        else {
85
            # A budget filter was selected, only get the orders for the selected budget
86
            my @filtered_budgets = C4::Budgets::GetBudgetReport($budgetfilter);
87
            foreach my $budget (@filtered_budgets)
88
            {
89
                push(@orders, $budget);
90
                $budget_name{$budget->{'budget_id'}} = $budget->{'budget_name'};
91
            }
92
            if ($filtered_budgets[0]) {
93
                $template->param(
94
                    current_budget_name => $filtered_budgets[0]->{'budget_name'},
95
                );
96
            }
97
        }
98
    }
99
100
    # Format the order's informations
101
    foreach my $order (@orders) {
102
        # Get the title of the ordered item
103
        my $biblio = C4::Biblio::GetBiblio($order->{'biblionumber'});
104
        my $basket = C4::Acquisition::GetBasket($order->{'basketno'});
105
106
        $order->{'authorisedbyname'} = $basket->{'authorisedbyname'};
107
108
        $order->{'title'} = $biblio->{'title'} || $order->{'biblionumber'};
109
110
        $order->{'total_rrp'} = $order->{'quantity'} * $order->{'rrp'};
111
        $order->{'total_ecost'} = $order->{'quantity'} * $order->{'ecost'};
112
113
        # Format the dates and currencies correctly
114
        $order->{'datereceived'} = format_date($order->{'datereceived'});
115
        $order->{'entrydate'} = format_date($order->{'entrydate'});
116
        $order->{'listprice'} = sprintf( "%.2f", $order->{'listprice'} );
117
        $order->{'rrp'} = sprintf( "%.2f", $order->{'rrp'} );
118
        $order->{'ecost'} = sprintf( "%.2f", $order->{'ecost'});
119
        $order->{'total_rrp'} = sprintf( "%.2f", $order->{'total_rrp'});
120
        $order->{'total_ecost'} = sprintf( "%.2f", $order->{'total_ecost'});
121
122
        $total_quantity += $order->{'quantity'};
123
        $total_rrp += $order->{'total_rrp'};
124
        $total_ecost += $order->{'total_ecost'};
125
126
        # Get the budget's name
127
        $order->{'budget_name'} = $budget_name{$order->{'budget_id'}};
128
    }
129
130
    # If we are outputting to screen, output to the template.
131
    if($params->{"output"} eq 'screen') {
132
        $template->param(
133
            total       => scalar @orders,
134
            ordersloop   => \@orders,
135
            get_orders   => $get_orders,
136
            total_quantity => $total_quantity,
137
            total_rrp => sprintf( "%.2f", $total_rrp ),
138
            total_ecost => sprintf( "%.2f", $total_ecost ),
139
        );
140
    }
141
    # If we are outputting to a file, create it and exit.
142
    else {
143
        my $basename = $params->{"basename"};
144
        my $sep = $params->{"sep"};
145
        $sep = "\t" if ($sep == 'tabulation');
146
147
        print $query->header(
148
            -type       => 'application/vnd.sun.xml.calc',
149
            -encoding    => 'utf-8',
150
            -attachment => "$basename.csv",
151
            -name       => "$basename.csv"
152
        );
153
154
        binmode STDOUT, ":encoding(UTF-8)";
155
156
        # Surrounds a string with double-quotes and escape the double-quotes inside
157
        sub _surround {
158
            my $string = shift || "";
159
            $string =~ s/"/""/g;
160
            return "\"$string\"";
161
        }
162
163
        # Create the CSV file
164
        print '"Budget"' . $sep;
165
        print '"Basket"' . $sep;
166
        print '"Basket by"' . $sep;
167
        print '"biblionumber"' . $sep;
168
        print '"Title"' . $sep;
169
        print '"Currency"' . $sep;
170
        print '"Vendor Price"' . $sep;
171
        print '"RRP"' . $sep;
172
        print '"Budgeted cost"' . $sep;
173
        print '"Quantity"' . $sep;
174
        print '"Total RRP"' . $sep;
175
        print '"Total cost"' . $sep;
176
        print '"Entry date"' . $sep;
177
        print '"Date received"' . $sep;
178
        print '"Notes"' . "\n";
179
180
        foreach my $order (@orders) {
181
            print _surround($order->{'budget_name'}) . $sep;
182
            print _surround($order->{'basketno'}) . $sep;
183
            print _surround($order->{'authorisedbyname'}) . $sep;
184
            print _surround($order->{'biblionumber'}) . $sep;
185
            print _surround($order->{'title'}) . $sep;
186
            print _surround($order->{'currency'}) . $sep;
187
            print _surround($order->{'listprice'}) . $sep;
188
            print _surround($order->{'rrp'}) . $sep;
189
            print _surround($order->{'ecost'}) . $sep;
190
            print _surround($order->{'quantity'}) . $sep;
191
            print _surround($order->{'total_rrp'}) . $sep;
192
            print _surround($order->{'total_ecost'}) . $sep;
193
            print _surround($order->{'entrydate'}) . $sep;
194
            print _surround($order->{'datereceived'}) . $sep;
195
            print _surround($order->{'notes'}) . "\n";
196
        }
197
198
        print '"TOTAL"'. ($sep x 8);
199
        print _surround($total_quantity) . $sep;
200
        print _surround($total_rrp) . $sep;
201
        print _surround($total_ecost);
202
203
        exit(0);
204
    }
205
}
206
else {
207
    # Set file export choices
208
    my $CGIextChoice = CGI::scrolling_list(
209
        -name     => 'MIME',
210
        -id       => 'MIME',
211
        -values   => ['CSV'], # FIXME translation
212
        -size     => 1,
213
        -multiple => 0
214
    );
215
216
    my $CGIsepChoice = GetDelimiterChoices;
217
218
    # getting all budgets
219
    # active budgets
220
    my @active_budgets = C4::Budgets::GetActiveBudgets(1);
221
    # non active budgets
222
    my @non_active_budgets = C4::Budgets::GetActiveBudgets(0);
223
    my @budgetsloop;
224
    foreach my $thisbudget ( sort {$a->{budget_name} cmp $b->{budget_name}} @active_budgets ) {
225
        my $budget_period_desc = C4::Budgets::GetBudgetPeriodDescription($thisbudget->{budget_id});
226
        my %row = (
227
            value       => $thisbudget->{budget_id},
228
            description => $thisbudget->{budget_name},
229
            period      => "(" . $budget_period_desc->{budget_period_description} . ")",
230
        );
231
        push @budgetsloop, \%row;
232
    }
233
    foreach my $thisbudget ( sort {$a->{budget_name} cmp $b->{budget_name}} @non_active_budgets ) {
234
        my $budget_period_desc = C4::Budgets::GetBudgetPeriodDescription($thisbudget->{budget_id});
235
        my %row = (
236
            value       => $thisbudget->{budget_id},
237
            description => "[i] ". $thisbudget->{budget_name},
238
            period      => "(" . $budget_period_desc->{budget_period_description} . ")",
239
        );
240
        push @budgetsloop, \%row;
241
    }
242
243
    $template->param(   budgetsloop   => \@budgetsloop,
244
        CGIextChoice => $CGIextChoice,
245
        CGIsepChoice => $CGIsepChoice,
246
    );
247
}
248
249
# writing the template
250
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/t/db_dependent/Acquisition.t (+28 lines)
Lines 130-139 ok( Link Here
130
);
130
);
131
ok( $basket = GetBasket($basketno), "GetBasket($basketno) returns $basket" );
131
ok( $basket = GetBasket($basketno), "GetBasket($basketno) returns $basket" );
132
132
133
my $bpid=AddBudgetPeriod({
134
        budget_period_startdate => '2008-01-01'
135
        , budget_period_enddate => '2008-12-31'
136
        , budget_period_active  => 1
137
        , budget_description    => "MAPERI"
138
});
139
133
my $budgetid = C4::Budgets::AddBudget(
140
my $budgetid = C4::Budgets::AddBudget(
134
    {
141
    {
135
        budget_code => "budget_code_test_getordersbybib",
142
        budget_code => "budget_code_test_getordersbybib",
136
        budget_name => "budget_name_test_getordersbybib",
143
        budget_name => "budget_name_test_getordersbybib",
144
        budget_period_id => $bpid,
137
    }
145
    }
138
);
146
);
139
my $budget = C4::Budgets::GetBudget($budgetid);
147
my $budget = C4::Budgets::GetBudget($budgetid);
Lines 925-928 is( $nonexistent_order, undef, 'GetOrder returns undef if no ordernumber is give Link Here
925
$nonexistent_order = GetOrder( 424242424242 );
933
$nonexistent_order = GetOrder( 424242424242 );
926
is( $nonexistent_order, undef, 'GetOrder returns undef if a nonexistent ordernumber is given' );
934
is( $nonexistent_order, undef, 'GetOrder returns undef if a nonexistent ordernumber is given' );
927
935
936
937
# Budget reports
938
939
my @report = GetBudgetReport($budget->{budget_id});
940
ok(@report == 3, "GetBudgetReport OK");
941
942
my $all_count = scalar GetBudgetsReport();
943
ok($all_count >= 3, "GetBudgetsReport OK");
944
945
my $active_count = scalar GetActiveBudgetsReport();
946
ok($active_count >= 3, "GetActiveBudgetsReport OK");
947
948
# Deactivate budget period
949
my $budgetperiod=GetBudgetPeriod($bpid);
950
$$budgetperiod{budget_period_active}=0;
951
ModBudgetPeriod($budgetperiod);
952
953
ok($all_count == scalar GetBudgetsReport(), "GetBudgetReport returns inactive budget period acquisitions.");
954
ok($active_count >= scalar GetActiveBudgetsReport(), "GetBudgetReport doesn't return inactive budget period acquisitions.");
955
928
$dbh->rollback;
956
$dbh->rollback;
(-)a/t/db_dependent/Budgets.t (-2 / +65 lines)
Lines 1-5 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
use Test::More tests => 107;
2
use Test::More tests => 107;
3
use strict;
4
use warnings;
3
5
4
BEGIN {
6
BEGIN {
5
    use_ok('C4::Budgets')
7
    use_ok('C4::Budgets')
Lines 406-411 $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod( Link Here
406
        mark_original_budget_as_inactive => 1,
408
        mark_original_budget_as_inactive => 1,
407
    }
409
    }
408
);
410
);
411
# Add A budget Period
412
if (C4::Context->preference('dateformat') eq "metric"){
413
ok($bpid=AddBudgetPeriod(
414
            { budget_period_startdate   =>'01-01-2008'
415
            , budget_period_enddate     =>'31-12-2008'
416
            , budget_period_description =>"MAPERI"
417
            , budget_period_active      =>1
418
            , budget_description        =>"MAPERI"}),
419
    "AddBudgetPeriod returned $bpid");
420
} elsif (C4::Context->preference('dateformat') eq "us"){
421
ok($bpid=AddBudgetPeriod(
422
            { budget_period_startdate   =>'01-01-2008'
423
            , budget_period_enddate     =>'12-31-2008'
424
            , budget_period_description =>"MAPERI"
425
            , budget_period_active      =>1
426
            , budget_description        =>"MAPERI"}),
427
    "AddBudgetPeriod returned $bpid");
428
}
429
else{
430
ok($bpid=AddBudgetPeriod(
431
            {budget_period_startdate=>'2008-01-01'
432
            ,budget_period_enddate  =>'2008-12-31'
433
            ,budget_description     =>"MAPERI"
434
            ,budget_period_active   =>1
435
            ,budget_period_description  =>"MAPERI"
436
            }),
437
"AddBudgetPeriod returned $bpid");
409
438
410
$budget_hierarchy        = GetBudgetHierarchy($budget_period_id);
439
$budget_hierarchy        = GetBudgetHierarchy($budget_period_id);
411
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
440
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
Lines 441-446 for my $budget (@$budget_hierarchy_cloned) { Link Here
441
is( $number_of_budgets_not_reset, 0,
470
is( $number_of_budgets_not_reset, 0,
442
    'CloneBudgetPeriod has reset all budgets (funds)' );
471
    'CloneBudgetPeriod has reset all budgets (funds)' );
443
472
473
my $budget_name = GetBudgetName( $budget_id );
474
is($budget_name, $budget->{budget_name}, "Test the GetBudgetName routine");
475
476
my $second_budget_id;
477
ok($second_budget_id=AddBudget(
478
                        {   budget_code         => "ZZZZ",
479
                            budget_amount       => "500.00",
480
                            budget_name     => "Art",
481
                            budget_notes        => "This is a note",
482
                            budget_description=> "Art",
483
                            budget_active       => 1,
484
                            budget_period_id    => $bpid,
485
                        }
486
                       ),
487
    "AddBudget returned $second_budget_id");
488
489
my $budgets = GetBudgets({ budget_period_id => $bpid});
490
ok($budgets->[0]->{budget_name} lt $budgets->[1]->{budget_name}, 'default sort order for GetBudgets is by name');
491
492
ok(GetBudgetPeriodDescription($budget_id)->{budget_period_description} eq "MAPERI",
493
    "GetBudgetPeriodDescription OK");
494
495
ok(GetActiveBudgets(1) > 0,
496
    "GetActiveBudgets can return active budgets");
497
498
# Deactivate budget period
499
$budgetperiod=GetBudgetPeriod($bpid);
500
$$budgetperiod{budget_period_active}=0;
501
ModBudgetPeriod($budgetperiod);
502
503
ok(GetActiveBudgets(0) > 0,
504
    "GetActiveBudgets can return inactive budgets");
505
my $del_status;
506
ok($del_status=DelBudget($budget_id),
507
    "DelBudget returned $del_status");
444
508
445
# MoveOrders
509
# MoveOrders
446
my $number_orders_moved = C4::Budgets::MoveOrders();
510
my $number_orders_moved = C4::Budgets::MoveOrders();
Lines 536-539 sub _get_budgetname_by_id { Link Here
536
# C4::Context->userenv
600
# C4::Context->userenv
537
sub Mock_userenv {
601
sub Mock_userenv {
538
    return $userenv;
602
    return $userenv;
539
}
603
}}
540
- 

Return to bug 11371