show credit balance on invoices, #11564
[freeside.git] / FS / FS / areacode.pm
1 package FS::areacode;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6
7 =head1 NAME
8
9 FS::areacode - Object methods for areacode records
10
11 =head1 SYNOPSIS
12
13   use FS::areacode;
14
15   $record = new FS::areacode \%hash;
16   $record = new FS::areacode { 'column' => 'value' };
17
18   $error = $record->insert;
19
20   $error = $new_record->replace($old_record);
21
22   $error = $record->delete;
23
24   $error = $record->check;
25
26 =head1 DESCRIPTION
27
28 An FS::areacode object represents an example.  FS::areacode inherits from
29 FS::Record.  The following fields are currently supported:
30
31 =over 4
32
33 =item code 
34
35 area code (primary key)
36
37 =item country
38
39 two-letter country code
40
41 =item state
42
43 two-letter state code, if appropriate
44
45 =item description
46
47 description (optional)
48
49
50 =back
51
52 =head1 METHODS
53
54 =over 4
55
56 =cut
57
58 sub table { 'areacode'; }
59
60 =item insert
61
62 Adds this record to the database.  If there is an error, returns the error,
63 otherwise returns false.
64
65 =cut
66
67 =item delete
68
69 Delete this record from the database.
70
71 =cut
72
73 =item replace OLD_RECORD
74
75 Replaces the OLD_RECORD with this one in the database.  If there is an error,
76 returns the error, otherwise returns false.
77
78 =cut
79
80 =item check
81
82 Checks all fields to make sure this is a valid example.  If there is
83 an error, returns the error, otherwise returns false.  Called by the insert
84 and replace methods.
85
86 =cut
87
88 # the check method should currently be supplied - FS::Record contains some
89 # data checking routines
90
91 sub check {
92   my $self = shift;
93
94   my $error = 
95     $self->ut_number('code')
96     || $self->ut_text('country')
97     || $self->ut_textn('state')
98     || $self->ut_textn('description')
99   ;
100   return $error if $error;
101
102   $self->SUPER::check;
103 }
104
105 =back
106
107 =head1 CLASS METHODS
108
109 locate CODE
110
111 Returns the country, state, and description for an area code.
112
113 =cut
114
115 sub locate {
116   my $class = shift;
117   my $code = shift;
118   my $areacode = qsearchs('areacode', { code => $code })
119     or return ();
120   return ($areacode->country, $areacode->state, $areacode->description);
121 }
122
123 =head1 SEE ALSO
124
125 L<FS::Record>, schema.html from the base documentation.
126
127 =cut
128
129 1;
130