diff options
author | ivan <ivan> | 2010-07-16 23:45:24 +0000 |
---|---|---|
committer | ivan <ivan> | 2010-07-16 23:45:24 +0000 |
commit | 556b8e9650155e74416496238cfc0e4abe64c53a (patch) | |
tree | 26a6cac98ec8a944361a0d913392eab6abd53b6a /FS | |
parent | 9414a814e49a86a832e4f56ec1a6bcc927f55e6b (diff) |
customer tags, RT#9192
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/AccessRight.pm | 1 | ||||
-rw-r--r-- | FS/FS/Record.pm | 11 | ||||
-rw-r--r-- | FS/FS/cust_main.pm | 96 | ||||
-rw-r--r-- | FS/FS/cust_tag.pm | 23 |
4 files changed, 113 insertions, 18 deletions
diff --git a/FS/FS/AccessRight.pm b/FS/FS/AccessRight.pm index 9e79754d3..92c4d2299 100644 --- a/FS/FS/AccessRight.pm +++ b/FS/FS/AccessRight.pm @@ -108,6 +108,7 @@ tie my %rights, 'Tie::IxHash', 'View customer', #'View Customer | View tickets', 'Edit customer', + 'Edit customer tags', 'Edit referring customer', 'View customer history', 'Cancel customer', diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index f3dead164..cd5e2d4ca 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -795,6 +795,17 @@ sub setfield { $self->set(@_); } +=item exists COLUMN + +Returns true if the column/field/key COLUMN exists. + +=cut + +sub exists { + my($self,$field) = @_; + exists($self->{Hash}->{$field}); +} + =item AUTLOADED METHODS $record->column is a synonym for $record->get('column'); diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index d8f525e58..84bd6a0e5 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -57,6 +57,7 @@ use FS::cust_tax_location; use FS::part_pkg_taxrate; use FS::agent; use FS::cust_main_invoice; +use FS::cust_tag; use FS::cust_credit_bill; use FS::cust_bill_pay; use FS::prepay_credit; @@ -473,6 +474,30 @@ sub insert { $self->invoicing_list( $invoicing_list ); } + warn " setting customer tags\n" + if $DEBUG > 1; + + foreach my $tagnum ( @{ $self->tagnum || [] } ) { + my $cust_tag = new FS::cust_tag { 'tagnum' => $tagnum, + 'custnum' => $self->custnum }; + my $error = $cust_tag->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + if ( $invoicing_list ) { + $error = $self->check_invoicing_list( $invoicing_list ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + #return "checking invoicing_list (transaction rolled back): $error"; + return $error; + } + $self->invoicing_list( $invoicing_list ); + } + + warn " setting cust_main_exemption\n" if $DEBUG > 1; @@ -1356,23 +1381,13 @@ sub delete { } } - foreach my $cust_main_invoice ( #(email invoice destinations, not invoices) - qsearch( 'cust_main_invoice', { 'custnum' => $self->custnum } ) - ) { - my $error = $cust_main_invoice->delete; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; - } - } - - foreach my $cust_main_exemption ( - qsearch( 'cust_main_exemption', { 'custnum' => $self->custnum } ) - ) { - my $error = $cust_main_exemption->delete; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; + foreach my $table (qw( cust_main_invoice cust_main_exemption cust_tag )) { + foreach my $record ( qsearch( 'table', { 'custnum' => $self->custnum } ) ) { + my $error = $record->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } } } @@ -1478,6 +1493,28 @@ sub replace { $self->invoicing_list( $invoicing_list ); } + if ( $self->exists('tagnum') ) { #so we don't delete these on edit by accident + + #this could be more efficient than deleting and re-inserting, if it matters + foreach my $cust_tag (qsearch('cust_tag', {'custnum'=>$self->custnum} )) { + my $error = $cust_tag->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + foreach my $tagnum ( @{ $self->tagnum || [] } ) { + my $cust_tag = new FS::cust_tag { 'tagnum' => $tagnum, + 'custnum' => $self->custnum }; + my $error = $cust_tag->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + } + my %options = @param; my $tax_exemption = delete $options{'tax_exemption'}; @@ -2475,6 +2512,31 @@ sub agent_name { $self->agent->agent; } +=item cust_tag + +Returns any tags associated with this customer, as FS::cust_tag objects, +or an empty list if there are no tags. + +=cut + +sub cust_tag { + my $self = shift; + qsearch('cust_tag', { 'custnum' => $self->custnum } ); +} + +=item part_tag + +Returns any tags associated with this customer, as FS::part_tag objects, +or an empty list if there are no tags. + +=cut + +sub part_tag { + my $self = shift; + map $_->part_tag, $self->cust_tag; +} + + =item cust_class Returns the customer class, as an FS::cust_class object, or the empty string diff --git a/FS/FS/cust_tag.pm b/FS/FS/cust_tag.pm index 1d174d127..5dfd156b4 100644 --- a/FS/FS/cust_tag.pm +++ b/FS/FS/cust_tag.pm @@ -2,7 +2,9 @@ package FS::cust_tag; use strict; use base qw( FS::Record ); -use FS::Record qw( qsearch qsearchs ); +use FS::Record qw( qsearchs ); +use FS::cust_main; +use FS::part_tag; =head1 NAME @@ -112,6 +114,25 @@ sub check { $self->SUPER::check; } +=item cust_main + +=cut + +sub cust_main { + my $self = shift; + qsearchs( 'cust_main', { 'custnum' => $self->custnum } ); +} + +=item part_tag + +=cut + +sub part_tag { + my $self = shift; + qsearchs( 'part_tag', { 'tagnum' => $self->tagnum } ); +} + + =back =head1 BUGS |