From 80e4d2329aa7d0dc99441f13ec2ca2ac31bc5634 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 6 Apr 2017 16:52:25 -0400 Subject: [PATCH] org settings and billing --- src/app/filters/jsonDateFilter.js | 8 ++ .../organizationBillingController.js | 68 +++++++++++- .../organizationSettingsController.js | 19 +++- .../views/organizationBilling.html | 104 +++++++++++++++++- .../views/organizationSettings.html | 46 +++++++- src/app/services/apiService.js | 1 + src/app/services/authService.js | 11 ++ src/index.html | 1 + 8 files changed, 249 insertions(+), 9 deletions(-) create mode 100644 src/app/filters/jsonDateFilter.js diff --git a/src/app/filters/jsonDateFilter.js b/src/app/filters/jsonDateFilter.js new file mode 100644 index 0000000000..8d05e4a124 --- /dev/null +++ b/src/app/filters/jsonDateFilter.js @@ -0,0 +1,8 @@ +angular + .module('bit.filters') + + .filter('jsonDate', function () { + return function (input) { + return input.split('T').join(' '); + }; + }); diff --git a/src/app/organization/organizationBillingController.js b/src/app/organization/organizationBillingController.js index f4f06be4f4..9202a54edc 100644 --- a/src/app/organization/organizationBillingController.js +++ b/src/app/organization/organizationBillingController.js @@ -1,6 +1,72 @@ angular .module('bit.organization') - .controller('organizationBillingController', function ($scope) { + .controller('organizationBillingController', function ($scope, apiService, $state) { + $scope.charges = []; + $scope.paymentSource = null; + $scope.plan = null; + $scope.subscription = null; + $scope.loading = true; + $scope.$on('$viewContentLoaded', function () { + apiService.organizations.getBilling({ id: $state.params.orgId }, function (org) { + $scope.loading = false; + + $scope.plan = { + name: org.Plan, + type: org.PlanType, + maxUsers: org.MaxUsers + }; + + $scope.subscription = { + trialEndDate: org.Subscription.TrialEndDate, + nextBillDate: org.Subscription.NextBillDate, + cancelNext: org.Subscription.CancelAtNextBillDate, + status: org.Subscription.Status + }; + + if (org.Subscription.Items) { + $scope.subscription.items = []; + for (var i = 0; i < org.Subscription.Items.length; i++) { + $scope.subscription.items.push({ + amount: org.Subscription.Items[i].Amount, + name: org.Subscription.Items[i].Name, + interval: org.Subscription.Items[i].Interval, + qty: org.Subscription.Items[i].Quantity + }); + } + } + + if (org.PaymentSource) { + $scope.paymentSource = { + type: org.PaymentSource.Type, + description: org.PaymentSource.Description, + cardBrand: org.PaymentSource.CardBrand + }; + } + + var charges = []; + for (var i = 0; i < org.Charges.length; i++) { + charges.push({ + date: org.Charges[i].CreatedDate, + paymentSource: org.Charges[i].PaymentSource ? org.Charges[i].PaymentSource.Description : '-', + amount: org.Charges[i].Amount, + status: org.Charges[i].Status, + failureMessage: org.Charges[i].FailureMessage, + refunded: org.Charges[i].Refunded, + partiallyRefunded: org.Charges[i].PartiallyRefunded, + refundedAmount: org.Charges[i].RefundedAmount + }); + } + $scope.charges = charges; + }); + }); + + $scope.changePayment = function () { + + }; + + $scope.cancel = function () { + + }; }); diff --git a/src/app/organization/organizationSettingsController.js b/src/app/organization/organizationSettingsController.js index 884803ff3e..6e9ad777eb 100644 --- a/src/app/organization/organizationSettingsController.js +++ b/src/app/organization/organizationSettingsController.js @@ -1,6 +1,23 @@ angular .module('bit.organization') - .controller('organizationSettingsController', function ($scope) { + .controller('organizationSettingsController', function ($scope, $state, apiService, toastr, authService) { + $scope.model = {}; + $scope.$on('$viewContentLoaded', function () { + apiService.organizations.get({ id: $state.params.orgId }, function (org) { + $scope.model = { + name: org.Name, + billingEmail: org.BillingEmail, + businessName: org.BusinessName + }; + }); + }); + $scope.generalSave = function () { + $scope.generalPromise = apiService.organizations.put({ id: $state.params.orgId }, $scope.model, function (org) { + authService.updateProfileOrganization(org).then(function (updatedOrg) { + toastr.success('Organization has been updated.', 'Success!'); + }); + }).$promise; + }; }); diff --git a/src/app/organization/views/organizationBilling.html b/src/app/organization/views/organizationBilling.html index 6c69ae5659..d77b4fbc6b 100644 --- a/src/app/organization/views/organizationBilling.html +++ b/src/app/organization/views/organizationBilling.html @@ -7,10 +7,110 @@
-

My Org

+

Plan

- Some data +
+
+
+
Name
+
{{plan.name}}
+
Maximum Users
+
{{plan.maxUsers}}
+
+
+
+
+
Status
+
{{subscription.status}}
+
Next Bill Date
+
{{subscription.nextBillDate | jsonDate}}
+
+
+
+
+
+ Details +
+ Loading... +
+
+ + + + + + + +
+ {{item.name}} {{item.qty > 1 ? '×' + item.qty : ''}} + @ {{item.amount | currency:'$'}} /{{item.interval}} + {{(item.qty * item.amount) | currency:'$'}} /{{item.interval}}
+
+
+
+
+ +
+
+
+

Payment Method

+
+
+
+ Loading... +
+
+ No payment method on file. +
+
+ +
+
+ +
+
+
+

Charges

+
+
+
+ Loading... +
+
+ No charges. +
+
+ + + + + + + + + +
+ {{charge.date | jsonDate}} + + {{charge.paymentSource}} + + {{charge.status}} + + {{charge.amount | currency:'$'}} +
+
diff --git a/src/app/organization/views/organizationSettings.html b/src/app/organization/views/organizationSettings.html index 0593598134..f17eec60d9 100644 --- a/src/app/organization/views/organizationSettings.html +++ b/src/app/organization/views/organizationSettings.html @@ -5,12 +5,48 @@
-
+
-

My Org

-
-
- Some data +

General

+
+
+
+
+
+

Errors have occured

+
    +
  • {{e}}
  • +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+
+
+ +
diff --git a/src/app/services/apiService.js b/src/app/services/apiService.js index 59054fb0a9..9086bc3016 100644 --- a/src/app/services/apiService.js +++ b/src/app/services/apiService.js @@ -35,6 +35,7 @@ _service.organizations = $resource(_apiUri + '/organizations/:id', {}, { get: { method: 'GET', params: { id: '@id' } }, + getBilling: { url: _apiUri + '/organizations/:id/billing', method: 'GET', params: { id: '@id' } }, list: { method: 'GET', params: {} }, post: { method: 'POST', params: {} }, put: { method: 'POST', params: { id: '@id' } }, diff --git a/src/app/services/authService.js b/src/app/services/authService.js index 31f29e5f58..5c1268a5f5 100644 --- a/src/app/services/authService.js +++ b/src/app/services/authService.js @@ -140,6 +140,17 @@ angular }); }; + _service.updateProfileOrganization = function (org) { + return _service.getUserProfile().then(function (profile) { + if (profile) { + if (profile.organizations && org.Id in profile.organizations) { + profile.organizations[org.Id].name = org.Name; + _userProfile = profile; + } + } + }); + }; + _service.isAuthenticated = function () { return tokenService.getToken() !== null; }; diff --git a/src/index.html b/src/index.html index 66ba19e9fa..08d168fa44 100644 --- a/src/index.html +++ b/src/index.html @@ -93,6 +93,7 @@ +