Thursday, January 3, 2019

Field formula

Component string &PROJECT_CMP_FLG, &ACTIVITY_CMP_FLG, &TEAM_MEM_FLG, &PC_BUD_PLAN_FLG, &PC_BUD_DETAIL_FLG;
Component array &Project, &StartDt, &EndDt;
Component number &arr;

rem Function DataValidation(&REC2 As Record, &P_Start_Dt1 As string, &P_End_dt1 As string) Returns string;
REM Function DataValidation(&REC2 As Record) Returns string;
Function DataValidation(&REC2 As Record, &Project As array, &StartDt As array, &EndDt As array, &arr As number) Returns string;
 
 
   &P_Start_Dt = &REC2.START_DT.Value;
   &P_End_dt = &REC2.END_DT.Value;
   &A_Start_Dt = &REC2.START_DT_2.Value;
   &A_End_Dt = &REC2.END_DT_2.Value;
   &T_Start_Dt = &REC2.NTT_START_DT.Value;
   &T_End_Dt = &REC2.NTT_END_DT.Value;
   &BP_Start_Dt = &REC2.NTT_START_DT1.Value;
   &BD_Budget_Item = &REC2.NTT_PC_BUDGET_ITEM.Value;
 
 
 
   &AP_Exist = "FALSE";
   &TP_Exist = "FALSE";
   &BPP_Exist = "FALSE";
   &BDP_Exist = "FALSE";
 
   &Validation_String = "";
 
   If &PROJECT_CMP_FLG = "Y" Then
      SQLExec("Select %Dateout(START_DT), %Dateout(END_DT) from PS_PROJECT where BUSINESS_UNIT = :1 AND PROJECT_ID = :2", &REC2.BUSINESS_UNIT.Value, &REC2.PROJECT_ID.Value, &START_DT, &END_DT);
      If All(&START_DT) And
            All(&END_DT) Then
         &Validation_String = &Validation_String | Char(13) | Char(10) | "Project ID already Exists in the System  - Project Info Tab.";
      End-If;
   End-If;
 
   If &ACTIVITY_CMP_FLG = "Y" Then
      SQLExec("Select Count(*) from PS_PROJ_ACTIVITY where BUSINESS_UNIT = :1 AND PROJECT_ID = :2 AND ACTIVITY_ID = :3", &REC2.BUSINESS_UNIT.Value, &REC2.NTT_PC_PROJECT_ID1.Value, &REC2.ACTIVITY_ID.Value, &A_COUNT);
      If &A_COUNT > 0 Then
         &Validation_String = &Validation_String | Char(13) | Char(10) | "Activity ID: " | &REC2.ACTIVITY_ID.Value | "  already exists in the System for Project ID: " | &REC2.NTT_PC_PROJECT_ID1.Value | " - Activity Info Tab.";
      End-If;
   End-If;
 
   If &TEAM_MEM_FLG = "Y" Then
      SQLExec("Select Count(*) from PS_PROJECT_TEAM where BUSINESS_UNIT = :1 AND PROJECT_ID = :2 AND TEAM_MEMBER = :3", &REC2.BUSINESS_UNIT.Value, &REC2.NTT_PC_PROJECT_ID2.Value, &REC2.TEAM_MEMBER.Value, &T_COUNT);
      If &T_COUNT > 0 Then
         &Validation_String = &Validation_String | Char(13) | Char(10) | "Team Member: " | &REC2.TEAM_MEMBER.Value | "  already exists in the System for Project ID: " | &REC2.NTT_PC_PROJECT_ID2.Value | " - Team Info Tab.";
      End-If;
   End-If;
 
   If &PC_BUD_PLAN_FLG = "Y" Then
      SQLExec("Select Count(*) from PS_PC_BUD_PLAN where BUSINESS_UNIT = :1 AND PROJECT_ID = :2 AND PC_BUDGET_ID = :3", &REC2.BUSINESS_UNIT.Value, &REC2.NTT_PC_PROJECT_ID3.Value, &REC2.PC_BUDGET_ID.Value, &BP_COUNT);
      If &BP_COUNT > 0 Then
         &Validation_String = &Validation_String | Char(13) | Char(10) | "Budget Plan ID: " | &REC2.PC_BUDGET_ID.Value | "  already exists in the System for Project ID: " | &REC2.NTT_PC_PROJECT_ID3.Value | " - Budget Plan Tab.";
      End-If;
   End-If;
 
   If &PC_BUD_DETAIL_FLG = "Y" Then
      SQLExec("Select Count(*) from PS_PC_BUD_DETAIL where BUSINESS_UNIT = :1 AND PROJECT_ID = :2 AND PC_BUDGET_ID = :3 AND  ACTIVITY_ID = :4 AND PC_BUDGET_ITEM = :5", &REC2.BUSINESS_UNIT.Value, &REC2.NTT_PC_PROJECT_ID4.Value, &REC2.PC_BUDGET_ID_TMP.Value, &REC2.NTT_ACTIVITY_ID_3.Value, &REC2.NTT_PC_BUDGET_ITEM.Value, &BD_COUNT);
      If &BD_COUNT > 0 Then
         &Validation_String = &Validation_String | Char(13) | Char(10) | "Project Budget Item: " | &REC2.NTT_PC_BUDGET_ITEM.Value | "  already exists in the System for Project: " | &REC2.NTT_PC_PROJECT_ID4.Value | " Activity: " | &REC2.NTT_ACTIVITY_ID_3.Value | " and Budget Plan: " | &REC2.PC_BUDGET_ID_TMP.Value | " combination  - Budget Detail Tab.";
      End-If;
   End-If;
 
 
   If &ACTIVITY_CMP_FLG = "Y" Then
      SQLExec("Select %Dateout(START_DT), %Dateout(END_DT) from PS_PROJECT where BUSINESS_UNIT = :1 AND PROJECT_ID = :2", &REC2.BUSINESS_UNIT.Value, &REC2.NTT_PC_PROJECT_ID1.Value, &START_DT, &END_DT);
      &PA_Start_Dt = &START_DT;
      &PA_End_dt = &END_DT;
      &A_Project_ID = &REC2.NTT_PC_PROJECT_ID1.Value;
      If All(&PA_Start_Dt) And
            All(&PA_End_dt) Then
         &AP_Exist = "TRUE";
      Else
         rem &Validation_String = &Validation_String | Char(13) | Char(10) | "Project ID: " | &REC2.NTT_PC_PROJECT_ID1.Value | " does not exist in the System. Please choose a valid Project ID from the Prompt - Activity Info Tab.";
         &AP_Exist = "FALSE";
       
         For &P1 = 1 To &arr - 1
            If &REC2.NTT_PC_PROJECT_ID1.Value = &Project [&P1] Then
               &AP_Start_Dt = String(&StartDt [&P1]);
               &AP_End_Dt = String(&EndDt [&P1]);
            End-If;
         End-For;
      End-If;
   End-If;
 
   If &TEAM_MEM_FLG = "Y" Then
      SQLExec("Select %Dateout(START_DT), %Dateout(END_DT) from PS_PROJECT where BUSINESS_UNIT = :1 AND PROJECT_ID = :2", &REC2.BUSINESS_UNIT.Value, &REC2.NTT_PC_PROJECT_ID2.Value, &START_DT, &END_DT);
      &PT_Start_Dt = &START_DT;
      &PT_End_dt = &END_DT;
      &T_Project_ID = &REC2.NTT_PC_PROJECT_ID2.Value;
      If All(&PT_Start_Dt) And
            All(&PT_End_dt) Then
         &TP_Exist = "TRUE";
      Else
         rem  &Validation_String = &Validation_String | Char(13) | Char(10) | "Project ID: " | &REC2.NTT_PC_PROJECT_ID2.Value | " does not exist in the System. Please choose a valid Project ID from the Prompt - Team Info Tab.";
         &TP_Exist = "FALSE";
         For &P1 = 1 To &arr - 1
           
            If &REC2.NTT_PC_PROJECT_ID2.Value = &Project [&P1] Then
               &TP_Start_Dt = String(&StartDt [&P1]);
               &TP_End_Dt = String(&EndDt [&P1]);
            End-If;
         End-For;
      End-If;
   End-If;
 
   If &PC_BUD_PLAN_FLG = "Y" Then
      SQLExec("Select %Dateout(START_DT), %Dateout(END_DT) from PS_PROJECT where BUSINESS_UNIT = :1 AND PROJECT_ID = :2", &REC2.BUSINESS_UNIT.Value, &REC2.NTT_PC_PROJECT_ID3.Value, &START_DT, &END_DT);
      &PBP_Start_Dt = &START_DT;
      &PBP_End_dt = &END_DT;
      &BP_Project_ID = &REC2.NTT_PC_PROJECT_ID3.Value;
      If All(&PBP_Start_Dt) And
            All(&PBP_End_dt) Then
         &BPP_Exist = "TRUE";
      Else
         rem &Validation_String = &Validation_String | Char(13) | Char(10) | "Project ID: " | &REC2.NTT_PC_PROJECT_ID3.Value | " does not exist in the System. Please choose a valid Project ID from the Prompt - Budget Plan Tab.";
         &BPP_Exist = "FALSE";
         For &P1 = 1 To &arr - 1
           
            If &REC2.NTT_PC_PROJECT_ID3.Value = &Project [&P1] Then
               &BPP_Start_Dt = String(&StartDt [&P1]);
               &BPP_End_Dt = String(&EndDt [&P1]);
            End-If;
         End-For;
      End-If;
   End-If;
 
   If &PC_BUD_DETAIL_FLG = "Y" Then
      SQLExec("Select %Dateout(START_DT), %Dateout(END_DT) from PS_PROJECT where BUSINESS_UNIT = :1 AND PROJECT_ID = :2", &REC2.BUSINESS_UNIT.Value, &REC2.NTT_PC_PROJECT_ID4.Value, &START_DT, &END_DT);
      &PBD_Start_Dt = &START_DT;
      &PBD_End_dt = &END_DT;
      &BD_Project_ID = &REC2.NTT_PC_PROJECT_ID4.Value;
      If All(&PBD_Start_Dt) And
            All(&PBD_End_dt) Then
         &BPD_Exist = "TRUE";
      Else
         rem  &Validation_String = &Validation_String | Char(13) | Char(10) | "Project ID: " | &REC2.NTT_PC_PROJECT_ID4.Value | " entered does not exist in the System. Please choose a valid Project ID from the Prompt - Budget Detail Tab.";
         &BPD_Exist = "FALSE";
         For &P1 = 1 To &arr - 1
           
            If &REC2.NTT_PC_PROJECT_ID4.Value = &Project [&P1] Then
               &BDP_Start_Dt = String(&StartDt [&P1]);
               &BDP_End_Dt = String(&EndDt [&P1]);
            End-If;
         End-For;
      End-If;
   End-If;
 
   rem End-If;
 
 
   If &PROJECT_CMP_FLG = "Y" Then
      If &P_Start_Dt > &P_End_dt Then
         &Validation_String = &Validation_String | Char(13) | Char(10) | "Project End Date should not be earlier than Project Start Date: " | &P_Start_Dt | " - Project Info Tab.";
      End-If;
   End-If;
 
   If &ACTIVITY_CMP_FLG = "Y" And
       
         (All(&A_Start_Dt) Or
            All(&A_End_Dt)) Then
      If &A_Start_Dt > &A_End_Dt Then
         &Validation_String = &Validation_String | Char(13) | Char(10) | "Activity End Date should not be earlier than Activity Start Date: " | &A_Start_Dt | " - Activity Info Tab.";
      End-If;
     
      REM   If &PROJECT_CMP_FLG = "Y" Then;
      If &AP_Exist = "FALSE" Then
       
       
         If All(&AP_Start_Dt) And
               All(&AP_End_Dt) Then
            If &A_Start_Dt < &AP_Start_Dt Then
               &Validation_String = &Validation_String | Char(13) | Char(10) | "Activity Start Date should not be earlier than Project Start Date: " | &AP_Start_Dt | " - Activity Info Tab.";
            End-If;
           
            If &A_End_Dt > &AP_End_Dt Then
               &Validation_String = &Validation_String | Char(13) | Char(10) | "Activity End Date should not be after the Project End Date: " | &AP_End_Dt | " - Activity Info Tab.";
            End-If;
         Else
            &Validation_String = &Validation_String | Char(13) | Char(10) | "Invalid Project ID: " | &A_Project_ID | " in Activity Info Tab.";
         End-If;
       
      Else
         If &A_Start_Dt < &PA_Start_Dt Then
            &Validation_String = &Validation_String | Char(13) | Char(10) | "Activity Start Date should not be earlier than Project Start Date: " | &PA_Start_Dt | " - Activity Info Tab.";
         End-If;
       
       
         If &A_End_Dt > &PA_End_dt Then
            &Validation_String = &Validation_String | Char(13) | Char(10) | "Activity End Date should not be after the Project End Date: " | &PA_End_dt | " - Activity Info Tab.";
         End-If;
       
      End-If;
   End-If;
 
   If &TEAM_MEM_FLG = "Y" And
         (All(&T_Start_Dt) Or
            All(&T_End_Dt)) Then
     
      If &T_Start_Dt > &T_End_Dt Then
         &Validation_String = &Validation_String | Char(13) | Char(10) | "Team End Date should not be earlier than Team Start Date: " | &T_Start_Dt | " - Team Info Tab.";
      End-If;
     
      REM  If &PROJECT_CMP_FLG = "Y" Then;
      If &TP_Exist = "FALSE" Then
         If All(&TP_Start_Dt) And
               All(&TP_End_Dt) Then
            If &T_Start_Dt < &TP_Start_Dt Then
             
               &Validation_String = &Validation_String | Char(13) | Char(10) | "Team Start Date should not be earlier than Project Start Date: " | &TP_Start_Dt | " - Team Info Tab.";
            End-If;
           
            If &T_End_Dt > &TP_End_Dt Then
             
               &Validation_String = &Validation_String | Char(13) | Char(10) | "Team End Date should not be after the Project End Date: " | &TP_End_Dt | " - Team Info Tab.";
            End-If;
         Else
            &Validation_String = &Validation_String | Char(13) | Char(10) | "Invalid Project ID: " | &T_Project_ID | " in Team Component Tab.";
         End-If;
       
      Else
         If &T_Start_Dt < &PT_Start_Dt Then
           
            &Validation_String = &Validation_String | Char(13) | Char(10) | "Team Start Date should not be earlier than Project Start Date: " | &PT_Start_Dt | " - Team Info Tab.";
         End-If;
       
         If &T_End_Dt > &PT_End_dt Then
            &Validation_String = &Validation_String | Char(13) | Char(10) | "Team End Date should not be after the Project end Date: " | &PT_End_dt | " - Team Info Tab.";
         End-If;
       
      End-If;
   End-If;
 
 
   If &PC_BUD_PLAN_FLG = "Y" And
         All(&BP_Start_Dt) Then
     
      If &BP_Start_Dt < &BPP_Start_Dt Then
       
         &Validation_String = &Validation_String | Char(13) | Char(10) | "Budget Plan Start Date should not be earlier than Project Start Date: " | &BPP_Start_Dt | " - Budget Plan  Tab.";
      End-If;
     
      REM If &PROJECT_CMP_FLG = "Y" Then;
      If &BPP_Exist = "FALSE" Then
         If All(&BPP_Start_Dt) And
               All(&BPP_End_Dt) Then
            If &BP_Start_Dt < &BPP_Start_Dt Then
               &Validation_String = &Validation_String | Char(13) | Char(10) | "Budget Plan Start Date should not be earlier than Project Start Date: " | &BPP_Start_Dt | " - Budget Plan Tab.";
            End-If;
         Else
            &Validation_String = &Validation_String | Char(13) | Char(10) | "Invalid Project ID: " | &BP_Project_ID | " in Budget Plan Tab.";
         End-If;
       
      Else
       
         If &BP_Start_Dt < &PBP_Start_Dt Then
           
            &Validation_String = &Validation_String | Char(13) | Char(10) | "Budget Plan Start Date should not be earlier than Project Start Date: " | &PBP_Start_Dt | " - Budget Plan  Tab.";
         End-If;
       
         If &BP_Start_Dt > &PBP_End_dt Then
            &Validation_String = &Validation_String | Char(13) | Char(10) | "Budget Plan Start Date should not be after Project End Date : " | &PBP_End_dt | " - Budget Plan Tab.";
         End-If;
      End-If;
   End-If;
 
 
   If &PC_BUD_DETAIL_FLG = "Y" And
         All(&BD_Budget_Item) Then
      If &BPD_Exist = "FALSE" Then
         If All(&BDP_Start_Dt) And
               All(&BDP_End_Dt) Then
         Else
            &Validation_String = &Validation_String | Char(13) | Char(10) | "Invalid Project ID: " | &BD_Project_ID | " in Budget Detail Tab.";
         End-If;
      End-If;
   End-If;
 
   &Validation_String = LTrim(RTrim(&Validation_String, Char(13) | Char(10)), Char(13) | Char(10));
 
   Return &Validation_String;
 
End-Function;

No comments:

Post a Comment