(function(){u8.Crm.SerialEntry.SampleProvider=function(e){this.DefaultProvider($.extend({},u8.Crm.SerialEntry.SampleProvider.defaults,e))};u8.Crm.SerialEntry.SampleProvider.makeClass({name:"SerialEntry.SampleProvider",deriveFrom:u8.Crm.SerialEntry.DefaultProvider});u8.Crm.SerialEntry.SampleProvider.defaults={activityCopyFields:{Date:"Date",RepID:"RepID"},linkInfoAreaIds:["AT"],using:{schema:"MU"}};$.extend(u8.Crm.SerialEntry.SampleProvider.prototype,{autoRefresh:function(e){var i=this.model;if(e.operation=="Delete"){return undefined}var r=e.options&&e.options.businessObject;if(!r){return}if(i.additionalParameters.ShowNoStock&&i.additionalParameters.ShowZeroQuota){return this._refreshOnlyAffectedRows(r.uid)}var t=u8.services.schema.getInfoArea("MU").toFieldId("QuotaAvlbl");var o=this;u8.services.crud.read({uid:r.uid,fields:[t]},a);function a(r,a){if(a.error||!a.businessObject){return}var s=Number(a.businessObject.get(t));var n=!i.additionalParameters.ShowNoStock||!i.additionalParameters.ShowZeroQuota&&s<=0;if(n){return o._refreshWholeList()}else{return o._refreshOnlyAffectedRows(e&&e.uid)}}},_onCreate:function(e){var i=this.model;var r=this.model.url;this._fieldIdQuotaAvlbl=u8.services.schema.toFieldId("MU","QuotaAvlbl");i.additionalParameters={ShowZeroQuota:r.getBoolean("showZeroQuota",false),ShowZeroStock:r.getBoolean("showZeroStock",false),ShowNoStock:r.getBoolean("showNoStock",false)};var t=this;var o={uid:this.model.link,fields:Object.keys(this.activityCopyFields),options:{linked:[{linkName:"$Link[KP]"}]}};u8.services.crud.read(o,function(e,i){t._activity=i.businessObject}.chain(e))},_onPreSave:function(e,i){var r=e.isNew;var t=e.crudOptions;var o=this._activity;if(o){for(var a in this.activityCopyFields){var s=this.activityCopyFields[a];var n=o.get(s);t.businessObject.set(a,n)}}if(r){var u=o.linked["KP"].businessObject;if(u){t.options.links.push(u.uid)}}return i&&i()},_onDuplicate:function(e,i){var r=[];var t={uid:e.originalUid,linkName:"$Link[MA]"};var o={uid:e.originalUid,linkName:"$Link[AT]"};u8.services.crud.readLink(t,function(t,a){if(u8.isValidRecordUid(a.uid)){r.push(a.uid)}u8.services.crud.readLink(o,function(t,o){if(u8.isValidRecordUid(o.uid)){r.push(o.uid)}u8.services.crud.update({uid:e.duplicateUid,options:{links:r}},i)})})},_refreshWholeList:function(){this.model.update({list:true});return true},_refreshOnlyAffectedRows:function(e){var i=this.model.listModel.resultSet;var r=1e5;var t=0;var o=i.findRowsContainingUid(e);if(!o||o.length==0){return}var a=o[0];var s=a.uids.find(u8._.eq("infoAreaId","AR"));if(!s){return}i.eachRowContainingUid(s,function(e,i){if(i>t){t=i}if(i<r){r=i}});var n={list:true};if(t>=r&&t-r!=i.rows.length){i.load({from:r,to:t})}else{this.model.update(n)}return true}})})();