Páginas filhas
  • Automatic compensation between portfolios - FINA450

01. OVERVIEW

Product Line:

Microsiga Protheus®

Industry:

Services

Module:

Financial


02. STATUS/REQUIREMENT

The automatic use of the Compensation routine between portfolios has been implemented. 

Notes

FINA450 (nPosArotina, aAutoCab, nOpcAuto)

  •  aAutoCab - Array used to send data related to the process.   These data are equivalent to the data entered in the manual filter screen, such as:
    • Start Date: Actual maturity start date to filter bills.
    • End Date: Actual maturity end date to filter bills.
    • Limit value: Limit value for compensation.   This information is used to filter the bills up to the value entered.
    • Customer and Store code: Customer/store code to filter bills for compensation. 
    • Supplier and Store code: Supplier/store code to filter bills for compensation.
    • Currency: Currency code of the bills to be used for compensation.
    • Debit or Credit: Filter the debit (NF, DP, BOL etc.) or credit (RA, PA, NCC, and NDF) types.
      • Content "1" filter regular bills, and "2", credit bills (e.g.: RA, PA)
    • Future Bills: Filters bills issued after the base date.
    • Bills Receivable Key (Array with Bills Receivable Key to be compensated):
      • SE1->E1_FILIAL+SE1->E1_PREFIXO+SE1->E1_NUM+SE1->E1_PARCELA+SE1→E1_TIPO
    • Bills Payable Key (Array with Bills Payable Key to be compensated):
      • SE2->E2_FILIAL+SE2->E2_PREFIXO+SE2->E2_NUM+SE2->E2_PARCELA+SE2->E2_TIPO+SE2→E2_FORNECE+SE2→E2_LOJA
    • -nOpcAuto - Menu option to be executed automatically.
      • 3 = Compensation

Note:

  • The automatic compensation between portfolios only posts the total value of the bill.
  • If the Customer and Supplier stores are empty, the system will consider all stores with the same supplier and customer code.  (Available as of June 1st, 2023)


03. EXAMPLE OF USE


Example of automatic routine
#include "rwmake.ch"
#include 'tbiconn.ch'

User Function AUTO450()
    Local aAutoCab := {}
    Local aArea    := GetArea()
    Local cTabSe1  := "TMPSE1A"
    Local cTabSe2  := "TMPSE2A"
    Local aSE1450  := {}
    Local aSE2450  := {}
    Local cFilSe2  := xFilial("SE2")
    Local cFilSe1  := xFilial("SE1")

    Private lMsHelpAuto := .T.
    Private lMsErroAuto := .F.

    BeginSql Alias cTabSe1
		SELECT R_E_C_N_O_ as RECNO
			FROM %Table:SE1% SE1
			WHERE SE1.E1_FILIAL = %Exp:cFilSe1%
				AND SE1.E1_PREFIXO = 'CPT'
				AND SE1.E1_NUM = 'VT001'
				AND SE1.E1_TIPO = 'NF'
				AND SE1.E1_CLIENTE = 'FIN001'
				AND SE1.E1_LOJA    = '01'
				AND SE1.%NotDel%
	EndSql

    While (cTabSe1)->(!EOF())
        SE1->(DbGoto((cTabSe1)->RECNO))
        AAdd(aSE1450, {SE1->E1_FILIAL+SE1->E1_PREFIXO+SE1->E1_NUM+SE1->E1_PARCELA+SE1->E1_TIPO})
        (cTabSe1)->(DbSkip())  
    Enddo

    (cTabSe1)->(DbCloseArea())

    BeginSql Alias cTabSe2
		SELECT R_E_C_N_O_ as RECNO
			FROM %Table:SE2% SE2
			WHERE SE2.E2_FILIAL = %Exp:cFilSe2%
				AND SE2.E2_PREFIXO = 'CPT'
				AND SE2.E2_NUM = 'VT001'
				AND SE2.E2_TIPO = 'NF'
				AND SE2.E2_FORNECE = 'FIN001'
				AND SE2.E2_LOJA    = '01'
				AND SE2.%NotDel%
	EndSql

    While (cTabSe2)->(!EOF())
        SE2->(DbGoto((cTabSe2)->RECNO))
        AAdd(aSE2450, {SE2->E2_FILIAL+SE2->E2_PREFIXO+SE2->E2_NUM+SE2->E2_PARCELA+SE2->E2_TIPO+SE2->E2_FORNECE+SE2->E2_LOJA})   
        (cTabSe2)->(DbSkip())  
    Enddo
    
    (cTabSe2)->(DbCloseArea())

    aAutoCab := { {"AUTDVENINI450", cTod('27/08/19') , nil},;
    {"AUTDVENFIM450", cTod('27/08/19') , nil},;
    {"AUTNLIM450" , 10000 , nil},;
    {"AUTCCLI450" , "FIN001" , nil},;
    {"AUTCLJCLI" , "01" , nil},;
    {"AUTCFOR450" , "FIN001" , nil},;
    {"AUTCLJFOR" , "01" , nil},;
    {"AUTCMOEDA450" , "01" , nil},; 
    {"AUTNDEBCRED" , 1 , nil},;
    {"AUTLTITFUTURO", .F. , nil},;
    {"AUTARECCHAVE" , aSE1450 , nil},;
    {"AUTAPAGCHAVE" , aSE2450 , nil}}

    MSExecAuto({|x,y,z| Fina450(x,y,z)}, nil , aAutoCab , 3 )

    If !lMsErroAuto
        alert("Added successfully! ")
        confirmsx8()
    Else
        alert("Error when adding!")
        rollbacksx8()
        MostraErro()
    EndIf
    
    RestArea(aArea)
