Return 
mDateCls={01/01/2017} && วันที่ต้องการ CLS
Do ClsDate

mYearRoom=2015 && เก็บไว้ 2 ปี 
mDirOld='2016' && ตำแหน่งข้อมูลที่เก็บ
Do ClsGuest

Do DupGuest
Return 



Procedure ClsDate 
Close Data
***
Use Room Exclu 
Delete All For !Empty(RoomDate) .and. Status='B' .and. Room4Flag='D' .and. RoomDate<mDateCls
Pack 
Close Data
***
Use RoomIN Exclu 
Delete All For !Empty(RoomDate) .and. RoomDate<mDateCls
Pack 
Close Data
***
Use RoomOpen Exclu 
Delete All For !Empty(OpenDate) .and. OpenDate<mDateCls
Pack 
Close Data
***
Use ChgPrice Exclu 
Delete All For !Empty(Date_Chg) .and. Date_Chg<mDateCls
Pack 
Close Data
***
Use DoorOpen Exclu 
Delete All For !Empty(OpenDrDt) .and. OpenDrDt<mDateCls
Pack 
Close Data
***
Use LoGinUse Exclu 
Delete All For !Empty(LoGinSysDT) .and. LoGinSysDT<mDateCls
Pack 
Close Data
***
Use RoomHead In 0 Exclu Alias RoomHead Order RmCode 
Use RoomTran In 0 Exclu Alias RoomTran Order RmCode
Use RoomHD2 In 0 Exclu Alias RoomHD2 Order RmCode
Use Room In 0 Share Noupdate Alias Room 
Use RoomCode In 0 Share Noupdate Alias RoomCode
Create Cursor TempCode (mRmCode C(10))
Index On mRmCode Tag mRmCode
Selec RoomCode 
Scan 
	If !Empty(RoomCode.Rent_No) 
		m.mRmCode=RoomCode.Rent_No	
		Insert Into TempCode From Memvar 
	Endif 
	If !Empty(RoomCode.Rent_n_No) 
		m.mRmCode=RoomCode.Rent_n_No
		Insert Into TempCode From Memvar 
	Endif 
EndScan 
Select Room 
Scan 
	If !Empty(Room.BkFirstNo) 
		m.mRmCode=Room.BkFirstNo
		Insert Into TempCode From Memvar 
	Endif 

	If !Empty(Room.ReCeiptno) 
		m.mRmCode=Room.ReCeiptno
		Insert Into TempCode From Memvar 
	Endif 
	If !Empty(Room.FirstDocno) 
		m.mRmCode=Room.FirstDocno
		Insert Into TempCode From Memvar 
	Endif 
EndScan 
Select RoomHead 
Scan 
	Do Case 
	Case Empty(RoomHead.HoSysDate)
		Delete 
	Case Seek(RoomHead.RmCode,'TempCode')
		****
	Case HoSysDate<mDateCls
		Delete 
	EndCase
EndScan
Select RoomHead 
Pack 
****
Select RoomTran 
Scan 
	If !Seek(RoomTran.RmCode,'RoomHead')
		Delete 
	Endif 
EndScan 
Select RoomTran 
Pack 
****
Select RoomHD2 
Scan 
	If !Seek(RoomHD2.RmCode,'RoomHead')
		Delete 
	Endif 
EndScan 
Select RoomHD2 
Pack 
Close Data
Return 




Procedure ClsGuest
Close Data
Use Room In 0 Exclu Alias Room 
Use Guest In 0 Exclu Order GuestCode Alias Guest 
Use Guesttrn In 0 Exclu Order GuestCode Alias Guesttrn
Use (mDirOld+'\RoomHead') In 0 Share Noupdate Alias HeadTran Order GuestCode 
Sele Room 
If Tagno('GuestCode')=0
	Index On GuestCode Tag GuestCode 
Endif 
Set Order To GuestCode
Select HeadTran
Set Filter To Year(HoSysDate)>=mYearRoom
Select Guest
Scan 
	If !Seek(Guest.GuestCode,'HeadTran') .and. !Seek(Guest.GuestCode,'Room')
		Delete 
	Endif 
EndScan 
Select Guest
Pack 
***
Select GuestTrn 
Scan 
	If !Seek(GuestTrn.GuestCode,'Guest')
		Delete 
	Endif 
EndScan 
Select GuestTrn 
Pack 
Select HeadTran
Set Filter To 
Close Data
Return 



Procedure DupGuest
Close Data
Use Room In 0 Exclu Alias Room 
Use Guest In 0 Exclu Alias Guest Order GuestName 
Use RoomHead In 0 Share Noupdate Alias RoomHead Order GuestCode 
Sele Room 
If Tagno('GuestCode')=0
	Index On GuestCode Tag GuestCode 
Endif 
Set Order To GuestCode
Selec Guest
mDupName='XXX'
Scan 
	If Guest.GuestName=mDupName .and. !Seek(Guest.GuestCode,'RoomHead') .and. !Seek(Guest.GuestCode,'Room')
		Delete 
	Endif
	mDupName=Guest.GuestName
EndScan 
Selec Guest
Pack 
Close Data
Return 


