sexta-feira, 29 de novembro de 2013

Programa Exportar os Saldos das Contas Contábeis ( Datasul )


/************************************************************
** Programa : expsaldo.p
** Objetivo : Exportar os saldos das contas contabeis
****************************************************************/

DEF NEW SHARED VAR i-empresa  AS INTEGER FORMAT ">>9".
DEF NEW SHARED VAR i-ct-conta AS INTEGER FORMAT "99999999".
DEF NEW SHARED VAR i-sc-conta AS INTEGER FORMAT "99999".
DEF NEW SHARED VAR ct-conta AS CHAR FORMAT "x(8)".
DEF NEW SHARED VAR sc-conta AS CHAR FORMAT "x(8)".

DEF VAR i-cod-empresa AS INTEGER FORMAT ">>9".
DEF VAR i-contador    AS INTEGER FORMAT ">>>>>9".

DEF NEW SHARED TEMP-TABLE tt-saldo-conta
    FIELD ep-codigo      AS INTEGER FORMAT ">>9"
    FIELD ano-fiscal     AS INTEGER FORMAT "9999"
    FIELD conta-contabil AS CHAR    FORMAT "x(17)"
    FIELD mo-codigo      AS INTEGER FORMAT "99"
    FIELD saldo          AS DECIMAL DECIMALS 4 FORMAT "->,>>>,>>>,>>9.9999" EXTENT 13
    FIELD debito         AS DECIMAL DECIMALS 4 FORMAT ">,>>>,>>>,>>9.9999"  EXTENT 13
    FIELD credito        AS DECIMAL DECIMALS 4 FORMAT ">,>>>,>>>,>>9.9999"  EXTENT 13
    FIELD val-zera       AS DECIMAL DECIMALS 4 FORMAT "->,>>>,>>>,>>9.9999"
    FIELD ct-codigo      AS CHAR    FORMAT "x(8)"
    FIELD sc-codigo      AS CHAR    FORMAT "x(8)".

ASSIGN i-cod-empresa = 2.

FOR EACH admvale.conta-contab NO-LOCK WHERE
    admvale.conta-contab.ep-codigo = i-cod-empresa:

    ASSIGN i-empresa = admvale.conta-contab.ep-codigo
        i-ct-conta = admvale.conta-contab.ct-codigo
        i-sc-conta = admvale.conta-contab.sc-codigo
        ct-conta   = ""
        sc-conta   = "".

    RUN esp/expsaldoX.p.

    IF ct-conta <> "" THEN DO:
        RUN pi-cria-conta.
    END.
END.

IF i-cod-empresa = 1 THEN DO:
    OUTPUT TO VALUE("c:\clientes\expdoemp1.txt").
END.

IF i-cod-empresa = 2 THEN DO:
    OUTPUT TO VALUE("c:\clientes\expdoemp2.txt").
END.

IF i-cod-empresa = 3 THEN DO:
    OUTPUT TO VALUE("c:\clientes\expdoemp3.txt").
END.


PUT '"LOT"' SKIP
    '"FGL"' ""
    i-cod-empresa "" 
    '"Saldo"' "" 
    '"'
    string(i-cod-empresa) ""
    '"' ""
    STRING("30/04/2005") FORMAT "x(10)" ""
    '"Nao"' "" 
    NO SKIP
    '"LAN"' SKIP
    '"Fiscal"' ""
    no ""
    no ""
    '""' ""
    0 "" 
    1 "" 
    '"Nao"' ""
    STRING("30/04/2005") FORMAT "x(10)" SKIP.

ASSIGN i-contador = 0.

FOR EACH tt-saldo-conta NO-LOCK WHERE
    tt-saldo-conta.ep-codigo = i-cod-empresa:

    ASSIGN i-contador = i-contador + 1.

    PUT '"ITE"' "" SKIP
        0 ""
        i-contador "".

    IF tt-saldo-conta.saldo[5] < 0 THEN
        PUT '"CR"'.
    ELSE
        PUT '"DB"'.

    PUT "".

    IF i-cod-empresa = 1 THEN 
        PUT '"Emp1"'.
    ELSE
    IF i-cod-empresa = 2 THEN
        PUT '"Emp2"'.
    ELSE
    IF i-cod-empresa = 3 THEN
        PUT '"Emp3"'.

    PUT ""
        '"'
        tt-saldo-conta.ct-codigo 
        '"' "".

    IF int(tt-saldo-conta.sc-codigo) <> 0 THEN DO:
        IF i-cod-empresa = 1 THEN
            PUT '"Emp1"'.
        ELSE
        IF i-cod-empresa = 2 THEN
            PUT '"Emp2"'.
        ELSE
        IF i-cod-empresa = 3 THEN
            PUT '"Emp3"'.
    END.
    ELSE
        PUT '""'.

    PUT "".

    IF i-cod-empresa = 1 THEN
        PUT '"101" "001"'.
    ELSE
    IF i-cod-empresa = 2 THEN
        PUT '"201" "002"'.
    ELSE
    IF i-cod-empresa = 3 THEN
        PUT '"301" "003"'.

    PUT "" 
        '"" "Saldo" ""' ""
        ? "" 
        '"" "" "Real"' ""
        STRING("30/04/2005") FORMAT "x(10)" ""
        0 "".

    IF tt-saldo-conta.saldo[5] < 0 THEN
        PUT (tt-saldo-conta.saldo[5] * -1).
    ELSE
        PUT tt-saldo-conta.saldo[5].

    PUT "" 
        0 "" 
        '"Nao"' "".

    IF int(tt-saldo-conta.sc-codigo) <> 0 THEN 
        PUT '"' tt-saldo-conta.sc-codigo '"'.
    ELSE
        PUT '""'.

    PUT SKIP 
        '"APR"' SKIP
        '"Corrente" "" ""' "" 0 "".

    IF tt-saldo-conta.saldo[5] < 0 THEN
        PUT (tt-saldo-conta.saldo[5] * -1).
    ELSE
        PUT tt-saldo-conta.saldo[5].

    PUT ""
        i-contador "" 
        0 ""
        STRING("30/04/2005") FORMAT "x(10)" ""
        1 "" 
        '"Nao" "Automatico" ""' SKIP.
