Bug 31036: Treat SIP00 that same as CASH
[koha-ffzg.git] / koha-tmpl / intranet-tmpl / prog / en / modules / pos / register.tt
index 5569539..a6fa3d6 100644 (file)
@@ -7,7 +7,7 @@
 [% SET footerjs = 1 %]
 [% PROCESS 'accounts.inc' %]
 [% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Cashup</title>
+<title>Cashup &rsaquo; Koha</title>
 [% INCLUDE 'doc-head-close.inc' %]
 [% Asset.css("lib/jquery/plugins/rowGroup/stylesheets/rowGroup.dataTables.min.css") | $raw %]
 </head>
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'circ-search.inc' %]
 
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/pos/pay.pl">Point of sale</a> &rsaquo; Register details</div>
+<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
+    <ol>
+        <li>
+            <a href="/cgi-bin/koha/mainpage.pl">Home</a>
+        </li>
+        <li>
+            <a href="/cgi-bin/koha/pos/pay.pl">Cash management</a>
+        </li>
+        <li>
+            <a href="#" aria-current="page">
+                Transaction history for [% register.name | html %]
+            </a>
+        </li>
+    </ol>
+</nav>
 
 <div class="main container-fluid">
     <div class="row">
@@ -54,7 +68,7 @@
             </div>
             [% END %]
 
-            <h1>Register transaction details for [% register.name | html %]</h1>
+            <h1>Transaction history for [% register.name | html %]</h1>
 
             <h2>Summary</h2>
             <ul>
@@ -62,9 +76,9 @@
                 <li>Last cashup: [% register.last_cashup.timestamp | $KohaDates with_hours => 1 %] (<a data-toggle="modal" data-cashup="[% register.last_cashup.id | html %]" data-register="[% register.description | html %]" href="#cashupSummaryModal" class="button">Summary</a>)</li>
                 [% END %]
                 <li>Float: [% register.starting_float | $Price %]</li>
-                <li>Total income (cash): [% accountlines.credits_total * -1 | $Price %] ([% accountlines.credits_total(payment_type => 'CASH') * -1 | $Price %])</li>
-                <li>Total outgoing (cash): [% accountlines.debits_total * -1 | $Price %] ([% accountlines.debits_total( payment_type => 'CASH') * -1 | $Price %])</li>
-                <li>Total bankable: [% accountlines.total( payment_type => 'CASH') * -1 | $Price %]</li>
+                <li>Total income (cash): [% accountlines.credits_total * -1 | $Price %] ([% accountlines.credits_total(payment_type => [ 'CASH', 'SIP00' ]) * -1 | $Price %])</li>
+                <li>Total outgoing (cash): [% accountlines.debits_total * -1 | $Price %] ([% accountlines.debits_total( payment_type => [ 'CASH', 'SIP00' ]) * -1 | $Price %])</li>
+                <li>Total bankable: [% accountlines.total( payment_type => [ 'CASH', 'SIP00' ]) * -1 | $Price %]</li>
             </ul>
 
             [% IF register.last_cashup %]
                             [% IF credit.debit %]
                             <tr>
                                 <td>[% accountline.accountlines_id | html %]</td>
