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(c){c=
$("#"+c);var b;c&&1===c.length&&(b=this.getModelFromElement(c));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(c,b){var a=this.Values&&this.Values[c];return void 0!==a?a:b};MathAction.prototype.put=function(c,b){this.Values=this.Values||{};this.Values[c]=b};MathAction.prototype.execute=function(c,b){var a,e=this.getMethod();e&&(a=[],a.push(c),a.push(b),e.apply(this,a))};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;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));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(b){this.ElementId=b.attr("id");this.Type===MathModelProperty.Types.Decimal?(b=b.is("span")?b.text():$.getVal(b),b=$.parseBigDecimal(b),this.Value=void 0===b||isNaN(b)?void 0:b):this.Type===MathModelProperty.Types.Boolean?
(b=this.Format===MathModelProperty.FormatTypes.BooleanRadio?b.is("input")?"true"===b.val():b.children('[value="true"]').is(":checked"):b.is(":checked"),this.Value=b):this.Type!==MathModelProperty.Types.ModelList&&this.Type===MathModelProperty.Types.String&&(this.Value=$.getVal(b))};MathModelProperty.prototype.setProperties=function(b){$.extend(this,c,b);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(b){this.ElementId&&""!==this.ElementId&&$("#"+this.ElementId).trigger(b)}}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.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",DefineBasePrice:"DefBasePrice",DefineLots:"DefLots",DefineLotsBasePrice:"DefLotsBasePrice",UsePriceListValues:"UsePLValues",LotBasePrice:"LotBasePrice",Lot:"LotModel",
CurrLotCode:"CurrLot",PrevLotCode:"PrevLot",JsonModel:"JsonM",Model:"Model",ReplyPrice:"ReplyPrice",ReplyPriceTotal:"ReplyPriceTotal",LineDiscountPercentage:"LineDiscountPercentage",DiscountValue:"DiscountValue",ITBIS:"ITBIS",ITBISValue:"ITBISValue",Tax:"Tax",TaxValue:"TaxValue",MontoGrabado:"MontoGrabado",ReplyValue:"ReplyValue",Rate:"Rate",BillingQuantity:"BillingQuantity",BillingPrice:"BillingPrice",BillingPriceTotal:"BillingPriceTotal",BillingDiscountPercentage:"BillingDiscountPercentage",CurrentBid:"CurrentBid"};
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&&null!==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.getChildModels=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];g.NextModelInfo&&g.NextModelInfo.ModelKey===b&&(e[f]=g)}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};ModelStorage.prototype.removeChildModels=function(a,b){if(b)for(var d in b){var e=
b[d];e.removeChildModels&&e.removeChildModels();$.modelStorage.removeModel(a,d)}}}(function(a){a.modelStorage=a.modelStorage||new ModelStorage})(jQuery);
