@include('header')
<style type="text/css">
fieldset legend {
    background: inherit;
    font-family: "Lato", sans-serif;
    color: #650812;
    font-size: 15px;
    left: 10px;
    padding: 0 10px;
    position: absolute;
    top: -12px;
    font-weight: 400;
    width: auto !important;
    border: none !important;
}

fieldset {
    background: #ffffff;
    border: 1px solid #C43853;
    border-radius: 5px;
    margin: 20px 0 1px 0;
    padding: 13px;
    position: relative;
}

.form-control {
    min-height: 1px;
    height: 25px;

    font-size: 17px;
}


.table th,
.table td {
    padding: 0.325rem;
    font-weight: bold;
}

label {
    font-weight: bold;
}

.select {
    height: 32px;
}

.btnpadding {
    padding: 3px;
}

.btnpadding2 {
    padding: 5px;
}
</style>
<div class="container-fluid flex-grow-1 container-p-y">
    <!-- <h4 class="font-weight-bold py-3 mb-0">O.T Schedule</h4> -->

    <div class="nav-tabs-top mb-4">
        <ul class="nav nav-tabs">
            <li class="nav-item">
                <a class="nav-link active" data-toggle="tab" href="#tab1">O.T. Schedule Form</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" data-toggle="tab" href="#tab4">O.T. Other Schedule Form</a>
            </li>
            <!-- <li class="nav-item">
                <a class="nav-link" data-toggle="tab" href="#tab2">O.T. Schedule List</a>
            </li> -->
            <li class="nav-item">
                <a class="nav-link" data-toggle="tab" href="#tab3" onclick="tab3()">Postpone O.T. List</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" data-toggle="tab" href="#tab5" onclick="tab5()">Postpone O.T. Other List</a>
            </li>
            <!-- <li class="nav-item">
                <a class="nav-link" data-toggle="tab" href="#tab3">OPD Summary Report 2</a>
            </li> -->

        </ul>
        <div class="tab-content">
            <div class="tab-pane fade show active" id="tab1">
            @include('ipd/incotschedule')
            </div>

            <div class="tab-pane fade" id="tab4">
            @include('ipd/incototherschedule')
            </div>
            <div class="tab-pane fade" id="tab2">
                <div class="card-body">
                    <form id="validation-form33" method="post" enctype="multipart/form-data">
                        <div class="form-row">

                            <div class="form-group col-md-2">
                                <label class="form-label">From Date </label>
                                <input type="date" name="FromDate" id="FromDate" class="form-control"
                                    value="{{date('Y-m-d')}}" autocomplete="off" required>
                            </div>
                            <div class="form-group col-md-2">
                                <label class="form-label">To Date</label>
                                <input type="date" name="ToDate" id="ToDate" class="form-control"
                                    value="{{date('Y-m-d')}}" autocomplete="off" required>
                            </div>

                            <input type="hidden" name="Search" value="Search">
                            <div class="form-group col-md-2" style="padding-top:20px;">
                                <button type="button" id="filter" class="btn btn-primary btn-finish">Search</button>
                            </div>
                        </div>

                    </form>

                    <div class="card">
                        <div class="card-body">


                            <div class="table-responsive" id="custresult">


                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="tab-pane fade" id="tab3">
                <div class="card-body">
                     <form id="validation-form44" method="post" enctype="multipart/form-data">
                     @csrf
                        <div class="form-row">

                            <div class="form-group col-md-2">
                                <label class="form-label">Next Operation Date </label>
                                <input type="date" name="OperationDate" id="OperationDate" class="form-control"
                                    value="{{date('Y-m-d')}}" autocomplete="off" required>
                            </div>
                            <!-- <div class="form-group col-md-2">
                                <label class="form-label">To Date</label>
                                <input type="date" name="ToDate3" id="ToDate3" class="form-control"
                                    value="{{date('Y-m-d')}}" autocomplete="off" required>
                            </div> -->

                            <input type="hidden" name="Search3" value="Search">
                            <div class="form-group col-md-2" style="padding-top:20px;">
                                <button type="submit" id="filter3" name="submit" class="btn btn-primary btn-finish">Update</button>
                            </div>
                        </div>

                    

                    <div class="card">
                        <div class="card-body">


                            <div class="table-responsive" id="custresult3">


                            </div>
                        </div>
                    </div>
                    </form>
                </div>
            </div>


            <div class="tab-pane fade" id="tab5">
                <div class="card-body">
                     <form id="validation-form442" method="post" enctype="multipart/form-data">
                     @csrf
                        <div class="form-row">

                            <div class="form-group col-md-2">
                                <label class="form-label">Next Operation Date </label>
                                <input type="date" name="OperationDate" id="OperationDate2" class="form-control"
                                    value="{{date('Y-m-d')}}" autocomplete="off" required>
                            </div>
                            <!-- <div class="form-group col-md-2">
                                <label class="form-label">To Date</label>
                                <input type="date" name="ToDate3" id="ToDate3" class="form-control"
                                    value="{{date('Y-m-d')}}" autocomplete="off" required>
                            </div> -->

                            <input type="hidden" name="Search3" value="Search">
                            <div class="form-group col-md-2" style="padding-top:20px;">
                                <button type="submit" id="filter32" name="submit" class="btn btn-primary btn-finish">Update</button>
                            </div>
                        </div>

                    

                    <div class="card">
                        <div class="card-body">


                            <div class="table-responsive" id="custresult32">


                            </div>
                        </div>
                    </div>
                    </form>
                </div>
            </div>

        </div>
    </div>


