[freeside-commits] freeside/FS/FS cust_pkg.pm,1.112,1.113

Ivan,,, ivan at wavetail.420.am
Sat Feb 21 12:14:58 PST 2009


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv16043

Modified Files:
	cust_pkg.pm 
Log Message:
hmm, add no_empty_county option to location_sql search, for tax reports.  RT#4878

Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.112
retrieving revision 1.113
diff -u -d -r1.112 -r1.113
--- cust_pkg.pm	8 Feb 2009 02:05:24 -0000	1.112
+++ cust_pkg.pm	21 Feb 2009 20:14:55 -0000	1.113
@@ -2359,16 +2359,18 @@
 sub location_sql {
   my($class, %opt) = @_;
   my $ornull = $opt{'ornull'};
+  my $nec    = $opt{'noempty_county'};
 
   my $conf = new FS::Conf;
 
   # '?' placeholders in _location_sql_where
   my @bill_param;
   if ( $ornull ) {
-    @bill_param = qw( county county county state state state country );
+    @bill_param = qw( county county state state state country );
   } else {
-    @bill_param = qw( county county state state country );
+    @bill_param = qw( county state state country );
   }
+  unshift @bill_param, 'county' unless $nec;
 
   my $main_where;
   my @main_param;
@@ -2376,10 +2378,10 @@
 
     $main_where = "(
          (     ( ship_last IS NULL     OR  ship_last  = '' )
-           AND ". _location_sql_where('cust_main', '', $ornull ). "
+           AND ". _location_sql_where('cust_main', '', $ornull, $nec ). "
          )
       OR (       ship_last IS NOT NULL AND ship_last != ''
-           AND ". _location_sql_where('cust_main', 'ship_', $ornull). "
+           AND ". _location_sql_where('cust_main', 'ship_', $ornull, $nec ). "
          )
     )";
     #    AND payby != 'COMP'
@@ -2397,10 +2399,17 @@
   my @param;
   if ( $conf->exists('tax-pkg_address') ) {
 
+    my $loc_where = _location_sql_where( 'cust_location',
+                                         '', #prefix
+                                         $ornull,
+                                         $nec,
+                                       );
+
     $where = " (
-         ( cust_pkg.locationnum IS     NULL AND $main_where                  )
-      OR ( cust_pkg.locationnum IS NOT NULL AND ". _location_sql_where('cust_location', '', $ornull). " )
-    )";
+                    ( cust_pkg.locationnum IS     NULL AND $main_where )
+                 OR ( cust_pkg.locationnum IS NOT NULL AND $loc_where  )
+               )
+             ";
     @param = ( @main_param, @bill_param );
   
   } else {
@@ -2414,15 +2423,19 @@
 
 }
 
-#subroutine, helper for able
+#subroutine, helper for location_sql
 sub _location_sql_where {
-  my $table = shift;
-  my $prefix = @_ ? shift : '';
-  my $ornull = @_ ? shift : '';
-  $ornull = $ornull ? ' OR ? IS NULL ' : '';
+  my $table           = shift;
+  my $prefix          = @_ ? shift : '';
+  my $ornull          = @_ ? shift : '';
+  my $no_empty_county = @_ ? shift : '';
+
+  $ornull             = $ornull          ? ' OR ? IS NULL ' : '';
+  my $or_empty_county = $no_empty_county ? ''               : " OR ? = '' ";
+
   "
-        ( $table.${prefix}county  = ? OR ? = '' $ornull )
-    AND ( $table.${prefix}state   = ? OR ? = '' $ornull )
+        ( $table.${prefix}county  = ? $or_empty_county $ornull )
+    AND ( $table.${prefix}state   = ? OR ? = ''        $ornull )
     AND   $table.${prefix}country = ?
   ";
 }



More information about the freeside-commits mailing list