[freeside-commits] freeside/FS/FS Schema.pm, 1.173, 1.174 class_Common.pm, NONE, 1.1 category_Common.pm, NONE, 1.1 cust_class.pm, NONE, 1.1 cust_category.pm, NONE, 1.1 cust_main.pm, 1.468, 1.469 pkg_class.pm, 1.3, 1.4 pkg_category.pm, 1.2, 1.3

Ivan,,, ivan at wavetail.420.am
Wed Oct 28 18:08:34 PDT 2009


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

Modified Files:
	Schema.pm cust_main.pm pkg_class.pm pkg_category.pm 
Added Files:
	class_Common.pm category_Common.pm cust_class.pm 
	cust_category.pm 
Log Message:
customer classification, RT#6376

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

use strict;
use base qw( FS::class_Common );
use FS::cust_main;
use FS::cust_category;

=head1 NAME

FS::cust_class - Object methods for cust_class records

=head1 SYNOPSIS

  use FS::cust_class;

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

  $error = $record->insert;

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

  $error = $record->delete;

  $error = $record->check;

=head1 DESCRIPTION

An FS::pkg_class object represents an customer class.  Every customer (see
L<FS::cust_main>) has, optionally, a customer class. FS::cust_class inherits
from FS::Record.  The following fields are currently supported:

=over 4

=item classnum

primary key

=item classname

Text name of this customer class

=item categorynum

Number of associated cust_category (see L<FS::cust_category>)

=item disabled

Disabled flag, empty or 'Y'

=back

=head1 METHODS

=over 4

=item new HASHREF

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

=cut

sub table { 'cust_class'; }
sub _target_table { 'cust_main'; }

=item insert

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

=item delete

Delete this customer class from the database.  Only customer classes with no
associated customers can be deleted.  If there is an error, returns
the error, otherwise returns false.

=item replace [ OLD_RECORD ]

Replaces 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 customer class.  If there is
an error, returns the error, otherwise returns false.  Called by the insert
and replace methods.

=item cust_category

=item category

Returns the cust_category record associated with this class, or false if there
is none.

=cut

sub cust_category {
  my $self = shift;
  $self->category;
}

=item categoryname

Returns the category name associated with this class, or false if there
is none.

=cut

=back

=head1 BUGS

=head1 SEE ALSO

L<FS::cust_main>, L<FS::Record>

=cut

1;

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

use strict;
use base qw( FS::Record );
use FS::Record qw( qsearch );

=head1 NAME

FS::category_Common - Base class for category (group of classifications) classes

=head1 SYNOPSIS

use base qw( FS::category_Common );
use FS::class_table; #should use this

#optional for non-standard names
sub _class_table { 'table_name'; } #default is to replace s/category/class/

=head1 DESCRIPTION

FS::category_Common is a base class for classes which provide a categorization
(group of classifications) for other classes, such as pkg_category or
cust_category.

=item delete

Deletes this category from the database.  Only categories with no associated
classifications can be deleted.  If there is an error, returns the error,
otherwise returns false.

=cut

sub delete {
  my $self = shift;

  return "Can't delete a ". $self->table.
         " with ". $self->_class_table. " records!"
    if qsearch( $self->_class_table, { 'categorynum' => $self->categorynum } );

  $self->SUPER::delete;
}

=item check

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

=cut

sub check {
  my $self = shift;

  $self->ut_numbern('categorynum')
    or $self->ut_text('categoryname')
    or $self->ut_snumbern('weight')
    or $self->ut_enum('disabled', [ '', 'Y' ])
    or $self->SUPER::check;

}

=back

=cut

#defaults

use vars qw( $_class_table );
sub _class_table {
  return $_class_table if $_class_table;
  my $self = shift;
  $_class_table = $self->table;
  $_class_table =~ s/category/cclass/ # s/_category$/_class/
    or die "can't determine an automatic class table for $_class_table";
  $_class_table;
}

=head1 BUGS

=head1 SEE ALSO

L<FS::Record>

=cut

1;


Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.468
retrieving revision 1.469
diff -u -d -r1.468 -r1.469
--- cust_main.pm	28 Oct 2009 19:01:18 -0000	1.468
+++ cust_main.pm	29 Oct 2009 01:08:32 -0000	1.469
@@ -45,6 +45,7 @@
 use FS::part_referral;
 use FS::cust_main_county;
 use FS::cust_location;
