Bug 23590: Add ability to edit the manager of a suggestion
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 6 Nov 2019 18:05:05 +0000 (19:05 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 25 Mar 2020 09:34:15 +0000 (09:34 +0000)
Prior to this patch there was an hidden behavior that set the manager to
the logged in user when a suggestion was edited. This patch proposes to
let the librarian pick another manager.
Other small adjustements will be added to polish this new behavior:
 * Create 2 new DB columns: suggestions.lastmodificationby and
 suggestion.lastmodificationdate
 * Choose a manager when editing a suggestion
 * Batch modify suggestions and set a manager for them
 * Let notify the new manager using the TO_PROCESS letter
 * Display the manageddate, lastmodificationby and lastmodificationdate
 info where appropriate

This first patch adds a new "Select manager" link when editing a
suggestion.

Test plan for the whole patchset:
0/
  a. Execute the update DB entry, generate the new DBIC file and restart all
  b. Create at least 2 patrons with the suggestions_manage permission
1/ Submit a new suggestion (OPAC or staff, not important)
2/ Accept it
3/ Edit it
=> "Last modification by" is empty
=> You see that you are the manager of this suggestion
4/ Click "Select manager" and search for a new manager
=> The patron search will only display patrons with the
suggestions_manage permission
5/ Save
6/ Edit again
=> The manager is set to you, but there is a note saying that previously
it was the patron you picked
=> The "Last modification by" is set to you
7/ Click "Keep existing manager"
=> The manager is now set to the previous manager
8/ Select another manager (which has a valid email address defined)
9/ Click the "notify" checkbox
10/ Save
11/ Confirm that a TO_PROCESS notice has been generated into the
message_queue table
12/ Create at least one other suggestion
13/ List the suggestions
=> There is a 4th action column to assign a manager to several
suggestions in one go.
14/ Use this new button and confirm that it works as expected
15/ Go to your purchase suggestion list (OPAC and staff)
=> You see the "managed date" displayed in a new column

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

koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt
suggestion/suggestion.pl

index 66e6d94..09bc053 100644 (file)
                 </td>
             </tr>
             <tr>
-                <th><label for="managedon">Managed by:</label> </th>
-                <td><input type="text" id="managedon" name="manageddate" class="datepicker" size="10" maxlength="10" value="[% manageddate | $KohaDates %]" />[% INCLUDE 'date-format.inc' %]</td>
-                <td><input type="hidden" id="managedby" name="managedby" value="[% managedby | html %]"/>[% IF ( managedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% managedby_borrowernumber | uri %]">[% managedby_surname | html %], [% managedby_firstname | html %] ([% suggestedby_cardnumber | html %])</a> [% Branches.GetName( managedby_branchcode ) | html %] ([% managedby_description | html %])[% END %]</td>
-            </tr>
-            <tr>
                 <th><label for="accepteddate">Accepted on:</label> </th>
                 <td><input type="text" id="accepteddate" name="accepteddate" class="datepicker" size="10" maxlength="10" value="[% accepteddate | $KohaDates %]" />[% INCLUDE 'date-format.inc' %]</td>
                 <td><input type="hidden" id="acceptedby" name="acceptedby" value="[% acceptedby | html %]"/>[% IF ( acceptedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% acceptedby_borrowernumber | uri %]">[% acceptedby_surname | html %], [% acceptedby_firstname | html %] ([% suggestedby_cardnumber | html %])</a> [% Branches.GetName( acceptedby_branchcode ) | html %] ([% acceptedby_description | html %])[% END %]</td>
             </tr>
             </tbody>
-        </table></li></ol>
+        </table></li>
+
+            <li>
+                <label for="managedon">Managed on:</label>
+                <input type="text" id="managedon" name="manageddate" class="datepicker" size="10" maxlength="10" value="[% manageddate | $KohaDates %]" />[% INCLUDE 'date-format.inc' %]
+            </li>
+            <li>
+                <label for="managedby_name">by:</label>
+                <div>
+                    <span id="managedby_name">
+                        <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% logged_in_user.borrowernumber | uri %]">You</a>
+                    </span>
+                    [% IF managedby_borrowernumber && logged_in_user.borrowernumber != managedby_borrowernumber %]
+                        | Previously was [% INCLUDE 'patron-title.inc' patron=managedby_patron hide_patron_infos_if_needed=1 %] [% Branches.GetName( managedby_branchcode ) | html %] ([% managedby_description | html %])
+                    [% END %]
+                    <br />
+                    <a id="edit_manager" class="new_window" href="#"><i class="fa fa-search"></i> Select manager</a>
+                    [% IF managedby_borrowernumber && logged_in_user.borrowernumber != managedby_borrowernumber %]
+                        <a id="restore_previous_manager" href="#"><i class="fa fa-trash"></i> Keep existing manager</a>
+                    [% END %]
+                    <input type="hidden" name="managedby" id="managedby" value="[% logged_in_user.borrowernumber | html %]" />
+                </div>
+            </li>
+        </ol>
     </fieldset>
     <fieldset class="rows"> <legend>Acquisition information</legend><ol>
         <li><label for="branchcode">Library:</label>
     [% END %]
     [% IF ( op_save )  %]
         <script>
+
+            function editManagerPopup() {
+                window.open("/cgi-bin/koha/admin/add_user_search.pl?selection_type=select",
+                    'PatronPopup',
+                    'width=740,height=450,location=yes,toolbar=no,'
+                    + 'scrollbars=yes,resize=yes'
+                );
+            }
+            function select_user(borrowernumber, borrower) {
+                $("#managedby_name").empty();
+                $("#managedby").val('');
+                var borrowername = borrower.firstname + ' ' + borrower.surname;
+                if (borrowernumber) {
+                    var managerlink = '<a href="/cgi-bin/koha/members/moremember.pl'
+                        + '?borrowernumber=' + borrowernumber + '">'
+                        + borrowername + '</a>';
+                    $('#managedby_name').html(managerlink);
+                    $('#managedby').val(borrowernumber);
+                }
+            }
+
             $(document).ready(function(){
                 calcNewsuggTotal();
                 $("#quantity,#price,#currency").on("change",function(){
                     $(".select-reason").show().find("option[value='']").attr("selected","selected");
                     $("#other_reason").hide();
                 });
+
+                $("#edit_manager").on("click",function(e){
+                    e.preventDefault();
+                    editManagerPopup();
+                });
+                $("#restore_previous_manager").on("click",function(e){
+                    e.preventDefault();
+
+                    $("#managedby_name").empty();
+                    $("#managedby").val('');
+                    var borrowername = "[% managedby_firstname | html %] [% managedby_surname | html %]";
+                    var managerlink = '<a href="/cgi-bin/koha/members/moremember.pl'
+                        + '?borrowernumber=[% managedby_borrowernumber | html %]">'
+                        + borrowername + '</a>';
+                    $('#managedby_name').html(managerlink);
+                    $('#managedby').val([% managedby_borrowernumber | html %]);
+                });
             });
         </script>
     [% END %]
index 365e1d1..723ccec 100755 (executable)
@@ -154,7 +154,7 @@ if ( $op =~ /save/i ) {
                 $suggestion_only->{ lc( $suggestion_only->{"STATUS"}) . "by" }   = C4::Context->userenv->{number};
             }
             $suggestion_only->{manageddate} = dt_from_string;
-            $suggestion_only->{"managedby"}   = C4::Context->userenv->{number};
+            $suggestion_only->{"managedby"} ||= C4::Context->userenv->{number};
         }
 
         my $otherreason = $input->param('other_reason');
@@ -334,6 +334,7 @@ foreach my $element ( qw(managedby suggestedby acceptedby) ) {
         my $patron = Koha::Patrons->find( $$suggestion_ref{$element} );
         my $category = $patron->category;
         $template->param(
+            $element."_patron"=> $patron,
             $element."_borrowernumber"=>$patron->borrowernumber,
             $element."_firstname"=>$patron->firstname,
             $element."_surname"=>$patron->surname,