/// <summary> /// Установка скидки исходя из выбранного основания скидки для строки счета без отгрузки на предоплату /// </summary> /// <param name="reason">Основание скидки</param> /// <param name="orderItem">Строка счета без отгрузки на предоплату</param> public void SetDiscountFromDiscountReasonForOrderItemWithoutShipment( DiscountReason reason, OrderWithoutShipmentForAdvancePaymentItem orderItem) { if (!CanSetDiscountForOrderWithoutShipment(reason, orderItem)) { return; } SetDiscount(reason, orderItem); }
private IQueryOver <OrderWithoutShipmentForAdvancePayment> GetOrdersWithoutShipmentForAdvancePaymentQuery(IUnitOfWork uow) { RetailOrderJournalNode resultAlias = null; OrderWithoutShipmentForAdvancePayment orderWSAPAlias = null; OrderWithoutShipmentForAdvancePaymentItem orderWSAPItemAlias = null; Counterparty counterpartyAlias = null; Employee authorAlias = null; Nomenclature nomenclatureAlias = null; var query = uow.Session.QueryOver(() => orderWSAPAlias) .Left.JoinAlias(o => o.Author, () => authorAlias); if (FilterViewModel.ViewTypes != ViewTypes.OrderWSFAP && FilterViewModel.ViewTypes != ViewTypes.All || FilterViewModel.RestrictStatus != null && FilterViewModel.RestrictStatus != OrderStatus.Closed || FilterViewModel.RestrictPaymentType != null || FilterViewModel.DeliveryPoint != null || FilterViewModel.RestrictOnlyService != null || FilterViewModel.RestrictOnlySelfDelivery != null || FilterViewModel.RestrictLessThreeHours == true || FilterViewModel.OrderPaymentStatus != null || FilterViewModel.Organisation != null || FilterViewModel.PaymentByCardFrom != null) { query.Where(o => o.Id == -1); } if (FilterViewModel != null && FilterViewModel.IsForRetail != null) { query.JoinEntityAlias( () => counterpartyAlias, () => counterpartyAlias.Id == orderWSAPAlias.Client.Id && counterpartyAlias.IsForRetail == FilterViewModel.IsForRetail, NHibernate.SqlCommand.JoinType.InnerJoin); } else { query.Left.JoinAlias(o => o.Client, () => counterpartyAlias); } if (FilterViewModel.RestrictStartDate != null) { query.Where(o => o.CreateDate >= FilterViewModel.RestrictStartDate); } if (FilterViewModel.RestrictEndDate != null) { query.Where(o => o.CreateDate <= FilterViewModel.RestrictEndDate.Value.AddDays(1).AddTicks(-1)); } if (FilterViewModel.RestrictCounterparty != null) { query.Where(o => o.Client == FilterViewModel.RestrictCounterparty); } var bottleCountSubquery = QueryOver.Of(() => orderWSAPItemAlias) .Where(() => orderWSAPAlias.Id == orderWSAPItemAlias.OrderWithoutDeliveryForAdvancePayment.Id) .JoinAlias(() => orderWSAPItemAlias.Nomenclature, () => nomenclatureAlias) .Where(() => nomenclatureAlias.Category == NomenclatureCategory.water && nomenclatureAlias.TareVolume == TareVolume.Vol19L) .Select(Projections.Sum(() => orderWSAPItemAlias.Count)); var orderSumSubquery = QueryOver.Of(() => orderWSAPItemAlias) .Where(() => orderWSAPItemAlias.OrderWithoutDeliveryForAdvancePayment.Id == orderWSAPAlias.Id) .Select(Projections.Sum( Projections.SqlFunction(new SQLFunctionTemplate(NHibernateUtil.Decimal, "(?1 * ?2 - ?3)"), NHibernateUtil.Decimal, new IProjection[] { Projections.Property(() => orderWSAPItemAlias.Price), Projections.Property(() => orderWSAPItemAlias.Count), Projections.Property(() => orderWSAPItemAlias.DiscountMoney) }) ) ); query.Where(GetSearchCriterion( () => orderWSAPAlias.Id, () => counterpartyAlias.Name, () => authorAlias.LastName )); var resultQuery = query .SelectList(list => list .Select(() => orderWSAPAlias.Id).WithAlias(() => resultAlias.Id) .Select(() => orderWSAPAlias.CreateDate).WithAlias(() => resultAlias.CreateDate) .Select(() => orderWSAPAlias.CreateDate).WithAlias(() => resultAlias.Date) .Select(() => authorAlias.LastName).WithAlias(() => resultAlias.AuthorLastName) .Select(() => authorAlias.Name).WithAlias(() => resultAlias.AuthorName) .Select(() => authorAlias.Patronymic).WithAlias(() => resultAlias.AuthorPatronymic) .Select(() => counterpartyAlias.Name).WithAlias(() => resultAlias.Counterparty) .SelectSubQuery(orderSumSubquery).WithAlias(() => resultAlias.Sum) .SelectSubQuery(bottleCountSubquery).WithAlias(() => resultAlias.BottleAmount) ) .OrderBy(x => x.CreateDate).Desc .SetTimeout(60) .TransformUsing(Transformers.AliasToBean <RetailOrderJournalNode <OrderWithoutShipmentForAdvancePayment> >()); return(resultQuery); }
/// <summary> /// Возможность установки скидки на строку счета без отгрузки на предоплату /// </summary> /// <param name="reason">Основание скидки</param> /// <param name="orderItem">Строка счета без отгрузки на предоплату</param> /// <returns>true/false</returns> private bool CanSetDiscountForOrderWithoutShipment(DiscountReason reason, OrderWithoutShipmentForAdvancePaymentItem orderItem) => IsApplicableDiscount(reason, orderItem.Nomenclature) && orderItem.Price * orderItem.Count != default(decimal);