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

(-)a/C4/Circulation.pm (-100 / +58 lines)
Lines 1294-1300 sub GetHardDueDate { Link Here
1294
1294
1295
FIXME - This is a copy-paste of GetLoanLength
1295
FIXME - This is a copy-paste of GetLoanLength
1296
as a stop-gap.  Do not wish to change API for GetLoanLength 
1296
as a stop-gap.  Do not wish to change API for GetLoanLength 
1297
this close to release, however, Overdues::GetIssuingRules is broken.
1297
this close to release.
1298
1298
1299
Get the issuing rule for an itemtype, a borrower type and a branch
1299
Get the issuing rule for an itemtype, a borrower type and a branch
1300
Returns a hashref from the issuingrules table.
1300
Returns a hashref from the issuingrules table.
Lines 2307-2371 sub CanBookBeRenewed { Link Here
2307
    my $dbh       = C4::Context->dbh;
2307
    my $dbh       = C4::Context->dbh;
2308
    my $renews    = 1;
2308
    my $renews    = 1;
2309
    my $renewokay = 0;
2309
    my $renewokay = 0;
2310
	my $error;
2310
    my $error;
2311
2311
2312
    # Look in the issues table for this item, lent to this borrower,
2312
    my $borrower    = C4::Members::GetMemberDetails( $borrowernumber, 0 )   or return;
2313
    # and not yet returned.
2313
    my $item        = GetItem($itemnumber)                                  or return;
2314
    my $itemissue   = GetItemIssue($itemnumber)                             or return;
2314
2315
2315
    # Look in the issues table for this item, lent to this borrower,
2316
    my $branchcode  = _GetCircControlBranch($item, $borrower);
2316
    # and not yet returned.
2317
    my %branch = (
2318
            'ItemHomeLibrary' => 'items.homebranch',
2319
            'PickupLibrary'   => 'items.holdingbranch',
2320
            'PatronLibrary'   => 'borrowers.branchcode'
2321
            );
2322
    my $controlbranch = $branch{C4::Context->preference('CircControl')};
2323
    my $itype         = C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype';
2324
    
2325
    my $sthcount = $dbh->prepare("
2326
                   SELECT 
2327
                    borrowers.categorycode, biblioitems.itemtype, issues.renewals, renewalsallowed, $controlbranch
2328
                   FROM  issuingrules, 
2329
                   issues
2330
                   LEFT JOIN items USING (itemnumber) 
2331
                   LEFT JOIN borrowers USING (borrowernumber) 
2332
                   LEFT JOIN biblioitems USING (biblioitemnumber)
2333
                   
2334
                   WHERE
2335
                    (issuingrules.categorycode = borrowers.categorycode OR issuingrules.categorycode = '*')
2336
                   AND
2337
                    (issuingrules.itemtype = $itype OR issuingrules.itemtype = '*')
2338
                   AND
2339
                    (issuingrules.branchcode = $controlbranch OR issuingrules.branchcode = '*') 
2340
                   AND 
2341
                    borrowernumber = ? 
2342
                   AND
2343
                    itemnumber = ?
2344
                   ORDER BY
2345
                    issuingrules.categorycode desc,
2346
                    issuingrules.itemtype desc,
2347
                    issuingrules.branchcode desc
2348
                   LIMIT 1;
2349
                  ");
2350
2351
    $sthcount->execute( $borrowernumber, $itemnumber );
2352
    if ( my $data1 = $sthcount->fetchrow_hashref ) {
2353
        
2354
        if ( ( $data1->{renewalsallowed} && $data1->{renewalsallowed} > $data1->{renewals} ) || $override_limit ) {
2355
            $renewokay = 1;
2356
        }
2357
        else {
2358
			$error="too_many";
2359
		}
2360
		
2361
        my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber);
2362
        if ($resfound) {
2363
            $renewokay = 0;
2364
			$error="on_reserve"
2365
        }
2366
2317
2318
    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
2319
2320
    if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) {
2321
        $renewokay = 1;
2322
    } else {
2323
        $error = "too_many";
2367
    }
2324
    }
2368
    return ($renewokay,$error);
2325
2326
    my ( $resfound, $resrec ) = C4::Reserves::CheckReserves($itemnumber);
2327
    if ( $resfound ) {
2328
        $renewokay = 0;
2329
        $error     = "on_reserve";
2330
    }
2331
2332
    return ( $renewokay, $error );
2369
}
2333
}
2370
2334
2371
=head2 AddRenewal
2335
=head2 AddRenewal
Lines 2876-2929 sub CalcDateDue { Link Here
2876
    my ( $startdate, $itemtype, $branch, $borrower ) = @_;
2840
    my ( $startdate, $itemtype, $branch, $borrower ) = @_;
2877
2841
2878
    # loanlength now a href
2842
    # loanlength now a href
2879
    my $loanlength =
2843
    my $issuingrule = GetIssuingRule( $borrower->{'categorycode'}, $itemtype, $branch );
2880
      GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch );
