Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
billing: Highlight manual license management errors for admins.
Lauryn Menard137f4fccdefc
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex 770f06236f4..8cd14f76e1c 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -2545,6 +2545,7 @@ class BillingSession(ABC):"licenses": licenses,"licenses_at_next_renewal": licenses_at_next_renewal,"seat_count": seat_count,+ "exempt_from_license_number_check": customer.exempt_from_license_number_check,"renewal_date": renewal_date,"renewal_amount": cents_to_dollar_string(renewal_cents) if renewal_cents != 0 else None,"payment_method": payment_method,diff --git a/templates/corporate/billing/billing.html b/templates/corporate/billing/billing.htmlindex 8fa819c28ef..f1d2bd21273 100644--- a/templates/corporate/billing/billing.html+++ b/templates/corporate/billing/billing.html@@ -143,7 +143,7 @@</label><div class="number-input-with-label"><form id="current-license-change-form">- <input type="number" name="licenses" autocomplete="off" id="current-manual-license-count" class="short-width-number-input" data-original-value="{{ licenses }}" value="{{ licenses }}" required/>+ <input type="number" name="licenses" autocomplete="off" id="current-manual-license-count" class="short-width-number-input" data-original-value="{{ licenses }}" value="{{ licenses }}" {%if not exempt_from_license_number_check %}min="{{ seat_count }}"{% endif %} required/></form><span class="licence-count-in-use">licenses ({{ seat_count }} in use)</span><button id="current-manual-license-count-update-button" class="license-count-update-button hide">@@ -170,7 +170,7 @@</label><div class="number-input-with-label"><form id="next-license-change-form">- <input type="number" name="licenses_at_next_renewal" autocomplete="off" id="next-manual-license-count" class="short-width-number-input" data-original-value="{{ licenses_at_next_renewal }}" value="{{ licenses_at_next_renewal }}" required/>+ <input type="number" name="licenses_at_next_renewal" autocomplete="off" id="next-manual-license-count" class="short-width-number-input" data-original-value="{{ licenses_at_next_renewal }}" value="{{ licenses_at_next_renewal }}" {%if not exempt_from_license_number_check %}min="{{ seat_count }}"{% endif %} required/></form><span class="licence-count-in-use">licenses ({{ seat_count }} in use)</span><button id="next-manual-license-count-update-button" class="license-count-update-button hide">diff --git a/web/src/billing/billing.ts b/web/src/billing/billing.tsindex 8c383784d40..66dbc8c3b5d 100644--- a/web/src/billing/billing.ts+++ b/web/src/billing/billing.ts@@ -101,9 +101,10 @@ export function initialize(): void {e.preventDefault();});- function get_old_and_new_license_count_for_current_cycle(): {+ function get_license_counts_for_current_cycle(): {new_current_manual_license_count: number;old_current_manual_license_count: number;+ min_current_manual_license_count: number;} {const new_current_manual_license_count: number = Number.parseInt($<HTMLInputElement>("input#current-manual-license-count").val()!,@@ -113,15 +114,25 @@ export function initialize(): void {$<HTMLInputElement>("input#current-manual-license-count").attr("data-original-value")!,10,);+ let min_current_manual_license_count: number = Number.parseInt(+ $<HTMLInputElement>("input#current-manual-license-count").attr("min")!,+ 10,+ );+ if (Number.isNaN(min_current_manual_license_count)) {+ // Customer is exempt from license number checks.+ min_current_manual_license_count = 0;+ }return {new_current_manual_license_count,old_current_manual_license_count,+ min_current_manual_license_count,};}- function get_old_and_new_license_count_for_next_cycle(): {+ function get_license_counts_for_next_cycle(): {new_next_manual_license_count: number;old_next_manual_license_count: number;+ min_next_manual_license_count: number;} {const new_next_manual_license_count: number = Number.parseInt($<HTMLInputElement>("input#next-manual-license-count").val()!,@@ -131,12 +142,43 @@ export function initialize(): void {$<HTMLInputElement>("input#next-manual-license-count").attr("data-original-value")!,10,);+ let min_next_manual_license_count: number = Number.parseInt(+ $<HTMLInputElement>("input#next-manual-license-count").attr("min")!,+ 10,+ );+ if (Number.isNaN(min_next_manual_license_count)) {+ // Customer is exempt from license number checks.+ min_next_manual_license_count = 0;+ }return {new_next_manual_license_count,old_next_manual_license_count,+ min_next_manual_license_count,};}+ function check_for_manual_billing_errors(): void {+ const {old_next_manual_license_count, min_next_manual_license_count} =+ get_license_counts_for_next_cycle();+ if (old_next_manual_license_count < min_next_manual_license_count) {+ $("#next-license-change-error").text(+ "Number of licenses for next billing period less than licenses in use.",+ );+ } else {+ $("#next-license-change-error").text("");+ }++ const {old_current_manual_license_count, min_current_manual_license_count} =+ get_license_counts_for_current_cycle();+ if (old_current_manual_license_count < min_current_manual_license_count) {+ $("#current-license-change-error").text(+ "Number of licenses for current billing period less than licenses in use.",+ );+ } else {+ $("#current-license-change-error").text("");+ }+ }+$("#current-license-change-form, #next-license-change-form").on("submit", (e) => {// We don't want user to accidentally update the license count on pressing enter.e.preventDefault();@@ -149,7 +191,7 @@ export function initialize(): void {}e.preventDefault();const {new_current_manual_license_count, old_current_manual_license_count} =- get_old_and_new_license_count_for_current_cycle();+ get_license_counts_for_current_cycle();const $modal = $("#confirm-licenses-modal-increase");$modal.find(".new_license_count_holder").text(new_current_manual_license_count);$modal.find(".current_license_count_holder").text(old_current_manual_license_count);@@ -166,7 +208,7 @@ export function initialize(): void {}e.preventDefault();const {new_next_manual_license_count, old_next_manual_license_count} =- get_old_and_new_license_count_for_next_cycle();+ get_license_counts_for_next_cycle();let $modal;if (new_next_manual_license_count > old_next_manual_license_count) {$modal = $("#confirm-licenses-modal-increase");@@ -290,15 +332,23 @@ export function initialize(): void {let timeout: ReturnType<typeof setTimeout> | null = null;+ check_for_manual_billing_errors();+$("#current-manual-license-count").on("keyup", () => {if (timeout !== null) {clearTimeout(timeout);}timeout = setTimeout(() => {- const {new_current_manual_license_count, old_current_manual_license_count} =- get_old_and_new_license_count_for_current_cycle();- if (new_current_manual_license_count > old_current_manual_license_count) {+ const {+ new_current_manual_license_count,+ old_current_manual_license_count,+ min_current_manual_license_count,+ } = get_license_counts_for_current_cycle();+ if (+ new_current_manual_license_count > old_current_manual_license_count &&+ new_current_manual_license_count > min_current_manual_license_count+ ) {$("#current-manual-license-count-update-button").toggleClass("hide", false);$("#current-license-change-error").text("");} else if (new_current_manual_license_count < old_current_manual_license_count) {@@ -308,7 +358,7 @@ export function initialize(): void {$("#current-manual-license-count-update-button").toggleClass("hide", true);} else {$("#current-manual-license-count-update-button").toggleClass("hide", true);- $("#current-license-change-error").text("");+ check_for_manual_billing_errors();}}, 300); // Wait for 300ms after the user stops typing});@@ -319,16 +369,26 @@ export function initialize(): void {}timeout = setTimeout(() => {- const {new_next_manual_license_count, old_next_manual_license_count} =- get_old_and_new_license_count_for_next_cycle();+ const {+ new_next_manual_license_count,+ old_next_manual_license_count,+ min_next_manual_license_count,+ } = get_license_counts_for_next_cycle();if (!new_next_manual_license_count ||new_next_manual_license_count < 0 ||new_next_manual_license_count === old_next_manual_license_count) {$("#next-manual-license-count-update-button").toggleClass("hide", true);+ check_for_manual_billing_errors();+ } else if (new_next_manual_license_count < min_next_manual_license_count) {+ $("#next-manual-license-count-update-button").toggleClass("hide", true);+ $("#next-license-change-error").text(+ "Cannot be less than the number of licenses currently in use.",+ );} else {$("#next-manual-license-count-update-button").toggleClass("hide", false);+ $("#next-license-change-error").text("");}}, 300); // Wait for 300ms after the user stops typing});