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

BAREDP4A.m

Go to the documentation of this file.
BAREDP4A ; IHS/SD/SDR - MATCH REASONS AND CLAIMS - 2 ; 01/09/2009
 ;;1.8;IHS ACCOUNTS RECEIVABLE;**20,21,23,24**;OCT 26, 2005;Build 69
 ;CLM/CLM2 split BARFROM BAREDP04 due to size
 ;IHS/SD/POT	APR 2012 HEAT#62015 BUG FIX: DO NOT CALL ^%DT IF DOS="" - BAR*1.8*.23
 ;IHS/SD/POT NOV 2012 HEAT#82698  LEADING/MISSING ZEROES IN BILL #- BAR*1.8*.23
 ;IHS/SD/POT JAN 2014 MATCHING MANUAL BILLS (NO ALPHA)- BAR*1.8*.24
 ;;
PAYER    ;EP
 S IENS=BARCKIEN_","_IMPDA_","
 S EPAYER=$$GET1^DIQ(90056.02011,IENS,".06")
 D ^XBFMK
 S DIC=$$DIC^XBDIQ1(90056.24)
 S DIC(0)="SMQ"
 S X=EPAYER
 D ^DIC
 Q:+Y<0  ;stop here if no match in A/R EDI BILL LOGIC file
 W !!,"A matching ""override"" has been set up for this A/R Account",!
 S BARIEN=+Y
 D DISPLAY^BAREDMCH
 D ^XBFMK
 K DIR
 S DIR(0)="Y"
 S DIR("A")="Do you wish to continue with the A/R Bill Matching using this criteria?"
 S DIR("B")="N"
 D ^DIR
 I Y=0 S QFLG=1 Q
 Q