-                                <td>{ "type": "credit", "identifier": "[%- accountline.credit_number | html -%]", "description": "[%- PROCESS account_type_description account=accountline -%] ([% AuthorisedValues.GetByCode( 'PAYMENT_TYPE', accountline.payment_type ) | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td>
+                                <td>{ "type": "credit", "identifier": "[%- accountline.credit_number | html -%]", "description": "[%- PROCESS account_type_description account=accountline -%] ([% AuthorisedValues.GetByCode( 'PAYMENT_TYPE', accountline.payment_type ) | html %])", "amount": "[% accountline.amount * -1 | $Price %]", "timestamp": "[% accountline.timestamp | $KohaDates with_hours => 1 %]" }</td>
                                 <td></td>
                                 <td>
                                     [%- PROCESS account_type_description account=credit.debit -%]
                                 <td>[% credit.debit.amount | $Price %]</td>
                                 <td></td>
                                 <td>
-                                    [% IF CAN_user_cash_management_anonymous_refund && !(credit.debit.status == 'REFUNDED' ) %]
-                                    <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=credit.debit -%]" data-accountline="[% credit.debit.accountlines_id | html %]" data-amount="[% credit.debit.amount | $Price %]" data-quantity="[% credit.debit.note | html %]"><i class="fa fa-money"></i> Issue refund</button>
-                                    [% ELSIF CAN_user_updatecharges_refund && !(credit.debit.status == 'REFUNDED') && credit.debit.borrowernumber %]
-                                    <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=credit.debit -%]" data-accountline="[% credit.debit.accountlines_id | html %]" data-amount="[% credit.debit.amount | $Price %]" data-quantity="[% credit.debit.note | html %]"><i class="fa fa-money"></i> Issue refund</button>
+                                    [% IF CAN_user_cash_management_anonymous_refund && !(credit.debit.status == 'REFUNDED') && !(credit.debit.debit_type_code == 'PAYOUT') %]
+                                    <button type="button" class="btn btn-default btn-xs pos_refund" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=credit.debit -%]" data-accountline="[% credit.debit.accountlines_id | html %]" data-amount="[% credit.debit.amount | $Price %]" data-amountoutstanding="[% credit.debit.amountoutstanding | $Price %]" data-member="[% credit.debit.borrowernumber | html %]"><i class="fa fa-money"></i> Issue refund</button>
+                                    [% ELSIF CAN_user_updatecharges_refund && !(credit.debit.status == 'REFUNDED') && credit.debit.borrowernumber && !(credit.debit.debit_type_code == 'PAYOUT') %]
+                                    <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=credit.debit -%]" data-accountline="[% credit.debit.accountlines_id | html %]" data-amount="[% credit.debit.amount | $Price %]" data-amountoutstanding="[% credit.debit.amountoutstanding | $Price %]" data-member="[% credit.debit.borrowernumber | html %]"><i class="fa fa-money"></i> Issue refund</button>
                                     [% END %]
                                 </td>
                             </tr>
                             [% IF debit.credit %]
                             <tr>
                                 <td>[% accountline.accountlines_id | html %]</td>
