[freeside-commits] freeside/httemplate/browse access_group.html, 1.4, 1.5 access_user.html, 1.5, 1.6 agent.cgi, 1.38, 1.39 invoice_template.html, NONE, 1.1 part_bill_event.cgi, 1.14, 1.15 part_event.html, NONE, 1.1 part_pkg.cgi, 1.38, 1.39 part_referral.html, 1.6, 1.7 pkg_class.html, 1.4, 1.5 reason.html, 1.2, 1.3

Ivan,,, ivan at wavetail.420.am
Wed Aug 1 15:25:01 PDT 2007


Update of /home/cvs/cvsroot/freeside/httemplate/browse
In directory wavetail:/tmp/cvs-serv23435/httemplate/browse

Modified Files:
	access_group.html access_user.html agent.cgi 
	part_bill_event.cgi part_pkg.cgi part_referral.html 
	pkg_class.html reason.html 
Added Files:
	invoice_template.html part_event.html 
Log Message:
event refactor, landing on HEAD!

Index: access_user.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/browse/access_user.html,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- access_user.html	30 Jan 2007 20:59:13 -0000	1.5
+++ access_user.html	1 Aug 2007 22:24:57 -0000	1.6
@@ -1,20 +1,21 @@
 <% include( 'elements/browse.html',
-                 'title'          => 'Internal Users',
-                 'menubar'        => [ #'Main menu' => $p,
-                                       'Internal access groups' => $p.'browse/access_group.html',
-                                     ],
-                 'html_init'      => $html_init,
-                 'html_posttotal' => $posttotal,
-                 'name'           => 'internal users',
-                 'query'          => { 'table'     => 'access_user',
-                                       'hashref'   => \%search,
-                                       'extra_sql' => 'ORDER BY last, first',
-                                     },
-                 'count_query'    => $count_query,
-                 'header'         => \@header,
-                 'fields'         => \@fields,
-                 'links'          => \@links,
-                 'style'          => \@style,
+                 'title'              => 'Internal Users',
+                 'menubar'            => [ #'Main menu' => $p,
+                                           'Internal access groups' => $p.'browse/access_group.html',
+                                         ],
+                 'html_init'          => $html_init,
+                 'name'               => 'internal users',
+                 'disableable'        => 1,
+                 'disabled_statuspos' => 2,
+                 'query'              => { 'table'     => 'access_user',
+                                           'hashref'   => {},
+                                           'extra_sql' => 'ORDER BY last, first'
+                                         },
+                 'count_query'        => $count_query,
+                 'header'             => \@header,
+                 'fields'             => \@fields,
+                 'links'              => \@links,
+                 'align'              => $align,
              )
 %>
 <%init>
@@ -26,14 +27,6 @@
   "Internal users have access to the back-office interface.  Typically, this is your employees and contractors, but in a VISP setup, you can also add accounts for your reseller's employees.  It is <B>highly recommended</B> to add a <B>separate account for each person</B> rather than using role accounts.<BR><BR>".
   qq!<A HREF="${p}edit/access_user.html"><I>Add an internal user</I></A><BR><BR>!;
 
-#false laziness w/part_pkg.cgi
-my %search = ();
-my $search = '';
-unless ( $cgi->param('showdisabled') ) {
-  %search = ( 'disabled' => '' );
-  $search = "( disabled = '' OR disabled IS NULL )";
-}
-
 #false laziness w/access_group.html & agent_type.cgi
 my $groups_sub = sub {
   my $access_user = shift;
@@ -58,45 +51,13 @@
 
 };
 
-my $posttotal;
-if ( $cgi->param('showdisabled') ) {
-  $cgi->param('showdisabled', 0);
-  $posttotal = '( <a href="'. $cgi->self_url. '">hide disabled users</a> )';
-  $cgi->param('showdisabled', 1);
-} else {
-  $cgi->param('showdisabled', 1);
-  $posttotal = '( <a href="'. $cgi->self_url. '">show disabled users</a> )';
-  $cgi->param('showdisabled', 0);
-}
-
 my $count_query = 'SELECT COUNT(*) FROM access_user';
-$count_query .= " WHERE $search"
-  if $search;
 
 my $link = [ $p.'edit/access_user.html?', 'usernum' ];
 
