i really hope this finally does it
[freeside.git] / FS / FS / cust_main.pm
index 4238b98..a8a9ae4 100644 (file)
@@ -5789,6 +5789,7 @@ sub _agent_plandata {
 
   my $part_event_option =
     qsearchs({
+      'select'    => 'part_event_option.*',
       'table'     => 'part_event_option',
       'addl_from' => q{
         LEFT JOIN part_event USING ( eventpart )
@@ -5803,28 +5804,30 @@ sub _agent_plandata {
              )
       },
       #'hashref'   => { 'optionname' => $option },
-      'hashref'   => { 'part_event_option.optionname' => $option },
-      'extra_sql' => " AND event = 'cust_bill_send_agent' ".
-                     " AND disabled != 'Y' ".
-                     " AND peo_agentnum.optionname = 'agentnum' ".
-                     " AND agentnum IS NULL OR agentnum = $agentnum ".
-                     " ORDER BY
-                        CASE WHEN peo_cust_bill_age.optionname != 'cust_bill_age'
-                        THEN -1
-                        ELSE EXTRACT( EPOCH FROM
-                                        REPLACE( peo_cust_bill_age.optionvalue,
-                                                 'm',
-                                                 'mon'
-                                               )::interval
-                                    )
-                       END
-                       , part_event.weight".
-                     " LIMIT 1"
+      #'hashref'   => { 'part_event_option.optionname' => $option },
+      'extra_sql' =>
+        " WHERE part_event_option.optionname = ". dbh->quote($option).
+        " AND action = 'cust_bill_send_agent' ".
+        " AND ( disabled IS NULL OR disabled != 'Y' ) ".
+        " AND peo_agentnum.optionname = 'agentnum' ".
+        " AND agentnum IS NULL OR agentnum = $agentnum ".
+        " ORDER BY
+           CASE WHEN peo_cust_bill_age.optionname != 'cust_bill_age'
+           THEN -1
+           ELSE EXTRACT( EPOCH FROM
+                           REPLACE( peo_cust_bill_age.optionvalue,
+                                    'm',
+                                    'mon'
+                                  )::interval
+                       )
+          END
+          , part_event.weight".
+        " LIMIT 1"
     });
     
   unless ( $part_event_option ) {
     return $self->agent->invoice_template || ''
-      if $option eq '$agent_templatename';
+      if $option eq 'agent_templatename';
     return '';
   }