Untitled

 avatar
unknown
plain_text
a year ago
29 kB
15
Indexable
#Requires AutoHotkey v2.0
#SingleInstance Force

; ========================================
; GLOBAL CONFIGURATION
; ========================================
global sleepDelay := 200

; Global variables for data storage
global Field1Content := “”
global Field2Content := “”
global Field3Content := “”
global AvailableQty := “”

; Toast notification globals
global toastGui := unset
global toastVisible := false

; GUI globals
global myGui, headerSubtitle, btnCopy
global locationDropdown, inputProduct, inputQty, categoryDropdown
global radioDry, radioWet, btnStart, btnClear
global statusText, statusIcon
global currentLines, dryLines, wetLines
global lastProductLength := 0

; ========================================
; STARTUP AND EMERGENCY EXIT
; ========================================

; Emergency Exit - double ESC
Esc:: {
static escCount := 0
static lastEscTime := 0

```
currentTime := A_TickCount
if (currentTime - lastEscTime < 1500) {
    escCount++
    if (escCount >= 2) {
        ExitApp
    }
} else {
    escCount := 1
}
lastEscTime := currentTime

SetTimer(() => escCount := 0, -1000)
```

}

; Check for updates on startup
CheckForUpdates()

CheckForUpdates() {
masterFile := “\Corp.coopervision.com\dfs\UK-MANF-DEPT-01\WC-Public\G Petrov\Work\Oracle - Support App\Oracle Support App - AutoUpdate.ahk”
currentFile := A_ScriptFullPath

```
if !FileExist(masterFile)
    return

masterTime := FileGetTime(masterFile, "M")
currentTime := FileGetTime(currentFile, "M")

if (masterTime > currentTime) {
    result := MsgBox("New version available! Update now?", "Update Available", "YesNo")
    if (result = "Yes") {
        FileCopy(masterFile, currentFile, 1)
        Run(A_ScriptFullPath)
        ExitApp
    }
}
```

}

; ========================================
; HOTKEYS
; ========================================

^o:: {
ShowGui()
}

; ========================================
; TOAST NOTIFICATION SYSTEM
; ========================================

ShowToast(title, message, icon := “ℹ”, duration := 4000, type := “info”) {
global toastGui, toastVisible

```
if (toastVisible && IsSet(toastGui)) {
    HideToast()
}

primaryMonitor := MonitorGetPrimary()
MonitorGet(primaryMonitor, &MonLeft, &MonTop, &MonRight, &MonBottom)
taskbarHeight := 40

; Color schemes based on type
switch type {
    case "success":
        bgColor := 0xF5F5F5
        borderColor := 0x00C851
        iconColor := 0x00C851
        textColor := 0x2D2D30
        subTextColor := 0x6D6D6D
    case "error":
        bgColor := 0xF5F5F5
        borderColor := 0xFF4444
        iconColor := 0xFF4444
        textColor := 0x2D2D30
        subTextColor := 0x6D6D6D
    case "warning":
        bgColor := 0xF5F5F5
        borderColor := 0xFFB300
        iconColor := 0xFFB300
        textColor := 0x2D2D30
        subTextColor := 0x6D6D6D
    case "process":
        bgColor := 0xF5F5F5
        borderColor := 0x2196F3
        iconColor := 0x2196F3
        textColor := 0x2D2D30
        subTextColor := 0x6D6D6D
    default:
        bgColor := 0xF5F5F5
        borderColor := 0x00A6FB
        iconColor := 0x00A6FB
        textColor := 0x2D2D30
        subTextColor := 0x6D6D6D
}

toastGui := Gui("+AlwaysOnTop +ToolWindow -MaximizeBox -MinimizeBox -Caption +LastFound", "Toast")
toastGui.BackColor := bgColor
toastGui.MarginX := 0
toastGui.MarginY := 0

toastWidth := 350
toastHeight := 90
xPos := MonRight - toastWidth - 15
yPos := MonBottom - toastHeight - taskbarHeight - 15

; Create toast elements
bgMain := toastGui.AddText("x2 y2 w" . (toastWidth-4) . " h" . (toastHeight-4) . " +Background", "")
bgMain.BackColor := bgColor

accentBorder := toastGui.AddText("x0 y0 w4 h" . toastHeight . " +Background", "")
accentBorder.BackColor := borderColor

iconBg := toastGui.AddText("x20 y20 w35 h35 +Background +Center", "")
iconBg.BackColor := borderColor

toastIcon := toastGui.AddText("x22 y22 w31 h31 +Center +Background", icon)
toastIcon.SetFont("s16 Bold", "Segoe UI Emoji")
toastIcon.BackColor := borderColor
toastIcon.TextColor := 0xFFFFFF

toastTitle := toastGui.AddText("x70 y18 w250 h22", title)
toastTitle.SetFont("s11 w600", "Segoe UI Variable")
toastTitle.BackColor := bgColor
toastTitle.TextColor := textColor

toastMessage := toastGui.AddText("x70 y42 w250 h35", message)
toastMessage.SetFont("s9", "Segoe UI Variable")
toastMessage.BackColor := bgColor
toastMessage.TextColor := subTextColor

closeBtn := toastGui.AddText("x315 y10 w25 h25 +Center +Background", "✕")
closeBtn.SetFont("s14", "Segoe UI Variable")
closeBtn.BackColor := bgColor
closeBtn.TextColor := 0x888888
closeBtn.OnEvent("Click", (*) => HideToast())

toastVisible := true
startX := MonRight + 50
toastGui.Show("x" . startX . " y" . yPos . " w" . toastWidth . " h" . toastHeight . " NoActivate")

AnimateToastModern(toastGui, startX, xPos, yPos, 300)
SetTimer(HideToast, -duration)
```

}

