(function(){u8.Crm.StockManagement=function(){this.commandBindings={"StockManagement/ExecuteStockTaking":this.executeStockTaking.bind(this)}};$.extend(u8.Crm.StockManagement.prototype,{hooks:{changeStockReceiptType:function(e){var t=e.getValue();var n=jQuery.Deferred();u8.services.queries.execute({statement:"select (QtyFactor) from (BD) where (StVType='#"+t+"')",maxRows:1},function(t,o){var r=o.resultSet;var i=r&&r.getValue(0,0);if(typeof i!="undefined"){e.setValue("QtyFactor",i)}n.resolve()});return n}},executeStockTaking:function(){var e,t,n,o,r;u8.using({texts:["net_stocktaking_text","error_text"],types:["Formats","DateInput"]},i);function i(){n=u8.session.webConfigValues.get("UpdateServer.RepID");if(!u8.services.reps.get(n)){u8.services.notification.error("TXT_error_text_80");return}a()}function a(){var e={forLoading:true,title:"TXT_net_stocktaking_text_2",formatname:"",formatType:31,includePublicFormats:true,includePrivateFormats:false};u8.services.formats.select(e,c)}function c(t,n){if(n.cancel){return}o=n.formatName;r=n.recordId;e=new u8.Base.Widgets.Popup("<div/>",{size:{width:800,height:200},title:"TXT_net_stocktaking_text_0",position:"center",alignTo:$w("main"),parent:page,onCreate:s});e.open()}function s(n,i){var a=e.getContent(),c=a.constructor;t=new u8.Base.Widgets.Form(c("<div/>").appendTo(a),{formName:"StockTaking",parent:e});t.commandBindings=c.extend({},t.commandBindings,{"StockTaking/CreateTodo":d.bind(this),"StockTaking/Cancel":u.bind(this)});u8.tools.ready(e.children,function(){var n=t.getComponent("$context");n.set("formatName",o);n.set("formatRecordId",r);e.autoSizeAndPosition()})}function u(){e.close()}function d(){var o=t.getComponent("$context");r=o.get("formatRecordId");var i=u8.services.typeConverter.dateToString(o.get("dateFrom"),"YYYYMMDD");var a=u8.services.typeConverter.dateToString(o.get("dateTo"),"YYYYMMDD");var c=o.get("text");if(r.charAt(0)==="x"){r=parseInt(r.substring(1),16)}u8.services.crud.create({infoAreaId:"TD",fields:[{field:"Text",value:"4;"+r+";"+i+";"+a+";"+c},{field:"RepGrpID",value:n},{field:"OfRepID",value:u8.session.identity.repId},{field:"TodoType",value:5}]},s);function s(t,n){if(n.error){return}e.close();u8.services.notification.info("TXT_net_stocktaking_text_10")}}}});u8.services.add({name:"stockManagement",scope:"Application",ctor:u8.Crm.StockManagement})})();