บทนำระบบ
ศึกษาปัญหา
ศึกษาความเป็นไปได้
ศึกษาระบบเดิม
ออกแบบระบบใหม่
พัฒนาระบบ
ติดตั้ง
บำรุงรักษา
โปรแกรมเมนู
โปรแกรมแสดงข้อมูล
โปรแกรมปรับปรุงข้อมูล
โปรแกรมเกี่ยวกับรายงาน
โปรแกรมเกี่ยวกับรายงานสรุป
โปรแกรมเกี่ยวกับระบบ
procedure sale
do while .t.
opt1=alert("เลือกการขาย",{"เงินสด","เงินเชื่อ","กลับเมนูหลัก"})
if opt1=1
   do cashs
elseif opt1=2
   do saledeb
else
    exit
endif
close all
enddo
return
//====================
//การขายสินค้าเงินสด
procedure cashs
set cursor on
set color to w/bg+
cls
set color to w/b
@1,2 clear to 3,77
set color to w/gr
@5,2 clear to 19,77
set color to w/rb+
@ 21,2 clear to 23,77
_saleid=0
saleid=_saleid
use sale; go bottom
_saleid=saleid+1
_custid=0
_status=1
_custname=space(25)
_custadd=space(30)
_empid=0
_custtel=0
set century on
_datesale=date()

set color to "rb/bg"
@ 24,0 clear to 24,80
@ 24,25 say "[ESC จบการทำงาน]"
@ 24,2 say "[Selectc File F2]"
  set key-1 to findcust
_custid="          "

@ 2,30 say "การขายเงินสด"
@ 2,60 say "รหัสขาย:"+ltrim(str(_saleid))
do while !found()
  @ 4,2 to 7,77
  set color to b/gr,/w
  @ 5,5 say "รหัสลูกค้า : " get _custid
  read
  set key-1 to
  @ 5,30 say "ชื่อ :"
  @ 5,61 say"วันที่ :"+dtoc(_datesale)
  @ 6,5 say "ที่อยู่ :"
  @ 6,30 say "Tel. :"
  @ 6,60 say "status :"+ltrim(str(_status))
  if lastkey()=27
    close all;return
  endif
  custid=_custid
use customer
   locate for custid=val(_custid)
if found()
    @ 5,37 say rtrim(custname)
    @ 6,15 say rtrim(custadd)
    @ 6,40 say rtrim(custtel)
else
 if _custid=0
        @ 5,19 say "ลูกค้าขาจร"
        @ 5,37 get _custname
        @ 6,15 get _custadd
        @ 6,35 get _custtel
        read
        exit
else
        @ 10,20 to 12,60 double
        @ 11,27 say "รหัสลูกค้าไม่พบ กรุณาป้อนใหม่"
        inkey(0)
        @ 10,5 clear to 12,70
        loop
endif
endif
enddo
use sale
append blank
repl saleid with _saleid,;
custid with val(_custid),;
date_sale with _datesale,;
empid with _empid,;
salestatus with _status
 _sum=0
 _stock=0
 r=11
 j=1
 _proid=array(16)
 _quant:=array(16)
 _tot=0;accept=1
 @ 9,4 say "รหัสสินค้า"
 @ 9,20 say "ชื่อสินค้า"
 @ 9,35 say "จำนวน"
 @ 9,50 say "ราคา"
 @ 9,65 say "รวม"
 @ 8,2 to 10,77
 do while lastkey()!=27
  _proid[j]=1
  do while _proid[j]!=0
    while !found()
use product
     _proid[j]:=_quant[j]:=0
     _tot=0
     proid=_proid[j]
set color to "rb/bg"
@ 24,25 say "[esc]"
@ 24,2 say "[select file f2]"
set key-1 to findpro
_proid[j]="           "

   @ r,3 get _proid[j]
     read
     set key-1 to
     if _proid[j]="  "
       @ r,3 clear to r,15
       @ r,69 say "---------"
       tax=_sum*.10
       net=_sum-tax
       @ r+1,50 say "รวมเงิน"
       @ r+1,67 say net pict "999,999.99"
       @ r+2,50 say "ภาษี 10%"
       @ r+2,67 say tax pict "999,999.99"
       @ r+3,50 say "รวมทั้งสิ้น"
       @ r+3,67 say _sum pict "999,999.99 "
  use sale
  _stotal=0
  _discount=0
  _rec=0
  _net=0
  go bottom
  set color to b/n+
  @7,20 clear to 17,50
  @7,20 to 17,50 double
          while lastkey()=27
             exit
          end
          @ 8,25 say "รายการชำระเงินทั้งหมด"
          @ 9,25 say "******************"
          @ 10,25 say "รวมเงิน"
          @ 10,40 say net pict "999,999.99"
          @ 11,25 say "ภาษี 10%"
          @ 11,40 say tax pict "999,999.99"
          @ 12,25 say "รวมทั้งสิ้น"
          @ 12,40 say _sum pict "999,999.99"
          _sum=_sum+_tot
          @ 14,25 say "รับเงิน  : "get _rec pict '999999999.99'
          read
          if _rec < _sum
            while _rec < _sum
             k8 = alert("เงินไม่พอชำระรับใหม่",{'ok'})
             @14,25 say "รับเงิน  : "get _rec pict '9999999999.99'
             read
            end
          endif
          _change=_rec - _sum
          @ 15,25 say "เงินทอน : "+ltrim(str(_change,15,2))
       do findemp
       inkey(0)
       do cashprint
       do askcon
       close all
       return
     endif
