summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2005-07-14 10:52:46 +0000
committerivan <ivan>2005-07-14 10:52:46 +0000
commit08662d58e7b9a13cf841e9c89daa39b28655724e (patch)
treebb6415dcfc8c94a30639c8a913051a38c31780ad /FS
parentc91e5cd4ce307d5f3573ea309cbcf03186ea3de4 (diff)
move account search (httemplate/search/svc_acct.cgi) to new template, cust-fields configuration value to control which customer fields are shown on reports
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Conf.pm17
-rw-r--r--FS/FS/UI/Web.pm98
-rw-r--r--FS/FS/cust_bill.pm12
-rw-r--r--FS/FS/cust_bill_event.pm10
-rw-r--r--FS/FS/cust_credit.pm11
-rw-r--r--FS/FS/cust_main.pm44
-rw-r--r--FS/FS/cust_main_Mixin.pm103
-rw-r--r--FS/FS/cust_pay.pm11
-rw-r--r--FS/FS/svc_Common.pm21
-rw-r--r--FS/MANIFEST2
-rw-r--r--FS/t/cust_main_Mixin.t5
11 files changed, 309 insertions, 25 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index d78135ad0..78b1f6179 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -1545,6 +1545,23 @@ httemplate/docs/config.html
'type' => 'checkbox',
},
+ {
+ 'key' => 'cust-fields',
+ 'section' => 'UI',
+ 'description' => 'Which customer fields to display on reports',
+ 'type' => 'select',
+ 'select_enum' => [
+ 'Customer: Last, First</b> or</i> Company (Last, First)</b>',
+ 'Cust# | Customer: custnum | Last, First or Company (Last, First)',
+ 'Name | Company: Last, First | Company',
+ 'Cust# | Name | Company: custnum | Last, First | Company',
+ '(bill) Customer | (service) Customer: Last, First or Company (Last, First) | (same for service address if present)',
+ 'Cust# | (bill) Customer | (service) Customer: custnum | Last, First or Company (Last, First) | (same for service address if present)',
+ '(bill) Name | (bill) Company | (service) Name | (service) Company: Last, First | Company | (same for service address if present)',
+ 'Cust# | (bill) Name | (bill) Company | (service) Name | (service) Company: custnum | Last, First | Company | (same for service address if present)',
+ ],
+ },
+
);
1;
diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm
index e701141ec..716fd861f 100644
--- a/FS/FS/UI/Web.pm
+++ b/FS/FS/UI/Web.pm
@@ -1,5 +1,8 @@
package FS::UI::Web;
+use FS::Conf;
+use FS::Record qw(dbdef);
+
#use vars qw(@ISA);
#use FS::UI
#@ISA = qw( FS::UI );
@@ -18,7 +21,102 @@ sub parse_beginning_ending {
( $beginning, $ending );
}
+###
+# cust_main report methods
+###
+
+=item cust_header
+
+Returns an array of customer information headers according to the
+B<cust-fields> configuration setting.
+
+=cut
+
+use vars qw( @cust_fields );
+
+sub cust_sql_fields {
+ my @fields = qw( last first company );
+ push @fields, map "ship_$_", @fields
+ if dbdef->table('cust_main')->column('ship_last');
+ map "cust_main.$_", @fields;
+}
+
+sub cust_header {
+
+ warn "FS::svc_Common::cust_header called"
+ if $DEBUG;
+
+ my $conf = new FS::Conf;
+
+ my %header2method = (
+ 'Customer' => 'name',
+ 'Cust#' => 'custnum',
+ 'Name' => 'contact',
+ 'Company' => 'company',
+ '(bill) Customer' => 'name',
+ '(service) Customer' => 'ship_name',
+ '(bill) Name' => 'contact',
+ '(service) Name' => 'ship_contact',
+ '(bill) Company' => 'company',
+ '(service) Company' => 'ship_company',
+ );
+
+ my @cust_header;
+ if ( $conf->exists('cust-fields')
+ && $conf->config('cust-fields') =~ /^([\w \|\#\(\)]+):/
+ )
+ {
+ warn " found cust-fields configuration value"
+ if $DEBUG;
+
+ my $cust_fields = $1;
+ @cust_header = split(/ \| /, $cust_fields);
+ @cust_fields = map { $header2method{$_} } @cust_header;
+ } else {
+ warn " no cust-fields configuration value found; using default 'Customer'"
+ if $DEBUG;
+ @cust_header = ( 'Customer' );
+ @cust_fields = ( 'cust_name' );
+ }
+
+ #my $svc_x = shift;
+ @cust_header;
+}
+
+=item cust_fields
+
+Given a svc_ object that contains fields from cust_main (say, from a
+JOINed search. See httemplate/search/svc_* for examples), returns an array
+of customer information according to the <B>cust-fields</B> configuration
+setting, or "(unlinked)" if this service is not linked to a customer.
+
+=cut
+
+sub cust_fields {
+ my $svc_x = shift;
+ warn "FS::svc_Common::cust_fields called for $svc_x ".
+ "(cust_fields: @cust_fields)"
+ if $DEBUG > 1;
+
+ cust_header() unless @cust_fields;
+
+ my $seen_unlinked = 0;
+ map {
+ if ( $svc_x->custnum ) {
+ warn " $svc_x -> $_"
+ if $DEBUG > 1;
+ $svc_x->$_(@_);
+ } else {
+ warn " ($svc_x unlinked)"
+ if $DEBUG > 1;
+ $seen_unlinked++ ? '' : '(unlinked)';
+ }
+ } @cust_fields;
+}
+
+###
# begin JSRPC code...
+###
package FS::UI::Web::JSRPC;
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index b9a99c900..d9e04de53 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -11,8 +11,9 @@ use String::ShellQuote;
use HTML::Entities;
use Locale::Country;
use FS::UID qw( datasrc );
-use FS::Record qw( qsearch qsearchs );
use FS::Misc qw( send_email send_fax );
+use FS::Record qw( qsearch qsearchs );
+use FS::cust_main_Mixin;
use FS::cust_main;
use FS::cust_bill_pkg;
use FS::cust_credit;
@@ -25,7 +26,7 @@ use FS::part_pkg;
use FS::cust_bill_pay;
use FS::part_bill_event;
-@ISA = qw( FS::Record );
+@ISA = qw( FS::cust_main_Mixin FS::Record );
$DEBUG = 0;
@@ -105,6 +106,13 @@ Invoices are normally created by calling the bill method of a customer object
sub table { 'cust_bill'; }
+sub cust_linked { $_[0]->cust_main_custnum; }
+sub cust_unlinked_msg {
+ my $self = shift;
+ "WARNING: can't find cust_main.custnum ". $self->custnum.
+ ' (cust_bill.invnum '. $self->invnum. ')';
+}
+
=item insert
Adds this invoice to the database ("Posts" the invoice). If there is an error,
diff --git a/FS/FS/cust_bill_event.pm b/FS/FS/cust_bill_event.pm
index 7b981391e..128e5a53d 100644
--- a/FS/FS/cust_bill_event.pm
+++ b/FS/FS/cust_bill_event.pm
@@ -3,10 +3,11 @@ package FS::cust_bill_event;
use strict;
use vars qw( @ISA $DEBUG );
use FS::Record qw( qsearch qsearchs );
+use FS::cust_main_Mixin;
use FS::cust_bill;
use FS::part_bill_event;
-@ISA = qw(FS::Record);
+@ISA = qw(FS::cust_main_Mixin FS::Record);
$DEBUG = 0;
@@ -70,6 +71,13 @@ points to. You can ask the object for a copy with the I<hash> method.
sub table { 'cust_bill_event'; }
+sub cust_linked { $_[0]->cust_main_custnum; }
+sub cust_unlinked_msg {
+ my $self = shift;
+ "WARNING: can't find cust_main.custnum ". $self->custnum.
+ ' (cust_bill.invnum '. $self->invnum. ')';
+}
+
=item insert
Adds this record to the database. If there is an error, returns the error,
diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm
index 026b92e84..9cc92d2e8 100644
--- a/FS/FS/cust_credit.pm
+++ b/FS/FS/cust_credit.pm
@@ -4,13 +4,14 @@ use strict;
use vars qw( @ISA $conf $unsuspendauto );
use Date::Format;
use FS::UID qw( dbh getotaker );
-use FS::Record qw( qsearch qsearchs );
use FS::Misc qw(send_email);
+use FS::Record qw( qsearch qsearchs );
+use FS::cust_main_Mixin;
use FS::cust_main;
use FS::cust_refund;
use FS::cust_credit_bill;
-@ISA = qw( FS::Record );
+@ISA = qw( FS::cust_main_Mixin FS::Record );
#ask FS::UID to run this stuff for us later
$FS::UID::callback{'FS::cust_credit'} = sub {
@@ -75,6 +76,12 @@ Creates a new credit. To add the credit to the database, see L<"insert">.
=cut
sub table { 'cust_credit'; }
+sub cust_linked { $_[0]->cust_main_custnum; }
+sub cust_unlinked_msg {
+ my $self = shift;
+ "WARNING: can't find cust_main.custnum ". $self->custnum.
+ ' (cust_credit.crednum '. $self->crednum. ')';
+}
=item insert
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 1bbf191ec..ab2c74a50 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -3160,11 +3160,53 @@ Returns a name string for this customer, either "Company (Last, First)" or
sub name {
my $self = shift;
- my $name = $self->get('last'). ', '. $self->first;
+ my $name = $self->bill_contact;
$name = $self->company. " ($name)" if $self->company;
$name;
}
+=item ship_name
+
+Returns a name string for this (service/shipping) contact, either
+"Company (Last, First)" or "Last, First".
+
+=cut
+
+sub ship_name {
+ my $self = shift;
+ if ( $self->get('ship_last') ) {
+ my $name = $self->ship_contact;
+ $name = $self->ship_company. " ($name)" if $self->ship_company;
+ $name;
+ } else {
+ $self->name;
+ }
+}
+
+=item contact
+
+Returns this customer's full (billing) contact name only, "Last, First"
+
+=cut
+
+sub contact {
+ my $self = shift;
+ $self->get('last'). ', '. $self->first;
+}
+
+=item ship_contact
+
+Returns this customer's full (shipping) contact name only, "Last, First"
+
+=cut
+
+sub ship_contact {
+ my $self = shift;
+ $self->get('ship_last')
+ ? $self->get('ship_last'). ', '. $self->ship_first
+ : $self->bill_contact;
+}
+
=item status
Returns a status string for this customer, currently:
diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm
new file mode 100644
index 000000000..a114c5a8a
--- /dev/null
+++ b/FS/FS/cust_main_Mixin.pm
@@ -0,0 +1,103 @@
+package FS::cust_main_Mixin;
+
+use strict;
+use FS::cust_main;
+
+=head1 NAME
+
+FS::cust_main_Mixin - Mixin class for records that contain fields from cust_main
+
+=head1 SYNOPSIS
+
+package FS::some_table;
+use vars qw(@ISA);
+@ISA = qw( FS::cust_main_Mixin FS::Record );
+
+=head1 DESCRIPTION
+
+This is a mixin class for records that contain fields from the cust_main table,
+for example, from a JOINed search. See httemplate/search/ for examples.
+
+=head1 METHODS
+
+=over 4
+
+=item name
+
+Given an object that contains fields from cust_main (say, from a JOINed
+search; see httemplate/search/ for examples), returns the equivalent of the
+FS::cust_main I<name> method, or "(unlinked)" if this object is not linked to
+a customer.
+
+=cut
+
+sub cust_unlinked_msg { '(unlinked)'; }
+sub cust_linked { $_[0]->custnum; }
+
+sub name {
+ my $self = shift;
+ $self->cust_linked
+ ? FS::cust_main::name($self)
+ : $self->cust_unlinked_msg;
+}
+
+=item ship_name
+
+Given an object that contains fields from cust_main (say, from a JOINed
+search; see httemplate/search/ for examples), returns the equivalent of the
+FS::cust_main I<ship_name> method, or "(unlinked)" if this object is not
+linked to a customer.
+
+=cut
+
+sub ship_name {
+ my $self = shift;
+ $self->cust_linked
+ ? FS::cust_main::ship_name($self)
+ : $self->cust_unlinked_msg;
+}
+
+=item contact
+
+Given an object that contains fields from cust_main (say, from a JOINed
+search; see httemplate/search/ for examples), returns the equivalent of the
+FS::cust_main I<contact> method, or "(unlinked)" if this object is not linked
+to a customer.
+
+=cut
+
+sub contact {
+ my $self = shift;
+ $self->cust_linked
+ ? FS::cust_main::contact($self)
+ : $self->cust_unlinked_msg;
+}
+
+=item ship_contact
+
+Given an object that contains fields from cust_main (say, from a JOINed
+search; see httemplate/search/ for examples), returns the equivalent of the
+FS::cust_main I<ship_contact> method, or "(unlinked)" if this object is not
+linked to a customer.
+
+=cut
+
+sub ship_contact {
+ my $self = shift;
+ $self->cust_linked
+ ? FS::cust_main::ship_contact($self)
+ : $self->cust_unlinked_msg;
+}
+
+=back
+
+=head1 BUGS
+
+=head1 SEE ALSO
+
+L<FS::cust_main>, L<FS::Record>
+
+=cut
+
+1;
+
diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index ccf991dc1..0f872a4d2 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -5,15 +5,16 @@ use vars qw( @ISA $conf $unsuspendauto $ignore_noapply );
use Date::Format;
use Business::CreditCard;
use Text::Template;
-use FS::Record qw( dbh qsearch qsearchs );
use FS::Misc qw(send_email);
+use FS::Record qw( dbh qsearch qsearchs );
+use FS::cust_main_Mixin;
use FS::cust_bill;
use FS::cust_bill_pay;
use FS::cust_pay_refund;
use FS::cust_main;
use FS::cust_pay_void;
-@ISA = qw( FS::Record );
+@ISA = qw( FS::cust_main_Mixin FS::Record );
$ignore_noapply = 0;
@@ -81,6 +82,12 @@ Creates a new payment. To add the payment to the databse, see L<"insert">.
=cut
sub table { 'cust_pay'; }
+sub cust_linked { $_[0]->cust_main_custnum; }
+sub cust_unlinked_msg {
+ my $self = shift;
+ "WARNING: can't find cust_main.custnum ". $self->custnum.
+ ' (cust_pay.paynum '. $self->paynum. ')';
+}
=item insert
diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm
index 80d5e21a6..205c33078 100644
--- a/FS/FS/svc_Common.pm
+++ b/FS/FS/svc_Common.pm
@@ -3,15 +3,16 @@ package FS::svc_Common;
use strict;
use vars qw( @ISA $noexport_hack $DEBUG );
use FS::Record qw( qsearch qsearchs fields dbh );
+use FS::cust_main_Mixin;
use FS::cust_svc;
use FS::part_svc;
use FS::queue;
use FS::cust_main;
-@ISA = qw( FS::Record );
+@ISA = qw( FS::cust_main_Mixin FS::Record );
-$DEBUG = 0;
-#$DEBUG = 1;
+#$DEBUG = 0;
+$DEBUG = 1;
=head1 NAME
@@ -547,20 +548,6 @@ sub clone_kludge_unsuspend {
shift;
}
-=item cust_name
-
-Given a svc_ object that contains fields from cust_main (say, from a
-JOINed search. See httemplate/search/svc_* for examples), returns the
-equivalent of "$svc_x->cust_svc->cust_pkg->name" (but much more efficient),
-or "(unlinked)" if this service is not linked to a customer.
-
-=cut
-
-sub cust_name {
- my $svc_x = shift;
- $svc_x->custnum ? FS::cust_main::name($svc_x) : '(unlinked)';
-}
-
=back
=head1 BUGS
diff --git a/FS/MANIFEST b/FS/MANIFEST
index 971fe403e..fa2cef097 100644
--- a/FS/MANIFEST
+++ b/FS/MANIFEST
@@ -52,6 +52,7 @@ FS/cust_bill_pkg_detail.pm
FS/cust_credit.pm
FS/cust_credit_bill.pm
FS/cust_main.pm
+FS/cust_main_Mixin.pm
FS/cust_main_county.pm
FS/cust_main_invoice.pm
FS/cust_pay.pm
@@ -177,6 +178,7 @@ t/cust_credit.t
t/cust_credit_bill.t
t/cust_credit_refund.t
t/cust_main.t
+t/cust_main_Mixin.t
t/cust_main_county.t
t/cust_main_invoice.t
t/cust_pay.t
diff --git a/FS/t/cust_main_Mixin.t b/FS/t/cust_main_Mixin.t
new file mode 100644
index 000000000..c8b929117
--- /dev/null
+++ b/FS/t/cust_main_Mixin.t
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::cust_main_Mixin;
+$loaded=1;
+print "ok 1\n";