</div>
@include('masters/incmedicinemodal')
@include('ipd/incsurgicalprescmodal')
@include('ipd/incsurgicalprescmodal2')
@include('footerscript')
@include('excelscript')
<script>
    function companyLists() {
    $.ajax({
        url: "{{ url('companyLists') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}'
        },
        success: function(data) {
            $('#IolName').html(data);
        }
    });
}
function modelLists(Cname,IolType) {
    //var Cname = $('#IolName').val();
    $.ajax({
        url: "{{ url('modelLists2') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            Cname: Cname
        },
        success: function(data) {
            
            $('#IolType').html(data);
            $('#IolType').val(IolType).attr("selected",true);
        }
    });
}

function powerLists(Model,Power) {
    //var Cname = $('#IolName').val();
    //var Model = $('#IolType').val();
    $.ajax({
        url: "{{ url('powerLists2') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            Model: Model
        },
        success: function(data) {
            $('#IolPower').html(data);
            $('#IolPower').val(Power).attr("selected",true);
        }
    });
}

function printSurgicalPres() {
    var id = $('#id').val();
    if (id == '') {
        alert("Please Select OT Scheduled Id");
    } else {
        setTimeout(function() {
            window.open(
                '/{{projectUrl()}}printSurgicalPres/' + id, 'popUpWindow4',
                'height=1000,width=800,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
    }
}

function printSurgicalPres2() {
    var id = $('#id2').val();
    if (id == '') {
        alert("Please Select OT Scheduled Id");
    } else {
        setTimeout(function() {
            window.open(
                '/{{projectUrl()}}printSurgicalPres2/' + id, 'popUpWindow42',
                'height=1000,width=800,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
    }
}



function surgicalPresc() {
    $.ajax({
        url: "{{ url('surgicalPrescLists') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}'
        },
        success: function(data) {
            //console.log(data);
            $('#surgicalpresccustresult').html(data);
            $('#modal-report-surgical').modal("show");
        }
    });

}


function surgicalPresc2() {
    $.ajax({
        url: "{{ url('surgicalPrescLists2') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}'
        },
        success: function(data) {
            //console.log(data);
            $('#surgicalpresccustresult2').html(data);
            $('#modal-report-surgical2').modal("show");
        }
    });

}

function fixedDate() {
    var FixedDate = $('#FixedDate').val();
    $.ajax({
        url: "{{ url('fixedDate') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            FixedDate: FixedDate
        },
        success: function(data) {
            alert('Date Fixed Successfully!');
        }
    });
}

function addNewDrug() {
    $('#Medicineaction').val('Save');
    $('#Medicineid').val('');
    $('#MedicineName').val('');
    $('#Amount').val('');
    $('#medicinebtn').text("Save");
    $('#drugtitle').html(
        "Add <span class='font-weight-light'>Medicine</span>");
    procedure_lists();

}

function procedure_lists() {
    $.ajax({
        url: "{{ url('viewMedicineList') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}'
        },
        success: function(data) {
            //console.log(data);
            $('#medicinecustresult').html(data);
        }
    });
}



function saveMedicine() {
    var MedicineName = $('#MedicineName').val();
    var Amount = $('#Amount').val();
    var action = $('#Medicineaction').val();
    var id = $('#Medicineid').val();
    $.ajax({
        url: "{{ url('saveMedicine') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            Name: MedicineName,
            Amount: Amount,
            action: action,
            id: id
        },
        beforeSend: function() {
            $('#medicinebtn').attr('disabled', 'disabled');
            $('#medicinebtn').text('Please Wait...');
        },
        success: function(data) {

            $('#modal-report656').modal('hide');
            $('#drugaction').val('Save');
            $('#drugid').val('');
            $('#medicinebtn').attr('disabled', false);
            $('#medicinebtn').text('Submit');


        }
    });
}

function otSchList() {
    var ScheduleDate = $('#ScheduleDate').val();
    setTimeout(function() {
        window.open(
            '/{{projectUrl()}}otSchList/' + ScheduleDate, 'popUpWindow3',
            'height=600,width=1300,left=20,top=40,right=20,bottom=40,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
        );
    }, 1);
}

function otSchList2() {
    var ScheduleDate = $('#ScheduleDate2').val();
    setTimeout(function() {
        window.open(
            '/{{projectUrl()}}otSchList/' + ScheduleDate, 'popUpWindow3',
            'height=600,width=1300,left=20,top=40,right=20,bottom=40,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
        );
    }, 1);
}

function preOptNotes() {
    var id = $('#id').val();
    if (id == '') {
        alert("Please Select OT Scheduled Id");
    } else {
        // setTimeout(function() {
        //     window.open(
        //         '/{{projectUrl()}}preOptNotes/' + id, 'popUpWindow3',
        //         'height=1000,width=800,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
        //     );
        // }, 1);

        setTimeout(function() {
            window.open(
                '/{{projectUrl()}}preOptNotesTreatments/' + id, 'popUpWindow3',
                'height=1000,width=1200,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
    }
}

function preOptNotes2() {
    var id = $('#id2').val();
    if (id == '') {
        alert("Please Select OT Scheduled Id");
    } else {
        // setTimeout(function() {
        //     window.open(
        //         '/{{projectUrl()}}preOptNotes2/' + id, 'popUpWindow32',
        //         'height=1000,width=800,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
        //     );
        // }, 1);

        setTimeout(function() {
            window.open(
                '/{{projectUrl()}}preOptNotesTreatments/' + id, 'popUpWindow32',
                'height=1000,width=1200,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
            );
        }, 1);
    }
}

function getPkgDetails(PackageName) {
    $.ajax({
        url: "{{ url('getPackageDetails') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            PackageName: PackageName
        },
        dataType: "json",
        success: function(data) {
            $('#Amount').val(data.PackageAmt);
        }
    });

}

function getPkgDetails2(PackageName) {
    $.ajax({
        url: "{{ url('getPackageDetails') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            PackageName: PackageName
        },
        dataType: "json",
        success: function(data) {
            $('#Amount2').val(data.PackageAmt);
        }
    });

}

function refresh() {
    window.location.href = "/{{projectUrl()}}OtScheduled";
}

function blankCounselDetails() {
    var CurrDate = $('#CurrDate').val();
    $('#action').val('Save');
    $('#ScheduleDate').val(CurrDate);
    $('#Eye').val('');
    $('#K1Re').val('');
    $('#K1Le').val('');
    $('#K2Re').val('');
    $('#K2Le').val('');
    $('#Diff').val('');
    $('#Category').val('');
    $('#IolPower').val('');
    $('#Aconstant').val('');
    $('#Diagnosis').val('');
    $('#Ga').val('');
    $('#Amount').val('');
    $('#Bs').val('');
    $('#Us').val('');
    $('#Bp').val('');
    $('#Package').val('');
    $('#IopRe').val('');
    $('#IopLe').val('');
    $('#Advice').val('');
    $('#SmsAdvice').val('');
    $('#PkgAmt').val('');
    $('#InsComp').val('');
    $('#ReqAmt').val('');
    $('#SanctAmt').val('');
    $('#AddAmt').val('');
    $('#SettleAmt').val('');
    $('#SettleDate').val('');
    $('#UtrNo').val('');
    $('#AL').val('');
    $('#Acd').val('');
    $('#Consultant').val('');
    $('#IolType').val('');
    $('#Cyl').val('');
    $('#LT').val('');
    $('#Wtw').val('');
    $('#delete').attr('disabled', true);
    $('#preopt_notes').attr('disabled', true);
    $('#surgical_presc').attr('disabled', true);
    $('#PostPone').attr('checked',false);
    $('#Tab1').attr('checked',false);
    $('#Tab2').attr('checked',false);
    $('#Cataract').attr('checked',false);
    
    $('#Language').val(1);
}

function getCounselDetails() {
    var val = $('#id').val();
    var CurrDate = $('#CurrDate').val();
    $.ajax({
        url: "{{ url('getOtSchDetails') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            id: val
        },
        dataType: "json",
        success: function(data) {
           // console.log(data);
            if (data == 0) {
                $('#action').val('Save');
                $('#PatientId').val('');
                $('#MrdNo').val('');
                $('#PatientName').val('');
                $('#ScheduleDate').val(CurrDate);
                $('#Phone').val('');
                $('#Age').val('');
                $('#Address').val('');
                $('#Gender').val('');
                $('#Eye').val('');
                $('#K1Re').val('');
                $('#K1Le').val('');
                $('#K2Re').val('');
                $('#K2Le').val('');
                $('#Diff').val('');
                $('#Category').val('');
                $('#IolPower').val('').attr("selected",true);
                $('#Aconstant').val('');
                $('#Diagnosis').val('');
                $('#Ga').val('');
                $('#Amount').val('');
                $('#Bs').val('');
                $('#Us').val('');
                $('#Bp').val('');
                $('#Package').val('');
                $('#IopRe').val('');
                $('#IopLe').val('');
                $('#Advice').val('');
                $('#SmsAdvice').val('');
                $('#PkgAmt').val('');
                $('#InsComp').val('');
                $('#ReqAmt').val('');
                $('#SanctAmt').val('');
                $('#AddAmt').val('');
                $('#SettleAmt').val('');
                $('#SettleDate').val('');
                $('#UtrNo').val('');
                $('#AL').val('');
                $('#Acd').val('');
                $('#Consultant').val('');
                $('#IolType').val('').attr("selected",true);
                $('#Cyl').val('');
                $('#LT').val('');
                $('#Wtw').val('');
                $('#delete').attr('disabled', true);
                $('#preopt_notes').attr('disabled', true);
                $('#surgical_presc').attr('disabled', true);
                $('#PostPone').attr('checked',false);
                $('#IolName').val('').attr("selected",true);
                $('#AddIol').val('');
                $('#Language').val(1);
                $('#Tab1').attr('checked',false);
                $('#Tab1').attr('checked',false);
                $('#Cataract').attr('checked',false);

            } else {
                $('#action').val('Edit');
                $('#IolName').val(data.IolName).attr("selected",true);
                modelLists(data.IolName,data.IolType);
                powerLists(data.IolType,data.IolPower);
                $('#PatientId').val(data.PatientId);
                $('#MrdNo').val(data.MrdNo);
                $('#PatientName').val(data.PatientName);
                $('#ScheduleDate').val(data.ScheduleDate);
                $('#Phone').val(data.Phone);
                $('#Age').val(data.Age);
                $('#Address').val(data.Address);
                $('#Gender').val(data.Gender);
                $('#Eye').val(data.Eye);
                $('#K1Re').val(data.K1Re);
                $('#K1Le').val(data.K1Le);
                $('#K2Re').val(data.K2Re);
                $('#K2Le').val(data.K2Le);
                $('#Diff').val(data.Diff);
                $('#Category').val(data.Category);
                
                $('#Aconstant').val(data.Aconstant);
                $('#Diagnosis').val(data.Diagnosis);
                $('#Ga').val(data.Ga);
                $('#Amount').val(data.Amount);
                $('#Bs').val(data.Bs);
                $('#Us').val(data.Us);
                $('#Bp').val(data.Bp);
                $('#Package').val(data.Package);
                $('#IopRe').val(data.IopRe);
                $('#IopLe').val(data.IopLe);
                $('#Advice').val(data.Advice);
                $('#SmsAdvice').val(data.Advice);
                $('#PkgAmt').val(data.PkgAmt);
                $('#InsComp').val(data.InsComp);
                $('#ReqAmt').val(data.ReqAmt);
                $('#SanctAmt').val(data.SanctAmt);
                $('#AddAmt').val(data.AddAmt);
                $('#SettleAmt').val(data.SettleAmt);
                $('#SettleDate').val(data.SettleDate);
                $('#UtrNo').val(data.UtrNo);
                $('#AL').val(data.AL);
                $('#Acd').val(data.Acd);
                $('#Consultant').val(data.Consultant);
                //$('#IolPower').val(data.IolPower).attr("selected",true);
                
                //$('#IolType').val(data.IolType).attr("selected",true);
                $('#Cyl').val(data.Cyl);
                $('#LT').val(data.LT);
                $('#Wtw').val(data.Wtw);
                $('#delete').attr('disabled', false);
                $('#preopt_notes').attr('disabled', false);
                $('#surgical_presc').attr('disabled', false);
                
                $('#AddIol').val(data.AddIol);
                $('#Language').val(data.Language);
                if(data.PostPone == 1){
                    $('#PostPone').attr('checked',true);
                }
                else{
                    $('#PostPone').attr('checked',false);
                }

                if(data.Tab1 == 1){
                    $('#Tab1').attr('checked',true);
                }
                else{
                    $('#Tab1').attr('checked',false);
                }

                if(data.Tab2 == 1){
                    $('#Tab2').attr('checked',true);
                }
                else{
                    $('#Tab2').attr('checked',false);
                }

                if(data.Cataract == 1){
                    $('#Cataract').attr('checked',true);
                }
                else{
                    $('#Cataract').attr('checked',false);
                }
                
               

            }
        }
    });
}


function blankCounselDetails2() {
    var CurrDate = $('#CurrDate').val();
    $('#action2').val('Save');
                $('#PatientId2').val('');
                
                $('#PatientName2').val('');
                $('#ScheduleDate2').val(CurrDate);
                $('#Phone2').val('');
                $('#Age2').val('');
                $('#Address2').val('');
                $('#Gender2').val('');
                $('#Eye2').val('');
                $('#Category2').val('');
                $('#Diagnosis2').val('');
                $('#Ga2').val('');
                $('#Amount2').val('');
                $('#Bs2').val('');
                $('#Us2').val('');
                $('#Bp2').val('');
                $('#Package2').val('');
                $('#IopRe2').val('');
                $('#IopLe2').val('');
                $('#Advice2').val('');
                $('#SmsAdvice2').val();
                $('#PkgAmt2').val('');
                $('#InsComp2').val('');
                $('#ReqAmt2').val('');
                $('#SanctAmt2').val('');
                $('#AddAmt2').val('');
                $('#SettleAmt2').val('');
                $('#SettleDate2').val('');
                $('#UtrNo2').val('');
                $('#Consultant2').val('');
                $('#delete2').attr('disabled', true);
                $('#preopt_notes2').attr('disabled', true);
                $('#surgical_presc2').attr('disabled', true);
                $('#PostPone2').attr('checked',false);
                $('#Tab12').attr('checked',false);
                $('#Tab22').attr('checked',false);
                $('#Language2').val(1);
}

function getCounselDetails2() {
    var val = $('#id2').val();
    var CurrDate = $('#CurrDate').val();
    $.ajax({
        url: "{{ url('getOtOtherSchDetails') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            id: val
        },
        dataType: "json",
        success: function(data) {
           // console.log(data);
            if (data == 0) {
                blankCounselDetails2();
                $('#MrdNo2').val('');

            } else {
                $('#action2').val('Edit');
                $('#PatientId2').val(data.PatientId);
                $('#MrdNo2').val(data.MrdNo);
                $('#PatientName2').val(data.PatientName);
                $('#ScheduleDate2').val(data.ScheduleDate);
                $('#Phone2').val(data.Phone);
                $('#Age2').val(data.Age);
                $('#Address2').val(data.Address);
                $('#Gender2').val(data.Gender);
                $('#Eye2').val(data.Eye);
                
                $('#Category2').val(data.Category);
               
               
                $('#Diagnosis2').val(data.Diagnosis);
                $('#Ga2').val(data.Ga);
                $('#Amount2').val(data.Amount);
                $('#Bs2').val(data.Bs);
                $('#Us2').val(data.Us);
                $('#Bp2').val(data.Bp);
                $('#Package2').val(data.Package);
                $('#IopRe2').val(data.IopRe);
                $('#IopLe2').val(data.IopLe);
                $('#Advice2').val(data.Advice);
                $('#SmsAdvice2').val(data.Advice);
                $('#PkgAmt2').val(data.PkgAmt);
                $('#InsComp2').val(data.InsComp);
                $('#ReqAmt2').val(data.ReqAmt);
                $('#SanctAmt2').val(data.SanctAmt);
                $('#AddAmt2').val(data.AddAmt);
                $('#SettleAmt2').val(data.SettleAmt);
                $('#SettleDate2').val(data.SettleDate);
                $('#UtrNo2').val(data.UtrNo);
                
                $('#Consultant2').val(data.Consultant);
               
                $('#delete2').attr('disabled', false);
                $('#preopt_notes2').attr('disabled', false);
                $('#surgical_presc2').attr('disabled', false);
                
                $('#Language2').val(data.Language);
                if(data.PostPone == 1){
                    $('#PostPone2').attr('checked',true);
                }
                else{
                    $('#PostPone2').attr('checked',false);
                }

                if(data.Tab1 == 1){
                    $('#Tab12').attr('checked',true);
                }
                else{
                    $('#Tab12').attr('checked',false);
                }
                
                if(data.Tab2 == 1){
                    $('#Tab22').attr('checked',true);
                }
                else{
                    $('#Tab22').attr('checked',false);
                }
                


            }
        }
    });
}

