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

(-)a/C4/Budgets.pm (-2 / +148 lines)
Lines 35-40 BEGIN { Link Here
35
        &GetBudgetByOrderNumber
35
        &GetBudgetByOrderNumber
36
        &GetBudgetByCode
36
        &GetBudgetByCode
37
        &GetBudgets
37
        &GetBudgets
38
        &BudgetsByActivity
39
        &GetBudgetsReport
40
        &GetBudgetReport
38
        &GetBudgetHierarchy
41
        &GetBudgetHierarchy
39
	    &AddBudget
42
	    &AddBudget
40
        &ModBudget
43
        &ModBudget
Lines 55-60 BEGIN { Link Here
55
        &GetBudgetPeriods
58
        &GetBudgetPeriods
56
        &ModBudgetPeriod
59
        &ModBudgetPeriod
57
        &AddBudgetPeriod
60
        &AddBudgetPeriod
61
        &GetBudgetPeriodDescription
58
	    &DelBudgetPeriod
62
	    &DelBudgetPeriod
59
63
60
        &ModBudgetPlan
64
        &ModBudgetPlan
Lines 459-464 sub GetBudgetPeriod { Link Here
459
}
463
}
460
464
461
# -------------------------------------------------------------------
465
# -------------------------------------------------------------------
466
=head2 GetBudgetPeriodDescription
467
468
       $description = GetBudgetPeriodDescription($budget_id);
469
470
    Return value: hashref
471
472
    Returns the budget period description for a given budget id.
473
474
    Description is fetched from aqbudgetperiods, id is compared aqbudgets. (INNER JOIN on budget_period_id)
475
476
=cut
477
sub GetBudgetPeriodDescription {
478
    my ($budget_id) = @_;
479
    my $dbh = C4::Context->dbh;
480
    my $sth;
481
    if ($budget_id) {
482
        $sth = $dbh->prepare(
483
        "SELECT budget_period_description
484
        FROM aqbudgetperiods bp
485
        INNER JOIN aqbudgets b
486
        ON bp.budget_period_id = b.budget_period_id
487
        WHERE b.budget_id=?
488
        "
489
        );
490
        $sth->execute($budget_id);
491
    }
492
    my $data = $sth->fetchrow_hashref;
493
    return $data;
494
}
495
496
# -------------------------------------------------------------------
462
sub DelBudgetPeriod{
497
sub DelBudgetPeriod{
463
	my ($budget_period_id) = @_;
498
	my ($budget_period_id) = @_;
464
	my $dbh = C4::Context->dbh;
499
	my $dbh = C4::Context->dbh;
Lines 602-607 sub DelBudget { Link Here
602
}
637
}
603
638
604
639
640
# -------------------------------------------------------------------
605
=head2 GetBudget
641
=head2 GetBudget
606
642
607
  &GetBudget($budget_id);
643
  &GetBudget($budget_id);
Lines 610-616 get a specific budget Link Here
610
646
611
=cut
647
=cut
612
648
613
# -------------------------------------------------------------------
614
sub GetBudget {
649
sub GetBudget {
615
    my ( $budget_id ) = @_;
650
    my ( $budget_id ) = @_;
616
    my $dbh = C4::Context->dbh;
651
    my $dbh = C4::Context->dbh;
Lines 625-630 sub GetBudget { Link Here
625
    return $result;
660
    return $result;
626
}
661
}
627
662
663
# -------------------------------------------------------------------
664
628
=head2 GetBudgetByOrderNumber
665
=head2 GetBudgetByOrderNumber
629
666
630
  &GetBudgetByOrderNumber($ordernumber);
667
  &GetBudgetByOrderNumber($ordernumber);
Lines 633-639 get a specific budget by order number Link Here
633
670
634
=cut
671
=cut
635
672
636
# -------------------------------------------------------------------
637
sub GetBudgetByOrderNumber {
673
sub GetBudgetByOrderNumber {
638
    my ( $ordernumber ) = @_;
674
    my ( $ordernumber ) = @_;
639
    my $dbh = C4::Context->dbh;
675
    my $dbh = C4::Context->dbh;
Lines 649-654 sub GetBudgetByOrderNumber { Link Here
649
    return $result;
685
    return $result;
650
}
686
}
651
687
688
=head2 GetBudgetReport
689
690
  &GetBudgetReport( [$budget_id] );
691
692
Get all orders for a specific budget, without cancelled orders.
693
694
Returns an array of hashrefs.
695
696
=cut
697
698
# --------------------------------------------------------------------
699
sub GetBudgetReport {
700
    my ( $budget_id ) = @_;
701
    my $dbh = C4::Context->dbh;
702
    my $query = '
703
        SELECT o.*, b.budget_name
704
        FROM   aqbudgets b
705
        INNER JOIN aqorders o
706
        ON b.budget_id = o.budget_id
707
        WHERE  b.budget_id=?
708
        AND (o.orderstatus != "cancelled")
709
        ORDER BY b.budget_name';
710
711
    my $sth = $dbh->prepare($query);
712
    $sth->execute( $budget_id );
713
714
    my @results = ();
715
    while ( my $data = $sth->fetchrow_hashref ) {
716
        push( @results, $data );
717
    }
718
    return @results;
719
}
720
721
=head2 GetBudgetsByActivity
722
723
  &GetBudgetsByActivity( $budget_period_active );
724
725
Get all active or inactive budgets, depending of the value
726
of the parameter.
727
728
1 = active
729
0 = inactive
730
731
=cut
732
733
# --------------------------------------------------------------------
734
sub GetBudgetsByActivity {
735
    my ( $budget_period_active ) = @_;
736
    my $dbh = C4::Context->dbh;
737
    my $query = "
738
        SELECT DISTINCT b.*
739
        FROM   aqbudgetperiods bp
740
        INNER JOIN aqbudgets b
741
        ON bp.budget_period_id = b.budget_period_id
742
        WHERE  bp.budget_period_active=?
743
        ";
744
    my $sth = $dbh->prepare($query);
745
    $sth->execute( $budget_period_active );
746
    my @results = ();
747
    while ( my $data = $sth->fetchrow_hashref ) {
748
        push( @results, $data );
749
    }
750
    return @results;
751
}
752
# --------------------------------------------------------------------
753
=head2 GetBudgetsReport
754
755
  &GetBudgetsReport( [$activity] );
756
757
Get all but cancelled orders for all funds.
758
759
If the optionnal activity parameter is passed, returns orders for active/inactive budgets only.
760
761
active = 1
762
inactive = 0
763
764
Returns an array of hashrefs.
765
766
=cut
767
768
sub GetBudgetsReport {
769
    my ($activity) = @_;
770
    my $dbh = C4::Context->dbh;
771
    my $query = '
772
        SELECT o.*, b.budget_name
773
        FROM   aqbudgetperiods bp
774
        INNER JOIN aqbudgets b
775
        ON bp.budget_period_id = b.budget_period_id
776
        INNER JOIN aqorders o
777
        ON b.budget_id = o.budget_id ';
778
    if($activity ne ''){
779
        $query .= 'WHERE  bp.budget_period_active=? ';
780
    }
781
    $query .= 'AND (o.orderstatus != "cancelled")
782
               ORDER BY b.budget_name';
783
784
    my $sth = $dbh->prepare($query);
785
    if($activity ne ''){
786
        $sth->execute($activity);
787
    }
788
    else{
789
        $sth->execute;
790
    }
791
    my @results = ();
792
    while ( my $data = $sth->fetchrow_hashref ) {
793
        push( @results, $data );
794
    }
795
    return @results;
796
}
797
652
=head2 GetBudgetByCode
798
=head2 GetBudgetByCode
653
799
654
    my $budget = &GetBudgetByCode($budget_code);
800
    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[% sep %]Basket by[% sep %]biblionumber[% 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
(-)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 (+125 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Reports &rsaquo; Orders by fund</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 fund</a> &rsaquo; Results[% ELSE %] &rsaquo; Orders by fund[% 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 fund '[% current_budget_name %]'</h1>
18
[% ELSE %]
19
<h1>Orders by fund</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>Fund</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">
82
    <legend>Filters</legend>
83
    <ol><li><label for="budgetfilter">Fund (Budget): </label><select name="budgetfilter" id="budgetfilter">
84
        <option value="">All funds</option>
85
        <option value="activebudgets">All active funds</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>
100
    <select id='MIME' name='MIME' size='1'>
101
    [% FOREACH outputFormatloo IN outputFormatloop %]
102
        <option value="[% outputFormatloo %]">[% outputFormatloo %]</option>
103
    [% END %]
104
    </select>
105
    <select id='sep' name='sep' size='1'>
106
    [% FOREACH delimiterloo IN delimiterloop %]
107
        <option value="[% delimiterloo %]">[% delimiterloo %]</option>
108
    [% END %]
109
    </select>
110
    </li></ol>
111
    </fieldset>
112
113
<fieldset class="action">    <input type="submit" value="Submit" />
114
    <input type="hidden" name="get_orders" value="1" /></fieldset>
115
</form>
116
117
    [% END %]
118
119
</div>
120
</div>
121
<div class="yui-b">
122
[% INCLUDE 'reports-menu.inc' %]
123
</div>
124
</div>
125
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt (-39 / +40 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 50-72 Link Here
50
	<ul>
50
	<ul>
51
        <li><a href="/cgi-bin/koha/reports/bor_issues_top.pl">Patrons with the most checkouts</a></li>
51
        <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/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 fund</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 (+233 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::GetBudgetsReport(1);
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 eq '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
        my @rows;
163
        foreach my $order (@orders) {
164
            my @row;
165
            push(@row, _surround($order->{'budget_name'}));
166
            push(@row, _surround($order->{'basketno'}));
167
            push(@row, _surround($order->{'authorisedbyname'}));
168
            push(@row, _surround($order->{'biblionumber'}));
169
            push(@row, _surround($order->{'title'}));
170
            push(@row, _surround($order->{'currency'}));
171
            push(@row, _surround($order->{'listprice'}));
172
            push(@row, _surround($order->{'rrp'}));
173
            push(@row, _surround($order->{'ecost'}));
174
            push(@row, _surround($order->{'quantity'}));
175
            push(@row, _surround($order->{'total_rrp'}));
176
            push(@row, _surround($order->{'total_ecost'}));
177
            push(@row, _surround($order->{'entrydate'}));
178
            push(@row, _surround($order->{'datereceived'}));
179
            push(@row, _surround($order->{'notes'}));
180
            push(@rows, \@row);
181
        }
182
183
        my @totalrow;
184
        for(1..9){push(@totalrow, "")};
185
        push(@totalrow, _surround($total_quantity));
186
        push(@totalrow, _surround($total_rrp));
187
        push(@totalrow, _surround($total_ecost));
188
189
        my $csvTemplate = C4::Templates::gettemplate('reports/csv/orders_by_budget.tt', 'intranet', $query);
190
        $csvTemplate->param(sep => $sep, rows => \@rows, totalrow => \@totalrow);
191
        print $csvTemplate->output;
192
193
        exit(0);
194
    }
195
}
196
else {
197
    # Set file export choices
198
    my @outputFormats = ('CSV');
199
    my @CSVdelimiters = qw(; tabulation , \\ / #);
200
201
    # getting all budgets
202
    # active budgets
203
    my @active_budgets = C4::Budgets::GetBudgetsByActivity(1);
204
    # non active budgets
205
    my @non_active_budgets = C4::Budgets::GetBudgetsByActivity(0);
206
    my @budgetsloop;
207
    foreach my $thisbudget ( sort {$a->{budget_name} cmp $b->{budget_name}} @active_budgets ) {
208
        my $budget_period_desc = C4::Budgets::GetBudgetPeriodDescription($thisbudget->{budget_id});
209
        my %row = (
210
            value       => $thisbudget->{budget_id},
211
            description => $thisbudget->{budget_name},
212
            period      => "(" . $budget_period_desc->{budget_period_description} . ")",
213
        );
214
        push @budgetsloop, \%row;
215
    }
216
    foreach my $thisbudget ( sort {$a->{budget_name} cmp $b->{budget_name}} @non_active_budgets ) {
217
        my $budget_period_desc = C4::Budgets::GetBudgetPeriodDescription($thisbudget->{budget_id});
218
        my %row = (
219
            value       => $thisbudget->{budget_id},
220
            description => "[i] ". $thisbudget->{budget_name},
221
            period      => "(" . $budget_period_desc->{budget_period_description} . ")",
222
        );
223
        push @budgetsloop, \%row;
224
    }
225
226
    $template->param(   budgetsloop   => \@budgetsloop,
227
        outputFormatloop => \@outputFormats,
228
        delimiterloop => \@CSVdelimiters
229
    );
230
}
231
232
# writing the template
233
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/t/db_dependent/Acquisition.t (+27 lines)
Lines 143-152 ok( Link Here
143
);
143
);
144
ok( $basket = GetBasket($basketno), "GetBasket($basketno) returns $basket" );
144
ok( $basket = GetBasket($basketno), "GetBasket($basketno) returns $basket" );
145
145
146
my $bpid=AddBudgetPeriod({
147
        budget_period_startdate => '2008-01-01'
148
        , budget_period_enddate => '2008-12-31'
149
        , budget_period_active  => 1
150
        , budget_description    => "MAPERI"
151
});
152
146
my $budgetid = C4::Budgets::AddBudget(
153
my $budgetid = C4::Budgets::AddBudget(
147
    {
154
    {
148
        budget_code => "budget_code_test_getordersbybib",
155
        budget_code => "budget_code_test_getordersbybib",
149
        budget_name => "budget_name_test_getordersbybib",
156
        budget_name => "budget_name_test_getordersbybib",
157
        budget_period_id => $bpid,
150
    }
158
    }
151
);
159
);
152
my $budget = C4::Budgets::GetBudget($budgetid);
160
my $budget = C4::Budgets::GetBudget($budgetid);
Lines 925-928 ok(($order4->{cancellationreason} eq "foobar"), "order has cancellation reason \ Link Here
925
ok((not defined GetBiblio($order4->{biblionumber})), "biblio does not exist anymore");
933
ok((not defined GetBiblio($order4->{biblionumber})), "biblio does not exist anymore");
926
# End of tests for DelOrder
934
# End of tests for DelOrder
927
935
936
# Budget reports
937
938
my @report = GetBudgetReport($budget->{budget_id});
939
ok(@report == 3, "GetBudgetReport OK");
940
941
my $all_count = scalar GetBudgetsReport();
942
ok($all_count >= 3, "GetBudgetReport OK");
943
944
my $active_count = scalar GetBudgetsReport(1);
945
ok($active_count >= 3, "GetBudgetsReport(1) OK");
946
947
# Deactivate budget period
948
my $budgetperiod=GetBudgetPeriod($bpid);
949
$$budgetperiod{budget_period_active}=0;
950
ModBudgetPeriod($budgetperiod);
951
952
ok($all_count == scalar GetBudgetsReport(), "GetBudgetReport returns inactive budget period acquisitions.");
953
ok($active_count >= scalar GetBudgetsReport(1), "GetBudgetReport doesn't return inactive budget period acquisitions.");
954
928
$dbh->rollback;
955
$dbh->rollback;
(-)a/t/db_dependent/Budgets.t (-2 / +63 lines)
Lines 423-428 $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod( Link Here
423
        mark_original_budget_as_inactive => 1,
423
        mark_original_budget_as_inactive => 1,
424
    }
424
    }
425
);
425
);
426
# Add A budget Period
427
if (C4::Context->preference('dateformat') eq "metric"){
428
ok($bpid=AddBudgetPeriod(
429
            { budget_period_startdate   =>'01-01-2008'
430
            , budget_period_enddate     =>'31-12-2008'
431
            , budget_period_description =>"MAPERI"
432
            , budget_period_active      =>1
433
            , budget_description        =>"MAPERI"}),
434
    "AddBudgetPeriod returned $bpid");
435
} elsif (C4::Context->preference('dateformat') eq "us"){
436
ok($bpid=AddBudgetPeriod(
437
            { budget_period_startdate   =>'01-01-2008'
438
            , budget_period_enddate     =>'12-31-2008'
439
            , budget_period_description =>"MAPERI"
440
            , budget_period_active      =>1
441
            , budget_description        =>"MAPERI"}),
442
    "AddBudgetPeriod returned $bpid");
443
}
444
else{
445
ok($bpid=AddBudgetPeriod(
446
            {budget_period_startdate=>'2008-01-01'
447
            ,budget_period_enddate  =>'2008-12-31'
448
            ,budget_description     =>"MAPERI"
449
            ,budget_period_active   =>1
450
            ,budget_period_description  =>"MAPERI"
451
            }),
452
"AddBudgetPeriod returned $bpid");
426
453
427
$budget_hierarchy        = GetBudgetHierarchy($budget_period_id);
454
$budget_hierarchy        = GetBudgetHierarchy($budget_period_id);
428
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
455
$budget_hierarchy_cloned = GetBudgetHierarchy($budget_period_id_cloned);
Lines 458-463 for my $budget (@$budget_hierarchy_cloned) { Link Here
458
is( $number_of_budgets_not_reset, 0,
485
is( $number_of_budgets_not_reset, 0,
459
    'CloneBudgetPeriod has reset all budgets (funds)' );
486
    'CloneBudgetPeriod has reset all budgets (funds)' );
460
487
488
my $budget_name = GetBudgetName( $budget_id );
489
is($budget_name, $budget->{budget_name}, "Test the GetBudgetName routine");
490
491
my $second_budget_id;
492
ok($second_budget_id=AddBudget(
493
                        {   budget_code         => "ZZZZ",
494
                            budget_amount       => "500.00",
495
                            budget_name     => "Art",
496
                            budget_notes        => "This is a note",
497
                            budget_description=> "Art",
498
                            budget_active       => 1,
499
                            budget_period_id    => $bpid,
500
                        }
501
                       ),
502
    "AddBudget returned $second_budget_id");
503
504
my $budgets = GetBudgets({ budget_period_id => $bpid});
505
ok($budgets->[0]->{budget_name} lt $budgets->[1]->{budget_name}, 'default sort order for GetBudgets is by name');
506
507
ok(GetBudgetPeriodDescription($budget_id)->{budget_period_description} eq "MAPERI",
508
    "GetBudgetPeriodDescription OK");
509
510
ok(GetBudgetsByActivity(1) > 0,
511
    "GetActiveBudgets can return active budgets");
512
513
# Deactivate budget period
514
$budgetperiod=GetBudgetPeriod($bpid);
515
$$budgetperiod{budget_period_active}=0;
516
ModBudgetPeriod($budgetperiod);
517
518
ok(GetBudgetsByActivity(0) > 0,
519
    "GetActiveBudgets can return inactive budgets");
520
my $del_status;
521
ok($del_status=DelBudget($budget_id),
522
    "DelBudget returned $del_status");
461
523
462
# MoveOrders
524
# MoveOrders
463
my $number_orders_moved = C4::Budgets::MoveOrders();
525
my $number_orders_moved = C4::Budgets::MoveOrders();
Lines 607-610 sub _get_budgetname_by_id { Link Here
607
# C4::Context->userenv
669
# C4::Context->userenv
608
sub Mock_userenv {
670
sub Mock_userenv {
609
    return $userenv;
671
    return $userenv;
610
}
672
}}
611
- 

Return to bug 11371