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

(-)a/Koha/Acquisition/Order.pm (+19 lines)
Lines 297-302 sub subscription { Link Here
297
    return Koha::Subscription->_new_from_dbic( $subscription_rs );
297
    return Koha::Subscription->_new_from_dbic( $subscription_rs );
298
}
298
}
299
299
300
=head3 suggestion
301
302
    my $suggestion = $order->suggestion
303
304
Returns the I<Koha::Suggestion> object for the suggestion associated
305
to the order.
306
307
It returns B<undef> if no linked suggestion is found.
308
309
=cut
310
311
sub suggestion {
312
    my ( $self )  = @_;
313
    my $rs = $self->_result->suggestion;
314
    return unless $rs;
315
    return Koha::Suggestion->_new_from_dbic( $rs );
316
}
317
300
=head3 current_item_level_holds
318
=head3 current_item_level_holds
301
319
302
    my $holds = $order->current_item_level_holds;
320
    my $holds = $order->current_item_level_holds;
Lines 657-662 sub to_api_mapping { Link Here
657
        sort2                         => 'statistics_2',
675
        sort2                         => 'statistics_2',
658
        sort2_authcat                 => 'statistics_2_authcat',
676
        sort2_authcat                 => 'statistics_2_authcat',
659
        subscriptionid                => 'subscription_id',
677
        subscriptionid                => 'subscription_id',
678
        suggestionid                  => 'suggestion_id',
660
        suppliers_reference_number    => undef,                    # EDIFACT related
679
        suppliers_reference_number    => undef,                    # EDIFACT related
661
        suppliers_reference_qualifier => undef,                    # EDIFACT related
680
        suppliers_reference_qualifier => undef,                    # EDIFACT related
662
        suppliers_report              => undef,                    # EDIFACT related
681
        suppliers_report              => undef,                    # EDIFACT related
(-)a/acqui/addorder.pl (+1 lines)
Lines 264-269 my $orderinfo = { Link Here
264
    sort2                => scalar $input->param('sort2'),
264
    sort2                => scalar $input->param('sort2'),
265
    subscriptionid       => scalar $input->param('subscriptionid'),
265
    subscriptionid       => scalar $input->param('subscriptionid'),
266
    estimated_delivery_date => scalar $input->param('estimated_delivery_date'),
266
    estimated_delivery_date => scalar $input->param('estimated_delivery_date'),
267
    suggestionid         => scalar $input->param('suggestionid'),
267
};
268
};
268
269
269
$orderinfo->{uncertainprice} ||= 0;
270
$orderinfo->{uncertainprice} ||= 0;
(-)a/acqui/basket.pl (-6 lines)
Lines 27-33 use CGI qw ( -utf8 ); Link Here
27
use C4::Acquisition qw( GetBasket CanUserManageBasket GetBasketAsCSV NewBasket NewBasketgroup ModBasket ReopenBasket ModBasketUsers GetBasketgroup GetBasketgroups GetBasketUsers GetOrders GetOrder get_rounded_price );
27
use C4::Acquisition qw( GetBasket CanUserManageBasket GetBasketAsCSV NewBasket NewBasketgroup ModBasket ReopenBasket ModBasketUsers GetBasketgroup GetBasketgroups GetBasketUsers GetOrders GetOrder get_rounded_price );
28
use C4::Budgets qw( GetBudgetHierarchy GetBudget CanUserUseBudget );
28
use C4::Budgets qw( GetBudgetHierarchy GetBudget CanUserUseBudget );
29
use C4::Contract qw( GetContract );
29
use C4::Contract qw( GetContract );
30
use C4::Suggestions qw( GetSuggestion GetSuggestionInfoFromBiblionumber GetSuggestionInfo );
31
use Koha::Biblios;
30
use Koha::Biblios;
32
use Koha::Acquisition::Baskets;
31
use Koha::Acquisition::Baskets;
33
use Koha::Acquisition::Booksellers;
32
use Koha::Acquisition::Booksellers;
Lines 503-513 sub get_order_infos { Link Here
503
502
504
    }
