Need help to make a condition

This is query :

SELECT f.matName
       ,f.matCode
       ,COALESCE(SUM(`INPUT`), 0) - COALESCE(SUM(`OUTPUT`), 0) AS `INVENTORY`
       ,f.unitPrice
       ,(COALESCE(SUM(`INPUT`), 0) - COALESCE(SUM(`OUTPUT`), 0))
        * (COALESCE(unitPrice, 0)) AS `RialiInventory`

FROM (
---subquery---
) AS `f`
GROUP BY f.matName
         ,f.matCode

In above query if (INVENTORY) value be less than “0” , then (RialiInventory) will be a negative value but I need to return “0” value for those (RialiInventory) values that their (INVENTORY) values are less than “0” .

Note : I don`t want miss any (INVENTORY) value .

thanks in advance

SELECT matName
     , matCode
     , inventory
     , unitPrice
     , CASE WHEN inventory < 0
            THEN 0
            ELSE inventory * COALESCE(unitPrice, 0) 
         END   AS RialiInventory
  FROM ( SELECT matName
              , matCode
              , COALESCE(SUM(`input`), 0) - 
                COALESCE(SUM(`output`), 0) AS inventory
              , unitPrice
           FROM (
                ---subquery---
                ) AS f
         GROUP 
             BY f.matName
              , f.matCode
              , f.unitPrice ) AS x