Untitled

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

; Global sleep variable - adjust this value to change all sleep delays
global sleepDelay := 200

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

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

; Reset counter after timeout
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  ; Your current running file

```
; Check if master file exists
if !FileExist(masterFile)
    return  ; No master file found, continue normally 

; Get file modification times
masterTime := FileGetTime(masterFile, "M")  ; Modified time
currentTime := FileGetTime(currentFile, "M")

; If master file is newer
if (masterTime > currentTime) {
    ; Show update message
    result := MsgBox("New version available! Update now?", "Update Available", "YesNo")
    if (result = "Yes") {
        ; Copy new version
        FileCopy(masterFile, currentFile, 1)  ; 1 = overwrite
        ; Restart program
        Run(A_ScriptFullPath)
        ExitApp
    }
}
```

}

; TOAST NOTIFICATION
global toastGui := unset
global toastVisible := false

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

```
; Hide existing toast if visible
if (toastVisible && IsSet(toastGui)) {
    HideToast()
}

; Get PRIMARY screen dimensions - works for single or multiple monitors
primaryMonitor := MonitorGetPrimary()
MonitorGet(primaryMonitor, &MonLeft, &MonTop, &MonRight, &MonBottom)

; Get taskbar position to position toast properly near clock
; Assume taskbar is at bottom (most common), clock area is bottom-right
taskbarHeight := 40  ; Standard taskbar height

; Modern white 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
}

; Create modern toast GUI with white theme
toastGui := Gui("+AlwaysOnTop +ToolWindow -MaximizeBox -MinimizeBox -Caption +LastFound", "Toast")
toastGui.BackColor := bgColor
toastGui.MarginX := 0
toastGui.MarginY := 0

; Calculate positioning on PRIMARY monitor (above taskbar, right side near clock)
toastWidth := 350
toastHeight := 90
xPos := MonRight - toastWidth - 15
yPos := MonBottom - toastHeight - taskbarHeight - 15  ; Above taskbar

; Create white background with subtle shadow effect
bgMain := toastGui.AddText("x2 y2 w" . (toastWidth-4) . " h" . (toastHeight-4) . " +Background", "")
bgMain.BackColor := bgColor

; Left accent border for modern look
accentBorder := toastGui.AddText("x0 y0 w4 h" . toastHeight . " +Background", "")
accentBorder.BackColor := borderColor

; Add modern icon with colored background circle - back to original design
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")  ; Use emoji font for better icon rendering
toastIcon.BackColor := borderColor
toastIcon.TextColor := 0xFFFFFF

; Add title with dark text on white background
toastTitle := toastGui.AddText("x70 y18 w250 h22", title)
toastTitle.SetFont("s11 w600", "Segoe UI Variable")
toastTitle.BackColor := bgColor
toastTitle.TextColor := textColor

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

; Add modern close button
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())

; Show toast on PRIMARY monitor only
toastVisible := true

; Start from right side off-screen of PRIMARY monitor
startX := MonRight + 50
toastGui.Show("x" . startX . " y" . yPos . " w" . toastWidth . " h" . toastHeight . " NoActivate")

; Smooth slide-in animation with easing
AnimateToastModern(toastGui, startX, xPos, yPos, 300)

; Auto-hide after duration using SetTimer with proper cleanup
SetTimer(HideToast, -duration)
```

}

AnimateToastModern(gui, startX, endX, yPos, duration) {
steps := 20  ; More steps for smoother animation
stepDelay := duration // steps

```
; Easing function for smooth animation (ease-out)
Loop steps {
    progress := A_Index / steps
    ; Ease-out cubic function
    easedProgress := 1 - ((1 - progress) ** 3)
    currentX := startX + (endX - startX) * easedProgress
    
    try {
        gui.Move(Round(currentX), yPos)
    }
    Sleep(stepDelay)
}
; Final position
try {
    gui.Move(endX, yPos)
}
```

}

HideToast() {
global toastGui, toastVisible

```
if (toastVisible && IsSet(toastGui)) {
    toastVisible := false
    try {
        ; Destroy the GUI completely
        toastGui.Destroy()
    } catch {
        ; If destroy fails, try close
        try {
            toastGui.Close()
        } catch {
            ; Ignore any errors
        }
    }
    ; Reset the global variable
    toastGui := unset
}
```

}

