forward
global type w_mail2_sm from ps_ventana_madre
end type
type pb_1 from uo_pb_orden within w_mail2_sm
end type
type dw_log from uo_dw_log within w_mail2_sm
end type
type cbx_async from uo_cbx within w_mail2_sm
end type
type cbx_html from uo_cbx within w_mail2_sm
end type
type pb_ninguno from uo_pb within w_mail2_sm
end type
type pb_invertir from uo_pb within w_mail2_sm
end type
type pb_todos from uo_pb within w_mail2_sm
end type
type em_periodo from uo_em within w_mail2_sm
end type
type st_descrip from uo_st within w_mail2_sm
end type
type st_porcentaje from uo_st within w_mail2_sm
end type
type hpb_1 from hprogressbar within w_mail2_sm
end type
type st_buscar from uo_st within w_mail2_sm
end type
type st_asunto from uo_st within w_mail2_sm
end type
type pb_seleccionar from uo_pb within w_mail2_sm
end type
type st_adjunto from uo_st within w_mail2_sm
end type
type st_periodo from uo_st within w_mail2_sm
end type
type pb_acumular from uo_pb within w_mail2_sm
end type
type pb_generar from uo_pb within w_mail2_sm
end type
type pb_salir from uo_pb within w_mail2_sm
end type
type pb_reiniciar from uo_pb within w_mail2_sm
end type
type dw_buffer from uo_dw within w_mail2_sm
end type
type mle_cuerpo from uo_mle within w_mail2_sm
end type
type sle_asunto from uo_sle within w_mail2_sm
end type
type st_cantidad from uo_st within w_mail2_sm
end type
type sle_1 from uo_sle within w_mail2_sm
end type
type dw_2 from uo_dw within w_mail2_sm
end type
type dw_1 from uo_dw within w_mail2_sm
end type
type ddlb_tipos from uo_ddlb within w_mail2_sm
end type
type st_tipo from uo_st within w_mail2_sm
end type
type gb_1 from groupbox within w_mail2_sm
end type
end forward

global type w_mail2_sm from ps_ventana_madre
boolean visible = true
integer width = 4535
integer height = 1684
string title = "Envío de mails"
boolean minbox = false
boolean maxbox = false
boolean resizable = false
windowtype windowtype = response!
string icon = "DosEdit5!"
boolean center = true
pb_1 pb_1
dw_log dw_log
cbx_async cbx_async
cbx_html cbx_html
pb_ninguno pb_ninguno
pb_invertir pb_invertir
pb_todos pb_todos
em_periodo em_periodo
st_descrip st_descrip
st_porcentaje st_porcentaje
hpb_1 hpb_1
st_buscar st_buscar
st_asunto st_asunto
pb_seleccionar pb_seleccionar
st_adjunto st_adjunto
st_periodo st_periodo
pb_acumular pb_acumular
pb_generar pb_generar
pb_salir pb_salir
pb_reiniciar pb_reiniciar
dw_buffer dw_buffer
mle_cuerpo mle_cuerpo
sle_asunto sle_asunto
st_cantidad st_cantidad
sle_1 sle_1
dw_2 dw_2
dw_1 dw_1
ddlb_tipos ddlb_tipos
st_tipo st_tipo
gb_1 gb_1
end type
global w_mail2_sm w_mail2_sm

type variables
boolean enviando,gb_salir
boolean ib_confirmacion, ib_error_adjunto, ib_autenticar
boolean ib_async
String is_nombre,is_email,is_pass, is_errmsj
String is_server,is_user_login, is_criterio, is_texto_firma
Integer ii_puerto
long ll_cod_firma_html
string is_email_confirmar,is_email_firma,is_eshtml

string ls_adjuntarArchivos
end variables

forward prototypes
public subroutine f_limpiar_campos ()
public function boolean f_adjuntar_archivos (string dni)
public subroutine agregar_a_buffer ()
public function boolean f_procesar ()
public function boolean f_email_valido (string ps_email)
public function string f_gen_factura (string dni)
public subroutine f_log_dw_and_file (string mensaje)
public subroutine f_set_reset ()
end prototypes

public subroutine f_limpiar_campos ();int xx
//Cfalico 10/08/2017 Limpio los campos
for xx=1 to dw_1.rowcount( )		
	dw_1.object.acumulada[xx] = 'N'
	dw_1.object.seleccion[xx] = 'N'						
next	
dw_buffer.reset( )
dw_1.setredraw(true)
end subroutine

