Hello everyone,
I have a function which receive 3 parameters CustomerNo, Year and Month.
I have to search on Contract Line Table and check if that Month and Year correspond to one of the contract lines.
What I did so far
AfisareContract(pCustomerNo : Code[20];pYear : Integer;pMonth : Integer;VAR pContractNo : Code[20];VAR pContractLine : Integer)
ContractHeader.SETRANGE("Customer No.",pCustomerNo);
IF ContractHeader.FINDFIRST THEN
ContractLine.SETRANGE("Contract No.",ContractHeader."No.");
IF ContractLine.FINDSET THEN
REPEAT
StartYear := DATE2DMY(ContractLine."Starting Date",3);
EndYear := DATE2DMY(ContractLine."Ending Date",3);
StartMonth := DATE2DMY(ContractLine."Starting Date",2);
EndMonth := DATE2DMY(ContractLine."Ending Date",2);
IF ((pYear >= StartYear) AND (pYear <= EndYear)) AND ((pMonth >= StartMonth) AND (pMonth <= EndMonth)) THEN BEGIN
pContractNo := ContractLine."Contract No.";
pContractLine := ContractLine."Line No.";
END;
UNTIL ContractLine.NEXT = 0;
For the year I think is correct how I did but is not for the Month.
How can I correctly search for the month and year and return the related contract line ??
Thank you
0
Answers
I would try to do something like following.
ContractHeader.SETRANGE("Customer No.",pCustomerNo);
IF ContractHeader.FINDFIRST THEN
BEGIN
ContractLine.SETRANGE("Contract No.",ContractHeader."No.");
ContractLine.SETRANGE("Starting Date",0D,pDate);
ContractLine.SETFILTER("Ending Date",'%1|>=%2',0D,pDate);
IF NOT ContractLine.ISEMPTY THEN
DO Stuff...
RIS Plus, LLC
MVP - Business Apps
Yes or just use the first date of the month....Or if possible change the logic that calls the function to use actual date instead of month/year, if in the future you want to let contracts expire on specific date instead of month