CLM(BAREIENS,BARBILL,BARX,BARMMFLG) ;EP
 NEW BARMMTOT,BARMCNT,BARMMTYP ;- BAR*1.8*.23
 S BARMMVAL="" ;RETURN VALUE OF MATCHED ITEM
 S BARCNT=0
 K BILMATCH S BILMATCH=0
 ;
 S BARMMFLG=0 ;NEGATIVE IF MATCH, 0 IF NO MATCH 1 FOR BILLED AMOUNT MATCH, 2 FOR DOS MATCH
 S BARMMTOT=0 ;COUNT OF MISMATCHES
 F I=0:1:3 S BARMMCNT(I)=0
 S BARFND=0
 ;
 I $$GET1^DIQ(90056.0205,BAREIENS,1.01)'="" D  Q  ;ALREADY MATCHED
 . S BARBIEN=$$GET1^DIQ(90056.0205,BAREIENS,1.01,"I")
 . S BARFND=10
 . S BARX="B"
 . I $D(^BARBL(DUZ(2),"G",BARBILL))!$D(^BARBL(DUZ(2),"G",+BARBILL)) S BARX="G"
 . S BARTMP=$$FINDING(BARBILL) I +BARTMP S BARX="G",(BARBILL)=$P(BARTMP,"^",2)
 . I $$CLM3(1,BARBIEN,IMPDA,CLMDA,.BARMMTYP) ;JUST DISPLAY (1ST PARAM=1)
 . Q
 ;-------------------------------------------------2/27/2013>- BAR*1.8*.23
 S BARX="G"
 I $D(^BARBL(DUZ(2),BARX,BARTEST)) D  Q
 . S BARFND=1051
 . D CLM2(BARX,BARTEST,.BARMMFLG)
 . Q
 ;
 S BARX="B"
 I $D(^BARBL(DUZ(2),BARX,BARTEST)) D  Q
 . S BARFND=1052
 . D CLM2(BARX,BARTEST,.BARMMFLG)
 . Q
 ;-------------------------------------------------2/27/2013<
 ;TRY TO MATCH MANUAL BILL (form: nnnnn-IHS-WHATEVER) 2/13/2014 - BAR*1.8*.24
 ;
 S BARX="G"
 ;
 S BARSAVE=+BARBILL
 S BARBILL=+BARBILL_"-" ;2/12/2014
 F  S BARBILL=$O(^BARBL(DUZ(2),BARX,BARBILL)) Q:'+BARBILL  Q:$E(BARBILL,1,$L(BARSAVE))'=BARSAVE  D
 . S BARFND=104
 . D CLM2(BARX,BARBILL,.BARMMFLG)
 I BARFND QUIT  ;Found in POS
 S BARBILL=BARSAVE
 ;
 S BARX="B"
 ; 
 S BARSAVE=+BARBILL
 S BARBILL=+BARBILL_"-" ;2/12/2014
 F  S BARBILL=$O(^BARBL(DUZ(2),BARX,BARBILL)) Q:'+BARBILL  Q:$E(BARBILL,1,$L(BARSAVE))'=BARSAVE  D
 . S BARFND=105
 . D CLM2(BARX,BARBILL,.BARMMFLG)
 I BARFND QUIT  ;found in A/R
 S BARBILL=BARSAVE
 ;---------------------------------------------------------------------------------- END 2/13/2014 
 S BARX="G"
 S BARSAVE=BARBILL,BARBILL=BARBILL_"@"
 F  S BARBILL=$O(^BARBL(DUZ(2),BARX,BARBILL)) Q:'+BARBILL  Q:$E(BARBILL,1,$L(BARSAVE))'=BARSAVE  D
 . S BARFND=104
 . D CLM2(BARX,BARBILL,.BARMMFLG)
 I BARFND QUIT  ;If found in POS do not search in A/R -->
 S BARBILL=BARSAVE
 ;
 S BARX="B"
 S BARSAVE=BARBILL,BARBILL=BARBILL_"@"
 F  S BARBILL=$O(^BARBL(DUZ(2),BARX,BARBILL)) Q:'+BARBILL  Q:$E(BARBILL,1,$L(BARSAVE))'=BARSAVE  D
 . S BARFND=105
 . D CLM2(BARX,BARBILL,.BARMMFLG)
 I BARFND QUIT  ;If found in POS do not search in A/R -->
 ;
 S BARBILL=BARSAVE
 ;
 ;CHK POS (OPTION WITH MISSING LEADING ZEROES) -------------------------
 ;
 S BARTMP=$$FINDING(BARBILL)
 I +BARTMP S BARX="G",(BARBILL)=$P(BARTMP,"^",2) D
 . S BARX="G",BARFND=100
 . D CLM2("G",BARBILL,.BARMMFLG)
 I BARFND QUIT  ;if found in POS do not search in A/R -->
 ;
 ;CHK POS (OPTION WITH LEADING ZEROES)
 ;
 I $D(^BARBL(DUZ(2),"G",BARBILL)) D
 . S BARX="G",BARFND=1
 . D CLM2("G",BARBILL,.BARMMFLG)
 I BARFND QUIT  ;if found in POS do not search in A/R -->
 ;
 ;CHK POS (OPTION WITH NO LEADING ZEROES)
 ;
 I +BARBILL'=BARBILL I $D(^BARBL(DUZ(2),"G",+BARBILL)) D
 . S BARX="G",BARFND=2
 . D CLM2("G",+BARBILL,.BARMMFLG) ;CHK POS
 I BARFND QUIT  ; if found in POS do not search in A/R -->
 ;
 S BARX="B" ;
 ;CHK POS (OPTION WITH LEADING ZEROES)
 ;
 I $D(^BARBL(DUZ(2),BARX,BARBILL)) D
 . S BARFND=3
 . D CLM2(BARX,BARBILL,.BARMMFLG)
 I BARFND QUIT  ;
 S BARSAVE=BARBILL,BARBILL=BARBILL_"@"
 F  S BARBILL=$O(^BARBL(DUZ(2),BARX,BARBILL)) Q:'+BARBILL  Q:$E(BARBILL,1,$L(BARSAVE))'=BARSAVE  D
 . S BARFND=4
 . D CLM2(BARX,BARBILL,.BARMMFLG)
 I BARFND QUIT  ;if found in POS do not search in A/R -->
 ;
 S BARSAVE=BARBILL
 F  S BARBILL=$O(^BARBL(DUZ(2),BARX,BARBILL)) Q:'+BARBILL  Q:$E(BARBILL,1,$L(BARSAVE))'=BARSAVE  D
 . S BARFND=4
 . D CLM2(BARX,BARBILL,.BARMMFLG)
 S BARBILL=BARSAVE
 ;
 ;CHK POS (OPTION WITH NO LEADING ZEROES)
 ;
 I +BARBILL'=BARBILL I $D(^BARBL(DUZ(2),BARX,+BARBILL)) D
 . S BARFND=5
 . D CLM2(BARX,+BARBILL,.BARMMFLG)
 S BARSAVE=+BARBILL,BARBILL=+BARBILL_"@"
 ;
 F  S BARBILL=$O(^BARBL(DUZ(2),BARX,BARBILL)) Q:'BARBILL  Q:$E(BARBILL,1,$L(BARSAVE))'=BARSAVE  D
 . S BARFND=6
 . D CLM2(BARX,BARBILL,.BARMMFLG)
 I BARFND QUIT
 S BARBILL=BARSAVE
 Q
 ;