AnimateToastModern(gui, startX, endX, yPos, duration) {
steps := 20
stepDelay := duration // steps

```
Loop steps {
    progress := A_Index / steps
    easedProgress := 1 - ((1 - progress) ** 3)
    currentX := startX + (endX - startX) * easedProgress
    
    try {
        gui.Move(Round(currentX), yPos)
    }
    Sleep(stepDelay)
}
try {
    gui.Move(endX, yPos)
}
```

}

HideToast() {
global toastGui, toastVisible

```
if (toastVisible && IsSet(toastGui)) {
    toastVisible := false
    try {
        toastGui.Destroy()
    } catch {
        try {
            toastGui.Close()
        } catch {
            ; Ignore any errors
        }
    }
    toastGui := unset
}
```

}

ForceHideToast() {
global toastGui, toastVisible

```
SetTimer(HideToast, 0)

if (IsSet(toastGui)) {
    toastVisible := false
    try {
        toastGui.Destroy()
    } catch {
        try {
            toastGui.Close()
        } catch {
            ; Ignore
        }
    }
    toastGui := unset
}
```

}

ShowStatusToast(message, type := “info”) {
switch type {
case “success”:
ShowToast(“✅ Success”, message, “✓”, 8500, “success”)
case “error”:
ShowToast(“❌ Error”, message, “✗”, 4000, “error”)
case “warning”:
ShowToast(“⚠ Warning”, message, “!”, 5000, “warning”)
case “process”:
ShowToast(“🔄 Processing”, message, “⟲”, 3500, “process”)
case “ready”:
ShowToast(“🎯 Ready”, message, “●”, 4000, “info”)
default:
ShowToast(“ℹ Info”, message, “ℹ”, 4500, “info”)
}
}

; ========================================
; DATA STRUCTURES
; ========================================

