[freeside-commits] freeside/FS/FS cust_pkg.pm,1.108,1.109
Ivan,,,
ivan at wavetail.420.am
Sun Jan 18 15:51:51 PST 2009
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv10967
Modified Files:
cust_pkg.pm
Log Message:
finish package location tax reporing, RT#4499
Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -d -r1.108 -r1.109
--- cust_pkg.pm 10 Jan 2009 23:56:56 -0000 1.108
+++ cust_pkg.pm 18 Jan 2009 23:51:49 -0000 1.109
@@ -2346,6 +2346,86 @@
}
+=item location_sql
+
+Returns a list: the first item is an SQL fragment identifying matching
+packages/customers via location (taking into account shipping and package
+address taxation, if enabled), and subsequent items are the parameters to
+substitute for the placeholders in that fragment.
+
+=cut
+
+sub location_sql {
+ my($class, %opt) = @_;
+ my $ornull = $opt{'ornull'};
+
+ 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 );
+ } else {
+ @bill_param = qw( county county state state country );
+ }
+
+ my $main_where;
+ my @main_param;
+ if ( $conf->exists('tax-ship_address') ) {
+
+ $main_where = "(
+ ( ( ship_last IS NULL OR ship_last = '' )
+ AND ". _location_sql_where('cust_main', '', $ornull ). "
+ )
+ OR ( ship_last IS NOT NULL AND ship_last != ''
+ AND ". _location_sql_where('cust_main', 'ship_', $ornull). "
+ )
+ )";
+ # AND payby != 'COMP'
+
+ @main_param = ( @bill_param, @bill_param );
+
+ } else {
+
+ $main_where = _location_sql_where('cust_main'); # AND payby != 'COMP'
+ @main_param = @bill_param;
+
+ }
+
+ my $where;
+ my @param;
+ if ( $conf->exists('tax-pkg_address') ) {
+
+ $where = " (
+ ( cust_pkg.locationnum IS NULL AND $main_where )
+ OR ( cust_pkg.locationnum IS NOT NULL AND ". _location_sql_where('cust_location', '', $ornull). " )
+ )";
+ @param = ( @main_param, @bill_param );
+
+ } else {
+
+ $where = $main_where;
+ @param = @main_param;
+
+ }
+
+ ( $where, @param );
+
+}
+
+#subroutine, helper for able
+sub _location_sql_where {
+ my $table = shift;
+ my $prefix = @_ ? shift : '';
+ my $ornull = @_ ? shift : '';
+ $ornull = $ornull ? ' OR ? IS NULL ' : '';
+ "
+ ( $table.${prefix}county = ? OR ? = '' $ornull )
+ AND ( $table.${prefix}state = ? OR ? = '' $ornull )
+ AND $table.${prefix}country = ?
+ ";
+}
+
=head1 SUBROUTINES
=over 4
More information about the freeside-commits
mailing list