Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: PRSPLVU

PRSPLVU.m

Go to the documentation of this file.
  1. PRSPLVU ;WOIFO/SAB - LEAVE UTILITIES ;3/31/2005
  1. ;;4.0;PAID;**93,126**;Sep 21, 1995;Build 59
  1. ;;Per VHA Directive 2004-038, this routine should not be modified.
  1. Q
  1. ;
  1. LOADTOD(PPI,PRSIEN,DAY,TOD,TODD) ; Load Tour of Duty into TOD() Array
  1. ; input
  1. ; PPI - pay period IEN, file 458
  1. ; PRSIEN - employee IEN, file 450
  1. ; DAY - day number in PP
  1. ; TOD - array, passed by reference, will be initialized
  1. ; TODD - array, passed by reference, will be initialized
  1. ; output
  1. ; TOD - array updated with tour segments in following format
  1. ; TOD(tour#-segment#)=
  1. ; start d/t (FM)^end d/t (FM)^type of time^start time(ETA)^end time(ETA)
  1. ; ^special code
  1. ; TODD - array updated with tour data in the following format
  1. ; TODD(tour#)=
  1. ; earliest regular start d/t (FM)^latest regular end d/t (FM)^
  1. ; tour meal length (minutes)^segment # of longest regular tour segment
  1. ;
  1. N FLD,NODE,PRSDT,PRSX,TN,TODI,TODY,TSC,TSE,TSI,TSLS,TSS,TST
  1. ;
  1. K TOD,TODD ; initialize array
  1. ;
  1. S PRSDT=$P($G(^PRST(458,PPI,1)),U,DAY)
  1. Q:'PRSDT
  1. ;
  1. ; loop thru both tours (#1 and #2) for the day
  1. F TN=1,2 D
  1. . S NODE=$S(TN=1:1,TN=2:4,1:"")
  1. . Q:NODE=""
  1. . S TODY=$G(^PRST(458,PPI,"E",PRSIEN,"D",DAY,NODE))
  1. . S TSLS(0)=0 ; init longest regular segment length (seconds)
  1. . ;
  1. . ; obtain the tour meal time
  1. . S FLD=$S(TN=1:2,1:10.3) ; field number corresponding to tour #1 or #2
  1. . S TODI=$$GET1^DIQ(458.02,DAY_","_PRSIEN_","_PPI_",",FLD,"I") ; tour of duty IEN
  1. . S:TODI $P(TODD(TN),U,3)=$$GET1^DIQ(457.1,TODI,2) ; tour meal (minutes)
  1. . ;
  1. . ; loop thru seven time segments of tour
  1. . F TSI=1:1:7 D
  1. . . S TSS=$P(TODY,U,(TSI-1)*3+1) ; time segment start
  1. . . Q:TSS=""
  1. . . S TSE=$P(TODY,U,(TSI-1)*3+2) ; time segment end
  1. . . Q:TSE=""
  1. . . S TSC=$P(TODY,U,(TSI-1)*3+3) ; time segment special code
  1. . . ; derive type of time
  1. . . S TST=$S(TSC:$P($G(^PRST(457.2,TSC,0)),U,2),1:"RG")
  1. . . ; convert times to FileMan date/time format
  1. . . S PRSX=$$CNVTS(PRSDT,TSS,TSE)
  1. . . Q:$P(PRSX,U)=""
  1. . . S TOD(TN_"-"_TSI)=$P(PRSX,U)_U_$P(PRSX,U,2)_U_TST_U_TSS_U_TSE_U_TSC
  1. . . ;
  1. . . ; skip remaining steps if segment is not regular time
  1. . . Q:TST'="RG"
  1. . . ;
  1. . . ; if earliest start time of tour is null, set it from current seg.
  1. . . S:$P($G(TODD(TN)),U)="" $P(TODD(TN),U)=$P(PRSX,U)
  1. . . ;
  1. . . ; if latest end time of tour is null, set it from current seg.
  1. . . S:$P($G(TODD(TN)),U,2)="" $P(TODD(TN),U,2)=$P(PRSX,U,2)
  1. . . ;
  1. . . ; if this segments start time is earlier, update the tour start
  1. . . I $P(PRSX,U)<$P(TODD(TN),U) S $P(TODD(TN),U)=$P(PRSX,U)
  1. . . ;
  1. . . ; if this segments end time is later, update the tour end
  1. . . I $P(PRSX,U,2)>$P(TODD(TN),U,2) S $P(TODD(TN),U,2)=$P(PRSX,U,2)
  1. . . ;
  1. . . ; compute length of the tour segment (seconds)
  1. . . S TSLS=$$FMDIFF^XLFDT($P(PRSX,U,2),$P(PRSX,U,1),2)
  1. . . ; if segment length more than longest found use it as longest found
  1. . . I TSLS>TSLS(0) S TSLS(0)=TSLS,$P(TODD(TN),U,4)=TSI
  1. Q
  1. ;
  1. LOADESR(PPI,PRSIEN,DAY,ESR) ; Load ESR into ESR() Array
  1. ; input
  1. ; PPI - pay period IEN, file 458
  1. ; PRSIEN - employee IEN, file 450
  1. ; DAY - day number in PP
  1. ; ESR - array, passed by reference, will be initialized
  1. ; output
  1. ; ESR - array updated with tour segments in following format
  1. ; ESR(segment #)=
  1. ; start d/t (FM)^end d/t (FM)^type of time^start time(ETA)^end time(ETA)
  1. ; ^meal (min)
  1. ;
  1. N ESRY,PRSDT,PRSX,TSE,TSI,TSM,TSS,TST
  1. ;
  1. K ESR ; initialize array
  1. ;
  1. S PRSDT=$P($G(^PRST(458,PPI,1)),U,DAY)
  1. Q:'PRSDT
  1. ;
  1. S ESRY=$G(^PRST(458,PPI,"E",PRSIEN,"D",DAY,5))
  1. ;
  1. ; loop thru seven time segments
  1. F TSI=1:1:7 D
  1. . S TSS=$P(ESRY,U,(TSI-1)*5+1) ; time segment start
  1. . Q:TSS=""
  1. . S TSE=$P(ESRY,U,(TSI-1)*5+2) ; time segment end
  1. . Q:TSE=""
  1. . S TST=$P(ESRY,U,(TSI-1)*5+3) ; time segment type of time
  1. . Q:TST=""
  1. . ; convert times to FileMan date/time format
  1. . S PRSX=$$CNVTS(PRSDT,TSS,TSE)
  1. . Q:$P(PRSX,U)=""
  1. . S TSM=$P(ESRY,U,(TSI-1)*5+5) ; time segment meal (min)
  1. . S ESR(TSI)=$P(PRSX,U)_U_$P(PRSX,U,2)_U_TST_U_TSS_U_TSE_U_TSM
  1. Q
  1. ;
  1. LOADTC(PPI,PRSIEN,DAY,TC) ; Load Time Card into TC() Array
  1. ; input
  1. ; PPI - pay period IEN, file 458
  1. ; PRSIEN - employee IEN, file 450
  1. ; DAY - day number in PP
  1. ; TC - array, passed by reference, may contain data
  1. ; output
  1. ; TC - array updated with tour segments in following format
  1. ; TC(segment #)=
  1. ; start d/t (FM)^end d/t (FM)^type of time^start time(ETA)^end time(ETA)
  1. ;
  1. N PRSDT,PRSX,TCY,TSE,TSI,TSS
  1. ;
  1. K TC ; initialize array
  1. ;
  1. S PRSDT=$P($G(^PRST(458,PPI,1)),U,DAY)
  1. Q:'PRSDT
  1. ;
  1. S TCY=$G(^PRST(458,PPI,"E",PRSIEN,"D",DAY,2))
  1. ;
  1. ; loop thru seven tour segments
  1. F TSI=1:1:7 D
  1. . S TSS=$P(TCY,U,(TSI-1)*4+1) ; time segment start
  1. . Q:TSS=""
  1. . S TSE=$P(TCY,U,(TSI-1)*4+2) ; time segment end
  1. . Q:TSE=""
  1. . S TST=$P(TCY,U,(TSI-1)*4+3) ; time segment type of time
  1. . Q:TST=""
  1. . ; convert times to FileMan date/time format
  1. . S PRSX=$$CNVTS(PRSDT,TSS,TSE)
  1. . Q:$P(PRSX,U)=""
  1. . S TC(TSI)=$P(PRSX,U)_U_$P(PRSX,U,2)_U_TST_U_TSS_U_TSE
  1. Q
  1. ;
  1. OKALVR(LVIEN) ; OK Approve Leave Request
  1. ; Called by Supervisory Approvals to see if it is OK to approve a
  1. ; leave request
  1. ; Input
  1. ; LVIEN - Leave Request IEN (file 458.1)
  1. ; Result
  1. ; string value
  1. ; = 1 if OK to approve leave request
  1. ; = 0 or 0^PPI if not OK to approve leave request
  1. ; where PPI is the Pay Period ien (file 458)
  1. ;
  1. N D1,DAY,EPP4Y,LVY0,PP4Y,PPE,PPI,PRSIEN,PRSRET,SPP4Y,Y
  1. ;
  1. S PRSRET=1 ; initialize as OK
  1. ;
  1. I '$G(LVIEN) S PRSRET=0 Q PRSRET ; required input
  1. ;
  1. S LVY0=$G(^PRST(458.1,LVIEN,0)) ; leave request 0 node
  1. S PRSIEN=$P(LVY0,U,2) ; employee IEN
  1. ;
  1. ; if employee has any memos
  1. I $$PTP^PRSPUT3(PRSIEN) D
  1. . ; determine starting and ending pay periods
  1. . S D1=$$FMADD^XLFDT($P(LVY0,U,3),-1) D PP^PRSAPPU S SPP4Y=PP4Y ; based on leave from -1 (use -1 in case of 2-day tour)
  1. . S D1=$P(LVY0,U,5) D PP^PRSAPPU S EPP4Y=PP4Y ; based on leave to
  1. . ;
  1. . ; loop thru pay periods
  1. . S PP4Y=$O(^PRST(458,"AB",SPP4Y),-1) ; set initial value to previous PP
  1. . F S PP4Y=$O(^PRST(458,"AB",PP4Y)) Q:PP4Y=""!(PP4Y]EPP4Y) D Q:'PRSRET
  1. . . S PPI=$O(^PRST(458,"AB",PP4Y,0))
  1. . . ;
  1. . . ; skip PP if not covered by memo
  1. . . S D1=$P($G(^PRST(458,PPI,1)),U)
  1. . . Q:$$MIEN^PRSPUT1(PRSIEN,D1)'>0 ; PP not covered by memo
  1. . . ;
  1. . . ; skip PP if time card status not = payroll
  1. . . Q:$P($G(^PRST(458,PPI,"E",PRSIEN,0)),U,2)'="P"
  1. . . ;
  1. . . ; can't approve this leave request until time card status changes
  1. . . S PRSRET=0_U_PPI
  1. ;
  1. Q PRSRET
  1. ;
  1. CNVTS(DATE,START,END) ; Convert Time Segment
  1. ; input
  1. ; returns string with value =
  1. ; Start Date/Time (FileMan internal)^End Date/Time (FileMan internal)
  1. ;
  1. N CNX,FMEND,FMSTR,PRSM,PRSRET,X,XMID,Y
  1. S X=START_U_END
  1. D CNV^PRSATIM
  1. S PRSM=Y
  1. S XMID=$S($P(PRSM,U,2)'>$P(PRSM,U):1,1:0)
  1. S FMSTR=$$FMADD^XLFDT(DATE,,,$P(PRSM,U))
  1. S FMEND=$$FMADD^XLFDT(DATE,XMID,,$P(PRSM,U,2))
  1. S PRSRET=FMSTR_"^"_FMEND
  1. ;
  1. Q PRSRET
  1. ;
  1. FMETA(TIME) ; FileMan to ETA time
  1. N HRS,MIN,PM,PRSRET
  1. S PRSRET=""
  1. S TIME=$$LJ^XLFSTR(TIME,4,"0") ; add trailing 0s to fileman time
  1. I TIME=1200 S PRSRET="NOON"
  1. I TIME=2400 S PRSRET="MID"
  1. I PRSRET="" D
  1. . S PM=0
  1. . S HRS=$E(TIME,1,2)
  1. . S MIN=$E(TIME,3,4)
  1. . I HRS>12 S HRS=HRS-12,PM=1
  1. . S PRSRET=$$RJ^XLFSTR(HRS,2,"0")_":"_$$RJ^XLFSTR(MIN,2,"0")_$S(PM:"P",1:"A")
  1. Q PRSRET
  1. ;PRSPLVU