[freeside-commits] freeside/FS/FS Schema.pm, 1.118, 1.119 cust_pkg.pm, 1.105, 1.106 Conf.pm, 1.256, 1.257 cust_location.pm, NONE, 1.1 cust_main.pm, 1.394, 1.395

Ivan,,, ivan at wavetail.420.am
Wed Jan 7 17:45:23 PST 2009


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

Modified Files:
	Schema.pm cust_pkg.pm Conf.pm cust_main.pm 
Added Files:
	cust_location.pm 
Log Message:
start adding package locations, RT#4499

--- NEW FILE: cust_location.pm ---
package FS::cust_location;

use strict;
use base qw( FS::Record );
use Locale::Country;
use FS::Record qw( qsearch ); #qsearchs );
use FS::cust_main;
use FS::cust_main_county;

=head1 NAME

FS::cust_location - Object methods for cust_location records

=head1 SYNOPSIS

  use FS::cust_location;

  $record = new FS::cust_location \%hash;
  $record = new FS::cust_location { 'column' => 'value' };

  $error = $record->insert;

  $error = $new_record->replace($old_record);

  $error = $record->delete;

  $error = $record->check;

=head1 DESCRIPTION

An FS::cust_location object represents a customer location.  FS::cust_location
inherits from FS::Record.  The following fields are currently supported:

=over 4

=item locationnum

primary key

=item custnum

custnum

=item address1

Address line one (required)

=item address2

Address line two (optional)

=item city

City

=item county

County (optional, see L<FS::cust_main_county>)

=item state

State (see L<FS::cust_main_county>)

=item zip

Zip

=item country

Country (see L<FS::cust_main_county>)

=item geocode

Geocode

=back

=head1 METHODS

=over 4

=item new HASHREF

Creates a new location.  To add the location to the database, see L<"insert">.

Note that this stores the hash reference, not a distinct copy of the hash it
points to.  You can ask the object for a copy with the I<hash> method.

=cut

sub table { 'cust_location'; }

=item insert

Adds this record to the database.  If there is an error, returns the error,
otherwise returns false.

=item delete

Delete this record from the database.

=item replace OLD_RECORD

Replaces the OLD_RECORD with this one in the database.  If there is an error,
returns the error, otherwise returns false.

=item check

Checks all fields to make sure this is a valid location.  If there is
an error, returns the error, otherwise returns false.  Called by the insert
and replace methods.

=cut

#some false laziness w/cust_main, but since it should eventually lose these
#fields anyway...
sub check {
  my $self = shift;

  my $error = 
    $self->ut_numbern('locationnum')
    || $self->ut_foreign_key('custnum', 'cust_main', 'custnum')
    || $self->ut_text('address1')
    || $self->ut_textn('address2')
    || $self->ut_text('city')
    || $self->ut_textn('county')
    || $self->ut_textn('state')
    || $self->ut_country('country')
    || $self->ut_zip('zip', $self->country)
    || $self->ut_alphan('geocode')
  ;
  return $error if $error;

  unless ( qsearch('cust_main_county', {
    'country' => $self->country,
    'state'   => '',
   } ) ) {
    return "Unknown state/county/country: ".
      $self->state. "/". $self->county. "/". $self->country
      unless qsearch('cust_main_county',{
        'state'   => $self->state,
        'county'  => $self->county,
        'country' => $self->country,
      } );
  }

  $self->SUPER::check;
}

=item country_full

Returns this locations's full country name

=cut

sub country_full {
  my $self = shift;
  code2country($self->country);
}

=back

=head1 BUGS

Not yet used for cust_main billing and shipping addresses.

=head1 SEE ALSO

L<FS::cust_main_county>, L<FS::cust_pkg>, L<FS::Record>,
schema.html from the base documentation.

=cut

1;


Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- Schema.pm	21 Dec 2008 18:09:55 -0000	1.118
+++ Schema.pm	8 Jan 2009 01:45:21 -0000	1.119
@@ -671,6 +671,28 @@
                  ],
     },
 
