

<div class="card">
    <div class="card-block">
        <h2 class="card-title">Listagem de Notas - Do Dia:  <?php echo date('d/m/Y') ?></h2>



        <div align="right">
            <a href="#adicionarNotaModal" class="btn btn-s-md btn-success" data-animation="swell"
               data-plugin="custommodal"
               data-overlaySpeed="100" data-overlayColor="#36404a"><i class="fa fa-user-plus fa-2x"></i> Adicionar</a>
        </div>

        <div class="row" style="font-size: small">
            <div class="col-sm-6">
                <label class="form-inline">Show
                    <select id="demo-show-entries" class="form-control input-sm">
                        <option value="5">5</option>
                        <option value="10">10</option>
                        <option value="15">15</option>
                        <option value="50">50</option>
                    </select> entries </label>
            </div>
            <div class="col-sm-6">
                <div class="m-t-40">
                    <div class="d-flex">
                        <div class="ml-auto">
                            <div class="form-group">
                                <input id="demo-input-search1" type="text" placeholder="Procurar" class="form-control"
                                       autocomplete="off">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <table id="demo-foo-pagination" class="table toggle-circle table-hover" data-page-size="6">
            <thead>


            <tr style="font-size: x-small">
                <th data-toggle="true">#</th>
                <th data-toggle="true">N.&ordm; Pedido</th>
                <th>Cliente</th>
                <th data-hide="phone">Vendedor</th>
                <th data-hide="phone">Data</th>
                <th data-hide="phone">Valor</th>
                <th data-hide="phone">Produto</th>
                <th data-hide="phone">Status</th>
                <th data-hide="phone">Quitado</th>
                <th data-hide="phone">Previsão</th>
                <th data-toggle="true"></th>
<!--                <th data-hide="all"></th>-->
            </tr>
            </thead>
            <tbody>
            <?php

            $totaVendas1 = 0;
            $totaVendasQuitadas = 0;
            $totaVendasEmAberto = 0;
            foreach ($notas as $r) {


                if(!is_null($r->DT_QUITADO)){
                    $totaVendasQuitadas += $r->VL_PEDIDO;
                }ELSE{
                    $totaVendasEmAberto+= $r->VL_PEDIDO;
                }


                $totaVendas1 += $r->VL_PEDIDO;

//                echo $totaVendas1;

                ?>

                <?php $statusPreventiva = is_null($r->DT_QUITADO)?'red':'green';  ?>

                <tr>
<!--                    <td style="font-size:x-small">--><?php //echo date('d/m/Y', strtotime($r->DT_PREVENTIVA)) ?><!--</td>-->
                    <td><?php echo $r->ID_NOTA  ?></td>
                    <td><?php echo $r->NU_PEDIDO  ?></td>
                    <td><?php echo $r->CLIENTE_ID ?></td>
                    <td><?php echo $r->NM_VENDEDOR ?></td>
                    <td><?php echo  date('d/m/Y', strtotime($r->DT_NOTA))  ?></td>
                    <td><?php echo $r->VL_PEDIDO ?></td>
                    <!--                    <td>--><?php //echo $r->DS_TIPO_MANUTENCAO=="P"?"Preventiva":"Corretiva" ?><!--</td>-->
                    <td><?php echo $r->NM_PRODUTO ?></td>

                    <td>
                        <span class="label label-table label-<?php echo is_null($r->DT_QUITADO)? 'warning' : 'success' ?>"><?php echo is_null($r->DT_QUITADO)? 'Pedente' : 'Quitado' ?></span>
                    </td>
                    <td style="color: <?php echo $statusPreventiva ?>"><?php
                        echo is_null($r->DT_QUITADO)?'Em Aberto':date('d/m/Y', strtotime($r->DT_QUITADO))
                        ?>
                    </td>

                    <td style="color: <?php echo $statusPreventiva ?>">
                        <?php echo is_null($r->DT_PREVISAO_PAGAMENTO)?'Sem Previsão': date('d/m/Y', strtotime($r->DT_PREVISAO_PAGAMENTO))
                        ?>
                    </td>
                    <td>

                        <div class="btn-group" role="group" aria-label="Button group with nested dropdown">
                            <div class="btn-group" role="group">
                                <button id="btnGroupDrop1" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                    Ações
                                </button>
                                <div class="dropdown-menu" aria-labelledby="btnGroupDrop1">

                                    <a class="dropdown-item <?php echo is_null($r->DT_QUITADO)?'':'isDisabled';  ?>" href="#"
                                       notaAQuitar="<?php echo $r->ID_NOTA ?>"


                                       data-toggle="modal" data-target="#quitarNotaModal"
                                    >
                                        <i class="fa fa-money"></i> Quitar
                                    </a>
                                    <a class="dropdown-item <?php echo is_null($r->DT_QUITADO)?'':'isDisabled';  ?>"
                                       href="<?php echo base_url().'manutencao/editarNotasDetalhado/'.$r->ID_NOTA ?>"
                                    ><i class="fa fa-pencil"></i> Editar</a>

                                    <!--                                    <a href="#"  class=""-->
                                    <!---->
                                    <!--                                    > Quitar nota-->
                                    <!--                                    </a>-->


                                    <a href="#" class="dropdown-item <?php echo is_null($r->DT_QUITADO)?'':'isDisabled';  ?>"
                                       servicoItem="<?php echo $r->ID_NOTA ?>"

                                       data-toggle="modal" data-target="#modalExluirItem"
                                    > <i class="fa fa-trash-o text-danger"> Excluir</i>
                                    </a>





                                    <a href="#" class="dropdown-item "
                                       imprimirNota="<?php echo $r->ID_NOTA ?>"

                                       data-toggle=""
                                       data-target=""
                                    > <i class="fa fa-print"> Imprimir</i>
                                    </a>
                                </div>
                            </div>
                        </div>

<!--                        <a href="#"  class="btn btn-default waves-effect waves-light --><?php //echo is_null($r->DT_QUITADO)?'':'isDisabled';  ?><!--"-->
<!--                           notaAQuitar="--><?php //echo $r->ID_NOTA ?><!--"-->
<!---->
<!---->
<!--                           data-toggle="modal" data-target="#quitarNotaModal"-->
<!--                        > <i class="fa fa-money"></i>-->
<!--                        </a>-->
<!---->
<!---->
<!--                        <a href="#" class="btn btn-default waves-effect waves-light --><?php //echo is_null($r->DT_QUITADO)?'':'isDisabled';  ?><!--"-->
<!--                        servicoItem="--><?php //echo $r->ID_NOTA ?><!--"-->
<!---->
<!--                        data-toggle="modal" data-target="#modalExluirItem"-->
<!--                        > <i class="fa fa-trash-o text-danger"></i>-->
<!--                        </a>-->
<!---->
<!---->
<!---->
<!--                        <a href="#editarNotaModal" id="editarNota"-->
<!--                           class="btn btn-default waves-effect waves-light --><?php //echo is_null($r->DT_QUITADO)?'':'isDisabled';  ?><!--"-->
<!--                           data-animation="swell"-->
<!--                           data-plugin="custommodal"-->
<!--                           data-overlaySpeed="100"-->
<!--                           data-overlayColor="#36404a"-->
<!---->
<!--                           idNota="--><?php //echo $r->ID_NOTA ?><!--"-->
<!--                           nomeCliente="--><?php //echo $r->CLIENTE_ID ?><!--"-->
<!--                           nomeProduto="--><?php //echo $r->NM_PRODUTO ?><!--"-->
<!--                           numeroPedido="--><?php //echo $r->NU_PEDIDO ?><!--"-->
<!--                           valorPedido="--><?php //echo $r->VL_PEDIDO ?><!--"-->
<!--                           dataQuitacao="--><?php //echo date('d/m/Y', strtotime($r->DT_QUITADO)) ?><!--"-->
<!--                           nomeVendedor="--><?php //echo $r->NM_VENDEDOR ?><!--"-->
<!--                           cpfcnpjCliente="--><?php //echo $r->CPFCNPJ ?><!--"-->
<!--                        >-->
<!--                        <i class="fa fa-pencil"></i>-->
<!--                        </a>-->
<!---->
<!--                        <a href="#" class="btn btn-default waves-effect waves-light "-->
<!--                           imprimirNota="--><?php //echo $r->ID_NOTA ?><!--"-->
<!---->
<!--                           data-toggle=""-->
<!--                           data-target=""-->
<!--                        > <i class="fa fa-print"></i>-->
<!--                        </a>-->




                    </td>
                </tr>
            <?php } ?>

            </tbody>
            <tfoot>
            <tr>
                <td colspan="5">
                    <div class="text-right">
                        <ul class="pagination pagination-split m-t-30"></ul>
                    </div>
                </td>
            </tr>
            </tfoot>
        </table>
    </div>