+use FS::cust_class;
 use FS::cust_main_exemption;
 use FS::cust_tax_adjustment;
 use FS::tax_rate;
@@ -1537,6 +1538,7 @@
     || $self->ut_number('agentnum')
     || $self->ut_textn('agent_custid')
     || $self->ut_number('refnum')
+    || $self->ut_foreign_keyn('classnum', 'cust_class', 'classnum')
     || $self->ut_textn('custbatch')
     || $self->ut_name('last')
     || $self->ut_name('first')

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

use strict;
use base qw( FS::Record );
use FS::Record qw( qsearch qsearchs );

=head1 NAME

FS::class_Common - Base class for classification classes

=head1 SYNOPSIS

use base qw( FS::class_Common );
use FS::category_table; #should use this

#required
sub _target_table { 'table_name'; }

#optional for non-standard names
sub _target_column { 'classnum'; } #default is classnum
sub _category_table { 'table_name'; } #default is to replace s/class/category/

=head1 DESCRIPTION

FS::class_Common is a base class for classes which provide a classification for
other classes, such as pkg_class or cust_class.

=head1 METHODS

=over 4

=item new HASHREF

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

=cut

=item insert

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

=item delete

Deletes this classification from the database.  Only classifications with no
associated target objects can be deleted.  If there is an error, returns
the error, otherwise returns false.

=cut

sub delete {
  my $self = shift;

  return "Can't delete a ". $self->table.
         " with ". $self->_target_table. " records!"
    if qsearch( $self->_target_table,
                { $self->_target_column => $self->classnum }
              );

  $self->SUPER::delete;
}

=item replace OLD_RECORD

Replaces 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 package classification.  If
there is an error, returns the error, otherwise returns false.  Called by the
insert and replace methods.

=cut

sub check {
  my $self = shift;

  $self->ut_numbern('classnum')
    or $self->ut_text('classname')
    or $self->ut_foreign_keyn( 'categorynum',
                               $self->_category_table,
                               'categorynum',
                             )
    or $self->ut_enum('disabled', [ '', 'Y' ] )
    or $self->SUPER::check;

}

=item category

Returns the category record associated with this class, or false if there is
none.

=cut

sub category {
  my $self = shift;
  qsearchs($self->_category_table, { 'categorynum' => $self->categorynum } );
}

=item categoryname

Returns the category name associated with this class, or false if there
is none.

=cut

sub categoryname {
  my $category = shift->category;
  $category ? $category->categoryname : '';
}

#required
sub _target_table {
  my $self = shift;
  die "_target_table unspecified for $self";
}

#defaults

sub _target_column { 'classnum'; }

use vars qw( $_category_table );
sub _category_table {
  return $_category_table if $_category_table;
  my $self = shift;
  $_category_table = $self->table;
  $_category_table =~ s/class/category/ # s/_class$/_category/
    or die "can't determine an automatic category table for $_category_table";
  $_category_table;
}

=head1 BUGS

=head1 SEE ALSO

L<FS::category_Common>, L<FS::pkg_class>, L<FS::cust_class>

=cut

1;

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.173
retrieving revision 1.174
diff -u -d -r1.173 -r1.174
--- Schema.pm	26 Oct 2009 07:12:11 -0000	1.173
+++ Schema.pm	29 Oct 2009 01:08:32 -0000	1.174
@@ -685,6 +685,7 @@
         'custnum',  'serial',  '',     '', '', '', 
         'agentnum', 'int',  '',     '', '', '', 
         'agent_custid', 'varchar', 'NULL', $char_d, '', '',
+        'classnum', 'int', 'NULL', '', '', '',
         'custbatch', 'varchar', 'NULL', $char_d, '', '',
 #        'titlenum', 'int',  'NULL',   '', '', '', 
         'last',     'varchar', '',     $char_d, '', '', 
@@ -752,7 +753,8 @@
       'unique' => [ [ 'agentnum', 'agent_custid' ] ],
       #'index' => [ ['last'], ['company'] ],
       'index' => [
-                   [ 'agentnum' ], [ 'refnum' ], [ 'custbatch' ],
+                   [ 'agentnum' ], [ 'refnum' ], [ 'classnum' ],
+                   [ 'custbatch' ],
                    [ 'referral_custnum' ],
                    [ 'payby' ], [ 'paydate' ],
                    [ 'archived' ],
@@ -841,6 +843,30 @@
       'index' => [ [ 'custnum' ], [ '_date' ], ],
     },
 
