Ported credit invoice return stock cogs difference posting code from official sql-ledger 3.0.6