locate for val(_proid[j])=proid
    if found()
          _proname=proname
           @ r,15 say rtrim(proname)
          _stock=quantity
       exit
       else
       @ r,15 say "รหัสสินค้าไม่พบ ป้อนใหม่"
       inkey(0)
       @ r,15 clear to r,37
      loop
    endif
  end
  @ r,38 get _quant[j]
  @ r,47 say price pict "99,999.99"
  read
     while _quant[j]=0
      @r,38 get _quant[j]
      if _quant[j]=0
         save screen to sx2
         set color to "b/w"
         @14,20 to 16,50 double
         @15,21 say "สินค้ามีจำนวน[0] กรุณาใส่ใหม่"
         inkey(0)
         restore screen from sx2
      endif
      read
    end
  locate for proid =val(_proid[j])
  if found()
    if quantity < _quant[j]
      @ 22,2 clear to 22,70
      @ r,15 say "สินค้ามีไม่พอขาย"
      @ 22,5 say "สินค้ามีไม่พอขาย มีจำนวน"+ltrim(str(_stock))+;
      "ถ้าไม่ต้องการใส่ 0"
      @ 22,57 prompt "[Enterเพื่อใส่จำนวนใหม่ ]"
      menu to accept
      if accept=1
        @ r,15 clear to r,50
        @ r,15 say _proname
        @ r,46 get _quant[j]
        read
        quant1=_quant[j]
        _tot=quant1*price
        repl quantity with quantity - quant1

      endif
    else
      _tot=_quant[j]*price
      accept=0
      repl quantity with quantity - _quant[j]
    endif
  endif
  @ r,60 say _tot pict "99,999.99"
  @ 22,2 clear to 22,77
  if accept=1 .and. quant1!=0
use saledet
    append blank
    repl saleid with _saleid,proid with val(_proid[j]),quant with quant1
    endif
    if accept=0
use saledet
      append blank
      repl saleid with _saleid,proid with val(_proid[j]),quant with _quant[j]
      endif
      if accept=1
        if quant1=0
        @ r,2 clear to r,77
        r--
       endif
     endif
     r++
     if r=19
       @ 11,2 clear to 19,77
       r=11
      endif
      _sum=_sum+ _tot
      j++
    enddo
    inkey(0)
    keyboard chr(27)
    inkey()
    enddo
    inkey(0)
    close all
    return

//==============================
procedure findemp
sele 1;use sale
sele 2;use employee
sele 2
do while !found()
 _empid=0
 empid=_empid
 @ 21,5 clear to 23,75
 @ 22,2 say "รหัสพนักงานขาย :  " get _empid
 read
 locate for employee->empid=_empid
 if found()
 @ 22,35 say "ชื่อ :"+rtrim(employee->empname)
 else
   @ 22,35 say "##รหัสพนักงานไม่พบ กรุณาป้อนใหม่## "
   inkey(0)
   @ 22,35 clear to 23,75
   loop
 endif
enddo
sele 1; go bottom
repl empid with _empid
close all
return

//===========================
procedure cashprint
askprn=alert("สอบถามการพิมพ์ใบเสร็จรับเงิน",{"พิมพ์ใบเสร็จ","ไม่พิมพ์เสร็จ"})
if askprn=1
  @ 0,0 clear to 24,79
  do print1
  @ 22,15 say "****Enter to [print] or ESC to [cancle]*****"
inkey(0)
if lastkey()=27
  return
else
  set device to printer
  do print1
  set device to screen
 endif
else
  do askcon
  return
endif
close all
return
//===========================
procedure print1
   sele 1;use customer
   sele 2;use sale
   sele 3;use product
   sele 4;use saledet
   sum=0;net=0;tax=0
   sele 2; go bottom
   @ 2,25 say "ใบเสร็จรับเงิน CASH RECEIPT"
   @ 2,62 say "รหัสใบเสร็จ :"+ltrim(str(saleid))
   @ 3,2 say repl("=",77)
   @ 4,5 say "ร้านอุปกรณ์ไฟฟ้า นิรันดร์ จำกัด"
   @ 4,62 say "วันที่ :" +dtoc(_datesale)
   @ 5,5 say " 99 หมู่ 7 บ้านเชียงบาน อ.เชียงคำ จ.พะเยา 56110"
   @ 6,5 say "โทร.(054)415314"
     _saleid=saleid
     _custid=custid
     _datesale=date_sale
   @ 8,5 say "รหัสลูกค้า: " +ltrim(str(custid))
   sele 1
   locate for custid=_custid
   if found()
      @ 8,30 say "ชื่อ :" +rtrim(custname)
      @ 9,5 say "ที่อยู่:" +rtrim(custadd)
      @ 9,40 say "Tel. :" +rtrim(custtel)
   else
      @ 8,30 say "ชื่อ : ลูกค้าขาจร"
   endif
   ln=13
   @10,2 say repl("_",77)
   @ 11,4 say "รหัสสินค้า"
   @ 11,20 say "ชื่อสินค้า"
   @ 11,50 say "จำนวน"
   @ 11,60 say "ราคา"
   @ 11,72 say "รวม"
   @ 12,2 say repl("_",77)
   sele 4
   locate for saleid=_saleid
   while found()
   tot=0
   @ ln,3 say proid
   _proid=proid
   sele 3
   locate for proid=_proid
   if found()
      @ ln,13 say rtrim(proname)
        _price=price
   endif
   sele 4
   @ ln,45 say quant
   @ ln,59 say _price pict "999.99"
   tot=quant*_price
   @ ln,67 say tot pict "99,999.99"
   sum=sum+tot
   skip;ln++
   locate rest for saleid=_saleid
end
tax=sum*.10
net=sum-tax
@ ln+1,69 say "---------------"
@ ln+2,50 say "รวมเงิน"; @ ln+2,67 say net pict "999,999.99"
@ ln+3,50 say "ภาษี 10%"; @ ln+3,67 say tax pict "999,999.99"
@ ln+4,50 say "รวมทั้งสิ้น"; @ ln+4,67 say sum pict "999,999.99"
return
//===========================
procedure askcon
  @ 22,2 clear to 22,70
  @ 22,18 say "คุณต้องการทำต่อไปหรือไม่"
  @ 22,50 prompt "[Yes]";@ 22,57 prompt "[No]"
  menu to ans
  if ans=1
   do cashs
  else
   close all
   return
  endif
