<?php echo $__env->make('header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<div class="container-fluid flex-grow-1 container-p-y">
<style>
    .table th, .table td {
    padding: 5px;
    padding-left: 10px;
}
</style>
    <h4 class="font-weight-bold py-3 mb-0">Create IPD Bill</h4>

    <form id="validation-form" novalidate="novalidate" method="POST" enctype="multipart/form-data" autocomplete="off"
        action="">

        <input type="hidden" name="actionvalue" value="<?php echo e($action); ?>">
        <input type="hidden" name="saveid" id="saveid" value="<?php echo e($id); ?>">
        <input type="hidden" name="OtId" id="OtId" value="<?php echo e($ConsellingId); ?>">
        <input type="hidden" name="Roll" value="<?php echo e($roll); ?>">
        <input type="hidden" name="IpdNo" value="<?php echo e($otresult[0]->IpdNo); ?>">
        
        <?php echo csrf_field(); ?>
        <div class="card mb-12 mb-4">
            <div class="card-body">
               

                <table class="table table-bordered table-striped mb-0">
                    <thead>

                        <tr>
                            <input type="hidden" id="BillId" value="<?php echo e($otresult[0]->id); ?>">
                            <th align="center" valign="top">Bill NO </th>
                            <th align="left" valign="top" style="width: 100px;"><input name="BillNo" id="Bill_No"
                                    type="text" class="form-control" placeholder="" value="<?php echo e($BillNo); ?>" readonly /></th>
                            <th align="center" valign="top">Bill Type </th>
                            <th align="left" valign="top">
                                <select class="form-control" name="BillType" id="BillType">
                                    <option value="General" <?php if($otresult[0]->BillType == 'General'){?> selected <?php } ?>>General</option>
                                    <option value="Cashless" <?php if($otresult[0]->BillType == 'Cashless'){?> selected <?php } ?>>Cashless</option>
                                </select>
                            </th>
                            <th width="20" align="center" valign="top">MRD No </th>
                            <th width="150" align="center" valign="top" style="width: 100px;"><input type="text"
                                    class="form-control" placeholder="" value="<?php echo e($otresult[0]->MrdNo); ?>" id="MrdNo" name="MrdNo" required readonly>
                                <div class="clearfix"></div>
                            </th>
                            <!-- <th width="20" align="center" valign="top">IPD.No </th>
                                    <th width="50" align="center" valign="top"><input type="text" class="form-control"
                                            placeholder="" id="IpdNo" name="IpdNo" readonly>
                                        <div class="clearfix"></div>
                                    </th> -->
                            <th width="30" align="center" valign="top">Patient Name </th>
                            <th colspan="2" width="180" align="center" valign="top"><input type="text"
                                    class="form-control" placeholder="" required value="<?php echo e($otresult[0]->PatientName); ?>" name="PatientName" id="PatientName">
                                <div class="clearfix"></div>
                            </th>

                            <th width="50" align="center" valign="top">Age/Gender </th>
                            <th width="100" align="center" valign="top"><input type="text" class="form-control"
                                    placeholder="" id="AgeGender"  required value="<?php echo e($AgeGender); ?>" name="AgeGender">

                                <div class="clearfix"></div>
                            </th>

                        </tr>

                        <tr>

                            <th width="20" align="center" valign="top">Bill Date </th>
                            <th width="20" align="center" valign="top"><input type="date" name="BillDate" id="BillDate"
                                    class="form-control" value="<?php echo e($BillDate); ?>" required></th>

                            <th width="50" align="center" valign="top">Admission Date</th>
                            <th width="20" align="center" valign="top"><input type="date" name="AdmissionDate"
                                    id="AdmissionDate" class="form-control" value="<?php echo e($otresult[0]->AdmissionDate); ?>"></th>

                            <th width="50" align="center" valign="top">Operation Date</th>
                            <th width="50" align="center" valign="top"><input type="date" name="OperationDate"
                                    class="form-control" id="OperationDate" value="<?php echo e($OperationDate); ?>" required></th>
                            <th width="30" align="center" valign="top">Discharge Date </th>
                            <th width="30" align="center" valign="top"><input type="date" id="DischargeDate"
                                    name="DischargeDate" class="form-control" value="<?php echo e($SurgeryDate); ?>"></th>

                            <th width="30" align="center" valign="top">Consultant Name </th>
                            <th width="30" align="center" valign="top" colspan="2"><select class="form-control"
                                    name="Consultant" id="ConsultantId" required>
                                    <option value="" selected disabled>Search Consultant</option>
                                    <?php $__currentLoopData = $consultantList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $result): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($result->id); ?>" <?php if($otresult[0]->Consultant == $result->id){?> selected <?php } ?>><?php echo e($result->Name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select></th>
                        </tr>

                        <tr>
                            <th>Procedure Name </th>
                            <th colspan="10"><input type="text" class="form-control" id="Diagnosis" placeholder=""
                                    name="Diagnosis" value="<?php echo e($Diagnosis); ?>"></th>
                        </tr>

                    </thead>
                    <tbody>
                    </tbody>
                </table>

                <table class="table table-bordered table-striped mb-0">
    <thead>
        <!-- Hidden Fields -->
        <input type="hidden" name="chargesaction" id="action" value="Save">
        <input type="hidden" name="id" id="id">
        <input type="hidden" name="Days" id="Days" value="1">
        <input type="hidden" name="SubTotal" id="SubTotal" value="<?php echo e($SubTotal); ?>" readonly>
        <input type="hidden" name="Discount" id="Discount" value="0">
        <input type="hidden" name="GrossAmt" id="GrossAmt" value="<?php echo e($SubTotal); ?>" readonly>
        <input type="hidden" name="PaidAmt" id="PaidAmt" value="<?php echo e($SubTotal); ?>" value="0">
        <input type="hidden" id="OldAmount" value="">

        <!-- Package Selection Row -->
        <tr>
            <th style="width: 15%;">Package Name</th>
            <th style="width: 25%;">
                <select name="PackageName" id="PackageName" class="form-control" onchange="getPackageDetails(this.value)">
                    <option value="" selected disabled>...</option>
                    <?php $__currentLoopData = $packagelist; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $result): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($result->PackageName); ?>" <?php echo e(($otresult[0]->PackageName == $result->PackageName) ? 'selected' : ''); ?>>
                            <?php echo e($result->PackageName); ?>

                        </option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </th>
            <th style="width: 15%;">Package Amount</th>
            <th style="width: 20%;">
                <input type="text" value="<?php echo e($SubTotal); ?>" class="form-control" id="PackageAmt" name="PackageAmt" placeholder="" onkeypress="return isNumberKey(event)">
            </th>
            <th style="width: 10%;">
                <button class="btn btn-success btn-sm" type="button" onclick="calCharges()">
                    <i class="feather icon-plus"></i> Calculate
                </button>
            </th>
            <th colspan="2" style="width: 15%;"></th>
        </tr>

        <!-- Charges Entry Row -->
        <tr>
            <th>Charges Name <span class="text-danger">*</span></th>
            <th>
                <input class="form-control" type="text" list="Charges" name="ChargesName" id="ChargesName" onchange="getChargesDetails(this.value)">
                <datalist id="Charges"></datalist>
            </th>

            <th>Rate <span class="text-danger">*</span></th>
            <th>
                <input type="text" class="form-control" name="Rate" id="Rate" placeholder="" onkeypress="return isNumberKey(event)" oninput="getAmount(Days.value, this.value)">
            </th>

            <th colspan="2">
                <!-- Amount field is hidden but remains a text input -->
                <div class="input-group">
                    <input type="text" class="form-control d-none" name="Amount" id="Amount" placeholder="" readonly onkeypress="return isNumberKey(event)">
                    <button class="btn btn-success btn-sm" type="button"  id="submit" onclick="saveBills()">
                        <i class="feather icon-plus"></i> Add
                    </button>
                </div>
            </th>
        </tr>

        <!-- Loading & Output Row -->
        <tr>
            <th colspan="7">
                <div id="please_wait" class="text-center" style="display: none; padding: 40px 0;">
                    Please Wait... 
                    <img src="<?php echo e(url('preload.gif')); ?>" alt="Loading" style="width: 30px; height: 30px;">
                </div>
                <div class="table-responsive" id="custresult"></div>
            </th>
        </tr>
    </thead>
