Bug 24163: Allow to define CSV profile for late orders export
[srvgit] / koha-tmpl / intranet-tmpl / prog / en / modules / acqui / lateorders.tt
index cdb8711..60e3168 100644 (file)
+[% USE raw %]
+[% USE Asset %]
+[% USE KohaDates %]
+[% USE Branches %]
+[% USE ColumnsSettings %]
+[% USE Price %]
+[% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; Late orders</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
-<script type="text/javascript">
-//<![CDATA[
-$(document).ready(function() {
-    $("input:checkbox[name=claim_for]").click(function(){
-        var booksellerid = $(this).attr('booksellerid');
-        if ( $("input:checkbox[name=claim_for]:checked").length > 0) {
-            $("input:checkbox[name=claim_for][booksellerid!="+booksellerid+"]").attr('disabled', true);
-        } else {
-            $("input:checkbox[name=claim_for]").attr('disabled', false);
-        }
-    });
-    $('#CheckAll').click(function(){ $("#late_orders td").checkCheckboxes();});
-    $('#CheckNone').click(function(){ $("#late_orders td").unCheckCheckboxes();});
-});
-//]]>
-</script>
 </head>
-<body>
+
+<body id="acq_lateorders" class="acq">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'acquisitions-search.inc' %]
 
 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo; <a href="lateorders.pl">Late orders</a></div>
 
-<div id="doc3" class="yui-t2">
-   
-   <div id="bd">
-       <div id="yui-main">
-       <div class="yui-b">
-       
-<h1>[% IF ( Supplier ) %][% Supplier %] : [% END %]Late orders</h1>
+<div class="main container-fluid">
+    <div class="row">
+        <div class="col-sm-10 col-sm-push-2">
+            <main>
+
+<h1>[% IF ( Supplier ) %][% Supplier | html %] : [% END %]Late orders</h1>
 <div id="acqui_lateorders">
 
 [% IF error_claim %]
     [% IF ( error_claim == "no_email" ) %]
-        <div class="error">This vendor has no email</div>
+        <div class="dialog alert">This vendor has no email</div>
+    [% ELSIF ( error_claim == "no_order_selected" ) %]
+        <div class="dialog alert">No order selected</div>
     [% ELSE %]
-        <div class="error">[% error_claim %]</div>
+        <div class="dialog alert">[% error_claim | html %]</div>
     [% END %]
 [% END %]
 [% IF info_claim %]
     <div class="dialog message">Email has been sent.</div>
 [% END %]
-[% IF ( lateorders ) %]
+[% IF lateorders.count %]
 <form action="lateorders.pl" name="claim" method="post">
   <input type="hidden" name="op" value="send_alert" />
-  <input type="hidden" name="delay" value="[% delay %]" />
-  <input type="hidden" name="booksellerid" value="[% booksellerid %]" />
+  <input type="hidden" name="delay" value="[% delay | html %]" />
+  <input type="hidden" name="booksellerid" value="[% booksellerid | html %]" />
        [% IF ( letters ) %]
        <p><label for="letter_code">Claim using notice: </label><select name="letter_code" id="letter_code">
          [% FOREACH letter IN letters %]
-               <option value="[% letter.code %]">[% letter.name %]</option>
+               <option value="[% letter.code | html %]">[% letter.name | html %]</option>
          [% END %]
          </select>
        </p>
        [% END %]
+    [% SET total = 0 %]
     <table id="late_orders">
+      <thead>
         <tr>
-            <th>Order Date</th>
-            <th>Vendor</th>
-            <th>Information</th>
-            <th>Total cost</th>
-            <th>Basket</th>
-            <th>Claims count</th>
-            <th>Claimed date</th>
             [% IF Supplier %]
                 <th><a id="CheckAll" href="#">Check all</a><br /><a id="CheckNone" href="#">Uncheck all</a></th>
             [% ELSE %]
                 <th></th>
             [% END %]
+            <th>Order line</th>
+            <th class="title-string">Order date</th>
+            <th class="title-string">Estimated delivery date</th>
+            <th>Vendor</th>
+            <th class="anti-the">Information</th>
+            <th>Total cost</th>
+            <th>Basket</th>
+            <th>Basket group</th>
+            <th>Library</th>
+            <th>Fund</th>
+            <th>Claims count</th>
+            <th class="title-string">Claimed date</th>
+            <th>Internal note</th>
+            <th>Vendor note</th>
+            <th>ISBN</th>
         </tr>
