<?php $__env->startSection('content'); ?>
<?php $currency =  setting_by_key("currency"); ?>

 <div class="row wrapper border-bottom white-bg page-heading">
                <div class="col-lg-10">
                    <h2><?php echo app('translator')->getFromJson('pos.tables'); ?></h2>
                    <ol class="breadcrumb">
                        <li>
                            <a href="<?php echo e(url('/')); ?>"><?php echo app('translator')->getFromJson('common.home'); ?></a>
                        </li>
                     
                        <li class="active">
                            <strong><?php echo app('translator')->getFromJson('pos.tables'); ?></strong>
                            
                        </li>
                    </ol>
                </div>
                <div class="col-lg-2">

                </div>
            </div>

             <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5><?php echo app('translator')->getFromJson('common.expenses'); ?>	</h5>
                        <div class="ibox-tools">
                        <a class="add_new btn btn-primary pull-right" href="javascript:void(0)" data-toggle="modal" data-target="#myModal" style="margin-bottom:15px"><i class="fa fa-plus"> </i> <?php echo app('translator')->getFromJson('common.add'); ?></a>
                        
                         
                          
                           
                        </div>
                    </div>
                    

<div class="ibox-content">
           
            <div class="table-responsive">
            <table class="table table-striped">
            <thead>
                <tr>

                    <th><?php echo app('translator')->getFromJson('common.title'); ?></th>
                    <th><?php echo app('translator')->getFromJson('common.options'); ?></th>
                </tr>
            </thead>
            <tbody>
                <?php if(!empty($tables)) { foreach ($tables as $row) { ?>
                    <tr id="<?php echo e($row->id); ?>">

                         <td><?php echo e($row->table_name); ?></td>
                         
                         <td> 
                            <a data-id="<?php echo e($row->id); ?>" class="edit" href="javascript:void(0)" data-toggle="modal" data-target="#myModal"> <i class="fa fa-edit"> </i> </a>
                            <a data-id="<?php echo e($row->id); ?>" class="delete" href="javascript:void(0)" > <i class="fa fa-trash-o "> </i> </a> 
                        </td>
                    </tr>
                <?php } 
                } else {  ?>
                <tr>
                    <td rowspan="5"><?php echo app('translator')->getFromJson('common.no_record_found'); ?> </td> 
                </tr>
<?php } ?>

            </tbody>
        </table>
		<?php echo $tables->render(); ?>

    </div>
    <!-- /.table-responsive -->
</div>
</div>
</div>
</div>
</div>

<?php

function clean($string) 
{
    $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
    return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
?>




<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Add New</h4>
            </div>
            <form role="form" action="<?php echo url("tables/save"); ?>" method="post" enctype="multipart/form-data">
                <div class="modal-body">
                    <?php echo csrf_field(); ?> 

                    <div class="form-group">
                        <label> Name </label>
                        <input class="form-control" required type="text" id="title" name="table_name">
                        <input class="form-control" type="hidden" id="id" name="id">
                    </div>
                    

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">Save changes</button>
                </div>
            </form>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

<script type="text/javascript">
    $("body").on("click", ".add_new", function () {
        $("#title").val("");
        $("#id").val("");
    });
    $("body").on("click", ".edit", function () {
        var id = $(this).attr("data-id");
        var form_data = {
            id: id
        };
        $.ajax({
            type: 'POST',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            url: '<?php echo url("tables/get"); ?>',
            data: form_data,
            success: function (msg) {
                var obj = $.parseJSON(msg);
                $("#title").val(obj['table_name']);
                $("#id").val(obj['id']);
            }
        });

    });


    $("body").on("click", ".delete", function () {
        var id = $(this).attr("data-id");
        var form_data = {
            id: id
        };
        $.ajax({
            type: 'POST',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            url: '<?php echo url("tables/delete"); ?>',
            data: form_data,
            success: function (msg) {
                $("#" + id).hide(1);
            }
        });
    });

</script>



<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>