</table>

                <br>
                <div class="col-sm-12">
                    <span style="color:red;display: none;" id="error_msg">Package Amount Not Matched
                        With Sub Total</span><br>
                    <button class="btn btn-primary" type="submit" id="submit_save">Submit</button>
                    <button class="btn btn-success" type="button" onclick="print()">Print</button>
                    <a href="/<?php echo e(projectUrl()); ?>addIpdBill2/<?php echo e($otresult[0]->MrdNo); ?>/<?php echo e($ConsellingId); ?>" class="btn btn-danger" type="button">Refresh</a>
                </div>

            </div>
        </div>







    </form>


</div>

<?php echo $__env->make('ipd/incbillchargesmodal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php echo $__env->make('footerscript', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<script>
    function updateCharges(id,name,amount){
        $('#Chargesid').val(id);
        $('#id').val(id);
        $('#submit').html('<i class="feather icon-plus"></i> Update');
        $('#action').val('Edit');
        $('#ChargesName').val(name);
        $('#Days').val(1);
        $('#Rate').val(amount);
        $('#Amount').val(amount);
        $('#OldAmount').val(amount);
        //$('#modal-report656').modal("show");
    }

    function saveUpdateCharges(){
        var id =  $('#Chargesid').val();
        var name =  $('#ChargesName').val();
        var PackageName = $('#PackageName').val();
        $.ajax({
        url: "<?php echo e(url('saveUpdateCharges')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            id: id,
            name: name
        },
        success: function(data) {
            procedure_lists(PackageName);
            $('#modal-report656').modal("hide");
        }
    });

    }
