web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Suggested Answer

Can not get object Shift in GetCustomReceiptsRequest request

(0) ShareShare
ReportReport
Posted on by

Hello all,

I have a request to get data of current Shift when print report to change some details in CustomReceipt7.

I create Request Handler: SingleRequestHandler<GetCustomReceiptsRequest, GetReceiptResponse>


I try to use this method to get shift, but AccountLines, TenderLines, TaxLines can not get, because in this time in database do not exist line of transaction.

private Shift GetShift()
{
long channelId = request.RequestContext.GetPrincipal().ChannelId;
long shiftId = request.RequestContext.GetPrincipal().ShiftId;
string terminalId = request.RequestContext.GetTerminalId().ToString();

GetShiftDataDataRequest shiftDataDataRequest = new GetShiftDataDataRequest(new ShiftDataQueryCriteria()
{
ChannelId = new long?(channelId),
TerminalId = terminalId,
ShiftId = new long?(shiftId),
SearchByTerminalId = true,
IncludeSharedShifts = true
}, QueryResultSettings.SingleRecord);
Shift entity = request.RequestContext.Runtime.Execute<EntityDataServiceResponse<Shift>>((Request)shiftDataDataRequest, request.RequestContext).PagedEntityCollection.FirstOrDefault<Shift>();
if (entity != null)
{
PagedResult<ShiftTenderLine> shiftEntity1 = this.GetShiftEntity<ShiftTenderLine>(string.Empty, "SHIFTTENDERLINESVIEW", terminalId, shiftId, (Request)request, false);
PagedResult<ShiftAccountLine> shiftEntity2 = this.GetShiftEntity<ShiftAccountLine>(string.Empty, "SHIFTACCOUNTSVIEW", terminalId, shiftId, (Request)request, false);
PagedResult<ShiftTaxLine> shiftEntity3 = this.GetShiftEntity<ShiftTaxLine>(string.Empty, "SHIFTTAXLINESVIEW", terminalId, shiftId, (Request)request, false);
entity.AccountLines = (IList<ShiftAccountLine>)shiftEntity2.Results.ToList<ShiftAccountLine>();
entity.TenderLines = (IList<ShiftTenderLine>)shiftEntity1.Results.ToList<ShiftTenderLine>();
entity.TaxLines = (IList<ShiftTaxLine>)shiftEntity3.Results.ToList<ShiftTaxLine>();
RetailLogger.Log.CrtDataServiceSqlServerGetShiftDataRequestSucceeded(entity.ShiftId, entity.TerminalId, entity.CashDrawer, entity.CurrentTerminalId, entity.StaffId, entity.CurrentStaffId, entity.IsShared.ToString(), entity.Status.ToString());
}
return entity;
}

Thanks for support.

