COGS Wrongly being debited at the time of booking Purchase

We are a trading co. and booking purchase after PO, expense account in Purchase invoice is Stock in Hand. But when I submit the purchase Invoice and see the Accounting ledger it debited the COGS account instead of Stock Account. ( out of stock of 50000, 40000 is debited to COGS and 1000 is debited to the stock account.)
which results in a loss in P&l as COGS is also being debited at the time of making sales for the same item.

This is expense head while making purchase invoice.