From c50a203bca67a25f66059eb9e0e027fc0043cc46 Mon Sep 17 00:00:00 2001 From: Ravi Gulhane Date: Mon, 19 Oct 2026 16:02:30 +0530 Subject: [PATCH] Changes --- app/Exports/AdherencePobDriveExport.php | 59 +++- app/Http/Controllers/FormController.php | 87 +++++- .../adherencepobdrivereport/report.blade.php | 30 +- ...2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php | 266 +++++++++++++++--- 4 files changed, 354 insertions(+), 88 deletions(-) diff --git a/app/Exports/AdherencePobDriveExport.php b/app/Exports/AdherencePobDriveExport.php index 4d89314c..c93c6352 100644 --- a/app/Exports/AdherencePobDriveExport.php +++ b/app/Exports/AdherencePobDriveExport.php @@ -18,6 +18,14 @@ class AdherencePobDriveExport private const PINK = 'F8CBAD'; + private const RED = 'C00000'; + + private const MAROON = '8A1538'; + + private const WHITE = 'FFFFFF'; + + private const BLUE = '0000FF'; + /** @var array */ private $abmRows; @@ -170,7 +178,8 @@ class AdherencePobDriveExport } $headers = array_merge($headers, $summary); $this->writeValues($sheet, 7, $headers); - $this->styleHeaderRow($sheet, 7, $lastCol); + $this->styleHeaderRow($sheet, 7, $lastCol, count($identity), $summaryStart); + $sheet->getStyle('A5')->getFont()->setName('Century Gothic')->setBold(true)->setSize(9)->getColor()->setARGB(self::BLUE); $this->paintDayTypes($sheet, 5, $dayStart, false); $this->paintDayHeaders($sheet, 7, $dayStart, false); @@ -195,7 +204,7 @@ class AdherencePobDriveExport $rowNumber++; } - $this->finishSheet($sheet, 7, max(7, $rowNumber - 1), $lastCol, $dayStart); + $this->finishSheet($sheet, 7, max(7, $rowNumber - 1), $lastCol, $dayStart, 14); $sheet->freezePane('A8'); } @@ -238,7 +247,7 @@ class AdherencePobDriveExport if (count($columns) >= 2 && $columns[count($columns) - 1]['kind'] === 'total-chemist') { $sheet->mergeCells($this->col($lastCol - 1) . '2:' . $this->col($lastCol) . '2'); } - $this->styleHeaderRow($sheet, 4, $lastCol); + $this->styleHeaderRow($sheet, 4, $lastCol, 3, $lastCol - 1); $this->paintRegionDayMarks($sheet, $columns); $rowNumber = 5; @@ -271,7 +280,7 @@ class AdherencePobDriveExport $rowNumber++; } - $this->finishSheet($sheet, 4, max(4, $rowNumber - 1), $lastCol, 4); + $this->finishSheet($sheet, 4, max(4, $rowNumber - 1), $lastCol, 4, 13); $sheet->freezePane('A5'); } @@ -298,7 +307,7 @@ class AdherencePobDriveExport } $headers[] = 'Total Chemists Qualified (≥₹15k POB)'; $this->writeValues($sheet, 5, $headers); - $this->styleHeaderRow($sheet, 5, $totalCol); + $this->styleHeaderRow($sheet, 5, $totalCol, 3, $totalCol); $this->paintDayTypes($sheet, 3, $dayStart, true); $this->paintDayHeaders($sheet, 5, $dayStart, true); @@ -322,7 +331,7 @@ class AdherencePobDriveExport $rowNumber++; } - $this->finishSheet($sheet, 5, max(5, $rowNumber - 1), $totalCol, $dayStart); + $this->finishSheet($sheet, 5, max(5, $rowNumber - 1), $totalCol, $dayStart, 13); $sheet->freezePane('A6'); } @@ -672,7 +681,9 @@ class AdherencePobDriveExport private function paintDayHeaders($sheet, int $row, int $startColumn, bool $singleColumn): void { foreach ($this->dayTemplate as $index => $day) { - $this->paintCell($sheet, $this->col($startColumn + $index) . $row, $day['type'] === 'H' ? self::GREY : self::GREEN); + $cell = $this->col($startColumn + $index) . $row; + $this->paintCell($sheet, $cell, $day['type'] === 'H' ? self::GREY : self::GREEN); + $sheet->getStyle($cell)->getFont()->setBold(true)->setSize(11)->getColor()->setARGB('000000'); } if ($singleColumn) { return; @@ -704,6 +715,7 @@ class AdherencePobDriveExport $color = $column['type'] === 'H' ? self::GREY : self::GREEN; $this->paintCell($sheet, $cell . '2', $color); $this->paintCell($sheet, $cell . '4', $color); + $sheet->getStyle($cell . '4')->getFont()->setBold(true)->setSize(11)->getColor()->setARGB('000000'); } } @@ -726,23 +738,40 @@ class AdherencePobDriveExport private function paintCell($sheet, string $cell, string $color): void { - $sheet->getStyle($cell)->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB($color); + $style = $sheet->getStyle($cell); + $style->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB($color); + $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER); } - private function styleHeaderRow($sheet, int $row, int $lastColumn): void + private function styleHeaderRow($sheet, int $row, int $lastColumn, int $identityCount, int $summaryStart): void { $range = 'A' . $row . ':' . $this->col($lastColumn) . $row; - $sheet->getStyle($range)->getFont()->setBold(true); $sheet->getStyle($range)->getAlignment()->setWrapText(true)->setVertical(Alignment::VERTICAL_CENTER)->setHorizontal(Alignment::HORIZONTAL_CENTER); - $sheet->getRowDimension($row)->setRowHeight(32); + $sheet->getRowDimension($row)->setRowHeight(36); + if ($identityCount > 0) { + $this->paintHeaderGroup($sheet, $row, 1, $identityCount, self::RED, 10); + } + if ($summaryStart > $identityCount && $summaryStart <= $lastColumn) { + $this->paintHeaderGroup($sheet, $row, $summaryStart, $lastColumn, self::MAROON, 9); + } } - private function finishSheet($sheet, int $headerRow, int $lastRow, int $lastColumn, int $dayStart): void + private function paintHeaderGroup($sheet, int $row, int $start, int $end, string $color, int $size): void { - $range = 'A1:' . $this->col($lastColumn) . $lastRow; - $sheet->getStyle($range)->getAlignment()->setVertical(Alignment::VERTICAL_CENTER); + $range = $this->col($start) . $row . ':' . $this->col($end) . $row; + $style = $sheet->getStyle($range); + $style->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB($color); + $style->getFont()->setName('Century Gothic')->setBold(true)->setSize($size)->getColor()->setARGB(self::WHITE); + $style->getAlignment()->setWrapText(true)->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER); + } + + private function finishSheet($sheet, int $headerRow, int $lastRow, int $lastColumn, int $dayStart, int $titleSize = 14): void + { + $sheet->getStyle('A1')->getFont()->setName('Century Gothic')->setBold(true)->setSize($titleSize)->getColor()->setARGB(self::MAROON); + if ($lastRow > 1) { + $sheet->getStyle('A2:' . $this->col($lastColumn) . $lastRow)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER); + } $sheet->getStyle('A' . $headerRow . ':' . $this->col($lastColumn) . $lastRow)->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN); - $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(14); for ($column = 1; $column <= $lastColumn; $column++) { $width = $column < $dayStart ? 22 : 14; $sheet->getColumnDimension($this->col($column))->setWidth($width); diff --git a/app/Http/Controllers/FormController.php b/app/Http/Controllers/FormController.php index 584cde81..2339ec29 100644 --- a/app/Http/Controllers/FormController.php +++ b/app/Http/Controllers/FormController.php @@ -5883,7 +5883,8 @@ class FormController extends Controller $replaceSubmissionId = $post['__replace_submission_id'] ?? ''; $deleteReason = $post['__delete_reason'] ?? ''; $reasonCode = $post['__reason_code'] ?? ''; - unset($post['__replace_submission_id'], $post['__delete_reason'], $post['__reason_code'], $post['reason_field_code']); + $deleteReasons = is_array($post['__delete_reasons'] ?? null) ? $post['__delete_reasons'] : []; + unset($post['__replace_submission_id'], $post['__delete_reason'], $post['__reason_code'], $post['__delete_reasons'], $post['reason_field_code'], $post['replace_submission_id']); Log::debug(print_r($post, true)); $finfo = LambdaRequest::postrequest('form', 'formentity/submitform', ['formdata' => $post, 'entity_id' => $formdata->form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition ]); } catch (\Throwable $e) { @@ -5904,7 +5905,8 @@ class FormController extends Controller $formdata->form_id, $replaceSubmissionId, $reasonCode, - $deleteReason + $deleteReason, + $deleteReasons ); if (!$marked) { return response()->json(['status' => 'failure', 'message' => 'The new entry was saved, but the previous entry could not be marked Deleted.']); @@ -8027,7 +8029,7 @@ class FormController extends Controller return response()->json($allapprovers->data->approvals); } - protected function markMotherForumSubmissionDeleted($partition, $userId, $formId, $submissionId, $reasonCode, $reason): bool + protected function markMotherForumSubmissionDeleted($partition, $userId, $formId, $submissionId, $reasonCode, $reason, array $reasons = []): bool { $loaded = LambdaRequest::postrequest('form', 'formentity/getformdefination', [ 'form_id' => $formId, @@ -8044,7 +8046,11 @@ class FormController extends Controller $previous['id'] = $submissionId; $previous['form_id'] = $formId; $previous['record_status'] = 'Deleted'; - if ($reasonCode !== '') { + if ($reasons !== []) { + foreach ($reasons as $code => $value) { + $previous[$code] = $value; + } + } elseif ($reasonCode !== '') { $previous[$reasonCode] = $reason; } $saved = LambdaRequest::postrequest('form', 'formentity/submitform', [ @@ -8061,8 +8067,53 @@ class FormController extends Controller switch($form) { case '1791539482-b06c2f9a-fe45-4b16-843a-224f07ed0d7b': $reasonCode = trim((string) ($post['reason_field_code'] ?? '')); - unset($post['reason_field_code']); + $replaceFromMonth = trim((string) ($post['replace_submission_id'] ?? '')); + unset($post['reason_field_code'], $post['replace_submission_id']); $post['record_status'] = 'Active'; + if ($replaceFromMonth !== '' && empty($post['id'])) { + $loaded = LambdaRequest::postrequest('form', 'formentity/getformdefination', [ + 'form_id' => $form, + 'user_id' => $user_id, + 'partition' => $partition, + 'id' => $replaceFromMonth, + ]); + $previous = json_decode(json_encode($loaded->data->formdata ?? new \stdClass()), true); + if (!is_array($previous) || $previous === []) { + $post['__error'] = 'Unable to load the entry being changed.'; + break; + } + $previousStatus = trim((string) ($previous['record_status'] ?? 'Active')); + if (strcasecmp($previousStatus, 'Deleted') === 0) { + $post['__error'] = 'This entry has been replaced and can no longer be changed.'; + break; + } + $reasons = []; + for ($slot = 1; $slot <= 5; $slot++) { + $previousContact = trim((string) ($previous['contact_id_'.$slot] ?? '')); + $nextContact = trim((string) ($post['contact_id_'.$slot] ?? '')); + if ($previousContact === '' || $previousContact === $nextContact) { + continue; + } + $reason = trim((string) ($post['reason_'.$slot] ?? '')); + if ($reason === '') { + $post['__error'] = 'Enter the reason for deletion for doctor '.$slot.'.'; + break 2; + } + $reasons['reason_'.$slot] = $reason; + } + $baseId = trim((string) ($previous['base_submission_id'] ?? '')); + if ($baseId === '') { + $baseId = $replaceFromMonth; + } + for ($slot = 1; $slot <= 5; $slot++) { + $post['reason_'.$slot] = ''; + } + $post['record_status'] = 'Active'; + $post['base_submission_id'] = $baseId; + $post['__replace_submission_id'] = $replaceFromMonth; + $post['__delete_reasons'] = $reasons; + break; + } if (empty($post['id'])) { $post['base_submission_id'] = ''; break; @@ -8084,24 +8135,32 @@ class FormController extends Controller $post['__error'] = 'This entry has been replaced and can no longer be edited.'; break; } - $reason = trim((string) ($reasonCode !== '' ? ($post[$reasonCode] ?? '') : '')); - if ($reason === '') { - $post['__error'] = 'Enter the reason for deletion.'; - break; + $reasons = []; + for ($slot = 1; $slot <= 5; $slot++) { + $previousContact = trim((string) ($previous['contact_id_'.$slot] ?? '')); + $nextContact = trim((string) ($post['contact_id_'.$slot] ?? '')); + if ($previousContact === '' || $previousContact === $nextContact) { + continue; + } + $reason = trim((string) ($post['reason_'.$slot] ?? '')); + if ($reason === '') { + $post['__error'] = 'Enter the reason for deletion for doctor '.$slot.'.'; + break 2; + } + $reasons['reason_'.$slot] = $reason; } $baseId = trim((string) ($previous['base_submission_id'] ?? '')); if ($baseId === '') { $baseId = $previousId; } unset($post['id']); + for ($slot = 1; $slot <= 5; $slot++) { + $post['reason_'.$slot] = ''; + } $post['record_status'] = 'Active'; $post['base_submission_id'] = $baseId; - if ($reasonCode !== '') { - $post[$reasonCode] = ''; - } $post['__replace_submission_id'] = $previousId; - $post['__delete_reason'] = $reason; - $post['__reason_code'] = $reasonCode; + $post['__delete_reasons'] = $reasons; break; case '1756965702-68add159-7312-476d-8c92-0c7683015351': if (($post['chemist_list'] ?? '') !== 'Others') { diff --git a/resources/views/adherencepobdrivereport/report.blade.php b/resources/views/adherencepobdrivereport/report.blade.php index 1ff55dfc..13bc5e99 100644 --- a/resources/views/adherencepobdrivereport/report.blade.php +++ b/resources/views/adherencepobdrivereport/report.blade.php @@ -15,6 +15,7 @@ .pob-table th, .pob-table td { vertical-align: middle; + text-align: center; } .pob-table thead tr:nth-child(1) th { @@ -31,16 +32,15 @@ background: #fff; } - .pob-table td.pob-day-w, .pob-table thead tr th.pob-day-w { - background: #e2efda; - color: inherit; + background: #c6efce; + color: #000; } .pob-table td.pob-day-h, .pob-table thead tr th.pob-day-h { background: #d9d9d9; - color: #808080; + color: #000; } .pob-table thead tr th.pob-identity { @@ -53,15 +53,9 @@ color: #fff; } - .pob-table td.pob-vacant { - background: #fce4e4; - color: #c00000; - } - - .pob-table td.pob-achieved { - background: #c6efce; - color: #006100; - font-weight: 700; + .pob-table tr.pob-vacant td { + background: #f8cbad; + color: #000; } @endsection @@ -153,19 +147,13 @@ @forelse ($section['rows'] as $row) - + @foreach ($row['cells'] as $cellIndex => $cell) @php $dayType = $section['dayTypes'][$cellIndex] ?? ''; $cellClass = ''; - if ($dayType === 'H' || $cell === 'Holiday') { + if (empty($row['vacant']) && ($dayType === 'H' || $cell === 'Holiday')) { $cellClass = 'pob-day-h'; - } elseif ($dayType === 'W') { - $cellClass = 'pob-day-w'; - } elseif (!empty($row['vacant']) && $firstDay !== null && $cellIndex < $firstDay) { - $cellClass = 'pob-vacant'; - } elseif ($cell === 'Achieved') { - $cellClass = 'pob-achieved'; } @endphp {{ $cell }} diff --git a/resources/views/form/rapport-team4/1791539482-b06c2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php b/resources/views/form/rapport-team4/1791539482-b06c2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php index a08c5266..94d3c874 100644 --- a/resources/views/form/rapport-team4/1791539482-b06c2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php +++ b/resources/views/form/rapport-team4/1791539482-b06c2f9a-fe45-4b16-843a-224f07ed0d7b.blade.php @@ -41,22 +41,75 @@ @endif @php - $submissions = Formhelper::getMultiformData( $form->partition, $form_id, $form->user_id); - $submissions = $submissions->data->submissions; + $history = Formhelper::getMultiformData( $form->partition, $form_id, $form->user_id); + $submissions = $history->data->submissions ?? []; /* echo "
";
                             print_r($submissions);
                             echo "
"; */ - $submittedMonths = []; + $monthEntries = []; + $monthEntryTimes = []; if (!empty($submissions)) { foreach ($submissions as $sub) { - if (isset($sub->formdata->month) && !empty($sub->formdata->month)) { - $submittedMonths[] = trim($sub->formdata->month); + $saved = $sub->formdata ?? null; + if (!$saved || empty($saved->month)) { + continue; } + $status = (string) ($saved->record_status ?? 'Active'); + if (strcasecmp($status, 'Deleted') === 0) { + continue; + } + $monthName = trim((string) $saved->month); + $updated = strtotime((string) ($sub->updatedAt ?? '')) ?: 0; + if (isset($monthEntryTimes[$monthName]) && $updated < $monthEntryTimes[$monthName]) { + continue; + } + $payload = json_decode(json_encode($saved), true); + if (!is_array($payload)) { + $payload = []; + } + unset($payload['id']); + $contactsById = []; + $contactsByName = []; + $savedContacts = isset($sub->contacts) ? $sub->contacts : []; + foreach ($savedContacts as $contact) { + $contactId = trim((string) ($contact->id ?? $contact->contact_id ?? '')); + $contactName = trim((string) ($contact->name ?? '')); + if ($contactId === '') { + continue; + } + $contactsById[$contactId] = $contactName; + if ($contactName !== '' && !isset($contactsByName[$contactName])) { + $contactsByName[$contactName] = $contactId; + } + } + $doctorLabels = []; + for ($slot = 1; $slot <= 5; $slot++) { + $contactKey = 'contact_id_'.$slot; + $current = trim((string) ($payload[$contactKey] ?? '')); + if ($current === '') { + continue; + } + if (isset($contactsById[$current])) { + $doctorLabels[$contactKey] = $contactsById[$current]; + continue; + } + if (isset($contactsByName[$current])) { + $payload[$contactKey] = $contactsByName[$current]; + $doctorLabels[$contactKey] = $current; + } + } + $monthEntries[$monthName] = [ + 'id' => (string) ($sub->id ?? ''), + 'formdata' => $payload, + 'labels' => $doctorLabels, + ]; + $monthEntryTimes[$monthName] = $updated; } } + $submittedMonths = array_keys($monthEntries); $isEditMode = !empty($id); @@ -87,9 +140,12 @@ - @if($reasonQuestionCode !== '') + @if($id && $reasonQuestionCode !== '') @endif + @if(!$id) + + @endif @csrf @if($id) @@ -101,12 +157,17 @@ @continue @endif @php - $isReasonField = $reasonQuestionCode !== '' && $question->code === $reasonQuestionCode; - $fieldRequired = $isReasonField ? $isEditMode : ($question->required == 'yes'); - $fieldDisabled = $isReasonField && !$isEditMode; + $reasonSlot = null; + if (preg_match('/^reason_(\d+)$/', (string) $question->code, $reasonMatch)) { + $reasonSlot = $reasonMatch[1]; + } + $isReasonField = $reasonSlot !== null; + $hideReason = $isReasonField; + $fieldRequired = $hideReason ? false : ($isReasonField ? true : ($question->required == 'yes')); + $fieldDisabled = $hideReason; @endphp -
- +
+ @switch($question->type) @case('hidden') @@ -160,10 +221,9 @@ @foreach ($question->options as $option) @php - $isSubmitted = ($question->code == 'month' && in_array(trim($option->value), $submittedMonths)); + $isSubmitted = ($question->code == 'month' && in_array(trim($option->value), $submittedMonths, true)); $isSelected = (isset($question->value) && $question->value == $option->value); - - $isDisabled = ($isSubmitted && (!$isEditMode || !$isSelected)); + $isDisabled = ($isEditMode && $isSubmitted && !$isSelected); @endphp @if($question->code == 'contact_id' && isset($option->contact->type) && $option->contact->type == 'doctor') @@ -177,7 +237,7 @@ @else