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

ACRFFF2.m

Go to the documentation of this file.
ACRFFF2 ;IHS/OIRM/DSD/AEF - PRODUCE FLAT FILE OF ITEMS ORDERED [ 10/27/2004   4:18 PM ]
 ;;2.1;ADMIN RESOURCE MGT SYSTEM;**13**;NOV 05, 2001
 ;
 ;
DESC ;----- ROUTINE DESCRIPTION
 ;;Create Items Ordered Flat File
 ;;
 ;;This option will gather all items ordered within the specified
 ;;date range for the specified object class code(s) and place them
 ;;into a comma delimited flat file which can then be imported
 ;;into an Access or Excel spreadsheet.
 ;;
 ;;Fields included in the flat file are:
 ;;     Requisition Number
 ;;     Document identifier
 ;;     Purchase Order Number
 ;;     Date of Purchase Order
 ;;     Vendor Name
 ;;     Order Number (Vendor or Part Number)
 ;;     National Stock Number (NSN)
 ;;     Description Lines 1-5
 ;;     Quantity
 ;;     Unit of Issue
 ;;     Unit Cost
 ;;     Object Class Code
 ;;     Can Number
 ;;     Fiscal Year of Funds
 ;;     Department Account Name
 ;;$$END
 ;
EN ;EP -- MAIN ENTRY POINT
 ;
 N ACRDATES,ACRFILE,ACRLOC,ACROCC,ACROUT
 ;
 D ^XBKVAR
 D HOME^%ZIS
 ;
 D TXT
 ;
 D DATE(.ACRDATES)
 Q:$G(ACRDATES)']""
 ;
 D OCC(.ACROCC)
 Q:$G(ACROCC)']""
 ;
 D LOC(.ACRLOC)
 Q:'$G(ACRLOC)
 ;
 D FILE(.ACRFILE)
 Q:$G(ACRFILE)']""
 ;
 W "   please wait..."
 ;
 D GET(ACRDATES,ACROCC,ACRLOC)
 ;
 I '$D(^TMP("ACR",$J,"ITEMS")) D  Q
 . W !!,"No data found"
 . D PAUSE^ACRFWARN
 ;
 D UNIX(ACRFILE)
 ;
 K ^TMP("ACR",$J,"ITEMS")
 ;
 ;D ^%ZISC                               ;ACR*2.1*13.01 IM13574
 ;
 D PAUSE^ACRFWARN
 ;
 Q
