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

(-)a/Koha/Suggestion.pm (+36 lines)
Lines 53-58 sub store { Link Here
53
    return $self->SUPER::store();
53
    return $self->SUPER::store();
54
}
54
}
55
55
56
sub manager {
57
    my ($self) = @_;
58
    my $manager_rs = $self->_result->managedby;
59
    return unless $manager_rs;
60
    return Koha::Patron->_new_from_dbic($manager_rs);
61
}
62
63
sub suggester {
64
    my ($self) = @_;
65
    my $suggester_rs = $self->_result->managedby;
66
    return unless $suggester_rs;
67
    return Koha::Patron->_new_from_dbic($suggester_rs);
68
}
69
70
sub rejecter {
71
    my ($self) = @_;
72
    my $rejecter_rs = $self->_result->managedby;
73
    return unless $rejecter_rs;
74
    return Koha::Patron->_new_from_dbic($rejecter_rs);
75
}
76
77
sub last_modifier {
78
    my ($self) = @_;
79
    my $last_modifier_rs = $self->_result->managedby;
80
    return unless $last_modifier_rs;
81
    return Koha::Patron->_new_from_dbic($last_modifier_rs);
82
}
83
84
sub fund {
85
    my ($self) = @_;
86
    my $fund_rs = $self->_result->budgetid;
87
    return unless $fund_rs;
88
    return Koha::Acquisition::Fund->_new_from_dbic($fund_rs);
89
}
90
91
56
=head3 type
92
=head3 type
57
93
58
=cut
94
=cut
(-)a/acqui/newordersuggestion.pl (-9 / +9 lines)
Lines 98-103 use C4::Biblio; Link Here
98
use C4::Budgets;
98
use C4::Budgets;
99
99
100
use Koha::Acquisition::Booksellers;
100
use Koha::Acquisition::Booksellers;
101
use Koha::Suggestions;
101
102
102
my $input = new CGI;
103
my $input = new CGI;
103
104
Lines 128-150 if ( $op eq 'connectDuplicate' ) { Link Here
128
    ConnectSuggestionAndBiblio( $suggestionid, $duplicateNumber );
129
    ConnectSuggestionAndBiblio( $suggestionid, $duplicateNumber );
129
}
130
}
130
131
131
# getting all suggestions.
132
my $suggestions = Koha::Suggestions->search(
132
my $suggestions_loop = SearchSuggestion(
133
    {
133
    {
134
        author        => $author,
134
        ( $author        ? ( author        => $author )        : () ),
135
        title         => $title,
135
        ( $title         ? ( title         => $title )         : () ),
136
        publishercode => $publishercode,
136
        ( $publishercode ? ( publishercode => $publishercode ) : () ),
137
        STATUS        => 'ACCEPTED'
137
        STATUS => 'ACCEPTED'
138
    }
138
    },
139
    { prefetch => ['managedby', 'suggestedby'] },
139
);
140
);
140
141
141
my $vendor = Koha::Acquisition::Booksellers->find( $booksellerid );
142
my $vendor = Koha::Acquisition::Booksellers->find( $booksellerid );
142
$template->param(
143
$template->param(
143
    suggestions_loop        => $suggestions_loop,
144
    suggestions             => $suggestions,
144
    basketno                => $basketno,
145
    basketno                => $basketno,
145
    booksellerid              => $booksellerid,
146
    booksellerid              => $booksellerid,
146
    name                    => $vendor->name,
147
    name                    => $vendor->name,
147
    loggedinuser            => $borrowernumber,
148
    "op_$op"                => 1,
148
    "op_$op"                => 1,
149
);
149
);
150
150
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/newordersuggestion.tt (-27 / +23 lines)
Lines 20-26 Link Here
20
            <main>
20
            <main>
21
21
22
<h1>Suggestions</h1>
22
<h1>Suggestions</h1>
23
    [% IF ( suggestions_loop ) %]
23
    [% IF suggestions.count %]
24
    <a href="#" id="show_only_mine">Show only mine</a> | <a href="#" id="show_all">Show all suggestions</a>
24
    <a href="#" id="show_only_mine">Show only mine</a> | <a href="#" id="show_all">Show all suggestions</a>
25
    <table id="suggestionst">
25
    <table id="suggestionst">
26
        <thead>
26
        <thead>
