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

(-)a/C4/Budgets.pm (+146 lines)
Lines 36-41 BEGIN { Link Here
36
        &GetBudget
36
        &GetBudget
37
        &GetBudgetByOrderNumber
37
        &GetBudgetByOrderNumber
38
        &GetBudgets
38
        &GetBudgets
39
        &GetActiveBudgets
40
        &GetBudgetReport
41
        &GetBudgetsReport
42
        &GetActiveBudgetsReport
39
        &GetBudgetHierarchy
43
        &GetBudgetHierarchy
40
	    &AddBudget
44
	    &AddBudget
41
        &ModBudget
45
        &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
        &GetAuthvalueDropbox
65
        &GetAuthvalueDropbox
Lines 471-476 sub GetBudgetPeriod { Link Here
471
}
476
}
472
477
473
# -------------------------------------------------------------------
478
# -------------------------------------------------------------------
479
sub GetBudgetPeriodDescription {
480
    my ($budget_id) = @_;
481
    my $dbh = C4::Context->dbh;
482
    my $sth;
483
    if ($budget_id) {
484
        $sth = $dbh->prepare(
485
        "SELECT budget_period_description
486
        FROM aqbudgetperiods bp
487
        INNER JOIN aqbudgets b
488
        ON bp.budget_period_id = b.budget_period_id 
489
        WHERE b.budget_id=?
490
        "
491
        );
492
        $sth->execute($budget_id);
493
    }
494
    my $data = $sth->fetchrow_hashref;
495
    return $data;
496
}
497
498
# -------------------------------------------------------------------
474
sub DelBudgetPeriod{
499
sub DelBudgetPeriod{
475
	my ($budget_period_id) = @_;
500
	my ($budget_period_id) = @_;
476
	my $dbh = C4::Context->dbh;
501
	my $dbh = C4::Context->dbh;
Lines 697-702 sub GetBudgetByOrderNumber { Link Here
697
    return $result;
722
    return $result;
698
}
723
}
699
724
725
=head2 GetBudgetReport
726
727
  &GetBudgetReport();
728
729
Get one specific budget for reports without cancelled baskets.
730
731
=cut
732
733
# --------------------------------------------------------------------
734
sub GetBudgetReport {
735
    my ( $budget_id ) = @_;
736
    my $dbh = C4::Context->dbh;
737
    my $query = "
738
        SELECT o.*, b.budget_name
739
        FROM   aqbudgets b
740
        INNER JOIN aqorders o
741
        ON b.budget_id = o.budget_id
742
        WHERE  b.budget_id=?
743
        AND (o.datecancellationprinted IS NULL OR o.datecancellationprinted='0000-00-00')
744
        ORDER BY b.budget_name
745
        ";
746
    my $sth = $dbh->prepare($query);
747
    $sth->execute( $budget_id );
748
    my @results = ();
749
    while ( my $data = $sth->fetchrow_hashref ) {
750
        push( @results, $data );
751
    }
752
    return @results;
753
}
754
755
=head2 GetBudgetsReport
756
757
  &GetBudgetsReport();
758
759
Get all budgets for reports without cancelled baskets.
760
761
=cut
762
763
# --------------------------------------------------------------------
764
sub GetBudgetsReport {
765
    my $dbh = C4::Context->dbh;
766
    my $query = "
767
        SELECT o.*, b.budget_name
768
        FROM   aqbudgets b
769
        INNER JOIN aqorders o
770
        ON b.budget_id = o.budget_id
771
        WHERE (o.datecancellationprinted IS NULL OR o.datecancellationprinted='0000-00-00')
772
        ORDER BY b.budget_name
773
        ";
774
    my $sth = $dbh->prepare($query);
775
    $sth->execute;
776
    my @results = ();
777
    while ( my $data = $sth->fetchrow_hashref ) {
778
        push( @results, $data );
779
    }
780
    return @results;
781
}
782
783
=head2 GetActiveBudgets
784
785
  &GetActiveBudgets( $budget_period_active );
786
787
Get all active budgets or all inactive budgets, depending of the value 
788
of the parameter.
789
790
1 = active
791
0 = inactive
792
793
=cut
794
795
# --------------------------------------------------------------------
796
sub GetActiveBudgets {
797
    my ( $budget_period_active ) = @_;
798
    my $dbh = C4::Context->dbh;
799
    my $query = "
800
        SELECT DISTINCT b.*
801
        FROM   aqbudgetperiods bp
802
        INNER JOIN aqbudgets b
803
        ON bp.budget_period_id = b.budget_period_id
804
        WHERE  bp.budget_period_active=?
805
        ";
806
    my $sth = $dbh->prepare($query);
807
    $sth->execute( $budget_period_active );
808
    my @results = ();
809
    while ( my $data = $sth->fetchrow_hashref ) {
810
        push( @results, $data );
811
    }
812
    return @results;
813
}
814
815
=head2 GetActiveBudgetsReport
816
817
  &GetActiveBudgetsReport();
818
819
Get all active budgets for reports without cancelled baskets.
820
821
=cut
822
823
# --------------------------------------------------------------------
824
sub GetActiveBudgetsReport {
825
    my $dbh = C4::Context->dbh;
826
    my $query = "
827
        SELECT o.*, b.budget_name
828
        FROM   aqbudgetperiods bp
829
        INNER JOIN aqbudgets b
830
        ON bp.budget_period_id = b.budget_period_id
831
        INNER JOIN aqorders o
832
        ON b.budget_id = o.budget_id
833
        WHERE  bp.budget_period_active=1
834
        AND (o.datecancellationprinted IS NULL OR o.datecancellationprinted='0000-00-00')
835
        ORDER BY b.budget_name
836
        ";
837
    my $sth = $dbh->prepare($query);
838
    $sth->execute;
839
    my @results = ();
840
    while ( my $data = $sth->fetchrow_hashref ) {
841
        push( @results, $data );
842
    }
843
    return @results;
844
}
845
700
=head2 GetChildBudgetsSpent
846
=head2 GetChildBudgetsSpent
701
847
702
  &GetChildBudgetsSpent($budget-id);
848
  &GetChildBudgetsSpent($budget-id);
(-)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 (-4 / +5 lines)
Lines 61-71 Link Here
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/manager.pl?report_name=itemtypes">Catalog by itemtype</a></li>
65
		<li><a href="/cgi-bin/koha/reports/issues_avg_stats.pl">Average loan time</a></li>
66
		<li><a href="/cgi-bin/koha/reports/issues_avg_stats.pl">Average loan time</a></li>
66
        <li><a href="http://schema.koha-community.org/" target="blank">Koha database schema</a></li>
67
                <li><a href="http://schema.koha-community.org/" target="blank">Koha database schema</a></li>
67
        <li><a href="http://wiki.koha-community.org/wiki/SQL_Reports_Library" target="blank">Koha reports library</a></li>
68
                <li><a href="http://wiki.koha-community.org/wiki/SQL_Reports_Library" target="blank">Koha reports library</a></li>
68
        <!--<li><a href="/cgi-bin/koha/reports/stats.screen.pl">Till reconciliation</a></li> -->
69
                <!--<li><a href="/cgi-bin/koha/reports/stats.screen.pl">Till reconciliation</a></li> -->
69
	</ul></div>
70
	</ul></div>
70
</div>
71
</div>
71
72
(-)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 2 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, ":utf8";
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 (-1 / +29 lines)
Lines 8-14 use POSIX qw(strftime); Link Here
8
8
9
use C4::Bookseller qw( GetBookSellerFromId );
9
use C4::Bookseller qw( GetBookSellerFromId );
10
10
11
use Test::More tests => 63;
11
use Test::More tests => 68;
12
12
13
BEGIN {
13
BEGIN {
14
    use_ok('C4::Acquisition');
14
    use_ok('C4::Acquisition');
Lines 40-49 my ($basket, $basketno); Link Here
40
ok($basketno = NewBasket($booksellerid, 1), "NewBasket(  $booksellerid , 1  ) returns $basketno");
40
ok($basketno = NewBasket($booksellerid, 1), "NewBasket(  $booksellerid , 1  ) returns $basketno");
41
ok($basket   = GetBasket($basketno), "GetBasket($basketno) returns $basket");
41
ok($basket   = GetBasket($basketno), "GetBasket($basketno) returns $basket");
42
42
43
my $bpid=AddBudgetPeriod({
44
        budget_period_startdate	=> '2008-01-01'
45
        , budget_period_enddate		=> '2008-12-31'
46
        , budget_period_active		=> 1
47
        , budget_description		=> "MAPERI"
48
});
49
43
my $budgetid = C4::Budgets::AddBudget(
50
my $budgetid = C4::Budgets::AddBudget(
44
    {
51
    {
45
        budget_code => "budget_code_test_getordersbybib",
52
        budget_code => "budget_code_test_getordersbybib",
46
        budget_name => "budget_name_test_getordersbybib",
53
        budget_name => "budget_name_test_getordersbybib",
54
        budget_period_id => $bpid,
47
    }
55
    }
48
);
56
);
49
my $budget = C4::Budgets::GetBudget( $budgetid );
57
my $budget = C4::Budgets::GetBudget( $budgetid );
Lines 224-227 is($order3->{'quantityreceived'}, 2, 'Order not split up'); Link Here
224
is($order3->{'quantity'}, 2, '2 items on order');
232
is($order3->{'quantity'}, 2, '2 items on order');
225
is($order3->{'budget_id'}, $budgetid2, 'Budget has changed');
233
is($order3->{'budget_id'}, $budgetid2, 'Budget has changed');
226
234
235
236
# Budget reports
237
238
my @report = GetBudgetReport($budget->{budget_id});
239
ok(@report == 3, "GetBudgetReport OK");
240
241
my $all_count = scalar GetBudgetsReport();
242
ok($all_count >= 3, "GetBudgetsReport OK");
243
244
my $active_count = scalar GetActiveBudgetsReport();
245
ok($active_count >= 3, "GetActiveBudgetsReport OK");
246
247
# Deactivate budget period
248
my $budgetperiod=GetBudgetPeriod($bpid);
249
$$budgetperiod{budget_period_active}=0;
250
ModBudgetPeriod($budgetperiod);
251
252
ok($all_count == scalar GetBudgetsReport(), "GetBudgetReport returns inactive budget period acquisitions.");
253
ok($active_count >= scalar GetActiveBudgetsReport(), "GetBudgetReport doesn't return inactive budget period acquisitions.");
254
227
$dbh->rollback;
255
$dbh->rollback;
(-)a/t/db_dependent/Budgets.t (-2 / +21 lines)
Lines 1-6 Link Here
1
use strict;
1
use strict;
2
use warnings;
2
use warnings;
3
use Test::More tests=>20;
3
use Test::More tests=>23;
4
4
5
BEGIN {use_ok('C4::Budgets') }
5
BEGIN {use_ok('C4::Budgets') }
6
use C4::Dates;
6
use C4::Dates;
Lines 46-57 if (C4::Context->preference('dateformat') eq "metric"){ Link Here
46
ok($bpid=AddBudgetPeriod(
46
ok($bpid=AddBudgetPeriod(
47
						{ budget_period_startdate	=>'01-01-2008'
47
						{ budget_period_startdate	=>'01-01-2008'
48
						, budget_period_enddate		=>'31-12-2008'
48
						, budget_period_enddate		=>'31-12-2008'
49
						, budget_period_description	=>"MAPERI"
50
						, budget_period_active		=>1
49
						, budget_description		=>"MAPERI"}),
51
						, budget_description		=>"MAPERI"}),
50
	"AddBudgetPeriod returned $bpid");
52
	"AddBudgetPeriod returned $bpid");
51
} elsif (C4::Context->preference('dateformat') eq "us"){
53
} elsif (C4::Context->preference('dateformat') eq "us"){
52
ok($bpid=AddBudgetPeriod(
54
ok($bpid=AddBudgetPeriod(
53
						{ budget_period_startdate	=>'01-01-2008'
55
						{ budget_period_startdate	=>'01-01-2008'
54
						, budget_period_enddate		=>'12-31-2008'
56
						, budget_period_enddate		=>'12-31-2008'
57
						, budget_period_description	=>"MAPERI"
58
						, budget_period_active		=>1
55
						, budget_description		=>"MAPERI"}),
59
						, budget_description		=>"MAPERI"}),
56
	"AddBudgetPeriod returned $bpid");
60
	"AddBudgetPeriod returned $bpid");
57
}
61
}
Lines 60-65 ok($bpid=AddBudgetPeriod( Link Here
60
						{budget_period_startdate=>'2008-01-01'
64
						{budget_period_startdate=>'2008-01-01'
61
						,budget_period_enddate	=>'2008-12-31'
65
						,budget_period_enddate	=>'2008-12-31'
62
						,budget_description		=>"MAPERI"
66
						,budget_description		=>"MAPERI"
67
						,budget_period_active	=>1
68
						,budget_period_description	=>"MAPERI"
63
						}),
69
						}),
64
	"AddBudgetPeriod returned $bpid");
70
	"AddBudgetPeriod returned $bpid");
