<?php use_helper('UrlFunctions'); ?>
<script>

acutalizarEspecialidad = function(destino,elm){
  $(destino).options.length = 1;
  var url = '<?=buildUrl('ajax/request')?>';
  var pars = 'type=getEspecialidad&nombreElm='+destino+'&value='+elm.value;
  
	var myAjax = new Ajax.Request(
                            		url, 
                            		{
                            			method: 'get', 
                            			parameters: pars, 
                            			onComplete: actualizaJSON
                            		});
}

</script>
<script>
actualizaJSON = function(request, json){
  var numeroElementos = json.length;
  for (var i = 0; i < numeroElementos; i++){
    if($(json[i][0])){
  	  switch ($(json[i][0]).tagName){
  	    case 'TD'      : Element.update(json[i][0], json[i][1]); break;
  	    case 'INPUT'   : $(json[i][0]).value=json[i][1]; break;
  	    case 'SELECT'  : 
  	      var objDDL = $(json[i][0]);
  	      if(typeof(cont) == 'undefined'){
  	        var cont = 0;
  	        objDDL.options.length = 1;
  	      }
  	      var a_contentValues = json[i][1].split("_;_");
      		var value	= a_contentValues[0];
      		var text	= a_contentValues[1];
  	      var option	= new Option(text,value);
      		try{
      			objDDL.add(option,null);
      		}catch (e){
      			objDDL.add(option,-1);
      		}
  	      cont++;
  	    break;
  	  }
    }else{
      if(json[i][0].indexOf("function") > -1){
        eval("scriptEval = "+json[i][0]);
        scriptEval();
      }
    }
  }
}
</script>
<?php

$con = Conexion::getConexion();
 
if(isset($control)){
  
  
  
  	
  
		
	$sql = "SELECT IdPlanilla 
			FROM 	cr_planilla_temp 
        	WHERE 	Periodo	= '$Periodo'
        			and IdColaborador = '$idColaborador'
        			and IdConcepto = '$idConcepto' "
		;
	
	//echo $sql;
	$result   = mysql_db_query(Conexion::getNameDb(), $sql, $con);
	$num_rows = mysql_num_rows($result);
	
	$a_tmp = array();

	if($num_rows>0){
		while ($o_valor = mysql_fetch_object($result)) {
   		 	$IdPlanilla = $o_valor->IdPlanilla;
   		 	$sql = "REPLACE INTO cr_planilla_temp 
		          	(IdPlanilla,	Periodo,	IdColaborador,	IdConcepto,	Valor,	FechaCreacion,	UsuarioCreacion)
		          VALUES	
		           ('$IdPlanilla','$Periodo','$idColaborador','$idConcepto','$Monto',now(),'')";
		  
		  $result3 = mysql_db_query(Conexion::getNameDb(), $sql, $con);
		}
	}else{
		 $sql = "REPLACE INTO cr_planilla_temp 
          		(IdPlanilla,	Periodo,	IdColaborador,	IdConcepto,	Valor,	FechaCreacion,	UsuarioCreacion)
         		VALUES	
           		(NULL,'$Periodo','$idColaborador','$idConcepto','$Monto',now(),'')";
  
 		 $result3 = mysql_db_query(Conexion::getNameDb(), $sql, $con);
	}
        
  
  
  
 
  if($result3){
  	
    ?>
    <script language="JavaScript">
    parent.objMainTab.reqBody('<?=buildUrl('planilla/add')?>','&block=001&periodo=<?=$Periodo?>');
    parent.objMainTab.windowsCloseAll();
    </script>
    <?
  }else{
    $url = buildUrl('tardanza/add', "block=".$block."&error=1");
  }
  exit;
}else{
	$sql = "SELECT Valor 
			FROM 	cr_planilla_temp 
        	WHERE 	Periodo	= '$Periodo'
        			and IdColaborador = '$idColaborador'
        			and IdConcepto = '$idConcepto' "
		;
	
	
	$result   = mysql_db_query(Conexion::getNameDb(), $sql, $con);
	$num_rows = mysql_num_rows($result);
	
	$a_tmp = array();

	if($num_rows>0){
		while ($o_valor = mysql_fetch_object($result)) {
   		 	$Valor = $o_valor->Valor;
		}
	}
}
	
 
 ?>
 
