 <?php $__env->startSection('content'); ?>
<?php Fun::lang()?>
<style></style>
<div class="title-page">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li><a href="#">Construction</a></li>
            <li><a href="#">Manage Contractor</a></li>
            <li><a href="#">Task&Responsibilities</a></li>
        </ul>
    </div>
</div>
    <div class="page">
        <div class="top-content">
            <div class="row">
                <div class="col-sm-12 col-xs-12">
                    <div class="title-page">
                        <div class="pull-left">
                            <h3>Task and Responsibilities of Contractor List</h3>
                        </div>
                    </div>
                    <div class="pull-right">
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Construction-Contractor-Task&Responsibilities-Create')): ?>
                        <a class="button_sm button_primary" href="<?php echo e(route('task_responsibilities_contractor.create')); ?>" data-toggle="modal"><span class="fa fa-plus"></span>  Create New</a>
                        <?php endif; ?>
                    </div>
                    <div class="pull-right">
                        <a class="button_sm button_info" href="javascript:void(0)" id="filter-toggle-search"><span class="fa fa-plus"></span>  Filter Toggle</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body table-responsive">
            <div class="row" id="toggle-seaching">
                <div class="col-md-6">
                    <div class="form-group">
                        <strong >Project :</strong>
                        <?php echo Form::select('project',\Globals::get_project(),null, array('class' => 'form-control select2')); ?>

                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <strong >Contractor Name :</strong>
                        <?php echo Form::text('contractor_name',null, array('class' => 'form-control')); ?>

                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <strong >Zone :</strong>
                        <?php echo Form::select('zone_id',\Globals::get_zone(),null, array('class' => 'form-control select2')); ?>

                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <strong >Work Group Type :</strong>
                        <?php echo Form::select('work_group_type_id',\Globals::get_work_group_type(),null, array('class' => 'form-control select2')); ?>

                    </div>
                </div>
                <div class="col-md-12" style="text-align:right;margin-bottom:40px !important;">
                    <a class="button_sm button_success" href="javascript:void(0)" id="search-submit" onclick="searching()"><span class="fa fa-search"></span> Search</a>
                </div>
            </div>  
            <table id="datatable_task_responsibility_index" width="100%" class="table table-striped table-bordered table-hover nowrap">
                <thead>
                    <tr>
                        <th>NO</th>
                        <th>Date</th>
                        <th>Project</th>
                        <th>Work Group Type</th>
                        <th>Zone</th>
                        <th>Building Type</th>
                        <th>Constructor</th>
                        <th>Total Amount</th>
                        <th>Status</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                   
                </tbody>
            </table>

        </div>
    </div>
    <div class="modal fade" id="modal-delete-info" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title"></h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    </button>
                </div>
                <form method="POST" id="form-modal-delete-info">
                    <?php echo csrf_field(); ?>
                    <div class="modal-body">
                        <div class="row">
                            <div class="form-group">
                                <div class="col-sm-12 col-xs-12">
                                    <input type="hidden" name="construction_table_id">
                                    <h4>Are you sure want ot delete?</h4>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                            <button type="button" class="btn btn btn-primary btn-sm" data-dismiss="modal">Cancel</button>
                            <button type="submit" class="btn btn-danger btn-sm">Delete</button>
                    </div>
                </form>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <?php $__env->stopSection(); ?>
    <?php echo $__env->make('administrator.construction.contractor-task-responsibilities.terminate-contract', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    <?php echo $__env->make('administrator.construction.contractor-task-responsibilities.contract-policy', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    <?php $__env->startSection('js'); ?>
    <?php echo $__env->make('administrator.construction.contractor-task-responsibilities.script', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    <script type="text/javascript">
        $(document).ready(function () {
            CKEDITOR.replace( 'policy' );
            $('#form-contract-policy').on('submit',function (e) {
                $('.btn-submit').removeAttr('disabled');
                e.preventDefault();
                var construct_id = $('#construct_id').val();
                var policy = CKEDITOR.instances['policy'].getData();
                $.ajax({
                    url : "<?php echo e(route('update_contract_policy')); ?>",
                    dataType : "JSON",
                    type : "POST",
                    data:{"_token" : "<?php echo e(csrf_token()); ?>","id" : construct_id,"policy" : policy},
                    success:function (data) {
                        if(data.error)
                        {
                            $.each(data.error,function (i,val) {
                                $('#contract-error .p-text').html(val);
                                $('#contract-error').show();
                            });
                        }
                        else if(data.success === true)
                        {
                            $('#contract-policy').modal('hide');
                            $('#contract-success .p-text').html(data.message);
                            $('#contract-success').show();
                            CKEDITOR.instances['policy'].setData("");
                            $("#datatable_task_responsibility_index").DataTable().ajax.reload();
                        }
                    },
                    error:function (err) {
                        $('#contract-error .p-text').html("Something went wrong!");
                        $('#contract-error').show();
                        $('#contract-policy').modal('hide');
                        console.log(err);
                    },
                });
            });
            $('#form-terminate-contract').on('submit',function (e) {
                e.preventDefault();
                $('.btn-submit').removeAttr('disabled');
                var date = $('#date').val();
                var con_id = $('#con_id').val();
                $.ajax({
                    url : "<?php echo e(route('terminate_contract')); ?>",
                    dataType:"JSON",
                    type:"POST",
                    data : {"_token" : "<?php echo e(csrf_token()); ?>","id" : con_id,"date" : date},
                    success:function (data) {
                        if(data.success === false)
                        {
                            $('#terminate-error .p-text').html(data.message);
                            $('#terminate-error').show();
                            $('#terminate-contract').modal('hide');
                        }
                        if(data.success === true)
                        {
                            $('#terminate-success .p-text').html(data.message);
                            $('#terminate-success').show();
                            $('#terminate-contract').modal('hide');
                            $('#datatable_task_responsibility_index').DataTable().ajax.reload();
                        }
                    },
                    error:function (err) {
                        console.log(err);
                    }
                });
            });
        });
        $(document).on('click','.btn-terminate',function () {
            $('#con_id').val($(this).data('id'));
        });
        $(document).on("submit","#form-modal-delete-info",function(e){
            e.preventDefault();
            let construction_table_id = $(this).find("input[name=construction_table_id]").val();
            let route = "<?php echo e(route('task_responsibilities_contractor.destroy',':id')); ?>";
            route = route.replace(':id',construction_table_id);

            $("#main-spinner").show();
            $.ajax({
                type: 'post',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url: route,
                data: {
                '_method': 'delete'
                },
                success: function (response, textStatus, xhr) {
                    if(xhr.status==200){
                        $("#datatable_task_responsibility_index").DataTable().ajax.reload( null,false);
                    }
                },
                complete:function(){
                    $("#main-spinner").hide();
                    $("button[type=submit]").removeAttr("disabled");
                    $("#modal-delete-info").modal("hide");
                }
            });
        });
        $(document).on('click','.btn-delete-info',function(){
            $("input[name=construction_table_id]").val($(this).data("id"));
        });
        $(document).on('click','.btn-contract',function () {
           $('#construct_id').val($(this).data('id'));
        });
    </script>
    <?php $__env->stopSection(); ?>
<?php echo $__env->make('adminlte::page', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>