(function(){function t(n){if(n&&n.status)return n;throw n;}var n=angular.module("callplus.api",[]);n.service("identityAPI",["$q","callplusAPI",function(n,t){this.getDefaultAccountCode=function(){return t.getDefaultAccountClaim().then(function(n){return n.Claim.AccountCode})}}]);n.service("paymentsAPI",["$q","identityAPI","callplusAPI",function(n,i,r){this.getStandardReference=function(){return i.getDefaultAccountCode().then(function(n){return"AN"+n+"/"+Date.now()})};this.getBillingInformation=function(){return i.getDefaultAccountCode().then(r.Payments.GetBillingInformation).then(t).then(function(n){return n.data.BillingInformation})};this.getPaymentMethod=function(){return i.getDefaultAccountCode().then(r.Payments.GetPaymentMethod).then(t).then(function(n){return n.data})};this.isPaymentMethodCreditCard=function(){return this.getPaymentMethod().then(function(n){return n.RecurringPaymentType==="CreditCard"})};this.isPaymentMethodDirectDebit=function(){return this.getPaymentMethod().then(function(n){return n.RecurringPaymentType==="DirectDebit"})};this.isPaymentMethodManual=function(){return this.getPaymentMethod().then(function(n){return n.RecurringPaymentType==="Manual"})}}])})(),function(){var n=angular.module("callplus.authpersons.services",[]);n.service("AuthorisedPersonsService",["$q","callplusAPI","cache",function(n,t,i){function r(){}return r.prototype.getAuthorisedPeople=function(i){return n(function(n,r){return t.Manage.GetAuthorisedPeople(i).then(function(t){angular.equals(t.status,200)?n(t.data):r("error")})})},r.prototype.removeAuthorisedPerson=function(r,u){return i.flush("Manage.GetAuthorisedPeople"),n(function(n,i){return t.Manage.RemoveAuthorisedPerson(r,u).then(function(t){angular.equals(t.status,200)?n(t.data):i("error")})})},r.prototype.addAuthorisedPerson=function(r,u){return i.flush("Manage.GetAuthorisedPeople"),n(function(n,i){var f=moment(u.DOB.Year+"-"+u.DOB.Month+"-"+u.DOB.Day,"YYYY-MM-DD");return u.DateOfBirth=f.add(15,"hours").toDate(),t.Manage.AddAuthorisedPerson(r,u).then(function(t){angular.equals(t.status,200)?n(t.data):i("error")})})},new r}])}(),function(){var n=angular.module("callplus.billing.services",[]);n.service("BillInformation",["$q","callplusAPI",function(n,t){function i(){}function r(n,t){return moment(n)-moment(t)}function u(n){return n?function(t,i){return r(t[n],i[n])}:r}function f(){return t.getDefaultAccountClaim().then(function(n){return n.Claim.AccountCode})}function e(){return f().then(function(n){return t.Payments.GetInvoiceHeaders(n)}).then(function(n){var t=n.data.InvoiceHeaders;return t.sort(u("BillDate")),t.length===0?null:t[0]})}function o(){return e().then(function(n){return n?moment(n.BillDate):moment()})}return i.prototype.getFinancialHistory=function(){return n.all([f().then(t.Payments.GetAccountStatements),o(),]).then(function(n){var i=n[0],r=n[1];i.data.Transactions.sort(u("Date"));var f=[],t=0,e=0;return angular.forEach(i.data.Transactions,function(n){if(e++,moment(n.Date).isAfter(r)||moment(n.Date).isSame(r)){var i=!1;if(n.Type==="Invoice")t+=n.Amount,n.Amount<0&&(i=!0);else if(n.Type==="Payment"||n.Type==="Refund"||n.Type==="Adjustment")t-=n.Amount,n.Type==="Payment"&&n.Amount>0?i=!0:n.Type==="Refund"&&n.Amount<0?i=!0:n.Type==="Adjustment"&&n.Amount>0&&(i=!0);else throw"Unknown Transaction Type found";f.push({itemNumber:n.StatementTransactionID,itemType:n.Type,itemDate:n.Date,itemAmount:Math.abs(n.Amount),itemDetails:n.Details,itemFinalBalance:t,itemIsCreditTransection:i,itemIndex:e})}}),f})},i.prototype.getDueAmount=function(){return getFinancialHistory().then(function(){})},new i}])}(),function(){var n=angular.module("callplus.common.services",[]);n.service("LayoutPromiseFacory",["$q",function(n){function t(){function f(){for(var i=arguments||[],n=0;n<i.length;n++)i[n].then(u());return t}var i=0,r=0,u=undefined,t=n(function(n){u=function(){return i++,function(){r++;r===i&&n()}}});return t.waitFor=f,t}return t},]);n.service("CoreProductsService",["$q","callplusAPI","xmlConverter","util",function(n,t,i,r){function u(){}function f(n){return(n.CoreProductComponents||[]).filter(function(n){return n.CoreProductComponentService==="Voice"}).map(function(n){return n.CoreProductComponentPlans})}function e(n){return(n.CoreProductComponents||[]).filter(function(n){return n.CoreProductComponentService==="Internet"}).map(function(n){return n.CoreProductComponentPlans})}return u.prototype.getProductForProductKey=function(n){return t.Sales.GetAllProducts().then(function(t){var i=null;return angular.equals(t.status,200)&&t.data.CoreServices.some(function(t){return i=r.arrayFind(t.CoreProducts,function(t){return t.CoreProductKey===n}),i!==null?(i.CoreServiceKey=t.CoreServiceKey,!0):void 0}),i})},u.prototype.getAllInternetPlansForCoreProductKey=function(n){var t=this;return t.getProductForProductKey(n).then(function(n){return n?e(n):null})},u.prototype.getAllVoicePlansForCoreProductKey=function(n){var t=this;return t.getProductForProductKey(n).then(function(n){return n?f(n):null})},u.prototype.getAllAdditionalProductsForCoreProductKey=function(n){var i={};return t.Sales.GetProductAddons(n).then(function(n){return angular.equals(n.status,200)&&(n.data.CallingPacks=n.data.AdditionalProducts.filter(function(n){return n.AdditionalProductService==="callingpack"}),n.data.MobileCallingPacks=n.data.AdditionalProducts.filter(function(n){return n.AdditionalProductService==="callingpackmobile"}),n.data.Extras=n.data.AdditionalProducts.filter(function(n){return n.AdditionalProductService!=="callingpack"&&n.AdditionalProductService!=="callingpackmobile"}),i=n.data),i})},u.prototype.getAllCoreProducts=function(){var n;return t.Sales.GetAllProducts().then(function(t){return angular.equals(t.status,200)&&(n=t.data),n})},new u}])}(),function(){var n=angular.module("callplus.invoice.services",[]);n.service("pdfService",["$q",function(n){return{getPDFUrl:function(){n(function(n,t){return t("Not supported")})},downloadPDF:function(t){n(function(n,i){var r,u;angular.isUndefined(t)&&i("Invalid dataset");r=t.Invoice.InvoiceHeader.InvoiceNumber;r&&""+r===r||(r="Callplus Invoice.pdf");r.slice(-4)!==".pdf"&&(r=r+".pdf");u=require("pdf");(new u).generate(t).then(function(n){n.download(r)}).catch(scExceptionHandler);n()})}}}]);n.service("invoiceOrganiser",["$q","$filter","xmlConverter","userInformation",function(n,t,i,r){function e(t){return n(function(n,r){var u=!1;u=""+t!==t?t.Invoice:t;u?n(i(u).then(function(n){var t=n.Invoice,i=h(t),r=o(t,i);return{Invoice:t,Statement:r,TaxInvoice:i}})):r("Invalid object provided to `invoiceOrganiser`")})}function o(n,i){var f={},h,o,s,l;f.UserName=r.getUsername();f.Invoice=n;f.Payments=[];f.CurrentInvoiceBalance={};var e=0,a=0,v=0,c,y;return n.InvoiceStatement.forEach(function(n){switch(n.Type){case"Balance":c=parseFloat(n.Amount);break;case"Invoice":y=parseFloat(n.Amount);break;case"Payment":e+=parseFloat(n.Amount);f.Payments.push(t("number")(n.Amount,"2"));break;case"Refund":a+=parseFloat(n.Amount);break;default:v+=parseFloat(n.Amount)}}),e=e+a+v,h=c-e,f.Balance=h,f.FinalBalanceWithGST=h+parseFloat(n.InvoiceHeader.Total),f.StatementDate=t("date")(n.InvoiceHeader.BillDate,"dd MMMM yyyy"),f.TotalPayments=e,f.PreviousInvoiceBalance=c,o={},angular.forEach(i.BundleInfo.datalist,function(n){var t=n.CustomerBillingGroupDescription;o[t]===undefined&&(o[t]=0);o[t]+=parseFloat(n.Charge)}),f.CurrentInvoiceBalance.Bundles=o,s={},angular.forEach(i.BroadbandInfo.datalist,function(n){var t=n.CategoryName;s[t]===undefined&&(s[t]=0);s[t]+=parseFloat(bundle.Charge)}),f.CurrentInvoiceBalance.BroadBands=s,angular.equals(i.ExtraInfo,{})||(f.CurrentInvoiceBalance.ExtrasTotal=i.ExtraInfo.TotalCharge),angular.equals(i.MobileInfo,{})||(f.CurrentInvoiceBalance.MobileTotal=i.MobileInfo.TotalCharge),angular.equals(i.TollFreeInfo,{})||(f.CurrentInvoiceBalance.TollFreeTotal=i.TollFreeInfo.TotalCharge),angular.equals(i.ElectricityInfo,{})||(f.CurrentInvoiceBalance.ElectricityTotal=i.ElectricityInfo.TotalCharge),f.IsOverdueBalance=h>0,f.CurrentInvoiceDueDate=moment(n.InvoiceHeader.BillDate).add(20,"days").format("DD MMMM"),f.LastBillDate=moment(n.InvoiceHeader.BillDate).add(1,"days").subtract(1,"month").format("DD MMMM"),l=0,u(n.InvoiceSummary).forEach(function(n){angular.equals(n.CategoryName,"GST")&&(l=n.Charge)}),f.TotalGST=t("number")(l,"2"),f}function u(n){var t=[];return typeof n=="undefined"?t=[]:angular.isArray(n)?t=n:t.push(n),t}function s(n,i){var u=[],r,e;return angular.isArray(n)||(r=[],r.push(n),n=r),angular.forEach(n,function(n){f(i,n)&&u.push(n)}),e=t("taxInvoiceChargeSum")(u,null),e===0}function f(n,t){return n.CategoryName.indexOf(t.CategoryName.toLowerCase())!==-1&&n.SubCategoryName.indexOf(t.SubCategoryName.toLowerCase())!==-1&&n.NumberBilled.indexOf(t.NumberBilled.toLowerCase())!==-1&&n.Description1.indexOf(t.Description1.toLowerCase())!==-1}function h(n){var i={},e,c;i.BroadbandPlan="";i.BundlePlan="";var r=0,o=0,h=0;if(i.BroadbandInfo={},i.BundleInfo={},i.ExtraInfo={},i.MobileInfo={},i.TollFreeInfo={},i.ElectricityInfo={},i.InvoiceBundles={},e={CategoryName:["misc credits","other"],SubCategoryName:["equipment credit","other"],NumberBilled:["inventory"],Description1:["nf4v"]},c=s(n.InvoiceDetail,e),i.ExtraInfo["Land to Mobile Calls"]={datalist:[],charge:0,showCallDetails:!0,CustomerBillingGroupDescription:undefined},i.ExtraInfo["Local Calls"]={datalist:[],charge:0,showCallDetails:!0,CustomerBillingGroupDescription:undefined},i.ExtraInfo["National Calls"]={datalist:[],charge:0,showCallDetails:!0,CustomerBillingGroupDescription:undefined},u(n.InvoiceDetail).forEach(function(n){var u,s,v,y,t;if(!c||!f(e,n))if(n.CategoryName==="Broadband")angular.isUndefined(i.BroadbandInfo.datalist)&&(i.BroadbandInfo.datalist=[],i.BroadbandInfo.totalCost=0),i.BroadbandInfo.datalist.push(n);else if(n.CategoryName==="Bundle"){angular.isUndefined(i.BundleInfo.datalist)&&(i.BundleInfo.datalist=[],i.BundleInfo.totalCost=0);var p=n.Description2,l=undefined,a=p.match(/\d{2}\/\d{2}\/\d{4}/g);if(a&&a.length===2)if(u=moment(a[0],"DD/MM/YYYY"),s=moment(a[1],"DD/MM/YYYY"),u.month()===s.month()&&u.year()===s.year()){var w=u.date(),b=s.date(),k=u.clone().startOf("month").date(),d=s.clone().endOf("month").date();l=w===k&&b===d?u.format("MMMM YYYY"):u.format("DD/MM/YYYY")+" to "+s.format("DD/MM/YYYY")}else l=p;else l=p;n.billDurationTxt=l;i.BundleInfo.datalist.push(n)}else angular.equals(n.CategoryName.toLowerCase(),"mobile services")||angular.equals(n.CategoryName.toLowerCase(),"mobile voice")||angular.equals(n.CategoryName.toLowerCase(),"mobile")?(t=n.SubCategoryName,i.MobileInfo[t]===undefined&&(i.MobileInfo[t]={datalist:{},charge:0,showCallDetails:!1}),o+=parseFloat(n.Charge),v=n.NumberBilled+" - "+n.CustomerBillingGroupDescription,i.MobileInfo[t].datalist[v]===undefined&&(i.MobileInfo[t].datalist[v]={records:[],charge:0}),i.MobileInfo[t].datalist[v].records.push(n),!i.MobileInfo[t].showCallDetails&&angular.equals(n.CategoryName.toLowerCase(),"mobile voice")&&(i.MobileInfo[t].showCallDetails=!0)):angular.equals(n.CategoryName.toLowerCase(),"toll free services")?(t=n.SubCategoryName,i.TollFreeInfo[t]===undefined&&(i.TollFreeInfo[t]={datalist:{},charge:0,showCallDetails:!1,CustomerBillingGroupDescription:undefined}),h+=parseFloat(n.Charge),y=n.CustomerBillingGroupDescription,i.TollFreeInfo[t].datalist[y]===undefined&&(i.TollFreeInfo[t].datalist[y]={records:[],charge:0}),i.TollFreeInfo[t].datalist[y].records.push(n),!i.TollFreeInfo[t].showCallDetails&&angular.equals(n.SubCategoryName.toLowerCase(),"toll free")&&(i.TollFreeInfo[t].showCallDetails=!0,i.TollFreeInfo[t].CustomerBillingGroupDescription=n.CustomerBillingGroupDescription)):angular.equals(n.CategoryName.toLowerCase(),"business line services")?(t=n.SubCategoryName,i.ExtraInfo[t]===undefined&&(i.ExtraInfo[t]={datalist:[],charge:0,showCallDetails:!1,CustomerBillingGroupDescription:undefined}),r+=parseFloat(n.Charge),i.ExtraInfo[t].datalist.push(n),i.ExtraInfo[t].showCallDetails=!0):angular.equals(n.CategoryName.toLowerCase(),"power")||(t=n.SubCategoryName,i.ExtraInfo[t]===undefined&&(i.ExtraInfo[t]={datalist:[],charge:0,showCallDetails:!1,CustomerBillingGroupDescription:undefined}),r+=parseFloat(n.Charge),i.ExtraInfo[t].datalist.push(n),i.ExtraInfo[t].showCallDetails||!angular.equals(n.CategoryName.toLowerCase(),"fixed line voice")||angular.equals(n.SubCategoryName.toLowerCase(),"calling pack")||(i.ExtraInfo[t].showCallDetails=!0,i.ExtraInfo[t].CustomerBillingGroupDescription=n.CustomerBillingGroupDescription))}),!angular.isUndefined(n.InvoiceElectricityDetail)){i.ElectricityInfo={icps:[],TotalCharge:0};var v=angular.copy(n.InvoiceElectricityDetail),l=[],a=0;u(v.ICPs.ICP).forEach(function(n){var t={icp:n.IcpNumber,faultContact:n.FaultContactName,faultNumber:n.FaultContactNumber,plan:n.CurrentUserPlan,isCurrentIcp:n.IsCurrentIcp,supplyAddress:n.SupplyAddress,totalCharge:0,showMeterInfo:!1,charges:[],meters:[]};u(n.InvoiceElectricityICPCharges.InvoiceElectricityICPCharge).forEach(function(n){t.charges.push(n);t.totalCharge+=parseFloat(n.Charge)});u(n.Meters.Meter).forEach(function(n){var i={serial:n.MeterSerial,channels:[]};u(n.Channels.Channel).forEach(function(n){var r={readDate:n.LastActualReadingDate,channelNumber:n.ChannelNumber,contentCode:n.ContentCode,contentCodeDescription:n.ContentCodeDescription,periodOfAvailability:n.PeriodOfAvailability,kwhUsed:0,totalCharge:0,charges:[],readPrevious:0,readCurrent:0,readPreviousDate:n.LastActualReadingDate};u(n.InvoiceElectricityChannelCharges.InvoiceElectricityChannelCharge).forEach(function(n){n.UnitType==="kWh"&&(r.kwhUsed+=parseFloat(n.UnitsUsed));r.totalCharge+=parseFloat(n.Charge);t.totalCharge+=r.totalCharge;t.charges.push(n);r.charges.push({charge:n,chargePerUnit:n.ChargePerUnit,unitType:n.UnitType,unitsUsed:n.UnitsUsed,subCategoryName:n.SubCategoryName,readType:n.ReadType,rateDisplayName:n.RateDisplayName});r.readPrevious+=parseFloat(n.PreviousReading);r.readCurrent+=parseFloat(n.CurrentReading);var i=moment(r.readPreviousDate),u=moment(n.ReadingFromDate);r.readPreviousDate=i<u?i.format("YYYY-MM-DD")+"T00:00:00":u.format("YYYY-MM-DD")+"T00:00:00"});i.channels.push(r)});t.meters.push(i)});l.push(t);a+=t.totalCharge});i.ElectricityInfo.icps=l;i.ElectricityInfo.TotalCharge=a}return angular.forEach(i.ExtraInfo,function(n){var i=t("taxInvoiceChargeSum")(n.datalist,null);n.charge=i}),angular.forEach(i.MobileInfo,function(n){angular.forEach(n.datalist,function(i){var r=t("taxInvoiceChargeSum")(i.records,null);i.charge=r;n.charge+=r})}),angular.forEach(i.TollFreeInfo,function(n){angular.forEach(n.datalist,function(i){var r=t("taxInvoiceChargeSum")(i.records,null);i.charge=r;n.charge+=r})}),angular.isUndefined(i.BroadbandInfo.datalist)||(i.BroadbandInfo.totalCost=t("taxInvoiceChargeSum")(i.BroadbandInfo.datalist,null)),angular.isUndefined(i.BundleInfo.datalist)||(i.BundleInfo.totalCost=t("taxInvoiceChargeSum")(i.BundleInfo.datalist,null)),angular.equals(i.ExtraInfo,{})||(i.ExtraInfo.TotalCharge=r),angular.equals(i.MobileInfo,{})||(i.MobileInfo.TotalCharge=o),angular.equals(i.TollFreeInfo,{})||(i.TollFreeInfo.TotalCharge=h),angular.forEach(u(n.InvoiceBundle),function(n){i.InvoiceBundles[n.BundleBillingName]=n.BundleComponents}),i}return e}])}(),function(){function t(n){if(n&&n.status)return n;throw n;}var n=angular.module("callplus.payment.services",[]);n.service("pxFusionService",["$filter","$http","$timeout","webConfigUrls","$q","util","cache","callplusAPI",function(n,t,i,r,u,f,e,o){this.requestTypes={PURCHASE:"Purchase",AUTH:"Authorisation"};this.currency="NZD";this.validRequestType=function(n){for(var t in this.requestTypes)if(this.requestTypes.hasOwnProperty(t)&&this.requestTypes[t]===n)return!0;return!1};this.createTransaction=function(i,f,s,h){var c=this;return u(function(u,l){if(!c.validRequestType(f))throw new Error("Invalid request type for transaction. Ref: "+s);return e.flush("Payments.GetBillingInformation"),e.flush("Payments.GetAccountStatements"),o.getDefaultAccountClaim().then(function(n){return n.Claim.AccountCode}).then(function(e){var o={Payment:{RequestRecurringBilling:Boolean(i),DPSRequestType:f,AccountCode:e,Reference:s,Amount:n("number")(h,2)}};return t.post(r.host+"/payments/v1.0/DPS/CreatePXFusionTransaction",o).then(function(n){angular.equals(n.status,200)?u(n):l("CreatePxFusionFailure")},function(){l("CreatePxFusionError")})})})};this.checkTransactionStatus=function(n){return u(function(t,r){function s(){if(f>=h)t(e);else{var o=u.when();f>0&&(o=i(angular.noop,c));o.then(function(){return a(n)}).then(l,r)}}function l(n){n?n.Status==="Pending"?(f++,s()):t(n):r()}function a(n){return o.getDefaultAccountClaim().then(function(n){return n.Claim.AccountCode}).then(function(t){return o.Payments.GetTransaction(t,n).then(function(n){return angular.equals(n.status,200)?e=n.data.TransactionResultDetail:undefined})})}var f=0,h=5,c=2e3,e;s()})};this.getTransactionStatus=function(n){return u(function(t,i){return o.getDefaultAccountClaim().then(function(n){return n.Claim.AccountCode}).then(function(t){return o.Payments.GetTransaction(t,n)}).then(function(n){angular.equals(n.status,200)?t(n.data.TransactionResultDetail):i("Fails")},function(){i("Fails")})})};this.doDpsPxFusionPost=function(n,t,r,f){return u(function(e){var a=this,h=document.createElement("iframe"),c,s,o,l;h.style.display="none";c=t;document.body.appendChild(h);h.contentWindow.name=c;s=document.createElement("form");s.style.display="none";s.target=c;s.action=n;s.method="POST";o=document.createElement("input");o.type="hidden";o.name="CardNumber";o.value=r.cardNumber;s.appendChild(o);o=document.createElement("input");o.type="hidden";o.name="ExpiryMonth";o.value=r.expiryMonth;s.appendChild(o);o=document.createElement("input");o.type="hidden";o.name="ExpiryYear";o.value=r.expiryYear.slice(2);s.appendChild(o);o=document.createElement("input");o.type="hidden";o.name="CardHolderName";o.value=r.cardName;s.appendChild(o);o=document.createElement("input");o.type="hidden";o.name="SessionId";o.value=t;s.appendChild(o);o=document.createElement("input");o.type="hidden";o.name="Cvc2";o.value=r.secCode;s.appendChild(o);o=document.createElement("input");o.type="hidden";o.name="Action";o.value="Add";s.appendChild(o);o=document.createElement("input");o.type="hidden";o.name="Object";o.value="DpsPxPay";s.appendChild(o);o=document.createElement("input");o.type="submit";o.name="Submit";s.appendChild(o);document.body.appendChild(s);s.submit();l=u.when();l=i(angular.noop,6e3);l.then(function(){e(f)})})}}]);n.service("dpsAPI",["$q","$timeout","identityAPI","paymentsAPI","callplusAPI",function(n,i,r,u,f){var e=this;e.createExistingPayment=function(i,e){var o=i?n.when(i):u.getStandardReference();return n.all([r.getDefaultAccountCode(),o]).then(function(n){var t=n[0],i=n[1];return f.Payments.CreateExistingPayment(t,i,e)}).then(t).then(function(n){return n.data.TransactionID})};e.waitForConfirm=function(t,r){function s(r,u,s){function c(){if(h>=f)u("Timeout");else{var r=n.when();h>0&&(r=i(angular.noop,o));r.then(function(){return s("PollStart"),e.getTransactionStatus(t)}).finally(function(){s("PollEnd")}).then(l,u)}h++}function l(n){n==="Pending"?c():n==="Successful"?r():u(n)}var h=0;c()}if(angular.isObject(t)&&!r)return r=t,function(n){return e.waitForConfirm(n,r)};r=angular.extend({maxTries:8,timeout:3e3},r);var f=r.maxTries,o=r.timeout,u=n.defer();return i(function(){s(u.resolve,u.reject,u.notify)},0),u.promise};e.getTransactionStatus=function(n){return r.getDefaultAccountCode().then(function(t){return f.Payments.GetTransaction(t,n)}).then(t).then(function(n){var t=n.data.TransactionResultDetail;return t.Status})};e.isTransactionConfirmed=function(n){return e.getTransactionStatus(n).then(function(n){return n==="Successful"})}}])}();"use strict";var services=angular.module("myCallPlusServices",[]);String.format||(String.format=function(n){var t=Array.prototype.slice.call(arguments,1);return n.replace(/{(\d+)}/g,function(n,i){return typeof t[i]!="undefined"?t[i]:n})});services.service("util",["$location","$window","$document",function(n,t,i){this.origin=function(){var t=n.protocol(),i=n.port(),r=t+"://"+n.host();return t==="http"&&i===80||t==="https"&&i===443||(r+=":"+n.port()),r};this.addPostMessageListener=function(n){t.addEventListener?t.addEventListener("message",n,!1):i.attachEvent("onmessage",n)};this.removePostMessageListener=function(n){t.removeEventListener?t.removeEventListener("message",n):i.detachEvent("onmessage",n)};this.goToLogin=function(){if(n.path()!=="/login"){var t=n.url();n.url("/login");t!=="/"&&n.search("redirect",t)}};this.arrayFind=function(n,t){var i=null;return n.some(function(n){if(t(n))return i=n,!0}),i}}]);services.provider("functionEnabled",[function(){var n={},t=!0;this.set=function(t,i){for(var u=(""+name).split("."),r=n,t;u.length>1;)t=u.shift(),r=r[t]=r[t]||{};r[u[0]]=i};this.add_all=function(t){$.extend(!0,n,t)};this.set_default=function(n){t=n};this.get=function(i,r){var f,u,i,e;for(r===undefined&&(r=t),f=(""+i).split("."),u=n;f.length>1;)i=f.shift(),u=u[i]||{};return i=f.shift(),e=u[i],e===undefined?r:e};this.$get=[function(){var n={},t=this.get;return function(i){if(n[i]!==undefined)return n[i];var r=t(i);return n[i]=r,r}}]}]);services.service("cache",["$q",function(n){var t={};this.promiseCacheDecorator=function(i){return function(r,u){function f(){var f=JSON.stringify(arguments),e;return t[r]===undefined&&(t[r]={}),t[r][f]===undefined&&(e=u.apply(i,arguments),e.then(angular.noop,function(){delete t[r][f]}),t[r][f]=e),t[r][f].then(function(t){return n(function(n){n(angular.copy(t))})},function(t){return n(function(n,i){i(angular.copy(t))})})}return f.skipCache=function(){var n=JSON.stringify(arguments);return t[r]===undefined&&(t[r]={}),delete t[r][n],f.apply(undefined,arguments)},f}};this.flush=function(n){n?t[n]={}:t={}}}]);services.service("userSession",["$window","cache","cookieService","jwtHelper",function(n,t,i,r){function o(){return u||s.loadFromCookie(),u}var f=["token","account","isManaged"],e="mycallplus_session",u=!1,s=this;this.isExpired=function(){try{return r.isTokenExpired(this.get("token"))}catch(n){return!0}};this.set=function(n){t.flush();u={};f.forEach(function(t){u[t]=n[t]})};this.get=function(n){if(n){if(f.indexOf(n)>-1)return o()[n]}else{var t={};return f.forEach(function(n){t[n]=o()[n]}),t}};this.clear=function(){u=!1;i.deleteCookie(e,"/");t.flush()};this.saveToCookie=function(n){var t=JSON.stringify(this.get());i.createOrUpdateCookie(e,t,"/",n)};this.loadFromCookie=function(){var n=i.findCookie(e);if(n)try{return this.set(JSON.parse(n)),!0}catch(t){return!1}else return!1}}]);services.service("userInformation",["userSession","jwtHelper",function(n,t){function i(){try{return t.decodeToken(n.get("token"))}catch(i){return{}}}this.getUsername=function(){return i().sub};this.getFirstName=function(){return i().firstname};this.getLastName=function(){return i().surname};this.getName=function(){return this.getFirstName()+" "+this.getLastName()}}]);services.service("authService",["$http","$window","webConfigUrls","callplusAPI","$q","$location","cookieService","jsonToFormPost","userSession","userInformation","util",function(n,t,i,r,u,f,e,o,s,h,c){this.isAuth=function(){return u(function(n,t){var i=s.get("token");i&&!s.isExpired()?n("User authenticated with token."):t("User authentication failed or token expired")})};this.login=function(t,r,u){function f(){s.clear()}var e={username:t,password:r,longlifesession:Boolean(u),businessgroup:"CP"};return n.post(i.host+"/identity/v1.0/user/login",e,{headers:{"Content-Type":"application/x-www-form-urlencoded"},transformRequest:o}).then(function(n){if(n.data){s.set({token:n.data});var t=!u;return s.saveToCookie(t),"Auth succeeded"}return f(n)},function(n){if(n.status===403)return f(n);scExceptionHandler(n);throw n;}).then(null,function(n){if(n.status!==403)throw{reason:"Unknown"};else if(n.statusText==="InTimeout"){var t=n.headers("Retry-After"),i=t<61?t+" seconds":Math.ceil(t/60)+" minutes";throw{reason:"Timeout",time:i};}else throw{reason:"Unknown"};})};this.logout=function(){return n.post(i.host+"/identity/v1.0/user/logout").then(function(){s.clear()})};this.updatePassword=function(t,r){var f={Username:h.getUsername(),CurrentPassword:t,NewPassword:r};return u(function(t,r){n.post(i.host+"/identity/v1.0/manage/changepassword",f).then(function(){t("updatePasswordCompleteSuccess")}).catch(r)})};this.resetPassword=function(t){var r={Username:t,BusinessGroup:"CP"};return u(function(t){n.post(i.host+"/identity/v1.0/manage/initiatepasswordreset",r).then(function(){t("resetPasswordSuccess")}).catch(function(){t("resetPasswordFails")})})};this.completeResetPassword=function(t,r,f){var e={UsernameSecret:f,ResetCode:r,NewPassword:t};return u(function(t,r){n.post(i.host+"/identity/v1.0/manage/completepasswordreset",e).then(function(n){if(n.status===200)t("resetPasswordCompleteSuccess");else throw"reset fails";},function(){throw"reset fails";}).catch(function(){r("resetPasswordCompleteFails")})})};this.setPassword=function(t,r,f){var e={Password:t};return u(function(t,u){n.post(i.host+"/sales/v1.0/Ordering/Order/"+f+"/Identity/SetPassword?ordertoken="+r,e).then(function(n){if(n.status===200)t("setPasswordCompleteSuccess");else throw"set fails";},function(){throw"set fails";}).catch(function(){u("setPasswordCompleteFails")})})};this.requireAuth=function(){var n=this;return u(function(t,i){n.isAuth().then(t,function(){i();c.goToLogin()})})}}]);services.service("cookieService",["$document","$cookieStore",function(){this.cookieExpire=function(n){if(n)return"";var t=new Date;return t.setTime(t.getTime()+31536e6),"expires="+t.toUTCString()+"; "};this.cookieExpireNow=function(){var n=new Date(0);return"expires="+n.toUTCString()};this.createOrUpdateCookie=function(n,t,i,r){var u=this,f=encodeURIComponent(t);document.cookie=n+"="+f+"; "+u.cookieExpire(r)+"Path="+i};this.deleteCookie=function(n,t){var i=this;document.cookie=n+"=; "+i.cookieExpireNow()+"; Path="+t};this.findCookie=function(n){for(var u=document.cookie.split(";"),i,r,f,t=0;t<u.length;t++)if(i=u[t].trim(),r=i.indexOf("="),r>0&&(f=i.substring(0,r),f===n))return decodeURIComponent(i.substring(r+1))}}]);services.service("DefaultAccountCodeService",["$routeParams",function(n){function t(){this.accountCode=""}return t.prototype.get=function(){return this.update(),this.accountCode},t.prototype.set=function(n){this.accountCode=n},t.prototype.update=function(){n.claim&&this.set(n.claim)},new t}]);services.service("callplusAPI",["$http","$window","$timeout","DefaultAccountCodeService","webConfigUrls","userSession","cache","$q","util",function(n,t,i,r,u,f,e,o,s){var h=e.promiseCacheDecorator(this);this.getDefaultAccountClaim=function(){var n=this;return o(function(t,i){function r(n){return t({Claim:n})}var u=f.get("account");u?r({AccountCode:u}):n.Identity.AccountClaims().then(function(n){var t=n.data.AccountClaims;r(t[0])},i)})};this.getAllAccountClaims=function(){var n=this;return o(function(t,i){n.Identity.AccountClaims().then(function(n){var i=angular.isUndefined(n.data)?n.Claim.AccountCode:n.data.AccountClaims;t(i)},i)})};this.setDefaultAccountClaim=function(n){var t=this;return o(function(t,i){var r=f.get("token");r&&!f.isExpired()?(f.set({token:r,account:n}),t({Claim:{AccountCode:n}})):i("User unauthorized or token expired ")})};this.Identity={AccountClaims:h("Identity.AccountClaims",function(){return o(function(t,i){n.post(u.host+"/identity/v1.0/user/claims").then(function(n){n.data.AccountClaims&&n.data.AccountClaims.length>0?t(n):f.get("account")?t({Claim:{AccountCode:f.get("account")}}):(f.clear(),s.goToLogin(),i("Unauthorized token"))})})}),PasswordComplexity:h("Identity.PasswordComplexity",function(t){if(!t){var i=o.defer();return i.resolve({}),i.promise}return n.post(u.host+"/identity/v1.0/utilities/calculatepasswordcomplexity",{Password:t}).then(function(n){var t=n.data.RequiredComplexity,i=n.data.ActualComplexity;return{required:t,actual:i,percent:i*100/t}})})};this.Manage={GetContactInformation:h("Manage.GetContactInformation",function(t){return n.get(u.host+"/manage/v1.0/account/contactinformation",{params:{AccountCode:t}})}),SetContactInformation:function(t,i){e.flush("Manage.GetContactInformation");var r={ContactInformation:i};return n.post(u.host+"/manage/v1.0/account/contactinformation",r,{params:{AccountCode:t}})},ChangeMobileNumber:function(t,i){return e.flush("Manage.GetContactInformation"),o(function(r,f){var e={AccountCode:t,MobileNumber:i};n.post(u.host+"/manage/v1.0/account/ChangeMobileNumber",e,{params:{AccountCode:t}}).then(function(n){n.status===200?r("updateMobileNumberSuccess"):f("UpdateMobileNumberFailsServerError")},function(){f("UpdateMobileNumberFailsReject")})})},ChangePhoneNumber:function(t,i){return e.flush("Manage.GetContactInformation"),o(function(r,f){var e={AccountCode:t,PhoneNumber:i};n.post(u.host+"/manage/v1.0/account/ChangePhoneNumber",e,{params:{AccountCode:t}}).then(function(n){n.status===200?r("updatePhoneNumberSuccess"):f("UpdatePhoneNumberFailsServerError")},function(){f("UpdatePhoneNumberFailsReject")})})},GetInternetUsageByBillDate:h("Manage.GetInternetUsageByBillDate",function(t,i){return n.get(u.host+"/manage/v1.0/usage/internetbybilldate",{params:{AccountCode:t,LineNumber:i}})}),GetInternetUsageByDay:h("Manage.GetInternetUsageByDay",function(t,i,r){return n.get(u.host+"/manage/v1.0/usage/internetbyday",{params:{AccountCode:t,LineNumber:i,BillDate:r}})}),GetInternetUsageByHour:h("Manage.GetInternetUsageByHour",function(t,i,r){return n.get(u.host+"/manage/v1.0/usage/internetbyhour",{params:{AccountCode:t,LineNumber:i,BillDate:r}})}),GetCallUsage:h("Manage.GetCallUsage",function(t,i){return n.get(u.host+"/manage/v1.0/usage/calling",{params:{AccountCode:t,BillDate:i}})}),GetProductOrders:h("Manage.GetProductOrders",function(t){return n.get(u.host+"/manage/v1.0/product/productorders",{params:{AccountCode:t}})}),GetProducts:h("Manage.GetProducts",function(t){return n.get(u.host+"/manage/v1.0/product/products",{params:{AccountCode:t}}).then(function(n){return angular.equals(n.status,200)||(n.data={CoreProducts:[]}),n})}),GetPowerDailyUsage:h("Manage.GetPowerDailyUsage",function(t,i,r){var f=moment(new Date).format("YYYY-MM-DD");return f===r&&(r="null"),n.get(String.format("{0}/accounts/{1}/electricityServices/{2}/usagedaily?billDate={3}",u.apiGatewayHost,t,i,r)).then(function(n){return angular.equals(n.status,200)||(n.data={fixedCharges:[],variableCharges:[]}),n})}),GetPowerMonthlyUsage:h("Manage.GetPowerMonthlyUsage",function(t,i){return n.get(String.format("{0}/accounts/{1}/electricityServices/{2}/usagesummary",u.apiGatewayHost,t,i)).then(function(n){return angular.equals(n.status,200)||(n.data={fixedCharges:[],variableCharges:[]}),n})})};this.Payments={GetBillingInformation:h("Payments.GetBillingInformation",function(t){return n.get(u.host+"/payments/v1.0/manage/billinginformation",{params:{AccountCode:t}})}),GetPaymentMethod:h("Payments.GetPaymentMethod",function(t){return n.get(u.host+"/payments/v1.0/manage/recurringpayment",{params:{AccountCode:t}})}),GetAllowedPaymentMethods:h("Payments.GetAllowedPaymentMethods",function(t){return n.get(u.host+"/payments/v1.0/manage/recurringpaymentmethods",{params:{AccountCode:t}})}),SetPaymentMethod:function(t,i,r){function s(n){return n.toString().replace(/\s/g,"")}var h=i.RecurringPaymentType,f={RecurringPaymentType:h,RecurringPaymentDetail:{}},c;switch(h){case"PaperlessDirectDebit":f.RequestorName=i.RecurringPaymentDetail.AccountName;f.RequestorEmail=r.ContactEmail;f.BankName=i.RecurringPaymentDetail.BankName;f.ConfirmAccountAuthority=!0;f.ConfirmTermsConditions=!0;f.BankAccountDetail={AccountName:i.RecurringPaymentDetail.AccountName,Bank:s(i.RecurringPaymentDetail.BankAccountDetail.Bank),Branch:s(i.RecurringPaymentDetail.BankAccountDetail.Branch),Account:s(i.RecurringPaymentDetail.BankAccountDetail.Account),Suffix:s(i.RecurringPaymentDetail.BankAccountDetail.Suffix)};break;case"PreviousDPSTransaction":f.TransactionID=i.RecurringPaymentDetail.TransactionID;break;case"Manual":f={accountcode:t};break;default:throw new Error("Unsupported payment type");}return e.flush("Payments.GetPaymentMethod"),c=h.toLowerCase(),o(function(i,r){n.post(u.host+"/payments/v1.0/manage/recurringpayment/"+c+"/"+t,f).then(function(n){n.status===200?i("updatePaymentMethodSuccess"):r("updatePaymentMethodFailsServerError")},function(n){r(n.data)})})},CreateExistingPayment:function(t,i,r){return n.post(u.host+"/payments/v1.0/DPS/createExistingPayment",{PaymentDetail:{AccountCode:t,Reference:i,Amount:r}})},GetTransaction:function(t,i){return n.get(u.host+"/payments/v1.0/DPS/GetTransaction",{params:{AccountCode:t,TransactionID:i}})},GetInvoiceHeaders:h("Payments.GetInvoiceHeaders",function(t){var r=this,i=n.get(u.host+"/payments/v1.0/manage/invoiceheaders",{params:{AccountCode:t}}),f=3;return i.then(function(n){n.data.InvoiceHeaders&&n.data.InvoiceHeaders.length>0&&n.data.InvoiceHeaders.slice(-f).forEach(function(n){r.Payments.GetInvoice(t,n.InvoiceNumber)})}),i}),GetInvoice:h("Payments.GetInvoice",function(t,i){return o(function(r,f){n.get(u.host+"/payments/v1.0/manage/invoice",{params:{AccountCode:t,InvoiceNumber:i}}).then(r).catch(function(n){n.status===403?f({reason:"Invoice could not be retrieved."}):scExceptionHandler(n)})})}),GetAccountStatements:h("Payments.GetAccountStatements",function(t){return n.get(u.host+"/payments/v1.0/manage/accountStatements",{params:{AccountCode:t}})}),GetPendingCredits:h("Payments.GetPendingCredits",function(t){return n.get(u.host+"/payments/v1.0/manage/pendingcredits",{params:{AccountCode:t}})})}}]);services.service("backService",["$location","$rootScope",function(n,t){var i;this.setBackPath=function(n){i=n};document.addEventListener("backbutton",function(){i&&(n.path(i),i=undefined,t.$apply())})}]);services.factory("authInterceptor",["$rootScope","$q","$window","webConfigUrls","userSession","util","$injector",function(n,t,i,r,u,f,e){function s(n){n.headers=n.headers||{};var t=u.get("token");return t&&(n.headers.Authorization="bearer "+t),n}function o(n){return n.status===403&&u.get("token")?n.config.url===r.host+"/identity/v1.0/user/claims"?(u.clear(),f.goToLogin(),t.reject({})):e.get("callplusAPI").Identity.AccountClaims.skipCache().then(function(){return t.reject(n||t.when(n))}):(n.status===401&&(!u.get("isManaged")||u.isExpired())&&(u.clear(),f.goToLogin()),n||t.when(n))}return{request:s,response:o,responseError:o}}]);services.config(["$httpProvider",function(n){n.interceptors.push("authInterceptor")}]);services.factory("messages",["$rootScope",function(n){var t=[],i=[];return n.$on("$routeChangeSuccess",function(){t.length=0;i.forEach(function(n){t.push(n)});i=[]}),{setMessage:function(n){i.push(n)},showMessage:function(n){t.push(n)},clear:function(){t.length=0},messages:t}}]);services.factory("jsonToFormPost",function(){return function(n){var t=[];return angular.forEach(n,function(n,i){t.push(encodeURIComponent(i)+"="+encodeURIComponent(n))}),t.join("&")}});services.service("PaymentInformation",["callplusAPI","$q",function(n,t){function i(){this.db={};this.doneInit=!1}return i.prototype.update=function(){this.doneInit=!1;var i=this;return this.db={},n.getDefaultAccountClaim().then(function(r){var u=i.db.AccountCode=r.Claim.AccountCode;return t.all([n.Manage.GetContactInformation(u).then(function(n){i.db.ContactInformation=n.data.ContactInformation}),n.Payments.GetPaymentMethod(u).then(function(n){var r,u,t;r=angular.equals(n.status,200)?n.data:{RecurringPaymentType:"Manual"};i.db.type=r.RecurringPaymentType;i.isCreditCard()?(u=r.GetRecurringPaymentDetail.MaskedCardDetail,i.db.Expiry=u.Expiry,i.db.ExpiryMoment=moment(i.db.Expiry,"MMYY").add(1,"month").subtract(1,"second"),i.db.Number=u.MaskedNumber,i.db.Type=u.Type):i.isDirectDebit()&&(t=r.GetRecurringPaymentDetail.BankAccountDetail,i.db.Number=t.Bank+"-"+t.Branch+"-"+t.Account+"-"+t.Suffix)}),n.Payments.GetAllowedPaymentMethods(u).then(function(n){i.db.isRemovePaymentMethodAllowed=angular.equals(n.status,200)?n.data.RecurringPaymentMethodList.indexOf("Manual")>=0:!1})]).then(function(){i.doneInit=!0})}).catch(scExceptionHandler)},i.prototype.isCreditCard=function(){return this.db.type==="CreditCard"},i.prototype.isDirectDebit=function(){return this.db.type==="DirectDebit"},i.prototype.isNoPayment=function(){return this.db.type==="Manual"},i.prototype.isCreditCardAndValid=function(){return this.isCreditCard()&&moment().diff(this.db.ExpiryMoment,"days")<0},i.prototype.getMonthsToCreditCardExpiry=function(){if(this.isCreditCard()&&this.db.ExpiryMoment)return this.db.ExpiryMoment.diff(moment(),"month")},i.prototype.isCreditCardAndExpired=function(){return this.isCreditCard()&&moment().diff(this.db.ExpiryMoment,"days")>0},i.prototype.hasInit=function(){return this.doneInit},new i}]);services.service("xmlConverter",["$q",function(n){function i(i){return n(function(n){var u=new X2JS,r=u.xml_str2json(i);t(r);n(r)})}function t(n){typeof n=="object"&&Object.keys(n).forEach(function(i){var r=n[i];r["_xsi:nil"]==="true"?n[i]=null:t(r)})}return i}]),function(){function r(n,t){var i=n.concat(t);return i.forEach(function(n){n.dateBilled||(n.dateBilled=moment().format())},this),i}function u(n){var t=[];return angular.forEach(n,function(n,i){var e="",o=i,r=0,u=0,f=0,s="",h="";n.forEach(function(n){e=n.icp;o=n.dateBilled;s=n.readingFromDate;h=n.readingFromDate;r=r+n.chargeGSTExcl;u=u+n.chargeIncludingGst;n.Channel&&(f=f+n.consumedUnits)},this);t.push({Icp:e,DateBilled:o,ChargeGSTExcl:r,ChargeIncludingGst:u,ReadingFromDate:s,ReadingToDate:h,ConsumedUnits:f})}),t}function f(n){var t=[];return angular.forEach(n,function(n,i){var o="",s=i,r="",u=0,f=0,e=0;n.forEach(function(n){o=n.Icp;s=n.billDate;r=n.readingDate;u=u+n.chargeExcludingGst;f=f+n.chargeIncludingGst;n.Channel&&(e=e+n.currentReadValue-n.previousReadValue)},this);t.push({Icp:o,DateBilled:s,ChargeExcludingGst:u,ChargeIncludingGst:f,ReadingDate:r,ReadingDay:Number(moment(r).format("DD")),DailyUsagekWh:e})}),t}var n=angular.module("callplus.usage.services",[]),t="#C4E8FA",i="#009FEE";n.factory("dailyDataUsageOpts",["$filter",function(n){return function(){return{colors:[t,i],xaxis:{min:0,max:32},yaxis:{tickFormatter:function(t){return n("number")(t/1024,1)+" GB"}},grid:{color:"#e5e5e5",outline:"s"},mouse:{trackFormatter:function(t){var i=parseFloat(n("megaToBytes")(t.y));return n("dataValueForRead")(i)}}}}}]);n.factory("monthlyDataUsageOpts",["$filter",function(n){return function(){return{colors:[t,i],xaxis:{min:-1,max:12},yaxis:{noTicks:5,tickFormatter:function(t){return n("number")(t/1024,2)+" GB"}},grid:{color:"#e5e5e5",outline:"s",verticalLines:!1},mouse:{trackFormatter:function(t){var i=parseFloat(n("megaToBytes")(t.y));return n("dataValueForRead")(i)+" - Click for more details"}}}}}]);n.factory("dailyVoiceUsageOpts",["$filter",function(n){return function(){return{colors:[i,t],bars:{show:!0,horizontal:!1,stacked:!1,barWidth:.46,lineWidth:1,shadowSize:0},xaxis:{min:0},yaxis:{min:0},grid:{color:"#e5e5e5",outline:"s"},mouse:{trackFormatter:function(t){return n("minsToString")(t.y,"mins")}}}}}]);n.factory("monthlyVoiceUsageOpts",["$filter",function(n){return function(){return{colors:[i,t],bars:{show:!0,horizontal:!1,stacked:!1,barWidth:.46,lineWidth:1,shadowSize:0},xaxis:{min:-1,max:12},yaxis:{noTicks:5,tickFormatter:function(t){return n("minsToString")(t,"mins")}},grid:{color:"#e5e5e5",outline:"s",verticalLines:!1},mouse:{trackFormatter:function(t){return n("minsToString")(t.y,"mins")+" - Click for more details"}}}}}]);n.factory("dailyPowerUsageOpts",["$filter",function(){return function(){return{colors:[i,t],bars:{show:!0,horizontal:!1,stacked:!1,barWidth:.46,lineWidth:1,shadowSize:0},xaxis:{min:0},yaxis:{min:0},grid:{color:"#e5e5e5",outline:"s"},mouse:{trackFormatter:function(n){var t="$"+n.y+" / "+Math.round(n.x);switch(parseInt(n.x)){case 1:t+="st";break;case 2:t+="nd";break;case 3:t+="rd";break;default:t+="th"}return t}}}}}]);n.factory("monthlyPowerUsageOpts",["$filter",function(){return function(){return{colors:[i,t],bars:{show:!0,horizontal:!1,stacked:!1,barWidth:.46,lineWidth:1,shadowSize:0},xaxis:{min:0},yaxis:{min:0},grid:{color:"#e5e5e5",outline:"s"},mouse:{trackFormatter:function(n){return"$"+n.y}}}}}]);n.service("usageInformationService",["$q","$filter","callplusAPI",function(n,t,i){function r(){}return r.prototype.getAccountCode=function(){return i.getDefaultAccountClaim().then(function(n){return n.Claim.AccountCode})},r.prototype.getLineNumber=function(){var n=this;return n.getAccountCode().then(function(n){return i.Manage.GetProducts(n)}).then(function(n){var t;return n.data.CoreProducts?(n.data.CoreProducts.some(function(n){for(var u=n.CoreProductComponents,r,i=0;i<u.length;i++)if(r=u[i],r.CoreProductComponentService==="Internet")return t=r.CoreProductComponentServiceID,!0}),t):undefined})},r.prototype.getInternetUsageByBillDates=function(){var t=this;return n.all([t.getAccountCode(),t.getLineNumber()]).then(function(n){var r=n[0],t=n[1];if(!angular.isUndefined(t))return i.Manage.GetInternetUsageByBillDate(r,t)}).then(function(t){return t&&t.data.InternetUsageByBillDates?t.data.InternetUsageByBillDates:n.reject()})},r.prototype.getBillingInformation=function(){var n=this;return n.getAccountCode().then(function(n){return i.Payments.GetBillingInformation(n)}).then(function(n){var t=n.data.BillingInformation;return t?{current:moment(t.CurrentInvoiceDate),next:moment(t.NextInvoiceDate)}:{current:undefined,next:undefined}})},r.prototype.getBillingDates=function(){var t=this;return t.getAccountCode().then(function(r){return n.all([i.Payments.GetInvoiceHeaders(r),t.getBillingInformation()])}).then(function(n){var u=n[0],t=n[1],i=[],f=u.data.InvoiceHeaders,r=!1;return angular.forEach(f,function(n){i.push(moment(n.BillDate));t.next&&angular.equals(moment(n.BillDate),t.next)&&(r=!0)}),t.next&&!r&&i.push(t.next),i})},r.prototype.getInvoiceBillingDate=function(n){n=parseInt(n);var t=this;return t.getAccountCode().then(function(n){return i.Payments.GetInvoiceHeaders(n)}).then(function(t){for(var u=t.data.InvoiceHeaders,r,i=0;i<u.length;i++)if(r=u[i],parseInt(r.InvoiceNumber)===n)return moment(r.BillDate);return undefined})},r.prototype.getNextBillDate=function(){var n=this;return n.getBillingInformation().then(function(n){return n.next})},r.prototype.getLastBillDate=function(){var n=this;return n.getBillingInformation().then(function(n){return n.current})},r.prototype.isCurrentBillSync=function(n){return n.isAfter(new Date)},r.prototype.getMonthlyDataUsage=function(){var t=this;return n.all([t.getInternetUsageByBillDates(),t.getBillingDates()]).then(function(n){var i=n[0],r=n[1],t={};return angular.forEach(i,function(n){var r=moment(n.BillDate),i=r.year(),u=r.month();t[i]||(t[i]={});t[i][u]=n.MBUsed}),t},function(){return t.getBillingDates().then(function(n){var t={};return angular.forEach(n,function(n){n=moment(n);var i=n.year(),r=n.month();t[i]||(t[i]={});t[i][r]=0}),t})})},r.prototype.getCurrentMonthDataUsageStat=function(){var t=this;return n.all([t.getBillingDates(),t.getMonthlyDataUsage()]).then(function(n){for(var u=n[0],o=n[1],i,r=0;r<u.length;r++)if(i=u[r],t.isCurrentBillSync(i)){var f=o[i.year()][i.month()],e=moment(i).add(-1,"month").add(1,"days"),s=i.diff(e,"days")+1,h=moment(new Date).diff(e,"days")+1;return{current:f,predicted:f*s/h}}return{current:0,predicted:0}})},r.prototype.getDailyDataUsageForPeriod=function(t){var r=this;return n.all([r.getAccountCode(),r.getLineNumber()]).then(function(n){var u=n[0],r=n[1];if(!angular.isUndefined(r))return i.Manage.GetInternetUsageByDay(u,r,moment(t).format("YYYY-MM-DD"))}).then(function(n){return n?n.data.InternetUsageByDays:[]})},r.prototype.getHourlyDataUsageForPeriod=function(t){var r=this;return n.all([r.getAccountCode(),r.getLineNumber()]).then(function(n){var u=n[0],r=n[1];if(!angular.isUndefined(r))return i.Manage.GetInternetUsageByHour(u,r,moment(t).format("YYYY-MM-DD"))}).then(function(n){return n.data.InternetUsageByHours||[]})},r.prototype.getCallUsageForBill=function(n,t){var r=this;return r.getAccountCode().then(function(t){return i.Manage.GetCallUsage(t,moment(n).format("YYYY-MM-DD"))}).then(function(n){return n.data.Transactions}).then(function(n){var i=[];return angular.forEach(n,function(n){var r=n.Duration,u=n.ChargeIncludingGST,f=0,e=0,o;r>0&&u>0?f=r:r>0&&u===0&&(e=r);o={dateTime:moment(n.Date),type:n.SubCategoryName,numberCalled:n.NumberDialed,numberBilled:n.NumberBilled,destinationCategory:n.SubCategoryName,duration:n.Duration,durationFree:n.DurationFree,durationCharged_m:moment.duration(f,"seconds"),durationFree_m:moment.duration(e,"seconds"),duration_m:moment.duration(r,"seconds"),charge:u,callingPackName:n.CallingPackName,callingPackBillingDescription:n.CallingPackBillingDescription};(angular.isUndefined(t)||angular.equals(t,"")||angular.equals(t,n.NumberBilled))&&i.push(o)}),i.sort(function(n,t){return moment(n.dateTime).diff(t.dateTime)})})},r.prototype.getBilledNumbers=function(n){return this.getCallUsageForBill(n,"").then(function(n){var t=[];return angular.forEach(n,function(n){t.indexOf(n.numberBilled)<0&&t.push(n.numberBilled)}),t})},r.prototype.getCallAggregateForBill=function(n,i,r){return this.getCallUsageForBill(n,i).then(function(n){var i={},u=t("filter")(n,r);return angular.forEach(u,function(n){var r=moment(n.dateTime).valueOf(),t;i[r]||(i[r]={free:moment.duration(0),charged:moment.duration(0),cost:0});t=i[r];t.free=t.free.add(n.durationFree_m);t.charged=t.charged.add(n.durationCharged_m);t.cost=t.cost+n.charge}),i})},new r}]);n.service("usageGraphHelper",[function(){return{buildYTicks:function(n,t,i,r){for(var s=i,f=n/t,e=[],o="",u=0;u<=t;u++)o=s.indexOf(u)!==-1?r(u*f):"",e.push([u*f,o]);return e},getPeriodStart:function(n){return moment(n).add(-1,"month").add(1,"days")},buildDailyXTicks:function(n,t){for(var i=moment(n),f=i.month(),e=[],u,r=0;i.isBefore(t);r++,i=i.add(1,"day"))r===0?u="D MMM<br/>dddd":r%7==0&&(f!==i.month()?(u="D MMM",f=i.month()):u="D"),u&&(e.push([r+1,i.format(u)]),u=!1);return{labels:e,max:r}}}}]);n.service("dailyDataUsageGraphHelper",["$q","$filter","usageInformationService","usageGraphHelper","dailyDataUsageOpts",function(n,t,i,r,u){return function(n){n=moment(n);var f=r.getPeriodStart(n);return i.getDailyDataUsageForPeriod(n).then(function(n){var i=0,t=[[],[]],r=moment(new Date).startOf("day");return angular.forEach(n,function(n,u){var f=moment(n.Date);i<n.MBTotal&&(i=n.MBTotal);f.isSame(r)?(t[0].push([u+1,0]),t[1].push([u+1,n.MBTotal])):(t[0].push([u+1,n.MBTotal]),t[1].push([u+1,0]))}),{max:i,dataPoints:t}}).then(function(i){var o=Math.ceil(i.max/512)*512+128,h=r.buildYTicks(o,5,[1,3],function(n){return t("number")(n/1024,1)+" GB"}),s=r.buildDailyXTicks(f,n),c=moment(n).diff(f,"days")+1,e=u();return e.xaxis.ticks=s.labels,e.xaxis.max=s.max+1,e.yaxis.ticks=h,e.yaxis.max=o,{graphData:i.dataPoints,graphOptions:e,billingPeriodDurationInDays:c}})}}]);n.service("monthlyDataUsageGraphHelper",["$q","$filter","usageInformationService","usageGraphHelper","monthlyDataUsageOpts",function(n,t,i,r,u){return function(f){var e=parseInt(f);n.all([i.getBillingDates(),i.getMonthlyDataUsage()]).then(function(n){var u=n[0],o=n[1],t=[[],[]],r=0;return u.forEach(function(n){if(moment(n).year()===e){var u=n.month(),s=o[f][u];s>r&&(r=s);i.isCurrentBillSync(n)?(t[0].push([u,"0"]),t[1].push([u,s])):(t[0].push([u,s]),t[1].push([u,"0"]))}}),{usage:t,maxValue:r}}).then(function(n){var e=n.usage,o=n.maxValue,f=Math.ceil((1+o)/5)*5,s=r.buildYTicks(f,5,[1,3],function(n){return t("number")(n/1024,1)+" GB"}),i=u();return i.yaxis.ticks=s,i.yaxis.max=f,{graphData:e,graphOptions:i}})}}]);n.service("dailyVoiceUsageGraphHelper",["$q","$filter","usageInformationService","usageGraphHelper","dailyVoiceUsageOpts",function(n,t,i,r,u){function f(n,t){var i=!1;return angular.forEach(n,function(n){i||angular.equals(n[0],t)&&(i=!0)}),i}function e(n,t,i){var r=0;return angular.forEach(n,function(n){if(angular.equals(n[0],t)){var u=n[1];r=u+i;n[1]=r}}),r}return function(n,o,s){n=moment(n);var h=r.getPeriodStart(n);return i.getCallAggregateForBill(n,o,s).then(function(n){var i=0,t=[[],[]];return angular.forEach(n,function(n,r){var c=0,l=0,u=moment(parseInt(r)).diff(h,"days")+1,o=moment.duration(n.free).asMinutes(),s=moment.duration(n.charged).asMinutes();s>0&&(f(t[0],u-.23)?c=e(t[0],u-.23,s):(t[0].push([u-.23,s]),c=s));o>0&&(f(t[1],u+.23)?l=e(t[1],u+.23,o):(t[1].push([u+.23,o]),l=o));i=Math.max(i,l+c)}),{max:i,dataPoints:t}}).then(function(i){var e=Math.ceil((1+i.max)/5)*6,s=r.buildYTicks(e,5,[1,3],function(n){return t("minsToString")(n,"mins")}),o=r.buildDailyXTicks(h,n),f=u();return f.xaxis.ticks=o.labels,f.xaxis.max=o.max+1,f.yaxis.ticks=s,f.yaxis.max=e,{graphData:i.dataPoints,graphOptions:f}})}}]);n.service("monthlyVoiceUsageGraphHelper",["$q","$filter","usageInformationService","usageGraphHelper","monthlyVoiceUsageOpts",function(n,t,i,r,u){return function(f,e,o){return i.getBillingDates().then(function(t){var u=parseInt(f),r=[];return angular.forEach(t,function(n){moment(n).year()===u&&r.push(i.getCallAggregateForBill(n,e,o).then(function(t){var i=moment.duration(0),r=moment.duration(0),u=0;return angular.forEach(t,function(n){i=i.add(n.free);r=r.add(n.charged);u+=n.cost}),{date:n,free:i,charged:r,cost:u}}))}),n.all(r)}).then(function(n){var f=[[],[]],o=[],e=0,s=0;angular.forEach(n,function(n){s+=n.cost;var u=moment(n.date),t=u.month(),i=n.free.asMinutes(),r=n.charged.asMinutes();r>0&&f[0].push([t-.23,r]);i>0&&f[1].push([t+.23,i]);e=Math.max(e,i+r);o.push([t,u.format("D MMM")])});var h=Math.ceil((1+e)/5)*5,c=r.buildYTicks(h,5,[1,3],function(n){return t("minsToString")(n,"mins")}),i=u();return i.xaxis.ticks=o,i.yaxis.ticks=c,i.yaxis.max=h,{totalCost:s,graphData:f,graphOptions:i}})}}]);n.service("powerDailyUsage",function(){this.GetPowerDailyUsage=function(n){var t=r(n.fixedCharges,n.variableCharges),i=_.groupBy(t,"readingDate");return f(i)};this.GetPowerDailyProps=function(n,t){var e=0,o=0,s=[],c=[],l=[],a=0,v=0,r=[],u=[],f,i,h;return angular.forEach(t,function(t){var h=moment(n).format("MM"),i;t.BillDate?(i=moment(t.BillDate).format("MM"),h==i&&(e+=t.ChargeExcludingGst,o+=t.DailyUsagekWh,u.push(Math.round(t.ChargeExcludingGst)),r.push(Number(moment(t.ReadingDate).format("DD"))),f=[Number(moment(t.ReadingDate).format("DD")),Math.round(t.ChargeExcludingGst)],s.push(f))):(e+=t.ChargeExcludingGst,o+=t.DailyUsagekWh,u.push(Math.round(t.ChargeExcludingGst)),r.push(Number(moment(t.ReadingDate).format("DD"))),f=[Number(moment(t.ReadingDate).format("DD")),Math.round(t.ChargeExcludingGst)],s.push(f))}),i=Math.round(u.sort(function(n,t){return n-t})[u.length-1]),h=Math.round(i/2),i&&l.push([0,"$0"],[h,"$"+h],[i,"$"+i]),i&&c.push([1,"1st"],[10,"10th"],[20,"20th"],[31,"31th"]),a=r.sort(function(n,t){return n-t})[0]-1,v=r.sort(function(n,t){return n-t})[r.length-1]+1,{SpendToDate:e,UsageToDate:o,GraphData:s,GraphXticks:c,GraphYticks:l,MinDay:a,MaxDay:v}}});n.service("powerMonthlyService",function(){this.GetPowerMonthlyUsage=function(n){var t=r(n.fixedCharges,n.variableCharges),i=_.groupBy(t,"dateBilled");return u(i)};this.GetPowerUsageBillDates=function(n){var t=[],i=[];return angular.forEach(n,function(n){var u=moment(n.DateBilled),f=u.valueOf(),r;t.indexOf(f)===-1&&t.push(f);r=u.year();i.indexOf(r)===-1&&i.push(r)}),t.sort().reverse(),i.sort().reverse(),{BillingDates:t,BillingYears:i}};this.GetPowerMonthlyProps=function(n,t){for(var o=0,s=0,h=[],c=[],l=[],f=[],a,r,u,e,i=0;i<t.length;i++)a=moment(t[i].ReadingToDate).format("YYYY"),a==n&&(o+=t[i].ChargeGSTExcl,s+=t[i].ConsumedUnits,f.push(Math.round(t[i].ChargeGSTExcl)),r=t[i].DateBilled?moment(t[i].DateBilled):moment().format(),h.push([Number(moment(r).format("MM")),Math.round(t[i].ChargeGSTExcl),r.valueOf()]),c.push([Number(moment(r).format("MM")),moment(r).format("MMM")]));return u=Math.round(f.sort(function(n,t){return n-t})[f.length-1]),e=Math.round(u/2),u&&l.push([0,"$0"],[e,"$"+e],[u,"$"+u]),{TotalMonthlySpend:o,TotalMonthlyUsage:s,MonthlyGraphData:h,GraphXticks:c,GraphYticks:l}}})}()