programa para implantar pedido de venda e suas bos

Discussão em 'EMS , HCM e Totvs 11' iniciado por Carlos Alberto Giusti, Fevereiro 9, 2023.

  1. Carlos Alberto Giusti

    Carlos Alberto Giusti Membro Ativo

    não tem as includes.
  2. rafael.andrade

    rafael.andrade Membro Master Moderador Equipe de Suporte

    As includes estão no topo do código que passei
  3. Carlos Alberto Giusti

    Carlos Alberto Giusti Membro Ativo

    não acha no sistema
  4. rafael.andrade

    rafael.andrade Membro Master Moderador Equipe de Suporte

    Se tem o totvs, tem que ter essas includes, elas são disponibilizadas pela totvs, faz parte do produto, se depois de fazer um localizar do windows não achar, então precisa pedir pra totvs
  5. Carlos Alberto Giusti

    Carlos Alberto Giusti Membro Ativo

    Este é o código que estou usando e não grava o pedido e itens

    Pedido

    FIND FIRST tt-ped-venda NO-ERROR.
    IF AVAIL tt-ped-venda THEN DO:
    blocoAtualiza:
    DO TRANSACTION:

    FIND FIRST ped-venda
    WHERE ped-venda.nome-abrev = emitente.nome-abrev
    AND ped-venda.nr-pedcli = tt-ped-venda.nr-pedcli NO-LOCK NO-ERROR.
    IF NOT AVAIL ped-venda THEN DO:

    message "implanta pedido 2" view-as alert-box.

    assign tt-ped-venda.tp-pedido = 'SM1'
    tt-ped-venda.ind-fat-par = yes.

    IF AVAIL natur-oper THEN DO:
    if natur-oper.consum-final = yes then assign tt-ped-venda.cod-des-merc = 2.
    if natur-oper.consum-final = no then assign tt-ped-venda.cod-des-merc = 1.
    END.

    if avail natur-oper and
    natur-oper.emite-duplic = no then
    assign tt-ped-venda.cod-cond-pag = 0
    tt-ped-venda.cod-canal-venda = natur-oper.cod-canal-venda
    tt-ped-venda.cod-mensagem = natur-oper.cod-mensagem.
    message "implanta pedido 3 " view-as alert-box.

    RUN setDefaultOrderNumber IN h_bodi159sdf(OUTPUT i-nr-pedido).

    assign tt-ped-venda.nr-pedido = i-nr-pedido.

    RUN InputTable IN h_bodi159sdf(INPUT TABLE tt-ped-venda).
    RUN outputTable IN h_bodi159sdf(OUTPUT TABLE tt-ped-venda).
    RUN emptyRowErrors IN h_bodi159.
    RUN openQueryStatic IN h_bodi159(INPUT "Main":U).
    RUN getRowErrors IN h_bodi159(OUTPUT TABLE RowErrors).
    RUN setRecord IN h_bodi159(INPUT TABLE tt-ped-venda).
    RUN createRecord IN h_bodi159.
    RUN getRowErrors IN h_bodi159(OUTPUT TABLE RowErrors).
    /* IF CAN-FIND(FIRST rowerrors) THEN DO: */
    /* END. */
    /* ELSE DO: */
    FIND FIRST tt-ped-venda NO-ERROR.

    IF NOT CAN-FIND(FIRST ped-repre OF tt-ped-venda) THEN DO:
    IF NOT CAN-FIND(FIRST tt-ped-repre) THEN DO:

    message "implanta pedido 4 " view-as alert-box.

    EMPTY TEMP-TABLE tt-ped-repre.
    CREATE tt-ped-repre.
    ASSIGN tt-ped-repre.nr-pedido = tt-ped-venda.nr-pedido
    tt-ped-repre.nome-ab-rep = tt-ped-venda.no-ab-reppri
    tt-ped-repre.perc-comis = repres.comis-direta.
    /* BPM */
    tt-ped-repre.ind-repbase = yes.
    tt-ped-repre.comis-emis = repres.comis-emis.

    RELEASE tt-ped-repre.
    message "implanta pedido 4.1 " view-as alert-box.


    END.

    message "implanta pedido 5 " view-as alert-box.

    RUN emptyRowErrors IN h_bodi157.
    RUN openQueryStatic IN h_bodi157(input "Main":U).
    RUN setRecord in h_bodi157(input table tt-ped-repre).
    RUN createRecord in h_bodi157.
    RUN getRowErrors IN h_bodi157(OUTPUT TABLE RowErrors).

    IF CAN-FIND(FIRST rowerrors) THEN DO:
    END.
    END.

    message "implanta pedido 6 " view-as alert-box.

    FIND FIRST tt-ped-venda NO-ERROR.
    FIND FIRST ped-venda
    WHERE ped-venda.nr-pedido = tt-ped-venda.nr-pedido NO-LOCK NO-ERROR.
    IF AVAIL ped-venda THEN DO:
    message "implanta pedido 6 " view-as alert-box.

    FIND FIRST repres WHERE repres.nome-abrev = ped-venda.no-ab-reppri NO-LOCK NO-ERROR.
    FIND FIRST ped-repre
    WHERE ped-repre.nr-pedido = ped-venda.nr-pedido
    AND ped-repre.nome-ab-rep = ped-venda.no-ab-reppri
    NO-LOCK NO-ERROR.
    END.

    run implanta-item-pedido.

    FIND FIRST tt-ped-venda NO-ERROR.
    FIND FIRST ped-venda
    WHERE ped-venda.nr-pedido = tt-ped-venda.nr-pedido NO-LOCK NO-ERROR.

    IF AVAIL ped-venda AND
    CAN-FIND (FIRST ped-item OF ped-venda) THEN DO:

    message "implanta pedido 7 " view-as alert-box.

    EMPTY TEMP-TABLE RowErrors NO-ERROR.
    RUN emptyRowErrors IN h_bodi159com NO-ERROR.
    RUN completeorder IN h_bodi159com (INPUT ROWID(ped-venda),
    OUTPUT TABLE rowerrors) NO-ERROR.
    IF CAN-FIND(FIRST rowerrors) THEN DO:
    END.
    END.

    END.
    /* END. */
    END.
    END.

    implanta-item-pedido

    FOR EACH tt-ped-item:
    // Verifica se não existe o item no pedido
    message "implanta item pedido 1" view-as alert-box.
    FIND FIRST ped-item
    WHERE ped-item.nome-abrev = tt-ped-item.nome-abrev
    AND ped-item.nr-pedcli = tt-ped-item.nr-pedcli
    AND ped-item.it-codigo = tt-ped-item.it-codigo
    AND ped-item.nr-sequencia = tt-ped-item.nr-sequencia
    AND ped-item.cod-refer = tt-ped-item.cod-refer
    EXCLUSIVE-LOCK NO-ERROR.


    IF NOT AVAIL ped-item THEN DO:

    message "implanta item pedido 2" view-as alert-box.
    EMPTY TEMP-TABLE tt-ped-item-aux.
    CREATE tt-ped-item-aux.
    BUFFER-COPY tt-ped-item TO tt-ped-item-aux.

    RUN goToKey IN h_bodi154 (INPUT tt-ped-item-aux.nome-abrev,
    INPUT tt-ped-item-aux.nr-pedcli,
    INPUT tt-ped-item-aux.nr-sequencia,
    INPUT tt-ped-item-aux.it-codigo,
    INPUT tt-ped-item-aux.cod-refer).

    /*ASSIGN tt-ped-item-aux.ind-componen = 1 /* Produto Normal */
    tt-ped-item-aux.esp-ped = 1 /* Pedido Simples */
    tt-ped-item-aux.dt-entorig = today
    tt-ped-item-aux.tipo-atend = 2 /* Parcial */
    .*/

    RUN openQueryStatic IN h_bodi154(INPUT "Main":U).
    RUN setRecord IN h_bodi154(INPUT TABLE tt-ped-item-aux).
    RUN emptyRowErrors IN h_bodi154.
    RUN createRecord IN h_bodi154.
    RUN getRowErrors IN h_bodi154(OUTPUT TABLE RowErrors).
    message "implanta item pedido 3" view-as alert-box.
    IF CAN-FIND(FIRST rowerrors
    WHERE RowErrors.ErrorSubType <> 'WARNING'
    and RowErrors.ErrorSubType <> 'Information') THEN DO:
    END.
    // delete tt-ped-item.
    END.
    END.
  6. rafael.andrade

    rafael.andrade Membro Master Moderador Equipe de Suporte

    Você viu a API e a BO que passei? muito mais simples que isso aí

Compartilhe esta Página