<?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">
    <h4 class="font-weight-bold py-3 mb-0">Package Master</h4>

    <div class="row">
        <!-- customar project  start -->
        <div class="col-xl-12">
            <div class="card">
                <div class="card-body">
                    <div class="row align-items-center m-l-0">



                        <div class="col-sm-2 text-left">
                            <button class="btn btn-success btn-sm mb-3 btn-round" data-toggle="modal"
                                data-target="#modal-report" id="add_button"><i class="feather icon-plus"></i> Add
                                Package</button>
                        </div>


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

                    </div>
                </div>
            </div>
        </div>
        <!-- customar project  end -->
    </div>


    <div class="modal fade" id="modal-report" tabindex="-1" role="dialog" aria-labelledby="myExtraLargeModalLabel"
        aria-hidden="true">
        <div class="modal-dialog" style="max-width: 70rem; ">
            <div class="modal-content">


                <div class="modal-header">
                    <h5 class="modal-title">Add Package</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form id="validation-form" method="POST" action="/saveProcedure">
                        <?php echo csrf_field(); ?>
                        <div class="row">

                            <input type="hidden" name="action" id="action" value="Save">
                            <input type="hidden" name="id" id="id" />
                            <div class="col-sm-4">
                                <div class="form-group">
                                    <label class="floating-label" for="Name">Package Name <span
                                            class="text-danger">*</span></label>
                                    <input type="text" class="form-control" name="Name" id="Name" 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" name="Amount" id="Amount" placeholder=""
                                        onKeyPress="return isNumberKey(event)" required="">
                                </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>
                        </div>
                    </form>
                </div>

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

</div>

<?php echo $__env->make('footerscript', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<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 Package Added Successfully!',
        location: isRtl ? 'tl' : 'tr'
    });
}

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



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

$(document).ready(function() {
    procedure_lists();

    $('#add_button').click(function() {
        $('.modal-title').html("Add <span class='font-weight-light'>New Procedure</span>");
        $('#action').val("Save");
        $('#id').val('');

        $('#Name').val('');
        $('#Amount').val('');
        $('#Type').val(1).attr("selected",true);
        $('#submit').text('Submit');

    })

    $('#validation-form').on('submit', function(e) {
        e.preventDefault();
        if ($('#validation-form').valid()) {
            $.ajax({
                url: "<?php echo e(url('savePackage')); ?>",
                method: "POST",
                data: new FormData(this),
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#submit').attr('disabled', 'disabled');
                    $('#submit').text('Please Wait...');
                },
                success: function(data) {
                    console.warn(data);
                    if (data == 1) {
                        $('#modal-report').modal('hide');
                        success_toast();
                        procedure_lists();

                    } else {
                        error_toast();
                        $('#modal-report').modal('show');
                    }
                    $('#submit').attr('disabled', false);
                    $('#submit').text('Submit');
                }
            });
        }
    });

    $(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('editPackage')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                id: id
            },
            dataType: "json",
            success: function(data) {
                $('#Name').val(data.PackageName);
                $('#Amount').val(data.PackageAmt);
                $('#Type').val(data.Type).attr("selected",true);
                $('#action').val('Edit');

                $('#id').val(id);
                $('#submit').text("Update");
                $('#modal-report').modal('show');
                $('.modal-title').html(
                    "Update <span class='font-weight-light'>Procedure</span>");

            }
        });
    });



    $(document).on("click", ".delete", 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 Procedure!",
            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('deletePackage')); ?>",
                    method: "POST",
                    data: {
                        _token: '<?php echo e(csrf_token()); ?>',
                        id: id
                    },

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

                        procedure_lists();

                    }
                });

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


    });

});
</script>
<?php /**PATH C:\laragon\www\parijathosp\resources\views/masters/packagemaster.blade.php ENDPATH**/ ?>