home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / filesbbs / dos / dbonlin2.exe / ORDER.ZIP / ORDER.PRG < prev    next >
Encoding:
Text File  |  1995-02-09  |  12.5 KB  |  569 lines

  1. if .not. isansi() .and. .not. islocal()
  2.   ? "We're sorry, but you must have ANSI to use this program."
  3.   quit
  4. endif
  5.  
  6. set exclusive off
  7. set bell off
  8. set escape off
  9. set procedure to windows
  10.  
  11. discount=0
  12.  
  13. c=getenv("dbonline")
  14. set path to &c
  15.  
  16. if len(trim(c)) > 0
  17.   c=c+"DISCOUNT.LST"
  18.   fd=fopen(c)
  19.   if fd > 0
  20.     do while .not. feof(fd)
  21.       c=fgets(fd)
  22.       i=at(c,',')
  23.       if i>0
  24.         u=left(c,i-1)
  25.         d=val(substr(c,i+1))
  26.       else
  27.         u=left(c,i)
  28.         d=0
  29.       endif
  30.       if c=username()
  31.         exit
  32.         discount=d
  33.       endif
  34.     enddo
  35.     =fclose(fd)
  36.   endif
  37. endif
  38.  
  39. SHIP=0
  40. CCNUM=space(19)
  41. CCXMONTH=1
  42. CCXYEAR=96
  43. CCNAME=space(32)
  44.  
  45. declare prod(8),pric(8),qty(8)
  46.  
  47. x=1
  48. do while x <8
  49.   prod(x)=0
  50.   pric(x)=0
  51.   qty(x)=0
  52.   x=x+1
  53. enddo
  54.  
  55. *i=0
  56. *do while i<8
  57. *  x=str(i,1)
  58. *  product&x=0
  59. *  pric&x=0
  60. *  qty&x=0
  61. *  i=i+1
  62. *enddo
  63.  
  64. select 1
  65. use sales
  66. select 2
  67. use products
  68. select 3
  69. use customer
  70.  
  71. clear
  72. ship=15
  73. subtotal=0
  74. xid=0
  75.  
  76. **************************
  77. ***select 1
  78. ***locate for invoice=invnum
  79. ***line=0
  80. **gst=0
  81. ***do while found()
  82. ***  x=str(line,1)
  83. ***  product&x=sales->product
  84. ***  qty&x=1
  85. ***  line=line+1
  86. ***  subtotal=subtotal+sales->price
  87. ***  continue
  88. ***enddo
  89. ***gst=sales->gst
  90. ***ship=sales->ship_cost
  91. ****************************
  92.  
  93. do Xwindow with 0,0,21,78,""
  94. do Xwindow with 22,0,24,78,""
  95. if iscolor()
  96.   set color to w+/w
  97. endif
  98. do Xcenter with 23,"dB Online - Order.db2            Copyright (c) 1995 Merlin Systems Inc."
  99. do intwindow with 14,50,20,76,""
  100. *if iscolor()
  101.  set color to n/BG+
  102. *endif
  103. @ 15,52 say "   Subtotal"
  104. @ 16,52 say "   Discount"
  105. @ 17,52 say "   Shipping"
  106. @ 18,51 say replicate("─",25)
  107. @ 19,52 say "      Total"
  108.  
  109. do button with 15,5, "   ~Add an Item   "
  110. *do button with 15,29," ~Remove an Item  "
  111. *do button with 17,5, ' Shipping ~Method '
  112. do button with 15,29,'      ~? Help     '
  113. do button with 18,5, "   ~Save Order    "
  114. do button with 18,29,'  ~Cancel Order   '
  115.  
  116. ***set color to w+/bg
  117. ****wait
  118. do drawStuff
  119. do drawTotal
  120.  
  121. ok=.T.
  122. do while ok
  123.  
  124.   k=0
  125.   do while k = 0 .or. k>255
  126.     k=inkey()
  127.   enddo
  128.  
  129.   c=upper(chr(k))
  130.  
  131.   do case
  132.     case c='A'
  133.       x=maxproducts()
  134.       if x < 8
  135.         do flatWindow with 2,2,13,76
  136.         @ 2,3 say " Description "
  137.         @ 2,69 say " Price "
  138.         xcont=0
  139.         i=10
  140.         do while i>9
  141.           do drawProducts with 4,3,xcont
  142.           i=1
  143.           menu to i
  144.           xcont=xcont+1
  145.         enddo
  146.         if i >0
  147.           str=getans("Quantity or <esc> to cancel ?")
  148.           q=val(str)
  149.           if q>0
  150.             x=maxproducts()
  151.             if x<8
  152.               select products
  153.               locate for id = i
  154.               if found() .and. products->display
  155.                 prod(x)=i+xcont*9-9
  156.                 qty(x)=q
  157.                 pric(x)=products->price
  158. *                if discount > 0
  159. *                  pric(x)=pric(x)*(100-discount)/100
  160. *                endif
  161.                 subtotal=subtotal + products->price * qty(x)
  162.                 do drawTotal
  163.               endif
  164.             endif
  165.           endif
  166.         endif
  167.         do drawstuff
  168.         do drawOrder
  169.       endif
  170.  
  171.     case c='C'
  172.       c=getans("Are you sure (yes/no) ?")
  173.       c=upper(left(c,1))
  174.       if c='Y'
  175.         ok=.F.
  176.       else
  177.         do drawstuff
  178.         do draworder
  179.       endif
  180.  
  181.     case c='S'
  182.       if maxproducts() > 0
  183.         ok=.F.
  184.         do client
  185.         do creditcard
  186.         do saveorder
  187.         set color to
  188.         clear
  189.         ? "Thank you for your order."
  190.         ?
  191.         ? "If you have any other questions please call us at 1-816-436-5206"
  192.         ?
  193.         wait
  194.       endif
  195.  
  196.     case c='?'
  197.       do flatWindow with 2,2,13,76
  198.       @ 2,3 say " Help "
  199.       @ 4,4 say "This is an example of a dB Online application.  The code was"
  200.       @ 5,4 say "written in the xBASE language and will work with any other"
  201.       @ 6,4 say "xBASE-compatible software.  It also saves all of its data into"
  202.       @ 7,4 say "a dBASE file in real-time and that file can be accessed by any"
  203.       @ 8,4 say "any other dBASE-compatible software."
  204.       @ 10,4 say "NOTE: Shipping is 15.00 within the U.S., 25.00 outside."
  205.       @ 12,4 say "Orders will be processed within 24 hours."
  206.       read
  207.       do drawstuff
  208.       do drawOrder
  209.  
  210. *    case c='P'
  211. *      do flatWindow with 2,2,13,76
  212. *      x=1
  213. *      do while x<7
  214. *        @ 5+x,4 say ""
  215. *        ?? prod(x), pric(x), qty(x)
  216. *        x=x+1
  217. *      enddo
  218. *      read
  219. *      do drawstuff
  220. *      do drawOrder
  221.  
  222.   endcase
  223. enddo
  224. clear
  225. clear all
  226. return
  227.  
  228.  
  229. function getans
  230.   parameters string
  231.  
  232.   x=len(string)+12
  233.   set color to GR+/R
  234.   @ 11,40-x/2 to 13,40+x/2
  235.   set color to W+/R
  236.   @ 12,40-x/2+1 say space(x-1)
  237.   @ 12,40-x/2+2 say string
  238.   ans=space(5)
  239.   @ 12,40+x/2-6 get ans
  240.   read
  241. return ans
  242.  
  243.  
  244. function maxproducts
  245.   x=0
  246.   do while x<8
  247.     if prod(x)=0
  248.       exit
  249.     endif
  250.     x=x+1
  251.   enddo
  252. return x
  253.  
  254. procedure creditcard
  255. *  if iscolor()
  256.     set color to w+/n
  257. *  endif
  258.   clear
  259.   do Xwindow with 4,10,21,70,"Credit Card Information"
  260.   do intwindow with 8,35,10,62,""
  261.   do intwindow with 11,35,13,39,""
  262.   do intwindow with 11,41,13,45,""
  263.   do intwindow with 14,35,16,67,""
  264. *  do Xcenter with 6,"Credit Card Information"
  265. *  if iscolor()
  266.     set color to r/w
  267. *  endif
  268.   do Xcenter with 18,"We accept Visa, MasterCard & American Express"
  269.   do Xcenter with 19,"Press <Esc> to cancel"
  270. *  if iscolor()
  271.     set color to gr+/w
  272. *  endif
  273.   @ 9,13  say "Credit Card #"
  274.   @ 12,13 say "Expiration (MM YY)"
  275.   @ 15,13 say "Card Holder's Name"
  276.  
  277. *  if iscolor()
  278.     set color to w+/b,w+/bg
  279. *  endif
  280.   CCNUM=space(25)
  281.   CCNAME=Username()
  282.   if len(ccname)=0
  283.     CCNAME=space(25)
  284.   endif
  285.   CCXYEAR=mod(year(date())+1,100)
  286.   @ 9,36 get CCNUM
  287.   @ 12,36 get CCXMONTH picture "999"
  288.   @ 12,42 get CCXYEAR picture "999"
  289.   @ 15,36 get CCNAME
  290.   read
  291. return
  292.  
  293.  
  294. procedure drawProducts
  295.   parameters x,y,cont
  296.  
  297.   line=0
  298.   select products
  299.   if cont = 0
  300.     go top
  301.   endif
  302.  
  303.   set color to w+/b,w/b,w/b
  304.  
  305.   do while .not. eof()
  306.     if products->display
  307.  
  308.       @ line+y,x prompt products->name + space(5)+transform(products->price,"999.99") color g/n
  309.       line=line+1
  310.     endif
  311.     skip
  312.     if line>8
  313.       @ line+y,x prompt "--- More Products ---"
  314.       exit
  315.     endif
  316.   enddo
  317.   if line <9
  318.     set color to w/b
  319.     do while line <10
  320.       @ line+y,x say space(80-x*2)
  321.       line=line+1
  322.     enddo
  323.   endif
  324. return
  325.  
  326.  
  327. procedure drawstuff
  328.   do intwindow with 3,2,13,76," Description                                              Qty      Price "
  329.  
  330.   if iscolor()
  331.     set color to n/w
  332.   endif
  333.   @ 2,2 say space(76)
  334.   do Xcenter with 2,"Sound Advice Limited"
  335. return
  336.  
  337.  
  338. procedure drawTotal
  339. *  if iscolor()
  340.     set color to w+/BG
  341. *  endif
  342.   @ 15,67 say transform(subtotal,"9999.99")
  343.   @ 16,72 say transform(discount,"99")+"%"
  344.   x=maxproducts()
  345.   if x>0
  346.     x=x-1
  347.   endif
  348.   @ 17,67 say transform(ship*x,"9999.99")
  349.   @ 19,66 say transform(ship*x+subtotal*((100-discount)/100),"99999.99")
  350. return
  351.  
  352.  
  353. procedure drawOrder
  354.   i=1
  355. *  if iscolor()
  356.     set color to W+/BG
  357. *  endif
  358.   do while i<8
  359.     select 2
  360.     if prod(i) = 0
  361.       @ i+4,3 say space(73)
  362.     else
  363.       locate for products->id=prod(i)
  364.       @ i+4,4 say products->name
  365.       @ i+4,69 say transform(pric(i),"999.99")
  366.       @ i+4,60 say transform(qty(i),"999")
  367.     endif
  368.     i=i+1
  369.   enddo
  370. return
  371.  
  372.  
  373. procedure client
  374.   set color to w+/n
  375.   clear
  376.   ? "Searching..."
  377.   select customer
  378.   xuser=trim(upper(username()))
  379.   locate for trim(upper(contact))=xuser .or. upper(trim(company))=xuser .or. upper(trim(bbsid))=xuser
  380.   if found() .and. len(trim(username())) > 0
  381.     xid=cust
  382.     x_company=company
  383.     x_address1=address1
  384.     x_address2=address2
  385.     x_city=city
  386.     x_post_code=post_code
  387.     x_country=country
  388.     x_contact=contact
  389.     x_phone=phone
  390.     x_fax=fax
  391.     x_data=data
  392.     x_internet=internet
  393.     x_fido=fidonet
  394.   else
  395.     x_company=space(60)
  396.     x_address1=space(30)
  397.     x_address2=space(23)
  398.     x_city=left(city()+space(24),24)
  399.     x_post_code=space(12)
  400.     x_country=space(24)
  401.     x_contact=left(username()+space(23),23)
  402.     x_phone=left(voicephone()+space(16),16)
  403.     x_fax=space(16)
  404.     x_data=left(dataphone()+space(16),16)
  405.     x_internet=space(30)
  406.     x_fido=space(15)
  407.   endif
  408.  
  409.   c='N'
  410.   clear
  411.   do Xwindow with 0,0,17,78,""
  412.   do intwindow with 3,24,16,76,""
  413. *  if iscolor()
  414.     set color to w+/w
  415. *  endif
  416.   do Xcenter with 2,"Customer Information"
  417. *  if iscolor()
  418.     set color to gr+/w
  419. *  endif
  420.   @  4,4 say "      Company Name"
  421.   @  5,4 say "           Address"
  422.   @  7,2 say "City, Province/State"
  423.   @  8,4 say "   Postal/Zip Code"
  424.   @  9,4 say "           Country"
  425.   @ 10,4 say "           Contact"
  426.   @ 11,4 say "      Phone Number"
  427.   @ 12,4 say "        Fax Number"
  428.   @ 13,4 say "        BBS Number"
  429.   @ 14,4 say "  Internet Address"
  430.   @ 15,4 say "   FidoNet Address"
  431.   do while c='N'
  432. *    if iscolor()
  433.       set color to w+/b,w+/bg
  434. *    endif
  435.     @  4,25 get x_company picture "@S51"
  436.     @  5,25 get x_address1 picture "@S30"
  437.     @  6,25 get x_address2 picture "@S23"
  438.     @  7,25 get x_city picture "@S24"
  439.     @  8,25 get x_post_code picture "@S12"
  440.     @  9,25 get x_country picture "@S24"
  441.     @ 10,25 get x_contact picture "@S23"
  442.     @ 11,25 get x_phone picture "@S16"
  443.     @ 12,25 get x_fax picture "@S16"
  444.     @ 13,25 get x_data picture "@S16"
  445.     @ 14,25 get x_internet picture "@S30"
  446.     @ 15,25 get x_fido picture "@S15"
  447.     read
  448.  
  449.     if (len(trim(x_company))=0)
  450.       do Xwindow with 18,10,22,70,""
  451.       set color to R*/w
  452.       @ 20,26 say "You must specify a Company Name!"
  453.       read
  454.       set color to w+/n
  455.       @ 18,10 clear to  22,70
  456.       loop
  457.     endif
  458.  
  459.     if (len(trim(x_country))=0)
  460.       do Xwindow with 18,10,22,70,""
  461.       set color to R*/w
  462.       @ 20,28 say "You must specify a Country!"
  463.       read
  464.       set color to w+/n
  465.       @ 18,10 clear to  22,70
  466.       loop
  467.     endif
  468.  
  469. *    if iscolor()
  470.       set color to w+/bg
  471. *    endif
  472.     @  4,25 say x_company picture "@S51"
  473.     @  5,25 say x_address1 picture "@S30"
  474.     @  6,25 say x_address2 picture "@S23"
  475.     @  7,25 say x_city picture "@S24"
  476.     @  8,25 say x_post_code picture "@S12"
  477.     @  9,25 say x_country picture "@S24"
  478.     @ 10,25 say x_contact picture "@S23"
  479.     @ 11,25 say x_phone picture "@S16"
  480.     @ 12,25 say x_fax picture "@S16"
  481.     @ 13,25 say x_data picture "@S16"
  482.     @ 14,25 say x_internet picture "@S30"
  483.     @ 15,25 say x_fido picture "@S15"
  484.  
  485.     do Xwindow with 18,10,22,70,""
  486. *    if iscolor()
  487.       set color to w+/w
  488. *    endif
  489.     @ 20,25 say "Is the above information correct? "
  490. *    if iscolor()
  491.       set color to gr+/w
  492. *    endif
  493.     i=0
  494.     do while i=0
  495.       i=inkey()
  496.       c=upper(chr(i))
  497.       if c <> 'Y' .and. c <> 'N'
  498.         i=0
  499.       endif
  500.     enddo
  501.     if c='Y'
  502.       ?? "Yes"
  503.     else
  504. *      if iscolor()
  505.         set color to w+/n
  506. *      endif
  507.       @ 18,10 clear to 22,70
  508.     endif
  509.   enddo
  510. return
  511.  
  512.  
  513. procedure saveorder
  514.   do Xwindow with 18,10,22,70,""
  515.   set color to w+/w
  516.   @ 20,25 say "Would you like to save this order? "
  517.   set color to gr+/w
  518.   i=0
  519.   do while i=0
  520.     i=inkey()
  521.     c=upper(chr(i))
  522.     if c <> 'Y' .and. c <> 'N'
  523.       i=0
  524.     endif
  525.   enddo
  526.   if c='Y'
  527.     if xid=0
  528.       select customer
  529.       xid=maxcust()
  530.  
  531.       append blank
  532.       replace company with x_company, address1 with x_address1
  533.       replace address2 with x_address2, city with x_city, post_code with x_post_code
  534.       replace country with x_country, contact with x_contact, phone with x_phone
  535.       replace fax with x_fax, data with x_data, internet with x_internet
  536.       replace fidonet with x_fido, cust with xid
  537.     endif
  538.  
  539.     select sales
  540.     x=1
  541.     do while x < 8 .and. prod(x) >0
  542.       append blank
  543.       replace id with xid, product with prod(x), date with date()
  544.       replace price with pric(x)
  545.       replace credit_num with ccnum+' '+transform(ccxmonth,'99')+'/'+transform(ccxyear,'99')+' '+ccname
  546.       replace seed with 0, endofsupp with date()+90
  547.       if upper(x_country) ='U.S.A.' or upper(x_country) = 'USA' or upper(x_country) ="US" or upper(x_country) = 'U.S.' or len(x_country)=0
  548.          replace ship_cost with 15.0, ship_type with "US"
  549.       else
  550.          replace ship_cost with 25.0, ship_type with "Intl"
  551.       endif
  552.       x=x+1
  553.     enddo
  554.   endif
  555. return
  556.  
  557. function maxcust
  558.   x=0
  559.   go top
  560.   do while .not. eof()
  561.     if x < cust
  562.       x=cust
  563.     endif
  564.     skip
  565.   enddo
  566. return x+1
  567.  
  568.  
  569.