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

ACRFIRS1.m

Go to the documentation of this file.
ACRFIRS1 ;IHS/OIRM/DSD/AEF - CREATE 1099 RECORDS FOR IRS; [ 07/20/2006   4:18 PM ]
 ;;2.1;ADMIN RESOURCE MGT SYSTEM;**1,6,8,13,20**;NOV 05, 2001
 ;
 ;      This routine gathers vendor payment data and puts it into a 
 ;      UNIX file to be transmitted to the IRS.
 ;      Routine ACRFIRS2 contains the record layout formats.
 ;
 ;      VARIABLE LIST SET AND USED BY ACRFIRS1 AND ACRFIRS2
 ;
 ;      ACRAREA   =  FINANCE AREA
 ;      ACRSTA    =  ANSWER IRS OR STATE
 ;      ACRFSTN   =  STATE NAME
 ;      ACRSTNO   =  STATE IEN
 ;      ACRSTAN   =  STATE IEN THE REPORT IS FOR
 ;      ACRSADR   =  VENDOR ADDRESS TYPE TO BE USED
 ;      ACRZOUT   =  QUIT CONTROLLER VARIABLE
 ;      ACRCNTA   =  COUNT OF A RECORDS
 ;      ACRCNTB   =  COUNT OF B RECORDS
 ;      ACRCNTR   =  SEQUENCE NUMBER OF RECORD ;ACR*2.1*6.01
 ;      ACRVEND0  =  LOOP COUNTER IN VENDOR FILE, VENDOR IEN
 ;      ACRNAME   =  VENDOR NAME
 ;      ACRAMT    =  VENDOR YTD PAID AMOUNT
 ;      ACRTIN    =  VENDOR TIN#
 ;      ACRADD    =  VENDOR ADDRESS
 ;      ACRCITY   =  VENDOR CITY
 ;      ACRSTAB   =  VENDOR STATE ABBREVIATION
 ;      ACRZIP    =  VENDOR ZIP CODE
 ;      ACRPMYR   =  PAYMENT YEAR
 ;      ACRTOT(   =  ARRAY CONTAINING PAYMENT TOTALS
 ;      ACRTOTAL  =  PAYMENT GRAND TOTAL
 ;      ACRAMTCD  =  PAYMENT AMOUNT TYPE CODE
 ;      ACRFOR    =  FOREIGN VENDOR (1 or NULL)  ;ACR*2.1*8.05
 ;
EN ;EP -- MAIN ENTRY POINT
 ;
 N ACRAREA,ACRFSTN,ACRPMYR,ACRSADR,ACRSTA,ACRSTAN
 ;
 D ^XBKVAR
 D HOME^%ZIS
 ;
 D AREA(.ACRAREA)
 Q:'$G(ACRAREA)
 ;
 D STATE(.ACRSTA,.ACRFSTN,.ACRSTAN)
 Q:$G(ACRSTA)']""
 ;
 D YEAR(.ACRPMYR)
 Q:'$G(ACRPMYR)
 ;
 D ADDRESS(.ACRSADR)
 Q:$G(ACRSADR)']""
 ;
 D GET(ACRAREA,ACRPMYR,ACRSADR,ACRFSTN,ACRSTAN)
 ;
 D UNIX(ACRFSTN)
 ;
 D PRINT(ACRPMYR,ACRSTA)
 ;
 K ^TMP("ACRZ",$J,"RECORD")
 D ^%ZISC
 Q
GET(ACRAREA,ACRPMYR,ACRSADR,ACRFSTN,ACRSTAN)     ;
 ;----- GATHER DATA AND PUT INTO ^TMP GLOBAL
 ;
 ;      INPUT:
 ;      ACRAREA = FINANCE AREA
 ;      ACRPMYR = PAYMENT YEAR
 ;      ACRSADR = VENDOR ADDRESS TYPE
 ;      ACRFSTN = STATE NAME
 ;      ACRSTAN = STATE IEN
 ;
 ;      OTHER VARIABLES USED:
 ;      ACRCNTA = COUNT OF A RECORDS
 ;      ACRCNTB = COUNT OF B RECORDS
 ;      ACRTOT( = ARRAY CONTAINING PAYMENT TOTALS
 ;
 N ACRCNTA,ACRCNTB,ACRTOT,ACRCNTR  ;ACR*2.1*6.01
 ;
 K ^TMP("ACRZ",$J)
 ;
 W !,"Working..."
 ;
 D RECORDA^ACRFIRS2(ACRAREA,ACRPMYR,.ACRCNTA)
 ;
 S ACRCNTR=2               ; FIRST B RECORD WILL BE #3 ACR*2.1*6.01
 D LOOP(ACRPMYR,ACRSADR,ACRFSTN,ACRSTAN,.ACRTOT,.ACRCNTB,.ACRCNTR) ; ACR*2.1*6.06
 ;
 D RECORDC^ACRFIRS0(ACRAREA,.ACRTOT,ACRCNTB,.ACRCNTR) ; ACR*2.1*6.01,ACR*2.1*8.07
 ;
 D RECORDF^ACRFIRS0(ACRCNTA,.ACRCNTR)       ; ACR*2.1*6.01,ACR*2.1*8.07
 ;
 D RECORDT^ACRFIRS0(ACRAREA,ACRPMYR,ACRCNTB)          ;ACR*2.1*8.07
 ;
 Q
LOOP(ACRPMYR,ACRSADR,ACRFSTN,ACRSTAN,ACRTOT,ACRCNTB,ACRCNTR)       ;
 ;----- LOOP THROUGH VENDOR FILE AND GATHER RECORD B DATA
 ;
 ;      INPUT:
 ;      ACRPMYR = PAYMENT YEAR
 ;      ACRSADR = VENDOR ADDRESS TYPE
 ;      ACRFSTN = STATE NAME
 ;      ACRSTAN = STATE IEN
 ;      ACRTOT( = ARRAY CONTAINING PAYMENT TOTALS
 ;      ACRCNTR = SEQUENCE RECORD NUMBER ; ACR*2.1*6.01
 ;
 ;      RETURNS:
 ;      ACRCNTB = COUNT OF B RECORDS
 ;      ACRCNTR = SEQUENCE RECORD COUNT ; ACR*2.1*6.01
 ;
 ;      OTHER VARIABLES USED:
 ;      ACRADD   = VENDOR ADDRESS
 ;      ACRAMT   = PAYMENT AMOUNT
 ;      ACRAMTCD = PAYMENT AMOUNT CODE
 ;      ACRCITY  = VENDOR CITY
 ;      ACRNAME  = VENDOR NAME
 ;      ACRSTAB  = VENDOR STATE ABBREVIATION
 ;      ACRSTNO  = STATE IEN
 ;      ACRTIN   = VENDOR TIN#
 ;      ACRTOTAL = PAMENT GRAND TOTAL
 ;      ACRVEND0 = LOOP COUNTER IN VENDOR FILE (VENDOR IEN)
 ;      ACRZIP   = VENDOR ZIP CODE
 ;   
 ;
 N ACRADD,ACRAMT,ACRAMTCD,ACRCITY,ACRNAME,ACRSTAB,ACRSTNO,ACRTIN,ACRTOTAL,ACRVEND0,ACRZIP,DATA,I
 ;
 K ACRTOT
 ;
 F I=1:1:9,"A","B","C" S ACRTOT(I)=0
 ;
 S (ACRVEND0,ACRCNTB,ACRTOTAL)=0
 F  S ACRVEND0=$O(^ACR1099V("C",ACRPMYR,ACRVEND0)) Q:'ACRVEND0  D
 . S ACRNAME=$$UPPER^ACRFUTL($P(^AUTTVNDR(ACRVEND0,0),U)) ;ACR*2.1*6.01
 . Q:'$D(^AUTTVNDR(ACRVEND0,11))
 . S ACRV0=$G(^ACR1099V(ACRVEND0,0)) ; ACR*2.1*8.05
 . S ACRAMTCD=$P(ACRV0,U,2)          ; ACR*2.1*8.05
 . S ACRFOR=$P(ACRV0,U,4)            ; ACR*2.1*8.05
 . Q:ACRAMTCD=""
 . S ACRAMT=+$P(^ACR1099V(ACRVEND0,1,ACRPMYR,0),U,2)
 . Q:'ACRAMT
 . S ACRAMT=ACRAMT*100
 . Q:ACRAMT<60000
 . S ACRTIN=$P($G(^AUTTVNDR(ACRVEND0,11)),U)
 . Q:ACRTIN=""
 . I ACRSADR="M" D
 . . S DATA=$$UPPER^ACRFUTL($G(^AUTTVNDR(ACRVEND0,13)))   ;ACR*2.1*6.01
 . . S ACRADD=$P(DATA,U)
 . . S ACRCITY=$P(DATA,U,2)
 . . S ACRSTNO=$P(DATA,U,3)
 . . I ACRSTNO="" S ACRSTNO=56       ;UNKNOWN     ACR*2.1*20.02  IM16042
 . . S ACRSTAB=$P($G(^DIC(5,ACRSTNO,0)),U,2)
 . . S ACRZIP=$P(DATA,U,4)
 . I ACRSADR="B" D
 . . S DATA=$$UPPER^ACRFUTL($G(^AUTTVNDR(ACRVEND0,13)))   ;ACR*2.1*6.01
 . . S ACRADD=$P(DATA,U,6)
 . . S ACRCITY=$P(DATA,U,7)
 . . S ACRSTNO=$P(DATA,U,8)
 . . I ACRSTNO="" S ACRSTNO=56       ;UNKNOWN    ACR*2.1*20.02  IM16042
 . . S ACRSTAB=$P($G(^DIC(5,ACRSTNO,0)),U,2)
 . . S ACRZIP=$P(DATA,U,9)
 . I ACRSADR="R" D
 . . S DATA=$$UPPER^ACRFUTL($G(^AUTTVNDR(ACRVEND0,14)))   ;ACR*2.1*6.01
 . . S ACRADD=$P(DATA,U)
 . . S ACRCITY=$P(DATA,U,3)
 . . S ACRSTNO=$P(DATA,U,4)
 . . I ACRSTNO="" S ACRSTNO=56       ;UNKNOWN    ACR*2.1*20.02  IM16042
 . . S ACRSTAB=$P($G(^DIC(5,ACRSTNO,0)),U,2)
 . . S ACRZIP=$P(DATA,U,5)
 . Q:ACRADD=""
 . Q:ACRCITY=""
 . Q:ACRSTAB=""
 . Q:ACRZIP=""
 . I ACRFSTN'="US" Q:ACRSTNO'=ACRSTAN
 . S ACRTOTAL=$G(ACRTOTAL)+ACRAMT
 . D RECORDB^ACRFIRS2(ACRPMYR,ACRNAME,ACRTIN,ACRVEND0,ACRAMT,ACRAMTCD,ACRADD,ACRCITY,ACRSTAB,ACRZIP,.ACRCNTB,.ACRTOT,.ACRCNTR,ACRFOR)   ;ACR*2.1*6.01,ACR*2.1*8.05
 . S ^TMP("ACRZ",$J,"REPORT",ACRVEND0,0)=ACRNAME_U_$E(ACRTIN,2,10)_U_ACRAMT
 S ^TMP("ACRZ",$J,"REPORT TOTAL",0)=ACRTOTAL
 Q
PRINT(ACRPMYR,ACRSTA)        ;
 ;----- PROMPT FOR DEVICE TO PRINT REPORT TO
 ;
 N ACRJ,ZTSAVE
 D HOME^%ZIS
 S ACRJ=$J
 S ZTSAVE("ACRJ")=""
 S ZTSAVE("ACRPMYR")=""
 S ZTSAVE("ACRSTA")=""
 D QUE^ACRFUTL("DQ^ACRFIRS3",.ZTSAVE,"1099 VENDOR REPORT")
 Q
 ;
AREA(ACRAREA)      ;
 ;----- PROMPT FOR AREA
 ;
 ;      RETURNS:
 ;      ACRAREA = FINANCE AREA
 ;
 N DIC,X,Y
 S ACRAREA=""
 S DIC="^ACR1099P("
 S DIC(0)="AQZEM"
 D ^DIC
 K DIC
 Q:+Y'>0!($D(DTOUT))!($D(DUOUT))
 S ACRAREA=+Y
 Q
 ;
STATE(ACRSTA,ACRFSTN,ACRSTAN)          ;
 ;----- PROMPT FOR STATE OR IRS
 ;
 ;      RETURNS:
 ;      ACRSTA  = ANSWER IRS OR STATE
 ;      ACRFSTN = STATE NAME
 ;      ACRSTAN = STATE IEN
 ;
STA ;----- PROMPT LOOP
 ;
 N DIR,X,Y
 S (ACRSTA,ACRFSTN,ACRSTAN)=""
 S DIR(0)="F^2:3^K:X'?.U X"
 S DIR("A")="Enter 2 character State Abbreviation or 'IRS'"
 S DIR("A",1)=""
 S DIR("A",2)="This generates files containing 1099 records.  You must select a STATE or IRS"
 S DIR("A",3)="and a file will be generated for that selection.  You may run this program"
 S DIR("A",4)="as many times as necessary until all STATE files needed are created."
 S DIR("A",5)=""
 D ^DIR
 Q:Y']""!($D(DTOUT))!($D(DUOUT))!($D(DIRUT))
 S (ACRSTA,ACRFSTN)=Y
 I ACRFSTN="IRS" S ACRFSTN="US" Q
 S ACRSTAN=$O(^DIC(5,"C",ACRSTA,0))
 I 'ACRSTAN W *7,"   NO SUCH STATE",! K ACRSTA,ACRSTAN,ACRFSTN G STA
 Q
 ;
YEAR(ACRPMYR)      ;
 ;----- PROMPT FOR YEAR
 ;
 ;      RETURNS:
 ;      ACRPMYR = PAYMENT YEAR
 ;
 N DIR,X,Y
 S ACRPMYR=""
 S DIR(0)="N^0000:9999"
 S DIR("A")="Enter Calendar Year (eg 1998)"
 S DIR("B")=($E(DT,1,3)+1700)-1
 D ^DIR
 Q:+Y'>0!($D(DTOUT))!($D(DUOUT))!($D(DIRUT))
 S ACRPMYR=Y
 Q
 ;
ADDRESS(ACRSADR)   ;
 ;----- PROMPT FOR ADDRESS TO USE
 ;
 ;      RETURNS:
 ;      ACRSADR = VENDOR ADDRESS TYPE
 ;
 N DIR,X,Y
 S ACRSADR=""
 S DIR(0)="S^M:Mailing Address;B:Billing Address;R:Remit To Address"
 S DIR("A")="Which VENDOR File Address is to be used?"
 S DIR("B")="M"
 D ^DIR
 Q:Y']""!($D(DTOUT))!($D(DIROUT))!($D(DUOUT))
 S ACRSADR=Y
 Q
 ;
 ;
UNIX(ACRSTN)       ;
 ;----- WRITE ^TMP GLOBAL TO UNIX FILE
 ;
 N %DEV,ACRAREA,ACRDIR,ACRFILE,ACRVEND0,ACRZOUT,I,J
 Q:'$D(^TMP("ACRZ",$J))
 ;S ACRDIR=$$ARMSDIR^ACRFIRSU(1)      ; ACR*2.1*13.06 IM14144
 S ACRDIR=$$ARMSDIR^ACRFSYS(1)        ; ACR*2.1*13.06 IM14144
 I ACRDIR["alb"!(ACRDIR["hqw") D      ; ACR*2.1*8.08
 .S ACRDIR=ACRDIR_"csv/"              ; ACR*2.1*8.08
 D HFS(ACRDIR,ACRSTN,.ACRZOUT,.ACRFILE,.%DEV)
 Q:$G(ACRZOUT)
 U %DEV
 F I=1:1:4 W $G(^TMP("ACRZ",$J,"RECORD","T",I))
 S ACRAREA=0
 F  S ACRAREA=$O(^TMP("ACRZ",$J,"RECORD","A",ACRAREA)) Q:'ACRAREA  D
 . F I=1:1:4 W $G(^TMP("ACRZ",$J,"RECORD","A",ACRAREA,I))
 . S ACRVEND0=0
 . F  S ACRVEND0=$O(^TMP("ACRZ",$J,"RECORD","B",ACRAREA,ACRVEND0)) Q:'ACRVEND0  D
 . . F J=1:1:4 W $G(^TMP("ACRZ",$J,"RECORD","B",ACRAREA,ACRVEND0,J))
 . F I=1:1:4 W $G(^TMP("ACRZ",$J,"RECORD","C",ACRAREA,I))
 F I=1:1:4 W $G(^TMP("ACRZ",$J,"RECORD","F",I))
 U 0 W !!,"Records have been put into file "_ACRDIR_ACRFILE
 D CLOSE^%ZISH("FILE")
 K %DEV
 Q
HFS(ACRDIR,ACRSTN,ACRZOUT,ACRFILE,%DEV)          ;
 ;----- CREATE AND OPEN UNIX FILE
 ;
 N POP,X,Y
 S ACRFILE="acrirs"_ACRFSTN_"."_$E(DT,1,3)_$$JDATE^ACRFUTL
 D OPEN^%ZISH("FILE",ACRDIR,ACRFILE,"W")
 I POP D  Q
 . S ACRZOUT=1
 . W !,"UNABLE TO OPEN FILE "_ACRFILE
 S %DEV=IO
 Q
 ;
NCTL(X) ;EP -- NAME CONTROL - RETURNS FIRST 4 SIGNIFICANT CHARACTERS
 ;
 ;      X  =  VENDOR NAME
 ;
 S X=$TR(X," ~!@#$%^*()_+`-={}|[]\:"""";'<>?,./","")
 S X=$E(X,1,4)
 Q X