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

(-)a/C4/Serials.pm (+35 lines)
Lines 87-92 BEGIN { Link Here
87
      &CountIssues
87
      &CountIssues
88
      HasItems
88
      HasItems
89
      &subscriptionCurrentlyOnOrder
89
      &subscriptionCurrentlyOnOrder
90
      &GuessEnddate
90
91
91
    );
92
    );
92
}
93
}
Lines 2663-2668 sub findSerialsByStatus { Link Here
2663
    return @$serials;
2664
    return @$serials;
2664
}
2665
}
2665
2666
2667
=head2 GessEnddate
2668
2669
my $enddate = GessEnddate($startdate_iso $frequencyid, $numberlength, $weeklength, $monthlength);
2670
2671
=cut
2672
2673
sub GuessEnddate {
2674
    my ($startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength) = @_;
2675
    my ($year, $month, $day);
2676
    my $enddate;
2677
    if($numberlength != 0) {
2678
        my $frequency = GetSubscriptionFrequency($frequencyid);
2679
        if($frequency->{'unit'} eq 'day') {
2680
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
2681
        } elsif($frequency->{'unit'} eq 'week') {
2682
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
2683
        } elsif($frequency->{'unit'} eq 'month') {
2684
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
2685
        } elsif($frequency->{'unit'} eq 'year') {
2686
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0);
2687
        }
2688
    } elsif($weeklength != 0) {
2689
        ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $weeklength * 7);
2690
    } elsif($monthlength != 0) {
2691
        ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $monthlength);
2692
    }
2693
    if(defined $year) {
2694
        $enddate = sprintf("%04d-%02d-%02d", $year, $month, $day);
2695
    } else {
2696
        undef $enddate;
2697
    }
2698
    return $enddate;
2699
}
2700
2666
1;
2701
1;
2667
__END__
2702
__END__
2668
2703
(-)a/Koha/Subscription.pm (+22 lines)
Lines 221-226 sub permanent_irregularities { Link Here
221
    return split(';', $self->permanent_irregularity);
221
    return split(';', $self->permanent_irregularity);
222
}
222
}
223
223
224
=head3 subtype
225
226
Return the length type (issues, weeks, months)
227
228
=cut
229
230
sub subtype {
231
    my ($self) = @_;
232
233
    if ($self->numberlength) {
234
        return 'issues';
235
    }
236
237
    if ($self->weeklength) {
238
        return 'weeks';
239
    }
240
241
    if ($self->monthlength) {
242
        return 'months';
243
    }
244
}
245
224
=head3 type
246
=head3 type
225
247
226
=cut
248
=cut
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (+1 lines)
Lines 558-563 fieldset.rows table { clear: none; margin: 0; } Link Here
558
558
559
        var BOOKSELLER_IDS = [% To.json( bookseller_ids ) || '[]' | $raw %];
559
        var BOOKSELLER_IDS = [% To.json( bookseller_ids ) || '[]' | $raw %];
560
    </script>
560
    </script>
561
    [% Asset.js("js/subscription.js") | $raw %]
561
    [% Asset.js("js/subscription-add.js") | $raw %]
562
    [% Asset.js("js/subscription-add.js") | $raw %]
562
    [% Asset.js("js/showpredictionpattern.js") | $raw %]
563
    [% Asset.js("js/showpredictionpattern.js") | $raw %]
