907 lines
47 KiB
PHP
907 lines
47 KiB
PHP
<!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
|
|
$history = Formhelper::getMultiformData($form->partition, $form_id, $form->user_id);
|
|
$doctorNameById = [];
|
|
$doctorIdByName = [];
|
|
|
|
foreach ($questions as $question) {
|
|
if ($question->code == 'contact_id' && is_iterable($question->options ?? null)) {
|
|
foreach ($question->options as $opt) {
|
|
$doctorNameById[$opt->value] = $opt->display;
|
|
$doctorIdByName[$opt->display] = $opt->value;
|
|
}
|
|
}
|
|
}
|
|
|
|
$resolveContactId = function ($raw) use ($doctorNameById, $doctorIdByName) {
|
|
if (is_array($raw) || $raw instanceof \Traversable) {
|
|
$raw = trim((string) (array_values((array) $raw)[0] ?? ''));
|
|
} else {
|
|
$raw = trim((string) ($raw ?? ''));
|
|
}
|
|
|
|
if ($raw === '') {
|
|
return '';
|
|
}
|
|
|
|
if (isset($doctorNameById[$raw])) {
|
|
return $raw;
|
|
}
|
|
|
|
if (isset($doctorIdByName[$raw])) {
|
|
return $doctorIdByName[$raw];
|
|
}
|
|
|
|
return $raw;
|
|
};
|
|
|
|
$latestByContact = [];
|
|
if (isset($history->data->submissions) && is_iterable($history->data->submissions)) {
|
|
foreach ($history->data->submissions as $sub) {
|
|
$formdata = $sub->formdata ?? null;
|
|
if (!$formdata) {
|
|
continue;
|
|
}
|
|
|
|
$contactId = $resolveContactId($formdata->contact_id ?? '');
|
|
|
|
if ($contactId === '') {
|
|
continue;
|
|
}
|
|
|
|
$ts = 0;
|
|
if (!empty($sub->createdAt)) {
|
|
$ts = strtotime($sub->createdAt) ?: 0;
|
|
} elseif (!empty($sub->updatedAt)) {
|
|
$ts = strtotime($sub->updatedAt) ?: 0;
|
|
} elseif (!empty($formdata->record_date)) {
|
|
$ts = strtotime($formdata->record_date) ?: 0;
|
|
}
|
|
|
|
if (!isset($latestByContact[$contactId]) || $ts >= $latestByContact[$contactId]['ts']) {
|
|
$latestByContact[$contactId] = ['sub' => $sub, 'ts' => $ts];
|
|
}
|
|
}
|
|
}
|
|
|
|
$latestDoctorRows = collect(array_values($latestByContact))
|
|
->map(function ($item) {
|
|
return $item['sub'];
|
|
})
|
|
->sortByDesc(function ($sub) {
|
|
$fd = $sub->formdata ?? null;
|
|
if (!$fd) {
|
|
return 0;
|
|
}
|
|
return strtotime($sub->createdAt ?? $sub->updatedAt ?? ($fd->record_date ?? '')) ?: 0;
|
|
})
|
|
->values();
|
|
|
|
$reportFormId = '1781620356-76fde7ab-e939-44ff-b0be-c33e7f2a05a7';
|
|
$report_form = Formhelper::getformdefination($form->partition, $reportFormId, $form->user_id);
|
|
$reportQuestions = $report_form->data->questions ?? [];
|
|
$reportHistory = Formhelper::getMultiformData($form->partition, $reportFormId, $form->user_id);
|
|
|
|
$reportMonths = [
|
|
'January', 'February', 'March', 'April', 'May', 'June',
|
|
'July', 'August', 'September', 'October', 'November', 'December',
|
|
];
|
|
$reportMonthNumToName = array_combine(range(1, 12), $reportMonths);
|
|
$reportMonthShortNames = [
|
|
'January' => 'Jan', 'February' => 'Feb', 'March' => 'Mar',
|
|
'April' => 'Apr', 'May' => 'May', 'June' => 'Jun',
|
|
'July' => 'Jul', 'August' => 'Aug', 'September' => 'Sep',
|
|
'October' => 'Oct', 'November' => 'Nov', 'December' => 'Dec',
|
|
];
|
|
$fiscalMonthColumns = [
|
|
'Apr-26', 'May-26', 'Jun-26', 'Jul-26', 'Aug-26', 'Sep-26',
|
|
'Oct-26', 'Nov-26', 'Dec-26', 'Jan-27', 'Feb-27', 'Mar-27',
|
|
];
|
|
|
|
$normalizeReportMonth = function ($month) use ($reportMonths, $reportMonthNumToName) {
|
|
if (is_array($month) || $month instanceof \Traversable) {
|
|
$month = array_values((array) $month)[0] ?? '';
|
|
}
|
|
|
|
$month = trim((string) $month);
|
|
if ($month === '') {
|
|
return '';
|
|
}
|
|
|
|
if (is_numeric($month)) {
|
|
return $reportMonthNumToName[(int) $month] ?? '';
|
|
}
|
|
|
|
foreach ($reportMonths as $monthName) {
|
|
if (strcasecmp($month, $monthName) === 0) {
|
|
return $monthName;
|
|
}
|
|
}
|
|
|
|
return $month;
|
|
};
|
|
|
|
$reportMonthColumnKey = function ($month, $year) use ($normalizeReportMonth, $reportMonthShortNames, $fiscalMonthColumns) {
|
|
$monthName = $normalizeReportMonth($month);
|
|
$year = trim((string) $year);
|
|
|
|
if ($monthName === '' || $year === '' || !isset($reportMonthShortNames[$monthName])) {
|
|
return null;
|
|
}
|
|
|
|
$columnKey = $reportMonthShortNames[$monthName] . '-' . substr($year, -2);
|
|
return in_array($columnKey, $fiscalMonthColumns, true) ? $columnKey : null;
|
|
};
|
|
|
|
$reportTotalsByContact = [];
|
|
if (isset($reportHistory->data->submissions) && is_iterable($reportHistory->data->submissions)) {
|
|
foreach ($reportHistory->data->submissions as $reportSub) {
|
|
$reportFd = $reportSub->formdata ?? null;
|
|
if (!$reportFd) {
|
|
continue;
|
|
}
|
|
|
|
$reportContactId = $resolveContactId($reportFd->contact_id ?? '');
|
|
if ($reportContactId === '') {
|
|
continue;
|
|
}
|
|
|
|
$columnKey = $reportMonthColumnKey($reportFd->month ?? '', $reportFd->year ?? '');
|
|
if ($columnKey === null) {
|
|
continue;
|
|
}
|
|
|
|
$totalValue = $reportFd->total_actual_value ?? $reportFd->total ?? 0;
|
|
if (is_array($totalValue) || $totalValue instanceof \Traversable) {
|
|
$totalValue = array_values((array) $totalValue)[0] ?? 0;
|
|
}
|
|
$totalValue = (float) $totalValue;
|
|
|
|
if (!isset($reportTotalsByContact[$reportContactId][$columnKey])) {
|
|
$reportTotalsByContact[$reportContactId][$columnKey] = 0;
|
|
}
|
|
$reportTotalsByContact[$reportContactId][$columnKey] += $totalValue;
|
|
}
|
|
}
|
|
|
|
$formatReportTotal = function ($value) {
|
|
if ($value === null || (float) $value === 0.0) {
|
|
return '';
|
|
}
|
|
|
|
$formatted = number_format((float) $value, 2, '.', '');
|
|
return rtrim(rtrim($formatted, '0'), '.');
|
|
};
|
|
|
|
$reportCurrentMonth = $reportMonths[(int) date('n') - 1];
|
|
$reportCurrentYear = (int) date('Y');
|
|
if ($reportCurrentYear < 2026) {
|
|
$reportCurrentYear = 2026;
|
|
} elseif ($reportCurrentYear > 2028) {
|
|
$reportCurrentYear = 2028;
|
|
}
|
|
|
|
$reportReadonlyCalcFields = [
|
|
'pulmosmart_group_actual_value',
|
|
'pulmosamrt_group_actual_value',
|
|
'total_actual_value',
|
|
'ps_share',
|
|
];
|
|
|
|
foreach ($reportQuestions as $question) {
|
|
if ($question->code == 'contact_id' && is_iterable($question->options ?? null)) {
|
|
foreach ($question->options as $opt) {
|
|
$doctorNameById[$opt->value] = $opt->display;
|
|
$doctorIdByName[$opt->display] = $opt->value;
|
|
}
|
|
}
|
|
}
|
|
@endphp
|
|
|
|
<body class="loading">
|
|
<div class="account-pages">
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-12 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 text-end">
|
|
@if($form->link_type == 'form')
|
|
<button type="button" class="btn btn-primary btn-sm" id="add-doctor-btn">Add New Doctor</button>
|
|
@else
|
|
<a href="{{url()->previous()}}" class="float-end pt-1">Back</a>
|
|
@endif
|
|
</div>
|
|
@endif
|
|
@if(isset($form->user_info))
|
|
<div class="col-12">
|
|
<h6>Submitted By: {{$form->user_info->name}}</h6>
|
|
</div>
|
|
@endif
|
|
|
|
<div class="col-12" id="table-wrapper">
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered table-hover mb-0 doctor-report-table">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Action</th>
|
|
<th>Doctor Name</th>
|
|
<th>Garnet Code</th>
|
|
<th>PBS Amount</th>
|
|
<th>Month & Year</th>
|
|
@foreach($fiscalMonthColumns as $fiscalColumn)
|
|
<th class="text-center">{{ $fiscalColumn }}</th>
|
|
@endforeach
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@forelse($latestDoctorRows as $sub)
|
|
@php
|
|
$fd = $sub->formdata;
|
|
$contactId = $resolveContactId($fd->contact_id ?? '');
|
|
$doctorName = $doctorNameById[$contactId] ?? trim((string) ($fd->contact_id ?? ''));
|
|
$reportPlanDetails = json_decode(json_encode($fd), true) ?: [];
|
|
$reportPlanDetails['contact_id'] = $contactId;
|
|
$recordDate = $fd->record_date ?? '';
|
|
$monthYear = $recordDate;
|
|
if ($recordDate && ($parsed = strtotime($recordDate))) {
|
|
$monthYear = date('M Y', $parsed);
|
|
}
|
|
$doctorReportTotals = $reportTotalsByContact[$contactId] ?? [];
|
|
@endphp
|
|
<tr>
|
|
<td>
|
|
<button type="button"
|
|
class="btn btn-xs btn-info report-btn"
|
|
data-contact-id="{{ $contactId }}"
|
|
data-doctor-name="{{ $doctorName }}"
|
|
plan_details="{{ json_encode($reportPlanDetails) }}">
|
|
Report
|
|
</button>
|
|
</td>
|
|
<td>{{ $doctorName }}</td>
|
|
<td>{{ $fd->msl_code ?? '' }}</td>
|
|
<td>{{ $fd->pbc_amt ?? '' }}</td>
|
|
<td>{{ $monthYear }}</td>
|
|
@foreach($fiscalMonthColumns as $fiscalColumn)
|
|
<td class="text-center">{{ $formatReportTotal($doctorReportTotals[$fiscalColumn] ?? null) }}</td>
|
|
@endforeach
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td colspan="{{ 5 + count($fiscalMonthColumns) }}" class="text-center text-muted">No doctors added yet.</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="form-wrapper" class="col-12">
|
|
<form method="POST" action="/form/submit" id="report-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="field-user_id" class="form-label"> Select User / Territory <span class="text-danger">*</span> </label>
|
|
<select class="form-control" id="field-user_id" name="user_id" required>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach($form->users as $option)
|
|
<option value="{{$option->value}}" hierarchy="{{$option->hierarchy_id}}" {{isset($question->value) && $question->value == $option->value ? 'selected':''}}>{{$option->display}}</option>
|
|
@endforeach
|
|
</select>
|
|
<input type="hidden" id="field-hierarchy_id" name="hierarchy_id" value="">
|
|
</div>
|
|
@endif
|
|
|
|
@foreach($questions as $question)
|
|
<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)
|
|
<option value="{{$option->value}}"
|
|
{{isset($question->value) && $question->value == $option->value ? 'selected':''}}
|
|
msl_code="{{ $option->contact->msl_code ?? '' }}"
|
|
speciality="{{ $option->contact->speciality ?? '' }}">
|
|
{{$option->display}}
|
|
</option>
|
|
@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('radio')
|
|
@foreach($question->options as $option)
|
|
<div class="form-check mb-2 form-check-success">
|
|
<input class="form-check-input" type="radio" name="{{$question->code}}" id="field-{{$question->code}}_{{$option->value}}" value="{{$option->value}}">
|
|
<label class="form-check-label" for="field-{{$question->code}}_{{$option->value}}">{{$option->display}}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
@case('radiometrix')
|
|
@php
|
|
$headings =
|
|
count($question->options) > 0
|
|
? json_decode($question->options[0]->value)
|
|
: [];
|
|
@endphp
|
|
<div class="table-responsive">
|
|
<div class="d-table w-100">
|
|
<div class="d-table-row font-weight-bold">
|
|
<div class="d-table-cell p-2" style="width: 150px;"></div>
|
|
@foreach ($headings as $head)
|
|
<div class="d-table-cell text-center p-2">{{ $head }}</div>
|
|
@endforeach
|
|
</div>
|
|
@foreach ($question->options as $option)
|
|
@php $nn = json_decode($option->value); @endphp
|
|
<div class="d-table-row align-middle">
|
|
<div class="d-table-cell font-weight-bold p-2" style="width: 150px;">
|
|
{{ $option->display }}
|
|
</div>
|
|
@foreach ($nn as $value)
|
|
<div class="d-table-cell text-center p-2">
|
|
<input type="radio"
|
|
id="field-{{ $option->display }}-{{ $value }}"
|
|
name="{{ $question->code }}[{{$option->display}}]" value="{{$value}}" class="form-check-input"
|
|
{{ isset($question->display) && $option->display != $option->display ? 'checked' : '' }}>
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
</div>
|
|
@break
|
|
@case('checkbox')
|
|
@foreach($question->options as $option)
|
|
<div class="form-check mb-2 form-check-primary ms-2">
|
|
<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('file')
|
|
@if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes' ) )
|
|
<input type="file" id="field-{{$question->code}}" name="{{$question->code}}" class="form-control" value="" {{$question->required == 'yes'?'required':'' }}>
|
|
@elseif(isset($question->value))
|
|
<img src="{{$question->value}}" class="img-fluid">
|
|
@endif
|
|
@break
|
|
@case('multitextbox')
|
|
<div class="row">
|
|
@foreach($question->options as $option)
|
|
<div class="col-6">{{$option->display}}</div>
|
|
<div class="col-6 mb-1">
|
|
<input type="number" id="field-{{$option->value}}" name="{{$option->value}}" class="form-control" required value="{{isset($option->val)?$option->val:0}}">
|
|
</div>
|
|
@endforeach
|
|
</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 type="button" class="btn btn-light me-2" id="cancel-form-btn">Cancel</button>
|
|
<button class="btn btn-primary" type="submit" id="submit-btn"> Submit </button>
|
|
</div>
|
|
@endif
|
|
</form>
|
|
</div>
|
|
|
|
<div id="report-entry-form-wrapper" class="col-12">
|
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
|
<h5 class="mb-0">Report</h5>
|
|
</div>
|
|
<form method="POST" action="/form/submit" id="report-entry-form" enctype="multipart/form-data">
|
|
<input type="hidden" name="form_id" value="{{ $reportFormId }}">
|
|
@csrf
|
|
|
|
@foreach($reportQuestions as $question)
|
|
<div class="col-md-12 mb-2">
|
|
<label for="report-field-{{ $question->code == 'contact_id' ? 'contact_id-display' : $question->code }}" class="form-label">{{$question->question}} {!!$question->required == 'yes' ? '<span class="text-danger">*</span>':''!!} </label>
|
|
@if($question->code == 'year')
|
|
<select class="form-control" id="report-field-year" name="year" {{$question->required == 'yes'?'required':'' }}>
|
|
@for($y = 2026; $y <= 2028; $y++)
|
|
<option value="{{ $y }}" {{ $reportCurrentYear === $y ? 'selected' : '' }}>{{ $y }}</option>
|
|
@endfor
|
|
</select>
|
|
@elseif($question->code == 'month')
|
|
<select class="form-control" id="report-field-month" name="month" {{$question->required == 'yes'?'required':'' }}>
|
|
@foreach($reportMonths as $monthName)
|
|
<option value="{{ $monthName }}" {{ $reportCurrentMonth === $monthName ? 'selected' : '' }}>{{ $monthName }}</option>
|
|
@endforeach
|
|
</select>
|
|
@elseif($question->code == 'contact_id')
|
|
<input type="hidden" id="report-field-contact_id" name="contact_id" value="">
|
|
<input type="text" id="report-field-contact_id-display" class="form-control" readonly tabindex="-1">
|
|
@else
|
|
@switch($question->type)
|
|
@case('hidden')
|
|
<input type="{{$question->type}}" id="report-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="report-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="any" id="report-field-{{$question->code}}" name="{{$question->code}}" class="form-control" {{$question->required == 'yes'?'required':'' }} {{ in_array($question->code, $reportReadonlyCalcFields) ? 'readonly' : '' }} value="{{isset($question->value)?$question->value:0}}">
|
|
@break
|
|
@case('textarea')
|
|
<textarea id="report-field-{{$question->code}}" name="{{$question->code}}" class="form-control" {{$question->required == 'yes'?'required':'' }}>{{isset($question->value)?$question->value:''}}</textarea>
|
|
@break
|
|
@case('dropdown')
|
|
<select class="form-control" id="report-field-{{$question->code}}" name="{{$question->code}}" {{$question->required == 'yes'?'required':'' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach($question->options as $option)
|
|
<option value="{{$option->value}}">{{$option->display}}</option>
|
|
@endforeach
|
|
</select>
|
|
@break
|
|
@case('radio')
|
|
@foreach($question->options as $option)
|
|
<div class="form-check mb-2 form-check-success">
|
|
<input class="form-check-input" type="radio" name="{{$question->code}}" id="report-field-{{$question->code}}_{{$option->value}}" value="{{$option->value}}">
|
|
<label class="form-check-label" for="report-field-{{$question->code}}_{{$option->value}}">{{$option->display}}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
@case('checkbox')
|
|
@foreach($question->options as $option)
|
|
<div class="form-check mb-2 form-check-primary ms-2">
|
|
<input class="form-check-input" type="checkbox" id="report-field-{{$question->code}}-{{$option->value}}" name="{{$question->code}}[]" value="{{$option->value}}">
|
|
<label class="form-check-label" for="report-field-{{$question->code}}-{{$option->value}}">{{$option->display}}</label>
|
|
</div>
|
|
@endforeach
|
|
@break
|
|
@case('file')
|
|
<input type="file" id="report-field-{{$question->code}}" name="{{$question->code}}" class="form-control" {{$question->required == 'yes'?'required':'' }}>
|
|
@break
|
|
@case('multitextbox')
|
|
<div class="row">
|
|
@foreach($question->options as $option)
|
|
<div class="col-6">{{$option->display}}</div>
|
|
<div class="col-6 mb-1">
|
|
<input type="number" id="report-field-{{$option->value}}" name="{{$option->value}}" class="form-control" required value="{{isset($option->val)?$option->val:0}}">
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
@break
|
|
@endswitch
|
|
@endif
|
|
</div>
|
|
@endforeach
|
|
|
|
<div class="text-center d-grid mt-3 report-entry-actions">
|
|
<button type="button" class="btn btn-light me-2" id="cancel-report-form-btn">Cancel</button>
|
|
<button class="btn btn-primary" type="submit" id="report-entry-submit-btn"> Submit </button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
</div> <!-- end card-body -->
|
|
</div>
|
|
<!-- end card -->
|
|
|
|
</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%;
|
|
}
|
|
.form-label {
|
|
font-weight:bold;
|
|
font-size:16px;
|
|
}
|
|
#form-wrapper .text-center.d-grid,
|
|
#report-entry-form-wrapper .report-entry-actions {
|
|
display: flex !important;
|
|
justify-content: center;
|
|
gap: 0.5rem;
|
|
}
|
|
#table-wrapper .doctor-report-table {
|
|
font-size: 12px;
|
|
}
|
|
#table-wrapper .doctor-report-table th,
|
|
#table-wrapper .doctor-report-table td {
|
|
white-space: nowrap;
|
|
vertical-align: middle;
|
|
}
|
|
</style>
|
|
@include('layouts.shared/footer-script')
|
|
<script src="{{asset('assets/libs/sweetalert2/sweetalert2.min.js')}}"></script>
|
|
<script type="text/javascript">
|
|
jQuery(document).ready(function($){
|
|
$('#form-wrapper').hide();
|
|
$('#report-entry-form-wrapper').hide();
|
|
|
|
const doctorNameById = @json($doctorNameById);
|
|
const doctorIdByName = @json($doctorIdByName);
|
|
|
|
function normalizeContactId(value) {
|
|
if (value === null || value === undefined) {
|
|
return '';
|
|
}
|
|
if (Array.isArray(value)) {
|
|
return String(value[0] || '').trim();
|
|
}
|
|
if (typeof value === 'object') {
|
|
return String(Object.values(value)[0] || '').trim();
|
|
}
|
|
return String(value).trim();
|
|
}
|
|
|
|
function resolveContactId(value) {
|
|
const raw = normalizeContactId(value);
|
|
if (!raw) {
|
|
return '';
|
|
}
|
|
if (doctorNameById[raw]) {
|
|
return raw;
|
|
}
|
|
if (doctorIdByName[raw]) {
|
|
return doctorIdByName[raw];
|
|
}
|
|
return raw;
|
|
}
|
|
|
|
function setReportContactFields(contactId, doctorName) {
|
|
contactId = resolveContactId(contactId);
|
|
doctorName = String(doctorName || '').trim();
|
|
|
|
if (!doctorName && contactId && doctorNameById[contactId]) {
|
|
doctorName = doctorNameById[contactId];
|
|
}
|
|
|
|
$('#report-field-contact_id').val(contactId);
|
|
$('#report-field-contact_id-display').val(doctorName);
|
|
}
|
|
|
|
const reportGroupTotalSelectors = [
|
|
'#report-field-pulmosmart_group_actual_value',
|
|
'#report-field-pulmosamrt_group_actual_value',
|
|
];
|
|
|
|
function parseReportNumber(selector) {
|
|
const $field = $(selector);
|
|
if (!$field.length) {
|
|
return null;
|
|
}
|
|
const value = parseFloat($field.val());
|
|
return isNaN(value) ? 0 : value;
|
|
}
|
|
|
|
function setReportNumber(selectors, value) {
|
|
const rounded = Math.round(value * 100) / 100;
|
|
(Array.isArray(selectors) ? selectors : [selectors]).forEach(function(selector) {
|
|
const $field = $(selector);
|
|
if ($field.length) {
|
|
$field.val(rounded);
|
|
}
|
|
});
|
|
}
|
|
|
|
function recalculateReportFields() {
|
|
const dpiPmdi = parseReportNumber('#report-field-pulmosmart_dpi_pmdi_actual_value');
|
|
const neb = parseReportNumber('#report-field-pulmosmart_neb_actual_value');
|
|
const pulmosmartG = parseReportNumber('#report-field-pulmosmart_g_actual_value');
|
|
setReportNumber(reportGroupTotalSelectors, dpiPmdi + neb + pulmosmartG);
|
|
|
|
const budasure = parseReportNumber('#report-field-budasure_actual_value');
|
|
const vilorespU = parseReportNumber('#report-field-viloresp_u');
|
|
const totalActual = budasure + vilorespU;
|
|
setReportNumber('#report-field-total_actual_value', totalActual);
|
|
|
|
let psShare = 0;
|
|
if (totalActual > 0) {
|
|
psShare = (dpiPmdi / totalActual) * 100;
|
|
}
|
|
setReportNumber('#report-field-ps_share', psShare);
|
|
}
|
|
|
|
function bindReportCalculations() {
|
|
const sourceSelectors = [
|
|
'#report-field-pulmosmart_dpi_pmdi_actual_value',
|
|
'#report-field-pulmosmart_neb_actual_value',
|
|
'#report-field-pulmosmart_g_actual_value',
|
|
'#report-field-budasure_actual_value',
|
|
'#report-field-viloresp_u',
|
|
].join(', ');
|
|
|
|
$(document).off('input.reportCalc change.reportCalc', sourceSelectors);
|
|
$(document).on('input.reportCalc change.reportCalc', sourceSelectors, recalculateReportFields);
|
|
|
|
reportGroupTotalSelectors.forEach(function(selector) {
|
|
$(selector).prop('readonly', true);
|
|
});
|
|
$('#report-field-total_actual_value, #report-field-ps_share').prop('readonly', true);
|
|
}
|
|
|
|
bindReportCalculations();
|
|
|
|
function showTable() {
|
|
$('#form-wrapper').hide();
|
|
$('#report-entry-form-wrapper').hide();
|
|
$('#table-wrapper').show();
|
|
$('#add-doctor-btn').show();
|
|
}
|
|
|
|
function showForm() {
|
|
$('#table-wrapper').hide();
|
|
$('#report-entry-form-wrapper').hide();
|
|
$('#form-wrapper').show();
|
|
$('#add-doctor-btn').hide();
|
|
}
|
|
|
|
function showReportForm(contactId, planDetails, doctorName) {
|
|
$('#table-wrapper').hide();
|
|
$('#form-wrapper').hide();
|
|
$('#add-doctor-btn').hide();
|
|
$('#report-entry-form-wrapper').show();
|
|
|
|
$('#report-entry-form')[0].reset();
|
|
$('#report-entry-form input[name="id"]').remove();
|
|
|
|
if (planDetails) {
|
|
for (let key of Object.keys(planDetails)) {
|
|
if (key === 'contact_id' || key === 'id' || key === 'month' || key === 'year') {
|
|
continue;
|
|
}
|
|
let $field = $('#report-field-' + key);
|
|
if ($field.length && !$field.is('#report-field-contact_id') && !$field.is('#report-field-contact_id-display')) {
|
|
$field.val(planDetails[key]);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($('#report-field-msl_code').length) {
|
|
$('#report-field-msl_code').prop('readonly', true);
|
|
}
|
|
|
|
let reportMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
let now = new Date();
|
|
if ($('#report-field-month').length) {
|
|
$('#report-field-month').val(reportMonths[now.getMonth()]);
|
|
}
|
|
if ($('#report-field-year').length) {
|
|
let currentYear = now.getFullYear();
|
|
if (currentYear < 2026) {
|
|
currentYear = 2026;
|
|
} else if (currentYear > 2028) {
|
|
currentYear = 2028;
|
|
}
|
|
$('#report-field-year').val(String(currentYear));
|
|
}
|
|
|
|
setReportContactFields(contactId, doctorName);
|
|
recalculateReportFields();
|
|
}
|
|
|
|
$('#add-doctor-btn').on('click', function() {
|
|
$('#report-form')[0].reset();
|
|
$('#report-form input[name="id"]').remove();
|
|
showForm();
|
|
});
|
|
|
|
$('#cancel-form-btn').on('click', function() {
|
|
showTable();
|
|
});
|
|
|
|
$('#cancel-report-form-btn').on('click', function() {
|
|
showTable();
|
|
});
|
|
|
|
$(document).on('click', '.report-btn', function() {
|
|
let contactId = resolveContactId($(this).attr('data-contact-id'));
|
|
let doctorName = String($(this).attr('data-doctor-name') || '').trim();
|
|
let planDetails = {};
|
|
try {
|
|
planDetails = JSON.parse($(this).attr('plan_details') || '{}');
|
|
} catch (e) {
|
|
planDetails = {};
|
|
}
|
|
if (!contactId) {
|
|
contactId = resolveContactId(planDetails.contact_id);
|
|
}
|
|
if (!doctorName && contactId && doctorNameById[contactId]) {
|
|
doctorName = doctorNameById[contactId];
|
|
}
|
|
showReportForm(contactId, planDetails, doctorName);
|
|
});
|
|
|
|
if ($('#field-user_id').length) {
|
|
$('#field-user_id').change(function(){
|
|
let hierarchy = $('option:selected', this).attr('hierarchy');
|
|
$('#field-hierarchy_id').val(hierarchy);
|
|
$.ajax({
|
|
type: "GET",
|
|
url: '/form/getdoctorlist?partition={{$form->partition}}&hierarchy='+hierarchy,
|
|
success: function(data) {
|
|
$("#pageloader").fadeOut();
|
|
$('#field-contact_id').html('');
|
|
$('#field-contact_id').append($("<option></option>").attr("value",'').text('-- Select --'));
|
|
for (let itm of data) {
|
|
$('#field-contact_id').append(
|
|
$("<option></option>")
|
|
.attr("value", itm.value)
|
|
.attr("msl_code", itm.contact?.msl_code || '')
|
|
.attr("speciality", itm.contact?.speciality || '')
|
|
.text(itm.display)
|
|
);
|
|
}
|
|
},
|
|
});
|
|
});
|
|
}
|
|
|
|
if ($('#field-contact_id').length) {
|
|
$('#field-contact_id').on('change', function() {
|
|
let $selected = $('option:selected', this);
|
|
$('#field-msl_code').val($selected.attr('msl_code') || '');
|
|
$('#field-speciality').val($selected.attr('speciality') || '');
|
|
});
|
|
}
|
|
|
|
if ($('#field-msl_code').length) {
|
|
$('#field-msl_code').prop('readonly', true);
|
|
}
|
|
|
|
$('#report-entry-form').on('submit', function(event){
|
|
event.preventDefault();
|
|
recalculateReportFields();
|
|
$("#pageloader").fadeIn();
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/form/ajaxsubmit',
|
|
data: new FormData($('#report-entry-form')[0]),
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(data) {
|
|
$("#pageloader").fadeOut();
|
|
if(data.status == 'success') {
|
|
Swal.fire({
|
|
title: 'Great!',
|
|
text: 'Your report is successfully submitted!',
|
|
icon: 'success'
|
|
}).then(function() {
|
|
location.reload();
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: data.hasOwnProperty('message') ? 'You are not mapped to any position code' : 'Data not submitted',
|
|
text: data.hasOwnProperty('message') ? 'for resolution please email Position code, L1 Manager and L2 Manager details to support1@stratawiz.com' : 'Something went wrong, please try again after some time!'
|
|
});
|
|
}
|
|
},
|
|
error: function() {
|
|
$("#pageloader").fadeOut();
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Error',
|
|
text: 'Something went wrong'
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
$('#report-form').on('submit', function(event){
|
|
event.preventDefault();
|
|
$("#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'
|
|
}).then(function() {
|
|
location.reload();
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: data.hasOwnProperty('message') ? 'You are not mapped to any position code' : 'Data not submitted',
|
|
text: data.hasOwnProperty('message') ? 'for resolution please email Position code, L1 Manager and L2 Manager details to support1@stratawiz.com' : 'Something went wrong, please try again after some time!'
|
|
});
|
|
}
|
|
},
|
|
error: function() {
|
|
$("#pageloader").fadeOut();
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Error',
|
|
text: 'Something went wrong'
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
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-record_date');
|
|
if (recordDateField) {
|
|
recordDateField.setAttribute('max', today);
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|