
var costSheet;CPN.CostSheet=function(args,container)
{CPN.CostSheet.superclass.constructor.call(this,args);if(typeof container!='undefined')
this.container=$(container);};YAHOO.lang.extend(CPN.CostSheet,CPN.EstimateForm,{CALCULATE_ERROR_MSG:'Failed to calculate cost estimate.',addListeners:function(container)
{var func=this.calculate;var fields=Dom.getElementsBy(function(e){return e.type!='BUTTON';},'input',container);for(var i=0;i<fields.length;i++)
{this.addFieldListener(fields[i],func,this);}},hideIfZero:function(field,elements)
{field=Dom.get(field);if(YAHOO.lang.isString(elements))
elements=[elements];var cells=[];for(var i=0;i<elements.length;i++)
{var cell=Dom.getAncestorByTagName(elements[i],'td');cells.push(cell);cells.push(Dom.getPreviousSibling(cell));}
Evt.addListener(field,'change',this.doHideIfZero,cells);this.doHideIfZero({target:field},cells);},doHideIfZero:function(evt,elements)
{var value=Evt.getTarget(evt).value;if(value==''||value==0)
Dom.batch(elements,function(e){e.style.visibility='hidden';});else
Dom.batch(elements,function(e){e.style.visibility='visible';});},updateOutputs:function(values)
{updateOutputs(values,this.container);},getInputValues:function()
{var inParams={};for(var i=0;i<this.inputs.length;i++)
{var id=this.inputs[i];inParams['$'+this.id2VarName(id)]=$float(id);}
return inParams;},getInputValues2:function()
{var regex=/[a-z\d_]+/;var filter=function(e){return e.type!='BUTTON'&&regex.test(e.id);};var inElems=Dom.getElementsBy(filter,'input',this.container);var inParams={};for(var i=0;i<this.inputs.length;i++)
{var id=this.inputs[i];inParams['$'+this.id2VarName(id)]=$float(id);}
return inParams;},onMaterialChange:function(material)
{this.calculate();},id2VarName:function(id)
{return id.dasherize().camelize();},varName2Id:function(varName)
{return varName.replace(/([A-Z])/g,"_$1").toLowerCase();},toggleRegrindDefects:function()
{var primaryProcess=PartSubmit.getPrimaryProcessId()-CS_START_ID;if(primaryProcess==ProcessIds.InjectionMolding)
name='regrind';else if(primaryProcess==ProcessIds.DieCasting)
name='remelt';var regrindRatio=$F(name+'_ratio'),defectRate=$F('defect_rate'),row=getParentRow(name+'_defects_1');if(regrindRatio==''||defectRate==''||regrindRatio==0||defectRate==0)
row.hide();else
row.show();}});CPN.InjectionMoldingCostSheet=function(params)
{this.constructor.superclass.constructor.call(this,params,Dom.get('proc_1063'));this.addListeners(this.container);this.hideIfZero('regrind_ratio','regrind_price');this.hideIfZero('additives_ratio','additives_price');this.addFieldListener('regrind_ratio',this.toggleRegrindDefects,this);this.addFieldListener('defect_rate',this.toggleRegrindDefects,this);this.addFieldListener('clamp_force',this.calculateMachineRate,this);this.toggleRegrindDefects();};YAHOO.lang.extend(CPN.InjectionMoldingCostSheet,CPN.CostSheet,{inputs:['material_density','volume_part','volume_runner','num_cavities','material_price','regrind_ratio','regrind_price','additives_ratio','additives_price','material_markup','mach_setup_time','time_cycle','mach_uptime','defect_rate','post_time','setup_rate','machine_rate','labor_rate','post_rate','production_markup','cost_mold'],machineRates:[[0,26],[50,26],[100,32],[300,42],[500,62],[750,65],[1000,73],[1500,98],[2000,161],[3000,208]],onMaterialChange:function(material)
{$('material_name').value=material.name;$('material_density').value=material.density;$('material_price').value=material.price_med_quant;this.calculate();},calculate:function()
{var inParams=this.getInputValues();try
{with(inParams)
{var $quantityParts=$float('selprodquant'),$density=$materialDensity,$regrindDefects=Dom.get('regrind_defects_1').checked?1:0;var $quantityDefects=($quantityParts/(1-$defectRate/100))-$quantityParts,$quantityRun=$quantityParts+$quantityDefects,$numCycles=$quantityRun/$numCavities,$weightPart=$volumePart*$density,$weightRunner=$volumeRunner*$density,$weightNet=$numCavities*$weightPart,$weightShot=$weightNet+$weightRunner,$weightMolded=$weightShot*$numCycles,$weightDefects=$weightPart*$quantityDefects,$weightRegrindAvail=$weightRunner*$numCycles+$regrindDefects*$weightDefects,$weightRegrindAllow=$weightMolded*($regrindRatio/100),$weightRegrindUsed=Math.min($weightRegrindAllow,$weightRegrindAvail),$weightAdditives=($additivesRatio/100)*($weightMolded-$weightRegrindUsed),$weightResin=($weightMolded-$weightRegrindUsed)*(1-$additivesRatio/100),$costResin=$weightResin*$materialPrice,$costRegrind=$weightRegrindUsed*(($regrindRatio>0)?$regrindPrice:0),$costAdditives=$weightAdditives*(($additivesRatio>0)?$additivesPrice:0),$costMaterialMarkup=($costAdditives+$costResin)*($materialMarkup/100),$costMaterial=$costRegrind+$costAdditives+$costResin+$costMaterialMarkup,$timeRun=($timeCycle/3600)*$numCycles,$timeProd=$timeRun/($machUptime/100),$timeDown=$timeProd-$timeRun,$prodRate=$quantityParts/$timeProd,$costSetup=$machSetupTime*$setupRate,$costMachine=$timeProd*$machineRate,$costLabor=$timeProd*$laborRate,$costPost=$postTime*$postRate,$costProdMarkup=($costSetup+$costMachine+$costLabor+$costPost)*($productionMarkup/100),$costProduction=$costSetup+$costMachine+$costLabor+$costPost+$costProdMarkup,$costTooling=$costMold,$costTotal=$costMaterial+$costProduction+$costTooling;}}catch(e){handleError(this.CALCULATE_ERROR_MSG,e);}
this.updateOutputs({'quantity_run':$quantityRun,'part_weight':$weightPart*16,'weight_resin':$weightResin,'time_prod':$timeProd,'prod_rate':$prodRate,'cost_material':$costMaterial,'cost_resin':$costResin,'cost_regrind':$costRegrind,'cost_additives':$costAdditives,'cost_material_markup':$costMaterialMarkup,'cost_production':$costProduction,'cost_setup':$costSetup,'cost_machine':$costMachine,'cost_labor':$costLabor,'cost_post':$costPost,'cost_prod_markup':$costProdMarkup,'cost_tooling':$costTooling,'total_cost':$costTotal,'im_total_cost':$costTotal});},calculateMachineRate:function()
{var clampForce=$float('clamp_force');if(isNaN(clampForce))
return;var rates=this.machineRates,i;for(i=0;i<rates.length&&clampForce>=rates[i][0];i++);Dom.get('machine_rate').value=rates[i-1][1];}});CPN.EstimateFormFactory.addType(ProcessIds.InjectionMoldingCs,CPN.InjectionMoldingCostSheet);CPN.DieCastingCostSheet=function(params)
{this.constructor.superclass.constructor.call(this,params,'proc_1055');this.addListeners(this.container);this.hideIfZero('remelt_ratio','remelt_price');this.hideIfZero('additives_ratio','additives_price');this.addFieldListener('remelt_ratio',this.toggleRegrindDefects,this);this.addFieldListener('defect_rate',this.toggleRegrindDefects,this);this.addFieldListener('clamp_force',this.calculateMachineRate,this);this.addFieldListener('machine_type_1',this.calculateMachineRate,this);this.addFieldListener('machine_type_2',this.calculateMachineRate,this);this.toggleRegrindDefects();};YAHOO.lang.extend(CPN.DieCastingCostSheet,CPN.CostSheet,{inputs:['defect_rate','num_cavities','material_price','material_density','volume_part','volume_runner','remelt_ratio','remelt_price','additives_ratio','additives_price','material_markup','mach_setup_time','time_cycle','mach_uptime','post_time','setup_labor','machine_rate','direct_labor','post_labor','production_markup','cost_die','num_dies'],coldMachineRates:[[0,98],[50,100],[100,106],[300,115],[500,125],[750,136],[1000,153],[1500,176],[2000,209],[3000,255]],hotMachineRates:[[0,67],[50,69],[100,75],[300,84]],onMaterialChange:function(material)
{$('material_name').value=material.name;$('material_density').value=material.density;$('material_price').value=material.price;if(material.cold_chamber=='t')
$('machine_type_1').checked=true;else
$('machine_type_2').checked=true;this.calculateMachineRate();this.calculate();},calculateMachineRate:function()
{var clampForce=$float('clamp_force');if(isNaN(clampForce))
return;var rates=($('machine_type_1').checked)?this.coldMachineRates:this.hotMachineRates;for(var i=0;i<rates.length&&clampForce>=rates[i][0];i++);Dom.get('machine_rate').value=rates[i-1][1];this.calculate();},calculate:function()
{var inParams=this.getInputValues();try{with(inParams)
{var $quantityParts=$float('selprodquant'),$density=$materialDensity,$remeltDefects=Dom.get('remelt_defects_1').checked?1:0;var $quantityDefects=($quantityParts/(1-$defectRate/100))-$quantityParts,$quantityRun=$quantityParts+$quantityDefects,$numCycles=$quantityRun/$numCavities,$weightPart=$volumePart*$density,$weightRunner=$volumeRunner*$density,$weightNet=$numCavities*$weightPart,$weightShot=$weightNet+$weightRunner,$weightCast=$weightShot*$numCycles,$weightPartTot=$weightPart*$quantityParts,$weightRunnerTot=$weightRunner*$numCycles,$weightDefects=$weightPart*$quantityDefects,$weightRemeltAvail=$weightRunnerTot+$remeltDefects*$weightDefects,$weightRemeltAllow=$weightCast*($remeltRatio/100),$weightRemeltUsed=Math.min($weightRemeltAllow,$weightRemeltAvail),$weightScrap=$weightRunnerTot+$weightDefects-$weightRemeltUsed,$weightAdditives=($additivesRatio/100)*($weightCast-$weightRemeltUsed),$weightMetal=($weightCast-$weightRemeltUsed)*(1-$additivesRatio/100),$costMetal=$weightMetal*$materialPrice,$costRemelt=$weightRemeltUsed*(($remeltRatio>0)?$remeltPrice:0),$costAdditives=$weightAdditives*(($additivesRatio>0)?$additivesPrice:0),$costMaterialMarkup=($costAdditives+$costMetal)*($materialMarkup/100),$costMaterial=$costRemelt+$costAdditives+$costMetal+$costMaterialMarkup,$timeRun=($timeCycle/3600)*$numCycles,$timeProd=$timeRun/($machUptime/100),$timeDown=$timeProd-$timeRun,$prodRate=$quantityParts/$timeProd,$costSetup=$machSetupTime*$setupLabor,$costMachine=$timeProd*$machineRate,$costLabor=$timeProd*$directLabor,$costPost=$postTime*$postLabor,$costProdMarkup=($costSetup+$costMachine+$costLabor+$costPost)*($productionMarkup/100),$costProduction=$costSetup+$costMachine+$costLabor+$costPost+$costProdMarkup,$costTooling=$costDie*$numDies,$costTotal=$costMaterial+$costProduction+$costTooling;}}catch(e){handleError(this.CALCULATE_ERROR_MSG,e);}
this.updateOutputs({'quantity_run':$quantityRun,'part_weight':$weightPart,'time_prod':$timeProd,'prod_rate':$prodRate,'cost_material':$costMaterial,'cost_metal':$costMetal,'cost_remelt':$costRemelt,'cost_additives':$costAdditives,'cost_material_markup':$costMaterialMarkup,'cost_production':$costProduction,'cost_setup':$costSetup,'cost_machine':$costMachine,'cost_labor':$costLabor,'cost_post':$costPost,'cost_prod_markup':$costProdMarkup,'cost_tooling':$costTooling,'total_cost':$costTotal,'dc_total_cost':$costTotal});}});CPN.EstimateFormFactory.addType(ProcessIds.DieCastingCs,CPN.DieCastingCostSheet);CPN.SandCastingCostSheet=function(params)
{this.constructor.superclass.constructor.call(this,params,'proc_1053');this.addListeners(this.container);this.initCores();};YAHOO.lang.extend(CPN.SandCastingCostSheet,CPN.CostSheet,{inputs:['defect_rate','num_cavities','material_price','material_density','volume_part','volume_feed','melting_price','melt_loss','mold_sand_weight','mold_sand_price','core_sand_price','defect_rate_cores','material_markup','material_yield','moldmaking_rate','moldmaking_labor','pouring_price','cleaning_price','plant_eff','coremaking_labor','coresetting_labor','production_markup','cost_pattern','num_patterns'],initCores:function()
{var table=$('coresTable');if(!table.visible())
{table.getElementsBySelector('input','select').invoke('disable');$('removeCoreButton').hide();this.hideRow('core_sand_price');this.hideRow('coremaking_labor');this.hideRow('coresetting_labor');}
Evt.addListener('addCoreButton','click',this.addCore,this,true);Evt.addListener('removeCoreButton','click',this.removeCore,this,true);},addCore:function()
{var num=addCore();var row=Dom.get('core'+num),inputs=row.getElementsByTagName('input'),cells=row.cells;var defaults=[null,'1','','','','1'];for(var i=0;i<defaults.length;i++)
{if(defaults[i]!==null)
Dom.getFirstChild(cells[i]).value=defaults[i];}
Dom.batch(inputs,function(e){this.addFieldListener(e,this.calculate,this);},this,true);this.showRow('core_sand_price');this.showRow('coremaking_labor');this.showRow('coresetting_labor');},removeCore:function()
{var num=removeCore();if(num==0)
{this.hideRow('core_sand_price');this.hideRow('coremaking_labor');this.hideRow('coresetting_labor');}
this.calculate();},onMaterialChange:function(material)
{$('material_name').value=material.name;$('material_density').value=material.density;$('material_price').value=material.casting_price;this.calculate();},calculate:function(e)
{var targetField=null;if(e)
{targetField=Evt.getTarget(e).id;}
var inParams=this.getInputValues();try{with(inParams)
{var $quantityParts=$float('selprodquant'),$density=$materialDensity,$defectRateParts=$defectRate;var $coreQuantity=[0],$coreWeight=[0],$coremakingRate=[0],$costCoreBox=[0],$numCoreBoxes=[0];var $cores=this.getCores();for(var $i=1;$i<=$cores.length;$i++)
{var $c=$cores[$i-1];if($c['core_quantity']!='')
{$coreQuantity[$i]=$c['core_quantity'];$coreWeight[$i]=$c['core_weight'];$coremakingRate[$i]=$c['coremaking_rate'];$costCoreBox[$i]=$c['cost_core_box'];$numCoreBoxes[$i]=$c['num_core_boxes'];}}
var $numCores=$coreQuantity.length-1;if($numCores==0)$coresettingLabor=0;var $coreQuantityTot=[0],$coreWeightTot=[0],$coreCost=[0],$timeCoremaking=[0],$costCoremaking=[0],$costCoreBoxes=[0],$coreIndex;var $quantityDefects=($quantityParts/(1-$defectRateParts/100))-$quantityParts,$quantityRun=$quantityParts+$quantityDefects,$numCycles=$quantityRun/$numCavities,$weightPart=$volumePart*$density,$weightNet=$numCavities*$weightPart;if(targetField=='material_yield')
{$materialYield=$materialYield/100;var $weightFeed=($weightNet-$materialYield*$weightNet)/$materialYield,$weightPoured=$weightNet+$weightFeed;$volumeFeed=$weightFeed/$density;if(!isNaN($volumeFeed))
$('volume_feed').value=$volumeFeed.toFixed(2);}
else
{var $weightFeed=$volumeFeed*$density,$weightPoured=$weightNet+$weightFeed;$materialYield=$weightNet/$weightPoured;if(!isNaN($materialYield))
$('material_yield').value=($materialYield*100).toFixed(2);else
$('material_yield').value='';}
var $weightPartTot=$weightPart*$quantityParts,$weightFeedTot=$weightFeed*$numCycles,$weightDefects=$weightPart*$quantityDefects,$weightPouredTot=$weightPoured*$numCycles,$weightMetal=$weightNet*$numCycles,$weightScrap=$weightFeedTot+$weightDefects,$costMetal=$weightMetal*$materialPrice,$costMelting=$weightPouredTot*$meltingPrice/(1-$meltLoss/100),$weightSandMold=$moldSandWeight*$numCycles,$costSandMold=$moldSandPrice*$weightSandMold;for($coreIndex=1;$coreIndex<=$numCores;$coreIndex++){$coreQuantityTot[$coreIndex]=$coreQuantity[$coreIndex]*$quantityRun/(1-$defectRateCores/100);$coreWeightTot[$coreIndex]=$coreWeight[$coreIndex]*$coreQuantityTot[$coreIndex];$coreCost[$coreIndex]=$coreWeightTot[$coreIndex]*$coreSandPrice;}
var $weightSandCores=array_sum($coreWeightTot),$costSandCores=array_sum($coreCost),$costMaterialMarkup=($costMetal+$costSandMold+$costSandCores)*($materialMarkup/100),$costMaterial=$costMetal+$costSandMold+$costSandCores+$costMaterialMarkup;for($coreIndex=1;$coreIndex<=$numCores;$coreIndex++){$timeCoremaking[$coreIndex]=$coreQuantityTot[$coreIndex]/($coremakingRate[$coreIndex]*($plantEff/100));$costCoremaking[$coreIndex]=$coremakingLabor*$timeCoremaking[$coreIndex];}
var $costCoremakingTotal=array_sum($costCoremaking),$timeMoldmaking=1/$moldmakingRate,$timeMoldmakingTotal=$timeMoldmaking*$numCycles/($plantEff/100),$costMoldmaking=$moldmakingLabor*$timeMoldmakingTotal,$costCoresetting=$coresettingLabor*$timeMoldmakingTotal,$costPouring=$pouringPrice*$weightPouredTot,$costCleaning=$cleaningPrice*$weightPartTot,$costProductionMarkup=($costMelting+$costCoresetting+$costCoremakingTotal+$costMoldmaking+$costPouring+$costCleaning)*($productionMarkup/100),$costProduction=$costMelting+$costCoremakingTotal+$costCoresetting+$costMoldmaking+$costPouring+$costCleaning+$costProductionMarkup,$costPatternTotal=$costPattern*$numPatterns;for($coreIndex=1;$coreIndex<=$numCores;$coreIndex++){$costCoreBoxes[$coreIndex]=$costCoreBox[$coreIndex]*$numCoreBoxes[$coreIndex];}
var $costCoreBoxesTotal=array_sum($costCoreBoxes),$costTooling=$costPatternTotal+$costCoreBoxesTotal,$costTotal=$costMaterial+$costProduction+$costTooling;}}catch(e){handleError(this.CALCULATE_ERROR_MSG,e);}
this.updateOutputs({'quantity_run':$quantityRun,'part_weight':$weightPart,'cost_material':$costMaterial,'cost_metal':$costMetal,'cost_melting':$costMelting,'cost_sand_mold':$costSandMold,'cost_sand_cores':$costSandCores,'cost_material_markup':$costMaterialMarkup,'cost_production':$costProduction,'cost_moldmaking':$costMoldmaking,'cost_coremaking_total':$costCoremakingTotal,'cost_coresetting':$costCoresetting,'cost_pouring':$costPouring,'cost_cleaning':$costCleaning,'cost_production_markup':$costProductionMarkup,'cost_pattern_total':$costPatternTotal,'cost_core_boxes_total':$costCoreBoxesTotal,'cost_tooling':$costTooling,'total_cost':$costTotal,'sc_total_cost':$costTotal});},getCores:function()
{if(!$('coresTable').visible())
{return[];}
var cores=[];for(var i=0,row=null;row=Dom.get('core'+i);i++)
{var core={};var inputs=row.getElementsByTagName('input');for(var j=0;j<inputs.length;j++)
{var id=inputs[j].name;id=id.substr(id.lastIndexOf('[')+1);id=id.substr(0,id.length-1);core[id]=$float(inputs[j]);}
cores.push(core);}
return cores;}});CPN.EstimateFormFactory.addType(ProcessIds.SandCastingCs,CPN.SandCastingCostSheet);CPN.SecondaryCostSheet=function(params)
{this.constructor.superclass.constructor.call(this,params,'process'+params.processOrder);var processOrder=this.getProcessOrder();this.ROW_PREFIX+=':'+processOrder+':';this.addListeners(this.container);var func=this.calculate;var fields=this.container.getElementsByTagName('select');for(var i=0;i<fields.length;i++)
this.addFieldListener(fields[i],func,this);this.addFieldListener('selprodquant',func,this);Evt.addListener('addSecOpButton'+processOrder,'click',this.addOperation,this,true);this.processNameInput=Dom.get('secondary:'+processOrder+':process_name');this.initProcessName();};CPN.SecondaryCostSheet.deleteOperation=function(icon,processOrder)
{getParentRow(icon).hide();$(icon).next('input').value=1;var form=PartSubmit.getProcessEstimateForm(processOrder);form.numberOperations();form.calculate();};YAHOO.lang.extend(CPN.SecondaryCostSheet,CPN.CostSheet,{ROW_PREFIX:'secOp',COMMON_OPERATIONS:['Assembly','Cleaning','Deburring','Grinding','Heat treat','Insert','Inspection','Measurement','Packaging','Packing','Painting','Plating','Polishing','Sanding','Shipping','Testing','Trimming','Welding'],addOperation:function()
{var processOrder=this.processOrder;var table=$('secOpsTable'+processOrder);var num=addItem(this.ROW_PREFIX,table,['name','select']);if(Dom.get(this.ROW_PREFIX+20))
Dom.hideElement('addSecOpButton'+processOrder);var row=Dom.get(this.ROW_PREFIX+num),cells=row.cells;this.numberOperations();try
{var defaults=[null,'','','m',1,null,'',''];for(var i=0;i<defaults.length;i++)
{if(defaults[i]!==null)
Dom.getFirstChild(cells[i]).value=defaults[i];}
var timePerPartId='sec_ops:'+processOrder+':'+num+':op_time_per_part';cells[5].innerHTML='<span id="'+timePerPartId+'"></span>';PartSubmit.addOutputField(timePerPartId,{id:timePerPartId});var matPerPartId='sec_ops:'+processOrder+':'+num+':mat_per_part';cells[8].innerHTML='<span id="'+matPerPartId+'"></span>';PartSubmit.addOutputField(matPerPartId,{id:matPerPartId,precision:2});var inputs=$A(row.getElementsByTagName('input'));inputs=inputs.concat(row.getElementsByTagName('select'));Dom.batch(inputs,function(e){this.addFieldListener(e,this.calculate,this);},this,true);}catch(e){handleError('Failed to add op',e);}
return num;},numberOperations:function(rows)
{var table=Dom.get('secOpsTable'+this.getProcessOrder());var rows=table.tBodies[0].rows;for(var i=0,n=0;i<rows.length;i++)
{if(Dom.getVisibility(rows[i]))
rows[i].cells[0].innerHTML=++n;}},onProcessNameChange:function()
{var processName=this.processNameInput.value;if(processName=='')processName='Custom';if(processName.length>40)
processName=processName.substring(0,40)+'...';this.setProcessName(processName);},initProcessName:function(row)
{var inputField=$('secondary:'+this.getProcessOrder()+':process_name');var container=inputField.wrap('div');var resultsContainer=new Element('div',{'class':'yui-ac-container'});container.insert(resultsContainer);this.opNameDataSource=new YAHOO.widget.DS_JSArray(this.COMMON_OPERATIONS);var autoComp=new YAHOO.widget.AutoComplete(inputField,resultsContainer,this.opNameDataSource);autoComp.useIFrame=(YAHOO.env.ua.ie==6)?true:false;autoComp.useShadow=true;autoComp.maxResultsDisplayed=50;autoComp.queryDelay=0;autoComp.prehighlightClassName='yui-ac-prehighlight';autoComp.minQueryLength=0;autoComp.doBeforeExpandContainer=this.setAutoCompleteHeight;autoComp.textboxFocusEvent.subscribe(function(){this.sendQuery('');});autoComp.itemSelectEvent.subscribe(this.onProcessNameChange,this,true);this.addFieldListener(this.processNameInput,this.onProcessNameChange,this);},setAutoCompleteHeight:function(elTextbox,elContainer,sQuery,aResults)
{if(YAHOO.env.ua.ie>=7)return true;Dom.setStyle($(elContainer).down('div.yui-ac-content'),'height',(aResults.length>10)?'200px':'');return true;},calculate:function()
{var outputs=[];try
{var processOrder=this.getProcessOrder();var prefix='secondary:'+processOrder+':';var $quantityParts=$float('selprodquant'),$efficiency=$float(prefix+'efficiency'),$laborRate=$float(prefix+'labor_rate'),$setupRate=$float(prefix+'setup_rate'),$markup=$float(prefix+'markup');var $operations=this.getListValues('secOpsTable'+processOrder,this.ROW_PREFIX);var $costMaterial=[],$costSetup=[],$costLabor=[],$costMarkup=[],$costTotal=[],$opTimePerPart=[],$matPerPart=[],$setupTimeTot=0,$materialPriceTot=0,$outSecOps=[];for(var $i=0;$i<$operations.length;$i++)
{var $op=$operations[$i],$opTime=$float($op['op_time']),$opTimeUnits=$op['op_time_units'].value,$opPerPart=1,$opParts=$float($op['op_parts']),$setupTime=$float($op['setup_time']),$materialPrice=$float($op['material_price']),$deleted=$op['deleted'].value;if($deleted==1)
continue;if(isNaN($opParts))$opParts=0;if(isNaN($opTime))$opTime=0;if(isNaN($setupTime))$setupTime=0;if(isNaN($materialPrice))$materialPrice=0;if($opTimeUnits=='s')$opTime/=60;else if($opTimeUnits=='h')$opTime*=60;var $opQuantity=$quantityParts*$opPerPart/$opParts,$opTimeTot=$opQuantity*$opTime;$opTimePerPart[$i]=$opTimeTot/$quantityParts;$costMaterial[$i]=$materialPrice*$opQuantity;$matPerPart[$i]=$costMaterial[$i]/$quantityParts;$costSetup[$i]=$setupRate*$setupTime/($efficiency/100);$costLabor[$i]=$laborRate*($opTimeTot/60)/($efficiency/100);$costMarkup[$i]=($costMaterial[$i]+$costSetup[$i]+$costLabor[$i])*($markup/100);$costTotal[$i]=$costMaterial[$i]+$costSetup[$i]+$costLabor[$i]+$costMarkup[$i];$outSecOps[$i]={};$outSecOps[$i]['op_time_per_part']=min2hms($opTimePerPart[$i]);$outSecOps[$i]['mat_per_part']=$matPerPart[$i];$setupTimeTot+=$setupTime;$materialPriceTot+=$matPerPart[$i];}}catch(e){handleError(this.CALCULATE_ERROR_MSG,e);}
var o={};o['sec_ops']=[];o['sec_ops'][processOrder]=$outSecOps;o['quantity_parts'+processOrder]=$quantityParts;o['sec_time_per_part_tot'+processOrder]=min2hms(array_sum($opTimePerPart));o['sec_setup_time_tot'+processOrder]=$setupTimeTot;o['sec_material_price_tot'+processOrder]=$materialPriceTot;o['sec_cost_material'+processOrder]=array_sum($costMaterial);o['sec_cost_setup'+processOrder]=array_sum($costSetup);o['sec_cost_labor'+processOrder]=array_sum($costLabor);o['sec_cost_markup'+processOrder]=array_sum($costMarkup);o['sec_cost'+processOrder]=array_sum($costTotal);o['total_cost']=array_sum($costTotal);this.updateOutputs(o);},getListValues:function(tableName,rowPrefix)
{if(!$(tableName).visible())
{return[];}
var items=[];for(var i=0,row=null;row=Dom.get(rowPrefix+i);i++)
{var item={};var inputs=$A(row.getElementsByTagName('input'));inputs=inputs.concat($A(row.getElementsByTagName('select')));for(var j=0;j<inputs.length;j++)
{var id=inputs[j].name;id=id.substr(id.lastIndexOf('[')+1);id=id.substr(0,id.length-1);item[id]=inputs[j];}
items.push(item);}
return items;}});CPN.EstimateFormFactory.addType(ProcessIds.SecondaryCs,CPN.SecondaryCostSheet);function array_sum(arr)
{for(var i=0,sum=0;i<arr.length;sum+=arr[i++]);return sum;}
function min2hms(time)
{if(isNaN(time)||time==0)return'0:00';var h=Math.floor(time/60);time-=h*60;var m=Math.floor(time);time-=m;var s=Math.round(time*60,0);if(s.toString().length<2)s='0'+s;if(h>0)
{if(m.toString().length<2)m='0'+m;return h+':'+m+':'+s;}
else
{return m+':'+s;}}