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

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

        <input type="hidden" name="action" id="action" value="Save">
        <input type="hidden" name="saveid" id="saveid" value="">
        @csrf
        <div class="card mb-12 mb-4">
            <div class="card-body">
                <div class="row">


                    <div class="col-sm-1">
                        <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="">
                        </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="">
                        </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="BalDate" Name="BalDate"
                                value="{{date('Y-m-d')}}" placeholder="" required>
                        </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"
                                value="" placeholder="" required>
                        </div>
                    </div>

                    <div class="col-sm-4">
                        <div class="form-group">
                            <label class="floating-label" for="Phone">Narration <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="Narration" Name="Narration"
                                value="" placeholder="" required>
                        </div>
                    </div>

                  

                 
                    <div class="col-sm-12">
                        <button class="btn btn-primary" type="submit" name="submit" id="submit">Save</button>
                        <a href="/addNewPatientBalance" class="btn btn-info">Add New Expense</a>
                    </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>

<script src="{{url('assets/js/jquery-3.6.0.min.js')}}"></script>
@include('masters/inccommonmodal')
@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 getValue(val, idval) {
    $('#ModalValue').val(val);
    $('#ValueId').val(idval);
    $('#OldValue').val('');
    $('#search_text77').val('');
    $('#Ref_By').focus();
    desc_lists(val);
}
function success_toast() {
    var isRtl = $('body').attr('dir') === 'rtl' || $('html').attr('dir') === 'rtl';
    $.growl.notice({
        title: 'Success',
        message: 'New Expenses Created Successfully!',
        location: isRtl ? 'tl' : 'tr'
    });
}

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

$(document).ready(function() {
    $('#validation-form').on('submit', function(e) {
        e.preventDefault();
        if ($('#validation-form').valid()) {
            $.ajax({
                url: "{{ url('saveNewPatientBalance') }}",
                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);
                    $('#saveid').val(res.id);
                    $('#action').val('Edit');
                    if (res.Status == 1) {
                        success_toast();
                    } else {
                        error_toast();
                    }
                    $('#submit').attr('disabled', false);
                    $('#submit').text('Save');
                }
            });
        }
    });
});

$(document).on("input", "#MrdNo", function(event) {
    var val = this.value;
    $.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);

        }
    });

});
</script>