public static void BaseOnDerive(this Quote @this, ObjectOnDerive method) { var session = @this.Strategy.Session; var derivation = method.Derivation; if ([email protected]) { var internalOrganisations = new Organisations(session).InternalOrganisations(); if (internalOrganisations.Count() == 1) { @this.Issuer = internalOrganisations.First(); } } if ([email protected] && @this.ExistIssuer) { @this.QuoteNumber = @this.Issuer.NextQuoteNumber(session.Now().Year); } @this.Currency ??= @this.Receiver?.PreferredCurrency ?? @this.Issuer?.PreferredCurrency; foreach (QuoteItem quoteItem in @this.QuoteItems) { var quoteItemDerivedRoles = (QuoteItemDerivedRoles)quoteItem; quoteItemDerivedRoles.VatRegime = quoteItem.AssignedVatRegime ?? @this.VatRegime; quoteItemDerivedRoles.VatRate = quoteItem.VatRegime?.VatRate ?? quoteItem.Product?.VatRate; } @this.AddSecurityToken(new SecurityTokens(session).DefaultSecurityToken); @this.Sync(derivation); }
public static void BaseOnDerive(this Quote @this, ObjectOnDerive method) { var session = @this.Strategy.Session; var derivation = method.Derivation; if ([email protected]) { var internalOrganisations = new Organisations(session).InternalOrganisations(); if (internalOrganisations.Count() == 1) { @this.Issuer = internalOrganisations.First(); } } if ([email protected] && @this.ExistIssuer) { var year = @this.IssueDate.Year; @this.QuoteNumber = @this.Issuer.NextQuoteNumber(year); var fiscalYearInternalOrganisationSequenceNumbers = @this.Issuer.FiscalYearsInternalOrganisationSequenceNumbers.FirstOrDefault(v => v.FiscalYear == year); var prefix = @this.Issuer.QuoteSequence.IsEnforcedSequence ? @this.Issuer.QuoteNumberPrefix : fiscalYearInternalOrganisationSequenceNumbers.QuoteNumberPrefix; ((QuoteDerivedRoles)@this).SortableQuoteNumber = @this.Session().GetSingleton().SortableNumber(prefix, @this.QuoteNumber, year.ToString()); } if (@this.QuoteState.IsCreated) { var quoteDerivedRoles = (QuoteDerivedRoles)@this; quoteDerivedRoles.DerivedLocale = @this.Locale ?? @this.Receiver?.Locale ?? @this.Issuer?.Locale; quoteDerivedRoles.DerivedCurrency = @this.AssignedCurrency ?? @this.Receiver?.PreferredCurrency ?? @this.Issuer?.PreferredCurrency; quoteDerivedRoles.DerivedVatRegime = @this.AssignedVatRegime; quoteDerivedRoles.DerivedIrpfRegime = @this.AssignedIrpfRegime; } if (@this.ExistIssueDate && @this.ExistIssuer && @this.DerivedCurrency != @this.Issuer.PreferredCurrency) { var exchangeRate = @this.DerivedCurrency.ExchangeRatesWhereFromCurrency.Where(v => v.ValidFrom.Date <= @this.IssueDate.Date && v.ToCurrency.Equals(@this.Issuer.PreferredCurrency)).OrderByDescending(v => v.ValidFrom).FirstOrDefault(); if (exchangeRate == null) { exchangeRate = @this.Issuer.PreferredCurrency.ExchangeRatesWhereFromCurrency.Where(v => v.ValidFrom.Date <= @this.IssueDate.Date && v.ToCurrency.Equals(@this.DerivedCurrency)).OrderByDescending(v => v.ValidFrom).FirstOrDefault(); } if (exchangeRate == null) { derivation.Validation.AddError(@this, M.Quote.AssignedCurrency, ErrorMessages.CurrencyNotAllowed); } } foreach (QuoteItem quoteItem in @this.QuoteItems) { var quoteItemDerivedRoles = (QuoteItemDerivedRoles)quoteItem; quoteItemDerivedRoles.DerivedVatRegime = quoteItem.AssignedVatRegime ?? @this.DerivedVatRegime; quoteItemDerivedRoles.VatRate = quoteItem.DerivedVatRegime?.VatRates.First(v => v.FromDate <= @this.IssueDate && (!v.ExistThroughDate || v.ThroughDate >= @this.IssueDate)); quoteItemDerivedRoles.DerivedIrpfRegime = quoteItem.AssignedIrpfRegime ?? @this.DerivedIrpfRegime; quoteItemDerivedRoles.IrpfRate = quoteItem.DerivedIrpfRegime?.IrpfRates.First(v => v.FromDate <= @this.IssueDate && (!v.ExistThroughDate || v.ThroughDate >= @this.IssueDate)); } @this.AddSecurityToken(new SecurityTokens(session).DefaultSecurityToken); @this.Sync(derivation); }