/// <summary> /// Все позиции с указанным товаром в указанные сроки, у которых МХ входит в указанный список /// </summary> /// <param name="articleId"></param> /// <param name="storageIds"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns></returns> public IEnumerable <ChangeOwnerWaybillRow> GetRows(int articleId, IEnumerable <short> storageIds, DateTime startDate, DateTime endDate, bool finallyMovedWaybillsOnly) { ISubQuery waybillSubQuery; if (finallyMovedWaybillsOnly) { waybillSubQuery = changeOwnerWaybillRepository.SubQuery <ChangeOwnerWaybill>() .OneOf(x => x.Storage.Id, storageIds) .Where(x => x.ChangeOwnerDate >= startDate && x.ChangeOwnerDate <= endDate) .Select(x => x.Id); } else { waybillSubQuery = changeOwnerWaybillRepository.SubQuery <ChangeOwnerWaybill>() .OneOf(x => x.Storage.Id, storageIds) .Where(x => x.AcceptanceDate >= startDate && x.AcceptanceDate <= endDate) .Select(x => x.Id); } return(changeOwnerWaybillRepository.Query <ChangeOwnerWaybillRow>() .PropertyIn(x => x.ChangeOwnerWaybill, waybillSubQuery) .Where(x => x.Article.Id == articleId) .ToList <ChangeOwnerWaybillRow>()); }
/// <summary> /// Получение списка входящих позиций по товару, МХ и организации, из которых доступно резервирование товаров /// </summary> /// <param name="article">Товар</param> /// <param name="storage">Место хранения</param> /// <param name="organization">Собственная организация</param> /// <param name="batch">Опциональный параметр для фильтра по партии</param> /// <param name="waybillType">Опциональный параметр для фильтра по типу накладной</param> /// <param name="startDate">Опциональный параметр для фильтра по дате (начало интервала)</param> /// <param name="endDate">Опциональный параметр для фильтра по дате (конец интервала)</param> /// <param name="number">Опциональный параметр для фильтра по номеру накладной</param> /// <returns>Отфильтрованный список позиций накладных с товаром article на складе storage от собственной организации organization</returns> public IEnumerable <IncomingWaybillRow> GetAvailableToReserveList(Article article, Storage storage, AccountOrganization organization, ReceiptWaybillRow batch = null, Guid?waybillRowId = null, WaybillType?waybillType = null, DateTime?startDate = null, DateTime?endDate = null, string number = null) { var result = new List <IncomingWaybillRow>(); var waybillRowArticleMovementSubquery = receiptWaybillRepository.SubQuery <WaybillRowArticleMovement>() .Where(x => x.DestinationWaybillRowId == waybillRowId).Select(x => x.SourceWaybillRowId); #region Приходы if (waybillType == null || waybillType == WaybillType.ReceiptWaybill) { var receiptWaybillSubQuery = receiptWaybillRepository.SubQuery <ReceiptWaybill>() .Where(x => x.ReceiptStorage.Id == storage.Id && x.AccountOrganization.Id == organization.Id && x.AcceptanceDate != null).Select(x => x.Id); var receiptWaybillRowsQuery = receiptWaybillRepository.Query <ReceiptWaybillRow>() .Where(x => x.Article.Id == article.Id) .PropertyIn(x => x.ReceiptWaybill, receiptWaybillSubQuery); if (waybillRowId != null) { var availableToReserveSubquery = receiptWaybillRepository.SubQuery <ReceiptWaybillRow>().Where(x => x.AvailableToReserveCount > 0).Select(x => x.Id); receiptWaybillRowsQuery.Or(x => x.PropertyIn(y => y.Id, waybillRowArticleMovementSubquery), x => x.PropertyIn(y => y.Id, availableToReserveSubquery)); } else { receiptWaybillRowsQuery.Where(x => x.AvailableToReserveCount > 0); } if (batch != null) { receiptWaybillRowsQuery.Where(x => x.Id == batch.Id); } if (startDate != null) { receiptWaybillSubQuery.Where(x => x.Date >= startDate); } if (endDate != null) { receiptWaybillSubQuery.Where(x => x.Date <= endDate); } if (number != null) { receiptWaybillSubQuery.Like(x => x.Number, number); } var receiptWaybillRows = receiptWaybillRowsQuery.ToList <ReceiptWaybillRow>(); foreach (var row in receiptWaybillRows) { result.Add(ConvertToIncomingWaybillRow(row)); } } #endregion #region Перемещения if (waybillType == null || waybillType == WaybillType.MovementWaybill) { var movementWaybillSubQuery = movementWaybillRepository.SubQuery <MovementWaybill>() .Where(x => x.RecipientStorage.Id == storage.Id && x.Recipient.Id == organization.Id && x.AcceptanceDate != null).Select(x => x.Id); var movementWaybillRowsQuery = movementWaybillRepository.Query <MovementWaybillRow>() .PropertyIn(x => x.MovementWaybill, movementWaybillSubQuery); if (waybillRowId != null) { var availableToReserveSubquery = receiptWaybillRepository.SubQuery <MovementWaybillRow>().Where(x => x.AvailableToReserveCount > 0).Select(x => x.Id); movementWaybillRowsQuery.Or(x => x.PropertyIn(y => y.Id, waybillRowArticleMovementSubquery), x => x.PropertyIn(y => y.Id, availableToReserveSubquery)); } else { movementWaybillRowsQuery.Where(x => x.AvailableToReserveCount > 0); } var batchSubQuery = movementWaybillRepository.SubQuery <ReceiptWaybillRow>().Where(x => x.Article.Id == article.Id).Select(x => x.Id); if (batch != null) { batchSubQuery.Where(x => x.Id == batch.Id); } if (number != null || startDate != null || endDate != null) { if (number != null) { movementWaybillSubQuery.Like(x => x.Number, number); } if (startDate != null) { movementWaybillSubQuery.Where(x => x.Date >= startDate); } if (endDate != null) { movementWaybillSubQuery.Where(x => x.Date <= endDate); } } var movementWaybillRows = movementWaybillRowsQuery.PropertyIn(x => x.ReceiptWaybillRow, batchSubQuery).ToList <MovementWaybillRow>(); foreach (var row in movementWaybillRows) { result.Add(ConvertToIncomingWaybillRow(row)); } } #endregion #region Смены собственника if (waybillType == null || waybillType == WaybillType.ChangeOwnerWaybill) { var changeOwnerWaybillSubQuery = changeOwnerWaybillRepository.SubQuery <ChangeOwnerWaybill>() .Where(x => x.Storage.Id == storage.Id && x.Recipient.Id == organization.Id && x.AcceptanceDate != null).Select(x => x.Id); var changeOwnerWaybillRowsQuery = changeOwnerWaybillRepository.Query <ChangeOwnerWaybillRow>() .PropertyIn(x => x.ChangeOwnerWaybill, changeOwnerWaybillSubQuery); if (waybillRowId != null) { var availableToReserveSubquery = receiptWaybillRepository.SubQuery <ChangeOwnerWaybillRow>().Where(x => x.AvailableToReserveCount > 0).Select(x => x.Id); changeOwnerWaybillRowsQuery.Or(x => x.PropertyIn(y => y.Id, waybillRowArticleMovementSubquery), x => x.PropertyIn(y => y.Id, availableToReserveSubquery)); } else { changeOwnerWaybillRowsQuery.Where(x => x.AvailableToReserveCount > 0); } var batchSubQuery = changeOwnerWaybillRepository.SubQuery <ReceiptWaybillRow>() .Where(x => x.Article.Id == article.Id).Select(x => x.Id); if (batch != null) { batchSubQuery.Where(x => x.Id == batch.Id); } if (number != null) { changeOwnerWaybillSubQuery.Like(x => x.Number, number); } if (startDate != null) { changeOwnerWaybillSubQuery.Where(x => x.Date >= startDate); } if (endDate != null) { changeOwnerWaybillSubQuery.Where(x => x.Date <= endDate); } var changeOwnerWaybillRows = changeOwnerWaybillRowsQuery.PropertyIn(x => x.ReceiptWaybillRow, batchSubQuery).ToList <ChangeOwnerWaybillRow>(); foreach (var row in changeOwnerWaybillRows) { result.Add(ConvertToIncomingWaybillRow(row)); } } #endregion #region Возврат от клиента if (waybillType == null || waybillType == WaybillType.ReturnFromClientWaybill) { var returnFromClientWaybillSubQuery = returnFromClientWaybillRepository.SubQuery <ReturnFromClientWaybill>() .Where(x => x.RecipientStorage.Id == storage.Id && x.Recipient.Id == organization.Id && x.AcceptanceDate != null).Select(x => x.Id); var returnFromClientWaybillRowsQuery = returnFromClientWaybillRepository.Query <ReturnFromClientWaybillRow>() .PropertyIn(x => x.ReturnFromClientWaybill, returnFromClientWaybillSubQuery); if (waybillRowId != null) { var availableToReserveSubquery = receiptWaybillRepository.SubQuery <ReturnFromClientWaybillRow>().Where(x => x.AvailableToReserveCount > 0).Select(x => x.Id); returnFromClientWaybillRowsQuery.Or(x => x.PropertyIn(y => y.Id, waybillRowArticleMovementSubquery), x => x.PropertyIn(y => y.Id, availableToReserveSubquery)); } else { returnFromClientWaybillRowsQuery.Where(x => x.AvailableToReserveCount > 0); } var batchSubQuery = returnFromClientWaybillRepository.SubQuery <ReceiptWaybillRow>().Where(x => x.Article.Id == article.Id).Select(x => x.Id); if (batch != null) { batchSubQuery.Where(x => x.Id == batch.Id); } if (number != null) { returnFromClientWaybillSubQuery.Like(x => x.Number, number); } if (startDate != null) { returnFromClientWaybillSubQuery.Where(x => x.Date >= startDate); } if (endDate != null) { returnFromClientWaybillSubQuery.Where(x => x.Date <= endDate); } var returnFromClientWaybillRows = returnFromClientWaybillRowsQuery .PropertyIn(x => x.ReceiptWaybillRow, batchSubQuery).ToList <ReturnFromClientWaybillRow>(); foreach (var row in returnFromClientWaybillRows) { result.Add(ConvertToIncomingWaybillRow(row)); } } #endregion return(result); }