then friend, you should check the condition, it may be that you are not entering the condition, that's why you never generate it ... within the if you must put something to prove whether I enter or not, for example:
<?php
if(isset($_POST["boton4"]))
{
$finalcode = 'RV-'.createRandomPassword();
echo "<script> console.log('$finalcode');</script>";
//header("location: ventas.php?codventa='".$finalcode."'");
}
?>
in this case you will be printed in console the value of variabe $finalcode
(if you do not know how to remove the console from the browser with F12 and in the tabs it says console) there you will notice if it is entering the if, detail that comment the hearde so you do not redirect, because if you let it redirect you and it will not let you see. You tell me what happened.