X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_Common.pm;h=a67504a5b49d8dc0c9ba091eed51543b2083f92a;hb=f274814c7cde3681578ca594a2b00475370e4c92;hp=21df6a78feb52eb9f46ef5fedd6f7b83809d8dd0;hpb=e94525637c601f912cd5f5f55115ae4717b338f2;p=freeside.git diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm index 21df6a78f..a67504a5b 100644 --- a/FS/FS/svc_Common.pm +++ b/FS/FS/svc_Common.pm @@ -1,8 +1,9 @@ package FS::svc_Common; use strict; -use vars qw( @ISA $noexport_hack $DEBUG $me ); -use Carp qw( cluck carp croak ); #specify cluck have to specify them all.. +use vars qw( @ISA $noexport_hack $DEBUG $me + $overlimit_missing_cust_svc_nonfatal_kludge ); +use Carp qw( cluck carp croak confess ); #specify cluck have to specify them all use Scalar::Util qw( blessed ); use FS::Record qw( qsearch qsearchs fields dbh ); use FS::cust_main_Mixin; @@ -18,6 +19,8 @@ use FS::inventory_class; $me = '[FS::svc_Common]'; $DEBUG = 0; +$overlimit_missing_cust_svc_nonfatal_kludge = 0; + =head1 NAME FS::svc_Common - Object method for all svc_ records @@ -49,7 +52,7 @@ sub search_sql_field { my( $class, $field, $string ) = @_; my $table = $class->table; my $q_string = dbh->quote($string); - "lc($table.$field) = lc($q_string)"; + "LOWER($table.$field) = LOWER($q_string)"; } #fallback for services that don't provide a search... @@ -151,6 +154,11 @@ sub label { $self->svcnum; } +sub label_long { + my $self = shift; + $self->label(@_); +} + =item check Checks the validity of fields in this record. @@ -247,8 +255,11 @@ sub insert { $self->svcpart($cust_svc->svcpart); } - my $error = $self->set_auto_inventory + my $error = $self->preinsert_hook_first + || $self->set_auto_inventory || $self->check + || $self->_check_duplicate + || $self->preinsert_hook || $self->SUPER::insert; if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -314,6 +325,12 @@ sub insert { ''; } +#fallbacks +sub preinsert_hook_first { ''; } +sub _check_duplcate { ''; } +sub preinsert_hook { ''; } +sub table_dupcheck_fields { (); } + =item delete [ , OPTION => VALUE ... ] Deletes this account from the database. If there is an error, returns the @@ -390,6 +407,25 @@ sub replace { return $error; } + #redundant, but so any duplicate fields are maniuplated as appropriate + # (svc_phone.phonenum) + $error = $new->check; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + #if ( $old->username ne $new->username || $old->domsvc != $new->domsvc ) { + if ( grep { $old->$_ ne $new->$_ } $new->table_dupcheck_fields ) { + + $new->svcpart( $new->cust_svc->svcpart ) unless $new->svcpart; + $error = $new->_check_duplicate; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + $error = $new->SUPER::replace($old); if ($error) { $dbh->rollback if $oldAutoCommit; @@ -511,7 +547,7 @@ sub setx { return $error if $error; my $part_svc = $self->part_svc; - return "Unkonwn svcpart" unless $part_svc; + return "Unknown svcpart" unless $part_svc; #set default/fixed/whatever fields from part_svc @@ -769,7 +805,19 @@ Sets or retrieves overlimit date. sub overlimit { my $self = shift; - $self->cust_svc->overlimit(@_); + #$self->cust_svc->overlimit(@_); + my $cust_svc = $self->cust_svc; + unless ( $cust_svc ) { #wtf? + my $error = "$me overlimit: missing cust_svc record for svc_acct svcnum ". + $self->svcnum; + if ( $overlimit_missing_cust_svc_nonfatal_kludge ) { + cluck "$error; continuing anyway as requested"; + return ''; + } else { + confess $error; + } + } + $cust_svc->overlimit(@_); } =item cancel