END.
OUTPUT CLOSE.

PROCEDURE pi-cria-conta:
    FIND FIRST tt-saldo-conta WHERE
        tt-saldo-conta.ep-codigo = admvale.conta-contab.ep-codigo AND
        tt-saldo-conta.ct-codigo = ct-conta AND 
        tt-saldo-conta.sc-codigo = sc-conta NO-ERROR.
    IF NOT AVAIL tt-saldo-conta THEN DO:
        CREATE tt-saldo-conta.
        ASSIGN tt-saldo-conta.ep-codigo   = admvale.conta-contab.ep-codigo
            tt-saldo-conta.ano-fiscal     = 2005
            tt-saldo-conta.ct-codigo      = ct-conta
            tt-saldo-conta.sc-codigo      = sc-conta
            tt-saldo-conta.conta-contabil = STRING(ct-conta,"99999999")
                                          + "." + STRING(sc-conta,"99999999")
            tt-saldo-conta.mo-codigo      = 0.
    END.

    ASSIGN tt-saldo-conta.saldo[5] = admvale.conta-contab.saldo[4]
                                   + admvale.conta-contab.debito[4]
                                   - admvale.conta-contab.credito[4].

END PROCEDURE.

/* Fim do programa */


/************************************************************** ** Programa : expsaldoX.p
** Objetivo : Exportar os saldos das contas contabeis
**            1 - Emp1 / 2 - Emp2 / 3 - Emp3
***************************************************************/

DEF SHARED VAR i-empresa  AS INTEGER FORMAT ">>9".
DEF SHARED VAR i-ct-conta AS INTEGER FORMAT "99999999".
DEF SHARED VAR i-sc-conta AS INTEGER FORMAT "99999".
DEF SHARED VAR ct-conta   AS CHAR FORMAT "x(8)".
DEF SHARED VAR sc-conta   AS CHAR FORMAT "x(8)".

IF i-empresa = 1 THEN DO:
    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111101.00005" THEN
        ASSIGN ct-conta = "11110101"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00005" THEN
        ASSIGN ct-conta = "11110201"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00010" THEN
        ASSIGN ct-conta = "11110202"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00020" THEN
        ASSIGN ct-conta = "11110203"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00025" THEN
        ASSIGN ct-conta = "11110204"
            sc-conta = "00000000".
    
    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00040" THEN
        ASSIGN ct-conta = "11110206"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00045" THEN
        ASSIGN ct-conta = "11110207"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00050" THEN
        ASSIGN ct-conta = "11110208"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00055" THEN
        ASSIGN ct-conta = "11110209"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00070" THEN
        ASSIGN ct-conta = "11110210"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00075" THEN
        ASSIGN ct-conta = "11110211"
            sc-conta = "00000000".
    
    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00080" THEN
        ASSIGN ct-conta = "11110212"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00085" THEN
        ASSIGN ct-conta = "11110213"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00090" THEN
        ASSIGN ct-conta = "11110214"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00095" THEN
        ASSIGN ct-conta = "11110215"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111102.00100" THEN
        ASSIGN ct-conta = "11110216"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00111103.00010" THEN
        ASSIGN ct-conta = "11110302"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112101.00005" THEN
        ASSIGN ct-conta = "11210102"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112101.00015" THEN
        ASSIGN ct-conta = "11210103"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112101.00020" THEN
        ASSIGN ct-conta = "11210102"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112105.00005" THEN
        ASSIGN ct-conta = "11310101"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112105.00010" THEN
        ASSIGN ct-conta = "11310102"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112105.00020" THEN
        ASSIGN ct-conta = "11310103"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112105.00075" THEN
        ASSIGN ct-conta = "11310109"
            sc-conta = "00000000".
    
    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112201.00005" THEN
        ASSIGN ct-conta = "11410101"
            sc-conta = "00000000".
    
    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112201.00010" THEN
        ASSIGN ct-conta = "11410102"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112202.00015" THEN
        ASSIGN ct-conta = "11430101"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112203.00005" THEN
        ASSIGN ct-conta = "11410201"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112203.00010" THEN
        ASSIGN ct-conta = "11410202"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112203.00015" THEN
        ASSIGN ct-conta = "11410203"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112203.00025" THEN
        ASSIGN ct-conta = "11410203"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112203.00030" THEN
        ASSIGN ct-conta = "11410203"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112203.00035" THEN
        ASSIGN ct-conta = "11410203"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112204.00005" THEN
        ASSIGN ct-conta = "11420101"
            sc-conta = "00000000".

    IF STRING(i-ct-conta,"99999999") + "." + 
        STRING(i-sc-conta,"99999") = "00112204.00015" THEN
        ASSIGN ct-conta = "11420103"
            sc-conta = "00000000".
END.

Nenhum comentário:

Postar um comentário