use FS::cust_tax_location;
use FS::part_pkg_taxrate;
use FS::cust_main;
+use FS::Misc qw( csv_from_fixed );
@ISA = qw( FS::Record );
|| $self->ut_textn('data_vendor')
|| $self->ut_textn('location')
|| $self->ut_foreign_key('taxclassnum', 'tax_class', 'taxclassnum')
- || $self->ut_numbern('effective_date')
+ || $self->ut_snumbern('effective_date')
|| $self->ut_float('tax')
|| $self->ut_floatn('excessrate')
|| $self->ut_money('taxbase')
my $taxable_units = 0;
unless ($self->recurtax =~ /^Y$/i) {
if ($self->unittype == 0) {
- $taxable_units += $_->units foreach @cust_bill_pkg;
+ my %seen = ();
+ foreach (@cust_bill_pkg) {
+ $taxable_units += $_->units
+ unless $seen{$_->pkgnum};
+ $seen{$_->pkgnum}++;
+ }
}elsif ($self->unittype == 1) {
return qq!fatal: can't (yet) handle fee with minute unit type!;
}elsif ($self->unittype == 2) {
my @fields;
my $hook;
+ my @column_lengths = ();
+ my @column_callbacks = ();
+ if ( $format eq 'cch-fixed' || $format eq 'cch-fixed-update' ) {
+ $format =~ s/-fixed//;
+ my $date_format = sub { my $r='';
+ /^(\d{4})(\d{2})(\d{2})$/ && ($r="$1/$2/$3");
+ $r;
+ };
+ $column_callbacks[8] = $date_format;
+ push @column_lengths, qw( 10 1 1 8 8 5 8 8 8 1 2 2 30 8 8 10 2 8 2 1 2 2 );
+ push @column_lengths, 1 if $format eq 'cch-update';
+ }
+
my $line;
my ( $count, $last, $min_sec ) = (0, time, 5); #progressbar
- if ( $job ) {
- $count++
- while ( defined($line=<$fh>) );
- seek $fh, 0, 0;
+ if ( $job || scalar(@column_callbacks) ) {
+ my $error =
+ csv_from_fixed(\$fh, \$count, \@column_lengths, \@column_callbacks);
+ return $error if $error;
}
$count *=2;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
+ my $hashref = $insert{$_};
+ $line = join(", ", map { "$_ => ". $hashref->{$_} } keys(%$hashref) );
return "can't insert tax_rate for $line: $error";
}
#join(" ", map { "$_ => ". $old->{$_} } @fields);
join(" ", map { "$_ => ". $old->{$_} } keys(%$old) );
}
- my $new = new FS::tax_rate( $insert{$_} );
+ my $new = new FS::tax_rate({ $old->hash, %{$insert{$_}}, 'manual' => '' });
$new->taxnum($old->taxnum);
my $error = $new->replace($old);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
- return "can't insert tax_rate for $line: $error";
+ my $hashref = $insert{$_};
+ $line = join(", ", map { "$_ => ". $hashref->{$_} } keys(%$hashref) );
+ return "can't replace tax_rate for $line: $error";
}
$imported++;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
- return "can't insert tax_rate for $line: $error";
+ my $hashref = $delete{$_};
+ $line = join(", ", map { "$_ => ". $hashref->{$_} } keys(%$hashref) );
+ return "can't delete tax_rate for $line: $error";
}
$imported++;
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
- return "Empty file!" unless $imported;
+ return "Empty file!" unless ($imported || $format eq 'cch-update');
''; #no error
=item process_batch
-Load an batch import as a queued JSRPC job
+Load a batch import as a queued JSRPC job
=cut
my (%files) = map { /^(\w+):([\.\w]+)$/ ? ($1,$2):() } split /,/, $files;
- if ($format eq 'cch') {
+ if ($format eq 'cch' || $format eq 'cch-fixed') {
my $oldAutoCommit = $FS::UID::AutoCommit;
local $FS::UID::AutoCommit = 0;
$error = "No $name supplied";
next;
}
- my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc;
+ my $dir = '%%%FREESIDE_CACHE%%%/cache.'. $FS::UID::datasrc;
my $filename = "$dir/". $files{$file};
open my $fh, "< $filename" or $error ||= "Can't open $name file: $!";
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
}
- }elsif ($format eq 'cch-update') {
+ }elsif ($format eq 'cch-update' || $format eq 'cch-fixed-update') {
my $oldAutoCommit = $FS::UID::AutoCommit;
local $FS::UID::AutoCommit = 0;
'PLUS4', 'plus4file', \&FS::cust_tax_location::batch_import,
'TXMATRIX', 'txmatrix', \&FS::part_pkg_taxrate::batch_import,
);
- my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc;
+ my $dir = '%%%FREESIDE_CACHE%%%/cache.'. $FS::UID::datasrc;
while( scalar(@list) ) {
my ($name, $file, $import_sub) = (shift @list, shift @list, shift @list);
unless ($files{$file}) {
unlink $file or warn "Can't delete $file: $!";
}
- $error = "No DETAIL supplied"
+ $error ||= "No DETAIL supplied"
unless ($files{detail});
open my $fh, "< $dir/". $files{detail}
or $error ||= "Can't open DETAIL file: $!";