 <?php $__env->startSection('content'); ?>
<?php Fun::lang() ?>
<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>
            <li><a href="#">Edit</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>Edit Task and Responsibilities of Contractor</h3>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12 col-xs-12">

            <div class="form-wrapper">
                
                <?php echo Form::model($data, ['method' => 'PATCH','route' => ['task_responsibilities_contractor.update', $data->id],'enctype'=>'multipart/form-data']); ?>

                <div class="row">
                    <div class="form-group col-sm-4 col-xs-12">
                        <label class="required">Contractor Name </label>
                        <?php echo Form::select('contractor_id', $contractors, null, ['class' => 'form-control select2 contractor_id','required']); ?>

                    </div>
                    <div class="form-group col-sm-4 col-xs-12">
                        <label class="required">Project Name </label>
                        <?php echo Form::select('project_id', $projects, null, ['class' => 'form-control select2','required']); ?>

                    </div>
                    <div class="form-group col-sm-4 col-xs-12">
                        <label class="required">Zone Name </label>
                        <?php echo Form::select('zone_name',$zones, null, ['class' => 'form-control select2','required']); ?>

                    </div>
                    <div class="form-group col-sm-4 col-xs-12">
                        <label class="required">Date</label>
                        <?php echo Form::text('date', date('d-m-Y'), array('laceholder'=>'Date','class' => 'form-control date_picker','required')); ?>

                    </div>
                    <div class="form-group col-sm-4 col-xs-12">
                        <label class="required">Start Work Date</label>
                        <?php echo Form::text('start_work_date', date('d-m-Y'), array('laceholder'=>'Date','class' => 'form-control date_picker','required')); ?>

                    </div>
                    <div class="form-group col-sm-4 col-xs-12">
                        <label class="required">Work Group Type </label>
                        <?php echo Form::select('work_group_type_id', $work_group_types, null, ['class' => 'form-control select2','required']); ?>

                    </div>
                    <div class="form-group col-sm-4 col-xs-12">
                        <label class="required">Total Amount ($)</label>
                        <?php echo Form::text('total_amount', @$data->total_amount, array('placeholder' => 'Amount','class' => 'form-control number-only sum_total_amount','required','readonly')); ?>

                    </div>
                    <div class="form-group col-sm-4 col-xs-12" style="display: none;">
                        <label class="required">Deposit Amount</label>
                        <?php echo Form::text('deposit_amount', 0, array('placeholder' => 'Amount','class' => 'form-control number-only','required')); ?>

                    </div>
                    
                </div>
                <div id="bwi-append">
                    <br/><br/>
                    <h3>Building & Work Info</h3>
                    <div class="row" style="padding: 15px;">
                        <table class="table table-striped table-bordered" width="100%">
                            <thead>
                                <tr>
                                    <th>
                                        <label class="required">
                                            បរិយាយ
                                        </label>
                                    </th>
                                    <th>
                                        <label class="required">
                                            ទិន្នន័យ
                                        </label>
                                    </th>
                                    <th>
                                        <label>
                                            ផ្សេងៗ
                                        </label>
                                    </th>
                                    <th>
                                        <span class="pull-right button_primary btn-sm plus_ens fa fa-plus" onclick="add_row_buliding_work(this)"></span>
                                    </th>
                                </tr>
                            </thead>
                            <tbody class="tb_building_work">
                                <tr>
                                    <td>
                                        <?php echo Form::text('type_of_house_title', 'ប្រភេទផ្ទះ', array('placeholder' => 'Type','class' => 'form-control','required','readonly')); ?>

                                    </td>
                                    <td>
                                        <?php echo Form::text('type_of_house', null, array('placeholder' => 'បញ្ចូលប្រភេទផ្ទះ','class' => 'form-control','required')); ?>

                                    </td>
                                    <td>
                                        <?php echo Form::textarea('des_type_house', null, array('placeholder' => 'ផ្សេងៗ','class' => 'form-control','rows'=>'2')); ?>

                                    </td>
                                    <td><button class="btn btn-sm btn-danger" disabled>
                                        <span class="fa fa-trash"></span></button>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <?php echo Form::text('duration_title', 'រយ:ពេលសាងសង់', array('placeholder' => 'Type','class' => 'form-control','required','readonly')); ?>

                                    </td>
                                    <td>
                                        <?php echo Form::text('total_duration', $data->duration, array('placeholder' => 'បញ្ចូលចំនួនថ្ងៃ','class' => 'form-control','required')); ?>

                                    </td>
                                    <td>
                                        <?php echo Form::textarea('des_duration', null, array('placeholder' => 'ផ្សេងៗ','class' => 'form-control','rows'=>'2')); ?>

                                    </td>
                                    <td><button class="btn btn-sm btn-danger" disabled>
                                        <span class="fa fa-trash"></span></button>
                                    </td>
                                </tr>
                                <?php $__currentLoopData = $data_description_construction_info; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td>
                                            <?php echo Form::text('des_title[]',$value->description_name, array('placeholder' => 'បញ្ចូលបរិយាយ','class' => 'form-control','required')); ?>

                                        </td>
                                        <td>
                                            <?php echo Form::text('des_value[]', $value->description_data, array('placeholder' => 'បញ្ចូលទិន្នន័យ','class' => 'form-control','required')); ?>

                                        </td>
                                        <td>
                                            <?php echo Form::textarea('other[]', $value->other, array('placeholder' => 'ផ្សេងៗ','class' => 'form-control','rows'=>'2')); ?>

                                        </td>
                                        <td><button type="button" class="btn btn-sm btn-danger" onclick="remove(this)">
                                            <span class="fa fa-trash"></span></button>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div id='trp-append'>
                    <br/>
                    <h3>Responsiblities for Contractor</h3>
                    <br/>
                    <div class="row" >
                        <div style="border: 1px solid gray;padding: 15px;margin:15px;" id="responsibility-table-form">
                            <p style="color: #045FB4 !important;font-size: 90%;margin-top: -25px;background-color: white !important;
                            width: 90px !important;text-align: center;font-family: 'Khmer OS Muol Light'">
                                <a href="javascript:void(0)" onclick="add_table_responsibility(this)">ADD NEW</a>
                            </p>
                        </div>
                    </div>
                </div>
                <br/><br/>
                <h3>Tasks for Contractor</h3>
                <br/>
                <div class="row" >
                    <div style="border: 1px solid gray;padding: 15px;margin:15px;" id="task-table-form">
                        <p style="color: #045FB4 !important;font-size: 90%;margin-top: -25px;background-color: white !important;
                        width: 90px !important;text-align: center;font-family: 'Khmer OS Muol Light'">
                            <a href="javascript:void(0)" onclick="add_table_tasks(this)">ADD NEW</a>
                        </p>
                        
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12 col-xs-12">
                        <div class="form-group">
                            <button type="submit" class="button_sm button_primary pull-right"><span class="fa fa-save"></span> Save</button>
                            <button type="button" onClick="javascript:history.go(-1)" class="button_sm button_warning pull-right">
                                <span class=" fa fa-arrow-circle-left"></span> Back</button>
                        </div>
                    </div>
                </div>
                <br/>

                <?php echo Form::close(); ?>

            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?> <?php $__env->startSection('js'); ?>