503
    }
505
504
506
    my $suggestion   = GetSuggestionInfoFromBiblionumber($line{biblionumber});
507
    $line{suggestionid}         = $$suggestion{suggestionid};
508
    $line{surnamesuggestedby}   = $$suggestion{surnamesuggestedby};
509
    $line{firstnamesuggestedby} = $$suggestion{firstnamesuggestedby};
510
511
    $line{estimated_delivery_date} = $order->{estimated_delivery_date};
505
    $line{estimated_delivery_date} = $order->{estimated_delivery_date};
512
506
513
    foreach my $key (qw(transferred_from transferred_to)) {
507
    foreach my $key (qw(transferred_from transferred_to)) {
(-)a/acqui/orderreceive.pl (-1 lines)
Lines 68-74 use C4::Output qw( output_html_with_http_headers ); Link Here
68
use C4::Budgets qw( GetBudget GetBudgetPeriods GetBudgetPeriod GetBudgetHierarchy CanUserUseBudget );
68
use C4::Budgets qw( GetBudget GetBudgetPeriods GetBudgetPeriod GetBudgetHierarchy CanUserUseBudget );
69
use C4::Members;
69
use C4::Members;
70
use C4::Biblio qw( GetMarcStructure );
70
use C4::Biblio qw( GetMarcStructure );
71
use C4::Suggestions qw( GetSuggestion GetSuggestionInfoFromBiblionumber GetSuggestionInfo );
72
71
73
use Koha::Acquisition::Booksellers;
72
use Koha::Acquisition::Booksellers;
74
use Koha::Acquisition::Currencies qw( get_active );
73
use Koha::Acquisition::Currencies qw( get_active );
(-)a/acqui/parcel.pl (-5 / +1 lines)
Lines 61-67 use C4::Acquisition qw( CancelReceipt GetInvoice GetInvoiceDetails get_rounded_p Link Here
61
use C4::Budgets qw( GetBudget GetBudgetByOrderNumber GetBudgetName );
61
use C4::Budgets qw( GetBudget GetBudgetByOrderNumber GetBudgetName );
62
use CGI qw ( -utf8 );
62
use CGI qw ( -utf8 );
63
use C4::Output qw( output_html_with_http_headers );
63
use C4::Output qw( output_html_with_http_headers );
64
use C4::Suggestions qw( GetSuggestion GetSuggestionInfoFromBiblionumber GetSuggestionInfo );
65
64
66
use Koha::Acquisition::Baskets;
65
use Koha::Acquisition::Baskets;
67
use Koha::Acquisition::Bookseller;
66
use Koha::Acquisition::Bookseller;
Lines 149-158 for my $order ( @orders ) { Link Here
149
    $total_tax_excluded += get_rounded_price($line{unitprice_tax_excluded}) * $line{quantity};
148
    $total_tax_excluded += get_rounded_price($line{unitprice_tax_excluded}) * $line{quantity};
150
    $total_tax_included += get_rounded_price($line{unitprice_tax_included}) * $line{quantity};
149
    $total_tax_included += get_rounded_price($line{unitprice_tax_included}) * $line{quantity};
151
150
152
    my $suggestion   = GetSuggestionInfoFromBiblionumber($line{biblionumber});
151
    $line{order_object} = $order_object;
153
    $line{suggestionid}         = $suggestion->{suggestionid};
154
    $line{surnamesuggestedby}   = $suggestion->{surnamesuggestedby};
155
    $line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby};
156
152
157
    if ( $line{parent_ordernumber} != $line{ordernumber} ) {
153
    if ( $line{parent_ordernumber} != $line{ordernumber} ) {
158
        if ( grep { $_->{ordernumber} == $line{parent_ordernumber} }
154
        if ( grep { $_->{ordernumber} == $line{parent_ordernumber} }
(-)a/api/v1/swagger/definitions/order.yaml (+9 lines)
Lines 204-209 properties: Link Here
204
      - integer
204
      - integer
205
      - "null"
205
      - "null"
206
    description: Subscription ID linking the order to a subscription
206
    description: Subscription ID linking the order to a subscription
207
  suggestion_id:
208
    type:
209
      - integer
210
      - "null"
211
    description: Suggestion ID linking the order to a suggestion
207
  parent_order_id:
212
  parent_order_id:
208
    type:
213
    type:
209
      - integer
214
      - integer
Lines 264-267 properties: Link Here
264
      - object
269
      - object
265
      - "null"
270
      - "null"
266
    description: Patron that created the order
271
    description: Patron that created the order
272
  suggestion:
273
    type:
274
      - object
275
      - "null"
267
additionalProperties: false
276
additionalProperties: false
(-)a/api/v1/swagger/paths/acquisitions_orders.yaml (-2 / +4 lines)
Lines 57-63 Link Here
57
            - biblio.active_orders+count
57
            - biblio.active_orders+count
58
            - biblio.holds+count
58
            - biblio.holds+count
59
            - biblio.items+count
59
            - biblio.items+count
60
            - biblio.suggestions.suggester
61
            - creator
60
            - creator
62
            - fund
61
            - fund
63
            - fund.budget
62
            - fund.budget
Lines 66-71 Link Here
66
            - items
65
            - items
67
            - items+strings
66
            - items+strings
68
            - subscription
67
            - subscription
68
            - suggestion
69
            - suggestion.suggester
69
        collectionFormat: csv
70
        collectionFormat: csv
70
    responses:
71
    responses:
71
      "200":
72
      "200":
Lines 177-188 Link Here
177
            - biblio.active_orders+count
178
            - biblio.active_orders+count
178
            - biblio.holds+count
179
            - biblio.holds+count
179
            - biblio.items+count
180
            - biblio.items+count
180
            - biblio.suggestions.suggester
181
            - fund
181
            - fund
182
            - current_item_level_holds+count
182
            - current_item_level_holds+count
183
            - invoice
183
            - invoice
184
            - items
184
            - items
185
            - subscription
185
            - subscription
186
            - suggestion
187
            - suggestion.suggester
186
        collectionFormat: csv
188
        collectionFormat: csv
187
    produces:
189
    produces:
188
      - application/json
190
      - application/json
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt (-3 / +5 lines)
Lines 582-591 Link Here
582
                                                                [%- IF ( books_loo.publicationyear ) %], [% books_loo.publicationyear | html -%]
582
                                                                [%- IF ( books_loo.publicationyear ) %], [% books_loo.publicationyear | html -%]
583
                                                                [%- ELSIF ( books_loo.copyrightdate ) %] [% books_loo.copyrightdate | html %][% END -%]
583
                                                                [%- ELSIF ( books_loo.copyrightdate ) %] [% books_loo.copyrightdate | html %][% END -%]
584
                                                                [%- IF ( books_loo.editionstatement ) %], [% books_loo.editionstatement | html %][% END -%]
584
                                                                [%- IF ( books_loo.editionstatement ) %], [% books_loo.editionstatement | html %][% END -%]
585
                                                                [%- IF ( books_loo.suggestionid ) %]
585
                                                                [% SET suggestion = books_loo.order_object.suggestion %]
586
                                                                [% IF suggestion %]
586
                                                                    <br/>
587
                                                                    <br/>
587
                                                                    Suggested by: [% books_loo.surnamesuggestedby | html %][% IF ( books_loo.firstnamesuggestedby ) %], [% books_loo.firstnamesuggestedby | html %] [% END %]
588
                                                                    [% SET suggester = suggestion.suggester %]
588
                                                                    (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% books_loo.suggestionid | uri %]&amp;op=show">suggestion #[% books_loo.suggestionid | html %]</a>)
589
                                                                    Suggested by: [% suggester.surname | html %][% IF suggester.firstname %] %], [% suggester.firstname | html %] [% END %]
590
                                                                    (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% suggestion.suggestionid | uri %]&amp;op=show">suggestion #[% suggestion.suggestionid | html %]</a>)
589
                                                                [% END %]
591
                                                                [% END %]
590
                                                            </p>
592
                                                            </p>
591
                                                            [% IF ( books_loo.order_internalnote ) %]
593
                                                            [% IF ( books_loo.order_internalnote ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt (-17 / +18 lines)
Lines 561-570 Link Here
561
                },
561
                },
562
                "embed": [
562
                "embed": [
563
                    "basket",
563
                    "basket",
564
                    "biblio.suggestions.suggester",
564
                    "biblio",
565
                    "fund.budget",
565
                    "fund.budget",
566
                    "items+strings",
566
                    "items+strings",
567
                    "creator"
567
                    "creator",
568
                    "suggestion.suggester",
568
                ],
569
                ],
569
                'dom': 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
570
                'dom': 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
570
                "columns": [
571
                "columns": [
Lines 693-705 Link Here
693
                params['ordernumber'] = row.order_id;
694
                params['ordernumber'] = row.order_id;
694
                params['booksellerid'] = row.basket.vendor_id;
695
                params['booksellerid'] = row.basket.vendor_id;
695
696
696
                if(row.biblio.suggestions.length && row.biblio.suggestions[0].reason) {
697
                if(row.suggestion && row.suggestion.reason) {
697
                    params["suggestionid"] = row.biblio.suggestions[0].suggestion_id;
698
                    params["suggestionid"] = row.suggestion.suggestion_id;
698
                    if($("#reason option[value='"+row.biblio.suggestions[0].reason+"']").length) {
699
                    if($("#reason option[value='"+row.suggestion.reason+"']").length) {
699
                        params['reason'] =  row.biblio.suggestions[0].reason;
700
                        params['reason'] =  row.suggestion.reason;
700
                    } else {
701
                    } else {
701
                        params['reason'] = 'other';
702
                        params['reason'] = 'other';
702
                        params['other_reason'] = row.biblio.suggestions[0].reason;
703
                        params['other_reason'] = row.suggestion.reason;
703
                    }
704
                    }
704
                }
705
                }
705
                params['datereceived'] = row.date_received;
706
                params['datereceived'] = row.date_received;
Lines 837-850 Link Here
837
                    $("#other_reason").show();
838
                    $("#other_reason").show();
838
                    $(this).hide();
839
                    $(this).hide();
839
                } else {
840
                } else {
840
                    row.biblio.suggestions[0].reason = val;
841
                    row.suggestion.reason = val;
841
                }
842
                }
842
            });
843
            });
843
844
844
            $("#order_edit").on("change", "#select-other_reason", function() {
845
            $("#order_edit").on("change", "#select-other_reason", function() {
845
                var val = $(this).val();
846
                var val = $(this).val();
846
                var row = $("#order_edit").data('row');
847
                var row = $("#order_edit").data('row');
847
                row.biblio.suggestions[0].reason = val;
848
                row.suggestion.reason = val;
848
            });
849
            });
849
850
850
            $("#order_edit").on("click", "#other_reason a", function() {
851
            $("#order_edit").on("click", "#other_reason a", function() {
Lines 1132-1161 Link Here
1132
                        o.parent().hide();
1133
                        o.parent().hide();
1133
                    }
1134
                    }
1134
                });
1135
                });