GET(ACRDATES,ACROCC,ACRLOC)  ;
 ;----- LOOP THROUGH AND GET ORDERS
 ;
 N ACRBEG,ACRDATA,ACRDATE,ACRDOCDA,ACREND,ACRREF
 K ^TMP("ACR",$J,"ITEMS")
 S ACRBEG=$P(ACRDATES,U)
 S ACREND=$P(ACRDATES,U,2)
 S ACRDATE=ACRBEG-1
 F  S ACRDATE=$O(^ACRDOC("DT",ACRDATE)) Q:'ACRDATE  Q:ACRDATE>ACREND  D
 . S ACRDOCDA=0
 . F  S ACRDOCDA=$O(^ACRDOC("S",ACRDATE,ACRDOCDA)) Q:'ACRDOCDA  D
 . . S ACRDATA=$G(^ACRDOC(ACRDOCDA,0))
 . . Q:$P(ACRDATA,U,14)["CANCELLED"
 . . S ACRREF=$P(ACRDATA,U,13)
 . . S ACRREF=$P($G(^AUTTDOCR(ACRREF,0)),U)
 . . Q:"^116^103"'[ACRREF
 . . S ACRLOCDA=$P(ACRDATA,U,6)
 . . I ACRLOCDA S ACRLOCDA=$P($G(^ACRLOCB(ACRLOCDA,"DT")),U,11)
 . . Q:ACRLOCDA'=ACRLOC
 . . D ITEMS(ACRDOCDA,ACROCC,ACRDATE)
 ;
 Q
ITEMS(ACRDOCDA,ACROCC,ACRDATE)         ;
 ;----- GET PO ITEMS AND PUT IN ^TMP GLOBAL
 ;
 N ACRCAN,ACRCOST,ACRDATA,ACRITMDA,ACRDEPT,ACRDESC1,ACRDESC2,ACRDESC3,ACRDESC4,ACRDESC5,ACRDOCNO,ACRNSN,ACROCCC,ACROCCDA,ACRORDNO,ACRPO,ACRQTY,ACRUI,ACRVEND,ACRID,ACRFY  ;ACR*2.1*13.06 IM14144
 S ACRITMDA=0
 F  S ACRITMDA=$O(^ACRSS("C",ACRDOCDA,ACRITMDA)) Q:'ACRITMDA  D
 . S ACRDATA=$G(^ACRSS(ACRITMDA,0))
 . S ACRDATA=$TR(ACRDATA,"""")                ;ACR*2.1*13.06 IM14144
 . S ACROCCDA=$P(ACRDATA,U,4)
 . Q:'ACROCCDA
 . S ACROCCC=$P($G(^AUTTOBJC(ACROCCDA,0)),U)
 . I $E(ACROCC,3,4)="00" Q:$E(ACROCCC,1,2)'=$E(ACROCC,1,2)
 . I $E(ACROCC,3,4)'="00" Q:ACROCCC'=ACROCC
 . S ACRCAN=$P(ACRDATA,U,5)
 . S ACRCAN=$P($G(^AUTTCAN(ACRCAN,0)),U)
 . S ACRDEPT=$P(ACRDATA,U,6)
 . S ACRFY=$$FYFUN^ACRFUTL1(ACRDEPT)          ;ACR*2.1*13.06 IM14144 
 . S ACRDEPT=$P($G(^ACRLOCB(ACRDEPT,0)),U,5)
 . I ACRDEPT S ACRDEPT=$P($G(^AUTTPRG(ACRDEPT,0)),U)
 . S ACRDATA=$G(^ACRSS(ACRITMDA,"DESC"))
 . S ACRDATA=$TR(ACRDATA,"""")                ;ACR*2.1*13.06 IM14144
 . S ACRDESC1=$P(ACRDATA,U)
 . S ACRDESC2=$P(ACRDATA,U,2)
 . S ACRDESC3=$P(ACRDATA,U,3)
 . S ACRDESC4=$P(ACRDATA,U,4)
 . S ACRDESC5=$P(ACRDATA,U,5)
 . S ACRDATA=$G(^ACRSS(ACRITMDA,"DT"))
 . S ACRDATA=$TR(ACRDATA,"""")                ;ACR*2.1*13.06 IM14144
 . S ACRQTY=$P(ACRDATA,U)
 . S ACRUI=$P(ACRDATA,U,2)
 . I ACRUI S ACRUI=$P($G(^ACRUI(ACRUI,0)),U)
 . S ACRCOST=$P(ACRDATA,U,3)
 . S ACRDATA=$G(^ACRSS(ACRITMDA,"NMS"))
 . S ACRDATA=$TR(ACRDATA,"""")                ;ACR*2.1*13.06 IM14144
 . S ACRORDNO=$P(ACRDATA,U)
 . S ACRNSN=$P(ACRDATA,U,2)
 . I ACRNSN']"" D
 . . S ACRNSN=$P($G(^ACRSS(ACRITMDA,0)),U,12)
 . . I ACRNSN S ACRNSN=$P($G(^ACRITEM(ACRNSN,"DT")),U,4)
 . S ACRDATA=$G(^ACRDOC(ACRDOCDA,0))
 . S ACRDATA=$TR(ACRDATA,"""")                ;ACR*2.1*13.06 IM14144
 . S ACRDOCNO=$P(ACRDATA,U)
 . S ACRPO=$P(ACRDATA,U,2)
 . S ACRID=$P(ACRDATA,U,14)                   ;ACR*2.1*13.06 IM14144
 . S ACRVEND=$P($G(^ACRDOC(ACRDOCDA,"PO")),U,5)
 . I ACRVEND S ACRVEND=$P($G(^AUTTVNDR(ACRVEND,0)),U)
 . ;S ^TMP("ACR",$J,"ITEMS",ACRDOCDA,ACRITMDA,0)=ACRDOCNO_U_ACRPO_U_$$SLDATE^ACRFUTL(ACRDATE)_U_ACRVEND_U_ACRORDNO_U_ACRNSN_U_ACRDESC1_U_ACRDESC2_U_ACRDESC3_U_ACRDESC4_U_ACRDESC5  ;ACR*2.1*13.06 IM14144
 . ;S ^TMP("ACR",$J,"ITEMS",ACRDOCDA,ACRITMDA,0)=^TMP("ACR",$J,"ITEMS",ACRDOCDA,ACRITMDA,0)_U_ACRQTY_U_ACRUI_U_$$DOL^ACRFUTL(ACRCOST)_U_ACROCCC_U_ACRCAN_U_ACRDEPT  ;ACR*2.1*13.06 IM14144
 . S ACRDATA=ACRDOCNO_U_ACRID_U_ACRPO_U_$$SLDATE^ACRFUTL(ACRDATE)  ;ACR*2.1*13.06 IM14144
 . S ACRDATA=ACRDATA_U_ACRVEND_U_ACRORDNO_U_ACRNSN_U_ACRDESC1  ;ACR*2.1*13.06 IM14144
 . S ACRDATA=ACRDATA_U_ACRDESC2_U_ACRDESC3_U_ACRDESC4_U_ACRDESC5  ;ACR*2.1*13.06 IM14144
 . S ACRDATA=ACRDATA_U_ACRQTY_U_ACRUI_U_$$DOL^ACRFUTL(ACRCOST)  ;ACR*2.1*13.06 IM14144
 . S ACRDATA=ACRDATA_U_ACROCCC_U_ACRCAN_U_ACRFY_U_ACRDEPT  ;ACR*2.1*13.06 IM14144
 . S ^TMP("ACR",$J,"ITEMS",ACRDOCDA,ACRITMDA,0)=ACRDATA  ;ACR*2.1*13.06 IM14144
 Q
UNIX(ACRFILE)      ;
 ;----- WRITE ^TMP GLOBAL TO FLAT FILE             ;ACR*2.1*13.06 IM14144
 ;
 ;N %FILE,ACRCNT,ACRDOCDA,ACRITMDA,ACROUT,X        ;ACR*2.1*13.06 IM14144
 N %FILE,ACRCNT,ACRDOCDA,ACRITMDA,ACROUT,X,ACRDIR  ;ACR*2.1*13.06 IM14144
 Q:'$D(^TMP("ACR",$J,"ITEMS"))
 ;D HFS(.ACROUT,.%FILE,ACRFILE)                    ;ACR*2.1*13.06 IM14144
 D HFS(.ACROUT,.%FILE,.ACRDIR,ACRFILE)             ;ACR*2.1*13.06 IM14144
 Q:$G(ACROUT)
 U %FILE
 S ACRCNT=0
 S ACRDOCDA=0
 F  S ACRDOCDA=$O(^TMP("ACR",$J,"ITEMS",ACRDOCDA)) Q:'ACRDOCDA  D
 . S ACRITMDA=0
 . F  S ACRITMDA=$O(^TMP("ACR",$J,"ITEMS",ACRDOCDA,ACRITMDA)) Q:'ACRITMDA  D
 . . S X=$G(^TMP("ACR",$J,"ITEMS",ACRDOCDA,ACRITMDA,0))
 . . S ACRCNT=$G(ACRCNT)+1
 . . D WRITE(X)
 . . W !
 ;U 0 W !!,ACRCNT_" Records have been put into UNIX file /usr/spool/afsdata/"_ACRFILE   ; ACR*2.1*13.06 IM14144
 ;D ^%ZISC   ; ACR*2.1*13.06 IM14144
 U 0 W !!,ACRCNT_" Records have been put into file "_ACRDIR_ACRFILE ; ACR*2.1*13.06 IM14144
 D CLOSE^ACRFZISH("FILE")            ; ACR*2.1*13.06 IM14144
 H 3
 Q
WRITE(X) ;----- FORMAT AND WRITE DATA TO FLAT FILE       ;ACR*2.1*13.06 IM14144
 ;
 F I=1:1:$L(X,U) D
 . S Y=$P(X,U,I)
 . W """"
 . W Y
 . W """"
 . W ","
 Q
DATE(ACRDATES)     ;
 ;----- ASK DATE RANGE
 ;
DLOOP ;----- DATE LOOP
 ;
 N ACRBEG,ACREND,DIR,DIRUT,DTOUT,DUOUT,X,Y
 W !
 S DIR(0)="DO^::E"
 S DIR("A")="Begin with ORDER DATE"
 S DIR("?")="The date the order was placed"
 D ^DIR
 Q:$D(DTOUT)!($D(DUOUT))!($D(DIRUT))
 Q:Y=""
 S ACRBEG=Y
 S DIR("A")="End with ORDER DATE"
 D ^DIR
 Q:$D(DTOUT)!($D(DUOUT))!($D(DIRUT))
 Q:Y=""
 S ACREND=Y
 I ACREND<ACRBEG D  G DLOOP
 . W *7,!?5,"ENDING DATE cannot be less than BEGINNING DATE"
 S ACRDATES=ACRBEG_U_ACREND
 Q
OCC(ACROCC)        ;
 ;----- ASK OBJECT CLASS CODE RANGE
 ;
 S DIR(0)="F^4:4"
 S DIR("A")="Select OBJECT CLASS CODE or GROUP"
 S DIR("?")="The OBJECT CLASS CODE or OBJECT CLASS CODE GROUP, e.g., 2600, 3100, 3200"
 D ^DIR
 Q:$D(DTOUT)!($D(DUOUT))!($D(DIRUT))
 S ACROCC=Y
 Q
LOC(ACRLOC)        ;
 ;----- ASK LOCATION CODE
 ;
 S DIC="^AUTTLCOD("
 S DIC(0)="AEMQ"
 D ^DIC
 Q:$D(DTOUT)!($D(DUOUT))
 Q:Y'>0
 S ACRLOC=+Y
 Q
FILE(ACRFILE)      ;
 ;----- ASK FILE NAME
 ;
 N DIR,DIRUT,DTOUT,DUOUT,X,Y
 S ACRFILE=""
 S DIR(0)="F"
 ;S DIR("A")="Select UNIX FILE NAME"       ;ACR*2.1*13.06 IM14144
 S DIR("A")="Select FILE NAME"             ;ACR*2.1*13.06 IM14144
 ;S DIR("?")="The name of the UNIX file you want to put the data into"  ;ACR*2.1*13.06 IM14144
 S DIR("?")="The name of the file you want to put the data into"  ;ACR*2.1*13.06 IM14144
 D ^DIR
 Q:$D(DTOUT)!($D(DUOUT))!($D(DIRUT))
 S ACRFILE=Y_".csv"
 Q
 ; HFS(ACROUT,%FILE,ACRFILE)    ; OLD FHS:     ; ACR*2.1*13.06 IM14144
 ;----- CREATE AND OPEN UNIX FILE
 ;
 ;N X,Y,ZISH1,ZISH2,ZISH3
 ;S ZISH1="/usr/spool/afsdata/"
 ;S ZISH2=ACRFILE
 ;S ZISH3="W"
 ;S Y=$$OPEN^ZISHMSMU(ZISH1,ZISH2,ZISH3)
 ;I Y D  Q
 ;. W "CANNOT OPEN FILE "_ZISH1_ZISH2
 ;. S ACROUT=1
 ;S %FILE=IO
 ;Q
HFS(ACROUT,%FILE,ACRDIR,ACRFILE)    ;         ;ACR*2.1*13.06 IM14144    
 ;----- CREATE AND OPEN FLAT FILE     ;ACR*2.1*13.06 IM14144    
 ;
 N X,Y,ZISH2,ZISH3                    ;ACR*2.1*13.06 IM14144
 S ACRDIR=$$ARMSDIR^ACRFSYS(1)        ;ACR*2.1*13.06 IM14144
 Q:ACRDIR']""                         ;ACR*2.1*13.06 IM14144
 S ZISH2=ACRFILE                      ;ACR*2.1*13.06 IM14144
 S ZISH3="W"                                      ;ACR*2.1*13.01 IM13574
 D HFS^ACRFZISH(ACRDIR,ZISH2,ZISH3,.%FILE) ;VERBOSE  ;ACR*2.1*13.01 IM13574
 I $G(%FILE)']"" S ACROUT=1                       ;ACR*2.1*13.01 IM13574
 Q
TXT ;----- PRINT OPTION TEXT
 ;
 F I=1:1 S X=$P($T(DESC+I),";",3) Q:X["$$END"  W !,X
 Q