public function boolean f_adjuntar_archivos (string dni);//dni=String(dw_buffer.object.dni[xx])
long cod
String tipo
int mes,año
String formato_preimpreso
mes =Integer(Mid(em_periodo.text,0,2))
año =Integer(Mid(em_periodo.text,4,em_periodo.linelength( )))
ib_error_adjunto=false
tipo=ddlb_tipos.text
if tipo <> "" then
choose case tipo
	case 'Factura'		
		//FOrtiz - 26/08/2021: INC9601 - No siempre el codigo de la entidad es el DNI
		//select top 1 cod_cab into :cod from t_sgp_facturacion_periodos where cod_entidad=:dni and (MONTH(fec_periodo))=:mes  and (YEAR(fec_periodo))=:año;
		select top 1 cod_cab into :cod from t_sgp_facturacion_periodos 
		join t_ent_datos on t_sgp_facturacion_periodos.cod_entidad = t_ent_datos.cod
		where /*cod_entidad=:dni */ t_ent_datos.nro_documento = :dni and (MONTH(fec_periodo))=:mes  and (YEAR(fec_periodo))=:año;

		if cod >0 then			
			select form.datawindow into :formato_preimpreso from t_com_cab com join t_com_centros_emision em on em.cod_tip_comprobante = com.cod_tip_comprobante
			and em.centro_emision = com.centro_emision
			join t_tip_formatos_preimpresos form on form.cod = em.cod_formato_preimpreso
			where com.cod = :cod;
			
			dw_2.dataobject=formato_preimpreso
			dw_2.settransobject( sqlca)
			dw_2.retrieve(cod,0,0)
			string ls_ruta	
			ls_ruta=gs_tempdir+"FACTURA"+String(dni)+".pdf"
			
			dw_2.Modify ("DataWindow.Export.PDF.Method = NativePDF!")
			dw_2.Modify ("DataWindow.Export.PDF.NativePDF.CustomOrientation = 0")
			dw_2.Modify ("DataWindow.Export.PDF.NativePDF.CustomSize = 0")
			
			dw_2.saveas(ls_ruta,PDF!,false )
			Yield()
			String ls_filename
			ls_filename = ls_ruta
			guo_smtp.f_set_mime_adjuntos( ls_filename)
			ib_error_adjunto=true
		else
			ib_error_adjunto=false
		end if
	case 'Reporte'
		//reporte
		case 'Otro'
			//otro
	end choose
end if
return ib_error_adjunto
end function

public subroutine agregar_a_buffer ();Boolean lb_Agregar, lb_mostrar_mj	/*ATozzi - 17/09/2019 - inc8534: se agrego la variable lb_mostrar_mj*/
Long xx, yy, ll_row
String ls_msj, ls_sql, ls_msj_final		/*ATozzi - 17/09/2019 - inc8534: se añadieron las siguientes variables ls_sql y ls_msj_final*/
//ls_msj="Los siguientes afiliados no se añadirán ya que no poseen cuenta de email: "+crlf	/*ATozzi - 17/09/2019 - inc8534*/

ls_msj = "("	/*ATozzi - 17/09/2019 - inc8534*/
lb_mostrar_mj = false	/*ATozzi - 17/09/2019 - inc8534*/

for xx = 1 to dw_1.rowcount() 
	if dw_1.object.seleccion[xx] = 'S' then
		lb_Agregar = True
		for yy = 1 to dw_buffer.RowCount()
			if dw_buffer.object.dni[yy] = dw_1.object.nro_documento[xx] then
				lb_Agregar = False
				exit
			end if
		next
		if lb_Agregar then			
			if /*not isnull(dw_1.object.e_mail[xx]) or  dw_1.object.e_mail[xx]<>"" or*/ f_email_valido(dw_1.object.e_mail[xx]) then	/*ATozzi - 16/092019 - inc8534: Se añadio f_email_valido(dw_1.object.e_mail[xx])*/
			ll_row = dw_buffer.insertrow(0)
			dw_buffer.object.dni[ll_row] = dw_1.object.nro_documento[xx]
			dw_buffer.object.titular[ll_row] = dw_1.object.nombre[xx]
			dw_buffer.object.email[ll_row] = dw_1.object.e_mail[xx]	
			dw_1.object.acumulada[xx] = 'S'
		else		
			/*ATozzi - 17/09/2019 - inc8534: Se van cargando los DNI de los afiliados en una cadena para despues mandarla a la restriccion de la consulta sql*/	
			ls_msj = ls_msj+"'"+String(dw_1.object.nro_documento[xx])+"'"+","	
			lb_mostrar_mj = true	/*ATozzi - 17/09/2019 - inc8534*/
			//ls_msj= ls_msj+String(dw_1.object.nombre[xx])+crlf	/*ATozzi - 17/09/2019 - inc8534: se comento esta parte*/
			dw_1.object.seleccion[xx]='N'			
		end if
		end if
		/* MLambert (31/05/2017) INC */
		//dw_1.object.seleccion[xx] = 'N'
		//dw_1.object.acumulada[xx] = 'S'
	end if
next
/*ATozzi - 17/09/2019 - inc8534: consulta para traer los datos del afiliado-----------------------------------------------------*/	
ls_msj_final = left(ls_msj, len(ls_msj)-1)
ls_msj_final = ls_msj_final + ")"

ls_sql = &
"	select"+& 
"		p.nro_documento,"+&
"		p.nombre,"+&
"		p.fec_alta,"+&
"		p.e_mail"+&
"	from"+&
"		t_ent_datos p"+& 
"	where"+& 
"		isnull(p.esta_deshabilitado,'N')='N'"+&
"		and p.nro_documento in "+ls_msj_final		

if lb_mostrar_mj then
	uo_fg.f_manejador_de_errores( "Los siguientes afiliados no se añadirán ya que poseen error en su cuenta de email", ls_sql, {"Nro Doc","Nombre","Fecha Alta","Email"},{300,1000,300,800})
end if
/*-------------------------------------------------------------------------------------------*/

/*ATozzi - 17/09/2019 - inc8534: se comento esta parte*/	
/*
if ls_msj <>"Los siguientes afiliados no se añadirán ya que no poseen cuenta de email: " +crlf then
	uo_fg.msg_advertencia( ls_msj)
end if
*/

