From what I perceive let me explain with an example, mods clarify if I am wrong.
Take a company x for example trading at around 110.
A month ago I bought 100 shares of company x at 110rs so total inestment = 110*100 = 11000
Now lets say today the same share was trading at 100 rs. I sell 50 of my shares at 100rs in the morning. Later in the same day prices fell to 90 and I again bought 25 shares at 90 rs.
So total profit in this case = 25 * 100 - 25 * 90 = 250rs at EOD which would be credited to your account.
Also you would be NET short 25 shares so 25 shares would be deducted from your holding and you would have only 75 shares at an average of 110 rs. Also you would have loss because the 25 shares you bought a month earlier at 110 were sold now at 100. This loss of course would be to your overall holding position. Since the stock is down so would be your profile value on the 75 remaining shares but on the 25 shares you sold you have realized the loss which amounts to 25 * (110-100) = 250rs.
Also in this case an additional amount of 25*100 would be credited to your account as this the amount you receive from selling your 25 share which were in your holding.
Now lets say today the same share was trading at 100 rs. I sell 50 of my shares at 100rs in the morning. Later in the same day prices fell to 90 and I again bought 25 shares at 90 rs. Again the share prices are down to 85 and I again bought 25 shares at 85rs.
So total profit in this case = 50 * 100 - 25 * 90 - 25 * 85 = 625 at EOD credited to account.
In this case all the share I sold in the morning I have covered at the end of the day so no share’s would be deducted from my account.
In this case since the share prices are down my entire portfolio of the share X would be down but I would have realized a gain of 625rs which would be credited to my account.
The simplest way to look at these trades is to see them as intraday and make your calculations as such if your total sell vs buy number of shares are equal.
Also charges have not been taken into account so keep that in mind. Also with respect to case 1 there would be an additional deduction of around 15rs (depository charges) as 25 shares are deducted from your holdings.