per-agent disable_previous_balance, #15863
[freeside.git] / FS / FS / cust_tag.pm
1 package FS::cust_tag;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearchs );
6 use FS::cust_main;
7 use FS::part_tag;
8
9 =head1 NAME
10
11 FS::cust_tag - Object methods for cust_tag records
12
13 =head1 SYNOPSIS
14
15   use FS::cust_tag;
16
17   $record = new FS::cust_tag \%hash;
18   $record = new FS::cust_tag { 'column' => 'value' };
19
20   $error = $record->insert;
21
22   $error = $new_record->replace($old_record);
23
24   $error = $record->delete;
25
26   $error = $record->check;
27
28 =head1 DESCRIPTION
29
30 An FS::cust_tag object represents a customer tag.  FS::cust_tag inherits from
31 FS::Record.  The following fields are currently supported:
32
33 =over 4
34
35 =item custtagnum
36
37 primary key
38
39 =item custnum
40
41 custnum
42
43 =item tagnum
44
45 tagnum
46
47
48 =back
49
50 =head1 METHODS
51
52 =over 4
53
54 =item new HASHREF
55
56 Creates a new customer tag.  To add the tag to the database, see L<"insert">.
57
58 Note that this stores the hash reference, not a distinct copy of the hash it
59 points to.  You can ask the object for a copy with the I<hash> method.
60
61 =cut
62
63 # the new method can be inherited from FS::Record, if a table method is defined
64
65 sub table { 'cust_tag'; }
66
67 =item insert
68
69 Adds this record to the database.  If there is an error, returns the error,
70 otherwise returns false.
71
72 =cut
73
74 # the insert method can be inherited from FS::Record
75
76 =item delete
77
78 Delete this record from the database.
79
80 =cut
81
82 # the delete method can be inherited from FS::Record
83
84 =item replace OLD_RECORD
85
86 Replaces the OLD_RECORD with this one in the database.  If there is an error,
87 returns the error, otherwise returns false.
88
89 =cut
90
91 # the replace method can be inherited from FS::Record
92
93 =item check
94
95 Checks all fields to make sure this is a valid customer tag.  If there is
96 an error, returns the error, otherwise returns false.  Called by the insert
97 and replace methods.
98
99 =cut
100
101 # the check method should currently be supplied - FS::Record contains some
102 # data checking routines
103
104 sub check {
105   my $self = shift;
106
107   my $error = 
108     $self->ut_numbern('custtagnum')
109     || $self->ut_foreign_key('custnum', 'cust_main', 'custnum')
110     || $self->ut_foreign_key('tagnum',  'part_tag',  'tagnum' )
111   ;
112   return $error if $error;
113
114   $self->SUPER::check;
115 }
116
117 =item cust_main
118
119 =cut
120
121 sub cust_main {
122   my $self = shift;
123   qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
124 }
125
126 =item part_tag
127
128 =cut
129
130 sub part_tag {
131   my $self = shift;
132   qsearchs( 'part_tag', { 'tagnum' => $self->tagnum } );
133 }
134
135
136 =back
137
138 =head1 BUGS
139
140 =head1 SEE ALSO
141
142 L<FS::Record>, schema.html from the base documentation.
143
144 =cut
145
146 1;
147