InitializeLineData() {
global dryLines := [
{Name: “”, Code: “”},
{Name: “—A Line—”, Code: “”},
{Name: “A IMM’s”, Code: “WC-MNT 1”},
{Name: “A F&C”, Code: “WC-MNT 2”},
{Name: “A Oven”, Code: “WC-MNT 3”},
{Name: “A Bagger”, Code: “WC-MNT 4”},
{Name: “”, Code: “”},
{Name: “—B Line—”, Code: “”},
{Name: “B IMM’s”, Code: “WC-MNT 5”},
{Name: “B F&C”, Code: “WC-MNT 6”},
{Name: “B Oven”, Code: “WC-MNT 7”},
{Name: “B Bagger”, Code: “WC-MNT 8”},
{Name: “”, Code: “”},
{Name: “—C Line—”, Code: “”},
{Name: “C IMM’s”, Code: “WC-MNT 9”},
{Name: “C F&C”, Code: “WC-MNT 10”},
{Name: “C Oven”, Code: “WC-MNT 11”},
{Name: “C Bagger”, Code: “WC-MNT 12”},
{Name: “”, Code: “”},
{Name: “—D Line—”, Code: “”},
{Name: “D IMM’s”, Code: “WC-MNT 13”},
{Name: “D F&C”, Code: “WC-MNT 14”},
{Name: “D Oven”, Code: “WC-MNT 15”},
{Name: “D Bagger”, Code: “WC-MNT 16”},
{Name: “”, Code: “”},
{Name: “—E Line—”, Code: “”},
{Name: “E IMM’s”, Code: “WC-MNT 17”},
{Name: “E F&C”, Code: “WC-MNT 18”},
{Name: “E Oven”, Code: “WC-MNT 19”},
{Name: “E Bagger”, Code: “WC-MNT 20”},
{Name: “”, Code: “”},
{Name: “—F Line—”, Code: “”},
{Name: “F IMM’s”, Code: “WC-MNT 21”},
{Name: “F F&C”, Code: “WC-MNT 22”},
{Name: “F Oven”, Code: “WC-MNT 23”},
{Name: “F Bagger”, Code: “WC-MNT 24”},
{Name: “”, Code: “”},
{Name: “—H Line—”, Code: “”},
{Name: “H IMM’s”, Code: “WC-MNT 25”},
{Name: “H F&C”, Code: “WC-MNT 26”},
{Name: “H Oven”, Code: “WC-MNT 27”},
{Name: “H Bagger”, Code: “WC-MNT 28”},
{Name: “”, Code: “”},
{Name: “—J Line—”, Code: “”},
{Name: “J IMM’s”, Code: “WC-MNT 29”},
{Name: “J F&C”, Code: “WC-MNT 30”},
{Name: “J Oven”, Code: “WC-MNT 31”},
{Name: “J Bagger”, Code: “WC-MNT 32”},
{Name: “”, Code: “”},
{Name: “—K Line—”, Code: “”},
{Name: “K IMM’s”, Code: “WC-MNT 33”},
{Name: “K F&C”, Code: “WC-MNT 34”},
{Name: “K Oven”, Code: “WC-MNT 35”},
{Name: “K Bagger”, Code: “WC-MNT 36”}
]

```
global wetLines := [
    {Name: "", Code: ""},
    {Name: "—B Line—", Code: ""},
    {Name: "B Sortimat", Code: "WC-MNT 37"},
    {Name: "B HH", Code: "WC-MNT 38"},
    {Name: "", Code: ""},
    {Name: "—C Line—", Code: ""},
    {Name: "C Sortimat", Code: "WC-MNT 39"},
    {Name: "C HH", Code: "WC-MNT 40"},
    {Name: "", Code: ""},
    {Name: "—D Line—", Code: ""},
    {Name: "D Sortimat", Code: "WC-MNT 41"},
    {Name: "D HH", Code: "WC-MNT 42"},
    {Name: "", Code: ""},
    {Name: "—E Line—", Code: ""},
    {Name: "E Sortimat", Code: "WC-MNT 43"},
    {Name: "E HH", Code: "WC-MNT 44"},
    {Name: "", Code: ""},
    {Name: "—F Line—", Code: ""},
    {Name: "F Sortimat", Code: "WC-MNT 45"},
    {Name: "F HH", Code: "WC-MNT 46"}
]

global currentLines := dryLines
```

}

; ========================================
; UTILITY FUNCTIONS
; ========================================

GetLocationCode() {
selectedLocation := locationDropdown.Text
switch selectedLocation {
case “Warrior Close”:
return “WC_ENG”
case “Speedwell”:
return “SW_ENG”
case “Hamble SP1”:
return “HM1_ENG”
case “Hamble SP4”:
return “HM4_ENG”
default:
return “WC_ENG”
}
}

GetLocationMessage(isLastOne) {
selectedLocation := locationDropdown.Text
if (selectedLocation = “Warrior Close”) {
if (isLastOne)
return “Taken from Warrior Store - 0 Stock”
else
return “Taken from Warrior Store”
} else {
if (isLastOne)
return “Please deliver to Warrior Close - 0 Stock”
else
return “Please deliver to Warrior Close”
}
}

UpdateStatus(message, color := 0xCCCCCC) {
statusText.Text := message
statusIcon.TextColor := color
}

; ========================================
; GUI CREATION AND MANAGEMENT
; ========================================

