Note

This routine was adjusted to comply with the General Personal Data Protection Law (Statute No. 13.70), so that some fields containing data regarded as sensitive and/or personal are blurred, becoming illegible.

01. OVERVIEW

This transaction allows compensating all advances performed and registered by the Customers (RA bills) and the credit notes to be deducted (NCC bills).

The bills cleared have their opening balances decreased or even zeroed, characterizing a posting of the cleared bill.

Important:

Note: the bills to be cleared cannot be posted, i.e., the colored ball on the left of the bill must be green, which indicates unposted bills.

 

Clearance of bills receivable enables:

Clearing bills from the same customer/store with advances from the same customer/store;
Clearing bills from a certain customer with advances from the same customer, regardless of the store of the bill to be cleared. Thus, it is possible to clear the bill with any advance bill from the same customer that is opened in the bills file, regardless of the store from which this bill comes from.
Clearing a bill from a certain customer with advances from several customers, in which case a customer range or all customers can be established. That way, the bill can be cleared with any advance bill opened in the file, regardless of the customer from which this bill comes from.
Clearing bills and advances between branches, i.e., customers with advances from this one or other customers in several branches of the company.

Important:

The rate used when posting bills received is treated in the system as it follows:

In Brazil, it is used the rate informed in the bill.

In localized countries, the rate of the day is considered.

 

Note:

Parameter MV_BR10925 defines the time of deduction of the amounts of the taxes (PIS, COFINS, and CSLL) and can be set to 1 (tax deduction occurs when the document is posted) or 2 (tax deduction occurs when the document is issued).

If the parameter MV_BR10925 is set to 1 (deduction of taxes on document posting), in cases in which there is clearing with deduction of these tax amounts, the tax bills will be generated linked to the main bill and never to the advance payment.

In the bills receivable settlement process, no taxes are calculated.
The PIS, COFINS, and CSLL taxes existing in the generating bills will only be passed on to the installments in cases where the nature of the bills generated by the invoice allows the calculation of taxes. That way, the taxes of the bills generating the invoice receivable will have their values added and proportionally sized in each installment.
In the scenario where the MV_BR10925 parameter is set with the content 1 (Posting) and a reduced base exists in the invoice bill, at the time of clearing, the system will take into consideration the reduced base for the calculation and generation of PIS, Cofins, and CSLL taxes.

 

Note:

This routine features integration with RM Classis Net.

For technical details about the procedures of Deployment, Usage, Table Synchronization among Bases and Parameterization for Generation, check the Protheus X Classis Integration Manual available on the TDN portal.

Also, check information about Education Management.

CMP Posting Reason

This routine uses posting reason CMP. Check the need to properly register and configure this posting reason in the Registration of Posting Reason - FINA490 routine. 

02. OPERATIONS 

Parameterization for the clearing operation is available via the F12 option. 


      


Consider Store: Indicate whether the customer's store, when the question "Consider Customer" equals Yes, should be considered in the selection of the bills to be cleared.

Consider Customer: Indicate whether the customer of the original bill should be considered in the selection of bills to be cleared, or whether the customers entered in the questions "From Customer" and "To Customer" will be considered

From customer: Initial code of the customers whose bills will be cleared if the question "Consider customer" equals yes.

To customer: End code of the customers whose bills will be cleared, if the question "Consider customer" equals yes.

Clear Transferred: Indicate whether you want the bills transferred to collection to be considered in the selection of the bills to be billed.

Calc.Comiss.w/o NCC: Indicate whether you want to calculate a commission over credit instrument (NCC).

Display Acc. Entry: Indicate whether the accounting entry must be displayed.

Cons.Deductions/Taxes: Indicate whether the balance to be compensated should be reduced by deductions and taxes. If they are not considered, the balance to be considered for operation will be only the balance of the bill.

Account Online: Enter if it is accounted for online.

Consider branches below: Enter whether to consider a branch range to be entered in the next parameters. (Parameter discontinued, replaced by the Branches button on the main bill selection screen)

From Branch: Enter the initial branch to be considered in the branches range. (Parameter discontinued, replaced by the Branches button on the main bill selection screen)

To Branch: Enter the final branch to be considered in the branches range. (Parameter discontinued, replaced by the Branches button on the main bill selection screen)

Calc.Comiss.w/o RA: Indicate whether you want to calculate a commission over credit instrument (RA).

Reuse rate entered: Indicate whether to reuse the rate entered for other compensations.

Cons.Commission Interest: Indicate whether the interest value should be considered when calculating the commission.

To perform the clearing process, you need to select the main bill that you want to be cleared.  

Choose the parameters to execute the process: 


Branches button: Used to select the branches that will be considered for clearing.

With the data from the bill to be cleared, we can choose the amount to be cleared as the clearing limit, and also the date of the posting. 

