<?
require_once 'header.php';
include 'erpc_gp_escala_toolbar.php';
require_once 'inc/usuario.php';
require_once('inc/parametros.php');
require_once('inc/gp_escala.php');

checkLogin('login.php');

$escala = new erpc_gp();

if(isset($_GET['id'])){ //Se estou editando esta escala
    
    $id_escala = base64_decode($_GET['id']);
    $evento = $escala->escala_get($id_escala);
    $colaboradores = $escala->colaboradores_evento_getAll($evento['id']);
    //$colaboradores_temp = $escala->colaboradores_not_in_evento_getAll($id_escala);
    //$colaboradores = array_merge($colaboradores, $colaboradores_temp);
}else{
    $colaboradores = array();
}



?>
<form method="post" action="erpc_gp_escala_ws.php" id=validate_custom>
<div class="block">


<div class="modal modal-white modal-draggable fade" id="helper-modal-div" tabindex="-1" role="dialog" aria-labelledby="helper-modal-label" aria-hidden="true">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="helper-modal-label">Helper</h4>
          </div>
          <div class="modal-body">
            Aguarde ...
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal" id="modalCancel">Cancelar</button>
            <button type="button" class="btn btn-primary" data-dismiss="modal" id="modalOk" disabled="disabled">Selecionar</button>
          </div>
        </div>
      </div>
    </div>
    

  
    <div class="header">
      <h2>Escala</h2>
    </div>


