Histórico da Página
Descrição
Este ponto epc altera o peso real dos itens conforme o peso bruto da nota fiscal
Ponto de Entrada - altera-item-docum-est
Descrição: | Altera o peso dos itens rateados conforme o peso bruto da nota fiscal | ||||||||
Localização: | cdapi651.i1 | ||||||||
Eventos: | altera-item-docum-est | ||||||||
Programa Fonte: | cdp/cdapi651.i1 | ||||||||
Função: | CDAPI651 - Integração Nota Fiscal de Compra | ||||||||
Parâmetro 1: |
| ||||||||
Parâmetro 2: |
| ||||||||
Retorno: | Não é retornada nenhuma informação ao programa cdapi651 |
Exemplo:
/*****************************************************************************
******************************************************************************/
{include/i-epc200.i upc-cdapi651}
DEF INPUT PARAM p-ind-event AS CHAR NO-UNDO.
DEF INPUT-OUTPUT PARAM TABLE FOR tt-epc.
{cdp/cdapi651.i}
DEFINE VARIABLE lc-xml AS CHAR NO-UNDO.
DEFINE VARIABLE r-rowid AS ROWID NO-UNDO.
DEFINE VARIABLE r-docum-est AS ROWID NO-UNDO.
DEFINE BUFFER bf-docum-est FOR docum-est.
DEFINE VARIABLE h-ttwm-docto-itens AS WIDGET-HANDLE NO-UNDO.
DEFINE VARIABLE h-Itens AS WIDGET-HANDLE NO-UNDO.
DEFINE VARIABLE h-buffer AS WIDGET-HANDLE NO-UNDO.
define variable h-cod-estabelec as WIDGET-handle no-undo.
define variable h-especie-doc as WIDGET-handle no-undo.
define variable h-cod-emitente as WIDGET-handle no-undo.
define variable h-serie-docto as WIDGET-handle no-undo.
define variable h-nro-docto as WIDGET-handle no-undo.
define variable h-nat-operacao as WIDGET-handle no-undo.
define variable h-sequencia as WIDGET-handle no-undo.
define variable h-it-codigo as WIDGET-handle no-undo.
define variable h-cont-uni-neg as WIDGET-handle no-undo.
define variable h-desc-item as WIDGET-handle no-undo.
define variable h-volume as WIDGET-handle no-undo.
define variable h-quantidade as WIDGET-handle no-undo.
define variable h-un as WIDGET-handle no-undo.
define variable h-peso-real as WIDGET-handle no-undo.
define variable h-peso-cubado as WIDGET-handle no-undo.
define variable h-valor as WIDGET-handle no-undo.
DEFINE VARIABLE h-tt-doc-itens AS WIDGET-HANDLE NO-UNDO.
DEFINE VARIABLE hQueryItens AS WIDGET-HANDLE NO-UNDO.
DEFINE VARIABLE hBTTItemDocumEst AS HANDLE NO-UNDO.
DEFINE VARIABLE hQTTItemDocumEst AS WIDGET-HANDLE NO-UNDO.
DEFINE VARIABLE de-quantidade AS DECIMAL NO-UNDO.
DEFINE VARIABLE de-peso-dif AS DECIMAL NO-UNDO.
DEFINE VARIABLE de-acum-peso AS DECIMAL NO-UNDO.
DEFINE VARIABLE de-percentual AS DECIMAL FORMAT "999.99" NO-UNDO.
IF p-ind-event = "altera-item-docum-est" THEN DO:
FIND FIRST tt-epc
WHERE tt-epc.cod-event = "altera-item-docum-est"
AND tt-epc.cod-parameter = "rowid-docum-est" NO-LOCK NO-ERROR.
IF NOT AVA IL tt-epc THEN
RETURN "NOK":U.
ASSIGN r-docum-est = TO-ROWID(tt-epc.val-parameter).
FIND FIRST tt-epc NO-LOCK
WHERE tt-epc.cod-event = "altera-item-docum-est"
AND tt-epc.cod-parameter = "handle-tt-item-docum-est" NO-ERROR.
IF AVAIL tt-epc THEN DO:
ASSIGN h-Itens = WIDGET-HANDLE(tt-epc.val-parameter) .
ASSIGN h-tt-doc-itens = WIDGET-HANDLE(tt-epc.val-parameter)
hQueryItens = h-tt-doc-itens:DEFAULT-BUFFER-HANDLE.
END.
FIND FIRST bf-docum-est NO-LOCK
WHERE ROWID(bf-docum-est) = r-docum-est NO-ERROR.
IF NOT AVAIL bf-docum-est THEN
RETURN "NOK":U.
IF bf-docum-est.peso-bruto-tot = 0 THEN
RETURN "NOK":U.
CREATE BUFFER hBTTItemDocumEst FOR TABLE hQueryItens BUFFER-NAME "tt-item-docum-est".
CREATE QUERY hQTTItemDocumEst.
hQTTItemDocumEst:SET-BUFFERS(hBTTItemDocumEst).
hQTTItemDocumEst:QUERY-PREPARE("FOR EACH tt-item-docum-est").
hQTTItemDocumEst:QUERY-OPEN.
hQTTItemDocumEst:GET-FIRST().
DO WHILE NOT(hQTTItemDocumEst:QUERY-OFF-END):
ASSIGN h-cod-estabelec = hBTTItemDocumEst:BUFFER-FIELD('cod-estabelec')
h-especie-doc = hBTTItemDocumEst:BUFFER-FIELD('especie-doc')
h-cod-emitente = hBTTItemDocumEst:BUFFER-FIELD('cod-emitente')
h-serie-docto = hBTTItemDocumEst:BUFFER-FIELD('serie-docto')
h-nro-docto = hBTTItemDocumEst:BUFFER-FIELD('nro-docto')
h-nat-operacao = hBTTItemDocumEst:BUFFER-FIELD('nat-operacao')
h-sequencia = hBTTItemDocumEst:BUFFER-FIELD('sequencia')
h-it-codigo = hBTTItemDocumEst:BUFFER-FIELD('it-codigo')
h-volume = hBTTItemDocumEst:BUFFER-FIELD('volume')
h-quantidade = hBTTItemDocumEst:BUFFER-FIELD('quantidade')
h-peso-real = hBTTItemDocumEst:BUFFER-FIELD('peso-real')
h-peso-cubado = hBTTItemDocumEst:BUFFER-FIELD('peso-cubado').
FIND FIRST tt-item-docum-est NO-LOCK
WHERE tt-item-docum-est.cod-emitente = INT(h-cod-emitente:BUFFER-VALUE)
AND tt-item-docum-est.serie-docto = STRING(h-serie-docto:BUFFER-VALUE)
AND tt-item-docum-est.nro-docto = STRING(h-nro-docto:BUFFER-VALUE)
AND tt-item-docum-est.it-codigo = STRING(h-it-codigo:BUFFER-VALUE)
AND tt-item-docum-est.nat-operacao = STRING(h-nat-operacao:BUFFER-VALUE) NO-ERROR.
IF NOT AVAIL tt-item-docum-est THEN DO:
CREATE tt-item-docum-est.
ASSIGN tt-item-docum-est.cod-estabelec = string(h-cod-estabelec:buffer-value)
tt-item-docum-est.especie-doc = string(h-especie-doc:buffer-value)
tt-item-docum-est.cod-emitente = INT(h-cod-emitente:buffer-value)
tt-item-docum-est.serie-docto = string(h-serie-docto:buffer-value)
tt-item-docum-est.nro-docto = string(h-nro-docto:BUFFER-VALUE)
tt-item-docum-est.nat-operacao = string(h-nat-operacao:buffer-value)
tt-item-docum-est.sequencia = string(h-sequencia:BUFFER-VALUE)
tt-item-docum-est.it-codigo = string(h-it-codigo:buffer-value)
tt-item-docum-est.volume = string(h-volume:BUFFER-VALUE)
tt-item-docum-est.quantidade = DECIMAL(h-quantidade:buffer-value)
tt-item-docum-est.peso-real = DECIMAL(h-peso-real:buffer-value)
tt-item-docum-est.peso-cubado = DECIMAL(h-peso-cubado:BUFFER-VALUE)
END.
hBTTItemDocumEst:BUFFER-DELETE.
hQTTItemDocumEst:GET-NEXT.
END.
hQTTItemDocumEst:QUERY-CLOSE.
DELETE OBJECT hQTTItemDocumEst.
ASSIGN de-acum-peso = 0
de-percentual = 0
de-peso-dif = 0.
/* Verifica a quantidade total dos itens */
FOR EACH tt-item-docum-est NO-LOCK
WHERE tt-item-docum-est.cod-emitente = bf-docum-est.cod-emitente
and tt-item-docum-est.serie-docto = bf-docum-est.serie-docto
and tt-item-docum-est.nro-docto = bf-docum-est.nro-docto
and tt-item-docum-est.nat-operacao = bf-docum-est.nat-operacao :
ASSIGN de-quantidade = de-quantidade + tt-item-docum-est.quantidade.
END.
/* Realiza o rateio do peso bruto do documento com base na quantidade de cada item */
FOR EACH tt-item-docum-est EXCLUSIVE-LOCK
WHERE tt-item-docum-est.cod-emitente = bf-docum-est.cod-emitente
and tt-item-docum-est.serie-docto = bf-docum-est.serie-docto
and tt-item-docum-est.nro-docto = bf-docum-est.nro-docto
and tt-item-docum-est.nat-operacao = bf-docum-est.nat-operacao :
ASSIGN de-percentual = tt-item-docum-est.quantidade / de-quantidade.
ASSIGN tt-item-docum-est.peso-real = bf-docum-est.peso-bruto-tot * de-percentual.
ASSIGN de-acum-peso = de-acum-peso + tt-item-docum-est.peso-real.
END.
/* Verifica questäes de arredondamento */
IF de-acum-peso < bf-docum-est.peso-bruto-tot THEN DO:
ASSIGN de-peso-dif = bf-docum-est.peso-bruto-tot - de-acum-peso.
END.
IF de-peso-dif > 0 THEN DO:
FOR LAST tt-item-docum-est EXCLUSIVE-LOCK
WHERE tt-item-docum-est.cod-emitente = bf-docum-est.cod-emitente
and tt-item-docum-est.serie-docto = bf-docum-est.serie-docto
and tt-item-docum-est.nro-docto = bf-docum-est.nro-docto
and tt-item-docum-est.nat-operacao = bf-docum-est.nat-operacao :
ASSIGN tt-item-docum-est.peso-real = tt-item-docum-est.peso-real + de-peso-dif.
END.
END.
FOR EACH tt-item-docum-est:
ASSIGN h-buffer = h-Itens:DEFAULT-BUFFER-HANDLE.
h-buffer:BUFFER-CREATE().
ASSIGN h-cod-estabelec = h-buffer:BUFFER-FIELD('cod-estabelec')
h-especie-doc = h-buffer:BUFFER-FIELD('especie-doc')
h-cod-emitente = h-buffer:BUFFER-FIELD('cod-emitente')
h-serie-docto = h-buffer:BUFFER-FIELD('serie-docto')
h-nro-docto = h-buffer:BUFFER-FIELD('nro-docto')
h-nat-operacao = h-buffer:BUFFER-FIELD('nat-operacao')
h-sequencia = h-buffer:BUFFER-FIELD('sequencia')
h-it-codigo = h-buffer:BUFFER-FIELD('it-codigo')
h-volume = h-buffer:BUFFER-FIELD('volume')
h-quantidade = h-buffer:BUFFER-FIELD('quantidade')
h-peso-real = h-buffer:BUFFER-FIELD('peso-real')
h-peso-cubado = h-buffer:BUFFER-FIELD('peso-cubado').
ASSIGN h-cod-estabelec:buffer-value = tt-item-docum-est.cod-estabelec
h-especie-doc:buffer-value = tt-item-docum-est.especie-doc
h-cod-emitente:buffer-value = tt-item-docum-est.cod-emitente
h-serie-docto:buffer-value = tt-item-docum-est.serie-docto
h-nro-docto:buffer-value = tt-item-docum-est.nro-docto
h-nat-operacao:buffer-value = tt-item-docum-est.nat-operacao
h-sequencia:buffer-value = tt-item-docum-est.sequencia
h-it-codigo:buffer-value = tt-item-docum-est.it-codigo
h-quantidade:buffer-value = tt-item-docum-est.quantidade
h-peso-real:buffer-value = tt-item-docum-est.peso-real
h-peso-cubado:buffer-value = tt-item-docum-est.peso-cubado
END.
END.
RETURN "OK":U.