The "Selected Bills" flag can facilitate the process by already selecting the bills according to the balance composition until the balance of the main bill is reached. 

Note: in some situations, due to the way the tax calculation is configured, the initial suggestion ("Selected Bills") is not performed by the system, leaving it up to the operator to select manually so that the tax calculation can be made at runtime. 


After the screen is displayed, the following options are available: 

  • Individual selection of each bill, and this consists of the balance of the bill to confirm or not the selection of the record. Using this option, the system automatically suggests how much the selected bill can be posted according to the balance of the main bill.



Important!

Values will be shown in the PIS, COFINS, CSLL, and Income Tax columns only when the corresponding withholding configuration is in the posting. 



Clearing with Contracted Rate 

Parameters involved:

MV_CMTXCON =Indicates that monetary correction will be generated for bills with contracted rate in CP clearing.  T = Generate / F = Do not generate

For the process of clearing with Contracted Rate, the parameter must be configured as follows:


MV_CMTXCON = T (True)

The monetary correction will start from the selected document:

If the advance payment (RA) bill is selected, the invoice bills will suffer monetary correction based on the rate of the selected RA bill.

If the invoice bill is selected, the advance payment (RA's) bills will suffer monetary correction based on the rate of the selected invoice bill.

MV_CMTXCON = F (False)

No monetary correction will be generated and clearing with different contracted rates will not be allowed.


Important

For the rate entered at the moment of clearing to be considered, when bills with contracted rates exist, the parameter MV_CMTXCON must have its content equal to .T. (True)


Example:

Invoice:

Value: 1,000.00

Currency: 2

Rate: 2

Converted Value: 2,000.00


Advance:

Value: 1,000.00

Currency: 2

Rate: 2.5

Converted Value: 2,500.00


Performing the clearing from the Invoice, we will have the following recordings in table SE5:

E5_TIPO

E5_VALOR

E5_VLMOED2

E5_TXMOEDA

E5_TIPODOC

Invoice

1000

2000

2

CP

RA

1000

2000

2

BA

RA

-500

-250

2

CM


Performing the clearing from the Advance Payment, we will have the following recordings in table SE5:

E5_TIPO

E5_VALOR

E5_VLMOED2

E5_TXMOEDA

E5_TIPODOC

RA

1000

2500

2.5

BA

Invoice

1000

2500

2.5

CP

Invoice

500

200

2.5

CM


Example of automatic clearing using the rates above:


Automatic Clearing Contracted Rate
#INCLUDE "TOTVS.ch"
#Include "PROTHEUS.ch"    
#Include "PRTOPDEF.CH"
#INCLUDE "TBICONN.CH" 

User FUNCTION COMPCR()

    Local lRetOK := .T.
    Local aArea := GetArea()
    Local nTaxaCM := 0
    Local aTxMoeda := {}
    Local cCliente := "001   "
    Local cLoja := "01"
    Local cPrefixo := "TIT"
    Local cNumDoc := '00001    '
    Local cParcela := " "
    Local cTipoDoc := "RA "
    Private nRecnoNDF
    Private nRecnoE1

    dbSelectArea("SE1")
    dbSetOrder(2) // E1_FILIAL, E1_CLIENTE, E1_LOJA, E1_PREFIXO, E1_NUM, E1_PARCELA, E1_TIPO, R_E_C_N_O_, D_E_L_E_T_

    IF dbSeek(XFILIAL("SE1") + cCliente + cLoja + cPrefixo + cNumDoc + cParcela + cTipoDoc)
        nRecnoRA := RECNO() 

        cTipoDoc := "NF"
        IF dbSeek(XFILIAL("SE1") + cCliente + cLoja + cPrefixo + cNumDoc + cParcela + cTipoDoc)
            nRecnoE1 := RECNO()
            
            PERGUNTE("AFI340",.F.)
            lContabiliza := .F.
            lAglutina := .F.
            lDigita := .F.

            SE1->(dbSetOrder(1)) //E1_FILIAL+E1_PREFIXO+E1_NUM+E1_PARCELA+E1_TIPO+E1_FORNECE+E1_LOJA
            aRecRA := { nRecnoRA }
            aRecSE1 := { nRecnoE1 }

            nSaldoComp := 2000 // Clearing value in strong currency

            nTaxaCM := 2 // Rate considered in the clearing

            aAdd(aTxMoeda, {SE1->E1_MOEDA, nTaxaCM} ) // Rates of the currencies used

            If !MaIntBxCR(3, aRecSE1,,aRecRA,,{lContabiliza,lAglutina,lDigita,.F.,.F.,.F.},,,,,nSaldoComp,,,, nTaxaCM, aTxMoeda)
                Help("XAFCMPAD",1,"HELP","XAFCMPAD","Could not perform clearing "+CRLF+" of the advance bill",1,0)
                lRetOK := .F.
            Else
                Alert("Clearing performed.")
            ENDIF
        ENDIF
   ENDIF

   RestArea(aArea)

Return lRetOK
  

The MV_RATXMOV parameter was created to define the rate to be considered for advance payments without contracted rate in the clearing.

The parameter has been incorporated into Protheus release 12.1.27 and made available in the continuous shipments for the previous releases in effect. 


MV_RATXMOV = .T.

When set to true .T., the rate of its inclusion transaction will be considered.

When clearing comes from the advance payment, this rate will be used for listed bills of the same currency.

When clearing comes from the bill, the bill will use the rate of the day or the rate entered at the time of clearing, and listed advances will use their transaction rate.


MV_RATXMOV = .F.

When set to false .F., the rate of the day of clearing or that used at the time of clearing for all the bills involved will be considered.


Specification of parameter:

Parameter name:

MV_RATXMOV

Type:

Logical

Description:

Defines whether the advance payment should use the rate of its transaction for clearing.

.T. Use the transaction / .F. Use the clearing) 