</div>

<?php

echo '<strong>'.'TOTAL DE VENDAS DO DIA - R$: '. number_format($totaVendas1, 2, ',', '.').'</strong>';
echo '<strong style="color: blue">'.'<br>TOTAL DE VENDAS QUITADAS DO DIA - R$: '. number_format($totaVendasQuitadas, 2, ',', '.').'</strong>';
echo '<strong style="color:red;">'.'<br>TOTAL DE VENDAS EM ABERTO DO DIA - R$: '. number_format($totaVendasEmAberto, 2, ',', '.').'</strong>';

?>

<style>
    .isDisabled {
        color: currentColor;
        cursor: not-allowed;
        opacity: 0.5;
        text-decoration: none;
        pointer-events: none;
    }
</style>


<?php $this->load->view("sistema/modais/notas/editarNotaModal"); ?>
<?php $this->load->view("sistema/modais/notas/adicionarNotaModal"); ?>
<?php $this->load->view("sistema/modais/notas/quitarNotaModal"); ?>
<?php $this->load->view("sistema/modais/exluirItemGerericosModal"); ?>



<script>
    $('a').on('click', function (e) {
        if ($(this).attr('imprimirNota')) {
            var preventiva = $(this).attr('imprimirNota')
            abreImpressaoPreventiva(preventiva);
            return false;
        }
    });


    function abreImpressaoPreventiva(preventiva) {
        var url = "<?php echo base_url() ?>relatorios/visualizarNotaPorID/" + preventiva;
        var win = window.open(url, target = "_blank", "left=400,top=300,width=700,height=500,location=no,menubar=no,toolbar=no");
        win.print();
    }
    ;
</script>

<script type="text/javascript">
    $(document).on('click', 'a', function (event) {
        if ($(this).attr('servicoItem')) {
            $('#idItemExcluir').val($(this).attr('servicoItem'));
            $("#excluirItem").attr("action", "<?php echo base_url() ?>manutencao/excluirNota");
        }
    });
</script>

