source: WorldVistAEHR/trunk/r/PAID-PRS/PRSPLVA1.m@ 1093

Last change on this file since 1093 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 7.7 KB
Line 
1PRSPLVA1 ;WOIFO/SAB - AUTOPOST LEAVE FOR PTP (CONT) ;03/30/2005
2 ;;4.0;PAID;**93**;Sep 21, 1995;Build 7
3 ;;Per VHA Directive 2004-038, this routine should not be modified.
4 Q
5 ;
6PDAY ; Process Day (within Pay Period loop)
7 ; called from PRSPLVA
8 ; input variables LVDTE,LVDTS,LVY0,PPDN,PPI,PRSIEN,PRSFDA(),
9 ; TCST,TCUNPOST()
10 ; output variable
11 ; FATAL = 1^PPI, only defined if fatal exception occurred
12 ; PRSFDA() may be updated with additional data to post to ESR
13 ; TCUNPOST() may be updated with another day to unpost from timecard
14 ;
15 N ESR,ESRRG,ESRLVM,ESRST,FOUND,OVERLAP,PPDIENS,PRSDT,PRSX
16 N PSTDTE,PSTDTS,PSTMEAL,PSTSEG,PSTTYP,SEGI,TC,TOD,TODD,TODL,TOURLV
17 N TSE,TSID,TSS,TSY
18 ;
19 ; skip day if not a scheduled tour
20 Q:$P($G(^PRST(458,PPI,"E",PRSIEN,"D",PPDN,1)),U)=""
21 ;
22 S PPDIENS=PPDN_","_PRSIEN_","_PPI_","
23 ;
24 S PRSDT=$P($G(^PRST(458,PPI,1)),U,PPDN) ; FileMan date of day number
25 ;
26 ; load tour segments from both tours into arrays TOD() and TODD()
27 D LOADTOD^PRSPLVU(PPI,PRSIEN,PPDN,.TOD,.TODD)
28 ;
29 ; load ESR segments into array ESR()
30 D LOADESR^PRSPLVU(PPI,PRSIEN,PPDN,.ESR)
31 ;
32 ; load time card segments into array TC()
33 D LOADTC^PRSPLVU(PPI,PRSIEN,PPDN,.TC)
34 ;
35 ; determine leave postings
36 ; loop thru tour segments
37 S TSID="" F S TSID=$O(TOD(TSID)) Q:TSID="" D Q:$G(FATAL)
38 . S TSY=TOD(TSID)
39 . S TSS=$P(TSY,U)
40 . S TSE=$P(TSY,U,2)
41 . ; skip if tour seg. end < OR = to leave start
42 . Q:TSE'>LVDTS
43 . ; skip if tour seg. start > OR = to leave end
44 . Q:TSS'<LVDTE
45 . ;
46 . ; leave overlaps tour segment
47 . ;
48 . ; determine posting times
49 . ; posting start is greater of leave start and tour seg. start
50 . S PSTDTS=$S(LVDTS>TSS:LVDTS,1:TSS)
51 . ; posting end is lesser of leave end and tour seg. end
52 . S PSTDTE=$S(LVDTE<TSE:LVDTE,1:TSE)
53 . ;
54 . ; determine type of time to post
55 . S PSTTYP=$P(LVY0,U,7)
56 . I $P(TSY,U,3)'="RG","TR TV"'[PSTTYP S PSTTYP="UN"
57 . ;
58 . S PSTMEAL=0 ; init meal time
59 . ;
60 . ; if leave is within or equal to the tour segment then calculate
61 . ; a meal based on the user-specified leave request hours
62 . I LVDTS'<TSS,LVDTE'>TSE D
63 . . N CLM,FLD,TODI,TODN
64 . . Q:$P(TSY,U,3)'="RG"
65 . . S CLM=($$FMDIFF^XLFDT(LVDTE,LVDTS,2))/60 ; calc lv length min
66 . . S PSTMEAL=CLM-($P(LVY0,U,15)*60)
67 . . I PSTMEAL<0 S PSTMEAL=0 Q ; must be positive or zero
68 . . I PSTMEAL#15 S PSTMEAL=0 Q ; must be multiple of 15
69 . . ; must not exceed meal time for TOD
70 . . S TODN=$P(TSID,"-",1) ; determine tour # (1 or 2) for segment
71 . . I PSTMEAL>$P($G(TODD(TODN)),U,3) S PSTMEAL=$P($G(TODD(TODN)),U,3)
72 . ;
73 . ; if meal was not set based on leave request hours then check if it
74 . ; can be set based on tour info
75 . I PSTMEAL=0 D
76 . . N TODN
77 . . S TODN=$P(TSID,"-",1) ; tour # (1 or 2)
78 . . ; quit if tour does not have a meal
79 . . Q:$P($G(TODD(TODN)),U,3)'>0
80 . . ; quit if segment # currently being processed is not the longest
81 . . ; (better to place meal in the longest segment when more than one)
82 . . Q:$P($G(TODD(TODN)),U,4)'=$P(TSID,"-",2)
83 . . ; quit if leave started after tour began
84 . . Q:LVDTS>$P($G(TODD(TODN)),U,1)
85 . . ; quit if leave ended before tour ended
86 . . Q:LVDTE<$P($G(TODD(TODN)),U,2)
87 . . ; since leave covers the entire tour - set meal time based on tour
88 . . S PSTMEAL=$P($G(TODD(TODN)),U,3)
89 . ;
90 . ; skip if proposed posting covered by holiday excused on ESR
91 . S FOUND=0
92 . ; loop thru ESR segments
93 . S SEGI="" F S SEGI=$O(ESR(SEGI)) Q:SEGI="" D Q:FOUND
94 . . N ESRY
95 . . S ESRY=ESR(SEGI)
96 . . Q:$P(ESRY,U,3)'="HX" ; quit if not holiday ex
97 . . I PSTDTS'<$P(ESRY,U),PSTDTE'>$P(ESRY,U,2) S FOUND=1
98 . Q:FOUND ; skip because posting is within HX (holiday excused)
99 . ;
100 . ; skip if proposed posting is already on the ESR
101 . S FOUND=0
102 . ; loop thru ESR segments
103 . S SEGI="" F S SEGI=$O(ESR(SEGI)) Q:SEGI="" D Q:FOUND
104 . . N ESRY
105 . . S ESRY=ESR(SEGI)
106 . . Q:$P(ESRY,U,3)'=PSTTYP ; quit if same type
107 . . I PSTDTS'<$P(ESRY,U),PSTDTE'>$P(ESRY,U,2) S FOUND=1
108 . Q:FOUND ; skip because posting is already covered on ESR
109 . ;
110 . ; if time card status = "P" and proposed posting in not on the
111 . ; current time card then record a fatal exception and quit
112 . ; loop thru time card exception segments
113 . I TCST="P" D I 'FOUND S FATAL="1^"_PPI Q
114 . . S FOUND=0
115 . . S SEGI="" F S SEGI=$O(TC(SEGI)) Q:SEGI="" D Q:FOUND
116 . . . N TCY
117 . . . S TCY=TC(SEGI)
118 . . . Q:$P(TCY,U,3)'=PSTTYP ; quit if not same type
119 . . . I PSTDTS'<$P(TCY,U),PSTDTE'>$P(TCY,U,2) S FOUND=1
120 . ;
121 . ; OK to add posting to FDA array
122 . ;
123 . ; review ESR and FDA to determine next open segment
124 . S PSTSEG=0 F SEGI=1:1:7 I '$D(ESR(SEGI)) S PSTSEG=SEGI Q
125 . ;
126 . ; if segment not available then report exception and skip?
127 . Q:'PSTSEG
128 . ;
129 . ; add posting to FDA() array and ESR() array
130 . S PRSFDA(458.02,PPDIENS,(PSTSEG-1)*5+110)=$$FMETA^PRSPLVU($P(PSTDTS,".",2)) ; start time
131 . S PRSFDA(458.02,PPDIENS,(PSTSEG-1)*5+111)=$$FMETA^PRSPLVU($P(PSTDTE,".",2)) ; stop time
132 . S PRSFDA(458.02,PPDIENS,(PSTSEG-1)*5+112)=PSTTYP ; type time
133 . S PRSFDA(458.02,PPDIENS,(PSTSEG-1)*5+114)=PSTMEAL ; meal
134 . S ESR(PSTSEG)=PSTDTS_U_PSTDTE_U_PSTTYP_U_PRSFDA(458.02,PPDIENS,(PSTSEG-1)*5+110)_U_PRSFDA(458.02,PPDIENS,(PSTSEG-1)*5+111)_U_PSTMEAL
135 ;
136 ; quit if fatal exception
137 Q:$G(FATAL)
138 ;
139 ; quit if nothing will be posted to ESR day
140 Q:'$D(PRSFDA(458.02,PPDIENS))
141 ;
142 ; obtain current ESR daily status
143 S ESRST=$P($G(^PRST(458,PPI,"E",PRSIEN,"D",PPDN,7)),U)
144 ;
145 ; determine proposed new status of ESR day
146 ;
147 ; determine if any ESR time segments overlap
148 ; (some types of time are excluded from check)
149 S OVERLAP=0
150 S SEGI=0 F S SEGI=$O(ESR(SEGI)) Q:'SEGI D
151 . N SEGJ,SEGX,SEGY
152 . S SEGX=ESR(SEGI)
153 . Q:"ON SB UN"[$P(SEGX,U,3)
154 . S SEGJ=SEGI F S SEGJ=$O(ESR(SEGJ)) Q:'SEGJ D
155 . . S SEGY=ESR(SEGJ)
156 . . Q:"ON SB UN"[$P(SEGY,U,3)
157 . . Q:$P(SEGX,U,2)'>$P(SEGY,U,1)
158 . . Q:$P(SEGX,U,1)'<$P(SEGY,U,2)
159 . . S OVERLAP=1
160 ;
161 ; determine if entire tour covered by leave
162 S PRSX=$G(^PRST(458,PPI,"E",PRSIEN,"D",PPDN,0))
163 S TODL=$P(PRSX,U,8)+$P(PRSX,U,14) ; tour of duty length in hours
164 ; loop thru ESR segments to add up leave
165 S ESRLVM=0 ; leave in minutes
166 S SEGI="" F S SEGI=$O(ESR(SEGI)) Q:SEGI="" D
167 . N ESRY,SEGLVM
168 . S ESRY=ESR(SEGI)
169 . Q:"AL SL WP CU AA ML RL NL CB AD DL"'[$P(ESRY,U,3)
170 . S SEGLVM=($$FMDIFF^XLFDT($P(ESRY,U,2),$P(ESRY,U,1),2)/60)-$P(ESRY,U,6)
171 . S ESRLVM=ESRLVM+SEGLVM
172 S TOURLV=$S((ESRLVM/60)'<TODL:1,1:0) ; true if tour covered by leave
173 ;
174 ; determine if any RG time on ESR
175 S ESRRG=$S($G(^PRST(458,PPI,"E",PRSIEN,"D",PPDN,5))["RG":1,1:0)
176 ;
177 ; if not started/pending/resubmit and no RG, no overlaps, and
178 ; tour covered by leave then auto sign based on leave. Otherwise,
179 ; if not started then change to pending
180 I "^1^2^3^"[(U_ESRST_U) D
181 . N SIGNED
182 . S SIGNED=0
183 . I 'ESRRG,'OVERLAP,TOURLV D
184 . . S PRSFDA(458.02,PPDIENS,146)="4" ; status = signed
185 . . S PRSFDA(458.02,PPDIENS,147)=$$NOW^XLFDT() ; signed d/t
186 . . S PRSFDA(458.02,PPDIENS,149)="3" ; signed method = leave request
187 . . S SIGNED=1
188 . I 'SIGNED,ESRST=1 S PRSFDA(458.02,PPDIENS,146)="2" ; status = pending
189 ;
190 ; if signed or approved and no overlap then re-sign. Otherwise
191 ; change to pending.
192 I "^4^5^"[(U_ESRST_U) D
193 . ;
194 . I 'OVERLAP D
195 . . S PRSFDA(458.02,PPDIENS,146)="4" ; status = signed
196 . . S PRSFDA(458.02,PPDIENS,147)=$$NOW^XLFDT() ; signed d/t
197 . . ; if tour covered by leave and method is extended absence then
198 . . ; change signed method to leave
199 . . I TOURLV,$P($G(^PRST(458,PPI,"E",PRSIEN,"D",PPDN,7)),U,3)=2 S PRSFDA(458.02,PPDIENS,149)="3"
200 . ;
201 . I OVERLAP D
202 . . S PRSFDA(458.02,PPDIENS,146)="2" ; status = pending
203 . . S PRSFDA(458.02,PPDIENS,147)="@" ; delete signed d/t
204 . . S PRSFDA(458.02,PPDIENS,149)="@" ; delete signed method
205 . ;
206 . ; if day was approved and time card status = T then add to unpost list
207 . I ESRST=5,TCST="T" S TCUNPOST(PPI,PPDN)=""
208 ;
209 Q
210 ;
211 ;PRSPLVA1
Note: See TracBrowser for help on using the repository browser.