Untitled

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

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

^o:: {
ShowIntroVan()
ShowGui()
}

ShowIntroVan() {
introGui := Gui(”+AlwaysOnTop -Caption +ToolWindow”, “Moving Van”)
introGui.BackColor := “White”
introGui.SetFont(“s36”, “Segoe UI Emoji”)

; Create the van icon initially off-screen to the left
vanIcon := introGui.AddText(“x0 y40 w80 h80 vVanIcon”, “🚐”)
introGui.Show(“w400 h150”)

; Animate van: move from left to right
Loop 31 {
xPos := 300 - (A_Index * 10)
introGui[“VanIcon”].Move(xPos, 40)
Sleep 40
}

Sleep 200  ; pause for a moment at the end
introGui.Destroy()
}

ShowGui() {
global myGui
if !IsSet(myGui) {
myGui := Gui(” +Resize -MaximizeBox”, “A-TEAM | Order System”)
myGui.BackColor := 0xF5F5F5
myGui.MarginX := 0
myGui.MarginY := 0
}
myGui.Show(“w380 h405”)
}

myGui := Gui(” +Resize -MaximizeBox”, “A-TEAM | Order System”)
myGui.BackColor := 0xF5F5F5
myGui.MarginX := 0
myGui.MarginY := 0
ShowIntroVan()

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

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

headerIcon := myGui.AddText(“x30 y20 w40 h40 +Center”, “🚐”)
headerIcon.SetFont(“s24”)
headerIcon.BackColor := 0x2D2D30
headerIcon.TextColor := 0x00A6FF

headerTitle := myGui.AddText(“x80 y20 w300 h25”, “A-TEAM | Order System”)
headerTitle.SetFont(“s16 Bold”, “Segoe UI Variable”)
headerTitle.BackColor := 0x2D2D30
headerTitle.TextColor := 0xFFFFFF

global headerSubtitle := myGui.AddText(“x80 y45 w300 h20”, “Warrior Close”)
headerSubtitle.SetFont(“s9”, “Segoe UI Variable”)
headerSubtitle.BackColor := 0x2D2D30
headerSubtitle.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 w40 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 y265 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 y265 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”)

; Custom toggle for last item (repositioned) - REMOVED THE CHECKBOX SINCE WE’RE AUTO-DETECTING
; checkboxLastOne := myGui.AddCheckbox(“x260 y190 w200”, “Mark as Last”)
; checkboxLastOne.BackColor := 0x252526
; checkboxLastOne.TextColor := 0xFFFFFF
; checkboxLastOne.SetFont(“s9”, “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`nCould you please check to see whether this has been reordered and provide us with an approximate lead time?`n`nMany Thanks”

A_Clipboard := “”
Sleep 100
A_Clipboard := myMessage
}

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(, , , ¤tControl, 2)

if (currentControl == locationLabel.Hwnd) {
if (lastControl != currentControl) {
ToolTip(“Enter 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
; Removed checkboxLastOne.Value := 0 since checkbox is removed
locationDropdown.Choose(1)  ; Reset to Warrior Close
headerSubtitle.Text := “Warrior Close”  ; Reset header subtitle
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
}

StartScript(*)
{
; Build full product number with 1000 prefix
productSuffix := inputProduct.Text
if (productSuffix == “”) {
UpdateStatus(“❌ Product number required”, 0xFF4444)
return
}

fullProductNumber := productSuffix

if (inputQty.Text == “” || !IsNumber(inputQty.Text) || inputQty.Text <= 0) {
UpdateStatus(“❌ Valid quantity required”, 0xFF4444)
return
}

; Update status with processing animation
UpdateStatus(“🔄 Initializing process…”, 0x00A6FF)
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 {
ShowTopMessage(”`n Oracle is not running. `n `n Please open 'Move Order' page `n”)
UpdateStatus(“💥 Oracle is not running - Please open ‘Move Order’ page.”, 0xFF4444)
return
}

ShowTopMessage(text) {
msgGui :=Gui(”+AlwaysOnTop “)
msgGui.BackColor := “White”
msgGui.SetFont(“s10”)
msgGui.AddText(“w200 h80 Center” , text)
msgGui.Show(“autosize xCenter yCenter”)
SetTimer(() => msgGui.Destroy(), -2500)
}

try {
selectedLocation := locationDropdown.Text
UpdateStatus(“🔄 Processing “ . selectedLocation . “ details…”, 0x00A6FF)

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

Sleep 200
Send “{Tab}”
Sleep 200

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

if (A_ClipBoard = “” || !RegExMatch(A_ClipBoard, “\w”))  {

MsgBox(” ❌Please open Oracle in `n Move Orders Page”)
UpdateStatus(“💥 Please open Oracle in Move Orders Page”, 0xFF4444)
return
}
A_Clipboard := “” ; Clear the clipboard

