[Koha-patches] [PATCH] IMPROVEMENT : serialsadditems at subscription level (bump 070)

paul.poulain at biblibre.com paul.poulain at biblibre.com
Thu Apr 17 19:52:56 CEST 2008


From: paul <paul.poulain at biblibre.com>

The patch update the DB by adding a row in the subscription table (serialsadditems), that is filled with the value of the syspref.
then, the syspref is deleted.
---
 C4/Items.pm                                        |    3 +-
 C4/Serials.pm                                      |   22 ++++++++++----------
 admin/systempreferences.pl                         |    1 -
 installer/data/mysql/updatedatabase.pl             |   13 +++++++++++
 .../prog/en/modules/serials/serials-edit.tmpl      |    4 +--
 .../prog/en/modules/serials/subscription-add.tmpl  |   13 ++++++++++-
 .../en/modules/serials/subscription-detail.tmpl    |    5 ++++
 kohaversion.pl                                     |    2 +-
 serials/serials-edit.pl                            |   12 ++++++----
 serials/subscription-add.pl                        |   11 ++++++---
 10 files changed, 58 insertions(+), 28 deletions(-)

diff --git a/C4/Items.pm b/C4/Items.pm
index 427e21f..1721eb8 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -229,6 +229,8 @@ sub AddItem {
 
     # create MARC tag representing item and add to bib
     my $new_item_marc = _marc_from_item_hash($item, $frameworkcode, $unlinked_item_subfields);
+    warn "HERE : ".$item->{'biblionumber'};
+    warn "HERE 2 : ".$new_item_marc->as_formatted;
     _add_item_field_to_biblio($new_item_marc, $item->{'biblionumber'}, $frameworkcode );
    
     logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
@@ -1866,7 +1868,6 @@ sub _add_item_field_to_biblio {
     my ($item_marc, $biblionumber, $frameworkcode) = @_;
 
     my $biblio_marc = GetMarcBiblio($biblionumber);
-
     foreach my $field ($item_marc->fields()) {
         $biblio_marc->append_fields($field);
     }
diff --git a/C4/Serials.pm b/C4/Serials.pm
index e2865ca..78d7e43 100644
--- a/C4/Serials.pm
+++ b/C4/Serials.pm
@@ -239,7 +239,7 @@ sub GetSerialInformation {
     my ($serialid) = @_;
     my $dbh        = C4::Context->dbh;
     my $query      = qq|
-        SELECT serial.*, serial.notes as sernotes, serial.status as serstatus,subscription.*,subscription.subscriptionid as subsid|;
+        SELECT serial.*, serial.notes as sernotes, serial.status as serstatus,subscription.*,subscription.subscriptionid as subsid |;
        if (C4::Context->preference('IndependantBranches') && 
               C4::Context->userenv && 
               C4::Context->userenv->{'flags'} != 1 && C4::Context->userenv->{'branch'}){
@@ -253,8 +253,8 @@ sub GetSerialInformation {
     my $rq = $dbh->prepare($query);
     $rq->execute($serialid);
     my $data = $rq->fetchrow_hashref;
-
-    if ( C4::Context->preference("serialsadditems") ) {
+    # create item information if we have serialsadditems for this subscription
+    if ( $data->{'serialsadditems'} ) {
         if ( $data->{'itemnumber'} ) {
             my @itemnumbers = split /,/, $data->{'itemnumber'};
             foreach my $itemnum (@itemnumbers) {
@@ -1239,7 +1239,7 @@ sub ModSubscription {
         $whenmorethan3,   $setto3,       $lastvalue3,     $innerloop3,
         $numberingmethod, $status,       $biblionumber,   $callnumber,
         $notes,           $letter,       $hemisphere,     $manualhistory,
-        $internalnotes,
+        $internalnotes,   $serialsadditems,
         $subscriptionid
     ) = @_;
 #     warn $irregularity;
@@ -1250,7 +1250,7 @@ sub ModSubscription {
                         add1=?,every1=?,whenmorethan1=?,setto1=?,lastvalue1=?,innerloop1=?,
                         add2=?,every2=?,whenmorethan2=?,setto2=?,lastvalue2=?,innerloop2=?,
                         add3=?,every3=?,whenmorethan3=?,setto3=?,lastvalue3=?,innerloop3=?,
-                        numberingmethod=?, status=?, biblionumber=?, callnumber=?, notes=?, letter=?, hemisphere=?,manualhistory=?,internalnotes=?
+                        numberingmethod=?, status=?, biblionumber=?, callnumber=?, notes=?, letter=?, hemisphere=?,manualhistory=?,internalnotes=?,serialsadditems=?
                     WHERE subscriptionid = ?";
 #     warn "query :".$query;
     my $sth = $dbh->prepare($query);
@@ -1265,7 +1265,7 @@ sub ModSubscription {
         $whenmorethan3,   $setto3,       $lastvalue3,     $innerloop3,
         $numberingmethod, $status,       $biblionumber,   $callnumber,
         $notes,           $letter,       $hemisphere,     ($manualhistory?$manualhistory:0),
-        $internalnotes,
+        $internalnotes,   $serialsadditems,
         $subscriptionid
     );
     my $rows=$sth->rows;
@@ -1284,7 +1284,7 @@ $subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbu
     $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
     $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
     $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
-    $numberingmethod, $status, $notes)
+    $numberingmethod, $status, $notes, $serialsadditems)
 
 Create a new subscription with value given on input args.
 
@@ -1307,7 +1307,7 @@ sub NewSubscription {
         $lastvalue3,    $innerloop3,   $numberingmethod, $status,
         $notes,         $letter,       $firstacquidate,  $irregularity,
         $numberpattern, $callnumber,   $hemisphere,      $manualhistory,
-        $internalnotes
+        $internalnotes, $serialsadditems,
     ) = @_;
     my $dbh = C4::Context->dbh;
 
@@ -1320,8 +1320,8 @@ sub NewSubscription {
             add2,every2,whenmorethan2,setto2,lastvalue2,innerloop2,
             add3,every3,whenmorethan3,setto3,lastvalue3,innerloop3,
             numberingmethod, status, notes, letter,firstacquidate,irregularity,
-            numberpattern, callnumber, hemisphere,manualhistory,internalnotes)
-        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
+            numberpattern, callnumber, hemisphere,manualhistory,internalnotes,serialsadditems)
+        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
         |;
     my $sth = $dbh->prepare($query);
     $sth->execute(
@@ -1345,7 +1345,7 @@ sub NewSubscription {
         format_date_in_iso($firstacquidate),                $irregularity,
         $numberpattern,                 $callnumber,
         $hemisphere,                    $manualhistory,
-        $internalnotes
+        $internalnotes,                 $serialsadditems,
     );
 
     #then create the 1st waited number
diff --git a/admin/systempreferences.pl b/admin/systempreferences.pl
index 58a2cb2..558d6fe 100755
--- a/admin/systempreferences.pl
+++ b/admin/systempreferences.pl
@@ -99,7 +99,6 @@ my %tabsysprefs;
     $tabsysprefs{LabelMARCView}="Cataloguing";
     $tabsysprefs{marc}="Cataloguing";
     $tabsysprefs{marcflavour}="Cataloguing";
-    $tabsysprefs{serialsadditems}="Cataloguing";
     $tabsysprefs{MARCOrgCode}="Cataloguing";
     $tabsysprefs{z3950AuthorAuthFields}="Cataloguing";
     $tabsysprefs{z3950NormalizeAuthor}="Cataloguing";
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index e8fedf1..c88d05f 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -1281,6 +1281,19 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
+$DBversion = "3.00.00.070";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do(" ALTER TABLE `subscription` ADD `serialsadditems` TINYINT( 1 ) NOT NULL DEFAULT '0';");
+    # fill the new field with the previous systempreference value, then drop the syspref
+    my $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='serialsadditems'");
+    $sth->execute;
+    my ($serialsadditems) = $sth->fetchrow();
+    $dbh->do("UPDATE subscription SET serialsadditems=$serialsadditems");
+    $dbh->do("DELETE FROM systempreferences WHERE variable='serialsadditems'");
+    print "Upgrade to $DBversion done ( moving serialsadditems from syspref to subscription )\n";
+    SetVersion ($DBversion);
+}
+
 =item DropAllForeignKeys($table)
 
   Drop all foreign keys of the table $table
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tmpl
index 6eeb3ca..126fb2c 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tmpl
@@ -60,7 +60,6 @@ function Check(f) {
         alert(alertString2);
     }
 }
-<!--TMPL_IF Name="serialsadditems"-->
 function unHideItems(index,labelindex) {
 	subfield = document.getElementById(index);
 	subfield.style.display = 'block';
@@ -137,7 +136,6 @@ function CloneSubfield(index){
     // insert this line on the page
     original.parentNode.insertBefore(clone,original.nextSibling);
 }
-<!--/TMPL_IF>
 //]]>
 </script>
 </head>
@@ -262,7 +260,7 @@ Error : Barcode Not Unique For serialseq <!--TMPL_VAR Name="errserialseq"-->
         <div id="item<!-- TMPL_VAR NAME="serialid" --><!-- TMPL_VAR NAME="countitems" -->" class="items">
         <!-- TMPL_LOOP NAME="iteminformation" -->
                <div name="line" class="subfield_line" style="<!-- TMPL_VAR NAME='hidden' -->;" id="subfield<!-- TMPL_VAR NAME='serialid' --><!-- TMPL_VAR NAME='countitems' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->">
-   
+                              
                 <label><!-- TMPL_VAR NAME="subfield" --> - <!-- TMPL_IF name="mandatory" --><b><!-- /TMPL_IF --><!-- TMPL_VAR NAME="marc_lib" --><!-- TMPL_IF name="mandatory" --> *</b><!-- /TMPL_IF --></label>
                 <!-- TMPL_VAR NAME="marc_value" -->
                 <input type="hidden" name="itemid" value="<!-- TMPL_VAR NAME="itemid" -->" />
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tmpl
index 5c7198f..93e2219 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tmpl
@@ -820,7 +820,7 @@ window.onload = irregular_order();
     <fieldset id="subscription_add_information" class="rows">
 	<legend>Subscription details</legend>
 	<ol>
-	<li><span class="label">Subscription #</span> <!--TMPL_VAR name="subscriptionid"--></li>
+        <li><span class="label">Subscription #</span> <!--TMPL_VAR name="subscriptionid"--></li>
         <li>
             <span class="label">Librarian: </span>            <!-- TMPL_VAR name="loggedinusername" -->
         </li>
@@ -837,6 +837,15 @@ window.onload = irregular_order();
                 <a href="#" onclick="addbiblioPopup(); return false;">Create Biblio</a><!--/TMPL_IF--></div>
             
         </li>
+        <li class="radio">
+            <!-- TMPL_IF name="serialsadditems" -->
+                <label for="serialsadditems-yes">serial recieve create an item </label><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1" checked="checked" />
+                <label for="serialsadditems-no">serial recieve don't create an item </label><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" />
+            <!-- TMPL_ELSE -->
+                <label for="serialsadditems-yes">serial recieve create an item </label><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1"/>
+                <label for="serialsadditems-no">serial recieve don't create an item </label><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" checked="checked" />
+            <!-- /TMPL_IF -->
+        </li>
         <li>
             <label for="callnumber">Call Number</label>
             <input type="text" name="callnumber" id="callnumber" value="<!-- TMPL_VAR name="callnumber" -->" size="20" />
@@ -890,7 +899,7 @@ window.onload = irregular_order();
                     <li>You <b>must</b> select a vendor if you wish to generate claims.</li>
                 </ul></div>
             
-
+            
 	</fieldset>
 	</div>
 	
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tmpl
index 0950afd..df83ea7 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tmpl
@@ -116,6 +116,11 @@ function popup(subscriptionid) {
         <li><span class="label">Vendor:</span> <a href="/cgi-bin/koha/acqui/supplier.pl?supplierid=<!-- TMPL_VAR name="aqbooksellerid"-->"><!-- TMPL_VAR name="aqbooksellername" -->&nbsp;</a></li>
         <li><span class="label">Biblio:</span> <i>(<!-- TMPL_VAR name="bibnum" -->)</i> <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=<!-- TMPL_VAR name="bibnum" -->"><!-- TMPL_VAR name="bibliotitle" --></a></li><br />
 <!-- TMPL_IF name="branchcode" --><li><span class="label">Library:</span> <!-- TMPL_VAR name="branchcode" -->&nbsp;</li><!-- /TMPL_IF -->
+        <!-- TMPL_IF name="serialsadditems" -->
+            <li>Serial recieve create an item</li>
+        <!-- TMPL_ELSE -->
+            <li>Serial recieve don't create an item</li>
+        <!-- /TMPL_IF -->
         <!-- TMPL_IF name="callnumber" --><li><span class="label">Call Number:</span> <!-- TMPL_VAR name="callnumber" -->&nbsp;</li><!-- /TMPL_IF -->
         <!-- TMPL_IF name="letter" --><li><span class="label">Patron alert with:</span> <!-- TMPL_VAR name="letter" -->&nbsp;</li><!-- /TMPL_IF -->
         <!-- TMPL_IF name="notes" --><li><span class="label">Notes:</span> <!-- TMPL_VAR name="notes" --></li><!-- /TMPL_IF -->
diff --git a/kohaversion.pl b/kohaversion.pl
index 3660838..938e935 100644
--- a/kohaversion.pl
+++ b/kohaversion.pl
@@ -10,7 +10,7 @@
 use strict;
 
 sub kohaversion {
-    our $VERSION = "3.00.00.069";
+    our $VERSION = "3.00.00.070";
     # version needs to be set this way
     # so that it can be picked up by Makefile.PL
     # during install
diff --git a/serials/serials-edit.pl b/serials/serials-edit.pl
index 93cf630..a7b01b6 100755
--- a/serials/serials-edit.pl
+++ b/serials/serials-edit.pl
@@ -130,12 +130,14 @@ my $bibdata=GetBiblioData($serialdatalist[0]->{'biblionumber'});
 
 my @newserialloop;
 my @subscriptionloop;
+# check, for each subscription edited, that we have an empty item line if applicable for the subscription
 foreach my $subscriptionid (@subscriptionids){
   my $cell;
-  if (C4::Context->preference("serialsadditems")){
+  if ($serialdatalist[0]->{'serialsadditems'}){
   #Create New empty item  
     $cell =
-      PrepareItemrecordDisplay( $serialdatalist[0]->{'biblionumber'} );
+    PrepareItemrecordDisplay( $serialdatalist[0]->{'biblionumber'} );
+    $cell->{serialsadditems} = 1;
   }
   $cell->{'subscriptionid'}=$subscriptionid;
   $cell->{'itemid'}       = "NNEW";
@@ -175,8 +177,8 @@ if ($op eq 'serialchangestatus') {
                             $notes[$i]);
         }
     }
-    if (C4::Context->preference("serialsadditems")){
-      my @moditems = $query->param('moditem');
+    my @moditems = $query->param('moditem');
+    if (scalar(@moditems)){
       my @tags = $query->param('tag');
       my @subfields = $query->param('subfield');
       my @field_values = $query->param('field_value');
@@ -227,7 +229,7 @@ if ($op eq 'serialchangestatus') {
             my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode");
             if (C4::Context->preference("autoBarcode") ne  'OFF'  ) {
               eval {    $record->field($tagfield)->subfield($tagsubfield) };
-		  if ($@) {
+              if ($@) {
                 my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
                 $sth_barcode->execute;
                 my ($newbarcode) = $sth_barcode->fetchrow;
diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl
index a4b48d1..d7cd4ff 100755
--- a/serials/subscription-add.pl
+++ b/serials/subscription-add.pl
@@ -40,7 +40,7 @@ my ($subscriptionid,$auser,$branchcode,$librarian,$cost,$aqbooksellerid, $aqbook
 	$add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
 	$add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
 	$numberingmethod, $status, $biblionumber, 
-	$bibliotitle, $callnumber, $notes, $hemisphere, $letter, $manualhistory);
+	$bibliotitle, $callnumber, $notes, $hemisphere, $letter, $manualhistory,$serialsadditems);
 
 	my @budgets;
 my ($template, $loggedinuser, $cookie)
@@ -220,13 +220,15 @@ if ($op eq 'addsubscription') {
 	my $letter = $query->param('letter');
     # ## BugFIX : hdl doesnot know what innerloops or letter stand for but it seems necessary. So he adds them.
     my $manualhistory = $query->param('manualhist');
+    my $serialsadditems = $query->param('serialsadditems');
 	my $subscriptionid = NewSubscription($auser,$branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
 					$startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
 					$add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
 					$add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
 					$add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
 					$numberingmethod, $status, $notes,$letter,$firstacquidate,join(",", at irregularity),
-                    $numberpattern, $callnumber, $hemisphere,($manualhistory?$manualhistory:0),$internalnotes
+                    $numberpattern, $callnumber, $hemisphere,($manualhistory?$manualhistory:0),$internalnotes,
+                    $serialsadditems,
 				);
 
     print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
@@ -289,9 +291,9 @@ if ($op eq 'addsubscription') {
     my $letter = $query->param('letter');
     my $manualhistory = $query->param('manualhist');
     my $enddate = $query->param('enddate');
+    my $serialsadditems = $query->param('serialsadditems');
     # subscription history
     my $histenddate = format_date_in_iso($query->param('histenddate'));
-    warn "HIST END : $histenddate";
     my $histstartdate = format_date_in_iso($query->param('histstartdate'));
     my $recievedlist = $query->param('recievedlist');
     my $missinglist = $query->param('missinglist');
@@ -312,7 +314,8 @@ if ($op eq 'addsubscription') {
             $whenmorethan3,   $setto3,       $lastvalue3,     $innerloop3,
             $numberingmethod, $status,       $biblionumber,   $callnumber,
             $notes,           $letter,       $hemisphere,     $manualhistory,$internalnotes,
-            $subscriptionid);
+            $serialsadditems, $subscriptionid,
+        );
     }
     print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
 } else {
-- 
1.5.3.2




More information about the Koha-patches mailing list