How to queryRecordType with gouping by date range and offset (hours) and also include quantity counters

Hello everyone,

I have 3 record types. "Orders", "Products" and "Order Product Variations" (relationship).

Orders (id, createdOn)
Products(id, categoryId)  *category must be equal to 5
Order Product Variations (id, productId, quantity, createdOn)

I want to create an interface that shows which products are ordered for each day.

  1. The orders products that are included for each day are from the previous date at 09:30:01 to current day at 09:30:00
  2. I want to have a counter for each product (including the quantity)

I want to ask what is the best way to proceed with this.
This interface will be used by the Canteen Manager to prepare lunch orders for employees.

At a later stage I will try to show which employees ordered each food.

Case scenarios:

##########Case No1###################


Today: 23 Feb 2024 08:00 AM

1st list el:
--------------------------------------------
Orders for 23/02/2024

  1. Food A                 qty: 7
  2. Food B                qty: 4
  3. Food C                qty: 2

--------------------------------------------

2nd list el:
--------------------------------------------
Orders for 22/02/2024

  1. Food A                 qty: 9
  2. Food D                qty: 4
  3. Food F                qty: 3

--------------------------------------------

##################################

###########Case No2##################


Today: 23 Feb 2024 09:31 AM

1st list el:
--------------------------------------------
Orders for 24/02/2024

  1. Food B                 qty: 1

--------------------------------------------

2nd list el:
--------------------------------------------
Orders for 23/02/2024

  1. Food A                 qty: 7
  2. Food B                qty: 4
  3. Food C                qty: 2

--------------------------------------------

3rd list el:
--------------------------------------------
Orders for 22/02/2024

  1. Food A                 qty: 9
  2. Food D                qty: 4
  3. Food F                qty: 3

--------------------------------------------

##################################

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Do you already have something? I mean, asking us to analyze your data structure and implement running code for you might a bit too much!?!

  • The code I have at the moment doesn't work for me as I want it. I tried this but data are not as I want them...

    a!localVariables(
    local!lunchOrdersPerDay: a!queryRecordType(
    recordType: 'recordType!{43c0dc45-98e0-40cf-aae3-b85bfa2dfeee}ICOS Order Product Variation',
    fields: {
    a!aggregationFields(
    groupings: {
    a!grouping(
    field: 'recordType!{43c0dc45-98e0-40cf-aae3-b85bfa2dfeee}ICOS Order Product Variation.fields.{399b36b5-c6ae-4b9b-a144-3a4639dcab41}createdOn',
    interval: "DATE",
    alias: "createdOn",
    ),
    a!grouping(
    field: 'recordType!{43c0dc45-98e0-40cf-aae3-b85bfa2dfeee}ICOS Order Product Variation.relationships.{839da51e-c9d0-44c7-a17c-9cf842ac54d8}product.fields.{6dd1c941-3e1f-45c7-9a13-bfdc7e900d30}name',
    alias: "product"
    ),
    },
    measures: {
    a!measure(
    field: 'recordType!{43c0dc45-98e0-40cf-aae3-b85bfa2dfeee}ICOS Order Product Variation.fields.{f264cc1d-2ee5-49b0-8645-76b6d4195e8c}productId',
    function: "COUNT",
    alias: "count"
    )
    }
    )
    },
    filters: {
    a!queryFilter(
    field: 'recordType!{43c0dc45-98e0-40cf-aae3-b85bfa2dfeee}ICOS Order Product Variation.relationships.{839da51e-c9d0-44c7-a17c-9cf842ac54d8}product.fields.{fcd0f810-cba5-406a-9cf0-930e1718bcf2}categoryId',
    operator: "=",
    value: 5
    )
    },
    pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 5000)
    )
    )

    Not sure If I have to make multiple queries and adjust my data using for loops and variables.

    I get this as a result

    [product:Chickpeas with spinach,
    count:1,
    createdOn:2/22/2024];
    
    [product:Briam,
    count:1,
    createdOn:2/23/2024];
    
    [product:Chickpeas with spinach,
    count:2,
    createdOn:2/23/2024]

  • 0
    Certified Lead Developer
    in reply to christodoulosp0001

    Can you update your post and use this?

  • 0
    Certified Senior Developer
    in reply to christodoulosp0001

    What looks wrong in the above output? Correct me if I am wrong,  As per your aggregation you have got the correct values. If you want to get the data based on the date selection have another filter in your queryRecordType which will have a variable for selected Date.

Reply Children
No Data