Try this:

=IFERROR(IF(AND(CM39=1,FIND("completed",W39)>0,AA39<>"Payment On Account"),1,0),0)