home *** CD-ROM | disk | FTP | other *** search
/ DOS Wares / doswares.zip / doswares / DATABASE / DBASE5 / CUA_SAMP.ZIP / INVOICES.PRG < prev    next >
Encoding:
Text File  |  1994-06-24  |  10.4 KB  |  368 lines

  1. ******************************************************************************
  2. * PROGRAM NAME: INVOICES.PRG
  3. *               SAMPLE CUSTOM REPORT - INVOICES
  4. *               GENERATES INVOICES & UPDATES ACCT_REC.DBF
  5. *               SAMPLE BUSINESS APPLICATION
  6. * LAST CHANGED: 09/25/89 09:26AM
  7. * WRITTEN BY:   Borland International Inc.
  8. ******************************************************************************
  9. *              Logic and some variable names modeled after reports generator
  10. ******************************************************************************
  11. *
  12. DO WHILE .NOT. PRINTSTATUS()
  13.    DO ErrorMsg WITH "Printer not ready, press Escape to cancel"
  14.    RETURN
  15. ENDDO
  16.  
  17. CLEAR
  18. inv_month = 0
  19.  
  20.    ?? CHR(7)
  21.    inv_month = MONTH(DATE())-1
  22.    @ 10, 8 CLEAR TO 14,72
  23.    @ 12,5 SAY "What month do want to process orders for (1-12, 0 to Abort)?" ;
  24.           GET inv_month PICTURE "99" RANGE 0,12
  25.    READ
  26.     IF Inv_Month=0
  27.         CLEAR
  28.         RETURN
  29.     ENDIF
  30. set talk off
  31. * Open database files and choose active indexes
  32. SELECT 1
  33. USE Orders   ORDER Order
  34. USE Cust     ORDER Cust_id IN 2
  35. USE Acct_rec ORDER Cust_id IN 3
  36. USE Goods    ORDER part_id IN 4
  37.  
  38. * Relate database files and activate the relation
  39. SET RELATION TO cust_id INTO Cust, cust_id INTO Acct_rec, part_id INTO Goods
  40. GO TOP
  41.  
  42. * If user presses Esc during printing, exit
  43. ON ESCAPE DO Stop_rpt
  44.  
  45. * Process errors
  46. ON ERROR DO Err_msg
  47.  
  48. * Set up environment
  49. SET SPACE OFF
  50. _plineno  =  0
  51. _peject   = "NONE"
  52. _pageno   = 1
  53.  
  54. * Initialize variables
  55. continu_on  = .T.               && Continue printing flag - set by Esc to .F.
  56. complete = .F.
  57. on_pg_line = 0                  && Line at which ON PAGE works
  58. STORE 0  TO amt_of_bil, amt_of_cur, inv_amount, oldbalance
  59. STORE 0  TO inv_count, ord_count, grand_tot, tot_price
  60. STORE "" TO invoice_no, mcust_id, today, this_year, this_month
  61. today      = DTOC(DATE())
  62. this_year  = RIGHT(today,2)
  63. this_month = LEFT(today,2)
  64.  
  65. * Calculate line no. to break page on
  66. on_pg_line = INT(_plength - 6)  && Height minus footer and margin
  67.  
  68. * Set up line number where page break procedure executes
  69. ON PAGE AT LINE on_pg_line DO Page_brk
  70.  
  71. SET CONSOLE off
  72. SET PRINTER on
  73. *================================ Begin Print Job ============================
  74. PRINTJOB
  75.    * ======= File loop - process records in index order to end of file =======
  76.    *                     or until user presses Esc (continu_on = .F.)
  77.    * Process all uninvoiced records for a particular customer
  78.    SCAN FOR .NOT. invoiced .AND. inv_month = MONTH(date_trans) ;
  79.         WHILE continu_on
  80.       mcust_id = cust_id
  81.       DO Pg_head      && Print standard page heading
  82.       DO Inv_head     && Print invoice heading
  83.       complete = .F.  && Flag customer's invoices not completely processed
  84.       * Print orders for this customer
  85.       SCAN FOR .NOT. invoiced .AND. inv_month = MONTH(date_trans) ;
  86.            WHILE cust_id = mcust_id .AND. continu_on
  87.          DO Detail
  88.       ENDSCAN
  89.       complete = .T.  && Flag customer's invoices are completely processed
  90.       SKIP -1         && Return to last record for customer
  91.       DO Inv_calc     && Print invoice total for last customer
  92.       EJECT PAGE      && Print invoice footer - Inv_foot called by ON PAGE
  93.       DO Updat_ar     && Update Acct_rec database file with processed data
  94.       DO Reinit       && Re-initialize summary variables
  95.    ENDSCAN
  96.    IF continu_on
  97.       * End of file - User did not press Esc to stop printing
  98.       message = "Invoices were completely processed and printed for month " ;
  99.                 + STR(inv_month,2)
  100.    ELSE
  101.       * Not EOF - User pressed Esc to stop printing
  102.       message = "Invoices were NOT COMPLETED - stopped by user at " + TIME()
  103.    ENDIF
  104.    DO Rpt_end WITH message
  105.    ON PAGE
  106. ENDPRINTJOB
  107. *============================= End Print Job =================================
  108. EJECT PAGE
  109. ON PAGE
  110. SET CONSOLE on
  111. SET PRINTER off
  112. CLEAR
  113.  
  114.    ?? CHR(7)
  115.    @ 10,12 SAY "COPYING processed orders...please wait                 "
  116.    @ 12,10 SAY SPACE(61)
  117.    @ 13,10 SAY SPACE(63)
  118.  
  119.    CLOSE DATABASES
  120.    * Create an archive database file for processed orders.
  121.    * Records will be copied to it, then erased from Orders.
  122.    IF .NOT. FILE("Archiv_o.dbf")
  123.       USE Orders
  124.       COPY STRUCTURE TO Archiv_o
  125.    ENDIF
  126.    USE Archiv_o
  127.  
  128.    APPEND FROM Orders FOR invoiced
  129.  
  130.    *-- Remove the archived records from Orders
  131.    USE Orders
  132.    SET TALK on
  133.    DELETE ALL FOR invoiced
  134.    @ 10,10 SAY "ERASING processed orders...please wait               "
  135.    PACK
  136.    SET TALK off
  137. ON ESCAPE
  138. ON ERROR
  139. CLOSE ALL
  140. SET PROCEDURE TO
  141. SET CONSOLE ON
  142. IF FILE("ARCHIV_O.DBF")
  143.     DELE FILE ARCHIV_O.DBF
  144. ENDIF
  145. CLEAR
  146. RETURN
  147. ********************* END OF MAIN REPORT PROCEDURE ***************************
  148.  
  149. * UTILITY PROCEDURES
  150.  
  151.  
  152.  
  153.  
  154. PROCEDURE Detail
  155.    * Print report detail
  156.    ?? date_trans       AT 0,
  157.    ?? part_id          AT 10,
  158.    ?? Goods->part_name AT 21,
  159.    ?? part_qty         AT 53 PICTURE "999",
  160.    ?? Goods->price     AT 58 PICTURE "99,999.99",
  161.    * Extend price
  162.    tot_price  = ROUND(part_qty * Goods->price,2)
  163.    ?? tot_price        AT 70 PICTURE "99,999.99"
  164.    ?
  165.    * Accumulate total amount of current invoice
  166.    amt_of_cur = amt_of_cur + tot_price
  167.    * Accumulate number of orders processed
  168.    ord_count  = ord_count + 1
  169.    * Update the posted flag "invoiced" to .T. in Orders dbf for this order
  170.    REPLACE invoiced WITH .T.
  171. RETURN
  172.  
  173.  
  174. PROCEDURE Inv_calc
  175.    * Print calculated summary data on details at cust_id break
  176.    amt_of_bil = amt_of_cur + oldbalance
  177.    ?? "----------" AT 69
  178.    ?
  179.    ?? "CURRENT ORDERS" AT 0,
  180.    ?? "$" AT 66,
  181.    ?? amt_of_cur PICTURE "999,999.99" AT 69
  182.    ?
  183.    IF oldbalance <> 0
  184.       ?? "----------" AT 69
  185.       ? "+ OLD BALANCE"
  186.       ?? oldbalance PICTURE "999,999.99" AT 69,
  187.       ?
  188.    ENDIF
  189.    ?? "==========" AT 69
  190.    ?
  191.    ?? "TOTAL AMOUNT DUE" STYLE "B" AT 0,
  192.    ?? "$" STYLE "B" AT 66,
  193.    ?? amt_of_bil PICTURE "999,999.99" STYLE "B" AT 69
  194.    ?
  195.    ?? "==========" AT 69
  196.    * Accumulate total billings for end of report
  197.    grand_tot = grand_tot + amt_of_bil
  198.    ?
  199.    ?
  200. RETURN
  201.  
  202. PROCEDURE Inv_foot
  203.    * Print invoice page footer
  204.    ?
  205.    ? "TERMS: " AT 27,Cust->terms
  206.    ?
  207.    ? Acct_rec->notes  AT 18
  208.    * Start new page
  209.    EJECT PAGE
  210. RETURN
  211.  
  212. PROCEDURE Inv_head
  213.    * Encode new unique invoice number
  214.    invoice_no = cust_id + this_year + this_month
  215.    * Increment invoice count
  216.    inv_count  = inv_count + 1
  217.    ?
  218.    ?? "INVOICE NO.: " STYLE "B" AT 0,
  219.    ?? invoice_no STYLE "B" FUNCTION "T" PICTURE "XXXXXXXXXX" ,
  220.    ?? DATE() AT 69
  221.    ?
  222.    ?
  223.    ?? "CUSTOMER NO.: " AT 0,
  224.    ?? cust_id FUNCTION "T" PICTURE "XXXXXX"
  225.    ?
  226.    ?
  227.    ?? Cust->customer AT 0
  228.    ?
  229.    ?? Cust->address1 AT 0, Cust->address2 AT LEN(TRIM(Cust->address1))+2
  230.    ?
  231.    ?? Cust->city PICTURE "@T XXXXXXXXXXXXXXXXXXXX" AT 0,
  232.    ?? ", ",
  233.    ?? Cust->state," ",
  234.    ?? Cust->zip
  235.    ?
  236.    ?? "ATTENTION: " AT 0 ,
  237.    ?? Cust->contact PICTURE "@T XXXXXXXXXXXXXXXXXXXX","  ",
  238.    ?? Cust->phone_cont
  239.    ?
  240.    ?  REPLICATE(CHR(205),80)        && Draw double line 80 characters wide
  241.    ?
  242.    ?
  243.    ?? "PREVIOUS ACTIVITY:" STYLE "BU" AT 0
  244.    ?
  245.    ?? "INVOICE NO.:" AT 4, Acct_rec->invoic_old AT 15
  246.    ?? "SENT:" AT 31, Acct_rec->dat_lstbil AT 37
  247.    ?
  248.    ?? "AMOUNT  $ " AT 4, Acct_rec->amt_lstbil PICTURE "999,999.99" AT 15
  249.    ?
  250.    ?? "PAID    $ " AT 4, Acct_rec->amt_lst_pd PICTURE "999,999.99" AT 15
  251.    ?
  252.    ?? "----------" AT 15
  253.    ?
  254.    ?? "BALANCE $ " AT 4
  255.    oldbalance = Acct_rec->oldbalance
  256.    ?? oldbalance PICTURE "999,999.99" AT 15
  257.    ?
  258.    ?
  259.    ?? "CURRENT ACTIVITY:" STYLE "BU" AT 0
  260.    ?  REPLICATE(CHR(196),80)        && Draw single line 80 characters wide
  261.    ?  "Ordered"    AT 0
  262.    ?? "Part no."   AT 10
  263.    ?? "Part name"  AT 21
  264.    ?? "Qty"        AT 53
  265.    ?? "Price"      AT 59
  266.    ?? "Total"      AT 74
  267.    ?  REPLICATE(CHR(196),80)        && Draw single line 80 characters wide
  268.    ?
  269. RETURN
  270.  
  271. PROCEDURE Page_brk
  272.    * Page break logic - occurs when report detail line = on_pg_line
  273.    DO Inv_foot
  274.    * Print heading if customer's invoices were not completed on prior page
  275.    IF .NOT. EOF() .AND. .NOT. complete
  276.       DO Pg_head
  277.    ENDIF
  278. RETURN
  279.  
  280. PROCEDURE Pg_head
  281.    * Print information at top of each invoice page
  282.    ?
  283.    ?  "Page " ,
  284.    ?? _pageno PICTURE "999"
  285.    ?
  286.    ?
  287.    ?  "A-T  FURNITURE INDUSTRIES" STYLE "B"   AT 27
  288.    ?
  289.    DEFINE BOX FROM 34 TO 45 HEIGHT 3 SINGLE
  290.    ?
  291.    ?? "INVOICE" STYLE "B" AT 36
  292.    ?
  293.    ?
  294.    ?  REPLICATE(CHR(205),80)        && Draw double line 80 characters wide
  295.    ?
  296. RETURN
  297.  
  298. PROCEDURE Reinit
  299.    * Re-initialize summary/calculation variables at customer breaks
  300.    STORE 0 TO amt_of_cur, inv_amount
  301.    _pageno = 1
  302. RETURN
  303.  
  304. PROCEDURE Rpt_end
  305.    PARAMETERS message
  306.    * Print end-of-report summary data
  307.    ?
  308.    ?
  309.    ?  "A-T  FURNITURE INDUSTRIES" STYLE "BU"   AT 27
  310.    ?
  311.    ?
  312.    ?  "INVOICE SUMMARY PAGE" STYLE "B" AT 30
  313.    ?
  314.    inv_date = CTOD(STR(inv_month,2)+RIGHT(DTOC(DATE()),6))
  315.    ?  "FOR MONTH of " AT 31, CMONTH(inv_date)
  316.    ?
  317.    ?
  318.    ?
  319.    ?  REPLICATE(CHR(205),80)        && Draw double line 80 characters wide
  320.    ?  DATE() AT 0 ,
  321.    ?? TIME() AT 69
  322.    ?  REPLICATE(CHR(205),80)        && Draw double line 80 characters wide
  323.    ?
  324.    ?
  325.    ?
  326.    ?
  327.    ?? "===========" AT 67,
  328.    ?
  329.    ?? "GRAND TOTAL for " AT 0,
  330.    ?? inv_count PICTURE "999",
  331.    ?? " invoices " AT 21,
  332.    ?? "and ", ord_count PICTURE "9,999",
  333.    ?? " orders:",
  334.    ?? "$" AT 66,
  335.    ?? grand_tot PICTURE "999,999.99" ,
  336.    ?
  337.    ?? "===========" AT 67
  338.    ?
  339.    ?
  340.    ?
  341.    ?  message AT 6
  342.    ?
  343. RETURN
  344.  
  345. PROCEDURE Stop_rpt
  346.    continu_on = .F.   && Set stop printing flag to .F. when user presses Esc
  347. RETURN
  348.  
  349. PROCEDURE Updat_ar
  350.    * Update the related Acct_rec database record for this customer with data
  351.    * processed/calculated during invoicing and prior data
  352.    SELECT Acct_rec
  353.    IF Orders->cust_id <> cust_id
  354.       * If customer has never been invoiced, create an AR record for customer
  355.       APPEND BLANK
  356.       REPLACE cust_id WITH Orders->cust_id
  357.    ENDIF
  358.    REPLACE invoic_old WITH invoice_no, dat_lstbil WITH dat_of_bil, ;
  359.            amt_lst_pd WITH amt_cur_pd, amt_lstbil WITH amt_of_cur, ;
  360.            oldbalance WITH amt_lstbil - amt_lst_pd, comments WITH "", ;
  361.            notes WITH "", invoice_no WITH m->invoice_no, ;
  362.            dat_of_bil WITH DATE(), amt_of_cur WITH m->amt_of_cur, ;
  363.            amt_of_bil WITH m->amt_of_bil
  364.    SELECT Orders
  365. RETURN
  366.  
  367. ****************************************** END OF INVOICES.PRG ***************
  368.