-- F13 finansal mutabakat (QA siparişleri)
SELECT o.order_number, o.status, o.subtotal_try, o.shipping_try, o.discount_try, o.total_try,
  (SELECT ROUND(SUM(quantity * unit_price_try), 2) FROM ecommerce_order_items WHERE order_id = o.id) AS items_sum,
  p.status AS pay_status, p.amount_try,
  JSON_UNQUOTE(JSON_EXTRACT(p.raw_payload_json, '$.iyzico_paid_price')) AS iyzico_paid_price
FROM ecommerce_orders o
LEFT JOIN ecommerce_payments p ON p.order_id = o.id
WHERE o.created_at > UTC_TIMESTAMP() - INTERVAL 6 HOUR
  AND (o.order_number LIKE 'FM-%' OR o.customer_email LIKE 'qa-%@faunamix.test')
ORDER BY o.id DESC;