-my @header = ( '#', 'Username' );
-my @fields = ( 'usernum', 'username' );
-my $align = 'rl';
-my @links = ( $link, $link );
-my @style = ( '', '' );
-
-#false laziness w/part_pkg.cgi
-#unless ( $cgi->param('showdisabled') ) { #its been reversed already
-if ( $cgi->param('showdisabled') ) { #its been reversed already
-  push @header, 'Status';
-  push @fields, sub { shift->disabled
-                        ? '<FONT COLOR="#FF0000">DISABLED</FONT>'
-                        : '<FONT COLOR="#00CC00">Active</FONT>'
-                    };
-  push @links, '';
-  $align .= 'c';
-  push @style, 'b';
-}
-
-push @header, 'Full name', 'Groups';
-push @fields, 'name',      $groups_sub;
-push @links,  $link,       '';
-$align .= 'll';
+my @header = ( '#',       'Username', 'Full name', 'Groups'    );
+my @fields = ( 'usernum', 'username', 'name',      $groups_sub );
+my $align = 'rlll';
+my @links = ( $link, $link, $link, '' );
 
 </%init>

Index: access_group.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/browse/access_group.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- access_group.html	30 Jan 2007 20:59:13 -0000	1.4
+++ access_group.html	1 Aug 2007 22:24:57 -0000	1.5
@@ -27,10 +27,7 @@
                                   ],
              )
 %>
-<%init>
-
-die "access denied"
-  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+<%once>
 
 my $html_init = 
   "Internal access groups control access to the back-office interface.<BR><BR>".
@@ -58,20 +55,45 @@
   
 };
 
+tie my %rights, 'Tie::IxHash', FS::AccessRight->rights_info;
+
 my $rights_sub = sub {
   my $access_group = shift;
 
-  [ map { my $access_right = $_;
-          [
-            { 
-              'data'  => $access_right->rightname,
-              'align' => 'left',
-            },
-          ];
-        }
-    $access_group->access_rights,
+  #[ map { my $access_right = $_;
+  #        [
+  #          { 
+  #            'data'  => $access_right->rightname,
+  #            'align' => 'left',
+  #          },
+  #        ];
+  #      }
+  #  $access_group->access_rights,
+  #];
 
-  ];
+  #some false laziness w/edit/access_group.html
+  my $columns = 3;
+  my $count = 0;
+
+  #include('/elements/table-grid.html', bgcolor=>'#cccccc' ).
+  '<TABLE>'.
+  '<TR>'. join( '', map {
+    
+    '<TD CLASS="inv" VALIGN="top"><TABLE WIDTH=100%>'.
+    '<TR><TH BGCOLOR="#dcdcdc">'. $_. '</TH></TR>'.
+    '<TR><TD>'.
+
+     join('<BR>', grep { warn "$access_group->access_right($_): ".
+                              $access_group->access_right($_). "\n";
+                         $access_group->access_right($_); }
+                   map { ref($_) ? $_->{'rightname'} : $_; }
+                       @{ $rights{$_} }
+         ).
+
+    '</TD></TR></TABLE></TD>'.
+    ( ++$count % $columns ? '' : '</TR><TR>')
+  
+  } keys %rights ). '</TR></TABLE>';
 
 };
 
@@ -79,4 +101,10 @@
 
 my $link = [ $p.'edit/access_group.html?', 'groupnum' ];
 
+</%once>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
 </%init>

Index: agent.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/browse/agent.cgi,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- agent.cgi	18 Jul 2007 18:07:38 -0000	1.38
+++ agent.cgi	1 Aug 2007 22:24:58 -0000	1.39
@@ -27,10 +27,11 @@
 <TR>
   <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=<% ( $cgi->param('showdisabled') || !dbdef->table('agent')->column('disabled') ) ? 2 : 3 %>>Agent</TH>
   <TH CLASS="grid" BGCOLOR="#cccccc">Type</TH>
+  <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Invoice<BR>Template</FONT></TH>
   <TH CLASS="grid" BGCOLOR="#cccccc">Customers</TH>
   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Customer<BR>packages</FONT></TH>
   <TH CLASS="grid" BGCOLOR="#cccccc">Reports</TH>
