datatype date fixed
This commit is contained in:
@@ -553,7 +553,8 @@ public function process(Import $import, ?Authenticatable $user = null): array
|
||||
$payload = [
|
||||
'account_id' => $accountIdForPayment,
|
||||
'reference' => $p['reference'] ?? null,
|
||||
'paid_at' => $p['payment_date'] ?? ($p['paid_at'] ?? null),
|
||||
// Normalize payment date to ISO (Y-m-d) to avoid DB parse errors
|
||||
'paid_at' => \App\Services\DateNormalizer::toDate((string) (($p['payment_date'] ?? ($p['paid_at'] ?? '')))),
|
||||
'currency' => $p['currency'] ?? 'EUR',
|
||||
'created_by' => $user?->getAuthIdentifier(),
|
||||
];
|
||||
@@ -1742,31 +1743,8 @@ private function sanitizeHeaderName(string $v): string
|
||||
*/
|
||||
private function normalizeDate(?string $raw): ?string
|
||||
{
|
||||
if ($raw === null) {
|
||||
return null;
|
||||
}
|
||||
$raw = trim($raw);
|
||||
if ($raw === '') {
|
||||
return null;
|
||||
}
|
||||
$candidates = ['d.m.Y', 'd.m.y', 'd/m/Y', 'd/m/y', 'Y-m-d'];
|
||||
foreach ($candidates as $fmt) {
|
||||
$dt = \DateTime::createFromFormat($fmt, $raw);
|
||||
if ($dt instanceof \DateTime) {
|
||||
// Reject invalid (createFromFormat returns false on mismatch; partial matches handled by checking errors)
|
||||
$errors = \DateTime::getLastErrors();
|
||||
if (($errors['warning_count'] ?? 0) === 0 && ($errors['error_count'] ?? 0) === 0) {
|
||||
return $dt->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fallback: strtotime (very permissive); if fails return null
|
||||
$ts = @strtotime($raw);
|
||||
if ($ts === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return date('Y-m-d', $ts);
|
||||
// Delegate to shared normalizer for consistency across the app
|
||||
return \App\Services\DateNormalizer::toDate($raw);
|
||||
}
|
||||
|
||||
private function findSourceColumnFor($mappings, string $targetField): ?string
|
||||
|
||||
Reference in New Issue
Block a user