MT120OK
MT120OK() --> lRetornoRuns user-specific validations on purchase order items before the process continues.
Overview
MT120OK is an entry point for the Purchase Order / Delivery Authorization routine. It is triggered at the end of A120TudOk(), after confirming the GetDados items and before the purchase order dialog footer. Its return controls whether the process continues: .T. allows it to proceed and .F. interrupts validation.
Syntax
MT120OK() --> lRetornoReturn value
lRetorno, logical. Return .T. to allow the validated items to continue the process. Return .F. to interrupt the process when a user-specific validation rule is not met.
Product, quantity and price validation
#Include "TOTVS.ch"
User Function MT120OK()
Local nProductPos := AScan(aHeader, {|x| AllTrim(x[2]) == "C7_PRODUTO"})
Local nQtyPos := AScan(aHeader, {|x| AllTrim(x[2]) == "C7_QUANT"})
Local nPricePos := AScan(aHeader, {|x| AllTrim(x[2]) == "C7_PRECO"})
Local lValid := .T.
Local nLine := 0
For nLine := 1 To Len(aCols)
If !aCols[nLine][Len(aCols[nLine])] .And. !Empty(aCols[nLine][nProductPos])
If Empty(aCols[nLine][nQtyPos]) .Or. Empty(aCols[nLine][nPricePos])
MsgAlert("Enter quantity and price for product " + aCols[nLine][nProductPos], "Order validation")
lValid := .F.
Exit
EndIf
EndIf
Next nLine
Return lValidThe example locates fields in aHeader, loops through aCols lines and prevents continuation when an entered product has no quantity or price.
Minimum structure
#Include "TOTVS.ch"
User Function MT120OK()
Local lReturn := .T.
// Run additional purchase item validations here.
// Return .F. to interrupt the process.
Return lReturnMinimum structure for creating an additional validation controlled by the logical return of the entry point.
- Use AScan() over aHeader to locate field positions before validation.
- Initialize the return value as .T. and change it to .F. only when a rule fails.
- Use Exit to stop the loop as soon as the first relevant inconsistency is found.
- Show a clear message when validation prevents the process from continuing.
- Test orders with one line, multiple lines, blank lines and lines marked for deletion.
- Do not assume C7_PRODUTO, C7_QUANT and C7_PRECO positions are fixed; locate fields in aHeader before accessing aCols.
- Pay attention to the last position of the aCols line, often used to indicate a marked/deleted browse line.
- Avoid returning .F. without explaining to the user why the process was interrupted.
- Do not run slow processing in this validation without assessing the impact on order confirmation.
- Avoid legacy includes in new code when they are not required; keep only the dependencies needed by the source.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.