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;
$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;
}
}
- 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;
+ }
}
}
$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'};
$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
--- /dev/null
+% if ( $curuser->access_right('Edit customer tags') && @part_tag ) {
+
+ <TR>
+ <TD ALIGN="right"><% $opt{'label'} || 'Tags' %></TD>
+ <TD>
+ <% include( '/elements/select-cust_tag.html',
+ 'curr_value' => \@curr_tagnum,
+ 'part_tag' => \@part_tag,
+ %opt,
+ )
+ %>
+ </TD>
+ </TR>
+
+% } else {
+
+% foreach my $tagnum (@curr_tagnum) {
+ <INPUT TYPE="hidden" NAME="tagnum" VALUE="<% $tagnum %>">
+% }
+
+% }
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+my %opt = @_;
+my $cgi = $opt{'cgi'};
+
+my @curr_tagnum = ();
+if ( $cgi->param('error') ) {
+ @curr_tagnum = $cgi->param('tagnum');
+} elsif ( $opt{'custnum'} ) {
+ @curr_tagnum = map $_->tagnum,
+ qsearch('cust_tag', { 'custnum' => $opt{'custnum'} } );
+}
+
+my $extra_sql = "WHERE disabled IS NULL OR disabled = '' ";
+$extra_sql .= ' OR tagnum IN ('. join(',', @curr_tagnum). ')' if @curr_tagnum;
+
+my @part_tag = qsearch({
+ 'table' => 'part_tag',
+ 'hashref' => {},
+ 'extra_sql' => $extra_sql,
+});
+
+</%init>
<TD BGCOLOR="#ffffff"><FONT COLOR="#<% $cust_main->statuscolor %>"><B><% ucfirst($cust_main->status) %></B></FONT></TD>
</TR>
+% my @part_tag = $cust_main->part_tag;
+% if ( @part_tag ) {
+<TR>
+ <TD ALIGN="right">Tags</TD>
+ <TD BGCOLOR="#ffffff">
+% foreach my $part_tag ( @part_tag ) {
+ <FONT <% length($part_tag->tagcolor)
+ ? 'STYLE="background-color:#'.$part_tag->tagcolor.'"'
+ : '' %>
+ ><% $part_tag->tagname.': '. $part_tag->tagdesc |h %></FONT>
+ <BR>
+% }
+ </TD>
+</TR>
+% }
+
%unless ( scalar(@agentnums) == 1
% && !$curuser->access_right('View customers of all agents') ) {
% my $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } );