Ejemplo n.º 1
0
        private string GetSegment()
        {
            //актуальный список сфер деятельности
            var actualActivities = new List <ActivityFieldEnum>
            {
                ActivityFieldEnum.ElectricityDistribution,
                ActivityFieldEnum.ElectricityTransmission,
                ActivityFieldEnum.ElectricityGeneration,
                ActivityFieldEnum.Fuel,
                ActivityFieldEnum.RailWay,
                ActivityFieldEnum.IndustrialEnterprise
            };

            //сегмент по владельцам объекта
            var owner = SalesUnits.First().Facility.OwnerCompany;

            do
            {
                var activityField = owner.ActivityFilds.FirstOrDefault(x => actualActivities.Contains(x.ActivityFieldEnum));
                if (activityField != null)
                {
                    return(activityField.Name);
                }
                owner = owner.ParentCompany;
            } while (owner != null);

            return("Промышленное предприятие");
        }
Ejemplo n.º 2
0
        //private Company GetFacilityOwnerHead()
        //{
        //    var head = FacilityOwners;
        //    while (head.ParentCompany != null)
        //    {
        //        head = head.ParentCompany;
        //    }
        //    return head;
        //}

        private Company GetTenderWinner()
        {
            var tenders = _tenders.Where(x => Equals(SalesUnits.First().Project.Id, x.Project.Id)).ToList();

            if (!tenders.Any())
            {
                return(null);
            }

            //поставщик
            var supplier = tenders
                           .Where(x => x.Types.Select(t => t.Type).Contains(TenderTypeEnum.ToSupply))
                           .OrderBy(x => x.DateClose)
                           .LastOrDefault()?.Winner;

            if (supplier != null)
            {
                return(supplier);
            }

            //подрядчик
            var worker = tenders
                         .Where(x => x.Types.Select(t => t.Type).Contains(TenderTypeEnum.ToWork))
                         .OrderBy(x => x.DateClose)
                         .LastOrDefault()?.Winner;

            return(worker);
        }
Ejemplo n.º 3
0
        private string GetOrderInTakeStatus()
        {
            var salesUnit = SalesUnits.First();

            if (salesUnit.IsLoosen)
            {
                return("14 - Проиграно другому производителю");
            }

            if (salesUnit.RealizationDateCalculated < DateTime.Today)
            {
                return("0 - Продукт реализован");
            }

            if (salesUnit.StartProductionConditionsDoneDate.HasValue &&
                salesUnit.StartProductionConditionsDoneDate.Value <= DateTime.Today)
            {
                return("1 - Условие на запуск производства исполнено");
            }

            if (salesUnit.Specification != null)
            {
                return(salesUnit.Specification.Date <= DateTime.Today
                    ? "2 - Контракт подписан"
                    : "3 - Контракт на оформлении");
            }

            if (salesUnit.Producer != null && salesUnit.Producer.Id == GlobalAppProperties.Actual.OurCompany.Id)
            {
                return("4 - Большая вероятность реализации");
            }

            return("7 - В проработке");
        }
Ejemplo n.º 4
0
        public MarketReportUnit(IEnumerable <SalesUnit> salesUnits, IEnumerable <Tender> tenders)
        {
            SalesUnits = salesUnits.ToList();
            var salesUnit = SalesUnits.First();

            var tenders1 = tenders.ToList();

            ProjectName = salesUnit.Project.Name;

            Order = salesUnit.Order?.ToString();

            Producer = salesUnit.Producer?.ToString();

            Voltage = salesUnit.Product.GetVoltageParameter()?.Value;

            Builder      = tenders1.GetWinner(TenderTypeEnum.ToWork)?.ToString();
            ProjectMaker = tenders1.GetWinner(TenderTypeEnum.ToProject)?.ToString();
            Supplier     = tenders1.GetWinner(TenderTypeEnum.ToSupply)?.ToString();

            var owners = new List <Company> {
                salesUnit.Facility.OwnerCompany
            };

            owners.AddRange(salesUnit.Facility.OwnerCompany.ParentCompanies().ToList());
            FacilityOwners = owners.ToStringEnum();
            var contragent = salesUnit.Specification?.Contract.Contragent ?? salesUnit.Facility.OwnerCompany;

            Contragent = contragent?.ToString();
            Facility   = salesUnit.Facility.ToString();
            var region = salesUnit.Facility.GetRegion();

            Region          = region?.Name;
            District        = region?.District.Name;
            Segment         = GetSegment();
            ProductType     = salesUnit.Product.ProductType.Name;
            Designation     = salesUnit.Product.Designation;
            ProductCategory = GetProductCategory(salesUnit.Product);
            Amount          = SalesUnits.Count;
            Status          = GetStatus(salesUnit);
            Cost            = salesUnit.Cost;

            var manager = salesUnit.Project.Manager.Employee;

            Manager = $"{manager.Person.Surname} {manager.Person.Name} {manager.Person.Patronymic}";

            RealizationDateContract = salesUnit.EndProductionDateByContractCalculated;

            OrderInTakeDate         = salesUnit.OrderInTakeDate;
            ShipmentDate            = salesUnit.ShipmentDateCalculated;
            DeliveryDate            = salesUnit.DeliveryDateCalculated;
            RealizationDate         = salesUnit.RealizationDateCalculated;
            RealizationDateRequared = salesUnit.DeliveryDateExpected;
        }