-  <TH CLASS="grid" BGCOLOR="#cccccc">Registration codes</TH>
+  <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Registration<BR>codes</FONT></TH>
   <TH CLASS="grid" BGCOLOR="#cccccc">Prepaid cards</TH>
 % if ( $conf->config('ticket_system') ) { 
 
@@ -39,8 +40,6 @@
 
   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Payment Gateway Overrides</FONT></TH>
   <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Configuration Overrides</FONT></TH>
-  <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Freq.</FONT></TH>
-  <TH CLASS="grid" BGCOLOR="#cccccc"><FONT SIZE=-1>Prog.</FONT></TH>
 </TR>
 % 
 %#        <TH><FONT SIZE=-1>Agent #</FONT></TH>
@@ -66,18 +65,29 @@
 
 
       <TR>
-        <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><A HREF="<%$p%>edit/agent.cgi?<% $agent->agentnum %>">
-          <% $agent->agentnum %></A></TD>
-% if ( dbdef->table('agent')->column('disabled')
-%        && !$cgi->param('showdisabled')           ) { 
 
-        <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $agent->disabled ? 'DISABLED' : '' %></TD>
-% } 
+        <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
+          <A HREF="<%$p%>edit/agent.cgi?<% $agent->agentnum %>"><% $agent->agentnum %></A>
+        </TD>
 
+%       if ( dbdef->table('agent')->column('disabled')
+%            && !$cgi->param('showdisabled')           ) { 
+          <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
+            <% $agent->disabled ? 'DISABLED' : '' %>
+          </TD>
+%       } 
 
-        <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><A HREF="<%$p%>edit/agent.cgi?<% $agent->agentnum %>">
-          <% $agent->agent %></A></TD>
-        <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><A HREF="<%$p%>edit/agent_type.cgi?<% $agent->typenum %>"><% $agent->agent_type->atype %></A></TD>
+        <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
+          <A HREF="<%$p%>edit/agent.cgi?<% $agent->agentnum %>"><% $agent->agent %></A>
+        </TD>
+
+        <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
+          <A HREF="<%$p%>edit/agent_type.cgi?<% $agent->typenum %>"><% $agent->agent_type->atype %></A>
+        </TD>
+
+        <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
+          <% $agent->invoice_template || '(Default)' %>
+        </TD>
 
         <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
           <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
@@ -366,11 +376,6 @@
           </TABLE>
         </TD>
 
-<!--
-        <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $agent->freq %></TD>
-        <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $agent->prog %></TD>
--->
-
       </TR>
 % } 
 

Index: part_pkg.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/browse/part_pkg.cgi,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- part_pkg.cgi	12 Apr 2007 03:16:43 -0000	1.38
+++ part_pkg.cgi	1 Aug 2007 22:24:58 -0000	1.39
@@ -1,20 +1,20 @@
 <% include( 'elements/browse.html',
-                 'title'          => 'Package Definitions',
-                 'menubar'        => [ 'Main Menu' => $p ],
-                 'html_init'      => $html_init,
-                 'html_posttotal' => $posttotal,
-                 'name'           => 'package definitions',
-                 'query'          => { 'select'    => $select,
-                                       'table'     => 'part_pkg',
-                                       'hashref'   => \%search,
-                                       'extra_sql' => "ORDER BY $orderby",
-                                     },
-                 'count_query'    => $count_query,
-                 'header'         => \@header,
-                 'fields'         => \@fields,
-                 'links'          => \@links,
-                 'align'          => $align,
-                 'style'          => \@style,
+                 'title'              => 'Package Definitions',
+                 'menubar'            => [ 'Main Menu' => $p ],
+                 'html_init'          => $html_init,
+                 'name'               => 'package definitions',
+                 'disableable'        => 1,
+                 'disabled_statuspos' => 3,
+                 'query'              => { 'select'    => $select,
+                                           'table'     => 'part_pkg',
+                                           'hashref'   => {},
+                                           'extra_sql' => "ORDER BY $orderby",
+                                         },
+                 'count_query'        => $count_query,
+                 'header'             => \@header,
+                 'fields'             => \@fields,
+                 'links'              => \@links,
+                 'align'              => $align,
              )
 %>
 <%init>
@@ -22,14 +22,6 @@
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
 
