public static void FillSaleDeals(IObjectSpace os, TrwSubject trw_subj, TrwSubjectImportDealParameters parms) { IList <crmContractDeal> deals = GetDeals(trw_subj, DealInfoDealType.DEAL_INFO_PROCEEDS, parms); foreach (crmContractDeal deal in deals) { TrwSubjectDealSale subj_deal = trw_subj.DealsSale.FirstOrDefault(x => x.Deal == deal); if (subj_deal == null) { subj_deal = os.CreateObject <TrwSubjectDealSale>(); trw_subj.DealsSale.Add(subj_deal); subj_deal.DealType = TrwSubjectDealType.TRW_SUBJECT_DEAL_REAL; subj_deal.Deal = deal; subj_deal.DealBudget = null; } } if (parms.CreateOtherDeal) { TrwSubjectDealSale sale_other = trw_subj.DealsSale.FirstOrDefault(x => x.DealType == TrwSubjectDealType.TRW_SUBJECT_DEAL_CONS_OTHER); if (sale_other == null) { sale_other = os.CreateObject <TrwSubjectDealSale>(); trw_subj.DealsSale.Add(sale_other); sale_other.DealType = TrwSubjectDealType.TRW_SUBJECT_DEAL_CONS_OTHER; sale_other.PersonInternal = TrwSettings.GetInstance(os).PersonOtherSale; } } }
void UpdateDeal() { using (IObjectSpace os = ObjectSpace.FindObjectSpaceByObject(this).CreateNestedObjectSpace()) { TrwSubjectDealSale subj_deal = os.GetObject <TrwSubjectDealSale>(this); TrwSubjectDealLogic.RefreshDeal(os, subj_deal); os.CommitChanges(); } }
public override void DealUpdated() { using (IObjectSpace os = ObjectSpace.FindObjectSpaceByObject(this).CreateNestedObjectSpace()) { TrwSubjectDealSale subj_deal = os.GetObject <TrwSubjectDealSale>(this); subj_deal.CrmContractDeals.Clear(); subj_deal.CrmContractDeals.Add(subj_deal.Deal); os.Delete(subj_deal.DealSaleOrders); TrwSubjectDealLogic.RefreshDeal(os, subj_deal); os.CommitChanges(); } }
public static void RefreshDeal(IObjectSpace os, TrwSubjectDealSale subj_deal) { if (subj_deal.DealType == TrwSubjectDealType.TRW_SUBJECT_DEAL_UNKNOW || subj_deal.TrwSubjectBase == null) { return; } if (subj_deal.DealType == TrwSubjectDealType.TRW_SUBJECT_DEAL_REAL) { if (subj_deal.Deal == null) { return; } DateTime period_end = new DateTime(subj_deal.TrwSubject.Period.Year, 12, 31); foreach (fmCSubject subj in subj_deal.TrwSubjectBase.Subjects) { TrwOrder trw_order = subj_deal.Deal.TrwOrders.FirstOrDefault(x => x.Subject == subj); if (trw_order == null) { subj.Deals.Add(subj_deal.Deal); trw_order = subj_deal.Deal.TrwOrders.FirstOrDefault(x => x.Subject == subj); } if (subj_deal.Nomenclature != null) { foreach (fmCOrder order in subj.Orders) { if (order.IsClosed || order.DateBegin > period_end) { continue; } TrwSubjectDealSaleOrder trw_subj_deal_order = subj_deal.DealSaleOrders.FirstOrDefault(x => x.Order == order); if (trw_subj_deal_order == null) { trw_subj_deal_order = os.CreateObject <TrwSubjectDealSaleOrder>(); subj_deal.DealSaleOrders.Add(trw_subj_deal_order); trw_subj_deal_order.TrwOrderSet(trw_order); trw_subj_deal_order.Order = order; trw_order.TrwSaleNomenclatures.Add(trw_subj_deal_order.TrwSaleNomenclature); } } } } } else { if (subj_deal.DealBudget == null) { return; } DateTime period_end = new DateTime(subj_deal.TrwSubject.Period.Year, 12, 31); foreach (fmCSubject subj in subj_deal.TrwSubjectBase.Subjects) { if (subj_deal.DealBudget == null) { return; } TrwOrder trw_order = subj_deal.DealBudget.TrwOrders.FirstOrDefault(x => x.Subject == subj); if (trw_order == null) { trw_order = os.CreateObject <TrwOrder>(); trw_order.Subject = subj; trw_order.TrwContractInt = subj_deal.DealBudget; } trw_order.TrwDateFrom = subj_deal.DealBudget.TrwDateValidFrom; trw_order.TrwDateToPlan = subj_deal.DealBudget.TrwDateValidToFact; trw_order.TrwOrderWorkType = subj_deal.TrwOrderWorkType; if (subj_deal.Nomenclature != null) { foreach (fmCOrder order in subj.Orders) { if (order.IsClosed || order.DateBegin > period_end) { continue; } TrwSubjectDealSaleOrder trw_subj_deal_order = subj_deal.DealSaleOrders.FirstOrDefault(x => x.Order == order); if (trw_subj_deal_order == null) { trw_subj_deal_order = os.CreateObject <TrwSubjectDealSaleOrder>(); subj_deal.DealSaleOrders.Add(trw_subj_deal_order); trw_subj_deal_order.TrwOrderSet(trw_order); trw_subj_deal_order.Order = order; trw_order.TrwSaleNomenclatures.Add(trw_subj_deal_order.TrwSaleNomenclature); } } } } } }