return
//======================
//การขายสินค้าเงินเชื่อ
procedure saledeb
set cursor on
set color to w/bg+
cls
set color to w/b
@ 1,2 clear to 3,77
set color to w/gr
@5,2 clear to 19,77
set color to w/rb+
@ 21,2 clear to 23,77

_saleid=0
use sale; go bottom
_saleid=saleid+1
saleid=_saleid
_custid=0
_empid=0
_status=2
set century on
_datesale=date()

 set color to "rb/bg"
@ 24,0 clear to 24,80
@ 24,25 say "[ESC จบการทำงาน]"
@ 24,2 say "[Selectc File F2]"
  set key-1 to findcust
_custid="          "

@ 2,30 say "การขายเงินเชื่อ"
@ 2,65 say "รหัสขาย: "+ltrim(str(_saleid))
do while !found()
  @ 4,2 to 7,77
  set color to b/gr,/w
  @ 5,5 say "รหัสลูกค้า :" get _custid
  read
  @ 5,30 say "ชื่อ :"
  @ 5,61 say"วันที่ :"+dtoc(_datesale)
  @ 6,5 say "ที่อยู่ :"
  @ 6,45 say "Tel.  : "
  @ 6,63 say "status :"+ltrim(str(_status))
  set key-1 to
  if lastkey()=27
    close all;return
  endif
  use customer
locate for custid=val(_custid)
   if found()
    @ 5,37 say rtrim(custname)
    @ 6,15 say rtrim(custadd)
    @ 6,50 say rtrim(custtel)
  else
    @ 10,20 to 12,60 double
    @ 11,27 say "รหัสลูกค้าไม่พบ กรุณาป้อนใหม่"
    inkey(0)
    @ 10,5 clear to 12,70
    loop
   endif
enddo
use sale
append blank
repl saleid with _saleid,;
custid with val(_custid),;
date_sale with _datesale,;
empid with _empid,;
salestatus with _status


 _sum=0
 r=11
 j=1
 _proid:=array(16)
 _quant:=array(16)
 _tot=0;quant1=0;accept=1
 @ 9,4 say "รหัสสินค้า"
 @ 9,20 say "ชื่อสินค้า"
 @ 9,50 say "จำนวน"
 @ 9,60 say "ราคา"
 @ 9,72 say "รวม"
 @ 8,2 to 10,77
do while lastkey()!=27
  _proid[j]=1
  proid=_proid[j]
  do while _proid[j]!=0
    while !found()
     use product
     _proid[j]:=_quant[j]:=0
     _tot=0
     proid=_proid[j]

set color to "rb/bg"
@ 24,25 say "[esc]"
@ 24,2 say "[select file f2]"
set key-1 to findpro
_proid[j]="           "

@ r,3 get _proid[j]
     read
     set key-1 to
     if _proid[j]="  "
       @ r,3 clear to r,15
       @ r,69 say "---------"
       tax=_sum*.10
       net=_sum-tax
       @ r+1,50 say "รวมเงิน"
       @ r+1,67 say net pict "999,999.99"
       @ r+2,50 say "ภาษี 10%"
       @ r+2,67 say tax pict "999,999.99"
       @ r+3,50 say "รวมทั้งสิ้น"
       @ r+3,67 say _sum pict "999,999.99"
       do findemp
       use receivab
       append blank
       repl custid with val(_custid),saleid with _saleid,;
            date_sale with _datesale,date_pay with _datesale+15,;
            total with _sum,;
            pay with 0
       inkey(0)
       do debprint
       do askcon1
       close all
       return
     endif
     proid=val(_proid[j])
   locate for val(_proid[j])=proid
     if found()
      @ r,15 say rtrim(proname)
       _proname=proname
       _stock=quantity
       exit
      else
      @ r,15 say "รหัสสินค้าไม่พบ ป้อนใหม่"
      inkey(0)
      @ r,15 clear to r,37
      loop
    endif
  end
  @ r,45 get _quant[j]
  @ r,55 say price pict "99,999.99"
  read
     while _quant[j]=0
      @r,45 get _quant[j]
      if _quant[j]=0
         save screen to sx2
         set color to "b/w"
         @14,20 to 16,50 double
         @15,21 say "สินค้ามีจำนวน[0] กรุณาใส่ใหม่"
         inkey(0)
         restore screen from sx2
      endif
      read
    end

  locate for proid = val(_proid[j])
  if found()
    if quantity < _quant[j]
      @ 22,2 clear to 22,70
      @ r,15 say "สินค้ามีไม่พอขาย"
      @22,5 say "สินค้ามีไม่พอขาย มีจำนวน"+ltrim(str(_stock))+;
      "ถ้าไม่ต้องการใส่ 0"
      @ 22,57 prompt "[Enter to get ]"
      menu to accept
      if accept=1
        @ r,15 clear to r,50
        @ r,15 say _proname
        @ r,37 get _quant[j]
        read
        quant1=_quant[j]
        _tot=quant1*price
        repl quantity with quantity - quant1
      endif
    else
      _tot= _quant[j]*price
      accept=0
      repl quantity with quantity - _quant[j]
    endif
  endif
  @ r,68 say _tot pict "99,999.99"
  @ 22,2 clear to 22,77
  if accept=1 .and. quant1!=0
use saledet
    append blank
    repl saleid with _saleid,proid with val (_proid[j]),quant with quant1
    endif
    if accept=0
use saledet
      append blank
      repl saleid with _saleid,proid with val(_proid[j]),quant with _quant[j]
      endif
      if accept=1
        if quant1=0
        @ r,2 clear to r,77
        r--
       endif
     endif
     r++
     if r=19
       @ 11,2 clear to 19,77
       r=11
      endif
      _sum=_sum+ _tot
      j++
    enddo
    inkey(0)
    keyboard chr(27)
    inkey()
    enddo
    inkey(0)
    close all
    return