-#false laziness w/access_user.html
-my %search = ();
-my $search = '';
-unless ( $cgi->param('showdisabled') ) {
-  %search = ( 'disabled' => '' );
-  $search = "( disabled = '' OR disabled IS NULL )";
-}
-
 my $select = '*';
 my $orderby = 'pkgpart';
 if ( $cgi->param('active') ) {
@@ -72,18 +64,6 @@
   !;
 #}
 
-my $posttotal;
-if ( $cgi->param('showdisabled') ) {
-  $cgi->param('showdisabled', 0);
-  $posttotal = '( <a href="'. $cgi->self_url. '">hide disabled packages</a> )';
-  $cgi->param('showdisabled', 1);
-} else {
-  $cgi->param('showdisabled', 1);
-  $posttotal = '( <a href="'. $cgi->self_url. '">show disabled packages</a> )';
-  $cgi->param('showdisabled', 0);
-}
-
-
 # ------
 
 my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
@@ -92,20 +72,6 @@
 my @fields = ( 'pkgpart', 'pkg', 'comment' );
 my $align = 'rll';
 my @links = ( $link, $link, '' );
-my @style = ( '', '', '' );
-
-#false laziness w/access_user.html
-#unless ( $cgi->param('showdisabled') ) { #its been reversed already
-if ( $cgi->param('showdisabled') ) { #its been reversed already
-  push @header, 'Status';
-  push @fields, sub { shift->disabled
-                        ? '<FONT COLOR="#FF0000">DISABLED</FONT>'
-                        : '<FONT COLOR="#00CC00">Active</FONT>'
-                    };
-  push @links, '';
-  $align .= 'c';
-  push @style, 'b';
-}
 
 unless ( 0 ) { #already showing only one class or something?
   push @header, 'Class';
@@ -255,7 +221,5 @@
 # --------
 
 my $count_query = 'SELECT COUNT(*) FROM part_pkg';
-$count_query .= " WHERE $search"
-  if $search;
 
 </%init>

Index: reason.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/browse/reason.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- reason.html	30 Jan 2007 20:59:13 -0000	1.2
+++ reason.html	1 Aug 2007 22:24:58 -0000	1.3
@@ -7,10 +7,12 @@
                                   ],
                  'html_init'   => $html_init,
                  'name'        => $classname . ' reasons',
+                 'disableable' => 1,
+                 'disabled_statuspos' => 3,
                  'query'       => { 'table'     => 'reason',
                                     'hashref'   => {},
-                                    'extra_sql' => $where_clause . 
-				                   'ORDER BY reason_type', 
+                                    'extra_sql' => $where_clause. 
+				                   ' ORDER BY reason_type', 
                                     'addl_from' => 'LEFT JOIN reason_type ON reason_type.typenum = reason.reason_type', 
                                   },
                  'count_query' => $count_query,
@@ -47,18 +49,7 @@
 qq!<A HREF="${p}edit/reason.html?class=$class">!.
 "<I>Add a $classname reason</I></A><BR><BR>";
 
-my $where_clause = "WHERE class='$class'";
-$where_clause .= " AND (disabled = '' OR disabled IS NULL)"
-unless $cgi->param('showdisabled');
-
-my $disabledurl = $cgi->param('showdisabled')
-   ? do { $cgi->param('showdisabled', 0);
-         '( <a href="'. $cgi->self_url. '">hide disabled reasons</a> )'; }
-   : do { $cgi->param('showdisabled', 1);
-         '( <a href="'. $cgi->self_url. '">show disabled reasons</a> )'; }
-   ;
-
-$html_init .= $disabledurl;
+my $where_clause = " WHERE class='$class' ";
 
 my $count_query = 'SELECT COUNT(*) FROM reason LEFT JOIN reason_type on ' .
                 'reason_type.typenum = reason.reason_type ' . $where_clause;

Index: part_bill_event.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/browse/part_bill_event.cgi,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- part_bill_event.cgi	30 Jan 2007 20:59:13 -0000	1.14
+++ part_bill_event.cgi	1 Aug 2007 22:24:58 -0000	1.15
@@ -1,6 +1,6 @@
 <% include("/elements/header.html",'Invoice Event Listing', menubar( 'Main Menu' => $p) ) %>
 
-    Invoice events are actions taken on open invoices.<BR><BR>
+    <FONT SIZE="+1">Invoice events are the deprecated, old-style actions taken on open invoices.  Any events still listed here should be migrated to new-style events.</FONT><BR><BR>
 
 <A HREF="<% $p %>edit/part_bill_event.cgi"><I>Add a new invoice event</I></A>
 <BR><BR>

Index: part_referral.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/browse/part_referral.html,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- part_referral.html	30 Jan 2007 20:59:13 -0000	1.6
+++ part_referral.html	1 Aug 2007 22:24:58 -0000	1.7
@@ -5,54 +5,11 @@
 
 <A HREF="<% $p %>edit/part_referral.html"><I>Add a new advertising source</I></A>
 <BR><BR>
-%
-%  my $today = timelocal(0, 0, 0, (localtime(time))[3..5] );
-%  my %after;
-%  tie %after, 'Tie::IxHash',
-%    'Today'         =>        0,
-%    'Yesterday'     =>    86400, # 60sec * 60min * 24hrs
-%    'Past week'     =>   518400, # 60sec * 60min * 24hrs * 6days
-%    'Past 30 days'  =>  2505600, # 60sec * 60min * 24hrs * 29days 
-%    'Past 60 days'  =>  5097600, # 60sec * 60min * 24hrs * 59days 
-%    'Past 90 days'  =>  7689600, # 60sec * 60min * 24hrs * 89days 
-%    'Past 6 months' => 15724800, # 60sec * 60min * 24hrs * 182days 
-%    'Past year'     => 31486000, # 60sec * 60min * 24hrs * 364days 
-%    'Total'         => $today,
-%  ;
-%  my %before = (
-%    'Today'         =>   86400, # 60sec * 60min * 24hrs
-%    'Yesterday'     =>       0,
-%    'Past week'     =>   86400, # 60sec * 60min * 24hrs
-%    'Past 30 days'  =>   86400, # 60sec * 60min * 24hrs
-%    'Past 60 days'  =>   86400, # 60sec * 60min * 24hrs
-%    'Past 90 days'  =>   86400, # 60sec * 60min * 24hrs
-%    'Past 6 months' =>   86400, # 60sec * 60min * 24hrs
-%    'Past year'     =>   86400, # 60sec * 60min * 24hrs
-%    'Total'         =>   86400, # 60sec * 60min * 24hrs
-%  );
-%
-%  my $curuser = $FS::CurrentUser::CurrentUser;
-%
-%  my $statement = "SELECT COUNT(*) FROM h_cust_main
-%                    WHERE history_action = 'insert'
-%                      AND refnum = ?
-%                      AND history_date >= ?
-%		      AND history_date < ?
-%		      AND ". $curuser->agentnums_sql;
-%  my $sth = dbh->prepare($statement)
-%    or die dbh->errstr;
-%
-%  my $show_agentnums = scalar($curuser->agentnums);
-%
-%
-
 
 <% include('/elements/table-grid.html') %>
 % my $bgcolor1 = '#eeeeee';
 %   my $bgcolor2 = '#ffffff';
 %   my $bgcolor = '';
-%
-
 
 <TR>
   <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2 ROWSPAN=2>Advertising source</TH>
@@ -61,7 +18,7 @@
     <TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=2>Agent</TH>
 % } 
 
