Skip to content

Commit 90d8c32

Browse files
committed
VCST-4474: Improvements for dashboard statistic (#484)
1 parent 3819464 commit 90d8c32

15 files changed

+255
-5
lines changed

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,82 @@ Virto Commerce Order module supports the following functionalities:
3939
* Manage order delivery (status, delivery details);
4040
* Repeated order creation (order cloning) with possibility to specify the frequency of order re-creation.
4141

42+
Number template format: `<template>@<reset_type>[:<start>:<increment>]`
43+
- Reset types: `None`, `Daily`, `Weekly`, `Monthly`, `Yearly`
44+
- Example: `CO{0:yyMMdd}-{1:D5}@Weekly:1:10` (weekly reset, start at 1, increment by 10)
45+
46+
#### Validation Settings
47+
48+
| Setting | Default | Description |
49+
|---------|---------|-------------|
50+
| `Order.Validation.Enable` | `true` | Enable/disable order validation on save |
51+
| `Order.MaxOrderDocumentCount` | `20` | Maximum child documents per order |
52+
53+
#### Feature Flags
54+
55+
| Setting | Default | Description |
56+
|---------|---------|-------------|
57+
| `Order.SendOrderNotifications` | `true` | Enable order status change notifications |
58+
| `Order.AdjustInventory` | `false` | Adjust inventory on order status changes |
59+
| `Order.LogOrderChanges` | `true` | Log changes to platform operation log |
60+
| `Order.Search.EventBasedIndexation.Enable` | `false` | Auto-update search index on changes |
61+
| `Order.PurchasedProductIndexation.Enable` | `false` | Enable purchased product indexing |
62+
| `Order.OrderPaidAndOrderSentNotifications.Enable` | `false` | Use order paid/sent notifications |
63+
| `Order.PaymentShipmentStatusChangedNotifications.Enable` | `false` | Use payment/shipment status notifications |
64+
65+
#### Dashboard Statistics Settings
66+
67+
| Setting | Default | Description |
68+
|---------|---------|-------------|
69+
| `Order.DashboardStatistics.Enable` | `true` | Enable or disable order statistics widgets on the main dashboard |
70+
| `Order.DashboardStatistics.RangeMonths` | `12` | Number of months to include in dashboard statistics calculations |
71+
72+
## Architecture
73+
74+
### Project Structure
75+
76+
```
77+
vc-module-order/
78+
??? src/
79+
? ??? VirtoCommerce.OrdersModule.Core/ # Domain models, interfaces
80+
? ??? VirtoCommerce.OrdersModule.Data/ # Data access, services, validators
81+
? ??? VirtoCommerce.OrdersModule.Data.SqlServer/ # SQL Server migrations
82+
? ??? VirtoCommerce.OrdersModule.Data.PostgreSql/ # PostgreSQL migrations
83+
? ??? VirtoCommerce.OrdersModule.Data.MySql/ # MySQL migrations
84+
? ??? VirtoCommerce.OrdersModule.Web/ # Web API, controllers
85+
??? tests/
86+
? ??? VirtoCommerce.OrdersModule.Tests/ # Unit and integration tests
87+
??? docs/ # Documentation
88+
??? samples/ # Sample implementations
89+
```
90+
91+
### Key Components
92+
93+
- **CustomerOrderService**: Core service for order CRUD operations
94+
- **CustomerOrderSearchService**: Advanced search and filtering
95+
- **CustomerOrderTotalsCalculator**: Order totals calculation
96+
- **CustomerOrderValidator**: FluentValidation-based validation
97+
- **OrderDocumentCountValidator**: Document count limit enforcement
98+
- **OrderRepository**: Data access layer with EF Core
99+
100+
### Domain Model
101+
102+
```
103+
CustomerOrder (IOperation)
104+
??? LineItem[]
105+
??? Address[]
106+
??? PaymentIn[] (IOperation)
107+
? ??? Capture[]
108+
? ??? Refund[]
109+
??? Shipment[] (IOperation)
110+
? ??? ShipmentItem[]
111+
? ??? ShipmentPackage[]
112+
? ??? Address
113+
??? DynamicProperties[]
114+
```
115+
116+
117+
42118
## Documentation
43119

44120
* [Order module user documentation](https://docs.virtocommerce.org/platform/user-guide/order-management/overview/)

src/VirtoCommerce.OrdersModule.Core/ModuleConstants.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,30 @@ public static class General
276276
IsPublic = true,
277277
};
278278

279+
public static SettingDescriptor MaxOrderDocumentCount { get; } = new SettingDescriptor
280+
{
281+
Name = "Order.MaxOrderDocumentCount",
282+
GroupName = "Orders|General",
283+
ValueType = SettingValueType.Integer,
284+
DefaultValue = 20,
285+
};
286+
287+
public static SettingDescriptor DashboardStatisticsEnabled { get; } = new SettingDescriptor
288+
{
289+
Name = "Order.DashboardStatistics.Enable",
290+
GroupName = "Orders|General",
291+
ValueType = SettingValueType.Boolean,
292+
DefaultValue = true,
293+
};
294+
295+
public static SettingDescriptor DashboardStatisticsRangeMonths { get; } = new SettingDescriptor
296+
{
297+
Name = "Order.DashboardStatistics.RangeMonths",
298+
GroupName = "Orders|General",
299+
ValueType = SettingValueType.PositiveInteger,
300+
DefaultValue = 12,
301+
};
302+
279303
public static IEnumerable<SettingDescriptor> AllSettings
280304
{
281305
get
@@ -301,6 +325,9 @@ public static IEnumerable<SettingDescriptor> AllSettings
301325
yield return PurchasedProductIndexation;
302326
yield return EventBasedPurchasedProductIndexation;
303327
yield return PurchasedProductStoreFilter;
328+
yield return MaxOrderDocumentCount;
329+
yield return DashboardStatisticsEnabled;
330+
yield return DashboardStatisticsRangeMonths;
304331
}
305332
}
306333
}