ShowGui() {
global myGui
if !IsSet(myGui) {
CreateMainGui()
}

```
myGui.Show("w380 h405")
ShowStatusToast("Oracle Support App opened", "ready")
```

}

CreateMainGui() {
global myGui := Gui(”  -MaximizeBox”, “Oracle Support App”)
myGui.BackColor := 0xF5F5F5
myGui.MarginX := 0
myGui.MarginY := 0
myGui.SetFont(“s10”, “Segoe UI Variable”)

```
CreateHeader()
CreateMainContent()
CreateActionButtons()
CreateStatusBar()

SetupEventHandlers()
SetupTooltips()
InitializeLineData()

myGui.Show("w380 h405")
```

}

CreateHeader() {
global headerBg := myGui.AddText(“x0 y0 w400 h70 +Background”, “”)
headerBg.BackColor := 0x2D2D30

```
global headerTitle := myGui.AddText("x87 y10 w300 h25", "Oracle Support App")
headerTitle.SetFont("s16 Bold", "Segoe UI Variable")
headerTitle.BackColor := 0x2D2D30
headerTitle.TextColor := 0xFFFFFF

global headerSubtitle := myGui.AddText("x158 y40 w300 h20", "Warrior Close")
headerSubtitle.SetFont("s9", "Segoe UI Variable")
headerSubtitle.BackColor := 0x2D2D30
headerSubtitle.TextColor := 0xCCCCCC

global appversion := myGui.AddText("x298 y25 w40 h20", "v 1.0")
appversion.SetFont("s6", "Segoe UI Variable")
appversion.BackColor := 0x2D2D30
appversion.TextColor := 0xCCCCCC
```

}

CreateMainContent() {
global contentBg := myGui.AddText(“x20 y90 w380 h210 +Background”, “”)
contentBg.BackColor := 0x252526

```
CreateLocationSection()
CreateProductSection()
CreateQuantitySection()
CreateLineTypeSection()
CreateLineSelectionSection()
```

}

CreateLocationSection() {
global locationLabel := myGui.AddText(“x40 y85 w270”, “Source Warehouse”)
locationLabel.SetFont(“s10 Bold”, “Segoe UI Variable”)
locationLabel.BackColor := 0x252526
locationLabel.TextColor := 0xFFFFFF

```
global locationDropdown := myGui.AddDropDownList("x40 y110 w300 h200 Choose1 vLocationSelect", ["Warrior Close", "Speedwell", "Hamble SP1", "Hamble SP4"])
locationDropdown.BackColor := 0x3C3C3C
locationDropdown.SetFont("s10", "Segoe UI Variable")
```

}

CreateProductSection() {
global productLabel := myGui.AddText(“x40 y160 w150”, “Product Number”)
productLabel.SetFont(“s10 Bold”, “Segoe UI Variable”)
productLabel.BackColor := 0x252526
productLabel.TextColor := 0xFFFFFF

```
global productContainer := myGui.AddText("x40 y180 w150 h35 +Background", "")
productContainer.BackColor := 0x3C3C3C

global inputProduct := myGui.AddEdit("x40 y185 w140 h25 +Background -Border +Number")
inputProduct.BackColor := 0x3C3C3C
inputProduct.TextColor := 0xFFFFFF
inputProduct.SetFont("s10", "Segoe UI Variable")
```

}

CreateQuantitySection() {
global qtyLabel := myGui.AddText(“x200 y160 w120 “, “Quantity”)
qtyLabel.SetFont(“s10 Bold”, “Segoe UI Variable”)
qtyLabel.BackColor := 0x252526
qtyLabel.TextColor := 0xFFFFFF

```
global inputQty := myGui.AddEdit("x200 y185 w140 h25 +Background -Border +Number")
inputQty.BackColor := 0x3C3C3C
inputQty.TextColor := 0xFFFFFF
inputQty.SetFont("s10", "Segoe UI Variable")
inputQty.Value := 1
```

}

CreateLineTypeSection() {
global lineTypeLabel := myGui.AddText(“x40 y240 w140”, “Line Type”)
lineTypeLabel.SetFont(“s10 Bold”, “Segoe UI Variable”)
lineTypeLabel.BackColor := 0x252526
lineTypeLabel.TextColor := 0xFFFFFF

```
global radioDry := myGui.AddRadio("x40 y270 w65 vRadioDry", "Dry")
radioDry.BackColor := 0x252526
radioDry.TextColor := 0xFFFFFF
radioDry.SetFont("s9", "Segoe UI Variable")
radioDry.Value := 1

global radioWet := myGui.AddRadio("x115 y270 w65 vRadioWet", "Wet")
radioWet.BackColor := 0x252526
radioWet.TextColor := 0xFFFFFF
radioWet.SetFont("s9", "Segoe UI Variable")
```

}

