<?php
/* @var $this PlanillaController */
/* @var $model Planilla */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'planilla-form',
        'htmlOptions'=>array('class'=>'form-horizontal'),
        'enableClientValidation'=>true,
        'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
      
    )); ?>
    <hr>
	<div class="row">
            <div class="col-12">
                <p class="note">Los campos con <span class="required">*</span> son obligatorios.</p>
            </div> 
        </div>

    <div class="row"> 
        <div class="col-12 col-sm-12 col-md-4">
                    <div class="form-group">
                       <?php echo $form->labelEx($model,'id_empleado', array('class' => 'col-12 mdi mdi-mail mdi-18px text-uppercase')); ?>
                       <div class="col-12">
                        <?php echo $form->textField($model,'id_empleado',array('size'=>60,'maxlength'=>100,
                               'class' => 'form-control form-control-line text-uppercase', 'readonly'=>'true','autocomplete'=>"off",
                               'placeholder'=>"")); ?>
                        <?php echo $form->error($model,'id_empleado'); ?>
                      </div>
                    </div>
         </div>
        <div class="col-12 col-sm-12 col-md-4">
                    <div class="form-group">
                       <?php echo $form->labelEx($model,'sueldo_diario', array('class' => 'col-12 mdi mdi-mail mdi-18px text-uppercase')); ?>
                       <div class="col-12">
                        <?php echo $form->textField($model,'sueldo_diario',array('size'=>60,'maxlength'=>100,
                               'class' => 'form-control form-control-line text-uppercase', 'readonly'=>'true','autocomplete'=>"off",
                               'placeholder'=>"")); ?>
                        <?php echo $form->error($model,'sueldo_diario'); ?>
                      </div>
                    </div>
         </div>
        
        
    </div>
    
    
    
    
    <div class="row">
           <div class="col-12 col-sm-12 col-md-4">
                    <div class="form-group">
                       <?php echo $form->labelEx($model,'dni', array('class' => 'col-12 mdi mdi-mail mdi-18px text-uppercase')); ?>
                       <div class="col-12">
                        <?php echo $form->textField($model,'dni',array('size'=>60,'maxlength'=>100,
                               'class' => 'form-control form-control-line text-uppercase', 'readonly'=>'true','autocomplete'=>"off",
                               'placeholder'=>"")); ?>
                        <?php echo $form->error($model,'dni'); ?>
                      </div>
                    </div>
         </div>
         
         
            <div class="col-12 col-sm-12 col-md-4 ">
                    <div class="form-group">
                       <?php echo $form->labelEx($model,'nombre', array('class' => 'col-12 mdi mdi-mail mdi-18px text-uppercase')); ?>
                       <div class="col-12">
                        <?php echo $form->textField($model,'nombre',array('size'=>60,'maxlength'=>100,
                               'class' => 'form-control form-control-line text-uppercase', 'readonly'=>'true','autocomplete'=>"off",
                               'placeholder'=>"")); ?>
                        <?php echo $form->error($model,'nombre'); ?>
                      </div>
                    </div>
            </div>
               <div class="col-12 col-sm-12 col-md-4 ">
                    <div class="form-group">
                       <?php echo $form->labelEx($model,'apellido', array('class' => 'col-12 mdi mdi-mail mdi-18px text-uppercase')); ?>
                       <div class="col-12">
                        <?php echo $form->textField($model,'apellido',array('size'=>60,'maxlength'=>100,
                               'class' => 'form-control form-control-line text-uppercase', 'readonly'=>'true','autocomplete'=>"off",
                               'placeholder'=>"")); ?>
                        <?php echo $form->error($model,'apellido'); ?>
                      </div>
                    </div>
          </div>
               
            
        </div>
    
    
    
      <div class="row">
             <div class="col-12 col-sm-12 col-md-4 ">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'fecha',array('class' => 'col-12 text-uppercase')); ?>
                    <div class="col-12">
                    <?php
                            $this->widget('ext.YiiDateTimePicker.jqueryDateTime', array(
                                'model' => $model,
                                'attribute' => 'fecha',
                                'options' => array(
                                    'lang'=>'es',
                                    'timepicker'=>false,
                                    'format'=>'d-m-Y',
                                    ),
                                    'htmlOptions' => array(
                                    'class' => 'form-control form-control-line',
                                    'placeholder'=>"dd-mm-aaaa",
                                    'autocomplete'=>"off"
                                    ),
                            ));
                            ?>
                     <?php echo $form->error($model,'fecha'); ?>
                   </div>
                 </div>
            </div>
            
            <div class="col-12 col-sm-12 col-md-4">
                <div class="form-group">
                   <?php echo $form->labelEx($model,'dia', array('class' => 'col-12 mdi mdi-mail mdi-18px text-uppercase')); ?>
                   <div class="col-12">
                    <?php echo $form->textField($model,'dia',array('size'=>60,'maxlength'=>100,
                           'class' => 'form-control form-control-line text-uppercase', 'readonly'=>'true','autocomplete'=>"off",
                           'placeholder'=>"")); ?>
                    <?php echo $form->error($model,'dia'); ?>
                  </div>
                </div>
            </div>
        </div>
    
	
    <div class="row mt-2">
            <div class="col-12 col-sm-12 col-md-3">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'dias_trabajo', array('class' => 'col-12')); ?>
                    <div class="col-12">
                    <?php echo $form->textField($model,'dias_trabajo',array('size'=>60,'maxlength'=>100,
                        'class' => 'form-control form-control-line ', 
                        'autocomplete'=>"off",
                        'placeholder'=>"",
                        'onChange'=>"calcular()"
                        )); ?>
                    <?php echo $form->error($model,'dias_trabajo'); ?>
                   </div>
                 </div>
            </div>
                    <div class="col-12 col-sm-12 col-md-3">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'feriado', array('class' => 'col-12')); ?>
                    <div class="col-12">
                    <?php echo $form->textField($model,'feriado',array('size'=>60,'maxlength'=>100,
                        'class' => 'form-control form-control-line ', 
                        'autocomplete'=>"off",
                        'placeholder'=>"",
                        'onChange'=>"calcular()"
                        
                        
                        )); ?>
                    <?php echo $form->error($model,'feriado'); ?>
                   </div>
                 </div>
            </div>
           <div class="col-12 col-sm-12 col-md-3">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'bono', array('class' => 'col-12')); ?>
                    <div class="col-12">
                    <?php echo $form->textField($model,'bono',array('size'=>60,'maxlength'=>100,
                        'class' => 'form-control form-control-line ', 
                        'autocomplete'=>"off",
                        'placeholder'=>"",
                        'onChange'=>"calcular()"
                        )); ?>
                    <?php echo $form->error($model,'bono'); ?>
                   </div>
                 </div>
            </div>
        <div class="col-12 col-sm-12 col-md-3">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'comision', array('class' => 'col-12')); ?>
                    <div class="col-12">
                    <?php echo $form->textField($model,'comision',array('size'=>60,'maxlength'=>100,
                        'class' => 'form-control form-control-line ', 
                        'autocomplete'=>"off",
                        'placeholder'=>"",
                        'onChange'=>"calcular()"
                        
                        
                        )); ?>
                    <?php echo $form->error($model,'comision'); ?>
                   </div>
                 </div>
            </div>
        
        <div class="col-12 col-sm-12 col-md-3">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'gratificacion', array('class' => 'col-12')); ?>
                    <div class="col-12">
                    <?php echo $form->textField($model,'gratificacion',array('size'=>60,'maxlength'=>100,
                        'class' => 'form-control form-control-line ', 
                        'autocomplete'=>"off",
                        'placeholder'=>"",
                        'onChange'=>"calcular()"
                        
                        
                        )); ?>
                    <?php echo $form->error($model,'gratificacion'); ?>
                   </div>
                 </div>
            </div>
        
        
        <div class="col-12 col-sm-12 col-md-3">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'descuento', array('class' => 'col-12')); ?>
                    <div class="col-12">
                    <?php echo $form->textField($model,'descuento',array('size'=>60,'maxlength'=>100,
                        'class' => 'form-control form-control-line ', 
                        'autocomplete'=>"off",
                        'placeholder'=>"",
                        'onChange'=>"calcular()",
                        'readonly'=>'true',
                        
                        )); ?>
                    <?php echo $form->error($model,'descuento'); ?>
                   </div>
                 </div>
            </div>
        
        <div class="col-12 col-sm-12 col-md-3">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'descuento2', array('class' => 'col-12')); ?>
                    <div class="col-12">
                    <?php echo $form->textField($model,'descuento2',array('size'=>60,'maxlength'=>100,
                        'class' => 'form-control form-control-line ', 
                        'autocomplete'=>"off",
                        'placeholder'=>"",
                        'onChange'=>"calcular()"
                        
                        
                        )); ?>
                    <?php echo $form->error($model,'descuento2'); ?>
                   </div>
                 </div>
            </div>
        
        <div class="col-12 col-sm-12 col-md-3">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'descuento3', array('class' => 'col-12')); ?>
                    <div class="col-12">
                    <?php echo $form->textField($model,'descuento3',array('size'=>60,'maxlength'=>100,
                        'class' => 'form-control form-control-line ', 
                        'autocomplete'=>"off",
                        'placeholder'=>"",
                        'onChange'=>"calcular()"
                        
                        
                        )); ?>
                    <?php echo $form->error($model,'descuento3'); ?>
                   </div>
                 </div>
            </div>
        
        
        
        
        <div class="col-12 col-sm-12 col-md-3">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'penalidad', array('class' => 'col-12')); ?>
                    <div class="col-12">
                    <?php echo $form->textField($model,'penalidad',array('size'=>60,'maxlength'=>100,
                        'class' => 'form-control form-control-line ', 
                        'autocomplete'=>"off",
                        'placeholder'=>"",
                        'onChange'=>"calcular()"
                        
                        )); ?>
                    <?php echo $form->error($model,'penalidad'); ?>
                   </div>
                 </div>
            </div>
            <div class="col-12 col-sm-12 col-md-3">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'descuento_prestamo', array('class' => 'col-12')); ?>
                    <div class="col-12">
                    <?php echo $form->textField($model,'descuento_prestamo',array('size'=>60,'maxlength'=>100,
                        'class' => 'form-control form-control-line ', 
                        'autocomplete'=>"off",
                        'placeholder'=>"",
                        'onChange'=>"calcular()"
                        
                        
                        )); ?>
                    <?php echo $form->error($model,'descuento_prestamo'); ?>
                   </div>
                 </div>
            </div>
        
        <div class="col-12 col-sm-12 col-md-3 ">
                    <div class="form-group">
                       <?php echo $form->labelEx($model,'total', array('class' => 'col-12 mdi mdi-mail mdi-18px text-uppercase')); ?>
                       <div class="col-12">
                        <?php echo $form->textField($model,'total',array('size'=>60,'maxlength'=>100,
                               'class' => 'form-control form-control-line text-uppercase', 'readonly'=>'true','autocomplete'=>"off",
                               'placeholder'=>"")); ?>
                        <?php echo $form->error($model,'total'); ?>
                      </div>
                    </div>
          </div>
        
        
        
    </div>
   
    <div class="row">
         <div class="col-12 col-sm-12">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'observacion', array('class' => 'col-12')); ?>
                    <div class="col-12">
                    <?php echo $form->textField($model,'observacion',array('size'=>60,'maxlength'=>100,
                        'class' => 'form-control form-control-line ', 
                        'autocomplete'=>"off",
                        'placeholder'=>"",
                        )); ?>
                    <?php echo $form->error($model,'observacion'); ?>
                   </div>
                 </div>
            </div>
    </div>
    
       <div class="row">
         <div class="col-12 col-sm-12">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'observacion1', array('class' => 'col-12')); ?>
                    <div class="col-12">
                    <?php echo $form->textField($model,'observacion1',array('size'=>60,'maxlength'=>100,
                        'class' => 'form-control form-control-line ', 
                        'autocomplete'=>"off",
                        'placeholder'=>"",
                        )); ?>
                    <?php echo $form->error($model,'observacion1'); ?>
                   </div>
                 </div>
            </div>
    </div>
    
    <div class="row">
         <div class="col-12 col-sm-12">
                 <div class="form-group">
                    <?php echo $form->labelEx($model,'observacion2', array('class' => 'col-12')); ?>
                    <div class="col-12">
                    <?php echo $form->textField($model,'observacion2',array('size'=>60,'maxlength'=>100,
                        'class' => 'form-control form-control-line ', 
                        'autocomplete'=>"off",
                        'placeholder'=>"",
                        )); ?>
                    <?php echo $form->error($model,'observacion2'); ?>
                   </div>
                 </div>
            </div>
    </div>
    
    
        <div class="row" >
            <div class="col-12 col-sm-12 col-md-4 m-t-20">

                <div class="form-group">
                    <div class="col-12">
                        <button type="submit" class="btn btn-large btn-block btn-primary  ">
                           <i class="fas fa-save fa-lg   "></i>    <?php echo $model->isNewRecord ? "REGISTRAR" : "EDITAR"; ?></button>
                    </div>
                </div>
            </div> 
        </div>
    
    
        <div class="row">
                <div class="col-12 col-sm-12 col-md-4">
                <?php echo $form->errorSummary($model); ?>
                </div>
        </div>
    
    
    
    