; Add function to force hide all toasts (useful when MsgBox appears)
ForceHideToast() {
global toastGui, toastVisible

```
; Stop any existing timers for HideToast
SetTimer(HideToast, 0)

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

}

; Enhanced status update function that shows modern toasts
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”)
}
}

; Global variables - declare at the top
global Field1Content := “”
global Field2Content := “”
global Field3Content := “”
global AvailableQty := “”

^o:: {
ShowGui()
}

ShowGui() {
global myGui
if !IsSet(myGui) {
myGui := Gui(”  -MaximizeBox”, “Oracle Support App”)
myGui.BackColor := 0xF5F5F5
myGui.MarginX := 0
myGui.MarginY := 0
}

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

}

myGui := Gui(”  -MaximizeBox”, “Oracle Support App”)
myGui.BackColor := 0xF5F5F5
myGui.MarginX := 0
myGui.MarginY := 0

; Modern font setup
myGui.SetFont(“s10”, “Segoe UI Variable”)

; —– Header with gradient effect —–
headerBg := myGui.AddText(“x0 y0 w400 h70 +Background”, “”)
headerBg.BackColor := 0x2D2D30

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

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

; —– Main Content Area —–
contentBg := myGui.AddText(“x20 y90 w380 h210 +Background”, “”)
contentBg.BackColor := 0x252526

; Location Selection Section with question mark tooltip
locationLabel := myGui.AddText(“x40 y85 w270”, “Source Warehouse”)
locationLabel.SetFont(“s10 Bold”, “Segoe UI Variable”)
locationLabel.BackColor := 0x252526
locationLabel.TextColor := 0xFFFFFF

; Location dropdown with corrected tooltip
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”)

; Product Number Section with auto-formatting
productLabel := myGui.AddText(“x40 y160 w150”, “Product Number”)
productLabel.SetFont(“s10 Bold”, “Segoe UI Variable”)
productLabel.BackColor := 0x252526
productLabel.TextColor := 0xFFFFFF

; Create a container for the product input
productContainer := myGui.AddText(“x40 y180 w150 h35 +Background”, “”)
productContainer.BackColor := 0x3C3C3C

; Input with normal left-to-right typing behavior
inputProduct := myGui.AddEdit(“x40 y185 w140 h25 +Background -Border +Number”)
inputProduct.BackColor := 0x3C3C3C
inputProduct.TextColor := 0xFFFFFF
inputProduct.SetFont(“s10”, “Segoe UI Variable”)

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

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

; Line Type Selection Section with Radio Buttons (moved up and repositioned)
lineTypeLabel := myGui.AddText(“x40 y240 w140”, “Line Type”)
lineTypeLabel.SetFont(“s10 Bold”, “Segoe UI Variable”)
lineTypeLabel.BackColor := 0x252526
lineTypeLabel.TextColor := 0xFFFFFF

; Radio buttons for line type selection (side by side)
radioDry := myGui.AddRadio(“x40 y270 w65 vRadioDry”, “Dry”)
radioDry.BackColor := 0x252526
radioDry.TextColor := 0xFFFFFF
radioDry.SetFont(“s9”, “Segoe UI Variable”)
radioDry.Value := 1  ; Default selection
radioDry.OnEvent(“Click”, UpdateLineDropdown)

radioWet := myGui.AddRadio(“x115 y270 w65 vRadioWet”, “Wet”)
radioWet.BackColor := 0x252526
radioWet.TextColor := 0xFFFFFF
radioWet.SetFont(“s9”, “Segoe UI Variable”)
radioWet.OnEvent(“Click”, UpdateLineDropdown)

; Line Selection Section (positioned next to Line Type)
categoryLabel := myGui.AddText(“x200 y240 w140”, “Line Selection”)
categoryLabel.SetFont(“s10 Bold”, “Segoe UI Variable”)
categoryLabel.BackColor := 0x252526
categoryLabel.TextColor := 0xFFFFFF

; Create complete category arrays
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”}
]

; Create dropdown with initial dry lines
global currentLines := dryLines
categoryDisplayNames := []
for item in currentLines
categoryDisplayNames.Push(item.Name)

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

; —– Action Buttons with Modern Styling —–
btnStart := myGui.AddButton(“Default x40 y320 w140 h40 +Background”, “▶ START”)
btnStart.OnEvent(“Click”, StartScript)
btnStart.SetFont(“s10 Bold”, “Segoe UI Variable”)
btnStart.BackColor := 0x0078D4
btnStart.TextColor := 0xFFFFFF

btnClear := myGui.AddButton(“x200 y320 w140 h40 +Background”, “🔄 RESET ALL”)
btnClear.OnEvent(“Click”, ClearAllFields)
btnClear.SetFont(“s10 Bold”, “Segoe UI Variable”)
btnClear.BackColor := 0x484848
btnClear.TextColor := 0xFFFFFF

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")
```

}

