/*
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
if(!dojo._hasResource["kfc.kwo.MultipleMeterReadingGrid"]){dojo._hasResource["kfc.kwo.MultipleMeterReadingGrid"]=true;dojo.provide("kfc.kwo.MultipleMeterReadingGrid");dojo.require("kfc.form.NumberTextBox");dojo.require("kfc.form.OracleDateTextBox");dojo.require("kfc.form.MultiPopupTextBox");dojo.require("kfc.kwo._MeterReading");dojo.require("kfc.kwo._GridBase");dojo.declare("kfc.kwo.MultipleMeterReadingGrid",[kfc.kwo._MeterReading,kfc.kwo._GridBase],{templateString:dojo.cache("kfc.kwo","templates/MultipleMeterReadingGrid.html","
\n"),widgetsInTemplate:true,constructor:function(){this.formatters=new kfc.grid.Formatters();},formatters:{},sourceFile:"server/getLookupValues.php",loadFile:"server/getLastMeterReading.php",assetFile:"server/getAsset.php",rowWarned:{},_getGridStructure:function(){return [{name:" ",field:"",formatter:function(){return " ";},editable:false,width:"1em"},{name:"Asset #",field:"P_ASSET_NO",editable:false,width:"7em"},{name:"Last Reading Date",field:"P_LAST_READING_DATE",widgetClass:kfc.form.OracleDateTextBox,editable:false,width:"11em"},{name:"Last Reading",field:"P_LAST_VALUE",widgetClass:kfc.form.NumberTextBox,editable:false,width:"11em"},{name:"Last Notes",field:"P_LAST_TEXT",editable:false,width:"auto"},{name:"Reading Date",field:"P_READING_DATE",widgetClass:kfc.form.OracleDateTextBox,type:dojox.grid.cells._Widget,editable:true,width:"11em"},{name:"Adjustment",field:"P_DNU_ADJUSTMENT",widgetClass:kfc.form.NumberTextBox,get:dojo.hitch(this,"_adjustReading"),editable:true,width:"11em"},{name:"Reading",field:"P_VALUE",widgetClass:kfc.form.NumberTextBox,get:dojo.hitch(this,"_validateReading"),editable:true,width:"11em"},{name:"Notes",field:"P_TEXT",editable:true,width:"auto"}];},_adjustReading:function(r,i){if(!i){return;}var lv=i.P_LAST_VALUE[0];var cv=i.P_VALUE[0];var a=(i.P_DNU_ADJUSTMENT&&i.P_DNU_ADJUSTMENT[0])?i.P_DNU_ADJUSTMENT[0]:0;if(!a){return 0;}var nv=parseFloat((lv)?lv:0)+parseFloat(a);i.P_VALUE[0]=nv;i.P_DNU_ADJUSTMENT[0]=0;i.ADJUSTED="Y";return i.P_DNU_ADJUSTMENT;},_validateReading:function(r,i){if(!i){return;}var cv=i.P_VALUE[0];var lv=i.P_LAST_VALUE[0];var a=i.P_ASSET_NO[0];if(cv&&parseFloat(lv)>parseFloat(cv)){var w=this.rowWarned[a];if(!w||w!=cv){this.throwError("WARNING: Current reading ("+cv+") is less than last reading ("+lv+").");this.rowWarned[a]=cv;i.IN_ERROR="Y";}}else{i.IN_ERROR="N";this.setStatus("New reading ok.");}var av=(parseFloat(cv)-parseFloat(lv));return i.P_VALUE;},setStatus:function(_1){},onBeforeSave:function(){var _2=this.store._arrayOfAllItems;for(var i=0;i<_2.length;i++){var _3=_2[i];if(_3){if(typeof (_3.P_VALUE)!="undefined"){if((!_3.P_VALUE[0])&&_3.P_VALUE[0]!==0){this.store.deleteItem(_3);}}}}},_loadData:function(_4){this._createStore();this.addSeededRows(_4.items);},_setSourceId:function(_5,_6,_7,_8){},getReadings:function(){this.P_SOURCE_ID=this.chooseMPTB.attr("value");this.P_SOURCE_ID=(this.P_SOURCE_ID.length)?this.P_SOURCE_ID:[-1];this.getData(this.P_SOURCE_LOOKUP_ID,this.P_SOURCE_LOOKUP_VALUE_ID,this.P_SOURCE_ID);},_getNewDataDefaults:function(i){i.P_ID=this.newId--;i.P_SOURCE_LOOKUP_ID=this.P_SOURCE_LOOKUP_ID;i.P_SOURCE_LOOKUP_VALUE_ID=this.P_SOURCE_LOOKUP_VALUE_ID;i.P_CREATED_BY="";i.P_LAST_UPDATED_BY="";i.P_CREATION_DATE="";i.P_LAST_UPDATE_DATE="";i.NEW_ROW_FLAG="Y";return i;},getSourceInfo:function(){var _9=this;dojo.xhrPost({sync:true,url:this.sourceFile,handleAs:"json",content:{"P_NAME":"SOURCE","P_CODE":"A"},load:function(_a){var r=_a.items;if(r&&typeof (r.length)!="undefined"){switch(r.length){case 1:_9.P_SOURCE_LOOKUP_ID=r[0].P_LOOKUP_ID;_9.P_SOURCE_LOOKUP_VALUE_ID=r[0].P_LOOKUP_VALUE_ID;break;default:document.write("COULD NOT LOAD METER READING FORM");break;}}},error:dojo.hitch(this,"throwError")});},addAll:function(){var c=dojo.connect(this.chooseMPTB,"onAfterSearch",this.chooseMPTB,function(){dojo.disconnect(c);this.chooseAll();});this.chooseMPTB.doSearch();},reset:function(){this.chooseMPTB.reset();var _b=this.P_SOURCE_LOOKUP_ID;var _c=this.P_SOURCE_LOOKUP_VALUE_ID;this.inherited(arguments);this.P_SOURCE_LOOKUP_ID=_b;this.P_SOURCE_LOOKUP_VALUE_ID=_c;},addGroupParam:function(){var _d={name:"P_GROUP_ID",label:"Group",dojoType:kfc.form.PopupTextBox,required:false,storeFile:"server/getGroups.php",valueField:"P_ID",displayField:"P_NAME",labelField:"P_DESCRIPTION",seedSearchOnOpen:true,searchSeeds:["P_NAME"],paramToUpper:true,searchOnOpen:true,closeOnFound:false,onVerified:dojo.hitch(this,"addAll"),paramMap:[{name:"P_NAME",label:"Group"},{name:"P_DESCRIPTION",label:"Description"},{name:"P_LOOKUP_ID",type:"hidden",value:"14"},{name:"P_LOOKUP_VALUE_ID",type:"hidden",value:"69"},{name:"P_VALIDATE",type:"hidden",value:"Y"},{name:"P_DELETED_FLAG",type:"hidden",value:"N"}],gStructure:[{field:"P_ACCESS_CODE",name:"Plant",width:"10em"},{field:"P_NAME",name:"Group",width:"10em"},{field:"P_DESCRIPTION",name:"Description",width:"24em"}]};this.chooseMPTB.paramMap.push(_d);this.chooseMPTB.attr("paramMap",this.chooseMPTB.paramMap);},postCreate:function(){this.inherited(arguments);this.getSourceInfo();this.chooseMPTB.storeFile=this.assetFile;this.addGroupParam();dojo.ready(dojo.hitch(this,"refreshGrid"));}});}