$tenantId = $this->setUpNewBasicTenant();

                $outPut = $this->mockPdo->query("select COALESCE(MAX(id), 0) from food_order")->fetchColumn();
                $lastOrderId = (int)$outPut;
                $lastOrderId++;

                // get a user id to use for the order inserts
                $outPut = $this->mockPdo->query("select COALESCE(MAX(pk_user_id), 0) from user_login")->fetchColumn();
                $lastUserId = (int)$outPut;

                // date should be yesterday ad 13:00 to ensure it is within the opening hours and picked up by the reporting function
                $yesterdayat1300 = (new DateTime('yesterday'))->setTime(13, 0)->format('Y-m-d H:i:s');
                $twoDaysAgoat1300 = (new DateTime('2 days ago'))->setTime(13, 0)->format('Y-m-d H:i:s');

                //$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,  'C02QD57Y',         $lastUserId,         NULL,           $ids[0],    2,                      NULL,                   'confirmed',    'delivery',     1040,                          1040,                           1290,                           1290,                           000,                   'Delivery Charge Applied, Admin Fee Applied',           'paid',                  200,                    050,                                050,                      062,                250,                     NULL,       '',                 'GBP',      'ch_3TCdZxDRk9nZ67Cn2c0uUuj9',  '',             'pi_3TCdZxDRk9nZ67Cn2DmYfS9d',  '',                     datetime('now', '-5 day'),  datetime('now', '-5 day'))");
                //$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',  '',                     '$twoDaysAgoat1300', '$twoDaysAgoat1300')");
                $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',  '',                     '$yesterdayat1300', '$yesterdayat1300')");
                $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')");


-- Results
Reporting State Platform after EOD run: Array
(
    [0] => Array
        (
            [id] => 2
            [run_id] => 1
            [run_type] => Automatic
            [tenant_id] => 7
            [window_start] => 2026-04-15 00:00:00
            [window_end] => 2026-04-16 00:00:00
            [business_date] => 2026-04-15
            [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 10:33:20
            [updated_at] => 2026-04-17 10:33:20
        )

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

)

Reporting State Tenant after EOD run: Array
(
    [0] => Array
        (
            [id] => 2
            [run_id] => 1
            [run_type] => Automatic
            [tenant_id] => 7
            [window_start] => 2026-04-15 00:00:00
            [window_end] => 2026-04-16 00:00:00
            [business_date] => 2026-04-15
            [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 10:33:20
            [updated_at] => 2026-04-17 10:33:20
        )

    [1] => Array
        (
            [id] => 3
            [run_id] => 2
            [run_type] => Automatic
            [tenant_id] => 7
            [window_start] => 2026-04-16 00:00:00
            [window_end] => 2026-04-17 00:00:00
            [business_date] => 2026-04-16
            [order_count] => 1
            [full_refund_count] => 1
            [partial_refund_count] => 0
            [customer_paid_total] => 1790
            [item_refund_total] => 0
            [partial_refund_total] => 0
            [tenant_gross_sales] => 1740
            [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] => 62
            [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] => 0
            [tenant_net_impact_post_platform_fee] => 0
            [tenant_net_impact] => -62
            [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 10:33:20
            [updated_at] => 2026-04-17 10:33:20
        )

)