Option selling PNL

I sold one lot of Banknifty (lot size 15) 47000 ce @ 190.75 and paid margin of Rs 86389.51/ and buy it back before expiry @ 348.8 , incurring net loss of Rs 2370.75.

Now as mentioned on zerodha varsity call option selling module that on expiry option seller losses his premium first then incur losses out of his own pocket.

But for this case where position is closed before expiry
premium received for selling option = 190.75*15=>Rs 2861.25/
losses incurred on buy to close = (348.8-190.75)*15=>Rs 2370.75/

So , Am I still in profit of =2861.25-2370.75=> Rs490.5/
Pls correct me if I am getting it wrong.

You are buying at 348.8, so buy value is 348.8*15=5232.
Your sell value = 2370.75.
So total loss = 5232-2370=2862 is the loss.