CLM2(BARX,BARBILL,BARMMFLG) ;
 S BARMMFLG=0
 S BARBIEN=0 F  S BARBIEN=$O(^BARBL(DUZ(2),BARX,BARBILL,BARBIEN)) Q:'+BARBIEN  D
 . I $$CLM3(2,BARBIEN,IMPDA,CLMDA,.BARMMTYP) D  Q  ;BLOCK FOR MATCHED
 . . S BARCNT=BARCNT+1
 . . S BARTMP(BARBIEN)="" ;ARRAY OF MATCHED BILLS
 . . S BARMMFLG=-1
 . . QUIT  ;
 . ;COUNTING TYPES OF UNMATCHED
 . S BARMMTOT=BARMMTOT+1 ;COUNT OF MISMATCHES (MM)
 . S BARMMCNT(BARMMTYP)=BARMMCNT(BARMMTYP)+1 ;COUNT TYPES OF MM
 . QUIT
 I $G(BARDBG) I BARMMCNT(1)+BARMMCNT(2)=1 D   ;ONE OR THE OTHER; NOT BOTH!
 . I BARMMCNT(1) S BARMMFLG=1 ;PARTIAL MATCH - AMOUNT MATCH"
 . I BARMMCNT(2) S BARMMFLG=2 ;PARTIAL MATCH - DOS MATCH"
 . Q
 Q