<?php $this->endWidget(); ?>

</div><!-- form -->


<script type="application/javascript">
    
      $('#Planilla_fecha').datetimepicker({
      onChangeDateTime:function(date){
      $('#Planilla_dia').val('');
      $('#Planilla_fecha_em_').val('');
      $('#Planilla_fecha_em_').hide();
           var dm = $('#Planilla_fecha').val();
           var f= dm.split("-");
           var fecha = new Date(f[2],f[1]-1,f[0]); 
           var numDia=fecha.getDay();
           var dia='';
           if(numDia==0){
               dia='DOMINGO (NO VALIDO)';
               $('#Planilla_fecha').val('');
               $('#Planilla_dia').val('');
               $('#Planilla_dia_em_').val('No se permite seleccionar el dia domingo, por favor verifique');
               $('#Planilla_dia_em_').show();
               $("#tabla").html('');
           }
            if(numDia==1){
               dia='LUNES';
            }
            if(numDia==2){
               dia='MARTES';
            }
            if(numDia==3){ 
               dia='MIERCOLES';
            }
            if(numDia==4){
               dia='JUEVES';
            }
            if(numDia==5){
               dia='VIERNES';
            }
            if(numDia==6){
               dia='SABADO';
           }
           $('#Planilla_dia').val(dia);
 }
});

