From b75579f346cdb0a55f95dc5eccc398689668f97b Mon Sep 17 00:00:00 2001 From: Ravi Gulhane Date: Wed, 4 Nov 2026 15:02:22 +0530 Subject: [PATCH 01/10] Changes --- app/Helpers/TgicsHelper.php | 29 ++++++- app/Http/Controllers/FormController.php | 76 +++++++++++++++++++ ...e937-cfb5-4679-989a-c3fea892568f.blade.php | 59 ++++++++------ 3 files changed, 135 insertions(+), 29 deletions(-) diff --git a/app/Helpers/TgicsHelper.php b/app/Helpers/TgicsHelper.php index 78fb0be0..c48105f4 100644 --- a/app/Helpers/TgicsHelper.php +++ b/app/Helpers/TgicsHelper.php @@ -95,6 +95,22 @@ class TgicsHelper return strtolower(trim((string) $value)) === 'yes'; } + /** + * Read validation flag from a contact object (supports attribute_ prefix). + */ + public static function contactHasWhatsappValidated($item): bool + { + if (!$item) { + return false; + } + $direct = $item->tgics_whatsapp_validated ?? null; + if (self::isWhatsappValidatedFlag($direct)) { + return true; + } + $prefixed = $item->attribute_tgics_whatsapp_validated ?? null; + return self::isWhatsappValidatedFlag($prefixed); + } + /** * Map contact_id => whether WhatsApp is validated for TGICS. * @@ -122,11 +138,16 @@ class TgicsHelper try { $resp = LambdaRequest::getrequest('contact', 'contact/get_one', ['id' => $id], $accessToken); $item = $resp->data->item ?? null; - if ($item && self::isWhatsappValidatedFlag($item->tgics_whatsapp_validated ?? '')) { - $status[$id] = true; - } + $validated = self::contactHasWhatsappValidated($item); + $status[$id] = $validated; + Log::info('[TGICS_WA_STATUS] contact lookup', [ + 'contact_id' => $id, + 'validated' => $validated, + 'flag' => $item->tgics_whatsapp_validated ?? ($item->attribute_tgics_whatsapp_validated ?? null), + 'api_status' => $resp->status ?? null, + ]); } catch (\Throwable $e) { - Log::warning('TGICS WhatsApp validation lookup failed for '.$id.': '.$e->getMessage()); + Log::warning('[TGICS_WA_STATUS] lookup failed for '.$id.': '.$e->getMessage()); } } diff --git a/app/Http/Controllers/FormController.php b/app/Http/Controllers/FormController.php index e048d53a..d5269226 100644 --- a/app/Http/Controllers/FormController.php +++ b/app/Http/Controllers/FormController.php @@ -1705,6 +1705,43 @@ class FormController extends Controller } } + // Team3 doctor tagging (single submit): mark attribute = Yes on selected doctor(s) + $team3DrTagAttributes = [ + '1793772514-e8e67206-8dba-471e-b08f-deece5d36d11' => 'levoswitch_drs', + '1793767249-069bf040-1469-4117-b364-e4851e1f4bdf' => 'toba_titans_drs', + ]; + if (isset($team3DrTagAttributes[$formdata->form_id])) { + $tagAttribute = $team3DrTagAttributes[$formdata->form_id]; + $rawContactIds = $post['contact_id'] ?? []; + if (!is_array($rawContactIds)) { + $rawContactIds = [$rawContactIds]; + } + $contactIds = []; + foreach ($rawContactIds as $contactId) { + $contactId = trim((string) $contactId); + if ($contactId !== '' && strcasecmp($contactId, 'others') !== 0) { + $contactIds[] = $contactId; + } + } + $contactIds = array_values(array_unique($contactIds)); + if ($contactIds !== [] && !empty($formdata->partition)) { + list($application, $domain) = explode('-', $formdata->partition); + $token = DB::table('users')->select('access_token')->where('domain', $domain)->where('permissions', 'like', '%contact_create%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get(); + $userId = trim((string) ($post['user_id'] ?? ($formdata->user_id ?? ''))); + if ($token->isNotEmpty() && $userId !== '') { + foreach ($contactIds as $contactId) { + LambdaRequest::postrequest('contact', 'contact/update', [ + 'domain' => $domain, + 'application' => $application, + 'user_id' => $userId, + 'id' => $contactId, + $tagAttribute => 'Yes', + ], $token[0]->access_token); + } + } + } + } + if($formdata->form_id == '1757055046-ba0eff4e-0d4a-4e90-b190-c59f12ef6edd') { // if(isset($post['cresar_bs_launched']) && $post['cresar_bs_launched'] == 'Yes' ) { list($application, $domain) = explode("-", $formdata->partition); @@ -8104,6 +8141,40 @@ class FormController extends Controller ]); } + // Team3 doctor tagging: mark attribute = Yes on each selected doctor + $team3DrTagAttributes = [ + '1793772514-e8e67206-8dba-471e-b08f-deece5d36d11' => 'levoswitch_drs', + '1793767249-069bf040-1469-4117-b364-e4851e1f4bdf' => 'toba_titans_drs', + ]; + if (isset($team3DrTagAttributes[$formdata->form_id])) { + $tagAttribute = $team3DrTagAttributes[$formdata->form_id]; + $contactIds = []; + if (!empty($post['contact_id']) && is_array($post['contact_id'])) { + foreach ($post['contact_id'] as $contactId) { + $contactId = trim((string) $contactId); + if ($contactId !== '' && strcasecmp($contactId, 'others') !== 0) { + $contactIds[] = $contactId; + } + } + } + $contactIds = array_values(array_unique($contactIds)); + if ($contactIds !== [] && !empty($formdata->partition)) { + list($application, $domain) = explode('-', $formdata->partition); + $token = DB::table('users')->select('access_token')->where('domain', $domain)->where('permissions', 'like', '%contact_create%')->orderBy('updated_at', 'desc')->skip(0)->take(1)->get(); + $userId = trim((string) ($post['user_id'] ?? ($formdata->user_id ?? ''))); + if ($token->isNotEmpty() && $userId !== '') { + foreach ($contactIds as $contactId) { + LambdaRequest::postrequest('contact', 'contact/update', [ + 'domain' => $domain, + 'application' => $application, + 'user_id' => $userId, + 'id' => $contactId, + $tagAttribute => 'Yes', + ], $token[0]->access_token); + } + } + } + } if(isset($formdata) && !empty($formdata) && $formdata->user_id != '') { $post = $this->applyPobAmounts($post); @@ -13550,6 +13621,11 @@ class FormController extends Controller } $validated = \App\Helpers\TgicsHelper::isContactWhatsappValidated($contactId, $domain); + \Log::info('[TGICS_WA_STATUS] poll', [ + 'contact_id' => $contactId, + 'domain' => $domain, + 'validated' => $validated, + ]); return response()->json([ 'status' => 'success', diff --git a/resources/views/form/rapport-lifemankind/1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php b/resources/views/form/rapport-lifemankind/1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php index e549a444..5edac330 100644 --- a/resources/views/form/rapport-lifemankind/1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php +++ b/resources/views/form/rapport-lifemankind/1792561624-4466e937-cfb5-4679-989a-c3fea892568f.blade.php @@ -866,41 +866,50 @@ $('body').addClass('modal-open'); } + function checkTgicsWaStatus(contactId) { + return $.ajax({ + type: 'GET', + url: '/form/tgicswhatsappstatus', + data: { + contact_id: contactId, + partition: 'rapport-lifemankind' + } + }).then(function(res) { + if (res && res.status === 'success' && res.data && res.data.validated) { + stopTgicsWaPoll(); + $('#tgics-validate-wa-status').text('Validated!'); + Swal.fire({ + icon: 'success', + title: 'WhatsApp validated', + text: 'You can now send the survey link to this doctor.', + timer: 1800, + showConfirmButton: false + }).then(function() { + window.location.reload(); + }); + return true; + } + return false; + }, function(err) { + console.warn('[TGICS_WA_STATUS] poll failed', err); + return false; + }); + } + function startTgicsWaPoll(contactId) { stopTgicsWaPoll(); tgicsWaPollStartedAt = Date.now(); $('#tgics-validate-wa-status').text('Waiting for validation…'); - + // Immediate check, then every 2s + checkTgicsWaStatus(contactId); tgicsWaPollTimer = setInterval(function() { if (Date.now() - tgicsWaPollStartedAt > 120000) { stopTgicsWaPoll(); $('#tgics-validate-wa-status').text('Still waiting. Close and try Validate again after the doctor sends the message.'); return; } - $.ajax({ - type: 'GET', - url: '/form/tgicswhatsappstatus', - data: { - contact_id: contactId, - partition: 'rapport-lifemankind' - }, - success: function(res) { - if (res && res.status === 'success' && res.data && res.data.validated) { - stopTgicsWaPoll(); - $('#tgics-validate-wa-status').text('Validated!'); - Swal.fire({ - icon: 'success', - title: 'WhatsApp validated', - text: 'You can now send the survey link to this doctor.', - timer: 1800, - showConfirmButton: false - }).then(function() { - window.location.reload(); - }); - } - } - }); - }, 3000); + checkTgicsWaStatus(contactId); + }, 2000); } $(document).on('click', '.tgics-validate-wa-btn', function(e) { From 1bae11f04870b7e9094ec0173755c142a3103a5f Mon Sep 17 00:00:00 2001 From: zeeshan Date: Wed, 4 Nov 2026 15:30:08 +0530 Subject: [PATCH 02/10] Team 4 (Montair LC KID 5 ABM Conversion) --- ...ca22-0891-4e77-88e8-56b43dd57c5e.blade.php | 499 ++++++++++++++++++ 1 file changed, 499 insertions(+) create mode 100644 resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php diff --git a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php new file mode 100644 index 00000000..e6f04797 --- /dev/null +++ b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php @@ -0,0 +1,499 @@ + + + + @include('layouts.shared/title-meta', ['title' => "Form"]) + @include('layouts.shared/head-css', ["mode" => $mode ?? '', "demo" => $demo ?? '']) + + + +
+ processing... +
+ + + + +@include('layouts.shared/footer-script') + + + + + + + + + + \ No newline at end of file From 0ddf28f839b3cf8dc7ca321b1f0045318d465dde Mon Sep 17 00:00:00 2001 From: zeeshan Date: Wed, 4 Nov 2026 15:36:51 +0530 Subject: [PATCH 03/10] Team 4 (Montair LC KID 5 ABM Conversion) --- .../1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php index e6f04797..7b5b6df4 100644 --- a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php +++ b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php @@ -47,7 +47,7 @@ @endphp - @if(count($submissions) ==4) + @if(count($submissions) ==10)
From 9637614b7971c53a6d876ec549b4fff38abe27a8 Mon Sep 17 00:00:00 2001 From: zeeshan Date: Wed, 4 Nov 2026 15:42:37 +0530 Subject: [PATCH 04/10] Team4 (Monitair LC Kid 5 ABM Conversion) --- ...ca22-0891-4e77-88e8-56b43dd57c5e.blade.php | 500 +----------------- 1 file changed, 1 insertion(+), 499 deletions(-) diff --git a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php index 7b5b6df4..2e65efe2 100644 --- a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php +++ b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php @@ -1,499 +1 @@ - - - - @include('layouts.shared/title-meta', ['title' => "Form"]) - @include('layouts.shared/head-css', ["mode" => $mode ?? '', "demo" => $demo ?? '']) - - - -
- processing... -
- - - - -@include('layouts.shared/footer-script') - - - - - - - - - - \ No newline at end of file +a \ No newline at end of file From e4acea72bcb1ec8f9c2b7f42bf184223660f6246 Mon Sep 17 00:00:00 2001 From: zeeshan Date: Wed, 4 Nov 2026 15:45:55 +0530 Subject: [PATCH 05/10] Team 4 (Montair LC KID 5 ABM Conversion) --- ...ca22-0891-4e77-88e8-56b43dd57c5e.blade.php | 467 +++++++++++++++++- 1 file changed, 466 insertions(+), 1 deletion(-) diff --git a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php index 2e65efe2..ef7b4ff1 100644 --- a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php +++ b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php @@ -1 +1,466 @@ -a \ No newline at end of file + + + + @include('layouts.shared/title-meta', ['title' => "Form"]) + @include('layouts.shared/head-css', ["mode" => $mode ?? '', "demo" => $demo ?? '']) + + + +
+ processing... +
+ + + + +@include('layouts.shared/footer-script') + + + + + + + + + + \ No newline at end of file From 0906e9d4e89d34a35e6b4d768ef18985ff9f8526 Mon Sep 17 00:00:00 2001 From: zeeshan Date: Wed, 4 Nov 2026 15:48:07 +0530 Subject: [PATCH 06/10] Team 4 (Montair LC Kid ABM Conversion) Limit --- ...793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php index ef7b4ff1..3917c2e5 100644 --- a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php +++ b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php @@ -47,7 +47,7 @@ @endphp - @if(count($submissions) ==4) +
@@ -147,9 +147,7 @@ @endif
- @else -

You have already submitted 5 Doctors

- @endif + From 33cd45030cea76ce8bd946fe365a53ac99867b4b Mon Sep 17 00:00:00 2001 From: zeeshan Date: Wed, 4 Nov 2026 15:51:18 +0530 Subject: [PATCH 07/10] Team 4 (Montair LC KID 5 ABM Conversion) 5 Doctor Limit --- ...93785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php index 3917c2e5..0029835c 100644 --- a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php +++ b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php @@ -47,7 +47,7 @@ @endphp - + @if($submissions && count($submissions) <=4)
@@ -147,8 +147,9 @@ @endif
- - + @else +
You have already submitted 5 Doctors
+ @endif
From 5cdea3cbaad1afb7e9d1be7e47ecbe55434de536 Mon Sep 17 00:00:00 2001 From: Ravi Gulhane Date: Wed, 4 Nov 2026 15:56:57 +0530 Subject: [PATCH 08/10] Changes --- app/Helpers/TgicsHelper.php | 41 ++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/app/Helpers/TgicsHelper.php b/app/Helpers/TgicsHelper.php index c48105f4..533d1025 100644 --- a/app/Helpers/TgicsHelper.php +++ b/app/Helpers/TgicsHelper.php @@ -113,6 +113,7 @@ class TgicsHelper /** * Map contact_id => whether WhatsApp is validated for TGICS. + * Prefers TGICS API (same RAPPORT token that wrote the flag); falls back to contact/get_one. * * @param array $contactIds * @return array @@ -127,20 +128,54 @@ class TgicsHelper return []; } + $status = array_fill_keys($ids, false); + + $base = rtrim((string) env('TGICS_API_BASE', ''), '/'); + if ($base !== '') { + try { + $response = Http::timeout(10)->acceptJson()->get($base.'/api/whatsapp/status', [ + 'contact_ids' => implode(',', $ids), + ]); + + if ($response->successful()) { + $json = $response->json(); + $validatedRaw = $json['data']['validated'] ?? []; + foreach ($ids as $id) { + $status[$id] = !empty($validatedRaw[$id]); + } + Log::info('[TGICS_WA_STATUS] via TGICS API', [ + 'ids' => $ids, + 'status' => $status, + 'http' => $response->status(), + ]); + return $status; + } + + Log::warning('TGICS WhatsApp status request failed', [ + 'status' => $response->status(), + 'body' => $response->body(), + ]); + } catch (\Throwable $e) { + Log::warning('[TGICS_WA_STATUS] TGICS API error: '.$e->getMessage()); + } + } else { + Log::warning('TGICS_API_BASE is not configured; falling back to Rapport contact/get_one'); + } + + // Fallback: Rapport via a lifemankind user token from local users table $accessToken = self::resolveContactAccessToken($domain); if ($accessToken === '') { Log::warning('TGICS WhatsApp validation: no contact access token for domain '.$domain); - return array_fill_keys($ids, false); + return $status; } - $status = array_fill_keys($ids, false); foreach ($ids as $id) { try { $resp = LambdaRequest::getrequest('contact', 'contact/get_one', ['id' => $id], $accessToken); $item = $resp->data->item ?? null; $validated = self::contactHasWhatsappValidated($item); $status[$id] = $validated; - Log::info('[TGICS_WA_STATUS] contact lookup', [ + Log::info('[TGICS_WA_STATUS] contact lookup fallback', [ 'contact_id' => $id, 'validated' => $validated, 'flag' => $item->tgics_whatsapp_validated ?? ($item->attribute_tgics_whatsapp_validated ?? null), From f960b2ad3d4951013ccdbbd18dcf62ece54d7b0e Mon Sep 17 00:00:00 2001 From: zeeshan Date: Wed, 4 Nov 2026 15:58:36 +0530 Subject: [PATCH 09/10] Team 4 (Montair LC Kid ABM Conversion) --- .../1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php index 0029835c..ed3c31b5 100644 --- a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php +++ b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php @@ -44,10 +44,10 @@ $submissions = Formhelper::getMultiformData( $form->partition, $form_id, $form->user_id); $submissions = $submissions->data->submissions; - + @endphp - @if($submissions && count($submissions) <=4) + @if(count($submissions) <=4)
From bd10ea014c6d0a22c3d5eafa2c92f2bcf4052273 Mon Sep 17 00:00:00 2001 From: zeeshan Date: Wed, 4 Nov 2026 16:05:59 +0530 Subject: [PATCH 10/10] Team 4 (Montair LC Kid ABM Conversion) Printing Submission --- .../1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php index ed3c31b5..6d1fff65 100644 --- a/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php +++ b/resources/views/form/rapport-team4/1793785288-f76eca22-0891-4e77-88e8-56b43dd57c5e.blade.php @@ -44,7 +44,9 @@ $submissions = Formhelper::getMultiformData( $form->partition, $form_id, $form->user_id); $submissions = $submissions->data->submissions; - + echo "
";
+                            print_r($submissions);
+                            echo "
"; @endphp @if(count($submissions) <=4)