Default Value:

.T.

Rates used and order of priority

Rate of the day (Table SM2): Once the rate of the day has been set for foreign currency bills, this rate will be considered at the time of clearing.

Bill rate (contracted): The rate set at the time of inclusion of the bills (E1_TXMOEDA) is respected in the clearing. When this contracted rate is entered, clearing uses it, even if a currency rate has been configured for the dates involved (Table SM2);

Rate on clearing: This rate can be set by the option Currency Rates, before selecting the bills for clearing.  Even if the bill has a rate of the day (Table SM2) for the currency in question, or a contracted rate (E1_TXMOEDA), the rate defined at the moment of clearing is considered, if entered;


The criterion for rate conversion is the order of rate configuration, being:

1 - Rate on clearing

2 - Bill rate (contracted)

3 - Rate of the day (Table SM2)


Clearing of RA in Dollars with an invoice in Reais.

Day rate of 2.0000 for currency 2 (Dollar) - Inclusion.


RA bill in foreign currency (Dollar):

Invoice bill in strong currency (Reais):


Performing the clearing on a different day than the inclusion:

Rate of the day: 3.0000 for currency 2 (Dollar) - Clearing.


The system considered the rate of the clearing day for the RA. This behavior can be parameterized through the MV_RATXMOV (In this example, the parameter is set to .F.).

SE5 transaction:

The rate of the day of the clearing was used for the transactions, and a monetary correction was generated in relation to the rate used in the inclusion of the RA.

RA cleared value: $ 5,000.00 (Dollar) x Rate of the inclusion (2.0000) = BRL 10,000.00 (Reais)

RA cleared value: $ 5,000.00 (Dollar) x Clearing Rate (3.0000) = BRL 15,000.00 (Reais)

Monetary adjustment: 15,000.00 - 10,000.00 = 5,000.00 (Reais) converting 1,666.67 (Dollar)

Example using contracted rate (E1_TXMOEDA)

Clearing of RA in Dollars with an invoice in Reais.

Rate of the day: 2.0000 for currency 2 (Dollar).

Bill with a contracted rate of 2.5000.


RA bill in foreign currency (Dollar):

Invoice bill in strong currency (Reais):


Performing the clearing on a different day than the inclusion:

Rate of the day: 3.0000 for currency 2 (Dollar) - Clearing.


The system considered the contracted rate for the RA. When the bill has a contracted rate, the clearing uses this, even if a currency rate has been set for the dates involved.

SE5 transaction:

The contracted rate was used in the transactions, in which case no monetary correction is generated because the RA had no variation in its rate.

Example using rate entered on clearing

Clearing of RA in Dollars with an invoice in Reais.

Rate of the day: 2.0000 for currency 2 (Dollar).

Bill with a contracted rate of 2.5000.


RA bill in foreign currency (Dollar):

Invoice bill in strong currency (Reais):


Performing the clearing on a different day than the inclusion:

Rate of the day: 3.0000 for currency 2 (Dollar) - Clearing.

Entering a rate of 3.2000 at the clearing time.


The system considered the rate entered for the RA. When you enter a rate at the time of clearing, the system will use it, even if the bill has a contracted rate (E1_TXMOEDA), or if you have set a currency rate for the dates involved.

SE5 transaction:

The rate entered in the clearing was used for the transactions, and a monetary correction was generated in relation to the rate informed in the clearing and the contracted rate of the bill.

RA cleared value: $ 4687.5 (Dollar) x Contracted Rate (2.5000) = BRL 11,718.75 (Reais)

RA cleared value: $ 4687.5 (Dollar) x Clearing Rate (3.2000) = BRL 15,000.00 (Reais)

