WHAT IS ALAN ?

I am late to the party. I started watching the show about a couple weeks ago so far I’m up to season six. I just don’t understand Alan’s character like what is it? In Some of the episodes I feel so sorry for him , feel like why everything going so wrong with him but in some of the episodes, I just wanna jump into the screen and start beating the shit out of him. Sometimes he have such a good thing going on for him and he manages to fuck it up within a blink of an eye he won the lotto. He got a beautiful girl and then he managed to fuck that up and then in season six he is with his receptionist she’s such a sweet girl and she’s ready to deal with his problem. She’s being so understanding with him and really want to be with the guy and yet he manages to fuck it up by getting in bed with her mother what is wrong with this guy? I don’t really understand the character like what’s going on there ?