private async Task <Currency> GetCurrency(ExcelCellValueLookup entries, CostLineItemSectionTemplateModel costSection, CostLineItemSectionTemplateItemModel item) { string code; var key = GetItemCurrencyKey(costSection, item); if (entries.ContainsKey(key)) { code = entries[key].Value; } else { key = GetSectionCurrencyKey(costSection); code = entries.ContainsKey(key) ? entries[key].Value : entries[GetAgencyCurrencyKey()].Value; } return(await _efContext.Currency.Where(c => c.Code == code).FirstOrDefaultAsync()); }
private static UpdateCostLineItemsModel GetCostLineModel(decimal initialAmount, Currency usdCurrency, CostLineItemSectionTemplateModel distributionTemplateSection, CostLineItemSectionTemplateModel otherTemplateSection) { var updateCostLineItemModel = new UpdateCostLineItemsModel { CostLineItemData = new List <CostLineItemModel> { new CostLineItemModel { Name = "distributionCosts", Value = initialAmount, LocalCurrencyId = usdCurrency.Id, TemplateSectionId = distributionTemplateSection.Id }, new CostLineItemModel { Name = "taxIfApplicable", Value = 0, LocalCurrencyId = usdCurrency.Id, TemplateSectionId = otherTemplateSection.Id }, new CostLineItemModel { Name = "technicalFee", Value = 0, LocalCurrencyId = usdCurrency.Id, TemplateSectionId = otherTemplateSection.Id }, new CostLineItemModel { Name = "foreignExchange", Value = 0, LocalCurrencyId = usdCurrency.Id, TemplateSectionId = otherTemplateSection.Id } } }; return(updateCostLineItemModel); }
private static string GetItemCurrencyKey(CostLineItemSectionTemplateModel costSection, CostLineItemSectionTemplateItemModel item) { return($"currency.{costSection.Name}.{item.Name}"); }
private static string GetSectionCurrencyKey(CostLineItemSectionTemplateModel costSection) { return($"currency.{costSection.Name}"); }
private static string GetLocalCurrencyLookupKey(CostLineItemSectionTemplateModel costSection, CostLineItemSectionTemplateItemModel item) { return($"{costSection.Name}.{item.Name}.local"); }
private static string GetLocalCurrencyLookupKey(ProductionDetailsFormDefinitionModel form, CostLineItemSectionTemplateModel costSection, CostLineItemSectionTemplateItemModel item) { return($"{form.Name}.{costSection.Name}.{item.Name}.local"); }
private CostLineItem GetOrCreateCostLineItem(CostStageRevision costStageRevision, Guid userId, CostLineItemSectionTemplateModel section, CostLineItemSectionTemplateItemModel item) { if (costStageRevision.CostLineItems == null) { costStageRevision.CostLineItems = new List <CostLineItem>(); } foreach (var cli in costStageRevision.CostLineItems) { if (cli.Name == item.Name && cli.CostLineItemSectionTemplate?.Name == section.Name) { return(cli); } } //Create new var costLineItem = new CostLineItem { CostStageRevision = costStageRevision, Id = Guid.NewGuid(), LocalCurrencyId = Guid.Empty, Name = item.Name, TemplateSectionId = section.Id }; costStageRevision.CostLineItems.Add(costLineItem); costLineItem.SetCreatedNow(userId); return(costLineItem); }
public void Setup() { _target = new CostLineItemUpdater(_efContextMock.Object, _revisionServiceMock.Object, _templateServiceMock.Object, new CostSectionFinder(), _costExchangeRateServiceMock.Object); var cost = new Cost(); var costStageRevision = new CostStageRevision() { CostLineItems = new List <CostLineItem> { new CostLineItem { } } }; var costTemplateVersion = new CostTemplateVersion(); var costTemplate = new CostTemplate(); var fieldDefinitions = new CustomFormData(); var usd = new Currency(); var euro = new Currency(); var gbp = new Currency(); cost.Id = _costId; costStageRevision.Id = _costStageRevisionId; cost.LatestCostStageRevision = costStageRevision; cost.LatestCostStageRevisionId = _costStageRevisionId; cost.CostTemplateVersion = costTemplateVersion; cost.CostTemplateVersionId = _costTemplateVersionId; costTemplateVersion.CostTemplate = costTemplate; costTemplateVersion.Id = _costTemplateVersionId; costTemplate.FieldDefinitions = fieldDefinitions; euro.Code = "EUR"; usd.Code = "USD"; gbp.Code = "GBP"; euro.Id = Guid.NewGuid(); usd.Id = _usdCurrencyId; gbp.Id = _gbpCurrencyId; var costs = new List <Cost> { cost }; _costStageRevisions = new List <CostStageRevision> { costStageRevision }; var currencies = new List <Currency> { euro, usd, gbp }; _efContextMock.MockAsyncQueryable(costs.AsQueryable(), c => c.Cost); _efContextMock.MockAsyncQueryable(_costStageRevisions.AsQueryable(), c => c.CostStageRevision); _efContextMock.MockAsyncQueryable(currencies.AsQueryable(), c => c.Currency); var stageDetails = new PgStageDetailsForm { ContentType = new core.Builders.DictionaryValue { Id = Guid.NewGuid(), Key = "Video", Value = "Video" }, CostType = dataAccess.Entity.CostType.Production.ToString(), ProductionType = new core.Builders.DictionaryValue { Id = Guid.NewGuid(), Key = "Full Production", Value = "Full Production" }, Title = "Cost Title" }; _revisionServiceMock.Setup(csr => csr.GetStageDetails <PgStageDetailsForm>(_costStageRevisionId)).ReturnsAsync(stageDetails); var costTemplateVersionModel = new CostTemplateVersionModel(); var productionDetailCollection = new List <ProductionDetailsTemplateModel>(); var productionDetails = new ProductionDetailsTemplateModel(); _form = new ProductionDetailsFormDefinitionModel { Name = FormName, Label = "Full production", ProductionType = Constants.ProductionType.FullProduction }; var section = new CostLineItemSectionTemplateModel(); var item = new CostLineItemSectionTemplateItemModel(); section.Name = SectionName; item.Name = ItemName; section.Items = new List <CostLineItemSectionTemplateItemModel> { item }; _form.CostLineItemSections = new List <CostLineItemSectionTemplateModel> { section }; productionDetails.Forms = new List <ProductionDetailsFormDefinitionModel> { _form }; productionDetails.Type = "Video"; productionDetailCollection.Add(productionDetails); costTemplateVersionModel.ProductionDetails = productionDetailCollection; _templateServiceMock.Setup(ts => ts.GetCostTemplateVersionModel(It.IsAny <Guid>())).ReturnsAsync(costTemplateVersionModel); _userIdentity = new UserIdentity { Id = _userId, IpAddress = "127.0.0.1" }; var expectedExchangeRates = new List <ExchangeRate>() { new ExchangeRate { FromCurrency = _usdCurrencyId, Rate = 1 }, }; _costExchangeRateServiceMock.Setup(cer => cer.GetExchangeRatesByDefaultCurrency(It.IsAny <Guid>())) .ReturnsAsync(expectedExchangeRates); }