Exemplo n.º 1
0
        public static void FillBayDeals(IObjectSpace os, TrwSubject trw_subj, TrwSubjectImportDealParameters parms)
        {
            IList <crmContractDeal> deals = GetDeals(trw_subj, DealInfoDealType.DEAL_INFO_EXPENDITURE, parms);

            foreach (crmContractDeal deal in deals)
            {
                TrwSubjectDealBay subj_deal = trw_subj.DealsBay.FirstOrDefault(x => x.Deal == deal);
                if (subj_deal == null)
                {
                    subj_deal = os.CreateObject <TrwSubjectDealBay>();
                    trw_subj.DealsBay.Add(subj_deal);
                    subj_deal.DealType   = TrwSubjectDealType.TRW_SUBJECT_DEAL_REAL;
                    subj_deal.Deal       = deal;
                    subj_deal.DealBudget = null;
                }
            }
            if (parms.CreateOtherDeal)
            {
                TrwSubjectDealBay bay_other = trw_subj.DealsBay.FirstOrDefault(x => x.DealType == TrwSubjectDealType.TRW_SUBJECT_DEAL_CONS_OTHER);
                if (bay_other == null)
                {
                    bay_other = os.CreateObject <TrwSubjectDealBay>();
                    trw_subj.DealsBay.Add(bay_other);
                    bay_other.DealType       = TrwSubjectDealType.TRW_SUBJECT_DEAL_CONS_OTHER;
                    bay_other.PersonInternal = TrwSettings.GetInstance(os).PersonOtherBay;
                }
            }
        }
Exemplo n.º 2
0
        public static IList <crmContractDeal> GetDeals2(TrwSubject trw_subj, DealInfoDealType deal_type, TrwSubjectImportDealParameters parms)
        {
            IDictionary <crmContractDeal, Decimal> dict = new Dictionary <crmContractDeal, Decimal>();

            foreach (fmCSubject subj in trw_subj.Subjects)
            {
                foreach (fmCSubject.DealInfo info in subj.DealInfos)
                {
                    if (info.DealType != deal_type ||
                        info.Subject != trw_subj.Subject ||
                        info.Year != trw_subj.Period.Year ||
                        info.NomType != DealInfoNomType.DEAL_INFO_DELIVERY)
                    {
                        continue;
                    }
                    if (dict.ContainsKey(info.Deal))
                    {
                        dict[info.Deal] += info.DeliverySummCost;
                    }
                    else
                    {
                        dict[info.Deal] = info.DeliverySummCost;
                    }
                }
            }
            return(new List <crmContractDeal>(dict.Keys));
        }
Exemplo n.º 3
0
 public static void RefreshSubjectDeals(IObjectSpace os, TrwSubject trw_subj)
 {
     foreach (TrwSubjectDealSale trw_deal in trw_subj.DealsSale)
     {
         TrwSubjectDealLogic.RefreshDeal(os, trw_deal);
     }
     foreach (TrwSubjectDealBay trw_deal in trw_subj.DealsBay)
     {
         TrwSubjectDealLogic.RefreshDeal(os, trw_deal);
     }
 }
Exemplo n.º 4
0
        private void ImportBayDealsAction_Execute(object sender, PopupWindowShowActionExecuteEventArgs e)
        {
            TrwSubject trw_subj = e.CurrentObject as TrwSubject;

            if (trw_subj == null)
            {
                return;
            }
            using (IObjectSpace os = ObjectSpace.CreateNestedObjectSpace()) {
                trw_subj = os.GetObject <TrwSubject>(trw_subj);
                TrwSubjectLogic.FillBayDeals(os, trw_subj, _ImportActionParameters);
                os.CommitChanges();
            }
            _ImportActionParameters = null;
        }
Exemplo n.º 5
0
        public static IList <crmContractDeal> GetDeals(TrwSubject trw_subj, DealInfoDealType deal_type, TrwSubjectImportDealParameters parms)
        {
            IDictionary <crmContractDeal, Decimal> dict = new Dictionary <crmContractDeal, Decimal>();

            foreach (fmCSubject subj in trw_subj.Subjects)
            {
                foreach (fmCSubject.DealInfo info in subj.DealInfos)
                {
                    if (info.DealType != deal_type ||
                        info.Subject != trw_subj.Subject ||
                        info.Year != trw_subj.Period.Year ||
                        info.NomType != DealInfoNomType.DEAL_INFO_DELIVERY)
                    {
                        continue;
                    }
                    if (dict.ContainsKey(info.Deal))
                    {
                        dict[info.Deal] += info.DeliverySummCost;
                    }
                    else
                    {
                        dict[info.Deal] = info.DeliverySummCost;
                    }
                }
            }
            IOrderedEnumerable <crmContractDeal> deals = dict.Keys.OrderBy(x => - dict[x]);
            IList <crmContractDeal> result             = new List <crmContractDeal>(parms.MaxCount);
            Decimal all_summ      = dict.Values.Sum();
            Decimal current_summ  = 0;
            Int32   current_count = 0;

            foreach (crmContractDeal deal in deals)
            {
                current_summ += dict[deal];
                current_count++;
                result.Add(deal);
                if (parms.MaxCount > 0 && current_count >= parms.MaxCount)
                {
                    break;
                }
                if (parms.VolumePercent > 0 && current_summ / all_summ >= parms.VolumePercent)
                {
                    break;
                }
            }
            return(result);
        }
Exemplo n.º 6
0
        public static void FillBayDeals2(IObjectSpace os, TrwSubject trw_subj, TrwSubjectImportDealParameters parms)
        {
            IList <crmContractDeal> deals = GetDeals2(trw_subj, DealInfoDealType.DEAL_INFO_EXPENDITURE, parms);
            IDictionary <crmCPerson, TrwSubjectDealBay> pers_deal = new Dictionary <crmCPerson, TrwSubjectDealBay>();
            IList <crmCPerson> pers_list = new List <crmCPerson>();

            foreach (crmCParty party in trw_subj.Period.CorporationPartys)
            {
                if (!pers_list.Contains(party.Person))
                {
                    pers_list.Add(party.Person);
                }
            }
            foreach (crmContractDeal deal in deals)
            {
                if (!pers_list.Contains(deal.Supplier.Person))
                {
                    continue;
                }
                if (pers_deal.ContainsKey(deal.Supplier.Person))
                {
                    continue;
                }
                TrwSubjectDealBay subj_deal = os.CreateObject <TrwSubjectDealBay>();
                trw_subj.DealsBay.Add(subj_deal);
                subj_deal.DealType              = TrwSubjectDealType.TRW_SUBJECT_DEAL_CONS_PARTNER;
                subj_deal.PersonInternal        = deal.Supplier.Person;
                pers_deal[deal.Supplier.Person] = subj_deal;
//                subj_deal.DealBudget = null;
            }
            if (parms.CreateOtherDeal)
            {
                TrwSubjectDealBay bay_other = trw_subj.DealsBay.FirstOrDefault(x => x.DealType == TrwSubjectDealType.TRW_SUBJECT_DEAL_CONS_OTHER);
                if (bay_other == null)
                {
                    bay_other = os.CreateObject <TrwSubjectDealBay>();
                    trw_subj.DealsBay.Add(bay_other);
                    bay_other.DealType       = TrwSubjectDealType.TRW_SUBJECT_DEAL_CONS_OTHER;
                    bay_other.PersonInternal = TrwSettings.GetInstance(os).PersonOtherBay;
                }
            }
        }