CreateLineSelectionSection() {
global categoryLabel := myGui.AddText(“x200 y240 w140”, “Line Selection”)
categoryLabel.SetFont(“s10 Bold”, “Segoe UI Variable”)
categoryLabel.BackColor := 0x252526
categoryLabel.TextColor := 0xFFFFFF

```
categoryDisplayNames := []
for item in currentLines
    categoryDisplayNames.Push(item.Name)

global categoryDropdown := myGui.AddDropDownList("x200 y265 w140 h200 Choose1 vCategorySelect", categoryDisplayNames)
categoryDropdown.BackColor := 0x3C3C3C
categoryDropdown.SetFont("s10", "Segoe UI Variable")
```

}

CreateActionButtons() {
global btnStart := myGui.AddButton(“Default x40 y320 w140 h40 +Background”, “▶ START”)
btnStart.SetFont(“s10 Bold”, “Segoe UI Variable”)
btnStart.BackColor := 0x0078D4
btnStart.TextColor := 0xFFFFFF

```
global btnClear := myGui.AddButton("x200 y320 w140 h40 +Background", "🔄 RESET ALL")
btnClear.SetFont("s10 Bold", "Segoe UI Variable")
btnClear.BackColor := 0x484848
btnClear.TextColor := 0xFFFFFF

global btnCopy := myGui.AddText("x340 y325 w35 h30 Center", "✉")
btnCopy.SetFont("s15", "Segoe UI Variable")
btnCopy.BackColor := 0x2D2D30
btnCopy.TextColor := 0xCCCCCC
btnCopy.Visible := false
```

}

CreateStatusBar() {
global statusBg := myGui.AddText(“x0 y370 w400 h35 +Background”, “”)
statusBg.BackColor := 0x2D2D30

```
global statusIcon := myGui.AddText("x15 y380 w20 h15 +Center")
statusIcon.BackColor := 0x2D2D30
statusIcon.TextColor := 0x00FF88
statusIcon.SetFont("s12")

global statusText := myGui.AddText("x40 y380 w340 h15", "Ready to process orders")
statusText.SetFont("s9", "Segoe UI Variable")
statusText.BackColor := 0x2D2D30
statusText.TextColor := 0xCCCCCC
```

}

SetupEventHandlers() {
btnStart.OnEvent(“Click”, StartScript)
btnClear.OnEvent(“Click”, ClearAllFields)
btnCopy.OnEvent(“Click”, CopyToClipboard)

```
radioDry.OnEvent("Click", UpdateLineDropdown)
radioWet.OnEvent("Click", UpdateLineDropdown)

inputProduct.OnEvent("Change", FormatProductNumber)
inputQty.OnEvent("Change", ValidateInputs)
categoryDropdown.OnEvent("Change", ValidateInputs)
```

}

SetupTooltips() {
SetTimer(CheckMousePosition, 50)
}

; ========================================
; EVENT HANDLERS
; ========================================

CheckMousePosition() {
static lastControl := “”
MouseGetPos(, , , &currentControl, 2)

```
if (currentControl == locationLabel.Hwnd) {
    if (lastControl != currentControl) {
        ToolTip("Choose which Warehouse the Item should come from")
        lastControl := currentControl
    }
} else {
    if (lastControl == locationLabel.Hwnd) {
        ToolTip()
        lastControl := ""
    }
}
```

}

FormatProductNumber(*) {
currentText := inputProduct.Text
cleanText := RegExReplace(currentText, “[^\d]”, “”)

```
if (StrLen(cleanText) > 9) {
    cleanText := SubStr(cleanText, 1, 9)
    inputProduct.Text := cleanText
    inputProduct.Focus()
    Send("{End}")
} else if (cleanText != currentText) {
    inputProduct.Text := cleanText
}

ValidateInputs()
```

}

