use Rose::Object::MakeMethods::Generic
(
scalar => [ qw(type profile file all_profiles all_charsets sep_char all_sep_chars quote_char all_quote_chars escape_char all_escape_chars all_buchungsgruppen
- import_status errors headers raw_data_headers data num_imported num_importable displayable_columns) ],
+ import_status errors headers raw_data_headers info_headers data num_imported num_importable displayable_columns) ],
);
__PACKAGE__->run_before('check_auth');
use List::MoreUtils qw(pairwise);
use SL::Helper::Csv;
+use SL::DB::Customer;
use SL::DB::Language;
use SL::DB::PaymentTerm;
+use SL::DB::Vendor;
use parent qw(Rose::Object);
use Rose::Object::MakeMethods::Generic
(
scalar => [ qw(controller file csv) ],
- 'scalar --get_set_init' => [ qw(profile displayable_columns existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by) ],
+ 'scalar --get_set_init' => [ qw(profile displayable_columns existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by all_vc vc_by) ],
);
sub run {
$headers->{used} = { map { ($_ => 1) } @{ $headers->{headers} } };
$self->controller->headers($headers);
$self->controller->raw_data_headers({ used => { }, headers => [ ] });
+ $self->controller->info_headers({ used => { }, headers => [ ] });
- # my @data;
- # foreach my $object ($self->csv->get_objects)
my @objects = $self->csv->get_objects;
my @raw_data = @{ $self->csv->get_data };
- $self->controller->data([ pairwise { { object => $a, raw_data => $b, errors => [], information => [] } } @objects, @raw_data ]);
- $::lxdebug->dump(0, "DATA", $self->controller->data);
+ $self->controller->data([ pairwise { { object => $a, raw_data => $b, errors => [], information => [], info_data => {} } } @objects, @raw_data ]);
$self->check_objects;
$self->check_duplicates if $self->controller->profile->get('duplicates', 'no_check') ne 'no_check';
}
}
+sub add_info_columns {
+ my ($self, @columns) = @_;
+
+ my $h = $self->controller->info_headers;
+
+ foreach my $column (grep { !$h->{used}->{ $_->{method} } } map { ref $_ eq 'HASH' ? $_ : { method => $_, header => $_ } } @columns) {
+ $h->{used}->{ $column->{method} } = 1;
+ push @{ $h->{methods} }, $column->{method};
+ push @{ $h->{headers} }, $column->{header};
+ }
+}
+
sub add_raw_data_columns {
my ($self, @columns) = @_;
return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_payment_terms } } ) } qw(id description) };
}
+sub init_all_vc {
+ my ($self) = @_;
+
+ return { customers => SL::DB::Manager::Customer->get_all,
+ vendors => SL::DB::Manager::Vendor->get_all };
+}
+
+sub init_vc_by {
+ my ($self) = @_;
+
+ my %by_id = map { ( $_->id => $_ ) } @{ $self->all_vc->{customers} }, @{ $self->all_vc->{vendors} };
+ my %by_number = ( customers => { map { ( $_->customernumber => $_ ) } @{ $self->all_vc->{customers} } },
+ vendors => { map { ( $_->vendornumber => $_ ) } @{ $self->all_vc->{vendors} } } );
+ my %by_name = ( customers => { map { ( $_->name => $_ ) } @{ $self->all_vc->{customers} } },
+ vendors => { map { ( $_->name => $_ ) } @{ $self->all_vc->{vendors} } } );
+
+ return { id => \%by_id,
+ number => \%by_number,
+ name => \%by_name, };
+}
+
+sub check_vc {
+ my ($self, $entry, $id_column) = @_;
+
+ if ($entry->{object}->$id_column) {
+ $entry->{object}->$id_column(undef) if !$self->vc_by->{id}->{ $entry->{object}->$id_column };
+ }
+
+ if (!$entry->{object}->$id_column) {
+ my $vc = $self->vc_by->{number}->{customers}->{ $entry->{raw_data}->{customernumber} }
+ || $self->vc_by->{number}->{vendors}->{ $entry->{raw_data}->{vendornumber} };
+ $entry->{object}->$id_column($vc->id) if $vc;
+ }
+
+ if (!$entry->{object}->$id_column) {
+ my $vc = $self->vc_by->{name}->{customers}->{ $entry->{raw_data}->{customer} }
+ || $self->vc_by->{name}->{vendors}->{ $entry->{raw_data}->{vendor} };
+ $entry->{object}->$id_column($vc->id) if $vc;
+ }
+
+ if ($entry->{object}->$id_column) {
+ $entry->{info_data}->{vc_name} = $self->vc_by->{id}->{ $entry->{object}->$id_column }->name;
+ } else {
+ push @{ $entry->{errors} }, $::locale->text('Error: Customer/vendor not found');
+ }
+}
+
sub handle_cvars {
my ($self, $entry) = @_;
use Rose::Object::MakeMethods::Generic
(
- scalar => [ qw(table) ],
- 'scalar --get_set_init' => [ qw(all_vc) ],
+ scalar => [ qw(table) ],
);
sub init_class {
$self->class('SL::DB::Contact');
}
-sub init_all_vc {
- my ($self) = @_;
-
- $self->all_vc({ customers => SL::DB::Manager::Customer->get_all(with_objects => [ 'contacts' ]),
- vendors => SL::DB::Manager::Vendor->get_all( with_objects => [ 'contacts' ]) });
-}
-
sub check_objects {
my ($self) = @_;
- my %by_id = map { ( $_->id => $_ ) } @{ $self->all_vc->{customers} }, @{ $self->all_vc->{vendors} };
- my %by_number = ( customers => { map { ( $_->customernumber => $_->id ) } @{ $self->all_vc->{customers} } },
- vendors => { map { ( $_->vendornumber => $_->id ) } @{ $self->all_vc->{vendors} } } );
- my %by_name = ( customers => { map { ( $_->name => $_->id ) } @{ $self->all_vc->{customers} } },
- vendors => { map { ( $_->name => $_->id ) } @{ $self->all_vc->{vendors} } } );
-
foreach my $entry (@{ $self->controller->data }) {
- my $object = $entry->{object};
- my $raw_data = $entry->{raw_data};
-
- my $name = $object->cp_name;
- $name =~ s/^\s+//;
- $name =~ s/\s+$//;
-
- if (!$name) {
- push @{ $entry->{errors} }, $::locale->text('Error: Name missing');
- next;
- }
+ $self->check_name($entry);
+ $self->check_vc($entry, 'cp_cv_id');
+ $self->check_gender($entry);
+ }
- if ($object->cp_cv_id) {
- $object->cp_cv_id(undef) if !$by_id{ $object->cp_cv_id };
- }
+ $self->add_info_columns({ header => $::locale->text('Customer/Vendor'), method => 'vc_name' });
+}
- if (!$object->cp_cv_id) {
- my $vc_id = $by_number{customers}->{ $raw_data->{customernumber} } || $by_number{vendors}->{ $raw_data->{vendornumber} };
- $object->cp_cv_id($vc_id) if $vc_id;
- }
+sub check_name {
+ my ($self, $entry) = @_;
- if (!$object->cp_cv_id) {
- my $vc_id = $by_name{customers}->{ $raw_data->{customer} } || $by_name{vendors}->{ $raw_data->{vendor} };
- $object->cp_cv_id($vc_id) if $vc_id;
- }
+ my $name = $entry->{object}->cp_name;
+ $name =~ s/^\s+//;
+ $name =~ s/\s+$//;
- if (!$object->cp_cv_id) {
- push @{ $entry->{errors} }, $::locale->text('Error: Customer/vendor not found');
- next;
- }
+ push @{ $entry->{errors} }, $::locale->text('Error: Name missing') unless $name;
+}
- $entry->{vc} = $by_id{ $object->cp_cv_id };
+sub check_gender {
+ my ($self, $entry) = @_;
- if (($object->cp_gender ne 'm') && ($object->cp_gender ne 'f')) {
- push @{ $entry->{errors} }, $::locale->text('Error: Gender (cp_gender) missing or invalid');
- next;
- }
- }
+ push @{ $entry->{errors} }, $::locale->text('Error: Gender (cp_gender) missing or invalid') if ($entry->{object}->cp_gender ne 'm') && ($entry->{object}->cp_gender ne 'f');
}
sub check_duplicates {
use Rose::Object::MakeMethods::Generic
(
- scalar => [ qw(table) ],
- 'scalar --get_set_init' => [ qw(all_vc) ],
+ scalar => [ qw(table) ],
);
sub init_class {
$self->class('SL::DB::Shipto');
}
-sub init_all_vc {
- my ($self) = @_;
-
- $self->all_vc({ customers => SL::DB::Manager::Customer->get_all,
- vendors => SL::DB::Manager::Vendor->get_all });
-}
-
sub check_objects {
my ($self) = @_;
- my %by_id = map { ( $_->id => $_ ) } @{ $self->all_vc->{customers} }, @{ $self->all_vc->{vendors} };
- my %by_number = ( customers => { map { ( $_->customernumber => $_->id ) } @{ $self->all_vc->{customers} } },
- vendors => { map { ( $_->vendornumber => $_->id ) } @{ $self->all_vc->{vendors} } } );
- my %by_name = ( customers => { map { ( $_->name => $_->id ) } @{ $self->all_vc->{customers} } },
- vendors => { map { ( $_->name => $_->id ) } @{ $self->all_vc->{vendors} } } );
-
foreach my $entry (@{ $self->controller->data }) {
- my $object = $entry->{object};
- my $raw_data = $entry->{raw_data};
-
- if ($object->trans_id) {
- $object->trans_id(undef) if !$by_id{ $object->trans_id };
- }
-
- if (!$object->trans_id) {
- my $vc_id = $by_number{customers}->{ $raw_data->{customernumber} } || $by_number{vendors}->{ $raw_data->{vendornumber} };
- $object->trans_id($vc_id) if $vc_id;
- }
-
- if (!$object->trans_id) {
- my $vc_id = $by_name{customers}->{ $raw_data->{customer} } || $by_name{vendors}->{ $raw_data->{vendor} };
- $object->trans_id($vc_id) if $vc_id;
- }
-
- if (!$object->trans_id) {
- push @{ $entry->{errors} }, $::locale->text('Error: Customer/vendor not found');
- next;
- }
-
- $object->module('CT');
-
- $entry->{vc} = $by_id{ $object->trans_id };
+ $self->check_vc($entry, 'trans_id');
+ $entry->{object}->module('CT');
}
+
+ $self->add_info_columns({ header => $::locale->text('Customer/Vendor'), method => 'vc_name' });
}
sub check_duplicates {
'Customer not on file!' => 'Kunde ist nicht in der Datenbank!',
'Customer saved!' => 'Kunde gespeichert!',
'Customer type' => 'Kundentyp',
+ 'Customer/Vendor' => 'Kunde/Lieferant',
'Customer/Vendor (database ID)' => 'Kunde/Lieferant (Datenbank-ID)',
'Customername' => 'Kundenname',
'Customernumberinit' => 'Kunden-/Lieferantennummernkreis',
<table>
<tr class="listheading">
+ [%- FOREACH column = SELF.info_headers.headers %]
+ <th>[%- HTML.escape(column) %]</th>
+ [%- END %]
[%- FOREACH column = SELF.headers.headers %]
<th>[%- HTML.escape(column) %]</th>
[%- END %]
[%- FOREACH row = SELF.data %]
<tr class="[% IF row.errors.size %]redrow[% ELSE %]listrow[% END %][% loop.count % 2 %]">
+ [%- FOREACH method = SELF.info_headers.methods %]
+ <td>[%- HTML.escape(row.info_data.$method) %]</td>
+ [%- END %]
[%- FOREACH method = SELF.headers.methods %]
<td>[%- HTML.escape(row.object.$method) %]</td>
[%- END %]