source: WorldVistAEHR/trunk/r/ACCOUNTS_RECEIVABLE-PRCA-PRY-RC/RCXFMSSV.m@ 1608

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

initial load of WorldVistAEHR

File size: 9.5 KB
Line 
1RCXFMSSV ;WISC/RFJ-fms standard voucher (sv) code sheet generator ;1 Nov 97
2 ;;4.5;Accounts Receivable;**96,101,135,139,98,156,170,191,203,220,138,184,239**;Mar 20, 1995
3 ;;Per VHA Directive 10-93-142, this routine should not be modified.
4 Q
5 ;
6 ;
7STARTSV(RCDATEND) ; top entry point to generate a sv code sheet
8 ;
9 ; rcdatend is the ending date of the period.
10 ; This date is the 3rd work day from the end of the month.
11 ; The utility $$LDATE^RCRJR is used to figure it out. It will
12 ; change from month to month and figures in holidays also.
13 ; For example, if running the ARDC for the month of June 2003
14 ; the EOAM will calculate out to be June 25, 2003.
15 ; This is called by the background monthly data collector
16 ;
17 ; data stored in tmp($j,rcrjrcolsv,type,fund,revsourcecode)
18 ; this is called by the background monthly data collector
19 ;
20 N GECSDATA,RCTRANID,RESULT
21 ; lookup fms document number to see if the monthly sv has been sent
22 ; example rcdatend=3010531, lookup on 3010500
23 D KEYLOOK^GECSSGET("SV-"_$E(RCDATEND,1,5)_"00",1)
24 ;
25 ; get the transacion id for the fms document
26 ; if it is not sent, get the next number available
27 I $G(GECSDATA) S RCTRANID=$E($P(GECSDATA("2100.1",GECSDATA,".01","E"),"-",2),1,11)
28 I $G(RCTRANID)="" S RCTRANID=$$ENUM^RCMSNUM
29 I RCTRANID<0 Q ;unable to retrieve the next number
30 ; remove dash (example 460-K1A05HY)
31 S RCTRANID=$TR(RCTRANID,"-")
32 ;
33 ; build and send the sv document to fms
34 S RESULT=$$BUILDSV(RCDATEND,+$G(GECSDATA),RCTRANID,"00")
35 ; error in building code sheet
36 I 'RESULT Q
37 ;
38 ; add/update entry in file 347 for reports
39 N %DT,%X,D,D0,DA347,DI,DQ,DIC,ERROR
40 S DA347=$O(^RC(347,"C",$P(RESULT,"^",2),0))
41 ; if not in the file, addit fmsdocid sv id
42 I 'DA347 D OPEN^RCFMDRV1($P(RESULT,"^",2),4,"SV-"_$E(RCDATEND,1,5)_"00",.DA347,.ERROR)
43 I DA347 D SSTAT^RCFMFN02($P(RESULT,"^",2),1)
44 Q
45 ;
46 ;
47BUILDSV(RCDATEND,RCGECSDA,RCTRANID,RCKS) ; generate a wr code sheet for monthly data
48 ; rcgecsda is the ien for the gcs stack file 2100.1 for rebuilds
49 ; data stored in tmp($j,rcrjrcolsv)
50 ; rcks is the "key suffix" to distinguish the gecs lookup key
51 ; for the SRB SV from the lookup key for the BDR SV
52 ;
53 N AMOUNT,COUNT,DESCRIP,DOCTOTAL,FISCALYR,FMSLINE,FUND,FY,GECSFMS,MONTH,REVDATE,REVFY,REVMONTH,RSC,SV2,TYPE,FMAMOUNT
54 ;
55 S FISCALYR=$$FY^RCFN01(RCDATEND)
56 ;
57 S COUNT=0,DOCTOTAL=0
58 S TYPE="" F S TYPE=$O(^TMP($J,"RCRJRCOLSV",TYPE)) Q:TYPE="" D
59 . S FUND="" F S FUND=$O(^TMP($J,"RCRJRCOLSV",TYPE,FUND)) Q:FUND="" D
60 . . S RSC="" F S RSC=$O(^TMP($J,"RCRJRCOLSV",TYPE,FUND,RSC)) Q:RSC="" D
61 . . . S AMOUNT=^TMP($J,"RCRJRCOLSV",TYPE,FUND,RSC),DOCTOTAL=DOCTOTAL+AMOUNT
62 . . . I +AMOUNT=0 Q
63 . . . S COUNT=COUNT+1
64 . . . S FMSLINE(COUNT)="LIN^~SVA^"_$S($L(COUNT)=1:"00",$L(COUNT)=2:"0",1:"")_COUNT
65 . . . S $P(FMSLINE(COUNT),"^",4)=TYPE
66 . . . S $P(FMSLINE(COUNT),"^",5)=FISCALYR ;begin fy
67 . . . I $E(FUND,1,4)=5287 S $P(FMSLINE(COUNT),"^",5)="05"
68 . . . S $P(FMSLINE(COUNT),"^",7)=FUND
69 . . . S $P(FMSLINE(COUNT),"^",9)=$E(RCTRANID,1,3) ;site number
70 . . . ; for transaction types 23,27,2B the RSC is 0, send null
71 . . . S $P(FMSLINE(COUNT),"^",14)=$S(RSC=0:"",1:RSC)
72 . . . ;
73 . . . ; vendor id
74 . . . S $P(FMSLINE(COUNT),"^",18)="MCCFVALUE"
75 . . . ; for transaction type P2, send vendorid of PERSONOTH
76 . . . I TYPE="P2" S $P(FMSLINE(COUNT),"^",18)="PERSONOTH"
77 . . . ; if it is hsif fund 5358.1, send vendorid of HSIFVALUE
78 . . . I FUND=5358.1 S $P(FMSLINE(COUNT),"^",18)="HSIFVALUE"
79 . . . ; if it is ltc fund 4032 or 528709, send vendorid of EXCFVALUE
80 . . . I FUND=4032!(FUND=528709) D
81 . . . . S $P(FMSLINE(COUNT),"^",18)="EXCFVALUE"
82 . . . . S:FUND=4032 $P(FMSLINE(COUNT),"^",5)="03" ; FY
83 . . . . S:$E(FUND,1,4)=5287 $P(FMSLINE(COUNT),"^",5)="05" ; FY
84 . . . ;
85 . . . ; send pos figure to FMS; neg amt requires a "D"
86 . . . S FMAMOUNT=$S(AMOUNT<0:-AMOUNT,1:AMOUNT)
87 . . . S $P(FMSLINE(COUNT),"^",19)="~SVB"
88 . . . S $P(FMSLINE(COUNT),"^",20)=$J(FMAMOUNT,0,2)
89 . . . S $P(FMSLINE(COUNT),"^",21)=$S(AMOUNT<0:"D",1:"I")
90 . . . ; for transaction types 23,27,2B the RSC is 0, send G
91 . . . S $P(FMSLINE(COUNT),"^",23)=$S(RSC=0:"G",1:"R")
92 . . . S $P(FMSLINE(COUNT),"^",25)=$E(RCDATEND,2,3)
93 . . . S $P(FMSLINE(COUNT),"^",26)=$E(RCDATEND,4,5)
94 . . . S $P(FMSLINE(COUNT),"^",27)=$E(RCDATEND,6,7)
95 . . . S $P(FMSLINE(COUNT),"^",28)="~"
96 ;
97 ; no code sheets to send
98 I COUNT=0 Q "0^No sv code sheets to send for this month"
99 ;
100 ; calculate the accounting month and fy
101 S FY=$E(RCDATEND,2,3) I $E(RCDATEND,4,5)>9 S FY=FY+1 I FY=100 S FY="00"
102 I $L(FY)=1 S FY="0"_FY
103 S MONTH=$P("04^05^06^07^08^09^10^11^12^01^02^03","^",$E(RCDATEND,4,5))
104 ; calculate the reversal month and fy (next month, add 1 day)
105 S REVDATE=$$FMADD^XLFDT(RCDATEND,9)
106 S REVFY=$E(REVDATE,2,3) I $E(REVDATE,4,5)>9 S REVFY=REVFY+1 I REVFY=100 S REVFY="00"
107 I $L(REVFY)=1 S REVFY="0"_REVFY
108 S REVMONTH=$P("04^05^06^07^08^09^10^11^12^01^02^03","^",$E(REVDATE,4,5))
109 ;
110 S SV2="SV2^"_$E(RCDATEND,2,3)_"^"_$E(RCDATEND,4,5)_"^"_$E(RCDATEND,6,7)
111 S $P(SV2,"^",5)=MONTH ;accounting period month
112 S $P(SV2,"^",6)=FY ;accounting period year
113 S $P(SV2,"^",7)="E"
114 S $P(SV2,"^",12)=REVFY ;reversal period year
115 S $P(SV2,"^",13)=REVMONTH ;reversal period month
116 S:DOCTOTAL<0 DOCTOTAL=-DOCTOTAL ; document total must be positive
117 S $P(SV2,"^",16)=$J(DOCTOTAL,0,2)_"^~"
118 ;
119 ; put together document in gcs
120 N %DT,D0,DA,DI,DIC,DIE,DQ,DR,X,Y
121 S Y=$E(RCDATEND,1,5)_"00" D DD^%DT
122 S DESCRIP="Monthly Standard Voucher for "_Y
123 I 'RCGECSDA D CONTROL^GECSUFMS("A",$E(RCTRANID,1,3),RCTRANID,"SV",10,0,"",DESCRIP)
124 I RCGECSDA D REBUILD^GECSUFM1(RCGECSDA,"A",10,"","Rebuild "_DESCRIP) S GECSFMS("DA")=RCGECSDA
125 ;
126 ; store document in gcs
127 D SETCS^GECSSTAA(GECSFMS("DA"),SV2)
128 F COUNT=1:1 Q:'$D(FMSLINE(COUNT)) D SETCS^GECSSTAA(GECSFMS("DA"),FMSLINE(COUNT))
129 D SETCODE^GECSSDCT(GECSFMS("DA"),"D RETN^RCFMFN02")
130 D SETSTAT^GECSSTAA(GECSFMS("DA"),"Q")
131 ; set the key for lookup
132 D SETKEY^GECSSTAA(GECSFMS("DA"),"SV-"_$E(RCDATEND,1,5)_RCKS)
133 ;
134 ; return 1 for success ^ fms document transaction number
135 Q "1^SV-"_$P(GECSFMS("CTL"),"^",9)
136 ;
137 ;
138BADDEBT(RCRJDATE) ; top entry point to generate a sv code sheet
139 ; for the bad debt report, transaction types 23, 27, 2B and 2J.
140 ; The fms document number in file 347 is SV-$e(dateend,1,5)_"01"
141 ;
142 ; Input: RCRJDATE -- last day of accounting month
143 ;
144 N DATA1319,DATA1338,DATA1339,DATA4032,DATAHSIF,GECSDATA,RESULT,RCRJFMM,RCRJFXSV,RCTRANID,X,RCNOHSIF,LTCFUND,DATA133M,DATA133T
145 N DATA133N
146 ;
147 S RCNOHSIF=$$NOHSIF^RCRJRCO() ; disabled HSIF
148 ;
149 ; lock cannot fail
150 L +^RC(348.1)
151 ;
152 ; get the data from the bad debt allowance file 348.1
153 K ^TMP($J,"RCRJRCOLSV")
154 S DATA1319=$G(^RC(348.1,+$O(^RC(348.1,"B",1319,0)),0))
155 S DATA1338=$G(^RC(348.1,+$O(^RC(348.1,"B",1338,0)),0))
156 S DATA1339=$G(^RC(348.1,+$O(^RC(348.1,"B",1339,0)),0))
157 S DATA133N=$G(^RC(348.1,+$O(^RC(348.1,"B","133N",0)),0))
158 I 'RCNOHSIF S DATAHSIF=$G(^RC(348.1,+$O(^RC(348.1,"B",1319.1,0)),0))
159 S DATA4032=$G(^RC(348.1,+$O(^RC(348.1,"B",1319.2,0)),0))
160 S DATA133M=$G(^RC(348.1,+$O(^RC(348.1,"B",1319.3,0)),0))
161 S DATA133T=$G(^RC(348.1,+$O(^RC(348.1,"B",1319.4,0)),0))
162 ;
163 ; the revenue source code here is a 0
164 S ^TMP($J,"RCRJRCOLSV","23",$$ADJFUND^RCRJRCO($S(DT<$$ADDPTEDT^PRCAACC():5287.3,1:528703)),0)=$P(DATA1319,"^",8)
165 I 'RCNOHSIF S ^TMP($J,"RCRJRCOLSV","23",5358.1,0)=$P(DATAHSIF,"^",8)
166 ;patch 220 replaces 4032 fund with 528709
167 S LTCFUND=$S(DT'<$$ADDPTEDT^PRCAACC():528709,1:4032)
168 S ^TMP($J,"RCRJRCOLSV","23",LTCFUND,0)=$P(DATA4032,"^",8)
169 S ^TMP($J,"RCRJRCOLSV","23",528701,0)=$P(DATA133M,"^",8)
170 S ^TMP($J,"RCRJRCOLSV","23",528704,0)=$P(DATA133T,"^",8)
171 ;
172 S ^TMP($J,"RCRJRCOLSV","2B",$$ADJFUND^RCRJRCO($S(DT<$$ADDPTEDT^PRCAACC():5287.4,1:528704)),0)=$P(DATA1338,"^",8)
173 S ^TMP($J,"RCRJRCOLSV","27",$$ADJFUND^RCRJRCO($S(DT<$$ADDPTEDT^PRCAACC():5287.4,1:528704)),0)=$P(DATA1339,"^",8)
174 ; post-MRA non-Medicare bills
175 S ^TMP($J,"RCRJRCOLSV","2J",$$ADJFUND^RCRJRCO($S(DT<$$ADDPTEDT^PRCAACC():5287.4,1:528704)),0)=$P(DATA133N,"^",8)
176 ;
177 ; the date is for previous month
178 ;S RCRJDATE=$$PREVMONT^RCRJRBD(DT)
179 ;I $E(DT,6,7)<$E($$LDATE^RCRJR(DT),6,7) S RCRJDATE=$$PREVMONT^RCRJRBD(DT)
180 ;I $E(DT,6,7)>$E($$LDATE^RCRJR(DT),6,7) S RCRJDATE=$E($$LDATE^RCRJR(DT),1,5)_"00"
181 ;I $E(DT,6,7)>$E($$LDATE^RCRJR(DT),6,7) S RCRJDATE=$$LDATE^RCRJR(DT)
182 ; find the last day of the month for the end date
183 ;S RCRJDATE=$E(RCRJDATE,1,5)_$P("31^28^31^30^31^30^31^31^30^31^30^31","^",+$E(RCRJDATE,4,5))
184 ;I $E(RCRJDATE,6,7)=28,$E(RCRJDATE,2,3)#4=0 S RCRJDATE=$E(RCRJDATE,1,5)_"29"
185 ;
186 ; lookup fms document number to see if the monthly sv has been sent
187 ; example rcdatend=3010531, lookup on 3010501
188 D KEYLOOK^GECSSGET("SV-"_$E(RCRJDATE,1,5)_"01",1)
189 ;
190 ; get the transacion id for the fms document
191 ; if it is not sent, get the next number available
192 I $G(GECSDATA) S RCTRANID=$E($P(GECSDATA("2100.1",GECSDATA,".01","E"),"-",2),1,11)
193 I $G(RCTRANID)="" S RCTRANID=$$ENUM^RCMSNUM
194 I RCTRANID<0 Q ;unable to retrieve the next number
195 ; remove dash (example 460-K1A05HY)
196 S RCTRANID=$TR(RCTRANID,"-")
197 ;
198 ; build and send the sv document to fms
199 S RESULT=$$BUILDSV(RCRJDATE,+$G(GECSDATA),RCTRANID,"01")
200 K ^TMP($J,"RCRJRCOLSV")
201 ; error in building code sheet
202 I 'RESULT D Q Q
203 ;
204 ; add/update entry in file 347 for reports
205 N %DT,%X,D,D0,DA347,DI,DQ,DIC,ERROR
206 S DA347=$O(^RC(347,"D","SV-"_$E(RCRJDATE,1,5)_"01",0))
207 ; if not in the file, addit fmsdocid sv id
208 I 'DA347 D OPEN^RCFMDRV1($P(RESULT,"^",2),4,"SV-"_$E(RCRJDATE,1,5)_"01",.DA347,.ERROR)
209 I DA347 D SSTAT^RCFMFN02($P(RESULT,"^",2),1)
210 ;
211Q ; jump here to finish
212 ; generate bad debt report
213 S RCRJFXSV=$P(RESULT,"^",2),RCRJFMM=1 D DQ^RCRJRBDR
214 L -^RC(348.1)
215 Q
Note: See TracBrowser for help on using the repository browser.