$(document).ready(function() {
    $('#Planilla_dias_trabajo').mask('A99999999999999', {translation: { 'A':{pattern: /[1-9]/}}, clearIfNotMatch: true});
    $('#Planilla_feriado').mask('999999999999999', {translation: { 'A':{pattern: /[1-9]/}}, clearIfNotMatch: true});
    $('#Planilla_bono').mask('999999999999999', {translation: { 'A':{pattern: /[1-9]/}}, clearIfNotMatch: true});
    $('#Planilla_comision').mask('999999999999999', {translation: { 'A':{pattern: /[1-9]/}}, clearIfNotMatch: true});
    $('#Planilla_descuento').mask('999999999999999', {translation: { 'A':{pattern: /[1-9]/}}, clearIfNotMatch: true});
    $('#Planilla_descuento2').mask('999999999999999', {translation: { 'A':{pattern: /[1-9]/}}, clearIfNotMatch: true});
    $('#Planilla_descuento3').mask('999999999999999', {translation: { 'A':{pattern: /[1-9]/}}, clearIfNotMatch: true});
    
    
    $('#Planilla_penalidad').mask('999999999999999', {translation: { 'A':{pattern: /[1-9]/}}, clearIfNotMatch: true});
    
}); 


function calcular() {
     var total=0;
     var dias_trabajo=$('#Planilla_dias_trabajo').val();
     var diario=$('#Planilla_sueldo_diario').val();
     var feriado=$('#Planilla_feriado').val();
     var bono=$('#Planilla_bono').val();
     var comision=$('#Planilla_comision').val();
     
     var gratificacion=$('#Planilla_gratificacion').val();
     
     
     
     
     var descuento=$('#Planilla_descuento').val();
     var descuento2=$('#Planilla_descuento2').val();
     var descuento3=$('#Planilla_descuento3').val();
     
     var penalidad=$('#Planilla_penalidad').val();
     var descuento_prestamo=$('#Planilla_descuento_prestamo').val();
     var total=$('#Planilla_total').val();
     var suma=0;
     var resta=0;
     var sueldo=0;
 
     if((diario == "" || diario.length == 0)){
         alert('DEBE SELECCIONAR EL EMPLEADO, Y TENER MONTO DE PAGO DIARIO.');
     }else{

         sueldo= dias_trabajo*diario;
         suma= parseFloat(sueldo) + parseFloat(feriado) +
                 parseFloat(bono) + parseFloat(comision)
               + parseFloat(gratificacion)
            ;
        
         resta=parseFloat(descuento3) + parseFloat(descuento2)+   parseFloat(descuento) + parseFloat(penalidad) + parseFloat(descuento_prestamo);
         
         total= parseFloat(suma) - parseFloat(resta);
         
         total=total.toFixed(2);
         
         
         $('#Planilla_total').val(total);
     }
 }
 
</script> 
<?php

Yii::app()->clientScript->registerScript('search', "
$('.buttonconyugue').click(function(){
	$('.conyugue').toggle();
	return false;
});
");