<!-- Tab panes -->
<div class="tab-content">

  <div role="tabpanel" class="tab-pane fade in active" id="form4">
  <div class="block">
  <div class="content controls">

  <input type="hidden" value="<?php echo base64_encode($evento['id']); ?>" name="evento[id_crip]" id="id">

  <div class="form-row">
        <div class="col-md-2"><label>ID</label></div>
        <div class="col-md-2">
            <div class="input-group">
              <input readonly value="<?php echo $evento['id']; ?>" name="evento[id]" id="id">
            </div>
        </div>
  </div>
  <div class="form-row">
        <div class="col-md-2"><label>Evento</label></div>
        <div class="col-md-2">
            <div class="input-group">
              <input required type=text name="evento[ds_evento]" value="<?= $evento['ds_evento'] ?>"/>
            </div>
        </div>
  </div>

  <div class="form-row">
      <div class="col-md-2"><label>Cliente</label></div>
      <div class="col-md-2">
        <div class="input-group">
          <input requerid type="number" id="evento[id_cliente]" name="evento[id_cliente]" class="form-control" value="<?= sgcws_attr($evento['id_cliente']); ?>" />

        <div class="input-group-addon">
          <a href="erpc_clientes_helper.php" class='input-helper' data-remote="false" data-toggle="modal" data-target="#helper-modal-div" data-value="input[name='evento[id_cliente]']" data-description="input[name='evento[ds_nome_cliente]']" data-title="Selecione:">
          <span class="fa fa-search"></span></a>
         </div>
         </div>
         </div>
      <div class="col-md-4"><input readonly name="evento[ds_nome_cliente]" id="evento[ds_nome_cliente]"/></div>
    </div>
	
    <div class="form-row">
      <div class="col-md-2"><label>Data Início:</label></div>
      <div class="col-md-2"><input required type=text data-mask="00/00/0000" name="evento[dt_inicio]" id="evento[dt_inicio]" value="<?php echo $evento['dt_inicio']; ?>" class="datepicker" /></div>
    </div>
    <div class="form-row">
      <div class="col-md-2"><label>Data Fim:</label></div>
      <div class="col-md-2"><input required type=text data-mask="00/00/0000" name="evento[dt_fim]" id="evento[dt_fim]" value="<?php echo $evento['dt_fim']; ?>" class="datepicker" /></div>
    </div>
    
    <!-- 
    <div class="col-md-2"><label>Escolha o Setor:</label></div>					
				<div class="col-md-2">
            		<select name="escala[id_setor]" required class="form-control">
            			<?php 
            			     $setores = $escala->setores_getAll();
            			     foreach($setores as $setor){
            			         echo "<option value='" .$setor['id'] ."'>" . $setor['ds_setor'] . "</option>";
            			     }
            			     echo "<option selected value=''></option>";
            			      
            			?>
            		</select>
            	</div>
  
     </div>
     -->
     
    


  <!-- início da sessão produtos -->
  <div class="form-row">
    <div class="col-md-12">
      <label>Colaboradores</label>
      <div class="table-responsive">
      <table class="table table-stripped code-sortable itens-1-n" id="colaboradores" data-n="<?= count($colaboradores); ?>" data-order-by="0">
        <thead>
          <tr>
            
            <th width="20%">#</th>
            <th width="20%">Colaborador</th>
            <th width="05%"># Função</th>
            <th width="05%">Função</th>
            <th width="05%"># Setor</th>
            <th width="05%">Setor</th>
            
            <th width="05%">Hr Entrada</th>
            <th width="05%">Hr Saida</th>
            <th width="05%">Valor Bonus</th>
            <th width="05%">Justificativa</th>
            
            <th width="05%">Vale Transp.</th>
            <th width="05%">Adicional Noturno</th>
            <th width="05%">Hr Extra Diferenciada</th>
            <th width="3%" class="text-center no-sort">Excluir</th>

          </tr>
        </thead>
        
        <tbody>
        
          <?php
          for($i = 0; $i < count($colaboradores); $i++) {
              
            $colaborador = $colaboradores[$i];
          ?>
          <tr>
              <td><div class="input-group">
                <input required type="text" width="20" name="evento[colaboradores][<?= $i; ?>][id_colaborador]" value="<?= sgcws_attr($colaborador['id_colaborador']); ?>" >
                <div class="input-group-addon">
                  <a href="erpc_gp_colaborador_helper.php" class='input-helper' data-remote="false" data-toggle="modal" data-target="#helper-modal-div" data-value="input[name='evento[colaboradores][<?= $i; ?>][id_colaborador]']" data-description="input[name='evento[colaboradores][<?= $i; ?>][ds_colaborador]']" data-title="Selecione:" value="<?= sgcws_attr($colaborador['id_colaborador']); ?>" >
                  <span class="fa fa-search"></span></a>
                </div>
                </div>
              </td>
			  
			  <td><input type="text" name="evento[colaboradores][<?= $i; ?>][ds_colaborador]" class="form-control" readonly value="<?= sgcws_attr($colaborador['ds_colaborador']); ?>" /></td>
			  
			  <td><div class="input-group">
                <input type="text" width="10" name="evento[colaboradores][<?= $i; ?>][id_funcao]" value="<?= sgcws_attr($colaborador['id_funcao']); ?>" >
                <div class="input-group-addon">
                  <a href="erpc_gp_funcoes_helper.php" class='input-helper' data-remote="false" data-toggle="modal" data-target="#helper-modal-div" data-value="input[name='evento[colaboradores][<?= $i; ?>][id_funcao]']" data-description="input[name='evento[colaboradores][<?= $i; ?>][ds_funcao]']" data-title="Selecione:" value="<?= sgcws_attr($colaborador['id_funcao']); ?>" >
                  <span class="fa fa-search"></span></a>
                </div>
                </div>
              </td>
              <td><input type="text" name="evento[colaboradores][<?= $i; ?>][ds_funcao]" class="form-control" readonly value="<?= sgcws_attr($colaborador['ds_funcao']); ?>" /></td>  
              
              
              <td><div class="input-group">
                <input type="text" width="10" name="evento[colaboradores][<?= $i; ?>][id_setor]" value="<?= sgcws_attr($colaborador['id_setor']); ?>" >
                <div class="input-group-addon">
                  <a href="erpc_gp_setores_helper.php" class='input-helper' data-remote="false" data-toggle="modal" data-target="#helper-modal-div" data-value="input[name='evento[colaboradores][<?= $i; ?>][id_setor]']" data-description="input[name='evento[colaboradores][<?= $i; ?>][ds_setor]']" data-title="Selecione:" value="<?= sgcws_attr($colaborador['id_funcao']); ?>" >
                  <span class="fa fa-search"></span></a>
                </div>
                </div>
              </td>
              <td><input type="text" name="evento[colaboradores][<?= $i; ?>][ds_setor]" class="form-control" readonly value="<?= sgcws_attr($colaborador['ds_setor']); ?>" /></td>
              
              
              <td><input type="text" name="evento[colaboradores][<?= $i; ?>][dh_entrada]" maxlength="16" size="16" onKeyPress="DataHora(event, this)" class="form-control" value="<?= sgcws_attr($colaborador['dh_entrada']); ?>" /></td>
			  <td><input type="text" name="evento[colaboradores][<?= $i; ?>][dh_saida]" maxlength="16" size="16" onKeyPress="DataHora(event, this)" class="form-control" value="<?= sgcws_attr($colaborador['dh_saida']); ?>" /></td>
			  
			  <td><input required type="text" name="evento[colaboradores][<?= $i; ?>][vl_bonus]" class="form-control mask_money" value="<?= sgcws_attr($colaborador['vl_bonus']); ?>" /></td>
			  <td><input type="text" name="evento[colaboradores][<?= $i; ?>][ds_justificativa]" class="form-control" value="<?= sgcws_attr($colaborador['ds_justificativa']); ?>" /></td>

			  <td><input required type="text" name="evento[colaboradores][<?= $i; ?>][vl_vale_transporte]" class="form-control mask_money" value="<?= sgcws_attr($colaborador['vl_vale_transporte']); ?>" /></td>
			  <td><input required type="text" name="evento[colaboradores][<?= $i; ?>][vl_add_noturno]" class="form-control mask_money" value="<?= sgcws_attr($colaborador['vl_add_noturno']); ?>" /></td>
			  <td><input required type="text" name="evento[colaboradores][<?= $i; ?>][vl_hr_extra_diferenciada]" class="form-control mask_money" value="<?= sgcws_attr($colaborador['vl_hr_extra_diferenciada']); ?>" /></td>

              <td class="text-center"><a class="item-delete" href="#"><span class="fa fa-trash"></span></a></td>
          </tr>
          <?php
                
          }
          if(!count($colaboradores) > 0 ){
          // uma linha separada para um item novo
          $colaborador = $escala->colaborador_create();

          ?>
          <tr>
              <td><div class="input-group">
                <input required type="text" width="20" name="evento[colaboradores][<?= $i; ?>][id_colaborador]" value="<?= sgcws_attr($colaborador['id_colaborador']); ?>" >
                <div class="input-group-addon">
                  <a href="erpc_gp_colaborador_helper.php" class='input-helper' data-remote="false" data-toggle="modal" data-target="#helper-modal-div" data-value="input[name='evento[colaboradores][<?= $i; ?>][id_colaborador]']" data-description="input[name='evento[colaboradores][<?= $i; ?>][ds_colaborador]']" data-title="Selecione:" value="<?= sgcws_attr($colaborador['id_colaborador']); ?>" >
                  <span class="fa fa-search"></span></a>
                </div>
                </div>
              </td>
			  
			  <td><input type="text" name="evento[colaboradores][<?= $i; ?>][ds_colaborador]" class="form-control" readonly value="<?= sgcws_attr($colaborador['ds_colaborador']); ?>" /></td>
			  
			  <td><div class="input-group">
                <input required type="text" width="10" name="evento[colaboradores][<?= $i; ?>][id_funcao]" value="<?= sgcws_attr($colaborador['id_funcao']); ?>" >
                <div class="input-group-addon">
                  <a href="erpc_gp_funcoes_helper.php" class='input-helper' data-remote="false" data-toggle="modal" data-target="#helper-modal-div" data-value="input[name='evento[colaboradores][<?= $i; ?>][id_funcao]']" data-description="input[name='evento[colaboradores][<?= $i; ?>][ds_funcao]']" data-title="Selecione:" value="<?= sgcws_attr($colaborador['id_funcao']); ?>" >
                  <span class="fa fa-search"></span></a>
                </div>
                </div>
              </td>
              <td><input type="text" name="evento[colaboradores][<?= $i; ?>][ds_funcao]" class="form-control" readonly value="<?= sgcws_attr($colaborador['ds_funcao']); ?>" /></td>  
              
              
              <td><div class="input-group">
                <input required type="text" width="10" name="evento[colaboradores][<?= $i; ?>][id_setor]" value="<?= sgcws_attr($colaborador['id_setor']); ?>" >
                <div class="input-group-addon">
                  <a href="erpc_gp_setores_helper.php" class='input-helper' data-remote="false" data-toggle="modal" data-target="#helper-modal-div" data-value="input[name='evento[colaboradores][<?= $i; ?>][id_setor]']" data-description="input[name='evento[colaboradores][<?= $i; ?>][ds_setor]']" data-title="Selecione:" value="<?= sgcws_attr($colaborador['id_funcao']); ?>" >
                  <span class="fa fa-search"></span></a>
                </div>
                </div>
              </td>
              <td><input type="text" name="evento[colaboradores][<?= $i; ?>][ds_setor]" class="form-control" readonly value="<?= sgcws_attr($colaborador['ds_setor']); ?>" /></td>
              
              
              <td><input type="text" name="evento[colaboradores][<?= $i; ?>][dh_entrada]" class="form-control" readonly value="<?= sgcws_attr($colaborador['dh_entrada']); ?>" /></td>
			  <td><input type="text" name="evento[colaboradores][<?= $i; ?>][dh_saida]" class="form-control" readonly value="<?= sgcws_attr($colaborador['dh_saida']); ?>" /></td>
			  
			  <td><input required type="text" name="evento[colaboradores][<?= $i; ?>][vl_bonus]" class="form-control mask_money" value="<?= sgcws_attr($colaborador['vl_bonus']); ?>" /></td>
			  <td><input type="text" name="evento[colaboradores][<?= $i; ?>][ds_justificativa]" class="form-control" value="<?= sgcws_attr($colaborador['ds_justificativa']); ?>" /></td>

			  <td><input required type="text" name="evento[colaboradores][<?= $i; ?>][vl_vale_transporte]" class="form-control mask_money" value="<?= sgcws_attr($colaborador['vl_vale_transporte']); ?>" /></td>
			  <td><input required type="text" name="evento[colaboradores][<?= $i; ?>][vl_add_noturno]" class="form-control mask_money" value="<?= sgcws_attr($colaborador['vl_add_noturno']); ?>" /></td>
			  <td><input required type="text" name="evento[colaboradores][<?= $i; ?>][vl_hr_extra_diferenciada]" class="form-control mask_money" value="<?= sgcws_attr($colaborador['vl_hr_extra_diferenciada']); ?>" /></td>

              <td class="text-center"><a class="item-delete" href="#"><span class="fa fa-trash"></span></a></td>
          </tr>
	      <?php 
          }
	      ?>
        </tbody>
      </table>
      </div>
      <p>
        <a href="#" class="item-add pull-right" data-target="#colaboradores"><span class="fa fa-plus-circle"></span> Novo item</a>
      </p>
    </div>
  </div>



    