+    'cust_category' => {
+      'columns' => [
+        'categorynum',   'serial',  '', '', '', '', 
+        'categoryname',  'varchar', '', $char_d, '', '', 
+        'weight',         'int', 'NULL',  '', '', '',
+        'disabled',      'char', 'NULL',   1, '', '', 
+      ],
+      'primary_key' => 'categorynum',
+      'unique' => [],
+      'index' => [ ['disabled'] ],
+    },
+
+    'cust_class' => {
+      'columns' => [
+        'classnum',    'serial',   '',      '', '', '', 
+        'classname',   'varchar',  '', $char_d, '', '', 
+        'categorynum', 'int',  'NULL',      '', '', '', 
+        'disabled',    'char', 'NULL',       1, '', '', 
+      ],
+      'primary_key' => 'classnum',
+      'unique' => [],
+      'index' => [ ['disabled'] ],
+    },
+
     'cust_main_exemption' => {
       'columns' => [
         'exemptionnum', 'serial', '',      '', '', '',

Index: pkg_category.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/pkg_category.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- pkg_category.pm	5 Oct 2009 00:49:34 -0000	1.2
+++ pkg_category.pm	29 Oct 2009 01:08:32 -0000	1.3
@@ -1,11 +1,12 @@
 package FS::pkg_category;
 
 use strict;
+use base qw( FS::category_Common );
 use vars qw( @ISA $me $DEBUG );
 use FS::Record qw( qsearch dbh );
+use FS::pkg_class;
 use FS::part_pkg;
 
- at ISA = qw( FS::Record );
 $DEBUG = 0;
 $me = '[FS::pkg_category]';
 
@@ -36,11 +37,21 @@
 
 =over 4
 
-=item categorynum - primary key (assigned automatically for new package categoryes)
+=item categorynum
 
-=item categoryname - Text name of this package category
+primary key (assigned automatically for new package categoryes)
 
-=item disabled - Disabled flag, empty or 'Y'
+=item categoryname
+
+Text name of this package category
+
+=item weight
+
+Weight
+
+=item disabled
+
+Disabled flag, empty or 'Y'
 
 =back
 
@@ -50,8 +61,8 @@
 
 =item new HASHREF
 
-Creates a new package category.  To add the package category to the database, see
-L<"insert">.
+Creates a new package category.  To add the package category to the database,
+see L<"insert">.
 
 =cut
 
@@ -64,22 +75,11 @@
 
 =item delete
 
-Deletes this package category from the database.  Only package categoryes with no
-associated package definitions can be deleted.  If there is an error, returns
-the error, otherwise returns false.
-
-=cut
-
-sub delete {
-  my $self = shift;
-
-  return "Can't delete an pkg_category with pkg_class records!"
-    if qsearch( 'pkg_class', { 'categorynum' => $self->categorynum } );
-
-  $self->SUPER::delete;
-}
+Deletes this package category from the database.  Only package categoryes with
+no associated package definitions can be deleted.  If there is an error,
+returns the error, otherwise returns false.
 
-=item replace OLD_RECORD
+=item replace [ OLD_RECORD ]
 
 Replaces OLD_RECORD with this one in the database.  If there is an error,
 returns the error, otherwise returns false.
@@ -90,18 +90,6 @@
 error, returns the error, otherwise returns false.  Called by the insert and
 replace methods.
 
-=cut
-
-sub check {
-  my $self = shift;
-
-  $self->ut_numbern('categorynum')
-  or $self->ut_text('categoryname')
-  or $self->ut_snumber('weight')
-  or $self->SUPER::check;
-
-}
-
 # _ upgrade_data
 #
 # Used by FS::Upgrade to migrate to a new database.
@@ -136,7 +124,7 @@
 
 =head1 SEE ALSO
 
-L<FS::Record>, L<FS::part_pkg>, schema.html from the base documentation.
+L<FS::category_Common>, L<FS::Record>
 
 =cut
 

Index: pkg_class.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/pkg_class.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- pkg_class.pm	19 Jun 2008 03:18:17 -0000	1.3
+++ pkg_class.pm	29 Oct 2009 01:08:32 -0000	1.4
@@ -1,13 +1,11 @@
 package FS::pkg_class;
 
 use strict;
-use vars qw( @ISA );
-use FS::Record qw( qsearchs qsearch );
+use FS::class_Common;
+use base qw( FS::class_Common );
 use FS::part_pkg;
 use FS::pkg_category;
 
- at ISA = qw( FS::Record );
-
 =head1 NAME
 
 FS::pkg_class - Object methods for pkg_class records
@@ -35,13 +33,21 @@
 
 =over 4
 
-=item classnum - primary key (assigned automatically for new package classes)
+=item classnum
 
-=item classname - Text name of this package class
+primary key (assigned automatically for new package classes)
 
-=item categorynum - Number of associated pkg_category (see L<FS::pkg_category>)
+=item classname
 
-=item disabled - Disabled flag, empty or 'Y'
+Text name of this package class
+
+=item categorynum
+
+Number of associated pkg_category (see L<FS::pkg_category>)
+
+=item disabled
+
+Disabled flag, empty or 'Y'
 
 =back
 
@@ -57,6 +63,7 @@
 =cut
 
 sub table { 'pkg_class'; }
+sub _target_table { 'part_pkg'; }
 
 =item insert
 
@@ -69,18 +76,7 @@
 associated package definitions can be deleted.  If there is an error, returns
 the error, otherwise returns false.
 
-=cut
-
-sub delete {
-  my $self = shift;
-
-  return "Can't delete an pkg_class with part_pkg records!"
-    if qsearch( 'part_pkg', { 'classnum' => $self->classnum } );
-
-  $self->SUPER::delete;
-}
-
-=item replace OLD_RECORD
+=item replace [ OLD_RECORD ]
 
 Replaces OLD_RECORD with this one in the database.  If there is an error,
 returns the error, otherwise returns false.
@@ -91,20 +87,10 @@
 error, returns the error, otherwise returns false.  Called by the insert and
 replace methods.
 
-=cut
-
-sub check {
-  my $self = shift;
-
-  $self->ut_numbern('classnum')
-  or $self->ut_text('classname')
-  or $self->ut_foreign_keyn('categorynum', 'pkg_category', 'categorynum')
-  or $self->SUPER::check;
-
-}
-
 =item pkg_category
 
+=item category
+
 Returns the pkg_category record associated with this class, or false if there
 is none.
 
@@ -112,7 +98,7 @@
 
 sub pkg_category {
   my $self = shift;
-  qsearchs('pkg_category', { 'categorynum' => $self->categorynum } );
+  $self->category;
 }
 
 =item categoryname
@@ -120,22 +106,14 @@
 Returns the category name associated with this class, or false if there
 is none.
 
-=cut
-
-sub categoryname {
-  my $pkg_category = shift->pkg_category;
-  $pkg_category->categoryname if $pkg_category;
-}
-
 =back
 
 =head1 BUGS
 
 =head1 SEE ALSO
 
-L<FS::Record>, L<FS::part_pkg>, schema.html from the base documentation.
+L<FS::part_pkg>, L<FS::Record>
 
 =cut
 
 1;
-

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

use strict;
use base qw( FS::category_Common );
use FS::cust_class;

=head1 NAME

FS::cust_category - Object methods for cust_category records

=head1 SYNOPSIS

  use FS::cust_category;

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

  $error = $record->insert;

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

  $error = $record->delete;

  $error = $record->check;

=head1 DESCRIPTION

An FS::cust_category object represents a customer category.  Every customer
class (see L<FS::cust_class>) has, optionally, a customer category.
FS::cust_category inherits from FS::Record.  The following fields are currently
supported:

=over 4

=item categorynum

primary key

=item categoryname

Text name of this package category

=item weight

Weight

=item disabled

Disabled flag, empty or 'Y'

=back

=head1 METHODS

=over 4

=item new HASHREF

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

=cut

sub table { 'cust_category'; }

=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 example.  If there is
an error, returns the error, otherwise returns false.  Called by the insert
and replace methods.

=back

=head1 BUGS

=head1 SEE ALSO

L<FS::cust_class>, L<FS::Record>

=cut

1;




More information about the freeside-commits mailing list