|
Lines 16-40
Link Here
|
| 16 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
16 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
| 17 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 |
|
18 |
|
| 19 |
|
|
|
| 20 |
|
| 21 |
=head1 NAME |
19 |
=head1 NAME |
| 22 |
|
20 |
|
| 23 |
acqui-home.pl |
21 |
acqui-home.pl |
| 24 |
|
22 |
|
| 25 |
=head1 DESCRIPTION |
23 |
=head1 DESCRIPTION |
| 26 |
|
24 |
|
| 27 |
this script is the main page for acqui/ |
25 |
this script is the main page for acqui |
| 28 |
|
|
|
| 29 |
=head1 CGI PARAMETERS |
| 30 |
|
| 31 |
=over 4 |
| 32 |
|
| 33 |
=item $status |
| 34 |
C<$status> is the status a suggestion could has. Default value is 'ASKED'. |
| 35 |
thus, it can be REJECTED, ACCEPTED, ORDERED, ASKED, AVAIBLE |
| 36 |
|
| 37 |
=back |
| 38 |
|
26 |
|
| 39 |
=cut |
27 |
=cut |
| 40 |
|
28 |
|
|
Lines 45-95
use Number::Format;
Link Here
|
| 45 |
use CGI; |
33 |
use CGI; |
| 46 |
use C4::Auth; |
34 |
use C4::Auth; |
| 47 |
use C4::Output; |
35 |
use C4::Output; |
| 48 |
use C4::Suggestions; |
|
|
| 49 |
use C4::Acquisition; |
36 |
use C4::Acquisition; |
| 50 |
use C4::Budgets; |
37 |
use C4::Budgets; |
| 51 |
use C4::Members; |
38 |
use C4::Members; |
| 52 |
use C4::Branch; |
39 |
use C4::Branch; |
| 53 |
use C4::Debug; |
40 |
use C4::Debug; |
| 54 |
|
41 |
|
| 55 |
my $query = new CGI; |
42 |
my $query = CGI->new; |
| 56 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
43 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
| 57 |
{ |
44 |
{ template_name => 'acqui/acqui-home.tmpl', |
| 58 |
template_name => "acqui/acqui-home.tmpl", |
|
|
| 59 |
query => $query, |
45 |
query => $query, |
| 60 |
type => "intranet", |
46 |
type => 'intranet', |
| 61 |
authnotrequired => 0, |
47 |
authnotrequired => 0, |
| 62 |
flagsrequired => { acquisition => "*" }, |
48 |
flagsrequired => { acquisition => '*' }, |
| 63 |
debug => 1, |
49 |
debug => 1, |
| 64 |
} |
50 |
} |
| 65 |
); |
51 |
); |
| 66 |
|
52 |
|
| 67 |
# budget |
53 |
my $user = GetMember( 'borrowernumber' => $loggedinuser ); |
| 68 |
my $borrower= GetMember('borrowernumber' => $loggedinuser); |
54 |
my $branchname = GetBranchName($user->{branchcode}); |
| 69 |
my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'}); |
|
|
| 70 |
|
| 71 |
my @results = GetBudgets($homebranch); |
| 72 |
my $count = scalar @results; |
| 73 |
my $branchname = GetBranchName($homebranch); |
| 74 |
|
| 75 |
my $classlist = ''; |
| 76 |
my $total = 0; |
| 77 |
my $totspent = 0; |
| 78 |
my $totordered = 0; |
| 79 |
my $totcomtd = 0; |
| 80 |
my $totavail = 0; |
| 81 |
my @loop_budget = (); |
| 82 |
|
55 |
|
| 83 |
# --------------------------------------------------- |
|
|
| 84 |
# currencies |
| 85 |
my $cur; |
| 86 |
|
56 |
|
| 87 |
my $active_currency = GetCurrency; |
57 |
my $num_formatter; |
| 88 |
my $num; |
|
|
| 89 |
|
58 |
|
| 90 |
my $cur_format = C4::Context->preference("CurrencyFormat"); |
59 |
my $cur_format = C4::Context->preference("CurrencyFormat"); |
| 91 |
if ( $cur_format eq 'FR' ) { |
60 |
if ( $cur_format eq 'FR' ) { |
| 92 |
$num = new Number::Format( |
61 |
$num_formatter = Number::Format->new( |
| 93 |
'decimal_fill' => '2', |
62 |
'decimal_fill' => '2', |
| 94 |
'decimal_point' => ',', |
63 |
'decimal_point' => ',', |
| 95 |
'int_curr_symbol' => '', |
64 |
'int_curr_symbol' => '', |
|
Lines 97-189
if ( $cur_format eq 'FR' ) {
Link Here
|
| 97 |
'thousands_sep' => ' ', |
66 |
'thousands_sep' => ' ', |
| 98 |
'mon_decimal_point' => ',' |
67 |
'mon_decimal_point' => ',' |
| 99 |
); |
68 |
); |
| 100 |
} else { # US by default.. |
69 |
} else { # US by default.. |
| 101 |
$num = new Number::Format( |
70 |
$num_formatter = Number::Format->new( |
| 102 |
'int_curr_symbol' => '', |
71 |
'int_curr_symbol' => '', |
| 103 |
'mon_thousands_sep' => ',', |
72 |
'mon_thousands_sep' => ',', |
| 104 |
'mon_decimal_point' => '.' |
73 |
'mon_decimal_point' => '.' |
| 105 |
); |
74 |
); |
| 106 |
} |
75 |
} |
| 107 |
|
76 |
|
| 108 |
# suggestions |
77 |
my $budget_arr = |
| 109 |
my $status = $query->param('status') || "ASKED"; |
78 |
GetBudgetHierarchy( '', $user->{branchcode}, |
| 110 |
my $suggestion = CountSuggestion($status); |
79 |
$template->{param_map}->{'USER_INFO'}[0]->{'borrowernumber'} ); |
| 111 |
my $suggestions_loop = &SearchSuggestion( {STATUS=> $status} ); |
|
|
| 112 |
# --------------------------------------------------- |
| 113 |
# number format |
| 114 |
my $period = GetBudgetPeriod; |
| 115 |
my $budget_period_id = $period->{budget_period_id}; |
| 116 |
my $budget_branchcode = $period->{budget_branchcode}; |
| 117 |
my $moo = GetBudgetHierarchy('',$homebranch, $template->{param_map}->{'USER_INFO'}[0]->{'borrowernumber'} ); |
| 118 |
@results = @$moo; |
| 119 |
my $period_total = 0; |
| 120 |
my $toggle = 0; |
| 121 |
my @loop; |
| 122 |
|
| 123 |
foreach my $result (@results) { |
| 124 |
# only get top-level budgets for display |
| 125 |
# warn $result->{'budget_branchcode'}; |
| 126 |
|
| 127 |
$period_total += $result->{'budget_amount'}; |
| 128 |
|
| 129 |
my $a = $result->{'budget_code_indent'}; |
| 130 |
$a =~ s/\ /\ \;/g; |
| 131 |
$result->{'budget_code_indent'} = $a; |
| 132 |
|
| 133 |
my $r = GetBranchName( $result->{'budget_owner_id'} ); |
| 134 |
$result->{'budget_branchname'} = GetBranchName( $result->{'budget_branchcode'} ); |
| 135 |
|
| 136 |
my $member = GetMember( borrowernumber => $result->{budget_owner_id} ); |
| 137 |
my $member_full = $member->{'firstname'} . ' ' . $member->{'surname'} if $member; |
| 138 |
# as we are going to treat these as numbers let's ensure they are not NULL |
| 139 |
if (!defined $result->{budget_amount} ) { |
| 140 |
$result->{budget_amount} = 0; |
| 141 |
} |
| 142 |
if (!defined $result->{budget_spent} ) { |
| 143 |
$result->{budget_spent} = 0; |
| 144 |
} |
| 145 |
if (!defined $result->{budget_ordered} ) { |
| 146 |
$result->{budget_ordered} = 0; |
| 147 |
} |
| 148 |
|
80 |
|
| 149 |
$result->{'budget_owner'} = $member_full; |
81 |
my $total = 0; |
| 150 |
$result->{'budget_ordered'} = GetBudgetOrdered( $result->{'budget_id'} ); |
82 |
my $totspent = 0; |
| 151 |
$result->{'budget_spent'} = GetBudgetSpent( $result->{'budget_id'} ); |
83 |
my $totordered = 0; |
| 152 |
$result->{'budget_avail'} = $result->{'budget_amount'} - $result->{'budget_spent'} - $result->{'budget_ordered'}; |
84 |
my $totcomtd = 0; |
|
|
85 |
my $totavail = 0; |
| 153 |
|
86 |
|
| 154 |
$total += $result->{'budget_amount'}; |
87 |
foreach my $budget ( @{$budget_arr} ) { |
| 155 |
$totspent += $result->{'budget_spent'}; |
|
|
| 156 |
$totordered += $result->{'budget_ordered'}; |
| 157 |
$totavail += $result->{'budget_avail'}; |
| 158 |
|
88 |
|
| 159 |
$result->{'budget_amount'} = $num->format_price( $result->{'budget_amount'} ); |
89 |
$budget->{budget_code_indent} =~ s/\ /\ \;/g; |
| 160 |
$result->{'budget_spent'} = $num->format_price( $result->{'budget_spent'} ); |
|
|
| 161 |
$result->{'budget_ordered'} = $num->format_price( $result->{'budget_ordered'} ); |
| 162 |
$result->{'budget_avail'} = $num->format_price( $result->{'budget_avail'} ); |
| 163 |
|
90 |
|
| 164 |
# my $spent_percent = ( $result->{'budget_spent'} / $result->{'budget_amount'} ) * 100; |
91 |
$budget->{'budget_branchname'} = |
| 165 |
# $result->{'budget_spent_percent'} = sprintf( "%00d", $spent_percent ); |
92 |
GetBranchName( $budget->{'budget_branchcode'} ); |
| 166 |
|
93 |
|
|
|
94 |
my $member = GetMember( borrowernumber => $budget->{budget_owner_id} ); |
| 167 |
if ($member) { |
95 |
if ($member) { |
| 168 |
$result->{budget_owner_name} = $member->{'firstname'} . ' ' . $member->{'surname'}; |
96 |
$budget->{budget_owner} = |
|
|
97 |
$member->{'firstname'} . ' ' . $member->{'surname'}; |
| 98 |
} |
| 99 |
|
| 100 |
if ( !defined $budget->{budget_amount} ) { |
| 101 |
$budget->{budget_amount} = 0; |
| 169 |
} |
102 |
} |
| 170 |
|
103 |
|
| 171 |
push( @loop_budget, { %{$result}, toggle => $toggle++ % 2, } ); |
104 |
$budget->{'budget_ordered'} = GetBudgetOrdered( $budget->{'budget_id'} ); |
|
|
105 |
$budget->{'budget_spent'} = GetBudgetSpent( $budget->{'budget_id'} ); |
| 106 |
if ( !defined $budget->{budget_spent} ) { |
| 107 |
$budget->{budget_spent} = 0; |
| 108 |
} |
| 109 |
if ( !defined $budget->{budget_ordered} ) { |
| 110 |
$budget->{budget_ordered} = 0; |
| 111 |
} |
| 112 |
$budget->{'budget_avail'} = |
| 113 |
$budget->{'budget_amount'} - ( $budget->{'budget_spent'} + $budget->{'budget_ordered'} ); |
| 114 |
|
| 115 |
$total += $budget->{'budget_amount'}; |
| 116 |
$totspent += $budget->{'budget_spent'}; |
| 117 |
$totordered += $budget->{'budget_ordered'}; |
| 118 |
$totavail += $budget->{'budget_avail'}; |
| 119 |
|
| 120 |
for my $field (qw( budget_amount budget_spent budget_ordered budget_avail ) ) { |
| 121 |
$budget->{$field} = $num_formatter->format_price( $budget->{$field} ); |
| 122 |
} |
| 172 |
} |
123 |
} |
| 173 |
|
124 |
|
| 174 |
$template->param( |
125 |
$template->param( |
| 175 |
classlist => $classlist, |
126 |
|
| 176 |
type => 'intranet', |
127 |
type => 'intranet', |
| 177 |
loop_budget => \@loop_budget, |
128 |
loop_budget => $budget_arr, |
| 178 |
active_symbol => $active_currency->{'symbol'}, |
|
|
| 179 |
branchname => $branchname, |
129 |
branchname => $branchname, |
| 180 |
budget => $period->{budget_name}, |
130 |
total => $num_formatter->format_price($total), |
| 181 |
total => $num->format_price( $total ), |
131 |
totspent => $num_formatter->format_price($totspent), |
| 182 |
totspent => $num->format_price( $totspent ), |
132 |
totordered => $num_formatter->format_price($totordered), |
| 183 |
totordered => $num->format_price( $totordered ), |
133 |
totcomtd => $num_formatter->format_price($totcomtd), |
| 184 |
totcomtd => $num->format_price( $totcomtd ), |
134 |
totavail => $num_formatter->format_price($totavail), |
| 185 |
totavail => $num->format_price( $totavail ), |
|
|
| 186 |
suggestion => $suggestion, |
| 187 |
); |
135 |
); |
| 188 |
|
136 |
|
| 189 |
output_html_with_http_headers $query, $cookie, $template->output; |
137 |
output_html_with_http_headers $query, $cookie, $template->output; |