end subroutine

public function boolean f_procesar ();int xx,opc
long cod
string dni,ls_aux
int cant,c,li_resp
String ps_mensaje, ls_cuerpo_mensaje, ls_resp,ls_err
Int cod_imagen
long ll_handle
cant=dw_buffer.rowcount()
c=0 




boolean lb_html, ib_imagen_firma, ib_data_loaded=false
string ls_SignFile="",ls_fact_Gen
//uo_cpp_smtp iuo_envio_msj



// si no hay nada en dw_buffer, salgo
if dw_buffer.rowcount() < 1  then
	uo_fg.minimensaje( "Nada para procesar.")
	guo_smtp.f_objeto_cerrar( )
	return false
end if  

//preparando
hpb_1.position = 0 
hpb_1.setrange(0, dw_buffer.rowcount( )  ) 
int porcentaje
st_porcentaje.text='0%'
hpb_1.visible=true
gb_salir=false
pb_salir.text='Cancelar'
st_descrip.text="Procesando la informacion..."

if em_periodo.text='' and ddlb_tipos.text<>'Ninguno' then
	uo_fg.msg_advertencia('Debe seleccionar un periodo')
	pb_generar.enabled = true
	guo_smtp.f_objeto_cerrar( )
	return false
end if

// procesamos	 
enviando=true

pb_generar.enabled = false

// tomo check html
lb_html = cbx_html.checked

//if lb_html and not isnull(ll_cod_firma_html) then
//	ls_SignFile=uo_fg.f_mail_create_file(ll_cod_firma_html,"IMG")
//end if 

guo_smtp.f_objeto_abrir( )
guo_smtp.f_set_default( 0)

//Obtener datos remitente
guo_smtp.f_set_sgap_sender( )

/* set de variables */
guo_smtp.f_set_mime_asunto( sle_asunto.text )
guo_smtp.f_set_mime_body( mle_cuerpo.text)
guo_smtp.f_set_eshtml( cbx_html.checked )



if not ib_async then 

	//************************************************************************
	//                        envío síncrono
	//************************************************************************
	//bucle
	for xx=dw_buffer.rowcount( ) to 1 step -1
	if gb_salir = false then
		//Yield()
		if ddlb_tipos.text<>'Ninguno' then
			// *** add any attachments **********************		
			st_descrip.text="Generando archivos..."				
			dni=String(dw_buffer.object.dni[xx])
			
			//genera factura 
			ls_fact_Gen = this.f_gen_factura( dni)
			if ls_fact_Gen = "" then
				opc = MessageBox('Error','No se pudo generar el archivo deseado para '+String(dw_buffer.object.titular[xx])+'. Desea mandar el mail igualmente?',Exclamation!,YesNo!,1)	
				if opc=2 then continue
			end if
			hpb_1.position = hpb_1.position + 1
		 end if	
	
		// *** send the message *************************
		st_descrip.text="Enviando a "+String(dw_buffer.object.email[xx])
		
		// set de destinatario [recipient ]
		guo_smtp.f_set_mime_reset( 1) 
		guo_smtp.f_set_mime_reset_var( 1)
		//set
		guo_smtp.f_set_mime_dest(dw_buffer.object.email[xx],dw_buffer.object.titular[xx])
		
		//set de adjuntos
		if len(ls_fact_Gen) <> 0 then 
			//limpiar adjuntos 
			guo_smtp.f_set_mime_adjunto_limpiar( )
			guo_smtp.f_set_mime_reset( 4)        
			//set adjunto
			guo_smtp.f_set_mime_adjuntos(ls_fact_Gen)
		end if 
		
		//set de contenido de variable en objeto
		if NOT guo_smtp.f_pre_send_settings(ls_err) then
			uo_fg.msg_advertencia(ls_err)
			hpb_1.position=0
			st_porcentaje.text=''
			st_descrip.text=''
			pb_generar.enabled = true
			guo_smtp.f_objeto_cerrar( )
			return false
		end if 
				
 		
		
		//                                       restablecer valores en bucles 		
		//datos de conexión no debe recargarse 
		guo_smtp.f_set_data_conect( false) 
		
		// Asunto y body es el mismo,  no debe recargarse
		guo_smtp.f_set_data_body( false) 
		
		//limpiar varaibles
		guo_smtp.f_set_mime_adjunto_limpiar( )
		guo_smtp.f_set_mime_reset_var( 1)
		
		//                                          enviar correo
		li_resp = guo_smtp.f_send( )
		
		if  li_resp <> 1  then
			ls_resp = guo_smtp.f_get_error_message( li_resp)
			uo_fg.msg_advertencia(ls_resp)
			hpb_1.position=0
			st_porcentaje.text=''
			st_descrip.text=''
			exit
		end if
		//Yield()
		c++
		porcentaje= (c*100) /cant
		st_porcentaje.text=String(porcentaje)+"%"
		dw_buffer.deleterow(xx)
	else	
		uo_fg.msg_advertencia("Cancelado por el usuario")
		hpb_1.position=0
		st_porcentaje.text=''
		st_descrip.text=''
		exit
	end if		
	//Yield()
	next
