Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d0809fbb

Von Moritz Bunkus vor etwa 4 Jahren hinzugefügt

  • ID d0809fbb46edd7741d69b3ee3375438e4c30d1e5
  • Vorgänger 82fa9647
  • Nachfolger c20ee3de

ZUGFeRD-Import: UStID-Nr auch finden, wenn sie nicht normalisiert sind

Sowohl die UStID-Nummern in der ZUGFeRD.xml als auch die Nummern der
Lieferanten in der Datenbank werden nun zum Vergleichen
normalisiert. Damit wird auch ein Lieferant gefunden, dessen UStID-Nr
in der Datenbank z.B. »DE 123 456 789« ist und in der XML
»DE123456789« steht.

Unterschiede anzeigen:

SL/Controller/ZUGFeRD.pm
5 5
use SL::DB::RecordTemplate;
6 6
use SL::Locale::String qw(t8);
7 7
use SL::Helper::DateTime;
8
use SL::VATIDNr;
8 9
use SL::ZUGFeRD;
9 10

  
10 11
use XML::LibXML;
......
40 41
  die t8("No VAT Info for this ZUGFeRD invoice," .
41 42
         " please ask your vendor to add this for his ZUGFeRD data.") unless $ustid;
42 43

  
43
  $ustid     =~ s/^\s+|\s+$//g;
44
  $ustid = SL::VATIDNr->normalize($ustid);
44 45

  
45 46
  # 1.1 check if we a have a vendor with this VAT-ID (vendor.ustid)
46 47
  my $vc     = $dom->findnodes('//ram:SellerTradeParty/ram:Name')->string_value;
47
  my $vendor = SL::DB::Manager::Vendor->find_by(ustid => $ustid);
48
  my $vendor = SL::DB::Manager::Vendor->find_by(
49
    ustid => $ustid,
50
    or    => [
51
      obsolete => undef,
52
      obsolete => 0,
53
    ]);
54

  
55
  if (!$vendor) {
56
    # 1.2 If no vendor with the exact VAT ID number is found, the
57
    # number might be stored slightly different in the database
58
    # (e.g. with spaces breaking up groups of numbers). Iterate over
59
    # all existing vendors with VAT ID numbers, normalize their
60
    # representation and compare those.
61

  
62
    my $vendors = SL::DB::Manager::Vendor->get_all(
63
      where => [
64
        '!ustid' => undef,
65
        '!ustid' => '',
66
        or       => [
67
          obsolete => undef,
68
          obsolete => 0,
69
        ],
70
      ]);
71

  
72
    foreach my $other_vendor (@{ $vendors }) {
73
      next unless SL::VATIDNr->normalize($other_vendor->ustid) eq $ustid;
74

  
75
      $vendor = $other_vendor;
76
      last;
77
    }
78
  }
79

  
48 80
  die t8("Please add a valid VAT-ID for this vendor: " . $vc) unless (ref $vendor eq 'SL::DB::Vendor');
49 81

  
50 82
  # 2. check if we have a ap record template for this vendor (TODO only the oldest template is choosen)

Auch abrufbar als: Unified diff