/// <summary> /// Calculates the specific reason code on an entity like sales line, tender line etc. /// </summary> /// <param name="request">The request.</param> /// <param name="sourceId">The source identifier.</param> /// <param name="tableRefType">The table identifier for the specific reason code.</param> /// <param name="refRelation">The first reference relation key corresponding to the entity and table.</param> /// <param name="refRelation2">The second reference relation key corresponding to the entity and table.</param> /// <param name="refRelation3">The third reference relation key corresponding to the entity and table.</param> /// <param name="requiredReasonCodes">The collection to which required reason codes are added.</param> /// <param name="reasonCodeRequirements">The required specific reason codes map.</param> /// <param name="presentReasonCodeLines">The collection with the already present reason code lines.</param> /// <param name="salesLine">The sales line when applicable.</param> private static void CalculateReasonCodesSpecificToEntity( CalculateRequiredReasonCodesServiceRequest request, string sourceId, ReasonCodeTableRefType tableRefType, string refRelation, string refRelation2, string refRelation3, IDictionary <string, ReasonCode> requiredReasonCodes, HashSet <ReasonCodeRequirement> reasonCodeRequirements, IEnumerable <ReasonCodeLine> presentReasonCodeLines, SalesLine salesLine) { GetReasonCodesByTableRefTypeDataRequest getReasonCodesByTableRefTypeDataRequest = new GetReasonCodesByTableRefTypeDataRequest(tableRefType, refRelation, refRelation2, refRelation3, QueryResultSettings.AllRecords); IEnumerable <ReasonCode> reasonCodes = request.RequestContext.Runtime.Execute <EntityDataServiceResponse <ReasonCode> >(getReasonCodesByTableRefTypeDataRequest, request.RequestContext).PagedEntityCollection.Results; reasonCodes = AddLinkedReasonCodes(reasonCodes, request.RequestContext); var triggeredReasonCodes = CalculateTriggeredReasonCodes(reasonCodes, presentReasonCodeLines, request.RequestContext); reasonCodes = reasonCodes.Union(triggeredReasonCodes).Distinct(); reasonCodes = AddLinkedReasonCodes(reasonCodes, request.RequestContext); foreach (var reasonCode in reasonCodes) { if (presentReasonCodeLines.Any(rc => string.Equals(rc.ReasonCodeId, reasonCode.ReasonCodeId, StringComparison.OrdinalIgnoreCase))) { continue; } bool entitySpecificApplicability = true; switch (tableRefType) { case ReasonCodeTableRefType.Item: entitySpecificApplicability = HasSalesLineSpecificApplicability(reasonCode, salesLine); break; } if (entitySpecificApplicability && ShouldReasonCodeBeApplied(reasonCode, request.SalesTransaction)) { var reasonCodeRequirement = new ReasonCodeRequirement() { ReasonCodeId = reasonCode.ReasonCodeId, SourceId = sourceId, TableRefTypeValue = (int)tableRefType, }; reasonCodeRequirements.Add(reasonCodeRequirement); requiredReasonCodes[reasonCode.ReasonCodeId] = reasonCode; } } }
/// <summary> /// Calculate specific reason codes on a tender line and add them to the incoming collection. /// </summary> /// <param name="request">The request object.</param> /// <param name="requiredReasonCodes">The collection to which required reason codes are added.</param> /// <param name="reasonCodeRequirements">The required specific reason codes map.</param> /// <param name="tenderLine">The tenderLine on which to calculate required reason codes.</param> private static void CalculateRequiredSpecificReasonCodesOnTenderLine( CalculateRequiredReasonCodesServiceRequest request, IDictionary <string, ReasonCode> requiredReasonCodes, HashSet <ReasonCodeRequirement> reasonCodeRequirements, TenderLine tenderLine) { if (tenderLine.Status == TenderLineStatus.Historical) { return; } // if tenderline is a card, refrelation3 becomes tenderline.cardtypeid and tablerefid is creditcard var getChannelTenderTypesDataRequest = new GetChannelTenderTypesDataRequest(request.RequestContext.GetPrincipal().ChannelId, QueryResultSettings.AllRecords); var tenderTypes = request.RequestContext.Runtime.Execute <EntityDataServiceResponse <TenderType> >(getChannelTenderTypesDataRequest, request.RequestContext).PagedEntityCollection.Results; ReasonCodeTableRefType tableRef = ReasonCodeTableRefType.Tender; string refRelation3 = string.Empty; TenderType tenderType = tenderTypes.Where(type => type.TenderTypeId == tenderLine.TenderTypeId).SingleOrDefault(); if (tenderType.OperationId == (int)RetailOperation.PayCard) { refRelation3 = tenderLine.CardTypeId; tableRef = ReasonCodeTableRefType.CreditCard; } CalculateReasonCodesSpecificToEntity( request, tenderLine.TenderTypeId, tableRef, request.SalesTransaction.StoreId, tenderLine.TenderTypeId, refRelation3, requiredReasonCodes, reasonCodeRequirements, tenderLine.ReasonCodeLines, null); }