<?php $__env->startSection('title', 'Dashboard'); ?>

<?php $__env->startSection('content'); ?>
        
    <div class="col-xs-12 main page-dashboard">

        <div class="row">
            <ol class="breadcrumb">
                <li><a href="<?php echo e(route('dashboard')); ?>"><svg class="glyph stroked home"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#stroked-home"></use></svg></a></li>
            </ol>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">Dashboard</h3>
            </div>
        </div>

        <div class="row">
            <div class="col-xs-12 col-sm-6 col-lg-3">
                <div class="panel panel-blue panel-widget ">
                    <div class="row no-padding">
                        <div class="col-sm-2 col-lg-3 widget-left">
                            <svg class="glyph stroked bag"><use xlink:href="#stroked-bag"></use></svg>
                        </div>
                        <div class="col-sm-10 col-lg-9 widget-right">
                            <div class="large"><?php echo e($jobs->count()); ?> jobs</div>
                            <div class="text-muted"><?php echo e($completed_jobs->count()); ?> completed (<?php echo e(number_format((($completed_jobs->count()/$jobs->count()) * 100), 2)); ?>%)</div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12 col-sm-6 col-lg-3">
                <div class="panel panel-orange panel-widget">
                    <div class="row no-padding">
                        <div class="col-sm-2 col-lg-3 widget-left">
                            <svg class="glyph stroked clipboard with paper"><use xlink:href="#stroked-clipboard-with-paper"/></svg>
                        </div>
                        <div class="col-sm-10 col-lg-9 widget-right">
                            <div class="large"><?php echo e($tasks->count()); ?> tasks</div>
                            <div class="text-muted"><?php echo e($completed_tasks->count()); ?> completed (<?php echo e(number_format((($completed_tasks->count()/$tasks->count()) * 100), 2)); ?>%)</div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12 col-sm-6 col-lg-3">
                <div class="panel panel-teal panel-widget">
                    <div class="row no-padding">
                        <div class="col-sm-2 col-lg-3 widget-left">
                            <svg class="glyph stroked lock"><use xlink:href="#stroked-lock"></use></svg>
                        </div>
                        <div class="col-sm-10 col-lg-9 widget-right">
                            <div class="large"><?php echo e($users->count()); ?> users</div>
                            <div class="text-muted"><?php echo e($outdoor_users->count()); ?> outdoor users</div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12 col-sm-6 col-lg-3">
                <div class="panel panel-red panel-widget">
                    <div class="row no-padding">
                        <div class="col-sm-2 col-lg-3 widget-left">
                            <svg class="glyph stroked star"><use xlink:href="#stroked-star"></use></svg>
                        </div>
                        <div class="col-sm-10 col-lg-9 widget-right">
                            <div class="large"><?php echo e($clients->count()); ?> clients</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-sm-6">
                                <svg class="glyph stroked bag"><use xlink:href="#stroked-bag"/></svg> Jobs List
                                <?php if($user->outdoor != 1): ?>
                                    | <a href="outdoor">Outdoor</a>
                                <?php endif; ?>
                            </div>
                            <div class="col-sm-6 text-right">
                                <?php if (app('Illuminate\Contracts\Auth\Access\Gate')->check('create_job')): ?>
                                    <a class="btn btn-primary js-addnewjob"><svg class="glyph stroked plus sign"><use xlink:href="#stroked-plus-sign"/></svg> Add new job</a>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                    <div class="panel-body">
                        <?php if(Session::has('message')): ?>
                            <div class="alert bg-<?php echo e(Session::get('class')); ?>"><?php echo e(Session::get('message')); ?></div>
                        <?php endif; ?>
                        <div class="js-status"></div>
                        <table class="js-table-jobs" data-toggle="table" data-url="<?php echo e(route('apiJobs')); ?>"  data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-search="true" data-pagination="true" <?php /*Additional:data-show-export="true"*/ ?>>
                            <thead>
                            <tr>
                                <th data-cell-style="cellStyle" data-formatter="runningFormatter">#</th>
                                <th data-cell-style="cellStyle" data-field="id" data-sortable="true">Job No.</th>
                                <th data-cell-style="cellStyle" data-field="created_at" data-sortable="true">Date, Time</th>
                                <th data-cell-style="cellStyle" data-field="company">Company</th>
                                <th data-cell-style="cellStyle" data-field="title">Title</th>
                                <th data-cell-style="cellStyle" data-field="client">Client</th>
                                <th data-cell-style="cellStyle" data-field="pic">PIC</th>
                                <th data-cell-style="cellStyle" data-field="piv">PIV</th>
                                <th data-cell-style="cellStyle" data-align="center" data-field="tasks">Tasks</th>
                                <th data-cell-style="cellStyle" data-field="invoices">Invoices</th>
                                <th data-cell-style="cellStyle" data-field="status">Status</th>
                                <th data-cell-style="cellStyle" data-align="center" data-field="operate" data-events="operateEvents">Actions</th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>

    </div>

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



