protected void RefreshSpinButtons()
        {
            int     bottlesMax           = BottlesRepository.GetBottlesAtDeliveryPoint(UoWGeneric, Entity.FromDeliveryPoint, Entity.TimeStamp);
            decimal depositsBottlesMax   = DepositRepository.GetDepositsAtDeliveryPoint(UoWGeneric, Entity.FromDeliveryPoint, DepositType.Bottles, Entity.TimeStamp);
            decimal depositsEquipmentMax = DepositRepository.GetDepositsAtDeliveryPoint(UoWGeneric, Entity.FromDeliveryPoint, DepositType.Equipment, Entity.TimeStamp);

            if (Entity.OutBottlesOperation != null)
            {
                spinBottles.Value = Entity.OutBottlesOperation.Returned != 0 ? Entity.OutBottlesOperation.Returned : (Entity.OutBottlesOperation.Delivered * -1);
            }
            else
            {
                spinBottles.Value = 0;
            }

            if (Entity.OutBottlesDepositOperation != null)
            {
                spinDepositsBottles.Value = (double)(Entity.OutBottlesDepositOperation.RefundDeposit != 0 ? Entity.OutBottlesDepositOperation.RefundDeposit : (Entity.OutBottlesDepositOperation.ReceivedDeposit * -1));
            }
            else
            {
                spinDepositsBottles.Value = 0;
            }

            if (Entity.OutEquipmentDepositOperation != null)
            {
                spinDepositsEquipment.Value = (double)(Entity.OutEquipmentDepositOperation.RefundDeposit != 0 ? Entity.OutEquipmentDepositOperation.RefundDeposit : (Entity.OutEquipmentDepositOperation.ReceivedDeposit * -1));
            }
            else
            {
                spinDepositsEquipment.Value = 0;
            }

            if (Math.Abs(bottlesMax) < Math.Abs(spinBottles.Value) ||
                Math.Abs(depositsBottlesMax) < Math.Abs((decimal)spinDepositsBottles.Value) ||
                Math.Abs(depositsEquipmentMax) < Math.Abs((decimal)spinDepositsEquipment.Value))
            {
                checkbuttonLock.Active = false;
            }

            spinBottles.Sensitive     = referenceDeliveryPointFrom.Subject != null;
            labelBottlesMax.LabelProp = bottlesMax.ToString();

            spinDepositsBottles.Sensitive     = referenceDeliveryPointFrom.Subject != null;
            labelDepositsBottlesMax.LabelProp = depositsBottlesMax.ToString();

            spinDepositsEquipment.Sensitive     = referenceDeliveryPointFrom.Subject != null;
            labelDepositsEquipmentMax.LabelProp = depositsEquipmentMax.ToString();

            if (checkbuttonLock.Active)
            {
                spinBottles.Adjustment.Upper = bottlesMax > 0 ? bottlesMax : 0;
                spinBottles.Adjustment.Lower = bottlesMax < 0 ? bottlesMax : 0;

                spinDepositsBottles.Adjustment.Upper = (double)(depositsBottlesMax > 0 ? depositsBottlesMax : 0);
                spinDepositsBottles.Adjustment.Lower = (double)(depositsBottlesMax < 0 ? depositsBottlesMax : 0);

                spinDepositsEquipment.Adjustment.Upper = (double)(depositsEquipmentMax > 0 ? depositsEquipmentMax : 0);
                spinDepositsEquipment.Adjustment.Lower = (double)(depositsEquipmentMax < 0 ? depositsEquipmentMax : 0);
            }
            else
            {
                spinBottles.Adjustment.Upper = 1000;
                spinBottles.Adjustment.Lower = -1000;

                spinDepositsBottles.Adjustment.Upper = 100000;
                spinDepositsBottles.Adjustment.Lower = -100000;

                spinDepositsEquipment.Adjustment.Upper = 100000;
                spinDepositsEquipment.Adjustment.Lower = -100000;
            }
        }
