View | Details | Raw Unified | Return to bug 17015
Collapse All | Expand All

(-)a/C4/Circulation.pm (-52 / +52 lines)
Lines 42-48 use Data::Dumper; Link Here
42
use Koha::Account;
42
use Koha::Account;
43
use Koha::AuthorisedValues;
43
use Koha::AuthorisedValues;
44
use Koha::DateUtils;
44
use Koha::DateUtils;
45
use Koha::Calendar;
45
use Koha::DiscreteCalendar;
46
use Koha::Checkouts;
46
use Koha::Checkouts;
47
use Koha::IssuingRules;
47
use Koha::IssuingRules;
48
use Koha::Items;
48
use Koha::Items;
Lines 153-163 Generic filter function for barcode string. Link Here
153
Called on every circ if the System Pref itemBarcodeInputFilter is set.
153
Called on every circ if the System Pref itemBarcodeInputFilter is set.
154
Will do some manipulation of the barcode for systems that deliver a barcode
154
Will do some manipulation of the barcode for systems that deliver a barcode
155
to circulation.pl that differs from the barcode stored for the item.
155
to circulation.pl that differs from the barcode stored for the item.
156
For proper functioning of this filter, calling the function on the 
156
For proper functioning of this filter, calling the function on the
157
correct barcode string (items.barcode) should return an unaltered barcode.
157
correct barcode string (items.barcode) should return an unaltered barcode.
158
158
159
The optional $filter argument is to allow for testing or explicit 
159
The optional $filter argument is to allow for testing or explicit
160
behavior that ignores the System Pref.  Valid values are the same as the 
160
behavior that ignores the System Pref.  Valid values are the same as the
161
System Pref options.
161
System Pref options.
162
162
163
=cut
163
=cut
Lines 247-253 sub decode { Link Here
247
247
248
=head2 transferbook
248
=head2 transferbook
249
249
250
  ($dotransfer, $messages, $iteminformation) = &transferbook($newbranch, 
250
  ($dotransfer, $messages, $iteminformation) = &transferbook($newbranch,
251
                                            $barcode, $ignore_reserves);
251
                                            $barcode, $ignore_reserves);
252
252
253
Transfers an item to a new branch. If the item is currently on loan, it is automatically returned before the actual transfer.
253
Transfers an item to a new branch. If the item is currently on loan, it is automatically returned before the actual transfer.
Lines 263-269 Returns three values: Link Here
263
263
264
=over
264
=over
265
265
266
=item $dotransfer 
266
=item $dotransfer
267
267
268
is true if the transfer was successful.
268
is true if the transfer was successful.
269
269
Lines 391-400 sub TooMany { Link Here
391
	my $branch;
391
	my $branch;
392
	# Get which branchcode we need
392
	# Get which branchcode we need
393
	$branch = _GetCircControlBranch($item,$borrower);
393
	$branch = _GetCircControlBranch($item,$borrower);
394
	my $type = (C4::Context->preference('item-level_itypes')) 
394
	my $type = (C4::Context->preference('item-level_itypes'))
395
  			? $item->{'itype'}         # item-level
395
  			? $item->{'itype'}         # item-level
396
			: $item->{'itemtype'};     # biblio-level
396
			: $item->{'itemtype'};     # biblio-level
397
 
397
398
    # given branch, patron category, and item type, determine
398
    # given branch, patron category, and item type, determine
399
    # applicable issuing rule
399
    # applicable issuing rule
400
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
400
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
Lines 428-435 sub TooMany { Link Here
428
                                    AND   (categorycode = ? OR categorycode = ?)
428
                                    AND   (categorycode = ? OR categorycode = ?)
429
                                    AND   itemtype <> '*'
429
                                    AND   itemtype <> '*'
430
                                  ) ";
430
                                  ) ";
431
            } else { 
431
            } else {
432
                $count_query .= " JOIN  biblioitems USING (biblionumber) 
432
                $count_query .= " JOIN  biblioitems USING (biblionumber)
433
                                  WHERE biblioitems.itemtype NOT IN (
433
                                  WHERE biblioitems.itemtype NOT IN (
434
                                    SELECT itemtype FROM issuingrules
434
                                    SELECT itemtype FROM issuingrules
435
                                    WHERE branchcode = ?
435
                                    WHERE branchcode = ?
Lines 445-452 sub TooMany { Link Here
445
            # specific item type
445
            # specific item type
446
            if (C4::Context->preference('item-level_itypes')) {
446
            if (C4::Context->preference('item-level_itypes')) {
447
                $count_query .= " WHERE items.itype = ? ";
447
                $count_query .= " WHERE items.itype = ? ";
448
            } else { 
448
            } else {
449
                $count_query .= " JOIN  biblioitems USING (biblionumber) 
449
                $count_query .= " JOIN  biblioitems USING (biblionumber)
450
                                  WHERE biblioitems.itemtype= ? ";
450
                                  WHERE biblioitems.itemtype= ? ";
451
            }
451
            }
452
            push @bind_params, $type;
452
            push @bind_params, $type;
Lines 561-567 sub TooMany { Link Here
561
561
562
=head2 CanBookBeIssued
562
=head2 CanBookBeIssued
563
563
564
  ( $issuingimpossible, $needsconfirmation ) =  CanBookBeIssued( $borrower, 
564
  ( $issuingimpossible, $needsconfirmation ) =  CanBookBeIssued( $borrower,
565
                      $barcode, $duedate, $inprocess, $ignore_reserves, $params );
565
                      $barcode, $duedate, $inprocess, $ignore_reserves, $params );
566
566
567
Check if a book can be issued.
567
Check if a book can be issued.
Lines 597-603 Possible values are : Link Here
597
597
598
=back
598
=back
599
599
600
=head3 INVALID_DATE 
600
=head3 INVALID_DATE
601
601
602
sticky due date is invalid
602
sticky due date is invalid
603
603
Lines 629-635 item withdrawn. Link Here
629
629
630
item is restricted (set by ??)
630
item is restricted (set by ??)
631
631
632
C<$needsconfirmation> a reference to a hash. It contains reasons why the loan 
632
C<$needsconfirmation> a reference to a hash. It contains reasons why the loan
633
could be prevented, but ones that can be overriden by the operator.
633
could be prevented, but ones that can be overriden by the operator.
634
634
635
Possible values are :
635
Possible values are :
Lines 673-679 sub CanBookBeIssued { Link Here
673
    my $item = GetItem(GetItemnumberFromBarcode( $barcode ));
673
    my $item = GetItem(GetItemnumberFromBarcode( $barcode ));
674
    my $issue = GetItemIssue($item->{itemnumber});
674
    my $issue = GetItemIssue($item->{itemnumber});
675
	my $biblioitem = GetBiblioItemData($item->{biblioitemnumber});
675
	my $biblioitem = GetBiblioItemData($item->{biblioitemnumber});
676
	$item->{'itemtype'}=$item->{'itype'}; 
676
	$item->{'itemtype'}=$item->{'itype'};
677
    my $dbh             = C4::Context->dbh;
677
    my $dbh             = C4::Context->dbh;
678
678
679
    # MANDATORY CHECKS - unless item exists, nothing else matters
679
    # MANDATORY CHECKS - unless item exists, nothing else matters
Lines 712-718 sub CanBookBeIssued { Link Here
712
    #
712
    #
713
    # BORROWER STATUS
713
    # BORROWER STATUS
714
    #
714
    #
715
    if ( $borrower->{'category_type'} eq 'X' && (  $item->{barcode}  )) { 
715
    if ( $borrower->{'category_type'} eq 'X' && (  $item->{barcode}  )) {
716
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
716
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
717
        &UpdateStats({
717
        &UpdateStats({
718
                     branch => C4::Context->userenv->{'branch'},
718
                     branch => C4::Context->userenv->{'branch'},
Lines 1203-1209 sub checkHighHolds { Link Here
1203
1203
1204
        my $issuedate = DateTime->now( time_zone => C4::Context->tz() );
1204
        my $issuedate = DateTime->now( time_zone => C4::Context->tz() );
1205
1205
1206
        my $calendar = Koha::Calendar->new( branchcode => $branch );
1206
        my $calendar = Koha::DiscreteCalendar->new( branchcode => $branch );
1207
1207
1208
        my $itype =
1208
        my $itype =
1209
          ( C4::Context->preference('item-level_itypes') )
1209
          ( C4::Context->preference('item-level_itypes') )
Lines 1333-1339 sub AddIssue { Link Here
1333
            if ($datesent) {
1333
            if ($datesent) {
1334
                # updating line of branchtranfert to finish it, and changing the to branch value, implement a comment for visibility of this case (maybe for stats ....)
1334
                # updating line of branchtranfert to finish it, and changing the to branch value, implement a comment for visibility of this case (maybe for stats ....)
1335
                my $sth = $dbh->prepare(
1335
                my $sth = $dbh->prepare(
1336
                    "UPDATE branchtransfers 
1336
                    "UPDATE branchtransfers
1337
                        SET datearrived = now(),
1337
                        SET datearrived = now(),
1338
                        tobranch = ?,
1338
                        tobranch = ?,
1339
                        comments = 'Forced branchtransfer'
1339
                        comments = 'Forced branchtransfer'
Lines 1573-1579 sub GetHardDueDate { Link Here
1573
  my $branch_cat_rule = GetBranchBorrowerCircRule($branchcode, $categorycode);
1573
  my $branch_cat_rule = GetBranchBorrowerCircRule($branchcode, $categorycode);
1574
1574
1575
Retrieves circulation rule attributes that apply to the given
1575
Retrieves circulation rule attributes that apply to the given
1576
branch and patron category, regardless of item type.  
1576
branch and patron category, regardless of item type.
1577
The return value is a hashref containing the following key:
1577
The return value is a hashref containing the following key:
1578
1578
1579
maxissueqty - maximum number of loans that a
1579
maxissueqty - maximum number of loans that a
Lines 1585-1595 patron of the given category can have at the given Link Here
1585
branch.  If the value is undef, no limit.
1585
branch.  If the value is undef, no limit.
1586
1586
1587
This will first check for a specific branch and
1587
This will first check for a specific branch and
1588
category match from branch_borrower_circ_rules. 
1588
category match from branch_borrower_circ_rules.
1589
1589
1590
If no rule is found, it will then check default_branch_circ_rules
1590
If no rule is found, it will then check default_branch_circ_rules
1591
(same branch, default category).  If no rule is found,
1591
(same branch, default category).  If no rule is found,
1592
it will then check default_borrower_circ_rules (default 
1592
it will then check default_borrower_circ_rules (default
1593
branch, same category), then failing that, default_circ_rules
1593
branch, same category), then failing that, default_circ_rules
1594
(default branch, default category).
1594
(default branch, default category).
1595
1595
Lines 1710-1716 sub GetBranchItemRule { Link Here
1710
        $result->{'hold_fulfillment_policy'} = $search_result->{'hold_fulfillment_policy'} unless ( defined $result->{'hold_fulfillment_policy'} );
1710
        $result->{'hold_fulfillment_policy'} = $search_result->{'hold_fulfillment_policy'} unless ( defined $result->{'hold_fulfillment_policy'} );
1711
        $result->{'returnbranch'} = $search_result->{'returnbranch'} unless ( defined $result->{'returnbranch'} );
1711
        $result->{'returnbranch'} = $search_result->{'returnbranch'} unless ( defined $result->{'returnbranch'} );
1712
    }
1712
    }
1713
    
1713
1714
    # built-in default circulation rule
1714
    # built-in default circulation rule
1715
    $result->{'holdallowed'} = 2 unless ( defined $result->{'holdallowed'} );
1715
    $result->{'holdallowed'} = 2 unless ( defined $result->{'holdallowed'} );
1716
    $result->{'hold_fulfillment_policy'} = 'any' unless ( defined $result->{'hold_fulfillment_policy'} );
1716
    $result->{'hold_fulfillment_policy'} = 'any' unless ( defined $result->{'hold_fulfillment_policy'} );
Lines 2011-2017 sub AddReturn { Link Here
2011
    if ($borrowernumber) {
2011
    if ($borrowernumber) {
2012
        my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox);
2012
        my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox);
2013
        defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!";  # zero is OK, check defined
2013
        defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!";  # zero is OK, check defined
2014
        
2014
2015
        if ( $issue->{overdue} && $issue->{date_due} ) {
2015
        if ( $issue->{overdue} && $issue->{date_due} ) {
2016
        # fix fine days
2016
        # fix fine days
2017
            $today = $dropboxdate if $dropbox;
2017
            $today = $dropboxdate if $dropbox;
Lines 2072-2081 sub AddReturn { Link Here
2072
            branch   => $branch,
2072
            branch   => $branch,
2073
        });
2073
        });
2074
    }
2074
    }
2075
    
2075
2076
    logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'})
2076
    logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'})
2077
        if C4::Context->preference("ReturnLog");
2077
        if C4::Context->preference("ReturnLog");
2078
    
2078
2079
    # Remove any OVERDUES related debarment if the borrower has no overdues
2079
    # Remove any OVERDUES related debarment if the borrower has no overdues
2080
    if ( $borrowernumber
2080
    if ( $borrowernumber
2081
      && $borrower->{'debarred'}
2081
      && $borrower->{'debarred'}
Lines 2112-2118 Unconditionally marks an issue as being returned by Link Here
2112
moving the C<issues> row to C<old_issues> and
2112
moving the C<issues> row to C<old_issues> and
2113
setting C<returndate> to the current date, or
2113
setting C<returndate> to the current date, or
2114
the last non-holiday date of the branccode specified in
2114
the last non-holiday date of the branccode specified in
2115
C<dropbox_branch> .  Assumes you've already checked that 
2115
C<dropbox_branch> .  Assumes you've already checked that
2116
it's safe to do this, i.e. last non-holiday > issuedate.
2116
it's safe to do this, i.e. last non-holiday > issuedate.
2117
2117
2118
if C<$returndate> is specified (in iso format), it is used as the date
2118
if C<$returndate> is specified (in iso format), it is used as the date
Lines 2122-2128 C<$privacy> contains the privacy parameter. If the patron has set privacy to 2, Link Here
2122
the old_issue is immediately anonymised
2122
the old_issue is immediately anonymised
2123
2123
2124
Ideally, this function would be internal to C<C4::Circulation>,
2124
Ideally, this function would be internal to C<C4::Circulation>,
2125
not exported, but it is currently needed by one 
2125
not exported, but it is currently needed by one
2126
routine in C<C4::Accounts>.
2126
routine in C<C4::Accounts>.
2127
2127
2128
=cut
2128
=cut
Lines 2144-2150 sub MarkIssueReturned { Link Here
2144
    my $query = 'UPDATE issues SET returndate=';
2144
    my $query = 'UPDATE issues SET returndate=';
2145
    my @bind;
2145
    my @bind;
2146
    if ($dropbox_branch) {
2146
    if ($dropbox_branch) {
2147
        my $calendar = Koha::Calendar->new( branchcode => $dropbox_branch );
2147
        my $calendar = Koha::DiscreteCalendar->new( branchcode => $dropbox_branch );
2148
        my $dropboxdate = $calendar->addDate( DateTime->now( time_zone => C4::Context->tz), -1 );
2148
        my $dropboxdate = $calendar->addDate( DateTime->now( time_zone => C4::Context->tz), -1 );
2149
        $query .= ' ? ';
2149
        $query .= ' ? ';
2150
        push @bind, $dropboxdate->strftime('%Y-%m-%d %H:%M');
2150
        push @bind, $dropboxdate->strftime('%Y-%m-%d %H:%M');
Lines 2271-2277 C<$brn> borrowernumber Link Here
2271
2271
2272
C<$itm> itemnumber
2272
C<$itm> itemnumber
2273
2273
2274
C<$exemptfine> BOOL -- remove overdue charge associated with this issue. 
2274
C<$exemptfine> BOOL -- remove overdue charge associated with this issue.
2275
C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue.
2275
C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue.
2276
2276
2277
Internal function, called only by AddReturn
2277
Internal function, called only by AddReturn
Lines 2418-2424 sub _FixAccountForLostAndReturned { Link Here
2418
2418
2419
   my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower);
2419
   my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower);
2420
2420
2421
Internal function : 
2421
Internal function :
2422
2422
2423
Return the library code to be used to determine which circulation
2423
Return the library code to be used to determine which circulation
2424
policy applies to a transaction.  Looks up the CircControl and
2424
policy applies to a transaction.  Looks up the CircControl and
Lines 2505-2511 Returns a hashref Link Here
2505
sub GetOpenIssue {
2505
sub GetOpenIssue {
2506
  my ( $itemnumber ) = @_;
2506
  my ( $itemnumber ) = @_;
2507
  return unless $itemnumber;
2507
  return unless $itemnumber;
2508
  my $dbh = C4::Context->dbh;  
2508
  my $dbh = C4::Context->dbh;
2509
  my $sth = $dbh->prepare( "SELECT * FROM issues WHERE itemnumber = ? AND returndate IS NULL" );
2509
  my $sth = $dbh->prepare( "SELECT * FROM issues WHERE itemnumber = ? AND returndate IS NULL" );
2510
  $sth->execute( $itemnumber );
2510
  $sth->execute( $itemnumber );
2511
  return $sth->fetchrow_hashref();
2511
  return $sth->fetchrow_hashref();
Lines 2570-2576 sub GetUpcomingDueIssues { Link Here
2570
2570
2571
    my $statement = <<END_SQL;
2571
    my $statement = <<END_SQL;
2572
SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
2572
SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
2573
FROM issues 
2573
FROM issues
2574
LEFT JOIN items USING (itemnumber)
2574
LEFT JOIN items USING (itemnumber)
2575
LEFT OUTER JOIN branches USING (branchcode)
2575
LEFT OUTER JOIN branches USING (branchcode)
2576
WHERE returndate is NULL
2576
WHERE returndate is NULL
Lines 2578-2584 HAVING days_until_due >= 0 AND days_until_due <= ? Link Here
2578
END_SQL
2578
END_SQL
2579
2579
2580
    my @bind_parameters = ( $params->{'days_in_advance'} );
2580
    my @bind_parameters = ( $params->{'days_in_advance'} );
2581
    
2581
2582
    my $sth = $dbh->prepare( $statement );
2582
    my $sth = $dbh->prepare( $statement );
2583
    $sth->execute( @bind_parameters );
2583
    $sth->execute( @bind_parameters );
2584
    my $upcoming_dues = $sth->fetchall_arrayref({});
2584
    my $upcoming_dues = $sth->fetchall_arrayref({});
Lines 2844-2850 sub AddRenewal { Link Here
2844
    # of how many times it has been renewed.
2844
    # of how many times it has been renewed.
2845
    my $renews = $issuedata->{'renewals'} + 1;
2845
    my $renews = $issuedata->{'renewals'} + 1;
2846
    my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ?
2846
    my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ?
2847
                            WHERE borrowernumber=? 
2847
                            WHERE borrowernumber=?
2848
                            AND itemnumber=?"
2848
                            AND itemnumber=?"
2849
    );
2849
    );
2850
2850
Lines 2860-2866 sub AddRenewal { Link Here
2860
        my $accountno = getnextacctno( $borrowernumber );
2860
        my $accountno = getnextacctno( $borrowernumber );
2861
        my $item = GetBiblioFromItemNumber($itemnumber);
2861
        my $item = GetBiblioFromItemNumber($itemnumber);
2862
        my $manager_id = 0;
2862
        my $manager_id = 0;
2863
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2863
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
2864
        $sth = $dbh->prepare(
2864
        $sth = $dbh->prepare(
2865
                "INSERT INTO accountlines
2865
                "INSERT INTO accountlines
2866
                    (date, borrowernumber, accountno, amount, manager_id,
2866
                    (date, borrowernumber, accountno, amount, manager_id,
Lines 2929-2935 sub GetRenewCount { Link Here
2929
    my $renewsleft    = 0;
2929
    my $renewsleft    = 0;
2930
2930
2931
    my $borrower = C4::Members::GetMember( borrowernumber => $bornum);
2931
    my $borrower = C4::Members::GetMember( borrowernumber => $bornum);
2932
    my $item     = GetItem($itemno); 
2932
    my $item     = GetItem($itemno);
2933
2933
2934
    # Look in the issues table for this item, lent to this borrower,
2934
    # Look in the issues table for this item, lent to this borrower,
2935
    # and not yet returned.
2935
    # and not yet returned.
Lines 3409-3421 sub SendCirculationAlert { Link Here
3409
3409
3410
  $items = updateWrongTransfer($itemNumber,$borrowernumber,$waitingAtLibrary,$FromLibrary);
3410
  $items = updateWrongTransfer($itemNumber,$borrowernumber,$waitingAtLibrary,$FromLibrary);
3411
3411
3412
This function validate the line of brachtransfer but with the wrong destination (mistake from a librarian ...), and create a new line in branchtransfer from the actual library to the original library of reservation 
3412
This function validate the line of brachtransfer but with the wrong destination (mistake from a librarian ...), and create a new line in branchtransfer from the actual library to the original library of reservation
3413
3413
3414
=cut
3414
=cut
3415
3415
3416
sub updateWrongTransfer {
3416
sub updateWrongTransfer {
3417
	my ( $itemNumber,$waitingAtLibrary,$FromLibrary ) = @_;
3417
	my ( $itemNumber,$waitingAtLibrary,$FromLibrary ) = @_;
3418
	my $dbh = C4::Context->dbh;	
3418
	my $dbh = C4::Context->dbh;
3419
# first step validate the actual line of transfert .
3419
# first step validate the actual line of transfert .
3420
	my $sth =
3420
	my $sth =
3421
        	$dbh->prepare(
3421
        	$dbh->prepare(
Lines 3502-3508 sub CalcDateDue { Link Here
3502
        else { # days
3502
        else { # days
3503
            $dur = DateTime::Duration->new( days => $loanlength->{$length_key});
3503
            $dur = DateTime::Duration->new( days => $loanlength->{$length_key});
3504
        }
3504
        }
3505
        my $calendar = Koha::Calendar->new( branchcode => $branch );
3505
        my $calendar = Koha::DiscreteCalendar->new( branchcode => $branch );
3506
        $datedue = $calendar->addDate( $datedue, $dur, $loanlength->{lengthunit} );
3506
        $datedue = $calendar->addDate( $datedue, $dur, $loanlength->{lengthunit} );
3507
        if ($loanlength->{lengthunit} eq 'days') {
3507
        if ($loanlength->{lengthunit} eq 'days') {
3508
            $datedue->set_hour(23);
3508
            $datedue->set_hour(23);
Lines 3549-3556 sub CalcDateDue { Link Here
3549
sub CheckValidBarcode{
3549
sub CheckValidBarcode{
3550
my ($barcode) = @_;
3550
my ($barcode) = @_;
3551
my $dbh = C4::Context->dbh;
3551
my $dbh = C4::Context->dbh;
3552
my $query=qq|SELECT count(*) 
3552
my $query=qq|SELECT count(*)
3553
	     FROM items 
3553
	     FROM items
3554
             WHERE barcode=?
3554
             WHERE barcode=?
3555
	    |;
3555
	    |;
3556
my $sth = $dbh->prepare($query);
3556
my $sth = $dbh->prepare($query);
Lines 3571-3591 sub IsBranchTransferAllowed { Link Here
3571
	my ( $toBranch, $fromBranch, $code ) = @_;
3571
	my ( $toBranch, $fromBranch, $code ) = @_;
3572
3572
3573
	if ( $toBranch eq $fromBranch ) { return 1; } ## Short circuit for speed.
3573
	if ( $toBranch eq $fromBranch ) { return 1; } ## Short circuit for speed.
3574
        
3574
3575
	my $limitType = C4::Context->preference("BranchTransferLimitsType");   
3575
	my $limitType = C4::Context->preference("BranchTransferLimitsType");
3576
	my $dbh = C4::Context->dbh;
3576
	my $dbh = C4::Context->dbh;
3577
            
3577
3578
	my $sth = $dbh->prepare("SELECT * FROM branch_transfer_limits WHERE toBranch = ? AND fromBranch = ? AND $limitType = ?");
3578
	my $sth = $dbh->prepare("SELECT * FROM branch_transfer_limits WHERE toBranch = ? AND fromBranch = ? AND $limitType = ?");
3579
	$sth->execute( $toBranch, $fromBranch, $code );
3579
	$sth->execute( $toBranch, $fromBranch, $code );
3580
	my $limit = $sth->fetchrow_hashref();
3580
	my $limit = $sth->fetchrow_hashref();
3581
                        
3581
3582
	## If a row is found, then that combination is not allowed, if no matching row is found, then the combination *is allowed*
3582
	## If a row is found, then that combination is not allowed, if no matching row is found, then the combination *is allowed*
3583
	if ( $limit->{'limitId'} ) {
3583
	if ( $limit->{'limitId'} ) {
3584
		return 0;
3584
		return 0;
3585
	} else {
3585
	} else {
3586
		return 1;
3586
		return 1;
3587
	}
3587
	}
3588
}                                                        
3588
}
3589
3589
3590
=head2 CreateBranchTransferLimit
3590
=head2 CreateBranchTransferLimit
3591
3591
Lines 3599-3607 sub CreateBranchTransferLimit { Link Here
3599
   my ( $toBranch, $fromBranch, $code ) = @_;
3599
   my ( $toBranch, $fromBranch, $code ) = @_;
3600
   return unless defined($toBranch) && defined($fromBranch);
3600
   return unless defined($toBranch) && defined($fromBranch);
3601
   my $limitType = C4::Context->preference("BranchTransferLimitsType");
3601
   my $limitType = C4::Context->preference("BranchTransferLimitsType");
3602
   
3602
3603
   my $dbh = C4::Context->dbh;
3603
   my $dbh = C4::Context->dbh;
3604
   
3604
3605
   my $sth = $dbh->prepare("INSERT INTO branch_transfer_limits ( $limitType, toBranch, fromBranch ) VALUES ( ?, ?, ? )");
3605
   my $sth = $dbh->prepare("INSERT INTO branch_transfer_limits ( $limitType, toBranch, fromBranch ) VALUES ( ?, ?, ? )");
3606
   return $sth->execute( $code, $toBranch, $fromBranch );
3606
   return $sth->execute( $code, $toBranch, $fromBranch );
3607
}
3607
}
Lines 3642-3650 sub LostItem{ Link Here
3642
    my ($itemnumber, $mark_returned) = @_;
3642
    my ($itemnumber, $mark_returned) = @_;
3643
3643
3644
    my $dbh = C4::Context->dbh();
3644
    my $dbh = C4::Context->dbh();
3645
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title 
3645
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title
3646
                           FROM issues 
3646
                           FROM issues
3647
                           JOIN items USING (itemnumber) 
3647
                           JOIN items USING (itemnumber)
3648
                           JOIN biblio USING (biblionumber)
3648
                           JOIN biblio USING (biblionumber)
3649
                           WHERE issues.itemnumber=?");
3649
                           WHERE issues.itemnumber=?");
3650
    $sth->execute($itemnumber);
3650
    $sth->execute($itemnumber);
(-)a/C4/HoldsQueue.pm (-4 / +4 lines)
Lines 29-35 use C4::Circulation; Link Here
29
use C4::Members;
29
use C4::Members;
30
use C4::Biblio;
30
use C4::Biblio;
31
use Koha::DateUtils;
31
use Koha::DateUtils;
32
32
use Koha::DiscreteCalendar;
33
use List::Util qw(shuffle);
33
use List::Util qw(shuffle);
34
use List::MoreUtils qw(any);
34
use List::MoreUtils qw(any);
35
use Data::Dumper;
35
use Data::Dumper;
Lines 76-82 sub TransportCostMatrix { Link Here
76
        };
76
        };
77
77
78
        if ( C4::Context->preference("HoldsQueueSkipClosed") ) {
78
        if ( C4::Context->preference("HoldsQueueSkipClosed") ) {
79
            $calendars->{$from} ||= Koha::Calendar->new( branchcode => $from );
79
            $calendars->{$from} ||= Koha::DiscreteCalendar->new( branchcode => $from );
80
            $transport_cost_matrix{$to}{$from}{disable_transfer} ||=
80
            $transport_cost_matrix{$to}{$from}{disable_transfer} ||=
81
              $calendars->{$from}->is_holiday( $today );
81
              $calendars->{$from}->is_holiday( $today );
82
        }
82
        }
Lines 205-211 sub CreateQueue { Link Here
205
        $total_requests        += scalar(@$hold_requests);
205
        $total_requests        += scalar(@$hold_requests);
206
        $total_available_items += scalar(@$available_items);
206
        $total_available_items += scalar(@$available_items);
207
207
208
        my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
208
       my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix);
209
        $item_map  or next;
209
        $item_map  or next;
210
        my $item_map_size = scalar(keys %$item_map)
210
        my $item_map_size = scalar(keys %$item_map)
211
          or next;
211
          or next;
Lines 736-742 sub load_branches_to_pull_from { Link Here
736
    my $today = dt_from_string();
736
    my $today = dt_from_string();
737
    if ( C4::Context->preference('HoldsQueueSkipClosed') ) {
737
    if ( C4::Context->preference('HoldsQueueSkipClosed') ) {
738
        @branches_to_use = grep {
738
        @branches_to_use = grep {
739
            !Koha::Calendar->new( branchcode => $_ )
739
            !Koha::DiscreteCalendar->new( branchcode => $_ )
740
              ->is_holiday( $today )
740
              ->is_holiday( $today )
741
        } @branches_to_use;
741
        } @branches_to_use;
742
    }
742
    }
(-)a/C4/Overdues.pm (-2 / +3 lines)
Lines 34-39 use C4::Accounts; Link Here
34
use C4::Log; # logaction
34
use C4::Log; # logaction
35
use C4::Debug;
35
use C4::Debug;
36
use Koha::DateUtils;
36
use Koha::DateUtils;
37
use Koha::DiscreteCalendar;
37
use Koha::Account::Line;
38
use Koha::Account::Line;
38
use Koha::Account::Lines;
39
use Koha::Account::Lines;
39
use Koha::IssuingRules;
40
use Koha::IssuingRules;
Lines 298-304 sub get_chargeable_units { Link Here
298
    my $charge_duration;
299
    my $charge_duration;
299
    if ($unit eq 'hours') {
300
    if ($unit eq 'hours') {
300
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
301
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
301
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
302
            my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode );
302
            $charge_duration = $calendar->hours_between( $date_due, $date_returned );
303
            $charge_duration = $calendar->hours_between( $date_due, $date_returned );
303
        } else {
304
        } else {
304
            $charge_duration = $date_returned->delta_ms( $date_due );
305
            $charge_duration = $date_returned->delta_ms( $date_due );
Lines 310-316 sub get_chargeable_units { Link Here
310
    }
311
    }
311
    else { # days
312
    else { # days
312
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
313
        if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
313
            my $calendar = Koha::Calendar->new( branchcode => $branchcode );
314
            my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode );
314
            $charge_duration = $calendar->days_between( $date_due, $date_returned );
315
            $charge_duration = $calendar->days_between( $date_due, $date_returned );
315
        } else {
316
        } else {
316
            $charge_duration = $date_returned->delta_days( $date_due );
317
            $charge_duration = $date_returned->delta_days( $date_due );
(-)a/C4/Reserves.pm (-2 / +2 lines)
Lines 37-43 use C4::Letters; Link Here
37
use C4::Log;
37
use C4::Log;
38
38
39
use Koha::DateUtils;
39
use Koha::DateUtils;
40
use Koha::Calendar;
40
use Koha::DiscreteCalendar;
41
use Koha::Database;
41
use Koha::Database;
42
use Koha::Hold;
42
use Koha::Hold;
43
use Koha::Old::Hold;
43
use Koha::Old::Hold;
Lines 1031-1037 sub CancelExpiredReserves { Link Here
1031
        while ( my $res = $sth->fetchrow_hashref ) {
1031
        while ( my $res = $sth->fetchrow_hashref ) {
1032
            my $do_cancel = 1;
1032
            my $do_cancel = 1;
1033
            unless ( $cancel_on_holidays ) {
1033
            unless ( $cancel_on_holidays ) {
1034
                my $calendar = Koha::Calendar->new( branchcode => $res->{'branchcode'} );
1034
                my $calendar = Koha::DiscreteCalendar->new( branchcode => $res->{'branchcode'} );
1035
                my $is_holiday = $calendar->is_holiday( $today );
1035
                my $is_holiday = $calendar->is_holiday( $today );
1036
1036
1037
                if ( $is_holiday ) {
1037
                if ( $is_holiday ) {
(-)a/circ/returns.pl (-2 / +2 lines)
Lines 49-55 use C4::Koha; # FIXME : is it still useful ? Link Here
49
use C4::RotatingCollections;
49
use C4::RotatingCollections;
50
use Koha::AuthorisedValues;
50
use Koha::AuthorisedValues;
51
use Koha::DateUtils;
51
use Koha::DateUtils;
52
use Koha::Calendar;
52
use Koha::DiscreteCalendar;
53
use Koha::Checkouts;
53
use Koha::Checkouts;
54
54
55
my $query = new CGI;
55
my $query = new CGI;
Lines 202-208 my $dropboxmode = $query->param('dropboxmode'); Link Here
202
my $dotransfer  = $query->param('dotransfer');
202
my $dotransfer  = $query->param('dotransfer');
203
my $canceltransfer = $query->param('canceltransfer');
203
my $canceltransfer = $query->param('canceltransfer');
204
my $dest = $query->param('dest');
204
my $dest = $query->param('dest');
205
my $calendar    = Koha::Calendar->new( branchcode => $userenv_branch );
205
my $calendar    = Koha::DiscreteCalendar->new( branchcode => $userenv_branch );
206
#dropbox: get last open day (today - 1)
206
#dropbox: get last open day (today - 1)
207
my $today       = DateTime->now( time_zone => C4::Context->tz());
207
my $today       = DateTime->now( time_zone => C4::Context->tz());
208
my $dropboxdate = $calendar->addDate($today, -1);
208
my $dropboxdate = $calendar->addDate($today, -1);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt (+5 lines)
Lines 74-79 Link Here
74
    <dd>Define days when the library is closed</dd>
74
    <dd>Define days when the library is closed</dd>
75
    [% END %]
75
    [% END %]
76
76
77
    [% IF ( CAN_user_tools_edit_calendar ) %]
78
    <dt><a href="/cgi-bin/koha/tools/discrete_calendar.pl">Discrete Calendar</a></dt>
79
    <dd>Define days when the library is closed</dd>
80
    [% END %]
81
77
    [% IF ( CAN_user_tools_manage_csv_profiles ) %]
82
    [% IF ( CAN_user_tools_manage_csv_profiles ) %]
78
    <dt><a href="/cgi-bin/koha/tools/csv-profiles.pl">CSV profiles</a></dt>
83
    <dt><a href="/cgi-bin/koha/tools/csv-profiles.pl">CSV profiles</a></dt>
79
	<dd>Manage CSV export profiles</dd>
84
	<dd>Manage CSV export profiles</dd>
(-)a/misc/cronjobs/fines.pl (-2 / +2 lines)
Lines 36-42 use Getopt::Long; Link Here
36
use Carp;
36
use Carp;
37
use File::Spec;
37
use File::Spec;
38
38
39
use Koha::Calendar;
39
use Koha::DiscreteCalendar;
40
use Koha::DateUtils;
40
use Koha::DateUtils;
41
use C4::Log;
41
use C4::Log;
42
42
Lines 176-182 EOM Link Here
176
sub set_holiday {
176
sub set_holiday {
177
    my ( $branch, $dt ) = @_;
177
    my ( $branch, $dt ) = @_;
178
178
179
    my $calendar = Koha::Calendar->new( branchcode => $branch );
179
    my $calendar = Koha::DiscreteCalendar->new( branchcode => $branch );
180
    return $calendar->is_holiday($dt);
180
    return $calendar->is_holiday($dt);
181
}
181
}
182
182
(-)a/misc/cronjobs/overdue_notices.pl (-4 / +4 lines)
Lines 40-46 use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes parse_overdues_lette Link Here
40
use C4::Log;
40
use C4::Log;
41
use Koha::Patron::Debarments qw(AddUniqueDebarment);
41
use Koha::Patron::Debarments qw(AddUniqueDebarment);
42
use Koha::DateUtils;
42
use Koha::DateUtils;
43
use Koha::Calendar;
43
use Koha::DiscreteCalendar;
44
use Koha::Libraries;
44
use Koha::Libraries;
45
use Koha::Acquisition::Currencies;
45
use Koha::Acquisition::Currencies;
46
46
Lines 444-450 elsif ( defined $text_filename ) { Link Here
444
444
445
foreach my $branchcode (@branches) {
445
foreach my $branchcode (@branches) {
446
    if ( C4::Context->preference('OverdueNoticeCalendar') ) {
446
    if ( C4::Context->preference('OverdueNoticeCalendar') ) {
447
        my $calendar = Koha::Calendar->new( branchcode => $branchcode );
447
        my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode );
448
        if ( $calendar->is_holiday($date_to_run) ) {
448
        if ( $calendar->is_holiday($date_to_run) ) {
449
            next;
449
            next;
450
        }
450
        }
Lines 543-549 END_SQL Link Here
543
                if ( C4::Context->preference('OverdueNoticeCalendar') )
543
                if ( C4::Context->preference('OverdueNoticeCalendar') )
544
                {
544
                {
545
                    my $calendar =
545
                    my $calendar =
546
                      Koha::Calendar->new( branchcode => $branchcode );
546
                      Koha::DiscreteCalendar->new( branchcode => $branchcode );
547
                    $days_between =
547
                    $days_between =
548
                      $calendar->days_between( dt_from_string($data->{date_due}),
548
                      $calendar->days_between( dt_from_string($data->{date_due}),
549
                        $date_to_run );
549
                        $date_to_run );
Lines 627-633 END_SQL Link Here
627
                while ( my $item_info = $sth2->fetchrow_hashref() ) {
627
                while ( my $item_info = $sth2->fetchrow_hashref() ) {
628
                    if ( C4::Context->preference('OverdueNoticeCalendar') ) {
628
                    if ( C4::Context->preference('OverdueNoticeCalendar') ) {
629
                        my $calendar =
629
                        my $calendar =
630
                          Koha::Calendar->new( branchcode => $branchcode );
630
                          Koha::DiscreteCalendar->new( branchcode => $branchcode );
631
                        $days_between =
631
                        $days_between =
632
                          $calendar->days_between(
632
                          $calendar->days_between(
633
                            dt_from_string( $item_info->{date_due} ), $date_to_run );
633
                            dt_from_string( $item_info->{date_due} ), $date_to_run );
(-)a/misc/cronjobs/staticfines.pl (-2 / +2 lines)
Lines 40-46 use Date::Calc qw/Date_to_Days/; Link Here
40
use C4::Context;
40
use C4::Context;
41
use C4::Circulation;
41
use C4::Circulation;
42
use C4::Overdues;
42
use C4::Overdues;
43
use C4::Calendar qw();    # don't need any exports from Calendar
43
use C4::DiscreteCalendar qw();    # don't need any exports from Calendar
44
use C4::Biblio;
44
use C4::Biblio;
45
use C4::Debug;            # supplying $debug and $cgi_debug
45
use C4::Debug;            # supplying $debug and $cgi_debug
46
use C4::Log;
46
use C4::Log;
Lines 176-182 for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { Link Here
176
176
177
    my $calendar;
177
    my $calendar;
178
    unless ( defined( $calendars{$branchcode} ) ) {
178
    unless ( defined( $calendars{$branchcode} ) ) {
179
        $calendars{$branchcode} = C4::Calendar->new( branchcode => $branchcode );
179
        $calendars{$branchcode} = C4::DiscreteCalendar->new( branchcode => $branchcode );
180
    }
180
    }
181
    $calendar = $calendars{$branchcode};
181
    $calendar = $calendars{$branchcode};
182
    my $isHoliday = $calendar->isHoliday( $tday, $tmonth, $tyear );
182
    my $isHoliday = $calendar->isHoliday( $tday, $tmonth, $tyear );
(-)a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl (-3 / +2 lines)
Lines 35-41 use C4::Context; Link Here
35
use C4::Items;
35
use C4::Items;
36
use C4::Letters;
36
use C4::Letters;
37
use C4::Overdues;
37
use C4::Overdues;
38
use Koha::Calendar;
38
use Koha::DiscreteCalendar;
39
use Koha::DateUtils;
39
use Koha::DateUtils;
40
40
41
sub usage {
41
sub usage {
Lines 291-297 sub GetWaitingHolds { Link Here
291
    $sth->execute();
291
    $sth->execute();
292
    my @results;
292
    my @results;
293
    while ( my $issue = $sth->fetchrow_hashref() ) {
293
    while ( my $issue = $sth->fetchrow_hashref() ) {
294
        my $calendar = Koha::Calendar->new( branchcode => $issue->{'site'} );
294
        my $calendar = Koha::DiscreteCalendar->new( branchcode => $issue->{'site'} );
295
295
296
        my $waiting_date = dt_from_string( $issue->{waitingdate}, 'sql' );
296
        my $waiting_date = dt_from_string( $issue->{waitingdate}, 'sql' );
297
        my $pickup_date = $waiting_date->clone->add( days => $pickupdelay );
297
        my $pickup_date = $waiting_date->clone->add( days => $pickupdelay );
298
- 

Return to bug 17015