-- Batch 3: reporting performance + license core support

ALTER TABLE sales_invoices
  ADD INDEX IF NOT EXISTS idx_si_status_date_party_id (status, invoice_date, party_id, id),
  ADD INDEX IF NOT EXISTS idx_si_party_date_id (party_id, invoice_date, id);

ALTER TABLE sales_returns
  ADD INDEX IF NOT EXISTS idx_sr_status_date_party_id (status, return_date, party_id, id),
  ADD INDEX IF NOT EXISTS idx_sr_party_date_id (party_id, return_date, id);

ALTER TABLE cash_payments
  ADD INDEX IF NOT EXISTS idx_cp_type_status_date_id (payment_type, status, voucher_date, id),
  ADD INDEX IF NOT EXISTS idx_cp_party_date_id (party_id, voucher_date, id),
  ADD INDEX IF NOT EXISTS idx_cp_expense_item_date (expense_item_id, voucher_date, id);

ALTER TABLE customer_receipts
  ADD INDEX IF NOT EXISTS idx_cr_party_date_id (party_id, receipt_date, id),
  ADD INDEX IF NOT EXISTS idx_cr_cashbox_date (cashbox_id, receipt_date, id);

ALTER TABLE supplier_payments
  ADD INDEX IF NOT EXISTS idx_sp_status_date_supplier_id (status, pay_date, supplier_id, id),
  ADD INDEX IF NOT EXISTS idx_sp_supplier_date_id (supplier_id, pay_date, id);

ALTER TABLE cashbox_transactions
  ADD INDEX IF NOT EXISTS idx_cbt_cashbox_date_id_b3 (cashbox_id, trx_date, id);

ALTER TABLE bank_transactions
  ADD INDEX IF NOT EXISTS idx_bt_account_date_id (bank_account_id, trx_date, id);

ALTER TABLE sales_items
  ADD INDEX IF NOT EXISTS idx_sales_items_invoice_id_id (invoice_id, id),
  ADD INDEX IF NOT EXISTS idx_sales_items_item_id_invoice_id (item_id, invoice_id);

ALTER TABLE sales_return_items
  ADD INDEX IF NOT EXISTS idx_sri_return_line (sales_return_id, line_no),
  ADD INDEX IF NOT EXISTS idx_sri_invoice_item (sales_invoice_item_id);

ALTER TABLE purchase_invoice_lines
  ADD INDEX IF NOT EXISTS idx_pil_invoice_id_id (invoice_id, id),
  ADD INDEX IF NOT EXISTS idx_pil_item_id_invoice_id (item_id, invoice_id);

ALTER TABLE purchase_return_lines
  ADD INDEX IF NOT EXISTS idx_prl_return_id_id (return_id, id),
  ADD INDEX IF NOT EXISTS idx_prl_item_id_return_id (item_id, return_id);
