billing - item description with more details (draft)
MODIFY
src/assets/i18n/en.json
src/assets/i18n/en.json
{
"billing": {
"generatedUser": "Generated user for '{{email}}'",
+ "chargingAtSiteArea": "Charging session: {{startDate}} at {startTime} - Energy Consumption: {{totalConsumption}} kWh at {{siteArea}} - Parking time: {{timeSpent}}",
+ "chargingAtChargeBox": "Charging session: {{startDate}} at {{startTime}} - Energy Consumption: {{totalConsumption}} kWh at charging station {{chargeBox}} - Parking time: {{timeSpent}}",
"chargingStopSiteArea": "Charging {{totalConsumption}} kWh at {{siteArea}} (finished at {{time}})",
"chargingStopChargeBox": "Charging {{totalConsumption}} kWh at charging station {{chargeBox}} (finished at {{time}})"
},

MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -983,24 +983,30 @@ export default class StripeBillingIntegration extends BillingIntegration {
}
private buildLineItemDescription(transaction: Transaction) {
- let description: string;
const chargeBox = transaction.chargeBox;
const i18nManager = I18nManager.getInstanceForLocale(transaction.user.locale);
- const time = i18nManager.formatDateTime(transaction.stop.timestamp, 'LTS');
+ const startDate = i18nManager.formatDateTime(transaction.timestamp, 'DD/MM/YYYY');
+ const startTime = i18nManager.formatDateTime(transaction.timestamp, 'LTS');
+ const stopTime = i18nManager.formatDateTime(transaction.stop.timestamp, 'LTS');
const consumptionkWh = this.convertConsumptionToKWh(transaction);
-
- if (chargeBox && chargeBox.siteArea && chargeBox.siteArea.name) {
- description = i18nManager.translate('billing.chargingStopSiteArea', {
- totalConsumption: consumptionkWh,
- siteArea:
- chargeBox.siteArea,
- time: time
- });
+ const timeSpent = this.convertTimeSpentToString(transaction);
+ // TODO: Determine the description pattern to use according to the billing settings
+ let descriptionPattern;
+ if (FeatureToggles.isFeatureActive(Feature.BILLING_ITEM_WITH_START_DATE)) {
+ descriptionPattern = (chargeBox?.siteArea?.name) ? 'billing.chargingAtSiteArea' : 'billing.chargingAtChargeBox';
} else {
- description = i18nManager.translate('billing.chargingStopChargeBox', {
- totalConsumption: consumptionkWh, chargeBox: transaction.chargeBoxID, time: time
- });
+ descriptionPattern = (chargeBox?.siteArea?.name) ? 'billing.chargingStopSiteArea' : 'billing.chargingStopChargeBox';
}
+ // Get the translated line item description
+ const description = i18nManager.translate(descriptionPattern, {
+ startDate,
+ startTime,
+ timeSpent,
+ totalConsumption: consumptionkWh,
+ siteArea: chargeBox?.siteArea?.name,
+ chargeBox: transaction?.chargeBoxID,
+ time: stopTime,
+ });
return description;
}
@@ -1008,6 +1014,16 @@ export default class StripeBillingIntegration extends BillingIntegration {
return new Decimal(transaction.stop.totalConsumptionWh).dividedBy(10).round().dividedBy(100).toNumber();
}
+ private convertTimeSpentToString(transaction: Transaction): string {
+ let totalDuration: number;
+ if (!transaction.stop) {
+ totalDuration = moment.duration(moment(transaction.lastConsumption.timestamp).diff(moment(transaction.timestamp))).asSeconds();
+ } else {
+ totalDuration = moment.duration(moment(transaction.stop.timestamp).diff(moment(transaction.timestamp))).asSeconds();
+ }
+ return moment.duration(totalDuration, 's').format('h[h]mm', { trim: false });
+ }
+
// eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
public async checkIfUserCanBeCreated(user: User): Promise<boolean> {
// throw new BackendError({

MODIFY
src/utils/FeatureToggles.ts
src/utils/FeatureToggles.ts
@@ -6,6 +6,9 @@ export enum Feature {
BILLING_CHECK_USER_BILLING_DATA,
BILLING_CHECK_CUSTOMER_ID,
BILLING_CHECK_USER_DEFAULT_PAYMENT_METHOD,
+ BILLING_WITH_PARKING_TIME,
+ BILLING_ITEM_WITH_PARKING_TIME,
+ BILLING_ITEM_WITH_START_DATE,
}
export default class FeatureToggles {
@@ -16,6 +19,8 @@ export default class FeatureToggles {
Feature.BILLING_CHECK_USER_BILLING_DATA,
Feature.BILLING_CHECK_CUSTOMER_ID,
Feature.BILLING_CHECK_USER_DEFAULT_PAYMENT_METHOD,
+ Feature.BILLING_ITEM_WITH_PARKING_TIME,
+ Feature.BILLING_ITEM_WITH_START_DATE,
];
// Check whether the feature is active or not!

billing - item description with more details (draft)