Beispiel #1
0
        public List <ReturnsNode> GetReturnsToWarehouse(IUnitOfWork uow, int routeListId, NomenclatureCategory[] categories = null, int[] excludeNomenclatureIds = null)
        {
            Nomenclature               nomenclatureAlias      = null;
            ReturnsNode                resultAlias            = null;
            CarUnloadDocumentItem      carUnloadItemsAlias    = null;
            WarehouseMovementOperation movementOperationAlias = null;

            var returnableQuery = uow.Session.QueryOver <CarUnloadDocument>().Where(doc => doc.RouteList.Id == routeListId)
                                  .JoinAlias(doc => doc.Items, () => carUnloadItemsAlias)
                                  .JoinAlias(() => carUnloadItemsAlias.WarehouseMovementOperation, () => movementOperationAlias)
                                  .Where(Restrictions.IsNotNull(Projections.Property(() => movementOperationAlias.IncomingWarehouse)))
                                  .JoinAlias(() => movementOperationAlias.Nomenclature, () => nomenclatureAlias)
                                  .Where(() => !nomenclatureAlias.IsSerial);

            if (categories != null)
            {
                returnableQuery.Where(() => nomenclatureAlias.Category.IsIn(categories));
            }

            if (excludeNomenclatureIds != null)
            {
                returnableQuery.Where(() => !nomenclatureAlias.Id.IsIn(excludeNomenclatureIds));
            }

            var result = returnableQuery.SelectList(list => list
                                                    .SelectGroup(() => nomenclatureAlias.Id).WithAlias(() => resultAlias.NomenclatureId)
                                                    .Select(() => nomenclatureAlias.Name).WithAlias(() => resultAlias.Name)
                                                    .Select(() => false).WithAlias(() => resultAlias.Trackable)
                                                    .Select(() => nomenclatureAlias.Category).WithAlias(() => resultAlias.NomenclatureCategory)
                                                    .SelectSum(() => movementOperationAlias.Amount).WithAlias(() => resultAlias.Amount))
                         .TransformUsing(Transformers.AliasToBean <ReturnsNode>())
                         .List <ReturnsNode>();

            DomainHelper.FillPropertyByEntity <ReturnsNode, Nomenclature>(uow, result, x => x.NomenclatureId, (node, nom) => node.Nomenclature = nom);
            return(result.ToList());
        }
Beispiel #2
0
        /// <summary>
        /// Возвращает список товаров возвращенного на склад по номенклатурам
        /// </summary>
        public List <ReturnsNode> GetReturnsToWarehouse(IUnitOfWork uow, int routeListId, params int[] nomenclatureIds)
        {
            List <ReturnsNode>         result                 = new List <ReturnsNode>();
            Nomenclature               nomenclatureAlias      = null;
            ReturnsNode                resultAlias            = null;
            Equipment                  equipmentAlias         = null;
            CarUnloadDocument          carUnloadAlias         = null;
            CarUnloadDocumentItem      carUnloadItemsAlias    = null;
            WarehouseMovementOperation movementOperationAlias = null;

            var returnableQuery = QueryOver.Of <CarUnloadDocument>(() => carUnloadAlias)
                                  .JoinAlias(() => carUnloadAlias.Items, () => carUnloadItemsAlias)
                                  .JoinAlias(() => carUnloadItemsAlias.WarehouseMovementOperation, () => movementOperationAlias)
                                  .JoinAlias(() => movementOperationAlias.Nomenclature, () => nomenclatureAlias)
                                  .Where(Restrictions.IsNotNull(Projections.Property(() => movementOperationAlias.IncomingWarehouse)))
                                  .Where(() => !nomenclatureAlias.IsSerial)
                                  .Where(() => carUnloadAlias.RouteList.Id == routeListId)
                                  .Where(() => nomenclatureAlias.Id.IsIn(nomenclatureIds))
                                  .GetExecutableQueryOver(uow.Session);

            var returnableItems = returnableQuery.SelectList
                                  (
                list => list.SelectGroup(() => nomenclatureAlias.Id).WithAlias(() => resultAlias.NomenclatureId)
                .Select(() => nomenclatureAlias.Name).WithAlias(() => resultAlias.Name)
                .Select(() => false).WithAlias(() => resultAlias.Trackable)
                .Select(() => nomenclatureAlias.Category).WithAlias(() => resultAlias.NomenclatureCategory)
                .Select(() => carUnloadItemsAlias.DefectSource).WithAlias(() => resultAlias.DefectSource)
                .SelectSum(() => movementOperationAlias.Amount).WithAlias(() => resultAlias.Amount)
                                  )
                                  .TransformUsing(Transformers.AliasToBean <ReturnsNode>())
                                  .List <ReturnsNode>();

            var returnableQueryEquipment = uow.Session.QueryOver <CarUnloadDocument>(() => carUnloadAlias)
                                           .JoinAlias(() => carUnloadAlias.Items, () => carUnloadItemsAlias)
                                           .JoinAlias(() => carUnloadItemsAlias.WarehouseMovementOperation, () => movementOperationAlias)
                                           .JoinAlias(() => movementOperationAlias.Equipment, () => equipmentAlias)
                                           .JoinAlias(() => equipmentAlias.Nomenclature, () => nomenclatureAlias)
                                           .Where(Restrictions.IsNotNull(Projections.Property(() => movementOperationAlias.IncomingWarehouse)))
                                           .Where(() => carUnloadAlias.RouteList.Id == routeListId)
                                           .Where(() => nomenclatureAlias.Id.IsIn(nomenclatureIds))
            ;


            var returnableEquipment =
                returnableQueryEquipment.SelectList(list => list
                                                    .Select(() => equipmentAlias.Id).WithAlias(() => resultAlias.Id)
                                                    .SelectGroup(() => nomenclatureAlias.Id).WithAlias(() => resultAlias.NomenclatureId)
                                                    .Select(() => nomenclatureAlias.Name).WithAlias(() => resultAlias.Name)
                                                    .Select(() => nomenclatureAlias.IsSerial).WithAlias(() => resultAlias.Trackable)
                                                    .Select(() => nomenclatureAlias.Category).WithAlias(() => resultAlias.NomenclatureCategory)
                                                    .SelectSum(() => movementOperationAlias.Amount).WithAlias(() => resultAlias.Amount)
                                                    .Select(() => nomenclatureAlias.Type).WithAlias(() => resultAlias.EquipmentType)
                                                    .Select(() => carUnloadItemsAlias.DefectSource).WithAlias(() => resultAlias.DefectSource)
                                                    )
                .TransformUsing(Transformers.AliasToBean <ReturnsNode>())
                .List <ReturnsNode>();

            result.AddRange(returnableItems);
            result.AddRange(returnableEquipment);
            DomainHelper.FillPropertyByEntity <ReturnsNode, Nomenclature>(uow, result, x => x.NomenclatureId, (node, nom) => node.Nomenclature = nom);
            return(result);
        }