6 [% USE TablesSettings %]
9 [% INCLUDE 'doc-head-open.inc' %]
10 [% SET registers = Registers.all( filters => { current_branch => 1 } ) %]
11 <title>Payments › Koha</title>
12 [% INCLUDE 'doc-head-close.inc' %]
15 <body id="payments" class="pos">
16 [% INCLUDE 'header.inc' %]
17 [% INCLUDE 'circ-search.inc' %]
19 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
22 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
25 <a href="#" aria-current="page">
32 <div class="main container-fluid">
34 <div class="col-md-10 col-md-push-2">
36 <h1>Point of sale</h1>
38 [% IF ( registers.size == 0 ) %]
39 <div id="error_message" class="dialog message">
41 You must have at least one cash register associated with the library before you can record payments.
43 [% IF ( CAN_user_parameters_manage_cash_registers ) %]
44 <form action="/cgi-bin/koha/admin/cash_registers.pl" method="get">
45 <input type="hidden" name="op" value="add_form" />
46 <button class="new" type="submit"><i class="fa fa-plus"></i> Create a new cash register</button>
52 [% IF payment_id && !Koha.Preference('FinePaymentAutoPopup') %]
53 <div class="dialog alert audio-alert-action">
54 Payment received: <a target="_blank" href="/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=[% payment_id | uri %]&collected=[% collected | uri %]&change=[% change | uri %]" class="btn btn-default btn-xs"><i class="fa fa-print"></i> Print receipt</a>
58 <form name="payForm" id="payForm" method="post" action="/cgi-bin/koha/pos/pay.pl">
61 <div class="col-md-6">
62 <fieldset class="rows">
63 <legend>Items for purchase</legend>
64 Please select items from below to add to this transaction:
65 [% IF invoice_types %]
71 <th class="NoSort">Cost</th>
72 <th class="NoSort">Action</th>
76 [% FOREACH invoice IN invoice_types %]
78 <td>[% invoice.code | html %]</td>
79 <td>[% invoice.description | html %]</td>
80 <td>[% invoice.default_amount | $Price %]</td>
82 <button type="button" class="btn btn-default btn-xs add_button" data-invoice-code="[% invoice.code | html %]" data-invoice-title="[% invoice.description | html %]" data-invoice-price="[% invoice.default_amount | html %]"><i class="fa fa-plus"></i> Add</button>
88 You have no manual invoice types defined
93 <div class="col-md-6">
95 <fieldset class="rows">
96 <legend>This sale</legend>
97 <p>Click to edit item cost or quantities</p>
98 <table id="sale" class="table_sale">
113 <td colspan="3">Total payable:</td>
122 <fieldset class="rows">
123 <legend>Collect payment</legend>
126 <label for="paid">Amount being paid: </label>
127 <input type="text" inputmode="none" pattern="[0-9]*" name="paid" id="paid" value="" readonly/>
130 <label for="collected" class="required">Amount tendered: </label>
131 <input type="text" inputmode="numeric" pattern="[0-9]*" name="collected" id="collected" value="" class="required" required="required" />
132 <span class="required">Required</span>
135 <label>Change to give: </label>
136 <span id="change">[% 0 | $Price %]</span>
137 <input type="hidden" name="change" value="[% 0 | $Price %]"/>
140 [% INCLUDE 'transaction_types.inc' type="payment" %]
143 <label for="registerid" class="required">Cash register: </label>
144 <select name="registerid" id="registerid" class="required" required="required">
145 <option id="noregister" disabled selected="selected" value="">-- Select an option--</option>
146 [% PROCESS options_for_registers %]
148 <span class="required">Required</span>
155 <input type="submit" id="submitbutton" name="submitbutton" value="Confirm" />
156 <a class="cancel" href="/cgi-bin/koha/pos/pay.pl">Cancel</a>
164 <div class="col-md-2 col-md-pull-10">
166 [% INCLUDE 'pos-menu.inc' %]
169 </div> <!-- /.row -->
172 <div id="confirm_change_form" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
173 <div class="modal-dialog">
174 <div class="modal-content">
175 <div class="modal-header">
176 <h3>The amount collected is more than the outstanding charge</h3>
178 <div class="modal-body">
179 <p>The amount collected from the patron is higher than the amount to be paid.</p>
180 <p>The change to give is <strong><span id="modal_change">[% 0 | $Price %]</span></strong>.</p>
181 <p>Confirm this payment?</p>
183 <div class="modal-footer">
184 <button class="btn btn-default approve" id="modal_submit" type="button"><i class="fa fa-check"></i> Yes</button>
185 <button class="btn btn-default deny cancel" href="#" data-dismiss="modal" aria-hidden="true" type="button"><i class="fa fa-times"></i> No</button>
191 [% IF payment_id && Koha.Preference('FinePaymentAutoPopup') %]
192 <!-- Automatic Print Receipt -->
193 <a id="printReceipt" style="display: none" href="#"></a>
196 [% MACRO jsinclude BLOCK %]
197 [% INCLUDE 'format_price.inc' %]
198 [% INCLUDE 'datatables.inc' %]
199 [% INCLUDE 'columns_settings.inc' %]
200 [% Asset.js("lib/jquery/plugins/jquery.jeditable.mini.js") | $raw %]
202 function moneyFormat(textObj) {
203 var newValue = textObj.value;
209 for(var i = newValue.length; 0 < i; i--) {
210 aChar = newValue.substring(i-1, i);
211 if ("0" <= aChar && aChar <= "9") {
213 dolAmount = "" + aChar + dolAmount;
216 decAmount = "" + aChar + decAmount;
219 if (aChar == "." || aChar == ",") {
225 dolAmount = decAmount;
229 if (dolAmount == "") {
233 if (dolAmount.length > 1) {
234 while(dolAmount.length > 1 && dolAmount.substring(0,1) == "0") {
235 dolAmount = dolAmount.substring(1,dolAmount.length);
238 if (decAmount.length > 2) {
239 decAmount = decAmount.substring(0,2);
242 if (decAmount.length == 1) {
243 decAmount = decAmount + "0";
245 if (decAmount.length == 0) {
246 decAmount = decAmount + "00";
249 textObj.value = dolAmount + "." + decAmount;
252 function fnClickAddRow( table, invoiceCode, invoiceTitle, invoicePrice ) {
253 var defaultPrice = { value: invoicePrice };
254 moneyFormat(defaultPrice);
260 '<button class="btn btn-default btn-xs drop" type="button"><i class="fa fa-trash"></i> ' + _("Remove") + '</button>',
266 function updateChangeValues() {
267 var change = $('#change')[0];
268 var zero_formatted = "[% 0 | $Price %]";
269 change.innerHTML = Math.round(($('#collected')[0].value - $('#paid')[0].value) * 100) / 100;
270 if (change.innerHTML <= 0) {
271 var paid = $('#paid')[0];
273 $('#collected').rules( "add", { min: Number(paid.value) });
274 change.innerHTML = zero_formatted;
275 $(':input[name="change"]').val(zero_formatted);
277 change.value = change.innerHTML;
279 change.innerHTML = change.value;
280 $(':input[name="change"]').val(change.value);
283 $('#modal_change').html(change.innerHTML);
286 $(document).ready(function() {
287 var sale_table = $("#sale").dataTable($.extend(true, {}, dataTablesDefaults, {
294 "bSearchable": false,
297 "mRender": function ( data, type, full ) {
298 var price = Number.parseFloat(data);
299 return price.format_price();
303 "sClass" : "editable",
306 "sClass" : "editable_int",
313 "fnDrawCallback": function (oSettings) {
315 local.$('.editable').editable( function(value, settings) {
316 var aPos = local.fnGetPosition( this );
317 local.fnUpdate( value, aPos[0], aPos[1], true, false );
321 pattern : "^\\d+(\.\\d{2})?$",
324 tooltip : _("Click to edit")
326 local.$('.editable_int').editable( function(value, settings) {
327 var aPos = local.fnGetPosition( this );
328 local.fnUpdate( value, aPos[0], aPos[1], true, false );
335 tooltip : _("Click to edit")
338 "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
339 var iTotal = aData[1] * aData[2];
340 this.fnUpdate( iTotal, nRow, 3, false, false );
342 "fnFooterCallback": function(nFoot, aData, iStart, iEnd, aiDisplay) {
344 for ( var i=0 ; i<aData.length ; i++ )
346 iTotalPrice += aData[i][3]*1;
348 iTotalPrice = iTotalPrice.format_price();
349 nFoot.getElementsByTagName('td')[1].innerHTML = iTotalPrice;
350 $('#paid').val(iTotalPrice);
351 $('#paid').trigger('change');
356 $("#sale").on("click", "button.drop", function(){
357 sale_table.DataTable().row($(this).parents('tr')).remove().draw(false);
360 var items_table_settings = [% TablesSettings.GetTableSettings('pos', 'pay', 'invoices', 'json') | $raw %];
361 var items_table = KohaTable("invoices", {
362 "sPaginationType": "full",
363 "aaSorting": [[ 0, "asc" ]],
365 }, items_table_settings, false);
367 $("#invoices").on("click", ".add_button", function(e) {
369 fnClickAddRow(sale_table, $( this ).data('invoiceCode'), $( this ).data('invoiceTitle'), $( this ).data('invoicePrice') );
370 if($('#invoices_filter').find('input[type=search]').val() !== ''){
371 items_table.fnFilter( '' );
375 // Change calculation and modal
376 var change = $('#change')[0];
377 $("#paid, #collected").on("change",function() {
379 if (change != undefined) {
380 updateChangeValues();
385 $('#modal_submit').click(function() {
387 $('#payForm').submit();
390 $('#payForm').validate({
407 $('#payForm').submit(function(e){
408 // first, clear stale sales 'rows' from the payForm
409 if($('input[name="sales"]').length > 0) {
410 $('input[name="sales"]').each(function() {
415 // now, process the current & fresh contents of the sale_table
416 if (change != undefined && change.innerHTML > 0.00 && !checked) {
418 $("#confirm_change_form").modal("show");
420 var rows = sale_table.fnGetData();
421 rows.forEach(function (row, index) {
430 value: JSON.stringify(sale)
431 }).appendTo('#payForm');
437 [% IF payment_id && Koha.Preference('FinePaymentAutoPopup') %]
438 $("#printReceipt").click(function() {
439 var win = window.open('/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=[% payment_id | uri %]&collected=[% collected | uri %]&change=[% change | uri %]', '_blank');
442 $("#printReceipt").click();
448 [% INCLUDE 'intranet-bottom.inc' %]