<!--
<div class="form-row">
  <div class="col-md-6">
    <label>Plano de Contas</label><br>
    <div class="col-md-4">
    <div class="input-group">
      <input requerid type="text" id="pedidos_venda[id_plano_contas]" name="pedidos_venda[id_plano_contas]" class="validate[required] form-control" value="<?=sgcws_attr($pedidos_venda['id_plano_contas']); ?>" />

    <div class="input-group-addon">
      <a href="erpc_plano_contas_helper.php" class='input-helper' data-remote="false" data-toggle="modal" data-target="#helper-modal-div" data-value="input[name='pedidos_venda[id_plano_contas]']" data-description="input[name='pedidos_venda[ds_plano_contas]']" data-title="Selecione:" value="<?= sgcws_attr($pedidos_venda['id_plano_contas']); ?>">
      <span class="fa fa-search"></span></a>
     </div>
     </div>
     </div>
   <div class="col-md-8"><input readonly name="pedidos_venda[ds_plano_contas]" id="pedidos_venda[ds_plano_contas]"/></div>
  </div>
</div>
-->

<div class="form-row">
  <div class="col-md-2"><label>Vlr Total Colaboradores</label></div>
  <div class="col-md-2"><input readonly name="evento[vl_total_colaboradores]" id="evento[vl_total_colaboradores]" class="form-control" value="<?= sgcws_attr($pedidos_venda['vl_total_produtos']); ?>" required /></div>