-    [% FOREACH lateorder IN lateorders %]
-        [% UNLESS ( loop.odd ) %]<tr class="highlight">
-        [% ELSE %]<tr>[% END %]
+      </thead>
+      <tbody>
+      [% FOREACH lateorder IN lateorders %]
+        <tr>
+            <td>
+                <input type="checkbox" value="[% lateorder.ordernumber | html %]" data-booksellerid="[% lateorder.basket.booksellerid | html %]" name="ordernumber">
+            </td>
+            <td>
+                [% lateorder.ordernumber | $raw %]
+            </td>
             <td>
-                ([% lateorder.supplierid %])
-                [% lateorder.orderdate %]
-                ([% lateorder.latesince %] days)
+                <span title="[% lateorder.basket.closedate | html %]">[% lateorder.basket.closedate | $KohaDates %] ([% lateorder.basket.late_since_days | html %] days)</span>
             </td>
             <td>
-                [% lateorder.supplier %]
+                [% SET estimated_delivery_date = lateorder.get_column('estimated_delivery_date') %]
+                [% IF estimated_delivery_date %]
+                    <span title="[% estimated_delivery_date | html %]">[% estimated_delivery_date | $KohaDates  %]</span>
+                [% END %]
             </td>
             <td>
-                <b>[% lateorder.title |html %]</b>
-                   [% IF ( lateorder.author ) %]<br/><i>Author:</i> [% lateorder.author %][% END %]
-                   [% IF ( lateorder.publisher ) %]
-                        <br/><i>Published by:</i> [% lateorder.publisher %]
-                        [% IF ( lateorder.publicationyear ) %]
-                            <i> in </i>[% lateorder.publicationyear %]
+                [% lateorder.basket.bookseller.name | html %]
+                ([% lateorder.basket.bookseller.id | html %])
+            </td>
+            <td>
+                <b>[% lateorder.biblio.title | html %]</b>
+                   [% IF ( lateorder.biblio.author ) %]<br/><i>Author:</i> [% lateorder.biblio.author | html %][% END %]
+                   [% IF ( lateorder.biblio.biblioitem.publishercode ) %]
+                        <br/><i>Published by:</i> [% lateorder.biblio.biblioitem.publishercode | html %]
+                        [% IF ( lateorder.biblio.biblioitem.publicationyear ) %]
+                            <i> in </i>[% lateorder.biblio.biblioitem.publicationyear | html %]
                         [% END %]
                    [% END %]
             </td>
             <td>
-                   [% lateorder.unitpricesupplier %]x[% lateorder.quantity %] = 
-                   [% lateorder.subtotal %]
-                    <p title="budget">[% lateorder.budget %]</p>
+                [% SET subtotal = (lateorder.quantity - lateorder.quantityreceived) * lateorder.rrp %]
+                [% SET total = total + subtotal %]
+                [% lateorder.rrp | html %]x[% lateorder.quantity - lateorder.quantityreceived | html %] = [% subtotal | $Price %]
             </td>
             <td>
-                 <p><a href="basket.pl?basketno=[% lateorder.basketno %]" title="basket">
-                        [% lateorder.basketno %]
-                       </a>
-                 </p>
-                 <p title="branch">[% lateorder.branch %]</p>
+                [% IF ( CAN_user_acquisition_order_manage ) %]
+                    <a href="basket.pl?basketno=[% lateorder.basketno | uri %]" title="basket">[% lateorder.basket.basketname | html %] ([% lateorder.basketno | html %])</a>
+                [% ELSE %]
+                    [% lateorder.basket.basketname | html %] ([% lateorder.basketno | html %])
+                [% END %]
             </td>
-            <td>[% lateorder.claims_count %]</td>
-            <td>[% lateorder.claimed_date %]</td>
             <td>