-                                <td>{ "type": "debit", "identifier": "[%- accountline.credit_number | html -%]", "description": "[%- PROCESS account_type_description account=accountline -%] ([% AuthorisedValues.GetByCode( 'PAYMENT_TYPE', accountline.payment_type ) | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td>
+                                <td>{ "type": "debit", "identifier": "[%- accountline.credit_number | html -%]", "description": "[%- PROCESS account_type_description account=accountline -%] ([% AuthorisedValues.GetByCode( 'PAYMENT_TYPE', accountline.payment_type ) | html %])", "amount": "[% accountline.amount * -1 | $Price %]", "timestamp": "[% accountline.timestamp | $KohaDates with_hours => 1 %]" }</td>
                                 <td></td>
-                                <td>[%- PROCESS account_type_description account=debit.credit -%]</td>
                                 <td>
+                                    [%- PROCESS account_type_description account=debit.credit -%]
                                     [%- IF debit.credit.description %][% debit.credit.description | html %][%- END -%]
                                     [%- IF ( debit.credit.itemnumber ) -%] (<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% debit.credit.item.biblionumber | uri %]&amp;itemnumber=[% debit.credit.itemnumber | uri %]">[% debit.credit.item.biblio.title | html %]</a>)[%- END -%]
                                 </td>
                                 <td>[% debit.credit.amount | $Price %]</td>
                                 <td></td>
+                                <td>
+                                    [%- IF debit.credit.credit_type_code == 'REFUND' -%]<a href="/cgi-bin/koha/members/accountline-details.pl?accountlines_id=[% debit.credit.accountlines_id | uri %]" class="btn btn-default btn-xs"><i class="fa fa-list"></i> Details</a>[%- END -%]
+                                </td>
                             </tr>
                             [% END %]
                             [% END %]
                     <ol>
                         <li>
                             <label for="trange_f">From: </label>
-                            <input type="text" size="10" id="from" class="datepickerfrom" name="trange_f" value="[% trange_f | html %]"/>
+                            <input type="text" size="10" id="from" class="flatpickr" data-date_to="to" name="trange_f" value="[% trange_f | html %]"/>
                             <label class="inline" for="trange_t">To: </label>
-                            <input type="text" size="10" id="to" class="datepickerto" name="trange_t" value="[% trange_t | html %]" />
+                            <input type="text" size="10" id="to" class="flatpickr" name="trange_t" value="[% trange_t | html %]" />
                             <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
                         </li>
                     </ol>
                             [% IF credit.debit %]
                             <tr>
                                 <td>[% accountline.accountlines_id | html %]</td>
-                                <td>{ "type": "credit", "identifier": "[%- accountline.credit_number | html -%]", "description": "[%- PROCESS account_type_description account=accountline -%] ([% accountline.payment_type | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td>
+                                <td>{ "type": "credit", "identifier": "[%- accountline.credit_number | html -%]", "description": "[%- PROCESS account_type_description account=accountline -%] ([% AuthorisedValues.GetByCode( 'PAYMENT_TYPE', accountline.payment_type ) | html %])", "amount": "[% accountline.amount * -1 | $Price %]", "timestamp": "[% accountline.timestamp | $KohaDates with_hours => 1 %]" }</td>
                                 <td></td>
                                 <td>
                                     [%- PROCESS account_type_description account=credit.debit -%]
                                 <td>[% credit.debit.amount | $Price %]</td>
                                 <td></td>
                                 <td>
-                                    [% IF CAN_user_cash_management_refund_cash_registers && !(credit.debit.status == 'REFUNDED' ) %]
-                                    <button type="button" class="btn btn-default btn-xs pos_refund" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=credit.debit -%]" data-accountline="[% credit.debit.accountlines_id | html %]" data-amount="[% credit.debit.amount | $Price %]" data-quantity="[% credit.debit.note | html %]"><i class="fa fa-money"></i> Issue refund</button>
+                                    [% IF CAN_user_cash_management_anonymous_refund && !(credit.debit.status == 'REFUNDED') && !(credit.debit.debit_type_code == 'PAYOUT') %]
+                                    <button type="button" class="btn btn-default btn-xs pos_refund" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=credit.debit -%]" data-accountline="[% credit.debit.accountlines_id | html %]" data-amount="[% credit.debit.amount | $Price %]" data-amountoutstanding="[% credit.debit.amountoutstanding | $Price %]" data-member="[% credit.debit.borrowernumber | html %]"><i class="fa fa-money"></i> Issue refund</button>
+                                    [% ELSIF CAN_user_updatecharges_refund && !(credit.debit.status == 'REFUNDED') && credit.debit.borrowernumber && !(credit.debit.debit_type_code == 'PAYOUT') %]
+                                    <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=credit.debit -%]" data-accountline="[% credit.debit.accountlines_id | html %]" data-amount="[% credit.debit.amount | $Price %]" data-amountoutstanding="[% credit.debit.amountoutstanding | $Price %]" data-member="[% credit.debit.borrowernumber | html %]"><i class="fa fa-money"></i> Issue refund</button>
                                     [% END %]
                                 </td>
                             </tr>
                             [% IF debit.credit %]
                             <tr>
                                 <td>[% accountline.accountlines_id | html %]</td>
-                                <td>{ "type": "debit", "identifier": "[%- accountline.credit_number | html -%]", "description": "[%- PROCESS account_type_description account=accountline -%] ([% accountline.payment_type | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td>
+                                <td>{ "type": "debit", "identifier": "[%- accountline.credit_number | html -%]", "description": "[%- PROCESS account_type_description account=accountline -%] ([% AuthorisedValues.GetByCode( 'PAYMENT_TYPE', accountline.payment_type ) | html %])", "amount": "[% accountline.amount * -1 | $Price %]", "timestamp": "[% accountline.timestamp | $KohaDates with_hours => 1 %]" }</td>
                                 <td></td>
-                                <td>[%- PROCESS account_type_description account=debit.credit -%]</td>
-                                <td>[%- IF debit.credit.description %][% debit.credit.description | html %][% END %]
-        &nbsp;[% IF ( debit.credit.itemnumber ) %]<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% debit.credit.item.biblionumber | uri %]&amp;itemnumber=[% debit.credit.itemnumber | uri %]">[% debit.credit.item.biblio.title | html %]</a>[% END %]</td>
+                                <td>
+                                    [%- PROCESS account_type_description account=debit.credit -%]
+                                    [%- IF debit.credit.description %][% debit.credit.description | html %][%- END -%]
+                                    [%- IF ( debit.credit.itemnumber ) -%] (<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% debit.credit.item.biblionumber | uri %]&amp;itemnumber=[% debit.credit.itemnumber | uri %]">[% debit.credit.item.biblio.title | html %]</a>)[%- END -%]
+                                </td>
                                 <td>[% debit.credit.amount | $Price %]</td>
                                 <td></td>
