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 261-266 my $orderinfo = { Link Here
261
    sort2                => scalar $input->param('sort2'),
261
    sort2                => scalar $input->param('sort2'),
262
    subscriptionid       => scalar $input->param('subscriptionid'),
262
    subscriptionid       => scalar $input->param('subscriptionid'),
263
    estimated_delivery_date => scalar $input->param('estimated_delivery_date'),
263
    estimated_delivery_date => scalar $input->param('estimated_delivery_date'),
264
    suggestionid         => scalar $input->param('suggestionid'),
264
};
265
};
265
266
266
$orderinfo->{uncertainprice} ||= 0;
267
$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 496-506 sub get_order_infos { Link Here
496
        $line{order_object}         = $order;
495
        $line{order_object}         = $order;
497
    }
496
    }
498
497
499
    my $suggestion   = GetSuggestionInfoFromBiblionumber($line{biblionumber});
500
    $line{suggestionid}         = $$suggestion{suggestionid};
501
    $line{surnamesuggestedby}   = $$suggestion{surnamesuggestedby};
502
    $line{firstnamesuggestedby} = $$suggestion{firstnamesuggestedby};
503
504
    $line{estimated_delivery_date} = $order->{estimated_delivery_date};
498
    $line{estimated_delivery_date} = $order->{estimated_delivery_date};
505
499
506
    foreach my $key (qw(transferred_from transferred_to)) {
500
    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 566-575 Link Here
566
                                                                [%- IF ( books_loo.publicationyear ) %], [% books_loo.publicationyear | html -%]
566
                                                                [%- IF ( books_loo.publicationyear ) %], [% books_loo.publicationyear | html -%]
567
                                                                [%- ELSIF ( books_loo.copyrightdate ) %] [% books_loo.copyrightdate | html %][% END -%]
567
                                                                [%- ELSIF ( books_loo.copyrightdate ) %] [% books_loo.copyrightdate | html %][% END -%]
568
                                                                [%- IF ( books_loo.editionstatement ) %], [% books_loo.editionstatement | html %][% END -%]
568
                                                                [%- IF ( books_loo.editionstatement ) %], [% books_loo.editionstatement | html %][% END -%]
569
                                                                [%- IF ( books_loo.suggestionid ) %]
569
                                                                [% SET suggestion = books_loo.order_object.suggestion %]
570
                                                                [% IF suggestion %]
570
                                                                    <br/>
571
                                                                    <br/>
571
                                                                    Suggested by: [% books_loo.surnamesuggestedby | html %][% IF ( books_loo.firstnamesuggestedby ) %], [% books_loo.firstnamesuggestedby | html %] [% END %]
572
                                                                    [% SET suggester = suggestion.suggester %]
572
                                                                    (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% books_loo.suggestionid | uri %]&amp;op=show">suggestion #[% books_loo.suggestionid | html %]</a>)
573
                                                                    Suggested by: [% suggester.surname | html %][% IF suggester.firstname %] %], [% suggester.firstname | html %] [% END %]
574
                                                                    (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% suggestion.suggestionid | uri %]&amp;op=show">suggestion #[% suggestion.suggestionid | html %]</a>)
573
                                                                [% END %]
575
                                                                [% END %]
574
                                                            </p>
576
                                                            </p>
575
                                                            [% IF ( books_loo.order_internalnote ) %]
577
                                                            [% IF ( books_loo.order_internalnote ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt (-17 / +18 lines)
Lines 544-553 Link Here
544
                },
544
                },
545
                "embed": [
545
                "embed": [
546
                    "basket",
546
                    "basket",
547
                    "biblio.suggestions.suggester",
547
                    "biblio",
548
                    "fund.budget",
548
                    "fund.budget",
549
                    "items+strings",
549
                    "items+strings",
550
                    "creator"
550
                    "creator",
551
                    "suggestion.suggester",
551
                ],
552
                ],
552
                'dom': 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
553
                'dom': 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