-                [% UNLESS lateorder.budget_lock %]
-                    <input type="checkbox" class="checkbox" name="claim_for" value="[% lateorder.ordernumber %]"  booksellerid="[% lateorder.supplierid %]"/>
+                [% IF ( lateorder.basket.basketgroupid ) %]
+                    [% IF ( CAN_user_acquisition_group_manage ) %]
+                        <a href="basketgroup.pl?op=add&booksellerid=[% lateorder.basket.booksellerid | uri %]&basketgroupid=[% lateorder.basket.basketgroupid | uri %]" title="basketgroup">[% lateorder.basket.basket_group.name | html %] ([% lateorder.basket.basketgroupid | html %])</a>
+                    [% ELSE %]
+                        [% lateorder.basket.basket_group.name | html %] ([% lateorder.basket.basketgroupid | html %])</a>
+                    [% END %]
                 [% END %]
-             </td>
             </td>
-        </tr>
-        [% END %]
-        <tr> 
-            <th>Total</th>
-            <th colspan="2">&nbsp;</th>
-            <th>[% total %]</th>
-            <th>&nbsp;</th>
-            <th>&nbsp;</th>
-            <th>&nbsp;</th>
+            <td>[% Branches.GetName( lateorder.basket.authorizer.branchcode ) | html %]
+            </td>
+            <td>[% lateorder.fund.budget_name | html %]
+            </td>
+            <td>[% lateorder.claims.count | html %]</td>
             <td>
-                <input type="submit" value="Claim Order" />
+                [% FOR claim IN lateorder.claims %]
+                    <span title="[% lateorder.claims.last.claimed_on | html %]">[% claim.claimed_on | $KohaDates %]</span>
+                    [% UNLESS loop.last %]<br/>[% END %]
+                [% END %]
             </td>
+            <td>
+                [% IF lateorder.order_internalnote %]
+                    <p class="ordernote">
+                        <span id="internal-note-[% lateorder.ordernumber | html %]">[% lateorder.order_internalnote | html %]</span>
+                        <a class="edit_note noExport" data-ordernumber="[% lateorder.ordernumber | html %]" data-note_type="internal" href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% lateorder.ordernumber | html %]&type=internal" title="Edit internal note">
+                            <i class="fa fa-pencil"></i> Edit internal note
+                        </a>
+                    </p>
+                [% ELSE %]
+                    <a class="edit_note noExport" data-ordernumber="[% lateorder.ordernumber | html %]" data-note_type="internal" href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% lateorder.ordernumber | html %]&type=internal" title="Add internal note">
+                        <i class="fa fa-plus"></i> Add internal note
+                    </a>
+                [% END %]
+            </td>
+            <td>
+                [% IF lateorder.order_vendornote %]
+                    <p class="ordernote">
+                        <span id="vendor-note-[% lateorder.ordernumber | html %]">[% lateorder.order_vendornote | html %]</span>
+                        <a class="edit_note noExport" data-ordernumber="[% lateorder.ordernumber | html %]" data-note_type="vendor" href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% lateorder.ordernumber | html %]&type=vendor" title="Edit vendor note">
+                            <i class="fa fa-pencil"></i> Edit vendor note
+                        </a>
+                    </p>
+                [% ELSE %]
+                    <a class="edit_note noExport" data-ordernumber="[% lateorder.ordernumber | html %]" data-note_type="vendor" href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber=[% lateorder.ordernumber | html %]&type=vendor" title="Add vendor note">
+                        <i class="fa fa-plus"></i> Add vendor note
+                    </a>
+                [% END %]
+            </td>
+            <td>[% lateorder.biblio.biblioitem.isbn | $raw %]</td>
         </tr>
+      [% END %]
+      </tbody>
+      <tfoot>
+        <tr>
+            <th colspan="6">Total</th>
+            <th>[% total | $Price %]</th>
+            <th colspan="9">&nbsp;</th>
+        </tr>
+      </tfoot>
     </table>
-     </form>
+    <div class="spacer"></div>
+
+    <p style="display:block;">
+        <div class="btn-group">
+          <a id="exportbutton" class="btn btn-default" href="/cgi-bin/koha/acqui/lateorders-export.pl"><i class="fa fa-download"></i> Export as CSV</a>
+          <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
+          <ul class="dropdown-menu" id="export-csv-menu">
+              <li><a href="#">Default</a></li>
+              [% IF csv_profiles %]
+                  [% FOR csv IN csv_profiles %]
+                    <li><a href="#" data-value="[% csv.export_format_id | html %]">[% csv.profile | html %]</a></li>
+                  [% END %]
+              [% END %]
+           </ul>
+        </div>
+
+        <input type="submit"  class="btn btn-default" value="Claim order" />
+    </p>
+</form>
 [% ELSE %]<p>There are no late orders.</p>
 [% END %]