Lines 38-86 Link Here
38
        </tr>
38
        </tr>
39
        </thead>
39
        </thead>
40
        <tbody>
40
        <tbody>
41
        [% FOREACH suggestions_loo IN suggestions_loop %]
41
        [% FOREACH suggestion IN suggestions %]
42
            <tr>
42
            <tr>
43
                <td>[% suggestions_loo.managedby | html %]</td>
43
                <td>[% suggestion.managedby | html %]</td>
44
                <td>
44
                <td>
45
                    <p>[% suggestions_loo.title | html %] - [% suggestions_loo.author | html %]</p>
45
                    <p>[% suggestion.title | html %] - [% suggestion.author | html %]</p>
46
                    <p>
46
                    <p>
47
                        [% IF ( suggestions_loo.copyrightdate ) %]&copy; [% suggestions_loo.copyrightdate | html %] [% END %]
47
                        [% IF ( suggestion.copyrightdate ) %]&copy; [% suggestion.copyrightdate | html %] [% END %]
48
                        [% IF ( suggestions_loo.volumedesc ) %]volume: <i>[% suggestions_loo.volumedesc | html %]</i> [% END %]
48
                        [% IF ( suggestion.volumedesc ) %]volume: <i>[% suggestion.volumedesc | html %]</i> [% END %]
49
                        [% IF ( suggestions_loo.isbn ) %]ISBN: <i>[% suggestions_loo.isbn | html %]</i> [% END %]
49
                        [% IF ( suggestion.isbn ) %]ISBN: <i>[% suggestion.isbn | html %]</i> [% END %]
50
                        [% IF ( suggestions_loo.publishercode ) %]<br />published by: [% suggestions_loo.publishercode | html %] [% END %]
50
                        [% IF ( suggestion.publishercode ) %]<br />published by: [% suggestion.publishercode | html %] [% END %]
51
                        [% IF ( suggestions_loo.publicationyear ) %] in <i>[% suggestions_loo.publicationyear | html %]</i> [% END %]
51
                        [% IF ( suggestion.publicationyear ) %] in <i>[% suggestion.publicationyear | html %]</i> [% END %]
52
                        [% IF ( suggestions_loo.place ) %] in <i>[% suggestions_loo.place | html %]</i> [% END %]
52
                        [% IF ( suggestion.place ) %] in <i>[% suggestion.place | html %]</i> [% END %]
53
                        [% IF ( suggestions_loo.note ) %]<p><i>([% suggestions_loo.note | html %])</i></p> [% END %]
53
                        [% IF ( suggestion.note ) %]<p><i>([% suggestion.note | html %])</i></p> [% END %]
54
                    </p>
54
                    </p>
55
                </td>
55
                </td>
56
                <td>[% INCLUDE 'patron-title.inc' patron => suggestion.suggester %]</td>
57
                <td>[% INCLUDE 'patron-title.inc' patron => suggestion.manager %]</td>
56
                <td>
58
                <td>
57
                    [% suggestions_loo.surnamesuggestedby | html %][% IF ( suggestions_loo.firstnamesuggestedby ) %],[% END %] [% suggestions_loo.firstnamesuggestedby | html %]
59
                    [% Branches.GetName(suggestion.branchcode) | html %]
58
                </td>
60
                </td>
59
                <td>
61
                <td>
60
                    [% suggestions_loo.surnamemanagedby | html %][% IF ( suggestions_loo.firstnamemanagedby ) %],[% END %] [% suggestions_loo.firstnamemanagedby | html %]
62
                    [% suggestion.fund.budget_name | html %]
61
                </td>
63
                </td>
62
                <td>
64
                <td>
63
                    [% Branches.GetName(suggestions_loo.branchcode) | html %]
65
                    [% suggestion.price | $Price %]
64
                </td>
66
                </td>
65
                <td>
67
                <td>
66
                    [% suggestions_loo.budget_name | html %]
68
                    [% IF (suggestion.quantity > 0) %]
67
                </td>
69
                        [% suggestion.quantity | html %]
68
                <td>
69
                    [% suggestions_loo.price | $Price %]
70
                </td>
71
                <td>
72
                    [% IF (suggestions_loo.quantity > 0) %]
73
                        [% suggestions_loo.quantity | html %]
74
                    [% END %]
70
                    [% END %]
75
                </td>
