#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: echoAwoo Taylor Haze Connor Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- #include Global $iCount=InputBox("Input Cycle #", "Please input the cycle number to begin at."&@CRLF&"Use this to resume script after unexpected termination.", 00) Global $aWO[4], $aDB Global $iRoom=IniRead("set.ini", "[Details]", "iLastRoomNum", 0) Local $s=60 If $iCount=0 Then Sleep($s) Local $oaH If WinExists("[LOCAL]") Then $oaH=WinGetHandle("[LOCAL]") ElseIf WinExists("Front Desk") Then $oaH=WinGetHandle("Front Desk") ElseIf WinExists("Guest Listing") Then $oaH=WinGetHandle("Guest Listing") EndIf WinActivate($oaH) Sleep($s) If NOT WinActive($oaH) Then MsgBox(0, "Report Generation Error", "Report generation failed at initilization."&@CRLF&"Continuing with previous workorder.") WinWaitClose("Report Generation Error") EndIf Send("{ALTDOWN}") Sleep($s) Send("{ALTUP}") Sleep($s) For $i = 1 to 2 Step 1 Send("r") Sleep($s) Next WinWait("Reports List") WinActivate("Reports List") If WinActive("Reports List") Then ;~ Else MsgBox(0, "Report Generation Failure", "Report generation failed at Report List") AND Exit Sleep($s) Send("{DOWN}{TAB}") Sleep($s) Send("LOCAL TRACKING-MARKET CATEGORY VALIDATION REPORT") Sleep($s) Send("{ALTDOWN}v{ALTUP}") Sleep($s) WinWait("Preview Options:") WinActivate("Preview Options:") If WinActive("Preview Options: LOCAL TRACKING-MARKET CATEGORY VALIDATION REPORT (Multi-Select)") Then ;~ Else MsgBox(0, "Report Generation Failure", "Report generation failed at preview") AND Exit Sleep($s) Send("{ENTER}") Sleep($s) WinWait ("LOCAL TRACKING") WinActivate("LOCAL TRACKING") If WinActive("LOCAL TRACKING-MARKET CATEGORY VALIDATION REPORT OnQ Property Management - Report Engine") Then ;~ Else MsgBox(0, "Report Generation Failure", "Report generation failed at export:click") AND Exit Sleep($s) MouseClick("left", 298, 37, 1, 40) Sleep($s) WinWait("Export") WinActivate("Export") If WinActive("Export") Then ;~ Else MsgBox(0, "Report Generation Failure", "Report generation failed at export:window") AND Exit Sleep($s) Send("{TAB}{TAB}") Sleep($s) Send("Excel 8.0 (XLS)") Sleep($s) Send("{TAB}") Sleep($s) Send("Disk file") Sleep($s) Send("{ENTER}") Sleep($s) WinWait("Choose Export File") WinActivate("Choose Export File") If WinActive("Choose Export File") Then ;~ Else MsgBox(0, "Report Generation Failure", "Report generation failed at export:save") AND Exit Sleep($s) Send("mktsegvl.xls") Sleep($s) Send("{ENTER}") Sleep($s) WinWait("File already exists") WinActivate("File already exists") If WinActive("File already exists") Then ;~ Else MsgBox(0, "Report Generation Failure", "Report generation failed at export:overwrite") AND Exit Sleep($s) Send("y") Sleep($s) WinActivate("LOCAL TRACKING-MARKET CATEGORY VALIDATION REPORT OnQ Property Management - Report Engine") WinWaitActive("LOCAL TRACKING-MARKET CATEGORY VALIDATION REPORT OnQ Property Management - Report Engine") Sleep($s) If WinActive("LOCAL TRACKING-MARKET CATEGORY VALIDATION REPORT OnQ Property Management - Report Engine") Then Send("{ALTDOWN}{F4}{ALTUP}") EndIf WinWaitClose("LOCAL TRACKING-MARKET CATEGORY VALIDATION REPORT OnQ Property Management - Report Engine") Sleep($s) WinActivate("Reports List") WinWaitActive("Reports List") Sleep($s) If WinActive("Reports List") Then Send("{ALTDOWN}{F4}{ALTUP}") EndIf WinWaitClose("Reports List") Sleep($s) If NOT WinActive($oaH) Then MsgBox(0, "Report Generation Failure", "Report generation failed at close-up."&@CRLF&"Failure not critical continuing.") ;~ ElseIf ;~ MsgBox(0, "Report Generation Failure", "Report generation failed at export:overwrite") ;~ Exit EndIf EndIf Else MsgBox(0, "Report Generation Failure", "Report generation failed at export:save") Exit EndIf Else MsgBox(0, "Report Generation Failure", "Report generation failed at export:window") Exit EndIf Else MsgBox(0, "Report Generation Failure", "Report generation failed at export:click") Exit EndIf Else MsgBox(0, "Report Generation Failure", "Report generation failed at preview") Exit EndIf Else MsgBox(0, "Report Generation Failure", "Report generation failed at Report List") Exit EndIf EndIf Sleep($s*5) While 1 $aWO=_at_WO($iCount) Sleep($s) $aDB=_at_DB($aWO) Sleep($s) _at_Log($aWO, $aDB, $iCount) ;~ Records to log Sleep($s) ;~ If NOT $aWO[0]="Skip" AND NOT $aWO[4]="Skip" AND NOT $aDB="Skip" AND $aWO[2]="INHOUSE" AND NOT $aWO[0]="END OF REPORT" Then If $aWO[2]="INHOUSE" Then If NOT ($aDB="Skip") Then _at_Init($aWO, $aDB, $iCount) Sleep($s) EndIf EndIf Sleep($s) If ($aWO[0]="Skip") OR ($aWO[0]=$iRoom) Then ExitLoop EndIf Sleep($s) $iCount += 1 Sleep($s) ;~ If $iCount=10 Then ExitLoop WEnd Sleep($s) _at_Archive() ;~ Finalizes log for archive Sleep($s) MsgBox(0, "Script Successful!", "Script completed successfully.") #cs ---------------------------------------------------------------------------- Functions Container #ce ---------------------------------------------------------------------------- Func _at_Log($aWO, $aDB, $iCount) Sleep($s) FileWriteLine("log.txt", ($iCount+0)&"|"&@HOUR&":"&@MIN&@TAB&"Rm.# "&$aWO[0]&" "&$aWO[1]&" "&$aWO[3]&@CRLF&@TAB&$aDB) EndFunc Func _at_Archive() If (@HOUR >= 00) AND (@HOUR <= 07) Then FileMove("log.txt", @Year&"_"&@MON&"-"&(@MDay-1)&"_"&"log.txt") Else FileMove("log.txt", @Year&"_"&@MON&"-"&(@MDay)&"_"&"log.txt") EndIf ;~ Sleep($s) ;~ If NOT WinExists("Notepad") Then ;~ FileMove("log.txt", @Year&"_"&@MON&"-"&@MDay&" _ "&@Hour&"_"&"log.txt") ;~ Else ;~ ControlSend("Notepad", "", "", "{CTRLDOWN}s{CTRLUP}") ;~ For $i = 1 to 6 Step 1 ;~ ControlSend("Save as", "", "", "{TAB}") ;~ Next ;~ ControlSend("Save as", "", "", @ScriptDir) ;~ For $i = 1 to 6 Step 1 ;~ ControlSend("Save as", "", "", "{TAB}") ;~ Next ;~ ControlSend("Notepad", "", "", @Year&"_"&@MON&"-"&@MDay&" _ "&@Hour&"_"&"log.txt"&"{ENTER}") ;~ EndIf Sleep($s) EndFunc Func _at_WO($iCount) Local $oExcel, $oWorkbook $oExcel=_Excel_Open(FALSE, FALSE, FALSE, FALSE, FALSE) If @error Then MsgBox(0, "Error: WorkOrder", "ExcelOpen failed with error " & @error) $oWorkbook=_Excel_BookOpen($oExcel, @ScriptDir&"\mktsegvl.xls", TRUE, FALSE) If @error Then MsgBox(0, "Error: WorkOrder", "BookOpen failed with error " & @error) Local $lfRoom, $sName, $aReturn[5] $lfRoom=18+(4*$iCount) $sName=StringSplit(_Excel_RangeRead($oWorkbook, DEFAULT, "B"&$lfRoom, 3, TRUE),"/",2) $aReturn[0]=_Excel_RangeRead($oWorkbook, DEFAULT, "A"&$lfRoom, 3, TRUE) ;~ Room# If @error Then MsgBox(0, "Error: WorkOrder", "RangeRead failed at Room with error " & @error) Sleep($s) $aReturn[1]=$sName[0] Sleep($s) $aReturn[2]=_Excel_RangeRead($oWorkbook, DEFAULT, "D"&$lfRoom, 3, TRUE) ;~ Room Status If @error Then MsgBox(0, "Error: WorkOrder", "RangeRead failed at Status with error " & @error) Sleep($s) $aReturn[3]=_Excel_RangeRead($oWorkbook, DEFAULT, "H"&$lfRoom, 3, TRUE) ;~ Rate Code If @error Then MsgBox(0, "Error: WorkOrder", "RangeRead failed at Rate with error " & @error) Sleep($s) $aReturn[4]=_Excel_RangeRead($oWorkbook, DEFAULT, "J"&$lfRoom, 3, TRUE) ;~ Tracking Value If @error Then MsgBox(0, "Error: WorkOrder", "RangeRead failed at Tracking with error " & @error) Sleep($s) If $aReturn[0]="END OF REPORT" Then Exit MsgBox(0, "Script Complete", "Script has completed.") EndIf Sleep($s) If $aReturn[0]=0 OR "" Then $aReturn[0]="Skip" If NOT $aReturn[4]=("" OR 0) Then $aReturn[4]="Skip" Sleep($s) _Excel_BookClose($oWorkbook, FALSE) If @error Then MsgBox(0, "Error: WorkOrder", "BookClose failed with error " & @error) Sleep($s) _Excel_Close($oExcel, FALSE, TRUE) If @error Then MsgBox(0, "Error: WorkOrder", "ExcelClose failed with error " & @error) Sleep($s) Return $aReturn EndFunc Func _at_DB($aWo) Local $oExcel, $oWorkbook, $aTracking, $sTracking $oExcel=_Excel_Open(FALSE, FALSE, FALSE, FALSE, FALSE) If @error Then MsgBox(0, "Error: Database", "ExcelOpen failed with error " & @error) Sleep($s) $oWorkbook=_Excel_BookOpen($oExcel, @ScriptDir&"\db.xlsx", TRUE, FALSE) If @error Then MsgBox(0, "Error: Database", "BookOpen failed with error " & @error) Sleep($s) $aTracking=_Excel_RangeFind($oWorkbook, $aWO[3], "A:A", Default, Default, False) ;~ If @error Then MsgBox(0, "Error: Database", "RangeFind failed with error " & @error) Sleep($s) ;~ _ArrayDisplay($aTracking, "Display $aTracking Array", "", DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, "") ;~ $aTracking Array size CheckSUM If UBound($aTracking, 1) > 0 Then $sTracking=_Excel_RangeRead($oWorkbook, DEFAULT, StringReplace($aTracking[0][2], "A", "B"), 3, TRUE) ElseIf UBound($aTracking, 1) = 0 Then $sTracking="SKIP" EndIf _Excel_BookClose($oWorkbook, FALSE) If @error Then MsgBox(0, "Error: Database", "BookClose failed with error " & @error) Sleep($s) _Excel_Close($oExcel, FALSE, TRUE) If @error Then MsgBox(0, "Error: Database", "ExcelClose failed with error " & @error) Sleep($s) Return $sTracking EndFunc Func _at_Init($aWO, $aDB, $iCount) Local $sToday, $soBoot, $soLogin, $soNew, $soMain, $soSearch, $soView, $soEdit, $soConfirm ;~ If @HOUR >= 21 AND @HOUR <= 23 Then ;~ $sToday=@MON&"/"&@MDay&"/"&@YEAR ;~ ElseIf @HOUR >= 00 AND @HOUR <= 04 Then ;~ $sToday=@MON&"/"&(@MDay-1)&"/"&@YEAR ;~ EndIf $soBoot="OnQ Property Management - Front Desk" $soLogin="OnQ Security" $soNew="Guest Listing for "&$sToday $soMain="[LOCAL] Guest Listing for "&$sToday $soSearch="Front Desk - Guest Listing Screen" $soView=$aWO[1]&" " $soEdit="Update Room Information" $soConfirm="Front Desk" If WinActive($soBoot) OR WinActive($soLogin) AND WinExists($soBoot) AND WinExists($soLogin) Then SetError(1,1) MsgBox(0, "Error "&@error&"/"&@extended, "Error generated @ _at_Modify. Script detected login screens. Please login and then restart the scipt.") Exit ElseIf NOT WinExists($soMain) AND NOT WinExists($soNew) AND NOT WinExists($soSearch) AND NOT WinExists($soView) AND NOT WinExists($soEdit) AND NOT WinExists($soConfirm) Then SetError(1,2) MsgBox(0, "Error "&@error&"/"&@extended, "Error generated @ _at_Modify. Script unable to detect any necessary screens. Please restart front desk and try again.") Exit Else If WinExists($soNew) Then WinActivate($soNew) WinWaitActive($soNew) Send("{ALTDOWN}") Sleep($s) Send("n") Sleep($s) Send("{ALTUP}") Sleep($s) If WinExists($soNew) AND WinActive($soNew) Then Send("{ENTER}") Sleep($s) WinWait($soSearch) ;~ Now at $soSearch EndIf EndIf If WinExists($soMain) Then WinActivate($soMain) WinWaitActive($soMain) Send("{ALTDOWN}") Sleep($s) Send("n") Sleep($s) Send("{ALTUP}") Sleep($s) If WinExists($soMain) AND WinActive($soMain) Then Send("{ENTER}") Sleep($s) WinWait($soSearch) ;~ Now at $soSearch EndIf EndIf If WinExists($soSearch) Then WinActivate($soSearch) WinWaitActive($soSearch) If $iCount=0 Then Send("{SHIFTDOWN}") Sleep($s) For $i = 1 to 5 Step 1 Send("{TAB}") Sleep($s) Next Send("{SHIFTUP}") Sleep($s) Send("In House") Sleep($s) For $i = 5 to 1 Step -1 Send("{TAB}") Sleep($s) Next EndIf For $i = 1 to 2 Step 1 Send("{TAB}") Sleep($s) Next Send($aWO[0]) Sleep($s) Send("{ENTER}") ;~ Needs to check for a few windows here. Currently script pauses and will not resume after unexpected window. If WinActive("Multi-user") Then Send("{ENTER}") WinWaitClose("Multi-user") ElseIf WinActive($soMain) Then Send("{ENTER}") WinActivate($soView) EndIf Sleep($s*5) If WinActive($soMain) Then Send($aWO[1]) Sleep(2000) Send("{ENTER}") WinWaitNotActive($soMain) Send("{TAB}") Sleep($s) Send($aWO[1]) Sleep($s) For $i = 1 to 10 Step 1 If NOT WinActive($soView) Then Send("{UP}") Sleep($s) Else ExitLoop EndIf Next Sleep($s) EndIf WinWait($soView,"",10) EndIf If WinExists($soView) Then WinActivate($soView) WinWaitActive($soView) Send("{ALTDOWN}") Sleep($s) Send("{ALTUP}") Sleep($s) Send("r") Sleep($s) Send("v") Sleep($s) EndIf If WinExists($soEdit) Then WinActivate($soEdit) WinWaitActive($soEdit) Send("{ALTDOWN}") Sleep($s) For $i = 1 to 2 Step 1 Send("a") Sleep($s) Next Send("{ALTUP}") Sleep($s) For $i = 1 to 3 Step 1 Send("{TAB}") Sleep($s) Next Send($aDB) Sleep($s) Send("{ENTER}") WinActivate($soView) WinWaitActive($soView) Send("{ALTDOWN}") Sleep($s) Send("{ALTUP}") Sleep($s) Send("a") Sleep($s) Send("s") Sleep($s) While 1 Sleep($s) If WinActive("Rate Change", "A change has") Then Send("{ESC}") If WinActive("Rate Change", "Override reason") Then Send("{ENTER}") ElseIf WinActive("Rate Change", "No rate override") Then Send("{ENTER}") WinWaitClose("Rate Change") ExitLoop EndIf Else ExitLoop EndIf WEnd If WinExists($soConfirm) AND NOT WinActive($soConfirm) Then WinActivate($soConfirm) ;~ If WinActive($soConfirm) Then Send("{ENTER}") EndIf If WinExists($soConfirm) Then WinActivate($soConfirm) WinWaitActive($soConfirm) Sleep($s) Send("{ENTER}") Sleep($s) EndIf EndIf EndFunc