+                                <td>
+                                    [%- IF debit.credit.credit_type_code == 'REFUND' -%]<a href="/cgi-bin/koha/members/accountline-details.pl?accountlines_id=[% debit.credit.accountlines_id | uri %]" class="btn btn-default btn-xs"><i class="fa fa-list"></i> Details</a>[%- END -%]
+                                </td>
                             </tr>
                             [% END %]
                             [% END %]
             </table>
             [% END %]
 
+            <hr/>
+            <h2>Cashup history</h2>
+            <table id="table_cashups">
+                <thead>
+                    <tr>
+                        <th>Date</th>
+                        <th>Cashier</th>
+                        <th>Amount</th>
+                        <th data-class-name="actions">Actions</th>
+                    </tr>
+                </thead>
+            </table>
             [% END %]
         </div>
 
                     <h4 class="modal-title" id="confirmCashupLabel">Confirm cashup of <em>[% register.description | html %]</em></h4>
                 </div>
                 <div class="modal-body">
-                    Please confirm that you have removed [% accountlines.total( payment_type => 'CASH') * -1 | $Price %] from the cash register and left a float of [% register.starting_float | $Price %].
+                    Please confirm that you have removed [% accountlines.total( payment_type => [ 'CASH', 'SIP00' ]) * -1 | $Price %] from the cash register and left a float of [% register.starting_float | $Price %].
                 </div> <!-- /.modal-body -->
                 <div class="modal-footer">
                     <a href="/cgi-bin/koha/pos/register.pl?op=cashup" class="btn btn-default" id="pos_cashup_confirm">Confirm</a>
                                 </li>
                                 <li>
                                     <label class="required" for="amount">Returned to patron: </label>
-                                    <input type="number" step="0.01" id="returned" name="amount" min="0.00" required="required">
+                                    <input type="text" inputmode="decimal" pattern="^\d+(\.\d{2})?$" id="returned" name="amount" required="required">
                                     <span class="required">Required</span>
                                 </li>
