Merging in katipo changes for serials
authorbob_lyon <bob_lyon>
Thu, 20 Jul 2006 03:14:49 +0000 (03:14 +0000)
committerbob_lyon <bob_lyon>
Thu, 20 Jul 2006 03:14:49 +0000 (03:14 +0000)
serials/alt_subscription-add.pl [new file with mode: 0755]
serials/alt_subscription-detail.pl [new file with mode: 0755]
serials/routing-preview.pl [new file with mode: 0755]
serials/routing.pl [new file with mode: 0755]
serials/serials-home.pl
serials/statecollection.pl [new file with mode: 0755]
serials/subscription-copy.pl [new file with mode: 0755]
serials/subscription-renew.pl

diff --git a/serials/alt_subscription-add.pl b/serials/alt_subscription-add.pl
new file mode 100755 (executable)
index 0000000..1cfb9f0
--- /dev/null
@@ -0,0 +1,274 @@
+#!/usr/bin/perl
+
+
+use strict;
+use CGI;
+use C4::Koha;
+use C4::Auth;
+use C4::Date;
+use C4::Output;
+use C4::Acquisition;
+use C4::Interface::CGI::Output;
+use C4::Context;
+use HTML::Template;
+use C4::Serials;
+use Date::Manip;
+
+my $query = new CGI;
+my $op = $query->param('op');
+my $dbh = C4::Context->dbh;
+my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
+       $firstacquidate, $dow, $irregularity, $numberpattern, $numberlength, $weeklength, $monthlength, $sublength,
+       $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
+       $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
+       $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
+       $numberingmethod, $status, $biblionumber, 
+       $bibliotitle, $callnumber, $notes, $hemisphere);
+
+       my @budgets;
+my ($template, $loggedinuser, $cookie)
+= get_template_and_user({template_name => "serials/alt_subscription-add.tmpl",
+                               query => $query,
+                               type => "intranet",
+                               authnotrequired => 0,
+                               flagsrequired => {catalogue => 1},
+                               debug => 1,
+                               });
+
+
+my $weekarrayjs='';
+my $count = 0;
+my ($year, $month, $day) = UnixDate("today", "%Y", "%m", "%d");
+my $firstday = Date_DayOfYear($month,$day,$year);
+my $wkno = Date_WeekOfYear($month,$day,$year,1); # week starting monday
+my $weekno = $wkno;
+for(my $i=$firstday;$i<($firstday+365);$i=$i+7){
+        $count = $i;
+        if($wkno > 52){$year++; $wkno=1;}
+        if($count>365){$count=$i-365;}    
+        my ($y,$m,$d) = Date_NthDayOfYear($year,$count);
+        my $output = "$y-$m-$d";
+        $weekarrayjs .= "'Wk $wkno: ".format_date($output)."',";
+        $wkno++;    
+}
+chop($weekarrayjs);
+# warn $weekarrayjs;
+
+my $sub_on;
+my @subscription_types = (
+            'issues', 'weeks', 'months'
+        ); 
+my @sub_type_data;
+if ($op eq 'mod') {
+       my $subscriptionid = $query->param('subscriptionid');
+       my $subs = &GetSubscription($subscriptionid);
+       $auser = $subs->{'user'};
+       $librarian => $subs->{'librarian'},
+       $cost = $subs->{'cost'};
+       $aqbooksellerid = $subs->{'aqbooksellerid'};
+       $aqbooksellername = $subs->{'aqbooksellername'};
+       $bookfundid = $subs->{'bookfundid'};
+       $aqbudgetid = $subs->{'aqbudgetid'};
+       $startdate = $subs->{'startdate'};
+       $firstacquidate = $subs->{'firstacquidate'};    
+       $periodicity = $subs->{'periodicity'};
+       $dow = $subs->{'dow'};
+        $irregularity = $subs->{'irregularity'};
+        $numberpattern = $subs->{'numberpattern'};
+       $numberlength = $subs->{'numberlength'};
+       $weeklength = $subs->{'weeklength'};
+       $monthlength = $subs->{'monthlength'};
+
+        if($monthlength > 0){
+           $sublength = $monthlength;
+           $sub_on = $subscription_types[2];
+       } elsif ($weeklength>0){
+           $sublength = $weeklength;
+           $sub_on = $subscription_types[1];
+       } else {
+           $sublength = $numberlength;
+           $sub_on = $subscription_types[0];
+       }
+        
+
+        while (@subscription_types) {
+           my $sub_type = shift @subscription_types;
+           my %row = ( 'name' => $sub_type );
+           if ( $sub_on eq $sub_type ) {
+            $row{'selected'} = ' selected';
+           } else {
+            $row{'selected'} = '';
+           }
+           push( @sub_type_data, \%row );
+        }
+    
+       $add1 = $subs->{'add1'};
+       $every1 = $subs->{'every1'};
+       $whenmorethan1 = $subs->{'whenmorethan1'};
+       $setto1 = $subs->{'setto1'};
+       $lastvalue1 = $subs->{'lastvalue1'};
+       $innerloop1 = $subs->{'innerloop1'};
+       $add2 = $subs->{'add2'};
+       $every2 = $subs->{'every2'};
+       $whenmorethan2 = $subs->{'whenmorethan2'};
+       $setto2 = $subs->{'setto2'};
+       $lastvalue2 = $subs->{'lastvalue2'};
+       $innerloop2 = $subs->{'innerloop2'};
+       $add3 = $subs->{'add3'};
+       $every3 = $subs->{'every3'};
+       $whenmorethan3 = $subs->{'whenmorethan3'};
+       $setto3 = $subs->{'setto3'};
+       $lastvalue3 = $subs->{'lastvalue3'};
+       $innerloop3 = $subs->{'innerloop3'};
+       $numberingmethod = $subs->{'numberingmethod'};
+       $status = $subs->{status};
+       $biblionumber = $subs->{'biblionumber'};
+       $bibliotitle = $subs->{'bibliotitle'};
+        $callnumber = $subs->{'callnumber'};
+       $notes = $subs->{'notes'};
+        $hemisphere = $subs->{'hemisphere'};
+       $template->param(
+               $op => 1,
+               user => $auser,
+               librarian => $librarian,
+               aqbooksellerid => $aqbooksellerid,
+               aqbooksellername => $aqbooksellername,
+               cost => $cost,
+               aqbudgetid => $aqbudgetid,
+               bookfundid => $bookfundid,
+               startdate => format_date($startdate),
+               firstacquidate => format_date($firstacquidate),     
+               periodicity => $periodicity,
+               dow => $dow,
+               irregularity => $irregularity,
+               numberpattern => $numberpattern,
+               sublength => $sublength,
+               subtype => \@sub_type_data,
+               add1 => $add1,
+               every1 => $every1,
+               whenmorethan1 => $whenmorethan1,
+               setto1 => $setto1,
+               lastvalue1 => $lastvalue1,
+               innerloop1 => $innerloop1,
+               add2 => $add2,
+               every2 => $every2,
+               whenmorethan2 => $whenmorethan2,
+               setto2 => $setto2,
+               lastvalue2 => $lastvalue2,
+               innerloop2 => $innerloop2,
+               add3 => $add3,
+               every3 => $every3,
+               whenmorethan3 => $whenmorethan3,
+               setto3 => $setto3,
+               lastvalue3 => $lastvalue3,
+               innerloop3 => $innerloop3,
+               numberingmethod => $numberingmethod,
+               status => $status,
+               biblionumber => $biblionumber,
+               bibliotitle => $bibliotitle,
+               callnumber => $callnumber,
+               notes => $notes,
+               subscriptionid => $subscriptionid,
+               weekarrayjs => $weekarrayjs,
+               weekno => $weekno,
+               hemisphere => $hemisphere,
+               );
+
+       $template->param(
+                               "periodicity$periodicity" => 1,
+                               "dow$dow" => 1,
+                               "numberpattern$numberpattern" => 1,
+                               );
+}
+(my $temp,@budgets) = bookfunds();
+# find default value & set it for the template
+for (my $i=0;$i<=$#budgets;$i++) {
+       if ($budgets[$i]->{'aqbudgetid'} eq $aqbudgetid) {
+               $budgets[$i]->{'selected'}=1;
+       }
+}
+$template->param(budgets => \@budgets,
+               intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
+
+if ($op eq 'addsubscription') {
+        my @irregular = $query->param('irregular');
+        my $irregular_count = @irregular;
+        for(my $i =0;$i<$irregular_count;$i++){
+            $irregularity .=$irregular[$i]."|";
+        }
+        $irregularity =~ s/\|$//;
+
+       my $auser = $query->param('user');
+       my $aqbooksellerid = $query->param('aqbooksellerid');
+       my $cost = $query->param('cost');
+       my $aqbudgetid = $query->param('aqbudgetid'); 
+       my $startdate = $query->param('startdate');
+       my $firstacquidate = $query->param('firstacquidate');    
+       my $periodicity = $query->param('periodicity');
+       my $dow = $query->param('dow');
+        # my $irregularity = $query->param('irregularity');
+       my $numberlength = 0;
+       my $weeklength = 0;
+       my $monthlength = 0;
+        my $numberpattern = $query->param('numbering_pattern');
+        my $sublength = $query->param('sublength');
+        my $subtype = $query->param('subtype');
+        if ($subtype eq 'months'){
+           $monthlength = $sublength;
+       } elsif ($subtype eq 'weeks'){
+           $weeklength = $sublength;
+       } else {
+           $numberlength = $sublength;
+       }
+
+       my $add1 = $query->param('add1');
+       my $every1 = $query->param('every1');
+       my $whenmorethan1 = $query->param('whenmorethan1');
+       my $setto1 = $query->param('setto1');
+       my $lastvalue1 = $query->param('lastvalue1');
+       my $add2 = $query->param('add2');
+       my $every2 = $query->param('every2');
+       my $whenmorethan2 = $query->param('whenmorethan2');
+       my $setto2 = $query->param('setto2');
+       my $lastvalue2 = $query->param('lastvalue2');
+       my $add3 = $query->param('add3');
+       my $every3 = $query->param('every3');
+       my $whenmorethan3 = $query->param('whenmorethan3');
+       my $setto3 = $query->param('setto3');
+       my $lastvalue3 = $query->param('lastvalue3');
+       my $numberingmethod = $query->param('numberingmethod');
+       my $status = 1;
+       my $biblionumber = $query->param('biblionumber');
+        my $callnumber = $query->param('callnumber');
+       my $notes = $query->param('notes');
+        my $hemisphere = $query->param('hemisphere') || 1;
+
+       my $subscriptionid = old_newsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
+                                       $startdate,$periodicity,$firstacquidate,$dow,$irregularity,$numberpattern,$numberlength,$weeklength,$monthlength,
+                                       $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,
+                                       $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,
+                                       $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,
+                                       $numberingmethod, $status, $callnumber, $notes, $hemisphere
+                               );
+       print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
+} else {
+
+        while (@subscription_types) {
+           my $sub_type = shift @subscription_types;
+           my %row = ( 'name' => $sub_type );
+           if ( $sub_on eq $sub_type ) {
+            $row{'selected'} = ' selected';
+           } else {
+            $row{'selected'} = '';
+           }
+           push( @sub_type_data, \%row );
+        }    
+    $template->param(subtype => \@sub_type_data,
+                weekarrayjs => $weekarrayjs,
+                weekno => $weekno,
+       );
+       output_html_with_http_headers $query, $cookie, $template->output;
+}
diff --git a/serials/alt_subscription-detail.pl b/serials/alt_subscription-detail.pl
new file mode 100755 (executable)
index 0000000..f595498
--- /dev/null
@@ -0,0 +1,189 @@
+#!/usr/bin/perl
+
+use strict;
+use CGI;
+use C4::Auth;
+use C4::Koha;
+use C4::Date;
+use C4::Serials;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Context;
+use HTML::Template;
+use Date::Manip;
+
+my $query = new CGI;
+my $op = $query->param('op');
+my $dbh = C4::Context->dbh;
+my $sth;
+# my $id;
+my ($template, $loggedinuser, $cookie, $subs);
+my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
+       $firstacquidate, $dow, $irregularity, $sublength, $subtype, $numberpattern, $numberlength, $weeklength, $monthlength,
+       $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
+       $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
+       $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
+       $numberingmethod, $status, $biblionumber, $bibliotitle, $callnumber, $notes, $hemisphere);
+
+$subscriptionid = $query->param('subscriptionid');
+
+if ($op eq 'modsubscription') {
+    my @irregular = $query->param('irregular');
+    my $irregular_count = @irregular;
+    for(my $i =0;$i<$irregular_count;$i++){
+       $irregularity .=$irregular[$i]."|";
+    }
+    $irregularity =~ s/\|$//;
+
+    
+       $auser = $query->param('user');
+       $librarian => $query->param('librarian'),
+       $cost = $query->param('cost');
+       $aqbooksellerid = $query->param('aqbooksellerid');
+       $biblionumber = $query->param('biblionumber');
+       $aqbudgetid = $query->param('aqbudgetid');
+       $startdate = format_date_in_iso($query->param('startdate'));
+       $firstacquidate = format_date_in_iso($query->param('firstacquidate'));    
+       $periodicity = $query->param('periodicity');
+       $dow = $query->param('dow');
+        $sublength = $query->param('sublength');
+        $subtype = $query->param('subtype');
+
+        if($subtype eq 'months'){
+           $monthlength = $sublength;
+       } elsif ($subtype eq 'weeks'){
+           $weeklength = $sublength;
+       } else {
+           $numberlength = $sublength;
+       }
+        $numberpattern = $query->param('numbering_pattern');
+       $add1 = $query->param('add1');
+       $every1 = $query->param('every1');
+       $whenmorethan1 = $query->param('whenmorethan1');
+       $setto1 = $query->param('setto1');
+       $lastvalue1 = $query->param('lastvalue1');
+       $innerloop1 = $query->param('innerloop1');
+       $add2 = $query->param('add2');
+       $every2 = $query->param('every2');
+       $whenmorethan2 = $query->param('whenmorethan2');
+       $setto2 = $query->param('setto2');
+       $lastvalue2 = $query->param('lastvalue2');
+       $innerloop2 = $query->param('innerloop2');
+       $add3 = $query->param('add3');
+       $every3 = $query->param('every3');
+       $whenmorethan3 = $query->param('whenmorethan3');
+       $setto3 = $query->param('setto3');
+       $lastvalue3 = $query->param('lastvalue3');
+       $innerloop3 = $query->param('innerloop3');
+       $numberingmethod = $query->param('numberingmethod');
+       $status = 1;
+        $callnumber = $query->param('callnumber');
+       $notes = $query->param('notes');
+        $hemisphere = $query->param('hemisphere');
+
+       &ModSubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$startdate,
+                                       $periodicity,$firstacquidate,$dow,$irregularity,$numberpattern,$numberlength,$weeklength,$monthlength,
+                                       $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
+                                       $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
+                                       $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
+                                       $numberingmethod, $status, $biblionumber, $callnumber, $notes, $hemisphere, $subscriptionid);
+}
+
+if ($op eq 'del') {
+       &DelSubscription($subscriptionid);
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=serials-home.pl\"></html>";
+       exit;
+
+}
+my $subs = &GetSubscription($subscriptionid);
+my ($routing, @routinglist) = getroutinglist($subscriptionid);
+my ($totalissues,@serialslist) = old_getserials($subscriptionid);
+$totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
+# the subscription must be deletable if there is NO issues for a reason or another (should not happend, but...)
+
+($template, $loggedinuser, $cookie)
+= get_template_and_user({template_name => "serials/subscription-detail.tmpl",
+                               query => $query,
+                               type => "intranet",
+                               authnotrequired => 0,
+                               flagsrequired => {catalogue => 1},
+                               debug => 1,
+                               });
+
+my ($user, $cookie, $sessionID, $flags)
+       = checkauth($query, 0, {catalogue => 1}, "intranet");
+
+my $weekarrayjs='';
+my $count = 0;
+my ($year, $month, $day) = UnixDate("today", "%Y", "%m", "%d");
+my $firstday = Date_DayOfYear($month,$day,$year);
+my $wkno = Date_WeekOfYear($month,$day,$year,1); # week starting monday
+my $weekno = $wkno;
+for(my $i=$firstday;$i<($firstday+365);$i=$i+7){
+            $count = $i;
+            if($wkno > 52){$year++; $wkno=1;}
+            if($count>365){$count=$i-365;}
+            my ($y,$m,$d) = Date_NthDayOfYear($year,$count);
+            my $output = "$y-$m-$d";
+            $weekarrayjs .= "'Wk $wkno: ".format_date($output)."',";
+            $wkno++;
+    }
+chop($weekarrayjs);
+
+$template->param(
+        routing => $routing,
+       user => $subs->{auser},
+       librarian => $subs->{librarian},
+       aqbooksellerid => $subs->{aqbooksellerid},
+       aqbooksellername => $subs->{aqbooksellername},
+       cost => $subs->{cost},
+       aqbudgetid => $subs->{aqbudgetid},
+       bookfundid => $subs->{bookfundid},
+       startdate => format_date($subs->{startdate}),
+       firstacquidate => format_date($subs->{firstacquidate}),    
+       periodicity => $subs->{periodicity},
+       dow => $subs->{dow},
+        irregularity => $subs->{irregularity},
+       numberlength => $subs->{numberlength},
+       weeklength => $subs->{weeklength},
+       monthlength => $subs->{monthlength},
+        numberpattern => $subs->{numberpattern},
+       add1 => $subs->{add1},
+       every1 => $subs->{every1},
+       whenmorethan1 => $subs->{whenmorethan1},
+       innerloop1 => $subs->{innerloop1},
+       setto1 => $subs->{setto1},
+       lastvalue1 => $subs->{lastvalue1},
+       add2 => $subs->{add2},
+       every2 => $subs->{every2},
+       whenmorethan2 => $subs->{whenmorethan2},
+       setto2 => $subs->{setto2},
+       lastvalue2 => $subs->{lastvalue2},
+       innerloop2 => $subs->{innerloop2},
+       add3 => $subs->{add3},
+       every3 => $subs->{every3},
+       whenmorethan3 => $subs->{whenmorethan3},
+       setto3 => $subs->{setto3},
+       lastvalue3 => $subs->{lastvalue3},
+       innerloop3 => $subs->{innerloop3},
+        weekarrayjs => $weekarrayjs,
+       numberingmethod => $subs->{numberingmethod},
+       status => $subs->{status},
+       biblionumber => $subs->{biblionumber},
+       bibliotitle => $subs->{bibliotitle},
+        callnumber => $subs->{callnumber},
+       notes => $subs->{notes},
+       subscriptionid => $subs->{subscriptionid},
+       serialslist => \@serialslist,
+       totalissues => $totalissues,
+        hemisphere => $hemisphere,
+       );
+$template->param(
+                       "periodicity$subs->{periodicity}" => 1,
+                       "arrival$subs->{dow}" => 1,
+                        "numberpattern$subs->{numberpattern}" => 1,
+                       intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+                       intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), 
+                       );
+
+output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/serials/routing-preview.pl b/serials/routing-preview.pl
new file mode 100755 (executable)
index 0000000..755d9c9
--- /dev/null
@@ -0,0 +1,122 @@
+#!/usr/bin/perl
+
+# Routing Preview.pl script used to view a routing list after creation
+# lets one print out routing slip and create (in this instance) the heirarchy
+# of reserves for the serial
+use strict;
+use CGI;
+use C4::Koha;
+use C4::Auth;
+use C4::Date;
+use C4::Output;
+use C4::Acquisition;
+use C4::Reserves2;
+use C4::Circulation::Circ2;
+use C4::Interface::CGI::Output;
+use C4::Context;
+use HTML::Template;
+use C4::Search;
+use C4::Serials;
+
+my $query = new CGI;
+my $subscriptionid = $query->param('subscriptionid');
+my $issue = $query->param('issue');
+my $routingid;
+my $ok = $query->param('ok');
+my $edit = $query->param('edit');
+my $delete = $query->param('delete');
+my $dbh = C4::Context->dbh;
+
+if($delete){
+    delroutingmember($routingid,$subscriptionid);
+    my $sth = $dbh->prepare("UPDATE serial SET routingnotes = NULL WHERE subscriptionid = ?");
+    $sth->execute($subscriptionid);    
+    print $query->redirect("routing.pl?subscriptionid=$subscriptionid&op=new");    
+}
+
+if($edit){
+    print $query->redirect("routing.pl?subscriptionid=$subscriptionid");
+}
+    
+my ($routing, @routinglist) = getroutinglist($subscriptionid);
+my $subs = GetSubscription($subscriptionid);
+my ($count,@serials) = GetSerials($subscriptionid);
+my ($template, $loggedinuser, $cookie);
+
+if($ok){
+    my $env;
+    # get biblio information....
+    my $biblio = $subs->{'biblionumber'};
+    
+    # get existing reserves .....
+    my ($count,$reserves) = FindReserves($biblio);
+    my $totalcount = $count;
+    foreach my $res (@$reserves) {
+        if ($res->{'found'} eq 'W') {
+           $count--;
+        }
+    }
+    my ($count2,@bibitems) = bibitems($biblio);
+    my @itemresults = ItemInfo($env, $subs->{'biblionumber'}, 'intra');    
+    my $branch = $itemresults[0]->{'holdingbranch'};
+    my $const = 'o';
+    my $notes;
+    my $title = $subs->{'bibliotitle'};
+    for(my $i=0;$i<$routing;$i++){
+       my $sth = $dbh->prepare("SELECT * FROM reserves WHERE biblionumber = ? AND borrowernumber = ? 
+                                 AND cancellationdate is NULL AND (found <> 'F' or found is NULL)");
+        $sth->execute($biblio,$routinglist[$i]->{'borrowernumber'});
+        my $data = $sth->fetchrow_hashref;
+#      warn Dumper($data);
+#       warn "$routinglist[$i]->{'borrowernumber'} is the same as $data->{'borrowernumber'}";
+       if($routinglist[$i]->{'borrowernumber'} == $data->{'borrowernumber'}){
+           UpdateReserve($routinglist[$i]->{'ranking'},$biblio,$routinglist[$i]->{'borrowernumber'},$branch);
+        } else {
+            CreateReserve(\$env,$branch,$routinglist[$i]->{'borrowernumber'},$biblio,$const,\@bibitems,$routinglist[$i]->{'ranking'},$notes,$title);
+       }
+    }
+    
+    
+    ($template, $loggedinuser, $cookie)
+= get_template_and_user({template_name => "serials/routing-preview-slip.tmpl",
+                               query => $query,
+                               type => "intranet",
+                               authnotrequired => 0,
+                               flagsrequired => {catalogue => 1},
+                               debug => 1,
+                               });    
+} else {
+    ($template, $loggedinuser, $cookie)
+= get_template_and_user({template_name => "serials/routing-preview.tmpl",
+                               query => $query,
+                               type => "intranet",
+                               authnotrequired => 0,
+                               flagsrequired => {catalogue => 1},
+                               debug => 1,
+                               });
+}    
+
+# my $firstdate = "$serials[0]->{'serialseq'} ($serials[0]->{'planneddate'})";
+my @results;
+my $data;
+for(my $i=0;$i<$routing;$i++){
+    $data=borrdata('',$routinglist[$i]->{'borrowernumber'});
+    $data->{'location'}=$data->{'streetaddress'};
+    $data->{'name'}="$data->{'firstname'} $data->{'surname'}";
+    $data->{'routingid'}=$routinglist[$i]->{'routingid'};
+    $data->{'subscriptionid'}=$subscriptionid;
+    push(@results, $data);
+}
+
+my $routingnotes = $serials[0]->{'routingnotes'};
+$routingnotes =~ s/\n/\<br \/\>/g;
+  
+$template->param(
+    title => $subs->{'bibliotitle'},
+    issue => $issue,
+    subscriptionid => $subscriptionid,
+    memberloop => \@results,    
+    routingnotes => $routingnotes,
+    );
+
+        output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/serials/routing.pl b/serials/routing.pl
new file mode 100755 (executable)
index 0000000..52efd84
--- /dev/null
@@ -0,0 +1,124 @@
+#!/usr/bin/perl
+
+# Routing.pl script used to create a routing list for a serial subscription
+# In this instance it is in fact a setting up of a list of reserves for the item
+# where the hierarchical order can be changed on the fly and a routing list can be
+# printed out
+use strict;
+use CGI;
+use C4::Koha;
+use C4::Auth;
+use C4::Date;
+use C4::Output;
+use C4::Acquisition;
+use C4::Interface::CGI::Output;
+use C4::Context;
+use HTML::Template;
+use C4::Search;
+use C4::Serials;
+
+my $query = new CGI;
+my $subscriptionid = $query->param('subscriptionid');
+my $serialseq = $query->param('serialseq');
+my $routingid = $query->param('routingid');
+my $bornum = $query->param('bornum');
+my $notes = $query->param('notes');
+my $op = $query->param('op');
+my $date_selected = $query->param('date_selected');
+my $dbh = C4::Context->dbh;
+
+if($op eq 'delete'){
+    delroutingmember($routingid,$subscriptionid);
+}
+
+if($op eq 'add'){
+    addroutingmember($bornum,$subscriptionid);
+}
+if($op eq 'save'){
+    my $sth = $dbh->prepare("UPDATE serial SET routingnotes = ? WHERE subscriptionid = ?");
+    $sth->execute($notes,$subscriptionid);
+    print $query->redirect("routing-preview.pl?subscriptionid=$subscriptionid&issue=$date_selected");
+}
+    
+my ($routing, @routinglist) = getroutinglist($subscriptionid);
+my $subs = GetSubscription($subscriptionid);
+my ($count,@serials) = old_getserials($subscriptionid);
+my ($serialdates) = GetLatestSerials($subscriptionid,$count);
+
+my @dates;
+my $i=0;
+foreach my $dateseq (@$serialdates) {
+        $dates[$i]->{'planneddate'} = $dateseq->{'planneddate'};
+        $dates[$i]->{'serialseq'} = $dateseq->{'serialseq'};
+        $dates[$i]->{'serialid'} = $dateseq->{'serialid'};
+        if($date_selected eq $dateseq->{'serialid'}){
+            $dates[$i]->{'selected'} = ' selected';
+        } else {
+            $dates[$i]->{'selected'} = '';
+        }
+        $i++;
+}
+
+my ($template, $loggedinuser, $cookie)
+= get_template_and_user({template_name => "serials/routing.tmpl",
+                               query => $query,
+                               type => "intranet",
+                               authnotrequired => 0,
+                               flagsrequired => {catalogue => 1},
+                               debug => 1,
+                               });
+# my $date;
+# if($serialseq){
+#    for(my $i = 0;$i<@serials; $i++){
+#      if($serials[$i]->{'serialseq'} eq $serialseq){
+#          $date = $serials[$i]->{'planneddate'}
+#      }
+#    }
+# } else {
+#    $serialseq = $serials[0]->{'serialseq'};
+#    $date = $serials[0]->{'planneddate'};
+# }
+
+# my $issue = "$serialseq ($date)";
+  
+my @results;
+my $data;
+for(my $i=0;$i<$routing;$i++){
+    $data=borrdata('',$routinglist[$i]->{'borrowernumber'});
+    $data->{'location'}=$data->{'streetaddress'};
+    $data->{'name'}="$data->{'firstname'} $data->{'surname'}";
+    $data->{'routingid'}=$routinglist[$i]->{'routingid'};
+    $data->{'subscriptionid'}=$subscriptionid;
+    my $rankingbox = '<select name="itemrank" onchange="reorder_item('.$subscriptionid.','.$routinglist[$i]->{'routingid'}.',this.options[this.selectedIndex].value)">';
+    for(my $j=1; $j <= $routing; $j++) {
+       $rankingbox .= "<option ";
+       if($routinglist[$i]->{'ranking'} == $j){
+           $rankingbox .= " selected='SELECTED'";
+       }
+       $rankingbox .= " value='$j'>$j</option>";
+    }
+    $rankingbox .= "</select>";
+    $data->{'routingbox'} = $rankingbox;
+    
+    push(@results, $data);
+}
+# warn Dumper(@results);
+# for adding routing list
+my $new;
+if ($op eq 'new') {
+    $new = 1;
+} else {
+# for modify routing list default
+    $new => 0;
+}
+
+$template->param(
+    title => $subs->{'bibliotitle'},
+    subscriptionid => $subscriptionid,
+    memberloop => \@results,    
+    op => $new,
+    dates => \@dates,
+    routingnotes => $serials[0]->{'routingnotes'},
+    );
+
+        output_html_with_http_headers $query, $cookie, $template->output;
index 1cb8507..ae341ac 100755 (executable)
@@ -54,6 +54,8 @@ use HTML::Template;
 my $query = new CGI;
 my $title = $query->param('title');
 my $ISSN = $query->param('ISSN');
+my $routing = $query->param('routing');
+my $searched = $query->param('searched');
 my $biblionumber = $query->param('biblionumber');
 my @subscriptions = GetSubscriptions($title,$ISSN,$biblionumber);
 my ($template, $loggedinuser, $cookie)
@@ -65,9 +67,20 @@ my ($template, $loggedinuser, $cookie)
                                debug => 1,
                                });
 