-  <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=<% scalar(keys %after) %>>Customers</TH>
+  <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=<% scalar(keys %after) %>>Customers and Packages</TH>
 </TR>
 % for my $period ( keys %after ) { 
 
@@ -69,7 +26,7 @@
 % } 
 
 </TR>
-%
+
 %foreach my $part_referral ( FS::part_referral->all_part_referral(1) ) {
 %
 %  if ( $bgcolor eq $bgcolor1 ) {
@@ -79,8 +36,6 @@
 %  }
 %
 %  $a = 0;
-%
-%
 
       <TR>
 
@@ -105,34 +60,63 @@
           <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $part_referral->agentnum ? $part_referral->agent->agent : '(global)' %></TD>
 % } 
 % for my $period ( keys %after ) {
-%          $sth->execute( $part_referral->refnum,
-%                         $today-$after{$period},
-%                         $today+$before{$period},
-%          ) or die $sth->errstr;
-%          my $number = $sth->fetchrow_arrayref->[0];
-%        
+%          my @param = ( $part_referral->refnum,
+%                        $today-$after{$period},
+%                        $today+$before{$period},
+%                      );
+%          $cust_sth->execute(@param) or die $cust_sth->errstr;
+%          my $num_cust = $cust_sth->fetchrow_arrayref->[0];
+%          $pkg_sth->execute(@param) or die $pkg_sth->errstr;
+%          my $num_pkg = $pkg_sth->fetchrow_arrayref->[0];
 
-          <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ALIGN="right"><% $number %></TD>
+          <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" ALIGN="right">
+            <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
+              <TR>
+                <TD ALIGN="right"><B><% $num_cust %></B></TD>
+                <TD ALIGN="left">customers</TD>
+              </TR>
+              <TR>
+                <TD ALIGN="right"><B><% $num_pkg %></B></TD>
+                <TD ALIGN="left">packages</TD>
+              </TR>
+            </TABLE>
+          </TD>
 % } 
 
       </TR>
 % } 
 %
