<?php
$v->layout("_themesis");
?>
<div class="container-fluid nav-hidden" id="content">
    <div id="">
        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-12">
                    <div class="box">
                        <div class="box-title">
                            <h3>
                                Sped - Verificação
                                <a href="<?php echo url('sped/index');?>" class="btn btn-primary">VOLTAR</a>
                            </h3>
                        </div>
                        <div class="box-content">
                            <div class="row">
                                <div class="form-group col-lg-12">
                                    <label>TIPO ARQUIVO</label>
                                    <select class="form-control type_arquivo">
                                        <option value=""></option>
                                        <option value="0">SPED CONTRIBUIÇÕES</option>
                                        <option value="1">SPED FISCAL</option>
                                    </select>
                                </div>
                            </div>
                            <hr />
                            <ul class="tabs tabs-inline tabs-top">
                                <li class='active'>
                                    <a href="#tab1" data-toggle='tab'>
                                        Resgatar Tags
                                    </a>
                                </li>
                                <li>
                                    <a href="#tab2" data-toggle='tab'>
                                        Exportar
                                    </a>
                                </li>
                            </ul>

                            <div class="tab-content padding tab-content-inline tab-content-bottom">
                                <div class="tab-pane active" id="tab1">
                                    <div class="row">
                                        <div class="form-group col-lg-12">
                                            <label>Tags</label>
                                            <input type="text" class="form-control tags_one" placeholder="C100,C175,C190" />
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <button class="btn btn-primary" type="button" onclick="send_tags();">PEGAR TAGS</button>
                                        </div>
                                    </div>
                                    <hr />
                                    <div class="load_sped_tags"></div>
                                </div>
                                <div class="tab-pane" id="tab2">
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <button class="btn btn-primary" type="button" onclick="send_export_excel();">EXPORTAR EXCEL</button>
                                        </div>
                                    </div>
                                    <hr />
                                    <div class="load_sped_exportar"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function send_tags(){
        var type_arquivo = $(".type_arquivo").val();
        var tags_one = $(".tags_one").val();
        var Data = "&action=search_doc_nfe&id=<?php echo $param['uri'];?>&type="+type_arquivo+"&tags="+tags_one;
        $.ajax({
            url: "<?= $router->route("sped.sendTags"); ?>",
            data: Data,
            type: 'POST',
            dataType: 'json',
            beforeSend: load_in(),
            success: function (data) {
                if(data[0].type === 'ok'){
                    $(".load_sped_tags").html(data.button);
                }else{
                    $(".load_sped_tags").html('');
                }
                load_out();
            },
            error: function (request, status, error) {
                load_out();
            }
        });
        return false;
    }

    function send_export_excel(){
        var type_arquivo = $(".type_arquivo").val();
        var Data = "&action=search_doc_nfe&id=<?php echo $param['uri'];?>&type="+type_arquivo;
        $.ajax({
            url: "<?= $router->route("sped.exportExcel"); ?>",
            data: Data,
            type: 'POST',
            dataType: 'json',
            beforeSend: load_in(),
            success: function (data) {
                if(data[0].type === 'ok'){
                    $(".load_sped_exportar").html(data.button);
                }else{
                    $(".load_sped_exportar").html('');
                }
                load_out();
            },
            error: function (request, status, error) {
                load_out();
            }
        });
        return false;
    }
</script>
