updates to UI and add archiving option
This commit is contained in:
@@ -71,6 +71,18 @@ public function simulate(Import $import, int $limit = 100, bool $verbose = false
|
||||
$assoc = $this->associateRow($columns, $rawValues);
|
||||
$rowEntities = [];
|
||||
|
||||
// Reactivation intent detection (row > import > template)
|
||||
$rowReactivate = false;
|
||||
if (array_key_exists('reactivate', $assoc)) {
|
||||
$rawReactivateVal = $assoc['reactivate'];
|
||||
if (! is_null($rawReactivateVal) && $rawReactivateVal !== '') {
|
||||
$rowReactivate = filter_var($rawReactivateVal, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? false;
|
||||
}
|
||||
}
|
||||
$importReactivate = (bool) ($import->reactivate ?? false);
|
||||
$templateReactivate = (bool) (optional($import->template)->reactivate ?? false);
|
||||
$reactivateMode = $rowReactivate || $importReactivate || $templateReactivate;
|
||||
|
||||
// Helper closure to resolve mapping value (with normalization fallbacks)
|
||||
$val = function (string $tf) use ($assoc, $targetToSource) {
|
||||
// Direct hit
|
||||
@@ -95,6 +107,15 @@ public function simulate(Import $import, int $limit = 100, bool $verbose = false
|
||||
// Contract
|
||||
if (isset($entityRoots['contract'])) {
|
||||
[$contractEntity, $summaries, $contractCache] = $this->simulateContract($val, $summaries, $contractCache, $val('contract.reference'));
|
||||
// If reactivation requested and contract exists but is inactive / soft-deleted, mark action as reactivate for UI clarity
|
||||
if ($reactivateMode && ($contractEntity['action'] === 'update') && (
|
||||
(isset($contractEntity['active']) && $contractEntity['active'] === 0) ||
|
||||
(! empty($contractEntity['deleted_at']))
|
||||
)) {
|
||||
$contractEntity['original_action'] = $contractEntity['action'];
|
||||
$contractEntity['action'] = 'reactivate';
|
||||
$contractEntity['reactivation'] = true;
|
||||
}
|
||||
$rowEntities['contract'] = $contractEntity + [
|
||||
'action_label' => $translatedActions[$contractEntity['action']] ?? $contractEntity['action'],
|
||||
];
|
||||
@@ -628,7 +649,7 @@ private function simulateContract(callable $val, array $summaries, array $cache,
|
||||
if (array_key_exists($reference, $cache)) {
|
||||
$contract = $cache[$reference];
|
||||
} else {
|
||||
$contract = Contract::query()->where('reference', $reference)->first(['id', 'reference', 'client_case_id']);
|
||||
$contract = Contract::query()->where('reference', $reference)->first(['id', 'reference', 'client_case_id', 'active', 'deleted_at']);
|
||||
$cache[$reference] = $contract; // may be null
|
||||
}
|
||||
}
|
||||
@@ -637,6 +658,8 @@ private function simulateContract(callable $val, array $summaries, array $cache,
|
||||
'id' => $contract?->id,
|
||||
'exists' => (bool) $contract,
|
||||
'client_case_id' => $contract?->client_case_id,
|
||||
'active' => $contract?->active,
|
||||
'deleted_at' => $contract?->deleted_at,
|
||||
'action' => $contract ? 'update' : ($reference ? 'create' : 'skip'),
|
||||
];
|
||||
$summaries['contract']['total_rows']++;
|
||||
@@ -658,7 +681,10 @@ private function simulateAccount(callable $val, array $summaries, array $cache,
|
||||
if (array_key_exists($reference, $cache)) {
|
||||
$account = $cache[$reference];
|
||||
} else {
|
||||
$account = Account::query()->where('reference', $reference)->first(['id', 'reference', 'balance_amount']);
|
||||
$account = Account::query()
|
||||
->where('reference', $reference)
|
||||
->where('active', 1)
|
||||
->first(['id', 'reference', 'balance_amount']);
|
||||
$cache[$reference] = $account;
|
||||
}
|
||||
}
|
||||
@@ -1156,6 +1182,7 @@ private function actionTranslations(): array
|
||||
'update' => 'posodobi',
|
||||
'skip' => 'preskoči',
|
||||
'implicit' => 'posredno',
|
||||
'reactivate' => 'reaktiviraj',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user