function MyContractsViewModel(){var a=this;a.downloadContractsLock=!1;a.skip=0;a.take=10;a.myContracts=ko.observableArray([]);a.dataAvailable=ko.observable(!1);a.selectedContract=ko.observable();a.reset=function(){a.skip=0;a.take=10;a.myContracts([]);a.dataAvailable(!1)};a.setData=function(b){for(var c in b)b[c].Date=moment(b[c].Date,Constants.FullDataFormat),b[c].Start=moment(b[c].Start,Constants.FullDataFormat),b[c].End=moment(b[c].End,Constants.FullDataFormat);a.myContracts(a.myContracts().concat(b))};
a.downloadContracts=function(){MainViewModel.checkInternetConnection()&&!a.downloadContractsLock&&(a.downloadContractsLock=!0,Overlay.create(!0,Culture.translations().stringMsgMyContractsUpdating),ServiceDataProvider.downloadMyContracts(a.skip,a.take).done(function(b){!b.length||b.length<a.take?a.dataAvailable(!1):a.dataAvailable(!0);a.setData(b);a.skip+=a.take;setTimeout(function(){Overlay.destroy()},1)}).always(function(b){if(this.state()==ASyncState.Resolved)b=Culture.translations().stringMsgMyContractsUpdated;
else switch(b){case 3015:case 3016:MainViewModel.handleLostSession("Contracts.html",a.downloadContracts);return;default:b=Culture.translations().stringTextDownloadingUserProfileFailed}a.downloadContractsLock=!1;Overlay.hideLoader();Overlay.showTextOnlyLoader(b)}).fail(function(){a.downloadContractsLock=!1;setTimeout(function(){Overlay.destroy()},2E3)}))};a.isEndOfContract=ko.computed(function(){return void 0!=a.selectedContract()&&1>=moment(a.selectedContract().End,Constants.LongDataFormat).diff(moment(),
Constants.Months)?!0:!1});a.sendEmail=ko.computed(function(){var b=a.selectedContract();if(void 0!=b){var c;c=""+String.format("{0}:  {1}\n",Culture.translations().stringTextNumber,b.Id);c+=String.format("{0}:  {1}\n",Culture.translations().stringTextDescription,b.ObjectDescription);c+=String.format("{0}:  {1}\n",Culture.translations().stringTextBeginning+"/"+Culture.translations().stringTextEnd,String.format("{0:d}",moment(b.Start,Constants.LongDataFormat).toDate())+"/"+String.format("{0:d}",moment(b.End,
Constants.LongDataFormat).toDate()));c+=String.format("{0}:  {1}\n",Culture.translations().stringTextCalculationType,b.ContractType);c+=String.format("{0}:  {1}\n",Culture.translations().stringTextObjectType,ObjectTypes.getText(b.ObjectType.toUpperCase()));c+=String.format("{0}:  {1}\n",Culture.translations().stringTextPrice,b.Price.formatCurrency());c+=String.format("{0}:  {1}\n",Culture.translations().stringTextOneOffPayment,b.OneOffPayment.formatCurrency());c+=String.format("{0}:  {1}\n",Culture.translations().stringTextPeriod+
"/"+Culture.translations().stringTextRest,b.Period+"/"+b.UntilContractEnd);c+=String.format("{0}:  {1}\n",Culture.translations().stringTextResidualValue,b.LastPayment.formatCurrency());c+=String.format("{0}:  {1}\n",Culture.translations().stringTextMonthlyPayment,b.MonthlyPayment.formatCurrency());c=encodeURIComponent(c);return String.format(Constants.EmailFormat,ApplicationSettings.defaultEmail,Culture.translations().stringTextEmailContractSubject+b.Id,c)}})};