function getMaxSchId() {
    $.ajax({
        url: "{{ url('getMaxSchId') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}'
        },
        success: function(data) {
            //alert(data);
            $('#id').val(data);
        }
    });
}

function getMaxSchId2() {
    $.ajax({
        url: "{{ url('getMaxSchId2') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}'
        },
        success: function(data) {
            //alert(data);
            $('#id2').val(data);
        }
    });
}

function success_toast() {
    var isRtl = $('body').attr('dir') === 'rtl' || $('html').attr('dir') === 'rtl';
    $.growl.notice({
        title: 'Success',
        message: 'Record Saved Successfully!',
        location: isRtl ? 'tl' : 'tr'
    });
}

function error_toast() {
    var isRtl = $('body').attr('dir') === 'rtl' || $('html').attr('dir') === 'rtl';
    $.growl.error({
        title: 'Error',
        message: 'Record Saved Successfully!',
        location: isRtl ? 'tl' : 'tr'
    });
}


function deleteRecord() {
    var id = $('#id').val();
    swal({
        title: "Are you sure?",
        text: "You will not be able to recover this Queue Record!",
        type: "warning",
        showCancelButton: true,
        confirmButtonClass: "btn-danger",
        confirmButtonText: "Yes, delete",
        cancelButtonText: "No, cancel",
        closeOnConfirm: false,
        closeOnCancel: false
    }, function(isConfirm) {
        if (isConfirm) {
            $.ajax({
                url: "{{ url('deleteOtSchedule') }}",
                method: "POST",
                data: {
                    _token: '{{csrf_token()}}',
                    id: id
                },
                beforeSend: function() {
                    $('.confirm').attr('disabled', 'disabled');
                    $('.confirm').text('Please Wait...');
                },
                success: function(data) {
                    swal("Deleted!", "Record has been deleted.", "success");
                    window.location.href = "/{{projectUrl()}}OtScheduled";
                }
            });
        } else {
            swal("Cancelled", "Record is safe :)", "error");
        }
    });
}

