[Koha-cvs] koha C4/Serials.pm serials/subscription-renew.p... [rel_3_0]
Antoine Farnault
antoine at koha-fr.org
Fri Dec 22 15:38:59 CET 2006
CVSROOT: /sources/koha
Module name: koha
Branch: rel_3_0
Changes by: Antoine Farnault <toins> 06/12/22 14:38:59
Modified files:
C4 : Serials.pm
serials : subscription-renew.pl
Added files:
koha-tmpl/intranet-tmpl/prog/en/serials: checkexpiration.tmpl
serials : checkexpiration.pl
Log message:
new script: serials/checkexpiration.pl this script displays subscriptions which will expire before a given date.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Serials.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.5.2.18&r2=1.5.2.19
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/intranet-tmpl/prog/en/serials/checkexpiration.tmpl?cvsroot=koha&only_with_tag=rel_3_0&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/serials/subscription-renew.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.2.2.3&r2=1.2.2.4
http://cvs.savannah.gnu.org/viewcvs/koha/serials/checkexpiration.pl?cvsroot=koha&only_with_tag=rel_3_0&rev=1.1.2.1
Patches:
Index: C4/Serials.pm
===================================================================
RCS file: /sources/koha/koha/C4/Serials.pm,v
retrieving revision 1.5.2.18
retrieving revision 1.5.2.19
diff -u -b -r1.5.2.18 -r1.5.2.19
--- C4/Serials.pm 21 Dec 2006 15:04:52 -0000 1.5.2.18
+++ C4/Serials.pm 22 Dec 2006 14:38:59 -0000 1.5.2.19
@@ -17,7 +17,7 @@
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
-# $Id: Serials.pm,v 1.5.2.18 2006/12/21 15:04:52 toins Exp $
+# $Id: Serials.pm,v 1.5.2.19 2006/12/22 14:38:59 toins Exp $
use strict;
use C4::Date;
@@ -33,7 +33,7 @@
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
# set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.5.2.18 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.5.2.19 $' =~ /\d+/g;
shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
};
@@ -59,7 +59,7 @@
&NewSubscription &ModSubscription &DelSubscription &GetSubscriptions
&GetSubscription &CountSubscriptionFromBiblionumber &GetSubscriptionsFromBiblionumber
&GetFullSubscriptionsFromBiblionumber &ModSubscriptionHistory
- &HasSubscriptionExpired &HasExpiredBefore &GetSubscriptionExpirationDate &abouttoexpire
+ &HasSubscriptionExpired &GetExpirationDate &abouttoexpire
&GetNextSeq &NewIssue &ItemizeSerials &GetSerials
&GetLatestSerials &ModSerialStatus &GetNextDate &GetSerials2
@@ -901,22 +901,18 @@
return $calculated;
}
-=head2 GetSubscriptionExpirationDate
+=head2 GetExpirationDate
-=over 4
-
-$sensddate = GetSubscriptionExpirationDate($subscriptionid)
+$sensddate = GetExpirationDate($subscriptionid)
this function return the expiration date for a subscription given on input args.
return
the enddate
-=back
-
=cut
-sub GetSubscriptionExpirationDate {
+sub GetExpirationDate {
my ($subscriptionid) = @_;
my $dbh = C4::Context->dbh;
my $subscription = GetSubscription($subscriptionid);
@@ -924,9 +920,9 @@
# we don't do the same test if the subscription is based on X numbers or on X weeks/months
if ( $subscription->{numberlength} ) {
-
#calculate the date of the last issue.
- for ( my $i = 1 ; $i <= $subscription->{numberlength} ; $i++ ) {
+ my $length = $subscription->{numberlength};
+ for ( my $i = 1 ; $i <= $length ; $i++ ) {
$enddate = GetNextDate( $enddate, $subscription );
}
}
@@ -940,6 +936,7 @@
$subscription->{weeklength} . " weeks"
) if ( $subscription->{weeklength} );
}
+
return $enddate;
}
@@ -1602,14 +1599,17 @@
$sth->execute($subscriptionid);
my $res = ParseDate( format_date_in_iso( $sth->fetchrow ) );
my $endofsubscriptiondate;
+
$endofsubscriptiondate = DateCalc(
format_date_in_iso( $subscription->{startdate} ),
$subscription->{monthlength} . " months"
) if ( $subscription->{monthlength} );
+
$endofsubscriptiondate = DateCalc(
format_date_in_iso( $subscription->{startdate} ),
$subscription->{weeklength} . " weeks"
) if ( $subscription->{weeklength} );
+
return 1 if ( $res >= $endofsubscriptiondate );
return 0;
}
@@ -2174,45 +2174,6 @@
}
}
-=head2 HasExpiredBefore
-
-$result = &HasExpiredBefore($subscriptionid,$date)
-
-C<$date> must be a string like "1 month","1 day","3 weeks"
-C<$result> is 1 or 0
-
-
-=cut
-
-sub HasExpiredBefore {
- my $subscriptionid = shift;
- my $date = shift;
- my $dbh = C4::Context->dbh;
- my $subscription = GetSubscription($subscriptionid);
-
- if ( $subscription->{numberlength} ) {
- return undef; # FIXME, don't know how count the date in this case.
- }
- else {
- my $sth =
- $dbh->prepare(
- "select max(planneddate) from serial where subscriptionid=?");
- $sth->execute($subscriptionid);
- my $res = ParseDate( format_date_in_iso( $sth->fetchrow ) );
- my $endofsubscriptiondate;
- $endofsubscriptiondate = DateCalc(
- format_date_in_iso( $subscription->{startdate} ),
- $subscription->{monthlength} . " months"
- ) if ( $subscription->{monthlength} );
- $endofsubscriptiondate = DateCalc(
- format_date_in_iso( $subscription->{startdate} ),
- $subscription->{weeklength} . " weeks"
- ) if ( $subscription->{weeklength} );
-
- return DateCalc( $endofsubscriptiondate, "- " . $date );
- }
-}
-
=head2 old_newsubscription
=over 4
@@ -2289,7 +2250,7 @@
#then create the 1st waited number
my $subscriptionid = $dbh->{'mysql_insertid'};
- my $enddate = GetSubscriptionExpirationDate($subscriptionid);
+ my $enddate = GetExpirationDate($subscriptionid);
$sth =
$dbh->prepare(
@@ -2441,8 +2402,6 @@
=head2 GetNextDate
-=over 4
-
($resultdate) = &GetNextDate($planneddate,$subscription)
this function is an extension of GetNextDate which allows for checking for irregularity
@@ -2455,7 +2414,7 @@
return :
$resultdate - then next date in the sequence
-=back
+FIXME : have to replace Date::Manip by Date::Calc in this function to improve performances.
=cut
Index: serials/subscription-renew.pl
===================================================================
RCS file: /sources/koha/koha/serials/subscription-renew.pl,v
retrieving revision 1.2.2.3
retrieving revision 1.2.2.4
diff -u -b -r1.2.2.3 -r1.2.2.4
--- serials/subscription-renew.pl 18 Dec 2006 16:35:19 -0000 1.2.2.3
+++ serials/subscription-renew.pl 22 Dec 2006 14:38:59 -0000 1.2.2.4
@@ -18,7 +18,7 @@
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
-# $Id: subscription-renew.pl,v 1.2.2.3 2006/12/18 16:35:19 toins Exp $
+# $Id: subscription-renew.pl,v 1.2.2.4 2006/12/22 14:38:59 toins Exp $
=head1 NAME
@@ -80,7 +80,7 @@
my $subscription= GetSubscription($subscriptionid);
-$template->param(startdate => format_date(GetSubscriptionExpirationDate($subscriptionid)),
+$template->param(startdate => format_date(GetExpirationDate($subscriptionid)),
numberlength => $subscription->{numberlength},
weeklength => $subscription->{weeklength},
monthlength => $subscription->{monthlength},
Index: koha-tmpl/intranet-tmpl/prog/en/serials/checkexpiration.tmpl
===================================================================
RCS file: koha-tmpl/intranet-tmpl/prog/en/serials/checkexpiration.tmpl
diff -N koha-tmpl/intranet-tmpl/prog/en/serials/checkexpiration.tmpl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ koha-tmpl/intranet-tmpl/prog/en/serials/checkexpiration.tmpl 22 Dec 2006 14:38:59 -0000 1.1.2.1
@@ -0,0 +1,145 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+ Koha -- Serials expiration
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+
+<!-- Additions to enable Calendar system -->
+<link rel="stylesheet" type="text/css" href="<!-- TMPL_VAR name="themelang" -->/includes/calendar/calendar-system.css">
+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/includes/calendar/calendar.js"></script>
+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/includes/calendar/calendar-en.js"></script>
+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/includes/calendar/calendar-setup.js"></script>
+<!-- End of additions -->
+
+<!-- TMPL_INCLUDE NAME="menus.inc" -->
+<!-- TMPL_INCLUDE NAME="menu-serials.inc" -->
+
+<h1>Check expiration</h1>
+
+<fieldset>
+ <legend>Select record which will expire</legend>
+
+ <form name="f"
+ action="/cgi-bin/koha/serials/checkexpiration.pl"
+ method="POST"
+ onsubmit="return CheckForm(this);">
+
+ <label for="title">Filter on title </label>
+ <input id="title" type="texte" name="title" size="15" value="<!--TMPL_VAR NAME="title"-->"/>
+ <br />
+ <label for="issn">Filter on ISSN</label>
+ <input id="issn" type="texte" name="issn" size="15" value="<!-- TMPL_VAR NAME="issn"-->"/>
+ <br />
+ <label for="date">with expiration date before</label>
+ <input id="date" type="texte" name="date" size="10" value="<!-- TMPL_VAR NAME="date"-->"/>
+ <script type="text/javascript">
+ Calendar.setup(
+ {
+ inputField : "date",
+ ifFormat : "%Y-%m-%d",
+ }
+ );
+ </script>
+ <input type="submit" value="Search" />
+ </form>
+</fieldset>
+
+<!-- TMPL_IF NAME="subscriptions_loop"-->
+<p>
+ <b><!-- TMPL_VAR NAME="numsubscription"--></b> subscription(s)
+ <!-- TMPL_IF NAME="title"-->
+ with title like <b><!-- TMPL_VAR NAME="title"--></b>
+ <!-- TMPL_IF NAME="issn"-->and <!-- /TMPL_IF -->
+ <!-- /TMPL_IF -->
+ <!-- TMPL_IF NAME="issn"-->
+ issn like <b><!-- TMPL_VAR NAME="issn" --></b>
+ <!-- /TMPL_IF -->
+ will expirate bebore <b><!-- TMPL_VAR NAME="date" --></b>
+</p>
+<div class="searchresults">
+ <table>
+ <tr>
+ <th>
+ issn
+ </th>
+ <th>
+ title
+ </th>
+ <th>
+ Note
+ </th>
+ <th>
+ Expiration date
+ </th>
+ </tr>
+ <!-- TMPL_LOOP NAME="subscriptions_loop"-->
+ <!-- TMPL_IF NAME="toogle"-->
+ <tr class="highlight">
+ <!-- TMPL_ELSE -->
+ <tr>
+ <!-- /TMPL_IF -->
+ <td>
+ <!-- TMPL_VAR NAME="issn" -->
+ </td>
+ <td>
+ <!-- TMPL_IF name="BiblioDefaultViewmarc" -->
+ <a class="title" href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->">
+ <!-- TMPL_IF NAME="title"-->
+ <!-- TMPL_VAR NAME="title" -->
+ <!-- TMPL_ELSE -->
+ <span class="problem"><b>No title</b></span>
+ <!-- /TMPL_IF -->
+ </a>
+ <!-- TMPL_ELSE -->
+ <!-- TMPL_IF name="BiblioDefaultViewisbd" -->
+ <a class="title" href="/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->">
+ <!-- TMPL_IF NAME="title"-->
+ <!-- TMPL_VAR NAME="title" -->
+ <!-- TMPL_ELSE -->
+ <span class="problem"><b>No title</b></span>
+ <!-- /TMPL_IF -->
+ </a>
+ <!-- TMPL_ELSE -->
+ <a class="title" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->">
+ <!-- TMPL_IF NAME="title"-->
+ <!-- TMPL_VAR NAME="title" -->
+ <!-- TMPL_ELSE -->
+ <span class="problem"><b>No title</b></span>
+ <!-- /TMPL_IF -->
+ </a>
+ <!-- /TMPL_IF -->
+ <!-- /TMPL_IF -->
+ </td>
+ <td>
+ <!-- TMPL_VAR NAME="notes"-->
+ </td>
+ <td>
+ <!-- TMPL_VAR NAME="expirationdate" -->
+ </td>
+ </tr>
+ <!-- /TMPL_LOOP -->
+ </table>
+</div>
+<!-- /TMPL_IF -->
+
+<script type="text/javascript" language="JavaScript">
+// <![CDATA[
+ document.f.datenumber.focus();
+
+ /**
+ * Function CheckForm
+ * This function checks the form before submit
+ */
+ function CheckForm(form){
+ if(form.datenumber.value){
+ return true;
+ }
+ else {
+ alert("you must write a date !");
+ document.f.datenumber.focus();
+ return false;
+ }
+ }
+ // ]]>
+</script>
+
+
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
Index: serials/checkexpiration.pl
===================================================================
RCS file: serials/checkexpiration.pl
diff -N serials/checkexpiration.pl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ serials/checkexpiration.pl 22 Dec 2006 14:38:59 -0000 1.1.2.1
@@ -0,0 +1,104 @@
+#!/usr/bin/perl
+
+#
+# This file is part of Koha.
+#
+# 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 2 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
+
+# $Id: checkexpiration.pl,v 1.1.2.1 2006/12/22 14:38:59 toins Exp $
+
+=head1 NAME
+
+checkexpiration.pl
+
+=head1 DESCRIPTION
+
+This script check what subscription will expire before C<$datenumber $datelimit>
+
+=head1 PARAMETERS
+
+=over 4
+
+=item title
+ To filter subscription on title
+
+=item issn
+ To filter subscription on issn
+
+=item date
+The date to filter on.
+
+=back
+
+=cut
+
+use strict;
+use CGI;
+use C4::Auth;
+use C4::Serials; # GetExpirationDate
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Context;
+use Date::Calc qw/Today Date_to_Days/;
+
+my $query = new CGI;
+
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
+ {
+ template_name => "serials/checkexpiration.tmpl",
+ query => $query,
+ type => "intranet",
+ authnotrequired => 0,
+ flagsrequired => { serials => 1 },
+ debug => 1,
+ }
+);
+
+my $title = $query->param('title');
+my $issn = $query->param('issn');
+my $date = $query->param('date');
+my $today = join "-",&Today;
+
+if ($date) {
+
+ my @subscriptions = GetSubscriptions( $title, $issn );
+ my @subscriptions_loop;
+
+ foreach my $subscription ( @subscriptions ) {
+
+ my $subscriptionid = $subscription->{'subscriptionid'};
+ my $expirationdate = GetExpirationDate($subscriptionid);
+
+ $subscription->{expirationdate} = $expirationdate;
+
+ next if $expirationdate !~ /\d{4}-\d{2}-\d{2}/; # next if not in good format.
+
+ if ($expirationdate < $date &&
+ Date_to_Days(split "-",$expirationdate) > Date_to_Days(split "-",$today) ) {
+
+ push @subscriptions_loop,$subscription;
+ }
+ }
+
+ $template->param (
+ title => $title,
+ issn => $issn,
+ numsubscription => scalar @subscriptions_loop,
+ date => $date,
+ subscriptions_loop => \@subscriptions_loop,
+ "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
+ );
+}
+
+output_html_with_http_headers $query, $cookie, $template->output;
More information about the Koha-cvs
mailing list