Skip to content

Commit 46729b2

Browse files
committed
Add next bill info to payment page
1 parent 70a8720 commit 46729b2

8 files changed

Lines changed: 471 additions & 402 deletions

File tree

OpenFlow/src/Messages/Message.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,8 +1745,9 @@ export class Message {
17451745
if (Util.IsNullUndefinded(msg.userid)) msg.userid = cli.user._id;
17461746
var users = await Config.db.query({ _id: msg.userid, _type: "user" }, null, 1, 0, null, "users", msg.jwt);
17471747
if (users.length == 0) throw new Error("Unknown userid");
1748-
var user = users[0];
1748+
var user: User = users[0] as any;
17491749
var dirty: boolean = false;
1750+
var hasbilling: boolean = false;
17501751

17511752
var billings = await Config.db.query<Billing>({ userid: msg.userid, _type: "billing" }, null, 1, 0, null, "users", rootjwt);
17521753
var billing: Billing;
@@ -1905,6 +1906,12 @@ export class Message {
19051906
billing = await Config.db._UpdateOne(null, billing, "users", 3, true, rootjwt);
19061907
}
19071908
}
1909+
1910+
hasbilling = (customer != null);
1911+
if (user._hasbilling != hasbilling) {
1912+
user._hasbilling = hasbilling;
1913+
await Config.db._UpdateOne(null, user, "users", 3, true, rootjwt);
1914+
}
19081915
msg.customer = customer;
19091916

19101917
} catch (error) {

OpenFlow/src/User.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class User extends Base {
3030
_lastclientversion: string;
3131
_lastopenrpaclientversion: string;
3232
_lastnoderedclientversion: string;
33+
_hasbilling: boolean;
3334
username: string;
3435
passwordhash: string;
3536
sid: string;

OpenFlow/src/public/Controllers.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,7 +3125,7 @@ module openflow {
31253125
public supportplans: stripe_plan[] = [];
31263126
public supporthoursplans: stripe_plan[] = [];
31273127

3128-
public nextbill: string;
3128+
public nextbill: stripe_invoice;
31293129

31303130
constructor(
31313131
public $scope: ng.IScope,
@@ -3322,10 +3322,16 @@ module openflow {
33223322
}
33233323

33243324

3325-
// if (this.stripe_customer && this.stripe_customer) {
3326-
// this.nextbill = (await this.api.Stripe<stripe_invoice>("GET", "invoices_upcoming", this.stripe_customer.id, null, null) as any);
3327-
// console.log(this.nextbill);
3328-
// }
3325+
if (this.stripe_customer && this.stripe_customer) {
3326+
try {
3327+
this.nextbill = (await this.api.Stripe<stripe_invoice>("GET", "invoices_upcoming", this.stripe_customer.id, null, null) as any);
3328+
console.log(this.nextbill);
3329+
this.nextbill.dtperiod_start = new Date(this.nextbill.period_start * 1000);
3330+
this.nextbill.dtperiod_end = new Date(this.nextbill.period_end * 1000);
3331+
} catch (error) {
3332+
console.error(error);
3333+
}
3334+
}
33293335

33303336
} catch (error) {
33313337
console.error(error);

OpenFlow/src/public/Message.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,10 @@ module openflow {
516516
public currency: string;
517517
public customer: string;
518518
public lines: stripe_list<stripe_invoice_line>;
519+
public period_start: number;
520+
public period_end: number;
521+
public dtperiod_start: Date;
522+
public dtperiod_end: Date;
519523
}
520524

521525
export class Message {

OpenFlow/src/public/Payment.html

Lines changed: 431 additions & 392 deletions
Large diffs are not rendered by default.

OpenFlow/src/public/Robots.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ <h1 translate lib="web">robots</h1>
4040
<th></th>
4141
<th></th>
4242
<th></th>
43+
<th></th>
4344
</tr>
4445
</thead>
4546
<tbody>
@@ -66,11 +67,16 @@ <h1 translate lib="web">robots</h1>
6667
class="fas fa-user-secret" style="color: #007bff;"></i></a>
6768
</td>
6869
<td class="btn-cell">
69-
<a href ng-click="ctrl.OpenNodered(model)" ng-show="model.hasnodered==true" class="table-btn">nodered</a>
70+
<a href ng-click="ctrl.OpenNodered(model)" ng-show="model.hasnodered==true" class="table-btn"><i
71+
class="fas fa-project-diagram"></i></a>
72+
</td>
73+
<td class="btn-cell">
74+
<a ng-href="#/Payment/{{model._id}}" class="table-btn"
75+
ng-show="menuctrl.WebSocketClient.stripe_api_key != '' && menuctrl.hasrole('admins') && model._hasbilling == true"><i
76+
class="fas fa-money-bill-wave"></i></a>
7077
</td>
7178
<td class="btn-cell">
72-
<!-- <a href ng-click="ctrl.ManageNodered(model)" class="table-btn">manage</a> -->
73-
<a ng-href="#/Nodered/{{model._id}}" class="table-btn">manage</a>
79+
<a ng-href="#/Nodered/{{model._id}}" class="table-btn"><i class="fas fa-tools"></i></a>
7480
</td>
7581
<td class="btn-cell">
7682
<a ng-href="#/Entity/{{ctrl.collection}}/{{model._id}}" class="table-btn"><i class="az-edit"></i></a>

OpenFlow/src/public/Users.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ <h1 translate lib="web">users</h1>
2424
<th></th>
2525
<th></th>
2626
<th></th>
27+
<th></th>
2728
</tr>
2829
</thead>
2930
<tbody>
@@ -41,6 +42,11 @@ <h1 translate lib="web">users</h1>
4142
chart-labels="model.chart.labels" chart-series="model.chart.series" height="40px" width="200">
4243
</canvas>
4344
</td> -->
45+
<td class="btn-cell">
46+
<a ng-href="#/Payment/{{model._id}}" class="table-btn"
47+
ng-show="menuctrl.WebSocketClient.stripe_api_key != '' && menuctrl.hasrole('admins') && model._hasbilling == true">
48+
<i class="fas fa-money-bill-wave"></i></a>
49+
</td>
4450
<td class="btn-cell">
4551
<a ng-href ng-click="ctrl.Impersonate(model)" ng-show="model._id != ctrl.WebSocketClient.user._id"><i
4652
class="fas fa-user-secret" style="color: #007bff;"></i></a>

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.566
1+
0.0.567

0 commit comments

Comments
 (0)