Ejemplo n.º 5
0
        //private void SetProperties(SalesUnit salesUnit)
        //{
        //    var properties = salesUnit.GetType().GetProperties().Where(x => x.CanWrite);
        //    foreach (var property in properties)
        //    {
        //        var value = property.GetValue(salesUnit);
        //        this.GetType().GetProperty(property.Name).SetValue(this, value);
        //    }
        //}

        private string GetContragentType(Company contragent)
        {
            if (Contragent == null)
            {
                return("Нет данных");
            }

            var salesUnit = SalesUnits.First();

            if (Equals(salesUnit.Facility.OwnerCompany, contragent) ||
                salesUnit.Facility.OwnerCompany.ParentCompanies().Contains(contragent))
            {
                return("Конечный заказчик");
            }

            if (_tenders.FirstOrDefault(x => Equals(x.Winner, contragent)) != null)
            {
                return("Подрядчик");
            }

            return("Посредник");
        }
Ejemplo n.º 6
0
        public ProjectUnitsGroup(IEnumerable <SalesUnit> salesUnits, ProjectItem projectItem)
        {
            ProjectItem = projectItem;
            if (salesUnits == null)
            {
                throw new ArgumentNullException(nameof(salesUnits));
            }
            if (!salesUnits.Any())
            {
                throw new ArgumentException($"{nameof(salesUnits)} - аргумент без членов");
            }

            SalesUnits = salesUnits.ToList();

            var salesUnit = SalesUnits.First();

            Facility        = salesUnit.Facility;
            Product         = salesUnit.Product;
            Amount          = SalesUnits.Count;
            Cost            = salesUnit.Cost;
            Total           = Amount * Cost;
            OrderInTakeDate = salesUnit.OrderInTakeDate;
            ShipmentDate    = salesUnit.ShipmentDateCalculated;
        }
