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 [% WRAPPER 'header.inc' %]
17 [% INCLUDE 'circ-search.inc' %]
20 [% WRAPPER 'sub-header.inc' %]
21 [% WRAPPER breadcrumbs %]
22 [% WRAPPER breadcrumb_item bc_active= 1 %]
23 <span>Point of sale</span>
25 [% END #/ WRAPPER breadcrumbs %]
26 [% END #/ WRAPPER sub-header.inc %]
28 <div class="main container-fluid">
30 <div class="col-md-10 col-md-push-2">
32 <h1>Point of sale</h1>
34 [% IF ( registers.size == 0 ) %]
35 <div id="error_message" class="dialog message">
37 You must have at least one cash register associated with the library before you can record payments.
39 [% IF ( CAN_user_parameters_manage_cash_registers ) %]
40 <form action="/cgi-bin/koha/admin/cash_registers.pl" method="get">
41 <input type="hidden" name="op" value="add_form" />
42 <button class="new" type="submit"><i class="fa fa-plus"></i> Create a new cash register</button>
48 [% IF payment_id && !Koha.Preference('FinePaymentAutoPopup') %]
49 <div class="dialog alert audio-alert-action">
50 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> <a type="button" data-toggle="modal" data-target="#emailReceiptModal" class="btn btn-default btn-xs"><i class="fa-solid fa-envelope"></i> Email receipt</a>
54 <form name="payForm" id="payForm" method="post" action="/cgi-bin/koha/pos/pay.pl">
57 <div class="col-md-6">
58 <fieldset class="rows">
59 <legend>Items for purchase</legend>
60 Please select items from below to add to this transaction:
61 [% IF invoice_types %]
67 <th class="NoSort">Cost</th>
68 <th class="NoSort">Action</th>
72 [% FOREACH invoice IN invoice_types %]
74 <td>[% invoice.code | html %]</td>
75 <td>[% invoice.description | html %]</td>
76 <td>[% invoice.default_amount | $Price %]</td>
78 <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>
84 You have no manual invoice types defined
89 <div class="col-md-6">
91 <fieldset class="rows">
92 <legend>This sale</legend>
93 <p>Click to edit item cost or quantities</p>
94 <table id="sale" class="table_sale">
109 <td colspan="3">Total payable:</td>
118 <fieldset class="rows">
119 <legend>Collect payment</legend>
122 <label for="paid">Amount being paid: </label>
123 <input type="text" inputmode="none" pattern="[0-9]*" name="paid" id="paid" value="" readonly/>
126 <label for="collected" class="required">Amount tendered: </label>
127 <input type="text" inputmode="numeric" pattern="[0-9]*" name="collected" id="collected" value="" class="required" required="required" />
128 <span class="required">Required</span>
131 <label>Change to give: </label>
132 <span id="change">[% 0 | $Price %]</span>
133 <input type="hidden" name="change" value="[% 0 | $Price %]"/>
136 [% INCLUDE 'transaction_types.inc' type="payment" %]
139 <label for="registerid" class="required">Cash register: </label>
140 <select name="registerid" id="registerid" class="required" required="required">
141 <option id="noregister" disabled selected="selected" value="">-- Select an option--</option>
142 [% PROCESS options_for_registers %]
144 <span class="required">Required</span>
151 <input type="submit" id="submitbutton" name="submitbutton" class="btn btn-primary" value="Confirm" />
152 <a class="cancel" href="/cgi-bin/koha/pos/pay.pl">Cancel</a>
160 <div class="col-md-2 col-md-pull-10">
162 [% INCLUDE 'pos-menu.inc' %]
165 </div> <!-- /.row -->
167 <!-- Email receipt modal -->
168 <div class="modal" id="emailReceiptModal" tabindex="-1" role="dialog" aria-labelledby="emailReceiptLabel">
169 <form id="email_form" action="/cgi-bin/koha/pos/pay.pl" method="get" enctype="multipart/form-data" class="validated">
170 <input type="hidden" name="payment_id" id="payment_id" value="[% payment_id | uri %]">
171 <input type="hidden" name="collected" id="collected" value="[% collected | uri %]">
172 <input type="hidden" name="change" id="change" value="[% change | uri %]">"
173 <div class="modal-dialog" role="document">
174 <div class="modal-content">
175 <div class="modal-header">
176 <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
177 <h4 class="modal-title" id="emailReceiptLabel">Email receipt</h4>
179 <div class="modal-body">
180 <fieldset class="rows">
183 <label class="required" for="toaddr">Email address: </label>
184 <input type="email" id="toaddr" name="toaddr" required="required">
185 <span class="required">Required</span>
188 </fieldset> <!-- /.rows -->
189 </div> <!-- /.modal-body -->
190 <div class="modal-footer">
191 <input type="hidden" name="action" value="send">
192 <button type="submit" class="btn btn-default">Confirm</button>
193 <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
194 </div> <!-- /.modal-footer -->
195 </div> <!-- /.modal-content -->
196 </div> <!-- /.modal-dialog -->
197 </form> <!-- /#email_form -->
198 </div> <!-- /#emailReceiptModal
200 <!-- Change modal -->
201 <div id="confirm_change_form" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
202 <div class="modal-dialog">
203 <div class="modal-content">
204 <div class="modal-header">
205 <h3>The amount collected is more than the outstanding charge</h3>
207 <div class="modal-body">
208 <p>The amount collected from the patron is higher than the amount to be paid.</p>
209 <p>The change to give is <strong><span id="modal_change">[% 0 | $Price %]</span></strong>.</p>
210 <p>Confirm this payment?</p>
212 <div class="modal-footer">
213 <button class="btn btn-default approve" id="modal_submit" type="button"><i class="fa fa-check"></i> Yes</button>
214 <button class="btn btn-default deny cancel" href="#" data-dismiss="modal" aria-hidden="true" type="button"><i class="fa fa-times"></i> No</button>
220 [% IF payment_id && Koha.Preference('FinePaymentAutoPopup') %]
221 <!-- Automatic Print Receipt -->
222 <a id="printReceipt" style="display: none" href="#"></a>
225 [% MACRO jsinclude BLOCK %]
226 [% INCLUDE 'format_price.inc' %]
227 [% INCLUDE 'datatables.inc' %]
228 [% INCLUDE 'columns_settings.inc' %]
229 [% Asset.js("lib/jquery/plugins/jquery.jeditable.mini.js") | $raw %]
231 function moneyFormat(textObj) {
232 var newValue = textObj.value;
238 for(var i = newValue.length; 0 < i; i--) {
239 aChar = newValue.substring(i-1, i);
240 if ("0" <= aChar && aChar <= "9") {
242 dolAmount = "" + aChar + dolAmount;
245 decAmount = "" + aChar + decAmount;
248 if (aChar == "." || aChar == ",") {
254 dolAmount = decAmount;
258 if (dolAmount == "") {
262 if (dolAmount.length > 1) {
263 while(dolAmount.length > 1 && dolAmount.substring(0,1) == "0") {
264 dolAmount = dolAmount.substring(1,dolAmount.length);
267 if (decAmount.length > 2) {
268 decAmount = decAmount.substring(0,2);
271 if (decAmount.length == 1) {
272 decAmount = decAmount + "0";
274 if (decAmount.length == 0) {
275 decAmount = decAmount + "00";
278 textObj.value = dolAmount + "." + decAmount;
281 function fnClickAddRow( table, invoiceCode, invoiceTitle, invoicePrice ) {
282 var defaultPrice = { value: invoicePrice };
283 moneyFormat(defaultPrice);
289 '<button class="btn btn-default btn-xs drop" type="button"><i class="fa fa-trash-can"></i> ' + _("Remove") + '</button>',
295 function updateChangeValues() {
296 var change = $('#change')[0];
297 var zero_formatted = "[% 0 | $Price %]";
298 change.innerHTML = Math.round(($('#collected')[0].value - $('#paid')[0].value) * 100) / 100;
299 if (change.innerHTML <= 0) {
300 var paid = $('#paid')[0];
302 $('#collected').rules( "add", { min: Number(paid.value) });
303 change.innerHTML = zero_formatted;
304 $(':input[name="change"]').val(zero_formatted);
306 change.value = change.innerHTML;
308 change.innerHTML = change.value;
309 $(':input[name="change"]').val(change.value);
312 $('#modal_change').html(change.innerHTML);
315 $(document).ready(function() {
316 var sale_table = $("#sale").dataTable($.extend(true, {}, dataTablesDefaults, {
323 "bSearchable": false,
326 "mRender": function ( data, type, full ) {
327 var price = Number.parseFloat(data);
328 return price.format_price();
332 "sClass" : "editable",
335 "sClass" : "editable_int",
342 "fnDrawCallback": function (oSettings) {
344 local.$('.editable').editable( function(value, settings) {
345 var aPos = local.fnGetPosition( this );
346 local.fnUpdate( value, aPos[0], aPos[1], true, false );
350 pattern : "^\\d+(\.\\d{2})?$",
353 tooltip : _("Click to edit")
355 local.$('.editable_int').editable( function(value, settings) {
356 var aPos = local.fnGetPosition( this );
357 local.fnUpdate( value, aPos[0], aPos[1], true, false );
364 tooltip : _("Click to edit")
367 "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
368 var iTotal = aData[1] * aData[2];
369 this.fnUpdate( iTotal, nRow, 3, false, false );
371 "fnFooterCallback": function(nFoot, aData, iStart, iEnd, aiDisplay) {
373 for ( var i=0 ; i<aData.length ; i++ )
375 iTotalPrice += aData[i][3]*1;
377 iTotalPrice = iTotalPrice.format_price();
378 nFoot.getElementsByTagName('td')[1].innerHTML = iTotalPrice;
379 $('#paid').val(iTotalPrice);
380 $('#paid').trigger('change');
385 $("#sale").on("click", "button.drop", function(){
386 sale_table.DataTable().row($(this).parents('tr')).remove().draw(false);
389 var items_table_settings = [% TablesSettings.GetTableSettings('pos', 'pay', 'invoices', 'json') | $raw %];
390 var items_table = KohaTable("invoices", {
391 "sPaginationType": "full",
392 "aaSorting": [[ 0, "asc" ]],
394 }, items_table_settings, false);
396 $("#invoices").on("click", ".add_button", function(e) {
398 fnClickAddRow(sale_table, $( this ).data('invoiceCode'), $( this ).data('invoiceTitle'), $( this ).data('invoicePrice') );
399 if($('#invoices_filter').find('input[type=search]').val() !== ''){
400 items_table.fnFilter( '' );
404 // Change calculation and modal
405 var change = $('#change')[0];
406 $("#paid, #collected").on("change",function() {
408 if (change != undefined) {
409 updateChangeValues();
414 $('#modal_submit').click(function() {
416 $('#payForm').submit();
419 $('#payForm').validate({
436 $('#payForm').submit(function(e){
437 // first, clear stale sales 'rows' from the payForm
438 if($('input[name="sales"]').length > 0) {
439 $('input[name="sales"]').each(function() {
444 // now, process the current & fresh contents of the sale_table
445 if (change != undefined && change.innerHTML > 0.00 && !checked) {
447 $("#confirm_change_form").modal("show");
449 var rows = sale_table.fnGetData();
450 rows.forEach(function (row, index) {
459 value: JSON.stringify(sale)
460 }).appendTo('#payForm');
466 [% IF payment_id && Koha.Preference('FinePaymentAutoPopup') %]
467 $("#printReceipt").click(function() {
468 var win = window.open('/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=[% payment_id | uri %]&collected=[% collected | uri %]&change=[% change | uri %]', '_blank');
471 $("#printReceipt").click();
477 [% INCLUDE 'intranet-bottom.inc' %]