/// <summary> /// Initializes a new instance of the <see cref="UPSERowPricing"/> class. /// </summary> /// <param name="price">The price.</param> /// <param name="priceProvider">The price provider.</param> /// <param name="rowRecordId">The row record identifier.</param> public UPSERowPricing(UPSEPrice price, UPSEPricing priceProvider, string rowRecordId) { this.Price = price; this.PriceProvider = priceProvider; this.RowRecordId = rowRecordId; this.bundleConditionsLoaded = false; this.conditionsLoaded = false; this.currentConditionsLoaded = false; }
/// <summary> /// Prices for row. /// </summary> /// <param name="row">The row.</param> /// <returns></returns> public UPSERowPricing PriceForRow(UPSERow row) { UPSERowPricing rowPricing; if (!string.IsNullOrEmpty(this.PricingItemNumber)) { string itemNumber = null; if (!string.IsNullOrEmpty(this.SerialEntry.ItemNumberFunctionName)) { itemNumber = row.ValueForFunctionName(this.SerialEntry.ItemNumberFunctionName); } if (itemNumber == null) { return(null); } rowPricing = this.rowPricingForArticle.ValueOrDefault(itemNumber); if (rowPricing != null) { return(rowPricing); } UPSEPrice price = this.priceForArticle.ValueOrDefault(itemNumber); string rowRecordId = row.RowRecordId; if (price == null) { Dictionary <string, object> dataDictionary = row.SourceFunctionValues(); price = new UPSEPrice(StringExtensions.InfoAreaIdRecordId(this.SerialEntry.SourceInfoAreaId, rowRecordId), dataDictionary, this); } if (price != null) { rowPricing = new UPSERowPricing(price, this, rowRecordId); if (this.rowPricingForArticle == null) { this.rowPricingForArticle = new Dictionary <string, UPSERowPricing>(); } this.rowPricingForArticle[itemNumber] = rowPricing; return(rowPricing); } } else { string rowRecordId = row.RowRecordId; rowPricing = this.rowPricingForArticle.ValueOrDefault(rowRecordId); if (rowPricing != null) { return(rowPricing); } UPSEPrice price = this.priceForArticle.ValueOrDefault(rowRecordId); if (price == null) { Dictionary <string, object> dataDictionary = row.SourceFunctionValues(); price = new UPSEPrice(StringExtensions.InfoAreaIdRecordId(this.SerialEntry.SourceInfoAreaId, rowRecordId), dataDictionary, this); } if (price != null) { rowPricing = new UPSERowPricing(price, this, rowRecordId); if (this.rowPricingForArticle == null) { this.rowPricingForArticle = new Dictionary <string, UPSERowPricing>(); } this.rowPricingForArticle[rowRecordId] = rowPricing; return(rowPricing); } } return(null); }
private void HandlePricingResult(UPCRMResult result) { int count = result.RowCount; Dictionary <string, UPSEPrice> articleDictionary = new Dictionary <string, UPSEPrice>(count); bool pricingByItemNumber = this.PricingItemNumber.Length > 0; int pricingItemNumberIndex = 0; if (pricingByItemNumber) { pricingItemNumberIndex = result.MetaInfo.IndexOfFunctionName(this.PricingItemNumber); Logger.LogError($"cannot execute pricing by item number because function name {this.PricingItemNumber} was not found in the pricing result"); if (pricingItemNumberIndex < 0) { pricingByItemNumber = false; } } for (int i = 0; i < count; i++) { UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(i); string articleRecordId = pricingByItemNumber ? row.RawValueAtIndex(pricingItemNumberIndex) : row.RecordIdentificationAtIndex(1).RecordId(); if (articleRecordId == null) { continue; } UPSEPrice price = new UPSEPrice(row, articleRecordId, this); UPSEPrice existingPrice = articleDictionary.ValueOrDefault(articleRecordId); if (existingPrice == null) { articleDictionary.SetObjectForKey(price, articleRecordId); } else { bool checkCurrency = true; foreach (string priorityColumn in this.PriceListPriorityColumns) { string existingValue = existingPrice.DataDictionary.ValueOrDefault(priorityColumn) as string; string currentValue = price.DataDictionary.ValueOrDefault(priorityColumn) as string; if (string.IsNullOrEmpty(existingValue) || existingValue == "0") { if (!string.IsNullOrEmpty(currentValue) && currentValue != "0") { articleDictionary[articleRecordId] = price; checkCurrency = false; break; } } else if (string.IsNullOrEmpty(currentValue) || currentValue == "0") { checkCurrency = false; break; } } if (checkCurrency) { if (price.Currency > 0 && this.Currency == price.Currency) { articleDictionary.SetObjectForKey(price, articleRecordId); } else if (existingPrice.Currency != this.Currency) { int baseCurrency = 0; if (this.CurrencyConversion != null) { baseCurrency = this.CurrencyConversion.BaseCurrency.CatalogCode; } if (baseCurrency != existingPrice.Currency) { if (price.Currency == baseCurrency) { articleDictionary.SetObjectForKey(price, articleRecordId); } } } } } } this.priceForArticle = articleDictionary; if (this.BulkVolumes != null) { this.BulkVolumes.Load(this.filterParameters, this.SerialEntry.RequestOption); } else { this.HandleBulkVolumesResult(); } }
/// <summary> /// Bases the price for row. /// </summary> /// <param name="row">The row.</param> /// <returns></returns> public double BasePriceForRow(UPSEOrderRow row) { UPSEPrice pricing = this.PricingForRow(row); return(pricing?.UnitPrice ?? 0); }