/// <summary> /// Получение списка накладных по МХ, кураторам и клиентам в диапозоне дат /// </summary> /// <param name="logicState">Статус накладной</param> /// <param name="expenditureWaybillSubQuery">Подзапрос на видимые накладные</param> /// <param name="storageIdList">Список кодов МХ</param> /// <param name="storageSubQuery">Подзапрос на видимые МХ</param> /// <param name="curatorIdList">Список кодов кураторов</param> /// <param name="curatorSubQuery">Подзапрос на видимых кураторов</param> /// <param name="clientIdList">Список кодов выбранных клиентов. (Подзапроса нет, т.к. они или видны все или не видны вовсе)</param> /// <param name="startDate">Начало интервала</param> /// <param name="endDate">Конец интервала</param> /// <param name="dateType">Тип даты</param> /// <param name="priorToDate">Параметр "До даты"</param> /// <returns>Список накладных</returns> public IEnumerable <ExpenditureWaybill> GetList(ExpenditureWaybillLogicState logicState, ISubCriteria <ExpenditureWaybill> expenditureWaybillSubQuery, IEnumerable <short> storageIdList, ISubCriteria <Storage> storageSubQuery, IEnumerable <int> curatorIdList, ISubCriteria <User> curatorSubQuery, IEnumerable <int> clientIdList, DateTime startDate, DateTime endDate, int pageNumber, WaybillDateType dateType, DateTime?priorToDate) { var crit = Query <ExpenditureWaybill>(); GetDateTypeCriteria(startDate, endDate, dateType, ref crit); GetLogicStateCriteria(logicState, dateType, priorToDate, ref crit); crit.PropertyIn(x => x.Id, expenditureWaybillSubQuery) .PropertyIn(x => x.SenderStorage.Id, storageSubQuery) .PropertyIn(x => x.Curator.Id, curatorSubQuery) .OrderByAsc(x => x.Id); if (dateType != WaybillDateType.Date) { var stateList = GetStateListForExpenditureWaybill(logicState); crit.OneOf(x => x.State, stateList); } if (storageIdList != null) { crit.OneOf(x => x.SenderStorage.Id, storageIdList); } if (curatorIdList != null) { crit.OneOf(x => x.Curator.Id, curatorIdList); } if (clientIdList != null) { // т.к. если на прямую написать .Oneof(x => x.Deal.Client.Id, clientIdList), то он не может разрешиться путь "Deal.Client.Id" var sq = SubQuery <Deal>() .OneOf(x => x.Client.Id, clientIdList) .Select(x => x.Id); crit.PropertyIn(x => x.Deal.Id, sq); } return(crit.SetFirstResult(100 * (pageNumber - 1)).SetMaxResults(100).ToList <ExpenditureWaybill>()); }
/// <summary> /// Добавить в запрос условие соответсвующее полю "До даты" /// </summary> private void GetLogicStateCriteria(ExpenditureWaybillLogicState logicState, WaybillDateType dateType, DateTime?priorToDate, ref ICriteria <ExpenditureWaybill> crit) { if (dateType != WaybillDateType.Date) { return; } switch (logicState) { case ExpenditureWaybillLogicState.All: break; case ExpenditureWaybillLogicState.Accepted: crit.Where(x => x.AcceptanceDate <= priorToDate); break; case ExpenditureWaybillLogicState.NotAccepted: crit.Where(x => x.AcceptanceDate > priorToDate || x.AcceptanceDate == null); break; case ExpenditureWaybillLogicState.AcceptedNotShipped: crit.Where(x => x.AcceptanceDate <= priorToDate && (x.ShippingDate > priorToDate || x.ShippingDate == null)); break; case ExpenditureWaybillLogicState.NotShipped: crit.Where(x => x.ShippingDate > priorToDate || x.ShippingDate == null); break; case ExpenditureWaybillLogicState.Shipped: crit.Where(x => x.ShippingDate <= priorToDate); break; default: throw new Exception("Непредусмотренный статус накладной."); } }
/// <summary> /// Получение параметров фильтрации для подгрузки накладных реализации /// </summary> private IEnumerable <ExpenditureWaybillState> GetStateListForExpenditureWaybill(ExpenditureWaybillLogicState state) { var result = new List <ExpenditureWaybillState>(); switch (state) { case ExpenditureWaybillLogicState.All: result.Add(ExpenditureWaybillState.ArticlePending); result.Add(ExpenditureWaybillState.ConflictsInArticle); result.Add(ExpenditureWaybillState.Draft); result.Add(ExpenditureWaybillState.ReadyToAccept); result.Add(ExpenditureWaybillState.ReadyToShip); result.Add(ExpenditureWaybillState.ShippedBySender); break; case ExpenditureWaybillLogicState.Accepted: result.Add(ExpenditureWaybillState.ArticlePending); result.Add(ExpenditureWaybillState.ConflictsInArticle); result.Add(ExpenditureWaybillState.ReadyToShip); result.Add(ExpenditureWaybillState.ShippedBySender); break; case ExpenditureWaybillLogicState.NotAccepted: result.Add(ExpenditureWaybillState.Draft); result.Add(ExpenditureWaybillState.ReadyToAccept); break; case ExpenditureWaybillLogicState.AcceptedNotShipped: result.Add(ExpenditureWaybillState.ArticlePending); result.Add(ExpenditureWaybillState.ConflictsInArticle); result.Add(ExpenditureWaybillState.ReadyToShip); break; case ExpenditureWaybillLogicState.NotShipped: result.Add(ExpenditureWaybillState.ArticlePending); result.Add(ExpenditureWaybillState.ConflictsInArticle); result.Add(ExpenditureWaybillState.Draft); result.Add(ExpenditureWaybillState.ReadyToAccept); result.Add(ExpenditureWaybillState.ReadyToShip); break; case ExpenditureWaybillLogicState.Shipped: result.Add(ExpenditureWaybillState.ShippedBySender); break; } return(result); }