MathEngine.toggleTreeCells=function(a,c){var b=$(a);if(b)for(var d=0;d<b.length;d++){var e=$(b[d]);$(e.children()[c]).toggle()}};MathEngine.showTreeCells=function(a,c){var b=$(a);if(b)for(var d=0;d<b.length;d++){var e=$(b[d]);$(e.children()[c]).show()}};MathEngine.hideTreeCells=function(a,c){var b=$(a);if(b)for(var d=0;d<b.length;d++){var e=$(b[d]);$(e.children()[c]).hide()}};
function MathEngine(){var a=this;MathEngine.prototype._actionFactory=function(){};MathEngine.prototype._modelFactory=function(){};MathEngine.prototype.enqueue=function(c){a.executionQueue||(a.executionQueue=[]);a.executionQueue.push(c)};MathEngine.prototype.execute=function(){if(a.executionQueue&&0<a.executionQueue.length){do{var c=a.executionQueue.shift(),b=c.Model||this.getModel(c,void 0);b&&c.execute(b,a)}while(0<a.executionQueue.length)}};MathEngine.prototype.getModel=function(c,b){var a=c.Model;
null===a&&c.ModelRef&&(a=$.modelStorage.get(c.ModelRef.Type,c.ModelRef.ModelId),void 0===a&&(b=b||$("#"+c.ModelRef.ModelKey))&&(a=this._modelFactory(c.ModelRef.Type,b))&&$.modelStorage.add(a));return a};MathEngine.prototype.getModelFromElement=function(c){var b=MathModel.getModelKey(c),a=MathModelReference.getModelType(b),b=MathModelReference.getModelId(b),b=$.modelStorage.get(a,b);void 0===b&&(b=this._modelFactory(a,c),$.modelStorage.add(b));return b};MathEngine.prototype.loadModel=function(a){a=
$("#"+a);var b;a&&1===a.length&&(b=this.getModelFromElement(a));return b}}
function MathAction(){var a={Type:"",MethodKey:"",ModelRef:"",Model:null,Values:null};MathAction.prototype.init=function(c){$.extend(this,a,c)};MathAction.prototype.get=function(a,b){var d=this.Values&&this.Values[a];return void 0!==d?d:b};MathAction.prototype.put=function(a,b){this.Values=this.Values||{};this.Values[a]=b};MathAction.prototype.execute=function(a,b){var d,e=this.getMethod();e&&(d=[],d.push(a),d.push(b),e.apply(this,d))};MathAction.prototype.getMethod=function(){if(this.Type===MathAction.Types.Add)return this.getAddAction();
if(this.Type===MathAction.Types.Remove)return this.getRemoveAction();if(this.Type===MathAction.Types.Update)return this.getUpdateAction();if(this.Type===MathAction.Types.Change)return this.getChangeAction()};MathAction.prototype.getChangeAction=function(){};MathAction.prototype.getUpdateAction=function(){};MathAction.prototype.getAddAction=function(){};MathAction.prototype.getRemoveAction=function(){}}MathAction.Constants={ALL_LOT_KEY:"ALLLOTS"};
MathAction.Types={Add:"Add",Remove:"Rem",Update:"Upd",Change:"Cng"};
function MathModelProperty(a){var c={Type:void 0,Format:void 0};this.ElementName=this.ElementId=this.Value=void 0;$.extend(this,c,a);MathModelProperty.prototype.get=function(b){return this.Type===MathModelProperty.Types.ModelList?void 0!==b?void 0!==this.Value?this.Value[b]:void 0:this.Value:void 0!==this.Value?this.Value:b};MathModelProperty.prototype.set=function(b){this.Value=b;if(void 0!==this.ElementId&&""!==this.ElementId)if(this.Type===MathModelProperty.Types.Decimal){b=this.Format||MathModelProperty.FormatTypes.DecimalGlobal;
var a=$("#"+this.ElementId),c=this.Value;c?b===MathModelProperty.FormatTypes.DecimalGlobal&&(c=$.format(this.Value,(this.Format||MathModelProperty.FormatTypes.DecimalGlobal)===MathModelProperty.FormatTypes.DecimalGlobal?"n"+$.settings.Math.Decimal.ProcedureFormat.Total:"n"+$.settings.Math.Decimal.ProcedureFormat.Intermedium)):c="";a.is("span")?a.text(c):a.val(c)}else this.Type===MathModelProperty.Types.Boolean?(b=$("#"+this.ElementId),this.Format!==MathModelProperty.FormatTypes.BooleanRadio&&((a=
$("#"+this.ElementId+"_hdn"))&&0<a.length&&a.val(this.Value),this.Value?b.attr("checked","checked"):b.removeAttr("checked"))):this.Type===MathModelProperty.Types.String&&(b=$("#"+this.ElementId),b.is("span")?b.text(this.Value):b.val(this.Value));return this};MathModelProperty.prototype.load=function(a){this.ElementId=a.attr("id");this.Type===MathModelProperty.Types.Decimal?(a=a.is("span")?a.text():$.getVal(a),a=$.parseBigDecimal(a),this.Value=void 0===a||isNaN(a)?void 0:a):this.Type===MathModelProperty.Types.Boolean?
(a=this.Format===MathModelProperty.FormatTypes.BooleanRadio?a.is("input")?"true"===a.val():a.children('[value="true"]').is(":checked"):a.is(":checked"),this.Value=a):this.Type!==MathModelProperty.Types.ModelList&&this.Type===MathModelProperty.Types.String&&(this.Value=$.getVal(a))};MathModelProperty.prototype.setProperties=function(a){$.extend(this,c,a);this.Type===MathModelProperty.Types.Decimal&&(this.Value=$.bigDecimalFromJSON(this.Value))};MathModelProperty.prototype.makeReadOnly=function(){this.ElementId&&
""!==this.ElementId&&($("#"+this.ElementId).attr("readonly","readonly"),$("#"+this.ElementId).attr("disabled","disabled"))};MathModelProperty.prototype.removeReadOnly=function(){this.ElementId&&""!==this.ElementId&&($("#"+this.ElementId).removeAttr("readonly"),$("#"+this.ElementId).removeAttr("disabled"))};MathModelProperty.prototype.removeModelBind=function(){this.ElementId&&""!==this.ElementId&&$("#"+this.ElementId).removeAttr("name")};MathModelProperty.prototype.addModelBind=function(){this.ElementId&&
""!==this.ElementId&&this.ElementName&&""!==this.ElementName&&$("#"+this.ElementId).attr("name",this.ElementName)};MathModelProperty.prototype.trigger=function(a){this.ElementId&&""!==this.ElementId&&$("#"+this.ElementId).trigger(a)}}MathModelProperty.Types={Decimal:"Dec",String:"Str",ModelList:"MList",Boolean:"Bool"};MathModelProperty.FormatTypes={DecimalGlobal:"DecGbl",DecimalIntermedium:"DecIntrm",BooleanCheckBox:"BoolChk",BooleanRadio:"BoolRd"};
MathModelProperty.decimalPropertyFactory=function(a){return new MathModelProperty({Type:MathModelProperty.Types.Decimal,Format:a||MathModelProperty.FormatTypes.DecimalGlobal})};MathModelProperty.stringPropertyFactory=function(a){return new MathModelProperty({Type:MathModelProperty.Types.String,Format:a})};MathModelProperty.booleanPropertyFactory=function(a){return new MathModelProperty({Type:MathModelProperty.Types.Boolean,Format:a||MathModelProperty.FormatTypes.BooleanCheckBox})};
MathModelProperty.listPropertyFactory=function(){return new MathModelProperty({Type:MathModelProperty.Types.ModelList,Value:{}})};MathModelProperty.getPropertyName=function(a){return a.data(MathModel.AttributeKeys.PropertyName)};MathModelProperty.isProperty=function(a){return void 0!=a.data(MathModel.AttributeKeys.PropertyName)};
function MathModel(){var a={Info:"",NextModelInfo:"",Propagate:1};this._canIgnoreElement=function(a){return void 0!=a.data(MathModel.AttributeKeys.IgnoreElement)};this._loadInternal=function(a){if(a&&0<a.length)for(var b=0,d=a.length;b<d;b++){var e,f=$(a[b]);MathModel.isModel(f)||this._canIgnoreElement(f)||((e=MathModelProperty.getPropertyName(f))&&this._loadProperty?this._loadProperty(e,f):this._loadInternal(f.children()))}};MathModel.prototype.init=function(c){$.extend(this,a,c)};MathModel.prototype.get=
function(a,b){};MathModel.prototype.load=function(a){var b=MathModel.getModelKey(a),d=a.data(MathModel.AttributeKeys.NextModelKey),e=a.data(MathModel.AttributeKeys.Propagate);this.Info=new MathModelReference(b);this.NextModelInfo=void 0!==d?new MathModelReference(d):void 0;this.Propagate=void 0===e;this._loadInternal(a.children())}}
MathModel.AttributeKeys={PropertyName:"prop",PropertyNieId:"nieid",PropertyNieUId:"nieuid",ModelElem:"mdl",ModelKey:"id",NextModelKey:"nmkey",ModelProperty:"mprop",IgnoreElement:"mnope",Propagate:"prpg"};
MathModel.Variables={RequestComment:"RqCom",ItemCode:"ItmCd",ReqRef:"ReqRef",Description:"Desc",Unit:"Unit",Quantity:"Qtd",CeilingPrice:"ClnP",CeilingPriceTotal:"ClnPT",CostPrice:"CstP",CostPriceTotal:"CstPT",SalesPrice:"SlsP",SalesPriceTotal:"SlsPT",LotCode:"Lot",ItemValues:"ItemValues",ItemTotalValues:"TotalValues",BasePrice:"BasePrice",BasePriceVAT:"BasePriceVAT",DefineBasePrice:"DefBasePrice",MinimumPrice:"MinimumPrice",DefineMinimumPrice:"DefMinimumPrice",DefineLots:"DefLots",DefineLotsPrices:"DefLotsPrices",
UsePriceListValues:"UsePLValues",LotBasePrice:"LotBasePrice",LotBasePriceVAT:"LotBasePriceVAT",LotMinimumPrice:"LotMinimumPrice",Lot:"LotModel",CurrLotCode:"CurrLot",PrevLotCode:"PrevLot",JsonModel:"JsonM",Model:"Model"};MathModel.getModelKey=function(a){return a.attr(MathModel.AttributeKeys.ModelKey)};MathModel.isModel=function(a){return void 0!=a.data(MathModel.AttributeKeys.ModelElem)};
MathModel.getModelElement=function(a){if((a="object"===typeof a?a:$("#"+a))&&!MathModel.isModel(a)&&MathModelProperty.isProperty(a))for(a=a.parent();void 0!=a&&!MathModel.isModel(a);)a=a.parent();return a};function MathModelReference(a){this.ModelKey=this.ModelId=this.Type=void 0;this.ModelKey=a;this.Type=MathModelReference.getModelType(a);this.ModelId=MathModelReference.getModelId(a)}MathModelReference.getModelType=function(a){return a.split("-")[0]};MathModelReference.getModelId=function(a){return a.split("-")[1]};
MathModelReference.factory=function(a){if(void 0!==a&&""!==a)return new MathModelReference(a)};
function ModelStorage(){var a=void 0;ModelStorage.prototype.add=function(c){if(void 0===c)throw"ArgumentNullException : model";var b=c.Info.Type,d=c.Info.ModelId;this.hasModel(b,d)||(void 0===a&&(a={}),void 0===a[b]&&(a[b]={}),a[b][d]=c)};ModelStorage.prototype.get=function(c,b){if(void 0===c||""===c)throw"ArgumentNullException : type";if(void 0===b||""===b)throw"ArgumentNullException : modelId";var d=void 0;void 0!==a&&void 0!==a[c]&&(d=a[c][b]);return d};ModelStorage.prototype.getByReference=function(a){if(void 0===
a)throw"ArgumentNullException : modelRef";return this.get(a.Type,a.ModelId)};ModelStorage.prototype.hasModel=function(a,b){if(void 0===a||""===a)throw"ArgumentNullException : type";if(void 0===b||""===b)throw"ArgumentNullException : modelId";return void 0!==this.get(a,b)};ModelStorage.prototype.getByType=function(c){if(void 0===c||""===c)throw"ArgumentNullException : modelType";return a&&a[c]};ModelStorage.prototype.getChildModel=function(a,b){if(void 0===a||""===a)throw"ArgumentNullException : modelType";
if(void 0===b||""===b)throw"ArgumentNullException : modelKey";var d=this.getByType(a),e;if(d)for(var f in d){var g=d[f];if(g.NextModelInfo&&g.NextModelInfo.ModelKey===b){e=g;break}}return e};ModelStorage.prototype.allModels=function(){return a};ModelStorage.prototype.removeModel=function(c,b){if(void 0===c||""===c)throw"ArgumentNullException : modelType";if(void 0===b||""===b)throw"ArgumentNullException : modelId";var d=a[c];d?d[b]=void 0:a[c]=void 0};ModelStorage.prototype.removeByType=function(c,
b){if(void 0===c||""===c)throw"ArgumentNullException : modelType";if(b&&0<b.length)for(var d=a[c],e=0,f=b.length;e<f;e++)d[b[e]]=void 0;else a[c]=void 0}}(function(a){a.modelStorage=a.modelStorage||new ModelStorage})(jQuery);