2844
    my $loanlength = $issuingrule->{renewalperiod}
2845
        ?
2846
            {
2847
                issuelength => $issuingrule->{renewalperiod},
2848
                lengthunit  => 'days',
2849
            }
2850
        : $issuingrule;
2881
2851
2882
    my $datedue;
2852
    my $datedue;
2883
2853
2884
    # if globalDueDate ON the datedue is set to that date
2854
    # calculate the datedue as normal
2885
    if (C4::Context->preference('globalDueDate')
2855
    if ( C4::Context->preference('useDaysMode') eq 'Days' )
2886
        && ( C4::Context->preference('globalDueDate') =~
2856
    {    # ignoring calendar
2887
            C4::Dates->regexp('syspref') )
2857
        my $dt =
2888
      ) {
2858
          DateTime->now( time_zone => C4::Context->tz() )
2889
        $datedue = dt_from_string(
2859
          ->truncate( to => 'minute' );
2890
            C4::Context->preference('globalDueDate'),
2860
        if ( $loanlength->{lengthunit} eq 'hours' ) {
2891
            C4::Context->preference('dateformat')
2861
            $dt->add( hours => $loanlength->{issuelength} );
2892
        );
2862
            return $dt;
2863
        } else {    # days
2864
            $dt->add( days => $loanlength->{issuelength} );
2865
            $dt->set_hour(23);
2866
            $dt->set_minute(59);
2867
            return $dt;
2868
        }
2893
    } else {
2869
    } else {
2894
2870
        my $dur;
2895
        # otherwise, calculate the datedue as normal
2871
        if ($loanlength->{lengthunit} eq 'hours') {
2896
        if ( C4::Context->preference('useDaysMode') eq 'Days' )
2872
            $dur = DateTime::Duration->new( hours => $loanlength->{issuelength});
2897
        {    # ignoring calendar
2873
        }
2898
            my $dt =
2874
        else { # days
2899
              DateTime->now( time_zone => C4::Context->tz() )
2875
            $dur = DateTime::Duration->new( days => $loanlength->{issuelength});
2900
              ->truncate( to => 'minute' );
2876
        }
2901
            if ( $loanlength->{lengthunit} eq 'hours' ) {
2877
        if (ref $startdate ne 'DateTime' ) {
2902
                $dt->add( hours => $loanlength->{issuelength} );
2878
            $startdate = dt_from_string($startdate);
2903
                return $dt;
2879
        }
2904
            } else {    # days
2880
        my $calendar = Koha::Calendar->new( branchcode => $branch );
2905
                $dt->add( days => $loanlength->{issuelength} );
2881
        $datedue = $calendar->addDate( $startdate, $dur, $loanlength->{lengthunit} );
2906
                $dt->set_hour(23);
2882
        if ($loanlength->{lengthunit} eq 'days') {
2907
                $dt->set_minute(59);
2883
            $datedue->set_hour(23);
2908
                return $dt;
2884
            $datedue->set_minute(59);
2909
            }
2910
        } else {
2911
            my $dur;
2912
            if ($loanlength->{lengthunit} eq 'hours') {
2913
                $dur = DateTime::Duration->new( hours => $loanlength->{issuelength});
2914
            }
2915
            else { # days
2916
                $dur = DateTime::Duration->new( days => $loanlength->{issuelength});
2917
            }
2918
            if (ref $startdate ne 'DateTime' ) {
2919
                $startdate = dt_from_string($startdate);
2920
            }
2921
            my $calendar = Koha::Calendar->new( branchcode => $branch );
2922
            $datedue = $calendar->addDate( $startdate, $dur, $loanlength->{lengthunit} );
2923
            if ($loanlength->{lengthunit} eq 'days') {
2924
                $datedue->set_hour(23);
2925
                $datedue->set_minute(59);
2926
            }
2927
        }
2885
        }
2928
    }
2886
    }