function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}

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

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

function updateBill() {
    var BillId = $('#BillId').val();
    var SubTotal = $('#SubTotal').val();
    var Discount = $('#Discount').val();
    var GrossAmt = $('#GrossAmt').val();
    var PaidAmt = $('#PaidAmt').val();
    var BalAmt = $('#BalAmt').val();
    var PayMode = $('#PayMode').val();
    var Narration = $('#Narration').val();
    var BillDate = $('#BillDate').val();
    var AdmissionDate = $('#AdmissionDate').val();
    var OperationDate = $('#OperationDate').val();
    var DischargeDate = $('#DischargeDate').val();
    var ConsultantId = $('#ConsultantId').val();
    var PatientName = $('#PatientName').val();
    var AgeGender = $('#AgeGender').val();
    $.ajax({
        url: "<?php echo e(url('updateIpdBill')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            BillId: BillId,
            SubTotal: SubTotal,
            Discount: Discount,
            GrossAmt: GrossAmt,
            PaidAmt: PaidAmt,
            BalAmt: BalAmt,
            PayMode: PayMode,
            Narration: Narration,
            BillDate: BillDate,
            AdmissionDate: AdmissionDate,
            OperationDate: OperationDate,
            DischargeDate: DischargeDate,
            ConsultantId: ConsultantId,
            PatientName: PatientName,
            AgeGender: AgeGender
        },
        success: function(data) {
            setTimeout(function() {
                window.open(
                    '/<?php echo e(projectUrl()); ?>ipdBillPrint/' + BillId, 'popUpWindow3',
                    'height=1000,width=1000,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
                );
            }, 1);
        }
    });
}

function getAmount(days, rate) {
    var Amount = Number(days) * Number(rate);
    $('#Amount').val(Amount);
}

