generate/cbs2.gif Credit Limit Check Hook (R-CLIMIT.MAC) generate/enh73.jpg


 

The script file must be located in your CAPITAL program directory and must have the file name R-CLIMIT.MAC. A sample script can be found in your \CAPITAL\MAC directory.

This hook script can be used to control credit limit checking in CAPITAL. Credit limits are checked when invoices and (optionally) sales orders are entered and saved.

Entry Values

Variable

Purpose

AccountBalance

The total balance that exceeds the customer's credit limit.

Amount

The amount of the transaction.

TotalDue

The total amount the customer owes

Custrec->X

You may query the contents of the fields of the customer account, in particular Custrec->Cuscredit. (The customer's credit limit.)

Cuaux000->X

You may query the contents of the customer account's user fields if applicable.

Return Values

The script should return TRUE if the credit limit for the selected account is OK. Return FALSE if the credit limit has been exceeded.

Comments

generate/hint1.gifIf you do not want to also perform a regular credit limit check, suppress the standard credit limit checking feature. For information on how to do this see the topic: Alerts & Messages.

Example #1

* This script sets a global credit limit of $1,000 if an individual

* credit limit rating is not specified for an account

If Custrec->Cuscredit = 0 .And. AccountBalance + Amount >= 1000

   Return False

Endif

Return True

Example #2

* This script checks that the credit limit has not been exceeded &

* also for any overdue transactions that remain unpaid by more than

* $5 dollars. An overdue transaction is defined as a transaction

* that remains unfully paid for twice the customer's terms plus 4

* days. If the transaction & account fail the credit test, then

* prompt for a password to proceed. The password is accepted only

* if the user has level 9 access (administrator level).

Declare lOverLimit Type Logic

Declare cPassword Type Character

Declare aInfo Type Array

lOverLimit := FALSE

* Check to see if account is over it's credit limit if we

* take into consideration this transaction's value

If TotalDue + Amount > Custrec->Cuscredit

   Echo("Accepting this transaction will cause this account to go over it's credit limit.",, TRUE)

   lOverLimit := TRUE

Endif

If lOverLimit

   Goto CheckLimit

Endif

* If OK, now check if any transactions are overdue.

* The Invoice table may not be open in all areas so

* request to open it here

OpenTable("Invoice")

* The 'AALLOC' search only finds transactions that

* are partly or fully unpaid

Invoice->(Find(Custrec->Cuscode, "AALLOC"))

:Loop

   If Invoice->Acccode # Custrec->Cuscode

      Goto CheckLimit

   Endif

   If Invoice->Invtot > 0 .AND. Unpaid() > 5 .AND. Today() - Invoice->Date > (Custrec->Custerms * 2) + 4

      Echo("One or more transactions are overdue for this account.")

      lOverLimit := TRUE

      Goto CheckLimit

   Endif

   Invoice->(Skip())

   Goto Loop

:CheckLimit

* Don't prompt for password if transaction has no value yet.

* Warning above will be sufficient.

If lOverLimit .AND. Amount = 0

   lOverLimit := FALSE

   Goto End

Endif

If lOverLimit

   * Offer password option to unlock

   FormCreate()

   FormAdd("Please Enter Password To Proceed", SPACE(8), "*")

   If FormShow("Password To Override Credit Restriction")

      cPassWord := FormResult(1)

      aInfo := PasswordInfo(cPassWord)

      * Access level 9 is administrator level

      If aInfo[1] == 9

         lOverLimit := FALSE

      Else

         Echo("Sorry, this password is not sufficient to permit approval.",, TRUE)

      Endif

   Endif

Endif

:End

CloseTable()

Return .NOT. lOverLimit

____________________________

Related Topics:

Scripting Hooks

Script Programming



Help Topic Map