SHARE
TWEET

Untitled

a guest Apr 27th, 2016 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(u,w,v){u.layLoadingPageSize=15;var f=angular.module("main.services",[]);f.config(["$provide","$httpProvider",function(f,n){f.factory("myHttpInterceptor",["$rootScope",function(c){function e(e){if("unauthorized"===e.data.errorMessage||"unauthorized"===e.data.authMessage||"userDisabled"===e.data.message)"/test"===u.location.pathname||c.isLogOut||(c.logOut&&"userDisabled"===e.data.message?c.logOut("Your account has been disabled."):c.logOut?c.logOut():(alert("Your will be logout now."),u.loggingOut=
  2. !0,u.location.href="/logout",u.location.hash=""));else return e.data.showMessage?(alert(e.data.showMessage),{}):e}return{request:function(c){c.url&&(c.params||(c.params={}),0<=c.url.indexOf(".html")||(c.params.t=(new Date).getTime()));return c},response:e,responseError:e}}]);n.interceptors.push("myHttpInterceptor")}]);f.run(["$http","$rootScope","ConstantsService",function(f,n,c){f.get("/users/current").success(function(c){n.currentUser=c});n.numberCounterDelimiter="-"}]);f.service("Downloader",function(){function f(h,
  3. b){if(/(iP)/g.test(navigator.userAgent))return alert("Your device does not support files downloading. Please try again in desktop browser."),!1;if(n||e){var a=document.createElement("a");a.href=h;a.download!==v&&(b||(b=h.substring(h.lastIndexOf("/")+1,h.length)),a.download=b);if(document.createEvent){var d=document.createEvent("MouseEvents");d.initEvent("click",!0,!0);a.dispatchEvent(d);return!0}}else if(c){w("#pdf").remove();w("body").append("<iframe id='pdf' style='display:none;'></iframe>");document.getElementById("pdf").src=
  4. h;return}u.open(h,"_new");return!0}var n=-1<navigator.userAgent.toLowerCase().indexOf("chrome"),c=-1<navigator.userAgent.toLowerCase().indexOf("safari"),e=-1<navigator.userAgent.toLowerCase().indexOf("firefox");return{downloadByUrl:f,downloadTicketAttachments:function(c){f("/v2/tickets/"+c+"/downloadAttachments")},downloadFile:function(c){f("/file/"+c)}}});f.service("Utils",["$http","$rootScope",function(f,n){function c(d){var a=d;!a&&this.staticCopy&&(a=this);if("[object Array]"===Object.prototype.toString.call(a)){d=
  5. [];for(var b=0;b<a.length;b++)d.push(c(a[b]))}else if("[object Object]"===Object.prototype.toString.call(a))for(b in d={},a)"staticCopy"!==b&&"$$hashKey"!=b&&(d[b]=c(a[b]));else return a;return d}function e(a,g){if("[object String]"===Object.prototype.toString.call(a))return a;g=g||a;for(var l in a){var k=a[l];"[object Array]"===Object.prototype.toString.call(k)?h(k):"[object Object]"===Object.prototype.toString.call(k)&&e(k);b(g,l,k)}b(g,"staticCopy",c);return g}function h(a,g){if(g){for(var l=0;l<
  6. a.length;l++)g.push(e(a[l]));b(g,"staticCopy",c);return g}for(l=0;l<a.length;l++)a[l]=e(a[l]);b(a,"staticCopy",c);return a}function b(a,c,b){Object.defineProperty(a,c,{value:b,writable:!1,enumerable:!0,configurable:!0})}function a(a,c){for(var b=0;b<a.length;b++){var k=a[b];if(k&&(k=k.versionedId?k.versionedId.id:k.id,k===c))return b}return-1}return{customizeObj:e,customizeArray:h,defineReadOnlyProperty:b,findById:function(a,c){for(var b=0;b<a.length;b++){var k=a[b];if((k.versionedId?k.versionedId.id:
  7. k.id)===c)return k}},indexOfId:a,handleCallback:function(a,c){c&&a.then(function(a){c(a.data)},function(a){c(a.data)})},deleteById:function(c,b){var l=a(c,b);-1<l&&c.splice(l,1)},getListByUrl:function(a,c,b){var k=[];b&&(k=h(k));f.get(a).then(function(a){if(b)h(a.data,k),b(k);else for(var d=0;d<a.data.length;d++)k.push(a.data[d]);c&&c(k)},function(a){c&&c(a.data)});return k},getFormattedNumber:function(a,c){var b;if(c)for(b=""+(parseInt(a.numPart)+1);b.length<a.numPart.length;)b="0"+b;else b=a.numPart;
  8. return a.charPart?a.charPart+n.numberCounterDelimiter+b:b},getComparatorBy:function(a,c){return function(b,k){return c?k[a]-b[a]:b[a]-k[a]}},formatDate:function(a){return a.getFullYear()+"-"+(a.getMonth()+1)+"-"+a.getDate()}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("AddressesService",["$http","$rootScope","RealTimeService","Utils","$filter",function(f,t,n,c){return{getLocales:function(e,h){if(null==e)throw"grouped is required!";var b=c.customizeArray([]);f.get("/addresses/"+(e?"getGroupedLocales":"getLocales")).then(function(a){c.customizeArray(a.data,b);h&&h(a.data)},function(a){h&&h(a.data)});return b},getLocaleByName:function(e,h){if(null==e)throw"name is required!";var b=f({url:"/addresses/getLocaleByName",
  9. method:"POST",data:e});c.handleCallback(b,h)}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("AssociationService",["$http","$rootScope","Utils","$filter",function(f,t,n){return{deleteAssociation:function(c,e){if(!c)throw"id is required!";var h=f({url:"/association/"+c,method:"DELETE"});n.handleCallback(h,e)}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("BillableService",["$http","$rootScope","RealTimeService","Utils","CompaniesService",function(f,t,n,c){function e(a){for(var c=0;c<a.tickets.length;c++)a.totalSum+=a.tickets[c].sum}function h(a){for(var c in a)if("staticCopy"!==c)for(var b=0;b<a[c].tickets.length;b++)a[c].totalSum||(a[c].totalSum=0),a[c].totalSum+=a[c].tickets[b].sum}function b(a){for(var c in a)if("staticCopy"!==c){a[c].lockType="NONE";for(var b=0;b<a[c].tickets.length;b++){var e=
  10. a[c].tickets[b];"NONE"===a[c].lockType&&null!=e.lockedBy?a[c].lockType="ALL":"ALL"==a[c].lockType&&null==e.lockedBy&&(a[c].lockType="NOT_ALL")}}}return{getTotalBilledAmount:function(a,b){var g=c.customizeObj({});f.get("/billable/totalBilled").then(function(e){c.customizeObj(e.data,g);n.subscribe("/billedTicketsSumAdded",a,function(a){console.log(a);"BILLED_TICKETS_SUM_ADDED"===a.action&&c.defineReadOnlyProperty(g,"value",g.value+a.data)});b&&b(e.data)},function(a){b&&b(a.data)});return g},getBillableChartData:function(a,
  11. b){var g=c.customizeArray([]);f.get("/billable/billed/lastDays").then(function(e){c.customizeArray(e.data,g);n.subscribe("/billedTicketsSumAdded",a,function(a){console.log(a);if("BILLED_TICKETS_SUM_ADDED"===a.action){var b=g[g.length-1];c.defineReadOnlyProperty(b,"sum",b.sum+a.data)}});b&&b(g)},function(a){b&&b(a.data)});return g},createInvoice:function(a,b,g,e){if(!a)throw"lockId is required!";if(!b)throw"contact is required!";if(!g)throw"address is required!";a=f.get("/invoice/create/"+a+"?&billTo="+
  12. b+"&shipTo="+g);c.handleCallback(a,e)},saveRegularOrder:function(a,b){if(!a)throw"order must be!";var g=f({url:"/billable/saveRegularOrder",method:"POST",data:a});c.handleCallback(g,b)},getActualInvoiceNumber:function(a,b){f.get("/data/actualNumber?type=INVOICE").success(function(a){b(a.number)});n.subscribe("/number?targetId=INVOICE",a,function(a){console.log(a);"NUMBER_CHANGED"===a.action&&b(c.getFormattedNumber(a.data,!1))})},search:function(a){if(!a)throw"Keyword is required!";return f.get("/billable/search?keyword="+
  13. a).then(function(a){return a.data})},getLockedTicketIds:function(a,c){},lockTicketIds:function(a,b){if(!a)throw"ticketIds is required!";var g=c.customizeObj({});f({url:"/invoice/lock",method:"POST",data:a}).then(function(a){c.customizeObj(a.data,g);b&&b(a.data)},function(a){b&&b(a.data)});return g},unlockTicketIds:function(a,b){if(!a)throw"lockId is required!";var g=f.get("/invoice/unlock/"+a);c.handleCallback(g,b)},getExistTimeByLockId:function(a,b){if(!a)throw"lockId is required!";var g=f.get("/invoice/lock/timeToUnlock/"+
  14. a);c.handleCallback(g,b)},lockTicketsByCompany:function(a,b){if(!a)throw"companyId is required!";var g=f.get("/invoice/lock/lockByCompany/"+a);c.handleCallback(g,b)},getBillablePageDto:function(a,d){if(!a||!a.$id)throw"First argument must be Angularjs scope!";var g=c.customizeObj({});f.get("/billable/billablePageInfo").then(function(l){c.customizeObj(l.data,g);h(g);b(g);n.subscribe("/billablePage",a,function(a){console.log(a);if("BILLABLE_EXPENSE_ADDED"==a.action){var p=a.data.companyId;g[p]||(g[p]=
  15. {},g[p].tickets=[],g[p].totalSum=0,g[p].lockType="NONE");var l=c.findById(g[p].tickets,a.data.id);l||(l={},g[p].tickets.push(l));c.customizeObj(a.data,l);e(g[p]);d&&d(g)}else if("BILLABLE_EXPENSE_REMOVED"==a.action)l=g[a.data.companyId].tickets,p=c.indexOfId(l,a.data.ticketId),-1<p&&l.splice(p,1),l&&l.length&&0!==l.length?e(g[a.data.companyId]):delete g[a.data.companyId],d&&d(g);else if("TICKET_LOCKED"==a.action){for(var h=Object.keys(a.data)[0],p=0;p<a.data[h].length;p++)for(var r in g)"staticCopy"!==
  16. r&&(l=c.findById(g[r].tickets,a.data[h][p]))&&c.defineReadOnlyProperty(l,"lockedBy",h);b(g);d&&d(g)}else if("TICKET_UNLOCKED"==a.action){for(r in g)if("staticCopy"!==r)for(p=0;p<g[r].tickets.length;p++)for(l=0;l<a.data.length;l++)g[r].tickets[p].id===a.data[l]&&c.defineReadOnlyProperty(g[r].tickets[p],"lockedBy",null);b(g);d&&d(g)}});d&&d(g)});return g}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("CompaniesService",["$http","$rootScope","RealTimeService","Utils","$filter",function(f,t,n,c){function e(){q++;if(2===q){d=!0;for(var a=0;a<g.length;a++)g[a]()}}function h(a,b){b&&(p=b);return c.findById(k.companies,a)||c.findById(k.deletedCompanies,a)}function b(a,c){if(!a)throw"Keyword is required!";for(var b=[],d=0;d<k.companies.length;d++){var g=k.companies[d];(c||k.currentCompany.id!==g.id)&&-1<g.name.indexOf(a)&&b.push(g)}return b}function a(a){a&&
  17. (d?a():g.push(a))}t=t.$new();var d=!1,g=[],l=[],k={companies:[],clientCompanies:[],deletedCompanies:[],currentCompany:{}},p,x={};c.customizeObj(k);f.get("/company/clients").then(function(a){for(var b=0;b<a.data.length;b++){var m=c.customizeObj(a.data[b]);a.data[b].deletedAt?k.deletedCompanies.push(m):(k.clientCompanies.push(m),k.companies.push(m))}e()},function(a){console.error(a);throw"Cannot initialize CompaniesService!";});f.get("/company/current").then(function(a){c.customizeObj(a.data,k.currentCompany);
  18. k.companies.push(k.currentCompany);e()},function(a){console.error(a);throw"Cannot initialize CompaniesService!";});var q=0;n.subscribe("/company",t,function(a){console.log(a);if(d){var b=a.data.id;if("COMPANY_SAVED"==a.action){var m=c.findById(k.companies,b);if(m)c.customizeObj(a.data,m);else{a=c.customizeObj(a.data);k.companies.push(a);k.clientCompanies.push(a);for(a=0;a<l.length;a++)l[a]();if(x[b])x[b](b)}}else if("COMPANY_ARCHIVED"==a.action)for(k.deletedCompanies.push(c.findById(k.companies,b)),
  19. c.deleteById(k.companies,b),c.deleteById(k.clientCompanies,b),p&&"function"==typeof p&&p(b),a=0;a<l.length;a++)l[a]();else if("COMPANY_DEARCHIVED"==a.action)for(m=c.customizeObj(a.data),k.clientCompanies.push(m),k.companies.push(m),a=0;a<l.length;a++)l[a]()}});return{_addInitListener:a,_addAmountChangeListener:function(a){l.push(a)},_search:b,_isInitialized:function(){return d},getCurrentCompany:function(){return k.currentCompany},getClientCompanies:function(c){a(c);return k.clientCompanies},getAllCompanies:function(){return k.companies},
  20. getOneById:h,getUnassignedCompany:function(){for(var a=0;a<k.companies.length;a++)if(k.companies[a].isDefault)return k.companies[a]},searchByAllCompanies:function(a){return b(a,!0)},searchByClientCompanies:function(a){return b(a,!1)},getClientCompaniesInfo:function(a,b){if(!a||!a.$id)throw"Second argument must be Angularjs scope!";var m=c.customizeObj({});f.get("/company/clients/info").then(function(a){c.customizeObj(a.data,m);b&&b(a.data)},function(a){b&&b(a.data)});n.subscribe("/clientCompaniesInfo",
  21. a,function(a){console.log(a);if("CLIENT_COMPANY_INFO"==a.action){a=JSON.parse(a.data);for(var b in a)c.defineReadOnlyProperty(m,b,c.customizeObj(a[b]))}else"COMPANY_ARCHIVED"==a.action&&(delete m[a.data.id],p&&"function"==typeof p&&p(a.data.id))});return m},getCompanyInfo:function(a,b,m){if(!a)throw"companyId is required!";if(!b||!b.$id)throw"Second argument must be Angularjs scope!";var d=c.customizeObj({});f.get("/company/"+a+"/info").then(function(a){c.customizeObj(a.data,d);m&&m(a.data)},function(a){m&&
  22. m(a.data)});n.subscribe("/clientCompaniesInfo",b,function(b){console.log(b);if("CLIENT_COMPANY_INFO"==b.action){b=JSON.parse(b.data);for(var m in b)m===a&&c.customizeObj(b[a],d)}});return d},archive:function(a,b){if(!a)throw"companyId is required!";f.get("/company/archive/"+a).then(function(a){b(a)},function(a){b(a)})},dearchive:function(a,b){if(!a)throw"companyId is required!";var m=f.get("/company/dearchive/"+a);c.handleCallback(m,b)},save:function(a,b){if(!a)throw"company is required!";var m="POST";
  23. a.id&&(m="PUT");m=f({url:"/company",method:m,data:a});!a.id&&b?m.then(function(a){var c=a.data.id;h(c)?b(a.data):x[c]=b}):c.handleCallback(m,b)},saveForCompanyProfile:function(a,b,m){if(!a)throw"data is required!";if(!b)throw"toUpdate is required!";b=b.toLowerCase();"addresses"===b&&(a={addresses:a});a=f({url:"/settings/companyProfile/"+b,method:"PUT",data:a});c.handleCallback(a,m)},saveCompanySettingsDto:function(a,b){if(!a)throw"companyDto is required!";var m=f({url:"/settings/companyProfile/",
  24. method:"PUT",data:a});c.handleCallback(m,b)},getCompanyForSettingPage:function(a){var b={};f.get("/settings/companyProfile/").then(function(m){c.customizeObj(m.data,b);a&&a(m.data)},function(b){a&&a(b.data)});return b},getCompanyData:function(a,b,m){if(!b)throw"companyId is required!";if(!a||!a.$id)throw"Second argument must be Angularjs scope!";var d=c.customizeObj({});f.get("/company/"+b+"/data").then(function(a){c.customizeObj(a.data,d);m&&m(a.data)},function(a){m&&m(a.data)});n.subscribe("/companyDto?targetId="+
  25. b,a,function(a){console.log(a);if("COMPANY_DTO_CHANGED"==a.action){a=JSON.parse(a.data);for(var m in a)m===b&&c.customizeObj(a[b],d)}});return d},isNameUnique:function(a,b,m){if(!a)throw"name is required!";var d=c.customizeObj({});f.get("/company/isCompanyNameUnique?name="+a+"&id="+b).then(function(a){c.customizeObj(a.data,d);m&&m(a.data)},function(a){m&&m(a.data)});return d},isDomainUnique:function(a,b,m){if(!a)throw"domain is required!";var d=c.customizeObj({});f.get("/company/isCompanyDomainUnique?domain="+
  26. a+"&id="+b).then(function(a){c.customizeObj(a.data,d);m&&m(a.data)},function(a){m&&m(a.data)});return d},isCompanyInboxUnique:function(a,b){if(!a)throw"inbox is required!";var m=c.customizeObj({});f.get("/isCompanyInboxUnique?inbox="+a).then(function(a){c.customizeObj(a.data,m);b&&b(a.data)},function(a){b&&b(a.data)});return m},changeUserAndPass:function(a,b,m,d){if(!m)throw"id is required!";var g=c.customizeObj({});f.get("/company/"+m+"/changeUserAndPass?userName="+a+"&password="+b).then(function(a){c.customizeObj(a.data,
  27. g);d&&d(a.data)},function(a){d&&d(a.data)});return g},saveCover:function(a,b,m){if(!a)throw"croppedImage is required!";if(!b)throw"companyId is required!";a=f({url:"/company/"+b+"/cover",method:"POST",data:a});c.handleCallback(a,m)},saveLogo:function(a,b,m){if(!a)throw"croppedImage is required!";if(!b)throw"companyId is required!";a=f({url:"/company/"+b+"/logo",method:"POST",data:a});c.handleCallback(a,m)},deleteCover:function(a,b){if(!a)throw"companyId is required!";var m=f({url:"/company/"+a+"/false",
  28. method:"DELETE"});c.handleCallback(m,b)},deleteLogo:function(a,b){if(!a)throw"companyId is required!";var m=f({url:"/company/"+a+"/true",method:"DELETE"});c.handleCallback(m,b)},getCompanyContacts:function(a,b,m){if(!a||!a.$id)throw"First argument must be Angularjs scope!";if(!b)throw"Second argument must be companyId!";return c.getListByUrl("/company/"+b+"/contacts",m,function(m){n.subscribe("/companyContact",a,function(a){console.log(a);"COMPANY_CONTACT"==a.action&&(m.splice(0,m.length),c.customizeArray(a.data,
  29. m))});n.subscribe("/subscription?targetId="+b,a,function(a){console.log(a);if(a.data.contact){var b=c.findById(m,a.data.contact.id);b&&("SUBSCRIPTION_SAVED"==a.action?c.defineReadOnlyProperty(b,"subscription",c.customizeObj(a.data)):"SUBSCRIPTION_DELETED"==a.action&&delete b.subscription)}})})}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("ConstantsService",["$http",function(f){var t;f.get("/data/getConstants").then(function(f){t=f.data});return{getConstant:function(f){if(!f)return t;if(Array.isArray(f)){for(var c={},e=0;e<f.length;e++)t.hasOwnProperty(f[e])&&(c[f[e]]=t[f[e]]);return c}if(t.hasOwnProperty(f))return t[f]}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("ContactsService",["$http","$rootScope","RealTimeService","Utils","CompaniesService",function(f,t,n,c,e){return{isEmailUnique:function(e,b,a){if(!e)throw"email is required!";var d=c.customizeObj({});f.get("/contacts/isEmailUnique?email="+e+"&id="+b).then(function(b){c.customizeObj(b.data,d);a&&a(b.data)},function(b){a&&a(b.data)});return d},getSubscribedContactsOnTicket:function(h,b){if(!h||!h.$id)throw"First argument must be Angularjs scope!";
  30. var a=c.customizeArray([]);f.get("/contacts/getSubscribedContactsOnTicket/").then(function(d){c.customizeArray(d.data,a);n.subscribe("/subscription?targetId="+e.getCurrentCompany().id,h,function(d){console.log(d);if(d.data.contact){var e=c.findById(a,d.data.contact.id);e&&("SUBSCRIPTION_SAVED"==d.action?(c.defineReadOnlyProperty(e,"subscription",c.customizeObj(d.data)),b&&b()):"SUBSCRIPTION_DELETED"==d.action&&(delete e.subscription,b&&b()))}});n.subscribe("/vendorContacts",h,function(d){console.log(d);
  31. if("VENDOR_CONTACTS_SAVE"==d.action){for(var e=0;e<d.data.length;e++){var k=d.data[e],p=c.findById(a,k.id);k.subscription.ticket?p?c.customizeObj(k,p):a.push(c.customizeObj(k)):p&&c.deleteById(a,p.id)}b&&b()}else if("VENDOR_CONTACTS_DELETE"==d.action){for(e=0;e<d.data.length;e++)c.deleteById(a,d.data[e].id);b&&b()}});b&&b(d.data)},function(a){b&&b(a.data)});return a},getAllVendorsContacts:function(e,b){if(!e||!e.$id)throw"First argument must be Angularjs scope!";var a=c.customizeArray([]);f.get("/contacts/getAllVendorsContacts/").then(function(d){c.customizeArray(d.data,
  32. a);n.subscribe("/vendorContacts",e,function(d){console.log(d);if("VENDOR_CONTACTS_SAVE"==d.action){for(var e=0;e<d.data.length;e++){var k=d.data[e],p=c.findById(a,k.id);p?c.customizeObj(k,p):a.push(c.customizeObj(k))}b&&b()}else if("VENDOR_CONTACTS_DELETE"==d.action){for(e=0;e<d.data.length;e++)c.deleteById(a,d.data[e].id);b&&b()}});b&&b(d.data)},function(a){b&&b(a.data)});return a}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("DevicesService",["$http","$rootScope","RealTimeService","Utils","UsersService","Downloader","CompaniesService",function(f,t,n,c,e,h,b){function a(){for(var a in g.callbacks)if("staticCopy"!==a){var b=g.callbacks[a];b&&b.callback&&"function"===typeof b.callback&&b.callback(g.devices[b.companyId])}}function d(){for(var b in g.devices)if("staticCopy"!==b){if(0==g.devices[b].length){delete g.devices[b];delete g.deviceCounter[b];a();return}g.deviceCounter.companyId||
  33. (g.deviceCounter[b]=c.customizeObj({all:0,online:0}));c.defineReadOnlyProperty(g.deviceCounter[b],"all",g.devices[b].length);for(var d=0,m=0;m<g.devices[b].length;m++)g.devices[b][m].online&&d++;c.defineReadOnlyProperty(g.deviceCounter[b],"online",d)}a()}var g={devices:{},callbacks:{},deviceCounter:{}},l=t.$new(),k={},p={},x=[],q=!1;c.customizeObj(g);b._addInitListener(function(){f.get("/devices?companyId="+b.getCurrentCompany().id).then(function(a){var b=g.devices;c.customizeObj(a.data,b);d();n.subscribe("/device",
  34. l,function(a){if("DEVICE_ONLINE"===a.action){for(var r in b[a.data.clientCompanyId])b[a.data.clientCompanyId][r].id===a.data.value&&c.defineReadOnlyProperty(b[a.data.clientCompanyId][r],"online",!0);d()}else if("DEVICE_OFFLINE"===a.action){for(r in b[a.data.clientCompanyId])b[a.data.clientCompanyId][r].id===a.data.value&&c.defineReadOnlyProperty(b[a.data.clientCompanyId][r],"online",!1);d()}else if("DEVICE_INSTALLED"===a.action)b[a.data.clientCompanyId]?b[a.data.clientCompanyId].push(c.customizeObj(JSON.parse(a.data.value).device)):
  35. (r=a.data.clientCompanyId,b[r]=[],b[r].push(JSON.parse(a.data.value).device)),d();else if("DEVICE_UNINSTALLED"===a.action){for(r in b[a.data.clientCompanyId])b[a.data.clientCompanyId][r].id===a.data.value&&b[a.data.clientCompanyId].splice(r,1);d()}});n.subscribe("/oneTimeConnection",t,function(a){"REMOTE_CONNECTION_CLOSED"===a.action&&(console.log(a),t.openCreateTicketForm(a.data.id,a.data.duration))})});q=!0;for(var a=0;a<x.length;a++)x[a]()});return{downloadAgent:function(a,b,c,d){if(!a)throw"CompanyId is required!";
  36. return f.get("/data/prepareDownloadAgent?companyId="+a+"&userName="+b+"&userPassword="+c).then(function(a){d&&d(a.data);400<=a.data.code||h.downloadByUrl(a.data.link)})},runScanDevices:function(a,b,c,d){if(!a)throw"scope is required!";if(!b)throw"CompanyId is required!";if(!c)throw"AgentId is required!";f.get("/devices/refreshNetworkScan?companyId="+b+"&agentId="+c).then(function(){d&&d()})},getDevicesCount:function(a,c){if(!a)throw"scope is required!";g.callbacks[a.$id]={companyId:b.getCurrentCompany().id,
  37. callback:c};g.devices&&c&&c(g.devices);return g.deviceCounter},getAgentsByCompany:function(a,b,c){if(!a)throw"scope is required!";if(!b)throw"CompanyId is required!";c&&(g.callbacks[a.$id]={companyId:b,callback:c});g.devices[b]&&c&&c(g.devices[b]);return g.devices[b]},getAllAgentsAndLogin:function(a,b){if(!a)throw"companyId is required!";var d=f({url:"/devices/getAllAgentsAndLogin?companyId="+a,method:"GET"});c.handleCallback(d,b)},getMasterAgentId:function(a,b){if(!a)throw"CompanyId is required!";
  38. f.get("/devices/getMasterAgentId?companyId="+a).then(function(a){b&&b(a.data);return a.data})},getLastScanDevices:function(a,b,d,g){if(!a)throw"scope is required!";if(!b)throw"CompanyId is required!";if(!d)throw"agentId is required!";var e=c.customizeObj({});f.get("/devices/networkScan?companyId="+b+"&agentId="+d).then(function(b){c.customizeObj(b.data,e);e.networkScan&&c.defineReadOnlyProperty(e,"networkScan",JSON.parse(e.networkScan));n.subscribe("/netScan",a,function(a){console.log(a);if("NETWORK_SCAN"===
  39. a.action)if("finished"===a.data)c.defineReadOnlyProperty(e.networkScan,"netScanStatus",a.data);else{var b=JSON.parse(a.data);a=e.networkScan.devices;var d=b.devices;c.defineReadOnlyProperty(e.networkScan,"netScanStatus",b.netScanStatus);c.defineReadOnlyProperty(e.networkScan,"lastScanDate",b.lastScanDate);for(var m in d){var b=d[m],r=c.findById(a,b.id);r?c.customizeObj(b,r):e.networkScan.devices.push(b)}}else if("REMOTE_INSTALL"===a.action){d=c.findById(e.networkScan.devices,a.data.netScanId);if(!d)for(m in e.networkScan.devices)e.networkScan.devices[m].deviceId===
  40. a.data.deviceId&&(d=e.networkScan.devices[m]);d&&("MANAGED"===a.data.status?c.defineReadOnlyProperty(d,"agentStatus","managed"):"INSTALLED"===a.data.status?c.defineReadOnlyProperty(d,"agentStatus","installed"):"ERROR"===a.data.status?c.defineReadOnlyProperty(d,"agentStatus","error"):"LOGIN_ERROR"===a.data.status?c.defineReadOnlyProperty(d,"agentStatus","login error"):"UNKNOWN"===a.data.status?c.defineReadOnlyProperty(d,"agentStatus","unknown"):"INIT"===a.data.status?c.defineReadOnlyProperty(d,"agentStatus",
  41. "init"):"IN_PROGRESS"===a.data.status&&c.defineReadOnlyProperty(d,"agentStatus","inProgress"),c.defineReadOnlyProperty(d,"message",a.data.content));(m=k[a.data.netScanId]||k[a.data.deviceId])&&"function"===typeof m&&m();(m=p[a.data.netScanId]||p[a.data.deviceId])&&"function"===typeof m&&m()}g&&g(e)});g&&g(e)},function(){g&&g(e);return e})},sendInstallAgentRequest:function(a,b,c,d,g){if(!a)throw"CompanyId is required!";if(!b)throw"agentId is required!";if(!c)throw"agentId is required!";Array.isArray(c)||
  42. (c=[c]);if(g&&"function"===typeof g)for(var e in c)k[c[e]]=g;f({url:"/devices/sendInstallAgentRequest?companyId="+a+"&agentId="+b+"&agentIfForType="+d,method:"POST",data:c})},sendUninstallAgentRequest:function(a,b,c){if(!a)throw"CompanyId is required!";if(!b)throw"agentId is required!";Array.isArray(b)||(b=[b]);if(c&&"function"===typeof c)for(var d in b)p[b[d]]=c;f({url:"/devices/sendUninstallAgentRequest?companyId="+a,method:"POST",data:b})},sendDescription:function(a,b,d,g){if(!a)throw"CompanyId is required!";
  43. if(!b)throw"agentId is required!";a=f({url:"/devices/sendDescription?companyId="+a+"&networkDeviceId="+b,method:"POST",data:d});c.handleCallback(a,g)},sendAgentUpdateRequest:function(a,b,d){if(!a)throw"CompanyId is required!";if(!b)throw"agentId is required!";Array.isArray(b)||(b=[b]);a=f({url:"/devices/sendAgentUpdateRequest?companyId="+a,method:"POST",data:b});c.handleCallback(a,d)},sendPowerAction:function(a,b,d,g){if(!a)throw"CompanyId is required!";if(!d)throw"action is required!";if(!b)throw"agentId is required!";
  44. Array.isArray(b)||(b=[b]);a=f({url:"/devices/sendPowerAction?companyId="+a+"&action="+d,method:"POST",data:b});c.handleCallback(a,g)},saveCredentials:function(a,b,d){if(!a)throw"list is required!";if(!b)throw"companyId is required!";a=f({url:"/devices/saveCredentials?companyId="+b,method:"POST",data:{credentialAgents:a}});c.handleCallback(a,d)},getCredentialsByCompany:function(a,b){if(!a)throw"companyId is required!";var c=f({url:"/devices/getAllCredentials?companyId="+a,method:"GET"});n.subscribe("/device",
  45. l,function(a){"CREDENTIALS_SAVED"===a.action&&b&&b(a.data)});b&&c.then(function(a){b(a.data)},function(a){b(a.data)})},updateAgentSettings:function(a,b){if(!a)throw"agentsSetting is required!";var d=f({url:"/devices/updateAgentSettings",method:"POST",data:a});c.handleCallback(d,b)},getAgentSettingsByCompany:function(a,b){if(!a)throw"companyId is required!";var d=f({url:"/devices/getAgentSettingsByCompany?companyId="+a,method:"GET"});c.handleCallback(d,b)},createOneTimeRemoteSession:function(a){f.get("/remote/createOneTimeRemoteSession").then(function(b){a&&
  46. a(b.data)},function(b){a&&a(b.data)})},getRemoteSessions:function(a,b){if(!a||!a.$id)throw"First argument must be Angularjs scope!";return c.getListByUrl("/remote/getRemoteSessions",b,function(b){n.subscribe("/oneTimeConnection",a,function(a){console.log(a);if("ONE_TIME_CONNECTION_CLOSED"!==a.action||a.data.id)if("ONE_TIME_DELETED"===a.action||"ONE_TIME_UNINSTALLED"===a.action)c.deleteById(b,a.data);else{var d=c.findById(b,a.data.id);d?c.customizeObj(a.data,d):b.unshift(c.customizeObj(a.data))}})})},
  47. getSessionId:function(a,b,c){if(!a)throw"remoteSessionId is required!";if(!b)throw"connectionType is required!";f.get("/devices/getSessionId?remoteSessionId="+a+"&connectionType="+b).then(function(a){c&&c(a.data)},function(a){c&&c(a.data)})},createRemoteSession:function(a,b,c,d){if(!a)throw"deviceId is required!";if(!b)throw"companyId is required!";if(!c)throw"connectionType is required!";f.get("/remote/createRemoteSession?deviceId="+a+"&connectionType="+c+"&companyId="+b).then(function(a){d&&d(a.data)},
  48. function(a){d&&d(a.data)})},deleteRemoteSession:function(a,b){if(!a)throw"ids is required!";Array.isArray(a)||(a=[a]);var d=f({url:"/remote/deleteRemoteSession",method:"POST",data:a});c.handleCallback(d,b)},_addInitListener:function(a){a&&(q?a():x.push(a))}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("EmailSettingsService",["$http","$rootScope","RealTimeService","Utils","$filter",function(f,t,n,c){return{saveNumberForm:function(e,h,b){if(!e)throw"data is required!";if(!h)throw"type is required!";e.type=h;e=f({url:"/settings/emailPages/updateNumberForm",method:"PUT",data:e});c.handleCallback(e,b)},getCompanyEmailNotification:function(e){var h={};f.get("/settings/emailPages/emailNotifications").then(function(b){c.customizeObj(b.data,h);e&&
  49. e(b.data)},function(b){e&&e(b.data)});return h},getEmailSettingPageDto:function(e,h){if(!e)throw"scope is required!";var b=c.customizeObj({});f.get("/settings/emailPages/").then(function(a){c.customizeObj(a.data,b);h&&h(a.data)},function(a){h&&h(a.data)});n.subscribe("/companyEmailNotification",e,function(a){console.log(a);"COMPANY_EMAIL_NOTIFICATION"==a.action&&c.customizeObj(a.data,b.activeAndNotDefault)});return b},getTermsAndConditions:function(e){var h={};f.get("/settings/emailPages/termsAndConditions").then(function(b){c.customizeObj(b.data,
  50. h);e&&e(b.data)},function(b){e&&e(b.data)});return h},setToDefaultTemplate:function(e,h){if(!e)throw"type is required!";var b=f({url:"/settings/emailPages/toDefaultTemplate/"+e,method:"POST"});c.handleCallback(b,h)},getTemplate:function(e,h){if(!e)throw"type is required!";var b={};f.get("/settings/emailPages/byType/"+e).then(function(a){c.customizeObj(a.data,b);h&&h(a.data)},function(a){h&&h(a.data)});return b},saveEmailTemplate:function(e,h,b){if(!e)throw"data is required!";if(!e.subject)throw"data.subject is required!";
  51. if(!e.body)throw"data.body is required!";if(!h)throw"type is required!";e=f({url:"/settings/emailPages/updateTemplate/"+h,method:"PUT",data:e});c.handleCallback(e,b)}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("FilesService",["$http","$rootScope","RealTimeService","Utils","$filter",function(f,t,n,c){return{create:function(c,h,b,a,d){if(!c)throw"file is required!";var g={},l=new FormData;l.append("file",c);c=new XMLHttpRequest;c.upload.addEventListener("progress",h,!1);c.addEventListener("load",function(a){a=angular.fromJson(a.currentTarget.responseText);for(var c in a)g[c]=a[c];b&&b(g)},!1);c.addEventListener("error",a,!1);c.open("POST","/file?isAvatar="+
  52. !!d);c.send(l);return g},createImageFromBase64Url:function(c,h){if(!c)throw"base64Url is required!";var b={};f({url:"/base64image",method:"POST",data:c.substring(22,c.length)}).then(function(a){for(var c in a.data)b[c]=a.data[c];h&&h(b)});return b},getMetadata:function(c,h){if(!c)throw"fileId is required!";var b={id:c};f.get("/file/"+c+"/meta").then(function(a){for(var c in a.data)b[c]=a.data[c];h&&h(b)},function(a){h&&h(a.data)});return b},remove:function(c,h){if(!c)throw"fileId is required!";f({url:"/file/"+
  53. c,method:"DELETE"}).then(function(b){h&&h(b.data)},function(b){h&&h(b.data)})},cropAvatar:function(c,h){if(!c)throw"image is required!";f({url:"/file/cropImage",method:"POST",data:c}).then(function(b){h&&h(b.data)},function(b){h&&h(b.data)})}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("ProductsService",["$http","$rootScope","RealTimeService","Utils","CompaniesService",function(f,t,n,c,e){return{search:function(c){if(!c)throw"Keyword is required!";return f.get("/products/search?keyword="+c).then(function(b){return b.data})},getFullListForAutocomplete:function(c){var b=[];f.get("/products/fullList").then(function(a){a.data.forEach(function(a){b.push(a)});c&&c()});return b},getCategories:function(e,b){if(!e||!e.$id)throw"First argument must be Angularjs scope!";
  54. return c.getListByUrl("/products/categories",b,function(a){n.subscribe("/productCategory",e,function(b){console.log(b);if("PRODUCT_CATEGORY_SAVED"==b.action){var g=c.findById(a,b.data.id);g?c.customizeObj(b.data,g):a.push(c.customizeObj(b.data))}else"PRODUCT_CATEGORY_DELETED"==b.action&&(c.deleteById(a,b.data.id),e.$broadcast("product_category_deleted",b.data))})})},saveCategory:function(e,b){if(!e)throw"category is required!";var a="/products/categories",d="POST";e.id&&(a+="/"+e.id,d="PUT");a=f({url:a,
  55. method:d,data:e});c.handleCallback(a,b)},deleteCategory:function(e,b){if(!e)throw"categoryId is required argument!";var a=f({url:"/products/categories/"+e,method:"DELETE"});c.handleCallback(a,b)},saveProduct:function(e,b){if(!e)throw"product is required!";var a="POST";e.id&&(a="PUT");a=f({url:"/products",method:a,data:e});c.handleCallback(a,b)},changeTaxableStatus:function(e,b,a){if(!e)throw"ids is required argument!";if(b===v)throw"toTaxable is required argument!";Array.isArray(e)||(e=[e]);e=f({url:"/products/changeTaxableStatus?toTaxable="+
  56. !!b,method:"POST",data:e});c.handleCallback(e,a)},deleteProduct:function(e,b){if(!e)throw"productId is required argument!";var a=f({url:"/products/"+e,method:"DELETE"});c.handleCallback(a,b)},isILCUnique:function(e,b,a){if(!e)throw"ilc is required!";var d=c.customizeObj({});f.get("/products/isILCUnique?ilc="+e+"&id="+b).then(function(b){c.customizeObj(b.data,d);a&&a(b.data)},function(b){a&&a(b.data)});return d},isMfgUnique:function(e,b,a){if(!e)throw"manufacture is required!";var d=c.customizeObj({});
  57. f.get("/products/isMfgUnique?manufacture="+e+"&id="+b).then(function(b){c.customizeObj(b.data,d);a&&a(b.data)},function(b){a&&a(b.data)});return d},moveProducts:function(e,b,a){if(!e)throw"categoryId is required argument!";if(!b)throw"productIds is required argument!";Array.isArray(b)||(b=[b]);e=f({url:"/products/moveProduct?categoryId="+e,method:"POST",data:b});c.handleCallback(e,a)},getAllProducts:function(e,b){if(!e)throw"scope is required!";var a={list:[],categories:[]};c.getListByUrl("/products/categories",
  58. b,function(d){for(var g=0;g<d.length;g++)d[g].productsList=[],a.categories.push(d[g]);n.subscribe("/productCategory",e,function(d){console.log(d);if("PRODUCT_CATEGORY_SAVED"==d.action){var g=c.findById(a.categories,d.data.id);if(g)for(c.customizeObj(d.data,g),g=0;g<a.list.length;g++)a.list[g].category.id===d.data.id&&c.customizeObj(d.data,a.list[g].category);else d.data.productsList=[],a.categories.push(c.customizeObj(d.data))}else if("PRODUCT_CATEGORY_DELETED"==d.action){c.deleteById(a.categories,
  59. d.data.id);e.$broadcast("product_category_deleted",d.data);for(var p=[],g=0;g<a.list.length;g++)a.list[g].category.id===d.data.id&&p.push(a.list[g].versionedId.id);for(g=0;g<p.length;g++)c.deleteById(a.list,p[g])}b&&b(a)})});f.get("/products/full").then(function(d){a.list=d.data;for(d=0;d<a.list.length;d++){var g=c.findById(a.categories,a.list[d].category.id);g.productsList.push(a.list[d])}b&&b(c.customizeObj(a));n.subscribe("/product",e,function(d){console.log(d);if("PRODUCT_SAVED"==d.action){var k=
  60. c.findById(a.list,d.data.versionedId.id);if(k){if(k.category.id!==d.data.category.id){var p=c.findById(a.categories,k.category.id);c.deleteById(p.productsList,k.versionedId.id);c.findById(a.categories,d.data.category.id).productsList.push(k)}c.customizeObj(d.data,k)}}else"PRODUCT_DELETED"==d.action&&(c.deleteById(a.list,d.data.versionedId.id),g=c.findById(a.categories,d.data.category.id),c.deleteById(g.productsList,d.data.versionedId.id),e.$broadcast("product_deleted",d.data));b&&b(a)})},function(a){b&&
  61. b(a.data)})}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("RealTimeService",["$http","$timeout","$rootScope",function(f,t,n){function c(){f.post("/realTime/createWatcher").success(function(b){a=b.id;if(0<d.length){for(b=0;b<d.length;b++){var c=d[b];k.subscribe(c.url,c.scope,c.callback)}d=[]}h()}).error(function(a,b,c,d){console.error("Cannot receive watcher Id !!!",a,b,c,d);throw"Cannot initialize RealTimeService";})}function e(){a=v;for(var b in l){var g=l[b];g&&!g.scope.$$destroyed&&d.push(g)}l=
  62. {};c()}function h(){0<g?t(h,300):f.post("/realTime/watch/"+a,Object.keys(l)||[],{timeout:22E5}).then(function(a){a.data||console.log("No Date in response!");console.log(a.data);if("timeout"==a.data||"destroyed"==a.data.message||205==a.status)e();else if("unauthorized"===a.data.errorMessage||"unauthorized"===a.data.authMessage||"userDisabled"===a.statusText)"userDisabled"===a.statusText&&alert("Your account has been disabled."),u.location.pathname="/logout";else{for(var b in a.data){var c=l[b];if(c&&
  63. !c.scope.$$destroyed){var d=a.data[b];if(d)for(var g=0;g<d.length;g++)c.callback(d[g])}}h()}},function(a){a&&0!==a.status?205==a.status?e():(console.log("ERRRORRR!!!!!!!!!!!!",a),t(h,300)):(console.log("ERRRORRR?????",a),t(e,1E3))})}function b(a){for(var c in l){var d=l[c];d&&!d.scope.$$destroyed&&d.callback!==b&&d.callback(a)}"COMPANY_ARCHIVED"!==a.action&&"COMPANY_DEARCHIVED"!==a.action||n.$broadcast(a.action.toLowerCase(),a.data.id)}var a,d=[{url:"/global",scope:n,callback:b}],g=0,l={};c();var k=
  64. {subscribe:function(b,c,k){a?(g++,f.get("/realTime/subscribe/"+a+b).success(function(a){g--;l[a.id]={url:b,scope:c,callback:k};c.$on("$destroy",function(){delete l[a.id]})}).error(function(a,f,m,l){g--;205==f&&(d.push({url:b,scope:c,callback:k}),n.isLogOut||e());console.error("Cannot subscribe on "+b,a,f,m,l)})):d.push({url:b,scope:c,callback:k})}};return k}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("ReceiptArchiveService",["$http","$rootScope","RealTimeService","Utils","$filter",function(f,t,n,c){return{getReceiptArchiveData:function(e,h){if(!e||!e.$id)throw"First argument must be Angularjs scope!";var b=c.customizeObj({list:[],companies:{}});f.get("/receiptArchive").then(function(a){c.customizeArray(a.data,b.list);b.list.forEach(function(a){var g=b.companies[a.companyId];g?g.push(a):c.defineReadOnlyProperty(b.companies,a.companyId,c.customizeArray([a]))});
  65. n.subscribe("/receiptArchive",e,function(a){console.log(a);if("RECEIPT_ARCHIVE_ADDED"===a.action){for(var g=[],e=0;e<a.data.length;e++){var k=a.data[e],f;if(k.recurringInvoice){var h=c.findById(b.list,k.recurringInvoice.id);h?(c.defineReadOnlyProperty(h,"invoicesCount",h.invoicesCount+1),c.defineReadOnlyProperty(h,"sum",h.sum+k.sum),k.date>h.date&&(c.defineReadOnlyProperty(h,"date",k.date),c.defineReadOnlyProperty(h,"paidOn",k.paidOn))):f=c.customizeObj({id:k.recurringInvoice.id,isRecurring:!0,frequency:k.recurringInvoice.frequency,
  66. number:k.recurringInvoice.number,companyId:k.company.id,date:k.date,paidOn:k.paidOn,sum:k.sum,invoicesCount:1})}else f=c.customizeObj({id:k.id,isRecurring:!1,frequency:null,number:k.number,companyId:k.company.id,date:k.date,paidOn:k.paidOn,sum:k.sum,invoicesCount:null});f&&(b.list.push(f),(k=b.companies[f.companyId])?k.push(f):c.defineReadOnlyProperty(b.companies,f.companyId,c.customizeArray([f])),0>g.indexOf(f.companyId)&&g.push(f.companyId))}b.list.sort(c.getComparatorBy("number"));g.forEach(function(a){b.companies[a].sort(c.getComparatorBy("number"))})}else if("COMPANY_ARCHIVED"===
  67. a.action){for(e=0;e<b.list.length;e++)b.list[e].companyId===a.data.id&&(b.list.splice(e,1),e--);delete b.companies[a.data.id]}});h&&h(a.data)},function(a){h&&h(a.data)});return b}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("ReceivableService",["$http","$rootScope","RealTimeService","CompaniesService","Utils","$filter",function(f,t,n,c,e){function h(b,a){if(!b)throw"invoiceIds is required!";var c=f({url:"/receivable/resend",method:"POST",data:b});e.handleCallback(c,a)}return{getReceivedPaymentsSumByCompany:function(b,a,c){if(!b)throw"companyId is required!";if(!a||!a.$id)throw"Second argument must be Angularjs scope!";var g=e.customizeObj({});f.get("/receivable/paymentSum/"+
  68. b).then(function(f){e.customizeObj(f.data,g);n.subscribe("/companyPaymentReceived?targetId="+b,a,function(a){console.log(a);"COMPANY_PAYMENT_RECEIVED"===a.action?(e.defineReadOnlyProperty(g,"value",g.value+a.data),c&&c(g)):"RECEIVED_PAYMENTS_SUM"===a.action&&e.defineReadOnlyProperty(g,"value",a.data)});c&&c(f.data)},function(a){c&&c(a.data)});return g},getReceivableGraphData:function(b,a){var d=e.customizeArray([]);f.get("/receivable/chart/lastDays").then(function(g){e.customizeArray(g.data,d);n.subscribe("/todayReceivableChartPoint?targetId="+
  69. c.getCurrentCompany().id,b,function(a){console.log(a);if("TODAY_RECEIVABLE_CHART_POINT"===a.action){var b=d[d.length-1],c=new Date(b.date),g=new Date(a.data.date);c.getFullYear()===g.getFullYear()&&c.getMonth()===g.getMonth()&&c.getDate()+1===g.getDate()?(d.push(e.customizeObj(a.data)),d.splice(0,1)):e.customizeObj(a.data,b)}});a&&a(g.data)},function(b){a&&a(b.data)});return d},getReceivableInvoicesData:function(b,a){if(!b||!b.$id)throw"First argument must be Angularjs scope!";var c=e.customizeObj({list:[],
  70. companies:{}});f.get("/receivable").then(function(g){for(var f=e.customizeArray([]),k=0;k<g.data.length;k++){var p=e.customizeObj(g.data[k]);if(p.recurringInvoice){var h=e.findById(f,p.recurringInvoice.id);h&&1!=h.invoices.length||(h=p.recurringInvoice,e.defineReadOnlyProperty(h,"isRecurring",!0),e.defineReadOnlyProperty(h,"company",p.company),e.defineReadOnlyProperty(h,"number",p.number),e.defineReadOnlyProperty(h,"invoices",e.customizeArray([])),f.push(h));e.defineReadOnlyProperty(p,"recurringInvoice",
  71. {id:h.id,frequency:h.frequency});h.invoices.push(p)}else f.push(p)}f.sort(e.getComparatorBy("number"));for(k=0;k<f.length;k++)p=f[k],c.companies[p.company.id]||e.defineReadOnlyProperty(c.companies,p.company.id,e.customizeArray([])),c.companies[p.company.id].push(p);e.defineReadOnlyProperty(c,"list",f);n.subscribe("/receivableInvoice",b,function(a){console.log(a);if("INVOICE_SAVED"==a.action){var b=a.data,g;b.recurringInvoice?(a=e.findById(c.list,b.recurringInvoice.id),a||(a=b.recurringInvoice,a.isRecurring=
  72. !0,a.company=b.company,a.invoices=[],g=a),b.recurringInvoice={id:a.id,frequency:a.frequency},a.invoices.push(b)):g=b;g&&(g=e.customizeObj(g),c.companies[g.company.id]||e.defineReadOnlyProperty(c.companies,g.company.id,[]),c.companies[g.company.id].push(g),c.list.push(g))}else if("INVOICE_STATUS"===a.action)a.data.recurringInvoice?((b=e.findById(c.list,a.data.recurringInvoice.id))||console.error("!!!!!!!----ATEMPT TO CHANGE STATUS OF UNEXISTING RECURRING INVOICE-----!!!!!!!"),b=e.findById(b.invoices,
  73. a.data.id)):b=e.findById(c.list,a.data.id),b?e.defineReadOnlyProperty(b,"status",a.data.status):console.error("!!!!!!!----ATEMPT TO CHANGE STATUS OF UNEXISTING INVOICE-----!!!!!!!!");else if("PAYMENT_RECEIVED"===a.action)for(a=a.data,b=0;b<a.length;b++){var m=a[b],k=v;g=v;for(var f=0;f<c.list.length&&!g;f++){var h=c.list[f];if(h.isRecurring)for(var l=0;l<h.invoices.length&&!g;l++){var p=h.invoices[l];m===p.id&&(h.invoices.splice(l,1),g=p.company.id,k=h.id,0===h.invoices.length&&c.list.splice(f,1))}else m===
  74. h.id&&(c.list.splice(f,1),g=h.company.id)}g&&c.companies[g]&&(f=c.companies[g],k?(k=e.indexOfId(f,k),-1<k&&(-1<e.indexOfId(f[k].invoices,m)&&f[k].invoices.splice(k,1),0===f[k].invoices.length&&f.splice(k,1))):(m=e.indexOfId(f,m),-1<m&&f.splice(m,1)),0===f.length&&delete c.companies[g])}});a&&a(g.data)},function(b){a&&a(b.data)});return c},receivePayment:function(b,a,c){if(!b)throw"paymentMethod is required!";if(!a||0===a.length)throw"invoiceIds is required!";b=f({url:"/receivable/receivePayment",
  75. method:"POST",params:{paymentMethod:b.toUpperCase()},data:a});e.handleCallback(b,c)},resendInvoice:function(b,a){if(!b)throw"invoiceId is required!";h([b],a)},resendInvoices:h,search:function(b){if(!b)throw"Keyword is required!";return f.get("/receivable/search?keyword="+b).then(function(a){return a.data})}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("RecurringService",["$http","$rootScope","RealTimeService","CompaniesService","Utils","$filter",function(f,t,n,c,e){function h(a,b,c,h){if(!b)throw"recurringInvoiceId is required!";if(!c)throw"expense is required!";a={url:"/recurringInvoice/"+b+"/"+a,data:c};c.id?(a.method="PUT",a.url=a.url+"/"+c.id):a.method="POST";c=f(a);e.handleCallback(c,h)}function b(a,b,c){if(!a)throw"recurringInvoiceId is required!";if(!b)throw"expenseId is required!";
  76. a=f({url:"/recurringInvoice/"+a+"/expense/"+b,method:"DELETE"});e.handleCallback(a,c)}return{getRecurringGraphData:function(a,b){var c=["WEEKLY","MONTHLY","YEARLY"],h=e.customizeArray([]);f.get("/recurringInvoice/billed/lastDays").then(function(k){e.customizeArray(k.data,h);n.subscribe("/recurringChart",a,function(a){console.log(a);if("RECURRING_CHART"===a.action){for(var b=new Date(a.data.date),d=0;d<h.length;d++){var k=h[d],f=new Date(k[k.length-1].date);f.getFullYear()===b.getFullYear()&&f.getMonth()===
  77. b.getMonth()&&f.getDate()+1===b.getDate()&&(k.push(e.customizeObj({date:e.formatDate(b),sum:0})),k.splice(0,1))}b=c.indexOf(a.data.type);b=h[b];e.defineReadOnlyProperty(b[b.length-1],"sum",a.data.sum)}});b&&b(k.data)},function(a){b&&b(a.data)});return h},getRecurringCompanies:function(a,b){if(!a||!a.$id)throw"First argument must be Angularjs scope!";var c=[];f({url:"/recurringInvoice/total",method:"GET"}).then(function(f){e.customizeArray(f.data,c);n.subscribe("/recurringTotal",a,function(a){console.log(a);
  78. if("CLIENT_RECURRING_TOTAL"===a.action){var b=e.indexOfId(c,a.data.id);if(0===a.data.total)-1<b&&c.splice(b,1);else if(-1<b)e.customizeObj(a.data,c[b]);else{for(var b=!0,d=0;d<c.length;d++)c[d].company.id===a.data.company.id&&(c[d].id=a.data.id,c[d].total=a.data.total,c[d].invoicesCount=a.data.invoicesCount,b=!1);b&&c.push(e.customizeObj(a.data))}}});b&&b(f.data)},function(a){b&&b(a.data)});return c},getCompanyRecurringInvoices:function(a,b,c){if(!a)throw"companyId is required!";if(!b||!b.$id)throw"Second argument must be Angularjs scope!";
  79. var h=[];f.get("/recurringInvoice?companyId="+a).then(function(f){e.customizeArray(f.data,h);n.subscribe("/recurring?targetId="+a,b,function(a){console.log(a);if("RECURRING_SAVED"==a.action){var b=e.findById(h,a.data.id);b?e.customizeObj(a.data,b):h.push(e.customizeObj(a.data))}else"RECURRING_DELETE"==a.action&&(a=e.indexOfId(h,a.data.id),-1<a&&h.splice(a,1))});c&&c(f.data)},function(a){c&&c(a.data)});return h},getAll:function(a,b){if(!a||!a.$id)throw"Second argument must be Angularjs scope!";var c=
  80. [];f.get("/recurringInvoice/getAll").then(function(f){e.customizeArray(f.data,c);n.subscribe("/recurring",a,function(a){console.log(a);if("RECURRING_SAVED"==a.action){var f=e.findById(c,a.data.id);f?e.customizeObj(a.data,f):c.unshift(e.customizeObj(a.data))}else"RECURRING_DELETE"==a.action&&e.deleteById(c,a.data.id);b&&b(c)});b&&b(c)});return c},saveRecurringOrder:function(a,b){if(!a)throw"order must be!";var c=f({url:"/recurringInvoice/saveRecurringOrder",method:"POST",data:a});e.handleCallback(c,
  81. b)},createRecurringInvoice:function(a,b,c){if(!a)throw"recurringInvoice is required!";if(!b)throw"companyId is required!";a.company={id:b};a=f({url:"/recurringInvoice",method:"POST",data:a});e.handleCallback(a,c)},deleteRecurringInvoice:function(a,b){if(!a)throw"recurringInvoiceId is required!";var c=f({url:"/recurringInvoice/"+a,method:"DELETE"});e.handleCallback(c,b)},deleteAllRecurringInvoicesByCompany:function(a,b,c){if(!a)throw"companyId is required!";var h=f({url:"/recurringInvoice/company/"+
  82. a,method:"DELETE"});e.handleCallback(h,function(e){if(b)for(var f=0;f<b.length;f++)b[f].company.id===a&&(b.splice(f,1),f--);c&&c(e.data)})},saveRecInvProductExpense:function(a,b,c){h("productExpense",a,b,c)},saveRecInvServiceExpense:function(a,b,c){h("serviceExpense",a,b,c)},deleteProductExpenseFromRecInv:function(a,c,e){b(a,c,e)},deleteServiceExpenseFromRecInv:function(a,c,e){b(a,c,e)},search:function(a){if(!a)throw"Keyword is required!";return f.get("/recurringInvoice/search?keyword="+a).then(function(a){return a.data})},
  83. addCompany:function(a,b){if(!a)throw"recurring is required!";if(!b)throw"companyId is required!";for(var e=0;e<a.length;e++)if(a[e].company.id===b)return;a.push({company:c.getOneById(b),total:0,ticketsCount:0})}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("RightPanelService",["$http","$rootScope","RealTimeService","Utils","CompaniesService","UsersService","DevicesService",function(f,t,n,c,e,h,b){function a(){l.groupedData.splice(0,l.groupedData.length);for(var a=e.getClientCompanies(),c=0;c<a.length;c++){var d=a[c];l.groupedData.push({company:d,users:h.getAllByCompanyId(d.id),devices:b.getAgentsByCompany(g,d.id)})}}function d(a,b){if(!a||!a.$id)throw"First argument must be Angularjs scope!";
  84. var d=l.lists[a.$id];if(!d)throw"There is no activities list for scope "+a.$id;d.loadingInProcess?console.log("Loading tickets already in process"):(0<d.list.length&&(d.params.createdAt=d.list[d.list.length-1].createdAt),d.loadingInProcess=!0,f({method:"GET",url:"/activity/",params:d.params}).then(function(a){a&&(c.customizeArray(a.data,d.list),d.loadingInProcess=!1,b&&b(a.data));d.loadingInProcess=!1},function(a){d.loadingInProcess=!1;b&&b(a.data)}))}var g=t.$new(),l={lists:{},recentActivities:{},
  85. groupedData:[]};c.customizeObj(l);e._addAmountChangeListener(a);return{getActivities:function(a,b,e){if(!a||!a.$id)throw"First argument must be Angularjs scope!";var g=c.customizeObj([]),f=!l.lists[a.$id];l.lists[a.$id]={params:b,scope:a,list:g};d(a,function(b){f&&n.subscribe("/activity",a,function(b){console.log(b);"ACTIVITY_CREATED"==b.action&&l.lists[a.$id].list.unshift(c.customizeObj(b.data))});e&&e(b)});a.$on("$destroy",function(){delete l.lists[a.$id]});return g},getRecentActivities:function(a,
  86. b,d){if(!a||!a.$id)throw"First argument must be Angularjs scope!";b.keyword="";var e=c.customizeObj([]);l.recentActivities[a.$id]={params:b,scope:a,list:e};f({method:"GET",url:"/activity/",params:b}).then(function(a){a&&(c.customizeArray(a.data,e),d&&d(a.data))},function(a){d&&d(a.data)});n.subscribe("/activity",a,function(a){console.log(a);"ACTIVITY_CREATED"==a.action&&(e.unshift(c.customizeObj(a.data)),e.pop())});a.$on("$destroy",function(){delete l.lists[a.$id]});return e},loadMoreActivities:d,
  87. getClientCompaniesGroupedData:function(c){b._addInitListener(function(){0==l.groupedData.length&&a();n.subscribe("/device",g,function(b){"DEVICE_INSTALLED"===b.action&&(a(),c&&c(l.groupedData))});c&&c(l.groupedData);return l.groupedData})},getOneCompanyGroupedData:function(a){return{company:e.getOneById(a),users:h.getAllByCompanyId(a),devices:b.getAgentsByCompany(g,a)}},getCurrentUserInfo:function(a,b){if(!a||!a.$id)throw"First argument must be Angularjs scope!";var d=c.customizeObj({});f.get("/userInfo").then(function(a){c.customizeObj(a.data,
  88. d);b&&b(a.data)},function(a){b&&b(a.data)});n.subscribe("/rightBarUserInfo",a,function(a){console.log(a);"RB_USER_INFO"==a.action&&c.customizeObj(a.data,d)});return d},getClientCompanyInfo:function(a,b,d){if(!a||!a.$id)throw"First argument must be Angularjs scope!";if(!b)throw"companyId is required!";var e=c.customizeObj({});f.get("/companyInfo/"+b).then(function(a){c.customizeObj(a.data,e);d&&d(a.data)},function(a){d&&d(a.data)});n.subscribe("/rightBarCompanyInfo?targetId="+b,a,function(a){console.log(a);
  89. "RB_COMPANY_INFO"==a.action&&c.customizeObj(a.data,e)});return e}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("ServicesService",["$http","$rootScope","RealTimeService","Utils","CompaniesService",function(f,t,n,c,e){function h(b,a){var d=a.company.id;d===e.getCurrentCompany().id&&(d="default");b[d]||c.defineReadOnlyProperty(b,d,[]);var g=c.findById(b[d],a.id);g?c.customizeObj(a,g):b[d].push(c.customizeObj(a))}return{search:function(b){if(!b)throw"Keyword is required!";return f.get("/services/search?keyword="+b).then(function(a){return a.data})},getAllByCompany:function(b,
  90. a,d){if(!b||!b.$id)throw"First argument must be Angularjs scope!";if(!a||"[object Function]"===Object.prototype.toString.call(a))throw"companyId is required argument!";return c.getListByUrl("/services/"+a,d,function(a){})},getServicesData:function(b,a,d){function e(a){var b;a:{b=l;var d=a.versionedId.id,g;for(g in b)if("staticCopy"!=g){var f=c.findById(b[g],d);if(f){b=f;break a}}b=void 0}b?c.customizeObj(a,b):h(l,a)}if(!b||!b.$id)throw"First argument must be Angularjs scope!";var l=c.customizeObj({}),
  91. k="/services";a&&(k+="/getDefaultServices");f.get(k).then(function(a){for(var b=0;b<a.data.length;b++)h(l,a.data[b]);d&&d(a.data)},function(a){d&&d(a.data)});n.subscribe("/service",b,function(a){console.log(a);if("SERVICE_SAVED"==a.action)e(a.data);else if("SERVICE_LIST_SAVED"==a.action)for(var b=0;b<a.data.length;b++)e(a.data[b]);else if("SERVICES_MOVED"==a.action)for(b=0;b<a.data.length;b++)h(l,a.data[b]);else if("COMPANY_SERVICES_DELETED"==a.action)delete l[a.data.id];else if("SERVICES_DELETED"==
  92. a.action)for(b=0;b<a.data.length;b++){var d=a.data[b].versionedId.id,f=l,k=void 0;for(k in f){var m=c.indexOfId(f[k],d);-1<m&&f[k].splice(m,1)}}});return l},save:function(b,a){if(!b)throw"service is required!";var d="/services",e="POST";b.id&&(e="PUT",d=d+"/"+b.id);d=f({url:d,method:e,data:b});c.handleCallback(d,a)},saveList:function(b,a,d){if(!b)throw"services is required!";if(!a)throw"companyId is required!";b=f({url:"/services/saveList/"+a,method:"POST",data:{serviceDtoList:b}});c.handleCallback(b,
  93. d)},addCompanyToServiceData:function(b,a){if(!b)throw"data argument is required";if(!a)throw"companyId argument is required";b[a]||c.defineReadOnlyProperty(b,a,[])},deleteCompanyFromServiceData:function(b,a){if(0<b[a].length)throw"This action cannot be performed on company that has not empty services list! Use deleteCompany() method.";delete b[a]},deleteService:function(b,a){if(!b)throw"serviceId is required argument!";var d=f({url:"/services/"+b,method:"DELETE"});c.handleCallback(d,a)},deleteCompany:function(b,
  94. a){if(!b)throw"companyId is required argument!";var d=f({url:"/services/company/"+b,method:"DELETE"});c.handleCallback(d,a)},move:function(b,a){if(!b)throw"mapping is required argument!";var d=f({url:"/services/move",method:"POST",data:b});c.handleCallback(d,a)},getActualMapping:function(b){var a={},c;for(c in b)if("default"!=c&&"staticCopy"!=c){for(var e=[],f=b[c],h=0;h<f.length;h++)e.push(f[h].originService.versionedId.id);a[c]=e}return a},changeBillableStatus:function(b,a,d){if(!b)throw"ids is required argument!";
  95. if(a===v)throw"toBillable is required argument!";Array.isArray(b)||(b=[b]);b=f({url:"/services/changeBillableStatus?toBillable="+!!a,method:"POST",data:b});c.handleCallback(b,d)}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("StatisticsService",["$http","$rootScope","RealTimeService","Utils","CompaniesService","UsersService",function(f,t,n,c,e,h){return{getResolvedTicketsCountByCompany:function(b,a,d){if(!b)throw"companyId is required!";if(!a||!a.$id)throw"Second argument must be Angularjs scope!";var e=c.customizeObj({});f.get("/statistic/tickets/resolvedCount/"+b).then(function(f){c.customizeObj(f.data,e);n.subscribe("/resolvedTicketsCount?targetId="+b,a,function(a){console.log(a);
  96. "RESOLVED_TICKETS_COUNT"===a.action&&c.defineReadOnlyProperty(e,"value",a.data)});d&&d(f.data)},function(a){d&&d(a.data)});return e},getSubmittedTicketsByCompany:function(b,a,d){var g={};if(e.getCurrentCompany()===b){var f=h.getClientUsers,k;for(k in f){var p=f[k].userStatistic||{ticketsSubmitted:0};g[f[k].company.id]=g[f[k].company.id]?g[f[k].company.id]+(p.ticketsSubmitted||0):p.ticketsSubmitted||0}}else for(k in f=h.getAllByCompanyId(b),g[b]=0,f)p=f[k].userStatistic||{ticketsSubmitted:0},g[b]+=
  97. p.ticketsSubmitted||0;g=c.customizeObj(g);d&&d(g);n.subscribe("/userSubmittedTicket",a,function(a){"USER_SUBMITTED_TICKET"===a.action&&(a=h.getOneById(a.data),g[a.company.id]&&c.defineReadOnlyProperty(g,[a.company.id],g[a.company.id]+1),d&&d(g))})},getTicketsResolutionTimeChartDataByCompany:function(b,a,d){if(!b)throw"companyId is required!";if(!a||!a.$id)throw"Second argument must be Angularjs scope!";var e=c.customizeObj({});f.get("/statistic/tickets/resolutionTime/"+b).then(function(f){c.customizeObj(f.data,
  98. e);n.subscribe("/ticketsResolutionTimeChart?targetId="+b,a,function(a){console.log(a);"TICKETS_RESOLUTION_TIME_CHART"===a.action&&c.customizeObj(a.data,e)});d&&d(f.data)},function(a){d&&d(a.data)});return e},getTimeBilledByCompany:function(b,a,d){if(!b)throw"companyId is required!";if(!a||!a.$id)throw"Second argument must be Angularjs scope!";var e=c.customizeObj({});f.get("/statistic/billed/time/"+b).then(function(f){c.customizeObj(f.data,e);n.subscribe("/billedTimeStatistic?targetId="+b,a,function(a){console.log(a);
  99. "BILLED_TIME_STATISTIC"===a.action&&c.defineReadOnlyProperty(e,"value",a.data)});d&&d(f.data)},function(a){d&&d(a.data)});return e},getReceivableAmountByCompany:function(b,a,d){if(!b)throw"companyId is required!";if(!a||!a.$id)throw"Second argument must be Angularjs scope!";var e=c.customizeObj({});f.get("/statistic/companies/receivable/"+b).then(function(f){c.customizeObj(f.data,e);n.subscribe("/todayReceivableChartPoint?targetId="+b,a,function(a){console.log(a);"TODAY_RECEIVABLE_CHART_POINT"===
  100. a.action&&c.defineReadOnlyProperty(e,"value",a.data.receivableLeft);d&&d(e)});d&&d(f.data)},function(a){d&&d(a.data)});return e},getContributedToEarningTopCompanies:function(b,a,d){if(!b)throw"topAmount is required!";if(!a||!a.$id)throw"Second argument must be Angularjs scope!";var e=c.customizeObj({});f.get("/statistic/companies/paymentSum/top/"+b).then(function(b){function f(b){n.subscribe("/companyPaymentReceived?targetId="+b,a,function(a){console.log(a);"COMPANY_PAYMENT_RECEIVED"===a.action&&
  101. c.defineReadOnlyProperty(e,b,(e[b]?e[b]:0)+a.data)})}for(var h in b.data)f(h);c.customizeObj(b.data,e);d&&d(b.data)},function(a){d&&d(a.data)});return e},getTopCompaniesByResolvedTickets:function(b,a,d){if(!b)throw"topAmount is required!";if(!a||!a.$id)throw"Second argument must be Angularjs scope!";var e=c.customizeObj({});f.get("/statistic/companies/resolvedTicket/top/"+b).then(function(b){function f(b){n.subscribe("/resolvedTicketsCount?targetId="+b,a,function(a){console.log(a);"RESOLVED_TICKETS_COUNT"===
  102. a.action&&c.defineReadOnlyProperty(e,b,a.data)})}for(var h in b.data)f(h);c.customizeObj(b.data,e);d&&d(b.data)},function(a){d&&d(a.data)});return e},getTotalEarningsByDays:function(b,a,d,e,h){if(!b)throw"companyId is required!";if(!a)throw"from date is required!";if(!d)throw"to date is required!";if(a.getTime()>d.getTime())throw"from date should be less that to date!";if(!e||!e.$id)throw"Angularjs scope is required!";var k=c.customizeObj({});f.get("/statistic/companies/paymentSum/receivedInterval/"+
  103. b+"?from="+c.formatDate(a)+"&to="+c.formatDate(d)).then(function(a){var d,f;for(f in a.data)d?(new Date(f)).getTime()>(new Date(d)).getTime()&&(d=f):d=f;var r=new Date(d);c.customizeObj(a.data,k);n.subscribe("/companyPaymentReceived?targetId="+b,e,function(a){console.log(a);if("COMPANY_PAYMENT_RECEIVED"===a.action){var b=new Date;r.getFullYear()===b.getFullYear()&&r.getMonth()===b.getMonth()&&r.getDate()===b.getDate()&&c.defineReadOnlyProperty(k,d,k[d]+a.data)}});h&&h(a.data)},function(a){h&&h(a.data)});
  104. return k},getTotalReceivableByDays:function(b,a,d,e,h){if(!b)throw"companyId is required!";if(!a)throw"from date is required!";if(!d)throw"to date is required!";if(a.getTime()>d.getTime())throw"from date should be less that to date!";if(!e||!e.$id)throw"Angularjs scope is required!";var k=c.customizeObj({});f.get("/statistic/companies/receivable/totalInterval/"+b+"?from="+c.formatDate(a)+"&to="+c.formatDate(d)).then(function(a){function d(a){var b=new Date;if(a.getFullYear()===b.getFullYear()&&a.getMonth()===
  105. b.getMonth()&&a.getDate()===b.getDate())return!0}var f,r;for(r in a.data)f?(new Date(r)).getTime()>(new Date(f)).getTime()&&(f=r):f=r;c.customizeObj(a.data,k);d(new Date(f))&&n.subscribe("/todayReceivableChartPoint?targetId="+b,e,function(a){console.log(a);"TODAY_RECEIVABLE_CHART_POINT"===a.action&&d(new Date(a.data.date))&&c.defineReadOnlyProperty(k,f,a.data.total)});h&&h(a.data)},function(a){h&&h(a.data)});return k},getTicketsClosedByDays:function(b,a,d,e,h){if(!b)throw"companyId is required!";
  106. if(!a)throw"from date is required!";if(!d)throw"to date is required!";if(a.getTime()>d.getTime())throw"from date should be less that to date!";if(!e||!e.$id)throw"Angularjs scope is required!";var k=c.customizeObj({});f.get("/statistic/companies/resolvedTicket/interval/"+b+"?from="+c.formatDate(a)+"&to="+c.formatDate(d)).then(function(a){function d(a){var b,c;for(c in a)if("staticCopy"!=c){b=c;break}if(b){a=new Date(a[b]);for(var e in k)if("staticCopy"!==e&&(b=new Date(e),b.getFullYear()===a.getFullYear()&&
  107. b.getMonth()===a.getMonth()&&b.getDate()===a.getDate()))return e}}c.customizeObj(a.data,k);n.subscribe("/ticketResolution?targetId="+b,e,function(a){console.log(a);"TICKET_RESOLVED"===a.action?(a=d(a.data))&&c.defineReadOnlyProperty(k,a,k[a]+1):"TICKET_REOPENED"===a.action&&(a=d(a.data))&&c.defineReadOnlyProperty(k,a,k[a]-1);h&&h()});h&&h(a.data)},function(a){h&&h(a.data)});return k},getUserSubmittedTicketsByCompany:function(b,a,d){console.warn("Deprecated! Use getSubmittedTicketsByCompany()");if(!b)throw"companyId is required!";
  108. if(!a||!a.$id)throw"Angularjs scope is required!";var e=c.customizeObj({});f.get("/statistic/tickets/submittedTickets/"+b).then(function(b){c.customizeObj(b.data,e);n.subscribe("/userSubmittedTicket",a,function(a){console.log(a);"USER_SUBMITTED_TICKET"===a.action&&c.defineReadOnlyProperty(e,a.data,(e[a.data]||0)+1)});d&&d(b.data)},function(a){d&&d(a.data)});return e}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("SubscriptionsService",["$http","$rootScope","RealTimeService","Utils","CompaniesService",function(f,t,n,c,e){function h(b,a,d,e,h){var k=c.customizeObj({});f(b).then(function(b){for(var f=0;f<b.data.length;f++){var q=b.data[f];c.defineReadOnlyProperty(k,q.user.id,c.customizeObj(q))}n.subscribe("/subscription?targetId="+a,d,function(a){console.log(a);"SUBSCRIPTION_SAVED"==a.action?a.data.user&&(!h||-1<h.indexOf(a.data.user.id))&&c.defineReadOnlyProperty(k,
  109. a.data.user.id,c.customizeObj(a.data)):"SUBSCRIPTION_DELETED"==a.action&&delete k[a.data.user.id]});e&&e(b.data)},function(a){e&&e(a.data)});return k}return{saveUserSubscription:function(b,a){if(!b)throw"userSubscription is required argument!";var d="/subscription",e="POST";b.id&&(d+="/"+b.id,e="PUT");d=f({url:d,method:e,data:b});c.handleCallback(d,a)},changeSubscriptionsForUsers:function(b,a,d,e){if(!b)throw"userIds is required argument!";if(d===v)throw"toSubscribe is required argument!";if(!a||
  110. "ticket"!==a.toLowerCase()&&"invoice"!==a.toLowerCase())throw"type is required argument and must be ticket or invoice!";b=f({url:"/subscription/changeSubscriptionsForUsers?type="+a+"&toSubscribe="+!!d,method:"POST",data:b});c.handleCallback(b,e)},deleteUserSubscription:function(b,a){if(!b)throw"userSubscriptionId is required argument!";var d=f({url:"/subscription/"+b,method:"DELETE"});c.handleCallback(d,a)},getUserSubscriptionsByCompanyId:function(b,a,c){if(!b)throw"companyId is required argument!";
  111. if(!a||!a.$id)throw"Second argument must be Angularjs scope!";return h({url:"/subscription/company/users/"+b,method:"GET"},b,a,c)},getAllClientUserSubscriptions:function(b,a){if(!b||!b.$id)throw"Second argument must be Angularjs scope!";return h({url:"/subscription/clientUsers",method:"GET"},e.getCurrentCompany().id,b,a)},getUserSubscriptionsByUserIds:function(b,a,c){if(!b||0==b.length)throw"userIds is required argument!";if(!a||!a.$id)throw"Second argument must be Angularjs scope!";Array.isArray(b)||
  112. (b=[b]);return h({url:"/subscription/users/",method:"POST",data:b},e.getCurrentCompany().id,a,c,b)}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("TagsService",["$http","$rootScope","RealTimeService","Utils","$filter",function(f,t,n,c){return{search:function(c,h){if(!c)throw"First argument must be word!";f.get("/tags/search?word="+c).then(function(b){h&&h(b.data);return b.data})},setTagsInTicket:function(e,h,b){if(!e||!Array.isArray(e))throw"ticketTags is required and must be array!";if(!h)throw"ticketId is required!";e=f({url:"/tags?ticketId="+h,method:"PUT",data:e});c.handleCallback(e,
  113. b)}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("TaxRatesService",["$http","$rootScope","RealTimeService","Utils","$filter",function(f,t,n,c){return{getAllByCompany:function(e,f,b){if(!f||!f.$id)throw"First argument must be Angularjs scope!";if(!e||"[object Function]"===Object.prototype.toString.call(e))throw"companyId is required argument!";return c.getListByUrl("/taxRate/"+e,b,function(a){n.subscribe("/taxRate?targetId="+e,f,function(d){console.log(d);if("TAX_RATE_SAVE"==d.action){var e=
  114. c.findById(a,d.data.versionedId.id);e?c.customizeObj(d.data,e):a.push(c.customizeObj(d.data))}else"TAX_RATE_DELETE"==d.action&&(c.deleteById(a,d.data.versionedId.id),f.$broadcast("tax_rate_delete",d.data));b&&b(a)})})},save:function(e,h){if(!e)throw"taxRate is required!";var b="/taxRate",a="POST";e.versionedId&&e.versionedId.id&&(a="PUT",b=b+"/"+e.versionedId.id);b=f({url:b,method:a,data:e});c.handleCallback(b,h)},saveList:function(e,h){if(!e)throw"taxRate is required!";var b=f({url:"/taxRate/saveList",
  115. method:"POST",data:{taxRates:e}});c.handleCallback(b,h)},deleteTaxRate:function(e,h){if(!e)throw"taxRateId is required argument!";var b=f({url:"/taxRate/"+e,method:"DELETE"});c.handleCallback(b,h)},isUniqueInCompany:function(e,h,b,a){if(!e)throw"taxRateCode is required!";if(!b)throw"companyId is required!";var d=c.customizeObj({});f.get("/taxRate/isUniqueInCompany?taxRateCode="+e+"&id="+h+"&companyId="+b).then(function(b){c.customizeObj(b.data,d);a&&a(b.data)},function(b){a&&a(b.data)});return d},
  116. getAllTaxRates:function(e,h){var b=c.customizeObj({});f.get("/taxRate/getTaxRates").success(function(a){c.customizeObj(a,b);h&&h(a)});n.subscribe("/taxRate",e,function(a){console.log(a);if("TAX_RATE_SAVE"===a.action){if(b[a.data.company.id]){var d=c.findById(b[a.data.company.id],a.data.versionedId.id);d?c.customizeObj(a.data,d):b[a.data.company.id].push(a.data)}else b[a.data.company.id]=[a.data];h&&h(b)}else"TAX_RATE_DELETE"===a.action&&(c.deleteById(b[a.data.company.id],a.data.versionedId.id),h&&
  117. h(b))});return b},move:function(e,h){if(!e)throw"mapping is required argument!";var b=f({url:"/taxRate/move",method:"POST",data:e});c.handleCallback(b,h)}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("TicketsService",["$http","$rootScope","RealTimeService","Utils","CompaniesService",function(f,t,n,c,e){function h(a){a=angular.extend({},a);a.filter&&(a.filter=a.filter.toUpperCase());a.priority&&(a.priority=a.priority.toUpperCase());a.status&&(a.status=a.status.toUpperCase());return a}function b(a,b){return a.createdAt-b.createdAt}function a(a,b){if(!a||!a.$id)throw"First argument must be Angularjs scope!";var d=r.lists[a.$id];if(!d)throw"There is no ticket list for scope "+
  118. a.$id;d.loadingInProcess?console.log("Loading tickets already in process"):(0<d.list.length?d.params.lastId=d.list[d.list.length-1].id:delete d.params.lastId,d.loadingInProcess=!0,f({method:"GET",url:"/v2/tickets",params:d.params}).then(function(a){if(a){for(var e=0;e<a.data.length;e++){var m=a.data[e];m.number="Tkt# "+m.number;var f=c.findById(d.list,m.id);f?c.customizeObj(m,f):d.list.push(c.customizeObj(m))}d.loadingInProcess=!1;b&&b(a.data)}d.loadingInProcess=!1},function(a){d.loadingInProcess=
  119. !1;b&&b(a.data)}))}function d(a,b,d,e){d={value:d};"[object Array]"===Object.prototype.toString.call(b)?(a="/v2/tickets/"+a,d.ids=b):a="/v2/tickets/"+b+"/"+a;b=f.put(a,d);c.handleCallback(b,e)}function g(a,b){for(var c in r.lists)for(var d=r.lists[c].list,e=0;e<d.length;e++){var f=d[e];if(f.id===a){b(f);break}}for(c in r.tickets)d=r.tickets[c].ticket,d.id===a&&b(d)}function l(a,b,c){if("USER"===c.filter){if("COMPLETED"===a.status&&"COMPLETED"!==b.status)return 1;if("COMPLETED"===b.status&&"COMPLETED"!==
  120. a.status)return-1}return y[c.filter](b)-y[c.filter](a)}function k(a){return a.assignedAt||a.createdAt}function p(a,b){return"URGENT"==b.filter&&("HIGH"!=a.priorityLevel||"COMPLETED"==a.status||"ADMIN"!==t.currentUser.role&&!a.sharedToCurrentUserAt)||"UNASSIGNED"==b.filter&&a.assignedUser&&a.assignedUser.id||"USER"==b.filter&&(!a.assignedUser||a.assignedUser.id!=t.currentUser.id)||"OPEN"==b.filter&&"COMPLETED"==a.status||"CLOSED"==b.filter&&("COMPLETED"!=a.status||"ADMIN"!==t.currentUser.role&&"SUPER_TECH_ADMIN"!==
  121. t.currentUser.role&&(!a.assignedUser||a.assignedUser.id!=t.currentUser.id))||"SHARED"==b.filter&&!a.sharedToCurrentUserAt||!("USER_SPAM"!=b.filter||a.spamReporter&&a.spamReporter.id&&t.currentUser.id==a.spamReporter.id)||"ADMIN_REPORTED_AS_SPAM"==b.filter&&(!a.spamReporter||!a.spamReporter.id||a.spamMarker&&a.spamMarker.id)||!("ADMIN_MARKED_AS_SPAM"!=b.filter||a.spamMarker&&a.spamMarker.id)||"TRASH"==b.filter&&!a.trash||"USER_SPAM"!==b.filter&&"ADMIN_REPORTED_AS_SPAM"!==b.filter&&"ADMIN_MARKED_AS_SPAM"!==
  122. b.filter&&"TRASH"!==b.filter&&(a.spamMarker&&a.spamMarker.id||a.spamReporter&&a.spamReporter.id||a.trash)||b.companyId&&b.companyId!=a.company.id||b.status&&b.status!=a.status||b.priority&&b.priority!=a.priorityLevel?!1:!0}var u="ASSIGNED_USER PRIORITY_CHANGED STATUS TRASH REPORT_AS_SPAM RESTORE_FROM_SPAM TICKET_INVOICED TICKET_SHARE MARKED_AS_SPAM".split(" "),q=0,r={lists:{},tickets:{},counts:{}};e=t.$new();n.subscribe("/tags",e,function(a){console.log(a);if("TAG_TICKET_SAVED"===a.action)for(var b in r.lists){var d=
  123. c.findById(r.lists[b].list,a.data.ticketId);if(d){d.tags.splice(0,d.tags.length);for(var e=0;e<a.data.tags.length;e++)d.tags.push(a.data.tags[e])}}});n.subscribe("/tickets",e,function(a){console.log(a);a.data&&a.data.number&&(a.data.number="Tkt# "+a.data.number);if("CREATED_TICKET"===a.action){var b=c.customizeObj(a.data,{}),d;for(d in r.lists){var e=r.lists[d];if(p(a.data,e.params)){var f=c.findById(e.list,a.data.id);f?c.customizeObj(a.data,f):e.list.unshift(b)}}}else if(-1<u.indexOf(a.action)){b=
  124. c.customizeObj(a.data,{});for(d in r.lists){var e=r.lists[d],f=!1,h=c.indexOfId(e.list,b.id);if(-1<h)p(a.data,e.params)?(c.customizeObj(b,e.list[h]),f=!0):(e.list.splice(h,1),t.$broadcast("ticket_is_not_available_anymore",{ticketId:a.data.id,ticketType:e.params.filter}));else if(p(a.data,e.params))if(0===e.list.length)e.list.push(b);else if(h=e.list[e.list.length-1],15>e.list.length||0>=l(b,h,e.params))e.list.push(b),f=!0;f&&e.list.sort(function(a,b){return l(a,b,e.params)})}for(d in r.tickets)f=
  125. r.tickets[d].ticket,f.id===b.id&&c.customizeObj(b,f)}else if("READ"===a.action)g(a.data.id,function(a){c.defineReadOnlyProperty(a,"unread",!1)});else if("TICKET_UPDATES_READ"===a.action)g(a.data.id,function(a){c.defineReadOnlyProperty(a,"hasNewUpdates",!1)});else if("TICKET_COLLAPSED"===a.action||"TICKET_DELETED"===a.action){for(d in r.lists)c.deleteById(r.lists[d].list,a.data.id);for(d in r.tickets)b=r.tickets[d],b.ticket.id===a.data.id&&(delete r.tickets[d],b.scope.$broadcast("ticket_is_not_available_anymore",
  126. {ticketId:a.data.id}))}else if("TAG_LINKED"===a.action)for(b in a.data)g(b,function(a){});else"TICKET_BILLABLE"===a.action&&g(a.data.id,function(b){c.defineReadOnlyProperty(b,"isBillable",a.data.isBillable)})});var y={URGENT:k,UNASSIGNED:function(a){return a.createdAt},USER:function(a){return a.closedAt||a.assignedAt},OPEN:function(a){return a.assignedAt},CLOSED:function(a){return a.closedAt},SHARED:function(a){return a.sharedToCurrentUserAt},ALL:k,NOT_SPAM_OR_TRASH:k,USER_SPAM:function(a){return a.reportedAsSpamAt},
  127. ADMIN_REPORTED_AS_SPAM:function(a){return a.reportedAsSpamAt},ADMIN_MARKED_AS_SPAM:function(a){return a.markedAsSpamAt},TRASH:function(a){return a.deletedAt}};return{getList:function(b,d,e){if(!b||!b.$id)throw"First argument must be Angularjs scope!";if(!d||!d.filter)throw"'filter' is mandatory parameter that must be counted in second argument";d=h(d);var f=c.customizeObj([]);r.lists[b.$id]={params:d,scope:b,list:f};a(b,e);b.$on("$destroy",function(){delete r.lists[b.$id]});return f},getCurrentlyWorkingWith:function(a,
  128. b){if(!a||!a.$id)throw"First argument must be Angularjs scope!";return c.getListByUrl("/v2/tickets/currentlyWorkingWith",b,function(b){n.subscribe("/tickets",a,function(a){console.log(a);"CURRENTLY_WORKING_WITH"==a.action&&(b.splice(0,b.length),c.customizeArray(a.data,b))})})},loadMore:a,search:function(a,b){if(!a||!a.filter)throw"'filter' is mandatory parameter that must be counted in first argument";if(!a.keyword)throw"'keyword' is mandatory parameter that must be counted in first argument";if(3>
  129. a.keyword.length)throw"minimal length of 'keyword' is 3 characters";a=h(a);var c=[];return f({method:"GET",url:"/v2/tickets/search",params:a}).then(function(a){for(var d=0;d<a.data.length;d++)c.push(a.data[d]);b&&b(c);return c},function(a){b&&b(a)})},getCount:function(a,b,d){if(!b||!b.$id)throw"Second argument must be Angularjs scope!";if(!a||!a.filter)throw"'filter' is mandatory parameter that must be counted in first argument";a=h(a);var e=c.customizeObj({});f({method:"GET",url:"/v2/tickets/countByType",
  130. params:a}).then(function(a){c.customizeObj(a.data,e);d&&d(a.data)},function(a){d&&d(a.data)});n.subscribe("/ticketsCount",b,function(b){console.log(b);"TICKETS_COUNT_CHANGED"==b.action&&f({method:"GET",url:"/v2/tickets/countByType",params:a}).then(function(a){c.customizeObj(a.data,e);d&&d(a.data)},function(a){d&&d(a.data)})});return e},getCounts:function(a,b){if(!a||!a.$id)throw"Second argument must be Angularjs scope!";var d=q++,e=c.customizeObj({});r.counts[d]=e;a.$on("$destroy",function(){delete r.counts[d]});
  131. f.get("/data/getCounters").then(function(a){c.customizeObj(a.data,e);b&&b(a.data)},function(a){b&&b(a.data)});n.subscribe("/leftPanelCounts",a,function(a){console.log(a);"LEFT_PANEL_COUNTS"==a.action&&c.customizeObj(a.data,e)});return e},getCountsByTypesAndCompany:function(a,b,d,e){function g(){f({url:"/v2/tickets/counts/",data:{companyId:b,types:d},method:"POST"}).then(function(a){c.customizeObj(a.data,h);e&&e(a.data)},function(a){e&&e(a.data)})}if(!a||!a.$id)throw"Second argument must be Angularjs scope!";
  132. if(!b)throw"companyId is required!";if(!d||0==d.length)throw"ticketTypes is required!";var h=c.customizeObj({});g();n.subscribe("/ticketsCount",a,function(a){console.log(a);"TICKETS_COUNT_CHANGED"==a.action&&g()});return h},getOne:function(a,d,e,g,h){if(!a)throw"Id is mandatory argument!";if(!d)throw"ticketsType is mandatory argument!";if(!e||!e.$id)throw"Third argument must be Angularjs scope!";var k=q++,l={id:a};d="SPAM"===d.toUpperCase()?"":d.toUpperCase();var y="/v2/tickets/"+a+"?ticketsType="+
  133. d;g&&(y+="&view=extended");r.tickets[k]={ticket:l,scope:e};e.$on("$destroy",function(){delete r.tickets[k]});f.get(y).then(function(a){400!==a.data.code&&(a.data.number="Tkt# "+a.data.number,c.customizeObj(a.data,l),g&&l.updates.sort(b));h&&h(a.data)},function(a){h&&h(a.data)});g&&(n.subscribe("/ticketUpdates?targetId="+a,e,function(a){console.log(a);if("UPDATE_SAVED"==a.action||"UPDATE_CREATED"==a.action){var e="SHARED"!==d.toUpperCase()||a.data.user.id===t.currentUser.id;if(!e)for(var f=0;f<a.data.shares.length&&
  134. !e;f++)e=(e=a.data.shares[f].user)&&e.id===t.currentUser.id;e?(f=c.findById(l.updates,a.data.id))?c.customizeObj(a.data,f):(f=c.customizeObj(a.data),l.updates.push(f)):c.deleteById(l.updates,a.data.id);l.updates.sort(b)}else"UPDATE_DELETED"==a.action&&c.deleteById(l.updates,a.data.id)}),n.subscribe("/tagsSpecifying?targetId="+a,e,function(a){console.log(a);if("TAG_TICKET_SPECIFYING_SAVED"==a.action){l.tags.splice(0,l.tags.length);for(var b=0;b<a.data.length;b++)l.tags.push(a.data[b]);h&&h(l);return l}}));
  135. return l},changePriority:function(a,b,c){if(!a||!b)throw"ticketId and priority is required arguments!";d("priority",a,b.toUpperCase(),c)},assignTo:function(a,b,c){if(!a||!b)throw"ticketId and userId is required arguments!";d("assign",a,b,c)},changeStatus:function(a,b,c){if(!a||!b)throw"ticketId and status is required arguments!";d("status",a,b.toUpperCase(),c)},markAsSpam:function(a,b){if(!a)throw"ticketId is required arguments!";d("markAsSpam",a,!1,b)},reportAsSpam:function(a,b){if(!a)throw"ticketId is required arguments!";
  136. d("reportAsSpam",a,!1,b)},restoreFromSpam:function(a,b){if(!a)throw"ticketId is required arguments!";d("restoreFromSpam",a,!1,b)},changeTrashFlag:function(a,b,c){if(!a)throw"ticketId is required arguments!";d("trash",a,!!b,c)},deleteForever:function(a,b){if(!a)throw"ticketId is required arguments!";var d=a;"[object Array]"!==Object.prototype.toString.call(a)&&(d=[a]);d=f({url:"/v2/tickets/delete/",data:{ids:d},method:"POST"});c.handleCallback(d,b)},claimUser:function(a){f.get("/tickets/claimUser?ticketId="+
  137. a)},createTicket:function(a,b){a.priorityLevel&&(a.priorityLevel=a.priorityLevel.toUpperCase());var d=f.post("/v2/tickets",a);c.handleCallback(d,b)},getActualNumber:function(a,b){f.get("/data/actualNumber?type=TICKET").success(function(a){b(a.number)});n.subscribe("/number?targetId=TICKET",a,function(a){console.log(a);"NUMBER_CHANGED"===a.action&&b(c.getFormattedNumber(a.data,!0))})},createTicketUpdate:function(a,b,d){if(!a)throw"ticketUpdate is required arguments!";if(!a.ticket.id)throw"ticketUpdate.ticket.id is required!";
  138. if(a.id)throw"TicketUpdate must be new, without ticketUpdate.id!";if(!a.type)throw"ticketUpdate.type is required!";if(!a.note&&!a.products&&!a.services)throw"In TicketUpdate must be or note or products or services!";a=f({url:"/v2/tickets/updates",method:"POST",params:{close:!!b},data:a});c.handleCallback(a,d)},deleteTicketUpdate:function(a,b,d){a=f({url:"/v2/tickets/"+a+"/updates/"+b,method:"DELETE"});c.handleCallback(a,d)},loadRemainingTicketUpdates:function(a,d){if(!a.id||!a.updates)throw"You can load updates only for detailed ticket!";
  139. if(0==a.updates.length)throw"There is no updates";for(var e=[],g=0;g<a.updates.length;g++)e.push(a.updates[g].id);f({url:"/v2/tickets/"+a.id+"/updates/fetch",method:"POST",data:e}).then(function(e){c.customizeArray(e.data,a.updates);c.defineReadOnlyProperty(a,"unloadedUpdates",0);a.updates.sort(b);d&&d(e.data)},function(a){d&&d(a.data)})},markUpdateAsRead:function(a,b,d){if(!a||!b)throw"ticketId and updateIds is required parameters";a=f({url:"/v2/tickets/"+a+"/updates/read",method:"POST",data:b});
  140. c.handleCallback(a,d)},updateExpenseInTicketUpdate:function(a,b){if(!a)throw"expense is required!";if(!a.ticketUpdateId)throw"ticketUpdateId is required!";if(!a.serviceExpense&&!a.productExpense)throw"serviceExpense or productExpense is required!";var d=f({url:"/v2/tickets/ticketUpdate/updateExpense",method:"PUT",data:a});c.handleCallback(d,b)}}}])})(window,jQuery);(function(u,w,v){angular.module("main.services").factory("UsersService",["$http","$rootScope","RealTimeService","Utils","CompaniesService",function(f,t,n,c,e){function h(a){var d=c.findById(q.users,a.id);d?(c.customizeObj(a,d),t.currentUser.id===d.id&&c.customizeObj(a,t.currentUser)):(a=c.customizeObj(a),q.users.push(a),a.company.id!==e.getCurrentCompany().id&&q.clientUsers.push(a),b(a),q.usersByCompanies[a.company.id]||(q.usersByCompanies[a.company.id]=[]),q.usersByCompanies[a.company.id].push(a))}
  141. function b(a){var b=[a.firstName,a.lastName].map(function(a){return a.charAt(0).toUpperCase()}).join("");c.defineReadOnlyProperty(a,"initials",b)}function a(){return d(t.currentUser.id)}function d(a){return c.findById(q.users,a)||c.findById(q.deleted,a)}function g(b,c,d){if(!b)throw"Keyword is required!";var e=[];d=d?q.usersByCompanies[d]||[]:q.users;for(var f=0;f<d.length;f++){var g=d[f];(c||a().company.id!==g.company.id)&&-1<(g.firstName+" "+g.lastName).toLowerCase().indexOf(b.toLowerCase())&&e.push(g)}return e}
  142. var l=t.$new(),k=[],p=!1,w=!1,q={users:[],clientUsers:[],deleted:[],usersByCompanies:{}};c.customizeObj(q);e._addInitListener(function(){w||(w=!0,f.get("/users").then(function(a){c.customizeArray(a.data,q.users);for(a=0;a<q.users.length;a++){var d=q.users[a];b(d);d.company.deletedAt||d.deletedAt||(q.usersByCompanies[d.company.id]||(q.usersByCompanies[d.company.id]=[]),q.usersByCompanies[d.company.id].push(d));var f=e.getOneById(d.company.id);d.company.id!==e.getCurrentCompany().id&&f&&!f.deletedAt?
  143. q.clientUsers.push(d):f&&f.deletedAt&&q.deleted.push(d)}p=!0;for(a=0;a<k.length;a++)k[a]();k=[]},function(a){console.error(a);throw"Cannot initialize CompaniesService!";}),n.subscribe("/user",l,function(b){console.log(b);if(p)if("USER_SAVED"==b.action)if(a().id===b.data.id&&(u.startPage=b.data.startPage),b.data.company.id!==a().company.id)h(b.data);else{var d=c.findById(q.usersByCompanies[b.data.company.id],b.data.id);d?c.customizeObj(b.data,d):(q.usersByCompanies[b.data.company.id].push(c.customizeObj(b.data)),
  144. q.users.push(c.customizeObj(b.data)))}else if("USER_DELETED"==b.action)d=c.findById(q.users,b.data.id),q.deleted.push(d),c.deleteById(q.users,b.data.id),c.deleteById(q.clientUsers,b.data.id),d&&c.deleteById(q.usersByCompanies[d.company.id],b.data.id);else if("USER_ONLINE"==b.action)(d=c.findById(q.users,b.data.id))&&c.defineReadOnlyProperty(d,"online",!!b.data.online);else if("COMPANY_ARCHIVED"==b.action){for(d=0;d<q.users.length;d++)q.users[d].company.id===b.data.id&&(q.deleted.push(q.users[d]),
  145. q.users.splice(d,1),d--);for(d=0;d<q.clientUsers.length;d++)q.clientUsers[d].company.id===b.data.id&&(q.clientUsers.splice(d,1),d--);delete q.usersByCompanies[b.data.id]}else"USERS_DEARCHIVED"==b.action&&b.data.forEach(h)}),n.subscribe("/userSubmittedTicket",l,function(a){console.log(a);"USER_SUBMITTED_TICKET"===a.action&&(a=d(a.data),c.defineReadOnlyProperty(a.userStatistic,"ticketsSubmitted",(a.userStatistic.ticketsSubmitted||0)+1))}),n.subscribe("/subscription?targetId="+e.getCurrentCompany().id,
  146. l,function(a){console.log(a);if(a.data.user){var b=c.findById(q.users,a.data.user.id);b&&("SUBSCRIPTION_SAVED"==a.action?c.defineReadOnlyProperty(b,"subscription",c.customizeObj(a.data)):"SUBSCRIPTION_DELETED"==a.action&&delete b.subscription)}}))});return{_addInitListener:function(a){if(!a)throw"callback is required!";p?a():k.push(a)},getCurrentUser:a,getAllUsers:function(){return q.users},getClientUsers:function(){return q.clientUsers},getTechUsers:function(){return q.usersByCompanies[a().company.id]||
  147. []},getAllByCompanyId:function(a){return q.usersByCompanies[a]||[]},getOneById:d,getUserProfile:function(a){var b={};f.get("/settings/userProfile/").then(function(d){c.customizeObj(d.data,b);a&&a(d.data)},function(b){a&&a(b.data)});return b},getUnassignedUser:function(a){for(var b=0;b<q.usersByCompanies[a].length;b++)if(q.usersByCompanies[a][b].isDefault)return q.usersByCompanies[a][b]},searchByAllUsers:function(a){return g(a,!0)},searchByClientUsers:function(a){return g(a,!1)},searchByUsersFromCompany:function(a,
  148. b){return g(a,!1,b)},changeUserRole:function(a,b,d){if(!a)throw"userId is required!";if(!b)throw"roleName is required!";a=f({url:"/users/updateRole/"+a+"?role="+b.toUpperCase(),method:"PUT"});c.handleCallback(a,d)},changeUsersRoles:function(a,b,d){if(!a)throw"userIds is required!";if("admin"!==b.toLowerCase()&&"user"!==b.toLowerCase())throw"role is required and must be admin or user!";a=f({url:"/users/updateRoles?role="+b,method:"PUT",data:a});c.handleCallback(a,d)},save:function(a,b){if(!a)throw"user is required!";
  149. var d="/users",e="POST";a.id&&(e="PUT",d=d+"/"+a.id);d=f({url:d,method:e,data:a});c.handleCallback(d,b)},saveUserSettingsDto:function(a,b){if(!a)throw"userDto is required!";var d=f({url:"/settings/userProfile/",method:"PUT",data:a});c.handleCallback(d,b)},saveForUserProfile:function(a,b,d){if(!a)throw"data is required!";if(!b)throw"toUpdate is required!";b="/settings/userProfile/"+b.toLowerCase();a=f({url:b,method:"PUT",data:a});c.handleCallback(a,d)},deleteOrArchiveUser:function(a,b,d){if(!a)throw"ids is required!";
  150. if(b===v)throw"isArchive is required!";Array.isArray(a)||(a=[a]);a=f({url:"/users/"+!!b,method:"POST",data:a});c.handleCallback(a,d)},isEmailUnique:function(a,b,d){if(!a)throw"email is required!";var e=c.customizeObj({});f.get("/users/isEmailUnique?email="+a+"&id="+b).then(function(a){c.customizeObj(a.data,e);d&&d(a.data)},function(a){d&&d(a.data)});return e},deleteAvatar:function(a,b){if(!a)throw"companyId is required!";var d=f({url:"/users/"+a+"/",method:"DELETE"});c.handleCallback(d,b)}}}])})(window,
  151. jQuery);(function(u,w,v){angular.module("main.services").factory("VendorsService",["$http","$rootScope","RealTimeService","Utils","$filter",function(f,t,n,c){return{save:function(e,h){if(!e)throw"vendor is required!";var b="POST";e.id&&(b="PUT");b=f({url:"/vendor",method:b,data:e});c.handleCallback(b,h)},getAll:function(e,f){if(!e||!e.$id)throw"First argument must be Angularjs scope!";return c.getListByUrl("/vendor",f,function(b){n.subscribe("/vendor",e,function(a){console.log(a);if("VENDOR_SAVE"==a.action){var d=
  152. c.findById(b,a.data.id);d?c.customizeObj(a.data,d):b.push(c.customizeObj(a.data))}else if("VENDOR_ARCHIVED"==a.action)c.deleteById(b,a.data.id),e.$broadcast("vendor_archived",a.data);else if("VENDOR_DEARCHIVED"==a.action)b.push(c.customizeObj(a.data)),e.$broadcast("vendor_dearchived",a.data);else if("VENDOR_PRODUCT_SAVE"==a.action){var d=c.findById(b,a.data.id),f=c.findById(d.products,a.data.products[0].versionedId.id);if(d&&f)for(a=0;d.products.length<a;a++);else d&&(d.products[d.products.length]=
  153. a.data.products[0])}else"VENDOR_PRODUCT_DELETE"==a.action&&(d=c.findById(b,a.data.id))&&c.deleteById(d.products,a.data.products[0].versionedId.id)})})},getAllForCompanyProfile:function(e,f,b){if(!e||!e.$id)throw"First argument must be Angularjs scope!";if(!f)throw"companyId is required!";return c.getListByUrl("/vendor/companyProfile/"+f,b,function(a){n.subscribe("/vendor",e,function(b){console.log(b);if("VENDOR_SAVE"==b.action){var f=c.findById(a,b.data.id);f?c.customizeObj(b.data,f):a.push(c.customizeObj(b.data))}else if("VENDOR_ARCHIVED"==
  154. b.action)c.deleteById(a,b.data.id),e.$broadcast("vendor_archived",b.data);else if("VENDOR_DEARCHIVED"==b.action)a.push(c.customizeObj(b.data)),e.$broadcast("vendor_dearchived",b.data);else if("VENDOR_PRODUCT_SAVE"==b.action){var f=c.findById(a,b.data.id),h=c.findById(f.products,b.data.products[0].versionedId.id);if(f&&h)for(b=0;f.products.length<b;b++);else f&&(f.products[f.products.length]=b.data.products[0])}else"VENDOR_PRODUCT_DELETE"==b.action&&(f=c.findById(a,b.data.id))&&c.deleteById(f.products,
  155. b.data.products[0].versionedId.id)})})},getAllForAutocomplete:function(e,f){if(!e||!e.$id)throw"First argument must be Angularjs scope!";return c.getListByUrl("/vendor/autocomplete/list",f,function(b){n.subscribe("/vendor",e,function(a){console.log(a);if("VENDOR_SAVE"==a.action){var d=c.findById(b,a.data.id);d?c.customizeObj(a.data,d):b.push(c.customizeObj(a.data))}else"VENDOR_ARCHIVED"==a.action?(c.deleteById(b,a.data.id),e.$broadcast("vendor_archived",a.data)):"VENDOR_DEARCHIVED"==a.action&&(b.push(c.customizeObj(a.data)),
  156. e.$broadcast("vendor_dearchived",a.data))})})},getAllInCompanyForAutocomplete:function(e,h){if(!e)throw"companyId is required!";var b=c.customizeArray([]);f.get("/vendor/getAll/"+e).then(function(a){c.customizeArray(a.data,b);h&&h(a.data)},function(a){h&&h(a.data)});return b},isWebsiteUnique:function(e,h,b){if(!e)throw"website is required!";var a=c.customizeObj({});f.get("/vendor/isWebsiteUnique?website="+e+"&id="+h).then(function(d){c.customizeObj(d.data,a);b&&b(d.data)},function(a){b&&b(a.data)});
  157. return a},isNameUnique:function(e,h,b){if(!e)throw"name is required!";var a=c.customizeObj({});f.get("/vendor/isNameUnique?name="+e+"&id="+h).then(function(d){c.customizeObj(d.data,a);b&&b(d.data)},function(a){b&&b(a.data)});return a},archive:function(e,h){if(!e)throw"id is required!";var b=f.get("/vendor/archive/"+e);c.handleCallback(b,h)},dearchive:function(e,h){if(!e)throw"id is required!";var b=f.get("/vendor/dearchive/"+e);c.handleCallback(b,h)},getOneById:function(e,h){if(!e)throw"vendorId is required!";
  158. var b=c.customizeObj({});f.get("/vendor/getOneById/"+e).then(function(a){c.customizeObj(a.data,b);h&&h(a.data)},function(a){h&&h(a.data)});return b},search:function(c){if(!c)throw"Keyword is required!";return f.get("/vendor/search?keyword="+c).then(function(c){return c.data})}}}])})(window,jQuery);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top