else 
	//************************************************************************
	//  										Envío asincrónico 
	
	
	// boton para ver resultado  OnSendFinished()  event 
	pb_1.enabled=true
	pb_1.visible =true
	
	
	dw_log.visible= true
	dw_log.iniciar_proceso( "Iniciando Envíos")
	ls_aux = string(now())
	f_log_dw_and_file( 'Inicio envío  asíncrono facturación afiliados. '+ls_aux)
	/****************/
	//bucle
	for xx=dw_buffer.rowcount( ) to 1 step -1
	if gb_salir = false then
		//Yield()
		if ddlb_tipos.text<>'Ninguno' then
			// *** add any attachments **********************		
			ls_fact_Gen=""
			f_log_dw_and_file( "Generando factura a "+dw_buffer.object.titular[xx])
			st_descrip.text="Generando archivos..."				
			dni=String(dw_buffer.object.dni[xx])
			ls_fact_Gen = this.f_gen_factura( dni)
			
			if ls_fact_Gen = "" then
				f_log_dw_and_file('---------------------No se pudo generar la factura-----------------------')	

			else
				f_log_dw_and_file('generado ok')	
			end if
			hpb_1.position = hpb_1.position + 1
		 end if	
	
		// *** send the message *************************
		st_descrip.text="Enviando a "+String(dw_buffer.object.email[xx])
		f_log_dw_and_file(st_descrip.text)
		
		// set de destinatario [recipient ]
		guo_smtp.f_set_mime_reset( 1) 
		//set
		guo_smtp.f_set_mime_dest(dw_buffer.object.email[xx],dw_buffer.object.titular[xx])
		
		//set de adjuntos
		if len(ls_fact_Gen) <> 0 then 
			//limpiar adjuntos 
			guo_smtp.f_set_mime_adjunto_limpiar( )
			guo_smtp.f_set_mime_reset( 4)        
			//set adjunto
			guo_smtp.f_set_mime_adjuntos(ls_fact_Gen)
			f_log_dw_and_file("adjunto:"+ls_fact_gen)
		end if 
		
		//Presend
		if NOT guo_smtp.f_pre_send_settings(ls_err) then
			f_log_dw_and_file("Destinatario:"+dw_buffer.object.email[xx]+"-->"+ ls_err)
			hpb_1.position=0
			st_porcentaje.text=''
			st_descrip.text=''
			guo_smtp.f_objeto_cerrar( )
			return false
		end if 
		
		//enviar correo
		
		ll_handle = guo_smtp.f_send_async( )
		f_log_dw_and_file("handle asignado: "+string(ll_handle))
		guo_smtp.f_async_lis_push( ll_handle)

		//                                       restablecer valores en bucles 		
		//datos de conexión no debe recargarse 
		guo_smtp.f_set_data_conect( false) 
		
		// Asunto y body es el mismo,  no debe recargarse
		guo_smtp.f_set_data_body( false) 
		
		//limpiar var
		guo_smtp.f_set_mime_reset( 1)  //destinatarios
		guo_smtp.f_set_mime_reset( 4)  //adjuntos
		guo_smtp.f_set_mime_reset_var( 0)  //variables dest, adjuntos
		

		//Yield()
		c++
		porcentaje= (c*100) /cant
		st_porcentaje.text=String(porcentaje)+"%"
		dw_buffer.deleterow(xx)
	else	
		uo_fg.msg_advertencia("Cancelado por el usuario")
		hpb_1.position=0
		st_porcentaje.text=''
		st_descrip.text=''
		exit
	end if		
	//Yield()
	next
	
	/****************/
end if 
if not ib_async then
	f_limpiar_campos()
	st_descrip.text="Terminado"
	st_porcentaje.text=""
	hpb_1.position=0
	pb_salir.text='Salir'
	
	//cerramos objeto si no es async
	 guo_smtp.f_objeto_cerrar( )
END IF 

pb_generar.enabled = true
return true




end function

public function boolean f_email_valido (string ps_email);string ls_errmsj

if not guo_smtp.f_validar_email( ps_email, ls_errmsj) then
	uo_fg.log( "Fact masiva"+ps_email+"-->"+ls_errmsj)
	return false
end if 
return true

end function

public function string f_gen_factura (string dni);long cod
String tipo
int mes,año
String formato_preimpreso
mes =Integer(Mid(em_periodo.text,0,2))
año =Integer(Mid(em_periodo.text,4,em_periodo.linelength( )))
ib_error_adjunto=false
tipo=ddlb_tipos.text
if tipo <> "" then
choose case tipo
	case 'Factura'		
		//FOrtiz - 26/08/2021: INC9601 - No siempre el codigo de la entidad es el DNI
		//select top 1 cod_cab into :cod from t_sgp_facturacion_periodos where cod_entidad=:dni and (MONTH(fec_periodo))=:mes  and (YEAR(fec_periodo))=:año;
		select top 1 cod_cab into :cod from t_sgp_facturacion_periodos 
		join t_ent_datos on t_sgp_facturacion_periodos.cod_entidad = t_ent_datos.cod
		where /*cod_entidad=:dni */ t_ent_datos.nro_documento = :dni and (MONTH(fec_periodo))=:mes  and (YEAR(fec_periodo))=:año;

		if cod >0 then			
			select form.datawindow into :formato_preimpreso from t_com_cab com join t_com_centros_emision em on em.cod_tip_comprobante = com.cod_tip_comprobante
			and em.centro_emision = com.centro_emision
			join t_tip_formatos_preimpresos form on form.cod = em.cod_formato_preimpreso
			where com.cod = :cod;
			
			dw_2.dataobject=formato_preimpreso
			dw_2.settransobject( sqlca)
			dw_2.retrieve(cod,1,0)
			string ls_ruta	
			ls_ruta=gs_tempdir+"FAC_"+string(mes)+"_"+string(año)+"_"+String(dni)+".pdf"
			
			dw_2.Modify ("DataWindow.Export.PDF.Method = NativePDF!")
			dw_2.Modify ("DataWindow.Export.PDF.NativePDF.CustomOrientation = 0")
			dw_2.Modify ("DataWindow.Export.PDF.NativePDF.CustomSize = 0")
			
			dw_2.saveas(ls_ruta,PDF!,false )
			//Yield()
		else
			ls_ruta = ""
		end if
	case 'Reporte'
		//reporte
		case 'Otro'
			//otro
	end choose
