*          ***********  IOPOST COMMAND FILE  *****************
* Gets information for insertion orders (instruction to magazine
* publishers from our ad agency).  Works much like Postbills and
* Posttime.
*********************************************************************

RESTORE FROM B:Constant

DO GetDate

USE B:Inserts
COPY STRUCTURE TO GetInser  
USE GetInser  

STORE Client TO MClient
STORE ' ' TO New
STORE 'Y' TO Inserting
DO WHILE !(Inserting) <> 'F'
   APPEND BLANK
   STORE STR(#,5) TO Number
   REPLACE IO:Date WITH Date, IO:Nmbr WITH Next:IO

   ERASE
   * Next loop is used when there has been an error in the entry
   * (defined as no client or no rate).
   STORE 'T' TO Incorrect
   DO WHILE !(Incorrect) <> 'F'
      ERASE
      @ 4,0 SAY ' INSERTION ORDER: '+IO:Nmbr
      @ 4,30 SAY '            DATE:'+Date
      ?
      @  6,0 SAY '  RECORD NUMBER: '-Number
      IF !(New) = 'S'
         @  7,0 SAY '      OUR CLIENT :' + MClient
      ELSE
         @  7,0 SAY '      OUR CLIENT ' GET MClient
         STORE !(MClient) TO MClient
      ENDIF
      @  8,0 SAY '      JOB NUMBER ' GET Job:Nmbr
      @  9,0 SAY '  AD DESCRIPTION ' GET Ad
      @ 10,0 SAY '  HOW MUCH SPACE ' GET Space
      @ 11,0 SAY '  WHICH MAGAZINE ' GET Magazine
      @ 12,0 SAY '     WHICH ISSUE ' GET Issue
      @ 13,0 SAY 'GROSS SPACE COST ' GET Gross:Cost
      @ 14,0 SAY '   DISCOUNT RATE ' GET Times
      READ
      
      REPLACE Net:Cost WITH Gross:Cost*0.8500, Client WITH MClient,;
              Ad WITH !(Ad), Magazine WITH !(Magazine), Issue WITH !(Issue)
      @  7,18 SAY Client
      @  9,18 SAY Ad
      @ 11,18 SAY Magazine
      @ 12,18 SAY Issue
      @ 15,18 SAY '  NET SPACE COST ' GET Net:Cost

      IF Client <> '  ' .AND. Gross:Cost > 0 .AND. Job:Nmbr > 99
         @ 18,5 SAY '   C to CHANGE,'
         @ 19,5 SAY '<Return> to continue.'
         ?
         WAIT TO New
         IF !(New) = 'C'
            STORE 'T' TO Incorrect
         ELSE
            @ 17,5 SAY '  F if FINISHED,'
            @ 18,5 SAY '  S for SAME insertion order,'
            @ 19,5 SAY '<Return> for NEXT insertion order.'
            @ 21,0 SAY '         '
            ACCEPT TO New

            IF !(New) <> 'S'
               IF VAL(Next:IO) < 9999
                  STORE STR(VAL(Next:IO)+1,4) TO Next:IO
               ELSE
                  STORE '1001' TO Next:IO
               ENDIF
            ENDIF
            STORE 'F' TO Incorrect
         ENDIF
         STORE New TO Inserting
      ELSE
         ?
         ?
         ?
         ?
         ?
         ?
         ? '   CLIENT, JOB or RATE missing.'
         ?
         ? '        F if FINISHED,'
         ? '     <Return> to correct the record.'
         ?
         WAIT TO Inserting
         IF !(Inserting) = 'F'
            DELETE RECORD &Number
            STORE 'F' TO Incorrect
         ELSE
            STORE 'T' TO Incorrect
         ENDIF
      ENDIF
   ENDDO Incorrect
ENDDO Inserting

RELEASE Date, NoDate, Inserting, Number, Update, New, Incorrect
SAVE TO B:Constant

COUNT FOR .NOT. * TO Any
ERASE
IF Any = 0
   ? 'No insertions to add to the file.'
   ? 'Press any key to continue.'
   USE 
   WAIT
ELSE 
   @  5,10 SAY 'To print the insertions you just entered,'
   @  6,10 SAY 'press <Return>.'
   WAIT TO Number
   *"Number" determines the starting record number for the printout.

   SET PRINT ON
   ? 'IO # MAGAZINE       ISSUE   JOB   AD             ';
               +'SPACE           GROSS      NET X  DATE'
   ?

   * "Output" and "Condition" needed in the Printout Command file
   STORE 'Y' TO Output
   STORE 'OFF' TO Condition
   DO Printout

   ERASE

   @ 5,20 SAY'UPDATING THE INSERTION ORDER FILE'
   USE B:Inserts Index B:Inserts
   APPEND FROM GetInserts
ENDIF

DELETE FILE GetInserts
RELEASE All
RETURN
