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

(-)a/C4/Budgets.pm (-4 / +152 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 77-83 BEGIN { Link Here
77
81
78
# ----------------------------BUDGETS.PM-----------------------------";
82
# ----------------------------BUDGETS.PM-----------------------------";
79
83
80
81
=head1 FUNCTIONS ABOUT BUDGETS
84
=head1 FUNCTIONS ABOUT BUDGETS
82
85
83
=cut
86
=cut
Lines 458-463 sub GetBudgetPeriod { Link Here
458
}
461
}
459
462
460
# -------------------------------------------------------------------
463
# -------------------------------------------------------------------
464
465
=head2 GetBudgetPeriodDescription
466
467
       $description = GetBudgetPeriodDescription($budget_id);
468
469
    Return value: hashref
470
471
    Returns the budget period description for a given budget id.
472
473
    Description is fetched from aqbudgetperiods, id is compared aqbudgets. (INNER JOIN on budget_period_id)
474
475
=cut
476
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
# -------------------------------------------------------------------
461
sub DelBudgetPeriod{
497
sub DelBudgetPeriod{
462
	my ($budget_period_id) = @_;
498
	my ($budget_period_id) = @_;
463
	my $dbh = C4::Context->dbh;
499
	my $dbh = C4::Context->dbh;
Lines 601-606 sub DelBudget { Link Here
601
}
637
}
602
638
603
639
640
# -------------------------------------------------------------------
641
604
=head2 GetBudget
642
=head2 GetBudget
605
643
606
  &GetBudget($budget_id);
644
  &GetBudget($budget_id);
Lines 609-615 get a specific budget Link Here
609
647
610
=cut
648
=cut
611
649
612
# -------------------------------------------------------------------
613
sub GetBudget {
650
sub GetBudget {
614
    my ( $budget_id ) = @_;
651
    my ( $budget_id ) = @_;
615
    my $dbh = C4::Context->dbh;
652
    my $dbh = C4::Context->dbh;
Lines 624-629 sub GetBudget { Link Here
624
    return $result;
661
    return $result;
625
}
662
}
626
663
664
# -------------------------------------------------------------------
665
627
=head2 GetBudgetByOrderNumber
666
=head2 GetBudgetByOrderNumber
628
667
629
  &GetBudgetByOrderNumber($ordernumber);
668
  &GetBudgetByOrderNumber($ordernumber);
Lines 632-638 get a specific budget by order number Link Here
632
671
633
=cut
672
=cut
634
673
635
# -------------------------------------------------------------------
636
sub GetBudgetByOrderNumber {
674
sub GetBudgetByOrderNumber {
637
    my ( $ordernumber ) = @_;
675
    my ( $ordernumber ) = @_;
638
    my $dbh = C4::Context->dbh;
676
    my $dbh = C4::Context->dbh;
Lines 648-653 sub GetBudgetByOrderNumber { Link Here
648
    return $result;
686
    return $result;
649
}
687
}
650
688
689
=head2 GetBudgetReport
690
691
  &GetBudgetReport( [$budget_id] );
692
693
Get all orders for a specific budget, without cancelled orders.
694
695
Returns an array of hashrefs.
696
697
=cut
698
699
# --------------------------------------------------------------------
700
sub GetBudgetReport {
701
    my ( $budget_id ) = @_;
702
    my $dbh = C4::Context->dbh;
703
    my $query = '
704
        SELECT o.*, b.budget_name
705
        FROM   aqbudgets b
706
        INNER JOIN aqorders o
707
        ON b.budget_id = o.budget_id
708
        WHERE  b.budget_id=?
709
        AND (o.orderstatus != "cancelled")
710
        ORDER BY b.budget_name';
711
712
    my $sth = $dbh->prepare($query);
713
    $sth->execute( $budget_id );
714
715
    my @results = ();
716
    while ( my $data = $sth->fetchrow_hashref ) {
717
        push( @results, $data );
718
    }
719
    return @results;
720
}
721
722
=head2 GetBudgetsByActivity
723
724
  &GetBudgetsByActivity( $budget_period_active );
725
726
Get all active or inactive budgets, depending of the value
727
of the parameter.
728
729
1 = active
730
0 = inactive
731
732
=cut
733
734
# --------------------------------------------------------------------
735
sub GetBudgetsByActivity {
736
    my ( $budget_period_active ) = @_;
737
    my $dbh = C4::Context->dbh;
738
    my $query = "
739
        SELECT DISTINCT b.*
740
        FROM   aqbudgetperiods bp
741
        INNER JOIN aqbudgets b
742
        ON bp.budget_period_id = b.budget_period_id
743
        WHERE  bp.budget_period_active=?
744
        ";
745
    my $sth = $dbh->prepare($query);
746
    $sth->execute( $budget_period_active );
747
    my @results = ();
748
    while ( my $data = $sth->fetchrow_hashref ) {
749
        push( @results, $data );
750
    }
751
    return @results;
752
}
753
# --------------------------------------------------------------------
754
755
=head2 GetBudgetsReport
756
757
  &GetBudgetsReport( [$activity] );
758
759
Get all but cancelled orders for all funds.
760
761
If the optionnal activity parameter is passed, returns orders for active/inactive budgets only.
762
763
active = 1
764
inactive = 0
765
766
Returns an array of hashrefs.
767
768
=cut
769
770
sub GetBudgetsReport {
771
    my ($activity) = @_;
772
    my $dbh = C4::Context->dbh;
773
    my $query = '
774
        SELECT o.*, b.budget_name
775
        FROM   aqbudgetperiods bp
776
        INNER JOIN aqbudgets b
777
        ON bp.budget_period_id = b.budget_period_id
778
        INNER JOIN aqorders o
779
        ON b.budget_id = o.budget_id ';
780
    if($activity ne ''){
781
        $query .= 'WHERE  bp.budget_period_active=? ';
782
    }
783
    $query .= 'AND (o.orderstatus != "cancelled")
784
               ORDER BY b.budget_name';
785
786
    my $sth = $dbh->prepare($query);
787
    if($activity ne ''){
788
        $sth->execute($activity);
789
    }
790
    else{
791
        $sth->execute;
792
    }
793
    my @results = ();
794
    while ( my $data = $sth->fetchrow_hashref ) {
795
        push( @results, $data );
796
    }
797
    return @results;
798
}
799
651
=head2 GetBudgetByCode
800
=head2 GetBudgetByCode
652
801
653
    my $budget = &GetBudgetByCode($budget_code);
802
    my $budget = &GetBudgetByCode($budget_code);
Lines 985-991 sub ConvertCurrency { Link Here
985
    return ( $price / $cur );
1134
    return ( $price / $cur );
986
}
1135
}
987
1136
988
989
=head2 CloneBudgetPeriod
1137
=head2 CloneBudgetPeriod
990
1138
991
  my $new_budget_period_id = CloneBudgetPeriod({
1139
  my $new_budget_period_id = CloneBudgetPeriod({
(-)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 %]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 (+143 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
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
10
[% INCLUDE 'datatables.inc' %]
11
<script type="text/javascript">
12
    $(document).ready( function () {
13
        $('#funds').DataTable($.extend(true, {}, dataTablesDefaults,{"sPaginationType": "full_numbers"}));
14
    } );
15
</script>
16
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a>[% IF ( get_orders ) %] &rsaquo; <a href="/cgi-bin/koha/reports/orders_by_fund.pl">Orders by fund</a> &rsaquo; Results[% ELSE %] &rsaquo; Orders by fund[% END %]</div>
17
18
<div id="doc3" class="yui-t2">
19
20
<div id="bd">
21
        <div id="yui-main">
22
        <div class="yui-b">
23
24
[% IF ( current_budget_name ) %]<h1>Orders for fund '[% current_budget_name %]'</h1>
25
[% ELSE %]<h1>Orders by fund</h1>
26
[% END %]
27
28
[% IF ( get_orders ) %]
29
    <div class="results">
30
        [% IF ( total ) %]
31
            Orders found: [% total %]
32
        [% ELSE %]
33
            No order found
34
        [% END %]
35
    </div>
36
37
    [% IF ( ordersloop ) %]<table id="funds">
38
        <thead>
39
        <tr>
40
        <th>Fund</th>
41
        <th>Basket</th>
42
        <th>Basket Name</th>
43
        <th>Basket By</th>
44
        <th>Title</th>
45
        <th>Currency</th>
46
        <th>Vendor Price</th>
47
        <th>RRP</th>
48
        <th>Budgeted Cost</th>
49
        <th>Quantity</th>
50
        <th>Total RRP</th>
51
        <th>Total Cost</th>
52
        <th>Entry Date</th>
53
        <th>Date Received</th>
54
        <th>Notes</th>
55
        </tr>
56
        </thead>
57
        <tbody>
58
        [% FOREACH ordersloo IN ordersloop %]
59
            [% UNLESS ( loop.odd ) %]<tr class="highlight">
60
            [% ELSE %] <tr>
61
            [% END %]
62
            <td>[% ordersloo.budget_name |html %]</td>
63
            <td><a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% ordersloo.basketno %]"> [% ordersloo.basketno |html %]</a></td>
64
            <td>[% ordersloo.basketname |html %]</td>
65
            <td>[% ordersloo.authorisedbyname %]</td>
66
            <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% ordersloo.biblionumber %]"> [% ordersloo.title |html %]</a></td>
67
            <td>[% ordersloo.currency %]</td>
68
            <td>[% ordersloo.listprice %]</td>
69
            <td>[% ordersloo.rrp %]</td>
70
            <td>[% ordersloo.ecost %]</td>
71
            <td>[% ordersloo.quantity %]</td>
72
            <td>[% ordersloo.total_rrp %]</td>
73
            <td>[% ordersloo.total_ecost %]</td>
74
            <td>[% ordersloo.entrydate %]</td>
75
            <td>[% ordersloo.datereceived %]</td>
76
            <td>[% ordersloo.order_internalnote |html %]</td>
77
            </tr>
78
        [% END %]
79
        </tbody>
80
        <tfoot><tr><th>TOTAL</th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th>[% total_quantity %]</th><th>[% total_rrp %]</th><th>[% total_ecost %]</th><th></th><th></th><th></th></tr></tfoot>
81
        </table>
82
    [% END %]
83
    [% ELSE %]
84
        <form name="f" action="/cgi-bin/koha/reports/orders_by_fund.pl" method="post">
85
        <fieldset class="rows">
86
        <legend>Filters</legend>
87
        <ol><li><label for="budgetfilter">Fund (Budget): </label>
88
        <select name="budgetfilter" id="budgetfilter">
89
            <option value="">All funds</option>
90
            <option value="activebudgets">All active funds</option>
91
        [% FOREACH budgetsloo IN budgetsloop %]
92
            [% IF ( budgetsloo.selected ) %]
93
                <option value="[% budgetsloo.value %]" selected="selected">[% budgetsloo.description %] [% budgetsloo.period %]</option>
94
            [% ELSE %]
95
                <option value="[% budgetsloo.value %]">[% budgetsloo.description %] [% budgetsloo.period %]</option>
96
            [% END %]
97
        [% END %]
98
        </select>
99
        </li></ol>
100
        </fieldset>
101
102
        <fieldset class="rows">
103
        <legend>Output</legend>
104
        <ol><li><label for="outputscreen">To screen into the browser: </label><input type="radio" checked="checked" name="output" id="outputscreen" value="screen" /> </li>
105
            <li><label for="outputfile">To a file:</label>
106
                <input type="radio" name="output" value="file" id="outputfile" />
107
                <label class="inline" for="basename">Named: </label>
108
                <input type="text" name="basename" id="basename" value="Export" />
109
                <label class="inline" for="MIME">Into an application </label>
110
                <select id='MIME' name='MIME' size='1'>
111
                [% FOREACH outputFormatloo IN outputFormatloop %]
112
                    <option value="[% outputFormatloo %]">[% outputFormatloo %]</option>
113
                [% END %]
114
                </select>
115
                <select id='sep' name='sep' size='1'>
116
                [% FOREACH delimiterloo IN delimiterloop %]
117
                    [% IF delimiterloo == delimiterPreference %]
118
                        <option value="[% delimiterloo %]">[% delimiterloo %]</option>
119
                    [% END %]
120
                [% END %]
121
                [% FOREACH delimiterloo IN delimiterloop %]
122
                    [% IF delimiterloo != delimiterPreference %]
123
                        <option value="[% delimiterloo %]">[% delimiterloo %]</option>
124
                    [% END %]
125
                [% END %]
126
                </select>
127
        </li></ol>
128
        </fieldset>
129
130
        <fieldset class="action">
131
        <input type="submit" value="Submit" />
132
        <input type="hidden" name="get_orders" value="1" /></fieldset>
133
        </form>
134
135
    [% END %]
136
137
</div>
138
</div>
139
<div class="yui-b">
140
[% INCLUDE 'reports-menu.inc' %]
141
</div>
142
</div>
143
[% 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_fund.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_fund.pl (+238 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::Acquisition; #GetBasket()
38
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
        $order->{'listprice'} = sprintf( "%.2f", $order->{'listprice'} );
116
        $order->{'rrp'} = sprintf( "%.2f", $order->{'rrp'} );
117
        $order->{'ecost'} = sprintf( "%.2f", $order->{'ecost'});
118
        $order->{'total_rrp'} = sprintf( "%.2f", $order->{'total_rrp'});
119
        $order->{'total_ecost'} = sprintf( "%.2f", $order->{'total_ecost'});
120
121
        $total_quantity += $order->{'quantity'};
122
        $total_rrp += $order->{'total_rrp'};
123
        $total_ecost += $order->{'total_ecost'};
124
125
        # Get the budget's name
126
        $order->{'budget_name'} = $budget_name{$order->{'budget_id'}};
127
    }
128
129
    # If we are outputting to screen, output to the template.
130
    if($params->{"output"} eq 'screen') {
131
        $template->param(
132
            total       => scalar @orders,
133
            ordersloop   => \@orders,
134
            get_orders   => $get_orders,
135
            total_quantity => $total_quantity,
136
            total_rrp => sprintf( "%.2f", $total_rrp ),
137
            total_ecost => sprintf( "%.2f", $total_ecost ),
138
        );
139
    }
140
    # If we are outputting to a file, create it and exit.
141
    else {
142
        my $basename = $params->{"basename"};
143
        my $sep = $params->{"sep"};
144
        $sep = "\t" if ($sep eq 'tabulation');
145
146
        print $query->header(
147
           -type       => 'application/vnd.sun.xml.calc',
148
           -encoding    => 'utf-8',
149
           -attachment => "$basename.csv",
150
           -name       => "$basename.csv"
151
        );
152
153
        #binmode STDOUT, ":encoding(UTF-8)";
154
155
        # Surrounds a string with double-quotes and escape the double-quotes inside
156
        sub _surround {
157
            my $string = shift || "";
158
            $string =~ s/"/""/g;
159
            return "\"$string\"";
160
        }
161
        my @rows;
162
        foreach my $order (@orders) {
163
            my @row;
164
            my $sep='';
165
            if ($order->{'order_vendornote'}){
166
            $sep='. Note2:'
167
            }
168
            $order->{'order_internalnote'} .= $sep .$order->{'order_vendornote'};
169
            push(@row, _surround($order->{'budget_name'}));
170
            push(@row, _surround($order->{'basketno'}));
171
            push(@row, _surround($order->{'basketname'}));
172
            push(@row, _surround($order->{'authorisedbyname'}));
173
            push(@row, _surround($order->{'biblionumber'}));
174
            push(@row, _surround($order->{'title'}));
175
            push(@row, _surround($order->{'currency'}));
176
            push(@row, _surround($order->{'listprice'}));
177
            push(@row, _surround($order->{'rrp'}));
178
            push(@row, _surround($order->{'ecost'}));
179
            push(@row, _surround($order->{'quantity'}));
180
            push(@row, _surround($order->{'total_rrp'}));
181
            push(@row, _surround($order->{'total_ecost'}));
182
            push(@row, _surround($order->{'entrydate'}));
183
            push(@row, _surround($order->{'datereceived'}));
184
            push(@row, _surround($order->{'order_internalnote'}));
185
            push(@rows, \@row);
186
        }
187
188
        my @totalrow;
189
        for(1..9){push(@totalrow, "")};
190
        push(@totalrow, _surround($total_quantity));
191
        push(@totalrow, _surround($total_rrp));
192
        push(@totalrow, _surround($total_ecost));
193
194
        my $csvTemplate = C4::Templates::gettemplate('reports/csv/orders_by_budget.tt', 'intranet', $query);
195
        $csvTemplate->param(sep => $sep, rows => \@rows, totalrow => \@totalrow);
196
        print $csvTemplate->output;
197
198
        exit(0);
199
    }
200
}
201
else {
202
    # Set file export choices
203
    my @outputFormats = ('CSV');
204
    my @CSVdelimiters =(',','#',qw(; tabulation \\ /));
205
206
    # getting all budgets
207
    # active budgets
208
    my @active_budgets = C4::Budgets::GetBudgetsByActivity(1);
209
    # non active budgets
210
    my @non_active_budgets = C4::Budgets::GetBudgetsByActivity(0);
211
    my @budgetsloop;
212
    foreach my $thisbudget ( sort {$a->{budget_name} cmp $b->{budget_name}} @active_budgets ) {
213
        my $budget_period_desc = C4::Budgets::GetBudgetPeriodDescription($thisbudget->{budget_id});
214
        my %row = (
215
            value       => $thisbudget->{budget_id},
216
            description => $thisbudget->{budget_name},
217
            period      => "(" . $budget_period_desc->{budget_period_description} . ")",
218
        );
219
        push @budgetsloop, \%row;
220
    }
221
    foreach my $thisbudget ( sort {$a->{budget_name} cmp $b->{budget_name}} @non_active_budgets ) {
222
        my $budget_period_desc = C4::Budgets::GetBudgetPeriodDescription($thisbudget->{budget_id});
223
        my %row = (
224
            value       => $thisbudget->{budget_id},
225
            description => "[i] ". $thisbudget->{budget_name},
226
            period      => "(" . $budget_period_desc->{budget_period_description} . ")",
227
        );
228
        push @budgetsloop, \%row;
229
    }
230
    $template->param(   budgetsloop   => \@budgetsloop,
231
        outputFormatloop => \@outputFormats,
232
        delimiterloop => \@CSVdelimiters,
233
        delimiterPreference => C4::Context->preference('delimiter')
234
    );
235
}
236
237
# writing the template
238
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/t/db_dependent/Acquisition.t (-1 / +22 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 922-924 ok((not defined GetBiblio($order4->{biblionumber})), "biblio does not exist anym Link Here
922
# End of tests for DelOrder
930
# End of tests for DelOrder
923
931
924
$schema->storage->txn_rollback();
932
$schema->storage->txn_rollback();
933
# Budget reports
934
#my @report = GetBudgetReport(1);
935
#ok(@report >= 1, "GetBudgetReport OK");
936
937
my $all_count = scalar GetBudgetsReport();
938
ok($all_count >= 1, "GetBudgetReport OK");
939
940
my $active_count = scalar GetBudgetsReport(1);
941
ok($active_count >= 1 , "GetBudgetsReport(1) OK");
942
943
ok($all_count == scalar GetBudgetsReport(), "GetBudgetReport returns inactive budget period acquisitions.");
944
ok($active_count >= scalar GetBudgetsReport(1), "GetBudgetReport doesn't return inactive budget period acquisitions.");
945
(-)a/t/db_dependent/Budgets.t (-2 / +30 lines)
Lines 1-5 Link Here
1
#!/usr/bin/perl
1
use Modern::Perl;
2
use Modern::Perl;
2
use Test::More tests => 122;
3
use Test::More ;
3
4
4
BEGIN {
5
BEGIN {
5
    use_ok('C4::Budgets')
6
    use_ok('C4::Budgets')
Lines 468-473 for my $budget (@$budget_hierarchy_cloned) { Link Here
468
is( $number_of_budgets_not_reset, 0,
469
is( $number_of_budgets_not_reset, 0,
469
    'CloneBudgetPeriod has reset all budgets (funds)' );
470
    'CloneBudgetPeriod has reset all budgets (funds)' );
470
471
472
#GetBudgetPeriodDescription
473
$my_budgetperiod = {
474
     budget_period_startdate   => '2008-01-01',
475
     budget_period_enddate     => '2008-12-31',
476
     budget_period_description => 'MAPERI',
477
     budget_period_active      => 0,
478
};
479
$bpid = AddBudgetPeriod($my_budgetperiod);
480
$my_budget = {
481
     budget_code      => 'ABCD',
482
     budget_amount    => '123.132000',
483
     budget_name      => 'Periodiques',
484
     budget_notes     => 'This is a note',
485
     budget_period_id => $bpid,
486
};
487
$budget_id = AddBudget($my_budget);
488
my $data=GetBudgetPeriodDescription($budget_id);
489
is( $data->{budget_period_description}, 'MAPERI' ,'GetBudgetPeriodDescription return right value');
490
491
#GetBudgetsByActivity
492
my $result=C4::Budgets::GetBudgetsByActivity(1);
493
isnt( $result, undef ,'GetBudgetsByActivity return correct value with parameter 1');
494
$result=C4::Budgets::GetBudgetsByActivity(0);
495
 isnt( $result, undef ,'GetBudgetsByActivity return correct value with parameter 0');
496
$result=C4::Budgets::GetBudgetsByActivity();
497
 is( $result, 0 , 'GetBudgetsByActivity return 0 with none parameter or other 0 or 1' );
498
DelBudget($budget_id);
499
DelBudgetPeriod($bpid);
471
500
472
# MoveOrders
501
# MoveOrders
473
my $number_orders_moved = C4::Budgets::MoveOrders();
502
my $number_orders_moved = C4::Budgets::MoveOrders();
474
- 

Return to bug 11371