This commit was generated by cvs2svn to compensate for changes in r4407,
[freeside.git] / FS / FS / h_cust_svc.pm
1 package FS::h_cust_svc;
2
3 use strict;
4 use vars qw( @ISA $DEBUG );
5 use Carp;
6 use FS::Record qw(qsearchs);
7 use FS::h_Common;
8 use FS::cust_svc;
9
10 @ISA = qw( FS::h_Common FS::cust_svc );
11
12 $DEBUG = 0;
13
14 sub table { 'h_cust_svc'; }
15
16 =head1 NAME
17
18 FS::h_cust_svc - Object method for h_cust_svc objects
19
20 =head1 SYNOPSIS
21
22 =head1 DESCRIPTION
23
24 An FS::h_cust_svc object  represents a historical service.  FS::h_cust_svc
25 inherits from FS::h_Common and FS::cust_svc.
26
27 =head1 METHODS
28
29 =over 4
30
31 =item label END_TIMESTAMP [ START_TIMESTAMP ] 
32
33 Returns a list consisting of:
34 - The name of this historical service (from part_svc)
35 - A meaningful identifier (username, domain, or mail alias)
36 - The table name (i.e. svc_domain) for this historical service
37
38 =cut
39
40 sub label {
41   my $self = shift;
42   carp "FS::h_cust_svc::label called on $self" if $DEBUG;
43   my $svc_x = $self->h_svc_x(@_);
44   my $part_svc = $self->part_svc;
45
46   unless ($svc_x) {
47     carp "can't find h_". $self->part_svc->svcdb. '.svcnum '. $self->svcnum if $DEBUG;
48     return $part_svc->svc, 'n/a', $part_svc->svcdb;
49   }
50
51   my @label;
52   eval { @label = $self->_svc_label($svc_x, @_); };
53
54   if ($@) {
55     carp 'while resolving history record for svcdb/svcnum ' . 
56          $part_svc->svcdb . '/' . $self->svcnum . ': ' . $@ if $DEBUG;
57     return $part_svc->svc, 'n/a', $part_svc->svcdb;
58   } else {
59     return @label;
60   }
61
62 }
63
64 =item h_svc_x END_TIMESTAMP [ START_TIMESTAMP ] 
65
66 Returns the FS::h_svc_XXX object for this service as of END_TIMESTAMP (i.e. an
67 FS::h_svc_acct object or FS::h_svc_domain object, etc.) and (optionally) not
68 cancelled before START_TIMESTAMP.
69
70 =cut
71
72 #false laziness w/cust_pkg::h_cust_svc
73 sub h_svc_x {
74   my $self = shift;
75   my $svcdb = $self->part_svc->svcdb;
76
77   warn "requiring FS/h_$svcdb.pm" if $DEBUG;
78   require "FS/h_$svcdb.pm";
79   my $svc_x = qsearchs(
80     "h_$svcdb",
81     { 'svcnum' => $self->svcnum, },
82     "FS::h_$svcdb"->sql_h_searchs(@_),
83   ) || $self->SUPER::svc_x;
84
85   if ($svc_x) {
86     carp "Using $svcdb in place of missing h_${svcdb} record."
87       if ($svc_x->isa('FS::' . $svcdb) and $DEBUG);
88     return $svc_x;
89   } else {
90     return '';
91   }
92
93 }
94
95 =back
96
97 =head1 BUGS
98
99 =head1 SEE ALSO
100
101 L<FS::h_Common>, L<FS::cust_svc>, L<FS::Record>, schema.html from the base
102 documentation.
103
104 =cut
105
106 1;
107