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

    <form id="validation-form" method="POST">
                    @csrf
                    <input type="text" name="action" id="action" value="Save">
                    <input type="text" name="id" id="id" />
                    <input type="text" name="pageval" id="ptbal" value="ptbal"/>
                    <input type="text" name="ptbalid" id="ptbalid" value="{{$data->id}}"/>
                    <input type="hidden" name="ConsultantId" id="ConsultantId" value="19" />
                    <input type="hidden" name="Consultant" id="Consultant" value="Dr. Pravin Vyawahare" />
                    <div class="card mb-12 mb-4">
            <div class="card-body">
                    <div class="row">
                        
                   
                        <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="{{$data->MrdNo}}" readonly>
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <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="{{$data->PatientName}}" readonly>
                            </div>
                        </div>

                        <div class="col-sm-6">
                            <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" id="Procedures" onchange="getProcedureDetails(this.value)" value="Clearing Old Balance">
                                <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="" required value="{{$data->Amount}}" readonly>
                            </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" value="{{date('Y-m-d')}}" class="form-control" id="CreatedDate" Name="CreatedDate" 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">Cash</option>
                                    <!-- <option value="Card">Card</option> -->
                                    <option value="Mobile Payment">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="">
                            </div>
                        </div> -->
                        
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label class="floating-label" for="gender">Transaction ID </label>
                                <input type="text" class="form-control" id="Narration" Name="Narration" placeholder=""
                                    >
                            </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="reset">Clear</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>
                    </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);
}

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

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