CLM3(BARFROM,BARBIEN,IMPDA,CLMDA,BARMMTYP) ;
 NEW ERABILL,ERADOS,BARDOS,BARAMT,ERATYPE,X,Y,ERADOS2
 S ERABILL=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,5)  ;E-BILLED
 S ERADOS=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,8)  ;E-DOS BEGIN
 S BARDOS=$$GET1^DIQ(90050.01,BARBIEN,102,"I")  ;DOS BEGIN
 S ERATYPE=$P($G(^BAREDI("I",DUZ(2),IMPDA,30,CLMDA,0)),U,11)  ;E-CLM STATUS CD
 K %DT
 S X=ERADOS I X]"" D ^%DT I Y'=-1 S ERADOS=Y ;P.OTT
 S BARAMT=$$GET1^DIQ(90050.01,BARBIEN,13,"I")  ;AMT BILLED
 I $G(BARDBG) D
 . D INS^BAR50DET("ERA BILL : "_$$GET1^DIQ(90056.0205,BAREIENS,.01),0)
 . D INS^BAR50DET($C(9,9)_"ERA BILL TYPE: "_ERATYPE,1)
 . D INS^BAR50DET("BAR BILL : "_BARBILL,0)
 . D INS^BAR50DET("ERA BILLED: "_ERABILL_$C(9,9)_"ERA DOS: "_ERADOS,0)
 . I $$GET1^DIQ(90056.0205,BAREIENS,.01)=0 Q  ;BAR*1.8*24
 . D INS^BAR50DET("A/R BILLED: "_BARAMT_$C(9,9)_"A/R DOS: "_BARDOS,0)
 . D INS^BAR50DET("A/R BILL# : "_BARBILL,0)
 S BARMMTYP=0 ;MATCH
 I ERABILL<0 S ERABILL=-ERABILL D  Q 0
 . I $G(BARDBG) D INS^BAR50DET($c(9,9)_"ERA BILL IS A NEGATIVE AMOUNT",1)
 I (+ERABILL=+BARAMT),(ERADOS=BARDOS) D  Q 1
 . S BILMATCH=BILMATCH+1,BILMATCH(BARBIEN)=""
 . I $G(BARDBG) D INS^BAR50DET("  MATCHED!",1)
 . QUIT  ;OK
 ; ---- NOT MATCHED - OTHER REASON FALL THRU	
 I BARFROM=1 QUIT 0
 ;BARMMTYP=0 - MATCH
 ;BARMMTYP=1 ONLY AMOUNT NOT MATCHED
 ;BARMMTYP=2 ONLY DOS NOT MATCHED
 ;BARMMTYP=3 AMOUNT & DOS NOT MATCHED
 ;
 I (+ERABILL'=+BARAMT),(ERADOS'=BARDOS) S BARMMTYP=3 D  Q 0
 . I $G(BARDBG) D INS^BAR50DET(" NOT MATCHED",1) Q  ;
 I (+ERABILL'=+BARAMT),(ERADOS=BARDOS) S BARMMTYP=1 D  Q 0
 . I $G(BARDBG) D INS^BAR50DET(" PARTIAL MATCH: DOS OK. AMT DIFF: $ "_$J(ERABILL-BARAMT,5,2),1) S BARMMVAL=BARDOS
 I (ERADOS'=BARDOS),(+ERABILL=+BARAMT) S BARMMTYP=2 D  Q 0
 . I $G(BARDBG) D INS^BAR50DET(" PARTIAL MATCH: AMOUNT OK",1) S BARMMVAL=BARAMT
 ; ---- NOT MATCHED - OTHER REASON FALL THRU		
 Q 0
 ;
TRANSCK  ;EP
 Q:$G(BARBIEN)=""  ;no bill number matched
 S BARTFLG=0
 S BARBTCH=$$GET1^DIQ(90056.02011,BARCKIEN,.07)
 S BARITEM=$$GET1^DIQ(90056.02011,BARCKIEN,.08)
 S BARTR=0,BARTFLG=0
 F  S BARTR=$O(^BARTR(DUZ(2),"AC",BARBIEN,BARTR)) Q:'BARTR  D  Q:(BARTFLG=1)
 . S BARTBTCH=$$GET1^DIQ(90050.03,BARTR,14)
 . S BARTITEM=$$GET1^DIQ(90050.03,BARTR,15)
 . I BARTBTCH'="",BARITEM'="",BARBTCH=BARTBTCH,BARITEM=BARTITEM S BARTFLG=1
 I BARTFLG S ERRORS("HTRN")=""
 Q
FINDING(BARBILL) ;RETURNS 1^BARXBILL (WITH MISSED OR ADDED LEADING ZERORS); OR 0
 NEW BARXBILL,BARRET,IXX ;REWRITE JAN 2013
 I $E(BARBILL)'="0" D  Q BARRET
 . S BARRET=0
 . S BARXBILL=BARBILL
 . F IXX=1:1 Q:($L(BARXBILL)=20)  D  Q:BARRET
 . . S BARXBILL="0"_BARXBILL
 . . I $D(^BARBL(DUZ(2),"G",BARXBILL)) S BARRET="1^"_BARXBILL
 . . Q
 . Q
 I $E(BARBILL)="0" D  Q BARRET
 . S BARRET=0
 . S BARXBILL=BARBILL
 . F IXX=1:1 Q:$E(BARXBILL,1)'="0"  D  Q:BARRET
 . . S BARXBILL=$E(BARXBILL,2,999) I BARXBILL=""  Q
 . . I $D(^BARBL(DUZ(2),"G",BARXBILL)) S BARRET="1^"_BARXBILL
 . . Q
 . Q
    I BARBILL=+BARBILL D  Q BARRET
    . S BARXBILL=+BARBILL
    . I $D(^BARBL(DUZ(2),"G",BARXBILL)) S BARRET="1^"_BARXBILL
    . Q
 Q ""  ;NEVER FALLS THROUGH