65
71
Lines 125-130 ok($second_budget_id=AddBudget( Link Here
125
my $budgets = GetBudgets({ budget_period_id => $bpid});
131
my $budgets = GetBudgets({ budget_period_id => $bpid});
126
ok($budgets->[0]->{budget_name} lt $budgets->[1]->{budget_name}, 'default sort order for GetBudgets is by name');
132
ok($budgets->[0]->{budget_name} lt $budgets->[1]->{budget_name}, 'default sort order for GetBudgets is by name');
127
133
134
ok(GetBudgetPeriodDescription($budget_id)->{budget_period_description} eq "MAPERI",
135
    "GetBudgetPeriodDescription OK");
136
137
ok(GetActiveBudgets(1) > 0,
138
    "GetActiveBudgets can return active budgets");
139
140
# Deactivate budget period
141
$budgetperiod=GetBudgetPeriod($bpid);
142
$$budgetperiod{budget_period_active}=0;
143
ModBudgetPeriod($budgetperiod);
144
145
ok(GetActiveBudgets(0) > 0,
146
    "GetActiveBudgets can return inactive budgets");
147
128
ok($del_status=DelBudget($budget_id),
148
ok($del_status=DelBudget($budget_id),
129
    "DelBudget returned $del_status");
149
    "DelBudget returned $del_status");
130
150
131
- 

Return to bug 11371