//===========================
procedure debprint
askprn=alert("สอบถามการพิมพ์ใบเสร็จรับเงิน",{"พิมพ์ใบเสร็จ","ไม่พิมพ์เสร็จ"})
if askprn=1
  @ 0,0 clear to 24,79
  do print2
  @ 22,15 say "****enter to [print] or esc to [cancle]*****"
inkey(0)
if lastkey()=27
  return
else
  set device to printer
  do print2
  set device to screen
 endif
else
  do askcon1
  return
endif
close all
return
//===========================
procedure print2
   sele 1;use customer
   sele 2;use sale
   sele 3;use product
   sele 4;use saledet
   sum=0;net=0;tax=0
   sele 2; go bottom
   @ 2,28 say "ใบส่งของ DELIVERY ORDER"
   @ 2,58 say "รหัสใบส่งของ :"+ltrim(str(saleid))
   @ 3,2 say repl("=",77)
   @ 4,5 say "ร้านอุปกรณ์ไฟฟ้า นิรันดร์ จำกัด"
   @ 4,62 say "วันที่ :" +dtoc(_datesale)
   @ 5,5 say " 99 หมู่ 7 บ้านเชียงบาน อ.เชียงคำ จ.พะเยา 56110"
   @ 6,5 say "โทร.(054)415314"
     _saleid=saleid
     _custid=custid
     _datesale=date_sale
      @ 8,5 say "รหัสลูกค้า: " +ltrim(str(custid))
   sele 1
      locate for custid=_custid
       if found()
      @ 8,30 say "ชื่อ :" +rtrim(custname)
      @ 9,5 say "ที่อยู่:"+rtrim(custadd)
   endif
   ln=13
   @10,2 say repl("_",77)
   @ 11,4 say "รหัสสินค้า"
   @ 11,20 say "ชื่อสินค้า"
   @ 11,35 say "จำนวน"
   @ 11,60 say "ราคา"
   @ 11,72 say "รวม"
   @ 12,2 say repl("_",77)
   sele 4
   locate for saleid=_saleid
   while found()
   tot=0
   @ ln,3 say proid
   _proid=proid
   sele 3
   locate for proid=_proid
   if found()
      @ ln,15 say rtrim(proname)
     _price=price
   endif
   sele 4
   @ ln,49 say quant
   @ ln,60 say _price pict "999.99"
   tot=quant*_price
   @ ln,67 say tot pict "99,999.99"
   sum=sum+tot
   skip;ln++
   locate rest for saleid=_saleid
end
tax=sum*.10
net=sum-tax
@ ln+1,69 say "---------------"
@ ln+2,50 say "รวมเงิน"; @ ln+2,67 say net pict "999,999.99"
@ ln+3,50 say "ภาษี 10%"; @ ln+3,67 say tax pict "999,999.99"
@ ln+4,50 say "รวมทั้งสิ้น"; @ ln+4,67 say sum pict "999,999.99"
close all
return
//===========================
procedure askcon1
  @ 22,2 clear to 22,70
  @ 22,18 say "คุณต้องการทำต่อไปหรือไม่"
  @ 22,50 prompt "[Yes]";@ 22,57 prompt "[No]"
  menu to ans
  if ans=1
   do saledeb
  else
   close all
   return
  endif
return
//============================
//การสั่งซื้อสินค้า
procedure orpro
set color to w/bg+
cls
set color to w/b
@ 1,2 clear to 3,77
set color to w/gr
@5,2 clear to 19,77
set color to w/rb+
@ 21,2 clear to 23,77

_saleid=0;_orderid=0
use order; go bottom
_orderid=orderid+1
_suppid=0
_empid=0
set century on
_dateorder=date()

set color to "rb/bg"
@ 24,0 clear to 24,80
@ 24,25 say "[ESC จบการทำงาน]"
@ 24,2 say "[Selectc File F2]"
  set key-1 to findsupp
_suppid="          "

@2,34 say "การสั่งซื้อสินค้า"
@2,63 say "รหัสสั่งซื้อ :" +ltrim(str(_orderid))
do while !found()
@4,2 to 7,77
  set color to b/gr,/w
@ 5,3 say "รหัสผู้จำหน่าย: " get _suppid
@ 5,32 say "ชื่อ :"
@ 5,63 say "วันที่ : "+dtoc(_dateorder)
@ 6,3 say "ที่อยู่ :"
@ 6,50 say "Tel :"
read
if lastkey()=27
   close all; return
   endif
use supplier
locate for suppid=val(_suppid)
   if found()
      @ 5,41 say rtrim(suppname)
      @ 6,14 say rtrim(suppadd)
      @ 6,55 say rtrim(supptel)
   else
      @ 10,20 to 12,65 doub
      @ 11,27 say "รหัสผู้จำหน่ายไม่พบ กรุณาป้อนใหม่"
      inkey(0)
      @10,5 clear to 12,70
      loop
   endif
 enddo
use order
 append blank
 repl orderid with _orderid,;
 suppid with val(_suppid),;
 empid with _empid,;
 date_order with _dateorder
_sum=0
r=11;j=1
_proid:=array(16)
_quant:=array(16)
_tot=0
  @ 9,4 say "รหัสสินค้า"
  @ 9,20 say "ชื่อสินค้า"
  @ 9,50 say "จำนวน"
  @ 9,60 say "ราคา"
  @ 9,72 say "รวม"
  @8,2 to 10,77
  do while lastkey()!=27
     _proid[j]=1
  do while _proid[j]!=0
    while !found()
use product
    _proid[j]:=_quant[j]:=0
    _tot=0
   set color to "rb/bg"
@ 24,0 clear to 24,80
@ 24,25 say "[ESC จบการทำงาน]"
@ 24,2 say "[Selectc File F2]"
  set key-1 to findpro
