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

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';
