Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 61fe16a0ea | |||
| 14979dba4b | |||
| 015586a9df |
+84
-4
@@ -58,9 +58,28 @@ class DirectAccessReportGenerator
|
||||
? trim($contact->get('firstName') . ' ' . $contact->get('lastName'))
|
||||
: 'ללא איש קשר';
|
||||
|
||||
// Get assigned user name
|
||||
$assignedUser = $userId ? $this->entityManager->getEntityById('User', $userId) : null;
|
||||
$assignedUserName = $assignedUser ? $assignedUser->get('name') : ($this->user->get('name') ?? '');
|
||||
// Get assigned user name — prefer case's assignedUser, then userId, then current user
|
||||
$assignedUserName = '';
|
||||
$caseAssignedUserId = $case->get('assignedUserId');
|
||||
if ($caseAssignedUserId) {
|
||||
$caseAssignedUser = $this->entityManager->getEntityById('User', $caseAssignedUserId);
|
||||
if ($caseAssignedUser) {
|
||||
$assignedUserName = $caseAssignedUser->get('name') ?? '';
|
||||
}
|
||||
}
|
||||
if (empty($assignedUserName) && $userId) {
|
||||
$assignedUser = $this->entityManager->getEntityById('User', $userId);
|
||||
if ($assignedUser) {
|
||||
$assignedUserName = $assignedUser->get('name') ?? '';
|
||||
}
|
||||
}
|
||||
if (empty($assignedUserName)) {
|
||||
$assignedUserName = $this->user->get('name') ?? '';
|
||||
}
|
||||
// Filter out system/API user names
|
||||
if (in_array(strtolower($assignedUserName), ['api', 'x-api-key', 'system', 'admin'], true)) {
|
||||
$assignedUserName = '';
|
||||
}
|
||||
|
||||
// Build placeholder data directly from params
|
||||
$data = $this->buildPlaceholderData($params, $case, $contactName, $assignedUserName);
|
||||
@@ -83,6 +102,11 @@ class DirectAccessReportGenerator
|
||||
$content = file_get_contents($outputPath);
|
||||
@unlink($outputPath);
|
||||
|
||||
// Clean up temp template if downloaded from storage
|
||||
if (str_starts_with($templatePath, self::TEMP_DIR)) {
|
||||
@unlink($templatePath);
|
||||
}
|
||||
|
||||
// Create Attachment
|
||||
$attachment = $this->entityManager->getNewEntity('Attachment');
|
||||
$attachment->set([
|
||||
@@ -128,9 +152,18 @@ class DirectAccessReportGenerator
|
||||
$legalAnalysis = json_decode($legalAnalysis, true) ?? [];
|
||||
}
|
||||
|
||||
// Fallback: if AI sent legalAnalysis fields flat (not nested), pick them up
|
||||
$laFields = ['q1DocsDetail', 'q2ReasonDetail', 'q4PanelComposition', 'q6ComplaintsDetail',
|
||||
'q8ClinicalGap', 'q9MoharaDetail', 'q10RehabDetail', 'q11ScoreDetail', 'q12UniqueDetail'];
|
||||
foreach ($laFields as $f) {
|
||||
if (empty($legalAnalysis[$f]) && !empty($params[$f])) {
|
||||
$legalAnalysis[$f] = $params[$f];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
// Header
|
||||
'legalAidNumber' => $params['legalAidNumber'] ?? $case->get('cLegalAidNumber') ?? '',
|
||||
'cLegalAidNumber' => $params['legalAidNumber'] ?? $case->get('cLegalAidNumber') ?? '',
|
||||
'contactName' => $contactName,
|
||||
'assignedUserName' => $assignedUserName,
|
||||
'reportDate' => $this->formatDate(date('Y-m-d')),
|
||||
@@ -206,6 +239,7 @@ class DirectAccessReportGenerator
|
||||
$data['chk_contact_bad'] = ($contactStatus === 'לא תקין') ? $CHK : $UNCHK;
|
||||
|
||||
$rec = $params['recommendationType'] ?? '';
|
||||
$data['chk_rec_proceed'] = ($rec === 'המשך ייצוג') ? $CHK : $UNCHK;
|
||||
$data['chk_rec_consulting'] = ($rec === 'ייעוץ והדרכה חלף ייצוג') ? $CHK : $UNCHK;
|
||||
$data['chk_rec_waiver'] = ($rec === 'ויתור הלקוח') ? $CHK : $UNCHK;
|
||||
$data['chk_rec_replacement'] = ($rec === 'החלפת ייצוג') ? $CHK : $UNCHK;
|
||||
@@ -248,6 +282,12 @@ class DirectAccessReportGenerator
|
||||
if (file_exists($resolved)) {
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
// Download from NetworkStorage (WebDAV)
|
||||
$downloaded = $this->downloadTemplateFromStorage($templatePath);
|
||||
if ($downloaded) {
|
||||
return $downloaded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,6 +306,46 @@ class DirectAccessReportGenerator
|
||||
throw new Error("Template '" . self::TEMPLATE_NAME . "' not found.");
|
||||
}
|
||||
|
||||
private function downloadTemplateFromStorage(string $templatePath): ?string
|
||||
{
|
||||
try {
|
||||
$nds = $this->injectableFactory->create(
|
||||
\Espo\Modules\NetworkStorageIntegration\Services\NetworkDocumentService::class
|
||||
);
|
||||
$client = $nds->getClient();
|
||||
|
||||
// Try Templates/{templatePath} on the storage
|
||||
$integration = $this->entityManager->getEntityById('Integration', 'NetworkStorage');
|
||||
$templatesFolderPath = 'Templates';
|
||||
if ($integration && $integration->get('enabled')) {
|
||||
$data = (array) ($integration->get('data') ?? []);
|
||||
$templatesFolderPath = $data['templatesFolderPath'] ?? 'Templates';
|
||||
}
|
||||
|
||||
$storagePath = $templatesFolderPath . '/' . $templatePath;
|
||||
|
||||
if (!$client->exists($storagePath)) {
|
||||
$this->log->debug("LegalAssistance: Template not found on storage: {$storagePath}");
|
||||
return null;
|
||||
}
|
||||
|
||||
$content = $client->downloadFile($storagePath);
|
||||
|
||||
// Save locally for this request
|
||||
if (!is_dir(self::TEMP_DIR)) {
|
||||
mkdir(self::TEMP_DIR, 0775, true);
|
||||
}
|
||||
$localPath = self::TEMP_DIR . 'template_' . uniqid() . '.docx';
|
||||
file_put_contents($localPath, $content);
|
||||
|
||||
$this->log->debug("LegalAssistance: Template downloaded from storage: {$storagePath} → {$localPath}");
|
||||
return $localPath;
|
||||
} catch (\Exception $e) {
|
||||
$this->log->warning("LegalAssistance: Failed to download template from storage: " . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function processTemplate(string $inputPath, string $outputPath, array $data): void
|
||||
{
|
||||
// Ensure PHPWord autoloader is registered
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "LegalAssistance",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.4",
|
||||
"acceptableVersions": [">=8.0.0"],
|
||||
"php": [">=8.1"],
|
||||
"releaseDate": "2026-04-07",
|
||||
"releaseDate": "2026-04-09",
|
||||
"author": "Marcus-Law",
|
||||
"description": "סיוע משפטי — יצירת דוח גישה ישירה (JSON ישירות ל-DOCX), אינטגרציה עם שירה",
|
||||
"scripts": {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -109,8 +109,8 @@
|
||||
},
|
||||
"recommendationType": {
|
||||
"type": "string",
|
||||
"enum": ["ייעוץ והדרכה חלף ייצוג", "ויתור הלקוח", "החלפת ייצוג", "לא נוצר קשר", "לא התקיימה פגישה", "עדיין לא ניתן להחליט", "נדרשים מסמכים נוספים", "המלצה לסירוב"],
|
||||
"description": "סוג ההמלצה/ההודעה"
|
||||
"enum": ["המשך ייצוג", "ייעוץ והדרכה חלף ייצוג", "ויתור הלקוח", "החלפת ייצוג", "לא נוצר קשר", "לא התקיימה פגישה", "עדיין לא ניתן להחליט", "נדרשים מסמכים נוספים", "המלצה לסירוב"],
|
||||
"description": "סוג ההמלצה/ההודעה — בחר ׳המשך ייצוג׳ כשמומלץ להגיש ערעור או להמשיך בייצוג"
|
||||
},
|
||||
"recommendationDetail": {
|
||||
"type": "string",
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user