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

<?php $__env->startSection('content-header'); ?>
    <?php if($budget->exists): ?>
    Editar orçamento N.º <b><?php echo $budget->doc_no; ?></b>
    <?php else: ?>
    Novo orçamento
    <?php endif; ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('breadcrumb'); ?>
<li>
    <a href="<?php echo route('admin.budgets.index'); ?>">
        Orçamentos
    </a>
</li>
<li class="active">
    <?php echo $action; ?>

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

<?php $__env->startSection('styles'); ?>
    <?php echo HTML::style('assets/vendor/admin-lte/plugins/datepicker/datepicker3.css'); ?>

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

<?php $__env->startSection('plugins'); ?>
    <?php echo HTML::script('assets/vendor/admin-lte/plugins/ckeditor/ckeditor.js'); ?>

    <?php echo HTML::script('assets/vendor/admin-lte/plugins/datepicker/bootstrap-datepicker.js'); ?>

    <?php echo HTML::script('assets/vendor/admin-lte/plugins/datepicker/locales/bootstrap-datepicker.pt.js'); ?>

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

<?php $__env->startSection('content'); ?>
<div class="row">
    <div class="col-xs-12">
        <div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                <li class="active"><a href="#tab-client" data-toggle="tab">Cliente</a></li>
                <?php if($budget->exists): ?>
                <li><a href="#tab-presentation" data-toggle="tab">Carta de Apresentação</a></li>
                <li><a href="#tab-lines" data-toggle="tab">Produtos e Serviços</a></li>
                <?php endif; ?>
            </ul>
            
            <?php echo Form::model($budget, $formOptions); ?>

            <div class="tab-content">
                <div class="tab-pane active" id="tab-client">
                    <div class="spacer-15"></div>
                    <?php echo $__env->make('admin.budgets.partials.customer', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
                </div>
                <?php if($budget->exists): ?>
                <div class="tab-pane" id="tab-presentation">
                    <?php echo $__env->make('admin.budgets.partials.presentation', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
                </div>
                <div class="tab-pane" id="tab-lines">
                    <?php echo $__env->make('admin.budgets.partials.lines', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
                </div>
                <?php endif; ?>
            </div>
            <?php echo Form::close(); ?>

            
        </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>
    $('.datepicker').datepicker({
        language: 'pt',
        format: 'yyyy-mm-dd',
        startDate: '<?php echo $budget->created_at->format("Y-m-d"); ?>'
    });
    
    $('input[name=validity]').inputmask("9[9][9]");
    
    $('.mask-price').inputmask({
        alias: 'numeric',
        digits: 2,
        groupSeparator: '.',
        radixPoint: ',',
        allowPlus: false,
        allowMinus: false,
        autoGroup: true,
        digitsOptional: 1,
        clearMaskOnLostFocus: !1,
        rightAlign: false,
        autoUnmask: true,
        removeMaskOnSubmit: true
    });
        
    //add new customer
    $(document).on('click', '#add-customer', function(e){
        e.preventDefault();
        $('select[name=customer_id]').select2('val', 0);
        $('select[name=customer_id], .select2').hide().prop('required', false);
        $('input[name=name]').show().prop('required', true);
        $('#search-customer').show();
        $(this).hide();
    });
    
    //search customer
    $(document).on('click', '#search-customer', function(e){
        e.preventDefault();
        $('select[name=customer_id], .select2').show().prop('required', true);
        $('input[name=name]').hide().prop('required', false);
        $('#add-customer').show();
        $(this).hide();
        $('#client-details').html('');
    });
    
    //choose customer from list
    $(document).on('change', 'select[name=customer_id]',function(){
        var id = $(this).val();
        var html = '<div class="text-center margin-top-30 margin-bottom-30"><i class="fa fa-spin fa-circle-o-notch"></i><br/>A carregar...</div>';
        var action = "<?php echo route('admin.budgets.get.customer'); ?>";
        
        if(id != null) {
            action+= "/" + id
        }
        
        $('#client-details').html(html);
        
        $.post(action, id, function(data){
            $('#client-details').html(data);
            $('input[name=tax],input[name=phone]').inputmask("999999999");
            $('input[name=zip_code]').inputmask("9999-999");
            
        }).fail(function(){
            $('#client-details').html('<div class="text-center text-red margin-30"><i class="fa fa-exclamation-circle bigger-130"></i><br/>Ocorreu um erro ao tentar obter os dados.</div>');
        })
    });
    
    $('.saved-presentations .list-group-item').on('click', function(e){
        e.preventDefault();
        
        var text = $(this).data('text');
        CKEDITOR.instances['presentation'].setData(text);
    })

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