This routine was adjusted to comply with the General Personal Data Protection Law (LGPD law No. 13.70), so that some fields containing data regarded as sensitive and/or personal are blurred, becoming illegible. |
This routine clears all advances made and registered by the Suppliers (PA bills type), in addition to the credit notes to be deducted (NDF bills type).
The advances selected and entered by the user are deducted from the total amount of the original bill.
Procedure manually performed through routine Accounts Payable Clearing (FINA340), with the display of the screens involved in the process - actions/commands from the user are required
Procedure automatically performed in routine Accounts Payable Clearing (FINA340) without the display of screen - no interaction from the user required.
Used in customizations in which the process does not required user's interactions (MSEXECAUTO)
#INCLUDE "Protheus.ch" #INCLUDE "RWMAKE.CH" #INCLUDE "TBICONN.CH" Static __COMPAUT := Nil User Function CMPAUTOMA() Local lRet := .F. Local cQry := "" Local aTipos := {"NF ", "PA ", "NDF"} Local cTblTmp := "" Local aNF := {} Local aPA_NDF := {} Local aContabil := {} Local bBlock := Nil Local aEstorno := {} Local nSldComp := 0 Local nTaxaPA := 0 Local nTaxaNF := 0 Local nHdl := 0 Local nOperacao := 0 If __COMPAUT == Nil cQry := "SELECT E2_TIPO TIPO, R_E_C_N_O_ R_E_C_N_O FROM " + RetSqlName("SE2") + " " cQry += "WHERE E2_SALDO > 0 AND E2_TIPO IN " cQry += "ORDER BY E2_TIPO" cQry := ChangeQuery(cQry) __COMPAUT := FWPreparedStatement():New(cQry) EndIf __COMPAUT:SetIn(1, aTipos) cQry := __COMPAUT:GetFixQuery() cTblTmp := MpSysOpenQuery(cQry) While (cTblTmp)->(!Eof()) If (cTblTmp)->TIPO $ MVPAGANT+"|"+MV_CPNEG Aadd(aPA_NDF, (cTblTmp)->R_E_C_N_O) Else Aadd(aNF, (cTblTmp)->R_E_C_N_O) EndIf (cTblTmp)->(DbSkip()) lRet := .T. EndDo (cTblTmp)->(DbCloseArea()) cTblTmp := "" If lRet Pergunte("AFI340", .F.) lContabiliza := MV_PAR11 == 1 lAglutina := MV_PAR08 == 1 lDigita := MV_PAR09 == 1 lRet := FinCmpAut(aNF, aPA_NDF, aContabil, bBlock, aEstorno, nSldComp, dDatabase, nTaxaPA ,nTaxaNF, nHdl, nOperacao) If lRet Alert("Compensation successful") Else Alert("An error occurred in the compensation process") EndIf EndIf Return |
To use the Automatic Accounts Payable Compensation process, call the function: FinCmpAut. Clearing can be carried out from N to N: N advances/returns (PA or NDF) for N bills (NF, DP, etc.) or vice versa. |
Use this operation to clear bills payable:
- Clearing bills from a supplier/store with advances from the same supplier/store
- Clearing bills from a given supplier with advances from the same supplier regardless of the bill receivable store
- Clear a bill from a given supplier with advances from several suppliers, in which case a supplier range or all suppliers can be established. Then, the bill can be cleared with any advance bill from the same supplier pending in the bill file, irrespective of the supplier for this bill.
The Clearing Date must be after the date of issue of the bills involved. For example:
You can only clear these bills after 4/02, considering that on 3/29 the NF did not yet exist, so the postings concept is correctly applied to clearing operations. (E2_Posting after E2_ISSUE)
For clearance between advances and bills from different branches, use button Branches to define which branches to consider for selection of bills to clear.If you do not use button Branches, only bills of the current branch are considered for clearing.
|
Operation to delete the transaction generated by the clearing
Operation that allows reversing the transaction generated by clearing, thus generating its counterpart.
It displays the caption chart and meanings related to bill payable status.
Search for the bill in the accounts payable file, having it placed and highlighted in the browser.
Operation to view the bill selected and check its balance and value.
List of parameters applied to FINA340 and its processing
|
The booking of processes applied to an accounts payable clearing via Financials module is done through the standard entries below:
SE | Taxable Event | ON | OFF (CTBAFIN) |
---|---|---|---|
589 | Cancellation of clearing of accounts payable bills | X | X |
597 | Clearing of accounts payable | X | X |
Booking of DIC type The booking of DIC type generated by clearing can be done by LP 510 - Addition of Bill Payable, because it is generated through the FINA050 (Accounts Payable) automatic routine. Booking of taxes generated when clearing. LP 597 - Clearing Payable itself can book taxes generated by clearing, through variables: NPIS340, NCOF340, NCSL340, NIRF340, NISS340. In the other cases, the booking remains unchanged, as documented below: |
Entry point | Note |
F340BROW | Entry point F340BROW is called before the browser, which you can use to handle the data displayed by the browser. |
F340LIBT | The entry point indicates whether to validate the bill release when clearing. |
F340DTFIN | PE is called in MV_DATAFIN parameter validations found in CP Clearing. |
F340TAXA | In this entry point you can change the currency rates used when clearing accounts payable. |
F340ATLIS | Use this entry point to handle the aTitulos Array, to change the listBox of the clearing screen.Document: {+}http://tdn.totvs.com/x/gKRc+ |
F340TOTCP | Use entry point F340TOTCP() to handle the total values of bills to be cleared. |
F340MKTIT | Use entry point F340MKTIT to customize bills already selected in the markbrowse. You can handle an array that contains the bills and, with its 8th occurrence, containing a logical value that indicates whether the bill is selected or not.Document:{+}http://tdn.totvs.com/x/L6Rc+ |
F340NAT | |
F340_PA | Entry point F340_PA is executed after booking each clearance payable bill. |
F340SE5 | Entry point F340SE5 handles Processed Bank Transactions with parameter Recno of records SE5 used in Clearing. |
F340GRV | Entry point F340GRV validates the addition in routine Accounts Payable Clearing (FINA340) |
F340ACAN | Use this entry point to create a rule to enter when the Reversal will occur, or not. |
F340CAN | Entry Point called upon confirmation of clearance reversal. |
F340GREST | Recording of additional data in clearance reversal |
F340FCAN | Use this entry point to save complementary data when reversing the clearance. |
FA340QRY | Query complement for cancellation of clearance |
FA340FILT | Run entry point FA340FILT when assembling the table of bills to clear and use it to select which bills you will clearDocument: {+}http://tdn.totvs.com/x/rqNc+ |
F340CMP | Use this entry point to calculate the NDF or PA bill. It is called in function Fa340Tit() |
FA340ORD | Use this Entry Point to edit the index, changing the order of bills displayed on the markbrowse for clearing payableDocument: {+}http://tdn.totvs.com/x/r6Nc+ |
F340ValOk | Entry point F340ValOk allows controlling data and confirming the payable bills clearing screenDocument: {+}http://tdn.totvs.com/x/fKVc+ |
F340TOTCP | Use this entry point to handle the total values of bills to be cleared. |
F340VLD | Use this entry point to validate whether a bill will be cleared or not.Document: {+}http://tdn.totvs.com/x/J6Vc+ |
F340LEGE | |
SE5FI340 | Use this Entry Point to make complementary recordings in table SE5, after recording the bank transaction of the main bill in automatic clearing payableDocument: {+}http://tdn.totvs.com/x/56Rc+ |
SE5FI341 | Use this Entry Point to make complementary recordings in table SE5, after recording the bank transaction of the Advance bill in automatic clearing payable.Document: {+}http://tdn.totvs.com/x/6KRc+ |
F340GERNDF | Use this to save additional fields when adding the NDF generated by the clearing payable. |
FA340NDFGrv | |
F340FLCP | Use this to implement a complementary expression in the bills filter. |
F340FCPTOP | Use this entry point to create a new filter for the routine Accounts Payable Clearing - FINA340. |
|
Cleared Taxes Difference
Accumulated DIC
Attention
The process described refers only to the net scenario:
MV_PABRUTO = 2 (Net)MV_COMPCP = .T.MV_BP10925 = 2MV_PAPRIME = 1
For gross scenario, clearings occur without generation of accumulated DIC.
Accumulated DIC
When clearing a NF that has withholding in posting with multiple advance payments not configured for withholding, a single bill of type DIC is generated for the last cleared PA. The DIC will have the accumulated value of the difference of calculated taxes of the other PAs.
Example: Clearing between one 3 PAs without withholding X 1 NF with withholding
NF of BRL 1,000.00
With PCC in posting (4.65%) = BRL 46.50
Total Net Value = BRL 1,000.00 (value of NF) - BRL 46.50 (taxes in posting) = BRL 953.50
NF balance = BRL 1,000.00
PA 1 of BRL 300.00
Without taxes
Net Value = BRL 300.00
PA balance = BRL 300.00
PA 2 of BRL 300.00
Without taxes
Net Value = BRL 300.00
PA balance = BRL 300.00
PA 3 of BRL 300.00
Without taxes
Net Value = BRL 300.00
PA balance = BRL 300.00
The routine performs the clearing calculation internally in three parts, as if it was clearing each PA separately, generating the DIC only in the last clearing.
1st clearing - Clear NF x PA:
NF balance = BRL 1,000.00 (NF balance) - BRL 13.95 (PCC generated in clearing) - BRL 286.05 (cleared value) = 700.00
Transaction: BRL 300.00
Generated the taxes configured in posting, in example, PCC in value of BRL 13.95 with calculation base of BRL 300.00
PA balance = 300.00 (PA balance) - 300.00 (cleared value) = 0.00
Value related to Difference of calculated tax: 13.95
{}Important*
As previously mentioned, the DIC is not generated at this time.
2nd clearing - Clear NF x PA:
NF balance = BRL 700.00 (NF balance) - BRL 13.95 (PCC generated in clearing) - BRL 286.05 (cleared value) = 400.00
Transaction: BRL 300.00
Generated the taxes configured in posting, in example, PCC in value of BRL 13.95 with calculation base of BRL 300.00
PA balance = 300.00 (PA balance) - 300.00 (cleared value) = 0.00
Value related to difference of calculated tax: 13.95
*Important
As previously mentioned, the DIC is not generated at this time.
3rd clearing - Clear NF x PA:
NF balance = BRL 400.00 (NF balance) - BRL 13.95 (PCC generated in clearing) - BRL 286.05 (cleared value) = 100.00
Transaction: BRL 300.00
Generated the taxes configured in posting, in example, PCC in value of BRL 13.95 with calculation base of BRL 300.00
PA balance = 300.00 (PA balance) - 300.00 (cleared value) = 0.00
Value related to Difference of calculated tax: 13.95
Important
The DIC is only generated at this time. In accumulated value of 41.85.
Generated DIC value = 13.95 (DIC calculated in 1st clearing) + 13.95 (DIC calculated in 2nd clearing) + 13.95 (DIC calculated in 3rd clearing) = 41.85
Total clearing without DIC generation
Attention
The process described refers only to the net scenario:
MV_PABRUTO = 2 (Net)
MV_COMPCP = .T.
MV_BP10925 = 2
MV_PAPRIME = 1
Total clearing without DIC generation
When clearing a NF that has withholding with PAs without withholding, in which the net value of NF is the total of PAs, the routine does not generate DIC.
Example: Total clearing between one 2 PAs without tax X NF with taxes
NF of BRL 1,000.00
With PCC in Posting (4.65%) = BRL 46.50
Total Net Value = BRL 1,000.00 (value of NF) - BRL 46.50 (taxes in posting) = BRL 953.50
NF balance = BRL 1,000.00
PA of BRL 500.00
Without taxes
Net Value = BRL 500.00
PA balance = BRL 500.00
PA of BRL 453.50
Without taxes
Net Value = BRL 453.50
PA balance = BRL 453.50
Clear 1 NF x 2 PAs
Notice the net value of invoice is equal to the sum of PAs, thus no additional value was paid to the supplier:
The withholdings set to be calculated in posting will be generated. In the example, PCC in the value of BRL 23.25 related to the first clearing.
The withholdings set to be calculated in posting will be generated. In the example, PCC in the value of BRL 23.25 related to the second clearing.
NF balance = BRL 1,000.00 (NF balance) - BRL 23.25 (PCC Generated in 1st clearing) - BRL 23.25 (PCC Generated in 2nd clearing) - BRL 500,00 (cleared value of 1st PA) - BRL 453.50 (cleared value of 2nd PA)
1st PA balance = 500.00 (PA balance) - 500.00 (cleared value) = 0.00
PA balance = 453.50 (PA balance) - 453.00 (cleared value) = 0.00
We have no DIC generation
Example: Reversal of 2nd clearing (2nd PA).
When reversing 2nd clearing (2nd PA):
The withholdings generated will be deleted upon clearing. In the example, PCC in the value of BRL 23.25
NF balance = 500.00
PA balance = 453.50
The system evaluates the clearings previous to the last one reversed and identifies whether a new DIC generation is needed.
Generated DIC value = 23.25 (DIC calculated in 1st clearing) = 23.25
The DIC bill generated refers to the last clearing. In the above example it would be the 1st PA in the value of 500.
Attention
For clearings done individually (1 PA x 1 NF), the system generates an independent DIC, that is, one DIC for each clearing. No accumulated DIC will be generated
DIC Booking
DIC Booking
You can book the addition of a DIC type bill through LP 510 (Accounts Payable - Addition of Bills).
You can book the deletion of a DIC type bill through LP 515 (Accounts Payable - Deletion of Bills).
Note: To book the LPs 510 and 515, the question: Book Online of routine Accounts payable (FINA050) must be set to Yes.
DIC generation at time of reversal
Attention
The process described refers only to the net scenario:
MV_PABRUTO = 2 (Net)
MV_COMPCP = .T.
MV_BP10925 = 2
MV_PAPRIME = 1
Process of DIC generation at time of reversal
For clearances with more than one bill, you can only revert/delete by clearing order. From the last clearing to the first, any different order of this routine will display a warning blocking the process.
When you reverse/delete the last clearing, the routine also deletes the DIC-type bill. After this process, a new DIC related to previous clearings is generated based on the last cleared PA if needed.
Example: Reversal of 3rd clearing
NF balance = BRL 100.00 (NF balance) + BRL 13.95 (PCC generated in clearing) + BRL 286.05 (compensated value) = 400.00
Transaction: BRL 300.00
Withholdings generated by clearing will be deleted. In example, PCC in value of BRL 13.95 with calculation base of BRL 300.00
Deletion of DIC generated by clearing with value of BRL 41.85 (accumulated DIC).
PA balance = 0.00 (PA balance) + 300.00 (cleared value) = 300.00
The system evaluates the clearings previous to the last one reversed and identifies whether a new DIC generation is needed.
Generated DIC value = 13.95 (DIC calculated in 1st clearing) + 13.95 (DIC calculated in 2nd clearing) = 27.90
At this point, a new DIC-type bill is generated related to the first and second clearing.
Example: Reversal of 2nd clearing
NF balance = BRL 400.00 (NF balance) + BRL 13.95 (PCC generated in clearing) + BRL 286.05 (compensated value) = 700.00
Transaction: BRL 300.00
Withholdings generated by clearing will be deleted. In example, PCC in value of BRL 13.95 with calculation base of BRL 300.00
Deletion of DIC generated by reversal with value of BRL 27.90 (accumulated DIC)
PA balance = 0.00 (PA balance) + 300.00 (cleared value) = 300.00
The system evaluates the clearings previous to the last one reversed and identifies whether a new DIC generation is needed.
Generated DIC value = 13.95 (DIC calculated in 1st clearing) = 13.95
At this point, a new DIC bill related to the last clearing is generated. In the example above, it would be the 1st PA with the value of 300.
See Also