<img src="/images/common/spacer.gif" width="10">
<table class="cuerpo" width="98%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="0">
      <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
          <td class="titleBody">
            <li>Concepto</li>
            <span class="subtitle"><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:::&nbsp;Ficha de Concepto</I></span></td>
          <td align="right" valign="baseline">&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>
     
  <tr>
    <td valign="top">
      <form id="form1" name="form1" method="POST">
      <input type="hidden" name="control" value="1">
        <table hspace="20px" class="marco" width="99%">
          <tr>
            <td valign="top">
              <table width="100%" border="0" cellpadding="5" cellspacing="0" style="background: #E3E9E2">
          		<tr>
    				  <td height="0">
    				  <fieldset>
    					<legend class="fielsettex"><I>Datos Generales</I></legend>
    					 <table width="100%" border="0" cellspacing="6" cellpadding="0">
							  
							  <tr>
                  				<td nowrap="nowrap" width="10%" class="cabecera"><label class="label req" for="txtAdministrador" >Colaborador</label></td>
  								 <td nowrap="nowrap"><label class="label"><?php
  								 $o_colaboradorBN = new ColaboradorBean();
  								 $o_colaboradorBN->setIdColaborador($idColaborador);
  								 $o_colaboradorDP = new ColaboradorDP($o_colaboradorBN);
  								 $a_o_colaboradorDP = $o_colaboradorDP->select();
  								// print_r($a_o_colaboradorDP);
  								 foreach ($a_o_colaboradorDP as $key => $o_colaboradorDP){
  								 	echo $o_colaboradorDP->getNombres()." ".$o_colaboradorDP->getApellidoPaterno()." ".$o_colaboradorDP->getApellidoMaterno();
  								 }
  								  //$idColaborador;?></label>
  								 <input type="hidden" name="idColaborador" value="<?echo $idColaborador;?>" /> 
                 				</td>
							  </tr>
							  <tr>
                  				<td nowrap="nowrap" width="10%" class="cabecera"><label class="label req" for="txtAdministrador" >Periodo</label></td>
  								 <td nowrap="nowrap"><label class="label"><?echo $Periodo;?></label>
  								 <input type="hidden" name="Periodo" value="<?php echo $Periodo;?>" />
                 				</td>
							  </tr>
							  <tr>
                  				<td nowrap="nowrap" width="10%" class="cabecera"><label class="label req" for="txtAdministrador" >Concepto</label></td>
  								 <td nowrap="nowrap"><label class="label">
  								 <input type="hidden" name="idConcepto" value="<?php echo $idConcepto;?>" />
  								 <?php
  								 $CrPlanillaConceptoFN = new CrPlanillaConceptoFN();
  								 $CrPlanillaConceptoFN->setIdConcepto($idConcepto);
  								 $o_CrPlanillaConceptoBN = $CrPlanillaConceptoFN->selectByPK();
  								// print_r($a_o_colaboradorDP);
  								 
  								 echo $o_CrPlanillaConceptoBN->getCodigo();
  								 ?></label>
  								 
                 				</td>
							  </tr>
							  <tr>
							  	<td nowrap="nowrap" width="10%" class="cabecera"><label class="label req" for="txtMonto" >Monto</label></td>
  								<td nowrap="nowrap"><input class="text required" type="text" name="Monto" id="Monto" size="15" maxlength="15" value="<?php echo $Valor;?>"/></td>
							  </tr>
							  
							   
							  
						</table>
						 <table width="100%" border="0" cellspacing="0" cellpadding="0">
							  <tr>
								 <td><img src="/images/common/spacer.gif" width="10"></td>
							  </tr>
							  <tr>
								<td align="center">
								  <input type="hidden" name="typeSubmit" id="typeSubmit">
								  <!--<input class="button" type="submit" value="Grabar y Nuevo" onclick="$('typeSubmit').value='add';"/>-->
								  <input class="button" type="submit" value="Grabar" onclick="$('typeSubmit').value='list';">
								  <input class="button" type="button" value="Cancelar" onclick="parent.objMainTab.windowsCloseAll();"/>
								</td>
							  </tr>
							  <tr>
								<td height="10">&nbsp;</td>
							  </tr>
							</table>
    					</fieldset>				
    				</td>
                </tr>
      </table>
      </form>
			<script type="text/javascript">
				var valid = new Validation('form1', {immediate : true});
			</script>
    </td>
  </tr>
</table>