<?php $__env->startSection('script'); ?>
<script>
    // Add table operation
    function runningFormatter(value, row, index) {
        return 1+index;
    }

    function cellStyle(value, row, index, field) {
        if(row.status=='Completed'){
            return {
                css: {"background-color": "#F3FFEB"}
            };
        }

        if(row.status=='Canceled'){
            return {
                css: {"background-color": "#f9f5f5"}
            };
        }

        if(row.status=='KIV'){
            return {
                css: {"background-color": "#f1f9fd"}
            };
        }

        return {
            css: {"background-color": ""}
        };
    }

    window.operateEvents = {
        'click .view': function (e, value, row, index) {
            window.location = '<?php echo e(URL::to("/")); ?>/jobs/' + row.id;
        },
        <?php if (app('Illuminate\Contracts\Auth\Access\Gate')->check('create_job')): ?>
        'click .task': function (e, value, row, index) {
            $.ajax({
                url: "<?php echo e(action('TaskController@create')); ?>",
                dataType: 'html',
                type: 'GET',
            }).success(function(response) {
                bootbox
                    .dialog({
                        title: '...',
                        message: response,
                        onEscape: true,
                        backdrop: true
                    }).on('shown.bs.modal', function() {
                        var title = $('.js-form-title').data('title');
                        var firstfield = $('input[name=description]');
                        var job_id = $('input[name=job_id]');
                        $('.modal-title').html(title + ' for job no. ' + row.id);
                        firstfield.focus();
                        job_id.val(row.id);
                    });
            });
        },
        <?php endif; ?>
        <?php if (app('Illuminate\Contracts\Auth\Access\Gate')->check('manage_finance')): ?>
        'click .invoice': function (e, value, row, index) {
            $.ajax({
                url: "<?php echo e(action('InvoiceController@create')); ?>",
                dataType: 'html',
                type: 'GET',
            }).success(function(response) {
                bootbox
                    .dialog({
                        title: '...',
                        message: response,
                        onEscape: true,
                        backdrop: true
                    }).on('shown.bs.modal', function() {
                        var title = $('.js-form-title').data('title');
                        var firstfield = $('input[name=invoice_no]');
                        var job_id = $('input[name=job_id]');
                        $('.modal-title').html(title + ' for job no. ' + row.id);
                        firstfield.focus();
                        job_id.val(row.id);
                    });
            });
        },
        <?php endif; ?>
        <?php if (app('Illuminate\Contracts\Auth\Access\Gate')->check('create_job')): ?>
        'click .edit': function (e, value, row, index) {
            $.ajax({
                url: '<?php echo e(URL::to("/")); ?>/jobs/' + row.id + '/edit',
                dataType: 'html',
                type: 'GET',
            }).success(function(response) {
                bootbox
                    .dialog({
                        title: '...',
                        message: response,
                        onEscape: true,
                        backdrop: true
                    }).on('shown.bs.modal', function() {
                        var title = $('.js-form-title').data('title');
                        var firstfield = $('input[name=title]');
                        $('.modal-title').html(title + ' no. ' + row.id);
                        firstfield.focus();
                    });
            });
        }
        <?php endif; ?>
    };

    <?php if (app('Illuminate\Contracts\Auth\Access\Gate')->check('create_job')): ?>
    //Click add new job button
    $('.js-addnewjob').on('click', function() {
        $.ajax({
            url: "<?php echo e(action('JobController@create')); ?>",
            dataType: 'html',
            type: 'GET',
        }).success(function(response) {
            bootbox
                .dialog({
                    title: '...',
                    message: response,
                        onEscape: true,
                        backdrop: true
                }).on('shown.bs.modal', function() {
                    var title = $('.js-form-title').data('title');
                    var firstfield = $('input[name=title]');
                    $('.modal-title').html(title);
                    firstfield.focus();
                });
        });

        return false;
    });
    <?php endif; ?>
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>