remove in-template fine-totaling: mod_perl code was already doing the same
authorsenator <lebbeous@esilibrary.com>
Thu, 12 May 2011 14:15:41 +0000 (10:15 -0400)
committersenator <lebbeous@esilibrary.com>
Thu, 12 May 2011 14:15:41 +0000 (10:15 -0400)
also:
    make that fine-totaling not use floating point math.
    don't provide payment form for <= 0 totals (we're not issuing refunds)
    last copyright date in footer always current year, not hardcoded

Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/web/css/skin/default/opac/style.css
Open-ILS/web/templates/default/opac/myopac/main_payment_form.tt2
Open-ILS/web/templates/default/opac/parts/footer.tt2
Open-ILS/web/templates/default/opac/parts/myopac/main_base.tt2

index a4fa51f..e9da422 100644 (file)
@@ -560,9 +560,20 @@ sub load_myopac_hold_history {
 
 sub load_myopac_payment_form {
     my $self = shift;
-    my $r = $self->load_fines(undef, undef, [$self->cgi->param('xact')]);
-    return $r if $r;
-    return $self->load_extended_user_info || Apache2::Const::OK;
+    my $r;
+
+    $r = $self->load_fines(undef, undef, [$self->cgi->param('xact')]) and return $r;
+
+    # total selected fines
+    foreach (
+        @{$self->ctx->{"fines"}->{"circulation"}},
+        @{$self->ctx->{"fines"}->{"grocery"}}
+    ) {
+    }
+
+    $r = $self->load_extended_user_info and return $r;
+
+    return Apache2::Const::OK;
 }
 
 # TODO: add other filter options as params/configs/etc.
@@ -631,6 +642,9 @@ sub load_fines {
         }
     );
 
+    my @total_keys = qw/total_paid total_owed balance_owed/;
+    $self->ctx->{"fines"}->{@total_keys} = (0, 0, 0);
+
     while(my $resp = $req->recv) {
         my $mobts = $resp->content;
         my $circ = $mobts->circulation;
@@ -641,10 +655,10 @@ sub load_fines {
             $last_billing = pop(@billings);
         }
 
-        # XXX TODO switch to some money-safe non-fp library for math
-        $self->ctx->{"fines"}->{$_} += $mobts->$_ for (
-            qw/total_paid total_owed balance_owed/
-        );
+        # XXX TODO confirm that the following, and the later division by 100.0
+        # to get a floating point representation once again, is sufficiently
+        # "money-safe" math.
+        $self->ctx->{"fines"}->{$_} += int($mobts->$_ * 100) for (@total_keys);
 
         my $marc_xml = undef;
         if ($mobts->xact_type eq 'reservation' and
@@ -669,7 +683,8 @@ sub load_fines {
         );
     }
 
-     return;
+    $self->ctx->{"fines"}->{$_} /= 100.0 for (@total_keys);
+    return;
 }
 
 sub load_myopac_main {
index c0a9004..0ce3c8e 100644 (file)
@@ -806,6 +806,8 @@ div.select-wrapper:hover {
        height: 166px;
 }
 
+#myopac_sum_fines_placehold { float: right; width: 177px; height: 166px; }
+
 .acct_holds_temp td {
        text-align: left;
 }
index a70b684..b054f46 100644 (file)
@@ -4,8 +4,15 @@
     myopac_page = "main";
     myopac_main_page = "payment_form";
 %]
+[% IF ctx.fines.balance_owed <= 0 %]
+<div>
+    [% l("You either have no fines to pay or you have selected fines whose " _
+        "total is non-positive.  We cannot process non-positive amounts.") %]
+</div>
+[% ELSE %]
 <div id="pay_fines_now">
-    <form action="[% ctx.opac_root %]/myopac/pay" method="POST">
+    <form action="[% ctx.opac_root %]/myopac/pay" method="POST"
+        onsubmit="return confirm('[% l("Are you sure you are ready to charge [_1] to your credit card?", money(ctx.fines.balance_owed)) %]');">
         [% FOR xact IN CGI.param('xact') %]
         <input type="hidden" name="xact" value="[% xact | html %]" />
         [% END %]
@@ -24,7 +31,6 @@
                             </thead>
                             <tbody>
                             [%
-                            pay_total = 0.0;
                             FOR f IN ctx.fines.circulation;
                                 NEXT IF CGI.param('xact').size &&
                                     !CGI.param('xact').grep(f.xact.id).size;
@@ -33,9 +39,7 @@
                                     PROCESS get_marc_attrs args=attrs;
                                 ELSIF f.xact.reservation;
                                     attrs.title = f.xact.reservation.target_resource_type.name;
-                                END;
-                                # XXX use fixed point math
-                                pay_total = pay_total + f.xact.balance_owed; %]
+                                END %]
                                 <tr>
                                     <td>[% attrs.title %]</td>
                                     <td class="text-right">[% money(f.xact.balance_owed) %]</td>
@@ -44,9 +48,7 @@
                             END;
                             FOR f IN ctx.fines.grocery;
                                 NEXT IF CGI.param('xact').size &&
-                                    !CGI.param('xact').grep(f.xact.id).size;
-                                # XXX use fixed point math
-                                pay_total = pay_total + f.xact.balance_owed; %]
+                                    !CGI.param('xact').grep(f.xact.id).size %]
                                 <tr>
                                     <td>[% f.xact.last_billing_type %]</td>
                                     <td class="text-right">[% money(f.xact.balance_owed) %]</td>
                         <br />
                         <div>
                             [% l('Total amount to pay:') %]
-                            [%# XXX TODO: calculate pay_total not here in the
-                            template but rather in the mod_perl, and only
-                            proceed when that number is positive %]
-                            <strong>[% money(pay_total) %]</strong>
+                            <strong>[% money(ctx.fines.balance_owed) %]</strong>
                         </div>
                         <br />
                         [% | l('<strong>', '</strong>') %]Click [_1]Cancel[_2] to go back and (un)select other fines.[% END %]
     </form>
 </div>
 [% END %]
+[% END %]
index 70379c4..eb6db18 100644 (file)
@@ -6,7 +6,7 @@
     <a href="http://example.com">[% l('Bottom Link 5') %]</a>
 
     <div id="copyright_text" style="margin-top: 2em;">
-        [% l('Copyright &copy; 2006-2011 Georgia Public Library Service, and others') %]
+        [% l('Copyright &copy; 2006-[_1] Georgia Public Library Service, and others', date.format(date.now, '%Y')) %]
     </div>
     <div id="footer_logo">
         [% l('Powered by') %]
index 2115655..0630a10 100644 (file)
@@ -10,6 +10,9 @@
     </div>
 
     <!-- fines summary along the right of the page -->
+    [% IF myopac_main_page == "payment_form" %]
+    <div id="myopac_sum_fines_placehold"></div>
+    [% ELSE %]
     <div id="myopac_sum_fines">
         <div style="position:absolute;">
             <div style="position:relative;top:-15px;left:-23px;">
@@ -43,6 +46,7 @@
             src="[% ctx.media_prefix %]/images/pay-fines-btn.png"
             class="pos-rel-top-5" /></form>
     </div>
+    [% END %]
 
     <div style="width:662px;">
         <div style="float:left;">