update
This commit is contained in:
@@ -128,6 +128,12 @@ class FakturowniaInvoiceImporter
|
||||
return 'skipped';
|
||||
|
||||
$clientMap = $this -> repo -> getClientMapping( $document['client_key'] );
|
||||
if ( !$clientMap && $document['legacy_client_key'] !== '' && $document['legacy_client_key'] !== $document['client_key'] )
|
||||
{
|
||||
// Backward compatibility for historical mappings saved as id:{client_id}.
|
||||
$clientMap = $this -> repo -> getClientMapping( $document['legacy_client_key'] );
|
||||
}
|
||||
|
||||
if ( !$clientMap )
|
||||
{
|
||||
$this -> repo -> queueUnmapped( 'client', $document['client_key'], $document['client_name'], [
|
||||
@@ -331,6 +337,7 @@ class FakturowniaInvoiceImporter
|
||||
'client_name' => $clientName,
|
||||
'client_tax_no' => $clientTaxNo,
|
||||
'client_key' => $this -> buildClientKey( $rawDocument, $clientName, $clientTaxNo ),
|
||||
'legacy_client_key' => $this -> buildLegacyClientKey( $rawDocument ),
|
||||
'positions' => $positions,
|
||||
'total_amount' => $this -> normalizeAmount( $totalAmount, $documentType )
|
||||
];
|
||||
@@ -379,14 +386,33 @@ class FakturowniaInvoiceImporter
|
||||
}
|
||||
|
||||
private function buildClientKey( $rawDocument, $clientName, $clientTaxNo )
|
||||
{
|
||||
$normalizedTaxNo = $this -> normalizeTaxNo( $clientTaxNo );
|
||||
if ( $normalizedTaxNo !== '' )
|
||||
return 'tax:' . $normalizedTaxNo;
|
||||
|
||||
$legacyClientKey = $this -> buildLegacyClientKey( $rawDocument );
|
||||
if ( $legacyClientKey !== '' )
|
||||
return $legacyClientKey;
|
||||
|
||||
return 'name:' . $this -> normalizeKeyValue( $clientName );
|
||||
}
|
||||
|
||||
private function buildLegacyClientKey( $rawDocument )
|
||||
{
|
||||
if ( isset( $rawDocument['client_id'] ) && (string)$rawDocument['client_id'] !== '' )
|
||||
return 'id:' . (string)$rawDocument['client_id'];
|
||||
|
||||
if ( $clientTaxNo !== '' )
|
||||
return 'tax:' . preg_replace( '/\s+/', '', $clientTaxNo );
|
||||
return '';
|
||||
}
|
||||
|
||||
return 'name:' . $this -> normalizeKeyValue( $clientName );
|
||||
private function normalizeTaxNo( $taxNo )
|
||||
{
|
||||
$normalizedTaxNo = preg_replace( '/\D+/', '', (string)$taxNo );
|
||||
if ( !is_string( $normalizedTaxNo ) || $normalizedTaxNo === '' )
|
||||
return '';
|
||||
|
||||
return $normalizedTaxNo;
|
||||
}
|
||||
|
||||
private function buildItemKey( $rawPosition, $name )
|
||||
|
||||
Reference in New Issue
Block a user