Q:

Function to allocate a changing proportion

Raw material, steel plate, is purchased in rectangular slabs
Parts manufactured are circular cuts from the steel plate however part requirements and costing are based on the square, part diameter = square Length and Width
The total amount of a plate that is consumed in production is proportionally allocated to the jobs/parts that are produced
The difference between the SQIN of the circle & the square as well as efficiencies/inefficiencies in the nesting of a plate impact the allocation
Inventory is issued based on units of measurement, length and width. 
Our ERP system dose not proportionally allocate inventory effectively.   A manual calculation is used to “daisy chain” allocate inventory.   The full plate is allocated to a job, the unneeded portion is allocated from the job back to inventory, and this process repeats itself for each job/item associated with a steel plate. 
This process is inefficient and prone to error.   I am trying to come up with the logic needed to either automate this process or at least automate the calculations to reduce errors.   The problem that I am running into is that my allocations skew the amounts issued towards the first jobs calculated.   Basically as the percentage of the plate that is returned to inventory decreases after each job is calculated, the percentage of inventory allocated to the next job also decreases
import pandas as pd

# Dimensions of a steel plate and the portions that will consumed in 
# production and returned to inventory
plateLength = 480
plateWidth = 96
plateSQIN = plateLength * plateWidth

plateReturnedLength = 60
plateReturnedWidth = 45
plateReturnedSQIN = plateReturnedLength * plateReturnedWidth

consumedLength = plateLength - plateReturnedLength
consumedWidth = plateWidth - plateReturnedWidth
consumedSQIN = plateSQIN - plateReturnedSQIN

# DataFrame for the job details and material requirements that will be 
# needed for production
data = {'JOB':[128576,128518,128577,128667,128630],
        'Length':[90,90,90,84,36],
        'Width':[90,90,90,84,36],
        'QTY':[1,2,1,1,2]}
layout = pd. DataFrame(data=data)

# Adding calculated values to the DataFrame
layout['REQUIRED'] = (layout['Length'] * layout['Width'])*layout['QTY']
totalRequired = layout['REQUIRED'].sum()

layout['CALC_USE'] = (layout['REQUIRED']/totalRequired) * consumedSQIN
totalUsed = layout['CALC_USE'].sum()

layout['CALC_%'] = layout['REQUIRED'] / totalRequired
totalAllocatedPcnt = layout['CALC_%'].sum()

# Creating DataFrame columns that will be populated by function
layout['I_L'] = None # issue length
layout['I_W'] = None # issue width
layout['R_L'] = None # return length
layout['R_W'] = None # return width
layout['issued'] = None # SQIN issued
layout['issue%'] = None # %of total SQIN issued

# Function for calculating how much material to issue to each job and 
# how much to return to inventory

def issue(data):

    issueLength = plateLength
    issueWidth = plateWidth

    for index, row in layout.iterrows():

        pcnt = data.loc[index,'CALC_%']

        returnLength = issueLength - consumedLength  * pcnt
        returnWidth = issueWidth - consumedWidth  * pcnt

        data.at[index,'I_L'] = round(issueLength,2)
        data.at[index,'I_W'] = round(issueWidth,2)        
        data.at[index,'R_L'] = round(returnLength,2)
        data.at[index,'R_W'] = round(returnWidth,2)

        issueLength = returnLength
        issueWidth = returnWidth

        data[['I_L','I_W','R_L','R_W']] = 
        data[['I_L','I_W','R_L','R_W']].astype(float).round(0)

        data['issued'] = (data['I_L'] * data['I_W']) - 
                         (data['R_L'] * data['R_W'])

    issueTotal = data['issued'].sum()

    data['issue%'] = data['issued']/issueTotal

    return data

# call function and view results
issue(layout)

I need to be able to calculate a length and a width to be issued and to be returned for each job that will generate a percentage issued that matches the calculated allocation percentage based on the sum of total requirements. 
Any sugestions on how to achive this will be greatly appreciated
Thanks all
P.S.
I have not got the formating of the code to work as a pure copy and paste.   Line 71 and 73 will generate an error but it is the spacing between single lines of code that were broken into two lines in order two fit in the code blocks

A:

Just needed some help form my old friend algebra, thanks all, I got it figured out. 
Changed the function as follows. 
L * W = SQIN
L = SQIN / W
Return width can be calculated by reducing the total reduction in plate width by the line % at each itteration. 
The SQIN returned can be calculated by reducing the issued SQIN by the required SQIN at each itteration. 
For each line the return value for Length = Returned SQIN / Returned Width
def issue(data):

    issueLength = plateLength
    issueWidth = plateWidth

    for index, row in layout.iterrows():

        pcnt = data.loc[index,'CALC_%']       
        reqSQIN = pcnt * (consumedSQIN)   
        issueSQIN = issueLength * issueWidth
        returnSQIN = issueSQIN - reqSQIN

        if returnSQIN <= 0:
            returnLength = 0
            returnWidth = 0
        else:
            returnWidth = issueWidth - (consumedWidth * pcnt)
            returnLength = returnSQIN/returnWidth

        data.at[index,'I_L'] = round(issueLength,2)
        data.at[index,'I_W'] = round(issueWidth,2)        
        data.at[index,'R_L'] = round(returnLength,2)
        data.at[index,'R_W'] = round(returnWidth,2)

        issueLength = returnLength
        issueWidth = returnWidth

    data[['I_L','I_W','R_L','R_W']] = 
    data[['I_L','I_W','R_L','R_W']].astype(float).round(0)

    data['issued'] = (data['I_L'] * data['I_W']) - (data['R_L'] * data['R_W'])

    issueTotal = data['issued'].sum()

    data['issue%'] = data['issued']/issueTotal

    return data

# call function and view results
issue(layout)