UpdateLineDropdown(*) {
global currentLines

```
if (radioDry.Value) {
    currentLines := dryLines
} else {
    currentLines := wetLines
}

categoryDisplayNames := []
for item in currentLines
    categoryDisplayNames.Push(item.Name)

currentSelection := categoryDropdown.Text

categoryDropdown.Delete()
categoryDropdown.Add(categoryDisplayNames)

selectionFound := false
Loop categoryDisplayNames.Length {
    if (categoryDisplayNames[A_Index] = currentSelection) {
        categoryDropdown.Choose(A_Index)
        selectionFound := true
        break
    }
}

if (!selectionFound) {
    categoryDropdown.Choose(1)
}

ValidateInputs()
```

}

ValidateInputs(*) {
global currentLines

```
productNum := inputProduct.Text
qty := inputQty.Text
selectedName := categoryDropdown.Text

selectedCode := ""
for item in currentLines {
    if item.Name = selectedName {
        selectedCode := item.Code
        break
    }
}

if (productNum != "" && qty != "" && IsNumber(qty) && qty > 0 && selectedCode != "") {
    UpdateStatus("✅ Ready to start process", 0x00FF88)
    btnStart.Enabled := true
    btnStart.BackColor := 0x00AA44
} else {
    UpdateStatus("⚠ Please complete all required fields", 0xFFAA00)
    btnStart.Enabled := false
    btnStart.BackColor := 0x666666
}
```

}

ClearAllFields(*) {
inputProduct.Text := “”
inputQty.Value := 1
locationDropdown.Choose(1)
radioDry.Value := 1
radioWet.Value := 0
UpdateLineDropdown()
categoryDropdown.Choose(1)
btnCopy.Visible := false
AvailableQty := “”

```
UpdateStatus("🔄 All fields cleared", 0x00A6FF)
btnStart.Enabled := true
btnStart.BackColor := 0x0078D4

ShowStatusToast("All fields have been reset", "ready")
```

}

CopyToClipboard(*) {
global Field1Content, Field2Content, Field3Content
myMessage := “Hi,`n`nWe are currently zero stock on the following:`n`n” Field2Content “`n" Field3Content "`n” Field1Content “`n`nMany Thanks”

```
A_Clipboard := ""
Sleep 100
A_Clipboard := myMessage
ShowStatusToast("Message copied to clipboard", "success")
```

}

; ========================================
; MAIN PROCESSING FUNCTION
; ========================================

StartScript(*) {
global sleepDelay, currentLines

```
; Validation
productSuffix := inputProduct.Text
if (productSuffix == "") {
    UpdateStatus("❌ Product number required", 0xFF4444)
    ShowStatusToast("Product number is required", "error")
    return
}

if (inputQty.Text == "" || !IsNumber(inputQty.Text) || inputQty.Text <= 0) {
    UpdateStatus("❌ Valid quantity required", 0xFF4444)
    ShowStatusToast("Valid quantity is required", "error")
    return
}

; Initialize processing
UpdateStatus("🔄 Initializing process…", 0x00A6FF)
ShowStatusToast("Initializing Oracle process…", "process")

btnStart.Enabled := true
btnClear.Enabled := true
btnStart.BackColor := 0x666666
btnClear.BackColor := 0x333333

; Get processing values
productNumber := productSuffix
quantity := inputQty.Text
requestedQty := Integer(quantity)
selectedName := categoryDropdown.Text
selectedCode := ""

for item in currentLines {
    if (item.Name = selectedName) {
        selectedCode := item.Code
        break
    }
}

; Check Oracle window
if WinExist("Oracle Applications - cvprd ahk_class Transparent Windows Client ahk_exe wfica32.exe") {
    WinActivate()
} else {
    MsgBox("Please navigate to the Move Orders Page in Oracle.", "Oracle - Not Open", 48)
    UpdateStatus("💥 Oracle is not running - Please open 'Move Order' page.", 0xFF4444)
    return
}

; Main processing
try {
    selectedLocation := locationDropdown.Text
    UpdateStatus("🔄 Processing " . selectedLocation . " details…", 0x00A6FF)
    ShowStatusToast("Processing " . selectedLocation . " order details", "process")

    myGui.Minimize()
    
    ProcessOracleOrder(productNumber, quantity, selectedCode, requestedQty)
    
} catch Error as e {
    UpdateStatus("💥 Error occurred during processing", 0xFF4444)
    ShowStatusToast("Processing failed: " . e.message, "error")
    MsgBox("Process failed: " . e.message, "Error", 16)
}

; Re-enable buttons
btnStart.Enabled := true
btnClear.Enabled := true
btnStart.BackColor := 0x00AA44
btnClear.BackColor := 0x484848
```

}

