@props(['demographyconfigId','moduleid','mandatory','results']) @php use App\Models\Demography; $Field = DB::table('DemographyConfig')->where('DemographyConfigId',$demographyconfigId)->first(); $DisplayName = $Field->LabelValue; $ColumnName = $Field->ColumnName; $DependentField = $Field->DependentField; $Helptext = $Field->Helptext; $DependentFieldId = explode(",", (string)$Field->DependentFieldId); $DependentFieldColumnName = ""; $DependentFieldColumnNameValue = ""; try { if (!empty($DependentFieldId[0])) { $DependentFieldColumnName = Demography::GetDependentFieldColumnName($moduleid, $DependentFieldId[0]); $DependentFieldColumnNameValue = $results->$DependentFieldColumnName ?? null; } } catch (\Exception $e) {} $LabelValue = $results->$ColumnName ?? ''; // Required marker if ($mandatory==1) { $RequiredField="required"; $DisplayredStar="*"; } else { $RequiredField=""; $DisplayredStar=""; } // Dependent field visibility if ($DependentField==1) { if (in_array($DependentFieldColumnNameValue, $DependentFieldId)) { $displayHide = ""; } else { $displayHide = "displayHide"; $RequiredField = ""; } } else { $displayHide = ""; } // Build ordered list of existing files from CSV of UUIDs $existingFiles = []; if (!empty($LabelValue)) { $ids = array_values(array_filter(array_map('trim', explode(',', (string)$LabelValue)))); if ($ids) { $rows = DB::table('TemporaryFiles') ->whereIn('TemporaryFilesId', $ids) ->where('DeletedStatus', 0) ->get(['TemporaryFilesId','FileName','FilePath']) ->keyBy('TemporaryFilesId'); foreach ($ids as $id) { if (isset($rows[$id])) { $existingFiles[] = [ 'TemporaryFilesId' => $id, 'FileName' => $rows[$id]->FileName ?? 'UnknownFile', 'FilePath' => $rows[$id]->FilePath ?? '', ]; } } } } // Get the existing UniqueReferenceId from the first file (all should have same UniqueReferenceId) $existingUniqueRefId = ''; if (!empty($existingFiles)) { $firstFile = DB::table('TemporaryFiles') ->where('TemporaryFilesId', $existingFiles[0]['TemporaryFilesId']) ->first(['UniqueReferenceId']); if ($firstFile) { $existingUniqueRefId = $firstFile->UniqueReferenceId; } } @endphp