<?php $provider = app('App\Http\Controllers\balanceController'); ?>
<?php $__env->startSection('main-content'); ?>
    <div class="container-fluid spark-screen">
        <div class="row">
            <div class="col-md-12 ">
                <div class="box-body">
                    <div class="container-fluid spark-screen">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="box box-admin-border">
                                    <div class="box-header with-border">
                                        <i class="fa fa-code-fork"></i><h3 class="box-title"><b>Balance global Categorias</b></h3>

                                        
                                    </div>
                                    <form action="/balance/balance" method = "get">
                                        <div class="col-sm-12 add_top_10">
                                            <div class="col-sm-8 " style="border-right: solid 1px #8d8d8d">
                                                <h5>Filtrar por subcategorias</h5>
                                                <div class="form-group col-sm-3">
                                                    <select class="form-control"  type="text" name="categoria" >
                                                        <option value="">Categorias</option>
                                                        <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $datas): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <option value="<?php echo e($datas->id); ?>"><?php echo e($datas->name); ?></option>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </select>
                                                </div>
                                                <div class="form-group col-sm-3">
                                                    <input type="date" name="start"   placeholder="Fecha Inicio" class="form-control">
                                                </div>
                                                <div class="form-group col-sm-3">
                                                    <input type="date" name="finish" placeholder="Fecha Final"  class="form-control">
                                                </div>
                                                <div class="form-group col-sm-3">
                                                    <select class="form-control"  type="text" name="tipo" >
                                                        <option selected value="out">Retiros</option>
                                                        <option value="add">Ingresos</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-sm-4 ">
                                                <h5>Categorias Anuales</h5>
                                                <div class="form-group col-sm-6">
                                                    <select class="form-control"  type="text" name="year" >
                                                        <option value="2019">2020</option>
                                                        <option selected value="2019">2019</option>
                                                        <option value="2018">2018</option>
                                                        <option value="2017">2017</option>
                                                        <option value="2016">2016</option>
                                                    </select>
                                                </div>
                                                <div class="col-sm-4 add_top_1  ">
                                                    <button type="submit" class="btn btn-sm  btn-default form-control "><i class="fa fa-filter"></i></button>
                                                </div>
                                            </div>


                                </div>

                        

                                            
                                                
                                                    
                                                    
                                                    
                                                    
                                                    
                                                
                                            
                                            
                                                
                                                    
                                                    
                                                
                                            

                                            
                                                
                                                    
                                                    
                                                        
                                                    
                                                
                                            
                                            
                                            
                                                
                                            

                                            
                                                           

                                                           
                                            
                                        
                                    </form>

                                    <div class="box-body responsive-table">

                                        <div id="lista_item_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
                                            <div class="row">
                                                <div class="col-sm-12">
                                                    <?php
                                                        if(count($timeline)>=12){
                                                            $valorletra = '10px';
                                                        } else {
                                                            $valorletra = '12px';
                                                        }
                                                    ?>
                                                    <table style="font-size: <?php echo  $valorletra ?>" id="balance" class="display" cellspacing="0" width="100%">
                                                        <thead>
                                                            <tr>
                                                                <th>
                                                                <?php if($tipom=="add"): ?>
                                                                        <small class="label pull-left bg-primary">
                                                                                <i class="fa fa-sort-up"></i>
                                                                        </small>
                                                                <?php elseif($tipom=="out"): ?>
                                                                        <small class="label pull-left bg-red">
                                                                                <i class="fa fa-sort-desc"></i>
                                                                        </small>
                                                                    <?php endif; ?>
                                                                    <?php if($cateselet): ?>
                                                                       &nbsp; <?php echo e($cateselet->name); ?>

                                                                        <?php else: ?>
                                                                        &nbsp; Categorias
                                                                    <?php endif; ?>
                                                                </th>
                                                                <?php $__currentLoopData = $timeline; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t=> $valor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <th><?php echo e($t); ?></th>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                <th style="background-color: #c6e0ec;">Total</th>
                                                            </tr>
                                                        </thead>
                                                            <tbody>
                                                                <?php $__currentLoopData = $subcategorias; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ss): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <tr>
                                                                        <td>
                                                                            <?php echo e($ss->name); ?>

                                                                        </td>

                                                                        
                                                                        <?php if( $filter ): ?>
                                                                            <?php $__currentLoopData = $timeline; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t=> $valor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                                <?php if( $valor ): ?>
                                                                                    <td>
                                                                                        <?php $sum = 0; ?>
                                                                                        <?php $__currentLoopData = $valor; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $datos): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                                            <?php if($datos->amount): ?>
                                                                                                <?php if($datos->id_attr ==  $ss->id): ?>
                                                                                                 <?php $sum += $datos->amount;
                                                                                                 ?>
                                                                                                <?php endif; ?>
                                                                                            <?php endif; ?>
                                                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                                        <?php echo number_format($sum, 2, '.', ',');?>
                                                                                    </td>
                                                                                <?php else: ?>
                                                                                    <td>
                                                                                       0
                                                                                    </td>
                                                                                <?php endif; ?>
                                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                        <?php endif; ?>

                                                                        <?php if(!$filter ): ?>
                                                                            <?php $__currentLoopData = $timeline; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t=> $valor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                                <?php if( $valor ): ?>
                                                                                    <td>
                                                                                        <?php $sum = 0; ?>
                                                                                        <?php $__currentLoopData = $valor; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $datos): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                                                                            <?php if($datos->amount): ?>
                                                                                                    
                                                                                                    
                                                                                                <?php if($datos->categories_id ==  $ss->id): ?>
                                                                                                    <?php $sum += $datos->amount;
                                                                                                    ?>
                                                                                                <?php endif; ?>
                                                                                            <?php endif; ?>
                                                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                                        <?php echo number_format($sum, 2, '.', ',');?>
                                                                                    </td>
                                                                                <?php else: ?>
                                                                                    <td>
                                                                                        0
                                                                                    </td>
                                                                                <?php endif; ?>
                                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                        <?php endif; ?>




                                                                            <td style="background-color: #c6e0ec; color: #111;">
                                                                                <?php if($filter ): ?>
                                                                                    <?php $sum = 0; ?>
                                                                                    <?php $__currentLoopData = $timeline; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t=> $valor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                                        <?php if( $valor ): ?>
                                                                                            <?php $__currentLoopData = $valor; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $datos): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                                                <?php if($datos->amount): ?>
                                                                                                    <?php if($datos->id_attr ==  $ss->id): ?>
                                                                                                        <?php $sum += $datos->amount;
                                                                                                        ?>
                                                                                                    <?php endif; ?>
                                                                                                <?php endif; ?>

                                                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                                        <?php endif; ?>
                                                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                                    <?php echo number_format($sum, 2, '.', ',');?>
                                                                                <?php endif; ?>



                                                                                <?php if(!$filter ): ?>
                                                                                <?php $sum = 0; ?>
                                                                                <?php $__currentLoopData = $timeline; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t=> $valor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                                    <?php if( $valor ): ?>

                                                                                        <?php $__currentLoopData = $valor; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $datos): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                                                                                <?php if($datos->categories_id ==  $ss->id): ?>
                                                                                                    <?php $sum += $datos->amount;
                                                                                                    ?>
                                                                                                <?php endif; ?>
                                                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                                    <?php endif; ?>
                                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                                 <?php echo number_format($sum, 2, '.', ',');?>
                                                                                <?php endif; ?>
                                                                                
                                                                                    
                                                                                
                                                                            </td>
                                                                    </tr>

                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                <?php if($timeline): ?>
                                                                <tr style="background-color: #c6e0ec; color: #111">
                                                                    <td style="background-color: #a2c5d5;"></td>
                                                                    <?php $totall = 0; ?>
                                                                     <?php $__currentLoopData = $timeline; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t=> $valor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                        <?php if( $valor ): ?>
                                                                            <td>
                                                                                <?php $sum = 0; ?>
                                                                                <?php $__currentLoopData = $valor; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $datos): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                                    <?php if($datos->amount): ?>
                                                                                        <?php if($datos->numberOf ==  $t): ?>
                                                                                            <?php
                                                                                                $sum += $datos->amount;
                                                                                                $totall += $datos->amount;
                                                                                            ?>
                                                                                        <?php endif; ?>
                                                                                    <?php endif; ?>
                                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                                <?php echo number_format($sum, 2, '.', ',') ;?>
                                                                            </td>
                                                                        <?php else: ?>
                                                                            <td>
                                                                               0
                                                                            </td>
                                                                        <?php endif; ?>
                                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                    <td>  <?php echo  number_format($totall, 2, '.', ',')  ?></td>
                                                                </tr>
                                                                <?php endif; ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </div>
                                            </div>
                                            <!-- /.box-body -->
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>




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

<?php echo $__env->make('adminlte::layouts.app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>