| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.ComponentModel.Design; |
| | | 4 | | using System.Linq; |
| | | 5 | | using System.Linq.Expressions; |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | using DocumentFormat.OpenXml.Drawing.Diagrams; |
| | | 8 | | using DocumentFormat.OpenXml.Office2010.Excel; |
| | | 9 | | using Microsoft.EntityFrameworkCore; |
| | | 10 | | using Microsoft.EntityFrameworkCore.Internal; |
| | | 11 | | using Microsoft.Extensions.DependencyInjection; |
| | | 12 | | using Microsoft.Extensions.Logging; |
| | | 13 | | using Newtonsoft.Json; |
| | | 14 | | using Newtonsoft.Json.Converters; |
| | | 15 | | using SVETA.Api.Data.DTO.Movements; |
| | | 16 | | using SVETA.Api.Data.DTO.Reports; |
| | | 17 | | using SVETA.Api.Helpers; |
| | | 18 | | using SVETA.Api.Services.Implements; |
| | | 19 | | using WinSolutions.Sveta.Common; |
| | | 20 | | using WinSolutions.Sveta.Server.Data.DataModel.Contexts; |
| | | 21 | | using WinSolutions.Sveta.Server.Data.DataModel.Entities; |
| | | 22 | | using WinSolutions.Sveta.Server.Data.DataModel.Kinds; |
| | | 23 | | using WinSolutions.Sveta.Server.Data.DataModel.Reports; |
| | | 24 | | using WinSolutions.Sveta.Server.Domain; |
| | | 25 | | using WinSolutions.Sveta.Server.Services.Interfaces; |
| | | 26 | | |
| | | 27 | | namespace WinSolutions.Sveta.Server.Services.Implements |
| | | 28 | | { |
| | | 29 | | public class ReportService: SvetaServiceBase, IReportService |
| | | 30 | | { |
| | | 31 | | private readonly ILogger<ReportService> _logger; |
| | | 32 | | private readonly SvetaDbContext _db; |
| | | 33 | | private readonly IGoodService _goodService; |
| | | 34 | | private readonly IAuthenticationService _authenticationService; |
| | | 35 | | private readonly IWalletPaymentService _walletPaymentService; |
| | | 36 | | public ReportService(IAuthenticationService authenticationService, |
| | | 37 | | ILogger<ReportService> logger, |
| | | 38 | | SvetaDbContext db, |
| | | 39 | | IWalletPaymentService walletPaymentService, |
| | | 40 | | IGoodService goodService |
| | 3 | 41 | | ) : base(authenticationService) |
| | 3 | 42 | | { |
| | 3 | 43 | | _authenticationService = authenticationService; |
| | 3 | 44 | | _walletPaymentService = walletPaymentService; |
| | 3 | 45 | | _logger = logger; |
| | 3 | 46 | | _db = db; |
| | 3 | 47 | | _goodService = goodService; |
| | 3 | 48 | | } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Возвращает товарный отчет |
| | | 52 | | /// </summary> |
| | | 53 | | /// <param name="contragentId">Склад для построения отчета</param> |
| | | 54 | | /// <param name="categoryId">категория товара - 0 для всех</param> |
| | | 55 | | /// <param name="dateFrom">Дата начала отбора - для всех по умолчанию</param> |
| | | 56 | | /// <param name="dateTo">Дата окончания отбора - для всех по умолчанию</param> |
| | | 57 | | /// <param name="sort">Сортировка - по умолочанию goodname, goodname|desc, category, category|desc, sum, sum|des |
| | | 58 | | /// <param name="filter">Фильтр по наименованию товара - по умолчанию для всех</param> |
| | | 59 | | /// <param name="page">Страница отбора - 0 по умолчанию</param> |
| | | 60 | | /// <param name="limit">Лимит отбора - 10 по умолчанию</param> |
| | | 61 | | /// <returns>Task<PaginatedData<List<GoodAccount>>></returns> |
| | | 62 | | public async Task<PaginatedData<List<GoodAccount>>> GoodAccountingReport(long contragentId, long categoryId = 0, |
| | | 63 | | DateTime dateTo = default, string sort = default, string filter = default, int page = 0, int limit = 10) |
| | 1 | 64 | | { |
| | 1 | 65 | | limit = limit < 1 ? 10 : limit; |
| | 1 | 66 | | var goodsList = _db.Goods |
| | 1 | 67 | | .Include(good => good.Category) |
| | 1 | 68 | | .Include(good => good.Prices) |
| | 1 | 69 | | .ThenInclude(prices => prices.PriceTrend) |
| | 1 | 70 | | .ThenInclude(trend => trend.SupplierDepartment) |
| | 1 | 71 | | .ThenInclude(suplierDep => suplierDep.Contragent) |
| | 1 | 72 | | .AsQueryable(); |
| | 1 | 73 | | List<long> cats = new List<long>(); |
| | 1 | 74 | | if (categoryId != 0) |
| | 0 | 75 | | { |
| | 0 | 76 | | cats = _goodService.ExpandCategoryTree(new List<long>() {categoryId}); |
| | 0 | 77 | | cats.Add(categoryId); |
| | 0 | 78 | | } |
| | | 79 | | |
| | 1 | 80 | | var totalCount = goodsList.Count(); |
| | | 81 | | |
| | 1 | 82 | | var filtered = goodsList.Where(good => |
| | 1 | 83 | | !good.IsDeleted |
| | 1 | 84 | | && good.Prices.Count > 0 && good.Prices.Any(price => |
| | 1 | 85 | | price.PriceTrend.SupplierDepartment.Contragent.Id == contragentId)) |
| | 1 | 86 | | .Where(good => categoryId == 0 || cats.Contains(good.Category.Id)) |
| | 1 | 87 | | .Where(good => string.IsNullOrEmpty(filter) || good.Name.ToLower().Contains(filter.ToLower().Trim())) |
| | 1 | 88 | | .Select(good => new {Id = good.Id, Name = good.Name, CatName = good.Category.Name}) |
| | 1 | 89 | | .AsEnumerable(); |
| | | 90 | | |
| | 1 | 91 | | var movementList = _db.MovementStatusJournals |
| | 1 | 92 | | .Include(journal => journal.Movement) |
| | 1 | 93 | | .ThenInclude(movement => movement.Items) |
| | 1 | 94 | | .ThenInclude(item => item.Good) |
| | 1 | 95 | | .Include(journal => journal.Movement) |
| | 1 | 96 | | .ThenInclude(movement => movement.Sender) |
| | 1 | 97 | | .Include(journal => journal.Movement) |
| | 1 | 98 | | .ThenInclude(movement => movement.Customer) |
| | 1 | 99 | | .Where(d => !d.Movement.IsDeleted) |
| | 1 | 100 | | .Where(d => dateFrom == default || d.Movement.CreationDateTime >= dateFrom) |
| | 1 | 101 | | .Where(d => dateTo == default || d.CreationDateTime < dateTo) |
| | 1 | 102 | | .Where(d => d.Movement.Supplier.Id == contragentId |
| | 1 | 103 | | && (d.StatusCurrent.Id == (long) MovementsStatus.Received |
| | 1 | 104 | | || d.StatusCurrent.Id == (long) MovementsStatus.ClaimDeclined )) |
| | 1 | 105 | | .Select(d => d.Movement) |
| | 1 | 106 | | .ToList(); |
| | | 107 | | |
| | 5 | 108 | | var result = filtered.Select(good => new GoodAccount |
| | 5 | 109 | | { |
| | 5 | 110 | | CategoryName = good.CatName, |
| | 5 | 111 | | GoodName = good.Name, |
| | 0 | 112 | | SellCount = movementList.Where(movement => movement.Items.Any(item => item.Good.Id == good.Id)) |
| | 5 | 113 | | .Count(), |
| | 5 | 114 | | SellItemCount = movementList |
| | 0 | 115 | | .Select(movement => movement.Items.FirstOrDefault(item => item.Good.Id == good.Id)) |
| | 0 | 116 | | .Where(item => item != null) |
| | 0 | 117 | | .Sum(item => item.Quantity), |
| | 5 | 118 | | Sum = movementList |
| | 0 | 119 | | .Select(movement => movement.Items.FirstOrDefault(item => item.Good.Id == good.Id)) |
| | 0 | 120 | | .Where(d => d != null) |
| | 0 | 121 | | .Sum(item => item.Price * item.Quantity), |
| | 5 | 122 | | BuyerCount = movementList |
| | 0 | 123 | | .Where(movement => movement.Items.Any(d => d.Good.Id == good.Id)) |
| | 0 | 124 | | .GroupBy(movement => movement.Customer) |
| | 0 | 125 | | .Select(movement => movement.First()) |
| | 5 | 126 | | .Count() |
| | 5 | 127 | | }).AsQueryable(); |
| | | 128 | | |
| | 1 | 129 | | result = result.Where(d => d.SellCount > 0); |
| | | 130 | | |
| | 1 | 131 | | var filteredCount = result.Count(); |
| | 1 | 132 | | Expression<Func<GoodAccount, object>> sortExpression = |
| | 1 | 133 | | (sort?.Split("|").ElementAtOrDefault(0) ?? "").ToLower() switch |
| | 1 | 134 | | { |
| | 1 | 135 | | "category" => e => e.CategoryName, |
| | 1 | 136 | | "sum" => e => e.Sum, |
| | 1 | 137 | | "sellcount" => e => e.SellCount, |
| | 1 | 138 | | "sellitemcount" => e => e.SellItemCount, |
| | 1 | 139 | | _ => e => e.GoodName |
| | 1 | 140 | | }; |
| | 1 | 141 | | var finished = (sort?.Split("|").ElementAtOrDefault(1) ?? "").ToLower() switch |
| | 1 | 142 | | { |
| | 1 | 143 | | "desc" => result.OrderByDescending(sortExpression), |
| | 1 | 144 | | _ => result.OrderBy(sortExpression) |
| | 1 | 145 | | }; |
| | | 146 | | |
| | 1 | 147 | | var paginated = new PaginatedData<List<GoodAccount>> |
| | 1 | 148 | | { |
| | 1 | 149 | | TotalCount = totalCount, |
| | 1 | 150 | | TotalFilteredCount = filteredCount, |
| | 1 | 151 | | Result = finished.Skip((page < 2 ? 0 : page-1) * (int)limit).Take((int)limit).ToList() |
| | 1 | 152 | | }; |
| | | 153 | | |
| | 1 | 154 | | return paginated; |
| | 1 | 155 | | } |
| | | 156 | | /// <summary> |
| | | 157 | | /// Возвращает товарный отчет без пагинации |
| | | 158 | | /// </summary> |
| | | 159 | | /// <param name="contragentId">Склад для построения отчета</param> |
| | | 160 | | /// <param name="categoryId">категория товара - 0 для всех</param> |
| | | 161 | | /// <param name="dateFrom">Дата начала отбора - для всех по умолчанию</param> |
| | | 162 | | /// <param name="dateTo">Дата окончания отбора - для всех по умолчанию</param> |
| | | 163 | | /// <param name="sort">Сортировка -goodname, goodname|desc, category, category|desc, sum, sum|desc, sellcount, s |
| | | 164 | | /// <param name="filter">Фильтр по наименованию товара - по умолчанию для всех</param> |
| | | 165 | | /// <returns>Task<List<GoodAccount>></returns> |
| | | 166 | | public async Task<List<GoodAccount>> GoodAccountingReportWithoutPagination(long contragentId, long categoryId = |
| | | 167 | | DateTime dateFrom = default, |
| | | 168 | | DateTime dateTo = default, string sort = default, string filter = default) |
| | 0 | 169 | | { |
| | 0 | 170 | | List<long> cats = new List<long>(); |
| | 0 | 171 | | if (categoryId != 0) |
| | 0 | 172 | | { |
| | 0 | 173 | | cats = _goodService.ExpandCategoryTree(new List<long>() {categoryId}); |
| | 0 | 174 | | cats.Add(categoryId); |
| | 0 | 175 | | } |
| | 0 | 176 | | var goodsList = _db.Goods |
| | 0 | 177 | | .Include(good => good.Category) |
| | 0 | 178 | | .Include(good => good.Prices) |
| | 0 | 179 | | .ThenInclude(prices => prices.PriceTrend) |
| | 0 | 180 | | .ThenInclude(trend => trend.SupplierDepartment) |
| | 0 | 181 | | .ThenInclude(suplierDep => suplierDep.Contragent) |
| | 0 | 182 | | .Where(good => |
| | 0 | 183 | | !good.IsDeleted |
| | 0 | 184 | | && good.Prices.Count > 0 && good.Prices.Any(price => |
| | 0 | 185 | | price.PriceTrend.SupplierDepartment.Contragent.Id == contragentId)) |
| | 0 | 186 | | .Where(good => categoryId == 0 || cats.Contains(good.Category.Id)) |
| | 0 | 187 | | .Where(good => string.IsNullOrEmpty(filter) || good.Name.ToLower().Contains(filter.ToLower().Trim())) |
| | 0 | 188 | | .Select(good => new {Id = good.Id, Name = good.Name, CatName = good.Category.Name}) |
| | 0 | 189 | | .AsEnumerable(); |
| | | 190 | | |
| | 0 | 191 | | var movementList = _db.MovementStatusJournals |
| | 0 | 192 | | .Include(journal => journal.Movement) |
| | 0 | 193 | | .ThenInclude(movement => movement.Items) |
| | 0 | 194 | | .ThenInclude(item => item.Good) |
| | 0 | 195 | | .Include(journal => journal.Movement) |
| | 0 | 196 | | .ThenInclude(movement => movement.Sender) |
| | 0 | 197 | | .Include(journal => journal.Movement) |
| | 0 | 198 | | .ThenInclude(movement => movement.Customer) |
| | 0 | 199 | | .Where(d => !d.Movement.IsDeleted) |
| | 0 | 200 | | .Where(d => dateFrom == default || d.Movement.CreationDateTime >= dateFrom) |
| | 0 | 201 | | .Where(d => dateTo == default || d.CreationDateTime < dateTo) |
| | 0 | 202 | | .Where(d => d.Movement.Supplier.Id == contragentId |
| | 0 | 203 | | && (d.StatusCurrent.Id == (long) MovementsStatus.Received |
| | 0 | 204 | | || d.StatusCurrent.Id == (long) MovementsStatus.ClaimDeclined )) |
| | 0 | 205 | | .Select(d => d.Movement) |
| | 0 | 206 | | .ToList(); |
| | 0 | 207 | | var result = goodsList.Select(good => new GoodAccount |
| | 0 | 208 | | { |
| | 0 | 209 | | CategoryName = good.CatName, |
| | 0 | 210 | | GoodName = good.Name, |
| | 0 | 211 | | SellCount = movementList.Where(movement => movement.Items.Any(item => item.Good.Id == good.Id)) |
| | 0 | 212 | | .Count(), |
| | 0 | 213 | | SellItemCount = movementList |
| | 0 | 214 | | .Select(movement => movement.Items.FirstOrDefault(item => item.Good.Id == good.Id)) |
| | | 215 | | .Where(item => item != null) |
| | | 216 | | .Sum(item => item.Quantity), |
| | 0 | 217 | | Sum = movementList |
| | 0 | 218 | | .Select(movement => movement.Items.FirstOrDefault(item => item.Good.Id == good.Id)) |
| | | 219 | | .Where(d => d != null) |
| | | 220 | | .Sum(item => item.Price), |
| | 0 | 221 | | BuyerCount = movementList |
| | 0 | 222 | | .Where(movement => movement.Items.Any(d => d.Good.Id == good.Id)) |
| | | 223 | | .GroupBy(movement => movement.Customer) |
| | | 224 | | .Select(movement => movement.First()) |
| | 0 | 225 | | .Count() |
| | 0 | 226 | | }).AsQueryable(); |
| | 0 | 227 | | result = result.Where(d => d.SellCount > 0); |
| | 0 | 228 | | Expression<Func<GoodAccount, object>> sortExpression = |
| | 0 | 229 | | (sort?.Split("|").ElementAtOrDefault(0) ?? "").ToLower() switch |
| | 0 | 230 | | { |
| | 0 | 231 | | "category" => e => e.CategoryName, |
| | 0 | 232 | | "sum" => e => e.Sum, |
| | 0 | 233 | | "sellcount" => e => e.SellCount, |
| | 0 | 234 | | "sellitemcount" => e => e.SellItemCount, |
| | 0 | 235 | | _ => e => e.GoodName |
| | 0 | 236 | | }; |
| | 0 | 237 | | var finished = (sort?.Split("|").ElementAtOrDefault(1) ?? "").ToLower() switch |
| | 0 | 238 | | { |
| | 0 | 239 | | "desc" => result.OrderByDescending(sortExpression), |
| | 0 | 240 | | _ => result.OrderBy(sortExpression) |
| | 0 | 241 | | }; |
| | 0 | 242 | | return await Task.FromResult(finished.ToList()); |
| | 0 | 243 | | } |
| | | 244 | | |
| | | 245 | | /// <summary> |
| | | 246 | | /// Возвращает финансовый отчет |
| | | 247 | | /// </summary> |
| | | 248 | | /// <param name="contragentId">Идентификатор контрагента поставщика - 0 для всех</param> |
| | | 249 | | /// <param name="dateFrom">Дата начала отбора - по умолчанию для всех</param> |
| | | 250 | | /// <param name="dateTo">Дата окончания отбора - по умолчанию для всех</param> |
| | | 251 | | /// <param name="sort">Сортировка -по умолчанию byername, byername|desc, customer, customer|desc, holdedsum, hol |
| | | 252 | | /// <param name="filter">Фильтрация по назаванию покупателя - по умолчанию для всех</param> |
| | | 253 | | /// <param name="page">Страница отбора - 0 по умолчанию</param> |
| | | 254 | | /// <param name="limit">Лимит отбора - 10 по умолчанию</param> |
| | | 255 | | /// <returns>Task<MoneyAccountWrapper></returns> |
| | | 256 | | public async Task<MoneyAccountWrapper> MoneyAccountingReport(long contragentId, DateTime dateFrom = default, |
| | | 257 | | DateTime dateTo = default, string sort = default, string filter = default, int page = 0, int limit = 10) |
| | | 258 | | { |
| | | 259 | | limit = limit < 1 ? 10 : limit; |
| | | 260 | | var movements = _db.Movements |
| | | 261 | | .AsNoTracking() |
| | | 262 | | .Include(movement => movement.Customer) |
| | | 263 | | .Include(movement => movement.Supplier) |
| | | 264 | | .Include(movement => movement.MovementType) |
| | | 265 | | .Include(movement => movement.MovementStatus); |
| | | 266 | | var total = movements.ToList().GroupBy(d => d.Customer.Id) |
| | | 267 | | .Select(d => d.First()).Count(); |
| | | 268 | | var filterMovements = movements |
| | | 269 | | .Where(movement => dateFrom == default || movement.CreationDateTime >= dateFrom) |
| | | 270 | | .Where(movement => dateTo == default || movement.CreationDateTime <= dateTo) |
| | | 271 | | .Where(movement => contragentId == 0 || movement.Supplier.Id == contragentId) |
| | | 272 | | .Where(movement => string.IsNullOrEmpty(filter) || |
| | | 273 | | movement.Customer.ShortName.ToLower().Contains(filter.ToLower()) |
| | | 274 | | || movement.Customer.FullName.ToLower().Contains(filter.ToLower())) |
| | | 275 | | .ToList(); |
| | | 276 | | |
| | | 277 | | var totalFiltered = filterMovements.GroupBy(d => d.Customer.Id) |
| | | 278 | | .Select(d => d.First()) |
| | | 279 | | .Count(); |
| | | 280 | | |
| | | 281 | | var shipInWork = new long[] |
| | | 282 | | { |
| | | 283 | | (long) MovementsStatus.ShipmentDraft, (long) MovementsStatus.PaymentAwaiting, |
| | | 284 | | (long) MovementsStatus.Picking,(long) MovementsStatus.ReadyForShipment, |
| | | 285 | | (long) MovementsStatus.Correction, (long) MovementsStatus.Shipped, |
| | | 286 | | (long) MovementsStatus.ClaimInProgress |
| | | 287 | | }; |
| | | 288 | | var rejected = new long[] |
| | | 289 | | { |
| | | 290 | | (long) MovementsStatus.ClaimAccepted, |
| | | 291 | | (long) MovementsStatus.SupplierReject, |
| | | 292 | | (long) MovementsStatus.ShipmentReject, |
| | | 293 | | (long) MovementsStatus.CustomerReject |
| | | 294 | | }; |
| | | 295 | | |
| | | 296 | | var list = filterMovements |
| | | 297 | | .GroupBy(d => d.Customer.Id) |
| | | 298 | | .Select(d => d.First()) |
| | 0 | 299 | | .Select(d => new MoneyAccount |
| | 0 | 300 | | { |
| | 0 | 301 | | BuyerName = d.Customer.ShortName, |
| | 0 | 302 | | OrderCount = filterMovements.Where(movement => |
| | 0 | 303 | | movement.Customer.Id == d.Customer.Id && |
| | 0 | 304 | | movement.MovementType.Id == (long) MovementKind.Order) |
| | 0 | 305 | | .Count(), |
| | 0 | 306 | | ShipmentInWorkCount = filterMovements.Where(movement => |
| | 0 | 307 | | movement.Customer.Id == d.Customer.Id && !movement.IsDeleted && shipInWork.Contains(movement |
| | 0 | 308 | | .Count(), |
| | 0 | 309 | | ShipmentReceivedCount = filterMovements.Where(movement => movement.Customer.Id == d.Customer.Id && ( |
| | 0 | 310 | | movement.MovementStatus.Id == |
| | 0 | 311 | | (long) MovementsStatus.Received |
| | 0 | 312 | | || movement.MovementStatus.Id == |
| | 0 | 313 | | (long) MovementsStatus.ClaimDeclined)) |
| | 0 | 314 | | .Count(), |
| | 0 | 315 | | ShipmentRejectedCount = filterMovements.Where(movement => movement.Customer.Id == d.Customer.Id |
| | 0 | 316 | | && (rejected.Contains(movement.MovementSt |
| | 0 | 317 | | || movement.IsDeleted)) |
| | 0 | 318 | | .Count(), |
| | 0 | 319 | | HoldedMoneySum = (_walletPaymentService.GetWalletInfo(d.Customer.Id).Result) == null |
| | 0 | 320 | | ? 0 |
| | 0 | 321 | | : (_walletPaymentService.GetWalletInfo(d.Customer.Id).Result).Hold, |
| | 0 | 322 | | RejectedMoneySum = _db.WalletTransactions |
| | 0 | 323 | | .Include(d => d.Movement) |
| | 0 | 324 | | .Where(w => w.Movement.Id == d.Customer.Id && |
| | 0 | 325 | | w.Status.Id == (long) TransactionStatusKind.Canceled) |
| | 0 | 326 | | .Sum(w => w.Sum), |
| | 0 | 327 | | AcceptedMoneySum = |
| | 0 | 328 | | _db.WalletTransactions |
| | 0 | 329 | | .Include(d => d.Movement) |
| | 0 | 330 | | .Where(w => w.Movement.Id == d.Customer.Id && |
| | 0 | 331 | | w.Status.Id == (long) TransactionStatusKind.Confirmed) |
| | 0 | 332 | | .Sum(w => w.Sum), |
| | 0 | 333 | | }).AsQueryable(); |
| | | 334 | | |
| | | 335 | | Expression<Func<MoneyAccount, object>> sortExpression = |
| | | 336 | | (sort?.Split("|").ElementAtOrDefault(0) ?? "").ToLower() switch |
| | | 337 | | { |
| | | 338 | | "customer" => e => e.BuyerName, |
| | | 339 | | "holdedsum" => e => e.HoldedMoneySum, |
| | | 340 | | "rejectedsum" => e => e.RejectedMoneySum, |
| | | 341 | | "acceptedsum" => e => e.AcceptedMoneySum, |
| | | 342 | | "ordercount" => e => e.OrderCount, |
| | | 343 | | _ => e => e.BuyerName |
| | | 344 | | }; |
| | | 345 | | var finished = (sort?.Split("|").ElementAtOrDefault(1) ?? "").ToLower() switch |
| | | 346 | | { |
| | | 347 | | "desc" => list.OrderByDescending(sortExpression), |
| | | 348 | | _ => list.OrderBy(sortExpression) |
| | | 349 | | }; |
| | | 350 | | var moneyAccounts = finished.Skip((page < 2 ? 0 : page - 1) * (int) limit).Take((int) limit).ToList(); |
| | | 351 | | return new MoneyAccountWrapper |
| | | 352 | | { |
| | | 353 | | Data = moneyAccounts, |
| | | 354 | | MoneyAccountReportSummary = new MoneyAccountReportSummary {HoldedSum = moneyAccounts.Sum(account => acco |
| | | 355 | | RejectedSum = moneyAccounts.Sum(account => account.RejectedMoneySum), |
| | | 356 | | AcceptedSum = moneyAccounts.Sum(account => account.AcceptedMoneySum), |
| | | 357 | | OrderCount = moneyAccounts.Sum(account => account.OrderCount), |
| | | 358 | | ShipmentCount = moneyAccounts.Sum(account => |
| | | 359 | | account.ShipmentInWorkCount + account.ShipmentReceivedCount + account.ShipmentRejectedCount) |
| | | 360 | | }, |
| | | 361 | | Pagination = new Pagination |
| | | 362 | | { |
| | | 363 | | TotalCount = total, |
| | | 364 | | TotalFilteredCount = totalFiltered |
| | | 365 | | } |
| | | 366 | | }; |
| | | 367 | | } |
| | | 368 | | |
| | | 369 | | /// <summary> |
| | | 370 | | /// Возвращает финансовый отчет без пагинации |
| | | 371 | | /// </summary> |
| | | 372 | | /// <param name="contragentId">Идентификатор контрагента поставщика - 0 для всех</param> |
| | | 373 | | /// <param name="dateFrom">Дата начала отбора - по умолчанию для всех</param> |
| | | 374 | | /// <param name="dateTo">Дата окончания отбора - по умолчанию для всех</param> |
| | | 375 | | /// <param name="sort">Сортировка -по умолчанию byername, byername|desc, customer, customer|desc, holdedsum, hol |
| | | 376 | | /// <param name="filter">Фильтрация по назаванию покупателя - по умолчанию для всех</param> |
| | | 377 | | /// <returns>Task<List<MoneyAccount>></returns> |
| | | 378 | | public async Task<List<MoneyAccount>> MoneyAccountingReportWithoutPagination(long contragentId, |
| | | 379 | | DateTime dateFrom = default, |
| | | 380 | | DateTime dateTo = default, string sort = default, string filter = default) |
| | | 381 | | { |
| | | 382 | | var movements = _db.Movements |
| | | 383 | | .AsNoTracking() |
| | | 384 | | .Include(movement => movement.Customer) |
| | | 385 | | .Include(movement => movement.Supplier) |
| | | 386 | | .Include(movement => movement.MovementType) |
| | | 387 | | .Include(movement => movement.MovementStatus); |
| | | 388 | | var total = movements.ToList().GroupBy(d => d.Customer.Id) |
| | | 389 | | .Select(d => d.First()).Count(); |
| | | 390 | | var filterMovements = movements |
| | | 391 | | .Where(movement => dateFrom == default || movement.CreationDateTime >= dateFrom) |
| | | 392 | | .Where(movement => dateTo == default || movement.CreationDateTime <= dateTo) |
| | | 393 | | .Where(movement => contragentId == 0 || movement.Supplier.Id == contragentId) |
| | | 394 | | .Where(movement => string.IsNullOrEmpty(filter) || |
| | | 395 | | movement.Customer.ShortName.ToLower().Contains(filter.ToLower()) |
| | | 396 | | || movement.Customer.FullName.ToLower().Contains(filter.ToLower())) |
| | | 397 | | .ToList(); |
| | | 398 | | var shipInWork = new long[] |
| | | 399 | | { |
| | | 400 | | (long) MovementsStatus.ShipmentDraft, (long) MovementsStatus.PaymentAwaiting, |
| | | 401 | | (long) MovementsStatus.Picking,(long) MovementsStatus.ReadyForShipment, |
| | | 402 | | (long) MovementsStatus.Correction, (long) MovementsStatus.Shipped, |
| | | 403 | | (long) MovementsStatus.ClaimInProgress |
| | | 404 | | }; |
| | | 405 | | var rejected = new long[] |
| | | 406 | | { |
| | | 407 | | (long) MovementsStatus.ClaimAccepted, |
| | | 408 | | (long) MovementsStatus.SupplierReject, |
| | | 409 | | (long) MovementsStatus.ShipmentReject, |
| | | 410 | | (long) MovementsStatus.CustomerReject |
| | | 411 | | }; |
| | | 412 | | |
| | | 413 | | var list = filterMovements |
| | | 414 | | .GroupBy(d => d.Customer.Id) |
| | | 415 | | .Select(d => d.First()) |
| | 0 | 416 | | .Select(d => new MoneyAccount |
| | 0 | 417 | | { |
| | 0 | 418 | | BuyerName = d.Customer.ShortName, |
| | 0 | 419 | | OrderCount = filterMovements.Where(movement => |
| | 0 | 420 | | movement.Customer.Id == d.Customer.Id && |
| | 0 | 421 | | movement.MovementType.Id == (long) MovementKind.Order) |
| | 0 | 422 | | .Count(), |
| | 0 | 423 | | ShipmentInWorkCount = filterMovements.Where(movement => |
| | 0 | 424 | | movement.Customer.Id == d.Customer.Id && !movement.IsDeleted && shipInWork.Contains(movement |
| | 0 | 425 | | .Count(), |
| | 0 | 426 | | ShipmentReceivedCount = filterMovements.Where(movement => movement.Customer.Id == d.Customer.Id && ( |
| | 0 | 427 | | movement.MovementStatus.Id == |
| | 0 | 428 | | (long) MovementsStatus.Received |
| | 0 | 429 | | || movement.MovementStatus.Id == |
| | 0 | 430 | | (long) MovementsStatus.ClaimDeclined)) |
| | 0 | 431 | | .Count(), |
| | 0 | 432 | | ShipmentRejectedCount = filterMovements.Where(movement => movement.Customer.Id == d.Customer.Id |
| | 0 | 433 | | && (rejected.Contains(movement.MovementSt |
| | 0 | 434 | | || movement.IsDeleted)) |
| | 0 | 435 | | .Count(), |
| | 0 | 436 | | HoldedMoneySum = (_walletPaymentService.GetWalletInfo(d.Customer.Id).Result) == null |
| | 0 | 437 | | ? 0 |
| | 0 | 438 | | : (_walletPaymentService.GetWalletInfo(d.Customer.Id).Result).Hold, |
| | 0 | 439 | | RejectedMoneySum = _db.WalletTransactions |
| | 0 | 440 | | .Include(d => d.Movement) |
| | 0 | 441 | | .Where(w => w.Movement.Id == d.Customer.Id && |
| | 0 | 442 | | w.Status.Id == (long) TransactionStatusKind.Canceled) |
| | 0 | 443 | | .Sum(w => w.Sum), |
| | 0 | 444 | | AcceptedMoneySum = |
| | 0 | 445 | | _db.WalletTransactions |
| | 0 | 446 | | .Include(d => d.Movement) |
| | 0 | 447 | | .Where(w => w.Movement.Id == d.Customer.Id && |
| | 0 | 448 | | w.Status.Id == (long) TransactionStatusKind.Confirmed) |
| | 0 | 449 | | .Sum(w => w.Sum), |
| | 0 | 450 | | }).AsQueryable(); |
| | | 451 | | |
| | | 452 | | Expression<Func<MoneyAccount, object>> sortExpression = |
| | | 453 | | (sort?.Split("|").ElementAtOrDefault(0) ?? "").ToLower() switch |
| | | 454 | | { |
| | | 455 | | "customer" => e => e.BuyerName, |
| | | 456 | | "holdedsum" => e => e.HoldedMoneySum, |
| | | 457 | | "rejectedsum" => e => e.RejectedMoneySum, |
| | | 458 | | "acceptedsum" => e => e.AcceptedMoneySum, |
| | | 459 | | "ordercount" => e => e.OrderCount, |
| | | 460 | | _ => e => e.BuyerName |
| | | 461 | | }; |
| | | 462 | | var finished = (sort?.Split("|").ElementAtOrDefault(1) ?? "").ToLower() switch |
| | | 463 | | { |
| | | 464 | | "desc" => list.OrderByDescending(sortExpression), |
| | | 465 | | _ => list.OrderBy(sortExpression) |
| | | 466 | | }; |
| | | 467 | | return finished.ToList(); |
| | | 468 | | } |
| | | 469 | | |
| | | 470 | | /// <summary> |
| | | 471 | | /// Ежедневный отчет |
| | | 472 | | /// </summary> |
| | | 473 | | /// <returns>List<EveryDay></returns> |
| | | 474 | | public List<EveryDay> EveryDayReport() |
| | 0 | 475 | | { |
| | 0 | 476 | | return _db.MovementStatusJournals |
| | 0 | 477 | | .Include(d => d.Movement) |
| | 0 | 478 | | .ThenInclude(movement => movement.Customer) |
| | 0 | 479 | | .Include(d => d.Movement) |
| | 0 | 480 | | .ThenInclude(movement => movement.Notes) |
| | 0 | 481 | | .Where(d => d.CreationDateTime >= DateTime.UtcNow.AddDays(-1) && d.CreationDateTime <= DateTime.UtcNow) |
| | 0 | 482 | | .AsEnumerable() |
| | 0 | 483 | | .GroupBy(d => d.Movement.Id) |
| | 0 | 484 | | .Select(d => d.First()) |
| | 0 | 485 | | .Select(d => new EveryDay |
| | 0 | 486 | | { |
| | 0 | 487 | | Name = d.Movement.Customer.FullName, |
| | 0 | 488 | | Inn = d.Movement.Customer.Inn, |
| | 0 | 489 | | MovementId = d.Movement.Id, |
| | 0 | 490 | | Date = d.Movement.CreationDateTime, |
| | 0 | 491 | | Sum = d.Movement.PrepaimentSum, |
| | 0 | 492 | | Statuses = String.Join("->", _db.MovementStatusJournals |
| | 0 | 493 | | .Include(j => j.Movement) |
| | 0 | 494 | | .Include(j => j.StatusCurrent) |
| | 0 | 495 | | .Where(j => j.Movement.Id == d.Movement.Id) |
| | 0 | 496 | | .Select(d => d.StatusCurrent.Name)), |
| | 0 | 497 | | Comment = String.Join(";", d.Movement.Notes.Select(s => s.Body)) |
| | 0 | 498 | | }).ToList(); |
| | 0 | 499 | | } |
| | | 500 | | |
| | | 501 | | /// <summary> |
| | | 502 | | /// Отчет матрица |
| | | 503 | | /// </summary> |
| | | 504 | | /// <param name="dateFrom">Дата начала отбора - по умолчанию для всех</param> |
| | | 505 | | /// <param name="dateTo">Дата окончания отбора - по умолчанию для всех</param> |
| | | 506 | | /// <returns>List<MatrixReport></returns> |
| | | 507 | | public List<MatrixReport> GetMatrixReport(DateTime dateFrom = default, DateTime dateTo = default) |
| | 0 | 508 | | { |
| | 0 | 509 | | Dictionary<long, List<MovementStatusJournal>> dict = _db.MovementStatusJournals |
| | 0 | 510 | | .Include(d => d.StatusCurrent) |
| | 0 | 511 | | .Include(d => d.Movement) |
| | 0 | 512 | | .ThenInclude(movement => movement.Customer) |
| | 0 | 513 | | .Include(d => d.Movement) |
| | 0 | 514 | | .ThenInclude(movement => movement.MovementStatus) |
| | 0 | 515 | | .Where(d => !d.Movement.IsDeleted) |
| | 0 | 516 | | .Where(d => dateFrom == default || d.Movement.CreationDateTime >= dateFrom) |
| | 0 | 517 | | .Where(d => dateTo == default || d.Movement.CreationDateTime <= dateTo) |
| | 0 | 518 | | .AsEnumerable() |
| | 0 | 519 | | .GroupBy(d => d.Movement.Id) |
| | 0 | 520 | | .Select(d => d.First()) |
| | 0 | 521 | | .OrderBy(d => d.Movement.Id) |
| | 0 | 522 | | .ToDictionary(d => d.Movement.Id, |
| | 0 | 523 | | d => _db.MovementStatusJournals |
| | 0 | 524 | | .Where(journal => journal.Movement.Id == d.Movement.Id).ToList()); |
| | 0 | 525 | | var t = dict.Select(d => new MatrixReport |
| | 0 | 526 | | { |
| | 0 | 527 | | Name = d.Value.FirstOrDefault()?.Movement?.Customer?.FullName, |
| | 0 | 528 | | Inn = d.Value.FirstOrDefault()?.Movement?.Customer?.Inn, |
| | 0 | 529 | | MovementId = d.Key, |
| | 0 | 530 | | Date = d.Value.FirstOrDefault()?.Movement?.CreationDateTime.ToMoscowTime() ?? DateTime.Now, |
| | 0 | 531 | | Sum = d.Value.FirstOrDefault()?.Movement?.PrepaimentSum ?? 0, |
| | 0 | 532 | | OrderDraft = d.Value |
| | 0 | 533 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.OrderDraft)? |
| | 0 | 534 | | .CreationDateTime != null ? d.Value |
| | 0 | 535 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.OrderDraft)? |
| | 0 | 536 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 537 | | OrderInQueue = d.Value |
| | 0 | 538 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.InQueue)? |
| | 0 | 539 | | .CreationDateTime != null ? d.Value |
| | 0 | 540 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.InQueue)? |
| | 0 | 541 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 542 | | OrderInProgress = d.Value |
| | 0 | 543 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.InProgress)? |
| | 0 | 544 | | .CreationDateTime != null ? d.Value |
| | 0 | 545 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.InProgress)? |
| | 0 | 546 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 547 | | OrderReject = d.Value |
| | 0 | 548 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.Reject)? |
| | 0 | 549 | | .CreationDateTime != null ? d.Value |
| | 0 | 550 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.Reject)? |
| | 0 | 551 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 552 | | OrderFinished = d.Value |
| | 0 | 553 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.Finished)? |
| | 0 | 554 | | .CreationDateTime != null ? d.Value |
| | 0 | 555 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.Finished)? |
| | 0 | 556 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 557 | | ShipmentDraft = d.Value |
| | 0 | 558 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.ShipmentDraft)? |
| | 0 | 559 | | .CreationDateTime != null ? d.Value |
| | 0 | 560 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.ShipmentDraft)? |
| | 0 | 561 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 562 | | ShipmentPaimentAwating = d.Value |
| | 0 | 563 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.PaymentAwaiting)? |
| | 0 | 564 | | .CreationDateTime != null ? d.Value |
| | 0 | 565 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.PaymentAwaiting)? |
| | 0 | 566 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 567 | | ShipmentPicking = d.Value |
| | 0 | 568 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.Picking)? |
| | 0 | 569 | | .CreationDateTime != null ? d.Value |
| | 0 | 570 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.Picking)? |
| | 0 | 571 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 572 | | ShipmentCorrection = d.Value |
| | 0 | 573 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.Correction)? |
| | 0 | 574 | | .CreationDateTime != null ? d.Value |
| | 0 | 575 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.Correction)? |
| | 0 | 576 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 577 | | ShipmentReadyToShip = d.Value |
| | 0 | 578 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.ReadyForShipment)? |
| | 0 | 579 | | .CreationDateTime != null ? d.Value |
| | 0 | 580 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.ReadyForShipment)? |
| | 0 | 581 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 582 | | ShipmentShipped = d.Value |
| | 0 | 583 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.Shipped)? |
| | 0 | 584 | | .CreationDateTime != null ? d.Value |
| | 0 | 585 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.Shipped)? |
| | 0 | 586 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 587 | | ShipmentCustomerReject = d.Value |
| | 0 | 588 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.CustomerReject)? |
| | 0 | 589 | | .CreationDateTime != null ? d.Value |
| | 0 | 590 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.CustomerReject)? |
| | 0 | 591 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 592 | | ShipmentSupplierReject = d.Value |
| | 0 | 593 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.SupplierReject)? |
| | 0 | 594 | | .CreationDateTime != null ? d.Value |
| | 0 | 595 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.SupplierReject)? |
| | 0 | 596 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 597 | | ShipmentReject = d.Value |
| | 0 | 598 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.ShipmentReject)? |
| | 0 | 599 | | .CreationDateTime != null ? d.Value |
| | 0 | 600 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.ShipmentReject)? |
| | 0 | 601 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 602 | | ShipmentReceived = d.Value |
| | 0 | 603 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.Received)? |
| | 0 | 604 | | .CreationDateTime != null ? d.Value |
| | 0 | 605 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.Received)? |
| | 0 | 606 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 607 | | ClaimInProgress = d.Value |
| | 0 | 608 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.ClaimInProgress)? |
| | 0 | 609 | | .CreationDateTime != null ? d.Value |
| | 0 | 610 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.ClaimInProgress)? |
| | 0 | 611 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 612 | | ClaimAccedpted = d.Value |
| | 0 | 613 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.ClaimAccepted)? |
| | 0 | 614 | | .CreationDateTime != null ? d.Value |
| | 0 | 615 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.ClaimAccepted)? |
| | 0 | 616 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 617 | | ClaimDeclined = d.Value |
| | 0 | 618 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.ClaimDeclined)? |
| | 0 | 619 | | .CreationDateTime != null ? d.Value |
| | 0 | 620 | | ?.FirstOrDefault(x => x.StatusCurrent.Id == (long) MovementsStatus.ClaimDeclined)? |
| | 0 | 621 | | .CreationDateTime.ToMoscowTime() : null, |
| | 0 | 622 | | }).ToList(); |
| | 0 | 623 | | return t; |
| | 0 | 624 | | } |
| | | 625 | | |
| | | 626 | | public async Task<List<StatusReport>> StatusReports(DateTime dateFrom, DateTime dateTo) |
| | | 627 | | { |
| | | 628 | | Dictionary<long, List<MovementStatusJournal>> dict = _db.MovementStatusJournals |
| | | 629 | | .Include(d => d.StatusCurrent) |
| | | 630 | | .Include(d => d.Movement) |
| | | 631 | | .ThenInclude(movement => movement.Customer) |
| | | 632 | | .Include(d => d.Movement) |
| | | 633 | | .ThenInclude(movement => movement.MovementStatus) |
| | | 634 | | .Include(d => d.Movement) |
| | | 635 | | .ThenInclude(movement => movement.Supplier) |
| | | 636 | | .Include(d => d.Movement) |
| | | 637 | | .ThenInclude(movement => movement.DeliveryType) |
| | | 638 | | .Where(d => !d.Movement.IsDeleted) |
| | | 639 | | .Where(d => d.StatusCurrent.Id != 1) |
| | | 640 | | .Where(d => dateFrom == default || d.Movement.CreationDateTime >= dateFrom) |
| | | 641 | | .Where(d => dateTo == default || d.Movement.CreationDateTime <= dateTo) |
| | | 642 | | .AsEnumerable() |
| | | 643 | | .GroupBy(d => d.Movement.Id) |
| | | 644 | | .Select(d => d.First()) |
| | | 645 | | .OrderBy(d => d.Movement.Id) |
| | | 646 | | .ToDictionary(d => d.Movement.Id, |
| | 0 | 647 | | d => _db.MovementStatusJournals |
| | 0 | 648 | | .Where(journal => journal.Movement.Id == d.Movement.Id) |
| | 0 | 649 | | .Where(journal => journal.StatusCurrent.Id != 1).ToList()); |
| | | 650 | | var guids = dict.Select(t => t.Value.FirstOrDefault().Movement.GUID).ToList(); |
| | | 651 | | var jsonSettings = new JsonSerializerSettings |
| | | 652 | | { |
| | | 653 | | Culture = new System.Globalization.CultureInfo("ru-RU"), //чтобы нормально было преобразование prepaimen |
| | | 654 | | Converters = new List<JsonConverter>() {new BadDateFixingConverter("dd/MM/yyyy hh:mm:ss")} |
| | | 655 | | }; |
| | | 656 | | |
| | | 657 | | var lis = _db.Events.Include(d => d.CreatedByUser) |
| | | 658 | | .Where(d => d.Entity.ToUpper().Equals("Movement".ToUpper())) |
| | | 659 | | .Where(d => guids.Contains(d.RecordGuid)) |
| | | 660 | | .Select(d => new |
| | | 661 | | { |
| | | 662 | | GUID = d.RecordGuid, |
| | | 663 | | User = d.CreatedByUser, |
| | | 664 | | Record = d.ReasonJson |
| | | 665 | | }).ToList(); |
| | | 666 | | |
| | | 667 | | Dictionary<Guid, List<EventRecord>> events = _db.Events |
| | | 668 | | .Where(d => d.Entity.ToUpper().Equals("Movement".ToUpper())) |
| | | 669 | | .Where(d => guids.Contains(d.RecordGuid)) |
| | | 670 | | .AsEnumerable() |
| | | 671 | | .GroupBy(d => d.RecordGuid) |
| | | 672 | | .Select(d => d.First()) |
| | | 673 | | .ToDictionary(d => d.RecordGuid, |
| | 0 | 674 | | d => lis |
| | 0 | 675 | | .Where(ev => ev.GUID == d.RecordGuid) |
| | 0 | 676 | | .Select(rec => new EventRecord |
| | 0 | 677 | | { |
| | 0 | 678 | | GUID = rec.GUID, |
| | 0 | 679 | | User = rec.User, |
| | 0 | 680 | | New = JsonConvert.DeserializeObject<MovementHistoryJsonDTO>(rec.Record, jsonSettings).New |
| | 0 | 681 | | }) |
| | | 682 | | .Where(rec => rec.New != null) |
| | 0 | 683 | | .ToList()); |
| | | 684 | | |
| | 0 | 685 | | var reports = dict.SelectMany(report => report.Value.Select(journal => new StatusReport |
| | 0 | 686 | | { |
| | 0 | 687 | | StatusName = journal.StatusCurrent.Name, |
| | 0 | 688 | | UserName = events.FirstOrDefault(d => d.Key.Equals(journal.Movement.GUID)) |
| | 0 | 689 | | .Value.FirstOrDefault(d => d.New.MovementStatusId == journal.StatusCurrent.Id) |
| | 0 | 690 | | .User.GetName(), |
| | 0 | 691 | | CustomerName = journal.Movement.Customer.ShortName, |
| | 0 | 692 | | SupplierName = journal.Movement.Supplier.ShortName, |
| | 0 | 693 | | BaseId = journal.Movement.ParentId ?? journal.Movement.Id, |
| | 0 | 694 | | CreationDate = journal.CreationDateTime.ToString("dd.MM.yyyy hh:mm:ss"), |
| | 0 | 695 | | Id = journal.Movement.Id, |
| | 0 | 696 | | StatusId = journal.StatusCurrent.Id, |
| | 0 | 697 | | Sum = events.FirstOrDefault(d => d.Key.Equals(journal.Movement.GUID)) |
| | 0 | 698 | | .Value.FirstOrDefault(d => d.New.MovementStatusId == journal.StatusCurrent.Id).New |
| | 0 | 699 | | .PrepaimentSum, |
| | 0 | 700 | | Month = journal.CreationDateTime.Month, |
| | 0 | 701 | | ParentId = journal.Movement.ParentId ?? 0, |
| | 0 | 702 | | DeliveryType = journal.Movement.DeliveryType?.Name ?? "Самовывоз" |
| | 0 | 703 | | })) |
| | | 704 | | .ToList(); |
| | | 705 | | return reports; |
| | | 706 | | } |
| | | 707 | | |
| | | 708 | | |
| | | 709 | | } |
| | | 710 | | } |