function calCharges(){
    var PackageName = $('#PackageName').val();
    var PackageAmt = $('#PackageAmt').val();
    $.ajax({
        url: "<?php echo e(url('getBillPackageDetails2')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            PackageName: PackageName,
            PackageAmt: PackageAmt
        },
        beforeSend:function(){
     $('#please_wait').show();
    },
        success: function(data) {
            $('#please_wait').hide();
            //alert(data);
            //console.log(data);exit();
            if (PackageName == 'Cashless') {

            } else {
                //$('#PackageAmt').val(PackageAmt);
            }
            //$('#BalanceAmt').val(data.BalanceAmt);
            calBalanceAmt(PackageName);
            totSumBills();
            procedure_lists(PackageName);
            
        }
    });
}
function getPackageDetails(val) {
    //alert(val);exit();
    var PackageAmt = $('#PackageAmt').val();
    $.ajax({
        url: "<?php echo e(url('getBillPackageDetails')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            PackageName: val,
            PackageAmt: PackageAmt
        },
        dataType: "json",
        success: function(data) {
            //alert(data);
            console.log(data);
            if (val == 'Cashless') {

            } else {
                $('#PackageAmt').val(data.PackageAmt);
            }
            //$('#BalanceAmt').val(data.BalanceAmt);
            procedure_lists(val);
            calBalanceAmt(val);
            totSumBills();
        }
    });
}

function calBalanceAmt(PackageName) {
    var PackageAmt = $('#PackageAmt').val();
    //alert(PackageName);
    $.ajax({
        url: "<?php echo e(url('calBillBalanceAmt')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            PackageName: PackageName,
            PackageAmt: PackageAmt
        },
        success: function(data) {
            //alert(data);
            //$('#BalanceAmt').val(data);
            if (data == 0) {
                $('#submit_save').attr('disabled', false);
                $('#error_msg').hide();
            } else {
                $('#submit_save').attr('disabled', false);
                $('#error_msg').hide();
            }
        }
    });
}

function totSumBills() {
    var Discount = $('#Discount').val();
    var GrossAmt = $('#GrossAmt').val();
    var PaidAmt = $('#PaidAmt').val();
    var BillNo = $('#Bill_No').val();
    $.ajax({
        url: "<?php echo e(url('totSumBills')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>'
        },
        success: function(data) {
            $('#SubTotal').val(data);
            netAmount(data, Discount, GrossAmt, PaidAmt);
            //balBillAmt();
        }
    });
}

function netAmount(SubTotal, Discount, GrossAmt, PaidAmt) {
    var GrossAmt = Number(SubTotal) - Number(Discount);
    $('#GrossAmt').val(GrossAmt);
    $('#PaidAmt').val(SubTotal);
    var BalAmt = Number(GrossAmt) - Number(PaidAmt);
    $('#BalAmt').val(BalAmt);
    //balBillAmt();

}

function procedure_lists(PackageName) {
    //alert(PackageName);
    $.ajax({
        url: "<?php echo e(url('billChargesView2')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            PackageName: PackageName
        },
        success: function(data) {
            //console.log(data);
            $('#custresult').html(data);
        }
    });
}



function saveBills() {
    var action = $('#action').val();
    var id = $('#id').val();
    var PackageName = $('#PackageName').val();
    var PackageAmt = $('#PackageAmt').val();
    var BalanceAmt = $('#BalanceAmt').val();
    var ChargesName = $('#ChargesName').val();
    var Amount = $('#Amount').val();
    var OldAmount = $('#OldAmount').val();
    var Days = $('#Days').val();
    var Rate = $('#Rate').val();
    var BillNo = $('#Bill_No').val();
    var MrdNo = $('#MrdNo').val();
    $.ajax({
        url: "<?php echo e(url('saveTempBills')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            action: action,
            id: id,
            PackageName: PackageName,
            PackageAmt: PackageAmt,
            BalanceAmt: BalanceAmt,
            ChargesName: ChargesName,
            Amount: Amount,
            OldAmount:OldAmount,
            Days: Days,
            Rate: Rate,
            BillNo: BillNo,
            MrdNo: MrdNo
        },
        beforeSend: function() {
            $('#submit').attr('disabled', 'disabled');
            $('#submit').text('Please Wait...');
        },
        success: function(data) {
            //console.log(data);exit();
            if (data == 1) {
                //$('#modal-report').modal('hide');
                success_toast();
                //getBillCharges(BillNo);
                procedure_lists(PackageName);
                calBalanceAmt(PackageName);
                totSumBills();
                $('#ChargesName').val('');
                $('#Amount').val('');
                $('#OldAmount').val('');
                $('#Days').val(1);
                $('#Rate').val('');
                $('#action').val('Save');

                $('#id').val('');
                $('#submit').html('<i class="feather icon-plus"></i> Add');
            } else {
                error_toast();
                //$('#modal-report').modal('show');
            }
            $('#submit').attr('disabled', false);
            $('#submit').text('Add');
        }
    });
}

