Once your opportunity process is complete, you can close an opportunity as won or lost using the ribbon buttons.

This is a sample to do it with
code
If my response helps you in finding your answer then please click 'Mark as Answer' and 'Vote as Helpful'