Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1453173f

Von Bernd Bleßmann vor mehr als 1 Jahr hinzugefügt

  • ID 1453173f93fac9186b9374f245d37cdd732ed94e
  • Vorgänger ee33349b
  • Nachfolger 973e7b1e

CSV-Import Kreditorenbuchungen: Dublettencheck

Unterschiede anzeigen:

SL/Controller/CsvImport/APTransaction.pm
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) = @_;
locale/de/all
4537 4537
  'Vendor Order Number'         => 'Bestellnummer beim Lieferanten',
4538 4538
  'Vendor Part Number'          => 'Lieferantenartikelnummer',
4539 4539
  'Vendor Record Number'        => 'Lieferantenbelegsnummer',
4540
  'Vendor and Invoice Number'   => 'Lieferant und Rechnungsnummer',
4540 4541
  'Vendor deleted!'             => 'Lieferant gelöscht!',
4541 4542
  'Vendor details'              => 'Lieferantendetails',
4542 4543
  'Vendor missing!'             => 'Lieferant fehlt!',
locale/en/all
4535 4535
  'Vendor Order Number'         => '',
4536 4536
  'Vendor Part Number'          => '',
4537 4537
  'Vendor Record Number'        => '',
4538
  'Vendor and Invoice Number'   => '',
4538 4539
  'Vendor deleted!'             => '',
4539 4540
  'Vendor details'              => '',
4540 4541
  'Vendor missing!'             => '',

Auch abrufbar als: Unified diff