Return
Example of automatic routine between branches
#include "rwmake.ch"
#include 'tbiconn.ch'
  
User Function Auto450()
    Local aAutoCab := {}
	Local aArea    := GetArea()
    Local cTabSe1  := "TMPSE1A"
    Local cTabSe2  := "TMPSE2A"
    Local aSE1450  := {}
    Local aSE2450  := {}
    Local aFilCmp  := {}

    Private lMsHelpAuto := .F.
    Private lMsErroAuto := .F.

    BeginSql Alias cTabSe1
		SELECT R_E_C_N_O_ as RECNO
			FROM %Table:SE1% SE1
			WHERE SE1.E1_FILIAL = 'D MG 01 '
				AND SE1.E1_PREFIXO = 'CPT'
				AND SE1.E1_NUM = 'VT001'
				AND SE1.E1_TIPO = 'NF'
				AND SE1.E1_CLIENTE = 'FIN001'
				AND SE1.E1_LOJA    = '01'
				AND SE1.%NotDel%
	EndSql

    While (cTabSe1)->(!EOF())
        SE1->(DbGoto((cTabSe1)->RECNO))
        AAdd(aSE1450, {SE1->E1_FILIAL+SE1->E1_PREFIXO+SE1->E1_NUM+SE1->E1_PARCELA+SE1->E1_TIPO})
        If ascan(aFilCmp,SE1->E1_FILIAL) == 0
            Aadd(aFilCmp, SE1->E1_FILIAL)
        EndIf    
        (cTabSe1)->(DbSkip())  
    Enddo

    (cTabSe1)->(DbCloseArea())

    BeginSql Alias cTabSe2
		SELECT R_E_C_N_O_ as RECNO
			FROM %Table:SE2% SE2
			WHERE SE2.E2_FILIAL = 'D MG 02 '
				AND SE2.E2_PREFIXO = 'CPT'
				AND SE2.E2_NUM = 'VT001'
				AND SE2.E2_TIPO = 'NF'
				AND SE2.E2_FORNECE = 'FIN001'
				AND SE2.E2_LOJA    = '01'
				AND SE2.%NotDel%
	EndSql

    While (cTabSe2)->(!EOF())
        SE2->(DbGoto((cTabSe2)->RECNO))
        AAdd(aSE2450, {SE2->E2_FILIAL+SE2->E2_PREFIXO+SE2->E2_NUM+SE2->E2_PARCELA+SE2->E2_TIPO+SE2->E2_FORNECE+SE2->E2_LOJA})
        If ascan(aFilCmp,SE2->E2_FILIAL) == 0
            Aadd(aFilCmp, SE2->E2_FILIAL)
        EndIf    
        (cTabSe2)->(DbSkip())  
    Enddo
    
    (cTabSe2)->(DbCloseArea())

    aAutoCab :={  {"AUTDVENINI450", cTod('27/08/19') , nil},;
                {"AUTDVENFIM450", cTod('27/08/19') , nil},;
                {"AUTNLIM450" ,8000, nil},;
                {"AUTCCLI450" , "FIN001" , nil},;
                {"AUTCLJCLI" , "01" , nil},;
                {"AUTCFOR450" , "FIN001" , nil},;
                {"AUTCLJFOR" , "01" , nil},;
                {"AUTCMOEDA450" , "01" , nil},; 
                {"AUTNDEBCRED" , 1 , nil},;
                {"AUTLTITFUTURO", .F. , nil},;
                {"AUTARECCHAVE" ,aSE1450, nil},;
                {"AUTAPAGCHAVE" , aSE2450 , nil},;
                {"AUTAFILCOMP" , aFilCmp , nil}}

    MSExecAuto({|x,y,z| Fina450(x,y,z)}, nil , aAutoCab , 3 )

    If !lMsErroAuto
        ConOut("Added successfully! ")
        confirmsx8()
    Else
        ConOut("Error when adding!")
        rollbacksx8()
        MostraErro()
    EndIf

	RestArea(aArea)
Return


IMPORTANT!

For the compensation to work between branches, use the AUTAFILCOMP parameter, otherwise there is no need to inform it.

04. OTHER INFORMATION

None.

05. RELATED SUBJECTS

None.