Ejemplo n.º 7
0
        public SalesReportUnit(
            IEnumerable <SalesUnit> salesUnits,
            IEnumerable <Tender> tenders,
            IEnumerable <CountryUnion> countryUnions,
            PriceCalculationItem priceCalculationItem)
        {
            SalesUnits = salesUnits.ToList();
            var salesUnit = SalesUnits.First();

            //SetProperties(salesUnit);

            _tenders       = tenders.ToList();
            _countryUnions = countryUnions.ToList();

            Order          = salesUnit.Order?.ToString();
            OrderPositions = SalesUnits.Select(x => x.OrderPosition).GetOrderPositions();

            ProductionTerm = salesUnit.ProductionTerm;
            var owners = new List <Company> {
                salesUnit.Facility.OwnerCompany
            };

            owners.AddRange(salesUnit.Facility.OwnerCompany.ParentCompanies().ToList());
            FacilityOwners = owners.ToStringEnum();
            var contragent = salesUnit.Specification?.Contract.Contragent ?? GetTenderWinner() ?? salesUnit.Facility.OwnerCompany;

            Contragent     = contragent.ToString();
            ContragentType = GetContragentType(contragent);
            Facility       = salesUnit.Facility.ToString();
            var region = salesUnit.Facility.GetRegion();

            Country = region?.District.Country;
            if (Country != null)
            {
                IsExport = Country.Name == "Россия" ? "РФ" : Country.Name;
                if (Country.Name == "Россия")
                {
                    RfSng = "РФ";
                }
                else if (GetCountryUnions().Any(x => x.Name == "СНГ"))
                {
                    RfSng = "СНГ";
                }
                else
                {
                    RfSng = "ДЗ";
                }
            }
            District = region?.District.Name;
            Segment  = SegmentConverter(GetSegment());
            if (RfSng != "РФ")
            {
                Segment = "Экспорт";
            }
            ProductType     = salesUnit.Product.ProductType.Name;
            Designation     = salesUnit.Product.Designation;
            ProductCategory = GetProductCategory(salesUnit.Product);
            Amount          = SalesUnits.Count;
            Status          = GetStatus();
            Vat             = salesUnit.Vat / 100.0 + 1.0;
            Cost            = salesUnit.Cost;
            var costDelivery = SalesUnits.Select(unit => unit.CostDelivery).Where(x => x.HasValue).Sum(x => x.Value);

            CostDelivery = -1.0 * costDelivery;

            var price = GlobalAppProperties.PriceService.GetPrice(salesUnit, salesUnit.OrderInTakeDate, true);

            Price = salesUnit.Price ?? price.SumPriceTotal;

            FixedCost = -1.0 * price.SumFixedTotal * Amount;
            //FixedCostAndDelivery = CostDelivery.HasValue ? CostDelivery.Value + FixedCost : FixedCost;

            var manager = salesUnit.Project.Manager.Employee;

            Manager = $"{manager.Person.Surname}";

            if (salesUnit.Specification != null)
            {
                var specification = salesUnit.Specification;
                SpecificationNumber = specification.Number;
                SpecificationDate   = specification.Date;

                ContractNumber = specification.Contract.Number;
                ContractDate   = specification.Contract.Date;
                ContractYear   = ContractDate.Value.Year;
            }

            RealizationDateContract = salesUnit.EndProductionDateByContractCalculated;

            OrderInTakeDate         = salesUnit.OrderInTakeDate;
            StartProductionDate     = salesUnit.StartProductionDateCalculated;
            ShipmentDate            = salesUnit.ShipmentDateCalculated;
            RealizationDate         = salesUnit.RealizationDateCalculated;
            RealizationDateRequared = salesUnit.DeliveryDateExpected;

            PaymentConditionSet = salesUnit.PaymentConditionSet;
            SetPaymentsConditions(salesUnit, PaymentConditionPointEnum.ProductionStart, ref _daysToStartProduction, ref _paymentStartProduction, ref _datePaymentStartProduction, ref _paymentTypeStartProduction);
            SetPaymentsConditions(salesUnit, PaymentConditionPointEnum.ProductionEnd, ref _daysToEndProduction, ref _paymentEndProduction, ref _datePaymentEndProduction, ref _paymentTypeEndProduction);
            SetPaymentsConditions(salesUnit, PaymentConditionPointEnum.Shipment, ref _daysToShipping, ref _paymentShipping, ref _datePaymentShipping, ref _paymentTypeShipping);
            SetPaymentsConditions(salesUnit, PaymentConditionPointEnum.Delivery, ref _daysToDelivery, ref _paymentDelivery, ref _datePaymentDelivery, ref _paymentTypeDelivery);


            DeliveryType = -1 * CostDelivery > 0  ? "Доставка" : "Самовывоз";

            DeliveryAddress = salesUnit.GetDeliveryAddressString();

            PickingDate = salesUnit.PickingDate;

            ProductsIncluded = SalesUnits
                               .SelectMany(x => x.ProductsIncluded)
                               .Distinct()
                               .OrderBy(x => x.Product.Designation)
                               .ToStringEnum();

            PaymentsActual = salesUnits.SelectMany(x => x.PaymentsActual).ToStringEnum();

            TceInfo = priceCalculationItem?.ToString();

            IsolationMaterial = salesUnit.Product.ProductBlock.Parameters
                                .FirstOrDefault(x => Equals(x.ParameterGroup, GlobalAppProperties.Actual.IsolationMaterialGroup))?.Value;
            IsolationDpu = salesUnit.Product.ProductBlock.Parameters
                           .FirstOrDefault(x => Equals(x.ParameterGroup, GlobalAppProperties.Actual.IsolationDpuGroup))?.Value;
            IsolationColor = salesUnit.Product.ProductBlock.Parameters
                             .FirstOrDefault(x => Equals(x.ParameterGroup, GlobalAppProperties.Actual.IsolationColorGroup))?.Value;

            if (salesUnit.IsLoosen)
            {
                TenderStatus = string.IsNullOrEmpty(Order) ? "Тендер проигран" : "Заказ аннулирован";
            }
            else if (OrderInTakeDate < DateTime.Today)
            {
                TenderStatus = $"Факт ОИТ {OrderInTakeDate.Year}";
            }
            else if (OrderInTakeDate.Year > DateTime.Today.Year)
            {
                TenderStatus = $"Закупка или тендер перенесены на {OrderInTakeDate.Year} год";
            }

            Producer = salesUnit.Producer?.ToString() ?? string.Empty;

            Comment = salesUnit.Comment;

            TenderLink = _tenders.Where(x => !string.IsNullOrEmpty(x.Link)).OrderBy(x => x.DateClose).LastOrDefault()?.Link;
        }
