| 1 | RCDPXPAY ;WISC/RFJ-server top to receive electronic payments ;1 Jun 99
 | 
|---|
| 2 |  ;;4.5;Accounts Receivable;**114,148,150**;Mar 20, 1995
 | 
|---|
| 3 |  ;;Per VHA Directive 10-93-142, this routine should not be modified.
 | 
|---|
| 4 |  Q
 | 
|---|
| 5 |  ;
 | 
|---|
| 6 |  ;
 | 
|---|
| 7 | START ;  start receiving message
 | 
|---|
| 8 |  N RCDPCNTL,RCDPCSUM,RCDPDATA,RCDPDATE,RCDPFLAG,RCDPFSUM,RCDPLIDA,RCDPLINE,RCDPNEXT,RCDPSEQ,RCDPSITE,RCDPTOTL,RCDPXMZ,X,Y
 | 
|---|
| 9 |  K ^TMP($J,"RCDPXPAY")
 | 
|---|
| 10 |  ;
 | 
|---|
| 11 |  ;  not a valid mail message
 | 
|---|
| 12 |  I '$D(^XMB(3.9,XMZ,0)) Q
 | 
|---|
| 13 |  ;
 | 
|---|
| 14 |  S RCDPXMZ=XMZ
 | 
|---|
| 15 |  ;  find line 1 of data and make sure it is correctly formatted
 | 
|---|
| 16 |  S RCDPLINE=.99 F  S RCDPLINE=$O(^XMB(3.9,RCDPXMZ,2,RCDPLINE)) Q:'RCDPLINE  S RCDPDATA=^(RCDPLINE,0) I $E(RCDPDATA,1,2)="RT" Q
 | 
|---|
| 17 |  ;  first 2 characters of line 1 must equal RT
 | 
|---|
| 18 |  I $E($G(RCDPDATA),1,2)'="RT" D ERROR^RCDPXPAM("",RCDPXMZ,"RT expected (line 1, piece 1)"),COMPLETE Q
 | 
|---|
| 19 |  ;  check the station number
 | 
|---|
| 20 |  S RCDPSITE=$$SITE^RCMSITE
 | 
|---|
| 21 |  I $P(RCDPDATA,"^",4)'=RCDPSITE D ERROR^RCDPXPAM("",RCDPXMZ,"Wrong station number (line 1, piece 4), station number should be "_RCDPSITE),COMPLETE Q
 | 
|---|
| 22 |  ;  get the transmission date and convert it to a fileman date
 | 
|---|
| 23 |  S RCDPDATE=$$CONVDATE($P(RCDPDATA,"^",8)) I RCDPDATE<0 D ERROR^RCDPXPAM("",RCDPXMZ,"Invalid transmission date (line 1, piece 8)"),COMPLETE Q
 | 
|---|
| 24 |  ;  get the sequence number
 | 
|---|
| 25 |  S RCDPSEQ=+$P(RCDPDATA,"^",2) I 'RCDPSEQ D ERROR^RCDPXPAM("",RCDPXMZ,"Sequence number of the message is missing (line 1, piece 2)"),COMPLETE Q
 | 
|---|
| 26 |  ;
 | 
|---|
| 27 |  ;  check for zero payments on message
 | 
|---|
| 28 |  ;  sequence=1          ,total sequence=1     ,no payments        ,no dollars on RT   ,no total dollars
 | 
|---|
| 29 |  I +$P(RCDPDATA,"^",2)=1,+$P(RCDPDATA,"^",3)=1,'$P(RCDPDATA,"^",5),'$P(RCDPDATA,"^",6),'$P(RCDPDATA,"^",7) D ZEROMSG^RCDPXPAM($P(RCDPDATA,"^",8)) Q
 | 
|---|
| 30 |  ;
 | 
|---|
| 31 |  ;  stay and wait for lock to clear
 | 
|---|
| 32 |  L +^RCY(344.2,RCDPDATE)
 | 
|---|
| 33 |  ;
 | 
|---|
| 34 |  ;  check for duplicate message, only store/process the first one
 | 
|---|
| 35 |  ;  still go and check to see if all messages have been received and can be processed
 | 
