4 # Copyright 2000-2002 Katipo Communications
5 # copyright 2010 BibLibre
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #use warnings; FIXME - Bug 2505
24 use Date::Calc qw/Today Date_to_Days/;
25 use Date::Manip qw/UnixDate/;
29 use C4::Log; # logaction
32 use vars qw($VERSION @ISA @EXPORT);
35 # set the version for version checking
36 $VERSION = 3.07.00.049;
39 # subs to rename (and maybe merge some...)
53 &GetOverdueMessageTransportTypes
60 # check that an equivalent don't exist already before moving
62 # subs to move to Circulation.pm
67 # &GetIssuingRules - delete.
68 # use C4::Circulation::GetIssuingRule instead.
70 # subs to move to Biblio.pm
78 C4::Circulation::Fines - Koha module dealing with fines
86 This module contains several functions for dealing with fines for
87 overdue items. It is primarily used by the 'misc/fines2.pl' script.
93 $overdues = Getoverdues( { minimumdays => 1, maximumdays => 30 } );
95 Returns the list of all overdue books, with their itemtype.
97 C<$overdues> is a reference-to-array. Each element is a
98 reference-to-hash whose keys are the fields of the issues table in the
106 my $dbh = C4::Context->dbh;
108 if ( C4::Context->preference('item-level_itypes') ) {
110 SELECT issues.*, items.itype as itemtype, items.homebranch, items.barcode
112 LEFT JOIN items USING (itemnumber)
113 WHERE date_due < NOW()
117 SELECT issues.*, biblioitems.itemtype, items.itype, items.homebranch, items.barcode
119 LEFT JOIN items USING (itemnumber)
120 LEFT JOIN biblioitems USING (biblioitemnumber)
121 WHERE date_due < NOW()
126 if ( exists $params->{'minimumdays'} and exists $params->{'maximumdays'} ) {
127 $statement .= ' AND TO_DAYS( NOW() )-TO_DAYS( date_due ) BETWEEN ? and ? ';
128 push @bind_parameters, $params->{'minimumdays'}, $params->{'maximumdays'};
129 } elsif ( exists $params->{'minimumdays'} ) {
130 $statement .= ' AND ( TO_DAYS( NOW() )-TO_DAYS( date_due ) ) > ? ';
131 push @bind_parameters, $params->{'minimumdays'};
132 } elsif ( exists $params->{'maximumdays'} ) {
133 $statement .= ' AND ( TO_DAYS( NOW() )-TO_DAYS( date_due ) ) < ? ';
134 push @bind_parameters, $params->{'maximumdays'};
136 $statement .= 'ORDER BY borrowernumber';
137 my $sth = $dbh->prepare( $statement );
138 $sth->execute( @bind_parameters );
139 return $sth->fetchall_arrayref({});
145 ($count, $overdueitems) = checkoverdues($borrowernumber);
147 Returns a count and a list of overdueitems for a given borrowernumber
152 my $borrowernumber = shift or return;
153 # don't select biblioitems.marc or biblioitems.marcxml... too slow on large systems
154 my $sth = C4::Context->dbh->prepare(
155 "SELECT biblio.*, items.*, issues.*,
158 biblioitems.itemtype,
161 biblioitems.publicationyear,
162 biblioitems.publishercode,
163 biblioitems.volumedate,
164 biblioitems.volumedesc,
165 biblioitems.collectiontitle,
166 biblioitems.collectionissn,
167 biblioitems.collectionvolume,
168 biblioitems.editionstatement,
169 biblioitems.editionresponsibility,
177 biblioitems.cn_source,
178 biblioitems.cn_class,
180 biblioitems.cn_suffix,
182 biblioitems.totalissues
184 LEFT JOIN items ON issues.itemnumber = items.itemnumber
185 LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
186 LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber
187 WHERE issues.borrowernumber = ?
188 AND issues.date_due < NOW()"
190 # FIXME: SELECT * across 4 tables? do we really need the marc AND marcxml blobs??
191 $sth->execute($borrowernumber);
192 my $results = $sth->fetchall_arrayref({});
193 return ( scalar(@$results), $results); # returning the count and the results is silly
198 ($amount, $chargename, $daycounttotal) = &CalcFine($item,
199 $categorycode, $branch,
200 $start_dt, $end_dt );
202 Calculates the fine for a book.
204 The issuingrules table in the Koha database is a fine matrix, listing
205 the penalties for each type of patron for each type of item and each branch (e.g., the
206 standard fine for books might be $0.50, but $1.50 for DVDs, or staff
207 members might get a longer grace period between the first and second
208 reminders that a book is overdue).
211 C<$item> is an item object (hashref).
213 C<$categorycode> is the category code (string) of the patron who currently has
216 C<$branchcode> is the library (string) whose issuingrules govern this transaction.
218 C<$start_date> & C<$end_date> are DateTime objects
219 defining the date range over which to determine the fine.
221 Fines scripts should just supply the date range over which to calculate the fine.
223 C<&CalcFine> returns four values:
225 C<$amount> is the fine owed by the patron (see above).
227 C<$chargename> is the chargename field from the applicable record in
228 the categoryitem table, whatever that is.
230 C<$unitcount> is the number of chargeable units (days between start and end dates, Calendar adjusted where needed,
231 minus any applicable grace period, or hours)
233 FIXME - What is chargename supposed to be ?
235 FIXME: previously attempted to return C<$message> as a text message, either "First Notice", "Second Notice",
236 or "Final Notice". But CalcFine never defined any value.
241 my ( $item, $bortype, $branchcode, $due_dt, $end_date ) = @_;
242 my $start_date = $due_dt->clone();
243 # get issuingrules (fines part will be used)
244 my $itemtype = $item->{itemtype} || $item->{itype};
245 my $data = C4::Circulation::GetIssuingRule($bortype, $itemtype, $branchcode);
246 my $fine_unit = $data->{lengthunit};
247 $fine_unit ||= 'days';
249 my $chargeable_units = _get_chargeable_units($fine_unit, $start_date, $end_date, $branchcode);
250 my $units_minus_grace = $chargeable_units - $data->{firstremind};
252 if ($data->{'chargeperiod'} && ($units_minus_grace > 0) ) {
253 if ( C4::Context->preference('FinesIncludeGracePeriod') ) {
254 $amount = int($chargeable_units / $data->{'chargeperiod'}) * $data->{'fine'};# TODO fine calc should be in cents
256 $amount = int($units_minus_grace / $data->{'chargeperiod'}) * $data->{'fine'};
259 # a zero (or null) chargeperiod or negative units_minus_grace value means no charge.
261 $amount = $data->{overduefinescap} if $data->{overduefinescap} && $amount > $data->{overduefinescap};
262 $debug and warn sprintf("CalcFine returning (%s, %s, %s, %s)", $amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units);
263 return ($amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units);
264 # FIXME: chargename is NEVER populated anywhere.
268 =head2 _get_chargeable_units
270 _get_chargeable_units($unit, $start_date_ $end_date, $branchcode);
272 return integer value of units between C<$start_date> and C<$end_date>, factoring in holidays for C<$branchcode>.
274 C<$unit> is 'days' or 'hours' (default is 'days').
276 C<$start_date> and C<$end_date> are the two DateTimes to get the number of units between.
278 C<$branchcode> is the branch whose calendar to use for finding holidays.
282 sub _get_chargeable_units {
283 my ($unit, $dt1, $dt2, $branchcode) = @_;
284 my $charge_units = 0;
286 if ($unit eq 'hours') {
287 if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
288 my $calendar = Koha::Calendar->new( branchcode => $branchcode );
289 $charge_duration = $calendar->hours_between( $dt1, $dt2 );
291 $charge_duration = $dt2->delta_ms( $dt1 );
293 if($charge_duration->in_units('hours') == 0 && $charge_duration->in_units('seconds') > 0){
296 return $charge_duration->in_units('hours');
299 if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
300 my $calendar = Koha::Calendar->new( branchcode => $branchcode );
301 $charge_duration = $calendar->days_between( $dt1, $dt2 );
303 $charge_duration = $dt2->delta_days( $dt1 );
305 return $charge_duration->in_units('days');
310 =head2 GetSpecialHolidays
312 &GetSpecialHolidays($date_dues,$itemnumber);
314 return number of special days between date of the day and date due
316 C<$date_dues> is the envisaged date of book return.
318 C<$itemnumber> is the book's item number.
322 sub GetSpecialHolidays {
323 my ( $date_dues, $itemnumber ) = @_;
325 # calcul the today date
326 my $today = join "-", &Today();
328 # return the holdingbranch
329 my $iteminfo = GetIssuesIteminfo($itemnumber);
331 # use sql request to find all date between date_due and today
332 my $dbh = C4::Context->dbh;
334 qq|SELECT DATE_FORMAT(concat(year,'-',month,'-',day),'%Y-%m-%d') as date
335 FROM `special_holidays`
336 WHERE DATE_FORMAT(concat(year,'-',month,'-',day),'%Y-%m-%d') >= ?
337 AND DATE_FORMAT(concat(year,'-',month,'-',day),'%Y-%m-%d') <= ?
340 my @result = GetWdayFromItemnumber($itemnumber);
344 my $sth = $dbh->prepare($query);
345 $sth->execute( $date_dues, $today, $iteminfo->{'branchcode'} )
346 ; # FIXME: just use NOW() in SQL instead of passing in $today
348 while ( my $special_date = $sth->fetchrow_hashref ) {
349 push( @result_date, $special_date );
352 my $specialdaycount = scalar(@result_date);
354 for ( my $i = 0 ; $i < scalar(@result_date) ; $i++ ) {
355 $dateinsec = UnixDate( $result_date[$i]->{'date'}, "%o" );
356 ( undef, undef, undef, undef, undef, undef, $wday, undef, undef ) =
357 localtime($dateinsec);
358 for ( my $j = 0 ; $j < scalar(@result) ; $j++ ) {
359 if ( $wday == ( $result[$j]->{'weekday'} ) ) {
365 return $specialdaycount;
368 =head2 GetRepeatableHolidays
370 &GetRepeatableHolidays($date_dues, $itemnumber, $difference,);
372 return number of day closed between date of the day and date due
374 C<$date_dues> is the envisaged date of book return.
376 C<$itemnumber> is item number.
378 C<$difference> numbers of between day date of the day and date due
382 sub GetRepeatableHolidays {
383 my ( $date_dues, $itemnumber, $difference ) = @_;
384 my $dateinsec = UnixDate( $date_dues, "%o" );
385 my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
386 localtime($dateinsec);
387 my @result = GetWdayFromItemnumber($itemnumber);
391 for ( my $i = 0 ; $i < scalar(@result) ; $i++ ) {
394 for ( $j = 0 ; $j < $difference ; $j++ ) {
395 if ( $result[$i]->{'weekday'} == $k ) {
396 push( @dayclosedcount, $k );
399 ( $k = 0 ) if ( $k eq 7 );
402 return scalar(@dayclosedcount);
406 =head2 GetWayFromItemnumber
408 &Getwdayfromitemnumber($itemnumber);
410 return the different week day from repeatable_holidays table
412 C<$itemnumber> is item number.
416 sub GetWdayFromItemnumber {
417 my ($itemnumber) = @_;
418 my $iteminfo = GetIssuesIteminfo($itemnumber);
420 my $query = qq|SELECT weekday
421 FROM repeatable_holidays
424 my $sth = C4::Context->dbh->prepare($query);
426 $sth->execute( $iteminfo->{'branchcode'} );
427 while ( my $weekday = $sth->fetchrow_hashref ) {
428 push( @result, $weekday );
434 =head2 GetIssuesIteminfo
436 &GetIssuesIteminfo($itemnumber);
438 return all data from issues about item
440 C<$itemnumber> is item number.
444 sub GetIssuesIteminfo {
445 my ($itemnumber) = @_;
446 my $dbh = C4::Context->dbh;
447 my $query = qq|SELECT *
451 my $sth = $dbh->prepare($query);
452 $sth->execute($itemnumber);
453 my ($issuesinfo) = $sth->fetchrow_hashref;
460 &UpdateFine($itemnumber, $borrowernumber, $amount, $type, $description);
462 (Note: the following is mostly conjecture and guesswork.)
464 Updates the fine owed on an overdue book.
466 C<$itemnumber> is the book's item number.
468 C<$borrowernumber> is the borrower number of the patron who currently
469 has the book on loan.
471 C<$amount> is the current amount owed by the patron.
473 C<$type> will be used in the description of the fine.
475 C<$description> is a string that must be present in the description of
476 the fine. I think this is expected to be a date in DD/MM/YYYY format.
478 C<&UpdateFine> looks up the amount currently owed on the given item
479 and sets it to C<$amount>, creating, if necessary, a new entry in the
480 accountlines table of the Koha database.
485 # Question: Why should the caller have to
486 # specify both the item number and the borrower number? A book can't
487 # be on loan to two different people, so the item number should be
490 # Possible Answer: You might update a fine for a damaged item, *after* it is returned.
493 my ( $itemnum, $borrowernumber, $amount, $type, $due ) = @_;
494 $debug and warn "UpdateFine($itemnum, $borrowernumber, $amount, " . ($type||'""') . ", $due) called";
495 my $dbh = C4::Context->dbh;
496 # FIXME - What exactly is this query supposed to do? It looks up an
497 # entry in accountlines that matches the given item and borrower
498 # numbers, where the description contains $due, and where the
499 # account type has one of several values, but what does this _mean_?
500 # Does it look up existing fines for this item?
501 # FIXME - What are these various account types? ("FU", "O", "F", "M")
503 # "A" is Account Management Fee
508 # "FU" is Fine UPDATE??
510 # "REF" is Cash Refund
511 my $sth = $dbh->prepare(
512 "SELECT * FROM accountlines
513 WHERE borrowernumber=?
514 AND accounttype IN ('FU','O','F','M')"
516 $sth->execute( $borrowernumber );
518 my $total_amount_other = 0.00;
519 my $due_qr = qr/$due/;
520 # Cycle through the fines and
521 # - find line that relates to the requested $itemnum
522 # - accumulate fines for other items
523 # so we can update $itemnum fine taking in account fine caps
524 while (my $rec = $sth->fetchrow_hashref) {
525 if ($rec->{itemnumber} == $itemnum && $rec->{description} =~ /$due_qr/) {
527 warn "Not a unique accountlines record for item $itemnum borrower $borrowernumber";
533 $total_amount_other += $rec->{'amountoutstanding'};
536 if (my $maxfine = C4::Context->preference('MaxFine')) {
537 if ($total_amount_other + $amount > $maxfine) {
538 my $new_amount = $maxfine - $total_amount_other;
539 return if $new_amount <= 0.00;
540 warn "Reducing fine for item $itemnum borrower $borrowernumber from $amount to $new_amount - MaxFine reached";
541 $amount = $new_amount;
547 # we're updating an existing fine. Only modify if amount changed
548 # Note that in the current implementation, you cannot pay against an accruing fine
549 # (i.e. , of accounttype 'FU'). Doing so will break accrual.
550 if ( $data->{'amount'} != $amount ) {
551 my $diff = $amount - $data->{'amount'};
552 #3341: diff could be positive or negative!
553 my $out = $data->{'amountoutstanding'} + $diff;
556 SET date=now(), amount=?, amountoutstanding=?,
557 lastincrement=?, accounttype='FU'
558 WHERE borrowernumber=?
560 AND accounttype IN ('FU','O')
561 AND description LIKE ?
563 my $sth2 = $dbh->prepare($query);
564 # FIXME: BOGUS query cannot ensure uniqueness w/ LIKE %x% !!!
565 # LIMIT 1 added to prevent multiple affected lines
566 # FIXME: accountlines table needs unique key!! Possibly a combo of borrowernumber and accountline.
567 # But actually, we should just have a regular autoincrementing PK and forget accountline,
568 # including the bogus getnextaccountno function (doesn't prevent conflict on simultaneous ops).
569 # FIXME: Why only 2 account types here?
570 $debug and print STDERR "UpdateFine query: $query\n" .
571 "w/ args: $amount, $out, $diff, $data->{'borrowernumber'}, $data->{'itemnumber'}, \"\%$due\%\"\n";
572 $sth2->execute($amount, $out, $diff, $data->{'borrowernumber'}, $data->{'itemnumber'}, "%$due%");
574 # print "no update needed $data->{'amount'}"
577 my $sth4 = $dbh->prepare(
578 "SELECT title FROM biblio LEFT JOIN items ON biblio.biblionumber=items.biblionumber WHERE items.itemnumber=?"
580 $sth4->execute($itemnum);
581 my $title = $sth4->fetchrow;
583 # # print "not in account";
584 # my $sth3 = $dbh->prepare("Select max(accountno) from accountlines");
587 # # FIXME - Make $accountno a scalar.
588 # my @accountno = $sth3->fetchrow_array;
592 my $nextaccntno = C4::Accounts::getnextacctno($borrowernumber);
593 my $desc = ($type ? "$type " : '') . "$title $due"; # FIXEDME, avoid whitespace prefix on empty $type
594 my $query = "INSERT INTO accountlines
595 (borrowernumber,itemnumber,date,amount,description,accounttype,amountoutstanding,lastincrement,accountno)
596 VALUES (?,?,now(),?,?,'FU',?,?,?)";
597 my $sth2 = $dbh->prepare($query);
598 $debug and print STDERR "UpdateFine query: $query\nw/ args: $borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno\n";
599 $sth2->execute($borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno);
606 "due=".$due." amount=".$amount." itemnumber=".$itemnum
607 ) if C4::Context->preference("FinesLog");
612 $borrower = &BorType($borrowernumber);
614 Looks up a patron by borrower number.
616 C<$borrower> is a reference-to-hash whose keys are all of the fields
617 from the borrowers and categories tables of the Koha database. Thus,
618 C<$borrower> contains all information about both the borrower and
619 category he or she belongs to.
624 my ($borrowernumber) = @_;
625 my $dbh = C4::Context->dbh;
626 my $sth = $dbh->prepare(
627 "SELECT * from borrowers
628 LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
629 WHERE borrowernumber=?"
631 $sth->execute($borrowernumber);
632 return $sth->fetchrow_hashref;
637 $data->{'sum(amountoutstanding)'} = &GetFine($itemnum,$borrowernumber);
639 return the total of fine
641 C<$itemnum> is item number
643 C<$borrowernumber> is the borrowernumber
648 my ( $itemnum, $borrowernumber ) = @_;
649 my $dbh = C4::Context->dbh();
650 my $query = q|SELECT sum(amountoutstanding) as fineamount FROM accountlines
651 where accounttype like 'F%'
652 AND amountoutstanding > 0 AND itemnumber = ? AND borrowernumber=?|;
653 my $sth = $dbh->prepare($query);
654 $sth->execute( $itemnum, $borrowernumber );
655 my $fine = $sth->fetchrow_hashref();
656 if ($fine->{fineamount}) {
657 return $fine->{fineamount};
662 =head2 NumberNotifyId
664 (@notify) = &NumberNotifyId($borrowernumber);
666 Returns amount for all file per borrowers
667 C<@notify> array contains all file per borrowers
669 C<$notify_id> contains the file number for the borrower number nad item number
674 my ($borrowernumber)=@_;
675 my $dbh = C4::Context->dbh;
676 my $query=qq| SELECT distinct(notify_id)
678 WHERE borrowernumber=?|;
680 my $sth = $dbh->prepare($query);
681 $sth->execute($borrowernumber);
682 while ( my ($numberofnotify) = $sth->fetchrow ) {
683 push( @notify, $numberofnotify );
690 ($totalnotify) = &AmountNotify($notifyid);
692 Returns amount for all file per borrowers
693 C<$notifyid> is the file number
695 C<$totalnotify> contains amount of a file
697 C<$notify_id> contains the file number for the borrower number and item number
702 my ($notifyid,$borrowernumber)=@_;
703 my $dbh = C4::Context->dbh;
704 my $query=qq| SELECT sum(amountoutstanding)
706 WHERE notify_id=? AND borrowernumber = ?|;
707 my $sth=$dbh->prepare($query);
708 $sth->execute($notifyid,$borrowernumber);
709 my $totalnotify=$sth->fetchrow;
711 return ($totalnotify);
716 ($items) = &GetItems($itemnumber);
718 Returns the list of all delays from overduerules.
720 C<$items> is a reference-to-hash whose keys are all of the fields
721 from the items tables of the Koha database. Thus,
723 C<$itemnumber> contains the borrower categorycode
727 # FIXME: This is a bad function to have here.
728 # Shouldn't it be in C4::Items?
729 # Shouldn't it be called GetItem since you only get 1 row?
730 # Shouldn't it be called GetItem since you give it only 1 itemnumber?
733 my $itemnumber = shift or return;
734 my $query = qq|SELECT *
737 my $sth = C4::Context->dbh->prepare($query);
738 $sth->execute($itemnumber);
739 my ($items) = $sth->fetchrow_hashref;
743 =head2 GetBranchcodesWithOverdueRules
745 my @branchcodes = C4::Overdues::GetBranchcodesWithOverdueRules()
747 returns a list of branch codes for branches with overdue rules defined.
751 sub GetBranchcodesWithOverdueRules {
752 my $dbh = C4::Context->dbh;
753 my $rqoverduebranches = $dbh->prepare("SELECT DISTINCT branchcode FROM overduerules WHERE delay1 IS NOT NULL AND branchcode <> '' ORDER BY branchcode");
754 $rqoverduebranches->execute;
755 my @branches = map { shift @$_ } @{ $rqoverduebranches->fetchall_arrayref };
757 my $availbranches = C4::Branch::GetBranches();
758 @branches = keys %$availbranches;
763 =head2 CheckItemNotify
765 Sql request to check if the document has alreday been notified
766 this function is not exported, only used with GetOverduesForBranch
770 sub CheckItemNotify {
771 my ($notify_id,$notify_level,$itemnumber) = @_;
772 my $dbh = C4::Context->dbh;
773 my $sth = $dbh->prepare("
778 AND itemnumber = ? ");
779 $sth->execute($notify_id,$notify_level,$itemnumber);
780 my $notified = $sth->fetchrow;
784 =head2 GetOverduesForBranch
786 Sql request for display all information for branchoverdues.pl
787 2 possibilities : with or without location .
788 display is filtered by branch
790 FIXME: This function should be renamed.
794 sub GetOverduesForBranch {
795 my ( $branch, $location) = @_;
796 my $itype_link = (C4::Context->preference('item-level_itypes')) ? " items.itype " : " biblioitems.itemtype ";
797 my $dbh = C4::Context->dbh;
800 borrowers.cardnumber,
801 borrowers.borrowernumber,
815 items.itemcallnumber,
818 itemtypes.description,
819 accountlines.notify_id,
820 accountlines.notify_level,
821 accountlines.amountoutstanding
823 LEFT JOIN issues ON issues.itemnumber = accountlines.itemnumber
824 AND issues.borrowernumber = accountlines.borrowernumber
825 LEFT JOIN borrowers ON borrowers.borrowernumber = accountlines.borrowernumber
826 LEFT JOIN items ON items.itemnumber = issues.itemnumber
827 LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
828 LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
829 LEFT JOIN itemtypes ON itemtypes.itemtype = $itype_link
830 LEFT JOIN branches ON branches.branchcode = issues.branchcode
831 WHERE (accountlines.amountoutstanding != '0.000000')
832 AND (accountlines.accounttype = 'FU' )
833 AND (issues.branchcode = ? )
834 AND (issues.date_due < NOW())
840 $sth = $dbh->prepare("$select AND items.location = ? ORDER BY borrowers.surname, borrowers.firstname");
841 $sth->execute($branch, $location);
843 $sth = $dbh->prepare("$select ORDER BY borrowers.surname, borrowers.firstname");
844 $sth->execute($branch);
846 while ( my $data = $sth->fetchrow_hashref ) {
847 #check if the document has already been notified
848 my $countnotify = CheckItemNotify($data->{'notify_id'}, $data->{'notify_level'}, $data->{'itemnumber'});
849 if ($countnotify eq '0') {
850 $getoverdues[$i] = $data;
854 return (@getoverdues);
860 &AddNotifyLine($borrowernumber, $itemnumber, $overduelevel, $method, $notifyId)
862 Create a line into notify, if the method is phone, the notification_send_date is implemented to
867 my ( $borrowernumber, $itemnumber, $overduelevel, $method, $notifyId ) = @_;
868 my $dbh = C4::Context->dbh;
869 if ( $method eq "phone" ) {
870 my $sth = $dbh->prepare(
871 "INSERT INTO notifys (borrowernumber,itemnumber,notify_date,notify_send_date,notify_level,method,notify_id)
872 VALUES (?,?,now(),now(),?,?,?)"
874 $sth->execute( $borrowernumber, $itemnumber, $overduelevel, $method,
878 my $sth = $dbh->prepare(
879 "INSERT INTO notifys (borrowernumber,itemnumber,notify_date,notify_level,method,notify_id)
880 VALUES (?,?,now(),?,?,?)"
882 $sth->execute( $borrowernumber, $itemnumber, $overduelevel, $method,
888 =head2 RemoveNotifyLine
890 &RemoveNotifyLine( $borrowernumber, $itemnumber, $notify_date );
892 Cancel a notification
896 sub RemoveNotifyLine {
897 my ( $borrowernumber, $itemnumber, $notify_date ) = @_;
898 my $dbh = C4::Context->dbh;
899 my $sth = $dbh->prepare(
906 $sth->execute( $borrowernumber, $itemnumber, $notify_date );
910 =head2 GetOverdueMessageTransportTypes
912 my $message_transport_types = GetOverdueMessageTransportTypes( $branchcode, $categorycode, $letternumber);
914 return a arrayref with message_transport_type for given branchcode, categorycode and letternumber(1,2 or 3)
917 sub GetOverdueMessageTransportTypes {
918 my ( $branchcode, $categorycode, $letternumber ) = @_;
919 return unless $categorycode and $letternumber;
920 my $dbh = C4::Context->dbh;
921 my $sth = $dbh->prepare("
922 SELECT message_transport_type FROM overduerules_transport_types
923 WHERE branchcode = ? AND categorycode = ? AND letternumber = ?
925 $sth->execute( $branchcode, $categorycode, $letternumber );
927 while ( my $mtt = $sth->fetchrow ) {
938 Koha Development Team <http://koha-community.org/>