553
                "columns": [
554
                "columns": [
Lines 676-688 Link Here
676
                params['ordernumber'] = row.order_id;
677
                params['ordernumber'] = row.order_id;
677
                params['booksellerid'] = row.basket.vendor_id;
678
                params['booksellerid'] = row.basket.vendor_id;
678
679
679
                if(row.biblio.suggestions.length && row.biblio.suggestions[0].reason) {
680
                if(row.suggestion && row.suggestion.reason) {
680
                    params["suggestionid"] = row.biblio.suggestions[0].suggestion_id;
681
                    params["suggestionid"] = row.suggestion.suggestion_id;
681
                    if($("#reason option[value='"+row.biblio.suggestions[0].reason+"']").length) {
682
                    if($("#reason option[value='"+row.suggestion.reason+"']").length) {
682
                        params['reason'] =  row.biblio.suggestions[0].reason;
683
                        params['reason'] =  row.suggestion.reason;
683
                    } else {
684
                    } else {
684
                        params['reason'] = 'other';
685
                        params['reason'] = 'other';
685
                        params['other_reason'] = row.biblio.suggestions[0].reason;
686
                        params['other_reason'] = row.suggestion.reason;
686
                    }
687
                    }
687
                }
688
                }
688
                params['datereceived'] = row.date_received;
689
                params['datereceived'] = row.date_received;
Lines 820-833 Link Here
820
                    $("#other_reason").show();
821
                    $("#other_reason").show();
821
                    $(this).hide();
822
                    $(this).hide();
822
                } else {
823
                } else {
823
                    row.biblio.suggestions[0].reason = val;
824
                    row.suggestion.reason = val;
824
                }
825
                }
825
            });
826
            });
826
827
827
            $("#order_edit").on("change", "#select-other_reason", function() {
828
            $("#order_edit").on("change", "#select-other_reason", function() {
828
                var val = $(this).val();
829
                var val = $(this).val();
829
                var row = $("#order_edit").data('row');
830
                var row = $("#order_edit").data('row');
830
                row.biblio.suggestions[0].reason = val;
831
                row.suggestion.reason = val;
831
            });
832
            });
832
833
833
            $("#order_edit").on("click", "#other_reason a", function() {
834
            $("#order_edit").on("click", "#other_reason a", function() {
Lines 1105-1134 Link Here
1105
                        o.parent().hide();
1106
                        o.parent().hide();
1106
                    }
1107
                    }
1107
                });
1108
                });
1108
                if(row.biblio.suggestions.length) {
1109
                if(row.suggestion) {
1109
                    $("#suggestion_fieldset").show();
1110
                    $("#suggestion_fieldset").show();
1110
                    if(row.biblio.suggestions[0].suggester) {
1111
                    if(row.suggestion.suggester) {
1111
                        $("#biblio_suggestion_suggester").parent().show();
1112
                        $("#biblio_suggestion_suggester").parent().show();
1112
                        $("#biblio_suggestion_suggester")
1113
                        $("#biblio_suggestion_suggester")
1113
                            .html(
1114
                            .html(
1114
                                [row.biblio.suggestions[0].suggester.surname, row.biblio.suggestions[0].suggester.firstname]
1115
                                [row.suggestion.suggester.surname, row.suggestion.suggester.firstname]
1115
                                    .filter(function(name){
1116
                                    .filter(function(name){
1116
                                        return name
1117
                                        return name
1117
                                    })
1118
                                    })
1118
                                    .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>)'
1119
                                    .join(', ')+' (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid='+row.suggestion.suggestion_id+'&op=show">'+SUGGESTION.format(row.suggestion.suggestion_id)+'</a>)'
1119
                            );
1120
                            );
1120
                    } else {
1121
                    } else {
1121
                        $("#biblio_suggestion_suggester").parent().hide();
1122
                        $("#biblio_suggestion_suggester").parent().hide();
1122
                    }
1123
                    }
1123
                    if(row.biblio.suggestions[0].reason) {
1124
                    if(row.suggestion.reason) {
1124
                        $("#suggestion_reason").show();
1125
                        $("#suggestion_reason").show();
1125
                        if($("#reason option[value='"+row.biblio.suggestions[0].reason+"']").length) {
1126
                        if($("#reason option[value='"+row.suggestion.reason+"']").length) {
1126
                             $("#other_reason a").click();
1127
                             $("#other_reason a").click();
1127
                            $("#reason").val(row.biblio.suggestions[0].reason);
1128
                            $("#reason").val(row.suggestion.reason);
1128
                            $("#select-other_reason").val(null);
1129
                            $("#select-other_reason").val(null);
1129
                        } else {
1130
                        } else {
1130
                            $("#reason").val("other").change();
1131
                            $("#reason").val("other").change();
1131
                            $("#select-other_reason").val(row.biblio.suggestions[0].reason);
1132
                            $("#select-other_reason").val(row.suggestion.reason);
1132
                        }
1133
                        }
1133
1134
1134
                    } else {
1135
                    } else {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt (-24 / +24 lines)
Lines 239-248 Link Here
239
                    [%- ELSIF ( order.copyrightdate   > 0) -%] [% order.copyrightdate | html %]
239
                    [%- ELSIF ( order.copyrightdate   > 0) -%] [% order.copyrightdate | html %]
240
                    [% END %]
240
                    [% END %]
241
                [% END %]
241
                [% END %]
242
                [% IF ( order.suggestionid ) %]
242
243
                [% SET suggestion = order.order_object.suggestion %]
244
                [% IF suggestion %]
245
                [% SET suggester = suggestion.suggester %]
243
                    <br/>
246
                    <br/>
244
                    Suggested by: [% order.surnamesuggestedby | html %][% IF ( order.firstnamesuggestedby ) %], [% order.firstnamesuggestedby | html %] [% END %]
247
                    Suggested by: [% suggester.surname | html %][% IF suggester.firstname %] %], [% suggester.firstname | html %] [% END %]
245
                    (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% order.suggestionid | uri %]&amp;op=show">suggestion #[% order.suggestionid | html %]</a>)
248
                    (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% suggestion.suggestionid | uri %]&amp;op=show">suggestion #[% suggestion.suggestionid | html %]</a>)
246
                [% END %]
249
                [% END %]
247
                <br />
250
                <br />
248
                [% IF ( order.order_internalnote ) %]
251
                [% IF ( order.order_internalnote ) %]
Lines 389-398 Link Here
389
                    "biblio.active_orders+count",
392
                    "biblio.active_orders+count",
390
                    "biblio.holds+count",
393
                    "biblio.holds+count",
391
                    "biblio.items+count",
394
                    "biblio.items+count",
392
                    "biblio.suggestions.suggester",
393
                    "fund",
395
                    "fund",
394
                    "current_item_level_holds+count",
396
                    "current_item_level_holds+count",
395
                    "items"
397
                    "items",
398
                    "suggestion.suggester"
396
                ],
399
                ],
