<?php 
    session_start();
    include('../../validadores/validarSession.php');
    include('../StoGlobal/include/conexion.php');
    include('../StoGlobal/include/conexion1.php');
    include('../StoGlobal/include/conexion3.php');
    error_reporting(0);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="shortcut icon" href="../../img/LogoBG.png">
    <title>StoGlobal - Cotizaciones</title>
    
    <!-- CSS -->
        <!-- Css - NavBar Boostrap 5 -->
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">

        <!-- Css - Body -->
        <link rel="stylesheet" href="../../styles/principal.css" type="text/css">

        <!-- Css - DataTable  -->
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.10.20/datatables.min.css"/>  

        <!-- Css - extension responsive DataTable  -->
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.2.3/css/responsive.dataTables.min.css">

        <!-- Css - DataTable -->
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.13.1/datatables.min.css"/>
        
        <style>
            table thead{
                background-color: #fff;        
            }

        
    </style>
    <!-- FIN CSS -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/js/all.min.js" crossorigin="anonymous"></script>
</head>
<body>
    <?php
        include('../../NavBar.php');
    ?>

    <div class="cssContainer mt-5">
        <div class="mb-3 pt-5" style="text-align:center;">
            <h2>Cotizaciones - StoGlobal</h2>
        </div>
        <div class="row" >
            <div class="col-lg-13" style="margin:auto;width:98%;background-color:#fff;padding: 8px">
                <table id="Tablas" class="table table-bordered  display nowrap" cellspacing="0" width="100%" >
                    <thead>
                        <tr>
                            <th>N°</th>
                            <th>ID Cotización</th>
                            <th>Tipo</th>
                            <th>Contacto</th>
                            <th>Cod. Proyecto</th>
                            <th>Monto Venta Neto </th>
                            <th>Ganancia Neto </th>
                            <th>Estado</th>
                            <th width="7px">Acción</th>
                            <th width="7px">View</th>
                        </tr>
                    </thead>
                    <tbody>
    
                        <?php

                            $cnt=1;

                            $query = "select * from sto_cotizacion ORDER BY id_cotizacion DESC";
                            $stmt = $DBcon->prepare( $query );
                            $stmt->execute();
                            
                            if($stmt->rowCount() > 0) {
                                while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
                                    extract($row);
                        ?>
                                    <tr>
                                        <td class="center"><?php echo $cnt;?>.</td>   
                                        <td><?php echo $id_cotizacion; ?></td>
                                        <td><?php echo $tipo_cotizacion; ?></td>
                                        <td><?php echo $contacto; ?></td>
                                        <td></td>

                                        <?php

                                            $Monto_Neto_compra=0;
                                            $Monto_Neto_venta=0;

                                            $query = "select * from sto_cotizacion_items where id_cotizacion='$id_cotizacion'";
                                            $stmt1 = $DBcon->prepare( $query );
                                            $stmt1->execute();
                                            
                                            if($stmt1->rowCount() > 0) {
                                                while($row=$stmt1->fetch(PDO::FETCH_ASSOC)) {
                                                    extract($row);
                                                    $Monto_Neto_compra=$Monto_Neto_compra+$valor_neto;
                                                    $Monto_Neto_venta=$Monto_Neto_venta+$precio_venta;
                                                    $Ganancia_Neto=$Monto_Neto_venta-$Monto_Neto_compra;
                                                } 
                                            }
                                        ?>
                                            <td><?php echo $Monto_Neto_venta;?></td>
                                            <td><?php echo $Ganancia_Neto;?></td>
                                        <td>
                                            <?php 
                                                if($estado1==0){
                                                     ?> 
                                                    <i class="fa fa-circle" style="color:red;font-size:8px;margin-bottom:3px"></i>
                                                    <?php
                                                    echo "Rechazada";
                                                   
                                                }
                                                if($estado1==1){
                                                    ?> 
                                                    <i class="fa fa-circle" style="color:yellow;font-size:8px;margin-bottom:3px"></i>
                                                    <?php
                                                    echo "En espera";
                                                    
                                                }
                                                if($estado1==2){
                                                    ?> 
                                                    <i class="fa fa-circle" style="color:gray;font-size:8px;margin-bottom:3px"></i>
                                                    <?php
                                                    echo "En proceso";
                                                }
                                                if($estado1==3){
                                                    ?> 
                                                    <i class="fa fa-circle" style="color:blue;font-size:8px;margin-bottom:3px"></i>
                                                    <?php
                                                    echo "Proceso de Pago";
                                                }
                                                if($estado1==4){
                                                    ?> 
                                                    <i class="fa fa-circle" style="color:green;font-size:8px;margin-bottom:3px"></i>
                                                    <?php
                                                    echo "Completado";
                                                }

                                                    /* 
                                                        0 Rechazado
                                                        1 En espera
                                                        2 En Proceso
                                                        3 Esperando Pago
                                                        4 Completado
                                                    
                                                    */
                                            ?>
                                        </td>
                                        <td>    
                                            <?php  
                                                if($estado1==1){
                                            ?>
                                                <a href="javascript:popUp('checkEstado.php?idCotiz=<?php echo $id_cotizacion;?>')">
                                                    <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M52.5 440.6c-9.5 7.9-22.8 9.7-34.1 4.4S0 428.4 0 416V96C0 83.6 7.2 72.3 18.4 67s24.5-3.6 34.1 4.4L224 214.3V256v41.7L52.5 440.6zM256 352V256 128 96c0-12.4 7.2-23.7 18.4-29s24.5-3.6 34.1 4.4l192 160c7.3 6.1 11.5 15.1 11.5 24.6s-4.2 18.5-11.5 24.6l-192 160c-9.5 7.9-22.8 9.7-34.1 4.4s-18.4-16.6-18.4-29V352z"/></svg>
                                                </a>
                                                &nbsp;&nbsp;&nbsp;
                                                
                                                <a href="javascript:popUp('checkEstado.php?idCotiz0=<?php echo $id_cotizacion;?>')" >
                                                    <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 384 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"/></svg>
                                                </a>
                                            <?php
                                                }
                                                if($estado1==0){
                                                // if($_SESSION['cargo']=='3'){
                                            ?>
                                                <a href="javascript:popUp('delete.php?id_cot=<?php echo $id_cotizacion;?>')" ><svg xmlns="http://www.w3.org/2000/svg" height="18" width="16" style="color: #FFD43B;cursor:pointer;" viewBox="0 0 448 512"><path d="M135.2 17.7L128 32H32C14.3 32 0 46.3 0 64S14.3 96 32 96H416c17.7 0 32-14.3 32-32s-14.3-32-32-32H320l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7zM416 128H32L53.2 467c1.6 25.3 22.6 45 47.9 45H346.9c25.3 0 46.3-19.7 47.9-45L416 128z"/></svg></a>
                                        
                                            <?php 
                                                // }                                          
                                                }
                                                if($estado1==3){
                                            ?>
                                                <!-- <a href="javascript:popUp('checkEstado.php?idCotiz1=')">
                                                    <svg xmlns="http://www.w3.org/2000/svg" height="1em" width="14" viewBox="0 0 448 512">
                                                        <path d="M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"/>
                                                    </svg>
                                                </a> -->    
                                            <?php
                                                }
                                            ?>

                                            
                                        </td>
                                        <td>
                                            <a href="javascript:popUp('Ulices5/Generar_PDF.php?id_cot=<?php echo $id_cotizacion;?>')"><svg xmlns="http://www.w3.org/2000/svg" height="18" width="16" style="cursor:pointer" viewBox="0 0 512 512"><path d="M64 464l48 0 0 48-48 0c-35.3 0-64-28.7-64-64L0 64C0 28.7 28.7 0 64 0L229.5 0c17 0 33.3 6.7 45.3 18.7l90.5 90.5c12 12 18.7 28.3 18.7 45.3L384 304l-48 0 0-144-80 0c-17.7 0-32-14.3-32-32l0-80L64 48c-8.8 0-16 7.2-16 16l0 384c0 8.8 7.2 16 16 16zM176 352l32 0c30.9 0 56 25.1 56 56s-25.1 56-56 56l-16 0 0 32c0 8.8-7.2 16-16 16s-16-7.2-16-16l0-48 0-80c0-8.8 7.2-16 16-16zm32 80c13.3 0 24-10.7 24-24s-10.7-24-24-24l-16 0 0 48 16 0zm96-80l32 0c26.5 0 48 21.5 48 48l0 64c0 26.5-21.5 48-48 48l-32 0c-8.8 0-16-7.2-16-16l0-128c0-8.8 7.2-16 16-16zm32 128c8.8 0 16-7.2 16-16l0-64c0-8.8-7.2-16-16-16l-16 0 0 96 16 0zm80-112c0-8.8 7.2-16 16-16l48 0c8.8 0 16 7.2 16 16s-7.2 16-16 16l-32 0 0 32 32 0c8.8 0 16 7.2 16 16s-7.2 16-16 16l-32 0 0 48c0 8.8-7.2 16-16 16s-16-7.2-16-16l0-64 0-64z"/></svg></a>
                                     
                                            &nbsp;
                                            <a href="javascript:popUp('index1.php?id_cot=<?php echo $id_cotizacion;?>')"><svg xmlns="http://www.w3.org/2000/svg" height="18" width="16" style="cursor:pointer" viewBox="0 0 576 512"><path d="M288 32c-80.8 0-145.5 36.8-192.6 80.6C48.6 156 17.3 208 2.5 243.7c-3.3 7.9-3.3 16.7 0 24.6C17.3 304 48.6 356 95.4 399.4C142.5 443.2 207.2 480 288 480s145.5-36.8 192.6-80.6c46.8-43.5 78.1-95.4 93-131.1c3.3-7.9 3.3-16.7 0-24.6c-14.9-35.7-46.2-87.7-93-131.1C433.5 68.8 368.8 32 288 32zM144 256a144 144 0 1 1 288 0 144 144 0 1 1 -288 0zm144-64c0 35.3-28.7 64-64 64c-7.1 0-13.9-1.2-20.3-3.3c-5.5-1.8-11.9 1.6-11.7 7.4c.3 6.9 1.3 13.8 3.2 20.7c13.7 51.2 66.4 81.6 117.6 67.9s81.6-66.4 67.9-117.6c-11.1-41.5-47.8-69.4-88.6-71.1c-5.8-.2-9.2 6.1-7.4 11.7c2.1 6.4 3.3 13.2 3.3 20.3z"/></svg></a>
                                       
                                        </td>
                                    </tr>
                            <?php 
                                $cnt++;} 
                                }
                            ?>
                        
                    </tbody>
                </table>  
            </div>
        </div> 
    </div>


    <!-- JS -->
        <!-- Js - importante para Funcionalidad DataTable -->
        <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>

        <!-- Js -Funcionalidad DataTable-->
        <script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.20/datatables.min.js"></script>  
        
        <!-- Js - extension DataTable responsive -->
        <script src="https://cdn.datatables.net/responsive/2.2.3/js/dataTables.responsive.min.js"></script>

        <!-- Js - NavBar -->
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>

        <script type="text/javascript">
            function popUp(URL) {
                window.open(URL, 'Nombre de la ventana', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=1200,height=700,left = 390,top = 50');
            }
        </script> 

        <!-- Js - español DataTable -->
        <script>
            $(document).ready(function() {
                $('#Tablas').DataTable({
                    responsive: true,
                    "language": 
                    {
                        "aria": {
                            "sortAscending": ": orden ascendente",
                            "sortDescending": ": orden descendente"
                        },
                        "autoFill": {
                            "cancel": "Cancelar",
                            "fill": "Llenar todas las celdas con <i>%d&lt;\\\/i&gt;<\/i>",
                            "fillHorizontal": "Llenar celdas horizontalmente",
                            "fillVertical": "Llenar celdas verticalmente"
                        },
                        "buttons": {
                            "collection": "Colección <span class=\"ui-button-icon-primary ui-icon ui-icon-triangle-1-s\"><\/span>",
                            "colvis": "Visibilidad de la columna",
                            "colvisRestore": "Restaurar visibilidad",
                            "copy": "Copiar",
                            "copyKeys": "Presiona ctrl or u2318 + C para copiar los datos de la tabla al portapapeles.<br \/><br \/>Para cancelar, haz click en este mensaje o presiona esc.",
                            "copySuccess": {
                                "_": "Copió %ds registros al portapapeles",
                                "1": "Copió un registro al portapapeles"
                            },
                            "copyTitle": "Copiado al portapapeles",
                            "csv": "CSV",
                            "excel": "Excel",
                            "pageLength": {
                                "_": "Mostrar %ds registros",
                                "-1": "Mostrar todos los registros"
                            },
                            "pdf": "PDF",
                            "print": "Imprimir"
                        },
                        "datetime": {
                            "amPm": [
                                "AM",
                                "PM"
                            ],
                            "hours": "Horas",
                            "minutes": "Minutos",
                            "months": {
                                "0": "Enero",
                                "1": "Febrero",
                                "10": "Noviembre",
                                "11": "Diciembre",
                                "2": "Marzo",
                                "3": "Abril",
                                "4": "Mayo",
                                "5": "Junio",
                                "6": "Julio",
                                "7": "Agosto",
                                "8": "Septiembre",
                                "9": "Octubre"
                            },
                            "next": "Siguiente",
                            "previous": "Anterior",
                            "seconds": "Segundos",
                            "weekdays": [
                                "Dom",
                                "Lun",
                                "Mar",
                                "Mie",
                                "Jue",
                                "Vie",
                                "Sab"
                            ]
                        },
                        "decimal": ",",
                        "editor": {
                            "close": "Cerrar",
                            "create": {
                                "button": "Nuevo",
                                "submit": "Crear",
                                "title": "Crear nuevo registro"
                            },
                            "edit": {
                                "button": "Editar",
                                "submit": "Actualizar",
                                "title": "Editar registro"
                            },
                            "error": {
                                "system": "Ocurrió un error de sistema (&lt;a target=\"\\\" rel=\"nofollow\" href=\"\\\"&gt;Más información)."
                            },
                            "multi": {
                                "info": "Los elementos seleccionados contienen diferentes valores para esta entrada. Para editar y configurar todos los elementos de esta entrada con el mismo valor, haga clic o toque aquí, de lo contrario, conservarán sus valores individuales.",
                                "noMulti": "Esta entrada se puede editar individualmente, pero no como parte de un grupo.",
                                "restore": "Deshacer cambios",
                                "title": "Múltiples valores"
                            },
                            "remove": {
                                "button": "Eliminar",
                                "confirm": {
                                    "_": "¿Está seguro de que desea eliminar %d registros?",
                                    "1": "¿Está seguro de que desea eliminar 1 registro?"
                                },
                                "submit": "Eliminar",
                                "title": "Eliminar registro"
                            }
                        },
                        "emptyTable": "Sin registros",
                        "info": "Mostrando _START_ a _END_ de _TOTAL_ registros",
                        "infoEmpty": "Mostrando 0 a 0 de 0 registros",
                        "infoFiltered": "(filtrado de _MAX_ registros)",
                        "infoThousands": ".",
                        "lengthMenu": "Mostrar _MENU_ registros",
                        "loadingRecords": "Cargando...",
                        "paginate": {
                            "first": "Primero",
                            "last": "Último",
                            "next": "Siguiente",
                            "previous": "Anterior"
                        },
                        "processing": "Procesando...",
                        "search": "Buscar:",
                        "searchBuilder": {
                            "add": "Agregar Condición",
                            "button": {
                                "_": "Filtros (%d)",
                                "0": "Filtrar"
                            },
                            "clearAll": "Limpiar Todo",
                            "condition": "Condición",
                            "conditions": {
                                "array": {
                                    "contains": "Contiene",
                                    "empty": "Vacío",
                                    "equals": "Igual",
                                    "not": "Distinto",
                                    "notEmpty": "No vacío",
                                    "without": "Sin"
                                },
                                "date": {
                                    "after": "Mayor",
                                    "before": "Menor",
                                    "between": "Entre",
                                    "empty": "Vacío",
                                    "equals": "Igual",
                                    "not": "Distinto",
                                    "notBetween": "No entre",
                                    "notEmpty": "No vacío"
                                },
                                "number": {
                                    "between": "Entre",
                                    "empty": "Vacío",
                                    "equals": "Igual",
                                    "gt": "Mayor",
                                    "gte": "Mayor o igual",
                                    "lt": "Menor",
                                    "lte": "Menor o igual",
                                    "not": "Distinto",
                                    "notBetween": "No entre",
                                    "notEmpty": "No vacío"
                                },
                                "string": {
                                    "contains": "Contiene",
                                    "empty": "Vacío",
                                    "endsWith": "Termina con",
                                    "equals": "Igual",
                                    "not": "Distinto",
                                    "notEmpty": "No vacío",
                                    "startsWith": "Comienza con"
                                }
                            },
                            "data": "Datos",
                            "deleteTitle": "Eliminar regla de filtrado",
                            "leftTitle": "Filtros anulados",
                            "logicAnd": "Y",
                            "logicOr": "O",
                            "rightTitle": "Filtro",
                            "title": {
                                "_": "Filtros (%d)",
                                "0": "Filtrar"
                            },
                            "value": "Valor"
                        },
                        "searchPanes": {
                            "clearMessage": "Limpiar todo",
                            "collapse": {
                                "_": "Paneles de búsqueda (%d)",
                                "0": "Paneles de búsqueda"
                            },
                            "count": "{total}",
                            "countFiltered": "{shown} ({total})",
                            "emptyPanes": "Sin paneles de búsqueda",
                            "loadMessage": "Cargando paneles de búsqueda...",
                            "title": "Filtros activos - %d"
                        },
                        "select": {
                            "cells": {
                                "_": "%d celdas seleccionadas",
                                "1": "Una celda seleccionada"
                            },
                            "columns": {
                                "_": "%d columnas seleccionadas",
                                "1": "Una columna seleccionada"
                            },
                            "rows": {
                                "1": "Una fila seleccionada",
                                "_": "%d filas seleccionadas"
                            }
                        },
                        "thousands": ".",
                        "zeroRecords": "No se encontraron registros"
                    }
                    
                });
            } );  
        </script>
    <!-- FIN JS -->
</body>
</html>