Ejemplo n.º 8
0
        public TceReportUnit(TechnicalRequrementsTask technicalRequrementsTask, TechnicalRequrements technicalRequrements, IEnumerable <Tender> tenders)
        {
            SalesUnits = technicalRequrements.SalesUnits.ToList();
            var salesUnit = SalesUnits.First();

            _tenders = tenders.ToList();

            OrderInTakeDate = salesUnit.OrderInTakeDate;

            if (technicalRequrementsTask.PriceCalculations.Any())
            {
                TceNumber = GetTceNumber(technicalRequrementsTask);
            }

            TaskOpenDate = technicalRequrementsTask.Start?.Date ?? DateTime.Today.AddYears(10);

            TaskStartDate  = technicalRequrementsTask.Start;
            TaskFinishDate = technicalRequrementsTask.Finish;

            Order = salesUnit.Order?.ToString();

            OrderPositions = SalesUnits.Select(unit => unit.OrderPosition).GetOrderPositions();

            var owners = new List <Company> {
                salesUnit.Facility.OwnerCompany
            };

            owners.AddRange(salesUnit.Facility.OwnerCompany.ParentCompanies().ToList());
            FacilityOwners = owners.ToStringEnum();

            var contragent = salesUnit.Specification?.Contract.Contragent ?? GetTenderWinner() ?? salesUnit.Facility.OwnerCompany;

            Contragent = contragent.ToString();

            Facility = salesUnit.Facility.ToString();

            Product = $"{salesUnit.Product.ProductType} {salesUnit.Product.Designation}";

            Amount = SalesUnits.Count;

            this.OrderInTakeStatus = GetOrderInTakeStatus();

            if (TaskStartDate.HasValue)
            {
                var dates = Offers
                            .Where(offer => offer.Project.Id == salesUnit.Project.Id)
                            .Select(offer => offer.Date)
                            .Where(x => x >= this.TaskStartDate.Value)
                            .ToList();

                if (dates.Any())
                {
                    FirstOfferDate = dates.Min();
                }

                if (FirstOfferDate.HasValue)
                {
                    Term = (FirstOfferDate.Value - TaskStartDate.Value).Days;
                }
            }


            if (salesUnit.IsLoosen)
            {
                CostOfWinner = salesUnit.Cost;
                Cost         = Math.Round(CostOfWinner.Value * (1.0 + _random.Next(5, 20) / 100.0), MidpointRounding.ToEven);

                if (salesUnit.ProductionTerm < GlobalAppProperties.Actual.StandartTermFromStartToEndProduction)
                {
                    LossReason = "Сроки производства";
                }
            }
            else
            {
                Cost = salesUnit.Cost;
            }

            Manager = salesUnit.Project.Manager?.Employee?.Person.ToString();

            BackManager = technicalRequrementsTask.BackManager?.Employee?.Person.ToString();

            RealizationDate = salesUnit.RealizationDateCalculated;


            if (salesUnit.IsLoosen)
            {
                CommonStatus = string.IsNullOrEmpty(Order) ? "Конкурс проигран" : "Заказ аннулирован";
            }
            else if (OrderInTakeDate < DateTime.Today)
            {
                CommonStatus = $"Факт ОИТ {OrderInTakeDate.Year}";
            }
            else if (OrderInTakeDate.Year > DateTime.Today.Year)
            {
                CommonStatus = $"Закупка или тендер перенесены на {OrderInTakeDate.Year} год";
            }

            Producer       = salesUnit.Producer?.ToString() ?? string.Empty;
            ProducerWinner = Producer;
        }