Bugzilla – Attachment 50468 Details for
Bug 11371
Add a new report : Orders by budget
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11371 - Add a new report : Orders by fund with more options
Bug-11371---Add-a-new-report--Orders-by-fund-with-.patch (text/plain), 30.52 KB, created by
Marc Véron
on 2016-04-20 15:44:34 UTC
(
hide
)
Description:
Bug 11371 - Add a new report : Orders by fund with more options
Filename:
MIME Type:
Creator:
Marc Véron
Created:
2016-04-20 15:44:34 UTC
Size:
30.52 KB
patch
obsolete
>From 284d28fb53254cafb068a7a4fd8636c4178456a4 Mon Sep 17 00:00:00 2001 >From: Bouzid Fergani <bouzid.fergani@inlibro.com> >Date: Thu, 5 Mar 2015 10:56:14 -0500 >Subject: [PATCH] Bug 11371 - Add a new report : Orders by fund with more > options >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > > Add option show or no inactive budget and more options > Use subroutine GetBudgetHierarchy for return all budgets > Delete subroutine GetBudgetPeriodDescription and theire tests > Use Price TT plugin > Correct name of column and capitalization the first letter > Add checkbox for show inactive budgets, default the drop down list containt a active budget > Not use [i] for inactive budgets, i add (inactive) at the end of inactive budget > Add vendor note in the list of show attribute > > Test case: > Go to Home > Reports > Orders by fund > Select one or all budgets > You can show the inactive budget, default the drop down list containt a active budget > Choose output to screen ou csv file > >Works as expected. QA tools OK with Bug 16104 applied. >Signed-off-by: Marc Véron <veron@veron.ch> >--- > C4/Budgets.pm | 123 ++++++++++- > .../csv_headers/reports/orders_by_budget.tt | 1 + > .../en/modules/reports/csv/orders_by_budget.tt | 12 ++ > .../prog/en/modules/reports/orders_by_budget.tt | 161 +++++++++++++++ > .../prog/en/modules/reports/reports-home.tt | 79 +++---- > reports/orders_by_fund.pl | 216 ++++++++++++++++++++ > t/db_dependent/Acquisition.t | 22 +- > t/db_dependent/Budgets.t | 13 +- > 8 files changed, 581 insertions(+), 46 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/orders_by_budget.tt > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/reports/csv/orders_by_budget.tt > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt > create mode 100755 reports/orders_by_fund.pl > >diff --git a/C4/Budgets.pm b/C4/Budgets.pm >index db936be..809f63e 100644 >--- a/C4/Budgets.pm >+++ b/C4/Budgets.pm >@@ -33,6 +33,9 @@ BEGIN { > &GetBudgetByOrderNumber > &GetBudgetByCode > &GetBudgets >+ &BudgetsByActivity >+ &GetBudgetsReport >+ &GetBudgetReport > &GetBudgetHierarchy > &AddBudget > &ModBudget >@@ -53,6 +56,7 @@ BEGIN { > &GetBudgetPeriods > &ModBudgetPeriod > &AddBudgetPeriod >+ &GetBudgetPeriodDescription > &DelBudgetPeriod > > &ModBudgetPlan >@@ -71,7 +75,6 @@ BEGIN { > > # ----------------------------BUDGETS.PM-----------------------------"; > >- > =head1 FUNCTIONS ABOUT BUDGETS > > =cut >@@ -451,7 +454,6 @@ sub GetBudgetPeriod { > return $data; > } > >-# ------------------------------------------------------------------- > sub DelBudgetPeriod{ > my ($budget_period_id) = @_; > my $dbh = C4::Context->dbh; >@@ -595,6 +597,8 @@ sub DelBudget { > } > > >+# ------------------------------------------------------------------- >+ > =head2 GetBudget > > &GetBudget($budget_id); >@@ -603,7 +607,6 @@ get a specific budget > > =cut > >-# ------------------------------------------------------------------- > sub GetBudget { > my ( $budget_id ) = @_; > my $dbh = C4::Context->dbh; >@@ -618,6 +621,8 @@ sub GetBudget { > return $result; > } > >+# ------------------------------------------------------------------- >+ > =head2 GetBudgetByOrderNumber > > &GetBudgetByOrderNumber($ordernumber); >@@ -626,7 +631,6 @@ get a specific budget by order number > > =cut > >-# ------------------------------------------------------------------- > sub GetBudgetByOrderNumber { > my ( $ordernumber ) = @_; > my $dbh = C4::Context->dbh; >@@ -642,6 +646,117 @@ sub GetBudgetByOrderNumber { > return $result; > } > >+=head2 GetBudgetReport >+ >+ &GetBudgetReport( [$budget_id] ); >+ >+Get all orders for a specific budget, without cancelled orders. >+ >+Returns an array of hashrefs. >+ >+=cut >+ >+# -------------------------------------------------------------------- >+sub GetBudgetReport { >+ my ( $budget_id ) = @_; >+ my $dbh = C4::Context->dbh; >+ my $query = ' >+ SELECT o.*, b.budget_name >+ FROM aqbudgets b >+ INNER JOIN aqorders o >+ ON b.budget_id = o.budget_id >+ WHERE b.budget_id=? >+ AND (o.orderstatus != "cancelled") >+ ORDER BY b.budget_name'; >+ >+ my $sth = $dbh->prepare($query); >+ $sth->execute( $budget_id ); >+ >+ my @results = (); >+ while ( my $data = $sth->fetchrow_hashref ) { >+ push( @results, $data ); >+ } >+ return @results; >+} >+ >+=head2 GetBudgetsByActivity >+ >+ &GetBudgetsByActivity( $budget_period_active ); >+ >+Get all active or inactive budgets, depending of the value >+of the parameter. >+ >+1 = active >+0 = inactive >+ >+=cut >+ >+# -------------------------------------------------------------------- >+sub GetBudgetsByActivity { >+ my ( $budget_period_active ) = @_; >+ my $dbh = C4::Context->dbh; >+ my $query = " >+ SELECT DISTINCT b.* >+ FROM aqbudgetperiods bp >+ INNER JOIN aqbudgets b >+ ON bp.budget_period_id = b.budget_period_id >+ WHERE bp.budget_period_active=? >+ "; >+ my $sth = $dbh->prepare($query); >+ $sth->execute( $budget_period_active ); >+ my @results = (); >+ while ( my $data = $sth->fetchrow_hashref ) { >+ push( @results, $data ); >+ } >+ return @results; >+} >+# -------------------------------------------------------------------- >+ >+=head2 GetBudgetsReport >+ >+ &GetBudgetsReport( [$activity] ); >+ >+Get all but cancelled orders for all funds. >+ >+If the optionnal activity parameter is passed, returns orders for active/inactive budgets only. >+ >+active = 1 >+inactive = 0 >+ >+Returns an array of hashrefs. >+ >+=cut >+ >+sub GetBudgetsReport { >+ my ($activity) = @_; >+ my $dbh = C4::Context->dbh; >+ my $query = ' >+ SELECT o.*, b.budget_name >+ FROM aqbudgetperiods bp >+ INNER JOIN aqbudgets b >+ ON bp.budget_period_id = b.budget_period_id >+ INNER JOIN aqorders o >+ ON b.budget_id = o.budget_id '; >+ if($activity ne ''){ >+ $query .= 'WHERE bp.budget_period_active=? '; >+ } >+ $query .= 'AND (o.orderstatus != "cancelled") >+ ORDER BY b.budget_name'; >+ >+ my $sth = $dbh->prepare($query); >+ if($activity ne ''){ >+ $sth->execute($activity); >+ } >+ else{ >+ $sth->execute; >+ } >+ my @results = (); >+ while ( my $data = $sth->fetchrow_hashref ) { >+ push( @results, $data ); >+ } >+ return @results; >+} >+ > =head2 GetBudgetByCode > > my $budget = &GetBudgetByCode($budget_code); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/orders_by_budget.tt b/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/orders_by_budget.tt >new file mode 100644 >index 0000000..2acc795 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/reports/orders_by_budget.tt >@@ -0,0 +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 %]"Internal note"[% sep %]"Vendor note" >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/csv/orders_by_budget.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/csv/orders_by_budget.tt >new file mode 100644 >index 0000000..e025c5c >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/csv/orders_by_budget.tt >@@ -0,0 +1,12 @@ >+[% INCLUDE csv_headers/reports/orders_by_budget.tt %] >+[%- FOREACH row IN rows %] >+ [%- FOREACH field IN row; >+ field; >+ sep IF !loop.last; >+ END %] >+[% END -%] >+TOTAL >+[%- FOREACH field IN totalrow; >+ field; >+ sep IF !loop.last; >+END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt >new file mode 100644 >index 0000000..2921d85 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/orders_by_budget.tt >@@ -0,0 +1,161 @@ >+[% USE Price %] >+[% INCLUDE 'doc-head-open.inc' %] >+<title>Koha › Reports › Orders by fund</title> >+[% INCLUDE 'doc-head-close.inc' %] >+</head> >+<body> >+[% INCLUDE 'header.inc' %] >+[% INCLUDE 'cat-search.inc' %] >+ >+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" /> >+[% INCLUDE 'datatables.inc' %] >+<script type="text/javascript"> >+ $(document).ready( function () { >+ $('#funds').DataTable($.extend(true, {}, dataTablesDefaults,{"sPaginationType": "full_numbers"})); >+ >+ showallbudgets = $('#budgetfilter').html(); >+ $('#budgetfilter .b_inactive').remove(); >+ >+ $('#showbudgets').click(function(){ >+ if ($(this).is(":checked")) >+ $('#budgetfilter').html(showallbudgets); >+ else >+ $('#budgetfilter .b_inactive').remove(); >+ }); >+ } ); >+</script> >+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a>[% IF ( get_orders ) %] › <a href="/cgi-bin/koha/reports/orders_by_fund.pl">Orders by fund</a> › Results[% ELSE %] › Orders by fund[% END %]</div> >+ >+<div id="doc3" class="yui-t2"> >+ >+<div id="bd"> >+ <div id="yui-main"> >+ <div class="yui-b"> >+ >+[% IF ( current_budget_name ) %]<h1>Orders for fund '[% current_budget_name %]'</h1> >+[% ELSE %]<h1>Orders by fund</h1> >+[% END %] >+ >+[% IF ( get_orders ) %] >+ <div class="results"> >+ [% IF ( total ) %] >+ Orders found: [% total %] >+ [% ELSE %] >+ No order found >+ [% END %] >+ </div> >+ >+ [% IF ( ordersloop ) %]<table id="funds"> >+ <thead> >+ <tr> >+ <th>Fund</th> >+ <th>Basket</th> >+ <th>Basket name</th> >+ <th>Basket by</th> >+ <th>Title</th> >+ <th>Currency</th> >+ <th>List price</th> >+ <th>RRP</th> >+ <th>Budgeted cost</th> >+ <th>Quantity</th> >+ <th>Total RRP</th> >+ <th>Total cost</th> >+ <th>Entry date</th> >+ <th>Date deceived</th> >+ <th>Internal note</th> >+ <th>Vendor note</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH ordersloo IN ordersloop %] >+ [% UNLESS ( loop.odd ) %]<tr class="highlight"> >+ [% ELSE %] <tr> >+ [% END %] >+ <td>[% ordersloo.budget_name |html %]</td> >+ <td><a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% ordersloo.basketno %]"> [% ordersloo.basketno |html %]</a></td> >+ <td>[% ordersloo.basketname |html %]</td> >+ <td>[% ordersloo.authorisedbyname %]</td> >+ <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% ordersloo.biblionumber %]"> [% ordersloo.title |html %]</a></td> >+ <td>[% ordersloo.currency %]</td> >+ <td>[% ordersloo.listprice | $Price %]</td> >+ <td>[% ordersloo.rrp | $Price %]</td> >+ <td>[% ordersloo.ecost | $Price %]</td> >+ <td>[% ordersloo.quantity %]</td> >+ <td>[% ordersloo.total_rrp | $Price %]</td> >+ <td>[% ordersloo.total_ecost | $Price %]</td> >+ <td>[% ordersloo.entrydate %]</td> >+ <td>[% ordersloo.datereceived %]</td> >+ <td>[% ordersloo.order_internalnote |html %]</td> >+ <td>[% ordersloo.order_vendornote |html %]</td> >+ </tr> >+ [% END %] >+ </tbody> >+ <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 | $Price %]</th><th>[% total_ecost | $Price %]</th><th></th><th></th><th></th></tr></tfoot> >+ </table> >+ [% END %] >+ [% ELSE %] >+ <form name="f" action="/cgi-bin/koha/reports/orders_by_fund.pl" method="post"> >+ <fieldset class="rows"> >+ <legend>Filters</legend> >+ <ol><li><label for="budgetfilter">Fund (Budget): </label> >+ <select name="budgetfilter" id="budgetfilter"> >+ <option value="">All funds</option> >+ <option value="activebudgets">All active funds</option> >+ [% FOREACH budgetsloo IN budgetsloop %] >+ [% IF ( budgetsloo.selected ) %] >+ <option value="[% budgetsloo.value %]" selected="selected"> >+ [% ELSE %] >+ [% bdgclass=budgetsloo.active? "": "b_inactive" %] >+ <option class="[% bdgclass %]" value="[% budgetsloo.value %]"> >+ [% END %] >+ [% budgetsloo.description %] [% IF !budgetsloo.active %](inactive)[% END %] >+ </option> >+ [% END %] >+ </select> >+ <label for="showallbudgets" style="float:none;"> Show inactive:</label> >+ <input type="checkbox" id="showbudgets" /> >+ </li></ol> >+ </fieldset> >+ >+ <fieldset class="rows"> >+ <legend>Output</legend> >+ <ol><li><label for="outputscreen">To screen into the browser: </label><input type="radio" checked="checked" name="output" id="outputscreen" value="screen" /> </li> >+ <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 </label> >+ <select id='MIME' name='MIME' size='1'> >+ [% FOREACH outputFormatloo IN outputFormatloop %] >+ <option value="[% outputFormatloo %]">[% outputFormatloo %]</option> >+ [% END %] >+ </select> >+ <select id='sep' name='sep' size='1'> >+ [% FOREACH delimiterloo IN delimiterloop %] >+ [% IF delimiterloo == delimiterPreference %] >+ <option value="[% delimiterloo %]">[% delimiterloo %]</option> >+ [% END %] >+ [% END %] >+ [% FOREACH delimiterloo IN delimiterloop %] >+ [% IF delimiterloo != delimiterPreference %] >+ <option value="[% delimiterloo %]">[% delimiterloo %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ </li></ol> >+ </fieldset> >+ >+ <fieldset class="action"> >+ <input type="submit" value="Submit" /> >+ <input type="hidden" name="get_orders" value="1" /></fieldset> >+ </form> >+ >+ [% END %] >+ >+</div> >+</div> >+<div class="yui-b"> >+[% INCLUDE 'reports-menu.inc' %] >+</div> >+</div> >+[% INCLUDE 'intranet-bottom.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt >index 39260c4..486a7fb 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt >@@ -13,30 +13,30 @@ > <div id="bd"> > <div id="yui-main"> > >- <div class="yui-g"> >- <h1>Reports</h1> >+ <div class="yui-g"> >+ <h1>Reports</h1> > <div class="yui-u first"><h2>Guided reports</h2> >- <ul> >- <li><a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a></li> >- [% IF ( CAN_user_reports_create_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build new</a></li>[% END %] >- [% IF ( CAN_user_reports_execute_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Use saved</a></li>[% END %] >- [% 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 %] >- </ul> >- >- <h5>Reports dictionary</h5> >- <ul> >- <li><a href="/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary">View dictionary</a></li> >- </ul> >+ <ul> >+ <li><a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports wizard</a></li> >+ [% IF ( CAN_user_reports_create_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build new</a></li>[% END %] >+ [% IF ( CAN_user_reports_execute_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Use saved</a></li>[% END %] >+ [% 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 %] >+ </ul> > >- <h2>Statistics wizards</h2> >- <ul> >- <li><a href="/cgi-bin/koha/reports/acquisitions_stats.pl">Acquisitions</a></li> >- <li><a href="/cgi-bin/koha/reports/borrowers_stats.pl">Patrons</a></li> >- <li><a href="/cgi-bin/koha/reports/catalogue_stats.pl">Catalog</a></li> >- <li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li> >- <li><a href="/cgi-bin/koha/reports/serials_stats.pl">Serials</a></li> >- <li><a href="/cgi-bin/koha/reports/reserves_stats.pl">Holds</a></li> >- </ul> >+ <h5>Reports dictionary</h5> >+ <ul> >+ <li><a href="/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary">View dictionary</a></li> >+ </ul> >+ >+ <h2>Statistics wizards</h2> >+ <ul> >+ <li><a href="/cgi-bin/koha/reports/acquisitions_stats.pl">Acquisitions</a></li> >+ <li><a href="/cgi-bin/koha/reports/borrowers_stats.pl">Patrons</a></li> >+ <li><a href="/cgi-bin/koha/reports/catalogue_stats.pl">Catalog</a></li> >+ <li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li> >+ <li><a href="/cgi-bin/koha/reports/serials_stats.pl">Serials</a></li> >+ <li><a href="/cgi-bin/koha/reports/reserves_stats.pl">Holds</a></li> >+ </ul> > > [% IF UseKohaPlugins %] > <h2>Report Plugins</h2> >@@ -51,23 +51,24 @@ > <ul> > <li><a href="/cgi-bin/koha/reports/bor_issues_top.pl">Patrons with the most checkouts</a></li> > <li><a href="/cgi-bin/koha/reports/cat_issues_top.pl">Most-circulated items</a></li> >- </ul> >- >- <h2>Inactive</h2> >- <ul> >- <li><a href="/cgi-bin/koha/reports/borrowers_out.pl">Patrons who haven't checked out</a></li> >- <li><a href="/cgi-bin/koha/reports/catalogue_out.pl">Items with no checkouts</a></li> >- </ul> >- >- <h2>Other</h2> >- <ul> >- <li><a href="/cgi-bin/koha/reports/itemslost.pl">Items lost</a></li> >- <li><a href="/cgi-bin/koha/reports/manager.pl?report_name=itemtypes">Catalog by item type</a></li> >- <li><a href="/cgi-bin/koha/reports/issues_avg_stats.pl">Average loan time</a></li> >- <li><a href="http://schema.koha-community.org/" target="blank">Koha database schema</a></li> >- <li><a href="http://wiki.koha-community.org/wiki/SQL_Reports_Library" target="blank">Koha reports library</a></li> >- <!--<li><a href="/cgi-bin/koha/reports/stats.screen.pl">Till reconciliation</a></li> --> >- </ul></div> >+ </ul> >+ >+ <h2>Inactive</h2> >+ <ul> >+ <li><a href="/cgi-bin/koha/reports/borrowers_out.pl">Patrons who haven't checked out</a></li> >+ <li><a href="/cgi-bin/koha/reports/catalogue_out.pl">Items with no checkouts</a></li> >+ </ul> >+ >+ <h2>Other</h2> >+ <ul> >+ <li><a href="/cgi-bin/koha/reports/itemslost.pl">Items lost</a></li> >+ <li><a href="/cgi-bin/koha/reports/orders_by_fund.pl">Orders by fund</a></li> >+ <li><a href="/cgi-bin/koha/reports/manager.pl?report_name=itemtypes">Catalog by itemtype</a></li> >+ <li><a href="/cgi-bin/koha/reports/issues_avg_stats.pl">Average loan time</a></li> >+ <li><a href="http://schema.koha-community.org/" target="blank">Koha database schema</a></li> >+ <li><a href="http://wiki.koha-community.org/wiki/SQL_Reports_Library" target="blank">Koha reports library</a></li> >+ <!--<li><a href="/cgi-bin/koha/reports/stats.screen.pl">Till reconciliation</a></li> --> >+</ul></div> > </div> > > >diff --git a/reports/orders_by_fund.pl b/reports/orders_by_fund.pl >new file mode 100755 >index 0000000..ce00d72 >--- /dev/null >+++ b/reports/orders_by_fund.pl >@@ -0,0 +1,216 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Author : Frédérick Capovilla, 2011 - SYS-TECH >+# Modified by : Ãlyse Morin, 2012 - Libéo >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along with >+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, >+# Suite 330, Boston, MA 02111-1307 USA >+ >+ >+=head1 orders_by_budget >+ >+This script displays all orders associated to a selected budget. >+ >+=cut >+ >+use strict; >+use warnings; >+use Modern::Perl; >+ >+use CGI; >+use C4::Auth; >+use C4::Output; >+use C4::Budgets; >+use C4::Biblio; >+use C4::Reports; >+use C4::Acquisition; #GetBasket() >+ >+my $query = new CGI; >+my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >+ { >+ template_name => "reports/orders_by_budget.tt", >+ query => $query, >+ type => "intranet", >+ authnotrequired => 0, >+ flagsrequired => { reports => '*' }, >+ debug => 1, >+ } >+); >+ >+my $params = $query->Vars; >+my $get_orders = $params->{'get_orders'}; >+ >+if ( $get_orders ) { >+ my $budgetfilter = $params->{'budgetfilter'} || undef; >+ my $total_quantity = 0; >+ my $total_rrp = 0; >+ my $total_ecost = 0; >+ my %budget_name; >+ >+ # Fetch the orders >+ my @orders; >+ unless($budgetfilter) { >+ # If no budget filter was selected, get the orders of all budgets >+ my @budgets = C4::Budgets::GetBudgetsReport(); >+ foreach my $budget (@budgets) { >+ push(@orders, $budget); >+ $budget_name{$budget->{'budget_id'}} = $budget->{'budget_name'}; >+ } >+ } >+ else { >+ if ($budgetfilter eq 'activebudgets') { >+ # If all active budgets's option was selected, get the orders of all active budgets >+ my @active_budgets = C4::Budgets::GetBudgetsReport(1); >+ foreach my $active_budget (@active_budgets) >+ { >+ push(@orders, $active_budget); >+ $budget_name{$active_budget->{'budget_id'}} = $active_budget->{'budget_name'}; >+ } >+ } >+ else { >+ # A budget filter was selected, only get the orders for the selected budget >+ my @filtered_budgets = C4::Budgets::GetBudgetReport($budgetfilter); >+ foreach my $budget (@filtered_budgets) >+ { >+ push(@orders, $budget); >+ $budget_name{$budget->{'budget_id'}} = $budget->{'budget_name'}; >+ } >+ if ($filtered_budgets[0]) { >+ $template->param( >+ current_budget_name => $filtered_budgets[0]->{'budget_name'}, >+ ); >+ } >+ } >+ } >+ >+ # Format the order's informations >+ foreach my $order (@orders) { >+ # Get the title of the ordered item >+ my $biblio = C4::Biblio::GetBiblio($order->{'biblionumber'}); >+ my $basket = C4::Acquisition::GetBasket($order->{'basketno'}); >+ >+ $order->{'basketname'} = $basket->{'basketname'}; >+ $order->{'authorisedbyname'} = $basket->{'authorisedbyname'}; >+ >+ $order->{'title'} = $biblio->{'title'} || $order->{'biblionumber'}; >+ >+ $order->{'total_rrp'} = $order->{'quantity'} * $order->{'rrp'}; >+ $order->{'total_ecost'} = $order->{'quantity'} * $order->{'ecost'}; >+ >+ # Format the dates and currencies correctly >+ $order->{'datereceived'} = Koha::DateUtils::output_pref(Koha::DateUtils::dt_from_string($order->{'datereceived'})); >+ $order->{'entrydate'} = Koha::DateUtils::output_pref(Koha::DateUtils::dt_from_string($order->{'entrydate'})); >+ $total_quantity += $order->{'quantity'}; >+ $total_rrp += $order->{'total_rrp'}; >+ $total_ecost += $order->{'total_ecost'}; >+ >+ # Get the budget's name >+ $order->{'budget_name'} = $budget_name{$order->{'budget_id'}}; >+ } >+ >+ # If we are outputting to screen, output to the template. >+ if($params->{"output"} eq 'screen') { >+ $template->param( >+ total => scalar @orders, >+ ordersloop => \@orders, >+ get_orders => $get_orders, >+ total_quantity => $total_quantity, >+ total_rrp => $total_rrp, >+ total_ecost => $total_ecost, >+ ); >+ } >+ # If we are outputting to a file, create it and exit. >+ else { >+ my $basename = $params->{"basename"}; >+ my $sep = $params->{"sep"}; >+ $sep = "\t" if ($sep eq 'tabulation'); >+ >+ print $query->header( >+ -type => 'application/vnd.sun.xml.calc', >+ -encoding => 'utf-8', >+ -attachment => "$basename.csv", >+ -name => "$basename.csv" >+ ); >+ >+ #binmode STDOUT, ":encoding(UTF-8)"; >+ >+ # Surrounds a string with double-quotes and escape the double-quotes inside >+ sub _surround { >+ my $string = shift || ""; >+ $string =~ s/"/""/g; >+ return "\"$string\""; >+ } >+ my @rows; >+ foreach my $order (@orders) { >+ my @row; >+ push(@row, _surround($order->{'budget_name'})); >+ push(@row, _surround($order->{'basketno'})); >+ push(@row, _surround($order->{'basketname'})); >+ push(@row, _surround($order->{'authorisedbyname'})); >+ push(@row, _surround($order->{'biblionumber'})); >+ push(@row, _surround($order->{'title'})); >+ push(@row, _surround($order->{'currency'})); >+ push(@row, _surround($order->{'listprice'})); >+ push(@row, _surround($order->{'rrp'})); >+ push(@row, _surround($order->{'ecost'})); >+ push(@row, _surround($order->{'quantity'})); >+ push(@row, _surround($order->{'total_rrp'})); >+ push(@row, _surround($order->{'total_ecost'})); >+ push(@row, _surround($order->{'entrydate'})); >+ push(@row, _surround($order->{'datereceived'})); >+ push(@row, _surround($order->{'order_internalnote'})); >+ push(@row, _surround($order->{'order_vendornote'})); >+ push(@rows, \@row); >+ } >+ >+ my @totalrow; >+ for(1..9){push(@totalrow, "")}; >+ push(@totalrow, _surround($total_quantity)); >+ push(@totalrow, _surround($total_rrp)); >+ push(@totalrow, _surround($total_ecost)); >+ >+ my $csvTemplate = C4::Templates::gettemplate('reports/csv/orders_by_budget.tt', 'intranet', $query); >+ $csvTemplate->param(sep => $sep, rows => \@rows, totalrow => \@totalrow); >+ print $csvTemplate->output; >+ >+ exit(0); >+ } >+} >+else { >+ # Set file export choices >+ my @outputFormats = ('CSV'); >+ my @CSVdelimiters =(',','#',qw(; tabulation \\ /)); >+ >+ # getting all budgets >+ my $budgets = GetBudgetHierarchy; >+ my $budgetloop = []; >+ foreach my $budget (@{$budgets}) { >+ push @{$budgetloop},{ >+ value => $budget->{budget_id}, >+ description => $budget->{budget_name}, >+ period => $budget->{budget_period_description}, >+ active => $budget->{budget_period_active}, >+ }; >+ } >+ @{$budgetloop} =sort { uc( $a->{description}) cmp uc( $b->{description}) } @{$budgetloop}; >+ $template->param( budgetsloop => \@{$budgetloop}, >+ outputFormatloop => \@outputFormats, >+ delimiterloop => \@CSVdelimiters, >+ delimiterPreference => C4::Context->preference('delimiter') >+ ); >+} >+ >+# writing the template >+output_html_with_http_headers $query, $cookie, $template->output; >diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t >index cd3f125..6063f09 100755 >--- a/t/db_dependent/Acquisition.t >+++ b/t/db_dependent/Acquisition.t >@@ -19,7 +19,7 @@ use Modern::Perl; > > use POSIX qw(strftime); > >-use Test::More tests => 87; >+use Test::More tests => 91; > use Koha::Database; > > BEGIN { >@@ -147,10 +147,18 @@ ok( > ); > ok( $basket = GetBasket($basketno), "GetBasket($basketno) returns $basket" ); > >+my $bpid=AddBudgetPeriod({ >+ budget_period_startdate => '2008-01-01' >+ , budget_period_enddate => '2008-12-31' >+ , budget_period_active => 1 >+ , budget_period_description => "MAPERI" >+}); >+ > my $budgetid = C4::Budgets::AddBudget( > { > budget_code => "budget_code_test_getordersbybib", > budget_name => "budget_name_test_getordersbybib", >+ budget_period_id => $bpid, > } > ); > my $budget = C4::Budgets::GetBudget($budgetid); >@@ -934,3 +942,15 @@ ok((not defined GetBiblio($order4->{biblionumber})), "biblio does not exist anym > # End of tests for DelOrder > > $schema->storage->txn_rollback(); >+# Budget reports >+#my @report = GetBudgetReport(1); >+#ok(@report >= 1, "GetBudgetReport OK"); >+ >+my $all_count = scalar GetBudgetsReport(); >+ok($all_count >= 1, "GetBudgetReport OK"); >+ >+my $active_count = scalar GetBudgetsReport(1); >+ok($active_count >= 1 , "GetBudgetsReport(1) OK"); >+ >+ok($all_count == scalar GetBudgetsReport(), "GetBudgetReport returns inactive budget period acquisitions."); >+ok($active_count >= scalar GetBudgetsReport(1), "GetBudgetReport doesn't return inactive budget period acquisitions."); >diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t >index 0f59b8b..e0ed6e9 100755 >--- a/t/db_dependent/Budgets.t >+++ b/t/db_dependent/Budgets.t >@@ -1,6 +1,6 @@ >+#!/usr/bin/perl > use Modern::Perl; >-use Test::More tests => 130; >- >+use Test::More tests => 129; > BEGIN { > use_ok('C4::Budgets') > } >@@ -468,6 +468,15 @@ for my $budget (@$budget_hierarchy_cloned) { > is( $number_of_budgets_not_reset, 0, > 'CloneBudgetPeriod has reset all budgets (funds)' ); > >+#GetBudgetsByActivity >+my $result=C4::Budgets::GetBudgetsByActivity(1); >+isnt( $result, undef ,'GetBudgetsByActivity return correct value with parameter 1'); >+$result=C4::Budgets::GetBudgetsByActivity(0); >+ isnt( $result, undef ,'GetBudgetsByActivity return correct value with parameter 0'); >+$result=C4::Budgets::GetBudgetsByActivity(); >+ is( $result, 0 , 'GetBudgetsByActivity return 0 with none parameter or other 0 or 1' ); >+DelBudget($budget_id); >+DelBudgetPeriod($bpid); > > # CloneBudgetPeriod with param amount_change_* > $budget_period_id_cloned = C4::Budgets::CloneBudgetPeriod( >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11371
:
23381
|
25397
|
25913
|
25915
|
30545
|
30546
|
35385
|
36620
|
36707
|
37010
|
37011
|
41463
|
41464
|
45243
|
45244
|
45245
|
45288
|
45338
|
45887
|
45890
|
45981
|
45982
|
50230
|
50231
|
50233
|
50466
|
50468
|
50769