end if

return ls_ruta
end function

public subroutine f_log_dw_and_file (string mensaje);dw_log.mensaje( mensaje)
guo_smtp.log( mensaje)
end subroutine

public subroutine f_set_reset ();cbx_async.checked = false
pb_1.visible = false
pb_generar.text='Listo'
pb_salir.text='Salir'
//dw_buffer.enabled=false
dw_buffer.Modify("Datawindow.color='16777215'")
pb_reiniciar.visible=true


pb_seleccionar.visible=true
pb_todos.visible=true
pb_ninguno.visible=true
pb_invertir.visible=true

pb_acumular.visible=true
dw_1.visible=true
st_asunto.visible=false
sle_asunto.visible=false
mle_cuerpo.visible=false
st_adjunto.visible=false
st_periodo.visible=false
st_tipo.visible=false
em_periodo.visible=false
ddlb_tipos.visible=false

sle_asunto.text=''
mle_cuerpo.text=''
sle_1.text =""
ddlb_tipos.selectitem(1)
sle_1.visible=true
st_buscar.visible = true
em_periodo.text=''
end subroutine

on w_mail2_sm.create
int iCurrent
call super::create
this.pb_1=create pb_1
this.dw_log=create dw_log
this.cbx_async=create cbx_async
this.cbx_html=create cbx_html
this.pb_ninguno=create pb_ninguno
this.pb_invertir=create pb_invertir
this.pb_todos=create pb_todos
this.em_periodo=create em_periodo
this.st_descrip=create st_descrip
this.st_porcentaje=create st_porcentaje
this.hpb_1=create hpb_1
this.st_buscar=create st_buscar
this.st_asunto=create st_asunto
this.pb_seleccionar=create pb_seleccionar
this.st_adjunto=create st_adjunto
this.st_periodo=create st_periodo
this.pb_acumular=create pb_acumular
this.pb_generar=create pb_generar
this.pb_salir=create pb_salir
this.pb_reiniciar=create pb_reiniciar
this.dw_buffer=create dw_buffer
this.mle_cuerpo=create mle_cuerpo
this.sle_asunto=create sle_asunto
this.st_cantidad=create st_cantidad
this.sle_1=create sle_1
this.dw_2=create dw_2
this.dw_1=create dw_1
this.ddlb_tipos=create ddlb_tipos
this.st_tipo=create st_tipo
this.gb_1=create gb_1
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.pb_1
this.Control[iCurrent+2]=this.dw_log
this.Control[iCurrent+3]=this.cbx_async
this.Control[iCurrent+4]=this.cbx_html
this.Control[iCurrent+5]=this.pb_ninguno
this.Control[iCurrent+6]=this.pb_invertir
this.Control[iCurrent+7]=this.pb_todos
this.Control[iCurrent+8]=this.em_periodo
this.Control[iCurrent+9]=this.st_descrip
this.Control[iCurrent+10]=this.st_porcentaje
this.Control[iCurrent+11]=this.hpb_1
this.Control[iCurrent+12]=this.st_buscar
this.Control[iCurrent+13]=this.st_asunto
this.Control[iCurrent+14]=this.pb_seleccionar
this.Control[iCurrent+15]=this.st_adjunto
this.Control[iCurrent+16]=this.st_periodo
this.Control[iCurrent+17]=this.pb_acumular
this.Control[iCurrent+18]=this.pb_generar
this.Control[iCurrent+19]=this.pb_salir
this.Control[iCurrent+20]=this.pb_reiniciar
this.Control[iCurrent+21]=this.dw_buffer
this.Control[iCurrent+22]=this.mle_cuerpo
this.Control[iCurrent+23]=this.sle_asunto
this.Control[iCurrent+24]=this.st_cantidad
this.Control[iCurrent+25]=this.sle_1
this.Control[iCurrent+26]=this.dw_2
this.Control[iCurrent+27]=this.dw_1
this.Control[iCurrent+28]=this.ddlb_tipos
this.Control[iCurrent+29]=this.st_tipo
this.Control[iCurrent+30]=this.gb_1
end on

on w_mail2_sm.destroy
call super::destroy
destroy(this.pb_1)
destroy(this.dw_log)
destroy(this.cbx_async)
destroy(this.cbx_html)
destroy(this.pb_ninguno)
destroy(this.pb_invertir)
destroy(this.pb_todos)
destroy(this.em_periodo)
destroy(this.st_descrip)
destroy(this.st_porcentaje)
destroy(this.hpb_1)
destroy(this.st_buscar)
destroy(this.st_asunto)
destroy(this.pb_seleccionar)
destroy(this.st_adjunto)
destroy(this.st_periodo)
destroy(this.pb_acumular)
destroy(this.pb_generar)
destroy(this.pb_salir)
destroy(this.pb_reiniciar)
destroy(this.dw_buffer)
destroy(this.mle_cuerpo)
destroy(this.sle_asunto)
destroy(this.st_cantidad)
destroy(this.sle_1)
destroy(this.dw_2)
destroy(this.dw_1)
destroy(this.ddlb_tipos)
destroy(this.st_tipo)
destroy(this.gb_1)
end on