ProcessOracleOrder(productNumber, quantity, selectedCode, requestedQty) {
global sleepDelay

```
; Set key delay and begin Oracle interaction
SetKeyDelay 40, 40

; Phase 1: Initial navigation and setup
ProcessPhase1()

; Phase 2: Product entry
ProcessPhase2(productNumber, quantity, selectedCode)

; Phase 3: Data extraction
ExtractItemData()

; Phase 4: Quantity validation
validatedQty := ValidateQuantity(quantity, requestedQty)

; Phase 5: Final processing
ProcessPhase5(validatedQty)
```

}

ProcessPhase1() {
global sleepDelay

```
Sleep sleepDelay
Send "{Tab}"
Sleep sleepDelay

Send "+{Tab}"
A_Clipboard := ""
Send("^a")
Sleep 100
Send("^c")
ClipWait(1)

if (A_ClipBoard = "" || !RegExMatch(A_ClipBoard, "\w")) {
    ForceHideToast()
    MsgBox("Please open Oracle in Move Orders Page", "Move Orders Page - Not Open", 48)
    UpdateStatus("💥 Please open Oracle in Move Orders Page", 0xFF4444)
    return
}
A_Clipboard := ""

Sleep sleepDelay
Send "{Tab}"
Sleep sleepDelay
Send "{Tab}"
Sleep sleepDelay

Send "Project Move Issue"
Sleep sleepDelay

Send "{Tab}"
Sleep sleepDelay

Send "CVI UK Warrior Close"
Sleep sleepDelay

Send "{Tab}"
Sleep sleepDelay

locationCode := GetLocationCode()
Send locationCode
Sleep sleepDelay

Send "{Tab}"
Sleep sleepDelay
Send "{Tab}"
Sleep sleepDelay
Send "{Tab}"
Sleep sleepDelay

Send "UKM - Dailies"
Sleep sleepDelay

Send "{Tab}"
Sleep sleepDelay
Send "{Enter}"
```

}

ProcessPhase2(productNumber, quantity, selectedCode) {
global sleepDelay

```
UpdateStatus("⚡ Processing order details…", 0x00A6FF)
ShowStatusToast("Entering product details in Oracle", "process")

Send productNumber
Sleep sleepDelay

Loop 4 {
    Send "{Tab}"
    Sleep sleepDelay
}

Send quantity
Sleep sleepDelay
Send "{Tab}"
Sleep sleepDelay
Send "11800"
Sleep sleepDelay
Send "{Tab}"
Sleep sleepDelay
Send selectedCode
Sleep sleepDelay

Loop 2 {
    Send "{Tab}"
    Sleep sleepDelay
}

Send("!o")
Sleep sleepDelay

Loop 4 {
    Send "{Tab}"
    Sleep sleepDelay
}

; Navigation sequence
Loop 5 {
    Send "{Enter}"
    Sleep sleepDelay
    Send "{Down}"
    Sleep sleepDelay
}

Send "{Enter}"
```

}

ExtractItemData() {
global sleepDelay, Field1Content, Field2Content, Field3Content

```
Send "{Tab}"
Sleep sleepDelay
Send "{Right 2}"
Sleep sleepDelay

; Extract Field 1
A_Clipboard := ""
Send("^c")
ClipWait(1)

if (A_ClipBoard = "") {
    ForceHideToast()
    MsgBox("The item could not be located in the store.", "Item Missing", 48)
    UpdateStatus("💥 The item could not be located in the store.", 0xFF4444)
    ShowStatusToast("Item not found in store", "error")
    myGui.Show("w380 h405")
    return
} else {
    Field1Content := A_Clipboard
}

Sleep sleepDelay

; Extract Field 2
Send "{Right}"
Sleep sleepDelay
A_Clipboard := ""
Send("^c")
ClipWait(1)

if (A_ClipBoard = "") {
    ForceHideToast()
    MsgBox("The item could not be located in the store.", "Item Missing", 48)
    UpdateStatus("💥 The item could not be located in the store.", 0xFF4444)
    ShowStatusToast("Item not found in store", "error")
    myGui.Show("w380 h405")
    return
} else {
    Field2Content := A_Clipboard
}

Sleep sleepDelay

; Extract Field 3
Send "{Right}"
Sleep sleepDelay
A_Clipboard := ""
Send("^c")
ClipWait(1)

if (A_ClipBoard = "") {
    ForceHideToast()
    MsgBox("The item could not be located in the store.", "Item Missing", 48)
    UpdateStatus("💥 The item could not be located in the store.", 0xFF4444)
    ShowStatusToast("Item not found in store", "error")
    myGui.Show("w380 h405")
    return
} else {
    Field3Content := A_Clipboard
}
```

}