_proid[j]="          "

    @ r,3 get _proid[j]
    read
    set key-1 to
    if _proid[j]="  "
       @ r,3 clear to r,15
       @ r,3 say repl("-",73)
       tax=_sum*.10
       net=_sum-tax
@ r+1,50 say "รวมเงิน";@ r+1,67 say net pict "999,999.99"
@ r+2,50 say "ภาษี 10% ";@r+2,67 say tax pict "999,999.99"
@ r+3,50 say "รวมทั้งสิ้น";@ r+3,67 say _sum pict "999,999.99"
do find1
  inkey(0)
  do orderprint
  do askcon2
  close all
  return
endif
locate for proid=val(_proid[j])
if found()
   @ r,15 say rtrim(proname)
   exit
 else
   @ r,15 say "รหัสสินค้าไม่พบ ป้อนใหม่";inkey(0)
   @ r,15 clear to r,37
   loop
  endif
end
@ r,45 get _quant[j]
@ r,57 say cost pict "99,999.99"
read
     while _quant[j]=0
      @r,45 get _quant[j]
      if _quant[j]=0
         save screen to sx2
         set color to "b/w"
         @14,20 to 16,50 double
         @15,21 say "สินค้ามีจำนวน[0] กรุณาใส่ใหม่"
         inkey(0)
         restore screen from sx2
      endif
      read
    end

_tot=_quant[j]*cost
@ r,68 say _tot pict "99,999.99"
r++
if r=19
   @ 11,2 clear to 19,77
   r=11
   endif
   _sum = _sum + _tot
use orderdet
   append blank
   repl orderid with _orderid,;
   proid with val(_proid[j]),;
   pquant with _quant[j]
   j++
  enddo
inkey(0);keyboard chr(27);inkey()
enddo
inkey(0)
close all
return
//=================
procedure askcon2
  @ 22,2 clear to 22,70
  @ 22,18 say "คุณต้องการทำต่อไปหรือไม่"
  @ 22,50 prompt "[Yes]";@ 22,57 prompt "[No]"
  menu to ans
  if ans=1
   do orpro
  else
   close all
   return
  endif
return
//=================
procedure orderprint
askprn=alert("สอบถามการพิมพ์ใบเสร็จ",{"พิมพ์ใบเสร็จ","ไม่พิมพ์เสร็จ"})
if askprn=1
  @ 0,0 clear to 24,79
  do print3
  @ 22,15 say "****enter to [print] or esc to [cancle]*****"
inkey(0)
if lastkey()=27
  return
else
  set device to printer
  do print3
  set device to screen
 endif
else
  do askcon2
  return
endif
close all
return
//===========================
procedure print3
   sele 1;use supplier
   sele 2;use order
   sele 3;use product
   sele 4;use orderdet
   sum=0
   sele 2; go bottom
   @ 2,28 say "ใบสั่งซื้อสินค้า PURCHASE"
   @ 2,58 say "รหัสใบสั่งซื้อ :"+ltrim(str(orderid))
   @ 3,2 say repl("=",77)
   @ 4,5 say "ร้านอุปกรณ์ไฟฟ้า นิรันดร์ จำกัด"
   @ 4,62 say "วันที่ :" +dtoc(date_order)
   @ 5,5 say " 99 หมู่ 7 บ้านเชียงบาน อ.เชียงคำ จ.พะเยา 56110"
   @ 6,5 say "โทร.(054)415314"
     _orderid=orderid
     _suppid=suppid
     _dateorder=date_order
   @ 8,5 say "รหัสผู้จำหน่าย:" +ltrim(str(suppid))
   sele 1
   locate for suppid=_suppid
   if found()
      @ 8,30 say "ชื่อ :" +rtrim(suppname)
      @ 9,5 say "ที่อยู่ :"+rtrim(suppadd)
      @ 9,45 say "โทรศัพท์ :" + rtrim(supptel)
   endif
   ln=13
   @10,2 say repl("_",77)
   @ 11,4 say "รหัสสินค้า"
   @ 11,20 say "ชื่อสินค้า"
   @ 11,50 say "จำนวน"
   @ 11,60 say "ราคา"
   @ 11,72 say "รวม"
   @ 12,2 say repl("_",77)
   sele 4
   locate for orderid=_orderid
   while found()
   tot=0
   @ ln,3 say proid
   _proid=proid
   sele 3
   locate for proid=_proid
   if found()
      @ ln,15 say rtrim(proname)
     _cost=cost
   endif
   sele 4
   @ ln,49 say pquant
   @ ln,55 say _cost pict "999.99"
   tot=pquant*_cost
   @ ln,67 say tot pict "99,999.99"
   sum=sum+tot
   skip;ln++
   locate rest for orderid=_orderid
end
tax=sum*.10
net=sum-tax
@ ln+1,69 say "---------------"
@ ln+2,50 say "รวมเงิน"; @ ln+2,67 say net pict "999,999.99"
@ ln+3,50 say "ภาษี 10%"; @ ln+3,67 say tax pict "999,999.99"
@ ln+4,50 say "รวมทั้งสิ้น"; @ ln+4,67 say sum pict "999,999.99"
close all
return
//===========================
procedure find1
sele 1;use order
sele 2;use employee
sele 2
do while !found()
 _empid=0
 empid=_empid
 @ 21,5 clear to 23,75
 @ 22,2 say "รหัสพนักงานขาย :  " get _empid
 read
 locate for employee->empid=_empid
 if found()
 @ 22,35 say "ชื่อ :"+rtrim(employee->empname)
 else
   @ 22,35 say "##รหัสพนักงานไม่พบ กรุณาป้อนใหม่## "
   inkey(0)
   @ 22,35 clear to 23,75
   loop
 endif
enddo
sele 1; go bottom
repl empid with _empid
close all
return