397
                "stateSave": true, // remember state on page reload
400
                "stateSave": true, // remember state on page reload
398
                "drawCallback": function (settings) {
401
                "drawCallback": function (settings) {
Lines 463-488 Link Here
463
                                        result += escape_str(row.biblio.copyright_date);
466
                                        result += escape_str(row.biblio.copyright_date);
464
                                    }
467
                                    }
465
                                }
468
                                }
466
                                var suggestions = row.biblio.suggestions;
469
                                let suggestion = row.suggestion;
467
                                if ( suggestions != null && suggestions.length > 0 ) {
470
                                if ( suggestion && suggestion.suggester != null ) {
468
                                    var suggestion = suggestions[0];
471
                                    var suggester = suggestion.suggester;
469
                                    if ( suggestion.suggester != null ) {
472
                                    var suggested_by = [];
470
                                        var suggester = suggestion.suggester;
473
                                    if ( suggester.surname != null ) {
471
                                        var suggested_by = [];
474
                                        suggested_by.push(escape_str(suggester.surname));
472
                                        if ( suggester.surname != null ) {
475
                                    }
473
                                            suggested_by.push(escape_str(suggester.surname));
476
                                    if ( suggester.firstname != null ) {
474
                                        }
477
                                        suggested_by.push(escape_str(suggester.firstname));
475
                                        if ( suggester.firstname != null ) {
476
                                            suggested_by.push(escape_str(suggester.firstname));
477
                                        }
478
479
                                            result += "<br/>" + _("Suggested by: ") +
480
                                                        '<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid='
481
                                                            + encodeURIComponent(suggestion.suggestionid)
482
                                                            + '&amp;op=show">'
483
                                                            + suggested_by.join(", ")
484
                                                            + " (#" + escape_str(suggestions[0].suggestionid) + ")</a>"; // FIXME: could be changed if we allow matching multiple suggestions
485
                                    }
478
                                    }
479
480
                                    result += "<br/>" + _("Suggested by: ") +
481
                                                '<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid='
482
                                                    + encodeURIComponent(suggestion.suggestion_id)
483
                                                    + '&amp;op=show">'
484
                                                    + suggested_by.join(", ")
485
                                                    + " (#" + escape_str(suggestion.suggestionid) + ")</a>";
486
                                }
486
                                }
487
                                result += '</p>';
487
                                result += '</p>';
488
                            }
488
                            }
(-)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