Return 
mDateCls1={01/01/2000} && วันที่ต้องการ CLS
mDateCls2={31/12/2015} && วันที่ต้องการ CLS
Do ClsDaily  
Do ClsOther
Return 







Procedure ClsDaily 
Close Data
Use Recvtrn In 0 Exclu 
Sele Recvtrn
Copy Stru To Temp\Tmtrn1 
Use Temp\Tmtrn1 In 0 Exclu Alias Tmtrn1
Sele Recvtrn
Scan For Between(Recvtrn.Posdate,mDateCls1,mDateCls2) .and. Substr(Recvtrn.Posno,1,2)<>Recvtrn.PosType
	Do Case
	Case !Empty(RecvTrn.DebtBaht) .and. Empty(RecvTrn.CheqBaht+RecvTrn.DebtCash+RecvTrn.NoPayBaht)
		***
	Otherwise
		Scatter Memvar 
		cTemp=Dtoc(m.Posdate)
		m.Posno=m.PosType+Substr(cTemp,1,2)+Substr(cTemp,4,2)+Substr(cTemp,9,2)+Alltrim(Str(m.WhsHouse))
		m.Refno=Padl(m.WhsHouse,2,'0')+Space(1)+Padl(m.SubPosType,2,'0')
		m.WhsHouse=0
		m.SubPosType=0
		m.Guest=0
		m.SumTran=0
		InSert Into Tmtrn1 From Memvar 	
		Delete 
	Endcase 	
EndScan 
Select Tmtrn1
Index On Posno+Refno Tag Tag1
Total To Temp\Tmtrn2 On Posno+Refno
Use Temp\Tmtrn2 In 0 Exclu Alias Tmtrn2
Select Tmtrn2
Replace All WhsHouse With Val(Substr(Refno,1,2)),SubPosType With Val(Substr(Refno,5,2))
Sele Recvtrn
Append From Temp\Tmtrn2.Dbf
Pack 
Close Data
Delete File Temp\Tmtrn1.Dbf
Delete File Temp\Tmtrn1.Cdx
Delete File Temp\Tmtrn2.Dbf
*******


Use Recvtail In 0 Exclu 
Sele Recvtail
Copy Stru To Temp\Tmtail1 
Use Temp\Tmtail1 In 0 Exclu Alias Tmtail1
Sele Recvtail
Scan For Between(Recvtail.Posdate,mDateCls1,mDateCls2) .and. Substr(Recvtail.Posno,1,2)<>Recvtail.PosType2
	Scatter Memvar 
	cTemp=Dtoc(m.Posdate)
	m.Posno=m.PosType2+'_'+Substr(cTemp,4,2)+Substr(cTemp,9,2)+'_'+Padl(m.Vattype,1,'0')+Padl(m.VatCode,1,'0')
	m.Vattype=0
	m.VatCode=0
	Insert Into Tmtail1 From Memvar 
	Delete 
EndScan 
Select Tmtail1
Index On Posno+PluCode Tag Tag1
Total To Temp\Tmtail2 On Posno+PluCode
Use Temp\Tmtail2 In 0 Exclu Alias Tmtail2
Select Tmtail2
Replace All Vattype With Val(Substr(Posno,9,1)),VatCode With Val(Substr(Posno,10,1))
Sele Recvtail
Append From Temp\Tmtail2.Dbf
Pack 
Close Data
Delete File Temp\Tmtail1.Dbf
Delete File Temp\Tmtail1.Cdx
Delete File Temp\Tmtail2.Dbf

Return 




Procedure ClsOther
****** สำหรับล้างและไม่เก็บข้อมูลไว้ 
*Use RecvTrn Exclu 
*Delete All For Between(PosDate,mDateCls1,mDateCls2)
*Pack 

*Use RecvTail Exclu 
*Delete All For Between(PosDate,mDateCls1,mDateCls2)
*Pack 
*****

Use Foodrepo Exclu 
Delete All For Between(OrFoodDate,mDateCls1,mDateCls2)
Pack 

Use PluCTrn Exclu 
Delete All For Between(PosDate,mDateCls1,mDateCls2)
Pack 


Use IvTrn Exclu 
Delete All For Between(PosDate,mDateCls1,mDateCls2)
Pack 

Use PayTrn Exclu 
Delete All For Between(PosDate,mDateCls1,mDateCls2)
Pack 

Use PayTrn Exclu 
Delete All For Between(PosDate,mDateCls1,mDateCls2)
Pack 


Use CanOfBil Exclu 
Delete All For Between(PosDate,mDateCls1,mDateCls2)
Pack 
Return 