<script>
    /*$(document).on('change','.contractor_id',function(){
        $("#main-spinner").show();
        var route = "<?php echo e(route('construction.check_constructor_type',':id')); ?>";
        route = route.replace(":id",$(this).val());
        var div_work_info = `<br/><br/>
                <h3 class="contract-constructor">Building & Work Info</h3>
                <div class="row contract-constructor" style="padding: 15px;">
                    <table class="table table-striped table-bordered" width="100%">
                        <thead>
                            <tr>
                                <th>
                                    <label class="required">
                                        បរិយាយ
                                    </label>
                                </th>
                                <th>
                                    <label class="required">
                                        ទិន្នន័យ
                                    </label>
                                </th>
                                <th>
                                    <label>
                                        ផ្សេងៗ
                                    </label>
                                </th>
                                <th>
                                    <span class="pull-right button_primary btn-sm plus_ens fa fa-plus" onclick="add_row_buliding_work(this)"></span>
                                </th>
                            </tr>
                        </thead>
                        <tbody class="tb_building_work">
                            <tr>
                                <td>
                                    <?php echo Form::text('type_of_house_title', 'ប្រភេទផ្ទះ', array('placeholder' => 'Type','class' => 'form-control','required','readonly')); ?>

                                </td>
                                <td>
                                    <?php echo Form::text('type_of_house', null, array('placeholder' => 'បញ្ចូលប្រភេទផ្ទះ','class' => 'form-control','required')); ?>

                                </td>
                                <td>
                                    <?php echo Form::textarea('des_type_house', null, array('placeholder' => 'ផ្សេងៗ','class' => 'form-control','rows'=>'2')); ?>

                                </td>
                                <td><button class="btn btn-sm btn-danger" disabled>
                                    <span class="fa fa-trash"></span></button>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <?php echo Form::text('duration_title', 'រយ:ពេលសាងសង់', array('placeholder' => 'Type','class' => 'form-control','required','readonly')); ?>

                                </td>
                                <td>
                                    <?php echo Form::text('total_duration', null, array('placeholder' => 'បញ្ចូលចំនួនថ្ងៃ','class' => 'form-control','required')); ?>

                                </td>
                                <td>
                                    <?php echo Form::textarea('des_duration', null, array('placeholder' => 'ផ្សេងៗ','class' => 'form-control','rows'=>'2')); ?>

                                </td>
                                <td><button class="btn btn-sm btn-danger" disabled>
                                    <span class="fa fa-trash"></span></button>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>`;
        var div_re_info = `<br/>
                <h3 class="contract-constructor">Responsiblities for Contractor</h3>
                <br/>
                <div class="row contract-constructor">
                    <div style="border: 1px solid gray;padding: 15px;margin:15px;" id="responsibility-table-form">
                        <p style="color: #045FB4 !important;font-size: 90%;margin-top: -25px;background-color: white !important;
                        width: 90px !important;text-align: center;font-family: 'Khmer OS Muol Light'">
                            <a href="javascript:void(0)" onclick="add_table_responsibility(this)">ADD NEW</a>
                        </p>
                        <div class="row" style="padding:15px;">
                           <div class="col-sm-4" style="padding: 0px;" > <label>Title : </label><input class="form-control" name="tt[]" placeholder="Title" id="title-responsibility1" onkeyup="title_press_key(this)" onchange="title_press_key(this)" required>
                                <br/>
                            </div>
                            
                            <table class="table table-striped table-bordered" width="100%">
                                <thead>
                                    <tr>
                                        <th>No</th>
                                        <th>
                                            <label class="required">
                                                Responsibility
                                            </label>
                                        </th>
                                        <th>
                                            <label>
                                                Description
                                            </label>
                                        </th>
                                        <th>
                                            <span class="pull-right button_primary btn-sm plus_ens fa fa-plus" onclick="add_row_responsibility(this)"></span>
                                        </th>
                                    </tr>
                                </thead>
                                <tbody class="responsibility1">
                                    <tr>
                                        <td>
                                            <span>1</span>
                                        </td>
                                        <td>
                                            <?php echo Form::textarea('responsibility[]', null, array('placeholder' => 'Responsibility','class' => 'form-control','rows'=>'2','required')); ?>

                                        </td>
                                        <td>
                                            <input type="hidden" class="form-control" name="title_responsibility[]">
                                            <?php echo Form::textarea('description_responsibility[]', null, array('placeholder' => 'Description','class' => 'form-control','rows'=>'2')); ?>

                                        </td>
                                        <td><button class="btn btn-sm btn-danger" disabled>
                                            <span class="fa fa-trash"></span></button>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>`;
        $.ajax({
            url:route,
            type:"GET",
            dataType:"JSON",
            success:function(data){
                $("#bwi-append").empty();
                $("#trp-append").empty();
                if(data==0){
                    $("#bwi-append").append(div_work_info);
                    $("#trp-append").append(div_re_info);
                }else if(data==1){
                    $("#bwi-append").empty();
                    $("#trp-append").empty();
                }else{

                }
            },
            complete:function(){
                $("#main-spinner").hide();
            }
        });
    });*/
    $(document).on("keyup change",".total-amount",function(){
        let total_amount = 0;
        $(".total-amount").each(function(index,value){
            total_amount += Number($(this).val());  
        });
        $(".sum_total_amount").val(total_amount);
    });
