create 
procedure dbo.P_cam_fec_doc_afe
 	 	@tdo_tdo char(3), 	-- Tipo de documento fuente
  		@ndo_doc int,		-- Número de documento fuente
  		@fec_doc datetime	-- Desde que fecha
as
 declare @cop_nom char(1),	-- cliente o proveedor
  		@cod_nom char(12),	-- Codigo del cliente
		@key_pri int,
		@MEN_ERR VARCHAR(256)

 declare movtos cursor for 
 select key_pri from comemvt where dia_dia=@tdo_tdo and num_pol=@ndo_doc

open movtos
--- borramos registro de pagos asignados

fetch next from movtos into @KEY_PRI


while (@@FETCH_STATUS=0) 		-- borra movtos en cotabilidad
	begin
	   delete from comemvt where KEY_PRI=@key_pri
		IF @@ERROR <> 0 
			begin
				set @men_err= 'Error al borrar en comemvt '+
     		    CAST(@key_pri as CHAR(12))
     			raiserror(@men_err,16,1)
     			ROLLBACK TRAN SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
                return
			end 	  
			
			fetch next from movtos into @KEY_PRI
	end
deallocate movtos

delete from comepol where dia_dia=@tdo_tdo and num_pol=@ndo_doc

IF @@ERROR <> 0 
			begin
				set @men_err= 'Error al borrar en comepol '
     			raiserror(@men_err,16,1)
     			ROLLBACK TRAN SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
                return
			end 

update comedoc set sta_doc='A' where tdo_tdo=@tdo_tdo and ndo_doc=@ndo_doc
update comedoc set fec_doc=@fec_doc where tdo_tdo=@tdo_tdo and ndo_doc=@ndo_doc


select * from comeprg where SIS_PRG=14
order by sis_prg,TPR_PRG,NUM_PRG
insert into comeprg (PRG_PRG,ext_prg,des_prg,SIS_PRG,num_prg,par_prg,sis_sis,tpr_prg)
values( 'distribuidoras\dist1315','frm','Genera documentos de a\<juste de cajas por vendedor',14,15,' ',' ','P')

insert into comeprg (PRG_PRG,ext_prg,des_prg,SIS_PRG,num_prg,par_prg,sis_sis,tpr_prg)
values( 'distribuidoras\dist1316','frm','Cambia fecha a documento \<con afectación contable',14,16,' ',' ','P')

update comeprg set par_prg='´RE´' where des_prg='R\<etiros caja chica' and sis_prg=14 and prg_prg='distribuidoras\dist1105'

delete from comekms where fkm_kms>getdate()
select * from comekms where fkm_kms>getdate()