global btnCopy := unset
btnCopy := myGui.AddText(“x340 y325 w35 h30 Center”, “✉”)
btnCopy.SetFont(“s15”, “Segoe UI Variable”)
btnCopy.OnEvent(“Click”, CopyToClipboard)
btnCopy.BackColor := 0x2D2D30
btnCopy.TextColor := 0xCCCCCC
btnCopy.Visible := false

; —– Status Bar with Modern Styling —–
statusBg := myGui.AddText(“x0 y370 w400 h35 +Background”, “”)
statusBg.BackColor := 0x2D2D30

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

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

; Set window size and show - compact layout
myGui.Show(“w380 h405”)

; Add input validation and formatting with improved number handling
inputProduct.OnEvent(“Change”, FormatProductNumber)
inputQty.OnEvent(“Change”, ValidateInputs)
categoryDropdown.OnEvent(“Change”, ValidateInputs)

; Global variable to track cursor position
lastProductLength := 0

; Enhanced tooltip system for mouse hover on question mark
SetTimer(CheckMousePosition, 50)

CheckMousePosition() {
static lastControl := “”
; Get mouse position
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 := ""
    }
}
```

}

; Functions
FormatProductNumber(*) {
currentText := inputProduct.Text

```
; Remove any non-numeric characters
cleanText := RegExReplace(currentText, "[^\d]", "")

; Limit to 9 digits max - if longer, keep only first 9 digits
if (StrLen(cleanText) > 9) {
    cleanText := SubStr(cleanText, 1, 9)
    ; Set the text to the truncated version
    inputProduct.Text := cleanText
    ; Move cursor to end
    inputProduct.Focus()
    Send("{End}")
} else if (cleanText != currentText) {
    ; Only update if the cleaned text is different from current text
    inputProduct.Text := cleanText
}

ValidateInputs()
```

}

GetLocationCode() {
; Function to get the appropriate code based on selected location
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) {
; Function to get the appropriate message based on selected location and last item status
selectedLocation := locationDropdown.Text
if (selectedLocation = “Warrior Close”) {
if (isLastOne)
return “Taken from Warrior Store - 0 Stock”
else
return “Taken from Warrior Store”
} else {
; For Hamble SP1, Hamble SP4, and Speedwell
if (isLastOne)
return “Please deliver to Warrior Close - 0 Stock”
else
return “Please deliver to Warrior Close”
}
}

UpdateLineDropdown(*) {
; Determine which radio button is selected and update dropdown accordingly
if (radioDry.Value) {
currentLines := dryLines
} else {
currentLines := wetLines
}

```
; Clear and repopulate dropdown
categoryDisplayNames := []
for item in currentLines
    categoryDisplayNames.Push(item.Name)

; Store current selection text if any
currentSelection := categoryDropdown.Text

; Update dropdown options
global currentLines
categoryDropdown.Delete()
categoryDropdown.Add(categoryDisplayNames)

; Try to maintain selection if it exists in new list, otherwise select first item
selectionFound := false
Loop categoryDisplayNames.Length {
    if (categoryDisplayNames[A_Index] = currentSelection) {
        categoryDropdown.Choose(A_Index)
        selectionFound := true
        break
    }
}

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

ValidateInputs()
```

}

ValidateInputs(*) {
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
}
```

}

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

ClearAllFields(*) {
inputProduct.Text := “”
inputQty.Value := 1
locationDropdown.Choose(1)  ; Reset to Warrior Close
radioDry.Value := 1  ; Reset to dry lines
radioWet.Value := 0
UpdateLineDropdown()  ; Reset dropdown to dry lines
categoryDropdown.Choose(1)  ; Reset dropdown to first option
btnCopy.Visible := false
AvailableQty := “”  ; Clear available quantity

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

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

}

