//============================================================================= // //============================================================================= function calculate(idx, objGram, objRoast, objCount){ var self = this; var _idx = idx; var _rowsCnt = objGram.length; var _roastCnt = gRoastParchment.length; var _data = new Array(); //-------------------------- // //-------------------------- this.init = function(){ for(var i=0; i<_roastCnt; i++){ _data[i] = [[0,0],[0,0],[0,0],[0,0],[0,0]];//price,count } this.calc(_idx); }; //--------------------------------------------- // //--------------------------------------------- this.calc = function(idx){ var i; var j; var roast; var count=0; var gram=0; var totalg=0; var totalc=0; var price=0; for(i=0; i<_rowsCnt; i++){ //alert(objRoast[i].selectedIndex); gram = objGram[i].value; //roast = 0;//###ロースト毎無効化objRoast[i].selectedIndex; roast = objRoast[i].selectedIndex; count = parseInt(objCount[i].value); this.addCount(roast, gram, count); } for(i=0; i<_data.length; i++){ totalg = this.getTotalGram(i); totalc = this.getTotalCount(i); for(j=0; j<_data[i].length; j++){ gram = 100*(j+1); count = this.getCount(i, j); if(count>0){ price = this.getUnitPrice(idx, i, 100*(j+1), totalg, totalc); } this.setPrice(i,j,price); } } }; //--------------------------------------------- // //--------------------------------------------- this.addCount = function(roast, gram, count){ _data[roast][gram/100 - 1][1] += count; }; //--------------------------------------------- // //--------------------------------------------- this.getCount = function(roast, gramIdx){ return(_data[roast][gramIdx][1]); }; //--------------------------------------------- // //--------------------------------------------- this.setPrice = function(roast, gramIdx, price){ _data[roast][gramIdx][0] = price; }; //--------------------------------------------- // //--------------------------------------------- this.getPrice = function(roast, gram){ return(_data[roast][gram/100-1][0]); }; //--------------------------------------------- // //--------------------------------------------- this.getTotalGram = function(roastIdx){ var gram=0; var loopStart; var loopEnd; if(roastIdx =="all"){ loopStart = 0; loopEnd = _data.length; }else{ loopStart = roastIdx; loopEnd = roastIdx + 1; } for(var i=loopStart; i