| | | 1 | | using OzonDomains; |
| | | 2 | | using OzonDomains.Models; |
| | | 3 | | |
| | | 4 | | namespace OzonOrdersWeb.Areas.Studio2.ViewModels.TransactionTimeTracking; |
| | | 5 | | |
| | | 6 | | public class TransactionTimeTrackingReportViewModel |
| | | 7 | | { |
| | 0 | 8 | | public DateTime? DateFromUtc { get; set; } |
| | 0 | 9 | | public DateTime? DateToUtc { get; set; } |
| | 0 | 10 | | public string? UserName { get; set; } |
| | 0 | 11 | | public string? TransactionType { get; set; } |
| | 0 | 12 | | public int PageNumber { get; set; } |
| | 0 | 13 | | public int PageSize { get; set; } |
| | 0 | 14 | | public int TotalCount { get; set; } |
| | 0 | 15 | | public int TotalPages => PageSize > 0 ? (int)Math.Ceiling(TotalCount / (double)PageSize) : 0; |
| | 0 | 16 | | public bool HasPreviousPage => PageNumber > 1; |
| | 0 | 17 | | public bool HasNextPage => PageNumber < TotalPages; |
| | | 18 | | |
| | 0 | 19 | | public List<string> AvailableTransactionTypes { get; set; } = new(); |
| | 0 | 20 | | public List<string> AvailableUsers { get; set; } = new(); |
| | 0 | 21 | | public List<TransactionTimeTrackingResult> Results { get; set; } = new(); |
| | | 22 | | |
| | 0 | 23 | | public TransactionTimeTrackingReportSummaryViewModel? Summary { get; set; } |
| | | 24 | | |
| | 0 | 25 | | public TransactionTimeTrackingChartsViewModel? ChartData { get; set; } |
| | | 26 | | |
| | | 27 | | public string GetTransactionTypeDisplayName(string? transactionType) |
| | | 28 | | { |
| | 0 | 29 | | if (string.IsNullOrWhiteSpace(transactionType)) |
| | 0 | 30 | | return "Не указан"; |
| | | 31 | | |
| | 0 | 32 | | return Enum.TryParse<OzonDomains.TransactionType>(transactionType, true, out var parsedType) |
| | 0 | 33 | | ? parsedType.GetDisplayName() |
| | 0 | 34 | | : transactionType; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | public string GetTransactionTypeBadgeClass(string? transactionType) |
| | | 38 | | { |
| | 0 | 39 | | if (string.IsNullOrWhiteSpace(transactionType)) |
| | 0 | 40 | | return "bg-secondary"; |
| | | 41 | | |
| | 0 | 42 | | if (!Enum.TryParse<OzonDomains.TransactionType>(transactionType, true, out var parsedType)) |
| | 0 | 43 | | return "bg-secondary"; |
| | | 44 | | |
| | 0 | 45 | | return parsedType switch |
| | 0 | 46 | | { |
| | 0 | 47 | | OzonDomains.TransactionType.OrderedToSupplier => "bg-success", |
| | 0 | 48 | | OzonDomains.TransactionType.ShippedBySupplier => "bg-info text-dark", |
| | 0 | 49 | | OzonDomains.TransactionType.ShippedToSeller => "bg-warning text-dark", |
| | 0 | 50 | | OzonDomains.TransactionType.OrderedToSeller => "bg-secondary", |
| | 0 | 51 | | OzonDomains.TransactionType.ShippedToClient => "bg-primary", |
| | 0 | 52 | | OzonDomains.TransactionType.Percentage => "bg-dark", |
| | 0 | 53 | | OzonDomains.TransactionType.ReceiptNote => "bg-light text-dark border", |
| | 0 | 54 | | OzonDomains.TransactionType.AcceptedToWarehouse => "bg-info", |
| | 0 | 55 | | OzonDomains.TransactionType.ToCancellation => "bg-secondary", |
| | 0 | 56 | | OzonDomains.TransactionType.Cancelled => "bg-danger", |
| | 0 | 57 | | OzonDomains.TransactionType.CustomerReturn => "bg-warning text-dark", |
| | 0 | 58 | | OzonDomains.TransactionType.WarehouseChange => "bg-primary", |
| | 0 | 59 | | OzonDomains.TransactionType.ReturnToSupplier => "bg-warning text-dark", |
| | 0 | 60 | | OzonDomains.TransactionType.ReturnToWarehouse => "bg-info text-dark", |
| | 0 | 61 | | OzonDomains.TransactionType.WarehouseTransfer => "bg-primary", |
| | 0 | 62 | | OzonDomains.TransactionType.ShippedToCommissioner => "bg-primary", |
| | 0 | 63 | | _ => "bg-secondary" |
| | 0 | 64 | | }; |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | public string GetTransactionTypeIconClass(string? transactionType) |
| | | 68 | | { |
| | 0 | 69 | | if (string.IsNullOrWhiteSpace(transactionType)) |
| | 0 | 70 | | return "fas fa-circle"; |
| | | 71 | | |
| | 0 | 72 | | return Enum.TryParse<OzonDomains.TransactionType>(transactionType, true, out var parsedType) |
| | 0 | 73 | | ? parsedType.GetTransactionTypeIcon() |
| | 0 | 74 | | : "fas fa-circle"; |
| | | 75 | | } |
| | | 76 | | |
| | | 77 | | public string GetOrdersPerMinute(int ordersCount, long durationSeconds) |
| | | 78 | | { |
| | 0 | 79 | | if (ordersCount <= 0 || durationSeconds <= 0) |
| | 0 | 80 | | return "—"; |
| | | 81 | | |
| | 0 | 82 | | var perMinute = ordersCount / (durationSeconds / 60d); |
| | 0 | 83 | | return perMinute.ToString("0.##"); |
| | | 84 | | } |
| | | 85 | | |
| | | 86 | | public string FormatOrdersPerMinute(double? value) |
| | | 87 | | { |
| | 0 | 88 | | if (!value.HasValue || double.IsNaN(value.Value) || double.IsInfinity(value.Value)) |
| | 0 | 89 | | return "—"; |
| | | 90 | | |
| | 0 | 91 | | return value.Value.ToString("0.##"); |
| | | 92 | | } |
| | | 93 | | |
| | | 94 | | public string FormatAvgDuration(double? avgSeconds) |
| | | 95 | | { |
| | 0 | 96 | | if (!avgSeconds.HasValue || double.IsNaN(avgSeconds.Value) || double.IsInfinity(avgSeconds.Value)) |
| | 0 | 97 | | return "—"; |
| | | 98 | | |
| | 0 | 99 | | var rounded = (long)Math.Round(avgSeconds.Value, MidpointRounding.AwayFromZero); |
| | 0 | 100 | | return TimeSpan.FromSeconds(rounded).ToString(@"hh\:mm\:ss"); |
| | | 101 | | } |
| | | 102 | | |
| | 0 | 103 | | public DateTime ToMskTime(DateTime utcDateTime) => MoscowTimeHelper.UtcToMsk(utcDateTime); |
| | | 104 | | } |