$c->profile($self->profile);
$c->type($job->data_as_hash->{type});
+ $c->{employee_id} = $job->data_as_hash->{employee_id};
my $test = $job->data_as_hash->{test};
}
$self->{background_job} = SL::BackgroundJob::CsvImport->create_job(
- file => $self->csv_file_name,
- profile => $self->profile,
- type => $self->profile->type,
- test => $params{test},
+ file => $self->csv_file_name,
+ profile => $self->profile,
+ type => $self->profile->type,
+ test => $params{test},
+ employee_id => SL::DB::Manager::Employee->current->id,
)->save;
if ($self->task_server->is_running) {
use strict;
-use List::MoreUtils qw(pairwise);
+use List::MoreUtils qw(pairwise any);
use SL::Helper::Csv;
use SL::DB::Currency;
use SL::DB::PaymentTerm;
use SL::DB::Vendor;
use SL::DB::Contact;
+use SL::DB::History;
use parent qw(Rose::Object);
if ( !$object->save(cascade => !!$self->save_with_cascade()) ) {
push @{ $entry->{errors} }, $::locale->text('Error when saving: #1', $entry->{object}->db->error);
} else {
+ $self->_save_history($object);
$self->controller->num_imported($self->controller->num_imported + 1);
}
} continue {
return @cleaned_fields;
}
+sub _save_history {
+ my ($self, $object) = @_;
+
+ if (any { $_ eq $self->controller->{type} } qw(parts customers_vendors)) {
+ my $snumbers = $self->controller->{type} eq 'parts' ? 'partnumber_' . $object->partnumber
+ : $self->controller->{type} eq 'customers_vendors' ?
+ ($self->table eq 'customer' ? 'customernumber_' . $object->customernumber : 'vendornumber_' . $object->vendornumber)
+ : '';
+
+ SL::DB::History->new(
+ trans_id => $object->id,
+ snumbers => $snumbers,
+ employee_id => $self->controller->{employee_id},
+ addition => 'SAVED',
+ )->save();
+ }
+}
+
1;