+    #eventually use for billing & ship from cust_main too
+    #for now, just cust_pkg locations
+    'cust_location' => {
+      'columns' => [
+        'locationnum',  'serial',     '',      '', '', '',
+        'custnum',         'int',     '',      '', '', '',
+        'address1',    'varchar',     '', $char_d, '', '', 
+        'address2',    'varchar', 'NULL', $char_d, '', '', 
+        'city',        'varchar',     '', $char_d, '', '', 
+        'county',      'varchar', 'NULL', $char_d, '', '', 
+        'state',       'varchar', 'NULL', $char_d, '', '', 
+        'zip',         'varchar', 'NULL',      10, '', '', 
+        'country',        'char',     '',       2, '', '', 
+        'geocode',     'varchar', 'NULL',      20, '', '',
+      ],
+      'primary_key' => 'locationnum',
+      'unique'      => [],
+      'index'       => [ [ 'custnum' ],
+                         [ 'county' ], [ 'state' ], [ 'country' ], [ 'zip' ],
+                       ],
+    },
+
     'cust_main_invoice' => {
       'columns' => [
         'destnum',  'serial',  '',     '', '', '', 
@@ -938,26 +960,27 @@
 
     'cust_pkg' => {
       'columns' => [
-        'pkgnum',         'serial',    '',   '', '', '', 
-        'custnum',        'int',    '',   '', '', '', 
-        'pkgpart',        'int',    '',   '', '', '', 
-        'otaker',         'varchar', '', 32, '', '', 
-        'setup',          @date_type, '', '', 
-        'bill',           @date_type, '', '', 
-        'last_bill',      @date_type, '', '', 
-        'susp',           @date_type, '', '', 
-        'adjourn',        @date_type, '', '', 
-        'cancel',         @date_type, '', '', 
-        'expire',         @date_type, '', '', 
-        'change_date',    @date_type, '', '',
-        'change_pkgnum',  'int', 'NULL', '', '', '',
-        'change_pkgpart', 'int', 'NULL', '', '', '',
-        'manual_flag',    'char', 'NULL', 1, '', '', 
-        'quantity',       'int', 'NULL', '', '', '',
+        'pkgnum',           'serial',     '', '', '', '', 
+        'custnum',             'int',     '', '', '', '', 
+        'pkgpart',             'int',     '', '', '', '', 
+        'locationnum',         'int', 'NULL', '', '', '',
+        'otaker',          'varchar',     '', 32, '', '', 
+        'setup',          @date_type,             '', '', 
+        'bill',           @date_type,             '', '', 
+        'last_bill',      @date_type,             '', '', 
+        'susp',           @date_type,             '', '', 
+        'adjourn',        @date_type,             '', '', 
+        'cancel',         @date_type,             '', '', 
+        'expire',         @date_type,             '', '', 
+        'change_date',    @date_type,             '', '',
+        'change_pkgnum',       'int', 'NULL', '', '', '',
+        'change_pkgpart',      'int', 'NULL', '', '', '',
+        'manual_flag',        'char', 'NULL',  1, '', '', 
+        'quantity',            'int', 'NULL', '', '', '',
       ],
       'primary_key' => 'pkgnum',
       'unique' => [],
-      'index' => [ ['custnum'], ['pkgpart'],
+      'index' => [ ['custnum'], ['pkgpart'], [ 'locationnum' ],
                    ['setup'], ['last_bill'], ['bill'], ['susp'], ['adjourn'],
                    ['expire'], ['cancel'],
                    ['change_date'],

Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.256
retrieving revision 1.257
diff -u -d -r1.256 -r1.257
--- Conf.pm	21 Dec 2008 21:33:28 -0000	1.256
+++ Conf.pm	8 Jan 2009 01:45:21 -0000	1.257
@@ -2001,6 +2001,13 @@
     'section'     => 'billing',
     'description' => 'By default, tax calculations are done based on the billing address.  Enable this switch to calculate tax based on the shipping address instead.  Note: Tax reports can take a long time when enabled.',
     'type'        => 'checkbox',
+  }
+,
+  {
+    'key'         => 'tax-pkg_address',
+    'section'     => 'billing',
+    'description' => 'By default, tax calculations are done based on the billing address.  Enable this switch to calculate tax based on the package address instead (when present).  Note: Tax reports can take a long time when enabled.',
+    'type'        => 'checkbox',
   },
 
   {

Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -d -r1.105 -r1.106
--- cust_pkg.pm	30 Dec 2008 22:00:27 -0000	1.105
+++ cust_pkg.pm	8 Jan 2009 01:45:21 -0000	1.106
@@ -13,6 +13,7 @@
 use FS::cust_svc;
 use FS::part_pkg;
 use FS::cust_main;
+use FS::cust_location;
 use FS::type_pkgs;
 use FS::pkg_svc;
 use FS::cust_bill_pkg;
@@ -106,7 +107,7 @@
 
 =item pkgnum
 
-primary key (assigned automatically for new billing items)
+Primary key (assigned automatically for new billing items)
 
 =item custnum
 
@@ -116,6 +117,10 @@
 
 Billing item definition (see L<FS::part_pkg>)
 
+=item locationnum
+
+Optional link to package location (see L<FS::location>)
+
 =item setup
 
 date
@@ -435,6 +440,7 @@
     $self->ut_numbern('pkgnum')
     || $self->ut_foreign_key('custnum', 'cust_main', 'custnum')
     || $self->ut_numbern('pkgpart')
+    || $self->ut_foreign_keyn('locationnum', 'location', 'locationnum')
     || $self->ut_numbern('setup')
     || $self->ut_numbern('bill')
     || $self->ut_numbern('susp')
@@ -1569,6 +1575,30 @@
   qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
 }
 
+=item cust_location
+
+Returns the location object, if any (see L<FS::cust_location>).
+
+=cut
+
+sub cust_location {
+  my $self = shift;
+  return '' unless $self->locationnum;
+  qsearchs( 'cust_main', { 'locationnum' => $self->locationnum } );
+}
+
+=item cust_location_or_main
+
+If this package is associated with a location, returns the locaiton (see
+L<FS::cust_location>), otherwise returns the customer (see L<FS::cust_main>).
+
+=cut
+
+sub cust_location_or_main {
+  my $self = shift;
+  $self->cust_location || $self->cust_main;
+}
+
 =item seconds_since TIMESTAMP
 
 Returns the number of seconds all accounts (see L<FS::svc_acct>) in this

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.394
retrieving revision 1.395
diff -u -d -r1.394 -r1.395
--- cust_main.pm	31 Dec 2008 18:07:31 -0000	1.394
+++ cust_main.pm	8 Jan 2009 01:45:21 -0000	1.395
@@ -135,101 +135,181 @@
 
 =over 4
 
-=item custnum - primary key (assigned automatically for new customers)
+=item custnum
 
-=item agentnum - agent (see L<FS::agent>)
+Primary key (assigned automatically for new customers)
 
-=item refnum - Advertising source (see L<FS::part_referral>)
+=item agentnum
 
-=item first - name
+Agent (see L<FS::agent>)
 
-=item last - name
+=item refnum
 
-=item ss - social security number (optional)
+Advertising source (see L<FS::part_referral>)
 
-=item company - (optional)
+=item first
+
+First name
+
+=item last
+
+Last name
+
+=item ss
+
+Cocial security number (optional)
+
+=item company
+
+(optional)
 
 =item address1
 
-=item address2 - (optional)
+=item address2
+
+(optional)
 
 =item city
 
-=item county - (optional, see L<FS::cust_main_county>)
+=item county
 
-=item state - (see L<FS::cust_main_county>)
+(optional, see L<FS::cust_main_county>)
+
+=item state
+
+(see L<FS::cust_main_county>)
 
 =item zip
 
-=item country - (see L<FS::cust_main_county>)
+=item country
 
-=item daytime - phone (optional)
+(see L<FS::cust_main_county>)
 
-=item night - phone (optional)
+=item daytime
 
-=item fax - phone (optional)
+phone (optional)
 
-=item ship_first - name
+=item night
 
-=item ship_last - name
+phone (optional)
 
-=item ship_company - (optional)
+=item fax
+
+phone (optional)
+
+=item ship_first
+
+Shipping first name
+
+=item ship_last
+
+Shipping last name
+
+=item ship_company
+
+(optional)
 
 =item ship_address1
 
-=item ship_address2 - (optional)
+=item ship_address2
+
+(optional)
 
 =item ship_city
 
-=item ship_county - (optional, see L<FS::cust_main_county>)
+=item ship_county
 
-=item ship_state - (see L<FS::cust_main_county>)
+(optional, see L<FS::cust_main_county>)
+
+=item ship_state
+
+(see L<FS::cust_main_county>)
 
 =item ship_zip
 
-=item ship_country - (see L<FS::cust_main_county>)
+=item ship_country
 
-=item ship_daytime - phone (optional)
+(see L<FS::cust_main_county>)
 
-=item ship_night - phone (optional)
+=item ship_daytime
 
-=item ship_fax - phone (optional)
+phone (optional)
 
-=item payby - Payment Type (See L<FS::payinfo_Mixin> for valid payby values)
+=item ship_night
 
-=item payinfo - Payment Information (See L<FS::payinfo_Mixin> for data format)
+phone (optional)
 
-=item paymask - Masked payinfo (See L<FS::payinfo_Mixin> for how this works)
+=item ship_fax
+
+phone (optional)
+
+=item payby
+
+Payment Type (See L<FS::payinfo_Mixin> for valid payby values)
+
+=item payinfo
+
+Payment Information (See L<FS::payinfo_Mixin> for data format)
+
+=item paymask
+
+Masked payinfo (See L<FS::payinfo_Mixin> for how this works)
 
 =item paycvv
 
 Card Verification Value, "CVV2" (also known as CVC2 or CID), the 3 or 4 digit number on the back (or front, for American Express) of the credit card
 
-=item paydate - expiration date, mm/yyyy, m/yyyy, mm/yy or m/yy
+=item paydate
 
-=item paystart_month - start date month (maestro/solo cards only)
+Expiration date, mm/yyyy, m/yyyy, mm/yy or m/yy
 
-=item paystart_year - start date year (maestro/solo cards only)
+=item paystart_month
 
-=item payissue - issue number (maestro/solo cards only)
+Start date month (maestro/solo cards only)
 
-=item payname - name on card or billing name
+=item paystart_year
 
-=item payip - IP address from which payment information was received
+Start date year (maestro/solo cards only)
 
-=item tax - tax exempt, empty or `Y'
+=item payissue
 
-=item otaker - order taker (assigned automatically, see L<FS::UID>)
+Issue number (maestro/solo cards only)
 
-=item comments - comments (optional)
+=item payname
 
-=item referral_custnum - referring customer number
+Name on card or billing name
 
-=item spool_cdr - Enable individual CDR spooling, empty or `Y'
+=item payip
 
-=item dundate - a suggestion to events (see L<FS::part_bill_event">) to delay until this unix timestamp
+IP address from which payment information was received
 
-=item squelch_cdr - Discourage individual CDR printing, empty or `Y'
+=item tax
+
+Tax exempt, empty or `Y'
+
+=item otaker
+
+Order taker (assigned automatically, see L<FS::UID>)
+
+=item comments
+
+Comments (optional)
+
+=item referral_custnum
+
+Referring customer number
+
+=item spool_cdr
+
+Enable individual CDR spooling, empty or `Y'
+
+=item dundate
+
+A suggestion to events (see L<FS::part_bill_event">) to delay until this unix timestamp
+
+=item squelch_cdr
+
+Discourage individual CDR printing, empty or `Y'
 
 =back
 
@@ -2905,6 +2985,11 @@
 
 Explicitly pass the objects to be tested (typically used with eventtable).
 
+=item testonly
+
+Set to true to return the objects, but not actually insert them into the
+database.
+
 =back
 
 =cut
@@ -2935,7 +3020,8 @@
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
-  $self->select_for_update; #mutex
+  $self->select_for_update #mutex
+    unless $opt{testonly};
 
   ###
   # 1: find possible events (initial search)



More information about the freeside-commits mailing list