BPM Code for Supplier Price List

Following on from last week, I have the code below in a BPM to pick up when we have reached a max order qty from Suppliers against the Price List. Am just not sure if I have the Effective Date criteria in the correct place, and also how I would add criteria against the Expiry Data as it could be filled in or blank. Any advice greatly appreciated. tia


/* Count Order Qtys and Email if Required */

def var totqty as decimal no-undo.
find first ttPODetail where ttPODetail.Company = CUR-COMP and ttPODetail.RowMod <> "" no-lock no-error.

if Available ttPODetail then
DO:
FOR EACH PODetail where PODetail.Company = ttPODetail.Company
and PODetail.VendorNum = ttPODetail.VendorNum
and PODetail.PartNum = ttPODetail.PartNum No-Lock :

Find VendPart where VendPart.Company = ttPODetail.Company
and VendPart.VendorNum = ttPODetail.VendorNum
and VendPart.PartNum = ttPODetail.PartNum
no-lock no-error.

if Available VendPart then

DO:
message "BPM - Found VendPart".
END.

totqty = totqty + PODetail.OrderQty.
message "BPM - found PO Qty" + string(totqty).
END.

DO:
Message "BPM - Found PO Detail".
if (ttPODetail.CalcOurQty + totqty) > VendPart.Number01
and VendPart.EffectiveDate < TODAY
and VendPart.ExpirationDate > TODAY
then
DO:
{lib/PublishInfoMsg.i
&InfoTable = "'PO.Update'"
&InfoMsg = "'The Supplier Price List for the following Supplier / Part has a Maximum Order Quantity which has now been reached.'"}

/* EMAIL CODE */

/* INITIALIZE VARIABLES */
define variable mFrom as character no-undo initial 'EmailAddress':U.
define variable mTo as character no-undo initial '':U.
define variable mCc as character no-undo initial '':U.
define variable mSubject as character no-undo initial '':U.
define variable mBody as character no-undo initial '':U.
define variable mhEmailProc as handle no-undo.

run Bpm/BpmEmail.p persistent set mhEmailProc.

find first ttPODetail where ttPODetail.Company = cur-comp and ttPODetail.RowMod <> '' no-error.
If Available ttPODetail then do:

/* Build Email Here */
mTo = 'EmailAddress'.
mSubject = 'Vantage Alert - Max PO Qty Reached'.
mBody = 'The Supplier Price List for the following Supplier / Part has a Maximum Order Quantity which has now been reached on PO ' + string (ttPODetail.PONUM) + '. Please expire this price and create a new one for further Purchase Orders. Supplier: ' + string (ttPOHeader.VendorVendorID) + ' / Part Number: ' + string (ttPODetail.PartNum) + '.'.

/* SEND EMAIL */
run SendEmail in mhEmailProc (false,CUR-COMP,mFrom,mTo,mCc,mSubject,mBody,"":U).
if valid-handle(mhEmailProc) then delete procedure mhEmailProc.
leave.
end.


END.

END.

END.