use C4::Output;
use C4::Koha;
use C4::Debug;
-#use POSIX qw(locale_h);
my $input = new CGI;
my $dbh = C4::Context->dbh;
my ($template, $borrowernumber, $cookie, $staffflags ) = get_template_and_user(
- { template_name => "admin/aqbudgets.tmpl",
+ { template_name => "admin/aqbudgets.tt",
query => $input,
type => "intranet",
authnotrequired => 0,
currency => $cur->{currency}
);
-my $op = $input->param('op') // '';
+my $op = $input->param('op') || 'list';
-# see if the user want to see all budgets or only owned ones
-my $show_mine = 1; #SHOW BY DEFAULT
-my $show = $input->param('show') // 0; # SET TO 1, BY A FORM SUMBIT
-$show_mine = $input->param('show_mine') if $show == 1;
+# see if the user want to see all budgets or only owned ones by default
+my $show_mine = $input->param('show_mine') // 1;
# IF USER DOESNT HAVE PERM FOR AN 'ADD', THEN REDIRECT TO THE DEFAULT VIEW...
if (not defined $template->{VARS}->{'CAN_user_acquisition_budget_add_del'}
and $op eq 'add_form')
{
- $op = '';
+ $op = 'list';
}
my $num=FormatNumber;
-my $script_name = "/cgi-bin/koha/admin/aqbudgets.pl";
my $budget_hash = $input->Vars;
my $budget_id = $$budget_hash{budget_id};
+my $budget_period_id = $input->param('budget_period_id');
my $budget_permission = $input->param('budget_permission');
my $filter_budgetbranch = $input->param('filter_budgetbranch') // '';
my $filter_budgetname = $input->param('filter_budgetname');
#filtering non budget keys
delete $$budget_hash{$_} foreach grep {/filter|^op$|show/} keys %$budget_hash;
-$template->param(
- notree => ($filter_budgetbranch or $show_mine)
-);
# ' ------- get periods stuff ------------------'
# IF PERIODID IS DEFINED, GET THE PERIOD - ELSE JUST GET THE ACTIVE PERIOD BY DEFAULT
-my $period = GetBudgetPeriod($$budget_hash{budget_period_id});
+my $period;
+if ( $budget_period_id ) {
+ $period = GetBudgetPeriod( $budget_period_id );
+}
-$template->param(
- %$period
-);
# ------- get periods stuff ------------------
# USED FOR PERMISSION COMPARISON LATER
my $user_branchcode = $user->{'branchcode'};
$template->param(
- action => $script_name,
- script_name => $script_name,
show_mine => $show_mine,
- $op || else => 1,
+ op => $op,
);
-
# retrieve branches
my ( $budget, );
push @branchloop2, \%row;
}
-$template->param(auth_cats_loop => GetBudgetAuthCats($$period{budget_period_id}) );
+$template->param(auth_cats_loop => GetBudgetAuthCats( $budget_period_id ))
+ if $budget_period_id;
# Used to create form to add or modify a record
if ($op eq 'add_form') {
# if no buget_id is passed then its an add
$template->param(
- add_validate => 1,
budget_parent_id => $budget_parent->{'budget_id'},
budget_parent_name => $budget_parent->{'budget_name'},
branchloop_select => \@branchloop_select,
);
# END $OP eq DELETE_CONFIRM
# called by delete_confirm, used to effectively confirm deletion of data in DB
-} else{
- if ( $op eq 'delete_confirmed' ) {
- my $rc = DelBudget($budget_id);
- }elsif( $op eq 'add_validate' ) {
- my @budgetusersid;
- if (defined $$budget_hash{'budget_users_ids'}){
- @budgetusersid = split(':', $budget_hash->{'budget_users_ids'});
- }
+} elsif ( $op eq 'delete_confirmed' ) {
+ my $rc = DelBudget($budget_id);
+ $op = 'list';
+} elsif( $op eq 'add_validate' ) {
+ my @budgetusersid;
+ if (defined $$budget_hash{'budget_users_ids'}){
+ @budgetusersid = split(':', $budget_hash->{'budget_users_ids'});
+ }
- if ( defined $$budget_hash{budget_id} ) {
- if (CanUserModifyBudget($borrowernumber, $budget_hash->{budget_id},
- $staffflags)
- ) {
- ModBudget( $budget_hash );
- ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid);
- }
- else {
- $template->param(error_not_authorised_to_modify => 1);
- }
- } else {
- AddBudget( $budget_hash );
+ if ( defined $$budget_hash{budget_id} ) {
+ if (CanUserModifyBudget($borrowernumber, $budget_hash->{budget_id},
+ $staffflags)
+ ) {
+ ModBudget( $budget_hash );
ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid);
}
+ else {
+ $template->param(error_not_authorised_to_modify => 1);
+ }
+ } else {
+ AddBudget( $budget_hash );
+ ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid);
}
+ $op = 'list';
+}
+
+if ( $op eq 'list' ) {
my $branches = GetBranches();
$template->param(
- budget_id => $budget_id,
+ budget_id => $budget_id,
%$period,
);
C4::Context->userenv->{branchcode}, $show_mine ? $borrower_id : '')
};
- my $toggle = 0;
- my @loop;
my $period_total = 0;
my ($period_alloc_total, $spent_total, $ordered_total, $available_total) = (0,0,0,0);
push @budget_hierarchy, { element_name => $period->{"budget_period_description"} };
@budget_hierarchy = reverse(@budget_hierarchy);
- push( @loop, { %{$budget},
- branchname => $branches->{ $budget->{branchcode} }->{branchname},
- budget_hierarchy => \@budget_hierarchy,
- }
- );
+ $budget->{branchname} = $branches->{ $budget->{branchcode} }->{branchname};
+ $budget->{budget_hierarchy} = \@budget_hierarchy;
}
my $budget_period_total = $period->{budget_period_total};
$_ = $num->format_price($_);
}
+ my $periods = GetBudgetPeriods();
+
$template->param(
- else => 1,
- budget => \@loop,
+ op => 'list',
+ budgets => \@budgets,
+ periods => $periods,
budget_period_total => $budget_period_total,
period_alloc_total => $period_alloc_total,
spent_total => $spent_total,
branchloop => \@branchloop2,
);
-} #---- END $OP eq DEFAULT
+} #---- END list
output_html_with_http_headers $input, $cookie, $template->output;
[% INCLUDE 'doc-head-open.inc' %]
-<title>Koha › Administration › Funds[% IF ( add_form ) %] › [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name %]'[% END %][% ELSE %]Add fund [% END %][% END %]</title>
+<title>Koha › Administration › Funds[% IF op == 'add_form' %] › [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name %]'[% END %][% ELSE %]Add fund [% END %][% END %]</title>
[% INCLUDE 'doc-head-close.inc' %]
<script type="text/javascript">
//<![CDATA[
</script>
<script type="text/javascript" src="[% themelang %]/js/acq.js"></script>
-
-[% IF ( add_form ) %]
+[% IF op == 'add_form' %]
<script type="text/javascript">
//<![CDATA[
}
//]]>
</script>
-[% ELSE %]
- [% IF ( notree ) %]
- <link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
- [% INCLUDE 'datatables.inc' %]
- [% ELSE %]
- <link href="[% themelang %]/lib/jquery/plugins/treetable/stylesheets/jquery.treeTable.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/treetable/jquery.treeTable.min.js"></script>
- [% END %]
-
-<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.qtip.js"></script>
+[% ELSIF op == 'list' %]
+ <link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
+ [% INCLUDE 'datatables.inc' %]
+ <link href="[% interface %]/lib/jquery/plugins/treetable/stylesheets/jquery.treetable.css" rel="stylesheet" type="text/css" />
+ <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/treetable/jquery.treetable.js"></script>
<script type="text/javascript">
//<![CDATA[
//
$(document).ready(function() {
- var tooltipcontent = $(".tooltipcontent");
- tooltipcontent.hide();
-
- $(".tooltiped td").each(function (){
- contentelem = $(this).parent().children().filter(".tooltipcontent");
- if(contentelem.html() != ""){
- $(this).qtip({
- content: contentelem.html(),
- show: "mouseover",
- hide: "mouseout",
- style: {
- name: "light",
- tip: "bottomLeft",
- border: {
- radius: 5,
- color: "#356CA1"
- }
- },
- position: {
- corner: {
- target: "topRight",
- tooltip: "bottomRight"
+ var oTable = $("#budgeth").dataTable($.extend(true, {}, dataTablesDefaults, {
+ "fnDrawCallback": function ( oSettings ) {
+ if ( oSettings.aiDisplay.length == 0 )
+ {
+ return;
+ }
+
+ var nTrs = $('#budgeth tbody tr');
+ var iColspan = nTrs[0].getElementsByTagName('td').length;
+ var sLastGroup = "";
+ for ( var i=0 ; i<nTrs.length ; i++ )
+ {
+ var iDisplayIndex = oSettings._iDisplayStart + i;
+ var sGroup = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData[0];
+ if ( sGroup != sLastGroup )
+ {
+ var nGroup = document.createElement( 'tr' );
+ var nCell = document.createElement( 'td' );
+ nCell.colSpan = iColspan;
+ nCell.className = "group";
+ nCell.innerHTML = sGroup;
+ nGroup.appendChild( nCell );
+ nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
+ sLastGroup = sGroup;
}
}
- });
- }
+ },
+ "aoColumnDefs": [
+ { "bVisible": false, "aTargets": [ 0 ] }
+ ],
+ "aaSortingFixed": [[ 0, 'asc' ]],
+ "aaSorting": [[ 1, 'asc' ]],
+ 'bSort': false,
+ 'bPaginate': false,
+ "bAutoWidth": false
+ }));
+
+ $(oTable).treetable({
+ expandable: true
+ });
+ $(oTable).treetable('expandAll');
+ $("#expand_all").click(function(e){
+ e.preventDefault();
+ $(oTable).treetable('expandAll');
+ });
+ $("#collapse_all").click(function(e){
+ e.preventDefault();
+ $(oTable).treetable('collapseAll');
});
- [% IF ( notree ) %]
- $("#budgeth").dataTable($.extend(true, {}, dataTablesDefaults, {
- "aoColumnDefs": [
- { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
- ],
- "sPaginationType": "four_button"
- }));
- [% ELSE %]
- $("#budgeth").treeTable();
- [% END %]
$("#filterbutton").click(function() {
$("#fundfilters").slideToggle(0);
[% INCLUDE 'budgets-admin-search.inc' %]
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> ›
- <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> › <a href="/cgi-bin/koha/admin/aqbudgetperiods.pl">Budgets</a> › [% IF ( else ) %]Funds for '[% budget_period_description %]'[% END %][% IF ( add_form ) %]
- <a href="/cgi-bin/koha/admin/aqbudgets.pl?budget_period_id=[% budget_period_id %]">Funds</a> › [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name %]'[% END %][% ELSE %]Add fund[% END %][% END %] [% IF ( delete_confirm ) %]
- <a href="/cgi-bin/koha/admin/aqbudgets.pl">Funds</a> › Delete fund?[% END %]</div>
+ <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> › <a href="/cgi-bin/koha/admin/aqbudgetperiods.pl">Budgets</a> › [% IF op == 'list' %][% IF budget_period_id %]Funds for '[% budget_period_description %]'[% ELSE %]All funds[% END %][% END %]
+ [% IF op == 'add_form' %]
+ <a href="/cgi-bin/koha/admin/aqbudgets.pl?budget_period_id=[% budget_period_id %]">Funds</a> › [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name %]'[% END %][% ELSE %]Add fund[% END %]
+ [% END %]
+ [% IF op == 'delete_confirm' %]
+ <a href="/cgi-bin/koha/admin/aqbudgets.pl">Funds</a> › Delete fund?
+ [% END %]
+</div>
<div id="doc3" class="yui-t2">
<div id="bd">
<div class="yui-b" id="content">
-[% UNLESS ( delete_confirm ) %][% INCLUDE 'budgets-admin-toolbar.inc' %][% END %]
+[% UNLESS op == 'delete_confirm' %][% INCLUDE 'budgets-admin-toolbar.inc' %][% END %]
[% IF (error_not_authorised_to_modify) %]
<div class="error">
</div>
[% END %]
-[% IF ( else ) %]
+[% IF op == 'list' %]
-<h1>Funds for '[% budget_period_description %]'</h1>
+<h1>
+ [% IF budget_period_id %]
+ Funds for '[% budget_period_description %]'
+ [% ELSE %]
+ All funds
+ [% END %]
+</h1>
[% INCLUDE 'budgets-active-currency.inc' %]
-[% IF ( budget ) %]
+[% IF budgets %]
<table id="budgeth">
+ <caption>
+ <span class="actions"><a href="#" id="expand_all">Expand all</a>
+ | <a href="#" id="collapse_all">Collapse all</a></span>
+ </caption>
<thead>
<tr>
+ <th>Budget period description</th>
<th>Fund code</th>
<th>Fund name</th>
<th>Base-level allocated</th>
<th>Total spent</th>
<th>Base-level available</th>
<th>Total available</th>
- <th class="tooltipcontent"> </th>
<th>Actions</th>
</tr>
</thead>
-<tfoot>
+ <tfoot>
<tr>
+ <th></th>
<th colspan="2" style="text-align: left;" nowrap="nowrap">Period allocated [% IF ( budget_period_total ) %][% budget_period_total %][% END %] </th>
<th nowrap="nowrap" class="data"> [% period_alloc_total %]</th>
<th></th>
<th></th>
<th class="data">[% spent_total %]</th>
<th></th>
- <th class="tooltipcontent"></th>
<th class="data">[% available_total %]</th>
<th></th>
</tr>
</tfoot>
<tbody>
- [% FOREACH budge IN budget %]
- [% IF ( budge.toggle ) %]
- <tr id="node-[% budge.budget_id %]" class="highlight[% IF ( budge.budget_parent_id ) %] child-of-node-[% budge.budget_parent_id %][% END %] tooltiped">
- [% ELSE %]
- <tr id="node-[% budge.budget_id %]" class="tooltiped [% IF ( budge.budget_parent_id ) %] child-of-node-[% budge.budget_parent_id %][% END %]">
- [% END %]
-
- <td>[% budge.budget_code_indent %]</td>
- <td>[% budge.budget_name %]</td>
+ [% FOREACH budget IN budgets %]
+ <tr data-tt-id="[% budget.budget_id %]" [% IF ( budget.budget_parent_id ) %]data-tt-parent-id="[% budget.budget_parent_id %]"[% END %]>
+ <td>Budget [% budget.budget_period_description %]</td>
+ <td>[% budget.budget_code_indent %]</td>
+ <td>[% budget.budget_name %]</td>
<td class="data">
- [% IF budge.budget_parent_id %]
- <span class="child_fund_amount">[% budge.budget_amount %]</span>
+ [% IF budget.budget_parent_id %]
+ <span class="child_fund_amount">[% budget.budget_amount %]</span>
[% ELSE %]
- [% budge.budget_amount %]
+ [% budget.budget_amount %]
[% END %]
</td>
<td class="data">
- [% IF budge.budget_parent_id %]
- <span class="child_fund_amount">[% budge.budget_ordered %]</span>
+ [% IF budget.budget_parent_id %]
+ <span class="child_fund_amount">[% budget.budget_ordered %]</span>
[% ELSE %]
- [% budge.budget_ordered %]
+ [% budget.budget_ordered %]
[% END %]
</td>
<td class="data">
- [% IF budge.budget_parent_id %]
- <span class="child_fund_amount">[% budge.total_ordered %]</span>
+ [% IF budget.budget_parent_id %]
+ <span class="child_fund_amount">[% budget.total_ordered %]</span>
[% ELSE %]
- [% budge.total_ordered %]
+ [% budget.total_ordered %]
[% END %]
</td>
<td class="data">
- [% IF budge.budget_parent_id %]
- <span class="child_fund_amount">[% budge.budget_spent %]</span>
+ [% IF budget.budget_parent_id %]
+ <span class="child_fund_amount">[% budget.budget_spent %]</span>
[% ELSE %]
- [% budge.budget_spent %]
+ [% budget.budget_spent %]
[% END %]
</td>
<td class="data">
- [% IF budge.budget_parent_id %]
- <span class="child_fund_amount">[% budge.total_spent %]</span>
+ [% IF budget.budget_parent_id %]
+ <span class="child_fund_amount">[% budget.total_spent %]</span>
[% ELSE %]
- [% budge.total_spent %]
+ [% budget.total_spent %]
[% END %]
</td>
</span>
[% END %]
<td class="data">
- [% INCLUDE colorcellvalue value=budge.budget_remaining text=budge.budget_remaining_display parent=budge.budget_parent_id %]
+ [% INCLUDE colorcellvalue value=budget.budget_remaining text=budget.budget_remaining_display parent=budget.budget_parent_id %]
</td>
<td class="data">
- [% INCLUDE colorcellvalue value=budge.total_remaining text=budge.total_remaining_display parent=budge.budget_parent_id %]
+ [% INCLUDE colorcellvalue value=budget.total_remaining text=budget.total_remaining_display parent=budget.budget_parent_id %]
</td>
-
- <td class="tooltipcontent">[% IF ( budge.budget_owner_id ) %]<strong>Owner: </strong><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% budge.budget_owner_id %]">[% budge.budget_owner_name %]</a>[% END %]
- [% IF ( budge.budget_branchcode ) %]<br /><strong>Library: </strong>[% budge.budget_branchcode %][% END %]
- [% IF ( budge.budget_notes ) %]<br /><strong>Notes: </strong>[% budge.budget_notes %][% END %]
- [% IF ( budge.budget_hierarchy ) %]
- <ul class="budget_hierarchy">[% FOREACH budget_hierarch IN budge.budget_hierarchy %]
- [% IF ( budget_hierarch.element_id ) %]
- <li><a href="?op=add_form&budget_id=[% budget_hierarch.element_id %]&budget_period_id=[% budget_hierarch.budget_period_id %]">[% budget_hierarch.element_name %]</a></li>
- [% ELSE %]
- <li><strong>[% budget_hierarch.element_name %] : </strong></li>
- [% END %]
- [% END %]
- </ul>
- [% END %]</td>
- [% IF ( budge.budget_lock ) %]
+ [% IF ( budget.budget_lock ) %]
<td> <span style="color: gray;"> Edit Delete </span> </td>
[% ELSE %]
<td>
- <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&budget_id=[% budge.budget_id %]&budget_period_id=[% budge.budget_period_id %]" >Edit</a>
- <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=delete_confirm&budget_id=[% budge.budget_id %]&budget_period_id=[% budge.budget_period_id %]">Delete</a>
- <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&budget_parent_id=[% budge.budget_id %]&budget_period_id=[% budge.budget_period_id %]">Add child fund</a>
+ <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&budget_id=[% budget.budget_id %]&budget_period_id=[% budget.budget_period_id %]" >Edit</a>
+ <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=delete_confirm&budget_id=[% budget.budget_id %]&budget_period_id=[% budget.budget_period_id %]">Delete</a>
+ <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&budget_parent_id=[% budget.budget_id %]&budget_period_id=[% budget.budget_period_id %]">Add child fund</a>
</td>
[% END %]
</tr>
No fund found
[% END %]
-[% IF ( pagination_bar ) %]<div class="pages">[% pagination_bar %]</div>[% END %]
-[% END %] <!-- else -->
+[% END %] <!-- list -->
<!-- ********************************************************************************************** -->
<!-- create add/mod entry form -->
-[% IF ( add_form && !error_not_authorised_to_modify ) %]
+[% IF op == 'add_form' && !error_not_authorised_to_modify %]
<form action="/cgi-bin/koha/admin/aqbudgets.pl" name="Aform" method="post">
<fieldset class="rows">
<legend>[% IF ( budget_id ) %]Modify[% ELSE %]Add[% END %] Fund
[% END %] <!-- add_form -->
-[% IF ( delete_confirm ) %]
+[% IF op == 'delete_confirm' %]
<div class="dialog alert"> <h3>Delete fund [% budget_name %]?</h3>
<table>
<tr>
</tr>
</table>
-<form action="[% action %]" method="post">
+<form action="/cgi-bin/koha/admin/aqbudgets.pl" method="post">
<input type="hidden" name="op" value="delete_confirmed" />
<input type="hidden" name="budget_id" value="[% budget_id %]" />
<input type="hidden" name="budget_period_id" value="[% budget_period_id %]" />
<input type="submit" value="Delete" class="approve" />
</form>
-<form action="[% action %]" method="get">
+<form action="/cgi-bin/koha/admin/aqbudgets.pl" method="get">
<input type="submit" class="deny" value="Cancel" />
</form>
</div>
</div>
</div>
<div class="yui-b">
-[% IF ( else ) %]<form action="/cgi-bin/koha/admin/aqbudgets.pl" method="get">
+[% IF op == 'list' %]
+ <form action="/cgi-bin/koha/admin/aqbudgets.pl" method="get">
<a href="#" id="filterbutton">Filters</a>
<fieldset class="brief" id="fundfilters">
<h4>Fund filters</h4>
<input type="checkbox" id="show_mine" name="show_mine" value="1" />
[% END %]
</li>
+
+ [% IF periods %]
+ <li>
+ <label for="periods">Budget:</label>
+ <select id="periods" name="budget_period_id">
+ <option value="">All budgets</option>
+ [% FOR period IN periods %]
+ [% IF budget_period_id && period.budget_period_id == budget_period_id %]
+ <option value="[% period.budget_period_id %]" selected="selected">[% period.budget_period_description %]</option>
+ [% ELSE %]
+ <option value="[% period.budget_period_id %]">[% period.budget_period_description %]</option>
+ [% END %]
+ [% END %]
+ </select>
+ </li>
+ [% END %]
</ol>
- <input type="hidden" name="show" value="1" />
- <input type="hidden" name="budget_period_id" value="[% budget_period_id %]" />
+ <input type="hidden" name="op" value="list" />
<input type="submit" class="submit" name="filter" value="Go" />
</fieldset>
</form>[% END %]