Bug 10862: (follow-up) fix a couple of issues
[koha_fer] / koha-tmpl / intranet-tmpl / prog / en / modules / acqui / invoices.tt
index 90d7fe1..7bfef8c 100644 (file)
@@ -4,25 +4,82 @@
 <title>Koha &rsaquo; Acquisitions &rsaquo; Invoices</title>
 <link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
-[% INCLUDE 'datatables-strings.inc' %]
-<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
+[% INCLUDE 'datatables.inc' %]
 [% INCLUDE 'calendar.inc' %]
 <script type="text/javascript">
 //<![CDATA[
 $(document).ready(function() {
-    [% IF (dateformat == 'metric') %]
-        dt_add_type_uk_date();
-    [% END %]
-    $("#resultst").dataTable($.extend(true, {}, dataTablesDefaults, {
-        bInfo: false,
-        bPaginate: false,
-        bFilter: false,
+    var resultst = $("#resultst").dataTable($.extend(true, {}, dataTablesDefaults, {
         sDom: "t",
+        bPaginate: false,
+        bInfo: false,
+        "aoColumns": [
+            null,null,null,{ "sType": "title-string" },null,null,null,null
+        ],
         aoColumnDefs: [
-            { "bSortable": false, "aTargets": [6] }
+            { "bSortable": false, "aTargets": [1, 8] },
+            { "bVisible": false, "aTargets": [0] }
         ]
     }));
+
+    $("#show_only_subscription").attr("checked", false);
+
+    $("#show_only_subscription").click(function(){
+        if ( $(this).attr("checked") ) {
+            resultst.fnFilter( "1", 0, true );
+        } else {
+            resultst.fnFilter( '', 0 );
+        }
+    });
+
+    $('#merge').click(function (ev) {
+        var booksellerid;
+        var mismatch;
+        var invoices = [ ];
+        if ($('.select-invoice:checked').size() < 2) {
+            alert(_("You must select at least two invoices to merge."));
+            return false;
+        }
+        $('.select-invoice:checked').each(function () {
+            var row = $(this).parents('tr');
+            booksellerid = booksellerid || $(row).attr('data-booksellerid');
+            if (booksellerid !== $(row).attr('data-booksellerid')) {
+                mismatch = true;
+            }
+            invoices.push({ 'invoiceid': $(row).attr('data-invoiceid'),
+                            'invoicenumber': $(row).find('td:nth-child(2) a').text(),
+                            'shipmentdate': $(row).attr('data-shipmentdate'),
+                            'billingdate': $(row).attr('data-billingdate'),
+                            'shipmentcost': $(row).attr('data-shipmentcost'),
+                            'shipment_budgetid': $(row).attr('data-shipment_budgetid'),
+                            'closedate': $(row).attr('data-closedate'), });
+            $('#merge_invoice_form').append('<input type="hidden" name="merge" value="' + $(row).attr('data-invoiceid') + '" />');
+        });
+        if (mismatch) {
+            alert(_("All invoices for merging must be from the same vendor"));
+        } else {
+            $('#merge_table tbody').empty();
+            $.each(invoices, function (idx, invoice) {
+                var row = $('<tr data-invoiceid="' + invoice.invoiceid + '"><td>' + invoice.invoicenumber + '</td><td>' + invoice.shipmentdate + '</td><td>' + invoice.billingdate + '</td><td>' + invoice.shipmentcost + '</td></tr>');
+                $(row).appendTo('#merge_table tbody');
+                $(row).click(function () {
+                    $('#merge_table tbody tr').removeClass('active');
+                    $(this).addClass('active');
+                    $('#merge_invoicenumber').text(invoice.invoicenumber);
+                    $.each(['invoiceid', 'shipmentdate', 'billingdate', 'shipmentcost', 'shipment_budgetid'], function (idx, prop) {
+                        $('#merge_' + prop).val(invoice[prop]);
+                    });
+                    if (invoice.closedate) {
+                        $('#merge_status').text(_("Closed on %s").format(invoice.closedate));
+                    } else {
+                        $('#merge_status').text(_("Open"));
+                    }
+                });
+            });
+            $('#merge_table tbody tr:first').click();
+            $('#merge_invoices').show();
+        }
+    });
 });
 //]]>
 </script>
@@ -41,10 +98,16 @@ $(document).ready(function() {
     <div class="yui-b">
       <h1>Invoices</h1>
       [% IF ( do_search ) %]
-        [% IF ( results_loop ) %]
+        [% IF invoices %]
+          <label for="show_only_subscription">
+            <input type="checkbox" style="vertical-align: middle;" id="show_only_subscription" />
+            Show only subscriptions
+          </label>
           <table id="resultst">
             <thead>
               <tr>
+                <th>&nbsp;</th>
+                <th>&nbsp;</th>
                 <th>Invoice no.</th>
                 <th>Vendor</th>
                 <th>Billing date</th>
@@ -55,36 +118,81 @@ $(document).ready(function() {
               </tr>
             </thead>
             <tbody>
-              [% FOREACH result IN results_loop %]
-                <tr>
-                  <td><a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% result.invoiceid %]">[% result.invoicenumber %]</a></td>
-                  <td><a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% result.booksellerid %]">[% result.suppliername %]</a></td>
+              [% FOREACH invoice IN invoices %]
+                <tr data-invoiceid="[% invoice.invoiceid %]" data-booksellerid="[% invoice.booksellerid %]" data-shipmentdate="[% invoice.shipmentdate | $KohaDates %]" data-billingdate="[% invoice.billingdate | $KohaDates %]" data-shipmentcost="[% invoice.shipmentcost %]" data-shipment_budgetid="[% invoice.shipmentcost_budgetid %]" data-closedate="[% invoice.closedate | $KohaDates %]">
+                  <td>[% invoice.is_linked_to_subscriptions %]</td>
+                  <td><input type="checkbox" class="select-invoice" value="[% invoice.invoiceid %]"></input></td>
+                  <td><a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoice.invoiceid %]">[% invoice.invoicenumber %]</a></td>
+                  <td><a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% invoice.booksellerid %]">[% invoice.suppliername %]</a></td>
                   <td>
-                    [% IF (result.billingdate) %]
-                      [% result.billingdate | $KohaDates %]
+                    [% IF invoice.billingdate %]
+                      <span title="[% invoice.billingdate %]">[% invoice.billingdate | $KohaDates %]</span>
+                    [% ELSE %]
+                      <span title="0000-00-00"></span>
                     [% END %]
                   </td>
-                  <td>[% result.receivedbiblios %]</td>
-                  <td>[% result.receiveditems %]</td>
+                  <td>[% invoice.receivedbiblios %]</td>
+                  <td>[% invoice.receiveditems %]</td>
                   <td>
-                    [% IF ( result.closedate ) %]
-                      Closed on [% result.closedate | $KohaDates %]
+                    [% IF invoice.closedate %]
+                      Closed on [% invoice.closedate | $KohaDates %]
                     [% ELSE %]
                       Open
                     [% END %]
                   </td>
                   <td>
-                    <a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% result.invoiceid %]">Details</a> /
-                    [% IF ( result.closedate ) %]
-                      <a href="invoice.pl?op=reopen&amp;invoiceid=[% result.invoiceid %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% supplier %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]">Reopen</a>
+                    <a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoice.invoiceid %]">Details</a> /
+                    [% IF invoice.closedate %]
+                      <a href="invoice.pl?op=reopen&amp;invoiceid=[% invoice.invoiceid %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% booksellerid %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]">Reopen</a>
                     [% ELSE %]
-                      <a href="invoice.pl?op=close&amp;invoiceid=[% result.invoiceid %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% supplier %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]">Close</a>
+                      <a href="invoice.pl?op=close&amp;invoiceid=[% invoice.invoiceid %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% booksellerid %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]">Close</a>
+                    [% END %]
+                    [% UNLESS invoice.receivedbiblios || invoice.receiveditems %]
+                      / <a href="invoice.pl?op=delete&amp;invoiceid=[% invoice.invoiceid %]&amp;referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% booksellerid %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]">Delete</a>
                     [% END %]
                   </td>
                 </tr>
               [% END %]
             </tbody>
           </table>
+          <a class="submit" id="merge" href="#merge_invoices">Merge selected invoices</a>
+            <div id="merge_invoices">
+                <form id="merge_invoice_form" action="/cgi-bin/koha/acqui/invoice.pl" method="post">
+                <fieldset class="rows">
+                    <ol>
+                    <li><h2>Merge invoices</h2></li>
+                    <li><table id="merge_table">
+                        <thead><tr><th>Invoice no.</th><th>Shipment date</th><th>Billing date</th><th>Shipment cost</th></tr></thead>
+                        <tbody>
+                        </tbody>
+                    </table></li>
+                    <li><label for="merge_invoicenumber">Invoice number:</label><span id="merge_invoicenumber"></span></li>
+                    <li><label for="merge_shipmentdate">Shipment date:</label>
+                            <input type="text" size="10" id="merge_shipmentdate" name="shipmentdate" value="" readonly="readonly" class="datepicker" /></li>
+
+                    <li><label for="merge_billingdate">Billing date:</label>
+                            <input type="text" size="10" id="merge_billingdate" name="billingdate" value="" readonly="readonly" class="datepicker" /></li>
+
+                    <li><label for="merge_shipmentcost">Shipment cost:</label>
+                            <input type="text" size="10" id="merge_shipmentcost" name="shipmentcost" value="" /></li>
+                    <li><label for="merge_shipment_budgetid">Fund:</label>
+                            <select id="merge_shipment_budgetid" name="shipment_budget_id">
+                                <option value="">No fund</option>
+                              [% FOREACH budget IN budgets_loop %]
+                                  <option value="[% budget.budget_id %]">
+                                  [% budget.budget_name %]
+                                  </option>
+                              [% END %]
+                            </select></li>
+
+                    <li><span class="label">Status:</span> <span id="merge_status"></span></li>
+                    <li><input type="submit" value="Merge" /></li>
+                    </ol>
+                    <input type="hidden" name="op" value="mod" />
+                    <input type="hidden" id="merge_invoiceid" name="invoiceid" value="" />
+                </fieldset>
+                </form>
+            </div>
         [% ELSE %]
           <p>Sorry, but there is no results for your search.</p>
           <p>Search was:
@@ -92,7 +200,7 @@ $(document).ready(function() {
               [% IF ( invoicenumber ) %]
                 <li>Invoice no.: [% invoicenumber %]</li>
               [% END %]
-              [% IF ( supplier ) %]
+              [% IF booksellerid %]
                 <li>Vendor: [% suppliername %]</li>
               [% END %]
               [% IF ( billingdatefrom ) %]
@@ -131,7 +239,7 @@ $(document).ready(function() {
               [% END %]
             </ul>
           </p>
-        [% END %]<!-- results_loop -->
+        [% END %]<!-- invoices -->
       [% ELSE %]
         <p>Use the search form on the left to find invoices.</p>
       [% END %]<!-- do_search -->
@@ -144,7 +252,7 @@ $(document).ready(function() {
         <ol>
           <li>
             <label for="invoicenumber">Invoice no:</label>
-            <input type="text" id="invoicenumber" name="invoicenumber" value="[% invoicenumber %]" />
+            <input type="text" id="invoicenumber" name="invoicenumber" value="[% invoicenumber %]" class="focus" />
           </li>
           <li>
             <label for="supplier">Vendor:</label>