event open;call super::open;is_criterio = Message.stringparm

dw_1.settransobject( sqlca)

st_porcentaje.x=(hpb_1.width/2)
st_descrip.x=(hpb_1.width/2)+st_porcentaje.width
enviando=false

dw_1.visible=true
st_asunto.visible=false
sle_asunto.visible=false
mle_cuerpo.visible=false
st_adjunto.visible=false
st_periodo.visible=false
st_tipo.visible=false
em_periodo.visible=false
ddlb_tipos.visible=false
	
if trim(is_criterio)<>'' and not isnull(is_criterio) then
		dw_1.agregar_criterio(is_criterio, true)
else
	close(this)
end if
end event

type pb_1 from uo_pb_orden within w_mail2_sm
integer x = 1979
integer y = 1308
integer width = 183
integer height = 160
integer taborder = 200
boolean enabled = false
boolean originalsize = false
end type

event clicked;call super::clicked;long hand
string ls_aux2
integer err
string errTXT

dw_log.visible = true

//ls_aux2 = guo_smtp.f_async_get_handle( )
//
//dw_log.mensaje("handles generados: "+ ls_aux2)
//
//do while  ls_aux2<> ""
//	hand = long(uo_fg.f_string_pop( ls_aux2, ";"))
//	guo_smtp.event onsendfinished( hand, err, errTXT)
//	dw_log.mensaje("handle:"+string(hand)+ "error:"+string(err)+ "  mensaje: "+errtxt)
//	
//loop

// 
f_log_dw_and_file("Mostrando resultados envio asíncrono:")
ls_aux2= guo_smtp.f_get_async_result( )             // --->>>    shows values is_asyncNook and is_asyncok
f_log_dw_and_file(ls_aux2)

if uo_fg.msg_pregunta_cancelar( "desea cerrar proceso ? ", 2)="SI" then
	dw_log.finalizar_proceso( "Finalizando envío de facturación")
	dw_log.visible= false
	f_limpiar_campos()
	st_descrip.text="Terminado"
	st_porcentaje.text=""
	hpb_1.position=0
	pb_salir.text='Salir'
	
	f_set_reset()
	//cerramos objeto si no es async
	 guo_smtp.f_objeto_cerrar( )
end if 
	
end event

type dw_log from uo_dw_log within w_mail2_sm
boolean visible = false
integer x = 27
integer y = 12
integer width = 3031
integer height = 1284
integer taborder = 80
boolean hscrollbar = false
end type

type cbx_async from uo_cbx within w_mail2_sm
integer x = 2464
integer y = 1116
integer width = 535
string text = "Envíos Asíncronos"
end type

event clicked;call super::clicked;if cbx_async.checked then
	ib_async = true
else
	ib_async = false
end if

end event

type cbx_html from uo_cbx within w_mail2_sm
integer x = 1993
integer y = 1116
string text = "HTML"
end type

type pb_ninguno from uo_pb within w_mail2_sm
integer x = 658
integer y = 1312
integer width = 128
integer height = 112
integer taborder = 190
boolean originalsize = false
string picturename = "C:\SISTEMAS\Grf\Botones\Ninguno01.bmp"
end type

event clicked;call super::clicked;Long xx
for xx = 1 to dw_1.RowCount()
	dw_1.object.seleccion[xx] = 'N'
next

dw_1.setredraw( true)
end event

type pb_invertir from uo_pb within w_mail2_sm
integer x = 530
integer y = 1312
integer width = 128
integer height = 112
integer taborder = 190
boolean originalsize = false
string picturename = "C:\SISTEMAS\Grf\Botones\Invertir01.bmp"
end type

event clicked;call super::clicked;
Long xx
for xx = 1 to dw_1.RowCount()
	if dw_1.object.seleccion[xx] = 'S' then 
		dw_1.object.seleccion[xx] = 'N'
	else
		dw_1.object.seleccion[xx] = 'S'
	end if
next

dw_1.setredraw( true)
dw_1.setredraw( true)
end event

type pb_todos from uo_pb within w_mail2_sm
integer x = 402
integer y = 1312
integer width = 128
integer height = 112
integer taborder = 190
boolean originalsize = false
string picturename = "C:\SISTEMAS\Grf\Botones\Todos01.bmp"
end type

event clicked;call super::clicked;Long xx

for xx = 1 to dw_1.RowCount()
	dw_1.object.seleccion[xx] = 'S'
next

dw_1.setredraw( true)
end event

type em_periodo from uo_em within w_mail2_sm
integer x = 1047
integer y = 1164
integer width = 247
integer taborder = 100
maskdatatype maskdatatype = datemask!
string mask = "MM/yyyy"
end type

type st_descrip from uo_st within w_mail2_sm
integer x = 558
integer y = 1440
integer width = 3013
integer height = 60
integer textsize = -9
long backcolor = 553648127
string text = ""
end type

