[freeside-commits] branch FREESIDE_3_BRANCH updated. 8924a9dd6fa3d985a061e8c6e542990173adae34

Mark Wells mark at 420.am
Fri May 24 18:14:02 PDT 2013


The branch, FREESIDE_3_BRANCH has been updated
       via  8924a9dd6fa3d985a061e8c6e542990173adae34 (commit)
      from  0501f29819775ab5a167ab81bcd9baba45c198ab (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 8924a9dd6fa3d985a061e8c6e542990173adae34
Author: Mark Wells <mark at freeside.biz>
Date:   Fri May 24 18:10:21 2013 -0700

    E911 fee summary, #23056

diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html
index 5689b12..c2ea023 100644
--- a/httemplate/elements/menu.html
+++ b/httemplate/elements/menu.html
@@ -358,6 +358,9 @@ if( $curuser->access_right('Financial reports') ) {
   $report_financial{'Tax Liability (vendor tax data)'} = [ $fsurl.'search/report_newtax.html', 'Tax liability report (vendor tax data)' ]
     if $taxproducts;
 
+  # most sites don't need this but there isn't really a config to enable it
+  $report_financial{'E911 Fee Summary'} = [ $fsurl.'search/report_e911.html', 'E911 fee summary' ];
+
   $report_financial{'Customer Accounting Summary'} = [ $fsurl.'search/report_customer_accounting_summary.html', 'Customer accounting summary report' ];
 
 } elsif($curuser->access_right('Receivables report')) {
diff --git a/httemplate/search/e911.html b/httemplate/search/e911.html
new file mode 100644
index 0000000..6a9dd0a
--- /dev/null
+++ b/httemplate/search/e911.html
@@ -0,0 +1,106 @@
+% if ( $row ) {
+%# pretty minimal report
+<& /elements/header.html, 'E911 Fee Report' &>
+<& /elements/table-grid.html &>
+<STYLE TYPE="text/css">
+table.grid TD:first-child { font-weight: normal }
+table.grid TD { font-weight: bold;
+                text-align: right;
+                padding: 1px 2px }
+</STYLE>
+  <TR><TH COLSPAN=2><% $legend %></TH></TR>
+  <TR>
+    <TD>E911 access lines:</TD>
+    <TD><% $row->{quantity} || 0 %></TD>
+  </TR>
+  <TR>
+    <TD>Total fees collected: </TD>
+    <TD><% $money_char.sprintf('%.2f', $row->{paid_amount}) %></TD>
+  </TR>
+  <TR>
+    <TD>Administrative fee (1%): </TD>
+    <TD><% $money_char.sprintf('%.2f', $row->{paid_amount} * $admin_fee) %></TD>
+  </TR>
+  <TR>
+    <TD>Amount due: </TD>
+    <TD><% $money_char.sprintf('%.2f', $row->{paid_amount} * (1-$admin_fee) ) %>
+    </TD>
+  </TR>
+</TABLE>
+<& /elements/footer.html &>
+% } else { # no data
+%   $cgi->param('error' => 'No paid E911 fees found.');
+<& /elements/errorpage.html &>
+% }
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+
+my $money_char = FS::Conf->new->config('money_char') || '$';
+
+my($begin, $end) = FS::UI::Web::parse_beginning_ending($cgi);
+
+$cgi->param('e911pkgpart') =~ /^(\d+)$/;
+my $pkgpart = $1 or die 'bad e911pkgpart';
+
+$cgi->param('agentnum') =~ /^(\d*)$/;
+my $agentnum = $1;
+
+# This has the potential to become as nightmarish as the old tax report.
+# If we end up doing multiple rows for some reason (date intervals, 
+# package classes, etc.), do NOT simply loop through this and do a 
+# bazillion scalar_sql queries.  Use a properly grouped aggregate query.
+
+my $select = 'SELECT cust_bill_pkg.billpkgnum, cust_bill_pkg.quantity, '.
+'SUM(cust_bill_pay_pkg.amount) AS paid_amount';
+
+my $from = 'FROM cust_pkg
+  JOIN cust_bill_pkg      USING (pkgnum)
+  JOIN cust_bill          USING (invnum)
+  JOIN cust_bill_pay_pkg  USING (billpkgnum)
+  JOIN cust_bill_pay      USING (billpaynum)
+';
+# going by payment application date here, which should be
+# max(invoice date, payment date)
+my $where = "WHERE cust_pkg.pkgpart = $pkgpart
+AND cust_bill_pay._date >= $begin AND cust_bill_pay._date < $end";
+
+if ( $agentnum ) {
+  $from .= '  JOIN cust_main ON (cust_pkg.custnum = cust_main.custnum)';
+  $where .= "\n AND cust_main.agentnum = $agentnum";
+}
+
+my $subquery = "$select $from $where
+GROUP BY cust_bill_pkg.billpkgnum, cust_bill_pkg.quantity";
+# This has one row for each E911 line item that has any payments applied.
+# Fields are the billpkgnum of the item (currently unused), the number of
+# E911 charges, and the total amount paid (always > 0).
+
+# now sum those rows.
+my $sql = "SELECT SUM(quantity) AS quantity, SUM(paid_amount) AS paid_amount
+FROM ($subquery) AS paid_fees"; # no grouping
+
+my $sth = dbh->prepare($sql);
+$sth->execute;
+my $row = $sth->fetchrow_hashref;
+
+my $admin_fee = 0.01; # 1% admin fee, allowed in Texas
+
+$end = '' if $end == 4294967295;
+my $legend = '';
+if ( $agentnum ) {
+  $legend = FS::agent->by_key($agentnum)->agent . ', ';
+}
+if ( $begin and $end ) {
+  $legend .= time2str('%h %o %Y', $begin) . '—' .
+             time2str('%h %o %Y', $end);
+} elsif ( $begin ) {
+  $legend .= time2str('after %h %o %Y', $begin);
+} elsif ( $end ) {
+  $legend .= time2str('before %h %o %Y', $end);
+} else {
+  $legend .= 'any time';
+}
+$legend = ucfirst($legend);
+</%init>
diff --git a/httemplate/search/report_e911.html b/httemplate/search/report_e911.html
new file mode 100644
index 0000000..fd96860
--- /dev/null
+++ b/httemplate/search/report_e911.html
@@ -0,0 +1,41 @@
+<& /elements/header.html, 'E911 Fee Report' &>
+
+<FORM ACTION="e911.html" METHOD="GET">
+
+<TABLE BGCOLOR="#cccccc" CELLSPACING=0>
+
+  <& /elements/tr-select-agent.html,
+               curr_value     => scalar( $cgi->param('agentnum') ),
+               disable_empty  => 0,
+  &>
+
+  <& /elements/tr-input-beginning_ending.html &>
+
+  <& /elements/tr-select-part_pkg.html,
+                field         => 'e911pkgpart',
+                label         => 'E911 package',
+                curr_value    => $e911pkgpart,
+                disable_empty => 1,
+  &>
+
+</TABLE>
+
+<BR>
+<INPUT TYPE="submit" VALUE="<% mt('Get Report') |h %>">
+
+</FORM>
+
+<& /elements/footer.html &>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+
+my $e911pkgpart;
+# make an educated guess
+my $e911_pkg = qsearchs('part_pkg', 
+                        { 'pkg' => { op=>'LIKE', value=>'%E911%' },
+                          'disabled' => '', } );
+$e911pkgpart = $e911_pkg->pkgpart  if $e911_pkg;
+
+</%init>

-----------------------------------------------------------------------

Summary of changes:
 httemplate/elements/menu.html      |    3 +
 httemplate/search/e911.html        |  106 ++++++++++++++++++++++++++++++++++++
 httemplate/search/report_e911.html |   41 ++++++++++++++
 3 files changed, 150 insertions(+), 0 deletions(-)
 create mode 100644 httemplate/search/e911.html
 create mode 100644 httemplate/search/report_e911.html




More information about the freeside-commits mailing list