//===========================
//การตรวจรับสินค้า
procedure preceive

set color to w/bg+
cls
set color to w/b
@ 1,2 clear to 3,77
set color to w/gr
@5,2 clear to 19,77
set color to w/rb+
@ 21,2 clear to 23,77

_recid=0
_empid=0
_orderid=0
use receive; go bottom
_recid=recid+1
set century on
_daterec=date()

set color to "rb/bg"
@ 24,25 say "[esc]"
@ 24,2 say "[select file f2]"
set key-1 to findor
_orderid="           "

@ 2,34 say "การตรวจรับสินค้า"
@ 2,56 say "เลขที่ใบรับสินค้า: " + ltrim(str(_recid))
do while !found()
  set color to w/g,/w
  @ 5,3 say "เลขที่ใบสั่งซื้อสินค้า :" get _orderid
  read
  set key-1 to
  if lastkey()=27
    close all; return
  endif
  @ 5,58 say"วันที่ :"+dtoc(_daterec)
use order
locate for orderid=val(_orderid)
  if found()
    _suppid=suppid
    @ 4,2 to 8,77
    @6,3 say "รหัสผู้จำหน่าย :"
    @6,25 say "ชื่อ   :"
    @7,3 say "ที่อยู่  :"
    @7,50 say "Tel :"
use supplier
    locate for suppid=_suppid
    if found()
    @ 6,20 say ltrim(str(_suppid))
    @ 6,35 say rtrim(suppname)
    @ 7,13 say rtrim(suppadd)
    @ 7,55 say rtrim(supptel)
    endif
  else
    @ 10,20 to 12,60 double
    @ 11,27 say "รหัสสั่งซื้อ"+ltrim(str(_orderid))+"ไม่พบ กรุณาป้อนใหม่"
    inkey(0)
    @ 10,5 clear to 12,70
    loop
   endif
enddo
use receive
append blank
repl recid with _recid,;
orderid with val(_orderid),;
empid with _empid,;
suppid with _suppid,;
date_rec with _daterec
 _sum=0
 r=12
 _tot=0
 close all
 @ 10,4 say "รหัสสินค้า"
 @ 10,20 say "ชื่อสินค้า"
 @ 10,50 say "จำนวน"
 @ 10,60 say "ราคา"
 @ 10,72 say "รวม"
 @ 9,2 to 11,77
sele 1; use orderdet
sele 2; use product
sele 3; use receidet
sele 1
  locate for orderid=val(_orderid)
    while found()
     _proid=0; _quant=0
     _quant=pquant
     _proid=proid
     @ r,6 say ltrim(str(_proid))
     sele 2
     locate for proid=_proid
     if found()
       @ r,15 say rtrim(proname)
     endif
       @ r,52 get _quant
       @ r,57 say cost pict "99,999.99"
       read
       _tot=_quant*cost
       @ r,68 say _tot pict "99,999.99"
       repl quantity with quantity + _quant
       if r=19
       @ 12,2 clear to 19,77
         r=12
       endif
       _sum=_sum+_tot
     if _quant!=0
       sele 3
       append blank
       repl recid with _recid
       repl proid with _proid
       repl rquant with _quant
     endif
     sele 1
     skip;r++
     locate rest for orderid =val(_orderid)
   end
   @ r,3 say repl("_",73)
   tax = _sum*.10
   net= _sum-tax
       @ r+1,50 say "รวมเงิน"
       @ r+1,67 say net pict "999,999.99"
       @ r+2,50 say "ภาษี 10%"
       @ r+2,67 say tax pict "999,999.99"
       @ r+3,50 say "รวมทั้งสิ้น"
       @ r+3,67 say _sum pict "999,999.99"
 use payable
       append blank
       repl suppid with _suppid,;
       recid with _recid,;
       pay_money with _sum,;
       pay_less with 0,;
       date_paid with _daterec+15
       do find2
       inkey(0)
       do receiveprint
       do askcon3
       close all
       return
//=========================
procedure askcon3
  @ 22,2 clear to 22,70
  @ 22,18 say "คุณต้องการทำต่อไปหรือไม่"
  @ 22,50 prompt "[Yes]";@ 22,57 prompt "[No]"
  menu to ans
  if ans=1
   do preceive
  else
   close all
   return
  endif
return
//=================
procedure receiveprint
askprn=alert("สอบถามการพิมพ์ใบเสร็จรับเงิน",{"พิมพ์ใบเสร็จ","ไม่พิมพ์เสร็จ"})
if askprn=1
  @ 0,0 clear to 24,79
  do print4
  @ 22,15 say "****enter to [print] or esc to [cancle]*****"
inkey(0)
if lastkey()=27
  return
else
  set device to printer
  do print4
  set device to screen
 endif
else
  do askcon3
  return
endif
close all
return
//===========================
procedure print4
   use receive; go bottom
   @ 2,28 say "การตรวจรับสินค้า "
   _recid=recid
   @ 2,58 say "เลขที่ใบรับสินค้า:"+ltrim(str(_recid))
   @ 3,2 say repl("=",77)
   @ 4,5 say "ร้านอุปกรณ์ไฟฟ้า นิรันดร์ จำกัด"
   @ 4,62 say "วันที่ :" +dtoc(date_rec)
   @ 5,5 say " 99 หมู่ 7 บ้านเชียงบาน อ.เชียงคำ จ.พะเยา 56110"
   @ 6,5 say "โทร.(054)415314"
   @ 8,3 say "เลขที่ใบสั่งซื้อสินค้า :"+ltrim(str(orderid))
     _orderid=orderid
   use order
   locate for orderid=_orderid
   if found()
     _suppid=suppid
     use supplier
     locate for suppid=_suppid
     if found()
   @ 9,3 say "รหัสผู้จำหน่าย:" +ltrim(str(suppid))
   @ 9,25 say "ชื่อ :" +rtrim(suppname)
   @ 10,3 say "ที่อยู่ :"+ rtrim(suppadd)
   @ 10,40 say "Tel :"+rtrim(supptel)
   endif
   endif
   close all
   _sum=0
   r=14
   _tot=0
   @10,2 say repl("_",77)
   @ 11,4 say "รหัสสินค้า"
   @ 11,20 say "ชื่อสินค้า"
   @ 11,50 say "จำนวน"
   @ 11,60 say "ราคา"
   @ 11,72 say "รวม"
   @ 12,2 say repl("_",77)
   sele 1;use product
   sele 2;use receidet
   locate for recid=_recid
   while found()
   _rquant=rquant
   _proid=proid
   @ r,6 say ltrim(str(proid))
   sele 1
   locate for proid=_proid
   if found()
      @ r,15 say rtrim(proname)
     endif
   @ r,52 say _rquant
   @ r,57 say cost pict "99,999.99"
   _tot=_rquant*cost
   @ r,68 say _tot pict "99,999.99"
   if r=25
     eject
   endif
   _sum=_sum+_tot
   sele 2
   skip;r++
   locate rest for recid=_recid