type st_porcentaje from uo_st within w_mail2_sm
integer x = 1335
integer y = 1444
integer width = 155
integer height = 60
integer textsize = -9
long backcolor = 553648127
string text = ""
end type

type hpb_1 from hprogressbar within w_mail2_sm
integer x = 37
integer y = 1520
integer width = 4416
integer height = 52
unsignedinteger maxposition = 100
boolean smoothscroll = true
end type

type st_buscar from uo_st within w_mail2_sm
integer x = 69
integer y = 48
integer width = 242
integer height = 84
string text = "Afiliado"
end type

type st_asunto from uo_st within w_mail2_sm
integer x = 82
integer y = 144
integer width = 283
integer height = 64
string facename = "Tahoma"
long backcolor = 553648127
string text = "Asunto"
end type

type pb_seleccionar from uo_pb within w_mail2_sm
integer x = 27
integer y = 1312
integer width = 375
integer height = 112
integer taborder = 180
integer textsize = -8
integer weight = 400
string facename = "Arial"
string text = "Seleccionar"
string picturename = "C:\SISTEMAS\Grf\Botones\Buscar00.bmp"
string disabledname = "C:\SISTEMAS\Grf\Botones\Buscar00d.bmp"
alignment htextalign = left!
end type

event clicked;dw_1.busquedas(Parent.Title, is_criterio)

sle_1.text=""
if dw_1.rowcount( ) >0 then
	st_cantidad.Text="Cantidad de resultados: "+String(dw_1.rowcount( ))
else
	st_cantidad.Text="No se encontraron resultados"
end if
end event

type st_adjunto from uo_st within w_mail2_sm
integer x = 357
integer y = 1080
integer width = 402
integer height = 64
string facename = "Tahoma"
long backcolor = 553648127
string text = "Adjuntar"
end type

type st_periodo from uo_st within w_mail2_sm
integer x = 823
integer y = 1172
integer width = 265
integer height = 64
string facename = "Tahoma"
long backcolor = 553648127
string text = "Periodo"
end type

type pb_acumular from uo_pb within w_mail2_sm
integer x = 1166
integer y = 1312
integer width = 375
integer height = 112
integer taborder = 140
integer textsize = -8
integer weight = 400
string facename = "Arial"
string text = "Acumular"
boolean originalsize = false
string picturename = "C:\SISTEMAS\Grf\Botones\siguiente00.bmp"
string disabledname = "C:\SISTEMAS\Grf\Botones\siguiente00d.bmp"
alignment htextalign = left!
end type

event clicked;agregar_a_buffer()
dw_1.setredraw(true)

end event

type pb_generar from uo_pb within w_mail2_sm
integer x = 1541
integer y = 1312
integer width = 375
integer height = 112
integer taborder = 150
integer textsize = -9
integer weight = 400
fontcharset fontcharset = defaultcharset!
string facename = "Arial"
string pointer = "Arrow!"
string text = "Listo"
boolean originalsize = false
string picturename = "C:\SISTEMAS\Grf\Botones\Aceptar00.bmp"
string disabledname = "C:\SISTEMAS\Grf\Botones\Aceptar00_D.bmp"
alignment htextalign = left!
end type

event clicked;if pb_generar.text = 'Listo' then
	if dw_buffer.rowcount() > 0 then
		pb_generar.text='Enviar'
		pb_salir.text='Cancelar'
		dw_buffer.enabled=false
		dw_buffer.Modify("DataWindow.color='12632256'")
		
		pb_reiniciar.visible=false		
		
		pb_seleccionar.visible=false
		pb_todos.visible=false
		pb_ninguno.visible=false
		pb_invertir.visible=false		
		pb_acumular.visible=false
		
		st_cantidad.text=""	
		dw_1.visible=false
		st_asunto.visible=true
		sle_asunto.visible=true
		mle_cuerpo.visible=true
		st_adjunto.visible=true
		
		st_tipo.visible=true

		ddlb_tipos.visible=true
		
		ddlb_tipos.selectitem( 1)
		em_periodo.visible=false
		st_periodo.visible=false
		
		sle_1.visible=false
		st_buscar.visible = false
		
	end if
else
	String ls_msj
	ls_msj="Debe completar los siguientes campos: "+CRLF	
	if sle_asunto.text ="" then
		ls_msj+= "•Asunto"
	end if	
	
	if ls_msj <>"Debe completar los siguientes campos: "+CRLF then
			uo_fg.msg_advertencia( ls_msj)
		return
	end if	
	enviando=false
	if f_procesar()	=true then
		
		uo_fg.minimensaje("Correos enviados con éxito")
		
		
		if not cbx_async.checked then f_set_reset()
		if cbx_async.checked then pb_generar.enabled = false
		
	end if
end if
setredraw( true)
end event

type pb_salir from uo_pb within w_mail2_sm
integer x = 2715
integer y = 1312
integer width = 375
integer height = 112
integer taborder = 160
integer textsize = -9
integer weight = 400
fontcharset fontcharset = defaultcharset!
string facename = "Arial"
string pointer = "Arrow!"
string text = "Salir"
boolean originalsize = false
string picturename = "C:\SISTEMAS\Grf\Botones\Salir00.bmp"
alignment htextalign = left!
end type