71
                </td>
76
                <td>
72
                <td>
77
                    [% suggestions_loo.total | $Price %]
73
                    [% suggestion.total | $Price %]
78
                </td>
74
                </td>
79
                <td class="actions">
75
                <td class="actions">
80
                    [% IF ( suggestions_loo.biblionumber ) %]
76
                    [% IF ( suggestion.biblionumber ) %]
81
                        <a href="neworderempty.pl?booksellerid=[% booksellerid | uri %]&amp;basketno=[% basketno | uri %]&amp;suggestionid=[% suggestions_loo.suggestionid | uri %]&amp;biblio=[% suggestions_loo.biblionumber | uri %]" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Order</a>
77
                        <a href="neworderempty.pl?booksellerid=[% booksellerid | uri %]&amp;basketno=[% basketno | uri %]&amp;suggestionid=[% suggestion.suggestionid | uri %]&amp;biblio=[% suggestion.biblionumber | uri %]" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Order</a>
82
                    [% ELSE %]
78
                    [% ELSE %]
83
                        <a href="neworderempty.pl?booksellerid=[% booksellerid | uri %]&amp;basketno=[% basketno | uri %]&amp;suggestionid=[% suggestions_loo.suggestionid | uri %]" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Order</a>
79
                        <a href="neworderempty.pl?booksellerid=[% booksellerid | uri %]&amp;basketno=[% basketno | uri %]&amp;suggestionid=[% suggestion.suggestionid | uri %]" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Order</a>
84
                    [% END %]
80
                    [% END %]
85
                </td>
81
                </td>
86
            </tr>
82
            </tr>
Lines 114-120 Link Here
114
        }));
110
        }));
115
        $("#show_only_mine").on('click', function(e){
111
        $("#show_only_mine").on('click', function(e){
116
            e.preventDefault();
112
            e.preventDefault();
117
            suggestionst.fnFilter('^[% loggedinuser | html %]$', 0, true);
113
            suggestionst.fnFilter('^[% logged_in_user.borrowernumber | html %]$', 0, true);
118
        });
114
        });