end
@ r,3 say repl("_",73)
tax=_sum*.10
net=_sum-tax
@ r+1,50 say "รวมเงิน"; @ r+1,67 say net pict "999,999.99"
@ r+2,50 say "ภาษี 10%"; @ r+2,67 say tax pict "999,999.99"
@ r+3,50 say "รวมทั้งสิ้น"; @ r+3,67 say _sum pict "999,999.99"
close all
return
//===========================
procedure find2
sele 1;use receive
sele 2;use employee
sele 2
do while !found()
 _empid=0
 empid=_empid
 @ 21,5 clear to 23,75
 @ 22,2 say "รหัสพนักงานขาย :  " get _empid
 read
 locate for employee->empid=_empid
 if found()
 @ 22,35 say "ชื่อ :"+rtrim(employee->empname)
 else
   @ 22,35 say "##รหัสพนักงานไม่พบ กรุณาป้อนใหม่## "
   inkey(0)
   @ 22,35 clear to 23,75
   loop
 endif
enddo
sele 1; go bottom
repl empid with _empid
close all
return

//===========================
procedure askcancel
do while .t.
   askcan=alert("เลือกการยกเลิกการขาย",{"ยกเลิกทั้งหมด","ยกเลิกบางรายการ",;
   "กลับเมนูหลัก"})
   if askcan=1
      do cancel1
   elseif askcan=2
      do cancel2
   else
      exit
   endif
   close all
enddo
   return
//==========================
//การยกเลิกรายการขายทั้งหมด
procedure cancel1
sele 1 ; use sale
sele 2 ; use customer
sele 3 ; use saledet
sele 4 ; use product
sele 5 ; use receivab
ans=1
do while ans=1
        set color to w/bg+
        cls
        set color to w/b
        @ 1,2 clear to 3,77
        set color to w/gr
        @5,2 clear to 19,77
        set color to w/rb+
        @ 21,2 clear to 23,77
  _saleid=0;ans=0
  set century on
  _date=date()
  sele sale; goto bottom
   set color to "rb/bg"
   @ 24,0 clear to 24,80
   @ 24,25 say "[ESC จบการทำงาน]"
   @ 24,2 say "[Selectc File F2]"
   set key-1 to findsale
   _saleid="          "

  @ 2,27 say "การยกเลิกรายการขายสินค้าทั้งหมด"
  do while !found()
      set color to w/g,/w

     @ 5,3 say "เลขที่รายการขายสินค้า :" get _saleid
     read
     if lastkey()=27
        close all
        return
     endif
     @ 5,58 say "วันที่ :" +dtoc(_date)
     Sele sale
     goto top
     locate for saleid=val(_saleid)
     if found()
        _custid=custid
        @ 4,2 to 8,77
        @ 6,3  say "รหัสลูกค้า:"
        @ 6,25 say "ชื่อ   :"
        @ 7,3  say "ที่อยู่ ## :"
        @ 7,35 say "Tel.   :"
        sele Customer
        goto top
        locate for custid= _custid
        if found()
           @ 6,20 say ltrim(str(_custid))
           @ 6,35 say rtrim(custname)
           @ 7,13 say rtrim(custadd)
           @ 7,38 say rtrim(custtel)
        else
           if custid=0
              @ 6,35 say "ลูกค้าขาจร"
              exit
           endif
        endif
      else
        @ 10,20 to 12,65 double
        @ 11,27 say "รหัสขาย"+ltrim(str(val(_saleid)))+"ไม่พบ กรุณาป้อนใหม่"
        inkey(0)
        @ 10,5 clear to 12,70
        loop
      endif
 enddo
 _sum=0; _tot=0
 r=12
 @ 10,4 say "รหัสสินค้า"
 @ 10,20 say "ชื่อสินค้า"
 @ 10,50 say "จำนวน"
 @ 10,60 say "ราคา"
 @ 10,72 say "รวม"
 @ 9,2 to 11,77
 sele saledet
 goto top
 locate for saleid = val(_saleid)
 while found()
   _quant=quant
   _proid=proid
   sele product
   @ r,6 say ltrim(str(_proid))
   goto top
   locate for proid=_proid
   if found()
   @ r,15 say rtrim(proname)
   endif
   @ r,52 say _quant
   @ r,57 say price pict "99,999.99"
   _tot=_quant*price
   @ r,68 say _tot pict "99,999.99"
   if r=19
     @ 12,2 clear to 19,77
     r=12
     endif
     _sum=_sum+_tot
     sele saledet
     skip;r++
     locate rest for saleid=val(_saleid)
  end
  @ r,3 say repl("-",73)
  tax=_sum*.10
  net=_sum-tax
  @ r+1,50 say "รวมเงิน";@ r+1,67 say net pict"999,999.99"
  @ r+2,50 say "ภาษี 10%";@ r+2,67 say tax pict "999,999.99"
  @ r+3,50 say"รวมทั้งสิ้น";@ r+3,67 say _sum pict "999,999.99"
  @ 22,2 clear to 22,77
  @ 22,15 say "คุณต้องการยกเลิกรายการนี้หรือไม่"
  @ 22,50 prompt "[Yes]"
  @ 22,60 prompt "[No]"
  menu to ans
  if ans=1
    sele saledet
    goto top
    locate for saledet->saleid = val(_saleid)
    while found()
       delete;pack
       _num=quant
       _proid=proid
       sele sale
       goto top
       locate for sale->saleid=val(_saleid)
       if found()
         _custid=custid
         delete;pack
       endif
       sele receivab
       goto top
       locate  for custid = _custid .and. saleid = val(_saleid)
       if found()
          delete;pack
       endif
       sele product
       goto top
       locate for proid=_proid
       if found()
          repl quantity with quantity+_num
       endif
       sele saledet
       skip
       locate rest for saledet->saleid=val(_saleid)
       //แฟ้ม->ฟิลด์
    enddo
  endif