Sleep 200
Send “{Tab}”
Sleep 200

Send “{Tab}”
Sleep 200

Send “Project Move Issue”
Sleep 200

Send “{Tab}”
Sleep 200

Send “CVI UK Warrior Close”
Sleep 200

Send “{Tab}”
Sleep 200

; Use the appropriate location code
locationCode := GetLocationCode()
Send locationCode
Sleep 200

Send “{Tab}”
Sleep 200
Send “{Tab}”
Sleep 200
Send “{Tab}”
Sleep 200

Send “UKM - Dailies”
Sleep 200

Send “{Tab}”
Sleep 200
Send “{Enter}”

UpdateStatus(“⚡ Processing order details…”, 0x00A6FF)

; ****** Start of Second Part ******
Send productNumber
Sleep 200
Send “{Tab 4}”
Sleep 200
Send quantity
Sleep 200
Send “{Tab}”
Sleep 200
Send “11800”
Sleep 200
Send “{Tab}”
Sleep 200
Send selectedCode  
Sleep 200
Send “{Tab 2}”
Sleep 200
Send(”!o”)
Sleep 200
Send “{Tab 4}”
Sleep 200

; Navigation sequence
Loop 6 {
Send “{Enter}”
Sleep 200
Send “{Down}”
Sleep 200
}

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

if (A_ClipBoard = “”) {
MsgBox(“💥Item was not found in store.”, “” , 48)
UpdateStatus(“💥 Item was not found in store.”, 0xFF4444)
myGui.Show(“w380 h405”)
return
} else {
global Field1Content
Field1Content := A_Clipboard ; Store the content of the first field
}

Sleep 200

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

if (A_ClipBoard = “”) {
MsgBox(“💥Item was not found in store for Field 2.”, “” , 48)
UpdateStatus(“💥 Item was not found in store for Field 2.”, 0xFF4444)
myGui.Show(“w380 h405”)
return
} else {
global Field2Content
Field2Content := A_Clipboard ; Store the content of the second field
}

Sleep 200

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

if (A_ClipBoard = “”) {
MsgBox(“💥Item was not found in store for Field 3.”, “” , 48)
UpdateStatus(“💥 Item was not found in store for Field 3.”, 0xFF4444)
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)

; Navigate to quantity field (3 additional tabs as requested)
Send “{Right 3}”
Sleep 200

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

if (A_ClipBoard = “”) {
MsgBox(“💥Could not read available quantity.”, “” , 48)
UpdateStatus(“💥 Could not read available quantity.”, 0xFF4444)
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(“⚠️ Requested quantity (” . quantity . “) is more than Available quantity on-hand (” . AvailableQty . “)  .`n`nDo you want to continue with the available quantity on-hand?”, “Quantity Check”, 4 + 48)

if (result = “No”) {
; User chose not to continue
UpdateStatus(“❌ Process cancelled - insufficient quantity in store”, 0xFF4444)
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)
}
} else if (availableQtyNum = requestedQtyNum) {
; MAIN CHANGE: Auto-detect when available quantity equals requested quantity
isLastOne := true
UpdateStatus(“✅ Available quantity matches requested quantity - Auto-detected as last item”, 0x00A6FF)
}

A_Clipboard := Field1Content ;

Sleep 200

Send(”^{F4}”)
Sleep 200
Send(”^v”)
Sleep 200
Send “{Tab 3}”
Sleep 200
Send “Damaged”
Sleep 200
Send “{Tab}”
Sleep 200

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

Send “{Tab 7}”
Sleep 200
; 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)

} catch Error as e {
UpdateStatus(“💥 Error occurred during processing”, 0xFF4444)
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