fix unapplied payment report, RT#73048, fallout from #25944
[freeside.git] / httemplate / search / phone_avail.html
index e1c264f..faf3544 100644 (file)
@@ -1,9 +1,9 @@
-<% include( 'elements/search.html',
+<& elements/search.html,
               'title'         => 'Phone Number (DID) Search Results',
               'name_singular' => 'phone number',
               'query'         => {
                                    'table'   => 'phone_avail',
-                                   'hashref' => {},
+                                   'hashref' => $hashref,
                                    'select'  => join(', ',
                                        'phone_avail.*',
                                        'cust_main.custnum',
                       '+'. $pn->countrycode. ' '.
                         $pn->npa. ' '.  $pn->nxx. '-'. $pn->station;
                     },
-               'name',
+               sub { shift->get('name') },
                'availbatch',
-                'exportnum', #XXX
-                #sub { },
-                'svcnum', #XXX
+               sub {
+                   my $pa = shift;
+                   return '' unless $pa->part_export;
+                   $pa->part_export->exportname;
+               },
+               sub {
+                   my $pa = shift;
+                   return '' unless $pa->cust_svc;
+                   my($label,$value) = $pa->cust_svc->label; 
+                   $label . ": " . $value;
+               },
                 \&FS::UI::Web::cust_fields,
+               '',
               ],
-              'align'         => 'rllllll'.FS::UI::Web::cust_aligns(),
+              'align'         => 'rllllllc'.FS::UI::Web::cust_aligns(),
               'links'         => [
                 '',
                 '',
                '',
                '',
                 '',
-                '', #XXX #$export_link
-                '', #XXX #$svc_link
+                '', #XXX #$export_link - to what exactly?
+                $svc_link,
                 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
                       FS::UI::Web::cust_header()
                 ),
+               '',
               ],
               'color' => [ 
                            '',
@@ -58,6 +68,7 @@
                            '',
                            '',
                            FS::UI::Web::cust_colors(),
+                          '',
                          ],
               'style' => [ 
                            '',
                            '',
                            '',
                            FS::UI::Web::cust_styles(),
+                          '',
                          ],
-      )
-%>
+      
+&>
 <%init>
 
 die "access denied"
-  unless $FS::CurrentUser::CurrentUser->access_right('Import');
+  unless ( $FS::CurrentUser::CurrentUser->access_right('List inventory')
+        );
 
 my @search = ();
 
@@ -112,9 +125,14 @@ my $search = scalar(@search)
 my $addl_from = ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
                 #' LEFT JOIN part_svc  USING ( svcpart ) '.
                 ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
-                ' LEFT JOIN cust_main USING ( custnum ) ';
+                FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg');
 
 my $count_query = "SELECT COUNT(*) FROM phone_avail $search"; #$addl_from?
+# All of these relationships are left joined in the many-to-one direction,
+# so including $addl_from won't affect the count.  Logic!
+
+my $hashref = {};
+$hashref->{'ordernum'} = $1 if $cgi->param('ordernum') =~ /^(\d+)$/;
 
 my $link_cust = sub {
   my $phone_avail = shift;
@@ -128,4 +146,13 @@ my $link_cust = sub {
   '';
 };
 
+my $svc_link = sub {
+    my $phone_avail = shift;
+    my $cust_svc = $phone_avail->cust_svc;
+    if ( $cust_svc ) {
+       return [ "${p}view/svc_phone.cgi?", 'svcnum'];
+    }
+    '';
+};
+
 </%init>