Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Want to cretae a script for FIFO

vik

New Coder
I have a database with lot No and quantity as below. I have to use first in first out concept (FIFO) to issue these materials

LOTNOQuantity
12
24
313
If requested quantity is 1 the i have to decrease quantity of lotNo 1 by 1 if the requested quantity is more than the quantity available in that lot i have to remove from lotNo 1 then 2 till i get the required quanty.

eg if requested quantity is 8, i have to remove 2 from lot 1 4 from lot 2 and remining 4 from lot 3.

I'm using classic asp as programming language with VBScript and JavaScript
 
You can use a loop to check the requested quantity against the available quantity in each lot until the requested quantity is fulfilled. Here's an example of a possible implementation in VBScript:
JavaScript:
Dim requestQty
requestQty = 8

Dim lots(3)
lots(0) = Array(1,2)
lots(1) = Array(2,4)
lots(2) = Array(3,13)

Dim i
For i = 0 To UBound(lots)
    If requestQty > lots(i)(1) Then
        requestQty = requestQty - lots(i)(1)
        lots(i)(1) = 0
    Else
        lots(i)(1) = lots(i)(1) - requestQty
        requestQty = 0
    End If
    If requestQty = 0 Then
        Exit For
    End If
Next

' Display the result
Response.Write "The remaining quantity in each lot after fulfilling the request:<br>"
For i = 0 To UBound(lots)
    Response.Write "Lot No. " & lots(i)(0) & ": " & lots(i)(1) & "<br>"
Next
 
You can use a loop to check the requested quantity against the available quantity in each lot until the requested quantity is fulfilled. Here's an example of a possible implementation in VBScript:
JavaScript:
Dim requestQty
requestQty = 8

Dim lots(3)
lots(0) = Array(1,2)
lots(1) = Array(2,4)
lots(2) = Array(3,13)

Dim i
For i = 0 To UBound(lots)
    If requestQty > lots(i)(1) Then
        requestQty = requestQty - lots(i)(1)
        lots(i)(1) = 0
    Else
        lots(i)(1) = lots(i)(1) - requestQty
        requestQty = 0
    End If
    If requestQty = 0 Then
        Exit For
    End If
Next

' Display the result
Response.Write "The remaining quantity in each lot after fulfilling the request:<br>"
For i = 0 To UBound(lots)
    Response.Write "Lot No. " & lots(i)(0) & ": " & lots(i)(1) & "<br>"
Next
Hi Thanks for the code its working but the lot No is dynamic and will keep on increasing in the database as new lots will be purchased.
 

Buy us a coffee!

Back
Top Bottom