563
[% END %]
564
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt (+39 lines)
Lines 1-3 Link Here
1
[% USE Asset %]
1
[% SET footerjs = 1 %]
2
[% SET footerjs = 1 %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
[% INCLUDE 'doc-head-open.inc' %]
3
[% IF subscription %]
4
[% IF subscription %]
Lines 28-33 Link Here
28
<form name="f" action="/cgi-bin/koha/serials/subscription-renew.pl" method="post">
29
<form name="f" action="/cgi-bin/koha/serials/subscription-renew.pl" method="post">
29
		<input type="hidden" name="op" value="renew" />
30
		<input type="hidden" name="op" value="renew" />
30
		<input type="hidden" name="subscriptionid" value="[% subscription.subscriptionid | html %]" />
31
		<input type="hidden" name="subscriptionid" value="[% subscription.subscriptionid | html %]" />
32
        <input type="hidden" id="frequency" value="[% subscription.periodicity | html %]" />
33
        <input type="hidden" id="acqui_date" value="[% subscription.firstacquidate | html %]" />
34
        <input type="hidden" id="nextacquidate" value="[% nextacquidate | html %]" />
35
36
        <input type="hidden" id="to" value="[% enddate | html %]" />
37
        <input type="hidden" id="subtype" value="[% subtype | html %]" />
38
        <input type="hidden" id="sublength" value="[% sublength | html %]" />
39
        <input type="hidden" id="numberingmethod" value="[% numberpattern.numberingmethod | html %]" />
40
        <input type="hidden" id="lastvalue1" value="[% subscription.lastvalue1 | html %]" />
41
        <input type="hidden" id="lastvalue2" value="[% subscription.lastvalue2 | html %]" />
42
        <input type="hidden" id="lastvalue3" value="[% subscription.lastvalue3 | html %]" />
43
        <input type="hidden" id="add1" value="[% numberpattern.add1 | html %]" />
44
        <input type="hidden" id="add2" value="[% numberpattern.add2 | html %]" />
45
        <input type="hidden" id="add3" value="[% numberpattern.add3 | html %]" />
46
        <input type="hidden" id="every1" value="[% numberpattern.every1 | html %]" />
47
        <input type="hidden" id="every2" value="[% numberpattern.every2 | html %]" />
48
        <input type="hidden" id="every3" value="[% numberpattern.every3 | html %]" />
49
        <input type="hidden" id="innerloop1" value="[% subscription.innerloop1 | html %]" />
50
        <input type="hidden" id="innerloop2" value="[% subscription.innerloop2 | html %]" />
51
        <input type="hidden" id="innerloop3" value="[% subscription.innerloop3 | html %]" />
52
        <input type="hidden" id="setto1" value="[% numberpattern.setto1 | html %]" />
53
        <input type="hidden" id="setto2" value="[% numberpattern.setto2 | html %]" />
54
        <input type="hidden" id="setto3" value="[% numberpattern.setto3 | html %]" />
55
        <input type="hidden" id="numbering1" value="[% numberpattern.numbering1 | html %]" />
56
        <input type="hidden" id="numbering2" value="[% numberpattern.numbering2 | html %]" />
57
        <input type="hidden" id="numbering3" value="[% numberpattern.numbering3 | html %]" />
58
        <input type="hidden" id="whenmorethan1" value="[% numberpattern.whenmorethan1 | html %]" />
59
        <input type="hidden" id="whenmorethan2" value="[% numberpattern.whenmorethan2 | html %]" />
60
        <input type="hidden" id="whenmorethan3" value="[% numberpattern.whenmorethan3 | html %]" />
61
        <input type="hidden" id="locale" value="[% subscription.locale | html %]" />
31
		<fieldset class="rows"><legend>Subscription renewal for [% subscription.bibliotitle | html %]</legend>
62
		<fieldset class="rows"><legend>Subscription renewal for [% subscription.bibliotitle | html %]</legend>
32
        <ol>
63
        <ol>
33
            <li>
64
            <li>
Lines 73-86 Link Here
73
104
74
    <li><label for="note">Note for the librarian that will manage your renewal request: </label>
105
    <li><label for="note">Note for the librarian that will manage your renewal request: </label>
75
		<textarea name="note" id="note" rows="5" cols="50"></textarea></li></ol></fieldset>
106
		<textarea name="note" id="note" rows="5" cols="50"></textarea></li></ol></fieldset>
107
        <li id="displayexample"></li>
76
		<fieldset class="action"><input type="submit" value="Submit" class="button" /></fieldset>
108
		<fieldset class="action"><input type="submit" value="Submit" class="button" /></fieldset>
109
77
</form>
110
</form>
78
[% END %]
111
[% END %]
79
112
80
[% MACRO jsinclude BLOCK %]
113
[% MACRO jsinclude BLOCK %]
81
    [% INCLUDE 'calendar.inc' %]
114
    [% INCLUDE 'calendar.inc' %]
82
    <script type="text/javascript">
115
    <script type="text/javascript">
116
        var subscriptionid = "[% subscription.subscriptionid %]";
117
        var irregularity = "[% subscription.irregularity %]";
118
        var more_than_one_serial = "[% more_than_one_serial %]";
83
        $(document).ready(function(){
119
        $(document).ready(function(){
120
            testPredictionPattern();
84
            $(".close").on("click", function(e){
121
            $(".close").on("click", function(e){
85
                e.preventDefault();
122
                e.preventDefault();
86
                window.opener.location.reload(false);
123
                window.opener.location.reload(false);
Lines 88-93 Link Here
88
            });
125
            });
89
        });
126
        });
90
    </script>
127
    </script>
128
    [% Asset.js("js/subscription.js") %]
129
    [% Asset.js("js/showpredictionpattern.js") %]
91
[% END %]
130
[% END %]
92
131
93
[% INCLUDE 'intranet-bottom.inc' popup_window=1 %]
132
[% INCLUDE 'intranet-bottom.inc' popup_window=1 %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/showpredictionpattern.js (-1 / +2 lines)
Lines 2-11 function Check_boxes(dow) { Link Here
2
    if($(":checkbox[data-dow='"+dow+"']:first").is(':checked')) {
2
    if($(":checkbox[data-dow='"+dow+"']:first").is(':checked')) {
3
        $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
3
        $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
4
            $(this).prop('checked', true);
4
            $(this).prop('checked', true);
5
            return false;
5
        });
6
        });
6
    } else {
7
    } else {
7
        $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
8
        $("#predictionst :checkbox[data-dow='"+dow+"']").each(function(){
8
            $(this).prop('checked', false);
9
            $(this).prop('checked', false);
10
            return false;
9
        });
11
        });
