add skip_dcontext_suffix to skip CDRs with dcontext ending in a definable string...
[freeside.git] / FS / FS / svc_video.pm
1 package FS::svc_video;
2 use base qw( FS::MAC_Mixin FS::svc_Common );
3
4 use strict;
5 use Tie::IxHash;
6 #use FS::Record qw( qsearch qsearchs );
7
8 =head1 NAME
9
10 FS::svc_video - Object methods for svc_video records
11
12 =head1 SYNOPSIS
13
14   use FS::svc_video;
15
16   $record = new FS::svc_video \%hash;
17   $record = new FS::svc_video { 'column' => 'value' };
18
19   $error = $record->insert;
20
21   $error = $new_record->replace($old_record);
22
23   $error = $record->delete;
24
25   $error = $record->check;
26
27 =head1 DESCRIPTION
28
29 An FS::svc_video object represents an IPTV or video-on-demand service.
30 FS::svc_video inherits from FS::Record.  The following fields are currently
31 supported:
32
33 =over 4
34
35 =item svcnum
36
37 primary key
38
39 =item smartcard_num
40
41 smartcard_num
42
43 =item mac_addr
44
45 mac_addr
46
47 =back
48
49 =head1 METHODS
50
51 =over 4
52
53 =item new HASHREF
54
55 Creates a new record.  To add the record to the database, see L<"insert">.
56
57 Note that this stores the hash reference, not a distinct copy of the hash it
58 points to.  You can ask the object for a copy with the I<hash> method.
59
60 =cut
61
62 sub table { 'svc_video'; }
63
64 sub search_sql {
65   my( $class, $string ) = @_;
66   if ( $string =~ /^([A-F0-9]{12})$/i ) {
67     $class->search_sql_field('mac_addr', uc($string));
68   } elsif ( $string =~ /^(([A-F0-9]{2}:){5}([A-F0-9]{2}))$/i ) {
69     $string =~ s/://g;
70     $class->search_sql_field('mac_addr', uc($string) );
71   } elsif ( $string =~ /^(\d+)$/ ) {
72     $class->search_sql_field('smartcard_num', $1);
73   } else {
74     '1 = 0'; #false
75   }
76 }
77
78 sub table_info {
79   my %opts = ( 'type' => 'text', 
80                'disable_select' => 1,
81                'disable_inventory' => 1,
82              );
83
84   tie my %fields, 'Tie::IxHash',
85     'svcnum'         => { label => 'Service' },
86     'smartcard_num'  => { label     => 'Smartcard #',
87                           size      => 17,
88                           maxlength => 16,
89                           %opts,
90                         },
91     'mac_addr'       => { label          => 'MAC address',
92                           type           => 'input-mac_addr',
93                           value_callback => sub {
94                                              my $svc = shift;
95                                              $svc->mac_addr_formatted('U',':');
96                                             },
97                         },
98     'duration'       => { label     => 'Duration (days)',
99                           size      => 4,
100                           maxlength => 3,
101                           %opts,
102                         },
103   ;
104
105   {
106     'name'                => 'Video', # service',
107     #'name_plural'     => '', #optional,
108     #'longname_plural' => '', #optional
109     'fields'              => \%fields,
110     #'sorts'               => [ 'smartcard_num' ],
111     'display_weight'      => 57.5,
112     'cancel_weight'       => 70, #?  no deps, so
113   };
114
115 }
116
117 sub label {
118   my $self = shift;
119   my $label = $self->smartcard_num;
120   $label .= ', MAC:'. $self->mac_addr
121     if $self->mac_addr;
122   return $label;
123 }
124
125 =item insert
126
127 Adds this record to the database.  If there is an error, returns the error,
128 otherwise returns false.
129
130 =item delete
131
132 Delete this record from the database.
133
134 =item replace OLD_RECORD
135
136 Replaces the OLD_RECORD with this one in the database.  If there is an error,
137 returns the error, otherwise returns false.
138
139 =item check
140
141 Checks all fields to make sure this is a valid record.  If there is
142 an error, returns the error, otherwise returns false.  Called by the insert
143 and replace methods.
144
145 =cut
146
147 sub check {
148   my $self = shift;
149
150   my $error = 
151     $self->ut_numbern('svcnum')
152     || $self->ut_number('smartcard_num')
153     || $self->ut_mac_addr('mac_addr')
154     || $self->ut_number('duration')
155   ;
156   return $error if $error;
157
158   $self->SUPER::check;
159 }
160
161 =back
162
163 =head1 BUGS
164
165 =head1 SEE ALSO
166
167 L<FS::Record>
168
169 =cut
170
171 1;
172