<section class="content-header">
    <h1><i class='fa-fw fa fa-building'></i> <?php echo $_translator->_getTranslation('Configuracion de gastos fijos de sucursal');?></small></h1>
    <ol class="breadcrumb">
        <li><a href="<?php echo ROOT_HOST?>/Controller/Home.php"><i class="fa fa-dashboard"></i><?php echo $_translator->_getTranslation('Inicio')?></a></li>
      <li class="active"><?php echo $_translator->_getTranslation('Configuracion de gastos fijos de sucursal');?></li>
    </ol>
</section>
<section class="content">
<div class="box">
    <div class='flashmessenger'><?php $flashmessenger->showMessage();?></div>
    <div class="box-header with-border">
        <div class="box-tools"></div><!-- /.box-tools -->
    </div><!-- /.box-header -->
    <div class="box-body">
     <div class="clear"></div>
            <div class="col-xs-12 col-md-12">                
                <table 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><!-- /.box -->
</section>
<style>
    table td{
        position:relative;
    }
</style>
<script>   
    $('#save').on('click',function(){
        var options = $('input[type=text]').serializeArray();
        $.post('/Controller/ExpensesConfig.php', {
        action: 'ajax',
        request: 'saveConfig',            
        options: options
            }, 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');
    });
</script>
