eliminate some false laziness in FS::Misc::send_email vs. msg_template/email.pm send_...
[freeside.git] / FS / FS / export_batch_item.pm
1 package FS::export_batch_item;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6
7 =head1 NAME
8
9 FS::export_batch_item - Object methods for export_batch_item records
10
11 =head1 SYNOPSIS
12
13   use FS::export_batch_item;
14
15   $record = new FS::export_batch_item \%hash;
16   $record = new FS::export_batch_item { '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::export_batch_item object represents a service change (insert, delete,
29 replace, suspend, unsuspend, or relocate) queued for processing by a 
30 batch-oriented export.
31
32 FS::export_batch_item inherits from FS::Record.  The following fields are
33 currently supported:
34
35 =over 4
36
37 =item itemnum
38
39 primary key
40
41 =item batchnum
42
43 L<FS::export_batch> foreign key; the batch that this item belongs to.
44
45 =item svcnum
46
47 L<FS::cust_svc> foreign key; the service that is being exported.
48
49 =item action
50
51 One of 'insert', 'delete', 'replace', 'suspend', 'unsuspend', or 'relocate'.
52
53 =item data
54
55 A place for the export to store data relating to the service change.
56
57 =item frozen
58
59 A flag indicating that C<data> is a base64-Storable encoded object rather
60 than a simple string.
61
62 =head1 METHODS
63
64 =over 4
65
66 =item new HASHREF
67
68 Creates a new batch item.  To add the example to the database, see L<"insert">.
69
70 Note that this stores the hash reference, not a distinct copy of the hash it
71 points to.  You can ask the object for a copy with the I<hash> method.
72
73 =cut
74
75 sub table { 'export_batch_item'; }
76
77 =item insert
78
79 Adds this record to the database.  If there is an error, returns the error,
80 otherwise returns false.
81
82 =item delete
83
84 Delete this record from the database.
85
86 =item replace OLD_RECORD
87
88 Replaces the OLD_RECORD with this one in the database.  If there is an error,
89 returns the error, otherwise returns false.
90
91 =item check
92
93 Checks all fields to make sure this is a valid example.  If there is
94 an error, returns the error, otherwise returns false.  Called by the insert
95 and replace methods.
96
97 =cut
98
99 sub check {
100   my $self = shift;
101
102   my $error = 
103     $self->ut_numbern('itemnum')
104     || $self->ut_number('batchnum')
105     || $self->ut_foreign_key('batchnum', 'export_batch', 'batchnum')
106     || $self->ut_number('svcnum')
107     || $self->ut_enum('action',
108       [ qw(insert delete replace suspend unsuspend relocate) ]
109     )
110     || $self->ut_anything('data')
111     || $self->ut_flag('frozen')
112   ;
113   return $error if $error;
114
115   $self->SUPER::check;
116 }
117
118 =back
119
120 =head1 BUGS
121
122 =head1 SEE ALSO
123
124 L<FS::export_batch>, L<FS::cust_svc>
125
126 =cut
127
128 1;
129