119
        $("#show_all").on('click', function(e){
115
        $("#show_all").on('click', function(e){
120
            e.preventDefault();
116
            e.preventDefault();
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/purchase-suggestions.tt (-8 / +2 lines)
Lines 31-37 Link Here
31
                    <a class="btn btn-default" id="newsuggestion" href="/cgi-bin/koha/suggestion/suggestion.pl?op=add&amp;suggestedby=[% patron.borrowernumber | html %]&amp;redirect=purchase_suggestions&amp;borrowernumber=[% patron.borrowernumber | html %]"><i class="fa fa-plus"></i> New purchase suggestion</a>
31
                    <a class="btn btn-default" id="newsuggestion" href="/cgi-bin/koha/suggestion/suggestion.pl?op=add&amp;suggestedby=[% patron.borrowernumber | html %]&amp;redirect=purchase_suggestions&amp;borrowernumber=[% patron.borrowernumber | html %]"><i class="fa fa-plus"></i> New purchase suggestion</a>
32
                </div>
32
                </div>
33
33
34
                [% IF suggestions %]
34
                [% IF suggestions.count %]
35
                  <table id="suggestions">
35
                  <table id="suggestions">
36
                    <thead>
36
                    <thead>
37
                        <tr>
37
                        <tr>
Lines 66-78 Link Here
66
                                </td>
66
                                </td>
67
                                <td>[% s.note | html %]
67
                                <td>[% s.note | html %]
68
                                <td>
68
                                <td>
69
                                    [% IF ( s.surnamemanagedby ) %]
69
                                    [% INCLUDE 'patron-title.inc' patron => s.manager %]
70
                                        [% s.surnamemanagedby | html %]
71
                                        [% IF ( s.firstnamemanagedby ) %],[% END %]
72
                                        [% s.firstnamemanagedby | html %]
73
                                    [% ELSE %]
74
                                        &nbsp;
75
                                    [% END %]
76
                                    [% IF s.manageddate %] - [% s.manageddate | $KohaDates %][% END %]
70
                                    [% IF s.manageddate %] - [% s.manageddate | $KohaDates %][% END %]
77
                                </td>
71
                                </td>
78
                                <td>
72
                                <td>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt (-32 / +30 lines)
Lines 250-256 Link Here
250
250
251
                            [% IF ( deleted ) %]<div class="alert alert-info">The selected suggestions have been deleted.</div>[% END %]
251
                            [% IF ( deleted ) %]<div class="alert alert-info">The selected suggestions have been deleted.</div>[% END %]
252
252
253
                            [% IF ( suggestions_loop ) %]
253
                            [% IF suggestions.count %]
254
                                <form action="/cgi-bin/koha/opac-suggestions.pl" class="form-inline" method="get">
254
                                <form action="/cgi-bin/koha/opac-suggestions.pl" class="form-inline" method="get">
255
                                    <fieldset>
255
                                    <fieldset>
256
                                        <label for="title">Search for:</label>
256
                                        <label for="title">Search for:</label>
Lines 309-374 Link Here
309
                                            </tr>
309
                                            </tr>
310
                                        </thead>
310
                                        </thead>
311
                                        <tbody>
311
                                        <tbody>
312
                                            [% FOREACH suggestions_loo IN suggestions_loop %]
312
                                            [% FOREACH suggestion IN suggestions %]
313
                                                <tr>
313
                                                <tr>
314
                                                    [% IF ( loggedinusername ) %]
314
                                                    [% IF logged_in_user %]
315
                                                        <td>
315
                                                        <td>
316
                                                            [% IF ( suggestions_loo.showcheckbox ) %]
316
                                                            [% IF logged_in_user.borrowernumber == suggestion.suggestedby %]
317
                                                                <input type="checkbox" class="cb" name="delete_field" value="[% suggestions_loo.suggestionid | html %]" />
317
                                                                <input type="checkbox" class="cb" name="delete_field" value="[% suggestion.suggestionid | html %]" />
318
                                                            [% END %]
318
                                                            [% END %]
319
                                                        </td>
319
                                                        </td>
320
                                                    [% END %]
320
                                                    [% END %]
321
                                                    <td>
321
                                                    <td>
322
                                                        <p><strong>[% suggestions_loo.title | html %]</strong></p>
322
                                                        <p><strong>[% suggestion.title | html %]</strong></p>
323
                                                            <p>[% IF ( suggestions_loo.author ) %][% suggestions_loo.author | html %],[% END %]
323
                                                            <p>[% IF ( suggestion.author ) %][% suggestion.author | html %],[% END %]
324
                                                                [% IF ( suggestions_loo.copyrightdate ) %] - [% suggestions_loo.copyrightdate | html %],[% END %]
324
                                                                [% IF ( suggestion.copyrightdate ) %] - [% suggestion.copyrightdate | html %],[% END %]
325
                                                                [% IF ( suggestions_loo.publishercode ) %] - [% suggestions_loo.publishercode | html %][% END %]
325
                                                                [% IF ( suggestion.publishercode ) %] - [% suggestion.publishercode | html %][% END %]
326
                                                                [% IF ( suggestions_loo.place ) %]([% suggestions_loo.place | html %])[% END %]
326
                                                                [% IF ( suggestion.place ) %]([% suggestion.place | html %])[% END %]
327
                                                                [% IF ( suggestions_loo.collectiontitle ) %] , [% suggestions_loo.collectiontitle | html %][% END %]
327
                                                                [% IF ( suggestion.collectiontitle ) %] , [% suggestion.collectiontitle | html %][% END %]
328
                                                                [% IF ( suggestions_loo.itemtype ) %] - [% AuthorisedValues.GetByCode( 'SUGGEST_FORMAT', suggestions_loo.itemtype, 1 ) | html %][% END %]
328
                                                                [% IF ( suggestion.itemtype ) %] - [% AuthorisedValues.GetByCode( 'SUGGEST_FORMAT', suggestion.itemtype, 1 ) | html %][% END %]
329
                                                        </p>
329
                                                        </p>
330
                                                    </td>
330
                                                    </td>
331
                                                    <td>
331
                                                    <td>
332
                                                        [% IF ( suggestions_loo.suggesteddate ) %][% suggestions_loo.suggesteddate |$KohaDates %][% END %]
332
                                                        [% IF ( suggestion.suggesteddate ) %][% suggestion.suggesteddate |$KohaDates %][% END %]
333
                                                    </td>
333
                                                    </td>
334
                                                    <td>
334
                                                    <td>
335
                                                        [% IF ( suggestions_loo.note ) %]
335
                                                        [% IF ( suggestion.note ) %]
336
                                                            <span class="tdlabel">Note: </span>
336
                                                            <span class="tdlabel">Note: </span>
337
                                                            [% suggestions_loo.note | html %]
337
                                                            [% suggestion.note | html %]
338
                                                        [% END %]
338
                                                        [% END %]
339
                                                    </td>
339
                                                    </td>
340
                                                    [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %]
340
                                                    [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %]
341
                                                        <td>
341
                                                        <td>
342
                                                            [% IF ( suggestions_loo.branchcodesuggestedby ) %]
342
                                                            [% IF suggestion.suggestedby %]
343
                                                                <span class="tdlabel">Suggested for:</span>
343
                                                                <span class="tdlabel">Suggested for:</span>
344
                                                                [% suggestions_loo.branchcodesuggestedby | html %]
344
                                                                [% Branches.GetName(suggestion.suggester.branchcode) | html %]
345
                                                            [% END %]
345
                                                            [% END %]
346
                                                        </td>
346
                                                        </td>
347
                                                    [% END %]
347
                                                    [% END %]
348
                                                    [% IF Koha.Preference( 'OpacSuggestionManagedBy' ) %]
348
                                                    [% IF Koha.Preference( 'OpacSuggestionManagedBy' ) %]
349
                                                    <td>
349
                                                    <td>
350
                                                        [% IF ( suggestions_loo.surnamemanagedby ) %]
350
                                                        [% IF suggestion.managedby %]
351
                                                            <span class="tdlabel">Managed by:</span>
351
                                                            <span class="tdlabel">Managed by:</span>
352
                                                            [% suggestions_loo.surnamemanagedby | html %]
352
                                                            [% INCLUDE 'patron-title.inc' patron = suggestion.manager %]
353
                                                            [% IF ( suggestions_loo.firstnamemanagedby ) %]    , [% suggestions_loo.firstnamemanagedby | html %]
353
                                                            [% IF ( suggestion.manageddate ) %] - [% suggestion.manageddate | $KohaDates %][% END %]
354
                                                            [% END %]
355
                                                            [% IF ( suggestions_loo.manageddate ) %] - [% suggestions_loo.manageddate | $KohaDates %][% END %]
356
                                                        [% END %]
354
                                                        [% END %]
357
                                                    </td>
355
                                                    </td>
358
                                                    [% END %]
356
                                                    [% END %]
359
                                                    <td>
357
                                                    <td>
360
                                                        <span class="tdlabel">Status:</span>
358
                                                        <span class="tdlabel">Status:</span>
361
                                                        [% IF ( suggestions_loo.ASKED ) %]Requested
359
                                                        [% IF ( suggestion.STATUS == 'ASKED' ) %]Requested
362
                                                        [% ELSIF ( suggestions_loo.CHECKED ) %]Checked by the library
360
                                                        [% ELSIF ( suggestion.STATUS == 'CHECKED' ) %]Checked by the library
363
                                                        [% ELSIF ( suggestions_loo.ACCEPTED ) %]Accepted by the library
361
                                                        [% ELSIF ( suggestion.STATUS == 'ACCEPTED' ) %]Accepted by the library
364
                                                        [% ELSIF ( suggestions_loo.ORDERED ) %]Ordered by the library
362
                                                        [% ELSIF ( suggestion.STATUS == 'ORDERED' ) %]Ordered by the library
365
                                                        [% ELSIF ( suggestions_loo.REJECTED ) %]Suggestion declined
363
                                                        [% ELSIF ( suggestion.STATUS == 'REJECTED' ) %]Suggestion declined
366
                                                        [% ELSIF ( suggestions_loo.AVAILABLE ) %]Available in the library
364
                                                        [% ELSIF ( suggestion.STATUS == 'AVAILABLE' ) %]Available in the library
367
                                                        [% ELSE %] [% AuthorisedValues.GetByCode( 'SUGGEST_STATUS', suggestions_loo.STATUS, 1 ) | html %] [% END %]
365
                                                        [% ELSE %] [% AuthorisedValues.GetByCode( 'SUGGEST_STATUS', suggestion.STATUS, 1 ) | html %] [% END %]
368
                                                        [% IF ( suggestions_loo.reason ) %]([% suggestions_loo.reason | html %])[% END %]
366
                                                        [% IF ( suggestion.reason ) %]([% suggestion.reason | html %])[% END %]
369
                                                    </td>
367
                                                    </td>
370
                                                </tr>
368
                                                </tr>
371
                                            [% END # / FOREACH suggestions_loo %]
369
                                            [% END # / FOREACH suggestions %]
372
                                        </tbody>
370
                                        </tbody>
373
                                    </table>
371
                                    </table>
374
372
Lines 391-397 Link Here
391
                                        <p><a class="new" href="/cgi-bin/koha/opac-suggestions.pl?op=add">New purchase suggestion</a></p>
389
                                        <p><a class="new" href="/cgi-bin/koha/opac-suggestions.pl?op=add">New purchase suggestion</a></p>
392
                                    [% END %]
390
                                    [% END %]
393
                                [% END %]
391
                                [% END %]
394
                            [% END # / IF suggestions_loop %]
392
                            [% END # / IF suggestions.count %]
395
393
396
                        [% END # IF op_else %]
394
                        [% END # IF op_else %]
397
                    </div> <!-- / #usersuggestions -->
395
                    </div> <!-- / #usersuggestions -->
(-)a/members/purchase-suggestions.pl (-3 / +2 lines)
Lines 23-31 use CGI qw ( -utf8 ); Link Here
23
use C4::Auth;
23
use C4::Auth;
24
use C4::Context;
24
use C4::Context;
25
use C4::Output;
25
use C4::Output;
26
use C4::Members;
27
use C4::Suggestions;
28
use Koha::Patrons;
26
use Koha::Patrons;
27
use Koha::Suggestions;
29
28
30
my $input = new CGI;
29
my $input = new CGI;
31
30
Lines 51-57 $template->param( Link Here
51
    suggestionsview  => 1,
50
    suggestionsview  => 1,
52
);
51
);
53
52
54
my $suggestions = SearchSuggestion( { suggestedby => $borrowernumber } );
53
my $suggestions = Koha::Suggestions->search( { suggestedby => $borrowernumber }, { prefetch => 'managedby' } );
55
54
56
$template->param( suggestions => $suggestions );
55
$template->param( suggestions => $suggestions );
57
56
(-)a/opac/opac-suggestions.pl (-47 / +36 lines)
Lines 38-44 use Koha::DateUtils qw( dt_from_string ); Link Here
38
my $input           = new CGI;
38
my $input           = new CGI;
39
my $op              = $input->param('op');
39
my $op              = $input->param('op');
40
my $biblionumber    = $input->param('biblionumber');
40
my $biblionumber    = $input->param('biblionumber');
41
my $suggestion      = $input->Vars;
42
my $negcaptcha      = $input->param('negcap');
41
my $negcaptcha      = $input->param('negcap');
43
my $suggested_by_anyone = $input->param('suggested_by_anyone') || 0;
42
my $suggested_by_anyone = $input->param('suggested_by_anyone') || 0;
44
my $need_confirm    = 0;
43
my $need_confirm    = 0;
Lines 47-56 my $need_confirm = 0; Link Here
47
if ($negcaptcha ) {
46
if ($negcaptcha ) {
48
    print $input->redirect("/cgi-bin/koha/opac-suggestions.pl");
47
    print $input->redirect("/cgi-bin/koha/opac-suggestions.pl");
49
    exit;
48
    exit;
50
} else {
51
    # don't pass 'negcap' column to DB, else DBI::Class will error
52
    # DBIx::Class::Row::store_column(): No such column 'negcap' on Koha::Schema::Result::Suggestion at  Koha/C4/Suggestions.pm
53
    delete $suggestion->{negcap};
54
}
49
}
55
50
56
#If suggestions are turned off we redirect to 404 error. This will also redirect guest suggestions
51
#If suggestions are turned off we redirect to 404 error. This will also redirect guest suggestions
Lines 59-65 if ( ! C4::Context->preference('suggestion') ) { Link Here
59
    exit;
54
    exit;
60
}
55
}
61
56
62
delete $suggestion->{$_} foreach qw<op suggested_by_anyone confirm>;
63
$op = 'else' unless $op;
57
$op = 'else' unless $op;
64
58
65
my ( $template, $borrowernumber, $cookie, @messages );
59
my ( $template, $borrowernumber, $cookie, @messages );
Lines 87-122 else { Link Here
87
    );
81
    );
88
}
82
}
89
83
84
my $suggested_by;
90
if ( $op eq 'else' ) {
85
if ( $op eq 'else' ) {
91
    if ( C4::Context->preference("OPACViewOthersSuggestions") ) {
86
    if ( C4::Context->preference("OPACViewOthersSuggestions") ) {
92
        if ( $borrowernumber ) {
87
        if ( $borrowernumber ) {
93
            # A logged in user is able to see suggestions from others
88
            # A logged in user is able to see suggestions from others
94
            $suggestion->{suggestedby} = $suggested_by_anyone
89
            $suggested_by = $suggested_by_anyone
95
                ? undef
90
                ? undef
96
                : $borrowernumber;
91
                : $borrowernumber;
97
        }
92
        }
98
        else {
93
        # else: Non logged in user is able to see all suggestions
99
            # Non logged in user is able to see all suggestions
100
            $suggestion->{suggestedby} = undef;
101
        }
102
    }
94
    }
103
    else {
95
    else {
104
        if ( $borrowernumber ) {
96
        if ( $borrowernumber ) {
105
            $suggestion->{suggestedby} = $borrowernumber;
97
            $suggested_by = $borrowernumber;
106
        }
98
        }
107
        else {
99
        else {
108
            $suggestion->{suggestedby} = -1;
100
            $suggested_by = -1;
109
        }
101
        }
110
    }
102
    }
111
} else {
103
} else {
112
    if ( $borrowernumber ) {
104
    if ( $borrowernumber ) {
113
        $suggestion->{suggestedby} = $borrowernumber;
105
        $suggested_by = $borrowernumber;
114
    }
106
    }
115
    else {
107
    else {
116
        $suggestion->{suggestedby} = C4::Context->preference("AnonymousPatron");
108
        $suggested_by = C4::Context->preference("AnonymousPatron");
117
    }
109
    }
118
}
110
}
119
111
112
my @suggestion_fields =
113
  qw( title author copyrightdate isbn publishercode collectiontitle place quantity itemtype patronreason note );
114
my $suggestion = {
115
    map {
116
        # Keep parameters that are not an empty string
117
        my $p = $input->param($_);
118
        ( defined $p && $p ne '' ? ( $_ => $p ) : () )
119
    } @suggestion_fields
120
};
121
120
if ( $op eq "add_validate" && not $biblionumber ) { # If we are creating the suggestion from an existing record we do not want to search for duplicates
122
if ( $op eq "add_validate" && not $biblionumber ) { # If we are creating the suggestion from an existing record we do not want to search for duplicates
121
    $op = 'add_confirm';
123
    $op = 'add_confirm';
122
    my $biblio = MarcRecordFromNewSuggestion($suggestion);
124
    my $biblio = MarcRecordFromNewSuggestion($suggestion);
Lines 129-152 if ( $op eq "add_validate" && not $biblionumber ) { # If we are creating the sug Link Here
129
131
130
my $patrons_pending_suggestions_count = 0;
132
my $patrons_pending_suggestions_count = 0;
131
if ( $borrowernumber && C4::Context->preference("MaxOpenSuggestions") ne '' ) {
133
if ( $borrowernumber && C4::Context->preference("MaxOpenSuggestions") ne '' ) {
132
    $patrons_pending_suggestions_count = scalar @{ SearchSuggestion( { suggestedby => $borrowernumber, STATUS => 'ASKED' } ) } ;
134
    $patrons_pending_suggestions_count = Koha::Suggestions->search(
135
        {
136
            suggestedby => $borrowernumber,
137
            STATUS => 'ASKED',
138
        }
139
    )->count;
133
}
140
}
134
141
135
if ( $op eq "add_confirm" ) {
142
if ( $op eq "add_confirm" ) {
136
    my $suggestions_loop = &SearchSuggestion($suggestion);
143
    my $suggestions = Koha::Suggestions->search($suggestion);
137
    if ( C4::Context->preference("MaxOpenSuggestions") ne '' && $patrons_pending_suggestions_count >= C4::Context->preference("MaxOpenSuggestions") ) #only check limit for signed in borrowers
144
    if ( C4::Context->preference("MaxOpenSuggestions") ne '' && $patrons_pending_suggestions_count >= C4::Context->preference("MaxOpenSuggestions") ) #only check limit for signed in borrowers
138
    {
145
    {
139
        push @messages, { type => 'error', code => 'too_many' };
146
        push @messages, { type => 'error', code => 'too_many' };
140
    }
147
    }
141
    elsif ( @$suggestions_loop >= 1 ) {
148
    elsif ( $suggestions->count >= 1 ) {
142
149
143
        #some suggestion are answering the request Donot Add
150
        #some suggestion are answering the request Donot Add
144
        for my $suggestion (@$suggestions_loop) {
151
        while ( my $suggestion = $suggestions->next ) {
145
            push @messages,
152
            push @messages,
146
              {
153
              {
147
                type => 'error',
154
                type => 'error',
148
                code => 'already_exists',
155
                code => 'already_exists',
149
                id   => $suggestion->{suggestionid}
156
                id   => $suggestion->suggestionid
150
              };
157
              };
151
            last;
158
            last;
152
        }
159
        }
Lines 165-183 if ( $op eq "add_confirm" ) { Link Here
165
        &NewSuggestion($suggestion);
172
        &NewSuggestion($suggestion);
166
        $patrons_pending_suggestions_count++;
173
        $patrons_pending_suggestions_count++;
167
174
168
        # delete empty fields, to avoid filter in "SearchSuggestion"
169
        foreach my $field ( qw( title author publishercode copyrightdate place collectiontitle isbn STATUS ) ) {
170
            delete $suggestion->{$field}; #clear search filters (except borrower related) to show all suggestions after placing a new one
171
        }
172
        $suggestions_loop = &SearchSuggestion($suggestion);
173
174
        push @messages, { type => 'info', code => 'success_on_inserted' };
175
        push @messages, { type => 'info', code => 'success_on_inserted' };
175
176
176
    }
177
    }
177
    $op = 'else';
178
    $op = 'else';
178
}
179
}
179
180
180
my $suggestions_loop = &SearchSuggestion({suggestedby => $suggestion->{suggestedby}});
181
my $suggestions = Koha::Suggestions->search(
182
    {
183
        $suggestion->{suggestedby}
184
        ? ( suggestedby => $suggestion->{suggestedby} )
185
        : ()
186
    }
187
);
188
181
if ( $op eq "delete_confirm" ) {
189
if ( $op eq "delete_confirm" ) {
182
    my @delete_field = $input->multi_param("delete_field");
190
    my @delete_field = $input->multi_param("delete_field");
183
    foreach my $delete_field (@delete_field) {
191
    foreach my $delete_field (@delete_field) {
Lines 188-211 if ( $op eq "delete_confirm" ) { Link Here
188
    exit;
196
    exit;
189
}
197
}
190
198
191
map{
192
    my $s = $_;
193
    my $library = Koha::Libraries->find($s->{branchcodesuggestedby});
194
    $library ? $s->{branchcodesuggestedby} = $library->branchname : ()
195
} @$suggestions_loop;
196
197
foreach my $suggestion(@$suggestions_loop) {
198
    if($suggestion->{'suggestedby'} == $borrowernumber) {
199
        $suggestion->{'showcheckbox'} = $borrowernumber;
200
    } else {
201
        $suggestion->{'showcheckbox'} = 0;
202
    }
203
    if($suggestion->{'patronreason'}){
204
        my $av = Koha::AuthorisedValues->search({ category => 'OPAC_SUG', authorised_value => $suggestion->{patronreason} });
205
        $suggestion->{'patronreason'} = $av->count ? $av->next->opac_description : '';
206
    }
207
}
208
209
my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG");
199
my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG");
210
200
211
# Is the person allowed to choose their branch
201
# Is the person allowed to choose their branch
Lines 247-253 my @mandatoryfields; Link Here
247
237
248
$template->param(
238
$template->param(
249
    %$suggestion,
239
    %$suggestion,
250
    suggestions_loop      => $suggestions_loop,
240
    suggestions           => $suggestions,
251
    patron_reason_loop    => $patron_reason_loop,
241
    patron_reason_loop    => $patron_reason_loop,
252
    "op_$op"              => 1,
242
    "op_$op"              => 1,
253
    $op                   => 1,
243
    $op                   => 1,
254
- 

Return to bug 23991