| | | 1 | | using Services.DataServices; |
| | | 2 | | |
| | | 3 | | namespace OzonOrdersWeb.WebServices.Transactions.Grid.Commit.Steps; |
| | | 4 | | |
| | | 5 | | /// <summary>История проводок 1С (по группам складов) и история переходов статусов — только после записи транзакции.</su |
| | | 6 | | public sealed class HistoryStep : ITransactionCommitStep |
| | | 7 | | { |
| | | 8 | | private readonly IStatusTransitionHistoryService? _statusHistory; |
| | | 9 | | |
| | 0 | 10 | | public HistoryStep(IStatusTransitionHistoryService? statusHistory = null) |
| | | 11 | | { |
| | 0 | 12 | | _statusHistory = statusHistory; |
| | 0 | 13 | | } |
| | | 14 | | |
| | 0 | 15 | | public string Key => TransactionCommitStepKeys.History; |
| | | 16 | | |
| | | 17 | | public async Task ExecuteAsync(TransactionCommitContext ctx) |
| | | 18 | | { |
| | 0 | 19 | | if (ctx.TransactionId <= 0) |
| | | 20 | | { |
| | 0 | 21 | | return; |
| | | 22 | | } |
| | | 23 | | |
| | 0 | 24 | | if (ctx.ProcessIn1C && ctx.OneCResponses.Count > 0) |
| | | 25 | | { |
| | 0 | 26 | | var kind = ctx.Definition.OneCDocument; |
| | 0 | 27 | | if (ctx.OneCGroups.Count > 0) |
| | | 28 | | { |
| | 0 | 29 | | foreach (var g in ctx.OneCGroups) |
| | | 30 | | { |
| | 0 | 31 | | await OrderHistoryOneCPostingRecorder.TryRecordMovementAsync(ctx.Services, g.Orders, g.Result, ctx.U |
| | | 32 | | } |
| | | 33 | | } |
| | 0 | 34 | | else if (kind == Definitions.OneCDocumentKind.Receipt) |
| | | 35 | | { |
| | 0 | 36 | | await OrderHistoryOneCPostingRecorder.TryRecordReceiptAsync(ctx.Services, ctx.OrdersToTransaction, ctx.O |
| | | 37 | | } |
| | 0 | 38 | | else if (kind == Definitions.OneCDocumentKind.Expense) |
| | | 39 | | { |
| | 0 | 40 | | await OrderHistoryOneCPostingRecorder.TryRecordExpenseAsync(ctx.Services, ctx.OrdersToTransaction, ctx.O |
| | | 41 | | } |
| | | 42 | | else |
| | | 43 | | { |
| | 0 | 44 | | await OrderHistoryOneCPostingRecorder.TryRecordMovementAsync(ctx.Services, ctx.OrdersToTransaction, ctx. |
| | | 45 | | } |
| | | 46 | | } |
| | | 47 | | |
| | 0 | 48 | | if (ctx.Transitions.Count > 0 && _statusHistory != null) |
| | | 49 | | { |
| | 0 | 50 | | var comment = TransactionServices.TransactionCommentAiSchedulingHelper.ResolveCommentForDatabase( |
| | 0 | 51 | | ctx.CommentFlow.UserCommentOnly, ctx.CommentFlow.ScheduleAiComment, ctx.TechnicalComment); |
| | 0 | 52 | | await _statusHistory.RecordStatusTransitionHistoryAsync( |
| | 0 | 53 | | ctx.Definition.Type, ctx.OrdersToTransaction, ctx.FromStatusByOrderId, ctx.Transitions, |
| | 0 | 54 | | comment, ctx.User.AccessProfileId, ctx.CreatedAt, null); |
| | | 55 | | } |
| | 0 | 56 | | } |
| | | 57 | | } |