76 |
76 |
return $profile;
|
77 |
77 |
}
|
78 |
78 |
|
|
79 |
sub init_existing_objects {
|
|
80 |
my ($self) = @_;
|
|
81 |
|
|
82 |
# only use objects of main class (the first one)
|
|
83 |
#eval "require " . $self->class->[0];
|
|
84 |
$self->existing_objects($self->manager_class->[0]->get_all);
|
|
85 |
}
|
|
86 |
|
|
87 |
sub get_duplicate_check_fields {
|
|
88 |
return {
|
|
89 |
vendor_and_invnumber => {
|
|
90 |
label => $::locale->text('Vendor and Invoice Number'),
|
|
91 |
default => 1,
|
|
92 |
std_check => 1,
|
|
93 |
maker => sub {
|
|
94 |
my ($object, $worker) = @_;
|
|
95 |
return if ref $object ne $worker->class->[0];
|
|
96 |
return '__' . $object->vendor_id . '__' . $object->invnumber . '__';
|
|
97 |
},
|
|
98 |
},
|
|
99 |
};
|
|
100 |
}
|
|
101 |
|
|
102 |
sub check_std_duplicates {
|
|
103 |
my $self = shift;
|
|
104 |
|
|
105 |
my $duplicates = {};
|
|
106 |
|
|
107 |
my $all_fields = $self->get_duplicate_check_fields();
|
|
108 |
|
|
109 |
foreach my $key (keys(%{ $all_fields })) {
|
|
110 |
if ( $self->controller->profile->get('duplicates_'. $key) && (!exists($all_fields->{$key}->{std_check}) || $all_fields->{$key}->{std_check} ) ) {
|
|
111 |
$duplicates->{$key} = {};
|
|
112 |
}
|
|
113 |
}
|
|
114 |
|
|
115 |
my @duplicates_keys = keys(%{ $duplicates });
|
|
116 |
|
|
117 |
if ( !scalar(@duplicates_keys) ) {
|
|
118 |
return;
|
|
119 |
}
|
|
120 |
|
|
121 |
if ( $self->controller->profile->get('duplicates') eq 'check_db' ) {
|
|
122 |
foreach my $object (@{ $self->existing_objects }) {
|
|
123 |
foreach my $key (@duplicates_keys) {
|
|
124 |
my $value = exists($all_fields->{$key}->{maker}) ? $all_fields->{$key}->{maker}->($object, $self) : $object->$key;
|
|
125 |
$duplicates->{$key}->{$value} = 'db';
|
|
126 |
}
|
|
127 |
}
|
|
128 |
}
|
|
129 |
|
|
130 |
# only check main class (the first one)
|
|
131 |
foreach my $entry (@{ $self->controller->data }) {
|
|
132 |
my $object = $entry->{object};
|
|
133 |
|
|
134 |
next if ref $object ne $self->class->[0];
|
|
135 |
next if scalar @{ $entry->{errors} };
|
|
136 |
|
|
137 |
foreach my $key (@duplicates_keys) {
|
|
138 |
my $value = exists($all_fields->{$key}->{maker}) ? $all_fields->{$key}->{maker}->($object, $self) : $object->$key;
|
|
139 |
|
|
140 |
if ( exists($duplicates->{$key}->{$value}) ) {
|
|
141 |
push(@{ $entry->{errors} }, $duplicates->{$key}->{$value} eq 'db' ? $::locale->text('Duplicate in database') : $::locale->text('Duplicate in CSV file'));
|
|
142 |
last;
|
|
143 |
} else {
|
|
144 |
$duplicates->{$key}->{$value} = 'csv';
|
|
145 |
}
|
|
146 |
}
|
|
147 |
}
|
|
148 |
}
|
79 |
149 |
|
80 |
150 |
sub setup_displayable_columns {
|
81 |
151 |
my ($self) = @_;
|
CSV-Import Kreditorenbuchungen: Dublettencheck