create or replace trigger PRYLABORCOBRABLEACTDET
Before Insert or Update Of Proyecto, Tarea, Horas or Delete On PRYLABORCOBRABLE	
For Each Row
Declare
   vLabor PryDetalleLabor.Labor%Type;
Begin
   If Inserting Then
      If :New.Control = 'S' Then
         Select Nvl(Max(Labor),0)+1 
            Into vLabor
         From PryDetalleLabor
         Where Informe=:New.Informe
           And Fecha  =:New.Fecha;

         Insert Into PryDetalleLabor(Informe, Fecha, Labor, Proyecto, Modulo,
     	  	     	             Referencia, Tarea, HorasPlan, HorasReal,
                                     LaborCobroRef)
            		      Values(:New.Informe, :New.Fecha, vLabor, :New.Proyecto, 
                                     Null, Null, :New.Tarea, 0,:New.Horas, 
                                     :New.Labor);
      End If;
   Elsif Updating Then
      Update PryDetalleLabor 
         Set Proyecto  = :New.Proyecto, 
             Tarea     = :New.Tarea, 
	     HorasReal = :New.Horas
      Where Informe       = :New.Informe
        And Fecha         = :New.Fecha
        And LaborCobroRef = :New.Labor;
   Else
      Delete From PryDetalleLabor
      Where Informe       = :Old.Informe
        And Fecha         = :Old.Fecha
        And LaborCobroRef = :Old.Labor;
   End If;         
End;
/