agent-virtualize credit card surcharge percentage, RT#72961
[freeside.git] / FS / FS / export_batch.pm
1 package FS::export_batch;
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 - Object methods for export_batch records
10
11 =head1 SYNOPSIS
12
13   use FS::export_batch;
14
15   $record = new FS::export_batch \%hash;
16   $record = new FS::export_batch { '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 object represents a batch of records being processed
29 by an export.  This mechanism allows exports to process multiple pending
30 service changes at the end of day or some other scheduled time, rather 
31 than doing everything in realtime or near-realtime (via the job queue).
32
33 FS::export_batch inherits from FS::Record.  The following fields are 
34 currently supported:
35
36 =over 4
37
38 =item batchnum
39
40 primary key
41
42 =item exportnum
43
44 The L<FS::part_export> object that created this batch.
45
46 =item _date
47
48 The time the batch was created.
49
50 =item status
51
52 A status string.  Allowed values are "open" (for a newly created batch that
53 can receive additional items), "closed" (for a batch that is no longer 
54 allowed to receive items but is still being processed), "done" (for a batch
55 that is finished processing), and "failed" (if there has been an error 
56 exporting the batch).
57
58 =item statustext
59
60 Free-text field for any status information from the remote machine or whatever
61 else the export is doing.  If status is "failed" this MUST contain a value.
62
63 =back
64
65 =head1 METHODS
66
67 =over 4
68
69 =item new HASHREF
70
71 Creates a new batch.  To add the example to the database, see L<"insert">.
72
73 Note that this stores the hash reference, not a distinct copy of the hash it
74 points to.  You can ask the object for a copy with the I<hash> method.
75
76 =cut
77
78 sub table { 'export_batch'; }
79
80 =item insert
81
82 Adds this record to the database.  If there is an error, returns the error,
83 otherwise returns false.
84
85 =item delete
86
87 Delete this record from the database.  Don't ever do this.
88
89 =item replace OLD_RECORD
90
91 Replaces the OLD_RECORD with this one in the database.  If there is an error,
92 returns the error, otherwise returns false.
93
94 =item check
95
96 Checks all fields to make sure this is a valid batch.  If there is
97 an error, returns the error, otherwise returns false.  Called by the insert
98 and replace methods.
99
100 =cut
101
102 sub check {
103   my $self = shift;
104
105   $self->set('status' => 'open') unless $self->get('status');
106   $self->set('_date' => time) unless $self->get('_date');
107
108   my $error = 
109     $self->ut_numbern('batchnum')
110     || $self->ut_number('exportnum')
111     || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum')
112     || $self->ut_number('_date')
113     || $self->ut_enum('status', [ qw(open closed done failed) ])
114     || $self->ut_textn('statustext')
115   ;
116   return $error if $error;
117
118   $self->SUPER::check;
119 }
120
121 =back
122
123 =head1 BUGS
124
125 =head1 SEE ALSO
126
127 L<FS::part_export>, L<FS::export_batch_item>
128
129 =cut
130
131 1;
132