function getPrevVisitDetails(MrdNo) {
    //var MrdNo = $('#MrdNo').val();
    $.ajax({
        url: "{{ url('getPrevVisitDetails') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            MrdNo: MrdNo
        },
        dataType: "json",
        success: function(data) {
            //console.log(data);
            // $('#K1Re').val(data.RefK1Re);
            // $('#K1Le').val(data.RefK1Le);
            // $('#K2Re').val(data.RefK2Re);
            // $('#K2Le').val(data.RefK2Le);
            // $('#Diff').val(data.RefDiffRe);
            $('#Diagnosis').val(data.Diagnosis);
            $('#Bp').val(data.BP);
            $('#IopRe').val(data.IopNctRe);
            $('#IopLe').val(data.IopNctLe);
            $('#Advice').val(data.Advice);
            $('#SmsAdvice').val('Catract Surgery');
        }
    });
}


function getPrevVisitDetails2(MrdNo) {
    //var MrdNo = $('#MrdNo').val();
    $.ajax({
        url: "{{ url('getPrevVisitDetails') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            MrdNo: MrdNo
        },
        dataType: "json",
        success: function(data) {
            
            //console.log(data);
            // $('#K1Re').val(data.RefK1Re);
            // $('#K1Le').val(data.RefK1Le);
            // $('#K2Re').val(data.RefK2Re);
            // $('#K2Le').val(data.RefK2Le);
            // $('#Diff').val(data.RefDiffRe);
            $('#Diagnosis2').val(data.Diagnosis);
            $('#Bp2').val(data.BP);
            $('#IopRe2').val(data.IopNctRe);
            $('#IopLe2').val(data.IopNctLe);
            $('#Advice2').val(data.Advice);
        }
    });
}
$(document).ready(function() {
    modelLists();
    companyLists();
    powerLists();
    //queueList3();
    $(document).on("click", ".updatemedicine", function(event) {
        event.preventDefault();
        event.stopPropagation();
        var id = $(this).attr("data-id");
        var action = "fetch_record";
        $.ajax({
            url: "{{ url('editMedicine') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                id: id
            },
            dataType: "json",
            success: function(data) {
                $('#MedicineName').val(data.Name);
                $('#Amount').val(data.Amount);
                $('#Medicineaction').val('Edit');

                $('#Medicineid').val(id);
                $('#medicinebtn').text("Update");
                $('#modal-report656').modal('show');
                $('.modal-title').html(
                    "Update <span class='font-weight-light'>Medicine</span>");

            }
        });
    });



    $(document).on("click", ".deletemedicine", function(event) {
        event.preventDefault();
        var id = $(this).attr("data-id");
        var action = "delete";
        //alert(id);
        swal({
            title: "Are you sure?",
            text: "You will not be able to recover this Medicine!",
            type: "warning",
            showCancelButton: true,
            confirmButtonClass: "btn-danger",
            confirmButtonText: "Yes, delete",
            cancelButtonText: "No, cancel",
            closeOnConfirm: false,
            closeOnCancel: false
        }, function(isConfirm) {
            if (isConfirm) {
                $.ajax({
                    url: "{{ url('deleteMedicine') }}",
                    method: "POST",
                    data: {
                        _token: '{{csrf_token()}}',
                        id: id
                    },

                    success: function(data) {
                        swal("Deleted!", "Medicine has been deleted.", "success");

                        procedure_lists();

                    }
                });

            } else {
                swal("Cancelled", "Medicine is safe :)", "error");
            }
        });


    });
    $(document).on("input", "#MrdNo", function(event) {
        getMaxSchId();
        
        blankCounselDetails();
        var val = this.value;
        if (val == '') {
            blankCounselDetails();
            $('#action').val('Save');
            $('#PatientId').val('');
            //$('#MrdNo').val('');
            $('#PatientName').val('');
            $('#Phone').val('');
            $('#Age').val('');
            $('#Address').val('');
            $('#Gender').val('');
        }
        $.ajax({
            url: "{{ url('getPatientDetails') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                id: val
            },
            dataType: "json",
            success: function(data) {
                //console.log(data);
                //$('#MrdNo').val(data.MrdNo);
                $('#PatientName').val(data.PatientName);
                $('#Phone').val(data.Phone);
                $('#Age').val(data.Age);
                $('#Address').val(data.Address);
                $('#Gender').val(data.Gender);
                getPrevVisitDetails(data.MrdNo);

            }
        });

    });

    $(document).on("input", "#MrdNo2", function(event) {
        
        getMaxSchId2();
        
        blankCounselDetails2();
        var val = this.value;
        if (val == '') {
            blankCounselDetails2();
            $('#action2').val('Save');
            $('#PatientId2').val('');
            //$('#MrdNo').val('');
            $('#PatientName2').val('');
            $('#Phone2').val('');
            $('#Age2').val('');
            $('#Address2').val('');
            $('#Gender2').val('');
        }
        $.ajax({
            url: "{{ url('getPatientDetails') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                id: val
            },
            dataType: "json",
            success: function(data) {
                //console.log(data);
                //$('#MrdNo').val(data.MrdNo);
                $('#PatientName2').val(data.PatientName);
                $('#Phone2').val(data.Phone);
                $('#Age2').val(data.Age);
                $('#Address2').val(data.Address);
                $('#Gender2').val(data.Gender);
                getPrevVisitDetails2(data.MrdNo);

            }
        });

    });


    $('#validation-form').on('submit', function(e) {
        e.preventDefault();
        if ($('#validation-form').valid()) {
            $.ajax({
                url: "{{ url('saveOtScheduled') }}",
                method: "POST",
                data: new FormData(this),
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#submit').attr('disabled', 'disabled');
                    $('#submit').text('Please Wait...');
                },
                success: function(data) {
                    //alert(data);exit();
                    if (data == 0) {
                        alert("Scheduled Date is Fixed");
                    } else {
                        success_toast();
                        $('#delete').attr('disabled', false);
                        $('#preopt_notes').attr('disabled', false);
                        $('#surgical_presc').attr('disabled', false);
                        $('#action').val('Edit');
                    }

                    $('#submit').attr('disabled', false);
                    $('#submit').text('Save');

                }
            });
        }
    });

    $('#validation-form2').on('submit', function(e) {
        e.preventDefault();
        if ($('#validation-form2').valid()) {
            $.ajax({
                url: "{{ url('saveOtOtherScheduled') }}",
                method: "POST",
                data: new FormData(this),
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#submit2').attr('disabled', 'disabled');
                    $('#submit2').text('Please Wait...');
                },
                success: function(data) {
                    //alert(data);exit();
                    if (data == 0) {
                        alert("Scheduled Date is Fixed");
                    } else {
                        success_toast();
                        $('#delete2').attr('disabled', false);
                        $('#preopt_notes2').attr('disabled', false);
                        $('#surgical_presc2').attr('disabled', false);
                        $('#action2').val('Edit');
                    }

                    $('#submit2').attr('disabled', false);
                    $('#submit2').text('Save');

                }
            });
        }
    });


    $('#validation-form22').on('submit', function(e) {
        //alert();
        e.preventDefault();

    });


    $('#filter').click(function() {
        var FromDate = $('#FromDate').val();
        var ToDate = $('#ToDate').val();
        if (FromDate != '' && ToDate != '') {
            queueList(FromDate, ToDate);
        } else {
            alert('Both Date is required');
        }
    });

    $('#refresh').click(function() {
        $('#FromDate').val('');
        $('#ToDate').val('');
        queueList();
    });

    function queueList(FromDate = '', ToDate = '') {
        $.ajax({
            url: "{{ url('viewOtScheduleList') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                FromDate: FromDate,
                ToDate: ToDate
            },
            success: function(data) {
                //console.log(data);
                $('#custresult').html(data);
            }
        });
    }


    $('#validation-form44').on('submit', function(e) {
        e.preventDefault();
        if ($('#validation-form44').valid()) {
            $.ajax({
                url: "{{ url('updateOperationDate') }}",
                method: "POST",
                data: new FormData(this),
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#filter3').attr('disabled', 'disabled');
                    $('#filter3').text('Please Wait...');
                },
                success: function(data) {
                    queueList3();
                    $('#filter3').attr('disabled', false);
                    $('#filter3').text('Update');
                    console.log(data);
                }
            });
        }
    });

    
    $('#validation-form442').on('submit', function(e) {
        e.preventDefault();
        if ($('#validation-form442').valid()) {
            $.ajax({
                url: "{{ url('updateOperationDate2') }}",
                method: "POST",
                data: new FormData(this),
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#filter32').attr('disabled', 'disabled');
                    $('#filter32').text('Please Wait...');
                },
                success: function(data) {
                    queueList32();
                    $('#filter32').attr('disabled', false);
                    $('#filter32').text('Update');
                    console.log(data);
                }
            });
        }
    });


    $('#filter3').click(function() {
        var FromDate = $('#FromDate3').val();
        var ToDate = $('#ToDate3').val();
        if (FromDate != '' && ToDate != '') {
            queueList(FromDate, ToDate);
        } else {
            alert('Both Date is required');
        }
    });

    $('#refresh3').click(function() {
        $('#FromDate3').val('');
        $('#ToDate3').val('');
        queueList3();
    });

    $('#filter32').click(function() {
        var FromDate = $('#FromDate32').val();
        var ToDate = $('#ToDate32').val();
        if (FromDate != '' && ToDate != '') {
            queueList(FromDate, ToDate);
        } else {
            alert('Both Date is required');
        }
    });

    $('#refresh32').click(function() {
        $('#FromDate32').val('');
        $('#ToDate32').val('');
        queueList32();
    });


});

function queueList3() {
        $.ajax({
            url: "{{ url('viewOtSchedulePostPoneList') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}'
            },
            success: function(data) {
                console.log(data);
                $('#custresult3').html(data);
            }
        });
    }

    function queueList32() {
        $.ajax({
            url: "{{ url('viewOtSchedulePostPoneList2') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}'
            },
            success: function(data) {
                console.log(data);
                $('#custresult32').html(data);
            }
        });
    }

function tab3(){
    queueList3();
}

function tab5(){
    queueList32();
}


</script>