|---|
| 36 |  I $D(^RCY(344.2,RCDPDATE,1,RCDPSEQ,0)) D DUPLCATE^RCDPXPAM(RCDPDATE,RCDPSEQ,RCDPXMZ),STARPROC Q
 | 
|---|
| 37 |  ;
 | 
|---|
| 38 |  ;  add transmission date if not in file
 | 
|---|
| 39 |  I '$$ADDTRAN^RCDPXPA1(RCDPDATE) D ERROR^RCDPXPAM("",RCDPXMZ,"Unable to add transmission to AR PAYMENT TRANSACTIONS file 344.2"),COMPLETE Q
 | 
|---|
| 40 |  ;  store total sequences and dollars if available for transmission
 | 
|---|
| 41 |  D TRANDOLL^RCDPXPA1(RCDPDATE,+$P(RCDPDATA,"^",3),+$P(RCDPDATA,"^",7)/100)
 | 
|---|
| 42 |  ;
 | 
|---|
| 43 |  ;  add the sequence to the transmission multiple
 | 
|---|
| 44 |  S RCDPSEQ=$$ADDSEQ^RCDPXPA1(RCDPDATE,+$P(RCDPDATA,"^",2)) I 'RCDPSEQ D ERROR^RCDPXPAM(RCDPDATE,RCDPXMZ,"Unable to add the sequence number (line 1, piece 2)"),COMPLETE Q
 | 
|---|
| 45 |  ;  store number of transactions, total dollars for the sequence, mail message number
 | 
|---|
| 46 |  D SEQUDOLL^RCDPXPA1(RCDPDATE,RCDPSEQ,+$P(RCDPDATA,"^",5),+$P(RCDPDATA,"^",6)/100,RCDPXMZ)
 | 
|---|
| 47 |  ;
 | 
|---|
| 48 |  ;  once the sequence has been added, future errors must pass the
 | 
|---|
| 49 |  ;  variable rcdpdate to the label error to set the status to error
 | 
|---|
| 50 |  ;  and prevent further processing later on.
 | 
|---|
| 51 |  ;
 | 
|---|
| 52 |  ;  store control header line 1 for comparing count and dollars of transactions
 | 
|---|
| 53 |  S RCDPCNTL=RCDPDATA
 | 
|---|
| 54 |  ;
 | 
|---|
| 55 |  ;  loop transactions and store the data
 | 
|---|
| 56 |  S RCDPCSUM=0  ;used to compute checksum for sequence
 | 
|---|
| 57 |  S RCDPLIDA=0  ;used to count entries stored in the data wp field
 | 
|---|
| 58 |  S RCDPTOTL=0  ;used to total all payments (transactions)
 | 
|---|
| 59 |  F  S RCDPLINE=$O(^XMB(3.9,RCDPXMZ,2,RCDPLINE)) Q:'RCDPLINE  D
 | 
|---|
| 60 |  .   S RCDPDATA=^XMB(3.9,RCDPXMZ,2,RCDPLINE,0)
 | 
|---|
| 61 |  .   I RCDPDATA=""!($E(RCDPDATA,1,4)="NNNN") Q
 | 
|---|
| 62 |  .   ;  convert deposit date to fm
 | 
|---|
| 63 |  .   S $P(RCDPDATA,"^",7)=$$CONVDATE($P(RCDPDATA,"^",7))
 | 
|---|
| 64 |  .   I $P(RCDPDATA,"^",7)<0 S $P(RCDPDATA,"^",7)=0
 | 
|---|
| 65 |  .   ;  check for errors
 | 
|---|
| 66 |  .   I $E(RCDPDATA,1,2)'="RD" S ^TMP($J,"RCDPXPAY","ERROR",RCDPLINE)="RD expected (line "_RCDPLINE_", piece 1)"
 | 
|---|
| 67 |  .   I '$P(RCDPDATA,"^",3) S ^TMP($J,"RCDPXPAY","ERROR",RCDPLINE)="No payment amount (line "_RCDPLINE_", piece 3)"
 | 
|---|
| 68 |  .   I $P(RCDPDATA,"^",6)="" S ^TMP($J,"RCDPXPAY","ERROR",RCDPLINE)="Deposit/215 number missing (line "_RCDPLINE_", piece 6)"
 | 
