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

(-)a/Koha/SharedContent.pm (-70 / +80 lines)
Lines 52-66 sub manaRequest { Link Here
52
        $mana_request->content( to_json($content) );
52
        $mana_request->content( to_json($content) );
53
    }
53
    }
54
54
55
    my $response  = $userAgent->request($mana_request);
55
    my $response = $userAgent->request($mana_request);
56
56
57
    eval { $result = from_json( $response->decoded_content, { utf8 => 1} ); };
57
    eval { $result = from_json( $response->decoded_content, { utf8 => 1} ); };
58
    $result->{code} = $response->code;
58
    $result->{code} = $response->code;
59
    if ( $@ ){
59
    if ( $@ ){
60
        $result->{msg} = $response->{_msg};
60
        $result->{msg} = $@;
61
    }
61
    }
62
    if ($response->is_error){
62
    if ($response->is_error){
63
        $result->{msg} = "An error occurred, mana server returned: ".$result->{msg};
63
        $result->{msg} = "An error occurred, mana server returned: " . $response->message;
64
    }
64
    }
65
    return $result ;
65
    return $result ;
66
}
66
}
Lines 70-90 sub manaRequest { Link Here
70
=cut
70
=cut
71
71
72
sub manaIncrementRequest {
72
sub manaIncrementRequest {
73
    my $resource = shift;
73
    return manaRequest(buildRequest('increment', @_));
74
    my $id       = shift;
75
    my $field    = shift;
76
    my $step     = shift;
77
    my $param;
78
    $param->{step} = $step || 1;
79
    $param->{id} = $id;
80
    $param->{resource} = $resource;
81
    $param = join '&',
82
       map { defined $param->{$_} ? $_ . "=" . $param->{$_} : () }
83
           keys %$param;
84
    my $url = "$MANA_IP/$resource/$id.json/increment/$field?$param";
85
    my $request = HTTP::Request->new( POST => $url );
86
87
    return manaRequest($request);
88
}
74
}
89
75
90
=head3 manaPostRequest
76
=head3 manaPostRequest
Lines 92-159 sub manaIncrementRequest { Link Here
92
=cut
78
=cut
93
79
94
sub manaPostRequest {
80
sub manaPostRequest {
95
    my $resource = shift;
81
    my ($lang, $loggedinuser, $resourceid, $resourcetype) = @_;
96
    my $content  = shift;
82
83
    my $content = prepareSharedData($lang, $loggedinuser, $resourceid, $resourcetype);
97
84
98
    my $url = "$MANA_IP/$resource.json";
85
    my $result = manaRequest(buildRequest('post', $resourcetype, $content));
99
    my $request = HTTP::Request->new( POST => $url );
100
86
101
    $content->{bulk_import} = 0;
87
    if ( $result and ($result->{code} eq "200" or $result->{code} eq "201") ) {
102
    my $json = to_json( $content, { utf8 => 1 } );
88
        my $packages = "Koha::".ucfirst($resourcetype)."s";
103
    $request->content($json);
89
        my $resource = $packages->find($resourceid);
104
    return manaRequest($request);
90
        eval { $resource->set( { mana_id => $result->{id} } )->store };
91
    }
92
    return $result;
105
}
93
}
106
94
107
=head3 manaShareInfos
95
=head3 prepareSharedData
108
96
109
=cut
97
=cut
110
98
111
sub manaShareInfos{
99
sub prepareSharedData {
112
    my ($query, $loggedinuser, $ressourceid, $ressourcetype) = @_;
100
    my ($lang, $loggedinuser, $ressourceid, $ressourcetype) = @_;
113
    my $mana_language;
101
    $lang ||= C4::Context->preference('language');
114
    if ( $query->param('mana_language') ) {
115
        $mana_language = $query->param('mana_language');
116
    }
117
    else {
118
        my $result = $mana_language = C4::Context->preference('language');
119
    }
120
102
121
    my $mana_email;
103
    my $mana_email;
122
    if ( $loggedinuser ne 0 ) {
104
    if ( $loggedinuser ne 0 ) {
123
        my $borrower = Koha::Patrons->find($loggedinuser);
105
        my $borrower = Koha::Patrons->find($loggedinuser);
124
        if ($borrower){
106
        $mana_email = $borrower->first_valid_email_address
125
            $mana_email = $borrower->email
107
            || Koha::Libraries->find( C4::Context->userenv->{'branch'} )->branchemail
126
              if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
127
            $mana_email = $borrower->emailpro
128
              if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
129
            $mana_email =
130
              Koha::Libraries->find( C4::Context->userenv->{'branch'} )->branchemail
131
              if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
132
        }
133
    }
108
    }
134
    $mana_email = C4::Context->preference('KohaAdminEmailAddress')
109
    $mana_email = C4::Context->preference('KohaAdminEmailAddress')
135
      if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
110
      if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) );
111
136
    my %versions = C4::Context::get_versions();
112
    my %versions = C4::Context::get_versions();
137
113
138
    my $mana_info = {
114
    my $mana_info = {
139
        language    => $mana_language,
115
        language    => $lang,
140
        kohaversion => $versions{'kohaVersion'},
116
        kohaversion => $versions{'kohaVersion'},
141
        exportemail => $mana_email
117
        exportemail => $mana_email
142
    };
118
    };
143
    my ($ressource, $ressource_mana_info);
119
120
    my $ressource_mana_info;
144
    my $packages = "Koha::".ucfirst($ressourcetype)."s";
121
    my $packages = "Koha::".ucfirst($ressourcetype)."s";
145
    my $package = "Koha::".ucfirst($ressourcetype);
122
    my $package = "Koha::".ucfirst($ressourcetype);
146
    $ressource_mana_info = $package->get_sharable_info($ressourceid);
123
    $ressource_mana_info = $package->get_sharable_info($ressourceid);
147
    $ressource_mana_info = { %$ressource_mana_info, %$mana_info };
124
    $ressource_mana_info = { %$ressource_mana_info, %$mana_info };
148
    $ressource = $packages->find($ressourceid);
149
150
    my $result = Koha::SharedContent::manaPostRequest( $ressourcetype,
151
        $ressource_mana_info );
152
125
153
    if ( $result and ($result->{code} eq "200" or $result->{code} eq "201") ) {
126
    return $ressource_mana_info;
154
       eval { $ressource->set( { mana_id => $result->{id} } )->store };
155
    }
156
    return $result;
157
}
127
}
158
128
159
=head3 manaGetRequestWithId
129
=head3 manaGetRequestWithId
Lines 161-173 sub manaShareInfos{ Link Here
161
=cut
131
=cut
162
132
163
sub manaGetRequestWithId {
133
sub manaGetRequestWithId {
164
    my $resource = shift;
134
    return manaRequest(buildRequest('getwithid', @_));
165
    my $id       = shift;
166
167
    my $url = "$MANA_IP/$resource/$id.json";
168
    my $request = HTTP::Request->new( GET => $url );
169
170
    return manaRequest($request);
171
}
135
}
172
136
173
=head3 manaGetRequest
137
=head3 manaGetRequest
Lines 175-190 sub manaGetRequestWithId { Link Here
175
=cut
139
=cut
176
140
177
sub manaGetRequest {
141
sub manaGetRequest {
178
    my $resource   = shift;
142
    return manaRequest(buildRequest('get', @_));
179
    my $parameters = shift;
143
}
144
145
=head3 buildRequest
180
146
181
    $parameters = join '&',
147
=cut
182
      map { defined $parameters->{$_} ? $_ . "=" . $parameters->{$_} : () }
148
183
      keys %$parameters;
149
sub buildRequest {
184
    my $url = "$MANA_IP/$resource.json?$parameters";
150
    my $type = shift;
185
    my $request = HTTP::Request->new( GET => $url );
151
    my $resource = shift;
186
152
187
    return manaRequest($request);
153
    if ( $type eq 'get' ) {
154
        my $params = shift;
155
        $params = join '&',
156
            map { defined $params->{$_} ? $_ . "=" . $params->{$_} : () }
157
            keys %$params;
158
        my $url = "$MANA_IP/$resource.json?$params";
159
        return HTTP::Request->new( GET => $url );
160
    }
161
162
    if ( $type eq 'getwithid' ) {
163
        my $id = shift;
164
165
        my $url = "$MANA_IP/$resource/$id.json";
166
        return HTTP::Request->new( GET => $url );
167
    }
168
169
    if ( $type eq 'post' ) {
170
        my $content  = shift;
171
172
        my $url = "$MANA_IP/$resource.json";
173
        my $request = HTTP::Request->new( POST => $url );
174
175
        $content->{bulk_import} = 0;
176
        my $json = to_json( $content, { utf8 => 1 } );
177
        $request->content($json);
178
179
        return $request;
180
    }
181
182
    if ( $type eq 'increment' ) {
183
        my $id       = shift;
184
        my $field    = shift;
185
        my $step     = shift;
186
        my $param;
187
188
        $param->{step} = $step || 1;
189
        $param->{id} = $id;
190
        $param->{resource} = $resource;
191
        $param = join '&',
192
           map { defined $param->{$_} ? $_ . "=" . $param->{$_} : () }
193
               keys %$param;
194
        my $url = "$MANA_IP/$resource/$id.json/increment/$field?$param";
195
        my $request = HTTP::Request->new( POST => $url );
196
197
    }
188
}
198
}
189
199
190
1;
200
1;
(-)a/Koha/Subscription/Numberpatterns.pm (+32 lines)
Lines 52-57 sub uniqueLabel { Link Here
52
    return $label;
52
    return $label;
53
}
53
}
54
54
55
=head3 new_or_existing
56
57
=cut
58
59
sub new_or_existing {
60
    my ($self, $params) = @_;
61
62
    my $params_np;
63
    if ( $params->{'numbering_pattern'} eq 'mana' ) {
64
        foreach (qw/numberingmethod label1 add1 every1 whenmorethan1 setto1
65
                   numbering1 label2 add2 every2 whenmorethan2 setto2 numbering2
66
                   label3 add3 every3 whenmorethan3 setto3 numbering3/) {
67
            $params_np->{$_} = $params->{$_} if $params->{$_};
68
        }
69
70
        my $existing = Koha::Subscription::Numberpatterns->search($params_np)->next();
71
72
        if ($existing) {
73
            return $existing->id;
74
        }
75
76
        $params_np->{label} = Koha::Subscription::Numberpatterns->uniqueLabel($params->{'patternname'});
77
        $params_np->{description} = $params->{'sndescription'};
78
79
80
        my $subscription_np = Koha::Subscription::Numberpattern->new()->set($params_np)->store();
81
        return $subscription_np->id;
82
    }
83
84
    return $params->{'numbering_pattern'};
85
}
86
55
=head3 type
87
=head3 type
56
88
57
=cut
89
=cut
(-)a/debian/templates/koha-conf-site.xml.in (+3 lines)
Lines 269-274 __END_SRU_PUBLICSERVER__ Link Here
269
 <logdir>__LOG_DIR__</logdir>
269
 <logdir>__LOG_DIR__</logdir>
270
 <docdir>/usr/share/doc/koha-common</docdir>
270
 <docdir>/usr/share/doc/koha-common</docdir>
271
 <backupdir>/var/spool/koha/__KOHASITE__</backupdir>
271
 <backupdir>/var/spool/koha/__KOHASITE__</backupdir>
272
 <!-- URL of the mana KB server -->
273
 <!-- alternative value http://mana-test.koha-community.org to query the test server -->
274
 <mana_config>https://mana-kb.koha-community.org</mana_config>
272
 <!-- Enable the two following to allow superlibrarians to download
275
 <!-- Enable the two following to allow superlibrarians to download
273
      database and configuration dumps (respectively) from the Export
276
      database and configuration dumps (respectively) from the Export
274
      tool -->
277
      tool -->
(-)a/installer/data/mysql/sysprefs.sql (-1 lines)
Lines 258-264 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
258
('LocalHoldsPriorityPatronControl',  'PickupLibrary',  'HomeLibrary|PickupLibrary',  'decides if the feature operates using the library set as the patron''s home library, or the library set as the pickup library for the given hold.',  'Choice'),
258
('LocalHoldsPriorityPatronControl',  'PickupLibrary',  'HomeLibrary|PickupLibrary',  'decides if the feature operates using the library set as the patron''s home library, or the library set as the pickup library for the given hold.',  'Choice'),
259
('makePreviousSerialAvailable','0','','make previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item.','YesNo'),
259
('makePreviousSerialAvailable','0','','make previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item.','YesNo'),
260
('Mana','1',NULL,'request to Mana Webservice. Mana centralize commun information between other Koha to facilitate the creation of new subscriptions, vendors, report queries etc... You can search, share, import and comment the content of Mana.','YesNo'),
260
('Mana','1',NULL,'request to Mana Webservice. Mana centralize commun information between other Koha to facilitate the creation of new subscriptions, vendors, report queries etc... You can search, share, import and comment the content of Mana.','YesNo'),
261
('hide_marc','0',NULL,'If ON, disables display of MARC fields, subfield codes & indicators (still shows data)','YesNo'),
262
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
261
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
263
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
262
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
264
('MarcFieldsToOrder','',NULL,'Set the mapping values for a new order line created from a MARC record in a staged file. In a YAML format.','textarea'),
263
('MarcFieldsToOrder','',NULL,'Set the mapping values for a new order line created from a MARC record in a staged file. In a YAML format.','textarea'),
(-)a/koha-tmpl/intranet-tmpl/lib/jquery/activatemana.js (-1 / +1 lines)
Lines 5-11 $(document).ready(function(){ Link Here
5
        var myemail = $("#email").val()
5
        var myemail = $("#email").val()
6
        $.ajax( {
6
        $.ajax( {
7
            type: "POST",
7
            type: "POST",
8
            url: "/cgi-bin/koha/svc/mana/getToken",
8
            url: "/cgi-bin/koha/svc/mana/token",
9
            data: { lastname: mylastname, firstname: myfirstname, email: myemail},
9
            data: { lastname: mylastname, firstname: myfirstname, email: myemail},
10
            dataType: "json",
10
            dataType: "json",
11
        })
11
        })
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc (-5 / +26 lines)
Lines 3-8 Link Here
3
[% USE AuthorisedValues %]
3
[% USE AuthorisedValues %]
4
[% USE Branches %]
4
[% USE Branches %]
5
5
6
<script type="text/javascript">
7
//<![CDATA[
8
$(document).ready(function() {
9
    $(document).on('click', 'button.mana-use', function() {
10
        id = $(this).attr('id');
11
        mana_use(id.substr(9));
12
    });
13
14
    $(document).on('change', 'select.mana-actions', function() {
15
        report_id = $(this).attr('id').substr(13);
16
        if ($(this).val() == 'other') {
17
            $('input#selected_id').val(report_id);
18
            $('#comment_box').modal('show');
19
        } else {
20
            comment_id = $(this).val();
21
            mana_increment(comment_id, 'resource_comment', 'nb');
22
        }
23
    });
24
});
25
//]]>
26
</script>
27
6
[% IF statuscode == "200" AND reports %]
28
[% IF statuscode == "200" AND reports %]
7
    <table id="mana_results_datatable" width=100%>
29
    <table id="mana_results_datatable" width=100%>
8
        <thead>
30
        <thead>
Lines 45-58 Link Here
45
67
46
                    [% UNLESS search_only %]
68
                    [% UNLESS search_only %]
47
                        <td>
69
                        <td>
48
                            <button onclick="mana_use([% report.id %])"> <i class="fa fa-inbox"></i> Use</button>
70
                            <button class="mana-use" id="mana-use-[% report.id %]"><i class="fa fa-inbox"></i> Use</button>
49
                            <input hidden type="text" id="selectedcomment">
71
                            <select class="mana-actions" id="mana-actions-[% report.id %]">
50
                            <select>
51
                                <option selected disabled>Report mistake</option>
72
                                <option selected disabled>Report mistake</option>
52
                                [% FOREACH comment IN report.comments %]
73
                                [% FOREACH comment IN report.comments %]
53
                                    <option class="actionreport1" value="[% comment.id %]" onclick="mana_increment('[% comment.id %]', 'resource_comment', 'nb')"> [% comment.message %] ([% comment.nb %])
74
                                    <option value="[% comment.id %]">[% comment.message %] ([% comment.nb %])</option>
54
                                [% END %]
75
                                [% END %]
55
                                    <option data-toggle="modal" onclick="($('#selected_id').val($('.rowid').val()))" data-target="#comment_box"> other
76
                                    <option>other</option>
56
                            </select>
77
                            </select>
57
                            <button hidden class="actionreport2" hidden> Cancel</button>
78
                            <button hidden class="actionreport2" hidden> Cancel</button>
58
                        </td>
79
                        </td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-subscription-search-result.inc (-5 / +25 lines)
Lines 3-8 Link Here
3
[% USE AuthorisedValues %]
3
[% USE AuthorisedValues %]
4
[% USE Branches %]
4
[% USE Branches %]
5
5
6
<script type="text/javascript">
7
//<![CDATA[
8
$(document).ready(function() {
9
    $(document).on('click', 'button.mana-use', function() {
10
        id = $(this).attr('id');
11
        mana_use(id.substr(9));
12
    });
13
14
    $(document).on('change', 'select.mana-actions', function() {
15
        report_id = $(this).attr('id').substr(13);
16
        if ($(this).val() == 'other') {
17
            $('input#selected_id').val(report_id);
18
            $('#comment_box').modal('show');
19
        } else {
20
            comment_id = $(this).val();
21
            mana_increment(comment_id, 'resource_comment', 'nb');
22
        }
23
    });
24
});
25
//]]>
26
</script>
6
27
7
[% IF statuscode == "200" %]
28
[% IF statuscode == "200" %]
8
    <table id="mana_results_datatable" width=100%>
29
    <table id="mana_results_datatable" width=100%>
Lines 43-56 Link Here
43
64
44
                        [% UNLESS search_only %]
65
                        [% UNLESS search_only %]
45
                            <td>
66
                            <td>
46
                                <button onclick="mana_use([% subscription.id %])"> <i class="fa fa-inbox"></i> Use</button>
67
                                <button class="mana-use" id="mana-use-[% subscription.id %]"><i class="fa fa-inbox"></i> Use</button>
47
                                <input hidden type="text" id="selectedcomment">
68
                                <select class="mana-actions" id="mana-actions-[% subscription.id %]">
48
                                <select>
49
                                    <option selected disabled>Report mistake</option>
69
                                    <option selected disabled>Report mistake</option>
50
                                    [% FOREACH comment IN subscription.comments %]
70
                                    [% FOREACH comment IN subscription.comments %]
51
                                        <option class="actionreport1" value="[% comment.id %]" onclick="mana_increment('[% comment.id %]', 'resource_comment', 'nb')"> [% comment.message %] ([% comment.nb %])
71
                                        <option value="[% comment.id %]"> [% comment.message %] ([% comment.nb %])</option>
52
                                    [% END %]
72
                                    [% END %]
53
                                        <option data-toggle="modal" onclick="($('#selected_id').val($('.rowid').val()))" data-target="#comment_box"> other
73
                                        <option>other</option>
54
                                </select>
74
                                </select>
55
                                <button hidden class="actionreport2" hidden> Cancel</button>
75
                                <button hidden class="actionreport2" hidden> Cancel</button>
56
                            </td>
76
                            </td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc (-2 / +2 lines)
Lines 109-115 Link Here
109
    function mana_increment(mana_id, resourcename, fieldvalue, stepvalue = 1){
109
    function mana_increment(mana_id, resourcename, fieldvalue, stepvalue = 1){
110
        $.ajax( {
110
        $.ajax( {
111
            type: "POST",
111
            type: "POST",
112
            url: "/cgi-bin/koha/svc/mana/addvaluetofield",
112
            url: "/cgi-bin/koha/svc/mana/increment",
113
            data: {id: mana_id, field: fieldvalue, resource: resourcename, step: stepvalue},
113
            data: {id: mana_id, field: fieldvalue, resource: resourcename, step: stepvalue},
114
            datatype: "json",
114
            datatype: "json",
115
        }).done( function() {
115
        }).done( function() {
Lines 144-150 Link Here
144
        })
144
        })
145
        .done( function( result ) {
145
        .done( function( result ) {
146
            $("#mana_search_result .modal-body").html(result);
146
            $("#mana_search_result .modal-body").html(result);
147
            $("#mana_search_result_label").text("Results from Mana Knowledge Base");
147
            $("#mana_search_result_label").text(_("Results from Mana Knowledge Base"));
148
            $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults,{
148
            $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults,{
149
                "sPaginationType":"four_button",
149
                "sPaginationType":"four_button",
150
                "autoWidth": false,
150
                "autoWidth": false,
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc (-2 / +41 lines)
Lines 1-4 Link Here
1
[% INCLUDE 'blocking_errors.inc' %]
1
[% INCLUDE 'blocking_errors.inc' %]
2
<script type="text/javascript">
3
    //<![CDATA[
4
5
    function confirm_close() {
6
        var is_confirmed = confirm(_("Are you sure you want to close this subscription?"));
7
        if (is_confirmed) {
8
            window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=close";
9
        }
10
    }
11
    function confirm_reopen() {
12
        var is_confirmed = confirm(_("Are you sure you want to reopen this subscription?"));
13
        if (is_confirmed) {
14
            window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=reopen";
15
        }
16
    }
17
18
     $(document).ready(function() {
19
        $("#deletesub").click(function(){
20
            confirm_deletion();
21
            return false;
22
        });
23
        $("#reopen").click(function(){
24
            confirm_reopen();
25
            return false;
26
        });
27
        $("#close").click(function(){
28
            confirm_close();
29
            return false;
30
        });
31
        $("#renew").click(function(){
32
            popup([% subscriptionid %]);
33
            return false;
34
        })
35
        $("#mana-subscription-share").click(function() {
36
            window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=share";
37
        });
38
     });
39
    //]]>
40
    </script>
2
[% IF subscriptionid and ( CAN_user_serials_edit_subscription || CAN_user_serials_create_subscription || CAN_user_serials_delete_subscription || CAN_user_serials_receive_serials ) %]
41
[% IF subscriptionid and ( CAN_user_serials_edit_subscription || CAN_user_serials_create_subscription || CAN_user_serials_delete_subscription || CAN_user_serials_receive_serials ) %]
3
    <div id="toolbar" class="btn-toolbar">
42
    <div id="toolbar" class="btn-toolbar">
4
        [% IF CAN_user_serials_create_subscription %]
43
        [% IF CAN_user_serials_create_subscription %]
Lines 11-17 Link Here
11
                [% IF one_language_enabled==0 or mana_id %]
50
                [% IF one_language_enabled==0 or mana_id %]
12
                    <div class="btn-group"><a data-toggle="modal" data-toggle="tooltip" title="Share the subscription with other librairies. Your email address will be associated to your sharing." data-target="#mana_share_modal" class="btn btn-default btn-sm"><i class="fa fa-share-alt"></i> Share</a></div>
51
                    <div class="btn-group"><a data-toggle="modal" data-toggle="tooltip" title="Share the subscription with other librairies. Your email address will be associated to your sharing." data-target="#mana_share_modal" class="btn btn-default btn-sm"><i class="fa fa-share-alt"></i> Share</a></div>
13
                [% ELSE %]
52
                [% ELSE %]
14
                    <div class="btn-group" data-toggle="tooltip" title="Share the subscription with other libraries. Your email address will be associated to your sharing."><a class="btn btn-default btn-sm" onclick="share()"><i class="fa fa-share-alt"></i> Share</a></div>
53
                    <div class="btn-group" id="mana-subscription-share" data-toggle="tooltip" title="Share the subscription with other libraries. Your email address will be associated to your sharing."><a class="btn btn-default btn-sm"><i class="fa fa-share-alt"></i> Share</a></div>
15
                [% END %]
54
                [% END %]
16
            [% END %]
55
            [% END %]
17
        [% END %]
56
        [% END %]
Lines 161-167 Link Here
161
                [% IF one_language_enabled==0 %]
200
                [% IF one_language_enabled==0 %]
162
                    <button type="submit" form="mana_share_form" class="btn btn-primary">Share</button>
201
                    <button type="submit" form="mana_share_form" class="btn btn-primary">Share</button>
163
                [% ELSE %]
202
                [% ELSE %]
164
                    <div class="btn-group"><a class="btn btn-primary" onclick="share()">Share</a></div>
203
                    <div class="btn-group" id="mana-subscription-share"><a class="btn btn-primary">Share</a></div>
165
                [% END %]
204
                [% END %]
166
            </div>
205
            </div>
167
        </div>
206
        </div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt (-5 / +5 lines)
Lines 430-436 canned reports and writing custom SQL reports.</p> Link Here
430
                [% IF one_language_enabled==0 %]
430
                [% IF one_language_enabled==0 %]
431
                    <button id="ManaShareButton" type="submit" form="mana_share_form" class="btn btn-primary">Share</button>
431
                    <button id="ManaShareButton" type="submit" form="mana_share_form" class="btn btn-primary">Share</button>
432
                [% ELSE %]
432
                [% ELSE %]
433
                    <div id="ManaShareButton" class="btn-group"><a class="btn btn-primary"'onclick="share()">Share</a></div>
433
                    <div id="ManaShareButton" class="btn-group"><a class="btn btn-primary">Share</a></div>
434
                [% END %]
434
                [% END %]
435
            </div>
435
            </div>
436
        </div>
436
        </div>
Lines 1104-1113 Sub report:<select name="subreport"> Link Here
1104
            }
1104
            }
1105
        }
1105
        }
1106
1106
1107
        function share() {
1108
            window.location="/cgi-bin/koha/reports/guided_reports.pl?phase=Save";
1109
        }
1110
1111
        $(document).ready(function(){
1107
        $(document).ready(function(){
1112
            $('#limit').change(function() {
1108
            $('#limit').change(function() {
1113
                $('#limitselect').submit();
1109
                $('#limitselect').submit();
Lines 1317-1322 Sub report:<select name="subreport"> Link Here
1317
            $(".delete").on("click",function(){
1313
            $(".delete").on("click",function(){
1318
                return confirmDelete(MSG_CONFIRM_DELETE);
1314
                return confirmDelete(MSG_CONFIRM_DELETE);
1319
            });
1315
            });
1316
1317
            $('div#ManaShareButton').click(function() {
1318
                window.location="/cgi-bin/koha/reports/guided_reports.pl?phase=Share";
1319
            });
1320
        });
1320
        });
1321
1321
1322
        function addColumn() {
1322
        function addColumn() {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (-1 / +1 lines)
Lines 488-494 width: 300px; /* not enough for IE7 apparently */ Link Here
488
                            <fieldset class="action">
488
                            <fieldset class="action">
489
                                <input type="button" id="subscription_add_previous" value="&lt;&lt; Previous" style="float:left;"/>
489
                                <input type="button" id="subscription_add_previous" value="&lt;&lt; Previous" style="float:left;"/>
490
                                <input id="testpatternbutton" type="button" value="Test prediction pattern" />
490
                                <input id="testpatternbutton" type="button" value="Test prediction pattern" />
491
                                <input type="submit" onclick="removeDisabledAttr()" value="Save subscription" style="float:right;" accesskey="w"/>
491
                                <input id="save-subscription" type="submit" value="Save subscription" style="float:right;" accesskey="w"/>
492
                            </fieldset>
492
                            </fieldset>
493
                        </div>
493
                        </div>
494
                    </div>
494
                    </div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt (-1 / +1 lines)
Lines 18-24 Link Here
18
   <div id="bd">
18
   <div id="bd">
19
	<div id="yui-main">
19
	<div id="yui-main">
20
	<div class="yui-b">
20
	<div class="yui-b">
21
    [% INCLUDE 'serials-toolbar.inc' mana_id = mana_id %]
21
    [% INCLUDE 'serials-toolbar.inc' %]
22
22
23
    <h1>Subscription for [% bibliotitle%] [% IF closed %](closed)[% END %]</h1>
23
    <h1>Subscription for [% bibliotitle%] [% IF closed %](closed)[% END %]</h1>
24
    [% IF ( abouttoexpire ) %]
24
    [% IF ( abouttoexpire ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js (-13 / +9 lines)
Lines 393-399 function show_page_2() { Link Here
393
}
393
}
394
394
395
function mana_search() {
395
function mana_search() {
396
    $("#mana_search").html("<p>Mana kb is being asked for your subscription..</p>");
396
    $("#mana_search").html("<p>" + _("Mana kb is being asked for your subscription..") + "</p>");
397
    $("#mana_search").show();
397
    $("#mana_search").show();
398
398
399
    $.ajax({
399
    $.ajax({
Lines 404-410 function mana_search() { Link Here
404
    })
404
    })
405
    .done( function( result ) {
405
    .done( function( result ) {
406
        $("#mana_search_result .modal-body").html(result);
406
        $("#mana_search_result .modal-body").html(result);
407
        $("#mana_search_result_label").text("Results from Mana Knowledge Base");
407
        $("#mana_search_result_label").text(_("Results from Mana Knowledge Base"));
408
        $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults, {
408
        $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults, {
409
            "sPaginationType": "four_button",
409
            "sPaginationType": "four_button",
410
            "order":[[4, "desc"], [5, "desc"]],
410
            "order":[[4, "desc"], [5, "desc"]],
Lines 419-428 function mana_search() { Link Here
419
            ]
419
            ]
420
        }));
420
        }));
421
        if( $("#mana_results_datatable").length && $("td.dataTables_empty").length == 0){
421
        if( $("#mana_results_datatable").length && $("td.dataTables_empty").length == 0){
422
            $("#mana_search").html("<p>Subscription found on Mana Knowledge Base:</p><p> <a style='cursor:pointer' data-toggle='modal' data-target='#mana_search_result'>Quick fill</a></p>");
422
            $("#mana_search").html("<p>" + _("Subscription found on Mana Knowledge Base:") + "</p><p> <a style='cursor:pointer' data-toggle='modal' data-target='#mana_search_result'>" + _("Quick fill") + "</a></p>");
423
        }
423
        }
424
        else if ( $("#mana_results_datatable").length ){
424
        else if ( $("#mana_results_datatable").length ){
425
            $("#mana_search").html("<p>No subscription found on Mana Knowledge Base :(</p><p> Please feel free to share you pattern with all others librarians once you are done</p>");
425
            $("#mana_search").html("<p>" + _("No subscription found on Mana Knowledge Base :(") + "</p><p>" + _(" Please feel free to share you pattern with all others librarians once you are done") + "</p>");
426
        }
426
        }
427
        else{
427
        else{
428
            $("#mana_search").html( result );
428
            $("#mana_search").html( result );
Lines 455-464 function mana_search() { Link Here
455
            mana_increment($("#selectedcomment").val(), 'resource_comment', 'nb', -1);
455
            mana_increment($("#selectedcomment").val(), 'resource_comment', 'nb', -1);
456
        });
456
        });
457
457
458
    }).fail(function(result){
458
    })
459
        console.log( msg );
460
        console.log( longmsg );
461
    });
462
}
459
}
463
460
464
function mana_comment( target_id, manamsg, resource_type ){
461
function mana_comment( target_id, manamsg, resource_type ){
Lines 473-479 function mana_comment( target_id, manamsg, resource_type ){ Link Here
473
function mana_increment(mana_id, resource, fieldvalue, stepvalue = 1){
470
function mana_increment(mana_id, resource, fieldvalue, stepvalue = 1){
474
    $.ajax( {
471
    $.ajax( {
475
        type: "POST",
472
        type: "POST",
476
        url: "/cgi-bin/koha/svc/mana/addvaluetofield",
473
        url: "/cgi-bin/koha/svc/mana/increment",
477
        data: {id: mana_id, resource: resource, field: fieldvalue, step: stepvalue},
474
        data: {id: mana_id, resource: resource, field: fieldvalue, step: stepvalue},
478
        datatype: "json",
475
        datatype: "json",
479
    })
476
    })
Lines 554-563 function mana_use(mana_id){ Link Here
554
    });
551
    });
555
}
552
}
556
553
557
function removeDisabledAttr() {
558
    $('select:disabled').removeAttr('disabled');
559
}
560
561
$(document).ready(function() {
554
$(document).ready(function() {
562
    mana_search();
555
    mana_search();
563
    $("#displayexample").hide();
556
    $("#displayexample").hide();
Lines 699-702 $(document).ready(function() { Link Here
699
        e.preventDefault();
692
        e.preventDefault();
700
        testPredictionPattern();
693
        testPredictionPattern();
701
    });
694
    });
695
    $('#save-subscription').on("click", function(e){
696
        $('select:disabled').removeAttr('disabled');
697
    });
702
});
698
});
(-)a/reports/guided_reports.pl (-2 / +2 lines)
Lines 181-187 elsif ( $phase eq 'Show SQL'){ Link Here
181
        'notes'      => $report->{notes},
181
        'notes'      => $report->{notes},
182
	'sql'     => $report->{savedsql},
182
	'sql'     => $report->{savedsql},
183
	'showsql' => 1,
183
	'showsql' => 1,
184
        'mana_success' => $input->param('mana_success'),
184
        'mana_success' => scalar $input->param('mana_success'),
185
    );
185
    );
186
}
186
}
187
187
Lines 658-664 elsif ( $phase eq 'Save Report' ) { Link Here
658
}
658
}
659
659
660
elsif ($phase eq 'Share'){
660
elsif ($phase eq 'Share'){
661
    my $result = Koha::SharedContent::manaShareInfos($input, $borrowernumber, $input->param('reportid'), 'report');
661
    my $result = Koha::SharedContent::manaPostRequest($input->param('mana_language'), $borrowernumber, scalar $input->param('reportid'), 'report');
662
    if ( $result ) {
662
    if ( $result ) {
663
        print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&manamsg=".$result->{msg});
663
        print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&manamsg=".$result->{msg});
664
    }else{
664
    }else{
(-)a/serials/subscription-add.pl (-44 / +18 lines)
Lines 289-323 sub _guess_enddate { Link Here
289
    return $enddate;
289
    return $enddate;
290
}
290
}
291
291
292
sub manage_subscription_numbering_pattern_id {
292
sub redirect_add_subscription {
293
    my $params;
293
    my $periodicity = $query->param('frequency');
294
    if ( $query->param('numbering_pattern') eq 'mana' ) {
294
    if ($periodicity eq 'mana') {
295
        foreach (qw/numberingmethod label1 add1 every1 whenmorethan1 setto1
296
                   numbering1 label2 add2 every2 whenmorethan2 setto2 numbering2
297
                   label3 add3 every3 whenmorethan3 setto3 numbering3/) {
298
            $params->{$_} = $query->param($_) if $query->param($_);
299
        }
300
301
        my $existing = Koha::Subscription::Numberpatterns->search($params)->next();
302
303
        if ($existing) {
304
            return $existing->id;
305
        }
306
307
        $params->{label} = Koha::Subscription::Numberpatterns->uniqueLabel($query->param('patternname'));
308
        $params->{description} = $query->param('sndescription');
309
310
311
        my $subscription_np = Koha::Subscription::Numberpattern->new()->set($params)->store();
312
        return $subscription_np->id;
313
    }
314
315
    return $query->param('numbering_pattern');
316
}
317
318
sub manage_subscription_frequencies_id {
319
    my $periodicity;
320
    if ( $query->param('frequency') eq 'mana' ) {
321
        my $subscription_freq = Koha::Subscription::Frequency->new()->set(
295
        my $subscription_freq = Koha::Subscription::Frequency->new()->set(
322
            {
296
            {
323
                description   => $query->param('sfdescription'),
297
                description   => $query->param('sfdescription'),
Lines 328-342 sub manage_subscription_frequencies_id { Link Here
328
        )->store();
302
        )->store();
329
        $periodicity = $subscription_freq->id;
303
        $periodicity = $subscription_freq->id;
330
    }
304
    }
331
    else {
305
    my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing($query->Vars);
332
        $periodicity = $query->param('frequency');
333
    }
334
    return $periodicity;
335
}
336
337
sub redirect_add_subscription {
338
    my $periodicity = manage_subscription_frequencies_id();
339
    my $numberpattern = manage_subscription_numbering_pattern_id();
340
306
341
    my $auser          = $query->param('user');
307
    my $auser          = $query->param('user');
342
    my $branchcode     = $query->param('branchcode');
308
    my $branchcode     = $query->param('branchcode');
Lines 378-386 sub redirect_add_subscription { Link Here
378
        $mana_id = $query->param('mana_id');
344
        $mana_id = $query->param('mana_id');
379
        Koha::SharedContent::manaIncrementRequest("subscription",$mana_id, "nbofusers");
345
        Koha::SharedContent::manaIncrementRequest("subscription",$mana_id, "nbofusers");
380
    }
346
    }
381
    else {
382
        $mana_id = undef;
383
    }
384
347
385
    my $startdate      = output_pref( { str => scalar $query->param('startdate'),      dateonly => 1, dateformat => 'iso' } );
348
    my $startdate      = output_pref( { str => scalar $query->param('startdate'),      dateonly => 1, dateformat => 'iso' } );
386
    my $enddate        = output_pref( { str => scalar $query->param('enddate'),        dateonly => 1, dateformat => 'iso' } );
349
    my $enddate        = output_pref( { str => scalar $query->param('enddate'),        dateonly => 1, dateformat => 'iso' } );
Lines 404-410 sub redirect_add_subscription { Link Here
404
        $skip_serialseq, $mana_id
367
        $skip_serialseq, $mana_id
405
    );
368
    );
406
    if ( (C4::Context->preference('Mana')) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){
369
    if ( (C4::Context->preference('Mana')) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){
407
        my $result = Koha::SharedContent::manaShareInfos( $query, $loggedinuser, $subscriptionid, 'subscription');
370
        my $result = Koha::SharedContent::manaPostRequest( $query->param('mana_language'), $loggedinuser, $subscriptionid, 'subscription');
408
        $template->param( mana_msg => $result->{msg} );
371
        $template->param( mana_msg => $result->{msg} );
409
    }
372
    }
410
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
373
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
Lines 434-441 sub redirect_mod_subscription { Link Here
434
        ? output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } )
397
        ? output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } )
435
        : $firstacquidate;
398
        : $firstacquidate;
436
399
437
    my $periodicity = manage_subscription_frequencies_id();
400
    my $periodicity = $query->param('frequency');
438
    my $numberpattern = manage_subscription_numbering_pattern_id();
401
    if ($periodicity eq 'mana') {
402
        my $subscription_freq = Koha::Subscription::Frequency->new()->set(
403
            {
404
                description   => $query->param('sfdescription'),
405
                unit          => $query->param('unit'),
406
                unitsperissue => $query->param('unitsperissue'),
407
                issuesperunit => $query->param('issuesperunit'),
408
            }
409
        )->store();
410
        $periodicity = $subscription_freq->id;
411
    }
412
    my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing($query->Vars);
439
413
440
    my $subtype = $query->param('subtype');
414
    my $subtype = $query->param('subtype');
441
    my $sublength = $query->param('sublength');
415
    my $sublength = $query->param('sublength');
(-)a/serials/subscription-detail.pl (-5 / +1 lines)
Lines 33-43 use Koha::Acquisition::Bookseller; Link Here
33
use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/;
33
use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/;
34
use Carp;
34
use Carp;
35
35
36
use LWP::UserAgent;
37
use Koha::SharedContent;
36
use Koha::SharedContent;
38
use Koha::Patrons;
39
use Koha::Subscriptions;
40
use Koha::Libraries;
41
37
42
my $query = new CGI;
38
my $query = new CGI;
43
my $op = $query->param('op') || q{};
39
my $op = $query->param('op') || q{};
Lines 100-106 if ($op eq 'del') { Link Here
100
    }
96
    }
101
}
97
}
102
elsif ( $op and $op eq "share" ) {
98
elsif ( $op and $op eq "share" ) {
103
    my $result = Koha::SharedContent::manaShareInfos($query, $loggedinuser, $subscriptionid, 'subscription');
99
    my $result = Koha::SharedContent::manaPostRequest($query->param('mana_language'), $loggedinuser, $subscriptionid, 'subscription');
104
    $template->param( mana_code => $result->{msg} );
100
    $template->param( mana_code => $result->{msg} );
105
    $subs->{mana_id} = $result->{id};
101
    $subs->{mana_id} = $result->{id};
106
}
102
}
(-)a/svc/mana/addvaluetofield (-1 / +7 lines)
Lines 38-42 my ( $auth_status, $sessionID ) = Link Here
38
if ( $auth_status ne "ok" ) {
38
if ( $auth_status ne "ok" ) {
39
    exit 0;
39
    exit 0;
40
}
40
}
41
my $result = Koha::SharedContent::manaIncrementRequest($input->param('resource'), $input->param('id'), $input->param('field'), $input->param('step') );
41
my $result = Koha::SharedContent::manaIncrementRequest(
42
    scalar $input->param('resource'),
43
    scalar $input->param('id'),
44
    scalar $input->param('field'),
45
    scalar $input->param('step')
46
);
47
42
return $result;
48
return $result;
(-)a/svc/mana/search (-1 / +5 lines)
Lines 39-45 if ( $auth_status ne "ok" ) { Link Here
39
}
39
}
40
40
41
my $templatename;
41
my $templatename;
42
$templatename = "mana/mana-".$input->param( "resource" )."-search-result.tt";
42
if ($input->param( "resource" ) eq 'report') {
43
    $templatename = "mana/mana-report-search-result.tt";
44
} else {
45
    $templatename = "mana/mana-subscription-search-result.tt";
46
}
43
47
44
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
48
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45
    {
49
    {
(-)a/svc/mana/share (-4 / +7 lines)
Lines 45-55 $content->{resource_id} = $input->param("resource_id"); Link Here
45
$content->{resource_type} = $input->param("resource");
45
$content->{resource_type} = $input->param("resource");
46
$content->{message} = $input->param("message");
46
$content->{message} = $input->param("message");
47
Koha::SharedContent::manaPostRequest('resource_comment', $content);
47
Koha::SharedContent::manaPostRequest('resource_comment', $content);
48
    my $package = "Koha::".ucfirst($input->param('resource'));
48
my $package = "Koha::".ucfirst($input->param('resource'));
49
    my $resource;
49
my $resource;
50
    my $result;
50
my $result;
51
eval{
51
eval{
52
    $result = Koha::SharedContent::manaGetRequestWithId($input->param('resource'), $input->param('id') );
52
    $result = Koha::SharedContent::manaGetRequestWithId(
53
        scalar $input->param('resource'),
54
        scalar $input->param('id')
55
    );
53
};
56
};
54
if ( $@ or $result->{code} == 500 ){
57
if ( $@ or $result->{code} == 500 ){
55
    $resource->{errmsg} =  "Error: mana access got broken, please try again later\n\n ( error: $@ )";
58
    $resource->{errmsg} =  "Error: mana access got broken, please try again later\n\n ( error: $@ )";
(-)a/svc/mana/use (-1 / +4 lines)
Lines 40-46 if ( $auth_status ne "ok" ) { Link Here
40
    exit 0;
40
    exit 0;
41
}
41
}
42
42
43
my $result = Koha::SharedContent::manaGetRequestWithId($input->param('resource'), $input->param('id') );
43
my $result = Koha::SharedContent::manaGetRequestWithId(
44
    scalar $input->param('resource'),
45
    scalar $input->param('id')
46
);
44
my $package = "Koha::".ucfirst($input->param('resource'));
47
my $package = "Koha::".ucfirst($input->param('resource'));
45
my $resource;
48
my $resource;
46
49
(-)a/t/db_dependent/Koha/SharedContent.t (-2 / +222 lines)
Lines 20-29 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
use Test::More tests => 1;
23
use t::lib::Mocks;
24
use Test::MockModule;
25
use Test::MockObject;
26
use Test::More tests => 43;
24
use Koha::Database;
27
use Koha::Database;
28
use Koha::Patrons;
29
use Koha::Subscriptions;
30
31
use HTTP::Status qw(:constants :is status_message);
25
32
26
use_ok('Koha::SharedContent');
33
use_ok('Koha::SharedContent');
27
34
28
my $schema = Koha::Database->new->schema;
35
my $schema = Koha::Database->new->schema;
29
$schema->storage->txn_begin;    # mode insertion
36
$schema->storage->txn_begin;
37
38
my $builder = t::lib::TestBuilder->new();
39
40
my $want_error = 0;
41
my $post_request = 0;
42
my $query = {};
43
44
$Koha::SharedContent::MANA_IP = 'https://foo.bar';
45
my $result = Koha::SharedContent::manaGetRequest('report', $query);
46
ok($result->{msg} =~ /Can\'t connect to foo.bar:443$/, 'Unable to connect');
47
is($result->{code}, 500, 'Code is 500');
48
49
my $ua = Test::MockModule->new('LWP::UserAgent');
50
$ua->mock('request', sub {
51
        return mock_response();
52
});
53
54
$want_error = 1;
55
$query = {query => 'foo', usecomments => 1};
56
$result = Koha::SharedContent::manaGetRequest('report', $query);
57
ok($result->{msg} =~ /^Error thrown by decoded_content/, 'Error in decoded_content');
58
is($result->{code}, 500, 'Code is 500');
59
60
$want_error = 0;
61
$query = {title => 'foo', usecomments => 1};
62
$result = Koha::SharedContent::manaGetRequest('subscription', $query);
63
is($result->{code}, 200, 'manaGetRequest success');
64
65
$result = Koha::SharedContent::manaGetRequestWithId('subscription', 23);
66
is($result->{code}, 200, 'manaGetRequestWithId success');
67
68
my $params = {
69
    title => 'The English historical review',
70
    issn => '0013-8266',
71
    ean => '',
72
    publishercode => 'Longman'
73
};
74
75
# Search a subscription.
76
my $request = Koha::SharedContent::buildRequest('get', 'subscription', $params);
77
is($request->method, 'GET', 'Get subscription - Method is get');
78
79
my %query = $request->uri->query_form;
80
is($query{title}, 'The English historical review', 'Check title');
81
is($query{issn}, '0013-8266', 'Check issn');
82
is($query{ean}, '', 'Check ean');
83
is($query{publishercode}, 'Longman', 'Check publisher');
84
85
is($request->uri->path, '/subscription.json', 'Path is subscription');
86
87
# Get a report by id.
88
$request = Koha::SharedContent::buildRequest('getwithid', 'report', 26);
89
is($request->method, 'GET', 'Get with id - Method is get');
90
91
is($request->uri->path, '/report/26.json', 'Path is report/26.json');
92
93
# Share a report.
94
my $content = {
95
    'kohaversion' => '17.06.00.008',
96
    'language' => 'fr-FR',
97
    'notes' => 'some notes',
98
    'report_group' => '',
99
    'exportemail' => 'xx@xx.com',
100
    'report_name' => 'A useless report',
101
    'savedsql' => 'SELECT * FROM ITEMS',
102
    'type' => undef
103
};
104
105
$request = Koha::SharedContent::buildRequest('post', 'report', $content);
106
is($request->method, 'POST', 'Share report - Method is post');
107
108
is($request->uri->path, '/report.json', 'Path is report.json');
109
110
# prepare shared data
111
my $loggedinuser = $builder->build({
112
    source => 'Borrower',
113
    value => {
114
        email => '',
115
        emailpro => '',
116
        B_email => ''
117
    }
118
});
119
120
my $library = $builder->build({
121
    source => 'Branch',
122
});
123
124
my $biblio = $builder->build({
125
    source => 'Biblio',
126
});
127
128
my $biblioitem = $builder->build({
129
    source => 'Biblioitem',
130
    value => {
131
        biblionumber => $biblio->{biblionumber}
132
    }
133
});
134
135
my $subscriptionFrequency = $builder->build({
136
    source => 'SubscriptionFrequency'
137
});
138
139
my $subscriptionNumberpattern = $builder->build({
140
    source => 'SubscriptionNumberpattern'
141
});
142
143
my $subscription = $builder->build({
144
    source => 'Subscription',
145
    value => {
146
        biblionumber => $biblio->{biblionumber},
147
        periodicity => $subscriptionFrequency->{id},
148
        numberpattern => $subscriptionNumberpattern->{id},
149
        mana_id => undef
150
    }
151
});
152
153
C4::Context->_new_userenv('xxx');
154
C4::Context->set_userenv(0,0,0,
155
    $loggedinuser->{firstname},
156
    $loggedinuser->{surname},
157
    $library->{branchcode},
158
    'Midway Public Library', '', '', '');
159
160
t::lib::Mocks::mock_preference('language', 'en');
161
162
$post_request = 1;
163
$result = Koha::SharedContent::manaPostRequest('en', $loggedinuser->{borrowernumber}, $subscription->{subscriptionid}, 'subscription');
164
is($result->{code}, 200, 'manaPostRequest success');
165
166
my $s = Koha::Subscriptions->find($subscription->{subscriptionid});
167
is($s->mana_id, 5, 'Mana id is set');
168
169
my $data = Koha::SharedContent::prepareSharedData(
170
    '',
171
    $loggedinuser->{borrowernumber},
172
    $subscription->{subscriptionid},
173
    'subscription'
174
);
175
176
is($data->{language}, 'en', 'Language is set to default');
177
my $branch = Koha::Libraries->find($library->{branchcode});
178
is($data->{exportemail}, $branch->branchemail, 'Email is set with the userenv branch one');
179
is($data->{title}, $biblio->{title}, 'Shared title');
180
is($data->{sfdescription}, $subscriptionFrequency->{description}, 'Shared sfdescription');
181
is($data->{unit}, $subscriptionFrequency->{unit}, 'Shared unit');
182
is($data->{unitsperissue}, $subscriptionFrequency->{unitsperissue}, 'Shared unitsperissue');
183
is($data->{issuesperunit}, $subscriptionFrequency->{issuesperunit}, 'Shared issuesperunit');
184
185
is($data->{label}, $subscriptionNumberpattern->{label}, 'Shared np label');
186
is($data->{sndescription}, $subscriptionNumberpattern->{description}, 'Shared np description');
187
is($data->{numberingmethod}, $subscriptionNumberpattern->{numberingmethod}, 'Shared numberingmethod');
188
is($data->{label1}, $subscriptionNumberpattern->{label1}, 'Shared label1');
189
is($data->{add1}, $subscriptionNumberpattern->{add1}, 'Shared add1');
190
is($data->{every1}, $subscriptionNumberpattern->{every1}, 'Shared every1');
191
is($data->{whenmorethan1}, $subscriptionNumberpattern->{whenmorethan1}, 'Shared whenmorethan1');
192
is($data->{setto1}, $subscriptionNumberpattern->{setto1}, 'Shared setto1');
193
is($data->{numbering1}, $subscriptionNumberpattern->{numbering1}, 'Shared numbering1');
194
is($data->{issn}, $biblioitem->{issn}, 'Shared ISSN');
195
is($data->{ean}, $biblioitem->{ean}, 'Shared EAN');
196
is($data->{publishercode}, $biblioitem->{publishercode}, 'Shared publishercode');
197
198
sub mock_response {
199
    my $response = Test::MockObject->new();
200
201
    if ($want_error) {
202
        $response->mock('code', sub {
203
            return 500;
204
        });
205
        $response->mock('is_error', sub {
206
            return 0;
207
        });
208
        $response->mock('decoded_content', sub {
209
            die 'Error thrown by decoded_content';
210
        });
211
    } elsif ( $post_request ) {
212
        $response->mock('code', sub {
213
            return 200;
214
        });
215
        $response->mock('is_error', sub {
216
            return 0;
217
        });
218
        $response->mock('decoded_content', sub {
219
            return '{"code": "200", "msg": "foo", "id": "5"}';
220
        });
221
    } else {
222
        $response->mock('code', sub {
223
            return 200;
224
        });
225
        $response->mock('is_error', sub {
226
            return 0;
227
        });
228
        $response->mock('decoded_content', sub {
229
            return '';
230
        });
231
    }
232
}
233
234
# Increment request.
235
$request = Koha::SharedContent::buildRequest('increment',
236
                                             'subscription',
237
                                             12,
238
                                             'foo');
239
240
is($request->method, 'POST', 'Increment subscription - Method is post');
241
242
%query = $request->uri->query_form;
243
is($query{id}, 12, 'Check id');
244
is($query{step}, 1, 'Step is default');
245
is($query{resource}, 'subscription', 'Check ressource');
246
247
is($request->uri->path, '/subscription/12.json/increment/foo', 'Path is subscription');
248
249
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Subscription/Numberpatterns.t (+97 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2017 BibLibre
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use t::lib::TestBuilder;
23
use Test::More tests => 6;
24
use Koha::Database;
25
26
use_ok('Koha::Subscription::Numberpatterns');
27
28
my $schema = Koha::Database->new->schema;
29
$schema->storage->txn_begin;
30
my $builder = t::lib::TestBuilder->new;
31
32
my $dbh = C4::Context->dbh;
33
$dbh->do('DELETE FROM subscription_numberpatterns');
34
35
my $numberpattern = $builder->build({
36
    source => 'SubscriptionNumberpattern',
37
    value => {
38
        label => 'Volume, Number, Issue',
39
        description => 'Volume Number Issue 1',
40
        numberingmethod => 'Vol.{X}, Number {Y}, Issue {Z}',
41
        label1 => 'Volume',
42
        add1 => '1',
43
        every1 => '48',
44
        whenmorethan1 => '99999',
45
        setto1 => '1',
46
        numbering1 => undef,
47
        label2 => 'Number',
48
        add2 => '1',
49
        every2 => '4',
50
        whenmorethan2 => '12',
51
        setto2 => '1',
52
        numbering2 => undef,
53
        label3 => 'Issue',
54
        add3 => '1',
55
        every3 => '1',
56
        whenmorethan3 => '4',
57
        setto3 => '1',
58
        numbering3 => undef
59
    }
60
});
61
62
my $search_ok = {
63
    umberingmethod => 'Vol.{X}, Number {Y}, Issue {Z}',
64
    label1 => 'Volume', add1 => '1', every1 => '48',
65
    whenmorethan1 => '99999', setto1 => '1',
66
    label2 => 'Number', add2 => '1', every2 => '4',
67
    whenmorethan2 => '12', setto2 => '1',
68
    label3 => 'Issue', add3 => '1', every3 => '1',
69
    whenmorethan3 => '4', setto3 => '1',
70
    numbering_pattern => 'mana'
71
};
72
73
my $number_pattern_id = Koha::Subscription::Numberpatterns->new_or_existing($search_ok);
74
is($number_pattern_id, $numberpattern->{id}, 'new_or_existing method should find the existing number pattern');
75
76
$number_pattern_id = Koha::Subscription::Numberpatterns->new_or_existing({numbering_pattern => 1});
77
is($number_pattern_id, 1, 'new_or_existing method should return passed numbering_pattern');
78
79
my $search_not_ok = {
80
    patternname => 'Number',
81
    sndescription => 'Simple Numbering method',
82
    numberingmethod => 'No.{X}',
83
    label1 => 'Number',
84
    add1 => 1,
85
    every1 => 1,
86
    whenmorethan1 => 99999,
87
    setto1 => 1,
88
    numbering_pattern => 'mana'
89
};
90
91
$number_pattern_id = Koha::Subscription::Numberpatterns->new_or_existing($search_not_ok);
92
my $new_number_pattern = Koha::Subscription::Numberpatterns->find($number_pattern_id);
93
is($new_number_pattern->label, 'Number');
94
is($new_number_pattern->description, 'Simple Numbering method');
95
is($new_number_pattern->numberingmethod, 'No.{X}');
96
97
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Serials/GetFictiveIssueNumber.t (-114 / +219 lines)
Lines 1-126 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use C4::Context;
3
# This test deals with GetFictiveIssueNumber (from C4::Serials)
4
use Test::More tests => 18;
4
5
use Modern::Perl;
5
use Modern::Perl;
6
use Test::More tests => 5;
7
8
use Koha::Database;
9
use C4::Serials;
10
use C4::Serials::Frequency;
6
11
12
my $schema  = Koha::Database->new->schema;
13
$schema->storage->txn_begin;
7
my $dbh = C4::Context->dbh;
14
my $dbh = C4::Context->dbh;
8
$dbh->{RaiseError} = 1;
9
$dbh->{AutoCommit} = 0;
10
15
11
use C4::Serials::Frequency;
16
subtest 'Tests for irregular frequency' => sub {
12
use C4::Serials;
17
    plan tests => 2;
13
18
14
# TEST CASE - 1 issue per day, no irregularities
19
    # Add a frequency
15
my $frequency = {
20
    my $freq_irr = AddSubscriptionFrequency({
16
    description   => "One issue per day",
21
        description => "Irregular",
17
    unit          => 'day',
22
        unit => undef,
18
    issuesperunit => 1,
23
    });
19
    unitsperissue => 1,
20
};
21
24
22
my $subscription = {
25
    # Test it
23
    firstacquidate     => '1970-01-01',
26
    my $subscription = {
24
    irregularity       => '',
27
        periodicity => $freq_irr,
25
    countissuesperunit => 1,
28
        firstacquidate => '1972-02-07',
26
};
29
    };
27
my $issueNumber;
30
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-12-31'), undef, 'Irregular: should be undef' );
28
31
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-12-31'), undef, 'Irregular: still undef' );
29
$issueNumber =
30
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
31
is( $issueNumber, '1' );
32
33
$issueNumber =
34
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
35
is( $issueNumber, '2' );
36
$issueNumber =
37
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
38
is( $issueNumber, '3' );
39
40
# TEST CASE - 2 issues per day, no irregularity
41
$frequency = {
42
    description   => "Two issues per day",
43
    unit          => 'day',
44
    issuesperunit => 2,
45
    unitsperissue => 1,
46
};
32
};
47
$subscription = {
33
48
    firstacquidate     => '1970-01-01',
34
subtest 'Tests for yearly frequencies' => sub {
49
    irregularity       => '',
35
    plan tests => 10;
50
    countissuesperunit => 1,
36
51
};
37
    # First add a few frequencies
52
$issueNumber =
38
    my $freq_1i_1y = AddSubscriptionFrequency({
53
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
39
        description => "1 issue per year",
54
is( $issueNumber, '1' );
40
        unit => 'year',
55
$issueNumber =
41
        issuesperunit => 1,
56
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
42
        unitsperissue => 1,
57
is( $issueNumber, '3' );
43
    });
58
$issueNumber =
44
    my $freq_1i_3y = AddSubscriptionFrequency({
59
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
45
        description => "1 issue per 3 years",
60
is( $issueNumber, '5' );
46
        unit => 'year',
61
47
        issuesperunit => 1,
62
$subscription->{countissuesperunit} = 2;
48
        unitsperissue => 3,
63
$issueNumber =
49
    });
64
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
50
    my $freq_5i_1y = AddSubscriptionFrequency({
65
is( $issueNumber, '2' );
51
        description => "5 issues per year",
66
$issueNumber =
52
        unit => 'year',
67
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
53
        issuesperunit => 5,
68
is( $issueNumber, '4' );
54
        unitsperissue => 1,
69
$issueNumber =
55
    });
70
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
56
    my $freq_366i_1y = AddSubscriptionFrequency({
71
is( $issueNumber, '6' );
57
        description => "366 issue per year",
72
58
        unit => 'year',
73
# TEST CASE - 1 issue every 2 days, no irregularity
59
        issuesperunit => 366,
74
$frequency = {
60
        unitsperissue => 1,
75
    description   => "one issue every two days",
61
    });
76
    unit          => 'day',
62
77
    issuesperunit => 1,
63
    # TEST CASE - 1 issue per year
78
    unitsperissue => 2,
64
    my $subscription = {
65
        periodicity => $freq_1i_1y,
66
        firstacquidate => '1972-02-10',
67
        countissuesperunit => 1,
68
    };
69
70
    my $frequency = GetSubscriptionFrequency($freq_1i_1y);
71
72
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-09', $frequency), 1, 'Feb 9 still 1' );
73
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-10', $frequency), 2, 'Feb 10 goes to 2' );
74
75
    # TEST CASE - 1 issue per 3 years
76
    $subscription->{periodicity} = $freq_1i_3y;
77
    $subscription->{firstacquidate} = '1972-02-20';
78
    $frequency = GetSubscriptionFrequency($freq_1i_3y);
79
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-19', $frequency), 1, 'Feb 19, 1975 still 1' );
80
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-20', $frequency), 2, 'Feb 20, 1975 goes to 2' );
81
82
    # TEST CASE - 5 issues per year
83
    $subscription->{periodicity} = $freq_5i_1y;
84
    $subscription->{firstacquidate} = '1972-02-29'; #leap year
85
    $subscription->{countissuesperunit} = 1;
86
    $frequency = GetSubscriptionFrequency($freq_5i_1y);
87
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-11', $frequency), 1, 'May 11 still 1' );
88
    $subscription->{countissuesperunit} = 2;
89
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-12', $frequency), 2, 'May 12 goes to 2' );
90
    $subscription->{countissuesperunit} = 5;
91
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27', $frequency), 5, 'Feb 27 should still be 5' );
92
    $subscription->{countissuesperunit} = 1;
93
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28', $frequency), 6, 'Feb 28 goes to 6' );
94
95
    # TEST CASE - 366 issues per year (hypothetical example)
96
    # Testing prevention of divide by zero
97
    $subscription->{periodicity} = $freq_366i_1y;
98
    $subscription->{firstacquidate} = '1972-02-29'; #leap year
99
    $subscription->{countissuesperunit} = 366;
100
    $frequency = GetSubscriptionFrequency($freq_366i_1y);
101
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27', $frequency), 366, 'Feb 27 still at 366' );
102
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28', $frequency), 732, 'Feb 28 goes to 732' );
103
79
};
104
};
80
$subscription = {
105
81
    firstacquidate     => '1970-01-01',
106
subtest 'Tests for monthly frequencies' => sub {
82
    irregularity       => '',
107
    plan tests => 8;
83
    countissuesperunit => 1,
108
109
    # First add a few frequencies
110
    my $freq_1i_5m = AddSubscriptionFrequency({
111
        description => "1 issue per 5 months",
112
        unit => 'month',
113
        issuesperunit => 1,
114
        unitsperissue => 5,
115
    });
116
    my $freq_4i_1m = AddSubscriptionFrequency({
117
        description => "4 issue per month",
118
        unit => 'month',
119
        issuesperunit => 4,
120
        unitsperissue => 1,
121
    });
122
123
    # TEST CASE - 1 issue per 5 months
124
    my $subscription = {
125
        periodicity => $freq_1i_5m,
126
        firstacquidate => '1972-02-10',
127
        countissuesperunit => 1,
128
    };
129
    my $frequency = GetSubscriptionFrequency($freq_1i_5m);
130
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-09', $frequency), 1, 'Jul 9 still 1' );
131
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-10', $frequency), 2, 'Jul 10 goes to 2' );
132
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-09', $frequency), 3, 'May 9 still 3' );
133
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-10', $frequency), 4, 'May 10 goes to 4' );
134
135
    # TEST CASE - 4 issue per 1 months
136
    $subscription = {
137
        periodicity => $freq_4i_1m,
138
        firstacquidate => '1972-02-22',
139
        countissuesperunit => 1,
140
    };
141
    $frequency = GetSubscriptionFrequency($freq_4i_1m);
142
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-28', $frequency), 1, 'Feb 28 still 1' );
143
    $subscription->{countissuesperunit} = 2;
144
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-29', $frequency), 2, 'Feb 29 goes to 2' );
145
    $subscription->{countissuesperunit} = 4;
146
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-21', $frequency), 4, 'Mar 21 still 4' );
147
    $subscription->{countissuesperunit} = 1;
148
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-22', $frequency), 5, 'Mar 22 goes to 5' );
149
84
};
150
};
85
$issueNumber =
151
86
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
152
subtest 'Tests for weekly frequencies' => sub {
87
is( $issueNumber, 1 );
153
    plan tests => 4;
88
$issueNumber =
154
89
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
155
    # First add a few frequencies
90
is( $issueNumber, 1 );
156
    my $freq_1i_7w = AddSubscriptionFrequency({
91
$issueNumber =
157
        description => "1 issue per 7 weeks",
92
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency );
158
        unit => 'week',
93
is( $issueNumber, 2 );
159
        issuesperunit => 1,
94
$issueNumber =
160
        unitsperissue => 7,
95
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-04', $frequency );
161
    });
96
is( $issueNumber, 2 );
162
    my $freq_3i_1w = AddSubscriptionFrequency({
97
$issueNumber =
163
        description => "3 issues per week",
98
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-05', $frequency );
164
        unit => 'week',
99
is( $issueNumber, 3 );
165
        issuesperunit => 3,
100
166
        unitsperissue => 1,
101
# TEST CASE - 1 issue per week, no irregularity
167
    });
102
$frequency = {
168
103
    description   => "one issue per week",
169
    # TEST CASE - 1 issue per 7 weeks
104
    unit          => 'week',
170
    my $subscription = {
105
    issuesperunit => 1,
171
        periodicity => $freq_1i_7w,
106
    unitsperissue => 1,
172
        firstacquidate => '1972-02-10',
173
        countissuesperunit => 1,
174
    };
175
    my $frequency = GetSubscriptionFrequency($freq_1i_7w);
176
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-29', $frequency), 1, 'Mar 29 still 1' );
177
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-30', $frequency), 2, 'Mar 30 goes to 2' );
178
179
    # TEST CASE - 3 issue per 1 week
180
    $subscription = {
181
        periodicity => $freq_3i_1w,
182
        firstacquidate => '1972-02-03',
183
        countissuesperunit => 1,
184
    };
185
    $subscription->{countissuesperunit} = 3;
186
    $frequency = GetSubscriptionFrequency($freq_3i_1w);
187
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-09', $frequency), 3, 'Feb 9 still 3' );
188
    $subscription->{countissuesperunit} = 1;
189
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-10', $frequency), 4, 'Feb 10 goes to 4' );
107
};
190
};
108
$subscription = {
191
109
    firstacquidate     => '1970-01-01',
192
subtest 'Tests for dayly frequencies' => sub {
110
    irregularity       => '',
193
    plan tests => 4;
111
    countissuesperunit => 1,
194
195
    # First add a few frequencies
196
    my $freq_1i_12d = AddSubscriptionFrequency({
197
        description => "1 issue per 12 days",
198
        unit => 'day',
199
        issuesperunit => 1,
200
        unitsperissue => 12,
201
    });
202
    my $freq_3i_1d = AddSubscriptionFrequency({
203
        description => "3 issues per day",
204
        unit => 'day',
205
        issuesperunit => 3,
206
        unitsperissue => 1,
207
    });
208
209
    # TEST CASE - 1 issue per 12 days
210
    my $subscription = {
211
        periodicity => $freq_1i_12d,
212
        firstacquidate => '1972-03-16',
213
        countissuesperunit => 1,
214
    };
215
    my $frequency = GetSubscriptionFrequency($freq_1i_12d);
216
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-27', $frequency), 1, 'Mar 27 still 1' );
217
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-28', $frequency), 2, 'Mar 28 goes to 2' );
218
219
    # TEST CASE - 3 issue per day
220
    $subscription = {
221
        periodicity => $freq_3i_1d,
222
        firstacquidate => '1972-04-23',
223
        countissuesperunit => 1,
224
    };
225
    $subscription->{countissuesperunit} = 3;
226
    $frequency = GetSubscriptionFrequency($freq_3i_1d);
227
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-01', $frequency), 27, 'May 1 still 27' );
228
    $subscription->{countissuesperunit} = 1;
229
    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-02', $frequency), 28, 'May 2 goes to 28' );
112
};
230
};
113
$issueNumber =
231
114
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency );
232
$schema->storage->txn_rollback;
115
is( $issueNumber, 1 );
116
$issueNumber =
117
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency );
118
is( $issueNumber, 1 );
119
$issueNumber =
120
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-08', $frequency );
121
is( $issueNumber, 2 );
122
$issueNumber =
123
  C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-15', $frequency );
124
is( $issueNumber, 3 );
125
126
$dbh->rollback;
127
- 

Return to bug 17047