#1485 (issuing rules improvement) continued
authorPaul POULAIN <paul@koha-fr.org>
Fri, 12 Oct 2007 22:35:27 +0000 (17:35 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Sat, 13 Oct 2007 03:22:40 +0000 (22:22 -0500)
updating fines rules management :
- replacing '*' by default
- removing bottom line (*) that means nothing
- dealing correctly with .0000 fine values
- fixing fine storage

still fines.pl to do

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
admin/finesrules.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/finesrules.tmpl

index b5fdeb7..3fea7f3 100755 (executable)
@@ -31,27 +31,27 @@ my $dbh = C4::Context->dbh;
 
 my $type=$input->param('type');
 my $branch = $input->param('branch');
-$branch="" unless $branch;
+$branch="*" unless $branch;
 my $op = $input->param('op');
 
 # my $flagsrequired;
 # $flagsrequired->{circulation}=1;
 my ($template, $loggedinuser, $cookie)
     = get_template_and_user({template_name => "admin/finesrules.tmpl",
-                             query => $input,
-                             type => "intranet",
-                             authnotrequired => 0,
-                            flagsrequired => {parameters => 1},
-                             debug => 1,
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
                              });
 # save the values entered
 if ($op eq 'save') {
   my @names=$input->param();
-  my $sth_search = $dbh->prepare("select count(*) as total from issuingrules where branchcode=? and categorycode=? and itemtype=?");
+  my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?");
 
-  my $sth_Finsert = $dbh->prepare("insert into issuingrules (branchcode,categorycode,itemtype,fine,firstremind,chargeperiod) values (?,?,?,?,?,?)");
-  my $sth_Fupdate=$dbh->prepare("Update issuingrules set fine=?,firstremind=?,chargeperiod=? where branchcode=? and categorycode=? and itemtype=?");
-  my $sth_Fdelete=$dbh->prepare("delete from issuingrules where branchcode=? and categorycode=? and itemtype=? and issuelength=0");
+  my $sth_Finsert = $dbh->prepare("INSERT INTO issuingrules (branchcode,categorycode,itemtype,fine,firstremind,chargeperiod) VALUES (?,?,?,?,?,?)");
+  my $sth_Fupdate=$dbh->prepare("UPDATE issuingrules SET fine=?,firstremind=?,chargeperiod=? WHERE branchcode=? AND categorycode=? AND itemtype=?");
+  my $sth_Fdelete=$dbh->prepare("DELETE FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=? AND issuelength=0");
 
   foreach my $key (@names){
     # FINES
@@ -61,17 +61,14 @@ if ($op eq 'save') {
       my $cat = $3; # item type
       my $data=$input->param($key);
       my ($fine,$firstremind,$chargeperiod)=split(',',$data);
-#       warn "$br $bor $cat $fine $firstremind $chargeperiod";
-#                      if ($fine >0) {
-#       $br="*" unless ($br);
       $bor="*" unless ($bor);
       $cat="*" unless ($cat);
       $sth_search->execute($br,$bor,$cat);
       my $res = $sth_search->fetchrow_hashref();
-      if ($res->{total}) {
-              $sth_Fupdate->execute($fine,$firstremind,$chargeperiod,$br,$bor,$cat);
+      if ($res->{total} >0) {
+        $sth_Fupdate->execute($fine,$firstremind,$chargeperiod,$br,$bor,$cat);
       } else {
-              $sth_Finsert->execute($br,$bor,$cat,$fine,$firstremind,$chargeperiod);
+        $sth_Finsert->execute($br,$bor,$cat,$fine,$firstremind,$chargeperiod);
       }
     }
   }
@@ -80,12 +77,12 @@ if ($op eq 'save') {
 my $branches = GetBranches;
 my @branchloop;
 foreach my $thisbranch (keys %$branches) {
-       my $selected = 1 if $thisbranch eq $branch;
-       my %row =(value => $thisbranch,
-                               selected => $selected,
-                               branchname => $branches->{$thisbranch}->{'branchname'},
-                       );
-       push @branchloop, \%row;
+    my $selected = 1 if $thisbranch eq $branch;
+    my %row =(value => $thisbranch,
+            selected => $selected,
+            branchname => $branches->{$thisbranch}->{'branchname'},
+    );
+    push @branchloop, \%row;
 }
 
 my $sth=$dbh->prepare("Select description,categorycode from categories order by description");
@@ -94,10 +91,9 @@ my @trow3;
 my @title_loop;
 # my $i=0;
 while (my $data=$sth->fetchrow_hashref){
-       my %row = (in_title => $data->{'description'});
-       push @title_loop,\%row;
-       push @trow3,$data->{'categorycode'};
-#      $i++;
+    my %row = (in_title => $data->{'description'});
+    push @title_loop,\%row;
+    push @trow3,$data->{'categorycode'};
 }
 
 my %row = (in_title => "*");
@@ -114,36 +110,35 @@ my @itemtypes;
 while (my $row=$sth->fetchrow_hashref){
        push @itemtypes,\$row;
 }
-my $line;
-$line->{itemtype} = "*";
-$line->{description} = "*";
-push @itemtypes,\$line;
 
 foreach my $data (@itemtypes) {
-       my @trow2;
-       my @cell_loop;
-       if ( $toggle eq 1 ) {
-               $toggle = 0;
-       } else {
-               $toggle = 1;
-       }
-       for (my $i=0;$i<=$#trow3;$i++){
-               my $sth2=$dbh->prepare("select * from issuingrules where branchcode=? and categorycode=? and itemtype=?");
-               $sth2->execute($branch,$trow3[$i],$$data->{'itemtype'});
-               my $dat=$sth2->fetchrow_hashref;
-               $sth2->finish;
-               my $fine=$dat->{'fine'}+0;
-               my $finesvalue;
-               $finesvalue= "$fine,$dat->{'firstremind'},$dat->{'chargeperiod'}" if $fine+$dat->{'firstremind'}+$dat->{'chargeperiod'}>0;
-               my %row = (finesname=> "F-$branch-$trow3[$i].$$data->{'itemtype'}",
-                                       finesvalue => $finesvalue,
-                                       toggle => $toggle,
-                                       );
-               push @cell_loop,\%row;
-       }
-       my %row = (categorycode => $$data->{description},
-                                       cell =>\@cell_loop);
-       push @row_loop, \%row;
+    my @trow2;
+    my @cell_loop;
+    if ( $toggle eq 1 ) {
+        $toggle = 0;
+    } else {
+        $toggle = 1;
+    }
+    for (my $i=0;$i<=$#trow3;$i++){
+        my $sth2=$dbh->prepare("SELECT * FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?");
+        $sth2->execute($branch,$trow3[$i],$$data->{'itemtype'});
+        my $dat=$sth2->fetchrow_hashref;
+        $sth2->finish;
+        my $fine=$dat->{'fine'};
+        # remove trailing 0s
+        $fine =~ s/\.*0*$//g;
+        my $finesvalue;
+        $finesvalue= "$fine,$dat->{'firstremind'},$dat->{'chargeperiod'}" if $fine ne '';
+        my %row = (finesname=> "F-$branch-$trow3[$i].$$data->{'itemtype'}",
+                    finesvalue => $finesvalue,
+                    toggle => $toggle,
+                    );
+        push @cell_loop,\%row;
+    }
+    my %row = (categorycode => $$data->{description},
+                cell =>\@cell_loop,
+                );
+    push @row_loop, \%row;
 }
 
 $sth->finish;
@@ -151,8 +146,5 @@ $template->param(title => \@title_loop,
                 row => \@row_loop,
                 branchloop => \@branchloop,
                 branch => $branch,
-                intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
-               intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-               IntranetNav => C4::Context->preference("IntranetNav"),
-                                               );
+                );
 output_html_with_http_headers $input, $cookie, $template->output;
index eee2b37..818c752 100644 (file)
@@ -9,71 +9,66 @@
 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Fines</div>
 
 <div id="doc3" class="yui-t2">
-   
-   <div id="bd">
-       <div id="yui-main">
-       <div class="yui-b">
 
-       <h1>Defining <!-- TMPL_IF NAME="branch" -->fining rules for <!-- TMPL_VAR NAME="branch" --><!-- TMPL_ELSE -->default fining rules<!-- /TMPL_IF --></h1>
-               
-       <div class="help">
-               <h3>HINT for fines</h3>
-               <p>Each box needs to be filled in with fine,time to start charging,charging cycle</p>
-               <p>eg 1,7,7 = 1 [USD,EUR,etc] fine after 7 days, every 7 days</p>
-               <p>Fines are calculated by the fines2.pl script, located in misc directory.  Ask your administrator to put this script in crontab, after midnight, to have fines calculated every night</p>
-       </div>
-       <div class="help">
-               <h3>Default values</h3>
-               <p> If a cell is not filled, the 1st of the following value is searched :</p>
-               <ul>
-                       <li>same library and same patron category, itemtype *</li>
-                       <li>same patron and same itemtype, patron category *</li>
-                       <li>same itemtype and patron category, library *</li>
-                       <li>library * and itemtype *, same patron category</li>
-                       <li>library * and patron category *, same itemtype </li>
-                       <li>library * and patron category *, itemtype *</li>
-               </ul>
-       </div>
-               <form method="post" action="/cgi-bin/koha/admin/finesrules.pl">
-               <label for="branch">Select a library :</label>
-                       <select id="branch" name="branch">
-                               <option value="">Default</option>
-                       <!-- TMPL_LOOP NAME="branchloop" -->
-                               <!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!-- TMPL_VAR NAME="branchname" --></option>
-                               <!-- TMPL_ELSE -->
-                               <option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="branchname" --></option>
-                               <!-- /TMPL_IF -->
-                       <!-- /TMPL_LOOP -->
-                       </select>
-                       <input type="submit" value="Select" />
-               </form>
-               <form method="post" action="/cgi-bin/koha/admin/finesrules.pl">
-                       <input type="hidden" name="op" value="save" />
-                       <input type="hidden" name="branch" value="<!-- TMPL_VAR NAME="branch" -->" />
-                       
-                       <table>
-                       <caption>Defining fines rules for <!-- TMPL_VAR NAME="branch" --></caption>
-                       <tr>
-                               <th>&nbsp;</th><!-- TMPL_LOOP NAME="title" --><th scope="col"><!-- TMPL_VAR NAME="in_title" --></th><!-- /TMPL_LOOP -->
-                       </tr>
-                       <!-- TMPL_LOOP NAME="row" -->
-                               <tr>
-                                       <th scope="row"><!-- TMPL_VAR NAME="categorycode" --></th>
-                                       <!-- TMPL_LOOP NAME="cell" -->
-                                               <!-- TMPL_IF NAME="toggle" -->
-   <td class="highlight">
-<!-- TMPL_ELSE -->
-   <td>
-<!-- /TMPL_IF -->
-                                                       <input name="<!-- TMPL_VAR NAME="finesname" -->" value="<!-- TMPL_VAR NAME="finesvalue" -->" size="6" maxlength="10" />
-                                               </td>
-                                       <!-- /TMPL_LOOP -->
-                               </tr>
-                       <!-- /TMPL_LOOP -->
-                       </table>
-                       
-                       <input type="submit" value="Save Changes" />
-               </form>
+<div id="bd">
+    <div id="yui-main">
+    <div class="yui-b">
+    
+    <h1>Defining <!-- TMPL_IF NAME="branch" -->fining rules for <!-- TMPL_VAR NAME="branch" --><!-- TMPL_ELSE -->default fining rules<!-- /TMPL_IF --></h1>
+            
+    <div class="help">
+        <h3>HINT for fines</h3>
+        <p>Each box needs to be filled in with fine,time to start charging,charging cycle</p>
+        <p>eg 1,7,7 = 1 [USD,EUR,etc] fine after 7 days, every 7 days</p>
+        <p>Fines are calculated by the fines2.pl script, located in misc directory.  Ask your administrator to put this script in crontab, after midnight, to have fines calculated every night</p>
+        <p>The rules are applied from most specific to less specific, the 1st who is filled :</p>
+        <ul>
+            <li>same branch, same category</li>
+            <li>same branch, default category</li>
+            <li>default branch, same category</li>
+            <li>default branch, default category</li>
+        </ul>
+    </div>
+        <form method="post" action="/cgi-bin/koha/admin/finesrules.pl">
+        <label for="branch">Select a library :</label>
+            <select id="branch" name="branch">
+                <option value="">Default</option>
+                <!-- TMPL_LOOP NAME="branchloop" -->
+                    <!-- TMPL_IF NAME="selected" -->
+                        <option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!-- TMPL_VAR NAME="branchname" --></option>
+                    <!-- TMPL_ELSE -->
+                        <option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="branchname" --></option>
+                    <!-- /TMPL_IF -->
+                <!-- /TMPL_LOOP -->
+            </select>
+            <input type="submit" value="Select" />
+        </form>
+        <form method="post" action="/cgi-bin/koha/admin/finesrules.pl">
+            <input type="hidden" name="op" value="save" />
+            <input type="hidden" name="branch" value="<!-- TMPL_VAR NAME="branch" -->" />
+            
+            <table>
+            <caption>Defining fines rules for <!-- TMPL_VAR NAME="branch" --></caption>
+            <tr>
+                <th>&nbsp;</th><!-- TMPL_LOOP NAME="title" --><th scope="col"><!-- TMPL_IF EXPR="in_title eq '*'" -->Default<!-- TMPL_ELSE --><!-- TMPL_VAR NAME="in_title" --><!-- /TMPL_IF --></th><!-- /TMPL_LOOP -->
+            </tr>
+            <!-- TMPL_LOOP NAME="row" -->
+                <tr>
+                    <th><!-- TMPL_IF name="total" -->Total <!-- TMPL_ELSE --><!-- TMPL_VAR NAME="categorycode" --><!-- /TMPL_IF --></th>
+                    <!-- TMPL_LOOP NAME="cell" -->
+                        <!-- TMPL_IF NAME="toggle" -->
+                            <td class="highlight">
+                        <!-- TMPL_ELSE -->
+                            <td>
+                        <!-- /TMPL_IF -->
+                            <input name="<!-- TMPL_VAR NAME="finesname" -->" value="<!-- TMPL_VAR NAME="finesvalue" -->" size="6" maxlength="10" />
+                        </td>
+                    <!-- /TMPL_LOOP -->
+                </tr>
+            <!-- /TMPL_LOOP -->
+        </table>
+        <input type="submit" value="Save Changes" />
+    </form>
 
 </div>
 </div>