StartScript(*) {
global sleepDelay  ; Use the global sleep variable

```
; Build full product number with 1000 prefix
productSuffix := inputProduct.Text
if (productSuffix == "") {
    UpdateStatus("❌ Product number required", 0xFF4444)
    ShowStatusToast("Product number is required", "error")
    return
}

fullProductNumber := productSuffix

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

; Update status with processing animation
UpdateStatus("🔄 Initializing process…", 0x00A6FF)
ShowStatusToast("Initializing Oracle process…", "process")
btnStart.Enabled := true
btnClear.Enabled := true
btnStart.BackColor := 0x666666
btnClear.BackColor := 0x333333

; Get values
productNumber := fullProductNumber
quantity := inputQty.Text
requestedQty := Integer(quantity)  ; Store the original requested quantity
selectedName := categoryDropdown.Text
selectedCode := ""
for item in currentLines {
    if (item.Name = selectedName) {
        selectedCode := item.Code
        break
    }
}

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
}

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

    myGui.Minimize()
    ; ****** Starting FIRST PART ******
    SetKeyDelay 40, 40

    Sleep sleepDelay
    Send "{Tab}"
    Sleep sleepDelay

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

    if (A_ClipBoard = "" || !RegExMatch(A_ClipBoard, "\w"))  {
        ForceHideToast()  ; Hide any existing toasts before showing MsgBox
        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 := "" ; Clear the 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

    ; Use the appropriate location code
    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}"

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

    ; ****** Start of Second Part ******
    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}"

    Send "{Tab}"
    Sleep sleepDelay
    Send "{Right 2}"
    Sleep sleepDelay
    A_Clipboard := "" ; Clear the clipboard
    Send("^c")
    ClipWait(1)

    if (A_ClipBoard = "") {
        ForceHideToast()  ; Hide any existing toasts before showing MsgBox
        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 {
        global Field1Content
        Field1Content := A_Clipboard ; Store the content of the first field
    }

    Sleep sleepDelay

    ; Move to the next field and copy Field 2
    Send "{Right}" ; Move to the next field
    Sleep sleepDelay
    A_Clipboard := "" ; Clear the clipboard again
    Send("^c")
    ClipWait(1)

    if (A_ClipBoard = "") {
        ForceHideToast()  ; Hide any existing toasts before showing MsgBox
        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 {
        global Field2Content
        Field2Content := A_Clipboard ; Store the content of the second field
    }

    Sleep sleepDelay

    ; Move to the next field and copy Field 3
    Send "{Right}" ; Move to the next field
    Sleep sleepDelay
    A_Clipboard := "" ; Clear the clipboard
    Send("^c")
    ClipWait(1)

    if (A_ClipBoard = "") {
        ForceHideToast()  ; Hide any existing toasts before showing MsgBox
        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 {
        global Field3Content
        Field3Content := A_Clipboard ; Store the content of the third field
    }

    ; ***** qty check *****
    UpdateStatus("🔍 Checking available quantity…", 0x00A6FF)
    ShowStatusToast("Checking available quantity in stock", "process")

    ; Navigate to quantity field (3 additional tabs as requested)
    Send "{Right 3}"
    Sleep sleepDelay

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

    if (A_ClipBoard = "") {
        ForceHideToast()  ; Hide any existing toasts before showing MsgBox
        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
    } else {
        global AvailableQty
        AvailableQty := A_Clipboard ; Store the available quantity
    }

    ; Convert strings to numbers for comparison
    availableQtyNum := Integer(AvailableQty)
    requestedQtyNum := Integer(quantity)

    ; Variable to track if this is the last item (auto-detected)
    isLastOne := false

    ; Check if available quantity is less than requested quantity
    if (availableQtyNum < requestedQtyNum) {
        ; Show message asking if user wants to continue with available quantity

        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") {
            ; User chose not to continue
            UpdateStatus("❌ Process cancelled - insufficient quantity in store", 0xFF4444)
            ShowStatusToast("Process cancelled - insufficient stock", "error")
            myGui.Show("w380 h405")
            return
        } else {
            ; User chose to continue with available quantity
            quantity := AvailableQty  ; Update the quantity to use available quantity
            isLastOne := true  ; Auto-detect as last item
            UpdateStatus("✅ Continuing with available quantity: " . AvailableQty . " (Auto-detected as last item)", 0x00A6FF)
            ShowStatusToast("Using available qty: " . AvailableQty . " (Last item)", "warning")
        }
    } else if (availableQtyNum = requestedQtyNum) {
        ; Auto-detect when available quantity equals requested quantity
        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")
    }

    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

    ; Use the appropriate message based on location and last item status
    locationMessage := GetLocationMessage(isLastOne)
    Send locationMessage
    Sleep sleepDelay

    Loop 7 {
        Send "{Tab}"
        Sleep sleepDelay
    }
    ; Paste the quantity (either original or available quantity)
    Send quantity

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

    ; Restore GUI and update status
    lineType := radioDry.Value ? "Dry" : "Wet"
    finalMessage := "🎉 Process completed! Product: " . productNumber . " | " . lineType . " Line: " . selectedCode
    if (availableQtyNum <= requestedQtyNum && isLastOne) {
        finalMessage .= " | Auto-detected as LAST ITEM"
    }
    UpdateStatus(finalMessage, 0x00FF88)

    ; Show success toast with details
    ShowStatusToast(finalMessage, "success")

} 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
```

}
Editor is loading...
Leave a Comment