@include('header')
<div class="container-fluid flex-grow-1 container-p-y">
    <h4 class="font-weight-bold py-3 mb-0">Create IPD Receipt</h4>

    <form id="validation-form" method="POST" action="">

        <input type="hidden" name="action" id="action" value="{{$action}}">
        <input type="hidden" name="id" id="saveid" value="{{$id}}">
        <input type="hidden" name="ConsellingId" id="ConsellingId" value="{{$ConsellingId}}">
        <input type="hidden" name="IpdNo" id="IpdNo" value="{{$otresult[0]->IpdNo}}">
        
        @csrf
         <div class="card mb-12 mb-4">
            <div class="card-body">
        <div class="row">
                        
        <div class="col-sm-2">
                            <div class="form-group">
                                <label>Receipt. No <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" name="ReceiptNo" id="ReceiptNo" placeholder=""
                                    value="{{$receiptno}}" readonly>
                            </div>
                        </div>
                        <div class="col-sm-2">
                            <div class="form-group">
                                <label>Mrd. No <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" name="MrdNo" id="MrdNo" placeholder="" value="{{$otresult[0]->MrdNo}}"
                                    >
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="form-group">
                                <label class="floating-label" for="Name">Patient Name <span
                                        class="text-danger">*</span></label>
                                <input type="text" class="form-control" name="PatientName" id="PatientName"
                                    placeholder="" value="{{$otresult[0]->PatientName}}">
                            </div>
                        </div>

                        <div class="col-sm-5">
                            <div class="form-group">
                                <label class="floating-label" for="gender">Procedures <span
                                        class="text-danger">*</span></label>
                                        <input class="form-control" list="DataList2" name="Procedures" value="{{$Procedures}}" id="Procedures" onchange="getProcedureDetails(this.value)">
                                <datalist id="DataList2">
                                    @foreach($procedures as $result)
                                   
                                    <option value="{{$result->Name}}">
                                        @endforeach
                                </datalist>
                            </div>
                        </div>


                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Amount <span
                                        class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="Amount" Name="Amount" placeholder="" value="{{$otresult[0]->Amount}}" required>
                            </div>
                        </div>

                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Date <span
                                        class="text-danger">*</span></label>
                                <input type="date" class="form-control" id="CreatedDate" Name="CreatedDate" value="{{date('Y-m-d')}}" placeholder="" required>
                            </div>
                        </div>
                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="gender">Payment Mode <span
                                        class="text-danger">*</span></label>
                                <select class="form-control" id="PayMode" name="PayMode" required>
                                    <option value=""></option>
                                    <option value="Cash" <?php if($otresult[0]->PayMode == 'Cash'){?> selected <?php } ?>>Cash</option>
                                    <option value="Cheque" <?php if($otresult[0]->PayMode == 'Cheque'){?> selected <?php } ?>>Cheque</option>
                                    <option value="Mobile Payment" <?php if($otresult[0]->PayMode == 'Mobile Payment'){?> selected <?php } ?>>Mobile Payment</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Cheque No</label>
                                <input type="text" class="form-control" id="ChequeNo" Name="ChequeNo" placeholder="" value="{{$otresult[0]->ChequeNo}}">
                            </div>
                        </div>

                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="gender">Cheque Deposite On</label>
                                <input type="date" class="form-control" id="ChqDep" Name="ChqDep" placeholder="" value="{{$otresult[0]->ChqDep}}">
                            </div>
                        </div>

                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="gender">Cheque Credit Date </label>
                                <input type="date" class="form-control" id="ChqDate" Name="ChqDate" placeholder="" value="{{$otresult[0]->ChqDate}}">
                            </div>
                        </div>

                        <div class="col-sm-3">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Bank Name</label>
                                <input type="text" class="form-control" id="BankName" Name="BankName" placeholder="" value="{{$otresult[0]->BankName}}">
                            </div>
                        </div>

                        <div class="col-sm-3">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Branch Name</label>
                                <input type="text" class="form-control" id="BranchName" Name="BranchName" placeholder="" value="{{$otresult[0]->BranchName}}">
                            </div>
                        </div>

                        <div class="col-sm-3">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Account No</label>
                                <input type="text" class="form-control" id="AccountNo" Name="AccountNo" placeholder="" value="{{$otresult[0]->AccountNo}}">
                            </div>
                        </div>

                        <div class="col-sm-3">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Account Holder</label>
                                <input type="text" class="form-control" id="AccountHolder" Name="AccountHolder" placeholder="" value="{{$otresult[0]->AccountHolder}}">
                            </div>
                        </div>
                        
                             
                        <div class="col-sm-12" >
                            <button class="btn btn-primary" type="submit" name="submit" id="submit">Submit</button>
                            <button class="btn btn-danger" type="button" id="printbtn" onclick="printCard()">Print</button>
                        </div><br>
                        <!-- <div class="col-sm-12" id="custresult2" style="padding-top: 25px;">

                        </div> -->

                    <input type="hidden" id="CurrDate" value="{{date('Y-m-d')}}">

                    </div></div>



    </form>


</div>


@include('footerscript')
<script>
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 printCard(){
    var id = $('#saveid').val();
    setTimeout(function () {
    window.open(
        '/{{projectUrl()}}ipdReceiptPrint/'+id, 'name', 'toolbar=1, scrollbars=1, location=1,statusbar=0, menubar=1, resizable=1, width=900, height=1000'
    );
}, 1);
}

function getIpdReceiptNo() {
    $.ajax({
        method: "POST",
        url: "{{ url('getIpdReceiptNo') }}",
        data: {
            _token: '{{csrf_token()}}'
        },
        success: function(data) {
            console.log(data);
            $('#ReceiptNo').val(data);
        }
    });
}

$(document).ready(function() {
    //getIpdReceiptNo();
    $('#validation-form').on('submit', function(e) {
        e.preventDefault();
        if ($('#validation-form').valid()) {
            $.ajax({
                url: "{{ url('saveIpdReceipt') }}",
                method: "POST",
                data: new FormData(this),
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#submit').attr('disabled', 'disabled');
                    $('#submit').text('Please Wait...');
                },
                success: function(data) {

                    //console.log(data);exit();
                    var res = JSON.parse(data);
                    var status = res.status;
                    var id = res.id;
                    var ConsellingId = res.ConsellingId;
                    $('#saveid').val(id);
                    $('#ConsellingId').val(ConsellingId);
                    $('#action').val('Edit');
                    if (status == 1) {
                        success_toast();
                    } else {
                        error_toast();
                    }
                    $('#submit').attr('disabled', false);
                    $('#submit').text('Submit');
                }
            });
        }
    });
});
</script>