Beispiel #1
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;
        }
Beispiel #2
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;
        }