|---|
| 69 |  .   I '$P(RCDPDATA,"^",7) S ^TMP($J,"RCDPXPAY","ERROR",RCDPLINE)="Deposit date missing/invalid format (line "_RCDPLINE_", piece 7)"
 | 
|---|
| 70 |  .   ;  add up dollars
 | 
|---|
| 71 |  .   S RCDPTOTL=RCDPTOTL+($P(RCDPDATA,"^",3)/100)
 | 
|---|
| 72 |  .   ;  remove RT, remove station number from account (based on site length)
 | 
|---|
| 73 |  .   ;  since the station number is variable 3 to 5 characters
 | 
|---|
| 74 |  .   S RCDPDATA=$P(RCDPDATA,"^",2,99),RCDPDATA=$E(RCDPDATA,$L(RCDPSITE)+1,99999)
 | 
|---|
| 75 |  .   ;  store the data
 | 
|---|
| 76 |  .   S RCDPLIDA=RCDPLIDA+1
 | 
|---|
| 77 |  .   S ^RCY(344.2,RCDPDATE,1,RCDPSEQ,1,RCDPLIDA,0)=RCDPDATA
 | 
|---|
| 78 |  .   ;  compute checksum
 | 
|---|
| 79 |  .   S X=RCDPCSUM_RCDPDATA X $S($G(^%ZOSF("LPC"))'="":^("LPC"),1:"S Y=""""") S RCDPCSUM=Y
 | 
|---|
| 80 |  ;
 | 
|---|
| 81 |  ;  store 0th node with count of lines and date
 | 
|---|
| 82 |  S ^RCY(344.2,RCDPDATE,1,RCDPSEQ,1,0)="^^"_RCDPLIDA_"^"_RCDPLIDA_"^"_DT_"^"
 | 
|---|
| 83 |  ;  store the checksum for sequence
 | 
|---|
| 84 |  D TRANCSUM^RCDPXPA1(RCDPDATE,RCDPSEQ,RCDPCSUM)
 | 
|---|
| 85 |  ;
 | 
|---|
| 86 |  ;  check number of transactions for sequence
 | 
|---|
| 87 |  I $P(RCDPCNTL,"^",5)'=RCDPLIDA D ERROR^RCDPXPAM(RCDPDATE,RCDPXMZ,"Expected number of transactions not equal actual number (line 1, piece 5)"),COMPLETE Q
 | 
|---|
| 88 |  ;  check total dollars for sequence
 | 
|---|
| 89 |  I ($P(RCDPCNTL,"^",6)/100)'=RCDPTOTL D ERROR^RCDPXPAM(RCDPDATE,RCDPXMZ,"Expected dollars of transactions not equal actual dollars (line 1, piece 6)"),COMPLETE Q
 | 
|---|
| 90 |  ;
 | 
|---|
| 91 |  ;  if errors on rd lines, stop process
 | 
|---|
| 92 |  I $O(^TMP($J,"RCDPXPAY","ERROR",0)) D ERROR^RCDPXPAM(RCDPDATE,RCDPXMZ,""),COMPLETE Q
 | 
|---|
| 93 |  ;
 | 
|---|
| 94 | STARPROC ;  start processing
 | 
|---|
| 95 |  ;  check to see if all messages (sequences) have been received
 | 
|---|
| 96 |  S RCDPFLAG=1
 | 
|---|
| 97 |  S RCDPDATA=^RCY(344.2,RCDPDATE,0) I $P(RCDPDATA,"^",2) D
 | 
|---|
| 98 |  .   S RCDPFLAG=0
 | 
|---|
| 99 |  .   F RCDPSEQ=1:1:$P(RCDPDATA,"^",2) I '$D(^RCY(344.2,RCDPDATE,1,RCDPSEQ)) S RCDPFLAG=1 Q
 | 
|---|
| 100 |  ;  not all sequences received yet
 | 
|---|
| 101 |  I $G(RCDPFLAG) D COMPLETE Q
 | 
|---|
| 102 |  ;
 | 
|---|
| 103 |  ;  ***** all sequences received, start processing *****
 | 
|---|
| 104 |  ;  if status is error, quit and wait for tomorrow to send retransmission
 | 
|---|
| 105 |  ;  message to mail group
 | 
|---|
| 106 |  I $P(^RCY(344.2,RCDPDATE,0),"^",4)="e" D COMPLETE Q
 | 
|---|
| 107 |  ;  already processing/processed the payments
 | 
|---|
| 108 |  I $P(^RCY(344.2,RCDPDATE,0),"^",4)="p" D COMPLETE Q
 | 
|---|
| 109 |  ;
 | 
|---|
| 110 |  ;  set status to processing
 | 
|---|
| 111 |  D TRANSTAT^RCDPXPA1(RCDPDATE,"p")
 | 
|---|
| 112 |  S RCDPTOTL=0
 | 
|---|
| 113 |  S RCDPNEXT=0  ;used for making tmp global entry unique
 | 
|---|
| 114 |  F RCDPSEQ=1:1 Q:'$D(^RCY(344.2,RCDPDATE,1,RCDPSEQ))  D
 | 
|---|
| 115 |  .   S RCDPCSUM=0
 | 
|---|
| 116 |  .   S RCDPTOTL=RCDPTOTL+$P(^RCY(344.2,RCDPDATE,1,RCDPSEQ,0),"^",3)
 | 
|---|
| 117 |  .   F RCDPLIDA=1:1 Q:'$D(^RCY(344.2,RCDPDATE,1,RCDPSEQ,1,RCDPLIDA,0))  D
 | 
|---|
| 118 |  .   .   S RCDPDATA=^RCY(344.2,RCDPDATE,1,RCDPSEQ,1,RCDPLIDA,0)
 | 
|---|
| 119 |  .   .   ;  compute checksum
 | 
|---|
| 120 |  .   .   S X=RCDPCSUM_RCDPDATA X $S($G(^%ZOSF("LPC"))'="":^("LPC"),1:"S Y=""""") S RCDPCSUM=Y
 | 
|---|
| 121 |  .   .   ;  store transaction for processing
 | 
|---|
| 122 |  .   .   ;  the deposit number and date should not be null unless the
 | 
|---|
| 123 |  .   .   ;  data was modified after receipt
 | 
|---|
| 124 |  .   .   I $P(RCDPDATA,"^",5)="" S $P(RCDPDATA,"^",5)=" " ; deposit number
 | 
|---|
| 125 |  .   .   S RCDPNEXT=RCDPNEXT+1,^TMP($J,"RCDPXPAY","DEPOSIT",$P(RCDPDATA,"^",5),RCDPNEXT)=$P(RCDPDATA,"^",1,4)_"^"_$P(RCDPDATA,"^",7,99)
 | 
|---|
| 126 |  .   .   ;  store deposit date for deposit if it is needed
 | 
|---|
| 127 |  .   .   I $P(RCDPDATA,"^",6),'$G(^TMP($J,"RCDPXPAY","DEPDATE",$P(RCDPDATA,"^",5))) S ^TMP($J,"RCDPXPAY","DEPDATE",$P(RCDPDATA,"^",5))=$P(RCDPDATA,"^",6)
 | 
|---|
| 128 |  .   ;  verify checksum
 | 
|---|
| 129 |  .   I $P(^RCY(344.2,RCDPDATE,1,RCDPSEQ,0),"^",5)'=RCDPCSUM S RCDPFSUM=1
 | 
|---|
| 130 |  ;
 | 
|---|
| 131 |  ;  verify totals for all sequences
 | 
|---|
| 132 |  I $P(^RCY(344.2,RCDPDATE,0),"^",3)'=RCDPTOTL D ERROR^RCDPXPAM(RCDPDATE,RCDPXMZ,"The total dollars for all sequences do not balance with expected total"),COMPLETE Q
 | 
|---|
| 133 |  ;  checksum error
 | 
|---|
| 134 |  I $G(RCDPFSUM) D ERROR^RCDPXPAM(RCDPDATE,RCDPXMZ,"The deposit information has been altered before processing occured"),COMPLETE Q
 | 
|---|
| 135 |  ;
 | 
|---|
| 136 |  ;  everything checks out, start processing
 | 
|---|
| 137 |  ;  modify the lockbox lookup for accepting payment from other systems
 | 
|---|
| 138 |  D PROCESS^RCDPXPAP(RCDPDATE,$O(^RC(341.1,"B","LOCKBOX",0)))
 | 
|---|
| 139 |  ;
 | 
|---|
| 140 | COMPLETE ;  complete the process
 | 
|---|
| 141 |  ;  check for errors in the transmission file for prior dates
 | 
|---|
| 142 |  ;  if they exist, mail a message to the users asking for retrans
 | 
|---|
| 143 |  ;  remove the entries
 | 
|---|
| 144 |  N DATA,DEPDATE,DEPOSIT,RCDPDA
 | 
|---|
| 145 |  S RCDPDA=DT F  S RCDPDA=$O(^RCY(344.2,RCDPDA),-1) Q:'RCDPDA  D
 | 
|---|
| 146 |  .   ;  if the status was last updated today, do not modify
 | 
|---|
| 147 |  .   I $P(^RCY(344.2,RCDPDA,0),"^",5)=DT Q
 | 
|---|
| 148 |  .   ;  try and find deposit number and deposit date
 | 
|---|
| 149 |  .   S (DEPOSIT,DEPDATE)="",RCDPFLAG=0
 | 
|---|
| 150 |  .   F RCDPSEQ=1:1 Q:'$D(^RCY(344.2,RCDPDA,1,RCDPSEQ))  D  Q:RCDPFLAG
 | 
|---|
| 151 |  .   .   F RCDPLIDA=1:1 Q:'$D(^RCY(344.2,RCDPDA,1,RCDPSEQ,1,RCDPLIDA,0))  D  Q:RCDPFLAG
 | 
|---|
| 152 |  .   .   .   S DATA=$G(^RCY(344.2,RCDPDA,1,RCDPSEQ,1,RCDPLIDA,0))
 | 
|---|
| 153 |  .   .   .   I $P(DATA,"^",5)'="" S DEPOSIT=$P(DATA,"^",5)
 | 
|---|
| 154 |  .   .   .   I $P(DATA,"^",6)'="" S DEPDATE=$P(DATA,"^",6)
 | 
|---|
| 155 |  .   .   .   I DEPOSIT'="",DEPDATE'="" S RCDPFLAG=1  ; used to stop for loops
 | 
|---|
| 156 |  .   ;
 | 
|---|
| 157 |  .   S ^TMP($J,"RCDPXPAY","RETRAN",RCDPDA)=DEPOSIT_"^"_DEPDATE_"^"_$P(^RCY(344.2,RCDPDA,0),"^",4)
 | 
|---|
| 158 |  .   ;  remove the entry from the file so it will not appear later
 | 
|---|
| 159 |  .   D DELETRAN^RCDPXPA1(RCDPDA)
 | 
|---|
| 160 |  ;  if there are any, send a message asking for retransmission
 | 
|---|
| 161 |  I $O(^TMP($J,"RCDPXPAY","RETRAN",0)) D RETRAN^RCDPXPAM
 | 
|---|
| 162 |  ;
 | 
|---|
| 163 |  ;  clear the current transmission date lock, clear it here to prevent
 | 
|---|
| 164 |  ;  two processes from sending the retransmission request message
 | 
|---|
| 165 |  I $G(RCDPDATE) L -^RCY(344.2,RCDPDATE)
 | 
|---|
| 166 |  ;
 | 
|---|
| 167 |  ;  clean up
 | 
|---|
| 168 |  K ^TMP($J,"RCDPXPAY")
 | 
|---|
| 169 |  ;
 | 
|---|
| 170 |  ;  remove message from server basket
 | 
|---|
| 171 |  N K,X,XMK,XMSER,Y
 | 
|---|
| 172 |  S XMSER="S.RCDP AUTOMATIC PAYMENTS",XMZ=RCDPXMZ
 | 
|---|
| 173 |  D REMSBMSG^XMA1C
 | 
|---|
| 174 |  Q
 | 
|---|
| 175 |  ;
 | 
|---|
| 176 |  ;
 | 
|---|
| 177 | CONVDATE(DATE) ;  convert date from mmddyyyy to fm date cyymmdd
 | 
|---|
| 178 |  Q ($E(DATE,5,6)-17)_$E(DATE,7,8)_$E(DATE,1,2)_$E(DATE,3,4)
 | 
|---|