10
    }
12
    }
11
}
13
}
Lines 21-27 function Check_permanent_irregularities() { Link Here
21
    // So check them according to permanent irregularity
23
    // So check them according to permanent irregularity
22
    if (nothing_checked) {
24
    if (nothing_checked) {
23
        $(".skip").each(function() {
25
        $(".skip").each(function() {
24
            console.log('iciiiiiiiiiiiiii');
25
            if ($(this).is(':checked')) {
26
            if ($(this).is(':checked')) {
26
                Check_boxes( $(this).data("dow"));
27
                Check_boxes( $(this).data("dow"));
27
            }
28
            }
(-)a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js (-70 lines)
Lines 266-341 function restoreAdvancedPattern() { Link Here
266
    advancedpatternlocked = 1;
266
    advancedpatternlocked = 1;
267
}
267
}
268
268
269
function testPredictionPattern() {
270
    var frequencyid = $("#frequency").val();
271
    var acquidate;
272
    var error = 0;
273
    var error_msg = "";
274
    if(frequencyid == undefined || frequencyid == ""){
275
        error_msg += "- " + MSG_FREQUENCY_UNDEFINED + "\n";
276
        error ++;
277
    }
278
    acquidate = $("#acqui_date").val();
279
    if(acquidate == undefined || acquidate == ""){
280
        error_msg += "-" + MSG_PUB_DATE_UNDEFINED + "\n";
281
        error ++;
282
    }
283
    if( more_than_one_serial !== "" ){
284
        var nextacquidate = $("#nextacquidate").val();
285
        if(nextacquidate == undefined || nextacquidate == ""){
286
            error_msg += "-" + MSG_NEXT_ISSUE_UNDEFINED + "\n";
287
            error ++;
288
        }
289
    }
290
291
    if(error){
292
        alert( MSG_PATTERN_TEST_FAILED.format(error_msg) );
293
        return false;
294
    }
295
296
    var custompattern = 0;
297
    if(advancedpatternlocked == 0) {
298
        custompattern = 1;
299
    }
300
301
    var ajaxData = {
302
        'custompattern': custompattern,
303
        'firstacquidate': acquidate
304
    };
305
306
    if( subscriptionid !== "" ){
307
        ajaxData.subscriptionid = subscriptionid;
308
    }
309
    if( more_than_one_serial !== "" ){
310
        ajaxData.nextacquidate = nextacquidate;
311
    }
312
313
314
    var ajaxParams = [
315
        'to', 'subtype', 'sublength', 'frequency', 'numberingmethod',
316
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
317
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
318
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
319
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale',
320
        'sfdescription', 'unitsperissue', 'issuesperunit', 'unit'
321
    ];
322
    for(i in ajaxParams) {
323
        var param = ajaxParams[i];
324
        var value = $("#"+param).val();
325
        if(value.length > 0)
326
            ajaxData[param] = value;
327
    }
328
329
    $.ajax({
330
        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
331
        data: ajaxData,
332
        success: function(data) {
333
            showPredictionPatternTest( data );
334
            patternneedtobetested = 0;
335
        }
336
    });
337
}
338
339
function saveAdvancedPattern() {
269
function saveAdvancedPattern() {
340
    if ($("#patternname").val().length == 0) {
270
    if ($("#patternname").val().length == 0) {
341
        alert( MSG_PATTERN_NAME );
271
        alert( MSG_PATTERN_NAME );
(-)a/koha-tmpl/intranet-tmpl/prog/js/subscription.js (+72 lines)
Line 0 Link Here
1
2
var advancedpatternlocked;
3
4
function testPredictionPattern() {
5
    var frequencyid = $("#frequency").val();
6
    var acquidate;
7
    var error = 0;
8
    var error_msg = "";
9
    if(frequencyid == undefined || frequencyid == ""){
10
        error_msg += "- " + MSG_FREQUENCY_UNDEFINED + "\n";
11
        error ++;
12
    }
13
    acquidate = $("#acqui_date").val();
14
    if(acquidate == undefined || acquidate == ""){
15
        error_msg += "-" + MSG_PUB_DATE_UNDEFINED + "\n";
16
        error ++;
17
    }
18
    if( more_than_one_serial !== "" ){
19
        var nextacquidate = $("#nextacquidate").val();
20
        if(nextacquidate == undefined || nextacquidate == ""){
21
            error_msg += "-" + MSG_NEXT_ISSUE_UNDEFINED + "\n";
22
            error ++;
23
        }
24
    }
25
26
    if(error){
27
        alert( MSG_PATTERN_TEST_FAILED.format(error_msg) );
28
        return false;
29
    }
30
31
    var custompattern = 0;
32
    if(advancedpatternlocked == 0) {
33
        custompattern = 1;
34
    }
35
36
    var ajaxData = {
37
        'custompattern': custompattern,
38
        'firstacquidate': acquidate
39
    };
40
41
    if( subscriptionid !== "" ){
42
        ajaxData.subscriptionid = subscriptionid;
43
    }
44
    if( more_than_one_serial !== "" ){
45
        ajaxData.nextacquidate = nextacquidate;
46
    }
47
48
49
    var ajaxParams = [
50
        'to', 'subtype', 'sublength', 'frequency', 'numberingmethod',
51
        'lastvalue1', 'lastvalue2', 'lastvalue3', 'add1', 'add2', 'add3',
52
        'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3',
53
        'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3',
54
        'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale',
55
        'sfdescription', 'unitsperissue', 'issuesperunit', 'unit'
56
    ];
57
    for(i in ajaxParams) {
58
        var param = ajaxParams[i];
59
        var value = $("#"+param).val();
60
        if(value.length > 0)
61
            ajaxData[param] = value;
62
    }
63
64
    $.ajax({
65
        url:"/cgi-bin/koha/serials/showpredictionpattern.pl",
66
        data: ajaxData,
67
        success: function(data) {
68
            showPredictionPatternTest( data );
69
            patternneedtobetested = 0;
70
        }
71
    });
72
}
(-)a/serials/subscription-add.pl (-30 / +12 lines)
Lines 265-296 sub get_letter_loop { Link Here
265
    ];
265
    ];
266
}
266
}
267
267
268
sub _guess_enddate {
268
sub _get_sub_length {
269
    my ($startdate_iso, $frequencyid, $numberlength, $weeklength, $monthlength) = @_;
269
    my ($type, $length) = @_;
270
    my ($year, $month, $day);
270
    return
271
    my $enddate;
271
        (
272
    if($numberlength != 0) {
272
            $type eq 'issues' ? $length : 0,
273
        my $frequency = GetSubscriptionFrequency($frequencyid);
273
            $type eq 'weeks'   ? $length : 0,
274
        if($frequency->{'unit'} eq 'day') {
274
            $type eq 'months'  ? $length : 0,
275
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
275
        );
276
        } elsif($frequency->{'unit'} eq 'week') {
277
            ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $numberlength * 7 * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
278
        } elsif($frequency->{'unit'} eq 'month') {
279
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'});
280
        } elsif($frequency->{'unit'} eq 'year') {
281
            ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), $numberlength * $frequency->{'unitsperissue'} / $frequency->{'issuesperunit'}, 0);
282
        }
283
    } elsif($weeklength != 0) {
284
        ($year, $month, $day) = Add_Delta_Days(split(/-/, $startdate_iso), $weeklength * 7);
285
    } elsif($monthlength != 0) {
286
        ($year, $month, $day) = Add_Delta_YM(split(/-/, $startdate_iso), 0, $monthlength);
287
    }
288
    if(defined $year) {
289
        $enddate = sprintf("%04d-%02d-%02d", $year, $month, $day);
290
    } else {
291
        undef $enddate;
292
    }
293
    return $enddate;
294
}
276
}
295
277
296
sub redirect_add_subscription {
278
sub redirect_add_subscription {
Lines 356-364 sub redirect_add_subscription { Link Here
356
338
357
    if(!defined $enddate || $enddate eq '') {
339
    if(!defined $enddate || $enddate eq '') {
358
        if($subtype eq "issues") {
340
        if($subtype eq "issues") {
359
            $enddate = _guess_enddate($firstacquidate, $periodicity, $numberlength, $weeklength, $monthlength)
341
            $enddate = GuessEnddate($firstacquidate, $periodicity, $numberlength, $weeklength, $monthlength)
360
        } else {
342
        } else {
361
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength)
343
            $enddate = GuessEnddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength)
362
        }
344
        }
363
    }
345
    }
364
    my $subscriptionid = NewSubscription(
346
    my $subscriptionid = NewSubscription(
Lines 470-478 sub redirect_mod_subscription { Link Here
470
    # Guess end date
452
    # Guess end date
471
    if(!defined $enddate || $enddate eq '') {
453
    if(!defined $enddate || $enddate eq '') {
472
        if($subtype eq "issues") {
454
        if($subtype eq "issues") {
473
            $enddate = _guess_enddate($nextacquidate, $periodicity, $numberlength, $weeklength, $monthlength);
455
            $enddate = GuessEnddate($nextacquidate, $periodicity, $numberlength, $weeklength, $monthlength);
474
        } else {
456
        } else {
475
            $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength);
457
            $enddate = GuessEnddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength);
476
        }
458
        }
477
    }
459
    }
478
460
(-)a/serials/subscription-renew.pl (-4 / +46 lines)
Lines 53-58 use C4::Context; Link Here
53
use C4::Auth;
53
use C4::Auth;
54
use C4::Output;
54
use C4::Output;
55
use C4::Serials;
55
use C4::Serials;
56
use C4::Serials::Frequency;
57
use C4::Serials::Numberpattern;
58
use Date::Calc qw(Today Day_of_Year Week_of_Year Add_Delta_Days Add_Delta_YM);
56
use Koha::DateUtils;
59
use Koha::DateUtils;
57
60
58
my $query = new CGI;
61
my $query = new CGI;
Lines 83-88 if ( $op eq "renew" ) { Link Here
83
    # Make sure the subscription exists
86
    # Make sure the subscription exists
84
    my $subscription = GetSubscription( $subscriptionid );
87
    my $subscription = GetSubscription( $subscriptionid );
85
    output_and_exit( $query, $cookie, $template, 'unknown_subscription') unless $subscription;
88
    output_and_exit( $query, $cookie, $template, 'unknown_subscription') unless $subscription;
89
90
    my @permanent_irregularities = $query->param('permanent_irregularity');
91
    my @irregularities = $query->param('irregularity');
86
    my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } );
92
    my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } );
87
    ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
93
    ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength( $subtype, $sublength );
88
    ReNewSubscription(
94
    ReNewSubscription(
Lines 97-102 if ( $op eq "renew" ) { Link Here
97
            branchcode     => $branchcode
103
            branchcode     => $branchcode
98
        }
104
        }
99
    );
105
    );
106
107
    my $subscription = Koha::Subscriptions->find($subscriptionid);
108
    $subscription->permanent_irregularity(join(';', @permanent_irregularities));
109
    $subscription->irregularity(join(';', @irregularities));
110
    $subscription->store;
100
} elsif ( $op eq 'multi_renew' ) {
111
} elsif ( $op eq 'multi_renew' ) {
101
    for my $subscriptionid ( @subscriptionids ) {
112
    for my $subscriptionid ( @subscriptionids ) {
102
        my $subscription = GetSubscription( $subscriptionid );
113
        my $subscription = GetSubscription( $subscriptionid );
Lines 124-140 if ( $op eq "renew" ) { Link Here
124
    my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } )
135
    my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } )
125
        or output_pref( { dt => dt_from_string, dateonly => 1 } );
136
        or output_pref( { dt => dt_from_string, dateonly => 1 } );
126
137
138
    my ($serials_number) = GetSerials($subscriptionid);
139
    if ($serials_number > 1) {
140
        $template->param(more_than_one_serial => 1);
141
    }
142
143
    my $subscription_o = Koha::Subscriptions->find($subscription->{subscriptionid});
144
    my $subtype = $subscription_o->subtype;
145
    my $nextexpected = GetNextExpected($subscriptionid);
146
    my $enddate = GuessEnddate($subscription->{enddate} || dt_from_string,
147
                                 $subscription->{periodicity},
148
                                 $subscription->{numberlength},
149
                                 $subscription->{weeklength},
150
                                 $subscription->{monthlength});
151
152
    my $sub_length;
153
    foreach my $length_unit (qw(numberlength weeklength monthlength)) {
154
        if ($subscription->{$length_unit}) {
155
            $sub_length=$subscription->{$length_unit};
156
            last;
157
        }
158
    }
159
160
    my $numberpattern = GetSubscriptionNumberpattern($subscription->{numberpattern});
161
127
    $template->param(
162
    $template->param(
128
        startdate      => $newstartdate,
163
        startdate       => $newstartdate,
129
        subscription   => $subscription,
164
        subscription    => $subscription,
165
        numberpattern   => $numberpattern,
166
        startdate       => $newstartdate,
167
        nextacquidate   => $nextexpected->{planneddate},
168
        enddate         => $enddate,
169
        subtype         => $subtype,
170
        sublength       => $sub_length,
130
    );
171
    );
131
}
172
}
132
173
133
my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
174
my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
134
175
135
$template->param(
176
$template->param(
136
    op => $op,
177
    op          => $op,
137
    libraries      => $libraries,
178
    libraries   => $libraries,
179
    popup       => ($mode eq 'popup'),
138
);
180
);
139
181
140
output_html_with_http_headers $query, $cookie, $template->output;
182
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/t/db_dependent/Koha/Subscription.t (-2 / +38 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 10;
22
use Test::More tests => 11;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Subscription;
25
use Koha::Subscription;
Lines 106-111 subtest 'Koha::Subscription->frequency' => sub { Link Here
106
    is( $subscription->frequency->id, $frequency->id, 'Koha::Subscription->frequency should return the correct frequency' );
106
    is( $subscription->frequency->id, $frequency->id, 'Koha::Subscription->frequency should return the correct frequency' );
107
};
107
};
108
108
109
subtest 'Koha::Subscription::subtype' => sub {
110
    plan tests => 3;
111
112
    my $subs = $builder->build({
113
        source => 'Subscription',
114
        value => {
115
            numberlength => 7,
116
            weeklength => 0,
117
            monthlength => 0,
118
        }
119
    });
120
    my $subscription = Koha::Subscriptions->find($subs->{subscriptionid});
121
    is($subscription->subtype, 'issues', 'Subscription with numberlength has issues type');
122
123
    my $subs2 = $builder->build({
124
        source => 'Subscription',
125
        value => {
126
            numberlength => 0,
127
            weeklength => 52,
128
            monthlength => 0,
129
        }
130
    });
131
    my $subscription2 = Koha::Subscriptions->find($subs2->{subscriptionid});
132
    is($subscription2->subtype, 'weeks', 'Subscription with weeklength has weeks type');
133
134
    my $subs3 = $builder->build({
135
        source => 'Subscription',
136
        value => {
137
            numberlength => 0,
138
            weeklength => 0,
139
            monthlength => 12,
140
        }
141
    });
142
    my $subscription3 = Koha::Subscriptions->find($subs3->{subscriptionid});
143
    is($subscription3->subtype, 'months', 'Subscription with monthlength has months type');
144
};
145
109
my $nb_of_subs = Koha::Subscriptions->search->count;
146
my $nb_of_subs = Koha::Subscriptions->search->count;
110
my $biblio_1   = $builder->build( { source => 'Biblio' } );
147
my $biblio_1   = $builder->build( { source => 'Biblio' } );
111
my $bi_1       = $builder->build(
148
my $bi_1       = $builder->build(
112
- 

Return to bug 17656