Monetary adjustment: 15,000.00 - 11,718.75 = 3,281.25 (Reais) converting 1,025.39 (Dollar)

The commission on CR clearing can be calculated as long as the financial bill (Invoice) is correctly configured with sales representative and percentage, and the questions below are configured with Yes according to the type of bill that will be cleared - NCC or RA.

Calc comiss w/o NCC?

Enter whether the System should calculate commission in compensations with NCC-type bills.

Question = YES - The system calculates commission.

Question = NO - The system does not calculate commission.


Calc comiss w/o RA?

Enter whether the System should calculate commission in compensations with RA-type bills.

Question = YES - The system calculates commission.

Question = NO - The system does not calculate commission.


Parameters

MV_COMISCR -Indicator that allows calculation of commission for sales representative in the CR clearing.  

"S" - calculate it or "N" - do not calculate it.


TABLE FOR POSTING REASONS

In the reasons for posting table (Miscellaneous -> Files), enter the CMP reason and enable the commission calculation in the reason for posting. Example:
Acronym: CMP
Description: Clearing
Portfolio: A (Both)
 Bank Trans.: N
Commission: S
Check: N


Note: In this process, the Sales Representative and Commission Percentage data of the credit instruments (NCC/RA) will not be considered, only of the financial bill (Invoice, RC etc.)


03.  BOOKING


    The accounting for bills with accessory values will be performed as follows: 

    • Clear positioned on the advance

    Cleared invoices are positioned during accounting, allowing accessory values to be accounted for as usual. 

    • Clear positioned in the Invoice with accessory value

    Since it is the invoice that has the accessory value, in the accounting of the first advance payment bill, tables SE1 and SE5 are positioned in the invoice, so that the accessory value is accounted for. 


    Example of accessory value accounting:

    Register an accessory value, filling the "CTB Variable" field with the variable to be used in the standard entry configuration. 

    Example: CTBDESPC

    In the configuration of the standard Clearing Receivables entry, use the variable previously registered in the value to be accounted for.

    In accounting, a row will be generated with the accessory value recorded in the cleared invoice. 


    Scenario:

    Standard Entries configured: 

    1) E5_VALOR

    2) Variable registered in the VA, for example CTBDESPC

    • Clear positioned in the Invoice with accessory value

    Invoice:

    Number: MAN - 03 -Invoice 

    Value: 10,000.00 with VA: 100.00

    Advance:

    1) Number: MAN - 04 - RA

    Value: 5,000.00

    2) Number: MAN - 05 - RA

    Value: 5,000.00

    The two rows displayed in the example below refer to the two cleared advance payments, where the first line refers to the cleared invoice (due to the need to account for the associated accessory value).

     


    • Clear positioned on the advance:

    Invoice:

    Number: MAN - 06 -Invoice 

    Value: 10,000.00 with VA: 100.00

    Advance:

    Number: MAN - 07 - RA

    Value: 10,000.00

    The row displayed in the example below refers to the cleared invoice.



    04.  PARAMETERS

      PCC Calculation

      When setting up PCC withholding on posting without RA withholding control, the preselection of the bills is not performed, so that when the bill is selected, the PCC calculation is performed.

      To use it, set the following parameters:

      • MV_BR10925 = 1
      • MV_RARTIMP = 2 

      Residual value tolerance to zero the balance after clearing (MV_TOLERPG)

      When a remaining balance of cents exists in one of the bills after clearing, you can set up so that the system considers a tolerance margin and posts the bill in its entirety.

      This margin value must be configured through the MV_TOLERPG parameter (the bills receivable postings also perform the same treatment through this parameter).

      This type of situation usually occurs in offsets involving a foreign currency bill against a local/strong currency bill, where it is common for cents to vary due to the rounding of decimal places after the conversion of the values between the currencies (e.g. Dollar x Real). 

      Below is an example of how the routine is impacted by the parameter:

      1. Using the FINA330 routine, a bill of type RA (advance) is selected in dollars. Its value converted to BRL is BRL 1000.05 ;
      2. On the selection screen of bills to be cleared, some bills in reais are selected, totaling BRL 1000.03 (difference of 2 cents in relation to the RA);
      3. For all the bills involved to have their balances reset to zero at the end of the clearing process, the MV_TOLERPG parameter must be set to a value equal to or greater than 00.02 (two cents), otherwise, the remaining difference will remain in the bill balance (which will remain open);

      Other parameters

      MV_ESTADO - must be set to the branch status

      Important!

      The MV_ESTADO parameter must be set as unique per branch, even if the financial tables are shared.

      05. FREQUENTLY ASKED QUESTIONS

      How to consider cash discount in the clearing?

      Financial discounts are not considered by default. In order for them to be considered, it is necessary to use the F330DES entry point. Further information at: F330DESC - Discount on clearing of accounts receivable

      06OTHER DOCUMENTATION