function print() {
    var BillId = $('#BillId').val();
    setTimeout(function() {
        window.open(
            '/<?php echo e(projectUrl()); ?>ipdBillPrint/' + BillId, 'popUpWindow3',
            'height=1000,width=1000,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
        );
    }, 1);
}

function getBillCharges(billno) {
    $.ajax({
        url: "<?php echo e(url('getBillCharges')); ?>",
        method: "POST",
        data: {
            _token: '<?php echo e(csrf_token()); ?>',
            billno: billno
        },
        success: function(data) {
            console.log(data);
            $('#custresult').html(data);
        }
    });
}
$(document).ready(function() {
     var PackageName = $('#PackageName').val();
    // getPackageDetails(PackageName);
    procedure_lists(PackageName)

    $(document).on("change", "#BillType", function(event) {
        var val = this.value;
        if (val == 'Cashless') {
            $('#PackageName').attr("selected", true).val('Cashless');
            getPackageDetails(val)
        }
        else{
            $('#PackageName').attr("selected", true).val('M1');
            getPackageDetails('M1')
        }
    });

    $(document).on("change", "#BillNo", function(event) {
        var val = this.value;

        $.ajax({
            url: "<?php echo e(url('getBillDetails')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                id: val
            },
            dataType: "json",
            success: function(data) {
                //console.log(data);
                $('#BillId').val(data.id);
                $('#Bill_No').val(data.BillNo);
                $('#MrdNo').val(data.MrdNo);
                $('#BillType').val(data.BillType).attr("selected", true);
                $('#PatientName').val(data.PatientName);
                $('#AgeGender').val(data.AgeGender);
                $('#BillDate').val(data.BillDate);
                $('#AdmissionDate').val(data.AdmissionDate);
                $('#OperationDate').val(data.OperationDate);
                $('#DischargeDate').val(data.DischargeDate);
                $('#ConsultantId').val(data.Consultant).attr("selected", true);
                $('#PackageName').val(data.PackageName);
                $('#PackageAmt').val(data.PackageAmt);
                $('#SubTotal').val(data.SubTotal);
                $('#Discount').val(data.Discount);
                $('#GrossAmt').val(data.GrossAmt);
                $('#PaidAmt').val(data.PaidAmt);
                $('#BalAmt').val(data.BalAmt);
                $('#PayMode').val(data.PayMode).attr("selected", true);
                $('#Narration').val(data.Narration);
                getBillCharges(data.BillNo);
            }
        });
    });
    $(document).on("change", "#PatientId", function(event) {
        var val = this.value;
        $.ajax({
            url: "<?php echo e(url('getIpdPatientDetails')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                id: val
            },
            dataType: "json",
            success: function(data) {
                //console.log(data);
                var AgeGender = data.Age + "/" + data.Gender;
                $('#IpdNo').val(data.IpdNo);
                $('#MrdNo').val(data.MrdNo);
                $('#PatientName').val(data.PatientName);
                $('#AgeGender').val(data.AgeGender);
                $('#AdmissionDate').val(data.AdmissionDate);
                $('#DischargeDate').val(data.DischargeDate);
                $('#ConsultantId').val(data.Consultant).attr("selected", true);
                $('#Diagnosis').val(data.Diagnosis);
            }
        });

    });

    $(document).on("click", ".update", function(event) {
        event.preventDefault();
        event.stopPropagation();
        var id = $(this).attr("data-id");
        var action = "fetch_record";

        $.ajax({
            url: "<?php echo e(url('fetchBillChargesRecord')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                id: id
            },
            dataType: "json",
            success: function(data) {
                //console.log(data);
                $('#ChargesName').val(data.Name);
                $('#Days').val(data.Days);
                $('#Rate').val(data.Rate);
                $('#Amount').val(data.Amount);
                $('#action').val('Edit');

                $('#id').val(id);
                $('#submit').html('<i class="feather icon-plus"></i> Update');
                $('#modal-report').modal('show');
                $('.modal-title').html(
                    "Update <span class='font-weight-light'>Charges</span>");

            }
        });
    });



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

                    success: function(data) {
                        //console.log(data);
                        swal("Deleted!", "Charges has been deleted.", "success");

                        procedure_lists(PackageName);
                        calBalanceAmt(PackageName);
                        totSumBills();

                    }
                });

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


    $(document).on("change", "#CounId", function(event) {
        var val = this.value;
        $.ajax({
            url: "<?php echo e(url('checkOtPatient')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                id: val
            },
            success: function(data) {
                //console.log(data);
                var res = JSON.parse(data);
                var result = res.result;
                var AgeGender = result.Age + "/" + result.Gender;

                $('#MrdNo').val(result.MrdNo);
                $('#PatientName').val(result.PatientName);
                $('#AgeGender').val(AgeGender);
                $('#PackageName').val(result.Package);
                $('#PackageAmt').val(result.PkgAmt);
                $('#Diagnosis').val(result.Diagnosis);
                getPackageDetails(result.Package);
            }
        });
    });


    $('#validation-form').on('submit', function(e) {
        e.preventDefault();
        var MrdNo = $('#MrdNo').val();
        var OtId = $('#OtId').val();
        if ($('#validation-form').valid()) {
            $.ajax({
                url: "<?php echo e(url('saveIpdBill')); ?>",
                method: "POST",
                data: new FormData(this),
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#submit_save').attr('disabled', 'disabled');
                    $('#submit_save').text('Please Wait...');
                },
                success: function(data) {
                    window.location.href="/<?php echo e(projectUrl()); ?>addIpdBill2/"+MrdNo+"/"+OtId;
                    setTimeout(function() {
                        window.open(
                            '/<?php echo e(projectUrl()); ?>ipdBillPrint/' + data,
                            'popUpWindow3',
                            'height=1000,width=800,left=0,top=0,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no'
                        );
                    }, 1);
                    // $('#actionvalue').val('Edit');
                    $('#saveid').val(data);
                    $('#BillId').val(data);
                    $('#printbtn').attr("disabled", false);
                    $('#submit_save').attr('disabled', true);
                    $('#submit_save').text('Submit');
                    //     $('#billbtn').attr("disabled", false);
                    // $('#receiptbtn').attr("disabled", false);
                    //window.parent.close();
                    //window.opener.location.reload(true);
                }
            });
        }

    });

    $(document).on("input", "#MrdNo", function(event) {
        var val = this.value;
        $.ajax({
            url: "<?php echo e(url('getPatientDetails')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                id: val
            },
            dataType: "json",
            success: function(data) {
                //console.log(data);
                $('#MrdNo').val(data.MrdNo);
                $('#PatientName').val(data.PatientName);
                $('#Phone').val(data.Phone);
                $('#AgeGender').val(data.Age + "/" + data.Gender);

            }
        });

    });

});
</script><?php /**PATH D:\Projects\Sidhha_Tech\st_projects\Laravel\deshmukh_hosp\resources\views//ipd/add-ipd-bill2.blade.php ENDPATH**/ ?>