Bug 18327: Add the ability to set the received date to today on multi receiving serials
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 16 Apr 2018 21:56:06 +0000 (18:56 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 19 Apr 2018 19:37:21 +0000 (16:37 -0300)
When receiving several issues for a subscription (Serials > Serial
collection > Multi receiving), the reception date is always identical to the
publication date.
In some use cases we would like to set this "date received" value to
today.
Note: "date received" refers to the DB column serial.planneddate

To make this possible this patch replaces the JS prompt with a modal
dialog asking for
 1. the number of issues to receive
 2. if the received date must be set to today

Ergonomic note: bootstrap styled buttons are used, but they do not display correctly
We may need to improve that (later)

Test plan:
- Receive 1 or more serials using the "Multi receiving" buttons
Note that this button appears twice, on the "serial collection
information" and the "serial edition" pages
- Try with and without the new checkbox ticked and confirm the behaviour
is correct (i.e. date received is set to today or set to the publish
date)
- Make sure "Edit serials" and "Generate next" buttons still work as
before

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt
serials/serials-collection.pl

index c00c7be..7f26f8b 100644 (file)
        <div id="yui-main">
        <div class="yui-b">
 
+    <!-- Modal -->
+    <div id="multi_receiving" class="modal" tabindex="-1" role="dialog" aria-labelledby="multi_receiving_label" aria-hidden="true">
+        <div class="modal-dialog">
+            <div class="modal-content">
+                <form action="/cgi-bin/koha/serials/serials-collection.pl" method="post">
+                    <div class="modal-body">
+                        <fieldset class="rows">
+                            <legend>Multi receiving</legend>
+                            <ol>
+                                <li>
+                                <label for="nbissues" class="required">How many issues do you want to receive?</label>
+                                <input type="text"  size="25" id="nbissues" name="nbissues" required="required" />
+                                <li>
+                                <li>
+                                    <label for="date_received_today">Set the date received to today?</label>
+                                    <input type="checkbox" id="date_received_today" name="date_received_today" />
+                                </li>
+                            </ol>
+                            <input type="hidden" name="op" value="gennext" />
+                            <input type="hidden" name="subscriptionid" value="[% subscriptionidlist %]" />
+                        </fieldset>
+                    </div>
+
+                    <div class="modal-footer">
+                        <a href="#" class="cancel" data-dismiss="modal" aria-hidden="true">Cancel</a>
+                        <input type="submit" class="btn btn-default approve" value="Multi receiving" />
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+
 
 [% UNLESS ( popup ) %]
        [% INCLUDE 'serials-toolbar.inc' %]
 <div id="subscription-year-[% year.year %]">
     [% IF ( CAN_user_serials_receive_serials ) %]
         <p>
-            <input type="submit" value="Edit serials" />&nbsp;
+            <div class="btn-group"><input type="submit" value="Edit serials" class="btn btn-default btn-sm" /></div>
             [% UNLESS subscription.closed %]
-                <input type="button" value="Generate next" onclick="javascript:generateNext([% subscriptionidlist %])" />
-                [% IF ( subscriptions.size == 1 and !serialsadditems ) %]&nbsp;<input type="button" value="Multi receiving" onclick="javascript:generateReceive([% subscriptionidlist %])" />[% END %]
+                <div class="btn-group"><input type="button" value="Generate next" onclick="javascription:generateNext([% subscriptionidlist %])" class="btn btn-default btn-sm" /></div>
+                [% IF ( subscriptions.size == 1 and !serialsadditems ) %]&nbsp;
+                    <div class="btn-group"><a href="#multi_receiving" role="button" class="btn btn-default btn-sm" data-toggle="modal"><i class="fa fa-plus"></i> Multi receiving</a></div>
+                [% END %]
             [% END %]
         </p>
     [% END %]
     </script>
     [% Asset.js("js/serials-toolbar.js") %]
     [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") %]
+
     <script type="text/javascript">
-        function generateReceive(subscriptionid) {
-            if(nbissues=prompt(_("How many issues do you want to receive ?"))){
-                document.location = 'serials-collection.pl?op=gennext&subscriptionid='+subscriptionid+'&nbissues='+nbissues;
-            }
-        }
+
         function print_slip(subscriptionid,issue){
             var myurl = 'routing-preview.pl?ok=1&subscriptionid='+subscriptionid+'&issue='+issue;
             window.open(myurl,'PrintSlip','width=500,height=500,toolbar=no,scrollbars=yes');
                 "bInfo": false,
                 "bFilter": false,
             } ));
+
+            $('#multi_receiving').on('show', function () {
+               $(this).find(".modal-body").html($(".serials_multi_receiving")[0].outerHTML);
+            });
         });
 
     </script>
index ed102c2..a4fd91d 100755 (executable)
@@ -28,12 +28,15 @@ use C4::Letters;
 use C4::Output;
 use C4::Context;
 
+use Koha::DateUtils qw( dt_from_string );
+
 use List::MoreUtils qw/uniq/;
 
 
 my $query = new CGI;
 my $op = $query->param('op') || q{};
 my $nbissues=$query->param('nbissues');
+my $date_received_today = $query->param('date_received_today') || 0;
 my $dbh = C4::Context->dbh;
 
 my ($template, $loggedinuser, $cookie)
@@ -66,8 +69,9 @@ if($op eq 'gennext' && @subscriptionid){
         $sth->execute($subscriptionid);
         # modify actual expected issue, to generate the next
         if ( my $issue = $sth->fetchrow_hashref ) {
+            my $planneddate = $date_received_today ? dt_from_string : $issue->{planneddate};
             ModSerialStatus( $issue->{serialid}, $issue->{serialseq},
-                    $issue->{planneddate}, $issue->{publisheddate},
+                    $planneddate, $issue->{publisheddate},
                     $issue->{publisheddatetext}, $status, "" );
         } else {
             require C4::Serials::Numberpattern;
@@ -81,9 +85,10 @@ if($op eq 'gennext' && @subscriptionid){
 
              ## We generate the next publication date
              my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, 1);
+             my $planneddate = $date_received_today ? dt_from_string : $nextpublisheddate;
              ## Creating the new issue
              NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
-                     1, $nextpublisheddate, $nextpublisheddate );
+                     1, $planneddate, $nextpublisheddate );
 
              ## Updating the subscription seq status
              my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?