event clicked;if pb_salir.text= 'Cancelar' then
	if enviando = false then
		pb_generar.text='Listo'
		pb_salir.text= 'Salir'
		pb_reiniciar.enabled=true
		dw_buffer.enabled=true
		dw_buffer.Modify("DataWindow.color='16777215'")
		pb_reiniciar.visible=true
		
	
		pb_seleccionar.visible=true
		pb_todos.visible=true
		pb_ninguno.visible=true
		pb_invertir.visible=true
		
		pb_acumular.visible=true
		dw_1.visible=true
		st_asunto.visible=false
		sle_asunto.visible=false
		mle_cuerpo.visible=false
		sle_1.visible=true
		st_buscar.visible = true
	else
		gb_salir=true
		pb_salir.text= 'Salir'
		setredraw( true)
	end if
else

	Close(Parent)
end if

end event

type pb_reiniciar from uo_pb within w_mail2_sm
integer x = 4114
integer y = 1312
integer width = 375
integer height = 112
integer taborder = 90
integer textsize = -8
integer weight = 400
fontcharset fontcharset = defaultcharset!
string facename = "Arial"
string text = "Reiniciar"
boolean originalsize = false
string picturename = "C:\SISTEMAS\Grf\Botones\Reiniciar.bmp"
alignment htextalign = left!
end type

event clicked;f_limpiar_campos()
end event

type dw_buffer from uo_dw within w_mail2_sm
integer x = 3113
integer y = 260
integer width = 1367
integer height = 1032
integer taborder = 50
string dataobject = "dw_email_buffer"
boolean border = false
borderstyle borderstyle = stylebox!
end type

event buttonclicked;long ll_row

ll_row = dw_1.find("nro_documento = "+string(this.object.dni[row]), 1, dw_1.rowcount())

if ll_row>0 then
	dw_1.object.acumulada[ll_row] = 'N'
	dw_1.object.seleccion[ll_row] = 'N'
end if

DeleteRow(Row)
dw_1.setredraw(true)
end event

type mle_cuerpo from uo_mle within w_mail2_sm
integer x = 78
integer y = 344
integer width = 2752
integer height = 720
integer taborder = 70
integer textsize = -11
string facename = "Tahoma"
boolean vscrollbar = true
end type

type sle_asunto from uo_sle within w_mail2_sm
integer x = 78
integer y = 216
integer width = 1605
integer height = 112
integer taborder = 30
integer textsize = -11
string facename = "Tahoma"
end type

type st_cantidad from uo_st within w_mail2_sm
integer x = 78
integer y = 152
integer width = 841
integer textsize = -9
string facename = "Tahoma"
string text = ""
end type

type sle_1 from uo_sle within w_mail2_sm
integer x = 325
integer y = 32
integer width = 1390
integer height = 100
textcase textcase = upper!
end type

event modified;long ll_dni,ll_nro 
string ls_email, ls_nombre
ll_dni = Long(sle_1.Text)

select t.nro_documento into :ll_nro from t_ent_datos t where t.nro_documento=:ll_dni;

if ll_nro <>0 then	
	dw_1.setfilter("nro_documento = "+String(ll_nro))	
else
	ls_nombre = sle_1.Text
	if ls_nombre <>'' then
		dw_1.setfilter("nombre like '%"+ls_nombre+"%'")
	else
		dw_1.setfilter("")
	end if
end if

dw_1.filter()
dw_1.retrieve( )
if dw_1.rowcount( ) >0 then
	st_cantidad.Text="Cantidad de resultados: "+String(dw_1.rowcount( ))
else
	st_cantidad.Text="No se encontraron resultados"
end if
end event

type dw_2 from uo_dw within w_mail2_sm
boolean visible = false
integer x = 2674
integer y = 1020
integer width = 613
integer height = 388
integer taborder = 190
boolean bringtotop = true
string title = "none"
string dataobject = "dw_imp_com_cab_concordia_ws"
string icon = "AppIcon!"
end type

type dw_1 from uo_dw within w_mail2_sm
boolean visible = false
integer x = 37
integer y = 260
integer width = 3067
integer height = 1032
integer taborder = 40
boolean bringtotop = true
string dataobject = "dw_titular_mail"
boolean border = false
borderstyle borderstyle = stylebox!
boolean ib_quick_sort = true
end type

event clicked;IF row > 0 THEN 
this.SelectRow(0, FALSE) 
this.SelectRow(row, TRUE) 


END IF


end event

event doubleclicked;IF row > 0 THEN 
if this.object.seleccion[row]='N' then
	this.object.seleccion[row]='S'
else
	this.object.seleccion[row]='N'
end if
END IF

end event

type ddlb_tipos from uo_ddlb within w_mail2_sm
integer x = 233
integer y = 1172
integer width = 530
integer taborder = 80
boolean sorted = false
string item[] = {"Ninguno","Factura"}
end type

event selectionchanged;call super::selectionchanged;if index = 2 then
	st_periodo.visible=true
	em_periodo.visible=true
else
	st_periodo.visible=false
	em_periodo.visible=false
	
end if
end event

type st_tipo from uo_st within w_mail2_sm
integer x = 78
integer y = 1172
integer width = 160
integer height = 84
fontcharset fontcharset = defaultcharset!
string facename = "Tahoma"
long backcolor = 553648127
string text = "Tipo"
end type

type gb_1 from groupbox within w_mail2_sm
integer x = 27
integer y = 228
integer width = 4462
integer height = 1076
integer taborder = 20
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 67108864
end type