1135
                if(row.biblio.suggestions.length) {
1136
                if(row.suggestion) {
1136
                    $("#suggestion_fieldset").show();
1137
                    $("#suggestion_fieldset").show();
1137
                    if(row.biblio.suggestions[0].suggester) {
1138
                    if(row.suggestion.suggester) {
1138
                        $("#biblio_suggestion_suggester").parent().show();
1139
                        $("#biblio_suggestion_suggester").parent().show();
1139
                        $("#biblio_suggestion_suggester")
1140
                        $("#biblio_suggestion_suggester")
1140
                            .html(
1141
                            .html(
1141
                                [row.biblio.suggestions[0].suggester.surname, row.biblio.suggestions[0].suggester.firstname]
1142
                                [row.suggestion.suggester.surname, row.suggestion.suggester.firstname]
1142
                                    .filter(function(name){
1143
                                    .filter(function(name){
1143
                                        return name
1144
                                        return name
1144
                                    })
1145
                                    })
1145
                                    .join(', ')+' (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid='+row.biblio.suggestions[0].suggestion_id+'&op=show">'+SUGGESTION.format(row.biblio.suggestions[0].suggestion_id)+'</a>)'
1146
                                    .join(', ')+' (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid='+row.suggestion.suggestion_id+'&op=show">'+SUGGESTION.format(row.suggestion.suggestion_id)+'</a>)'
1146
                            );
1147
                            );
1147
                    } else {
1148
                    } else {
1148
                        $("#biblio_suggestion_suggester").parent().hide();
1149
                        $("#biblio_suggestion_suggester").parent().hide();
1149
                    }
1150
                    }
1150
                    if(row.biblio.suggestions[0].reason) {
1151
                    if(row.suggestion.reason) {
1151
                        $("#suggestion_reason").show();
1152
                        $("#suggestion_reason").show();
1152
                        if($("#reason option[value='"+row.biblio.suggestions[0].reason+"']").length) {
1153
                        if($("#reason option[value='"+row.suggestion.reason+"']").length) {
1153
                             $("#other_reason a").click();
1154
                             $("#other_reason a").click();
1154
                            $("#reason").val(row.biblio.suggestions[0].reason);
1155
                            $("#reason").val(row.suggestion.reason);
1155
                            $("#select-other_reason").val(null);
1156
                            $("#select-other_reason").val(null);
1156
                        } else {
1157
                        } else {
1157
                            $("#reason").val("other").change();
1158
                            $("#reason").val("other").change();
1158
                            $("#select-other_reason").val(row.biblio.suggestions[0].reason);
1159
                            $("#select-other_reason").val(row.suggestion.reason);
1159
                        }
1160
                        }
1160
1161
1161
                    } else {
1162
                    } else {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt (-24 / +24 lines)
Lines 244-253 Link Here
244
                    [%- ELSIF ( order.copyrightdate   > 0) -%] [% order.copyrightdate | html %]
244
                    [%- ELSIF ( order.copyrightdate   > 0) -%] [% order.copyrightdate | html %]
245
                    [% END %]
245
                    [% END %]
246
                [% END %]
246
                [% END %]
247
                [% IF ( order.suggestionid ) %]
247
248
                [% SET suggestion = order.order_object.suggestion %]
249
                [% IF suggestion %]
250
                [% SET suggester = suggestion.suggester %]
248
                    <br/>
251
                    <br/>
249
                    Suggested by: [% order.surnamesuggestedby | html %][% IF ( order.firstnamesuggestedby ) %], [% order.firstnamesuggestedby | html %] [% END %]
252
                    Suggested by: [% suggester.surname | html %][% IF suggester.firstname %] %], [% suggester.firstname | html %] [% END %]
250
                    (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% order.suggestionid | uri %]&amp;op=show">suggestion #[% order.suggestionid | html %]</a>)
253
                    (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% suggestion.suggestionid | uri %]&amp;op=show">suggestion #[% suggestion.suggestionid | html %]</a>)
251
                [% END %]
254
                [% END %]
252
                <br />
255
                <br />
253
                [% IF ( order.order_internalnote ) %]
256
                [% IF ( order.order_internalnote ) %]
Lines 394-403 Link Here
394
                    "biblio.active_orders+count",
397
                    "biblio.active_orders+count",
395
                    "biblio.holds+count",
398
                    "biblio.holds+count",
396
                    "biblio.items+count",
399
                    "biblio.items+count",
397
                    "biblio.suggestions.suggester",
398
                    "fund",
400
                    "fund",
399
                    "current_item_level_holds+count",
401
                    "current_item_level_holds+count",
400
                    "items"
402
                    "items",
403
                    "suggestion.suggester"
401
                ],
404
                ],
402
                "stateSave": true, // remember state on page reload
405
                "stateSave": true, // remember state on page reload
403
                "drawCallback": function (settings) {
406
                "drawCallback": function (settings) {
Lines 468-493 Link Here
468
                                        result += escape_str(row.biblio.copyright_date);
471
                                        result += escape_str(row.biblio.copyright_date);
469
                                    }
472
                                    }
470
                                }
