<?php $__env->startSection('title'); ?>
Orçamentos
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content-header'); ?>
Orçamentos
<?php $__env->stopSection(); ?>

<?php $__env->startSection('breadcrumb'); ?>
<li class="active">
    Orçamentos
</li>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">Os meus orçamentos</h3>
                <div class="box-tools pull-right">
                    <a href="<?php echo route('admin.budgets.create'); ?>" class="btn btn-success btn-sm"><i class="fa fa-plus"></i> Novo orçamento</a>
                </div>
            </div>
            <div class="box-body">
                <table id="table-users" class="table table-bordered table-striped dataTable">
                    <thead>
                        <tr>
                            <th style="width: 1%">Proposta</th>
                            <th>Cliente</th>
                            <th style="width: 1%">Total</th>
                            <th style="width: 80px">Data</th>
                            <th style="width: 120px">Estado</th>
                            <th style="width: 60px"></th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?php echo $__env->make('admin.budgets.modals.print', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script type="text/javascript">
    $(document).ready(function () {
        $('#table-users').dataTable({
            processing: true,
            serverSide: true,
            "ajax": {
                url: "<?php echo route('admin.budgets.datatables'); ?>",
                type: "POST"
            },    
            "autoWidth": false,
            columns: [
                {data: 'doc_no', name: 'doc_no'},
                {data: 'customer_id'},
                {data: 'total', name: 'total'},
                {data: 'date', name: 'date'},
                {data: 'status', name: 'status'},
                {data: 'actions', name: 'actions', orderable: false, searchable: false},
            ]
        });
    });
    
    $(document).on('click', '.btn-print', function (e) {
        e.preventDefault();
        var url = $(this).attr('href');
        $('#modal-confirm-print .btn-no').attr('href', url + '?graphics=0');
        $('#modal-confirm-print .btn-yes').attr('href', url);
        $('#modal-confirm-print').modal('show');
    });
    
    $(document).on('click', '.btn-no, .btn-yes', function (e) {
        $('#modal-confirm-print').modal('hide')
    })
    
    $(document).on('click', '.change-status', function (e) {
        e.preventDefault();
        var $this = $(this);
        var $button = $this.closest('.btn-group').find('button');
        $button.button('loading');
        $.post($this.attr('href'), function (data) {
            $button.button('complete');
            $button.html(data.btnText);
            $button.removeClass('btn-danger')
                    .removeClass('btn-info')
                    .removeClass('btn-warning')
                    .removeClass('btn-success')
                    .addClass(data.btnClass);
            
        });
    });
</script>
<?php $__env->stopSection(); ?>