-%  $statement =~ s/AND refnum = \?//;
-%  $sth = dbh->prepare($statement)
+%  $cust_statement =~ s/AND refnum = \?//;
+%  $cust_sth = dbh->prepare($cust_statement)
+%    or die dbh->errstr;
+%  $pkg_statement =~ s/AND h_pkg_referral\.refnum = \?//;
+%  $pkg_sth = dbh->prepare($pkg_statement)
 %    or die dbh->errstr;
-%
 
       <TR>
         <TD BGCOLOR="#dddddd" ALIGN="center" COLSPAN=3><B>Total</B></TD>
 % for my $period ( keys %after ) {
-%          $sth->execute( $today-$after{$period},
-%                         $today+$before{$period},
-%          ) or die $sth->errstr;
-%          my $number = $sth->fetchrow_arrayref->[0];
-%        
+%          my @param = ( $today-$after{$period},
+%                        $today+$before{$period},
+%                      );
+%          $cust_sth->execute( @param ) or die $cust_sth->errstr;
+%          my $num_cust = $cust_sth->fetchrow_arrayref->[0];
+%          $pkg_sth->execute(@param) or die $pkg_sth->errstr;
+%          my $num_pkg = $pkg_sth->fetchrow_arrayref->[0];
+
+          <TD CLASS="inv" BGCOLOR="#dddddd" ALIGN="right">
+            <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
+              <TR>
+                <TD ALIGN="right"><B><% $num_cust %></B></TD>
+                <TD ALIGN="left">customers</TD>
+              </TR>
+              <TR>
+                <TD ALIGN="right"><B><% $num_pkg %></B></TD>
+                <TD ALIGN="left">packages</TD>
+              </TR>
+            </TABLE>
+          </TD>
 
-          <TD BGCOLOR="#dddddd" ALIGN="right"><B><% $number %><B></TD>
 % } 
 
       </TR>
@@ -140,8 +124,59 @@
   </BODY>
 </HTML>
 <%init>
+
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Configuration')
       || $FS::CurrentUser::CurrentUser->access_right('Edit advertising sources')
       || $FS::CurrentUser::CurrentUser->access_right('Edit global advertising sources');
+
+my $today = timelocal(0, 0, 0, (localtime(time))[3..5] );
+
+tie my %after, 'Tie::IxHash',
+  'Today'         =>        0,
+  'Yesterday'     =>    86400, # 60sec * 60min * 24hrs
+  'Past week'     =>   518400, # 60sec * 60min * 24hrs * 6days
+  'Past 30 days'  =>  2505600, # 60sec * 60min * 24hrs * 29days 
+  'Past 60 days'  =>  5097600, # 60sec * 60min * 24hrs * 59days 
+  'Past 90 days'  =>  7689600, # 60sec * 60min * 24hrs * 89days 
+  'Past 6 months' => 15724800, # 60sec * 60min * 24hrs * 182days 
+  'Past year'     => 31486000, # 60sec * 60min * 24hrs * 364days 
+  'Total'         => $today,
+;
+my %before = (
+  'Today'         =>   86400, # 60sec * 60min * 24hrs
+  'Yesterday'     =>       0,
+  'Past week'     =>   86400, # 60sec * 60min * 24hrs
+  'Past 30 days'  =>   86400, # 60sec * 60min * 24hrs
+  'Past 60 days'  =>   86400, # 60sec * 60min * 24hrs
+  'Past 90 days'  =>   86400, # 60sec * 60min * 24hrs
+  'Past 6 months' =>   86400, # 60sec * 60min * 24hrs
+  'Past year'     =>   86400, # 60sec * 60min * 24hrs
+  'Total'         =>   86400, # 60sec * 60min * 24hrs
+);
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+my $show_agentnums = ( scalar($curuser->agentnums) > 1 );
+
+my $cust_statement = "SELECT COUNT(*) FROM h_cust_main
+                       WHERE history_action = 'insert'
+                         AND refnum = ?
+                         AND history_date >= ?
+                         AND history_date < ?
+                         AND ". $curuser->agentnums_sql;
+my $cust_sth = dbh->prepare($cust_statement)
+  or die dbh->errstr;
+
+my $pkg_statement = "SELECT COUNT(*) FROM h_pkg_referral
+                       LEFT JOIN cust_pkg  USING ( pkgnum )
+                       LEFT JOIN cust_main USING ( custnum )
+                       WHERE history_action = 'insert'
+                         AND h_pkg_referral.refnum = ?
+                         AND history_date >= ?
+                         AND history_date < ?
+                         AND ". $curuser->agentnums_sql;
+my $pkg_sth = dbh->prepare($pkg_statement)
+  or die dbh->errstr;
+
 </%init>