</script>
<script type="text/javascript">
    function select_get_work_responsibilities(obj){
        var category_responsibilitiy_id = $(obj).val();
        var data = get_work_responsibilities(category_responsibilitiy_id);
        let table_last =  $(obj).closest("div.main-add-new").find('table').last();
        $(table_last).find("tr.row-responsibilites").remove();
        $.each(data,function(index,value){
            if(index>0){
               $(table_last).find('thead').find('tr').find("th:eq(3)").find("span").click();
            }
            $(table_last).find('tr').last().find("td:eq(1)").find("textarea").val(value.name);
            $(table_last).find('tr').last().find("td:eq(2)").find("textarea").val(value.description);
        });
    }
    function select_get_work_tasks(obj){
        var category_task_id = $(obj).val();
        var data = get_work_tasks(category_task_id);
        console.log(data);
        let table_last =  $(obj).closest("div.main-add-new").find('table').last();
        $(table_last).find("tr.row-tasks").remove();
        $.each(data,function(index,value){
            if(index>0){
               $(table_last).find('thead').find('tr').find("th:eq(5)").find("span").click();
            }
            $(table_last).find('tr').last().find("td:eq(1)").find("textarea").val(value.name);
            $(table_last).find('tr').last().find("td:eq(2)").find("input").val(value.amount);
            $(table_last).find('tr').last().find("td:eq(4)").find("textarea").val(value.description);
        });
    }
    $(document).ready(function() {
            
        var table = $('#datatable_task_responsibility_index').DataTable({
            ordering: false,
            "serverSide": true,
            "scrollY":"600px",
            "scrollCollapse": true,
            "lengthMenu": [
            [20, 25, 50, 100, 500],
            [20, 25, 50, 100, 500]
        ],
            ajax: "<?php echo e(route('task_responsibilities_contractor.get_index')); ?>",
            columns: [
            {
                data: 'DT_RowIndex'
            },{
                data: 'date'
            }
            ,{
                data: 'project_name'
            }
            ,{
                data: 'group_work_name'
            }
            ,{
                data: 'block_name'
            }
            ,{
                data: 'type_of_house'
            }
            , {
                data: 'contractor_name'
            },
            {
                data: 'total_amount'
            },
            {
                data : 'status'
            },
            {
                data: 'action'
            }, ],
            "initComplete": function(settings, json) {
                $('#main-spinner').hide();
            }
        });
        $('#datatable_task__index').DataTable({
            ordering: false,
            "serverSide": true,
            "scrollY":"600px",
            "scrollCollapse": true,
            "scrollX": true,
            "lengthMenu": [
            [20, 25, 50, 100, 500],
            [20, 25, 50, 100, 500]
        ],
            ajax: "<?php echo e(route('task_contractor.get_check_task_index')); ?>",
            columns: [
            {
                data: 'DT_RowIndex'
            },{
                data: 'date'
            }
            ,{
                data:'start_work_date'
            },
            {
                data:'duration'
            }
            ,
            {
                data:'deadline'
            }
            ,{
                data: 'project_name'
            }
            ,{
                data: 'group_work_name'
            }
            ,{
                data: 'block_name'
            }
            ,{
                data: 'type_of_house'
            }
            , {
                data: 'contractor_name'
            },
            {
                data : 'total_amount'
            },
             {
                data: 'type'
            },{
                data: 'action'
            }, ],
            "initComplete": function(settings, json) {
                $('#main-spinner').hide();
            }
        });

        $.fn.dataTable.ext.errMode = 'throw';
        
    });
    function add_row_buliding_work(obj)
    {
        var tb_building_work = `
                            <tr>
                                <td>
                                    <?php echo Form::text('des_title[]',null, array('placeholder' => 'បញ្ចូលបរិយាយ','class' => 'form-control','required')); ?>

                                </td>
                                <td>
                                    <?php echo Form::text('des_value[]', null, array('placeholder' => 'បញ្ចូលទិន្នន័យ','class' => 'form-control','required')); ?>

                                </td>
                                <td>
                                    <?php echo Form::textarea('other[]', null, array('placeholder' => 'ផ្សេងៗ','class' => 'form-control','rows'=>'2')); ?>

                                </td>
                                <td><button type="button" onclick="remove(this)" class="btn btn-sm btn-danger">
                                    <span class="fa fa-trash"></span></button>
                                </td>
                            </tr>
        `;
        $(obj).closest('table').find('tbody').append(tb_building_work);
        
    }
    function add_table_responsibility(obj)
    {
        let opt_category = $(".first-category-responsibilities").html();
        var count_table = $("#responsibility-table-form").find("table").length;
        var div = `<div class="row sub-div-app-responsibilities" style="padding:15px;">
                    <div style="border: 1px solid gray;height:1px;margin-bottom:35px;"></div>
                    <p style="color: #045FB4 !important;font-size: 90%;margin-top: -30px;background-color: white !important;
                        width: 90px !important;text-align: center;font-family: 'Khmer OS Muol Light';position: absolute;right:30px;" >
                        <span class="button_danger btn-sm plus_ens" style="cursor:pointer;" onclick="$(this).closest('div').remove()">Remove</span>
                    </p>
                    <div class="main-add-new">
                        <div class="row" style="padding:15px;" class="">
                            <div class="row" style="padding:15px;">
                                <div class="col-sm-4" style="padding: 0px;" >
                                    <label>Category Responsibilities</label>
                                    <?php echo Form::select('category_responsibilities',$responsibilities_categories, null, array('class' => 'form-control select2 select-category_responsibilities','onchange'=>'select_get_work_responsibilities(this)')); ?>

                                </div>
                        </div>
                        <div class="col-sm-4" style="padding: 0px;" > <label>Title : </label><input class="form-control" name="t[]" placeholder="Title" id="title-responsibility${count_table+1}" onkeyup="title_press_key(this)" onchange="title_press_key(this)" required>
                            <br/>
                        </div>
                        
                        <table class="table table-striped table-bordered" width="100%">
                            <thead>
                                <tr>
                                    <th>No</th>
                                    <th>
                                        <label class="required">
                                            Responsibility
                                        </label>
                                    </th>
                                    <th>
                                        <label>
                                            Description
                                        </label>
                                    </th>
                                    <th>
                                        <span class="pull-right button_primary btn-sm plus_ens fa fa-plus" onclick="add_row_responsibility(this)"></span>
                                    </th>
                                </tr>
                            </thead>
                            <tbody class="responsibility${count_table+1}">
                                <tr>
                                    <td>
                                        <span>1</span>
                                    </td>
                                    <td>
                                        <?php echo Form::textarea('responsibility[]', null, array('placeholder' => 'Responsibility','class' => 'form-control','rows'=>'2','required')); ?>

                                    </td>
                                    <td>
                                        <input type="hidden" class="form-control" name="title_responsibility[]">
                                        <?php echo Form::textarea('description_responsibility[]', null, array('placeholder' => 'Description','class' => 'form-control','rows'=>'2')); ?>

                                    </td>
                                    <td><button class="btn btn-sm btn-danger" disabled>
                                        <span class="fa fa-trash"></span></button>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>`;
        $("#responsibility-table-form").append(div);
        $(".select2").select2();
    }
    function add_table_tasks(obj)
    {
        var count_table = $("#task-table-form").find("table").length;
        var div = `<div class="row row-sub-task" style="padding:15px;">
                    <div style="border: 1px solid gray;height:1px;margin-bottom:35px;"></div>
                    <p style="color: #045FB4 !important;font-size: 90%;margin-top: -30px;background-color: white !important;
                        width: 90px !important;text-align: center;font-family: 'Khmer OS Muol Light';position: absolute;right:30px;" >
                        <span class="button_danger btn-sm plus_ens" style="cursor:pointer;" onclick="$(this).closest('div').remove()">Remove</span>
                    </p>
                    <div class="main-add-new">
                        <div class="row" style="padding:15px;" >
                            <div class="row" style="padding:15px;">
                                <div class="col-sm-4" style="padding: 0px;" >
                                    <label>Category Task</label>
                                    <?php echo Form::select('category_task',$task_categories, null, array('class' => 'form-control select2 select-category_task','onchange'=>'select_get_work_tasks(this)')); ?>

                                </div>
                        </div>
                        <div class="col-sm-6" style="padding: 0px;" > <label>Title : </label><input class="form-control" name="t[]" placeholder="Title" id="title-task${count_table+1}" onkeyup="title_press_key_task(this)" onchange="title_press_key_task(this)" required>
                            <br/>
                        </div>

                        <div class="col-sm-6" > 
                            <label>Type : </label>
                            <select class="form-control select2" onchange="type_main_task_change(this)" name="type_main_task" id="type_main_task${count_table+1}" required>
                                <option value = "1">Labour</option>
                                <option value = "2">Material</option>
                            </select>
                            <br/>
                        </div>
                        
                        <table class="table table-striped table-bordered" width="100%">
                            <thead>
                                <tr>
                                    <th>No</th>
                                    <th>
                                        <label class="required">
                                            Task
                                        </label>
                                    </th>
                                    <th style="width: 150px">
                                        <label class="required">
                                            Amount
                                        </label>
                                    </th>
                                    <th style="width: 150px">
                                        <label>Duration</label>
                                    </th>
                                    <th>
                                        <label>
                                            Description
                                        </label>
                                    </th>
                                    <th>
                                        <span class="pull-right button_primary btn-sm plus_ens fa fa-plus" onclick="add_row_task(this)"></span>
                                    </th>
                                </tr>
                            </thead>
                            <tbody class="task${count_table+1}">
                                <tr>
                                    <td>
                                        <span>1</span>
                                    </td>
                                    <td>
                                        <?php echo Form::textarea('task[]', null, array('placeholder' => 'Task','class' => 'form-control','rows'=>'2','required')); ?>

                                    </td>
                                    <td>
                                        <input type="text" class="form-control number-only total-amount" name="amount[]" placeholder="Amount" required>
                                    </td>
                                    <td>
                                        <input type="text" class="form-control number-only" name="duration[]" placeholder="ថ្ងៃ" required>
                                    </td>
                                    <td>
                                        <input type="hidden" class="form-control" name="title_task[]">
                                        <?php echo Form::textarea('description_task[]', null, array('placeholder' => 'Description','class' => 'form-control','rows'=>'2')); ?>

                                    </td>
                                    <td><button class="btn btn-sm btn-danger" disabled>
                                        <span class="fa fa-trash"></span></button>
                                        <input type="hidden" class="form-control task_type" name="task_type[]" value = "1">
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>`;
        $("#task-table-form").append(div);
        $(".select2").select2();
    }
    function buttom_btn_add_new_responsibilities(obj){
        $(obj).closest('table').find('thead>tr').find('th:eq(3)').find('span').click();
    }
    function add_row_responsibility(obj)
    {
        $(obj).closest("table").find('button.btn-row-add-responsibilities').remove();
        var tr_class =  $(obj).closest("table").find('tbody').attr('class');
        var tr = `<tr class="tr-table-${tr_class} row-responsibilites">
                    <td>
                        <span>${ $(obj).closest("table").find("tbody").find("tr").length+1}</span>
                    </td>
                    <td>
                        <?php echo Form::textarea('responsibility[]', null, array('placeholder' => 'Responsibility','class' => 'form-control','rows'=>'2','required')); ?>

                    </td>
                    <td>
                        <input type="hidden" class="form-control" name="title_responsibility[]">
                        <?php echo Form::textarea('description_responsibility[]', null, array('placeholder' => 'Description','class' => 'form-control','rows'=>'2')); ?>

                    </td>
                    <td>
                        <button type="button" class="btn btn-sm btn-danger" onclick="remove(this)">
                            <span class="fa fa-trash"></span>
                        </button>
                        <button style="margin-left:10px !important;" onclick="buttom_btn_add_new_responsibilities(this)" type="button" class="btn btn-sm btn-primary btn-row-add-responsibilities">
                            <span class="fa fa-plus"></span>
                        </button>
                    </td>
                </tr>`;

        var table = $(obj).closest("table");
            
        $(table).find("tbody").append(tr);
        var title = $("#title-"+tr_class).val();
        get_title(table,title);
        $(".select2").select2();
    }
    function buttom_btn_add_new_task(obj){
        $(obj).closest('table').find('thead>tr').find('th:eq(5)').find('span').click();
    }
    function add_row_task(obj)
    {
        $(obj).closest("table").find('button.btn-row-add-task').remove();
        var tr_class =  $(obj).closest("table").find('tbody').attr('class');
        var task_main_type = $(obj).closest('div.main-add-new').find("select[name=type_main_task]").val();
        var tr = `<tr class="tr-table-${tr_class} row-tasks">
                    <td>
                        <span>${ $(obj).closest("table").find("tbody").find("tr").length+1}</span>
                    </td>
                    <td>
                        <?php echo Form::textarea('task[]', null, array('placeholder' => 'Task','class' => 'form-control','rows'=>'2','required')); ?>

                    </td>
                    <td>
                        <input type="text" class="form-control number-only total-amount" name="amount[]" placeholder="Amount" required>
                    </td>
                    <td>
                        <input type="text" class="form-control number-only" name="duration[]" placeholder="ថ្ងៃ" required>
                    </td>
                    <td>
                        <input type="hidden" class="form-control" name="title_task[]">
                        <?php echo Form::textarea('description_task[]', null, array('placeholder' => 'Description','class' => 'form-control','rows'=>'2')); ?>

                    </td>
                    <td>
                        <button type="button" class="btn btn-sm btn-danger" onclick="remove(this)">
                            <span class="fa fa-trash"></span>
                        </button>
                        <button style="margin-left:5px !important;" onclick="buttom_btn_add_new_task(this)" type="button" class="btn btn-sm btn-primary btn-row-add-task">
                            <span class="fa fa-plus"></span>
                        </button>
                        <input type="hidden" class="form-control task_type" name="task_type[]" value = "${task_main_type}">
                    </td>
                </tr>`;

        var table = $(obj).closest("table");
            
        $(table).find("tbody").append(tr);
        var title = $("#title-"+tr_class).val();
        get_title_task(table,title);
        $(".select2").select2();
    }
    function remove(obj)
    {
        var index = 1;
        var tr_class =  $(obj).closest("table").find('tbody').attr('class');
        $(obj).closest('tr').remove();
        $("tr.tr-table-"+tr_class).each(function(){
            $(this).find('td:eq(0)').html(`<span>${++index}</span>`);
        });
    }
    function type_main_task_change(obj){
        let data_value = $(obj).val();
        $(obj).closest("div.main-add-new").find("tbody").find("tr").each(function(){
            $(this).find("input.task_type").val(data_value);
        });
    }
    function get_title(table_obj,title){
        $(table_obj).find("tbody").find("tr").each(function(){
            $(this).find("td:eq(2)").find('input').first().val(title);
        });
    }
    function get_title_task(table_obj,title){
        $(table_obj).find("tbody").find("tr").each(function(){
            $(this).find("td:eq(4)").find('input').first().val(title);
        });
    }
    function title_press_key(obj){
        var id_name = $(obj).attr("id");
        var title_value = $(obj).val();
        var table_name_class = id_name.split("-")[1];
        var table = $("tbody."+table_name_class).closest("table");
        get_title(table,title_value);
    }
    function title_press_key_task(obj){
        var id_name = $(obj).attr("id");
        var title_value = $(obj).val();
        var table_name_class = id_name.split("-")[1];
        var table = $("tbody."+table_name_class).closest("table");
        get_title_task(table,title_value);
    }
    function get_category_task(work_group_id)
    {
        $("#main-spinner").show();
        var data;
        let route = "<?php echo e(route('task-working-construction.get_sub_category_task',':id')); ?>";
        route = route.replace(':id',work_group_id);
        $.ajax({
            url:route,
            type:"GET",
            dataType:"JSON",
            async:false,
            success:function(d){
                data = d;
            },
            complete:function(){
                $("#main-spinner").hide();
            }
        });
        return data;
    }
    function get_work_tasks(category_task_id)
    {
        $("#main-spinner").show();
        var data;
        let route = "<?php echo e(route('task-working-construction.get_work_task',':id')); ?>";
        route = route.replace(':id',category_task_id);
        $.ajax({
            url:route,
            type:"GET",
            dataType:"JSON",
            async:false,
            success:function(d){
                data = d;
            },
            complete:function(){
                $("#main-spinner").hide();
            }
        });
        return data;
    }
    function get_category_responsibilities(work_group_id)
    {
        $("#main-spinner").show();
        var data;
        let route = "<?php echo e(route('task-working-construction.get_category_sponsibilities',':id')); ?>";
        route = route.replace(':id',work_group_id);
        $.ajax({
            url:route,
            type:"GET",
            dataType:"JSON",
            async:false,
            success:function(d){
                data = d;
            },
            complete:function(){
                $("#main-spinner").hide();
            }
        });
        return data;
    }
    function get_work_responsibilities(category_responsibilities_id)
    {
        $("#main-spinner").show();
        var data;
        let route = "<?php echo e(route('task-working-construction.get_work_responsibilities',':id')); ?>";
        route = route.replace(':id',category_responsibilities_id);
        $.ajax({
            url:route,
            type:"GET",
            dataType:"JSON",
            async:false,
            success:function(d){
                data = d;
            },
            complete:function(){
                $("#main-spinner").hide();
            }
        });
        return data;
    }
</script>
<?php echo $__env->make('administrator.construction.contractor-task-responsibilities.script-edit', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('adminlte::page', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>