1 package FS::transaction867;
4 use vars qw( @ISA @EXPORT_OK );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::UID qw( getotaker dbh );
10 @ISA = qw(FS::Record);
11 @EXPORT_OK = qw(batch_867data_import);
15 FS::transaction867 - Object methods for transaction867 records
19 use FS::transaction867;
21 $record = new FS::transaction867 \%hash;
22 $record = new FS::transaction867 { 'column' => 'value' };
24 $error = $record->insert;
26 $error = $new_record->replace($old_record);
28 $error = $record->delete;
30 $error = $record->check;
34 An FS::transaction867 object represents an example. FS::transaction867 inherits from
35 FS::Record. The following fields are currently supported:
39 =item id - primary key
43 =item ref_identification -
47 =item trans_creation_date -
51 =item srvc_period_start_date -
53 =item srvc_period_end_date -
55 =item prev_read_kwatts -
57 =item curr_read_kwatts -
59 =item meter_multiplier -
63 =item measured_demand -
78 Creates a new example. To add the example to the database, see L<"insert">.
80 Note that this stores the hash reference, not a distinct copy of the hash it
81 points to. You can ask the object for a copy with the I<hash> method.
85 # the new method can be inherited from FS::Record, if a table method is defined
87 sub table { 'transaction867'; }
91 Adds this record to the database. If there is an error, returns the error,
92 otherwise returns false.
96 # the insert method can be inherited from FS::Record
100 Delete this record from the database.
104 # the delete method can be inherited from FS::Record
106 =item replace OLD_RECORD
108 Replaces the OLD_RECORD with this one in the database. If there is an error,
109 returns the error, otherwise returns false.
113 # the replace method can be inherited from FS::Record
117 Checks all fields to make sure this is a valid example. If there is
118 an error, returns the error, otherwise returns false. Called by the insert
123 # the check method should currently be supplied - FS::Record contains some
124 # data checking routines
130 $self->ut_numbern('id')
131 || $self->ut_number('tdsp_duns')
132 || $self->ut_text('ref_identification')
133 || $self->ut_text('esiid')
134 || $self->ut_number('trans_creation_date')
135 || $self->ut_text('meter_no')
136 || $self->ut_number('srvc_period_start_date')
137 || $self->ut_number('srvc_period_end_date')
138 || $self->ut_float('prev_read_kwatts')
139 || $self->ut_float('curr_read_kwatts')
140 || $self->ut_float('meter_multiplier')
141 || $self->ut_float('usage_kwatts')
142 || $self->ut_floatn('measured_demand')
143 || $self->ut_number('ack_997')
144 || $self->ut_number('processed')
146 return $error if $error;
154 =item batch_867data_import
157 Importing a CVS file with the following column:
158 867_usage esiid date meter srvc_from_date srvc_to_date previous_read_kwatts
159 current_read_kwatts mult usage_kwatts measure_demand 997_ack
163 #@EXPORT_OK=qw(batch_867data_import);
164 sub batch_867data_import {
166 my ($fh,$format) = @_;
168 # print "\n\n****************** the cvs file\n\n";
170 # print ("\n$format\n");
173 #my $fh = $param->{filehandle};
174 #my $format = $param->{'format'};
179 if ( $format eq 'extended' ) {
181 tdsp_duns ref_identification esiid trans_creation_date
182 meter_no srvc_period_start_date srvc_period_end_date
183 prev_read_kwatts curr_read_kwatts meter_multiplier
184 usage_kwatts measured_demand ack_997 processed
187 die "unknown format $format";
190 eval "use Text::CSV_XS;";
193 my $csv = new Text::CSV_XS;
200 local $SIG{HUP} = 'IGNORE';
201 local $SIG{INT} = 'IGNORE';
202 local $SIG{QUIT} = 'IGNORE';
203 local $SIG{TERM} = 'IGNORE';
204 local $SIG{TSTP} = 'IGNORE';
205 local $SIG{PIPE} = 'IGNORE';
207 my $oldAutoCommit = $FS::UID::AutoCommit;
208 local $FS::UID::AutoCommit = 0;
211 #while ( $columns = $csv->getline($fh) ) {
213 while ( defined($line=<$fh>) ) {
215 $csv->parse($line) or do {
216 $dbh->rollback if $oldAutoCommit;
217 return "can't parse: ". $csv->error_input();
220 my @columns = $csv->fields();
221 #warn join('-',@columns);
223 # this hash will hold each CVS line
224 my %transaction867_data;
227 # my %cust_pkg = ( pkgpart => $pkgpart );
229 foreach my $field ( @fields ) {
230 # -cal this section is ignored by the 867 import
231 $transaction867_data{$field} = shift @columns;
234 # make sure to set the 'ack_997' column
235 $transaction867_data{'ack_997'} = 0;
237 # make sure to set the 'processed' column
238 $transaction867_data{'processed'} = 0;
240 print Dumper(\%transaction867_data) if $debug;
242 ### Check to see if the invoice is already in transaction810 table
243 # if so then print a warning
245 my $ref_identification = $transaction867_data{'ref_identification'};
246 my $search_res = qsearchs ( 'transaction867',
247 {'ref_identification' => $ref_identification}
253 # place some code here to fix the problme of trying to insert
254 # data that have the same references identification number
257 print "OOps! a transaction with the same references identification"
258 ." number $ref_identification\n"
259 ."\tis in the transaction867 table already!!\n";
264 my $transaction867_obj = new FS::transaction867( \%transaction867_data );
265 $error = $transaction867_obj->insert;
267 $dbh->rollback if $oldAutoCommit;
268 return "can't bill customer for $line: $error";
277 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
279 return "Empty file!" unless $imported;
291 The author forgot to customize this manpage.
295 L<FS::Record>, schema.html from the base documentation.