-                                [% SET payment_types = [] %]
-                                [% FOR pt IN AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
-                                    [% NEXT IF pt.authorised_value.grep("^SIP[[:digit:]]{2}$").size() %]
-                                    [% payment_types.push(pt) %]
-                                [% END %]
-                                <li>
-                                    <label for="transaction_type">Transaction type: </label>
-                                    <select name="transaction_type" id="transaction_type">
-                                        [% FOREACH pt IN payment_types %]
-                                            <option value="[% pt.authorised_value | html %]">[% pt.lib | html %]</option>
-                                        [% END %]
-                                    </select>
-                                </li>
+                                [% INCLUDE 'transaction_types.inc' type="refund" %]
                             </ol>
                         </fieldset> <!-- /.rows -->
                     </div> <!-- /.modal-body -->
     [% MACRO jsinclude BLOCK %]
     [% INCLUDE 'datatables.inc' %]
     [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
+    [% INCLUDE 'format_price.inc' %]
     [% Asset.js("js/cashup_modal.js") | $raw %]
     [% INCLUDE 'calendar.inc' %]
+    [% INCLUDE 'js-date-format.inc' %]
     <script>
         var sales_table = $("#sales").dataTable($.extend(true, {}, dataTablesDefaults, {
             orderFixed: [ 0, 'asc'],
                     var details = JSON.parse(rows.data().pluck(1).pop());
                     var identifier = details.identifier || group;
                     return $('<tr class="'+details.type+'"/>')
-                        .append( '<td>'+identifier+'</td>' )
+                        .append( '<td>'+details.timestamp+' ('+identifier+')</td>' )
                         .append( '<td colspan="2">'+details.description+'</td>' )
                         .append( '<td>'+details.amount+'</td>' )
                         .append( '<td><button class="printReceipt btn btn-default btn-xs" data-accountline="'+group+'"><i class="fa fa-print"></i> ' + _("Print receipt") + '</button></td>');
                     var details = JSON.parse(rows.data().pluck(1).pop());
                     var identifier = details.identifier || group;
                     return $('<tr class="'+details.type+'"/>')
-                        .append( '<td>'+identifier+'</td>' )
+                        .append( '<td>'+details.timestamp+' ('+identifier+')</td>' )
                         .append( '<td colspan="2">'+details.description+'</td>' )
                         .append( '<td>'+details.amount+'</td>' )
                         .append( '<td><button class="printReceipt btn btn-default btn-xs" data-accountline="'+group+'"><i class="fa fa-print"></i> Print receipt</button></td>');
            var accountline = button.data('accountline');
            $('#refundline').val(accountline);
            var amount = button.data('amount');
-           $("#paid + span").replaceWith(amount);
-           $("#returned").attr({ "value": amount, "max": amount });
-           $("#returned, #transaction_type").focus();
+           var amountoutstanding = button.data('amountoutstanding') || 0;
+           var paid = amount - amountoutstanding;
+           $("#paid + span").replaceWith(paid);
+           $("#returned").attr({ "value": paid, "max": paid });
+           var member = button.data('member');
+           if ( member === '' ) {
+               $("#refund_type option[value='AC']").remove();
+           } else if ( $("#refund_type option[value='AC']").length == 0 ) {
+               $("#refund_type").prepend('<option value="AC" selected="selected">Account credit</option>');
+           }
+           $("#returned, #refund_type").focus();
         });
 
-        $(".printReceipt").click(function() {
+        $("body").on('click', ".printReceipt", function() {
             var accountlines_id = $(this).data('accountline');
             var win = window.open('/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=' + accountlines_id, '_blank');
             win.focus();
         });
 
-        $('.modal.printable').on('shown.bs.modal', function() {
-            $('.modal-dialog', this).addClass('focused');
-            $('body').addClass('modalprinter');
-
-            if ($(this).hasClass('autoprint')) {
-                window.print();
-            }
-        }).on('hidden.bs.modal', function () {
-            $('.modal-dialog', this).removeClass('focused');
-            $('body').removeClass('modalprinter');
-        });
-
-        $('.printModal').click(function() {
-            window.print();
-        });
-
-        $(document).ready(function() {
-            // http://jqueryui.com/demos/datepicker/#date-range
-            var dates = $( "#from, #to" ).datepicker({
-                changeMonth: true,
-                numberOfMonths: 1,
-                onSelect: function( selectedDate ) {
-                    var option = this.id == "from" ? "minDate" : "maxDate",
-                        instance = $( this ).data( "datepicker" );
-                        date = $.datepicker.parseDate(
-                            instance.settings.dateFormat ||
-                            $.datepicker._defaults.dateFormat,
-                            selectedDate, instance.settings );
-                    dates.not( this ).datepicker( "option", option, date );
+        var cashups_table_url = "/api/v1/cash_registers/[% register.id | html %]/cashups?";
+        var cashups_table = $("#table_cashups").kohaTable({
+            "ajax": {
+                "url": cashups_table_url
+            },
+            "header_filter": true,
+            "embed": [
+               "manager"
+            ],
+            "order": [[ 0, "asc" ]],
+            "columns": [
+                {
+                    "data": "timestamp",
+                    "searchable": true,
+                    "orderable": true,
+                    "render": function(data, type, row, meta) {
+                        return $datetime(row.timestamp);
+                    }
+                },
+                {
+                    "data": "manager.firstname:manager.surname",
+                    "searchable": true,
+                    "orderable": true,
+                    "render": function(data, type, row, meta) {
+                        var fullname;
+                        if ( row.manager.firstname == null ) {
+                            fullname = row.manager.surname;
+                        }
+                        else {
+                            fullname = row.manager.firstname + " " + row.manager.surname;
+                        }
+                        return escape_str(fullname);
+                    }
+                },
+                {
+                    "data": "amount",
+                    "searchable": true,
+                    "orderable": true,
+                    "render": function(data, type, row, meta) {
+                        var amt = row.amount * -1;
+                        return escape_price(amt);
+                    }
+                },
+                {
+                    "data": function( row, type, val, meta ) {
+                        var result = '<a class="btn btn-default btn-xs" role="button" data-toggle="modal" data-cashup="'+encodeURIComponent(row.cashup_id)+'" data-register="[% register.description | html %]" href="#cashupSummaryModal"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Summary")+'</a>\n';
+                        return result;
+                    },
+                    "searchable": false,
+                    "orderable": false
                 }
-            });
-        });
+            ]
+        }, [], 1);
     </script>
 [% END %]