rb
|
The approach can be used to set up a rule that calculates values in one folder based on values in another OR vice versa! Download the attached Ecco file, to explore! For example, we may have the simple relation: Cost=Rate*Hrs where Cost is in one folder and Hrs is in another. If we change Cost, we want EccoExt to calculate the resulting Hrs (=Cost/Rate) If we change Hrs, we want EccoExt to calculate the resulting Cost(=Rate*Hrs) I setup 4 number folders: Cost, Hrs, PrCost, PrHrs PrCost & PrHrs are dummy folders that holds the previous values (only used for the LUA Rule to work). The LUA script is then copied into any folder as an "Auto Assign Rule" (e.g. Folder named "LUA_Rules"). The two columns Cost and Hrs are added to the Notepad (e.g. My Projects) If you set the Cost=1,000, Hrs is calculated to 20. If you then change Hrs to 30, Cost is calculated to 1,500, etc. Try doing this in Excel! LUA Script to Copy: ++:L: cRate=50 -- The Rate is $50/Hr vCost=get_folder_value("Cost",item_id) vHrs=get_folder_value("Hrs",item_id) vPrCost=get_folder_value("PrCost",item_id) -- Get Previous Value vPrHrs=get_folder_value("PrHrs",item_id) -- Get Previous Value if vPrCost~=vCost then -- Cost changed => Calulate Hrs & set new PrCost, PrHrs vHrs=vCost/cRate set_folder_value("Hrs",item_id,vHrs) set_folder_value("PrHrs",item_id,vHrs) set_folder_value("PrCost",item_id,vCost) elseif vPrHrs~=vHrs then -- Hrs Changed => Calulate Cost & set new PrCost, PrHrs vCost=vHrs*cRate set_folder_value("Cost",item_id,vCost) set_folder_value("PrCost",item_id,vCost) set_folder_value("PrHrs",item_id,vHrs) end
|