Rapport-Laravel/resources/views/form/rapport-oncocare/1761902573-540017be-706b-4f...

1418 lines
89 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
@include('layouts.shared/title-meta', ['title' => 'Form'])
@include('layouts.shared/head-css', ['mode' => $mode ?? '', 'demo' => $demo ?? ''])
<link href="{{ asset('assets/libs/sweetalert2/sweetalert2.min.css') }}" rel="stylesheet" type="text/css" />
</head>
<div id="pageloader">
<img src="http://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif" alt="processing..." />
</div>
@php
// echo "<pre>";
// print_r($form);
// exit;
@endphp
<body class="loading">
<div class="account-pages">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-6 col-xl-5 p-0">
<div class="card bg-pattern">
<div class="card-body p-3 row">
@if (Session::has('error'))
<div class="alert alert-danger">{{ Session::get('error') }}</div>
<br>
@endif
@if (session('success'))
<div class=" alert alert-success">{{ session('success') }}
</div>
<br>
@endif
<div class="col-8">
<h4 class="page-title">{{ $form->title }}</h4>
</div>
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
<div class="col-4">
@if ($form->link_type == 'form')
<!-- <a href="/form/history" class="float-end pt-1">View History</a> -->
<button type="button" class="btn btn-primary btn-xs" id="add-camp-btn">Add
Plan</button>
@else
<a href="{{ url()->previous() }}" class="float-end pt-1">Back</a>
@endif
</div>
@endif
@php
$history = Formhelper::getMultiformData(
$form->partition,
$form->form_id,
$form->user_id,
);
// echo "<pre>";
// print_r($history);
@endphp
@php
$plannedBrandData = [
[
'brand' => 'ENCICARB 1K',
'slug' => 'secondary_sales_tracker_planned_encicarb_1k_values',
// 'pseudoId' => 'secondary_sales_planned_encicarb_1k_values',
'total_slug' => 'secondary_sales_tracker_planned_encicarb_1k_total_values',
// 'total_slug_value' => 'secondary_sales_planned_encicarb_1k_total_values',
],
[
'brand' => 'EMBREMMA',
'slug' => 'secondary_sales_tracker_planned_embremma_values',
// 'pseudoId' => 'secondary_sales_tracker_planned_embremma_values',
'total_slug' => 'secondary_sales_tracker_planned_embremma_total_values',
// 'total_slug_value' => 'secondary_sales_tracker_planned_embremma_total_values',
],
[
'brand' => 'SOMALINX-LAR',
'slug' => 'secondary_sales_tracker_planned_somalinx_lar_values',
// 'pseudoId' => 'secondary_sales_tracker_planned_somalinx_lar_values',
'total_slug' => 'secondary_sales_tracker_planned_somalinx_lar_total_values',
// 'total_slug_value' => 'secondary_sales_tracker_planned_somalinx_lar_total_values',
],
[
'brand' => 'Enzuta 40mg',
'slug' => 'secondary_sales_tracker_planned_enzuta_40mg_values',
// 'pseudoId' => 'secondary_sales_tracker_planned_enzuta_40mg_values',
'total_slug' => 'secondary_sales_tracker_planned_enzuta_40mg_total_values',
// 'total_slug_value' => 'secondary_sales_tracker_planned_enzuta_40mg_total_values',
],
[
'brand' => 'Others',
'slug' => 'secondary_sales_tracker_planned_others_values',
// 'pseudoId' => 'secondary_sales_tracker_planned_enzuta_40mg_values',
'total_slug' => 'secondary_sales_tracker_planned_others_total_values',
// 'total_slug_value' => 'secondary_sales_tracker_planned_enzuta_40mg_total_values',
],
[
'brand' => 'Grand Total',
'slug' => 'secondary_sales_tracker_planned_grand_total',
// 'pseudoId' => 'secondary_sales_tracker_planned_enzuta_40mg_values',
'total_slug' => 'secondary_sales_tracker_planned_grand_total_values',
// 'total_slug_value' => 'secondary_sales_tracker_planned_enzuta_40mg_total_values',
],
];
$executionBrandData = [
[
'brand' => 'ENCICARB 1K',
'slug' => 'secondary_sales_tracker_execution_encicarb_1k_values',
// 'pseudoId' => 'secondary_sales_tracker_execution_encicarb_1k_values',
'total_slug' => 'secondary_sales_tracker_execution_encicarb_1k_total_values',
// 'total_slug_value' => 'secondary_sales_tracker_execution_encicarb_1k_total_values',
],
[
'brand' => 'EMBREMMA',
'slug' => 'secondary_sales_tracker_execution_embremma_values',
// 'pseudoId' => 'secondary_sales_tracker_execution_embremma_values',
'total_slug' => 'secondary_sales_tracker_execution_embremma_total_values',
// 'total_slug_value' => 'secondary_sales_tracker_execution_embremma_total_values',
],
[
'brand' => 'SOMALINX-LAR',
'slug' => 'secondary_sales_tracker_execution_somalinx_lar_values',
// 'pseudoId' => 'secondary_sales_tracker_execution_somalinx_lar_values',
'total_slug' => 'secondary_sales_tracker_execution_somalinx_lar_total_values',
// 'total_slug_value' => 'secondary_sales_tracker_execution_somalinx_lar_total_values',
],
[
'brand' => 'Enzuta 40mg',
'slug' => 'secondary_sales_tracker_execution_enzuta_40mg_values',
// 'pseudoId' => 'secondary_sales_tracker_execution_enzuta_40mg_values',
'total_slug' => 'secondary_sales_tracker_execution_enzuta_40mg_total_values',
// 'total_slug_value' => 'secondary_sales_tracker_execution_enzuta_40mg_total_values',
],
[
'brand' => 'Others',
'slug' => 'secondary_sales_tracker_execution_others_values',
// 'pseudoId' => 'secondary_sales_tracker_execution_enzuta_40mg_values',
'total_slug' => 'secondary_sales_tracker_execution_others_total_values',
// 'total_slug_value' => 'secondary_sales_tracker_execution_enzuta_40mg_total_values',
],
[
'brand' => 'Grand Total',
'slug' => 'secondary_sales_tracker_execution_grand_total',
// 'pseudoId' => 'secondary_sales_tracker_execution_enzuta_40mg_values',
'total_slug' => 'secondary_sales_tracker_execution_grand_total_values',
// 'total_slug_value' => 'secondary_sales_tracker_execution_enzuta_40mg_total_values',
],
];
$weeks = [1, 2, 3, 4];
@endphp
@php
usort($history->data->submissions, function ($a, $b) {
$dateA = isset($a->formdata->plan_date)
? \Carbon\Carbon::createFromFormat('Y-m-d', $a->formdata->plan_date)->timestamp
: 0;
$dateB = isset($b->formdata->plan_date)
? \Carbon\Carbon::createFromFormat('Y-m-d', $b->formdata->plan_date)->timestamp
: 0;
return $dateB <=> $dateA; // descending
});
@endphp
<div class="col-md-12" id="table-wrapper">
<div class="card">
<div class="card-body p-0">
<div class="table-responsive">
<table
class="table table-striped table-hover table-nowrap table-centered m-0">
<thead class="table-light">
<tr>
<th>Status</th>
<th>Action</th>
<th>Execution Done</th>
<th>Plan Date</th>
<th>Execution Date</th>
</tr>
</thead>
<tbody>
@foreach ($history->data->submissions as $sub)
@php
$sub->formdata->id = $sub->id;
@endphp
<tr>
<td>{{ $sub->workflow_status }}</td>
<td>
@if ($sub->workflow_status == 'approved')
<button type="button"
class="btn btn-xs btn-info edit-btn"
plan_details="{{ json_encode($sub->formdata) }}">
<i class="mdi mdi-pencil"></i> Execute
</button>
{{-- @elseif (
$sub->workflow_status == 'approved' ||
$sub->workflow_status == 'unapproved' ||
!empty($sub->formdata->patient_tracker_execution_date)) --}}
@elseif ($sub->workflow_status == 'rejected')
<button type="button"
class="btn btn-xs btn-info edit-plan-btn"
plan_details="{{ json_encode($sub->formdata) }}">
<i class="mdi mdi-pencil"></i> Edit Plan
</button>
@endif
</td>
<td>{{ isset($sub->formdata->patient_tracker_execution_date) && $sub->formdata->patient_tracker_execution_date > 0 ? 'Yes' : 'No' }}
</td>
<td>{{ $sub->formdata->plan_date }}</td>
<td>{{ isset($sub->formdata->patient_tracker_execution_date) ? $sub->formdata->patient_tracker_execution_date : '' }}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
<div id="form-wrapper">
<form method="POST" action="/form/submit" id="report-form">
<input type="hidden" name="form_id" value="{{ $form_id }}">
@csrf
@if (isset($form->manager_can_submit) && $form->manager_can_submit == true)
<div class="col-md-12 mb-2">
<label for="field-user_id" class="form-label"> Select User / Territory <span
class="text-danger">*</span> </label>
<select class="form-control" id="field-territory_tm_user_id"
name="territory_tm_user_id" required>
<option value=""> -- Select -- </option>
@foreach ($form->users as $option)
@php
$shortLabel = trim(explode(' - Territory', $option->display)[0]);
@endphp
<option value="{{ $shortLabel }}"
hierarchy="{{ $option->hierarchy_id }}"
{{ isset($question->value) && $question->value == $shortLabel ? 'selected' : '' }}>
{{ $shortLabel }}
</option>
@endforeach
</select>
<input type="hidden" id="field-hierarchy_id" name="hierarchy_id"
value="">
</div>
@endif
@foreach ($questions as $question)
@if (in_array($question->code, ['execution_date', 'exe_values_for_the_week_selected']))
@continue
@endif
<div class="col-md-12 mb-2">
<label for="field-{{ $question->code }}"
class="form-label">{{ $question->question }} {!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!}
</label>
@switch($question->type)
@case('hidden')
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
name="{{ $question->code }}"
value="{{ isset($question->value) ? $question->value : '' }}">
@break
@case('text')
@case('email')
@case('tel')
@case('date')
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
name="{{ $question->code }}" class="form-control"
{{ $question->required == 'yes' ? 'required' : '' }}
value="{{ isset($question->value) ? $question->value : '' }}">
@break
@case('number')
<input type="{{ $question->type }}" min="0" max="9999999999"
step="1" id="field-{{ $question->code }}"
name="{{ $question->code }}" class="form-control"
{{ $question->required == 'yes' ? 'required' : '' }}
value="{{ isset($question->value) ? $question->value : 0 }}">
@break
@case('textarea')
<textarea id="field-{{ $question->code }}" name="{{ $question->code }}" class="form-control"
{{ $question->required == 'yes' ? 'required' : '' }}>{{ isset($question->value) ? $question->value : '' }}</textarea>
@break
@case('dropdown')
@if ($question->code == 'contact_id')
<select class="form-control" id="field-{{ $question->code }}"
name="{{ $question->code }}"
{{ $question->required == 'yes' ? 'required' : '' }}>
<option value=""> -- Select -- </option>
@foreach ($question->options as $option)
@if ($option->contact->type == 'doctor')
<option value="{{ $option->value }}"
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
uid="{{ isset($option->contact->uid) ? $option->contact->uid : '' }}"
speciality="{{ isset($option->contact->speciality) ? $option->contact->speciality : '' }}">
{{ $option->display }}
</option>
@endif
@endforeach
</select>
@elseif($question->code == 'hospital_name')
<select class="form-control" id="field-{{ $question->code }}"
name="{{ $question->code }}"
{{ $question->required == 'yes' ? 'required' : '' }}>
<option value=""> -- Select -- </option>
@foreach ($question->options as $option)
@if (isset($option->contact->type) && $option->contact->type == 'hospital')
<option value="{{ $option->value }}" {{-- dd={{print_r($option)}} --}}
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
city="{{ isset($option->contact->city) ? $option->contact->city : '' }}">
{{ $option->display }}</option>
@endif
@endforeach
</select>
@else
<select class="form-control" id="field-{{ $question->code }}"
name="{{ $question->code }}"
{{ $question->required == 'yes' ? 'required' : '' }}>
<option value=""> -- Select -- </option>
@foreach ($question->options as $option)
<option value="{{ $option->value }}"
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
{{ $option->display }}</option>
@endforeach
</select>
@endif
@break
@case('checkbox')
@foreach ($question->options as $option)
<div class="form-check mb-2 form-check-primary">
<input class="form-check-input" type="checkbox"
id="field-{{ $question->code }}-{{ $option->value }}"
name="{{ $question->code }}[]" value="{{ $option->value }}"
{{ isset($question->value) && $question->value != '' && in_array($option->value, $question->value) ? 'checked' : '' }}>
<label class="form-check-label"
for="field-{{ $question->code }}-{{ $option->value }}">{{ $option->display }}</label>
</div>
@endforeach
@break
@case('multitextbox')
<div class="row">
<div
style="width: auto; overflow-y: auto; overflow-x: auto; border: 1px solid #0d6efd; border-radius: 3px; padding: 10px; margin-bottom: 10px;">
<table class="table tableclass">
<thead id="heading">
<tr>
<th>Brand Name</th>
@foreach ($weeks as $week)
<th class="text-center">W{{ $week }}
Planned Total Value*</th>
@endforeach
<th>Total Week Planned Values</th>
</tr>
</thead>
<tbody>
@foreach ($plannedBrandData as $brand)
<tr>
<td>{{ $brand['brand'] }}</td>
@foreach ($weeks as $week)
<td>
<input type="number"
id="field-{{ $brand['slug'] }}_w{{ $week }}"
name="{{ $brand['slug'] }}_w{{ $week }}"
class="form-control form-control-large"
style="width:90px;"
value="{{ $id && isset($formdata) && isset($formdata->{$brand['slug']}) ? $formdata->{$brand['slug']} : 0 }}"
required min="0">
</td>
{{-- <td>
<input type="number"
id="field-{{ $brand['pseudoId'] }}_w{{ $week }}"
name="{{ $brand['pseudoId'] }}_w{{ $week }}"
class="form-control form-control-large"
style="width:100px;"
value="{{ $id && isset($formdata) && isset($formdata->{$brand['pseudoId']}) ? $formdata->{$brand['pseudoId']} : 0 }}"
required>
</td> --}}
@endforeach
<td class="text-center fw-bold total-cell"
id="total-{{ $brand['slug'] }}">
<input type="number"
id="field-{{ $brand['total_slug'] }}"
name="{{ $brand['total_slug'] }}"
class="form-control form-control-large"
style="width:100px;" min="0"
value="{{ $id && isset($formdata) && isset($formdata->{$brand['total_slug']}) ? $formdata->{$brand['total_slug']} : 0 }}"
required>
</td>
{{-- <td class="text-center fw-bold total-cell"
id="total-{{ $brand['slug'] }}">
<input type="number"
id="field-{{ $brand['total_slug_value'] }}"
name="{{ $brand['total_slug_value'] }}"
class="form-control form-control-large"
style="width:100px;"
value="{{ $id && isset($formdata) && isset($formdata->{$brand['total_slug_value']}) ? $formdata->{$brand['total_slug_value']} : 0 }}"
required>
</td> --}}
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@break
@endswitch
</div>
@endforeach
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
<div class="text-center d-grid mt-3">
<button class="btn btn-primary" type="submit" id="submit-btn"> Submit
</button>
</div>
@endif
</form>
</div>
<div id="execution-form-wrapper">
<form method="POST" action="/form/submit" id="execution-form"
enctype="multipart/form-data">
<input type="hidden" name="form_id" value="{{ $form_id }}">
@csrf
{{-- @if (isset($form->manager_can_submit) && $form->manager_can_submit == true)
<div class="col-md-12 mb-2">
<label for="execution-user_id" class="form-label"> Select User / Territory
<span class="text-danger">*</span> </label>
<select class="form-control" id="execution-territory_tm_user_id"
name="territory_tm_user_id" required>
<option value=""> -- Select -- </option>
@foreach ($form->users as $option)
<option value="{{ $option->display }}"
hierarchy="{{ $option->hierarchy_id }}"
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
{{ $option->display }}</option>
@endforeach
</select>
<input type="hidden" id="execution-hierarchy_id" name="hierarchy_id"
value="">
</div>
@endif --}}
@if (isset($form->manager_can_submit) && $form->manager_can_submit == true)
<div class="col-md-12 mb-2">
<label for="execution-user_id" class="form-label"> Select User / Territory
<span class="text-danger">*</span> </label>
<select class="form-control" id="execution-territory_tm_user_id"
name="territory_tm_user_id" required>
<option value=""> -- Select -- </option>
@foreach ($form->users as $option)
@php
$shortLabel = trim(explode(' - Territory', $option->display)[0]);
@endphp
<option value="{{ $shortLabel }}"
hierarchy="{{ $option->hierarchy_id }}"
{{ isset($question->value) && $question->value == $shortLabel ? 'selected' : '' }}>
{{ $shortLabel }}</option>
@endforeach
</select>
<input type="hidden" id="execution-hierarchy_id" name="hierarchy_id"
value="">
</div>
@endif
<input type="hidden" name="id" value="" id="execution-id">
@foreach ($questions as $question)
<div class="col-md-12 mb-2">
<label for="execution-{{ $question->code }}"
class="form-label">{{ $question->question }} {!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!}
</label>
@switch($question->type)
@case('hidden')
<input type="{{ $question->type }}" id="execution-{{ $question->code }}"
name="{{ $question->code }}"
value="{{ isset($question->value) ? $question->value : '' }}">
@break
@case('text')
@case('email')
@case('tel')
@case('date')
<input type="{{ $question->type }}" id="execution-{{ $question->code }}"
name="{{ $question->code }}" class="form-control"
{{ $question->required == 'yes' ? 'required' : '' }}
value="{{ isset($question->value) ? $question->value : '' }}">
@break
@case('number')
<input type="{{ $question->type }}" min="0" max="9999999999"
step="1" id="execution-{{ $question->code }}"
name="{{ $question->code }}" class="form-control"
{{ $question->required == 'yes' ? 'required' : '' }}
value="{{ isset($question->value) ? $question->value : 0 }}">
@break
@case('textarea')
<textarea id="execution-{{ $question->code }}" name="{{ $question->code }}" class="form-control"
{{ $question->required == 'yes' ? 'required' : '' }}>{{ isset($question->value) ? $question->value : '' }}</textarea>
@break
@case('dropdown')
@if ($question->code == 'contact_id')
<select class="form-control" id="execution-{{ $question->code }}"
name="{{ $question->code }}"
{{ $question->required == 'yes' ? 'required' : '' }}>
<option value=""> -- Select -- </option>
@foreach ($question->options as $option)
@if ($option->contact->type == 'doctor')
<option value="{{ $option->value }}"
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
uid="{{ isset($option->contact->uid) ? $option->contact->uid : '' }}"
speciality="{{ isset($option->contact->speciality) ? $option->contact->speciality : '' }}">
{{ $option->display }}
</option>
@endif
@endforeach
</select>
@elseif($question->code == 'hospital_name')
<select class="form-control" id="execution-{{ $question->code }}"
name="{{ $question->code }}"
{{ $question->required == 'yes' ? 'required' : '' }}>
<option value=""> -- Select -- </option>
@foreach ($question->options as $option)
@if (isset($option->contact->type) && $option->contact->type == 'hospital')
<option value="{{ $option->value }}"
{{-- dd={{print_r($option)}} --}}
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
city="{{ isset($option->contact->city) ? $option->contact->city : '' }}">
{{ $option->display }}</option>
@endif
@endforeach
</select>
@else
<select class="form-control" id="execution-{{ $question->code }}"
name="{{ $question->code }}"
{{ $question->required == 'yes' ? 'required' : '' }}>
<option value=""> -- Select -- </option>
@foreach ($question->options as $option)
<option value="{{ $option->value }}"
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
{{ $option->display }}</option>
@endforeach
</select>
@endif
@break
@case('checkbox')
@foreach ($question->options as $option)
<div class="form-check mb-2 form-check-primary">
<input class="form-check-input" type="checkbox"
id="execution-{{ $question->code }}-{{ $option->value }}"
name="{{ $question->code }}[]"
value="{{ $option->value }}"
{{ isset($question->value) && $question->value != '' && in_array($option->value, $question->value) ? 'checked' : '' }}>
<label class="form-check-label"
for="execution-{{ $question->code }}-{{ $option->value }}">{{ $option->display }}</label>
</div>
@endforeach
@break
@case('file')
<input type="file" id="execution-{{ $question->code }}"
name="{{ $question->code }}" class="form-control" value=""
accept="image/jpg, image/jpeg, image/png">
@break
@case('multitextbox')
{{-- @php echo "<pre>"; print_r($question->code); @endphp --}}
@if ($question->code == 'values_for_the_week_selected')
<div class="row">
<div
style="width: auto; overflow-y: auto; overflow-x: auto; border: 1px solid #0d6efd; border-radius: 3px; padding: 10px; margin-bottom: 10px;">
<table class="table tableclass">
<thead id="heading">
<tr>
<th>Brand Name</th>
@foreach ($weeks as $week)
<th class="text-center">W{{ $week }}
Total Planned Value*</th>
@endforeach
<th>Total Week Planned Values</th>
</tr>
</thead>
<tbody>
@foreach ($plannedBrandData as $brand)
<tr>
<td>{{ $brand['brand'] }}</td>
@foreach ($weeks as $week)
<td>
<input type="number"
id="execution-{{ $brand['slug'] }}_w{{ $week }}"
name="{{ $brand['slug'] }}_w{{ $week }}"
class="form-control form-control-large"
value="{{ $id && isset($formdata) && isset($formdata->{$brand['slug']}) ? $formdata->{$brand['slug']} : 0 }}"
style="width:90px;" required
min="0">
</td>
{{-- <td>
<input type="number"
id="execution-{{ $brand['pseudoId'] }}_w{{ $week }}"
name="{{ $brand['pseudoId'] }}_w{{ $week }}"
class="form-control form-control-large"
value="{{ $id && isset($formdata) && isset($formdata->{$brand['pseudoId']}) ? $formdata->{$brand['pseudoId']} : 0 }}"
style="width:100px;" required
min="1">
</td> --}}
@endforeach
<td class="text-center fw-bold total-cell"
id="total-{{ $brand['total_slug'] }}">
<input type="number"
id="execution-{{ $brand['total_slug'] }}"
name="{{ $brand['total_slug'] }}"
class="form-control form-control-large"
style="width:100px;"
test="{{ isset($formdata) ? print_r($formdata) : '' }}"
value="{{ isset($formdata) && isset($formdata->patient_tracker_planned_encicarb_1k_total_units) ? $formdata->patient_tracker_planned_encicarb_1k_total_units : 0 }}"
required>
</td>
{{-- <td class="text-center fw-bold total-cell"
id="total-{{ $brand['total_slug'] }}">
<input type="number"
id="execution-{{ $brand['total_slug_value'] }}"
name="{{ $brand['total_slug_value'] }}"
class="form-control form-control-large"
style="width:100px;"
value="{{ isset($formdata) && isset($formdata->patient_tracker_planned_encicarb_1k_total_values) ? $formdata->patient_tracker_planned_encicarb_1k_total_values : 0 }}"
required>
</td> --}}
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@elseif($question->code == 'exe_values_for_the_week_selected')
<div class="row" id="execution-row">
<div
style="width: auto; overflow-y: auto; overflow-x: auto; border: 1px solid #0d6efd; border-radius: 3px; padding: 10px; margin-bottom: 10px;">
<table class="table tableclass">
<thead id="heading">
<tr>
<th>Brand Name</th>
@foreach ($weeks as $week)
<th class="text-center">W{{ $week }}
Actual Total Value*</th>
@endforeach
<th>Total Week Actual Values</th>
</tr>
</thead>
<tbody>
@foreach ($executionBrandData as $brand)
<tr>
<td>{{ $brand['brand'] }}</td>
@foreach ($weeks as $week)
<td>
<input type="number"
id="execution-{{ $brand['slug'] }}_w{{ $week }}"
name="{{ $brand['slug'] }}_w{{ $week }}"
class="form-control form-control-large"
style="width:90px;"
value="{{ $id && isset($formdata) && isset($formdata->{$brand['slug']}) ? $formdata->{$brand['slug']} : 0 }}"
required min="0">
</td>
{{-- <td>
<input type="number"
id="execution-{{ $brand['pseudoId'] }}_w{{ $week }}"
name="{{ $brand['pseudoId'] }}_w{{ $week }}"
class="form-control form-control-large"
style="width:100px;"
value="{{ $id && isset($formdata) && isset($formdata->{$brand['pseudoId']}) ? $formdata->{$brand['pseudoId']} : 0 }}"
required>
</td> --}}
@endforeach
<td class="text-center fw-bold total-cell"
id="total-{{ $brand['slug'] }}">
<input type="number"
id="execution-{{ $brand['total_slug'] }}"
name="{{ $brand['total_slug'] }}"
class="form-control form-control-large"
style="width:100px;"
value="{{ $id && isset($formdata) && isset($formdata->{$brand['total_slug']}) ? $formdata->{$brand['total_slug']} : 0 }}"
required>
</td>
{{-- <td class="text-center fw-bold total-cell"
id="total-{{ $brand['slug'] }}">
<input type="number"
id="execution-{{ $brand['total_slug_value'] }}"
name="{{ $brand['total_slug_value'] }}"
class="form-control form-control-large"
style="width:100px;"
value="{{ $id && isset($formdata) && isset($formdata->{$brand['total_slug_value']}) ? $formdata->{$brand['total_slug_value']} : 0 }}"
required>
</td> --}}
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endif
@break
@endswitch
</div>
@endforeach
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
<div class="text-center d-grid mt-3">
<button class="btn btn-primary" type="submit" id="submit-btn"> Submit
</button>
</div>
@endif
</form>
</div>
</div> <!-- end card-body -->
</div>
<!-- end card -->
<!-- end row -->
</div> <!-- end col -->
</div>
<!-- end row -->
</div>
<!-- end container -->
</div>
<!-- end page -->
<style type="text/css">
#pageloader {
background: rgba(255, 255, 255, 0.8);
display: none;
height: 100%;
position: fixed;
width: 100%;
z-index: 9999;
}
#pageloader img {
left: 50%;
margin-left: -32px;
margin-top: -32px;
position: absolute;
top: 50%;
}
</style>
@include('layouts.shared/footer-script')
<script src="{{ asset('assets/libs/sweetalert2/sweetalert2.min.js') }}"></script>
<script type="text/javascript">
$('#field-tm_user_id').closest('div').hide();
$('#execution-tm_user_id').closest('div').hide();
$('#form-wrapper').hide()
$('#execution-form-wrapper').hide()
$('[id*="total_values"]').prop('readonly', true);
$('#field-uid').prop("readonly", true);
$('#field-speciality').prop("readonly", true);
$('#field-plan_date').on('change', function() {
let dateVal = $(this).val();
if (dateVal) {
let dateObj = new Date(dateVal);
let monthName = dateObj.toLocaleString('default', {
month: 'long'
});
let year = dateObj.getFullYear();
$('#field-month').val(monthName);
} else {
$('#field-month').val('');
}
});
$('#field-contact_id').change(function() {
$('#field-uid').val($('option:selected', this).attr('uid'))
});
$('#field-contact_id').change(function() {
$('#field-speciality').val($('option:selected', this).attr('speciality'))
});
const disableplanbrands = ['patient_tracker_planned_encicarb_1k_units', 'patient_tracker_planned_embremma_units',
'patient_tracker_planned_somalinx_lar_units', 'patient_tracker_planned_enzuta_40_units'
];
disableplanbrands.forEach(function(brand) {
$(`#field-${brand}_w1, #field-${brand}_w2, #field-${brand}_w3, #field-${brand}_w4`).on('input',
function() {
$(`#total-${brand} #field-patient_tracker_planned_total_units`).prop('readonly', true);
});
});
const disableexebrands = ['patient_tracker_execution_encicarb_1k_units', 'patient_tracker_execution_embremma_units',
'patient_tracker_execution_somalinx_lar_units', 'patient_tracker_execution_enzuta_40_units'
];
disableexebrands.forEach(function(brand) {
$(`#execution-${brand}_w1, #execution-${brand}_w2, #execution-${brand}_w3, #execution-${brand}_w4`).on(
'input',
function() {
$(`#total-${brand} #execution-patient_tracker_execution_total_units`).prop('readonly',
true);
});
});
const baseValues = {
encicarb_1k: 2140,
embremma: 7000,
somalinx_lar: 9350,
enzuta_40mg: 10800
};
$('#add-camp-btn').click(function() {
$('#form-wrapper').show()
$('#table-wrapper').hide()
$('#execution-form-wrapper').hide()
$('#field-other_activity').closest('.col-md-12').hide();
$('#field-uid').prop("readonly", true);
$('#field-speciality').prop("readonly", true);
$('#field-city').prop("readonly", true);
$('#field-plan_date').on('change', function() {
let dateVal = $(this).val();
if (dateVal) {
let dateObj = new Date(dateVal);
let monthName = dateObj.toLocaleString('default', {
month: 'long'
});
let year = dateObj.getFullYear();
$('#field-month').val(monthName);
} else {
$('#field-month').val('');
}
});
$('#field-contact_id').change(function() {
$('#field-uid').val($('option:selected', this).attr('uid'))
});
$('#field-contact_id').change(function() {
$('#field-speciality').val($('option:selected', this).attr('speciality'))
});
$('#field-hospital_name').change(function() {
$('#field-city').val($('option:selected', this).attr('city'))
});
$('#field-territory_tm_user_id').on('change', function() {
const selectedText = $(this).find('option:selected').text().trim();
$('#field-tm_user_id').val(selectedText);
});
const brands = [
'patient_tracker_planned_encicarb_1k_units',
'patient_tracker_planned_embremma_units',
'patient_tracker_planned_somalinx_lar_units',
'patient_tracker_planned_enzuta_40mg_units'
];
brands.forEach(function(brand) {
$(`#field-${brand}_w1, #field-${brand}_w2, #field-${brand}_w3, #field-${brand}_w4`).on(
'input',
function() {
let total = 0;
for (let i = 1; i <= 4; i++) {
total += parseFloat($(`#field-${brand}_w${i}`).val()) || 0;
}
$(`#total-${brand} #field-patient_tracker_planned_total_units`).val(total);
});
});
$('input[id*="_values_w"]').on('input', function() {
const id = $(this).attr('id');
const brand = id.split('_values_')[0].replace('field-', '');
let total = 0;
for (let i = 1; i <= 4; i++) {
const val = parseFloat($(`#field-${brand}_values_w${i}`).val()) || 0;
total += val;
}
const totalField = $(`#field-${brand}_total_values`);
if (totalField.length) {
totalField.val(total);
}
for (let i = 1; i <= 4; i++) {
let colTotal = 0;
$(`input[id^="field-secondary_sales_tracker_planned_"][id*="_values_w${i}"]`).each(
function() {
if (!$(this).attr('id').includes('grand_total')) {
colTotal += parseFloat($(this).val()) || 0;
}
});
$(`#field-secondary_sales_tracker_planned_grand_total_w${i}`).val(colTotal);
}
let finalGrandTotal = 0;
$(`input[id^="field-secondary_sales_tracker_planned_"][id*="_total_values"]`).each(
function() {
if (!$(this).attr('id').includes('grand_total')) {
finalGrandTotal += parseFloat($(this).val()) || 0;
}
});
$(`#field-secondary_sales_tracker_planned_grand_total_values`).val(finalGrandTotal);
});
$(document).ready(function() {
$('input[id*="grand_total"]').attr('readonly', true);
});
// $('input[id*="_total_units"], input[id*="_total_values"]').prop('readonly', true);
});
$('.edit-btn').click(function() {
$('#execution-plan_date, #execution-month, #execution-patient_tracker_planned_brand_1_units, #execution-patient_tracker_planned_brand_2_units, #execution-patient_tracker_planned_brand_3_units, #execution-patient_tracker_planned_brand_4_units, #execution-patient_tracker_planned_brand_1_values, #execution-patient_tracker_planned_brand_2_values, #execution-patient_tracker_planned_brand_3_values, #execution-patient_tracker_planned_brand_4_values, #execution-city')
.prop('readonly', true);
$('#execution-uid').prop("readonly", true);
$('#execution-speciality').prop("readonly", true);
$('#execution-contact_id, #execution-hospital_name, #execution-record_week, #execution-territory_tm_user_id')
.on('mousedown keydown', function(e) {
e.preventDefault();
});
$('#execution-territory_tm_user_id').on('change', function() {
const selectedText = $(this).find('option:selected').text().trim();
$('#execution-tm_user_id').val(selectedText);
});
$('input[id^="execution-secondary_sales_tracker_planned"]').prop('readonly', true);
let selected = JSON.parse($(this).attr('plan_details'))
for (let k of Object.keys(selected)) {
if (selected[k] != '') {
$('#execution-' + k).val(selected[k]);
}
}
let instid = $('#execution-hospital_name option').map(function() {
if ($(this).text().trim() == selected['hospital_name']) return this;
}).attr('value')
$('#execution-hospital_name').val(instid)
let docid = $('#execution-contact_id option').map(function() {
if ($(this).text().trim() == selected['contact_id']) return this;
}).attr('value')
let tmid = $('#execution-territory_tm_user_id option').map(function() {
if ($(this).text().trim() == selected['territory_tm_user_id']) return this;
}).attr('value')
$('#execution-contact_id').val(docid)
$('#execution-territory_tm_user_id').val(tmid)
$('#execution-id').val(selected['id'])
$('#form-wrapper').hide()
$('#execution-form-wrapper').show()
$('#table-wrapper').hide()
$('input[id*="_units_w"]').on('input', function() {
const id = $(this).attr('id');
const brand = id.split('_units_')[0].replace('execution-patient_tracker_execution_', '');
const week = id.split('_units_')[1];
const units = parseFloat($(this).val()) || 0;
const valueField1 = $(`#execution-patient_tracker_execution_${brand}_values_${week}`);
const valueField2 = $(`#execution-patient_tracker_execution_${brand}_units_values_${week}`);
if (baseValues[brand]) {
const calc = units * baseValues[brand];
console.log(`→ calculated: ${calc}`);
if (valueField1.length) {
valueField1.val(calc.toFixed(2));
} else if (valueField2.length) {
valueField2.val(calc.toFixed(2));
} else {
console.warn("⚠ No matching value field found for:", brand, week);
}
} else {
console.warn("⚠ No base value found for brand:", brand);
}
});
$('input[id*="_values_w"]').on('input', function() {
const id = $(this).attr('id');
const brand = id.split('_values_')[0].replace('execution-', '');
let total = 0;
// --- Row total calculation (W1–W4 → Total) ---
for (let i = 1; i <= 4; i++) {
const val = parseInt($(`#execution-${brand}_values_w${i}`).val()) || 0;
total += val;
}
const totalField = $(`#execution-${brand}_total_values`);
if (totalField.length) {
totalField.val(total);
}
// --- Column-wise totals (each week → Grand Total row) ---
for (let i = 1; i <= 4; i++) {
let colTotal = 0;
$(`input[id^="execution-secondary_sales_tracker_execution_"][id*="_values_w${i}"]`)
.each(function() {
if (!$(this).attr('id').includes('grand_total')) {
colTotal += parseInt($(this).val()) || 0;
}
});
$(`#execution-secondary_sales_tracker_execution_grand_total_w${i}`).val(colTotal);
}
// --- Final Grand Total (sum of all row totals) ---
let finalGrandTotal = 0;
$(`input[id^="execution-secondary_sales_tracker_execution_"][id*="_total_values"]`).each(
function() {
if (!$(this).attr('id').includes('grand_total')) {
finalGrandTotal += parseInt($(this).val()) || 0;
}
});
$(`#execution-secondary_sales_tracker_execution_grand_total_values`).val(finalGrandTotal);
});
$(document).ready(function() {
$('input[id*="grand_total"]').attr('readonly', true);
});
// $('input[id*="_total_units"], input[id*="_total_values"]').prop('readonly', true);
})
$('.edit-plan-btn').click(function() {
$('#execution-plan_date').on('change', function() {
let dateVal = $(this).val();
if (dateVal) {
let dateObj = new Date(dateVal);
let monthName = dateObj.toLocaleString('default', {
month: 'long'
});
let year = dateObj.getFullYear();
$('#execution-month').val(monthName);
} else {
$('#execution-month').val('');
}
});
$('#execution-contact_id').change(function() {
$('#execution-uid').val($('option:selected', this).attr('uid'))
});
$('#execution-contact_id').change(function() {
$('#execution-speciality').val($('option:selected', this).attr('speciality'))
});
$('#execution-territory_tm_user_id').on('change', function() {
const selectedText = $(this).find('option:selected').text().trim();
$('#execution-tm_user_id').val(selectedText);
});
$('#execution-hospital_name').change(function() {
$('#execution-city').val($('option:selected', this).attr('city'))
});
$('#execution-city').prop("readonly", true);
$('#execution-uid').prop("readonly", true);
$('#execution-speciality').prop("readonly", true);
$('#execution-form-wrapper').show(100, () => {
$('#add-camp-btn').hide(0);
})
$('#table-wrapper').hide();
$('#execution-row').prev('label').hide();
$('#execution-row').hide();
$('#execution-execution_date').hide();
$('#execution-execution_date').prev('label').hide();
$('#execution-execution_date').prop("required", false);
let selected = JSON.parse($(this).attr('plan_details'));
if (selected['contact_id']) {
selected['contact_id'] = selected['contact_id'].trim();
}
if (selected['activity'] === 'OTHERS') {
console.log(selected['activity'])
$('#execution-other_activity').parent().show();
$('#execution-other_activity').attr("required", true);
} else {
$('#execution-other_activity').parent().hide();
$('#execution-other_activity').attr("required", false);
}
for (let k of Object.keys(selected)) {
if (selected[k] != '') {
if (k == 'contact_id') {
$('#execution-contact_id').val($("#execution-contact_id option:contains(" +
selected[k] + ")").attr('value'));
} else if (k == 'hospital_name') {
let instid = $('#execution-hospital_name option').filter(function() {
return $(this).text().trim() === selected[k];
}).val();
console.log("selected['hospital_name']", selected[k]);
console.log('instid', instid);
$('#execution-hospital_name').val(instid);
} else {
$('#execution-' + k).val(selected[k]);
}
}
}
let docid = $('#execution-contact_id option').map(function() {
if ($(this).text().trim() == selected['contact_id']) return this;
}).attr('value')
$('#execution-contact_id').val(docid)
$('#execution-id').val(selected['id'])
$('input[id*="_units_w"]').on('input', function() {
const id = $(this).attr('id');
const brand = id.split('_units_')[0].replace('execution-patient_tracker_planned_', '');
const week = id.split('_units_')[1];
const units = parseFloat($(this).val()) || 0;
const valueField1 = $(`#execution-patient_tracker_planned_${brand}_values_${week}`);
const valueField2 = $(`#execution-patient_tracker_planned_${brand}_units_values_${week}`);
if (baseValues[brand]) {
const calc = units * baseValues[brand];
if (valueField1.length) {
valueField1.val(calc.toFixed(2));
} else if (valueField2.length) {
valueField2.val(calc.toFixed(2));
} else {
console.log("⚠ No matching value field found for:", brand, week);
}
} else {
console.log("⚠ No base value found for brand:", brand);
}
});
$('input[id*="secondary_sales_tracker_planned_"][id*="_values_w"]').on('input', function() {
const id = $(this).attr('id');
const brand = id.split('_values_')[0].replace('execution-', '');
let rowTotal = 0;
// ---- ROW TOTAL (for each brand) ----
for (let i = 1; i <= 4; i++) {
const val = parseFloat($(`#execution-${brand}_values_w${i}`).val()) || 0;
rowTotal += val;
}
// Update brand total (no decimals)
const totalField = $(`#execution-${brand}_total_values`);
if (totalField.length) {
totalField.val(Math.round(rowTotal));
}
// ---- COLUMN TOTALS (W1–W4) ----
for (let i = 1; i <= 4; i++) {
let colTotal = 0;
$(`input[id^="execution-secondary_sales_tracker_planned_"][id*="_values_w${i}"]`)
.each(function() {
if (!$(this).attr('id').includes('grand_total')) {
colTotal += parseFloat($(this).val()) || 0;
}
});
// Update Grand Total row (column-wise)
$(`#execution-secondary_sales_tracker_planned_grand_total_w${i}`).val(Math
.round(colTotal));
}
// ---- FINAL GRAND TOTAL (sum of brand totals) ----
let finalGrandTotal = 0;
$(`input[id^="execution-secondary_sales_tracker_planned_"][id*="_total_values"]`)
.each(function() {
if (!$(this).attr('id').includes('grand_total')) {
finalGrandTotal += parseFloat($(this).val()) || 0;
}
});
// Update overall total
$('#execution-secondary_sales_tracker_planned_grand_total_values').val(Math
.round(finalGrandTotal));
});
$('input[id*="_total_units"], input[id*="_total_values"]').prop('readonly', true);
$('input[id*="grand_total"]').attr('readonly', true);
})
function validateWeeklyInputs() {
console.log('validateWeeklyInputs');
const brands = [
'embremma',
'somalinx_lar',
'enzuta_40mg',
'encicarb_1k',
'others'
];
// 👇 Detect prefix based on the form that triggered validation
const form = event?.target ? $(event.target) : $('body');
const prefix = form.find('input[id^="execution-secondary_sales_tracker_planned_"]').length ?
'execution' :
'field';
console.log('Detected prefix:', prefix);
let anyCompleteBrand = false;
let incompleteBrand = null;
for (const brand of brands) {
const weeks = ['w1', 'w2', 'w3', 'w4'];
const values = weeks.map(week =>
parseFloat(form.find(`#${prefix}-secondary_sales_tracker_planned_${brand}_values_${week}`).val()) ||
0
);
const hasAnyPlanned = values.some(v => v >= 1);
const allPlanned = values.every(v => v >= 1);
if (allPlanned) {
anyCompleteBrand = true;
} else if (hasAnyPlanned && !allPlanned && !incompleteBrand) {
incompleteBrand = {
brand,
values,
weeks
};
}
}
if (anyCompleteBrand) return true;
if (incompleteBrand) {
const {
brand,
values,
weeks
} = incompleteBrand;
Swal.fire({
icon: 'warning',
title: 'Incomplete Plan',
text: `Please enter values for all 4 weeks of ${brand.replace(/_/g, ' ').toUpperCase()}`,
confirmButtonColor: '#3085d6'
});
const missingWeek = weeks[values.findIndex(v => v < 1)];
form.find(`#${prefix}-secondary_sales_tracker_planned_${brand}_values_${missingWeek}`).focus();
return false;
}
Swal.fire({
icon: 'error',
title: 'No Data Entered',
text: 'Please enter planned values for at least one brand before submitting.',
confirmButtonColor: '#d33'
});
return false;
}
jQuery(document).ready(function($) {
$('#field-month').prop("readonly", true);
$('#field-contact_id').change(function() {
$('#field-speciality').val($('option:selected', this).attr('speciality'))
})
$('#field-contact_id').change(function() {
$('#field-sbu_code').val($('option:selected', this).attr('sbucode'))
})
$('#report-form').on('submit', function(event) {
event.preventDefault();
if (!validateWeeklyInputs()) {
return false;
}
$("#pageloader").fadeIn();
$.ajax({
type: "POST",
url: '/form/ajaxsubmit',
data: new FormData($('#report-form')[0]),
processData: false,
contentType: false,
success: function(data) {
$("#pageloader").fadeOut();
if (data.status == 'success') {
Swal.fire({
title: 'Great!',
text: 'Your data is successfully submitted!',
icon: 'success'
})
window.location.reload();
} else {
Swal.fire({
icon: 'error',
title: 'Data not submitted',
text: 'Something went wrong, please try again after some time!'
})
}
},
});
});
$('#execution-form').on('submit', function(event) {
event.preventDefault();
if (!validateWeeklyInputs()) {
return false;
}
$("#pageloader").fadeIn();
$.ajax({
type: "POST",
url: '/form/ajaxsubmit',
data: new FormData($('#execution-form')[0]),
processData: false,
contentType: false,
success: function(data) {
$("#pageloader").fadeOut();
if (data.status == 'success') {
Swal.fire({
title: 'Great!',
text: 'Your data is successfully submitted!',
icon: 'success'
})
window.location.reload();
//$('#report-form').trigger("reset");
} else {
Swal.fire({
icon: 'error',
title: 'Data not submitted',
text: 'Something went wrong, please try again after some time!'
})
}
},
});
});
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0');
var yyyy = today.getFullYear();
today = yyyy + '-' + mm + '-' + dd;
var recordDateField = document.getElementById('field-plan_date');
recordDateField.setAttribute('min', today);
var executionDateField = document.getElementById('execution-plan_date');
executionDateField.setAttribute('min', today);
$('.edit-btn').click(function() {
var executionexeField = document.getElementById('execution-execution_date');
executionexeField.setAttribute('min', executionDateField.value);
});
executionDateField.addEventListener('change', function() {
var executionexeField = document.getElementById('execution-record_date');
executionexeField.setAttribute('min', executionDateField.value);
});
});
</script>