Original Query
SELECT DISTINCT
IP.op_code as ip_op_code,
IPH.op_code as iph_op_code,
debt_trans.tx_amount as cash,
DT.tx_amount as revenu
looking to your data could you join must match also for op_code AND instplanheader.op_code = instplan.op_code
$sql = "SELECT DISTINCT
instplan.debt_code,
instplan.op_code,
instplanheader.op_code as plan_op,
instplan.ipactualpaymentamt
FROM instplanheader
LEFT JOIN instplan ON instplanheader.debt_code=instplan.debt_code
AND instplanheader.op_code = instplan.op_code
AND instplan.tran_code NOT IN ('DR3001','DR3002','DR3003','DR3004')
AND instplan.ipactualpaymentamt > 0.00
AND instplan.ipactualpaymentdt >= '2019-02-04' AND instplan.ipactualpaymentdt <= '2019-02-04'
AND instplanheader.iphcreationdate >= '2018-12-01' AND instplanheader.iphcreationdate <= '2019-02-04'
";