src/VirtoCommerce.OrdersModule.Web/Controllers/Api/OrderModuleController.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,24 @@ public async Task<ActionResult> DeleteOrdersByIds([FromQuery] string[] ids)
487487
return unauthorizedRequest ? Forbid() : NoContent();
488488
}
489489

490+
/// <summary>
491+
/// Get dashboard statistics settings
492+
/// </summary>
493+
[HttpGet]
494+
[Route("~/api/order/dashboardStatistics/settings")]
495+
[Authorize(ModuleConstants.Security.Permissions.ViewDashboardStatistics)]
496+
public async Task<ActionResult<object>> GetDashboardStatisticsSettingsAsync()
497+
{
498+
var enabled = await settingsManager.GetValueAsync<bool>(ModuleConstants.Settings.General.DashboardStatisticsEnabled);
499+
var rangeMonths = await settingsManager.GetValueAsync<int>(ModuleConstants.Settings.General.DashboardStatisticsRangeMonths);
500+
501+
return Ok(new
502+
{
503+
Enabled = enabled,
504+
RangeMonths = rangeMonths
505+
});
506+
}
507+
490508
/// <summary>
491509
/// Get a some order statistic information for Commerce manager dashboard
492510
/// </summary>
@@ -497,7 +515,18 @@ public async Task<ActionResult> DeleteOrdersByIds([FromQuery] string[] ids)
497515
[Authorize(ModuleConstants.Security.Permissions.ViewDashboardStatistics)]
498516
public async Task<ActionResult<DashboardStatisticsResult>> GetDashboardStatisticsAsync([FromQuery] DateTime? start = null, [FromQuery] DateTime? end = null)
499517
{
500-
start ??= DateTime.UtcNow.AddYears(-1);
518+
var dashboardEnabled = await settingsManager.GetValueAsync<bool>(ModuleConstants.Settings.General.DashboardStatisticsEnabled);
519+
if (!dashboardEnabled)
520+
{
521+
return Ok(new DashboardStatisticsResult());
522+
}
523+
524+
if (start == null)
525+
{
526+
var rangeMonths = await settingsManager.GetValueAsync<int>(ModuleConstants.Settings.General.DashboardStatisticsRangeMonths);
527+
start = DateTime.UtcNow.AddMonths(-rangeMonths);
528+
}
529+
501530
end ??= DateTime.UtcNow;
502531

503532
// Hack: to compensate for incorrect Local dates to UTC

src/VirtoCommerce.OrdersModule.Web/Localizations/de.VirtoCommerce.Orders.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,18 @@
620620
"Order.PurchasedProductStoreFilter.Enable": {
621621
"title": "Aktivierung des Store-Filters für gekaufte Produkte",
622622
"description": "Zeigt den Filter für gekaufte Produkte im Store an."
623+
},
624+
"Order.MaxOrderDocumentCount": {
625+
"title": "Maximale Anzahl von Unterdokumenten pro Bestellung",
626+
"description": "Definiert die maximale Anzahl von Unterdokumenten (Zahlungen, Sendungen, Captures, Rückerstattungen usw.), die pro Bestellung erstellt oder gespeichert werden können. Dies gewährleistet Systemleistung, Speicheroptimierung und Datenkonsistenz. Bei Überschreitung dieser Grenze wird beim Speichern eine Ausnahme ausgelöst"
627+
},
628+
"Order.DashboardStatistics.Enable": {
629+
"title": "Dashboard-Statistiken aktivieren",
630+
"description": "Aktiviert oder deaktiviert die Bestellstatistik-Widgets auf dem Haupt-Dashboard"
631+
},
632+
"Order.DashboardStatistics.RangeMonths": {
633+
"title": "Dashboard-Statistik Zeitraum (Monate)",
634+
"description": "Definiert die Anzahl der Monate, die in die Dashboard-Statistikberechnungen einbezogen werden. Standard ist 12 Monate"
623635
}
624636
},
625637
"module": {

src/VirtoCommerce.OrdersModule.Web/Localizations/en.VirtoCommerce.Orders.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,18 @@
620620
"Order.PurchasedProductStoreFilter.Enable": {
621621
"title": "Enable purchased product store filter",
622622
"description": "Display the purchased product filter for the store"
623+
},
624+
"Order.MaxOrderDocumentCount": {
625+
"title": "Maximum number of child documents per order",
626+
"description": "Defines the maximum number of child documents (payments, shipments, captures, refunds, etc.) that can be created or stored per order. This ensures system performance, storage optimization, and data consistency. An exception will be thrown on save if this limit is exceeded"
627+
},
628+
"Order.DashboardStatistics.Enable": {
629+
"title": "Enable dashboard statistics",
630+
"description": "Turn on or off the order statistics dashboard widgets on the main dashboard"
631+
},
632+
"Order.DashboardStatistics.RangeMonths": {
633+
"title": "Dashboard statistics range (months)",
634+
"description": "Defines the number of months to include in the dashboard statistics calculations. Default is 12 months"
623635
}
624636
},
625637
"module": {

src/VirtoCommerce.OrdersModule.Web/Localizations/es.VirtoCommerce.Orders.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,18 @@
620620
"Order.PurchasedProductStoreFilter.Enable": {
621621
"title": "Habilitar el filtro de productos comprados en la tienda",
622622
"description": "Muestra el filtro de productos comprados en la tienda."
623+
},
624+
"Order.MaxOrderDocumentCount": {
625+
"title": "Número máximo de documentos secundarios por pedido",
626+
"description": "Define el número máximo de documentos secundarios (pagos, envíos, capturas, reembolsos, etc.) que se pueden crear o almacenar por pedido. Esto garantiza el rendimiento del sistema, la optimización del almacenamiento y la consistencia de los datos. Se generará una excepción al guardar si se excede este límite"
627+
},
628+
"Order.DashboardStatistics.Enable": {
629+
"title": "Habilitar estadísticas del panel",
630+
"description": "Activa o desactiva los widgets de estadísticas de pedidos en el panel principal"
631+
},
632+
"Order.DashboardStatistics.RangeMonths": {
633+
"title": "Período de estadísticas del panel (meses)",
634+
"description": "Define el número de meses a incluir en los cálculos de estadísticas del panel. El valor predeterminado es 12 meses"
623635
}
624636
},
625637
"module": {

src/VirtoCommerce.OrdersModule.Web/Localizations/fr.VirtoCommerce.Orders.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,18 @@
621621
"Order.PurchasedProductStoreFilter.Enable": {
622622
"title": "Activer le filtre de produits achetés en magasin",
623623
"description": "Affiche le filtre de produits achetés pour le magasin."
624+
},
625+
"Order.MaxOrderDocumentCount": {
626+
"title": "Nombre maximum de documents enfants par commande",
627+
"description": "Définit le nombre maximum de documents enfants (paiements, expéditions, captures, remboursements, etc.) qui peuvent être créés ou stockés par commande. Cela garantit les performances du système, l'optimisation du stockage et la cohérence des données. Une exception sera levée lors de la sauvegarde si cette limite est dépassée"
628+
},
629+
"Order.DashboardStatistics.Enable": {
630+
"title": "Activer les statistiques du tableau de bord",
631+
"description": "Active ou désactive les widgets de statistiques de commandes sur le tableau de bord principal"
632+
},
633+
"Order.DashboardStatistics.RangeMonths": {
634+
"title": "Période des statistiques du tableau de bord (mois)",
635+
"description": "Définit le nombre de mois à inclure dans les calculs des statistiques du tableau de bord. La valeur par défaut est de 12 mois"
624636
}
625637
},
626638
"module": {

src/VirtoCommerce.OrdersModule.Web/Localizations/it.VirtoCommerce.Orders.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,18 @@
620620
"Order.PurchasedProductStoreFilter.Enable": {
621621
"title": "Abilita il filtro dei prodotti acquistati nel negozio",
622622
"description": "Visualizza il filtro dei prodotti acquistati per il negozio."
623+
},
624+
"Order.MaxOrderDocumentCount": {
625+
"title": "Numero massimo di documenti secondari per ordine",
626+
"description": "Definisce il numero massimo di documenti secondari (pagamenti, spedizioni, acquisizioni, rimborsi, ecc.) che possono essere creati o memorizzati per ordine. Ciò garantisce le prestazioni del sistema, l'ottimizzazione dello storage e la coerenza dei dati. Verrà generata un'eccezione durante il salvataggio se questo limite viene superato"
627+
},
628+
"Order.DashboardStatistics.Enable": {
629+
"title": "Abilita statistiche dashboard",
630+
"description": "Attiva o disattiva i widget delle statistiche ordini sulla dashboard principale"
631+
},
632+
"Order.DashboardStatistics.RangeMonths": {
633+
"title": "Intervallo statistiche dashboard (mesi)",
634+
"description": "Definisce il numero di mesi da includere nei calcoli delle statistiche della dashboard. Il valore predefinito è 12 mesi"
623635
}
624636
},
625637
"module": {

src/VirtoCommerce.OrdersModule.Web/Localizations/ja.VirtoCommerce.Orders.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,18 @@
620620
"Order.PurchasedProductStoreFilter.Enable": {
621621
"title": "購入済み商品ストアフィルターを有効にする",
622622
"description": "ストアで購入済み商品フィルターを表示します。"
623+
},
624+
"Order.MaxOrderDocumentCount": {
625+
"title": "注文あたりの子ドキュメントの最大数",
626+
"description": "注文ごとに作成または保存できる子ドキュメント(支払い、配送、キャプチャ、返金など)の最大数を定義します。これにより、システムパフォーマンス、ストレージの最適化、データの整合性が確保されます。この制限を超えた場合、保存時に例外がスローされます"
627+
},
628+
"Order.DashboardStatistics.Enable": {
629+
"title": "ダッシュボード統計を有効にする",
630+
"description": "メインダッシュボードの注文統計ウィジェットを有効または無効にします"
631+
},
632+
"Order.DashboardStatistics.RangeMonths": {
633+
"title": "ダッシュボード統計の範囲(月)",
634+
"description": "ダッシュボード統計計算に含める月数を定義します。デフォルトは12ヶ月です"
623635
}
624636
},
625637
"module": {

src/VirtoCommerce.OrdersModule.Web/Localizations/pl.VirtoCommerce.Orders.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,18 @@
620620
"Order.PurchasedProductStoreFilter.Enable": {
621621
"title": "Włącz filtr zakupionych produktów w sklepie",
622622
"description": "Wyświetla filtr zakupionych produktów w sklepie."
623+
},
624+
"Order.MaxOrderDocumentCount": {
625+
"title": "Maksymalna liczba dokumentów podrzędnych na zamówienie",
626+
"description": "Określa maksymalną liczbę dokumentów podrzędnych (płatności, przesyłki, przechwycenia, zwroty itp.), które można utworzyć lub przechowywać dla jednego zamówienia. Zapewnia to wydajność systemu, optymalizację przechowywania i spójność danych. Jeśli ten limit zostanie przekroczony, podczas zapisywania zostanie zgłoszony wyjątek"
627+
},
628+
"Order.DashboardStatistics.Enable": {
629+
"title": "Włącz statystyki pulpitu",
630+
"description": "Włącza lub wyłącza widżety statystyk zamówień na głównym pulpicie"
631+
},
632+
"Order.DashboardStatistics.RangeMonths": {
633+
"title": "Zakres statystyk pulpitu (miesiące)",
634+
"description": "Określa liczbę miesięcy do uwzględnienia w obliczeniach statystyk pulpitu. Domyślnie 12 miesięcy"
623635
}
624636
},
625637
"module": {

0 commit comments

Comments
 (0)