--- NEW FILE: invoice_template.html ---
<% include("/elements/header.html", 'Invoice templates') %>

<% include('/elements/table-grid.html') %>
% my $bgcolor1 = '#eeeeee';
%   my $bgcolor2 = '#ffffff';
%   my $bgcolor = '';

<TR>
  <TH CLASS="grid" BGCOLOR="#cccccc">Template</TH>
  <TH CLASS="grid" BGCOLOR="#cccccc">HTML</TH>
  <TH CLASS="grid" BGCOLOR="#cccccc">Print/PDF (typeset)</TH>
  <TH CLASS="grid" BGCOLOR="#cccccc">Plaintext</TH>
</TR>

% foreach my $templatename ( '', @templatenames ) {
%   my $tname = length($templatename) ? "_$templatename" : '';
%
%   if ( $bgcolor eq $bgcolor1 ) {
%     $bgcolor = $bgcolor2;
%   } else {
%     $bgcolor = $bgcolor1;
%   }
%
%   my $display = length($templatename) ? $templatename : '<i>(Default)</i>';

    <TR>

      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
        <% $display %>
      </TD>

      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">

%       my( $logo_label, $logo_link_label)= length( $templatename )
%                                             ? labels("logo_$templatename.png")
%                                             : ( '', 'edit' );
        <% $logo_label %> Logo
        (<A HREF="<% $p %>edit/invoice_logo.html?type=png;name=<% $templatename %>"><% $logo_link_label %></A>)
        <BR>

%       foreach my $suffix (qw( returnaddress notes footer), '' ) {
%         my $file = "invoice_html$suffix$tname";
%         my($label, $link_label) = length($templatename)
%                                     ? labels($file)
%                                     : ( '', 'edit' );

          <% $label %> <% $suffix2name{$suffix} %>
          (<A HREF="<% $p %>edit/invoice_template.html?type=html;suffix=<% $suffix %>;name=<% $templatename %>"><% $link_label %></A>)
          <BR>

%       }

      </TD>

      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">

%       my( $logo_label, $logo_link_label)= length( $templatename )
%                                             ? labels("logo_$templatename.eps")
%                                             : ( '', 'edit' );
        <% $logo_label %> Logo
        (<A HREF="<% $p %>edit/invoice_logo.html?type=eps;name=<% $templatename %>"><% $logo_link_label %></A>)
        <BR>

%       foreach my $suffix (qw( returnaddress notes footer smallfooter), '' ) {
%         my $file = "invoice_latex$suffix$tname";
%         my($label, $link_label) = length($templatename)
%                                     ? labels($file)
%                                     : ( '', 'edit' );

          <% $label %> <% $suffix2name{$suffix} %>
          (<A HREF="<% $p %>edit/invoice_template.html?type=latex;suffix=<% $suffix %>;name=<% $templatename %>"><% $link_label %></A>)
          <BR>

%       }

      </TD>

      <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">

%       my( $txt_label, $txtlink_label)=
%         length( $templatename )
%           ? labels("invoice_template_$templatename.png")
%           : ( 'Main template', 'edit' );
        <% $txt_label %> 
        (<A HREF="<% $p %>edit/invoice_template.html?type=text;name=<% $templatename %>"><% $txtlink_label %></A>)

      </TD>

    </TR>

% }

<% include("/elements/footer.html") %>

<%once>

my %suffix2name = (
  'returnaddress' => 'Return address',
  'notes'         => 'Notes',
  'footer'        => 'Footer',
  'smallfooter'   => 'Small footer',
  ''              => 'Main template',
);

my $conf = new FS::Conf;

sub labels {
  my $filename = shift;
  if ( $conf->exists($filename) ) {
    ( 'Custom', 'edit' );
  } else {
    ( 'Standard', 'customize' );
  }
}

</%once>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');

my @templatenames = $conf->invoice_templatenames;

</%init>

