added option to import payments from csv file
This commit is contained in:
@@ -77,7 +77,13 @@ public function suggest(Request $request)
|
||||
if (! is_array($cols)) {
|
||||
$cols = [];
|
||||
}
|
||||
$entities = ImportEntity::all();
|
||||
// Optional filter: only suggest for specific entity keys (e.g., template meta.entities)
|
||||
$only = $request->input('only_entities');
|
||||
$query = ImportEntity::query()->orderByRaw("(ui->>'order')::int nulls last");
|
||||
if (is_array($only) && ! empty($only)) {
|
||||
$query->whereIn('key', array_values(array_filter($only, fn ($v) => is_string($v) && $v !== '')));
|
||||
}
|
||||
$entities = $query->get();
|
||||
$suggestions = [];
|
||||
foreach ($cols as $col) {
|
||||
$s = $this->suggestFor($col, $entities);
|
||||
@@ -92,6 +98,8 @@ public function suggest(Request $request)
|
||||
private function suggestFor(string $source, $entities): ?array
|
||||
{
|
||||
$s = trim(mb_strtolower($source));
|
||||
$best = null;
|
||||
$bestRank = PHP_INT_MAX;
|
||||
foreach ($entities as $ent) {
|
||||
$rules = (array) ($ent->rules ?? []);
|
||||
foreach ($rules as $rule) {
|
||||
@@ -101,15 +109,27 @@ private function suggestFor(string $source, $entities): ?array
|
||||
continue;
|
||||
}
|
||||
if (@preg_match($pattern, $s)) {
|
||||
return [
|
||||
'entity' => $ent->key, // UI key (plural except person)
|
||||
'field' => $field,
|
||||
'canonical_root' => $ent->canonical_root,
|
||||
];
|
||||
// Rank preferences: payments over address for amount/date-like terms
|
||||
$rank = (int) ($ent->ui['order'] ?? 999);
|
||||
$isPayment = ($ent->canonical_root ?? null) === 'payment';
|
||||
$isAddress = ($ent->canonical_root ?? null) === 'address';
|
||||
if ($isPayment) {
|
||||
$rank -= 10; // boost payments
|
||||
} elseif ($isAddress && in_array($field, ['amount', 'payment_date', 'payment_nu', 'reference'])) {
|
||||
$rank += 10; // demote addresses for these
|
||||
}
|
||||
if ($rank < $bestRank) {
|
||||
$bestRank = $rank;
|
||||
$best = [
|
||||
'entity' => $ent->key,
|
||||
'field' => $field,
|
||||
'canonical_root' => $ent->canonical_root,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return $best;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user