private Decimal getPlanAssets(CRM.Model.Engagement engagement, Generator generator) { var planAssetValue = engagement.GetAssetsForInvoice(generator.BillingDate, generator.PlanEngagements, generator.PlanAccounts, generator.PlanAssets, this.getPreviousBillingDate().AddDays(1)); // is not first, tiered rate, ongoing engagement and is in arrears var billingType = Calculator.GetInvoiceBillingType(this._engagementProductType, this._engagementEffectiveDate, this._generator.BillingDate, this._isNewEngagement); var billingLength = (this._generator.BillingDate.Date - this.getPreviousBillingDate().Date).Days; var isFirstEngagementInvoice = !(this._generator.BillingDate >= this._engagement.EffectiveDate.AddDays(billingLength)); if (isFirstEngagementInvoice) { var clientId = this._engagement.ClientId; var clientEngagements = this._generator.Engagements.FindAll(x => x.ClientId == clientId); if (clientEngagements.FindAll(x => x.IsTieredOngoingEngagement()).Count > 0) { var firstProductType = clientEngagements.FindAll(x => x.IsTieredOngoingEngagement()).OrderBy(x => x.EffectiveDate).First().ProductType; if (firstProductType != this._engagement.ProductType) { isFirstEngagementInvoice = false; } } } if (this._engagement.IsTieredOngoingEngagement() && !isFirstEngagementInvoice && billingType == Model.BillingType.InArrears) { planAssetValue = engagement.GetAssetsForInvoice(this.getPreviousBillingDate(), generator.PlanEngagements, generator.PlanAccounts, generator.PlanAssets, this.getPreviousBillingDate(this.getPreviousBillingDate()).AddDays(1)); } else if (billingType == Model.BillingType.InAdvanced && this._isTerminatedEngagement) { planAssetValue = engagement.GetAssetsForInvoice(this.getPreviousBillingDate(), generator.PlanEngagements, generator.PlanAccounts, generator.PlanAssets, this.getPreviousBillingDate(this.getPreviousBillingDate()).AddDays(1)); } return(planAssetValue); }
public GeneratorInvoice(CRM.Model.Engagement engagement, Generator generator) { this._generator = generator; this._engagement = engagement; this._engagementProductType = engagement.GetProductTypeDetail(); this._engagementEffectiveDate = (DateTime)engagement.EffectiveDate; this._engagementTerminationDate = engagement.ContractTerminationDate; this._engagementTierLevel = (int)engagement.Tier; this._isNewEngagement = engagement.IsNewOnBillingDate(generator.BillingDate); this._isTerminatedEngagement = engagement.IsTerminatedOnBillingDate(generator.BillingDate); this._planAssetValue = this.getPlanAssets(engagement, generator); this.calculateInvoiceFeesAndCredits(); }
public static List <Model.ComponentTask> Retrieve(Model.Engagement engagement) { var criteria = new FilterExpression(); criteria.AddCondition("new_projectid", ConditionOperator.Equal, engagement.Id); var request = Globals.GetRetrieveMultipleRequest(_tableName, criteria); var retrieveMultipleResponse = Globals.CrmServiceBroker.ExecuteRetrieveMultipleRequest(request); var businessEntityCollection = retrieveMultipleResponse.BusinessEntityCollection; var result = new List <Model.ComponentTask>(); foreach (var businessEntity in businessEntityCollection.BusinessEntities) { var dynamicEntity = (DynamicEntity)businessEntity; var componentTask = new CRM.Model.ComponentTask(dynamicEntity); result.Add(componentTask); } return(result.FindAll(x => x.EngagementId == engagement.Id)); }