473
                                }
471
                                var suggestions = row.biblio.suggestions;
474
                                let suggestion = row.suggestion;
472
                                if ( suggestions != null && suggestions.length > 0 ) {
475
                                if ( suggestion && suggestion.suggester != null ) {
473
                                    var suggestion = suggestions[0];
476
                                    var suggester = suggestion.suggester;
474
                                    if ( suggestion.suggester != null ) {
477
                                    var suggested_by = [];
475
                                        var suggester = suggestion.suggester;
478
                                    if ( suggester.surname != null ) {
476
                                        var suggested_by = [];
479
                                        suggested_by.push(escape_str(suggester.surname));
477
                                        if ( suggester.surname != null ) {
480
                                    }
478
                                            suggested_by.push(escape_str(suggester.surname));
481
                                    if ( suggester.firstname != null ) {
479
                                        }
482
                                        suggested_by.push(escape_str(suggester.firstname));
480
                                        if ( suggester.firstname != null ) {
481
                                            suggested_by.push(escape_str(suggester.firstname));
482
                                        }
483
484
                                            result += "<br/>" + _("Suggested by: ") +
485
                                                        '<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid='
486
                                                            + encodeURIComponent(suggestion.suggestionid)
487
                                                            + '&amp;op=show">'
488
                                                            + suggested_by.join(", ")
489
                                                            + " (#" + escape_str(suggestions[0].suggestionid) + ")</a>"; // FIXME: could be changed if we allow matching multiple suggestions
490
                                    }
483
                                    }
484
485
                                    result += "<br/>" + _("Suggested by: ") +
486
                                                '<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid='
487
                                                    + encodeURIComponent(suggestion.suggestion_id)
488
                                                    + '&amp;op=show">'
489
                                                    + suggested_by.join(", ")
490
                                                    + " (#" + escape_str(suggestion.suggestionid) + ")</a>";
491
                                }
491
                                }