ValidateQuantity(quantity, requestedQty) {
global sleepDelay, AvailableQty

```
UpdateStatus("🔍 Checking available quantity…", 0x00A6FF)
ShowStatusToast("Checking available quantity in stock", "process")

; Navigate to quantity field
Send "{Right 3}"
Sleep sleepDelay

; Copy the available quantity
A_Clipboard := ""
Send("^c")
ClipWait(1)

if (A_ClipBoard = "") {
    ForceHideToast()
    MsgBox("Unable to retrieve the available quantity.", "Quantity Missing", 48)
    UpdateStatus("💥 Unable to retrieve the available quantity.", 0xFF4444)
    ShowStatusToast("Unable to retrieve available quantity", "error")
    myGui.Show("w380 h405")
    return quantity
} else {
    AvailableQty := A_Clipboard
}

; Convert for comparison
availableQtyNum := Integer(AvailableQty)
requestedQtyNum := Integer(quantity)
isLastOne := false

; Check quantity logic
if (availableQtyNum < requestedQtyNum) {
    result := MsgBox("The requested quantity of (" . quantity . ") exceeds the available quantity on hand, which is (" . AvailableQty . ").`n`nWould you like to proceed with the available quantity of (" . AvailableQty . ") instead?", "Quantity Check", 4 + 48)

    if (result = "No") {
        UpdateStatus("❌ Process cancelled - insufficient quantity in store", 0xFF4444)
        ShowStatusToast("Process cancelled - insufficient stock", "error")
        myGui.Show("w380 h405")
        return quantity
    } else {
        quantity := AvailableQty
        isLastOne := true
        UpdateStatus("✅ Continuing with available quantity: " . AvailableQty . " (Auto-detected as last item)", 0x00A6FF)
        ShowStatusToast("Using available qty: " . AvailableQty . " (Last item)", "warning")
    }
} else if (availableQtyNum = requestedQtyNum) {
    isLastOne := true
    UpdateStatus("✅ Available quantity matches requested quantity - Auto-detected as last item", 0x00A6FF)
    ShowStatusToast("Available quantity matches requested quantity - Auto-detected as last item", "success")
}

; Show copy button if it's the last item
global btnCopy
if isLastOne {
    btnCopy.Visible := true
} else {
    btnCopy.Visible := false
}

return quantity
```

}

ProcessPhase5(quantity) {
global sleepDelay, Field1Content, currentLines

```
A_Clipboard := Field1Content
Sleep sleepDelay

Send("^{F4}")
Sleep sleepDelay
Send("^v")
Sleep sleepDelay

Loop 3 {
    Send "{Tab}"
    Sleep sleepDelay
}

Send "Damaged"
Sleep sleepDelay
Send "{Tab}"
Sleep sleepDelay

; Determine if this is the last item based on button visibility
isLastOne := btnCopy.Visible
locationMessage := GetLocationMessage(isLastOne)
Send locationMessage
Sleep sleepDelay

Loop 7 {
    Send "{Tab}"
    Sleep sleepDelay
}

Send quantity

; Final status update
lineType := radioDry.Value ? "Dry" : "Wet"
selectedCode := ""
selectedName := categoryDropdown.Text

for item in currentLines {
    if (item.Name = selectedName) {
        selectedCode := item.Code
        break
    }
}

finalMessage := "🎉 Process completed! Product: " . inputProduct.Text . " | " . lineType . " Line: " . selectedCode
if (isLastOne) {
    finalMessage .= " | Auto-detected as LAST ITEM"
}

UpdateStatus(finalMessage, 0x00FF88)
ShowStatusToast(finalMessage, "success")
```

}

; ========================================
; INITIALIZATION
; ========================================

; Initialize the application
CreateMainGui()
Editor is loading...
Leave a Comment