| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using System.Reflection; |
| | | 5 | | using OzonDomains.Models; |
| | | 6 | | |
| | | 7 | | namespace OzonDomains |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Расширения для работы с типами транзакций |
| | | 11 | | /// Объединяет функциональность для работы с TransactionType enum |
| | | 12 | | /// </summary> |
| | | 13 | | public static class TransactionTypeExtensions |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// Получает все типы транзакций, исключая служебные (All) |
| | | 17 | | /// </summary> |
| | | 18 | | /// <returns>Список типов транзакций</returns> |
| | | 19 | | public static IEnumerable<TransactionType> GetTransactionTypes() |
| | | 20 | | { |
| | 26 | 21 | | return Enum.GetValues(typeof(TransactionType)) |
| | 26 | 22 | | .Cast<TransactionType>() |
| | 502 | 23 | | .Where(t => t != TransactionType.All); |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Получает отображаемое имя типа транзакции |
| | | 28 | | /// </summary> |
| | | 29 | | /// <param name="transactionType">Тип транзакции</param> |
| | | 30 | | /// <returns>Отображаемое имя</returns> |
| | | 31 | | public static string GetTransactionDisplayName(this TransactionType transactionType) |
| | | 32 | | { |
| | 4 | 33 | | return transactionType.GetDisplayName(); |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Проверяет, является ли тип транзакции валидным (не All) |
| | | 38 | | /// </summary> |
| | | 39 | | /// <param name="transactionType">Тип транзакции</param> |
| | | 40 | | /// <returns>True, если тип валидный</returns> |
| | | 41 | | public static bool IsValidTransactionType(this TransactionType transactionType) |
| | | 42 | | { |
| | 6 | 43 | | return transactionType != TransactionType.All; |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Получает тип транзакции по имени контроллера |
| | | 48 | | /// </summary> |
| | | 49 | | /// <param name="controllerName">Имя контроллера (например, "ReturnToSupplierTransactionController")</param> |
| | | 50 | | /// <returns>Тип транзакции или null, если не найден</returns> |
| | | 51 | | public static TransactionType? GetTransactionTypeByControllerName(string controllerName) |
| | | 52 | | { |
| | 12 | 53 | | if (string.IsNullOrWhiteSpace(controllerName)) |
| | 3 | 54 | | return null; |
| | | 55 | | |
| | | 56 | | // Удаляем суффикс "TransactionController" или "Controller" |
| | 9 | 57 | | var name = controllerName |
| | 9 | 58 | | .Replace("TransactionController", "", StringComparison.OrdinalIgnoreCase) |
| | 9 | 59 | | .Replace("Controller", "", StringComparison.OrdinalIgnoreCase); |
| | | 60 | | |
| | | 61 | | // Маппинг имен контроллеров на типы транзакций |
| | 9 | 62 | | var mapping = new Dictionary<string, TransactionType>(StringComparer.OrdinalIgnoreCase) |
| | 9 | 63 | | { |
| | 9 | 64 | | { "OrderToSupplier", TransactionType.OrderedToSupplier }, |
| | 9 | 65 | | { "OrderedToSupplier", TransactionType.OrderedToSupplier }, |
| | 9 | 66 | | { "ShippedBySupplier", TransactionType.ShippedBySupplier }, |
| | 9 | 67 | | { "ShippedToSeller", TransactionType.ShippedToSeller }, |
| | 9 | 68 | | { "OrderedToSeller", TransactionType.OrderedToSeller }, |
| | 9 | 69 | | { "ShippedToClient", TransactionType.ShippedToClient }, |
| | 9 | 70 | | { "Percentage", TransactionType.Percentage }, |
| | 9 | 71 | | { "AcceptedToWarehouse", TransactionType.AcceptedToWarehouse }, |
| | 9 | 72 | | { "ToCancellation", TransactionType.ToCancellation }, |
| | 9 | 73 | | { "Cancelled", TransactionType.Cancelled }, |
| | 9 | 74 | | { "CustomerReturn", TransactionType.CustomerReturn }, |
| | 9 | 75 | | { "WarehouseChange", TransactionType.WarehouseChange }, |
| | 9 | 76 | | { "ReturnToSupplier", TransactionType.ReturnToSupplier }, |
| | 9 | 77 | | { "ReturnToWarehouse", TransactionType.ReturnToWarehouse }, |
| | 9 | 78 | | { "ShippedToCommissioner", TransactionType.ShippedToCommissioner }, |
| | 9 | 79 | | { "ReturnTransfer", TransactionType.ReturnTransfer } |
| | 9 | 80 | | }; |
| | | 81 | | |
| | 9 | 82 | | return mapping.TryGetValue(name, out var type) ? type : null; |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | /// <summary> |
| | | 86 | | /// Получает имя метода создания транзакции для типа транзакции |
| | | 87 | | /// </summary> |
| | | 88 | | /// <param name="transactionType">Тип транзакции</param> |
| | | 89 | | /// <returns>Имя метода</returns> |
| | | 90 | | public static string? GetCreateMethodName(this TransactionType transactionType) |
| | | 91 | | { |
| | 6 | 92 | | var mapping = new Dictionary<TransactionType, string> |
| | 6 | 93 | | { |
| | 6 | 94 | | { TransactionType.OrderedToSupplier, "CreateOrderToSupplierTransaction" }, |
| | 6 | 95 | | { TransactionType.ShippedBySupplier, "CreateShippedBySupplierTransaction" }, |
| | 6 | 96 | | { TransactionType.ShippedToSeller, "CreateShippedToSellerTransaction" }, |
| | 6 | 97 | | { TransactionType.OrderedToSeller, "CreateOrderedToSellerTransaction" }, |
| | 6 | 98 | | { TransactionType.ShippedToClient, "CreateShippedToClientTransaction" }, |
| | 6 | 99 | | { TransactionType.Percentage, "CreatePercentageTransaction" }, |
| | 6 | 100 | | { TransactionType.AcceptedToWarehouse, "AcceptedToWarehouseTransaction" }, |
| | 6 | 101 | | { TransactionType.ToCancellation, "CreateToCancellationTransaction" }, |
| | 6 | 102 | | { TransactionType.Cancelled, "CreateCancelledTransaction" }, |
| | 6 | 103 | | { TransactionType.CustomerReturn, "CreateCustomerReturnTransaction" }, |
| | 6 | 104 | | { TransactionType.WarehouseChange, "CreateWarehouseChangeTransaction" }, |
| | 6 | 105 | | { TransactionType.ReturnToSupplier, "CreateReturnToSupplierTransaction" }, |
| | 6 | 106 | | { TransactionType.ReturnToWarehouse, "CreateReturnToWarehouseTransaction" }, |
| | 6 | 107 | | { TransactionType.ShippedToCommissioner, "CreateShippedToCommissionerTransaction" }, |
| | 6 | 108 | | { TransactionType.ReturnTransfer, "CreateReturnTransferTransaction" } |
| | 6 | 109 | | }; |
| | | 110 | | |
| | 6 | 111 | | return mapping.TryGetValue(transactionType, out var methodName) ? methodName : null; |
| | | 112 | | } |
| | | 113 | | |
| | | 114 | | /// <summary> |
| | | 115 | | /// Иконка FontAwesome для типа транзакции (как в списке операций на главной странице). |
| | | 116 | | /// </summary> |
| | | 117 | | public static string GetTransactionTypeIcon(this TransactionType transactionType) |
| | | 118 | | { |
| | 4 | 119 | | var mapping = new Dictionary<TransactionType, string> |
| | 4 | 120 | | { |
| | 4 | 121 | | { TransactionType.OrderedToSupplier, "fas fa-shopping-cart" }, |
| | 4 | 122 | | { TransactionType.ShippedBySupplier, "fas fa-truck-loading" }, |
| | 4 | 123 | | { TransactionType.ShippedToSeller, "fas fa-truck" }, |
| | 4 | 124 | | { TransactionType.OrderedToSeller, "fas fa-handshake" }, |
| | 4 | 125 | | { TransactionType.ShippedToClient, "fas fa-shipping-fast" }, |
| | 4 | 126 | | { TransactionType.Percentage, "fas fa-percent" }, |
| | 4 | 127 | | { TransactionType.ReceiptNote, "fas fa-file-invoice" }, |
| | 4 | 128 | | { TransactionType.AcceptedToWarehouse, "fas fa-warehouse" }, |
| | 4 | 129 | | { TransactionType.ToCancellation, "fas fa-hourglass-half" }, |
| | 4 | 130 | | { TransactionType.Cancelled, "fas fa-times-circle" }, |
| | 4 | 131 | | { TransactionType.CustomerReturn, "fas fa-undo" }, |
| | 4 | 132 | | { TransactionType.WarehouseChange, "fas fa-edit" }, |
| | 4 | 133 | | { TransactionType.ReturnToSupplier, "fas fa-reply-all" }, |
| | 4 | 134 | | { TransactionType.ReturnToWarehouse, "fas fa-undo-alt" }, |
| | 4 | 135 | | { TransactionType.WarehouseTransfer, "fas fa-exchange-alt" }, |
| | 4 | 136 | | { TransactionType.ShippedToCommissioner, "fas fa-dolly" }, |
| | 4 | 137 | | { TransactionType.ReturnTransfer, "fas fa-forward" } |
| | 4 | 138 | | }; |
| | 4 | 139 | | return mapping.TryGetValue(transactionType, out var icon) ? icon : "fas fa-circle"; |
| | | 140 | | } |
| | | 141 | | |
| | | 142 | | /// <summary> |
| | | 143 | | /// Bootstrap link-* класс для типа транзакции (как в выпадающем меню операций на главной). |
| | | 144 | | /// </summary> |
| | | 145 | | public static string GetTransactionTypeCssClass(this TransactionType transactionType) |
| | | 146 | | { |
| | 4 | 147 | | var mapping = new Dictionary<TransactionType, string> |
| | 4 | 148 | | { |
| | 4 | 149 | | { TransactionType.OrderedToSupplier, "link-success" }, |
| | 4 | 150 | | { TransactionType.OrderedToSeller, "link-secondary" }, |
| | 4 | 151 | | { TransactionType.ShippedBySupplier, "link-info" }, |
| | 4 | 152 | | { TransactionType.ShippedToSeller, "link-warning" }, |
| | 4 | 153 | | { TransactionType.ShippedToClient, "link-success" }, |
| | 4 | 154 | | { TransactionType.AcceptedToWarehouse, "link-info" }, |
| | 4 | 155 | | { TransactionType.ToCancellation, "link-secondary" }, |
| | 4 | 156 | | { TransactionType.Cancelled, "link-danger" }, |
| | 4 | 157 | | { TransactionType.CustomerReturn, "link-warning" }, |
| | 4 | 158 | | { TransactionType.WarehouseChange, "link-primary" }, |
| | 4 | 159 | | { TransactionType.ReturnToSupplier, "link-warning" }, |
| | 4 | 160 | | { TransactionType.ReturnToWarehouse, "link-info" }, |
| | 4 | 161 | | { TransactionType.WarehouseTransfer, "link-primary" }, |
| | 4 | 162 | | { TransactionType.ShippedToCommissioner, "link-primary" }, |
| | 4 | 163 | | { TransactionType.Percentage, "link-secondary" }, |
| | 4 | 164 | | { TransactionType.ReceiptNote, "link-secondary" }, |
| | 4 | 165 | | { TransactionType.ReturnTransfer, "link-primary" } |
| | 4 | 166 | | }; |
| | 4 | 167 | | return mapping.TryGetValue(transactionType, out var css) ? css : "link-secondary"; |
| | | 168 | | } |
| | | 169 | | } |
| | | 170 | | } |
| | | 171 | | |