2929
2887
(-)a/C4/Overdues.pm (-39 lines)
Lines 72-81 BEGIN { Link Here
72
	push @EXPORT, qw(
72
	push @EXPORT, qw(
73
        &GetIssuesIteminfo
73
        &GetIssuesIteminfo
74
	);
74
	);
75
    #
76
	# &GetIssuingRules - delete.
77
	# use C4::Circulation::GetIssuingRule instead.
78
	
79
	# subs to move to Members.pm
75
	# subs to move to Members.pm
80
	push @EXPORT, qw(
76
	push @EXPORT, qw(
81
        &CheckBorrowerDebarred
77
        &CheckBorrowerDebarred
Lines 692-732 sub GetFine { Link Here
692
    return 0;
688
    return 0;
693
}
689
}
694
690
695
696
=head2 GetIssuingRules
697
698
FIXME - This sub should be deprecated and removed.
699
It ignores branch and defaults.
700
701
    $data = &GetIssuingRules($itemtype,$categorycode);
702
703
Looks up for all issuingrules an item info 
704
705
C<$itemnumber> is a reference-to-hash whose keys are all of the fields
706
from the borrowers and categories tables of the Koha database. Thus,
707
708
C<$categorycode> contains  information about borrowers category 
709
710
C<$data> contains all information about both the borrower and
711
category he or she belongs to.
712
=cut 
713
714
sub GetIssuingRules {
715
	warn "GetIssuingRules is deprecated: use GetIssuingRule from C4::Circulation instead.";
716
   my ($itemtype,$categorycode)=@_;
717
   my $dbh   = C4::Context->dbh();    
718
   my $query=qq|SELECT *
719
        FROM issuingrules
720
        WHERE issuingrules.itemtype=?
721
            AND issuingrules.categorycode=?
722
        |;
723
    my $sth = $dbh->prepare($query);
724
    #  print $query;
725
    $sth->execute($itemtype,$categorycode);
726
    return $sth->fetchrow_hashref;
727
}
728
729
730
sub ReplacementCost2 {
691
sub ReplacementCost2 {
731
    my ( $itemnum, $borrowernumber ) = @_;
692
    my ( $itemnum, $borrowernumber ) = @_;
732
    my $dbh   = C4::Context->dbh();
693
    my $dbh   = C4::Context->dbh();
(-)a/admin/smart-rules.pl (-4 / +5 lines)
Lines 101-108 elsif ($op eq 'delete-branch-item') { Link Here
101
# save the values entered
101
# save the values entered
102
elsif ($op eq 'add') {
102
elsif ($op eq 'add') {
103
    my $sth_search = $dbh->prepare('SELECT COUNT(*) AS total FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?');
103
    my $sth_search = $dbh->prepare('SELECT COUNT(*) AS total FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?');
104
    my $sth_insert = $dbh->prepare('INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, renewalsallowed, reservesallowed, issuelength, lengthunit, hardduedate, hardduedatecompare, fine, finedays, firstremind, chargeperiod,rentaldiscount, overduefinescap) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
104
    my $sth_insert = $dbh->prepare('INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, renewalsallowed, renewalperiod, reservesallowed, issuelength, lengthunit, hardduedate, hardduedatecompare, fine, finedays, firstremind, chargeperiod,rentaldiscount, overduefinescap) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
105
    my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, reservesallowed=?, issuelength=?, lengthunit = ?, hardduedate=?, hardduedatecompare=?, rentaldiscount=?, overduefinescap=?  WHERE branchcode=? AND categorycode=? AND itemtype=?");
105
    my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, renewalperiod=?, reservesallowed=?, issuelength=?, lengthunit = ?, hardduedate=?, hardduedatecompare=?, rentaldiscount=?, overduefinescap=?  WHERE branchcode=? AND categorycode=? AND itemtype=?");
106
    
106
    
107
    my $br = $branch; # branch
107
    my $br = $branch; # branch
108
    my $bor  = $input->param('categorycode'); # borrower category
108
    my $bor  = $input->param('categorycode'); # borrower category
Lines 113-118 elsif ($op eq 'add') { Link Here
113
    my $chargeperiod = $input->param('chargeperiod');
113
    my $chargeperiod = $input->param('chargeperiod');
114
    my $maxissueqty  = $input->param('maxissueqty');
114
    my $maxissueqty  = $input->param('maxissueqty');
115
    my $renewalsallowed  = $input->param('renewalsallowed');
115
    my $renewalsallowed  = $input->param('renewalsallowed');
116
    my $renewalperiod    = $input->param('renewalperiod');
116
    my $reservesallowed  = $input->param('reservesallowed');
117
    my $reservesallowed  = $input->param('reservesallowed');
117
    $maxissueqty =~ s/\s//g;
118
    $maxissueqty =~ s/\s//g;
118
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
119
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
Lines 128-136 elsif ($op eq 'add') { Link Here
128
    $sth_search->execute($br,$bor,$cat);
129
    $sth_search->execute($br,$bor,$cat);
129
    my $res = $sth_search->fetchrow_hashref();
130
    my $res = $sth_search->fetchrow_hashref();
130
    if ($res->{total}) {
131
    if ($res->{total}) {
131
        $sth_update->execute($fine, $finedays,$firstremind, $chargeperiod, $maxissueqty, $renewalsallowed,$reservesallowed, $issuelength,$lengthunit, $hardduedate,$hardduedatecompare,$rentaldiscount,$overduefinescap, $br,$bor,$cat);
132
        $sth_update->execute($fine, $finedays,$firstremind, $chargeperiod, $maxissueqty, $renewalsallowed, $renewalperiod, $reservesallowed, $issuelength,$lengthunit, $hardduedate,$hardduedatecompare,$rentaldiscount,$overduefinescap, $br,$bor,$cat);
132
    } else {
133
    } else {
133
        $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed,$reservesallowed,$issuelength,$lengthunit,$hardduedate,$hardduedatecompare,$fine,$finedays,$firstremind,$chargeperiod,$rentaldiscount,$overduefinescap);
134
        $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed, $renewalperiod, $reservesallowed,$issuelength,$lengthunit,$hardduedate,$hardduedatecompare,$fine,$finedays,$firstremind,$chargeperiod,$rentaldiscount,$overduefinescap);
134
    }
135
    }
135
} 
136
} 
136
elsif ($op eq "set-branch-defaults") {
137
elsif ($op eq "set-branch-defaults") {
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 998-1003 CREATE TABLE `issuingrules` ( -- circulation and fine rules Link Here
998
  `hardduedate` date default NULL, -- hard due date
998
  `hardduedate` date default NULL, -- hard due date
999
  `hardduedatecompare` tinyint NOT NULL default "0", -- type of hard due date (1 = after, 0 = on, -1 = before)
999
  `hardduedatecompare` tinyint NOT NULL default "0", -- type of hard due date (1 = after, 0 = on, -1 = before)
1000
  `renewalsallowed` smallint(6) NOT NULL default "0", -- how many renewals are allowed
1000
  `renewalsallowed` smallint(6) NOT NULL default "0", -- how many renewals are allowed
1001
  `renewalperiod` int(11) NOT NULL default 0 -- renewal period in days
1001
  `reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed
1002
  `reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed
1002
  `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
1003
  `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
1003
  overduefinescap decimal default NULL, -- the maximum amount of an overdue fine
1004
  overduefinescap decimal default NULL, -- the maximum amount of an overdue fine
(-)a/installer/data/mysql/updatedatabase.pl (+7 lines)
Lines 5696-5701 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
5696
    SetVersion($DBversion);
5696
    SetVersion($DBversion);
5697
}
5697
}
5698
5698
5699
$DBversion = '3.09.00.XXX';
5700
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
5701
    $dbh->do('ALTER TABLE issuingrules ADD COLUMN renewalperiod int(11) NOT NULL default 0 AFTER renewalsallowed');
5702
    print "Upgrade to $DBversion done (Add colum issuingrules.renewalperiod)\n";
5703
    SetVersion ($DBversion);
5704
}
5705
5699
=head1 FUNCTIONS
5706
=head1 FUNCTIONS
5700
5707
5701
=head2 TableExists($table)
5708
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (+3 lines)
Lines 75-80 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
75
                <th>Overdue Fines Cap ($)</th>
75
                <th>Overdue Fines Cap ($)</th>
76
                <th>Suspension in days (day)</th>
76
                <th>Suspension in days (day)</th>
77
                <th>Renewals allowed (count)</th>
77
                <th>Renewals allowed (count)</th>
78
                <th>Renewals period (days)</th>
78
                <th>Holds allowed (count)</th>
79
                <th>Holds allowed (count)</th>
79
		<th>Rental discount (%)</th>
80
		<th>Rental discount (%)</th>
80
				<th>&nbsp;</th>
81
				<th>&nbsp;</th>
Lines 120-125 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
120
                            <td>[% rule.overduefinescap FILTER format("%.2f") %]</td>
121
                            <td>[% rule.overduefinescap FILTER format("%.2f") %]</td>
121
							<td>[% rule.finedays %]</td>
122
							<td>[% rule.finedays %]</td>
122
							<td>[% rule.renewalsallowed %]</td>
123
							<td>[% rule.renewalsallowed %]</td>
124
                            <td>[% rule.renewalperiod %]</td>
123
							<td>[% rule.reservesallowed %]</td>
125
							<td>[% rule.reservesallowed %]</td>
124
							<td>[% rule.rentaldiscount %]</td>
126
							<td>[% rule.rentaldiscount %]</td>
125
							<td>
127
							<td>
Lines 166-171 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
166
                    <td><input name="overduefinescap" size="6" /> </td>
168
                    <td><input name="overduefinescap" size="6" /> </td>
167
                    <td><input name="finedays" size="3" /> </td>
169
                    <td><input name="finedays" size="3" /> </td>
168
                    <td><input name="renewalsallowed" size="2" /></td>
170
                    <td><input name="renewalsallowed" size="2" /></td>
171
                    <td><input name="renewalperiod" size="2" /></td>
169
                    <td><input name="reservesallowed" size="2" /></td>
172
                    <td><input name="reservesallowed" size="2" /></td>
170
		    <td><input name="rentaldiscount" size="2" /></td>
173
		    <td><input name="rentaldiscount" size="2" /></td>
171
                    <td><input type="hidden" name="branch" value="[% current_branch %]"/><input type="submit" value="Add" class="submit" /></td>
174
                    <td><input type="hidden" name="branch" value="[% current_branch %]"/><input type="submit" value="Add" class="submit" /></td>
(-)a/t/db_dependent/lib/KohaTest/Overdues.pm (-2 lines)
Lines 23-29 sub methods : Test( 1 ) { Link Here
23
                       BorType 
23
                       BorType 
24
                       ReplacementCost 
24
                       ReplacementCost 
25
                       GetFine 
25
                       GetFine 
26
                       GetIssuingRules 
27
                       ReplacementCost2 
26
                       ReplacementCost2 
28
                       GetNextIdNotify 
27
                       GetNextIdNotify 
29
                       NumberNotifyId
28
                       NumberNotifyId
30
- 

Return to bug 8365