&XMLkoha2marc
&XML_separate
&XML_record_header
+&XMLmodLCindex
&ZEBRAdelbiblio
&ZEBRAgetrecord
&ZEBRAop
$data->{'datelastborrowed'} = $data2->{'issue_date'};
$data->{'card'} = $data2->{'cardnumber'};
$data->{'borrower'} = $data2->{'borrowernumber'};
+ $data->{issues}++;
}
$sth2->finish;
+ my $sth2 = $dbh->prepare("select * from reserveissue,borrowers
+where itemnumber = ?
+and rettime is NULL
+and reserveissue.borrowernumber = borrowers.borrowernumber");
+
+ $sth2->execute($itemnumber);
+ if (my $data2 = $sth2->fetchrow_hashref) {
+
+ $data->{'date_due'}=$data2->{'duetime'};
+ $data->{'datelastborrowed'} = $data2->{'restime'};
+ $data->{'card'} = $data2->{'cardnumber'};
+ $data->{'borrower'} = $data2->{'borrowernumber'};
+ $data->{issues}++;
+ }
+ $sth2->finish;
# Find the last 2 people who borrowed this item.
$sth2 = $dbh->prepare("select * from issues, borrowers
where itemnumber = ?
and returndate is not NULL
order by returndate desc,timestamp desc limit 2") ;
$sth2->execute($itemnumber) ;
-# for (my $i2 = 0; $i2 < 2; $i2++) { # FIXME : error if there is less than 3 pple borrowing this item
my $i2=0;
while (my $data2 = $sth2->fetchrow_hashref) {
$data->{"timestamp$i2"} = $data2->{'timestamp'};
$data->{'datelastborrowed'} = $data2->{'issue_date'} unless $data->{'datelastborrowed'};
$i2++;
} # while
-# } # for
$sth2->finish;
return($data);
} else {
my $tobrcd = ReserveWaiting($res->{'itemnumber'}, $res->{'borrowernumber'});
transferbook($tobrcd,$barcode, 1);
- warn "transferbook";
+# warn "transferbook";
}
}
}
if (not $itemrecord) {
$messages->{'BadBarcode'} = $barcode;
$doreturn = 0;
- return ($doreturn, $messages, "", "");
+ return ($doreturn, $messages, undef, undef);
}
my $iteminformation=XMLmarc2koha_onerecord($dbh,$itemrecord,"holdings");
$iteminformation->{'itemtype'}=MARCfind_itemtype($dbh,$iteminformation->{biblionumber});
# check that the book has been cancelled
if ($iteminformation->{'wthdrawn'}) {
$messages->{'wthdrawn'} = 1;
- $doreturn = 0;
+ # $doreturn = 0;
}
# update issues, thereby returning book (should push this out into another subroutine
my ($borrower) = getpatroninformation(\%env, $currentborrower, 0);
$messages->{'WasReturned'} = 1; # FIXME is the "= 1" right?
$sth->finish;
+ }
$itemrecord=XML_writeline($itemrecord, "date_due", "","holdings");
$itemrecord=XML_writeline($itemrecord, "onloan", "0","holdings");
$itemrecord=XML_writeline($itemrecord, "borrowernumber", "","holdings");
- }
+
my ($transfered, $mess, $item) = transferbook($branch, $barcode, 1);
my ($sec,$min,$hour,$mday,$mon,$year) = localtime();
$year += 1900;
my $renews = 1;
my $resfound;
my $resrec;
- my $renewokay; ##
+ my $renewokay=0; ##
# Look in the issues table for this item, lent to this borrower,
# and not yet returned.
my $borrower=C4::Members::getpatroninformation($dbh,$bornum,undef);
and returndate is null
and items.itemnumber=issues.itemnumber");
$sth1->execute($bornum,$itemnumber);
- if (my $data1 = $sth1->fetchrow_hashref) {
+my $data1 = $sth1->fetchrow_hashref;
+ if ($data1 ) {
# Found a matching item
- if (C4::Context->preference("LibraryName") eq "NEU Grand Library"){
- ##privileged get renewal whatever the case may be
- if ($borrower->{'categorycode'} eq 'P'){
- $renewokay = 1;
- return $renewokay;
+ if (C4::Context->preference("LibraryName") eq "NEU Grand Library"){
+ ##privileged get renewal whatever the case may be
+ if ($borrower->{'categorycode'} eq 'P'){
+ $renewokay = 1;
+ return $renewokay;
+ }
}
- }
# See if this item may be renewed.
my $sth2 = $dbh->prepare("select renewalsallowed from itemtypes where itemtypes.itemtype=?");
$sth2->execute($data1->{itemtype});
$renewokay = 0;
}
}
- }## item found
($resfound, $resrec) = CheckReserves($itemnumber);
if ($resfound) {
if (C4::Context->preference("strictrenewals")){
$renewokay=4;
- }else{
+ }else{
$renewokay = 0;
}
- }
-# }
- $sth1->finish;
-if (C4::Context->preference("strictrenewals")){
+ }
+ if (C4::Context->preference("strictrenewals")){
### A new system pref "allowRenewalsBefore" prevents the renewal before a set amount of days left before expiry
## Try to find whether book can be renewed at this date
my $loanlength;
if ($difference < 0) {
$renewokay=2 ;
}
-}##strictrenewals
+ }##strictrenewals
+ }##item found
+ $sth1->finish;
+
return($renewokay);
}
&XMLmoditemonefield($dbh,$iteminformation->{'biblionumber'},$iteminformation->{'itemnumber'},'date_due',$datedue);
# Log the renewal
- UpdateStats($env,$env->{'branchcode'},'renew','','',$itemnumber,'',$bornum);
+ UpdateStats($env,$env->{'branchcode'},'renew','','',$itemnumber,$iteminformation->{'itemtype'},$bornum);
# Charge a new rental fee, if applicable?
my ($charge,$type)=calc_charges($env, $itemnumber, $bornum);
members might get a longer grace period between the first and second
reminders that a book is overdue).
-The fine is calculated as follows: if it is time for the first
-reminder, the fine is the value listed for the given (branch, item type,
-borrower code) combination. If it is time for the second reminder, the
-fine is doubled. Finally, if it is time to send the account to a
-collection agency, the fine is set to 5 local monetary units (a really
-good deal for the patron if the library is in Italy). Otherwise, the
-fine is 0.
-
-Note that the way this function is currently implemented, it only
-returns a nonzero value on the notable days listed above. That is, if
-the issuingruless entry says to send a first reminder 7 days after the
-book is due, then if you call C<&CalcFine> 7 days after the book is
-due, it will give a nonzero fine. If you call C<&CalcFine> the next
-day, however, it will say that the fine is 0.
+
C<$itemnumber> is the book's item number.
my $dbh = C4::Context->dbh;
# Look up the issuingrules record for this book's item type and the
# given borrwer type.
- # The reason this query is so messy is that it's a messy question:
- # given the barcode, we can find the book's items record. This gives
- # us the biblio record, which gives us a set of issuingrules
- # records. Then we select the one that corresponds to the desired
- # borrower type.
-
- # FIXME - Is it really necessary to get absolutely everything from
- # all four tables? It looks as if this code only wants
- # firstremind, chargeperiod, accountsent, and chargename from the
- # issuingrules table.
+
my $sth=$dbh->prepare("Select * from items,biblio,itemtypes,issuingrules where items.itemnumber=?
and items.biblionumber=biblio.biblionumber and
my $amount=0;
my $printout;
- # Is it time to send out the first reminder?
- # FIXME - I'm not sure the "=="s are correct here. Let's say that
- # $data->{firstremind} is today, but 'fines2.pl' doesn't run for
- # some reason (the cron daemon died, the server crashed, the
- # sysadmin had the machine down for maintenance, or whatever).
- #
- # Then the next day, the book is $data->{firstremind}+1 days
- # overdue. But this function returns $amount == 0, $printout ==
- # undef, on the assumption that 'fines2.pl' ran the previous day. So
- # the first thing the patron gets is a second notice, but that's a
- # week after the server crash, so people may not connect the two
- # events.
if ($difference > $data->{'firstremind'}){
# Yes. Set the fine as listed.
- $amount=$data->{'fine'}* $difference;
+$amount=$data->{'fine'}* $difference;
+
$printout="First Notice";
}
# Is it time to send out a second reminder?
- my $second=$data->{'firstremind'}+$data->{'chargeperiod'};
+ my $second=$data->{'firstremind'}+$data->{chargeperiod};
if ($difference == $second){
-# # Yes. The fine is double.
-# $amount=$data->{'fine'}*2;
+$amount=$data->{'fine'}* $difference;
+
$printout="Second Notice";
}
# Is it time to send the account to a collection agency?
- # FIXME - At least, I *think* that's what this code is doing.
- if ($difference == $data->{'accountsent'} && $data->{'fine'} > 0){
- # Yes. Set the fine at 5 local monetary units.
- # FIXME - This '5' shouldn't be hard-wired.
- $amount=$data->{'fine'}* $difference;
+ # FIXME -This $data->{'accountsent'} is not seemed to be set in the DB
+ if ($difference == $data->{'accountsent'}){
+ $amount=$data->{'fine'}* $difference;
+
$printout="Final Notice";
}
return($amount,$data->{'chargename'},$printout);
use DateTime::Format::ISO8601;
use DateTime::Format::Strptime;
use DateTime::Format::Duration;
-
+use POSIX qw(ceil floor);
require Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
}
sub get_duration{
my $period=shift;
+
my $parse;
-if ($period=~/day/){
+if ($period=~/ays/){
$parse="\%e days";
}elsif ($period=~/week/){
$parse="\%W weeks";
}elsif ($period=~/year/){
$parse="\%Y years";
-}elsif ($period=~/month/){
+}elsif ($period=~/onth/){
$parse="\%m months";
}
+
my $parser=DateTime::Format::Duration->new(pattern => $parse );
my $duration=$parser->parse_duration($period);
+
return $duration;
}
my $dt2=DateTime::Format::ISO8601->parse_datetime($date2);
my $dur=$dt2->subtract_datetime_absolute($dt1);## in seconds
my $days=$dur->seconds/(60*60*24);
-return int($days);
+return floor($days);
}
1;
=cut
sub GetLateIssues {
- my ($supplierid) = @_;
+ my ($supplierid) = shift;
my $dbh = C4::Context->dbh;
my $sth;
if ($supplierid) {
=cut
sub GetSubscriptions {
- my ($title,$ISSN,$biblionumber) = @_;
- return unless $title or $ISSN or $biblionumber;
+ my ($title,$ISSN,$biblionumber,$supplierid) = @_;
+ return unless $title or $ISSN or $biblionumber or $supplierid;
my $dbh = C4::Context->dbh;
my $sth;
if ($biblionumber) {
);
$sth = $dbh->prepare($query);
$sth->execute($biblionumber);
- } else {
- if ($ISSN and $title){
+ } elsif ($ISSN and $title){
my $query = qq|
- SELECT subscription.subscriptionid,biblio.title,biblio.issn,subscription.notes,biblio.biblionumber
+ SELECT subscription.subscriptionid,biblio.title,biblio.issn,subscription.notes,biblio.biblionumber,aqbooksellerid
FROM subscription,biblio
WHERE biblio.biblionumber= subscription.biblionumber
AND (biblio.title LIKE ? or biblio.issn = ?)
|;
$sth = $dbh->prepare($query);
$sth->execute("%$title%",$ISSN);
- }
- else{
- if ($ISSN){
+ } elsif ($ISSN){
my $query = qq(
- SELECT subscription.subscriptionid,biblio.title,biblio.issn,subscription.notes,biblio.biblionumber
+ SELECT subscription.subscriptionid,biblio.title,biblio.issn,subscription.notes,biblio.biblionumber,aqbooksellerid
FROM subscription,biblio
- WHERE biblio.biblionumber = biblioitems.biblionumber
- AND biblio.biblionumber=subscription.biblionumber
- AND biblioitems.issn = ?
+ WHERE biblio.biblionumber=subscription.biblionumber
+ AND biblio.issn = ?
ORDER BY title
);
$sth = $dbh->prepare($query);
$sth->execute($ISSN);
+ }elsif ($supplierid){
+ my $query = qq(
+ SELECT subscription.subscriptionid,biblio.title,biblio.issn,subscription.notes,biblio.biblionumber,aqbooksellerid
+ FROM subscription,biblio
+ WHERE biblio.biblionumber=subscription.biblionumber
+ AND subscription.aqbooksellerid = ?
+ ORDER BY title
+ );
+ $sth = $dbh->prepare($query);
+ $sth->execute($supplierid);
} else {
my $query = qq(
- SELECT subscription.subscriptionid,biblio.title,biblio.issn,subscription.notes,biblio.biblionumber
+ SELECT subscription.subscriptionid,biblio.title,biblio.issn,subscription.notes,biblio.biblionumber,aqbooksellerid
FROM subscription,biblio
WHERE biblio.biblionumber=subscription.biblionumber
AND biblio.title LIKE ?
);
$sth = $dbh->prepare($query);
$sth->execute("%$title%");
- }
}
- }
+
+
my @results;
my $previoustitle="";
my $odd=1;
=back
=cut
-sub GetNextSeq {
+sub Get_Next_Seq {
my ($val) =@_;
my ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3);
$calculated = $val->{numberingmethod};
}
-sub New_Get_Next_Seq {
+sub GetNextSeq {
my ($val) =@_;
my ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3);
my $pattern = $val->{numberpattern};
=back
=cut
-sub GetNextDate(@) {
- my ($planneddate,$subscription) = @_;
- my $resultdate;
- my $duration;
- if ($subscription->{periodicity} == 1) {
- $duration=get_duration("1 days");
- }
- if ($subscription->{periodicity} == 2) {
- $duration=get_duration("1 weeks");
- }
- if ($subscription->{periodicity} == 3) {
- $duration=get_duration("2 weeks");
- }
- if ($subscription->{periodicity} == 4) {
- $duration=get_duration("3 weeks");
- }
- if ($subscription->{periodicity} == 5) {
- $duration=get_duration("1 months");
- }
- if ($subscription->{periodicity} == 6) {
- $duration=get_duration("2 months");
- }
- if ($subscription->{periodicity} == 7 || $subscription->{periodicity} == 8) {
- $duration=get_duration("3 months");
- }
-
- if ($subscription->{periodicity} == 9) {
- $duration=get_duration("6 months");
- }
- if ($subscription->{periodicity} == 10) {
- $duration=get_duration("1 years");
- }
- if ($subscription->{periodicity} == 11) {
- $duration=get_duration("2 years");
- }
- $resultdate=DATE_Add_Duration($planneddate,$duration);
- return $resultdate;
-}
=head2 GetSeq
}
}
else {
- my $duration=get_duration($subscription->{monthlength}." months") if ($subscription->{monthlength});
- my $duration=get_duration($subscription->{weeklength}." weeks") if ($subscription->{weeklength});
-
+ my $duration;
+ $duration=get_duration($subscription->{monthlength}." months") if ($subscription->{monthlength});
+ $duration=get_duration($subscription->{weeklength}." weeks") if ($subscription->{weeklength});
$enddate = DATE_Add_Duration($subscription->{startdate},$duration) ;
}
return $enddate;
# next issue number
my ($newserialseq,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3) = GetNextSeq($val);
# next date (calculated from actual date & frequency parameters)
- my $nextplanneddate = Get_Next_Date($planneddate,$val);
- my $nextpublisheddate = Get_Next_Date($publisheddate,$val);
+ my $nextplanneddate = GetNextDate($planneddate,$val);
+ my $nextpublisheddate = GetNextDate($publisheddate,$val);
NewIssue($newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextpublisheddate,$nextplanneddate,0);
my $query = qq|
UPDATE subscription
my $val = $sth->fetchrow_hashref;
# next issue number
my ($newserialseq,$newlastvalue1,$newlastvalue2,$newlastvalue3) = New_Get_Next_Seq($val);
- my $nextplanneddate = Get_Next_Date($planneddate,$val);
+ my $nextplanneddate = GetNextDate($planneddate,$val);
NewIssue($newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextplanneddate);
$sth = $dbh->prepare("update subscription set lastvalue1=?, lastvalue2=?,lastvalue3=? where subscriptionid = ?");
$sth->execute($newlastvalue1,$newlastvalue2,$newlastvalue3,$subscriptionid);
$sth->execute($subscriptionid);
my $res = $sth->fetchrow;
my $endofsubscriptiondate;
- my $duration=get_duration($subscription->{monthlength}." months") if ($subscription->{monthlength});
- my $duration=get_duration($subscription->{weeklength}." weeks") if ($subscription->{weeklength});
+ my $duration;
+ $duration=get_duration($subscription->{monthlength}." months") if ($subscription->{monthlength});
+ $duration=get_duration($subscription->{weeklength}." weeks") if ($subscription->{weeklength});
$endofsubscriptiondate = DATE_Add_Duration($subscription->{startdate},$duration) ;
- return 1 if ($res >= $endofsubscriptiondate);
+ return 1 if ($res ge $endofsubscriptiondate);
return 0;
}
}
$sth->execute($subscriptionid);
my $res = $sth->fetchrow;
my $endofsubscriptiondate;
- my $duration=get_duration($subscription->{monthlength}." months") if ($subscription->{monthlength});
- my $duration=get_duration($subscription->{weeklength}." weeks") if ($subscription->{weeklength});
+my $duration;
+ $duration=get_duration($subscription->{monthlength}." months") if ($subscription->{monthlength});
+ $duration=get_duration($subscription->{weeklength}." weeks") if ($subscription->{weeklength});
$endofsubscriptiondate = DATE_Add_Duration($subscription->{startdate},$duration) ;
my $per = $subscription->{'periodicity'};
-=head2 Get_Next_Date
+=head2 GetNextDate
=over 4
-($resultdate) = &Get_Next_Date($planneddate,$subscription)
-
-this function is an extension of GetNextDate which allows for checking for irregularity
+($resultdate) = &GetNextDate($planneddate,$subscription)
-it takes the planneddate and will return the next issue's date and will skip dates if there
+this function takes the planneddate and will return the next issue's date and will skip dates if there
exists an irregularity
- eg if periodicity is monthly and $planneddate is 2007-02-10 but if March and April is to be
skipped then the returned date will be 2007-05-10
=back
=cut
-sub Get_Next_Date(@) {
+sub GetNextDate {
my ($planneddate,$subscription) = @_;
my @irreg = split(/\|/,$subscription->{irregularity});
my $dateobj=DATE_obj($planneddate);
my $dayofweek = $dateobj->day_of_week;
my $month=$dateobj->month;
my $resultdate;
- # warn "DOW $dayofweek";
if ($subscription->{periodicity} == 1) {
+ my %irreghash;
+ for(my $i=0;$i<@irreg;$i++){
+ $irreghash{$irreg[$i]}=1;
+ }
my $duration=get_duration("1 days");
for(my $i=0;$i<@irreg;$i++){
if($dayofweek == 7){ $dayofweek = 0; }
- if(in_array(($dayofweek+1), @irreg)){
+ if($irreghash{$dayofweek+1}){
$planneddate = DATE_Add_Duration($planneddate,$duration);
$dayofweek++;
}
}
}
$resultdate=DATE_Add_Duration($planneddate,$duration);
- # warn "Planneddate2: $planneddate";
}
if ($subscription->{periodicity} == 6) {
my $duration=get_duration("2 months");
#module to insert stats data into stats table
my ($env,$branch,$type,$amount,$other,$itemnum,$itemtype,$borrowernumber,$accountno)=@_;
my $dbh = C4::Context->dbh;
+ $env=C4::Context->userenv unless $env;
if ($branch eq ''){
$branch=$env->{'branchcode'};
}
- my $user = $env->{'usercode'};
- print $borrowernumber;
+ my $user = C4::Context->userenv;
+# print $borrowernumber;
+ my $userid=$user->{'cardnumber'} if $user;
# FIXME - Use $dbh->do() instead
my $sth=$dbh->prepare("Insert into statistics (datetime,branch,type,usercode,value,
other,itemnumber,itemtype,borrowernumber,proccode) values (now(),?,?,?,?,?,?,?,?,?)");
- $sth->execute($branch,$type,$user,$amount,$other,$itemnum,$itemtype,$borrowernumber,$accountno);
+ $sth->execute($branch,$type,$userid,$amount,$other,$itemnum,$itemtype,$borrowernumber,$accountno);
$sth->finish;
}