@if (!empty($task_id)) 
    <legend>Tarea a trabajar</legend> 
@endif 
<div class="row mb-3">
    <div class="col text-end">
        <form id="ver_tabla_">
            <input type="hidden" name="id_balance" class="id" value="">
            <input type="hidden" name="cuit" class="id" value="{{$cuit}}">
            <input type="hidden" name="nombre_persona" class="id" value="{{$nombre_persona}}">
            <input type="hidden" name="ver_tres" class="ver_tres" value="1">
            <input type="hidden" name="columnas" class="columnas" value="3">
            <input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">
            @if($balanceSinCarga == false)
                <button type="submit" id="ver_3_ultimos" class="ver_tabla btn btn-fidelitas text-center mb-1" data-toggle="modal" data-target="#myModalVer">Ver últimos 3 en tabla</button>
            @else
                <button type="submit" id="ver_3_ultimos" class="ver_tabla btn btn-fidelitas text-center mb-1" data-toggle="modal" data-target="#myModalVer" disabled>Ver últimos 3 en tabla</button>
            @endif
        </form>
    </div>
</div>
<table id="tabla_balances" class="table table-bordered text-right table-hover">
    <thead>
        <tr class="text-center" style="background-color:#eeeeee;">
            <th class="d-none"></th>
            <th class="d-none"></th>
            <th style="width:10%;">Fecha</th>
            <th>Nro. Ejercicio</th>
            <th style="width:10%;">Balance o <br>Manifestación Bienes </th>
            <th style="width:10%;">Período</th>
            <th style="width:10%;">Moneda</th>
            <th style="width:10%;">Total Activo</th>
            <th style="width:10%;">Total Pasivo</th>
            <th style="width:10%;">Resultado Ejercicio</th>
            <th style="width:10%;">Estado</th>
            <th style="width:10%;">ID</th>
            <th class="no-sort"></th>
            <th class="no-sort"></th>
            <th class="no-sort"></th>
            <th class="no-sort"></th>
            <!-- <th class="no-sort"></th> -->
        </tr>
    </thead>
    <tbody> 
        @foreach ($balances as $balance) 
        <tr class="text-center">
            <td class="d-none">{{$balance->fecha_balance}}</td>
            <td class="id d-none">{{$balance->id_balance}}</td>
            <td class="fecha" style="width:10%;">{{$balance->fecha_dia_mes_anio}}</td>
            <td class="ejercicio">{{$balance->ejercicio}}</td>
            <td style="width:10%;" class="text-center">{{$balance->bal_man}}</td>
            <td style="width:10%;" class="text-center">{{$balance->periodo}} meses</td>
            <td style="width:10%;">{{$balance->nombre_moneda}}</td>
            <td style="width:10%;">{{number_format($balance->act_total,2)}}</td>
            <td style="width:10%;">{{number_format($balance->pas_total,2)}}</td>
            <td style="width:10%;">{{number_format($balance->ganancia,2)}}</td> @if ($balance->estado=="PUBLICADO") <td style="width:10%; color:#4caf50;"> @endif @if ($balance->estado=="A VERIFICAR")
            <td style="width:10%;color:#fbc02d;"> @endif @if ($balance->estado=="GRABADO PARCIAL")
            <td style="width:10%;color:#f44336;"> @endif @if ($balance->estado=="ELIMINADO")
            <td style="width:10%;color:#f44336;"> @endif @if ($balance->estado=="CARGA LED")
            <td style="width:10%;color:#f44336;"> @endif @if ($balance->estado!="PUBLICADO" && $balance->estado!="A VERIFICAR" && $balance->estado!="GRABADO PARCIAL" && $balance->estado!="ELIMINADO" && $balance->estado!="CARGA LED")
            <td style="width:10%;color:#f44336;"> @endif {{$balance->estado}}</td>
            <td>{{$balance->task_id}}</td> @if($balance->estado!="ELIMINADO") <td>
                <form id="modificar_{{$balance->id_balance}}">
                    <input type="hidden" name="id_balance" class="id" value="{{$balance->id_balance}}">
                    <input type="hidden" name="cuit" class="id" value="{{$cuit}}">
                    <input type="hidden" name="nombre_persona" class="id" value="{{$nombre_persona}}">
                    <input type="hidden" name="task_id" class="id" value="{{$task_id}}">
                    <input type="hidden" name="task_id1" class="id" value="{{$balance->task_id}}">
                    <input type="hidden" name="fecha_inicio_tarea" value="{{$balance->fecha_inicio_tarea}}">
                    <input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">
                    <input type="hidden" name="usuario_tarea" value="{{$balance->usuario_tarea}}">
                    <input type="hidden" name="cargar_datos" value="{{$balance->cargar_datos}}">
                    <input type="hidden" name="nominal_ajustado" value="{{$balance->nominal_ajustado}}">

                    {{-- @if ($menu['BALANCE']) --}} 
                    @if ($balance->autorizado=='autorizado') 
                        <input type="hidden" class="usuario" value="autorizado"> 
                    @else 
                        <input type="hidden" class="usuario" value="NOautorizado"> 
                    @endif 
                    {{-- @if (!empty($task_id) && !isset($menu['BALANCE']) ) --}} 
                    @if (!empty($task_id) && $user_id == $balance->usuario_tarea ) 
                        @if($balance->fecha_fin_tarea == null) 
                            @if($balance->fecha_inicio_tarea == null) 
                                <button type="submit" class="iniciar btn btn-info btn-fidelitas text-center" data-toggle="modal" data-target="#modalNuevoBalance">Iniciar <br>Tarea </button> 
                            @else 
                                <button type="submit" class="iniciar btn btn-info btn-fidelitas text-center" data-toggle="modal" data-target="#modalNuevoBalance">Continuar <br>Tarea </button> 
                            @endif 
                            @else 
                                <button type="submit" class="btn btn-primary text-center" data-bs-toggle="modal" data-bs-target="#modalNuevoBalance">Modificar</button> 
                            @endif 
                        @else 
                            <button type="submit" class="btn btn-primary text-center" data-bs-toggle="modal" data-bs-target="#modalNuevoBalance">Modificar</button> 
                    @endif
                </form>
            </td>
            {{-- @if (!empty($task_id) && !isset($menu['BALANCE']) ) --}} @if (!empty($task_id) && $user_id == $balance->usuario_tarea ) @if($balance->fecha_fin_tarea == null) <td>
                <form id="finalizar_{{$balance->id_balance}}">
                    <input type="hidden" name="task_id" class="id" value="{{$task_id}}">
                    <input type="hidden" name="tipo" class="id" value="balance">
                    <input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">
                    {{csrf_field()}} @if($balance->fecha_inicio_tarea == null || $balance->estado != 'A VERIFICAR') <button type="submit" class="finalizar btn btn-info btn-fidelitas text-center" disabled>Finalizar <br>Tarea </button> @else <button type="submit" class="finalizar btn btn-info btn-fidelitas text-center">Finalizar <br>Tarea </button> @endif
                </form>
            </td>@else <td></td> @endif @else <td></td> @endif @else <td></td>
            <td></td>
            <td></td> @endif <td> @if ($menu['BALANCE'])
                <!-- Es un usuario autorizado -->
                <form name="baja_balance_{{$balance->id_balance}}" class="baja_balance_{{$balance->id_balance}}">
                    <input type="hidden" name="id_balance" class="id" value="{{$balance->id_balance}}">
                    <input type="hidden" name="cuit" class="cuit" value="{{ $cuit}}">
                    <input type="hidden" name="_token" id="token" value="{{ csrf_token() }}"> @if($balance->estado=="ELIMINADO") <button class="btn btn-danger text-center">Pasar a Grabado Parcial</button> @else <button class="btn btn-danger text-center">Eliminar</button> @endif
                </form> @endif
            </td>
            <td> 
                @if ($menu['BALANCE'])
                    <!-- Es un usuario autorizado -->
                    <form id="tabla_singlular_{{$balance->id_balance}}">
                        <input type="hidden" name="id_balance" class="id" value="{{$balance->id_balance}}">
                        <input type="hidden" name="cuit" class="id" value="{{$cuit}}">
                        <input type="hidden" name="nombre_persona" class="id" value="{{$nombre_persona}}">
                        <input type="hidden" name="ver_tres" class="ver_tres" value="0">                        
                        <input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">
                        <button type="submit" class="btn btn-success text-center" data-toggle="modal" data-target="#myModalVer">Ver en tabla</button>
                    </form> 
                @endif
            </td>            
        </tr> @endforeach </tbody>
    <tfoot>
        <tr class="text-center" style="background-color:#eeeeee;">
            <th class="d-none"></th>
            <th class="d-none"></th>
            <th style="width:10%;">Fecha</th>
            <th>Nro. Ejercicio</th>
            <th style="width:10%;">Balance o <br>Manifestación Bienes </th>
            <th style="width:10%;">Período</th>
            <th style="width:10%;">Moneda</th>
            <th style="width:10%;">Total Activo</th>
            <th style="width:10%;">Total Pasivo</th>
            <th style="width:10%;">Resultado Ejercicio</th>
            <th style="width:10%;">Estado</th>
            <th>ID</th>
            <th class="no-sort"></th>
            <th class="no-sort"></th>
            <th class="no-sort"></th>
            <th style="width:30%;" class="no-sort"></th>
            <!-- <th class="no-sort"></th> -->
        </tr>
    </tfoot>
</table>
<script>
    crearDataTablePersonalizado('#tabla_balances', '0', '"desc"');
</script>