@ 22,2 clear to 22,77
@ 22,18 say "คุณต้องการทำต่อไปหรือไม่"
@ 22,50 prompt "[Yes]"; @ 22,57 prompt "[No]"
menu to ans
  if ans=2
     close all
     exit
  endif
enddo
close all
return
//========================
//การยกเลิกรายการขายบางรายการ
procedure cancel2
sele 1; use saledet
sele 2; use product
sele 3; use sale
sele 4; use receivab
sele 5; use customer
ans=1
  do while ans=1
    set color to w/bg+
    cls
    set color to w/b
    @ 1,2 clear to 3,77
    set color to w/gr
    @5,2 clear to 19,77
    set color to w/rb+
    @ 21,2 clear to 23,77
    _saleid=0;ans=0
    set century on
    _date=date()
   sele sale;goto bottom
   set color to "rb/bg"
   @ 24,0 clear to 24,80
   @ 24,25 say "[ESC จบการทำงาน]"
   @ 24,2 say "[Selectc File F2]"
   set key-1 to findsale
   _saleid="          "
   @ 2,27 say "การยกเลิกรายการขายบางรายการ"
   do while !found() 
      set color to w/g,/w
      @ 5,3 say "เลขที่รายการขายสินค้า :" get _saleid
      read
      if lastkey()=27
        close all
        return
      endif
      @ 5,58 say "วันที่ :" +dtoc(_date)
   sele sale
   goto top
   locate for sale->saleid=val(_saleid)
     if found()
        _custid=custid
        @ 4,2 to 8,77
        @ 6,3  say "รหัสลูกค้า :"
        @ 6,25 say "ชื่อ    :"
        @ 7,3  say "ที่อยู่ # # :"
        @ 7,35 say "Tel.    :"
        sele customer
        goto top
        locate for custid= _custid
        if found()
           @ 6,20 say ltrim(str(_custid))
           @ 6,35 say rtrim(custname)
           @ 7,13 say rtrim(custadd)
           @ 7,38 say rtrim(custtel)
          else
           if custid=0
              @ 6,35 say "ลูกค้าขาจร"
           exit
         endif
        endif
      else
      @ 10,20 to 12,65 double
      @ 11,27 say "รหัสขาย"+ltrim(str(val(_saleid)))+"ไม่พบ กรุณาป้อนใหม่"
      inkey(0)
      @ 10,5 clear to 12,70
      loop
  endif
enddo
 _sum=0; _tot=0
 r=12
 @ 10,4 say "รหัสสินค้า"
 @ 10,20 say "ชื่อสินค้า"
 @ 10,50 say "จำนวน"
 @ 10,60 say "ราคา"
 @ 10,72 say "รวม"
 @ 9,2 to 11,77
  sele saledet
  goto top
  locate for saledet->saleid = val(_saleid)
  while found()
      _quant=quant
      _proid=proid
      sele sale
      goto top
      locate for saleid=val(_saleid)
      if found()
         _custid=custid
      endif
      @ r,6 say ltrim(str(_proid))
      sele product
      goto top
      locate for proid=_proid
      if found()
        @ r,15 say rtrim(proname)
      endif
      @ r,52 say _quant
      @ r,57 say price pict "99,999.99"
      _tot=_quant*price
      @ r,68 say _tot pict "99,999.99"
      if r=19
        @ 12,2 clear to 19,77
        r=12
      endif
      @ 22,2 clear to 22,77
      @ 22,15 say "คุณต้องการยกเลิกรายการนี้หรือไม่"
      @ 22,50 prompt "[Yes]"
      @ 22,60 prompt "[No]"
      menu to ans
      if ans=1
          sele product
          goto top
          locate for proid=_proid
          if found()
             repl quantity with quantity+_quant
          endif
          sele receivab
          goto top
          locate for saleid = val(_saleid) .and. custid = _custid
          if found()
               repl total with total- _tot
          endif
          sele saledet
          delete ; pack
       endif
    _sum = _sum+_tot
    sele saledet
    skip;r++
    locate rest for saleid=val(_saleid)
  enddo
  @ r,3 say repl("_",73)
  tax=_sum*.10
  net=_sum-tax
@ r+1,50 say "รวมเงิน";@ r+1,67 say net pict "999,999.99"
@ r+2,50 say "ภาษี 10%";@ r+2,67 say tax pict "999,999.99"
@ r+2,50 say "รวมทั้งสิ้น";@ r+3,67 say _sum pict "999,999.99"
@ 22,2 clear to 22,77
@ 22,18 say "คุณต้องการทำต่อไปหรือไม่"
@ 22,50 prompt "[Yes]"; @ 22,57 prompt "[No]"
menu to ans
 if ans=2
  close all
  return
 endif
enddo
close all
return
//==========================
1