I have the same question (0)
  • Omar Hesham Shehab Profile Picture
    on at

    Hi,

    can you please provide some details  regarding to the method "Getshift" and what are you actually trying to achieve using this code

  • Abigail Profile Picture
    552 on at

    1. PostOpenShiftTrigger - Non-cancelable - This trigger is executed after the new shift is opened.

    2. PreCloseShiftTrigger - Cancelable - This trigger is executed before the shift is closed.

    Use the second command to make changes in the customer Receipt and get that data before you close that shift.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi all,

    Currently, I have a solution, in GetEndOfDayShiftDetailsDataRequest,

    we can get object shift with current data in TaxLines and TenderLines, ActiveLines.

    Thanks all for following.

    {

    long channelId = request.RequestContext.GetPrincipal().ChannelId;

    long shiftId = request.RequestContext.GetPrincipal().ShiftId;

    string terminalId = request.RequestContext.GetTerminalId().ToString();

    string hardwareProfileId = request.RequestContext.GetTerminal().HardwareProfile;

    GetEndOfDayShiftDetailsDataRequest detailsDataRequest = new GetEndOfDayShiftDetailsDataRequest(terminalId, shiftId, this.Context.GetChannelConfiguration().PriceIncludesSalesTax);

    Shift entity1 = this.Context.Runtime.Execute<SingleEntityDataServiceResponse<Shift>>((Request)detailsDataRequest, this.Context).Entity;

    }

  • Omar Hesham Shehab Profile Picture
    on at

    i would suggest in case the above mentioned piece of code didn't help to solve the issue i'll suggest you to open a service request in order to get into deeper investigation

  • Community Member Profile Picture
    on at

    Finally, I found code in decompile dll.

    This method inside of request to call XZ Report.

    This really final solution I choosed.

    public static void Calculate(

      RequestContext context,

      Shift currentShift,

      string shiftTerminalId,

      long shiftId)

    {

     GetEndOfDayShiftDetailsDataRequest detailsDataRequest = new GetEndOfDayShiftDetailsDataRequest(shiftTerminalId, shiftId, context.GetChannelConfiguration().PriceIncludesSalesTax);

     Shift entity1 = context.Runtime.Execute>((Request)detailsDataRequest, context).Entity;

     LAW_ShiftCalculator.SetShiftSalesTotals(currentShift, entity1);

     LAW_ShiftCalculator.SetShiftTenderLine(currentShift, entity1);

     LAW_ShiftCalculator.SetShiftAccountLines(currentShift, entity1);

     GetShiftTransactionsCountDataRequest countDataRequest = new GetShiftTransactionsCountDataRequest(shiftTerminalId, shiftId);

     Shift entity2 = context.Runtime.Execute>((Request)countDataRequest, context).Entity;

     LAW_ShiftCalculator.SetRetailTransactionCount(currentShift, entity2);

     GetShiftTenderedAmountDataRequest amountDataRequest = new GetShiftTenderedAmountDataRequest(shiftTerminalId, shiftId, QueryResultSettings.AllRecords);

     ReadOnlyCollection results = context.Runtime.Execute>((Request)amountDataRequest, context).PagedEntityCollection.Results;

     LAW_ShiftCalculator.SetShiftTenderLineTenderAmounts(currentShift, (IEnumerable)results);

     if (context.GetChannelConfiguration().CountryRegionISOCode != CountryRegionISOCode.SE)

      return;

     GetEndOfDayShiftDetailsSwedenDataRequest swedenDataRequest = new GetEndOfDayShiftDetailsSwedenDataRequest(currentShift.StoreId, shiftTerminalId, shiftId, context.GetChannelConfiguration().PriceIncludesSalesTax);

     Shift entity3 = context.Runtime.Execute>((Request)swedenDataRequest, context).Entity;

     LAW_ShiftCalculator.SetShiftSalesTotals_SE(currentShift, entity3);

     LAW_ShiftCalculator.SetShiftTaxLine(currentShift, entity3);

    }

    private static void SetShiftSalesTotals(Shift currentShift, Shift shiftTotals)

    {

     currentShift.SalesTotal = shiftTotals.SalesTotal;

     currentShift.ReturnsTotal = shiftTotals.ReturnsTotal;

     currentShift.DiscountTotal = shiftTotals.DiscountTotal;

     currentShift.TaxTotal = shiftTotals.TaxTotal;

     currentShift.PaidToAccountTotal = shiftTotals.PaidToAccountTotal;

     currentShift.SuspendedTransactionCount = shiftTotals.SuspendedTransactionCount;

     currentShift.DepositCollected = shiftTotals.DepositCollected;

     currentShift.DepositRedeemed = shiftTotals.DepositRedeemed;

     currentShift.DepositRefunded = shiftTotals.DepositRefunded;

     currentShift.CancellationCharges = shiftTotals.CancellationCharges;

     currentShift.CustomerOrdersPlaced = shiftTotals.CustomerOrdersPlaced;

     currentShift.CustomerOrdersCanceled = shiftTotals.CustomerOrdersCanceled;

     currentShift.CustomerOrdersVoidedLines = shiftTotals.CustomerOrdersVoidedLines;

     currentShift.CustomerOrdersEdited = shiftTotals.CustomerOrdersEdited;

     currentShift.GiftCardsTotal = shiftTotals.GiftCardsTotal;

     currentShift.GiftCardCashOutTotal = shiftTotals.GiftCardCashOutTotal;

     currentShift.VoidedSalesTotal = shiftTotals.VoidedSalesTotal;

     currentShift.ChargeTotal = shiftTotals.ChargeTotal;

    }

    private static void SetShiftSalesTotals_SE(Shift currentShift, Shift shiftTotals)

    {

     currentShift.ReceiptsCount = shiftTotals.ReceiptsCount;

     currentShift.ReturnsCount = shiftTotals.ReturnsCount;

     currentShift.GoodsSoldQty = shiftTotals.GoodsSoldQty;

     currentShift.ServicesSoldQty = shiftTotals.ServicesSoldQty;

     currentShift.ReceiptCopiesCount = shiftTotals.ReceiptCopiesCount;

     currentShift.ReceiptCopiesTotal = shiftTotals.ReceiptCopiesTotal;

     currentShift.PriceOverrideTotal = shiftTotals.PriceOverrideTotal;

     currentShift.SuspendedTotal = shiftTotals.SuspendedTotal;

     currentShift.SalesTotalIncludingTax = shiftTotals.SalesTotalIncludingTax;

     currentShift.SalesTotalExcludingTax = shiftTotals.SalesTotalExcludingTax;

     currentShift.SalesGrandTotal = shiftTotals.SalesGrandTotal;

     currentShift.ReturnsGrandTotal = shiftTotals.ReturnsGrandTotal;

    }

    private static void SetShiftTenderLine(Shift currentShift, Shift endOfDayShiftDetails)

    {

     currentShift.TenderLines.AddRange((IEnumerable)endOfDayShiftDetails.TenderLines);

    }

    private static void SetShiftAccountLines(Shift currentShift, Shift endOfDayShiftDetails)

    {

     currentShift.AccountLines.AddRange((IEnumerable)endOfDayShiftDetails.AccountLines);

    }

    private static void SetShiftTaxLine(Shift currentShift, Shift endOfDayShiftDetails)

    {

     currentShift.TaxLines.AddRange((IEnumerable)endOfDayShiftDetails.TaxLines);

    }

    private static void SetShiftTenderLineTenderAmounts(

      Shift currentShift,

      IEnumerable shiftTenderLines)

    {

     foreach (ShiftTenderLine shiftTenderLine in shiftTenderLines)

     {

      ShiftTenderLine orCreate = currentShift.TenderLines.FindOrCreate(shiftTenderLine);

      orCreate.CountingRequired = shiftTenderLine.CountingRequired;

      orCreate.TenderCurrency = shiftTenderLine.TenderCurrency;

      orCreate.ChangeLine = shiftTenderLine.ChangeLine;

      if (orCreate.ChangeLine)

      {

       orCreate.ChangeAmountOfTenderCurrency = Decimal.Negate(shiftTenderLine.TenderedAmountOfTenderCurrency);

       orCreate.ChangeAmountOfStoreCurrency = Decimal.Negate(shiftTenderLine.TenderedAmountOfStoreCurrency);

      }

      else

      {

       orCreate.TenderedAmountOfTenderCurrency = shiftTenderLine.TenderedAmountOfTenderCurrency;

       orCreate.TenderedAmountOfStoreCurrency = shiftTenderLine.TenderedAmountOfStoreCurrency;

       orCreate.Count = shiftTenderLine.Count;

      }

     }

    }

    private static ShiftTenderLine FindOrCreate(

      this IList shiftTenderLines,

      ShiftTenderLine tenderLine)

    {

     string tenderTypeId = tenderLine.TenderTypeId;

     string tenderCurrency = tenderLine.TenderCurrency;

     string tenderTypeName = tenderLine.TenderTypeName;

     ShiftTenderLine shiftTenderLine = shiftTenderLines.FirstOrDefault((Func)(p =>

     {

      if (p.TenderTypeId == tenderTypeId)

       return p.TenderCurrency == tenderCurrency;

      return false;

     }));

     if (shiftTenderLine == null)

     {

      shiftTenderLine = new ShiftTenderLine()

      {

       TenderTypeId = tenderTypeId,

       CardTypeId = string.Empty,

       TenderCurrency = tenderCurrency,

       TenderTypeName = tenderTypeName

      };

      shiftTenderLines.Add(shiftTenderLine);

     }

     return shiftTenderLine;

    }

    private static void SetRetailTransactionCount(Shift currentShift, Shift endOfDayShift)

    {

     currentShift.VoidTransactionCount = endOfDayShift.VoidTransactionCount;

     currentShift.NoSaleTransactionCount = endOfDayShift.NoSaleTransactionCount;

     currentShift.RoundedAmountTotal = endOfDayShift.RoundedAmountTotal;

     currentShift.TransactionCount = endOfDayShift.TransactionCount;

     currentShift.CustomerCount = endOfDayShift.CustomerCount;

     currentShift.SaleTransactionCount = endOfDayShift.SaleTransactionCount;

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
Laurens vd Tang Profile Picture

Laurens vd Tang 92 Super User 2026 Season 1

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 79 Super User 2026 Season 1

#3
Sagar Suman Profile Picture

Sagar Suman 64 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans