UPDATE proformas AS p
JOIN document_series AS ds
  ON ds.code = p.target_invoice_series_code
 AND ds.document_type = 'proforma'
SET
  p.target_invoice_series_code = NULL,
  p.updated_at = NOW()
WHERE p.target_invoice_series_code IS NOT NULL;

SELECT p.id, p.proforma_reference, p.target_invoice_series_code
FROM proformas AS p
JOIN document_series AS ds
  ON ds.company_id = p.company_id
 AND ds.code = p.target_invoice_series_code
WHERE ds.document_type = 'proforma';