-</div>
-</div>
-</div>
-<div class="yui-b">
+</div> <!-- /#acqui_lateorders -->
+</main>
+</div> <!-- /.col-sm-10.col-sm-push-2 -->
+
+<div class="col-sm-2 col-sm-pull-10">
+    <aside>
 <form action="lateorders.pl" method="get">
 <fieldset class="brief">
-<h4>Filter Results:</h4>
+<h4>Filter results:</h4>
 [% FOREACH ERROR_LOO IN ERROR_LOOP %]
-[% IF ( ERROR_LOO.delay_digits ) %]<p class="error">The number of days ([% ERROR_LOO.bad_delay %]) must be a number between 0 and 999.</p>[% END %]
+[% IF ( ERROR_LOO.delay_digits ) %]<p class="error">The number of days ([% ERROR_LOO.bad_delay | html %]) must be a number between 0 and 999.</p>[% END %]
 [% END %]
-<ol><li><label for="delay">Order date:</label><input size="3" maxlength="3" id="delay" type="text" name="delay" value="[% delay %]" /> days ago</li>
+<ol>
+    <li><label for="delay">Order date:</label><input size="3" maxlength="3" id="delay" type="text" name="delay" value="[% delay | html %]" /> days ago</li>
+    <li><label for="from">Estimated delivery date from: </label>
+        <input type="text" size="10" id="from" name="estimateddeliverydatefrom" value="[% estimateddeliverydatefrom | html %]" class="datepickerfrom" />
+        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
+    </li>
+    <li><label for="to">To: </label>
+        <input type="text" size="10" id="to" name="estimateddeliverydateto" value="[% estimateddeliverydateto | html %]" class="datepickerto" />
+        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
+    </li>
+
        <li><label for="booksellerid">Vendor:</label>
                <select id="booksellerid" size="1" tabindex="" name="booksellerid">
-                       <option value=""/>
+            <option value=""></option>
                        [% FOREACH SUPPLIER_LOO IN SUPPLIER_LOOP %]
-                [% IF ( SUPPLIER_LOO.selected ) %]<option value="[% SUPPLIER_LOO.id %]" selected="selected">[% SUPPLIER_LOO.name %]</option>
-                [% ELSE %]<option value="[% SUPPLIER_LOO.id %]">[% SUPPLIER_LOO.name %]</option>[% END %]
+                [% IF ( SUPPLIER_LOO.selected ) %]<option value="[% SUPPLIER_LOO.id | html %]" selected="selected">[% SUPPLIER_LOO.name | html %]</option>
+                [% ELSE %]<option value="[% SUPPLIER_LOO.id | html %]">[% SUPPLIER_LOO.name | html %]</option>[% END %]
                [% END %]
                </select>
 </ol>
-       <fieldset class="action"><input type="submit" value="filter" /></fieldset>
+    <fieldset class="action"><input type="submit" value="Filter" /></fieldset>
 </fieldset>
     </form>
 [% INCLUDE 'acquisitions-menu.inc' %]
+</aside>
+</div> <!-- /.col-sm-2.col-sm-pull-10 -->
 </div>
+
+<!-- Modal for editing vendor and internal notes -->
+<div class="modal" id="noteEditor" tabindex="-1" role="dialog" aria-labelledby="noteEditorLabel">
+    <div class="modal-dialog" role="document">
+        <form id="modify_order_notes" action="/cgi-bin/koha/acqui/modordernotes.pl" method="post">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
+                    <h4 class="modal-title" id="noteEditorLabel">Order note</h4>
+                </div>
+                <div class="modal-body">
+                <textarea id="ordernotes" name="ordernotes" rows="3" cols="30" class="focus">[% ordernotes | html %]</textarea>
+                <input type="hidden" id="ordernumber" name="ordernumber" value="" />
+                <input type="hidden" name="op" value="save" />
+                <input type="hidden" id="type" name="type" value="" />
+            </div>
+            <div class="modal-footer">
+                <button type="submit" class="btn btn-default">Save</button>
+                <button type="button" class="btn btn-link cancel" data-dismiss="modal">Cancel</button>
+            </div>
+            </div>
+        </form>
+    </div>
 </div>
