Bug 23213: Enable minimum payment threshold check in OPAC
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / en / modules / opac-account.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% USE AuthorisedValues %]
6 [% USE Price %]
7 [% SET ENABLE_OPAC_PAYMENTS = Koha.Preference('EnablePayPalOpacPayments') || plugins %]
8 [% SET DISPLAY_PAYMENT_BLOCK = 0 %]
9 [% INCLUDE 'doc-head-open.inc' %]
10 <title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog &rsaquo; Your charges</title>
11 [% INCLUDE 'doc-head-close.inc' %]
12 [% BLOCK cssinclude %]
13     [% Asset.css("css/datatables.css") | $raw %]
14 [% END %]
15 </head>
16
17 [% INCLUDE 'bodytag.inc' bodyid='opac-account' bodyclass='scrollto' %]
18 [% INCLUDE 'masthead.inc' %]
19
20 <div class="main">
21     <ul class="breadcrumb">
22         <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">&rsaquo;</span></li>
23         <li>[% IF logged_in_user %]<a href="/cgi-bin/koha/opac-user.pl">[% INCLUDE 'patron-title.inc' patron = logged_in_user %]</a>[% END %] <span class="divider">&rsaquo;</span></li>
24         <li><a href="#">Your charges</a></li>
25     </ul>
26
27     <div class="container-fluid">
28         <div class="row-fluid">
29             <div class="span2">
30                 <div id="navigation">
31                     [% INCLUDE 'navigation.inc' IsPatronPage=1 %]
32                 </div>
33             </div>
34             <div class="span10">
35                 <div id="useraccount" class="maincontent">
36
37                     [% IF message %]
38                         <div class="alert alert-info">
39                             [% IF message == 'valid_payment' %]
40                                 <p>Your payment of $[% message_value | html %] has been processed successfully!</p>
41                             [% ELSIF message == 'duplicate_payment' %]
42                                 <p>A payment with the transaction id '[% message_value | html %]' has already been posted to an account.</p>
43                                 <p>Please contact a librarian for details.</p>
44                             [% ELSIF message == 'invalid_payment' %]
45                                 <p>The transaction id '[% message_value | html %]' for this payment is invalid.</p>
46                                 <p>Please contact a librarian for details.</p>
47                             [% END %]
48                         </div>
49                     [% END %]
50
51                     [% IF payment_error %]
52                         <div id="error" class="dialog alert">
53                             <p><strong>Error:</strong> there was a problem processing your payment</p>
54
55                             [% IF payment_error == "PAYPAL_UNABLE_TO_CONNECT" %]
56                                 <p>Unable to connect to PayPal.</p>
57                                 <p>Please contact a librarian to verify your payment.</p>
58                             [% ELSIF payment_error == "PAYPAL_ERROR_PROCESSING" %]
59                                 <p>Unable to verify payment.</p>
60                                 <p>Please contact a librarian to verify your payment.</p>
61                             [% END %]
62                         </div>
63                     [% ELSIF payment %]
64                         <div class="alert alert-info">
65                             <p><strong>Payment applied:</strong> your payment of [% payment | html %] has been applied to your account</p>
66                         </div>
67                     [% END %]
68
69                     [% PROCESS 'account-table.inc' ACCOUNT_LINES = ACCOUNT_LINES, ENABLE_OPAC_PAYMENTS = ENABLE_OPAC_PAYMENTS, plugins = plugins %]
70
71
72                 </div> <!-- / #useraccount -->
73             </div> <!-- / .span10 -->
74         </div> <!-- / .row-fluid -->
75     </div> <!-- / .container-fluid -->
76 </div> <!-- / .main -->
77
78 [% INCLUDE 'opac-bottom.inc' %]
79 [% BLOCK jsinclude %]
80 [% INCLUDE 'datatables.inc' %]
81 <script>
82 $( document ).ready(function() {
83
84     var MSG_MIN_THRESHOLD = _("Minimum amount needed by this service is %s");
85
86     $("#finestable").dataTable($.extend(true, {}, dataTablesDefaults, {
87         "columnDefs": [
88              { "type": "title-string", "targets" : [ "title-string" ] }
89          ],
90          "order": [[ 0, "desc" ]]
91     } ));
92
93     $(".paypal").on("click", function() {
94         window.open('https://www.paypal.com/webapps/mpp/paypal-popup','WIPaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=1060, height=700');
95         return false;
96     });
97
98     $(".pay-online").removeClass("hidden");
99
100     $("#amount-to-pay-label").hide();
101
102     $(".checkbox-pay, input[name='payment_method']").change( function() {
103         // Disable the pay button if no fees are selected
104         //$("#submit-pay").prop("disabled", ! $(".checkbox-pay:checked").length );
105
106         // Calculate the total amount to be paid based on selected fees
107         var total = 0;
108         $(".checkbox-pay").each( function() {
109             if ( $(this).is(":checked") ) {
110                 var id = this.id.split("checkbox-pay-")[1];
111                 total += parseFloat( $("#amount-" + id).val() );
112             }
113         });
114
115         var p = Promise.resolve();
116         if ( total ) {
117             p = Promise.all(
118                 $('input[name="payment_method"]').map(function() {
119                     var self = this;
120                     return new Promise(function(resolve, reject) {
121                         var threshold = $(self).data('threshold');
122                         var help = $(self).parent().siblings('.help-block');
123                         if(threshold == '' || threshold <= total) {
124                             $(self).prop('disabled', false);
125                             help.addClass('hide');
126                         } else {
127                             $(self).prop('disabled', true);
128                             help.html(MSG_MIN_THRESHOLD.format(parseInt(threshold,10).toFixed(2))).removeClass('hide');
129                         }
130                         resolve();
131                     })
132                 }).toArray()
133             );
134
135             $("#amount-to-pay").html( total.toFixed(2) );
136             $("#amount-to-pay-label").show();
137         } else {
138             $('input[name="payment_method"]').prop('disabled', false).parent().siblings('.help-block').addClass('hide');
139             $("#amount-to-pay-label").hide();
140         }
141         p.then(function() {
142             $("#submit-pay").prop("disabled", ! $(".checkbox-pay:checked").length || ! $('input[name="payment_method"]:checked:not(:disabled)').length);
143         })
144     });
145 });
146 </script>
147 [% END %]