                -- Test Data
                
                $fiveDaysAgoAt1300  = (new DateTime('5 days ago'))->setTime(13, 0)->format('Y-m-d H:i:s');
                $fiveDaysAgoAt0000  = (new DateTime('5 days ago'))->setTime(0, 0)->format('Y-m-d H:i:s');
                $fiveDaysAgo        = (new DateTime('5 days ago'))->format('Y-m-d');
                $fourDaysAgoAt1300  = (new DateTime('4 days ago'))->setTime(13, 0)->format('Y-m-d H:i:s');
                $fourDaysAgoAt0000  = (new DateTime('4 days ago'))->setTime(0, 0)->format('Y-m-d H:i:s');
                $fourDaysAgo        = (new DateTime('4 days ago'))->format('Y-m-d');
                $threeDaysAgoAt1300 = (new DateTime('3 days ago'))->setTime(13, 0)->format('Y-m-d H:i:s');
                $threeDaysAgoAt0000 = (new DateTime('3 days ago'))->setTime(0, 0)->format('Y-m-d H:i:s');
                $threeDaysAgo       = (new DateTime('3 days ago'))->format('Y-m-d');
                $twoDaysAgoAt1300   = (new DateTime('2 days ago'))->setTime(13, 0)->format('Y-m-d H:i:s');
                $twoDaysAgoAt0000   = (new DateTime('2 days ago'))->setTime(0, 0)->format('Y-m-d H:i:s');
                $twoDaysAgo         = (new DateTime('2 days ago'))->format('Y-m-d');
                $yesterdayAt1300    = (new DateTime('yesterday'))->setTime(13, 0)->format('Y-m-d H:i:s');
                $yesterdayAt0000    = (new DateTime('yesterday'))->setTime(0, 0)->format('Y-m-d H:i:s');
                $yesterday          = (new DateTime('yesterday'))->format('Y-m-d');
                $todayAt0000        = (new DateTime('today'))->setTime(0, 0)->format('Y-m-d H:i:s');


                $orderId = [];
                $this->mockPdo->exec("INSERT INTO food_order    (id,            public_order_code,  user_id,             guest_user_id,  tenant_id,  delivery_address_id,    billing_address_id,     order_status,   order_type,     product_total_original_gross,  product_total_current_gross,    order_total_current_gross,      order_total_original_gross,     order_full_refund,      order_total_current_reason,                             payment_status,         delivery_fee_gross,     customer_service_fee_gross,         platform_fee_gross,       stripe_fee_total,   small_order_fee_gross,    comment,    tenant_comment,     currency,   transaction_id,                 refunded_id,    payment_intent_id,              stripe_receipt_url,     created_at,                 updated_at) 
                                                    VALUES      ($lastOrderId,  'C02QD57Z',         $lastUserId,         NULL,           $tenantId,  2,                      NULL,                   'confirmed',    'delivery',     1540,                          1540,                           1790,                           1790,                           000,                   'Delivery Charge Applied',                              'paid',                  200,                    050,                                050,                      062,                250,                     NULL,       '',                 'GBP',      'ch_3TCdZxDRk9nZ67Cn2c0uUuj8',  '',             'pi_3TCdZxDRk9nZ67Cn2DmYfS9e',  '',                     '$fiveDaysAgoAt1300',        '$fiveDaysAgoAt1300')");
                $orderId[] = $lastOrderId;
                $lastOrderId++;
                $this->mockPdo->exec("INSERT INTO food_order    (id,            public_order_code,  user_id,             guest_user_id,  tenant_id,  delivery_address_id,    billing_address_id,     order_status,   order_type,     product_total_original_gross,  product_total_current_gross,    order_total_current_gross,      order_total_original_gross,     order_full_refund,      order_total_current_reason,                             payment_status,         delivery_fee_gross,     customer_service_fee_gross,         platform_fee_gross,       stripe_fee_total,   small_order_fee_gross,    comment,    tenant_comment,     currency,   transaction_id,                 refunded_id,    payment_intent_id,              stripe_receipt_url,     created_at,                 updated_at) 
                                                    VALUES      ($lastOrderId,  'C02QD57Z',         $lastUserId,         NULL,           $tenantId,  2,                      NULL,                   'confirmed',    'delivery',     1540,                          1540,                           1790,                           1790,                           000,                   'Delivery Charge Applied',                              'paid',                  200,                    050,                                050,                      062,                250,                     NULL,       '',                 'GBP',      'ch_3TCdZxDRk9nZ67Cn2c0uUuj8',  '',             'pi_3TCdZxDRk9nZ67Cn2DmYfS9e',  '',                     '$fiveDaysAgoAt1300',        '$fiveDaysAgoAt1300')");
                $orderId[] = $lastOrderId;
                $lastOrderId++;
                $this->mockPdo->exec("INSERT INTO food_order    (id,            public_order_code,  user_id,             guest_user_id,  tenant_id,  delivery_address_id,    billing_address_id,     order_status,   order_type,     product_total_original_gross,  product_total_current_gross,    order_total_current_gross,      order_total_original_gross,     order_full_refund,      order_total_current_reason,                             payment_status,         delivery_fee_gross,     customer_service_fee_gross,         platform_fee_gross,       stripe_fee_total,   small_order_fee_gross,    comment,    tenant_comment,     currency,   transaction_id,                 refunded_id,    payment_intent_id,              stripe_receipt_url,     created_at,                 updated_at) 
                                                    VALUES      ($lastOrderId,  'C02QD57Z',         $lastUserId,         NULL,           $tenantId,  2,                      NULL,                   'confirmed',    'delivery',     1540,                          1540,                           1790,                           1790,                           000,                   'Delivery Charge Applied',                              'paid',                  200,                    050,                                050,                      062,                250,                     NULL,       '',                 'GBP',      'ch_3TCdZxDRk9nZ67Cn2c0uUuj8',  '',             'pi_3TCdZxDRk9nZ67Cn2DmYfS9e',  '',                     '$fiveDaysAgoAt1300',        '$fiveDaysAgoAt1300')");
                $orderId[] = $lastOrderId;
                $lastOrderId++;
                $this->mockPdo->exec("INSERT INTO food_order    (id,            public_order_code,  user_id,             guest_user_id,  tenant_id,  delivery_address_id,    billing_address_id,     order_status,   order_type,     product_total_original_gross,  product_total_current_gross,    order_total_current_gross,      order_total_original_gross,     order_full_refund,      order_total_current_reason,                             payment_status,         delivery_fee_gross,     customer_service_fee_gross,         platform_fee_gross,       stripe_fee_total,   small_order_fee_gross,    comment,    tenant_comment,     currency,   transaction_id,                 refunded_id,    payment_intent_id,              stripe_receipt_url,     created_at,                 updated_at) 
                                                    VALUES      ($lastOrderId,  'C02QD57Z',         $lastUserId,         NULL,           $tenantId,  2,                      NULL,                   'confirmed',    'delivery',     1540,                          1540,                           0000,                           1790,                           1790,                   'Delivery Charge Applied',                              'refunded',             200,                    050,                                050,                      062,                250,                     NULL,       '',                 'GBP',      'ch_3TCdZxDRk9nZ67Cn2c0uUuj8',  '',             'pi_3TCdZxDRk9nZ67Cn2DmYfS9e',  '',                     '$threeDaysAgoAt1300',       '$yesterdayAt1300')");
                $orderId[] = $lastOrderId;
                $lastOrderId++;  

                // get the last inserted id for food_order_refund_event
                $this->mockPdo->exec("INSERT INTO food_order_refund_event (refund_group_id, order_id, tenant_id, refund_type, order_item_id, gross_pence, net_pence, vat_pence, vat_rate, note, processed_at) VALUES (1, $lastOrderId - 1, $tenantId, 'full', NULL, NULL, NULL, NULL, NULL, 'Full refund for order', '$yesterdayAt1300')");



Test Results 
Reporting State after EOD run: Array
Reporting State after EOD run: Array
(
    [0] => Array
        (
            [id] => 9
            [run_id] => 1
            [run_type] => Automatic
            [tenant_id] => 9
            [window_start] => 2026-04-12 00:00:00
            [window_end] => 2026-04-13 00:00:00
            [business_date] => 2026-04-12
            [order_count] => 3
            [full_refund_count] => 0
            [partial_refund_count] => 0
            [full_refund_total] => 0
            [customer_paid_total] => 5370
            [item_refund_total] => 0
            [partial_refund_total] => 0
            [platform_stripe_fees_net] => 186
            [platform_fees_net] => 150
            [platform_customer_service_fee_net] => 150
            [platform_tenant_fee_gross] => 150
            [platform_customer_service_fee_gross] => 150
            [platform_gross_revenue] => 300
            [platform_refunds] => 0
            [platform_net_revenue] => 300
            [platform_refund_impact] => 0
            [platform_net_impact] => 300
            [platform_sales_vat] => 0
            [platform_refund_vat] => 0
            [platform_net_vat] => 0
            [created_at] => 2026-04-17 12:43:13
            [updated_at] => 2026-04-17 12:43:13
        )

    [1] => Array
        (
            [id] => 10
            [run_id] => 2
            [run_type] => Automatic
            [tenant_id] => 9
            [window_start] => 2026-04-13 00:00:00
            [window_end] => 2026-04-14 00:00:00
            [business_date] => 2026-04-13
            [order_count] => 0
            [full_refund_count] => 0
            [partial_refund_count] => 0
            [full_refund_total] => 0
            [customer_paid_total] => 0
            [item_refund_total] => 0
            [partial_refund_total] => 0
            [platform_stripe_fees_net] => 0
            [platform_fees_net] => 0
            [platform_customer_service_fee_net] => 0
            [platform_tenant_fee_gross] => 0
            [platform_customer_service_fee_gross] => 0
            [platform_gross_revenue] => 0
            [platform_refunds] => 0
            [platform_net_revenue] => 0
            [platform_refund_impact] => 0
            [platform_net_impact] => 0
            [platform_sales_vat] => 0
            [platform_refund_vat] => 0
            [platform_net_vat] => 0
            [created_at] => 2026-04-17 12:43:13
            [updated_at] => 2026-04-17 12:43:13
        )

    [2] => Array
        (
            [id] => 11
            [run_id] => 3
            [run_type] => Automatic
            [tenant_id] => 9
            [window_start] => 2026-04-14 00:00:00
            [window_end] => 2026-04-15 00:00:00
            [business_date] => 2026-04-14
            [order_count] => 1
            [full_refund_count] => 0
            [partial_refund_count] => 0
            [full_refund_total] => 0
            [customer_paid_total] => 1790
            [item_refund_total] => 0
            [partial_refund_total] => 0
            [platform_stripe_fees_net] => 62
            [platform_fees_net] => 50
            [platform_customer_service_fee_net] => 50
            [platform_tenant_fee_gross] => 50
            [platform_customer_service_fee_gross] => 50
            [platform_gross_revenue] => 100
            [platform_refunds] => 0
            [platform_net_revenue] => 100
            [platform_refund_impact] => 0
            [platform_net_impact] => 100
            [platform_sales_vat] => 0
            [platform_refund_vat] => 0
            [platform_net_vat] => 0
            [created_at] => 2026-04-17 12:43:13
            [updated_at] => 2026-04-17 12:43:13
        )

    [3] => Array
        (
            [id] => 12
            [run_id] => 4
            [run_type] => Automatic
            [tenant_id] => 9
            [window_start] => 2026-04-15 00:00:00
            [window_end] => 2026-04-16 00:00:00
            [business_date] => 2026-04-15
            [order_count] => 0
            [full_refund_count] => 0
            [partial_refund_count] => 0
            [full_refund_total] => 0
            [customer_paid_total] => 0
            [item_refund_total] => 0
            [partial_refund_total] => 0
            [platform_stripe_fees_net] => 0
            [platform_fees_net] => 0
            [platform_customer_service_fee_net] => 0
            [platform_tenant_fee_gross] => 0
            [platform_customer_service_fee_gross] => 0
            [platform_gross_revenue] => 0
            [platform_refunds] => 0
            [platform_net_revenue] => 0
            [platform_refund_impact] => 0
            [platform_net_impact] => 0
            [platform_sales_vat] => 0
            [platform_refund_vat] => 0
            [platform_net_vat] => 0
            [created_at] => 2026-04-17 12:43:13
            [updated_at] => 2026-04-17 12:43:13
        )

    [4] => Array
        (
            [id] => 13
            [run_id] => 5
            [run_type] => Automatic
            [tenant_id] => 9
            [window_start] => 2026-04-16 00:00:00
            [window_end] => 2026-04-17 00:00:00
            [business_date] => 2026-04-16
            [order_count] => 0
            [full_refund_count] => 1
            [partial_refund_count] => 0
            [full_refund_total] => 1790
            [customer_paid_total] => 0
            [item_refund_total] => 0
            [partial_refund_total] => 0
            [platform_stripe_fees_net] => 0
            [platform_fees_net] => 0
            [platform_customer_service_fee_net] => 0
            [platform_tenant_fee_gross] => 0
            [platform_customer_service_fee_gross] => 0
            [platform_gross_revenue] => 0
            [platform_refunds] => 100
            [platform_net_revenue] => 0
            [platform_refund_impact] => -100
            [platform_net_impact] => -100
            [platform_sales_vat] => 0
            [platform_refund_vat] => 0
            [platform_net_vat] => 0
            [created_at] => 2026-04-17 12:43:13
            [updated_at] => 2026-04-17 12:43:13
        )

)

Reporting State Tenant after EOD run: Array
(
    [0] => Array
        (
            [id] => 9
            [run_id] => 1
            [run_type] => Automatic
            [tenant_id] => 9
            [window_start] => 2026-04-12 00:00:00
            [window_end] => 2026-04-13 00:00:00
            [business_date] => 2026-04-12
            [order_count] => 3
            [full_refund_count] => 0
            [partial_refund_count] => 0
            [customer_paid_total] => 5370
            [item_refund_total] => 0
            [partial_refund_total] => 0
            [tenant_gross_sales] => 5220
            [tenant_full_refund_total] => 0
            [tenant_total_refunds] => 0
            [tenant_refund_total] => 0
            [tenant_delivery_fees_net] => 600
            [tenant_small_order_fees_net] => 750
            [tenant_platform_fees_net] => 150
            [tenant_stripe_fees_net] => 186
            [tenant_net_pre_fee] => 5220
            [tenant_net_post_platform_fee] => 5070
            [tenant_net] => 4884
            [tenant_refund_impact] => 0
            [tenant_stripe_fee_impact] => -186
            [tenant_net_impact_pre_fee] => 5220
            [tenant_net_impact_post_platform_fee] => 5070
            [tenant_net_impact] => 4884
            [tenant_sales_vat_gross] => 0
            [tenant_sales_vat_net] => 0
            [tenant_sales_vat] => 0
            [tenant_refund_vat_gross] => 0
            [tenant_refund_vat_net] => 0
            [tenant_refund_vat] => 0
            [tenant_net_vat_gross] => 0
            [tenant_net_vat_net] => 0
            [tenant_net_vat] => 0
            [created_at] => 2026-04-17 12:43:13
            [updated_at] => 2026-04-17 12:43:13
        )

    [1] => Array
        (
            [id] => 10
            [run_id] => 2
            [run_type] => Automatic
            [tenant_id] => 9
            [window_start] => 2026-04-13 00:00:00
            [window_end] => 2026-04-14 00:00:00
            [business_date] => 2026-04-13
            [order_count] => 0
            [full_refund_count] => 0
            [partial_refund_count] => 0
            [customer_paid_total] => 0
            [item_refund_total] => 0
            [partial_refund_total] => 0
            [tenant_gross_sales] => 0
            [tenant_full_refund_total] => 0
            [tenant_total_refunds] => 0
            [tenant_refund_total] => 0
            [tenant_delivery_fees_net] => 0
            [tenant_small_order_fees_net] => 0
            [tenant_platform_fees_net] => 0
            [tenant_stripe_fees_net] => 0
            [tenant_net_pre_fee] => 0
            [tenant_net_post_platform_fee] => 0
            [tenant_net] => 0
            [tenant_refund_impact] => 0
            [tenant_stripe_fee_impact] => 0
            [tenant_net_impact_pre_fee] => 0
            [tenant_net_impact_post_platform_fee] => 0
            [tenant_net_impact] => 0
            [tenant_sales_vat_gross] => 0
            [tenant_sales_vat_net] => 0
            [tenant_sales_vat] => 0
            [tenant_refund_vat_gross] => 0
            [tenant_refund_vat_net] => 0
            [tenant_refund_vat] => 0
            [tenant_net_vat_gross] => 0
            [tenant_net_vat_net] => 0
            [tenant_net_vat] => 0
            [created_at] => 2026-04-17 12:43:13
            [updated_at] => 2026-04-17 12:43:13
        )

    [2] => Array
        (
            [id] => 11
            [run_id] => 3
            [run_type] => Automatic
            [tenant_id] => 9
            [window_start] => 2026-04-14 00:00:00
            [window_end] => 2026-04-15 00:00:00
            [business_date] => 2026-04-14
            [order_count] => 1
            [full_refund_count] => 0
            [partial_refund_count] => 0
            [customer_paid_total] => 1790
            [item_refund_total] => 0
            [partial_refund_total] => 0
            [tenant_gross_sales] => 1740
            [tenant_full_refund_total] => 0
            [tenant_total_refunds] => 0
            [tenant_refund_total] => 0
            [tenant_delivery_fees_net] => 200
            [tenant_small_order_fees_net] => 250
            [tenant_platform_fees_net] => 50
            [tenant_stripe_fees_net] => 62
            [tenant_net_pre_fee] => 1740
            [tenant_net_post_platform_fee] => 1690
            [tenant_net] => 1628
            [tenant_refund_impact] => 0
            [tenant_stripe_fee_impact] => -62
            [tenant_net_impact_pre_fee] => 1740
            [tenant_net_impact_post_platform_fee] => 1690
            [tenant_net_impact] => 1628
            [tenant_sales_vat_gross] => 0
            [tenant_sales_vat_net] => 0
            [tenant_sales_vat] => 0
            [tenant_refund_vat_gross] => 0
            [tenant_refund_vat_net] => 0
            [tenant_refund_vat] => 0
            [tenant_net_vat_gross] => 0
            [tenant_net_vat_net] => 0
            [tenant_net_vat] => 0
            [created_at] => 2026-04-17 12:43:13
            [updated_at] => 2026-04-17 12:43:13
        )

    [3] => Array
        (
            [id] => 12
            [run_id] => 4
            [run_type] => Automatic
            [tenant_id] => 9
            [window_start] => 2026-04-15 00:00:00
            [window_end] => 2026-04-16 00:00:00
            [business_date] => 2026-04-15
            [order_count] => 0
            [full_refund_count] => 0
            [partial_refund_count] => 0
            [customer_paid_total] => 0
            [item_refund_total] => 0
            [partial_refund_total] => 0
            [tenant_gross_sales] => 0
            [tenant_full_refund_total] => 0
            [tenant_total_refunds] => 0
            [tenant_refund_total] => 0
            [tenant_delivery_fees_net] => 0
            [tenant_small_order_fees_net] => 0
            [tenant_platform_fees_net] => 0
            [tenant_stripe_fees_net] => 0
            [tenant_net_pre_fee] => 0
            [tenant_net_post_platform_fee] => 0
            [tenant_net] => 0
            [tenant_refund_impact] => 0
            [tenant_stripe_fee_impact] => 0
            [tenant_net_impact_pre_fee] => 0
            [tenant_net_impact_post_platform_fee] => 0
            [tenant_net_impact] => 0
            [tenant_sales_vat_gross] => 0
            [tenant_sales_vat_net] => 0
            [tenant_sales_vat] => 0
            [tenant_refund_vat_gross] => 0
            [tenant_refund_vat_net] => 0
            [tenant_refund_vat] => 0
            [tenant_net_vat_gross] => 0
            [tenant_net_vat_net] => 0
            [tenant_net_vat] => 0
            [created_at] => 2026-04-17 12:43:13
            [updated_at] => 2026-04-17 12:43:13
        )

    [4] => Array
        (
            [id] => 13
            [run_id] => 5
            [run_type] => Automatic
            [tenant_id] => 9
            [window_start] => 2026-04-16 00:00:00
            [window_end] => 2026-04-17 00:00:00
            [business_date] => 2026-04-16
            [order_count] => 0
            [full_refund_count] => 1
            [partial_refund_count] => 0
            [customer_paid_total] => 0
            [item_refund_total] => 0
            [partial_refund_total] => 0
            [tenant_gross_sales] => 0
            [tenant_full_refund_total] => 1790
            [tenant_total_refunds] => 1790
            [tenant_refund_total] => 1740
            [tenant_delivery_fees_net] => 0
            [tenant_small_order_fees_net] => 0
            [tenant_platform_fees_net] => 0
            [tenant_stripe_fees_net] => 0
            [tenant_net_pre_fee] => 0
            [tenant_net_post_platform_fee] => 0
            [tenant_net] => 0
            [tenant_refund_impact] => -1740
            [tenant_stripe_fee_impact] => -62
            [tenant_net_impact_pre_fee] => -1740
            [tenant_net_impact_post_platform_fee] => -1740
            [tenant_net_impact] => -1802
            [tenant_sales_vat_gross] => 0
            [tenant_sales_vat_net] => 0
            [tenant_sales_vat] => 0
            [tenant_refund_vat_gross] => 0
            [tenant_refund_vat_net] => 0
            [tenant_refund_vat] => 0
            [tenant_net_vat_gross] => 0
            [tenant_net_vat_net] => 0
            [tenant_net_vat] => 0
            [created_at] => 2026-04-17 12:43:13
            [updated_at] => 2026-04-17 12:43:13
        )

)