 <?php $__env->startSection('content'); ?>
<?php Fun::lang() ?>
<style>
    .form-control:disabled, .form-control[readonly] {
        background-color: transparent !important;
        opacity: 1 !important;
    }
    .table-inv-head td {
        border: none;
    }

    .table th {
        vertical-align: middle !important;
    }

    table tr:nth-child(even), table tr:hover {
        background: none;
    }

    .table > thead > tr > th {
        border: 1px solid white;
        text-align: center;
    }
</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="#">Check Tasks Working</a></li>
            <li><a href="#">Show</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>Show Tasks of Contractor</h3>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12 col-xs-12">

            <div class="form-wrapper">
                
                    <div class="row box-body">
                        <div class="row" style="margin-left: 10px;">
                            <div class="col-md-4">
                                Contractor Name : <?php echo e(optional($data_construction)->contractor_name); ?>

                            </div>
                            <div class="col-md-4">
                                Start Work Date : <?php echo e(!empty($data_construction)?date('d-m-Y',strtotime($data_construction->start_work_date)):""); ?>

                            </div>
                            <div class="col-md-4">
                                Duration : <?php echo e(@$data_construction->duration); ?> (Days)
                            </div>
                        </div>
                        <div class="row" style="margin-left: 10px;margin-top:20px;">
                            <div class="col-md-4">
                                Project Name : <?php echo e(@$data_construction->project_name); ?>

                            </div>
                            <div class="col-md-4">
                                Zone : <?php echo e(@$data_construction->block_name); ?>

                            </div>
                            <div class="col-md-4">
                                Building Type : <?php echo e(@$data_construction->type_of_house); ?>

                            </div>
                        </div>
                        <div class="col-xs-12 col-sm-12 col-md-12 text-right">
                            <button type="button" class="button_primary btn-sm search"><a href="<?php echo e(route('show-contract-task.show_contract_task',Crypt::encrypt($id))); ?>" style="color:white;"><span class="fa fa-print"> Print</span></a></button>
                        </div>
                    </div>
                    <div>
                        <div class="box-body table-responsive">
                            <table class="table" width="100%">
                                <thead>
                                    <tr>
                                        <th>No</th>
                                        <th>
                                            <label>
                                                Task
                                            </label>
                                        </th>
                                        <th>
                                            <label>
                                                Amount($)
                                            </label>
                                        </th>
                                        <th>
                                            <label>
                                                Paid Amount($)
                                            </label>
                                        </th>
                                        <th>
                                            <label>
                                                Percentage of complete-work(%)
                                            </label>
                                        </th>
                                        <th>
                                            <label>
                                                Description
                                            </label>
                                        </th>
                                        
                                        <th>
                                            <label>
                                                Action
                                            </label>
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $index=0;$total_amount = 0; $total_paid_amount = 0;?>
                                    <?php $__currentLoopData = $data_task_title; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <td colspan="7" style="text-align:center;">
                                                <u style="font-weight: bold;">
                                                    <h5 style="font-size: 120%;"><?php echo e($value->title); ?></h5>
                                                </u>
                                            </td>
                                        </tr>
                                        <?php $__currentLoopData = $data_task; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $k=>$val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <?php if($val->title==$value->title): ?>
                                                <tr>
                                                    <td><?php echo e(++$index); ?></td>
                                                    <td><?php echo e($val->name); ?></td>
                                                    <td>$<?php echo e(number_format($val->amount,2)); ?></td>
                                                    <td>$<?php echo e(number_format($val->paid_amount,2)); ?></td>
                                                    <td><?php echo e($val->percentage_completed); ?></td>
                                                    <td><?php echo e($val->description); ?></td>
                                                    <td><?php if($val->construction_status == 1): ?>
                                                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Construction-Contractor-Check-Task-Working-Update-Progress-Work')): ?>
                                                                <a data-id = "<?php echo e($val->id); ?>" data-percentage = "<?php echo e($val->percentage_completed); ?>" onclick="update_completed_work(this)" title='Edit Percentage Completed Work' href='javascript:void(0)' class='btn btn-sm btn-primary button-edit' ><i class='fa fa-edit'></i></a>
                                                            <?php endif; ?>
                                                        <?php endif; ?>
                                                    </td>
                                                    <?php $total_amount += $val->amount; $total_paid_amount += $val->paid_amount;?>
                                                </tr>
                                            <?php endif; ?>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td colspan="2" class="text-center"><b>Total</b></td>
                                        <td><b>$<?php echo e(number_format($total_amount,2)); ?></b></td>
                                        <td><b>$<?php echo e(number_format($total_paid_amount,2)); ?></b></td>
                                        <td colspan="3"></td>
                                    </tr>
                                </tbody>
                            </table>
                            
                        </div><br/>
                        <div class="col-sm-12 col-xs-12">
                            <div class="form-group">
                                
                                <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/>

                
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?> <?php $__env->startSection('js'); ?>
<script type="text/javascript">
    function update_completed_work(obj)
    {
        var id = $(obj).data("id");
        var percentage = $(obj).data("percentage");
        var route = "<?php echo e(route('task_contractor.show_task_index')); ?>";
        var max_percent_completed_payment = 0;
        $.ajax({
            url:route,
            type:"POST",
            dataType:"JSON",
            data:{
                "_token":"<?php echo e(csrf_token()); ?>",
                "task_id":id
            },
            success:function(data)
            {
                max_percent_completed_payment = data;
            },
            complete:function()
            {

            }
        });
        $.confirm({
            title:'<H4>COMPLETED WORK(%)</H4>',
            content:
            '<form action="" class="formName">' +
                '<div class="form-group">' +
                    '<input type="text" placeholder="%" value="'+percentage+'" data-max_percent_completed_payment = "'+max_percent_completed_payment+'" class="percentage-work number-only form-control" required />' +
                '</div>' +
            '</form>',
            theme:'modern',
            buttons: {
                formSubmit: {
                    text: 'Submit',
                    btnClass: 'btn-blue btn',
                    action: function () {
                        var value = this.$content.find('.percentage-work').val();
                        if(!value){
                            $.alert('Please input value');
                            return false;
                        }
                        if(value<max_percent_completed_payment||value>100){
                            $.alert("Invalide value");
                            return false;
                        }
                        $.ajax({
                            url:"<?php echo e(route('task_contractor.save_percentage_work')); ?>",
                            type:"POST",
                            dataType:"JSON",
                            data:{
                                "_token":"<?php echo e(csrf_token()); ?>",
                                percentage:value,
                                id:id
                            },
                            success:function(data){
                                $(obj).closest('tr').find('td:eq(4)').html(data);
                                window.location.reload();
                            }
                        });
                    }
                },
                cancel: function () {
                },
            },
            onContentReady: function () {
                var jc = this;
                this.$content.find('form').on('submit', function (e) {
                    e.preventDefault();
                    jc.$$formSubmit.trigger('click');
                });
            }
        });
    }
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('adminlte::page', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>