+
+[% MACRO jsinclude BLOCK %]
+    [% Asset.js("js/acquisitions-menu.js") | $raw %]
+    [% INCLUDE 'datatables.inc' %]
+    [% INCLUDE 'columns_settings.inc' %]
+    [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
+    [% INCLUDE 'calendar.inc' %]
+    <script>
+        var late_orderst;
+        function check_uncheck() {
+            var all_nodes = $(late_orderst.fnGetNodes());
+            if ( $(all_nodes).find("input:checkbox[name=ordernumber]:checked").length > 0) {
+                var booksellerid = $(all_nodes).find("input:checkbox[name=ordernumber]:checked:first").attr("data-booksellerid");
+                $(all_nodes).find("input:checkbox[name=ordernumber][data-booksellerid!="+booksellerid+"]").prop('disabled', true);
+            } else {
+                $("input:checkbox[name=ordernumber]").prop('disabled', false);
+            }
+        }
+
+        $(document).ready(function() {
+
+            var columns_settings = [% ColumnsSettings.GetColumns( 'acqui', 'lateorders', 'late_orders', 'json' ) | $raw %];
+            late_orderst = KohaTable("late_orders", {
+                "aoColumnDefs": [
+                    { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
+                    { "sType": "anti-the", "aTargets" : [ "anti-the" ] },
+                    { "sType": "title-string", "aTargets" : [ "title-string" ] }
+                ],
+                "sPaginationType": "full",
+                "bAutoWidth": false,
+                "fnDrawCallback": function() {
+                    if ( typeof late_orderst != 'undefined' ) {
+                        check_uncheck();
+                        $('input:checkbox[name=ordernumber]').bind('click', check_uncheck);
+                    };
+                }
+            }, columns_settings );
+            $('input:checkbox[name=ordernumber]').bind('click', check_uncheck);
+            $('#CheckAll').click(function(){ $(late_orderst.fnGetNodes()).find("td").checkCheckboxes();});
+            $('#CheckNone').click(function(){ $(late_orderst.fnGetNodes()).find("td").unCheckCheckboxes();});
+
+            // Generates a dynamic link for exporting the selection's data as CSV
+            $("#exportbutton, #export-csv-menu a").click(function() {
+                var all_nodes = $(late_orderst.fnGetNodes());
+                var selected = $(all_nodes).find("input[name='ordernumber']:checked");
+
+                if (selected.length == 0) {
+                    alert(_("Please select at least one item to export."));
+                    return false;
+                }
+
+                var url = $('#exportbutton').attr('href') + '?';
+                // Building the url from currently checked boxes
+                for (var i = 0; i < selected.length; i++) {
+                    url += '&amp;ordernumber=' + selected[i].value;
+                }
+                if($(this).attr("data-value")) {
+                    url += '&amp;csv_profile=' + $(this).attr("data-value");
+                }
+                // And redirecting to the CSV page
+                location.href = url;
+                return false;
+            });
+
+            $(".edit_note").on("click", function(e) {
+                e.preventDefault();
+                var ordernumber = $(this).data("ordernumber");
+                var note_type = $(this).data("note_type");
+                var modalTitle = $(this).attr("title") + " (order number " + ordernumber + ")";
+                var note_text = $( "#" + note_type + "-note-" + ordernumber ).html();
+                $("#noteEditor .modal-title").text(modalTitle);
+                $("#ordernumber").val( ordernumber );
+                $("#ordernotes").html( note_text );
+                $("#type").val( note_type );
+                $("#noteEditor").modal("show");
+                $("#ordernotes").focus();
+            });
+
+             $("#noteEditor").on('hidden.bs.modal', function (e) {
+                $("#noteEditorLabel").html("");
+                $("#noteEditor .modal-title").text("");
+                $("#ordernotes").html( "" );
+                $("#ordernumber").val("");
+                $("#type").val("");
+            });
+        });
+    </script>
+[% END %]
+
 [% INCLUDE 'intranet-bottom.inc' %]