| Lines 27-33
          use C4::Dates qw/format_date format_date_in_iso/;
      
      
        Link Here | 
        
          | 27 | use C4::Acquisition; | 27 | use C4::Acquisition; | 
        
          | 28 | use C4::Output; | 28 | use C4::Output; | 
        
          | 29 | use C4::Context; | 29 | use C4::Context; | 
          
            
              | 30 | use C4::Branch; # GetBranches | 30 | use C4::Branch;    # GetBranches | 
        
          | 31 | use C4::Serials; | 31 | use C4::Serials; | 
        
          | 32 | use C4::Letters; | 32 | use C4::Letters; | 
        
          | 33 | use Carp; | 33 | use Carp; | 
  
    | Lines 43-120
          my @budgets;
      
      
        Link Here | 
        
          | 43 |  | 43 |  | 
        
          | 44 | # Permission needed if it is a modification : edit_subscription | 44 | # Permission needed if it is a modification : edit_subscription | 
        
          | 45 | # Permission needed otherwise (nothing or dup) : create_subscription | 45 | # Permission needed otherwise (nothing or dup) : create_subscription | 
          
            
              | 46 | my $permission = ($op eq "modify") ? "edit_subscription" : "create_subscription"; | 46 | my $permission = | 
            
              | 47 |  | 47 |   ( $op eq "modify" ) ? "edit_subscription" : "create_subscription"; | 
            
              | 48 | my ($template, $loggedinuser, $cookie) |  |  | 
            
              | 49 | = get_template_and_user({template_name => "serials/subscription-add.tmpl", | 
            
              | 50 | 				query => $query, | 
            
              | 51 | 				type => "intranet", | 
            
              | 52 | 				authnotrequired => 0, | 
            
              | 53 | 				flagsrequired => {serials => $permission}, | 
            
              | 54 | 				debug => 1, | 
            
              | 55 | 				}); | 
            
              | 56 |  | 
        
          | 57 |  | 48 |  | 
            
              |  |  | 49 | my ( $template, $loggedinuser, $cookie ) = get_template_and_user( | 
            
              | 50 |     { | 
            
              | 51 |         template_name   => "serials/subscription-add.tmpl", | 
            
              | 52 |         query           => $query, | 
            
              | 53 |         type            => "intranet", | 
            
              | 54 |         authnotrequired => 0, | 
            
              | 55 |         flagsrequired   => { serials => $permission }, | 
            
              | 56 |         debug           => 1, | 
            
              | 57 |     } | 
            
              | 58 | ); | 
        
          | 58 |  | 59 |  | 
        
          | 59 | my $sub_on; | 60 | my $sub_on; | 
          
            
              | 60 | my @subscription_types = ( | 61 | my @subscription_types = ( 'issues', 'weeks', 'months' ); | 
            
              | 61 |             'issues', 'weeks', 'months' |  |  | 
            
              | 62 |         ); | 
        
          | 63 | my @sub_type_data; | 62 | my @sub_type_data; | 
        
          | 64 |  | 63 |  | 
        
          | 65 | my $subs; | 64 | my $subs; | 
        
          | 66 | our $firstissuedate; | 65 | our $firstissuedate; | 
        
          | 67 |  | 66 |  | 
          
            
              | 68 | if ($op eq 'modify' || $op eq 'dup' || $op eq 'modsubscription') { | 67 | if ( $op eq 'modify' || $op eq 'dup' || $op eq 'modsubscription' ) { | 
        
          | 69 |  | 68 |  | 
        
          | 70 |     my $subscriptionid = $query->param('subscriptionid'); | 69 |     my $subscriptionid = $query->param('subscriptionid'); | 
        
          | 71 |     $subs = GetSubscription($subscriptionid); | 70 |     $subs = GetSubscription($subscriptionid); | 
        
          | 72 | ## FIXME : Check rights to edit if mod. Could/Should display an error message. | 71 | ## FIXME : Check rights to edit if mod. Could/Should display an error message. | 
          
            
              | 73 |     if ($subs->{'cannotedit'} && $op eq 'modify'){ | 72 |     if ( $subs->{'cannotedit'} && $op eq 'modify' ) { | 
            
              | 74 |       carp "Attempt to modify subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed"; | 73 |         carp "Attempt to modify subscription $subscriptionid by " | 
            
              | 75 |       print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); | 74 |           . C4::Context->userenv->{'id'} | 
            
              |  |  | 75 |           . " not allowed"; | 
            
              | 76 |         print $query->redirect( | 
            
              | 77 | "/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid" | 
            
              | 78 |         ); | 
        
          | 76 |     } | 79 |     } | 
          
            
              | 77 |     $firstissuedate = $subs->{firstacquidate} || '';  # in iso format. | 80 |     $firstissuedate = $subs->{firstacquidate} || '';    # in iso format. | 
        
          | 78 |     for (qw(startdate firstacquidate histstartdate enddate histenddate)) { | 81 |     for (qw(startdate firstacquidate histstartdate enddate histenddate)) { | 
        
          | 79 |         next unless defined $subs->{$_}; | 82 |         next unless defined $subs->{$_}; | 
          
            
              | 80 | 	# TODO : Handle date formats properly. | 83 |  | 
            
              | 81 |          if ($subs->{$_} eq '0000-00-00') { | 84 |         # TODO : Handle date formats properly. | 
            
              | 82 |             $subs->{$_} = '' | 85 |         if ( $subs->{$_} eq '0000-00-00' ) { | 
            
              | 83 |     	} else { | 86 |             $subs->{$_} = ''; | 
            
              | 84 |             $subs->{$_} = format_date($subs->{$_}); |  |  | 
        
          | 85 |         } | 87 |         } | 
          
            
              | 86 | 	  } | 88 |         else { | 
            
              | 87 |       if (!defined $subs->{letter}) { | 89 |             $subs->{$_} = format_date( $subs->{$_} ); | 
            
              | 88 |           $subs->{letter}= q{}; | 90 |         } | 
            
              | 89 |       } | 91 |     } | 
            
              | 90 |     letter_loop($subs->{'letter'}, $template); | 92 |     if ( !defined $subs->{letter} ) { | 
            
              |  |  | 93 |         $subs->{letter} = q{}; | 
            
              | 94 |     } | 
            
              | 95 |     letter_loop( $subs->{'letter'}, $template ); | 
        
          | 91 |     my $nextexpected = GetNextExpected($subscriptionid); | 96 |     my $nextexpected = GetNextExpected($subscriptionid); | 
          
            
              | 92 |     $nextexpected->{'isfirstissue'} = $nextexpected->{planneddate}->output('iso') eq $firstissuedate ; | 97 |     $nextexpected->{'isfirstissue'} = | 
            
              | 93 |     $subs->{nextacquidate} = $nextexpected->{planneddate}->output()  if($op eq 'modify'); | 98 |       $nextexpected->{planneddate}->output('iso') eq $firstissuedate; | 
            
              | 94 |     unless($op eq 'modsubscription') { | 99 |     $subs->{nextacquidate} = $nextexpected->{planneddate}->output() | 
            
              |  |  | 100 |       if ( $op eq 'modify' ); | 
            
              | 101 |     unless ( $op eq 'modsubscription' ) { | 
        
          | 95 |         foreach my $length_unit (qw(numberlength weeklength monthlength)) { | 102 |         foreach my $length_unit (qw(numberlength weeklength monthlength)) { | 
          
            
              | 96 | 			if ($subs->{$length_unit}){ | 103 |             if ( $subs->{$length_unit} ) { | 
            
              | 97 | 				$sub_length=$subs->{$length_unit}; | 104 |                 $sub_length = $subs->{$length_unit}; | 
            
              | 98 | 				$sub_on=$length_unit; | 105 |                 $sub_on     = $length_unit; | 
            
              | 99 | 				last; | 106 |                 last; | 
            
              | 100 | 			} | 107 |             } | 
            
              | 101 | 		} | 108 |         } | 
        
          | 102 |  | 109 |  | 
        
          | 103 |         $template->param( %{$subs} ); | 110 |         $template->param( %{$subs} ); | 
          
            
              | 104 |         $template->param("dow".$subs->{'dow'} => 1) if defined $subs->{'dow'}; | 111 |         $template->param( "dow" . $subs->{'dow'} => 1 ) | 
            
              |  |  | 112 |           if defined $subs->{'dow'}; | 
        
          | 105 |         $template->param( | 113 |         $template->param( | 
          
            
              | 106 |                     $op => 1, | 114 |             $op               => 1, | 
            
              | 107 |                     "subtype_$sub_on" => 1, | 115 |             "subtype_$sub_on" => 1, | 
            
              | 108 |                     sublength =>$sub_length, | 116 |             sublength         => $sub_length, | 
            
              | 109 |                     history => ($op eq 'modify'), | 117 |             history => ( $op eq 'modify' ), | 
            
              | 110 |                     "periodicity".$subs->{'periodicity'} => 1, | 118 |             "periodicity" . $subs->{'periodicity'}     => 1, | 
            
              | 111 |                     "numberpattern".$subs->{'numberpattern'} => 1, | 119 |             "numberpattern" . $subs->{'numberpattern'} => 1, | 
            
              | 112 |                     firstacquiyear => substr($firstissuedate,0,4), | 120 |             firstacquiyear => substr( $firstissuedate, 0, 4 ), | 
            
              | 113 |                     ); | 121 |         ); | 
        
          | 114 |     } | 122 |     } | 
        
          | 115 |  | 123 |  | 
        
          | 116 |     if ( $op eq 'dup' ) { | 124 |     if ( $op eq 'dup' ) { | 
          
            
              | 117 |         my $dont_copy_fields = C4::Context->preference('SubscriptionDuplicateDroppedInput'); | 125 |         my $dont_copy_fields = | 
            
              |  |  | 126 |           C4::Context->preference('SubscriptionDuplicateDroppedInput'); | 
        
          | 118 |         my @fields_id = map { fieldid => $_ }, split '\|', $dont_copy_fields; | 127 |         my @fields_id = map { fieldid => $_ }, split '\|', $dont_copy_fields; | 
        
          | 119 |         $template->param( dont_export_field_loop => \@fields_id ); | 128 |         $template->param( dont_export_field_loop => \@fields_id ); | 
        
          | 120 |     } | 129 |     } | 
  
    | Lines 126-205
          my $onlymine=C4::Context->preference('IndependentBranches') &&
      
      
        Link Here | 
        
          | 126 |              C4::Context->userenv->{branch}; | 135 |              C4::Context->userenv->{branch}; | 
        
          | 127 | my $branches = GetBranches($onlymine); | 136 | my $branches = GetBranches($onlymine); | 
        
          | 128 | my $branchloop; | 137 | my $branchloop; | 
          
            
              | 129 | for my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %{$branches}) { | 138 | for my $thisbranch ( | 
            
              |  |  | 139 |     sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } | 
            
              | 140 |     keys %{$branches} ) | 
            
              | 141 | { | 
        
          | 130 |     my $selected = 0; | 142 |     my $selected = 0; | 
          
            
              | 131 |     $selected = 1 if (defined($subs) && $thisbranch eq $subs->{'branchcode'}); | 143 |     $selected = 1 if ( defined($subs) && $thisbranch eq $subs->{'branchcode'} ); | 
            
              | 132 |     push @{$branchloop}, { | 144 |     push @{$branchloop}, | 
            
              | 133 |         value => $thisbranch, | 145 |       { | 
            
              | 134 |         selected => $selected, | 146 |         value      => $thisbranch, | 
            
              |  |  | 147 |         selected   => $selected, | 
        
          | 135 |         branchname => $branches->{$thisbranch}->{'branchname'}, | 148 |         branchname => $branches->{$thisbranch}->{'branchname'}, | 
          
            
              | 136 |     }; | 149 |       }; | 
        
          | 137 | } | 150 | } | 
        
          | 138 |  | 151 |  | 
          
            
              | 139 | my $locations_loop = GetAuthorisedValues("LOC",$subs->{'location'}); | 152 | my $locations_loop = GetAuthorisedValues( "LOC", $subs->{'location'} ); | 
        
          | 140 |  | 153 |  | 
          
            
              | 141 | $template->param(branchloop => $branchloop, | 154 | $template->param( | 
            
              | 142 |     locations_loop=>$locations_loop, | 155 |     branchloop     => $branchloop, | 
            
              |  |  | 156 |     locations_loop => $locations_loop, | 
        
          | 143 | ); | 157 | ); | 
            
              |  |  | 158 |  | 
        
          | 144 | # prepare template variables common to all $op conditions: | 159 | # prepare template variables common to all $op conditions: | 
          
            
              | 145 | if ($op!~/^mod/) { | 160 | if ( $op !~ /^mod/ ) { | 
            
              | 146 |     letter_loop(q{}, $template); | 161 |     letter_loop( q{}, $template ); | 
        
          | 147 | } | 162 | } | 
        
          | 148 |  | 163 |  | 
          
            
              | 149 | if ($op eq 'addsubscription') { | 164 | if ( $op eq 'addsubscription' ) { | 
        
          | 150 |     redirect_add_subscription(); | 165 |     redirect_add_subscription(); | 
          
            
              | 151 | } elsif ($op eq 'modsubscription') { | 166 | } | 
            
              |  |  | 167 | elsif ( $op eq 'modsubscription' ) { | 
        
          | 152 |     redirect_mod_subscription(); | 168 |     redirect_mod_subscription(); | 
          
            
              | 153 | } else { | 169 | } | 
            
              | 154 |         while (@subscription_types) { | 170 | else { | 
            
              | 155 |            my $sub_type = shift @subscription_types; | 171 |     while (@subscription_types) { | 
            
              | 156 |            my %row = ( 'name' => $sub_type ); | 172 |         my $sub_type = shift @subscription_types; | 
            
              | 157 |            if ( defined $sub_on and $sub_on eq $sub_type ) { | 173 |         my %row = ( 'name' => $sub_type ); | 
            
              | 158 | 	     $row{'selected'} = ' selected'; | 174 |         if ( defined $sub_on and $sub_on eq $sub_type ) { | 
            
              | 159 |            } else { | 175 |             $row{'selected'} = ' selected'; | 
            
              | 160 | 	     $row{'selected'} = ''; |  |  | 
            
              | 161 |            } | 
            
              | 162 |            push( @sub_type_data, \%row ); | 
        
          | 163 |         } | 176 |         } | 
          
            
              | 164 |     $template->param(subtype => \@sub_type_data); | 177 |         else { | 
            
              |  |  | 178 |             $row{'selected'} = ''; | 
            
              | 179 |         } | 
            
              | 180 |         push( @sub_type_data, \%row ); | 
            
              | 181 |     } | 
            
              | 182 |     $template->param( subtype => \@sub_type_data ); | 
        
          | 165 |  | 183 |  | 
          
            
              | 166 |     letter_loop( '', $template ) if ($op ne 'modsubscription' && $op ne 'dup' && $op ne 'modify'); | 184 |     letter_loop( '', $template ) | 
            
              |  |  | 185 |       if ( $op ne 'modsubscription' && $op ne 'dup' && $op ne 'modify' ); | 
        
          | 167 |  | 186 |  | 
        
          | 168 |     my $new_biblionumber = $query->param('biblionumber_for_new_subscription'); | 187 |     my $new_biblionumber = $query->param('biblionumber_for_new_subscription'); | 
          
            
              | 169 |     if (defined $new_biblionumber) { | 188 |     if ( defined $new_biblionumber ) { | 
        
          | 170 |         my $bib = GetBiblioData($new_biblionumber); | 189 |         my $bib = GetBiblioData($new_biblionumber); | 
          
            
              | 171 |         if (defined $bib) { | 190 |         if ( defined $bib ) { | 
            
              | 172 |             $template->param(bibnum      => $new_biblionumber); | 191 |             $template->param( bibnum      => $new_biblionumber ); | 
            
              | 173 |             $template->param(bibliotitle => $bib->{title}); | 192 |             $template->param( bibliotitle => $bib->{title} ); | 
        
          | 174 |         } | 193 |         } | 
        
          | 175 |     } | 194 |     } | 
          
            
              | 176 |         $template->param((uc(C4::Context->preference("marcflavour"))) => 1); | 195 |     $template->param( ( uc( C4::Context->preference("marcflavour") ) ) => 1 ); | 
            
              | 177 | 	output_html_with_http_headers $query, $cookie, $template->output; | 196 |     output_html_with_http_headers $query, $cookie, $template->output; | 
        
          | 178 | } | 197 | } | 
        
          | 179 |  | 198 |  | 
        
          | 180 | sub letter_loop { | 199 | sub letter_loop { | 
          
            
              | 181 |     my ($selected_letter, $templte) = @_; | 200 |     my ( $selected_letter, $templte ) = @_; | 
        
          | 182 |     my $letters = GetLetters('serial'); | 201 |     my $letters = GetLetters('serial'); | 
        
          | 183 |     my $letterloop; | 202 |     my $letterloop; | 
          
            
              | 184 |     foreach my $thisletter (keys %{$letters}) { | 203 |     foreach my $thisletter ( keys %{$letters} ) { | 
            
              | 185 |         push @{$letterloop}, { | 204 |         push @{$letterloop}, | 
            
              | 186 |             value => $thisletter, | 205 |           { | 
            
              | 187 |             selected => $thisletter eq $selected_letter, | 206 |             value      => $thisletter, | 
            
              |  |  | 207 |             selected   => $thisletter eq $selected_letter, | 
        
          | 188 |             lettername => $letters->{$thisletter}, | 208 |             lettername => $letters->{$thisletter}, | 
          
            
              | 189 |         }; | 209 |           }; | 
        
          | 190 |     } | 210 |     } | 
          
            
              | 191 |     $templte->param(letterloop => $letterloop); | 211 |     $templte->param( letterloop => $letterloop ); | 
        
          | 192 |     return; | 212 |     return; | 
        
          | 193 | } | 213 | } | 
        
          | 194 |  | 214 |  | 
        
          | 195 | sub _get_sub_length { | 215 | sub _get_sub_length { | 
          
            
              | 196 |     my ($type, $length) = @_; | 216 |     my ( $type, $length ) = @_; | 
            
              | 197 |     return | 217 |     return ( | 
            
              | 198 |         ( | 218 |         $type eq 'numberlength' ? $length : 0, | 
            
              | 199 |             $type eq 'numberlength' ? $length : 0, | 219 |         $type eq 'weeklength'   ? $length : 0, | 
            
              | 200 |             $type eq 'weeklength'   ? $length : 0, | 220 |         $type eq 'monthlength'  ? $length : 0, | 
            
              | 201 |             $type eq 'monthlength'  ? $length : 0, | 221 |     ); | 
            
              | 202 |         ); |  |  | 
        
          | 203 | } | 222 | } | 
        
          | 204 |  | 223 |  | 
        
          | 205 | sub redirect_add_subscription { | 224 | sub redirect_add_subscription { | 
  
    | Lines 214-221
          sub redirect_add_subscription {
      
      
        Link Here | 
        
          | 214 |     my $numberpattern  = $query->param('numbering_pattern'); | 233 |     my $numberpattern  = $query->param('numbering_pattern'); | 
        
          | 215 |     my $graceperiod    = $query->param('graceperiod') || 0; | 234 |     my $graceperiod    = $query->param('graceperiod') || 0; | 
        
          | 216 |  | 235 |  | 
          
            
              | 217 |     my ( $numberlength, $weeklength, $monthlength ) | 236 |     my ( $numberlength, $weeklength, $monthlength ) = | 
            
              | 218 |         = _get_sub_length( $query->param('subtype'), $query->param('sublength') ); | 237 |       _get_sub_length( $query->param('subtype'), $query->param('sublength') ); | 
        
          | 219 |     my $add1              = $query->param('add1'); | 238 |     my $add1              = $query->param('add1'); | 
        
          | 220 |     my $every1            = $query->param('every1'); | 239 |     my $every1            = $query->param('every1'); | 
        
          | 221 |     my $whenmorethan1     = $query->param('whenmorethan1'); | 240 |     my $whenmorethan1     = $query->param('whenmorethan1'); | 
  
    | Lines 247-357
          sub redirect_add_subscription {
      
      
        Link Here | 
        
          | 247 |     my $staffdisplaycount = $query->param('staffdisplaycount'); | 266 |     my $staffdisplaycount = $query->param('staffdisplaycount'); | 
        
          | 248 |     my $opacdisplaycount  = $query->param('opacdisplaycount'); | 267 |     my $opacdisplaycount  = $query->param('opacdisplaycount'); | 
        
          | 249 |     my $location          = $query->param('location'); | 268 |     my $location          = $query->param('location'); | 
          
            
              | 250 |     my $startdate = format_date_in_iso( $query->param('startdate') ); | 269 |     my $startdate         = format_date_in_iso( $query->param('startdate') ); | 
            
              | 251 |     my $enddate = format_date_in_iso( $query->param('enddate') ); | 270 |     my $enddate           = format_date_in_iso( $query->param('enddate') ); | 
            
              | 252 |     my $firstacquidate  = format_date_in_iso($query->param('firstacquidate')); | 271 |     my $firstacquidate = format_date_in_iso( $query->param('firstacquidate') ); | 
            
              | 253 |     my $histenddate = format_date_in_iso($query->param('histenddate')); | 272 |     my $histenddate    = format_date_in_iso( $query->param('histenddate') ); | 
            
              | 254 |     my $histstartdate = format_date_in_iso($query->param('histstartdate')); | 273 |     my $histstartdate  = format_date_in_iso( $query->param('histstartdate') ); | 
            
              | 255 |     my $recievedlist = $query->param('recievedlist'); | 274 |     my $recievedlist   = $query->param('recievedlist'); | 
            
              | 256 |     my $missinglist = $query->param('missinglist'); | 275 |     my $missinglist    = $query->param('missinglist'); | 
            
              | 257 |     my $opacnote = $query->param('opacnote'); | 276 |     my $opacnote       = $query->param('opacnote'); | 
            
              | 258 |     my $librariannote = $query->param('librariannote'); | 277 |     my $librariannote  = $query->param('librariannote'); | 
            
              | 259 | 	my $subscriptionid = NewSubscription($auser,$branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber, | 278 |     my $subscriptionid = NewSubscription( | 
            
              | 260 | 					$startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength, | 279 |         $auser,           $branchcode, | 
            
              | 261 | 					$add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1, | 280 |         $aqbooksellerid,  $cost, | 
            
              | 262 | 					$add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2, | 281 |         $aqbudgetid,      $biblionumber, | 
            
              | 263 | 					$add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3, | 282 |         $startdate,       $periodicity, | 
            
              | 264 | 					$numberingmethod, $status, $notes,$letter,$firstacquidate,join(",",@irregularity), | 283 |         $dow,             $numberlength, | 
            
              | 265 |                     $numberpattern, $callnumber, $hemisphere,($manualhistory?$manualhistory:0),$internalnotes, | 284 |         $weeklength,      $monthlength, | 
            
              | 266 |                     $serialsadditems,$staffdisplaycount,$opacdisplaycount,$graceperiod,$location,$enddate | 285 |         $add1,            $every1, | 
            
              | 267 | 				); | 286 |         $whenmorethan1,   $setto1, | 
            
              | 268 |     ModSubscriptionHistory ($subscriptionid,$histstartdate,$histenddate,$recievedlist,$missinglist,$opacnote,$librariannote); | 287 |         $lastvalue1,      $innerloop1, | 
            
              | 269 |  | 288 |         $add2,            $every2, | 
            
              | 270 |     print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); | 289 |         $whenmorethan2,   $setto2, | 
            
              |  |  | 290 |         $lastvalue2,      $innerloop2, | 
            
              | 291 |         $add3,            $every3, | 
            
              | 292 |         $whenmorethan3,   $setto3, | 
            
              | 293 |         $lastvalue3,      $innerloop3, | 
            
              | 294 |         $numberingmethod, $status, | 
            
              | 295 |         $notes,           $letter, | 
            
              | 296 |         $firstacquidate, join( ",", @irregularity ), | 
            
              | 297 |         $numberpattern,  $callnumber, | 
            
              | 298 |         $hemisphere, ( $manualhistory ? $manualhistory : 0 ), | 
            
              | 299 |         $internalnotes,     $serialsadditems, | 
            
              | 300 |         $staffdisplaycount, $opacdisplaycount, | 
            
              | 301 |         $graceperiod,       $location, | 
            
              | 302 |         $enddate | 
            
              | 303 |     ); | 
            
              | 304 |     ModSubscriptionHistory( | 
            
              | 305 |         $subscriptionid, $histstartdate, $histenddate, $recievedlist, | 
            
              | 306 |         $missinglist,    $opacnote,      $librariannote | 
            
              | 307 |     ); | 
            
              | 308 |  | 
            
              | 309 |     print $query->redirect( | 
            
              | 310 | "/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid" | 
            
              | 311 |     ); | 
        
          | 271 |     return; | 312 |     return; | 
        
          | 272 | } | 313 | } | 
        
          | 273 |  | 314 |  | 
        
          | 274 | sub redirect_mod_subscription { | 315 | sub redirect_mod_subscription { | 
        
          | 275 |     my $subscriptionid = $query->param('subscriptionid'); | 316 |     my $subscriptionid = $query->param('subscriptionid'); | 
          
            
              | 276 | 	  my @irregularity = $query->param('irregularity_select'); | 317 |     my @irregularity   = $query->param('irregularity_select'); | 
            
              | 277 |     my $auser = $query->param('user'); | 318 |     my $auser          = $query->param('user'); | 
        
          | 278 |     my $librarian => $query->param('librarian'), | 319 |     my $librarian => $query->param('librarian'), | 
          
            
              | 279 |     my $branchcode = $query->param('branchcode'); | 320 |       my $branchcode   = $query->param('branchcode'); | 
            
              | 280 |     my $cost = $query->param('cost'); | 321 |     my $cost           = $query->param('cost'); | 
        
          | 281 |     my $aqbooksellerid = $query->param('aqbooksellerid'); | 322 |     my $aqbooksellerid = $query->param('aqbooksellerid'); | 
          
            
              | 282 |     my $biblionumber = $query->param('biblionumber'); | 323 |     my $biblionumber   = $query->param('biblionumber'); | 
            
              | 283 |     my $aqbudgetid = $query->param('aqbudgetid'); | 324 |     my $aqbudgetid     = $query->param('aqbudgetid'); | 
            
              | 284 |     my $startdate = format_date_in_iso($query->param('startdate')); | 325 |     my $startdate      = format_date_in_iso( $query->param('startdate') ); | 
            
              | 285 |     my $nextacquidate = $query->param('nextacquidate') ? | 326 |     my $nextacquidate = | 
            
              | 286 |                             format_date_in_iso($query->param('nextacquidate')): | 327 |       $query->param('nextacquidate') | 
            
              | 287 |                             format_date_in_iso($query->param('startdate')); | 328 |       ? format_date_in_iso( $query->param('nextacquidate') ) | 
            
              | 288 |     my $enddate = format_date_in_iso($query->param('enddate')); | 329 |       : format_date_in_iso( $query->param('startdate') ); | 
            
              |  |  | 330 |     my $enddate     = format_date_in_iso( $query->param('enddate') ); | 
        
          | 289 |     my $periodicity = $query->param('periodicity'); | 331 |     my $periodicity = $query->param('periodicity'); | 
          
            
              | 290 |     my $dow = $query->param('dow'); | 332 |     my $dow         = $query->param('dow'); | 
            
              | 291 |  | 333 |  | 
            
              | 292 |     my ($numberlength, $weeklength, $monthlength) | 334 |     my ( $numberlength, $weeklength, $monthlength ) = | 
            
              | 293 |         = _get_sub_length( $query->param('subtype'), $query->param('sublength') ); | 335 |       _get_sub_length( $query->param('subtype'), $query->param('sublength') ); | 
            
              | 294 |     my $numberpattern = $query->param('numbering_pattern'); | 336 |     my $numberpattern   = $query->param('numbering_pattern'); | 
            
              | 295 |     my $add1 = $query->param('add1'); | 337 |     my $add1            = $query->param('add1'); | 
            
              | 296 |     my $every1 = $query->param('every1'); | 338 |     my $every1          = $query->param('every1'); | 
            
              | 297 |     my $whenmorethan1 = $query->param('whenmorethan1'); | 339 |     my $whenmorethan1   = $query->param('whenmorethan1'); | 
            
              | 298 |     my $setto1 = $query->param('setto1'); | 340 |     my $setto1          = $query->param('setto1'); | 
            
              | 299 |     my $lastvalue1 = $query->param('lastvalue1'); | 341 |     my $lastvalue1      = $query->param('lastvalue1'); | 
            
              | 300 |     my $innerloop1 = $query->param('innerloop1'); | 342 |     my $innerloop1      = $query->param('innerloop1'); | 
            
              | 301 |     my $add2 = $query->param('add2'); | 343 |     my $add2            = $query->param('add2'); | 
            
              | 302 |     my $every2 = $query->param('every2'); | 344 |     my $every2          = $query->param('every2'); | 
            
              | 303 |     my $whenmorethan2 = $query->param('whenmorethan2'); | 345 |     my $whenmorethan2   = $query->param('whenmorethan2'); | 
            
              | 304 |     my $setto2 = $query->param('setto2'); | 346 |     my $setto2          = $query->param('setto2'); | 
            
              | 305 |     my $lastvalue2 = $query->param('lastvalue2'); | 347 |     my $lastvalue2      = $query->param('lastvalue2'); | 
            
              | 306 |     my $innerloop2 = $query->param('innerloop2'); | 348 |     my $innerloop2      = $query->param('innerloop2'); | 
            
              | 307 |     my $add3 = $query->param('add3'); | 349 |     my $add3            = $query->param('add3'); | 
            
              | 308 |     my $every3 = $query->param('every3'); | 350 |     my $every3          = $query->param('every3'); | 
            
              | 309 |     my $whenmorethan3 = $query->param('whenmorethan3'); | 351 |     my $whenmorethan3   = $query->param('whenmorethan3'); | 
            
              | 310 |     my $setto3 = $query->param('setto3'); | 352 |     my $setto3          = $query->param('setto3'); | 
            
              | 311 |     my $lastvalue3 = $query->param('lastvalue3'); | 353 |     my $lastvalue3      = $query->param('lastvalue3'); | 
            
              | 312 |     my $innerloop3 = $query->param('innerloop3'); | 354 |     my $innerloop3      = $query->param('innerloop3'); | 
        
          | 313 |     my $numberingmethod = $query->param('numberingmethod'); | 355 |     my $numberingmethod = $query->param('numberingmethod'); | 
          
            
              | 314 |     my $status = 1; | 356 |     my $status          = 1; | 
            
              | 315 |     my $callnumber = $query->param('callnumber'); | 357 |     my $callnumber      = $query->param('callnumber'); | 
            
              | 316 |     my $notes = $query->param('notes'); | 358 |     my $notes           = $query->param('notes'); | 
            
              | 317 |     my $internalnotes = $query->param('internalnotes'); | 359 |     my $internalnotes   = $query->param('internalnotes'); | 
            
              | 318 |     my $hemisphere = $query->param('hemisphere'); | 360 |     my $hemisphere      = $query->param('hemisphere'); | 
            
              | 319 |     my $letter = $query->param('letter'); | 361 |     my $letter          = $query->param('letter'); | 
            
              | 320 |     my $manualhistory = $query->param('manualhist'); | 362 |     my $manualhistory   = $query->param('manualhist'); | 
        
          | 321 |     my $serialsadditems = $query->param('serialsadditems'); | 363 |     my $serialsadditems = $query->param('serialsadditems'); | 
            
              |  |  | 364 |  | 
        
          | 322 |     # subscription history | 365 |     # subscription history | 
          
            
              | 323 |     my $histenddate = format_date_in_iso($query->param('histenddate')); | 366 |     my $histenddate   = format_date_in_iso( $query->param('histenddate') ); | 
            
              | 324 |     my $histstartdate = format_date_in_iso($query->param('histstartdate')); | 367 |     my $histstartdate = format_date_in_iso( $query->param('histstartdate') ); | 
            
              | 325 |     my $recievedlist = $query->param('recievedlist'); | 368 |     my $recievedlist  = $query->param('recievedlist'); | 
            
              | 326 |     my $missinglist = $query->param('missinglist'); | 369 |     my $missinglist   = $query->param('missinglist'); | 
            
              | 327 |     my $opacnote = $query->param('opacnote'); | 370 |     my $opacnote      = $query->param('opacnote'); | 
        
          | 328 |     my $librariannote = $query->param('librariannote'); | 371 |     my $librariannote = $query->param('librariannote'); | 
          
            
              | 329 | 	my $staffdisplaycount = $query->param('staffdisplaycount'); | 372 |     my $staffdisplaycount = $query->param('staffdisplaycount'); | 
            
              | 330 | 	my $opacdisplaycount = $query->param('opacdisplaycount'); | 373 |     my $opacdisplaycount  = $query->param('opacdisplaycount'); | 
            
              | 331 |     my $graceperiod     = $query->param('graceperiod') || 0; | 374 |     my $graceperiod       = $query->param('graceperiod') || 0; | 
            
              | 332 |     my $location = $query->param('location'); | 375 |     my $location          = $query->param('location'); | 
            
              | 333 |     my $nextexpected = GetNextExpected($subscriptionid); | 376 |     my $nextexpected      = GetNextExpected($subscriptionid); | 
            
              | 334 | 	#  If it's  a mod, we need to check the current 'expected' issue, and mod it in the serials table if necessary. | 377 |  | 
            
              |  |  | 378 | #  If it's  a mod, we need to check the current 'expected' issue, and mod it in the serials table if necessary. | 
        
          | 335 |     if ( $nextacquidate ne $nextexpected->{planneddate}->output('iso') ) { | 379 |     if ( $nextacquidate ne $nextexpected->{planneddate}->output('iso') ) { | 
          
            
              | 336 |         ModNextExpected($subscriptionid,C4::Dates->new($nextacquidate,'iso')); | 380 |         ModNextExpected( $subscriptionid, | 
            
              | 337 |         # if we have not received any issues yet, then we also must change the firstacquidate for the subs. | 381 |             C4::Dates->new( $nextacquidate, 'iso' ) ); | 
            
              | 338 |         $firstissuedate = $nextacquidate if($nextexpected->{isfirstissue}); | 382 |  | 
            
              |  |  | 383 | # if we have not received any issues yet, then we also must change the firstacquidate for the subs. | 
            
              | 384 |         $firstissuedate = $nextacquidate if ( $nextexpected->{isfirstissue} ); | 
        
          | 339 |     } | 385 |     } | 
        
          | 340 |  | 386 |  | 
          
            
              | 341 |         ModSubscription( | 387 |     ModSubscription( | 
            
              | 342 |             $auser,           $branchcode,   $aqbooksellerid, $cost, | 388 |         $auser,          $branchcode, | 
            
              | 343 |             $aqbudgetid,      $startdate,    $periodicity,    $firstissuedate, | 389 |         $aqbooksellerid, $cost, | 
            
              | 344 |             $dow,             join(q{,},@irregularity), $numberpattern,  $numberlength, | 390 |         $aqbudgetid,     $startdate, | 
            
              | 345 |             $weeklength,      $monthlength,  $add1,           $every1, | 391 |         $periodicity,    $firstissuedate, | 
            
              | 346 |             $whenmorethan1,   $setto1,       $lastvalue1,     $innerloop1, | 392 |         $dow,               join( q{,}, @irregularity ), | 
            
              | 347 |             $add2,            $every2,       $whenmorethan2,  $setto2, | 393 |         $numberpattern,     $numberlength, | 
            
              | 348 |             $lastvalue2,      $innerloop2,   $add3,           $every3, | 394 |         $weeklength,        $monthlength, | 
            
              | 349 |             $whenmorethan3,   $setto3,       $lastvalue3,     $innerloop3, | 395 |         $add1,              $every1, | 
            
              | 350 |             $numberingmethod, $status,       $biblionumber,   $callnumber, | 396 |         $whenmorethan1,     $setto1, | 
            
              | 351 |             $notes,           $letter,       $hemisphere,     $manualhistory,$internalnotes, | 397 |         $lastvalue1,        $innerloop1, | 
            
              | 352 |             $serialsadditems, $staffdisplaycount,$opacdisplaycount,$graceperiod,$location,$enddate,$subscriptionid | 398 |         $add2,              $every2, | 
            
              | 353 |         ); | 399 |         $whenmorethan2,     $setto2, | 
            
              | 354 |         ModSubscriptionHistory ($subscriptionid,$histstartdate,$histenddate,$recievedlist,$missinglist,$opacnote,$librariannote); | 400 |         $lastvalue2,        $innerloop2, | 
            
              | 355 |     print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); | 401 |         $add3,              $every3, | 
            
              |  |  | 402 |         $whenmorethan3,     $setto3, | 
            
              | 403 |         $lastvalue3,        $innerloop3, | 
            
              | 404 |         $numberingmethod,   $status, | 
            
              | 405 |         $biblionumber,      $callnumber, | 
            
              | 406 |         $notes,             $letter, | 
            
              | 407 |         $hemisphere,        $manualhistory, | 
            
              | 408 |         $internalnotes,     $serialsadditems, | 
            
              | 409 |         $staffdisplaycount, $opacdisplaycount, | 
            
              | 410 |         $graceperiod,       $location, | 
            
              | 411 |         $enddate,           $subscriptionid | 
            
              | 412 |     ); | 
            
              | 413 |     ModSubscriptionHistory( | 
            
              | 414 |         $subscriptionid, $histstartdate, $histenddate, $recievedlist, | 
            
              | 415 |         $missinglist,    $opacnote,      $librariannote | 
            
              | 416 |     ); | 
            
              | 417 |     print $query->redirect( | 
            
              | 418 | "/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid" | 
            
              | 419 |     ); | 
        
          | 356 |     return; | 420 |     return; | 
        
          | 357 | } | 421 | } | 
            
              | 358 | -  |  |  |