</div>


</div>
</div>

<div class="block">
  <div class="content controls">
    <div class="form-row">
      <div class="col-md-12 text-right">
        <button type="submit" name="btn-edit" id="btn-edit" class="btn btn-primary btn-cleanx" onClick="$('#validate_custom').validationEngine('hide');" >Salvar</button>
        <button type="button" name="btn-voltar" id="btn-voltar" class="btn btn-default btn-cleanx">Voltar</button>
      </div>
    </div>
  </div>
</div>
</form>

<?php include 'inc/helper_modal_div.php'; ?>
<?php include 'footer.php'; ?>

<script type='text/javascript' src='js/pedidos_venda.js' ></script>
<script type='text/javascript' src='js/valida_cpf_cnpj.js' ></script>
<script type='text/javascript'>
function DataHora(evento, objeto){
	var keypress=(window.event)?event.keyCode:evento.which;
	campo = eval (objeto);
	if (campo.value == '00/00/0000 00:00:00')
	{
		campo.value=""
	}
 
	caracteres = '0123456789';
	separacao1 = '/';
	separacao2 = ' ';
	separacao3 = ':';
	conjunto1 = 2;
	conjunto2 = 5;
	conjunto3 = 10;
	conjunto4 = 13;
	conjunto5 = 16;
	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (19))
	{
		if (campo.value.length == conjunto1 )
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto2)
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto3)
		campo.value = campo.value + separacao2;
		else if (campo.value.length == conjunto4)
		campo.value = campo.value + separacao3;
		else if (campo.value.length == conjunto5)
		campo.value = campo.value;
	}
	else
		event.returnValue = false;
}
</script>
<style>
  .input-group {
    min-width:130px;// if you want width please write here //
    text-align:left;
  }
</style>