492
                                result += '</p>';
492
                                result += '</p>';
493
                            }
493
                            }
(-)a/t/db_dependent/Koha/Acquisition/Order.t (-2 / +30 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 13;
22
use Test::More tests => 14;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 210-215 subtest 'subscription' => sub { Link Here
210
    $schema->storage->txn_rollback;
210
    $schema->storage->txn_rollback;
211
};
211
};
212
212
213
subtest 'suggestion' => sub {
214
    plan tests => 2;
215
216
    $schema->storage->txn_begin;
217
    my $o = $builder->build_object(
218
        {
219
            class => 'Koha::Acquisition::Orders',
220
            value => { suggestionid => undef }, # not linked to a suggestion
221
        }
222
    );
223
224
    my $order = Koha::Acquisition::Orders->find( $o->ordernumber );
225
    is( $order->suggestion, undef,
226
        '->suggestion should return undef if not created from a suggestion');
227
228
    $o = $builder->build_object(
229
        {
230
            class => 'Koha::Acquisition::Orders',
231
            # Will be linked to a suggestion by TestBuilder
232
        }
233
    );
234
235
    $order = Koha::Acquisition::Orders->find( $o->ordernumber );
236
    is( ref( $order->suggestion ), 'Koha::Suggestion',
237
        '->suggestion should return a Koha::Suggestion object if created from a suggestion');
238
239
    $schema->storage->txn_rollback;
240
};
241
213
subtest 'duplicate_to | add_item' => sub {
242
subtest 'duplicate_to | add_item' => sub {
214
    plan tests => 3;
243
    plan tests => 3;
215
244
216
- 

Return to bug 28844