[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 8f2548798a84c949d47b3eb11899fe0e37987a09

Ivan ivan at 420.am
Mon Dec 17 16:09:26 PST 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  8f2548798a84c949d47b3eb11899fe0e37987a09 (commit)
      from  0ed24da8397a00b70aa03fe8bc494aad5cbb1d0c (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 8f2548798a84c949d47b3eb11899fe0e37987a09
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Mon Dec 17 16:09:22 2012 -0800

    add taxclass and paid/credit columns to line item reports, clickthrough to credit detail, RT#18676

diff --git a/httemplate/search/cust_bill_pkg.cgi b/httemplate/search/cust_bill_pkg.cgi
index 48c7684..712adb7 100644
--- a/httemplate/search/cust_bill_pkg.cgi
+++ b/httemplate/search/cust_bill_pkg.cgi
@@ -8,6 +8,7 @@
                                   ],
                  'header'      => [
                    emt('Description'),
+                   @post_desc_header,
                    ( $unearned
                      ? ( emt('Unearned'), 
                          emt('Owed'), # useful in 'paid' mode?
@@ -24,6 +25,8 @@
                    ),
                    emt('Invoice'),
                    emt('Date'),
+                   emt('Paid'),
+                   emt('Credited'),
                    FS::UI::Web::cust_header(),
                  ],
                  'fields'      => [
@@ -31,6 +34,7 @@
                            ? $_[0]->get('pkg')      # possibly use override.pkg
                            : $_[0]->get('itemdesc') # but i think this correct
                        },
+                   @post_desc,
                    #strikethrough or "N/A ($amount)" or something these when
                    # they're not applicable to pkg_tax search
                    sub { my $cust_bill_pkg = shift;
@@ -69,10 +73,13 @@
                    ),
                    'invnum',
                    sub { time2str('%b %d %Y', shift->_date ) },
+                   sub { sprintf($money_char.'%.2f', shift->get('pay_amount')) },
+                   sub { sprintf($money_char.'%.2f', shift->get('credit_amount')) },
                    \&FS::UI::Web::cust_fields,
                  ],
                  'sort_fields' => [
                    '',
+                   @post_desc_null,
                    'setup', #broken in $unearned case i guess
                    ( $unearned ? ('', '') : () ),
                    ( $use_usage eq 'recurring' or $unearned
@@ -84,47 +91,60 @@
                    ( $unearned ? ('sdate', 'edate') : () ),
                    'invnum',
                    '_date',
+                   #'pay_amount',
+                   #'credit_amount',
                  ],
                  'links'       => [
                    #'',
                    '',
+                   @post_desc_null,
                    '',
                    ( $unearned ? ( '', '' ) : () ),
                    '',
                    ( $unearned ? ( '', '' ) : () ),
                    $ilink,
                    $ilink,
+                   $pay_link,
+                   $credit_link,
                    ( map { $_ ne 'Cust. Status' ? $clink : '' }
                          FS::UI::Web::cust_header()
                    ),
                  ],
                  #'align' => 'rlrrrc'.FS::UI::Web::cust_aligns(),
-                 'align' => 'lr'.
+                 'align' => 'l'.
+                            $post_desc_align.
+                            'r'.
                             ( $unearned ? 'rc' : '' ).
                             'r'.
                             ( $unearned ? 'cc' : '' ).
-                            'rc'.
+                            'rcrr'.
                             FS::UI::Web::cust_aligns(),
                  'color' => [ 
                               #'',
                               '',
+                              @post_desc_null,
                               '',
                               ( $unearned ? ( '', '' ) : () ),
                               '',
                               ( $unearned ? ( '', '' ) : () ),
                               '',
                               '',
+                              '',
+                              '',
                               FS::UI::Web::cust_colors(),
                             ],
                  'style' => [ 
                               #'',
                               '',
+                              @post_desc_null,
                               '',
                               ( $unearned ? ( '', '' ) : () ),
                               '',
                               ( $unearned ? ( '', '' ) : () ),
                               '',
                               '',
+                              '',
+                              '',
                               FS::UI::Web::cust_styles(),
                             ],
 &>
@@ -143,7 +163,18 @@ my $unearned_base = '';
 my $unearned_sql = '';
 
 my @select = ( 'cust_bill_pkg.*', 'cust_bill._date' );
-my ($join_cust, $join_pkg ) = ('', '');
+
+my @post_desc_header = ();
+my @post_desc = ();
+my @post_desc_null = ();
+my $post_desc_align = '';
+if ( $conf->exists('enable_taxclasses') ) {
+  push @post_desc_header, 'Tax class';
+  push @post_desc, 'taxclass';
+  push @post_desc_null, '';
+  $post_desc_align .= 'l';
+  push @select, 'part_pkg.taxclass'; # or should this use override?
+}
 
 #here is the agent virtualization
 my $agentnums_sql =
@@ -549,11 +580,11 @@ if ( $cgi->param('pkg_tax') ) {
 
 }
 
-$join_cust =  '        JOIN cust_bill USING ( invnum )
-                  LEFT JOIN cust_main USING ( custnum ) ';
+my $join_cust =  '        JOIN cust_bill USING ( invnum )
+                     LEFT JOIN cust_main USING ( custnum ) ';
 
-# then we want the package and its definition
-$join_pkg = 
+# we want the package and its definition if available
+my $join_pkg = 
 ' LEFT JOIN cust_pkg      USING (pkgnum) 
   LEFT JOIN part_pkg      USING (pkgpart)';
 
@@ -614,6 +645,22 @@ if ( $cgi->param('nottax') ) {
 
 }
 
+#total payments
+my $pay_sub = "SELECT SUM(cust_bill_pay_pkg.amount) AS pay_amount,
+    billpkgnum
+  FROM cust_bill_pay_pkg
+  GROUP BY billpkgnum";
+$join_pkg .= " LEFT JOIN ($pay_sub) AS item_pay USING (billpkgnum)";
+push @select, 'item_pay.pay_amount';
+
+#total credits
+my $credit_sub = "SELECT SUM(cust_credit_bill_pkg.amount) AS credit_amount,
+    billpkgnum
+  FROM cust_credit_bill_pkg
+  GROUP BY billpkgnum";
+$join_pkg .= " LEFT JOIN ($credit_sub) AS item_credit USING (billpkgnum)";
+push @select,   'item_credit.credit_amount';
+
 my $where = ' WHERE '. join(' AND ', @where);
 
 if ($use_usage) {
@@ -645,6 +692,8 @@ my $query = {
 
 my $ilink = [ "${p}view/cust_bill.cgi?", 'invnum' ];
 my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
+my $pay_link    = ''; #[, 'billpkgnum', ];
+my $credit_link = [ "${p}search/cust_credit_bill_pkg.html?billpkgnum=", 'billpkgnum', ];
 
 my $conf = new FS::Conf;
 my $money_char = $conf->config('money_char') || '$';
diff --git a/httemplate/search/cust_credit_bill_pkg.html b/httemplate/search/cust_credit_bill_pkg.html
index 4612118..a57a5ae 100644
--- a/httemplate/search/cust_credit_bill_pkg.html
+++ b/httemplate/search/cust_credit_bill_pkg.html
@@ -1,10 +1,10 @@
 <% include( 'elements/search.html',
-              'title'       => 'Tax credits', #well, actually application of
-              'name'        => 'tax credits', # credit to line item
-              'query'       => $query,
-              'count_query' => $count_query,
-                 'count_addl'  => [ $money_char. '%.2f total', ],
-                 'header'      => [
+              'title'         => 'Credit application detail', #to line item
+              'name_singular' => 'credit application',
+              'query'         => $query,
+              'count_query'   => $count_query,
+               'count_addl'   => [ $money_char. '%.2f total', ],
+               'header'       => [
                    #'#',
 
                    'Amount',
@@ -21,8 +21,8 @@
                    'Invoice',
                    'Date',
                    FS::UI::Web::cust_header(),
-                 ],
-                 'fields'      => [
+               ],
+               'fields'       => [
                    #'creditbillpkgnum',
                    sub { sprintf($money_char.'%.2f', shift->amount ) },
 
@@ -37,8 +37,8 @@
                    'invnum',
                    sub { time2str('%b %d %Y', shift->_date ) },
                    \&FS::UI::Web::cust_fields,
-                 ],
-                 'sort_fields' => [
+               ],
+               'sort_fields'  => [
                    'amount',
                    'cust_credit_date',
                    '', #'otaker',
@@ -47,8 +47,8 @@
                    'invnum',
                    '_date',
                    #cust fields
-                 ],
-                 'links'       => [
+               ],
+               'links' => [
                    '',
                    '',
                    '',
@@ -59,9 +59,9 @@
                    ( map { $_ ne 'Cust. Status' ? $clink : '' }
                          FS::UI::Web::cust_header()
                    ),
-                 ],
-                 'align' => 'rrlllrr'.FS::UI::Web::cust_aligns(),
-                 'color' => [ 
+               ],
+               'align' => 'rrlllrr'.FS::UI::Web::cust_aligns(),
+               'color' => [ 
                               '',
                               '',
                               '',
@@ -71,7 +71,7 @@
                               '',
                               FS::UI::Web::cust_colors(),
                             ],
-                 'style' => [ 
+               'style' => [ 
                               '',
                               '',
                               '',
@@ -80,7 +80,7 @@
                               '',
                               '',
                               FS::UI::Web::cust_styles(),
-                            ],
+                          ],
            )
 %>
 <%init>
@@ -106,6 +106,10 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
   push @where, "cust_main.agentnum = $1";
 }
 
+if ( $cgi->param('billpkgnum') =~ /^(\d+)$/ ) {
+  push @where, "billpkgnum = $1";
+}
+
 #classnum
 # not specified: all classes
 # 0: empty class
@@ -346,7 +350,7 @@ if ( $cgi->param('cust_tax') ) {
   push @where, $cust_exempt;
 }
 
-my $count_query = "SELECT COUNT(DISTINCT billpkgnum),
+my $count_query = "SELECT COUNT(DISTINCT creditbillpkgnum),
                           SUM(cust_credit_bill_pkg.amount)";
 
 my $join_cust =
@@ -412,8 +416,8 @@ my $join_credit = ' LEFT JOIN cust_credit_bill USING ( creditbillnum )
                     LEFT JOIN cust_credit      USING ( crednum ) ';
 
 $count_query .= " FROM cust_credit_bill_pkg
-                         $join_pkg
                          $join_cust_bill_pkg
+                         $join_pkg
                          $join_credit
                          $join_cust
                        $where";
@@ -430,8 +434,8 @@ push @select, 'cust_main.custnum',
 
 my $query = {
   'table'     => 'cust_credit_bill_pkg',
-  'addl_from' => "$join_pkg
-                  $join_cust_bill_pkg
+  'addl_from' => "$join_cust_bill_pkg
+                  $join_pkg
                   $join_credit
                   $join_cust",
   'hashref'   => {},

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

Summary of changes:
 httemplate/search/cust_bill_pkg.cgi         |   63 ++++++++++++++++++++++++---
 httemplate/search/cust_credit_bill_pkg.html |   46 +++++++++++---------
 2 files changed, 81 insertions(+), 28 deletions(-)




More information about the freeside-commits mailing list