+# to toggle between create or edit routing list options
+if($routing){ 
+    for(my $i=0;$i<@subscriptions;$i++){
+       my $checkrouting = check_routing($subscriptions[$i]->{'subscriptionid'});
+       $subscriptions[$i]->{'routingedit'} = $checkrouting;
+       # warn "check $checkrouting";
+    }
+}
+
 $template->param(
        subscriptions => \@subscriptions,
        title => $title,
        ISSN => $ISSN,
+        done_searched => $searched,
+        routing => $routing,
        );
 output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/serials/statecollection.pl b/serials/statecollection.pl
new file mode 100755 (executable)
index 0000000..a97b333
--- /dev/null
@@ -0,0 +1,220 @@
+#!/usr/bin/perl
+
+use strict;
+use CGI;
+use C4::Auth;
+use C4::Date;
+use C4::Biblio;
+use C4::Koha;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Context;
+use C4::Serials;
+use HTML::Template;
+
+my $query = new CGI;
+my $op = $query->param('op');
+my $dbh = C4::Context->dbh;
+my $subscriptionid = $query->param('subscriptionid');
+# my $auser = $query->param('user');
+my $histstartdate = format_date_in_iso($query->param('histstartdate'));
+my $enddate = format_date_in_iso($query->param('enddate'));
+my $recievedlist = $query->param('recievedlist');
+my $missinglist = $query->param('missinglist');
+my $opacnote = $query->param('opacnote');
+my $librariannote = $query->param('librariannote');
+my @serialids = $query->param('serialid');
+my @serialseqs = $query->param('serialseq');
+my @planneddates = $query->param('planneddate');
+my @status = $query->param('status');
+my @notes = $query->param('notes');
+my @barcodes = $query->param('barcode');
+my @itemcallnumbers = $query->param('itemcallnumber');
+my @locations = $query->param('location');
+my @itemstatus = $query->param('itemstatus');
+my @homebranches = $query->param('branch');
+my $hassubscriptionexpired = HasSubscriptionExpired($subscriptionid);
+my $abouttoexpire = abouttoexpire($subscriptionid);
+
+my $subscription=GetSubscription($subscriptionid);
+my $auser = $subscription->{'librarian'}; # bob
+my $routing = check_routing($subscriptionid); # to see if routing list exists
+my $manualdate ='';
+my $manualissue ='';
+my $manualstatus =0;
+my $manualid ='';
+if ($op eq 'found'){
+    $manualdate = $query->param('planneddate');
+    $manualissue = $query->param('missingissue');
+    $manualstatus = 1;
+    my $sth = $dbh->prepare("select serialid from serial where subscriptionid = ? AND serialseq = ? AND planneddate = ?");
+    $sth->execute($subscriptionid,$manualissue,format_date_in_iso($manualdate));
+    $manualid = $sth->fetchrow;
+}
+
+if ($op eq 'modsubscriptionhistory') {
+       ModSubscriptionHistory($subscriptionid,$histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote);
+}
+
+# change status except, if subscription has expired, for the "waited" issue.
+if ($op eq 'serialchangestatus') {
+       my $sth = $dbh->prepare("select status from serial where serialid=?");
+       for (my $i=0;$i<=$#serialids;$i++) {
+               $sth->execute($serialids[$i]);
+               
+               my ($oldstatus) = $sth->fetchrow;
+               if ($serialids[$i]) {
+                       serialchangestatus($serialids[$i],$serialseqs[$i],format_date_in_iso($planneddates[$i]),$status[$i],$notes[$i]) unless ($hassubscriptionexpired && $oldstatus == 1);
+                       if (($status[$i]==2) && C4::Context->preference("serialsadditems")){
+                               my %info;
+                               $info{branch}=$homebranches[$i];
+                               $info{barcode}=$barcodes[$i];
+                               $info{itemcallnumber}=$itemcallnumbers[$i];
+                               $info{location}=$locations[$i];
+                               $info{status}=$itemstatus[$i];
+                               $info{notes}=$serialseqs[$i]." (".$planneddates[$i].")";
+                               my ($status2, @errors)= ItemizeSerials($serialids[$i],\%info);
+                               my $sth2 = $dbh->prepare("UPDATE subscriptionhistory SET lastbranch = ? WHERE subscriptionid = ?");
+                               $sth2->execute($homebranches[$i],$subscriptionid);
+                               $sth2->finish;                      
+                               # remove from missing list if item being checked in is on it
+                               if ($status2 ==1){
+                                   removeMissingIssue($serialseqs[$i],$subscriptionid);
+                               }                           
+                       }
+               } else {
+                       # add a special issue
+                       if ($serialseqs[$i]) {
+                               NewIssue($serialseqs[$i],$subscriptionid,$subscription->{biblionumber},$status[$i], format_date_in_iso($planneddates[$i]));
+                       }
+                       if (($status[$i]==2) && C4::Context->preference("serialsadditems") && !hassubscriptionexpired($subscriptionid)){
+                               my %info;
+                               $info{branch}=$homebranches[$i];
+                               $info{barcode}=$barcodes[$i];
+                               $info{itemcallnumber}=$itemcallnumbers[$i];
+                               $info{location}=$locations[$i];
+                               $info{status}=$itemstatus[$i];
+                               $info{notes}=$serialseqs[$i]." (".$planneddates[$i].")";
+                               my ($status2, @errors)= ItemizeSerials($serialids[$i],\%info);
+                               my $sth2 = $dbh->prepare("UPDATE subscriptionhistory SET lastbranch = ? WHERE subscriptionid = ?");
+                               $sth2->execute($homebranches[$i],$subscriptionid);
+                               $sth2->finish;
+                               # remove from missing list if item being checked in is on it
+                               if ($status2 ==1){
+                                   removeMissingIssue($serialseqs[$i],$subscriptionid);
+                               }
+                       }
+
+               }
+       }
+}
+my ($template, $loggedinuser, $cookie)
+= get_template_and_user({template_name => "serials/statecollection.tmpl",
+                               query => $query,
+                               type => "intranet",
+                               authnotrequired => 0,
+                               flagsrequired => {catalogue => 1},
+                               debug => 1,
+                               });
+
+my $subs = &GetSubscription($subscriptionid);
+my ($totalissues,@serialslist) = old_getserials($subscriptionid);
+my $count = @serialslist;
+for(my $i=0;$i<$count;$i++){
+    $serialslist[$i]->{'callnumber'} = $subscription->{'callnumber'};
+    my $temp = rand(10000000);
+    $serialslist[$i]->{'barcode'} = "TEMP" . sprintf("%.0f",$temp);
+}
+# use Data::Dumper;
+# warn Dumper(@serialslist);
+
+my $sth=$dbh->prepare("select * from subscriptionhistory where subscriptionid = ?");
+$sth->execute($subscriptionid);
+my $solhistory = $sth->fetchrow_hashref;
+
+if (C4::Context->preference("serialsadditems")){
+       my $bibid=MARCfind_MARCbibid_from_oldbiblionumber($dbh,$subscription->{biblionumber});
+       my $fwk=MARCfind_frameworkcode($dbh,$bibid);
+
+       my $branches = getbranches;
+       my @branchloop;
+       foreach my $thisbranch (keys %$branches) {
+           my $selected = 0;
+           if($thisbranch eq $solhistory->{'lastbranch'}){
+               $selected = 1;
+           }
+               my %row =(value => $thisbranch,
+                         branchname => $branches->{$thisbranch}->{'branchname'},
+                         selected => $selected,
+                               );
+               push @branchloop, \%row;
+       }
+       
+       my $itemstatushash = getitemstatus($fwk);
+       my @itemstatusloop;
+        my $itemstatusloopcount=0;    
+       foreach my $thisitemstatus (keys %$itemstatushash) {
+               my %row =(itemval => $thisitemstatus,
+                                       itemlib => $itemstatushash->{$thisitemstatus},
+                               );
+#              warn "".$row{'itemval'}.", ". $row{"itemlib"};
+               $itemstatusloopcount++;
+               push @itemstatusloop, \%row;
+       }
+       
+       my $itemlocationhash = getitemlocation($fwk);
+       my @itemlocationloop;
+       foreach my $thisitemlocation (keys %$itemlocationhash) {
+               my %row =(value => $thisitemlocation,
+                                       itemlocationname => $itemlocationhash->{$thisitemlocation},
+                               );
+               push @itemlocationloop, \%row;
+       }
+
+        my $choice = 0;
+        if($itemstatusloopcount == 1){ $choice = 1;}   
+        foreach my $data (@serialslist){
+               if (scalar(@itemstatusloop)){$data->{"itemstatusloop"}=\@itemstatusloop;}
+               else { $data->{"itemstatusloop"}=[];}
+               if (scalar(@itemlocationloop)){$data->{"itemlocationloop"}=\@itemlocationloop;}
+               else {$data->{"itemlocationloop"}=[];}
+               $data->{"branchloop"}=\@branchloop ;
+       }
+# warn "Choice: $choice";
+       $template->param(choice => $choice);    
+       $template->param(serialadditems =>C4::Context->preference("serialsadditems"),
+                                       branchloop => \@branchloop,
+                                       ) ;
+       $template->param(itemstatus=>1,itemstatusloop=>\@itemstatusloop) if (scalar(@itemstatusloop));
+       $template->param(itemlocation=>1,itemlocationloop=>\@itemlocationloop) if (scalar(@itemlocationloop));
+}else{
+       $template->param(branchloop=>[],itemstatusloop=>[],itemlocationloop=>[]) ;
+}
+       
+
+$template->param(
+                        user => $auser,
+                       serialslist => \@serialslist,
+                        count => $count,
+                       biblionumber => $subscription->{biblionumber},
+                       histstartdate => format_date($solhistory->{'histstartdate'}),
+                       enddate => format_date($solhistory->{'enddate'}),
+                       recievedlist => $solhistory->{'recievedlist'},
+                       missinglist => $solhistory->{'missinglist'},
+                       opacnote => $solhistory->{'opacnote'},
+                       librariannote => $solhistory->{'librariannote'},
+                       subscriptionid => $subscriptionid,
+                       bibliotitle => $subs->{bibliotitle},
+                       biblionumber => $subs->{biblionumber},
+                       hassubscriptionexpired =>$hassubscriptionexpired,
+                       abouttoexpire =>$abouttoexpire,    
+                       intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
+                       intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+                       IntranetNav => C4::Context->preference("IntranetNav"),
+                        routing => $routing,
+                        missingseq => $manualissue,
+                        frommissing => $manualstatus,
+                        missingdate => $manualdate,
+                        missingid => $manualid,
+               );
+output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/serials/subscription-copy.pl b/serials/subscription-copy.pl
new file mode 100755 (executable)
index 0000000..e1bc6e3
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+
+
+use strict;
+use CGI;
+use C4::Koha;
+use C4::Auth;
+use C4::Date;
+use C4::Output;
+use C4::Acquisition;
+use C4::Interface::CGI::Output;
+use C4::Context;
+use HTML::Template;
+use C4::Serials;
+use Date::Manip;
+
+my $query = new CGI;
+my $subscriptionid = $query->param('subscriptionid');
+my $dbh = C4::Context->dbh;
+# get old subscription
+my $subs = &GetSubscription($subscriptionid);
+
+# make newsubscription()
+my $subscriptionid =  old_newsubscription($subs->{'auser'},$subs->{'aqbooksellerid'},$subs->{'cost'},$subs->{'aqbudgetid'},
+           $subs->{'biblionumber'},$subs->{'startdate'},$subs->{'periodicity'},$subs->{'firstacquidate'},
+           $subs->{'dow'},$subs->{'irregularity'},$subs->{'numberpattern'},$subs->{'numberlength'},
+           $subs->{'weeklength'},$subs->{'monthlength'},$subs->{'add1'},$subs->{'every1'},
+           $subs->{'whenmorethan1'},$subs->{'setto1'},$subs->{'lastvalue1'},$subs->{'add2'},
+           $subs->{'every2'},$subs->{'whenmorethan2'},$subs->{'setto2'},$subs->{'lastvalue2'},$subs->{'add3'},
+           $subs->{'every3'},$subs->{'whenmorethan3'},$subs->{'setto3'},$subs->{'lastvalue3'},
+           $subs->{'numberingmethod'},$subs->{'status'},$subs->{'notes'},
+                               );
+print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
+
index 09e8349..127e47e 100755 (executable)
@@ -65,7 +65,7 @@ my $dbh = C4::Context->dbh;
 
 my $op = $query->param('op');
 my $subscriptionid = $query->param('subscriptionid');
-
+my $done = 0; # for after form has been submitted
 my ($template, $loggedinuser, $cookie)
         = get_template_and_user({template_name => "serials/subscription-renew.tmpl",
                 query => $query,
@@ -76,6 +76,7 @@ my ($template, $loggedinuser, $cookie)
                 });
 if ($op eq "renew") {
     ReNewSubscription($subscriptionid,$loggedinuser,$query->param('startdate'),$query->param('numberlength'),$query->param('weeklength'),$query->param('monthlength'),$query->param('note'));
+    $done = 1;
 }
 
 my $subscription= GetSubscription($subscriptionid);
@@ -87,6 +88,7 @@ $template->param(startdate => format_date(GetSubscriptionExpirationDate($subscri
                 subscriptionid => $subscriptionid,
                 bibliotitle => $subscription->{bibliotitle},
                 $op => 1,
+                done => $done,
                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
                 IntranetNav => C4::Context->preference("IntranetNav"),