revisa este codigo, derrepente te puede ser util, saludos
'Asi lo invocas el ultimo parametro 2 , es para agregar
IF !thisform.ntransaction1.of_act_stk_compra(ls_tipodoc, ls_nser,ls_ndoc, ls_codprov, 2) THEN && Agregamos Stock
MESSAGEBOX("ERROR, no se actualizo el Stock",16,gs_app_name)
RETURN .F.
ENDIF
' Clase Custom
LPARAMETERS as_tip_doc, as_nro_ser, as_nro_doc, as_cod_pro, ai_tipo
ls_sql = [ select n_lote, ]+;
[ cant, ]+;
[ item, ]+;
[ venc, ]+;
[ codarti ]+;
[ from compra_detalle ]+;
[ where TRIM(tipodoc)=']+ as_tip_doc +[']+;
[ and nser=']+ as_nro_ser +[']+;
[ and ndoc=']+ as_nro_doc +[']+;
[ and codprov=']+ as_cod_pro +[']
this.ejectsql(ls_sql,'cCur1')
SELECT cCur1
GO TOP
SCAN
ls_nlote = ALLTRIM(cCur1.n_lote)
li_cant = cCur1.cant
IF (ISNULL(cCur1.venc))
ld_venc = [venc = null ]
ELSE
ld_venc = DTOC(cCur1.venc)
ld_venc = [venc = ']+ ld_venc +[']
ENDIF
ln_item = cCur1.item
ls_codarti = ALLTRIM(cCur1.codarti)
ls_sql = [ select count(*)::numeric(2,0)as dato ]+;
[ from stock_lote ]+;
[ where n_lote=']+ ls_nlote +[' and codarti=']+ ls_codarti +[']
vCant = f_get_data_select(ls_sql)
IF vCant > 0 THEN
&& 'Actualizar Stock'
IF ai_tipo = 2 && Sustrae Stock
ls_sql = [ update stock_lote set stock = stock - ]+ STR(li_cant,12,2) +[, ]+ ld_venc +;
[ where n_lote = ']+ ls_nlote +[' and codarti=']+ ls_codarti +[']
ELSE && Adiciona Stock
ls_sql = [ update stock_lote set stock = stock + ]+ STR(li_cant,12,2) +[, ]+ ld_venc +;
[ where n_lote = ']+ ls_nlote +[' and codarti=']+ ls_codarti +[']
ENDIF
ELSE
&& 'Insertar en Tabla Stock_Lote'
ls_sql =[ insert into ]+;
[ stock_lote(n_lote,]+;
[ venc,]+;
[ stock,]+;
[ codarti)]+;
[ select ]+;
[ n_lote,]+;
[ venc,]+;
[ cant,]+;
[ codarti]+;
[ from compra_detalle]+;
[ where tipodoc=']+ as_tip_doc +[']+;
[ and nser=']+ as_nro_ser +[']+;
[ and ndoc=']+ as_nro_doc +[']+;
[ and codprov=']+ as_cod_pro +[']+;
[ and n_lote=']+ ls_nlote +[']+;
[ and codarti=']+ ls_codarti +[']+;
[ and item=]+ STR(ln_item,4,0)
ENDIF
this.ejectsql(ls_sql)
ENDSCAN
close_cursor('cCur1')
--
Moises Daniel Vilchez Tello
Chiclayo - Lambayeque - Peru