additional by-otaker searches fixed for the brave new world of usernum, RT#9555
authorivan <ivan>
Sun, 15 Aug 2010 07:00:21 +0000 (07:00 +0000)
committerivan <ivan>
Sun, 15 Aug 2010 07:00:21 +0000 (07:00 +0000)
httemplate/elements/select-user.html
httemplate/search/cust_bill_pkg_discount.html
httemplate/search/cust_credit.html
httemplate/search/cust_pkg_discount.html
httemplate/search/report_cust_bill_pkg_discount.html
httemplate/search/report_cust_credit.html
httemplate/search/report_cust_pkg_discount.html
httemplate/search/report_h_cust_pay.html

index 6264398..ec2341b 100644 (file)
@@ -4,7 +4,10 @@
   <OPTION VALUE="">all</OPTION>
 % }
 
-% foreach my $usernum ( keys %{ $opt{'access_user'} } ) { 
+% foreach my $usernum (
+%   sort { $opt{'access_user'}->{$a} cmp $opt{'access_user'}->{$b} }
+%   keys %{ $opt{'access_user'} }
+% ) { 
     <OPTION VALUE="<%$usernum%>"><% $opt{'access_user'}->{$usernum} %></OPTION>
 % } 
 
@@ -16,12 +19,9 @@ my %opt = @_;
 
 unless ( $opt{'access_user'} ) {
 
-  tie %{ $opt{'access_user'} }, 'Tie::IxHash';
-
   my $sth = dbh->prepare("
     SELECT usernum, username FROM access_user
       WHERE disabled = '' or disabled IS NULL
-        ORDER BY username
   ") or die dbh->errstr;
   $sth->execute or die $sth->errstr;
   while ( my $row = $sth->fetchrow_arrayref ) {
index 088b291..b472366 100644 (file)
@@ -85,6 +85,11 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
   push @where, "cust_main.agentnum = $1";
 }
 
+#usernum
+if ( $cgi->param('usernum') =~ /^(\d+)$/ ) {
+  push @where, "cust_pkg_discount.usernum = $1";
+}
+
 # #classnum
 # # not specified: all classes
 # # 0: empty class
@@ -110,18 +115,25 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
 
 my $count_query = "SELECT COUNT(*), SUM(amount)";
 
-my $join_cust =  '      JOIN cust_bill_pkg USING ( billpkgnum )
-                        JOIN cust_bill USING ( invnum ) 
-                   LEFT JOIN cust_main USING ( custnum ) ';
+my $join_cust_pkg_discount =
+  'LEFT JOIN cust_pkg_discount USING (pkgdiscountnum)';
+
+my $join_cust =
+  '      JOIN cust_bill_pkg USING ( billpkgnum )
+         JOIN cust_bill USING ( invnum ) 
+    LEFT JOIN cust_main USING ( custnum ) ';
 
-my $join_pkg = ' LEFT JOIN cust_pkg USING ( pkgnum )
-                 LEFT JOIN part_pkg USING ( pkgpart ) ';
-                 #LEFT JOIN part_pkg AS override
-                 #  ON pkgpart_override = override.pkgpart ';
+my $join_pkg =
+  ' LEFT JOIN cust_pkg ON ( cust_bill_pkg.pkgnum = cust_pkg.pkgnum )
+  LEFT JOIN part_pkg USING ( pkgpart ) ';
+  #LEFT JOIN part_pkg AS override
+  #  ON pkgpart_override = override.pkgpart ';
 
 my $where = ' WHERE '. join(' AND ', @where);
 
-$count_query .= " FROM cust_bill_pkg_discount $join_cust $join_pkg $where";
+$count_query .=
+  " FROM cust_bill_pkg_discount $join_cust_pkg_discount $join_cust $join_pkg ".
+  $where;
 
 my @select = (
                'cust_bill_pkg_discount.*',
@@ -135,7 +147,7 @@ push @select, 'cust_main.custnum',
 
 my $query = {
   'table'     => 'cust_bill_pkg_discount',
-  'addl_from' => "$join_cust $join_pkg",
+  'addl_from' => "$join_cust_pkg_discount $join_cust $join_pkg",
   'hashref'   => {},
   'select'    => join(', ', @select ),
   'extra_sql' => $where,
index 9a14dce..ad84721 100755 (executable)
@@ -56,8 +56,8 @@ my $title = 'Credit Search Results';
 
 my @search = ();
 
-if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
-  push @search, "cust_credit.otaker = '$1'";
+if ( $cgi->param('usernum') =~ /^(\d+)$/ ) {
+  push @search, "cust_credit.usernum = $1";
 }
 
 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
index 233345e..d70c311 100644 (file)
@@ -78,9 +78,9 @@ if ( $cgi->param('status') eq 'active' ) {
                ";     #XXX also end date
 }
 
-#otaker
-if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
-  push @where, "cust_pkg_discount.otaker = '$1'";
+#usernum
+if ( $cgi->param('usernum') =~ /^(\d+)$/ ) {
+  push @where, "cust_pkg_discount.usernum = $1";
 }
 
 #agent
index f1879d4..f9ab901 100644 (file)
@@ -5,9 +5,9 @@
 
 <TABLE>
 
-  <% include( '/elements/tr-select-otaker.html',
-                'label'   => 'Discounts by employee: ',
-                'otakers' => \@otakers,
+  <% include( '/elements/tr-select-user.html',
+                'label'       => 'Discounts by employee: ',
+                'access_user' => \%access_user,
             )
   %>
 
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
 
-my $sth = dbh->prepare("SELECT DISTINCT otaker FROM cust_pkg_discount")
+my $sth = dbh->prepare("SELECT DISTINCT usernum FROM cust_pkg_discount")
   or die dbh->errstr;
 $sth->execute or die $sth->errstr;
-my @otakers = map { $_->[0] } @{$sth->fetchall_arrayref};
+my @usernum = map $_->[0], @{$sth->fetchall_arrayref};
+my %access_user =
+  map { $_ => qsearchs('access_user',{'usernum'=>$_})->username }
+      @usernum;
 
 </%init>
index 9c719b7..c7e5522 100644 (file)
@@ -5,9 +5,9 @@
 
 <TABLE>
 
-  <% include( '/elements/tr-select-otaker.html',
-                'label'   => 'Credits by employee: ',
-                'otakers' => \@otakers,
+  <% include( '/elements/tr-select-user.html',
+                'label'       => 'Credits by employee: ',
+                'access_user' => \%access_user,
             )
   %>
 
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
 
-my $sth = dbh->prepare("SELECT DISTINCT otaker FROM cust_credit")
+my $sth = dbh->prepare("SELECT DISTINCT usernum FROM cust_credit")
   or die dbh->errstr;
 $sth->execute or die $sth->errstr;
-my @otakers = map { $_->[0] } @{$sth->fetchall_arrayref};
+my @usernum = map $_->[0], @{$sth->fetchall_arrayref};
+my %access_user =
+  map { $_ => qsearchs('access_user',{'usernum'=>$_})->username }
+      @usernum;
+
 
 </%init>
index 7ebd44f..31774c3 100644 (file)
@@ -16,9 +16,9 @@
     </TD>
   </TR>
 
-  <% include( '/elements/tr-select-otaker.html',
-                'label'   => 'Discounts by employee: ',
-                'otakers' => \@otakers,
+  <% include( '/elements/tr-select-user.html',
+                'label'       => 'Discounts by employee: ',
+                'access_user' => \%access_user,
             )
   %>
 
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
 
-my $sth = dbh->prepare("SELECT DISTINCT otaker FROM cust_pkg_discount")
+my $sth = dbh->prepare("SELECT DISTINCT usernum FROM cust_pkg_discount")
   or die dbh->errstr;
 $sth->execute or die $sth->errstr;
-my @otakers = map { $_->[0] } @{$sth->fetchall_arrayref};
+my @usernum = map $_->[0], @{$sth->fetchall_arrayref};
+my %access_user =
+  map { $_ => qsearchs('access_user',{'usernum'=>$_})->username }
+      @usernum;
 
 </%init>
index fe7c4a9..5c7f27a 100644 (file)
@@ -88,7 +88,7 @@
              )
   %>
 
-  <% include( '/elements/tr-select-otaker.html' ) %>
+  <% include( '/elements/tr-select-user.html' ) %>
 
   <TR>
     <TD ALIGN="right" VALIGN="center">Payment</TD>