home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / p / prohp5.zip / DPRINV.PRG < prev    next >
Text File  |  1993-02-10  |  10KB  |  279 lines

  1. /*
  2.   ┌─────────────────────────────────────────────────────────────────────────┐
  3.   │                                                                         │
  4.   │   Program : Prinv.prg                                                   │
  5.   │   Usage   :                                                             │
  6.   │   Purpose : Here's how to create an Invoice Form with shadow boxes.     │
  7.   │             Store it to a string type var, make it a macro and          │
  8.   │             then call it each time you need the form.                   │
  9.   │             You may also save the invoice to a file                     │
  10.   │             and download it later.                                      │
  11.   │                                                                         │
  12.   │   Author  : Copyright (C) 1992, I.L.A.,Inc. All Rights reserved.        │
  13.   │                                                                         │
  14.   │   Comments: This source code may be distributed and used freely         │
  15.   │             provided that the copyright notice is not removed.          │
  16.   │                                                                         │
  17.   └─────────────────────────────────────────────────────────────────────────┘
  18. */
  19.  
  20. #include "prohp.ch"
  21.  
  22. proc main()
  23. Local HPCinv:=""
  24. set2print("dprinv.hpc")
  25. HP_init()
  26. HP_send(.T.)
  27. // process the invoice internally
  28.  
  29.  HP_orient(PORTRAIT)
  30.  HPscale(100)
  31.  PrInvoice(0.5,0.5,7,5)
  32.  HP_reset()
  33.  
  34.  HPscale(65)
  35.  PrInvoice(0.5,0.5,7,5)
  36.  HP_reset()
  37.  
  38.  HP_orient(LANDSCAPE)
  39.  HPscale(100)
  40.  PrInvoice(0.3,0.3,9.5,3)
  41.  HP_reset()
  42.  
  43.  
  44.  
  45. // now we will test downloading this invoice
  46. // DLinvoice()
  47. // HP_reset()
  48.  
  49. set2screen()
  50. return
  51.  
  52. Function PrInvoice(nTop,nLeft,nWidth,nInvH)
  53. Local nInvoice:= 18000, nTotInv := 0
  54. Local nRscale:=HPscale()/100  // used to adjust scale where
  55.                               // HPscale() has no efect
  56. Local aCompany:={"I.L.A., Inc. ","520 W. Hwy 436 #1180",;
  57.                  "Altamonte Springs, FL 32714","Tel. (407) 774-7734, Fax. (407) 774-6750"}
  58. // Local nTop:=0.3,nLeft:=0.3
  59. Local nLogoH:=2.2*nRscale
  60. //Local nWidth:=7    // try changing the width and all the rest
  61.                      // will be adjusted try it !
  62. // Local nInvH:=5.5
  63. Local nInvW:=nWidth
  64. Local o:='',nBoxSpace:=0.2
  65. Local nS2H:=1         // height of Sold to / ship to box
  66. Local nS2W:=(nWidth-nBoxSpace)/2   // width of S2/S2 box
  67. Local aSold2Box:={nTop+nLogoH,nLeft,nS2H,nS2W}  //
  68. Local aShip2Box:={nTop+nLogoH,nLeft+(nS2W*nRscale)+(nBoxSpace*nRscale),nS2H,nS2W}
  69. Local aInvBox:={nTop+nLogoH+(aSold2Box[3]*nRscale)+(nBoxSpace*nRscale),nLeft,nInvH,nInvW}
  70. local nWUnit:=nWidth/10*nRscale
  71. // set array of Invoice column width
  72. Local aColW:={nWUnit*1,nWUnit*6,nWUnit*1.2,nWUnit*1.8}
  73. Local aInvTab:={nLeft,nLeft+nWUnit,nLeft+nWUnit*7,nLeft+nWUnit*8.2}
  74. //Local aInvTab:={nLeft,aColW[1],aColW[1]+aColW[2],aColW[1]+aColW[2]+aColW[3]}
  75. Local line:=0,nttop:=0,cInvoice:="",os,HPCinv:=''
  76. Local ntdate,nQty,nUnitp,cDescr,aaddress,nLM
  77. os:=HP_send(.f.)
  78. HPshadow(.t.)          // make shadow boxes
  79. HPsetshadow(HPsetshadow()[1]*nRscale) // set shadow width
  80. if HPscale() < 80
  81.    HPCinv+=HP_pitch(16,ITALIC)
  82.    HPCinv+=HP_lpi(8)
  83. else
  84.    HPCinv+=HP_pitch(10,ITALIC)
  85.    HPCinv+=HP_lpi(5)
  86. endif
  87. ntTop:=nTop
  88. // print company header
  89. HPCinv+=HP_hline(ntTop,nLeft,nWidth,0.08,GFILLGRAY,40)
  90. ntTop+=1.5/HP_data(D_LPI)
  91. for line:=1 to len(aCompany)
  92.     HPCinv+=HP_atsay(ntTop,nLeft,aCompany[line])
  93.     ntTop+=1/HP_data(D_LPI)
  94. next
  95. HPCinv+=HP_hline(ntTop,nLeft,nWidth,0.08,GFILLGRAY,40)
  96.  
  97. ntTop+=1/HP_data(D_LPI)+0.08
  98. nTdate:=ntTop   // mark date line for later
  99. // HPCinv+=HP_lpi(7)
  100.  
  101. // make "sold to" box
  102. HPCinv+=HP_box(aSold2Box[1],aSold2Box[2],aSold2Box[3],aSold2Box[4])
  103. HPCinv+=HP_atsay(aSold2Box[1]-0.5/HP_data(D_LPI),aSold2Box[2],"Sold To:")
  104. // make "ship to" box
  105. HPCinv+=HP_box(aShip2Box[1],aShip2Box[2],aShip2Box[3],aShip2Box[4])
  106. HPCinv+=HP_atsay(aShip2Box[1]-0.5/HP_data(D_LPI),aShip2Box[2],"Ship To:")
  107. // make invoice detail box
  108. HPCinv+=HP_box(aInvBox[1],aInvBox[2],aInvBox[3],aInvBox[4])
  109. HPCinv+=HP_hline(aInvBox[1]+1.5/HP_data(D_LPI),aInvBox[2],aInvBox[4])
  110. HPCinv+=HP_hline(aInvBox[1],aInvBox[2],aInvBox[4],1.5/HP_data(D_LPI),GFILLGRAY,10)
  111. HPCinv+=HP_pitch(16)      // use small font for column header
  112. // print column header at center of each col.
  113. HPCinv+=HP_atsay(aInvBox[1]+1/HP_data(D_LPI),aInvBox[2]+;
  114.         (aColW[1]-HPstsize("QTY."))/2,"QTY.")
  115. HPCinv+=HP_vline(aInvBox[1],aInvBox[2]+aColW[1],aInvBox[3])
  116. HPCinv+=HP_atsay(aInvBox[1]+1/HP_data(D_LPI),aInvBox[2]+aColW[1]+;
  117.         (aColW[2]-HPstsize("Description"))/2,"Description")
  118. HPCinv+=HP_vline(aInvBox[1],aInvBox[2]+aColW[1]+aColW[2],aInvBox[3])
  119. HPCinv+=HP_atsay(aInvBox[1]+1/HP_data(D_LPI),aInvBox[2]+aColW[1]+aColw[2]+;
  120.         (aColW[3]-HPstsize("Unit"))/2,"Unit")
  121. HPCinv+=HP_vline(aInvBox[1],aInvBox[2]+aColW[1]+aColW[2]+aColW[3],aInvBox[3])
  122. HPCinv+=HP_atsay(aInvBox[1]+1/HP_data(D_LPI),aInvBox[2]+aColW[1]+aColw[2]+aColW[3]+;
  123.         (aColW[4]-HPstsize("Amount"))/2,"Amount")
  124. // Invoice format is complete, and it's in HPCinv
  125. HP_send(os)     // restore output flag
  126. if HPscale() < 80
  127.    HP_pitch(16)
  128. else
  129.     HP_pitch(10,ITALIC)
  130. endif
  131. nInvoice:=18000         // invoice # to start
  132. nQty:=1                  // quantity
  133. cDescr:="ProHP - Laser Printer Library"      // description
  134. nUnitp:=199.00            // unit price
  135. nLM:=1/HP_data(D_CPI)   // Relative Left margin for column
  136.  
  137. /*
  138.    You may save this invoice format to a disk file.
  139.    Save it using memowrit() and later download the invoice using memoread().
  140.    Do not forget to save the invoice coordinates, so you can
  141.    print the invoice details after downloading.
  142. */
  143.  
  144. memowrit("invoice.mac",HPCinv)
  145.  
  146.  
  147. /* This  command saves the invoice format to a file. We didn't use it here,
  148.    but this shows that you can create forms in one application, and use them
  149.    elsewhere. You probably want to create your own form library. Use this file
  150.    with applications written in other languages, just read
  151.    and send the file to the printer. */
  152.  
  153. // Open DBF file
  154. select 1
  155. use prohp alias pro
  156. go top
  157.  
  158. /*
  159.    Let's store the invoice format into Macro so we do not need to send it
  160.    to the printer each time we print an invoice. That's faster because the
  161.    macro is stored in the printer memory. To activate it, send a macro call
  162.    command.
  163. */
  164.    
  165.  HP_stmacro(1)   // open macro id # 1
  166.     qqout(HPCinv)     // send to printer
  167.  HP_endmacro(1,PERMMACRO)        // close macro 1 and protect it from reset CMD
  168.  
  169. if HPscale() < 80       // if sizes reduced below 80%
  170.     HP_pitch(16)        // change pitch
  171.     HP_lpi(8)           // and LPI
  172. else
  173.      HP_pitch(10,ITALIC)         // set font to Courier 10 cpi Italic
  174.      HP_lpi(5)                   // 5 lines per inch
  175. endif
  176. while !eof()
  177.      HP_callmacro(1)             // call macro # 1 (our invoice format)
  178.     // print date and invoice #
  179.      HP_atsay(nTdate,nLeft,"Date :"+dtoc(date()))
  180.     cInvoice:="Invoice  #  "+str(nInvoice,6)
  181.  
  182.     // Right justify Invoice #
  183.      HP_atsay(nTdate,nLeft+(nWidth*nRscale)-HPstsize(cInvoice),cInvoice)
  184.  
  185.     // read address into array
  186.     aAddress:={pro->name,pro->address,trim(pro->city)+', '+pro->state+' '+;
  187.               pro->zip}
  188.  
  189.     // print Sold to and ship to address location using HP_aatsay()
  190.      HP_aatsay(aSold2Box[1]+1/HP_data(D_LPI),aSold2Box[2]+nLM,aAddress)
  191.      HP_aatsay(aShip2Box[1]+1/HP_data(D_LPI),aShip2Box[2]+nLM,aAddress)
  192.  
  193.     // detail of invoice
  194.  
  195.      HP_setpos(aInvBox[1]+2/HP_data(D_LPI),nLeft+nLM)
  196.  
  197.     // If you have more than one line invoices use DO WHILE (.invoice.) here
  198.      HP_rcpos(1,,.t.)  // down one line
  199.  
  200.     // print quantity
  201.      HP_atsay(,aInvTab[1]+nLm,padl(str(nQty,4),HPi2col(aColW[1])-1))
  202.  
  203.     // print description
  204.      HP_atsay(,aInvTab[2]+nLm,cDescr)
  205.  
  206.     // print unit price
  207.      HP_atsay(,aInvTab[3]+nLm,padl(str(nUnitp,6,2),HPi2col(aColW[3])-1))
  208.  
  209.       // print amount
  210.      HP_atsay(,aInvTab[4]+nLm,padl(str(nQty*nUnitp,9,2),HPi2col(aColW[4])-1))
  211.     nTotInv+=nQty*nUnitp
  212.     // ENDDO WHILE (.invoice.) here
  213.  
  214.     // print totals
  215.      HP_rcpos(2,,.t.) // 2 lines down
  216.  
  217.     // print Total Amounts
  218.     // first draw gray bar over the current line
  219.      HP_atsay(,aInvTab[2],HPgraytext(padl("",;
  220.         HPi2col(aColW[2]+aColW[3]+aColW[4]))))
  221.  
  222.     // print 'Total '
  223.      HP_atsay(,aInvTab[3]-HPstsize("Total "),"Total ")
  224.  
  225.     // Print the total amount
  226.      HP_atsay(,aInvTab[4]+nLm,padl(str(nTotInv,9,2),;
  227.         HPi2col(aColW[4])-1))
  228.  
  229.     // print message at the bottom of the invoice
  230.      HP_atsay(aInvBox[1]+(aInvBox[3]*nRscale)-1/HP_data(D_LPI),aInvTab[2]+nLm,;
  231.             HPbold("DO NOT FORGET TO SEND REGISTRATION CARD."))
  232.  
  233.     nInvoice++          // increment invoice number
  234. //     HP_feed(FEEDOUT)    // feed the page out. (no change to the printer environment)
  235.      EXIT       // for this demo we'll print only one invoice
  236.     skip        // next record
  237. enddo
  238.  
  239. HP_setpos(aInvBox[1]+(aInvBox[3]*nRscale),aInvTab[1]) // go to bottom left of invocie
  240. // HP_rcpos(1,,.t.) // down 1 line
  241. HP_lmiset(nLeft) // aInvTab[2]) // set tab to left of second invoice column.
  242. qout("* ProHP creates professional forms with ease. ")
  243. qout("* Vary Size and orientation.")
  244. qout("* These three invoice pages were created using the same procedure.")
  245. qout("  See 'DPRINV.PRG'.")
  246. IF HPscale() <> 100
  247.    qout("** We specified "+ltrim(str(100-HPscale()))+"% reduction from previous form. ")
  248.    qout(space(30)+HPulstr("It doesn't get any easier than that!"))
  249. endif
  250.  
  251. HP_feed(FEEDOUT)
  252. return NIL
  253.  
  254.  
  255. proc DLinvoice()
  256. /*
  257.         It's simple and fast to download previously built forms of any kind.
  258.         Both methods work fine with most cases, but we recomend
  259.         the use of HPdownload() . That sends the file in binary mode to
  260.         the printer and return .F. if an error occurs during downloading.
  261. */
  262.  
  263. Local HPCinv:=[], cfName:="invoice.mac"
  264.  
  265. if file(cfName)         // make sure we have the file
  266.    HP_pitch(10)
  267.    HP_atsay(5,2,"Using MEMOREAD()")
  268.    HPCinv := memoread(cfName) // load form into memory
  269.    qqout(HPCinv)          // print it.
  270.    // if you do not need the form in memory do: QQOUT(MEMOREAD(cfName))
  271.  
  272.    HP_feed(FEEDOUT)
  273.    HPdownload(cfName,"LPT1")    // download invoice format
  274.    HP_atsay(5,2,"USING HPdownload()")
  275. endif
  276. return
  277.  
  278.  
  279.