--- NEW FILE: part_event.html ---
<% include( 'elements/browse.html',
                'title'              => 'Billing Event Definitions',
                'html_init'          => $html_init,
                'name'               => 'billing event definitions',
                'disableable'        => 1,
                'disabled_statuspos' => 2,
                'agent_virt'         => 1,
                'agent_null_right'   => 'Edit global billing events',
                'agent_pos'          => 3,
                'query'              => { 'select'    => 'part_event.*',
                                          'table'     => 'part_event',
                                          'addl_from' => $join_conditions,
                                          'hashref'   => {},
                                          'order_by'  => $order_conditions,
                                        },
                'count_query'        => $count_query,
                'header'             => [ '#',
                                          'Event',
                                          'Type',
                                          'Check freq.',
                                          'Conditions',
                                          'Action',
                                        ],
                'fields'             => [ 'eventpart',
                                          'event',
                                          $eventtable_sub,
                                          $check_freq_sub,
                                          $conditions_sub,
                                          $action_sub,
                                        ],
                'links'              => [ $link,
                                          $link,
                                          '',
                                          '',
                                          '',
                                          '',
                                        ],
                'align'              => 'rllccc',
          )
%>
<%once>

my $eventtable_labels = FS::part_event->eventtable_labels;
my $eventtable_sub = sub { $eventtable_labels->{ shift->eventtable }; };

my $check_freq_labels = FS::part_event->check_freq_labels;
my $check_freq_sub = sub { $check_freq_labels->{ shift->check_freq }; };

my $conditions_sub = sub {
  my $part_event = shift;
  my $addl = 0;

  [
    map {
           my $part_event_condition = $_;
           my %options = $part_event_condition->options;

           [
             {
               'data'       => $part_event_condition->description,
               'width'      => '100%',
               'align'      => 'center',
               'colspan'    => 2,
               'style'      => ( $addl++ ? 'border-top: 1px solid gray' : '' ), 
             },
           ],

           map {

             my $data = $options{$_};
             if ( ref($data) ) {
               $data = join('<BR>', keys %$data); #XXX display hash values too?
             }

             [
               {
                 'data'   => $part_event_condition->option_label($_). ':',
                 'align'  => 'right',
                 'valign' => 'top',
                 'size'   => '-1',
               },
               {
                 'data'  => $data,
                 'align' => 'left',
                 'size'  => '-1',
               },
             ];

           } keys %options

        }
        $part_event->part_event_condition

  ];

};

my $action_sub = sub {
  my $part_event = shift;

  my %options = $part_event->options;
  
  [

    [
      {
        'data'       => $part_event->description,
        'width'      => '100%',
        'align'      => 'center',
        'colspan'    => 2,
      },
    ],

    map {
          [
            {
              'data'  => $part_event->option_label($_). ':',
              'align' => 'right',
              'size'  => '-1',
            },
            {
             'data'  => $options{$_},
             'align' => 'left',
              'size'  => '-1',
            },
          ];
        }

        keys %options
  ];

};

my $link = [ $p.'edit/part_event.html?', 'eventpart' ];

</%once>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Edit billing events')
      || $FS::CurrentUser::CurrentUser->access_right('Edit global billing events');

my $html_init =
  #XXX better description
  'Events are billing, collection or other actions triggered when certain '.
  'customer, invoice, package or other conditions are met.<BR><BR>'.
  qq!<A HREF="${p}edit/part_event.html"><I>Add a new event</I></A><BR><BR>!;
     
my $count_query = 'SELECT COUNT(*) FROM part_event WHERE '.
                  $FS::CurrentUser::CurrentUser->agentnums_sql(
                    'null_right' => 'Edit global billing events',
                  );

my $join_conditions  = FS::part_event_condition->join_conditions_sql;
my $order_conditions = FS::part_event_condition->order_conditions_sql;

</%init>

Index: pkg_class.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/browse/pkg_class.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- pkg_class.html	30 Jan 2007 20:59:13 -0000	1.4
+++ pkg_class.html	1 Aug 2007 22:24:58 -0000	1.5
@@ -3,6 +3,7 @@
                  'html_init'   => $html_init,
                  'name'        => 'package classes',
                  'disableable' => 1,
+                 'disabled_statuspos' => 2,
                  'query'       => { 'table'     => 'pkg_class',
                                     'hashref'   => {},
                                     'extra_sql' => 'ORDER BY classnum',



More information about the freeside-commits mailing list