632 lines
35 KiB
PHP
632 lines
35 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
@include('layouts.shared/title-meta', ['title' => 'POB'])
|
|
@include('layouts.shared/head-css', ['mode' => $mode ?? '', 'demo' => $demo ?? ''])
|
|
<link href="{{ asset('assets/libs/sweetalert2/sweetalert2.min.css') }}" rel="stylesheet" type="text/css" />
|
|
<link href="{{ asset('assets/libs/select2/select2.min.css') }}" rel="stylesheet" type="text/css" />
|
|
<style>
|
|
.pob-card .form-control { font-size: 16px; }
|
|
.pob-card .table-responsive {
|
|
overflow-x: auto;
|
|
-webkit-overflow-scrolling: touch;
|
|
}
|
|
.pob-card #doctor-table,
|
|
.pob-card #chemist-table,
|
|
.pob-card .pob-orders {
|
|
width: max-content;
|
|
min-width: 100%;
|
|
}
|
|
.pob-card #doctor-table th,
|
|
.pob-card #doctor-table td,
|
|
.pob-card #chemist-table th,
|
|
.pob-card #chemist-table td,
|
|
.pob-card .pob-orders th,
|
|
.pob-card .pob-orders td {
|
|
white-space: nowrap;
|
|
}
|
|
.pob-orders { background: #f7f9fb; }
|
|
.pob-orders td { font-size: 13px; }
|
|
#pageloader {
|
|
display: none;
|
|
position: fixed;
|
|
inset: 0;
|
|
z-index: 9999;
|
|
background: rgba(255, 255, 255, 0.8);
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="loading">
|
|
<div id="pageloader">Loading</div>
|
|
<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 pob-card quick-action-form-card">
|
|
<div class="card-body p-3">
|
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
|
<h4 class="page-title mb-0">POB</h4>
|
|
<button type="button" class="btn btn-link pt-1 d-none" id="pob-back">Back</button>
|
|
</div>
|
|
|
|
<div id="tabs-wrapper">
|
|
<ul class="nav nav-tabs nav-bordered nav-justified" role="tablist">
|
|
<li class="nav-item" role="presentation">
|
|
<a href="#doctor-tab" data-bs-toggle="tab" class="nav-link active" role="tab">Doctors</a>
|
|
</li>
|
|
<li class="nav-item" role="presentation">
|
|
<a href="#chemist-tab" data-bs-toggle="tab" class="nav-link" role="tab">Chemists</a>
|
|
</li>
|
|
</ul>
|
|
<div class="tab-content">
|
|
<div class="tab-pane active show" id="doctor-tab" role="tabpanel">
|
|
<input type="search" class="form-control my-2 pob-search" data-table="doctor-table" placeholder="Search doctor" aria-label="Search doctor">
|
|
<div class="table-responsive">
|
|
<table class="table table-sm table-hover mb-0" id="doctor-table">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Action</th>
|
|
<th>Doctor Name</th>
|
|
<th>Speciality</th>
|
|
<th>MSL Code</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="tab-pane" id="chemist-tab" role="tabpanel">
|
|
<input type="search" class="form-control my-2 pob-search" data-table="chemist-table" placeholder="Search chemist" aria-label="Search chemist">
|
|
<div class="table-responsive">
|
|
<table class="table table-sm table-hover mb-0" id="chemist-table">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Action</th>
|
|
<th>Chemist Name</th>
|
|
<th>MSL Code</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="report-panel" class="d-none">
|
|
<h5 class="mt-2" id="report-title">POB Details (Without Visit)</h5>
|
|
<form method="POST" action="/form/submit" id="report-form" enctype="multipart/form-data">
|
|
@csrf
|
|
<input type="hidden" name="form_id" value="{{ $form_id }}">
|
|
<input type="hidden" name="user_id" value="{{ $form->user_id ?? '' }}">
|
|
<input type="hidden" name="partition" value="{{ $form->partition ?? '' }}">
|
|
<input type="hidden" name="contact_name" id="field-contact_name" value="">
|
|
<input type="hidden" name="contact_type" id="field-contact_type" value="">
|
|
<input type="hidden" name="id" id="field-submission-id" value="">
|
|
<input type="hidden" name="submission_status" value="Order Taken">
|
|
|
|
<div class="mb-2">
|
|
<label class="form-label" for="field-record_date">Date <span class="text-danger">*</span></label>
|
|
<input type="date" class="form-control" id="field-record_date" name="record_date" required>
|
|
</div>
|
|
<div class="mb-2">
|
|
<label class="form-label" for="field-contact_id" id="contact-label">Select Doctor <span class="text-danger">*</span></label>
|
|
<select class="form-control" id="field-contact_id" name="contact_id" required></select>
|
|
</div>
|
|
<div class="mb-2" id="wrap-speciality">
|
|
<label class="form-label" for="field-speciality">Speciality</label>
|
|
<input type="text" class="form-control" id="field-speciality" name="speciality" readonly>
|
|
</div>
|
|
<div class="mb-2" id="wrap-doctor_location">
|
|
<label class="form-label" for="field-doctor_location">Doctor Address</label>
|
|
<input type="text" class="form-control" id="field-doctor_location" name="doctor_location" readonly>
|
|
</div>
|
|
<div class="mb-2 d-none" id="wrap-chemist_location">
|
|
<label class="form-label" for="field-chemist_location">Chemist Address</label>
|
|
<input type="text" class="form-control" id="field-chemist_location" name="chemist_location" readonly disabled>
|
|
</div>
|
|
<div class="mb-2">
|
|
<label class="form-label" for="field-msl_code">MSL Code</label>
|
|
<input type="text" class="form-control" id="field-msl_code" name="msl_code" readonly>
|
|
</div>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table table-sm mb-2">
|
|
<thead>
|
|
<tr>
|
|
<th>SKU</th>
|
|
<th>POB Units</th>
|
|
<th>POB Value</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr data-price="129">
|
|
<td>Asthalin Inhaler</td>
|
|
<td><input type="text" inputmode="numeric" class="form-control pob-units" name="asthalin_inhaler_units" value="0"></td>
|
|
<td><input type="text" class="form-control pob-value" name="asthalin_inhaler_value" value="0" readonly></td>
|
|
</tr>
|
|
<tr data-price="55">
|
|
<td>Asthalin Rotacap</td>
|
|
<td><input type="text" inputmode="numeric" class="form-control pob-units" name="asthalin_rotacap_units" value="0"></td>
|
|
<td><input type="text" class="form-control pob-value" name="asthalin_rotacap_value" value="0" readonly></td>
|
|
</tr>
|
|
<tr data-price="260">
|
|
<td>Aerocort Inhaler</td>
|
|
<td><input type="text" inputmode="numeric" class="form-control pob-units" name="aerocort_inhaler_units" value="0"></td>
|
|
<td><input type="text" class="form-control pob-value" name="aerocort_inhaler_value" value="0" readonly></td>
|
|
</tr>
|
|
<tr data-price="109">
|
|
<td>Aerocort Rotacap</td>
|
|
<td><input type="text" inputmode="numeric" class="form-control pob-units" name="aerocort_rotacap_units" value="0"></td>
|
|
<td><input type="text" class="form-control pob-value" name="aerocort_rotacap_value" value="0" readonly></td>
|
|
</tr>
|
|
<tr data-price="99">
|
|
<td>Aerocort Forte Rotacap</td>
|
|
<td><input type="text" inputmode="numeric" class="form-control pob-units" name="aerocort_forte_rotacap_units" value="0"></td>
|
|
<td><input type="text" class="form-control pob-value" name="aerocort_forte_rotacap_value" value="0" readonly></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Total</td>
|
|
<td><input type="text" class="form-control" id="field-total_pob_units" name="total_pob_units" value="0" readonly></td>
|
|
<td><input type="text" class="form-control" id="field-total_pob_value" name="total_pob_value" value="0" readonly></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="mb-2">
|
|
<label class="form-label" for="field-supply_status">Supply Status <span class="text-danger">*</span></label>
|
|
<select class="form-control" id="field-supply_status" name="supply_status" required>
|
|
<option value="">-- Select --</option>
|
|
<option value="Yes">Yes</option>
|
|
<option value="No">No</option>
|
|
</select>
|
|
</div>
|
|
<div id="actual-section" class="d-none">
|
|
<h5 class="mt-3">Actual Values</h5>
|
|
<div class="mb-2">
|
|
<label class="form-label" for="field-upload_invoice">Upload Invoice</label>
|
|
<input type="file" class="form-control" id="field-upload_invoice" name="upload_invoice" accept=".jpg,.jpeg,.png,.pdf,image/jpeg,image/png,application/pdf">
|
|
</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-sm mb-2">
|
|
<thead>
|
|
<tr>
|
|
<th>SKU</th>
|
|
<th>Actual POB Units</th>
|
|
<th>Actual POB Value</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr data-price="129">
|
|
<td>Actual Asthalin Inhaler</td>
|
|
<td><input type="text" inputmode="numeric" class="form-control actual-units" name="actual_asthalin_inhaler_units" value="0"></td>
|
|
<td><input type="text" class="form-control actual-value" name="actual_asthalin_inhaler_value" value="0" readonly></td>
|
|
</tr>
|
|
<tr data-price="55">
|
|
<td>Actual Asthalin Rotacap</td>
|
|
<td><input type="text" inputmode="numeric" class="form-control actual-units" name="actual_asthalin_rotacap_units" value="0"></td>
|
|
<td><input type="text" class="form-control actual-value" name="actual_asthalin_rotacap_value" value="0" readonly></td>
|
|
</tr>
|
|
<tr data-price="260">
|
|
<td>Actual Aerocort Inhaler</td>
|
|
<td><input type="text" inputmode="numeric" class="form-control actual-units" name="actual_aerocort_inhaler_units" value="0"></td>
|
|
<td><input type="text" class="form-control actual-value" name="actual_aerocort_inhaler_value" value="0" readonly></td>
|
|
</tr>
|
|
<tr data-price="109">
|
|
<td>Actual Aerocort Rotacap</td>
|
|
<td><input type="text" inputmode="numeric" class="form-control actual-units" name="actual_aerocort_rotacap_units" value="0"></td>
|
|
<td><input type="text" class="form-control actual-value" name="actual_aerocort_rotacap_value" value="0" readonly></td>
|
|
</tr>
|
|
<tr data-price="99">
|
|
<td>Actual Aerocort Forte Rotacap</td>
|
|
<td><input type="text" inputmode="numeric" class="form-control actual-units" name="actual_aerocort_forte_rotacap_units" value="0"></td>
|
|
<td><input type="text" class="form-control actual-value" name="actual_aerocort_forte_rotacap_value" value="0" readonly></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Total</td>
|
|
<td><input type="text" class="form-control" id="field-total_actual_pob_units" name="total_actual_pob_units" value="0" readonly></td>
|
|
<td><input type="text" class="form-control" id="field-total_actual_pob_value" name="total_actual_pob_value" value="0" readonly></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="d-grid mt-3">
|
|
<button class="btn btn-primary" type="submit">Submit</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@include('layouts.shared/footer-script')
|
|
<script src="{{ asset('assets/libs/sweetalert2/sweetalert2.min.js') }}"></script>
|
|
<script src="{{ asset('assets/libs/select2/select2.min.js') }}"></script>
|
|
<script>
|
|
(function () {
|
|
var hierarchy = @json($form->hierarchy_id ?? ($form->hierarchy ?? ''));
|
|
var partition = @json($form->partition ?? '');
|
|
var formId = @json($form_id);
|
|
var contacts = { ebt_doctor: [], ebt_chemist: [] };
|
|
var openContactId = '';
|
|
var unitFields = [
|
|
'asthalin_inhaler_units',
|
|
'asthalin_rotacap_units',
|
|
'aerocort_inhaler_units',
|
|
'aerocort_rotacap_units',
|
|
'aerocort_forte_rotacap_units'
|
|
];
|
|
|
|
function esc(value) {
|
|
return String(value == null ? '' : value)
|
|
.replace(/&/g, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/"/g, '"');
|
|
}
|
|
|
|
function whole(value) {
|
|
var text = String(value == null ? '' : value).trim();
|
|
if (text === '') return 0;
|
|
return /^\d+$/.test(text) ? parseInt(text, 10) : null;
|
|
}
|
|
|
|
function recalc(unitClass, valueClass, totalUnits, totalValue) {
|
|
var units = 0;
|
|
var value = 0;
|
|
var valid = true;
|
|
$(unitClass).each(function () {
|
|
var row = $(this).closest('tr');
|
|
var count = whole($(this).val());
|
|
if (count === null) {
|
|
valid = false;
|
|
row.find(valueClass).val('');
|
|
return;
|
|
}
|
|
var amount = count * parseInt(row.data('price'), 10);
|
|
row.find(valueClass).val(amount);
|
|
units += count;
|
|
value += amount;
|
|
});
|
|
$(totalUnits).val(valid ? units : '');
|
|
$(totalValue).val(valid ? value : '');
|
|
return valid;
|
|
}
|
|
|
|
function syncContactFields(type) {
|
|
var chemist = type === 'ebt_chemist';
|
|
$('#wrap-speciality').toggleClass('d-none', chemist);
|
|
$('#field-speciality').prop('disabled', chemist);
|
|
$('#wrap-doctor_location').toggleClass('d-none', chemist);
|
|
$('#field-doctor_location').prop('disabled', chemist);
|
|
$('#wrap-chemist_location').toggleClass('d-none', !chemist);
|
|
$('#field-chemist_location').prop('disabled', !chemist);
|
|
}
|
|
|
|
function fillContact(select) {
|
|
var option = select.options[select.selectedIndex];
|
|
$('#field-speciality').val(option ? (option.getAttribute('data-speciality') || '') : '');
|
|
$('#field-doctor_location').val(option ? (option.getAttribute('data-doctor-location') || '') : '');
|
|
$('#field-chemist_location').val(option ? (option.getAttribute('data-chemist-location') || '') : '');
|
|
$('#field-msl_code').val(option ? (option.getAttribute('data-code') || '') : '');
|
|
$('#field-contact_name').val(option ? (option.getAttribute('data-name') || '') : '');
|
|
$('#field-contact_type').val(option ? (option.getAttribute('data-type') || '') : '');
|
|
}
|
|
|
|
function initContactSearch(type) {
|
|
var select = $('#field-contact_id');
|
|
if (select.data('select2')) {
|
|
select.select2('destroy');
|
|
}
|
|
select.empty().append('<option value=""></option>');
|
|
(contacts[type] || []).forEach(function (item) {
|
|
var contact = item.contact || {};
|
|
var option = document.createElement('option');
|
|
option.value = item.value;
|
|
option.textContent = item.display || contact.name || '';
|
|
option.setAttribute('data-name', item.display || contact.name || '');
|
|
option.setAttribute('data-speciality', contact.speciality || '');
|
|
option.setAttribute('data-doctor-location', contact.doctor_location || '');
|
|
option.setAttribute('data-chemist-location', contact.chemist_location || '');
|
|
option.setAttribute('data-code', contact.msl_code || '');
|
|
option.setAttribute('data-type', type);
|
|
select.append(option);
|
|
});
|
|
select.select2({
|
|
width: '100%',
|
|
dropdownParent: $('.quick-action-form-card'),
|
|
placeholder: '-- Select --'
|
|
});
|
|
}
|
|
|
|
function lockContactSelect() {
|
|
$('#field-contact_id').prop('disabled', true);
|
|
}
|
|
|
|
function showList() {
|
|
$('#report-panel').addClass('d-none');
|
|
$('#tabs-wrapper').removeClass('d-none');
|
|
$('#pob-back').addClass('d-none');
|
|
}
|
|
|
|
function setActualVisible(show) {
|
|
$('#actual-section').toggleClass('d-none', !show);
|
|
$('#actual-section').find('input').prop('disabled', !show);
|
|
$('#field-upload_invoice').prop('required', false);
|
|
if (show) {
|
|
recalc('.actual-units', '.actual-value', '#field-total_actual_pob_units', '#field-total_actual_pob_value');
|
|
}
|
|
}
|
|
|
|
function unlockReportUnits() {
|
|
$('#report-form input[data-locked-unit]').remove();
|
|
$('.pob-units').each(function () {
|
|
var input = $(this);
|
|
var name = input.attr('data-unit-name') || input.attr('name');
|
|
if (name) input.attr('name', name);
|
|
input.prop('disabled', false).prop('readonly', false);
|
|
});
|
|
}
|
|
|
|
function lockReportUnits() {
|
|
unlockReportUnits();
|
|
$('.pob-units').each(function () {
|
|
var input = $(this);
|
|
var name = input.attr('name');
|
|
if (!name) return;
|
|
input.attr('data-unit-name', name);
|
|
$('<input type="hidden">').attr('data-locked-unit', '1').attr('name', name).val(input.val()).insertAfter(input);
|
|
input.prop('disabled', true).removeAttr('name');
|
|
});
|
|
}
|
|
|
|
function showReport(type, contactId) {
|
|
$('#tabs-wrapper').addClass('d-none');
|
|
$('#report-panel').removeClass('d-none');
|
|
$('#pob-back').removeClass('d-none');
|
|
$('#report-title').text('POB Details (Without Visit)');
|
|
$('#contact-label').html((type === 'ebt_chemist' ? 'Select Chemist' : 'Select Doctor') + ' <span class="text-danger">*</span>');
|
|
$('#report-form')[0].reset();
|
|
unlockReportUnits();
|
|
$('#field-submission-id').val('');
|
|
$('#field-record_date').prop('readonly', false);
|
|
$('#field-contact_type').val(type);
|
|
syncContactFields(type);
|
|
initContactSearch(type);
|
|
if (contactId) {
|
|
$('#field-contact_id').val(contactId).trigger('change');
|
|
}
|
|
lockContactSelect();
|
|
openContactId = contactId || '';
|
|
recalc('.pob-units', '.pob-value', '#field-total_pob_units', '#field-total_pob_value');
|
|
setActualVisible(false);
|
|
}
|
|
|
|
function openExisting(submission, mode) {
|
|
var data = submission.formdata || {};
|
|
var type = data.contact_type || 'ebt_doctor';
|
|
$('#tabs-wrapper').addClass('d-none');
|
|
$('#report-panel').removeClass('d-none');
|
|
$('#pob-back').removeClass('d-none');
|
|
$('#report-title').text(mode === 'upload' ? 'Upload Invoice' : 'Edit Order');
|
|
$('#contact-label').html((type === 'ebt_chemist' ? 'Select Chemist' : 'Select Doctor') + ' <span class="text-danger">*</span>');
|
|
$('#report-form')[0].reset();
|
|
unlockReportUnits();
|
|
$('#field-submission-id').val(submission.id || '');
|
|
$('#field-contact_type').val(type);
|
|
initContactSearch(type);
|
|
if (data.contact_id) {
|
|
$('#field-contact_id').val(data.contact_id).trigger('change');
|
|
}
|
|
lockContactSelect();
|
|
if (data.record_date) $('#field-record_date').val(data.record_date);
|
|
$('#field-record_date').prop('readonly', false);
|
|
syncContactFields(type);
|
|
$('#field-supply_status').val(mode === 'upload' ? 'Yes' : (data.supply_status || ''));
|
|
unitFields.forEach(function (name) {
|
|
$('#report-form [name="' + name + '"]').val(data[name] || 0);
|
|
var actual = data['actual_' + name];
|
|
$('#report-form [name="actual_' + name + '"]').val(mode === 'upload' ? (actual || data[name] || 0) : (actual || 0));
|
|
});
|
|
recalc('.pob-units', '.pob-value', '#field-total_pob_units', '#field-total_pob_value');
|
|
setActualVisible($('#field-supply_status').val() === 'Yes');
|
|
lockReportUnits();
|
|
openContactId = data.contact_id || '';
|
|
}
|
|
|
|
function loadOrders(row) {
|
|
var contactId = row.getAttribute('data-contact');
|
|
var holder = row.nextElementSibling;
|
|
if (holder && holder.classList.contains('pob-child') && holder.getAttribute('data-open') === 'yes') {
|
|
holder.remove();
|
|
return;
|
|
}
|
|
if (holder && holder.classList.contains('pob-child')) {
|
|
holder.remove();
|
|
}
|
|
var child = document.createElement('tr');
|
|
child.className = 'pob-child';
|
|
child.setAttribute('data-open', 'yes');
|
|
var colSpan = row.closest('table') && row.closest('table').id === 'chemist-table' ? 3 : 4;
|
|
child.innerHTML = '<td colspan="' + colSpan + '">Loading...</td>';
|
|
row.after(child);
|
|
$.getJSON('/form/pobhistory', { form_id: formId, contact_id: contactId }, function (data) {
|
|
var submissions = (data && data.submissions) || [];
|
|
var orderRows = submissions.map(function (submission) {
|
|
var info = submission.formdata || {};
|
|
var payload = esc(JSON.stringify(submission));
|
|
var button = '';
|
|
var workflowStatus = String(submission.workflow_status || '').toLowerCase();
|
|
if (info.supply_status === 'No' && info.submission_status === 'Order Taken') {
|
|
button = '<button type="button" class="btn btn-warning btn-xs edit-order" data-submission="' + payload + '">Edit</button>';
|
|
} else if (workflowStatus === 'rejected' && info.submission_status === 'Rejected') {
|
|
button = '<button type="button" class="btn btn-warning btn-xs upload-invoice" data-submission="' + payload + '">Upload Invoice</button>';
|
|
}
|
|
return '<tr><td>' + button + '</td><td>' + esc(info.record_date || '') + '</td><td>' + esc(info.submission_status || '') + '</td><td>' + esc(info.total_pob_value || '') + '</td><td>' + esc(info.total_actual_pob_value || '') + '</td></tr>';
|
|
}).join('');
|
|
child.innerHTML = '<td colspan="' + colSpan + '" class="p-0"><div class="table-responsive"><table class="table table-sm mb-0 pob-orders"><thead class="table-light"><tr><th>Action</th><th>Date</th><th>Status</th><th>Total Value</th><th>Actual Total</th></tr></thead><tbody>'
|
|
+ (orderRows || '<tr><td colspan="5" class="text-muted">No orders yet.</td></tr>')
|
|
+ '</tbody></table></div></td>';
|
|
}).fail(function () {
|
|
child.innerHTML = '<td colspan="' + colSpan + '" class="text-danger">Could not load orders.</td>';
|
|
});
|
|
}
|
|
|
|
function renderTable(tableId, type) {
|
|
var body = document.querySelector('#' + tableId + ' tbody');
|
|
var rows = contacts[type] || [];
|
|
body.innerHTML = '';
|
|
var chemist = type === 'ebt_chemist';
|
|
if (!rows.length) {
|
|
body.innerHTML = '<tr><td colspan="' + (chemist ? 3 : 4) + '" class="text-muted">No ' + (chemist ? 'chemists' : 'doctors') + ' yet.</td></tr>';
|
|
return;
|
|
}
|
|
rows.forEach(function (item) {
|
|
var contact = item.contact || {};
|
|
var tr = document.createElement('tr');
|
|
tr.setAttribute('data-contact', item.value);
|
|
tr.innerHTML = '<td><button type="button" class="btn btn-info btn-xs report-btn">Report</button></td>'
|
|
+ '<td class="pob-toggle"><i class="mdi mdi-arrow-down-drop-circle"></i> ' + esc(item.display || contact.name || '') + '</td>'
|
|
+ (chemist ? '' : '<td>' + esc(contact.speciality || '') + '</td>')
|
|
+ '<td>' + esc(contact.msl_code || '') + '</td>';
|
|
tr.querySelector('.report-btn').addEventListener('click', function () {
|
|
showReport(type, item.value);
|
|
});
|
|
tr.querySelector('.pob-toggle').addEventListener('click', function () {
|
|
loadOrders(tr);
|
|
});
|
|
body.appendChild(tr);
|
|
});
|
|
}
|
|
|
|
function refreshOpen() {
|
|
if (!openContactId) return;
|
|
var row = document.querySelector('tr[data-contact="' + openContactId.replace(/"/g, '\\"') + '"]');
|
|
if (!row) return;
|
|
var child = row.nextElementSibling;
|
|
if (child && child.classList.contains('pob-child')) {
|
|
child.remove();
|
|
}
|
|
loadOrders(row);
|
|
}
|
|
|
|
function filterTable(tableId, query) {
|
|
var needle = String(query || '').trim().toLowerCase();
|
|
document.querySelectorAll('#' + tableId + ' tbody tr').forEach(function (row) {
|
|
if (row.classList.contains('pob-child')) return;
|
|
var cells = row.querySelectorAll('td');
|
|
var label = [cells[1], cells[2], cells[3]].map(function (cell) {
|
|
return cell ? cell.textContent : '';
|
|
}).join(' ').toLowerCase();
|
|
var hide = needle !== '' && label.indexOf(needle) === -1;
|
|
row.style.display = hide ? 'none' : '';
|
|
var child = row.nextElementSibling;
|
|
if (child && child.classList.contains('pob-child')) {
|
|
child.style.display = hide ? 'none' : '';
|
|
}
|
|
});
|
|
}
|
|
|
|
function submitForm(form, done) {
|
|
if (!recalc('.pob-units', '.pob-value', '#field-total_pob_units', '#field-total_pob_value')) {
|
|
Swal.fire({ icon: 'error', title: 'Check the units', text: 'POB units must be a whole number. 0 is allowed.' });
|
|
return;
|
|
}
|
|
if (!$('#actual-section').hasClass('d-none') && !recalc('.actual-units', '.actual-value', '#field-total_actual_pob_units', '#field-total_actual_pob_value')) {
|
|
Swal.fire({ icon: 'error', title: 'Check the units', text: 'Actual POB units must be a whole number. 0 is allowed.' });
|
|
return;
|
|
}
|
|
var contactSelect = $('#field-contact_id');
|
|
contactSelect.prop('disabled', false);
|
|
openContactId = contactSelect.val() || openContactId;
|
|
var supplyYes = $('#field-supply_status').val() === 'Yes';
|
|
var invoiceFile = document.getElementById('field-upload_invoice');
|
|
var hasInvoice = invoiceFile && invoiceFile.files && invoiceFile.files.length > 0;
|
|
var submissionStatus = 'Order Taken';
|
|
if (supplyYes) submissionStatus = hasInvoice ? 'Invoice Uploaded' : 'Submitted';
|
|
$('#report-form [name="submission_status"]').val(submissionStatus);
|
|
var payload = new FormData(form);
|
|
contactSelect.prop('disabled', true);
|
|
$('#pageloader').css('display', 'flex').hide().fadeIn();
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/form/ajaxsubmit',
|
|
data: payload,
|
|
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' });
|
|
showList();
|
|
refreshOpen();
|
|
if (done) done();
|
|
} else {
|
|
Swal.fire({ icon: 'error', title: 'Data not submitted', text: data.message || 'Please try again.' });
|
|
}
|
|
},
|
|
error: function () {
|
|
$('#pageloader').fadeOut();
|
|
Swal.fire({ icon: 'error', title: 'Data not submitted', text: 'Please try again.' });
|
|
}
|
|
});
|
|
}
|
|
|
|
$('#field-contact_id').on('change', function () {
|
|
fillContact(this);
|
|
});
|
|
$('#report-form').on('input', '.pob-units', function () {
|
|
recalc('.pob-units', '.pob-value', '#field-total_pob_units', '#field-total_pob_value');
|
|
});
|
|
$('#field-supply_status').on('change', function () {
|
|
if (this.value === 'Yes') {
|
|
unitFields.forEach(function (name) {
|
|
var actual = $('#report-form [name="actual_' + name + '"]');
|
|
if (!actual.val() || actual.val() === '0') {
|
|
actual.val($('#report-form [name="' + name + '"]').val() || 0);
|
|
}
|
|
});
|
|
}
|
|
setActualVisible(this.value === 'Yes');
|
|
});
|
|
$('#report-form').on('input', '.actual-units', function () {
|
|
recalc('.actual-units', '.actual-value', '#field-total_actual_pob_units', '#field-total_actual_pob_value');
|
|
});
|
|
$('.pob-search').on('input', function () {
|
|
filterTable($(this).data('table'), $(this).val());
|
|
});
|
|
$('#report-form').on('submit', function (event) {
|
|
event.preventDefault();
|
|
submitForm(this);
|
|
});
|
|
$('#pob-back').on('click', showList);
|
|
setActualVisible(false);
|
|
$(document).on('click', '.edit-order', function () {
|
|
var raw = $(this).attr('data-submission');
|
|
if (!raw) return;
|
|
openExisting(JSON.parse(raw), 'edit');
|
|
});
|
|
$(document).on('click', '.upload-invoice', function () {
|
|
var raw = $(this).attr('data-submission');
|
|
if (!raw) return;
|
|
openExisting(JSON.parse(raw), 'upload');
|
|
});
|
|
|
|
$.getJSON('/form/getdoctorlist', { partition: partition, hierarchy: hierarchy }, function (data) {
|
|
(Array.isArray(data) ? data : []).forEach(function (item) {
|
|
var type = String((item.contact && item.contact.type) || '').toLowerCase();
|
|
if (contacts[type]) contacts[type].push(item);
|
|
});
|
|
renderTable('doctor-table', 'ebt_doctor');
|
|
renderTable('chemist-table', 'ebt_chemist');
|
|
});
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|