Bug 23596: Edit suggestion's reason when receiving
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 8 Nov 2019 14:50:57 +0000 (15:50 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 14 Apr 2020 15:30:16 +0000 (16:30 +0100)
This patch displays and let the librarian edit the suggestion.reason
information when receiving an order.

Note that if no reason was given the edit is not possible (easily
modifiable if needed but it seems that we do not want to display too
much details unnecessarily)

Test plan:
- Create a suggestion and fill the reason
- Create an order from this suggestion
- Close the basket and start receiving the order
=> The reason is displayed and editable
- Modify the reason and click Save
- Receive again
=> The reason has been correctly modified
- Play with the "Others..." option and give a specific reason

Sponsored-by: BULAC - http://www.bulac.fr/
Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
Signed-off-by: Bouzid Fergani <bouzid.fergani@inlibro.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

acqui/finishreceive.pl
acqui/orderreceive.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt

index cc05526..a651970 100755 (executable)
@@ -56,6 +56,7 @@ my $invoiceno        = $invoice->{invoicenumber};
 my $booksellerid     = $input->param('booksellerid');
 my $cnt              = 0;
 my $bookfund         = $input->param("bookfund");
+my $suggestion_id    = $input->param("suggestionid");
 my $order            = GetOrder($ordernumber);
 my $new_ordernumber  = $ordernumber;
 
@@ -181,4 +182,12 @@ while ( my $item = $items->next )  {
     $item->store;
 }
 
+if ($suggestion_id) {
+    my $reason = $input->param("reason") || '';
+    my $other_reason = $input->param("other_reason");
+    $reason = $other_reason if $reason eq 'other';
+    my $suggestion = Koha::Suggestions->find($suggestion_id);
+    $suggestion->update( { reason => $reason } ) if $suggestion;
+}
+
 print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid&sticky_filters=1");
index f676ae8..d73f61b 100755 (executable)
@@ -186,8 +186,6 @@ if( defined $order->{tax_rate_on_receiving} ) {
     $tax_rate = $order->{tax_rate_on_ordering} + 0.0;
 }
 
-my $suggestion = GetSuggestionInfoFromBiblionumber($order->{biblionumber});
-
 my $creator = Koha::Patrons->find( $order->{created_by} );
 
 my $budget = GetBudget( $order->{budget_id} );
@@ -252,12 +250,14 @@ $template->param(
     datereceived          => $datereceived,
     order_internalnote    => $order_internalnote,
     order_vendornote      => $order_vendornote,
-    suggestionid          => $suggestion->{suggestionid},
-    surnamesuggestedby    => $suggestion->{surnamesuggestedby},
-    firstnamesuggestedby  => $suggestion->{firstnamesuggestedby},
     gst_values            => \@gst_values,
 );
 
+my $suggestion = GetSuggestionInfoFromBiblionumber($order->{biblionumber});
+if ( $suggestion ) {
+    $template->param( suggestion => $suggestion );
+}
+
 my $patron = Koha::Patrons->find( $loggedinuser )->unblessed;
 my @budget_loop;
 my $periods = GetBudgetPeriods( );
index d897270..9671bfe 100644 (file)
     </ol>
        </fieldset>
 
-    [% IF ( suggestionid ) %]
+    [% IF suggestion %]
         <fieldset class="rows">
         <legend>Suggestion</legend>
         <ol>
           <li>
             <span class="label">Suggested by: </span>
-            [% surnamesuggestedby | html %][% IF ( firstnamesuggestedby ) %], [% firstnamesuggestedby | html %][% END %] (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% suggestionid | uri %]&amp;op=show">suggestion #[% suggestionid | html %]</a>)
+            [% suggestion.surnamesuggestedby | html %][% IF suggestion.firstnamesuggestedby %], [% suggestion.firstnamesuggestedby | html %][% END %] (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% suggestion.suggestionid | uri %]&amp;op=show">suggestion #[% suggestion.suggestionid | html %]</a>)
+            [% IF suggestion.reason %]
+                <li>
+                    <span class="label">Reason:</span>
+                    [% SET avs = AuthorisedValues.GetAuthValueDropbox( 'SUGGEST' ) %]
+                    [% SET other_reason = 1 %]
+                    <select class="select-reason" id="reason" name="reason">
+                        <option value=""> -- Choose a reason -- </option>
+                        [% FOREACH reason IN suggestion_reasons %]
+                            [% IF reason.lib == suggestion.reason %]
+                                <option value="[% reason.lib | html %]" selected="selected">[% reason.lib | html %]</option>
+                                [% SET other_reason = 0 %]
+                            [% ELSE %]
+                                <option value="[% reason.lib | html %]">[% reason.lib | html %]</option>
+                            [% END %]
+                        [% END %]
+                        <option value="other">Others...</option>
+                    </select>
+
+                    <span id="other_reason" name="other_reason">
+                        [% IF other_reason %]
+                            <input type="text" size="31" id="select-other_reason" name="other_reason" placeholder="please note your reason here..." value="[% suggestion.reason | html %]"/>
+                        [% ELSE %]
+                            <input type="text" size="31" id="select-other_reason" name="other_reason" placeholder="please note your reason here..." />
+                        [% END %]
+                        <a href="#back">Cancel</a>
+                    </span>
+
+                    <input type="hidden" name="suggestionid" value="[% suggestion.suggestionid | html %]" />
+                </li>
+            [% END %]
           </li>
         </ol>
         </fieldset>
             }
             $("select[name='currency']").on("change", function(){update_unitprice()} );
             $("#unitprice_currency").on("change", function(){update_unitprice()} );
+
+            [% IF other_reason %]
+                $(".select-reason").hide();
+                $(".select-reason").find("option[value='other']").attr("selected","selected");
+                $("#other_reason").show();
+            [% ELSE %]
+                $("#other_reason").hide();
+            [% END %]
+            $(".select-reason").change(function(){
+                if($(this).val() == "other"){
+                    $(this).hide();
+                    $("#other_reason").show();
+                }
+            });
+            $("a[href*=back]").click(function(){
+                $(".select-reason").show().find("option[value='']").attr("selected","selected");
+                $("#other_reason").hide();
+            });
+
         });
     </script>
 [% END %]