Two points:
You seem to be completely misusing purchase invoices. A purchase invoice is not an account. It records the amount paid to a supplier. It has nothing to do with your margin, which you determine independently. See the Guide:
https://forum.manager.io/t/creating-purchase-invoices/7189
Manager uses the average cost method. You cannot change that.
And your copied-and-pasted tutorial was completely unnecessary.