<div class="box box-primary">
<div class="box-header with-border">
    <h3 class="box-title"><i class="fa fa-th-large"></i> <?php echo $_translator->_getTranslation(ucfirst($_reporte->getTituloReporte()));?></h3>
    <!-- /.box-tools -->
</div><!-- /.box-header -->
<div class="box-body">
<?php
$data = $_reporte->getReporte();
if($data == null){
    echo "There is no information";
    exit;
}

$reportOptions = $_reporte->getOptions();
$month = $reportOptions['month'];
$year = $reportOptions['year'];
$_expensesList =  $data['fixed_expense_list'];
$_storeList =  $data['store_list'];
$_dataConfig =  $data['data_config'];

?>    
    <div class="box-body">
     <div class="clear"></div>
            <div class="col-xs-12 col-md-12">                
                <table id='tblFixedExpenses' class='table table-condensed table-hover '>
                    <thead>
                        <th class='text-center bg-default'><?php echo $_translator->_getTranslation('Sucursal')?></th>
                        <?php
                        if($_expensesList){
                            foreach ($_expensesList as $expense_id => $expense_name){?>
                                <th class='text-center'><?php echo $expense_name?></th><?php
                            }
                        }?>
                    </thead>
                    <tbody>
                        <?php
                        if($_storeList){
                            foreach($_storeList as $store_id => $store_name){
                                $dataStoreConfig = $_dataConfig[$store_id];?>
                                <tr>
                                    <td style='text-align: center;vertical-align: middle;' class="bg-primary"><?php echo $store_name; ?></td><?php   
                                    if($_expensesList){                                        
                                        foreach ($_expensesList as $expense_id => $expense_name){
                                            $cost_value = 0;
                                            $due_date = '';
                                         
                                            if(key_exists($expense_id, $dataStoreConfig)){                                                
                                                $cost_value = $dataStoreConfig[$expense_id]['cost'];
                                                $due_date = $dataStoreConfig[$expense_id]['due_date'];
                                            }?>
                                            <td class='text-center'>                                                
                                                <div class="input-group">
                                                    <span class="input-group-addon" title='<?php echo $_translator->_getTranslation('Costo') ?>'><i class='fa fa-fw fa-dollar'> </i> </span>	
                                                    <input type='text' id='cost_<?php echo $store_id.'_'.$expense_id ?>' name='cost_<?php echo $store_id.'_'.$expense_id ?>' value='<?php echo $cost_value ?>' class='_cost form-control mg_decimal text-right' />
                                                </div>
                                                <div class="input-group">
                                                    <span class="input-group-addon" title='<?php echo $_translator->_getTranslation('Dia de pago') ?>'><i class='fa fa-fw fa-calendar'></i></span>	
                                                    <input type='text' id='duedate_<?php echo $store_id.'_'.$expense_id ?>' name='duedate_<?php echo $store_id.'_'.$expense_id ?>' value='<?php echo $due_date ?>' class='_duedate mg_decimal form-control  text-right' />                                               
                                                </div>                                                
                                            </td><?php
                                        }
                                    } ?>
                                </tr><?php
                            }
                        }
                        ?>
                    </tbody>
                </table>
                <span id='save' class='btn btn-primary pull-right'><?php echo $_translator->_getTranslation('Guardar') ?></span>
            <?php
            
            ?>
            </div>
            <div class="clear"></div>
            <!-- Modal -->               
  </div><!-- /.box-body -->
</div>
</div>
<script>   
    $('#save').on('click',function(){
        var options = $('input[type=text]').serializeArray();

        $.post('/Controller/Reports.php', {
        action: 'ajax',
        request: 'saveFixedExpense',            
        options: options,
        month: <?php echo json_encode($month); ?>,
        year: <?php echo json_encode($year); ?>
            }, function(data) {
               if(data.response){
                    $.confirm({ 
                        title:"<i class='fa fa-check-circle'></i> Mensaje", 
                        content:data.msj,
                        type: 'green',
                        columnClass: 'col-md-6 col-md-offset-3',
                        buttons: {   
                            ok: {
                                text: "OK",
                                btnClass: 'btn-default',
                                keys: ['esc'],
                                action: function(){
                                     $(this).remove();
                                }
                            }
                        }                             
                    });     
               }else{
                   $.confirm({ 
                        title:"<i class='fa fa-info-circle'></i> Mensaje", 
                        content:data.msj,
                        type: 'red',
                        columnClass: 'col-md-6 col-md-offset-3',
                        buttons: {   
                            ok: {
                                text: "OK",
                                btnClass: 'btn-default',
                                keys: ['esc'],
                                action: function(){
                                     $(this).remove();
                                }
                            }
                        }                             
                    });     
               }                
            },
        'json');
    });
    
    $('#tblFixedExpenses').DataTable({
        paginate:false,
        filter:true,
        bFilter:true,
        aaSorting:[],
         dom: 'Bfrtip',
        buttons: [{               
            text: "<i class='fa fa-file-pdf-o' style='color:red'></i> Exportar a pdf",                                                              
            action : function(doc){ 
                document.location = "<?php echo $_reporte->getStringToSendGET().'&action=create&output=pdf' ?>";
            }
        }]
    });
    
    $('#tblFixedExpenses_filter').hide();
</script>