Пример #2
0
        public void Refresh()
        {
            DeliveryPoint = (InfoProvider as IDeliveryPointInfoProvider)?.DeliveryPoint;
            if (DeliveryPoint == null)
            {
                buttonSaveComment.Sensitive = false;
                return;
            }
            buttonSaveComment.Sensitive = true;
            labelAddress.Text           = DeliveryPoint.CompiledAddress;

            foreach (var child in PhonesTable.Children)
            {
                PhonesTable.Remove(child);
                child.Destroy();
            }

            uint rowsCount = Convert.ToUInt32(DeliveryPoint.Phones.Count) + 1;

            PhonesTable.Resize(rowsCount, 2);
            for (uint row = 0; row < rowsCount - 1; row++)
            {
                Label label = new Label();
                label.Selectable = true;
                label.Markup     = $"{DeliveryPoint.Phones[Convert.ToInt32(row)].LongText}";

                HandsetView handsetView = new HandsetView(DeliveryPoint.Phones[Convert.ToInt32(row)].DigitsNumber);

                PhonesTable.Attach(label, 0, 1, row, row + 1);
                PhonesTable.Attach(handsetView, 1, 2, row, row + 1);
            }

            Label labelAddPhone = new Label()
            {
                LabelProp = "Щёлкните чтоб\n добавить телефон-->"
            };

            PhonesTable.Attach(labelAddPhone, 0, 1, rowsCount - 1, rowsCount);

            Image addIcon = new Image();

            addIcon.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-add", IconSize.Menu);
            Button btn = new Button();

            btn.Image    = addIcon;
            btn.Clicked += OnBtnAddPhoneClicked;
            PhonesTable.Attach(btn, 1, 2, rowsCount - 1, rowsCount);
            PhonesTable.ShowAll();

            var bottlesAtDeliveryPoint  = BottlesRepository.GetBottlesAtDeliveryPoint(InfoProvider.UoW, DeliveryPoint);
            var bottlesAvgDeliveryPoint = DeliveryPointRepository.GetAvgBottlesOrdered(InfoProvider.UoW, DeliveryPoint, 5);

            lblBottlesQty.LabelProp = $"{bottlesAtDeliveryPoint} шт. (сред. зак.: {bottlesAvgDeliveryPoint:G3})";
            var bottlesAtCounterparty = BottlesRepository.GetBottlesAtCounterparty(InfoProvider.UoW, DeliveryPoint.Counterparty);

            debtByClientLabel.LabelProp = $"{bottlesAtCounterparty} шт.";
            var depositsAtDeliveryPoint = DepositRepository.GetDepositsAtDeliveryPoint(InfoProvider.UoW, DeliveryPoint, null);

            labelDeposits.LabelProp     = CurrencyWorks.GetShortCurrencyString(depositsAtDeliveryPoint);
            textviewComment.Buffer.Text = DeliveryPoint.Comment;

            var currentOrders = OrderRepository.GetLatestOrdersForDeliveryPoint(InfoProvider.UoW, DeliveryPoint, 5);

            ytreeLastOrders.SetItemsSource <Order>(currentOrders);
            vboxLastOrders.Visible = currentOrders.Any();

            table2.ShowAll();
        }
        public override bool IsValidForOrder(Order order)
        {
            if (!IsForZeroDebt)
            {
                return(true);
            }

            var forfeitId = new BaseParametersProvider().GetForfeitId();

            BottlesRepository bottlesRepository = new BottlesRepository();

            BottlesMovementOperation bottlesMovementAlias = null;
            Order orderAlias = null;

            //Долг клиента
            var counterpartyDebtQuery = order.UoW.Session.QueryOver <BottlesMovementOperation>(() => bottlesMovementAlias)
                                        .Where(() => bottlesMovementAlias.DeliveryPoint == null)
                                        .Where(() => bottlesMovementAlias.Counterparty.Id == order.Client.Id)
                                        .Select(
                Projections.SqlFunction(new SQLFunctionTemplate(NHibernateUtil.Int32, "( ?2 - ?1 )"),
                                        NHibernateUtil.Int32, new IProjection[] {
                Projections.Sum(() => bottlesMovementAlias.Returned),
                Projections.Sum(() => bottlesMovementAlias.Delivered)
            }
                                        )).SingleOrDefault <int>();

            if (counterpartyDebtQuery != 0)
            {
                return(false);
            }

            //Долг по точкам доставки
            foreach (var deliveryPoint in order.Client.DeliveryPoints)
            {
                if (bottlesRepository.GetBottlesAtDeliveryPoint(order.UoW, deliveryPoint) != 0)
                {
                    return(false);
                }
            }

            //Возврат бутылей и(ничего или возврат залога или неустойка)
            var orders1 = order.UoW.Session.QueryOver(() => orderAlias)
                          .Where(() => orderAlias.Client.Id == order.Client.Id)
                          .Where(() => orderAlias.OrderStatus == OrderStatus.Closed)
                          .Where(() => orderAlias.BottlesReturn != 0)
                          .List <Order>();

            if (orders1.Count == 0)
            {
                return(false);
            }

            var orders2 = new List <Order>();

            foreach (var o in orders1)
            {
                if (o.OrderDepositItems != null && o.OrderItems == null)
                {
                    orders2.Add(o);
                }
                if (o.OrderItems.All(i => i.Nomenclature.Id == forfeitId))
                {
                    orders2.Add(o);
                }
                if (o.OrderItems == null)
                {
                    orders2.Add(o);
                }
            }

            if (orders2.Count == 0)
            {
                return(false);
            }

            //Ввод остатков
            foreach (var o in orders2)
            {
                if (o.DeliveryPoint == null)
                {
                    continue;
                }
                if (o.DeliveryPoint.HaveResidue.HasValue)
                {
                    if (!o.DeliveryPoint.HaveResidue.Value)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }