Skip to content

Commit

Permalink
Fix buyin count updating all products
Browse files Browse the repository at this point in the history
  • Loading branch information
ArktinenKarpalo committed Mar 12, 2024
1 parent b406a21 commit 1f89224
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/db/boxStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,26 @@ module.exports.buyIn = async (boxBarcode, boxCount) => {
.leftJoin('PRICE', 'RVBOX.itembarcode', 'PRICE.barcode')
.leftJoin('RVITEM', 'PRICE.itemid', 'RVITEM.itemid')
.where('RVBOX.barcode', boxBarcode)
.first('RVBOX.itemcount', 'PRICE.priceid', 'PRICE.count');
.first(
'RVBOX.itemcount',
'PRICE.priceid',
'PRICE.count',
'PRICE.barcode',
);

if (row === undefined) {
return undefined;
}

const { count, itemcount, priceid } = row;
const { count, itemcount, priceid, barcode } = row;

const newCount = count + itemcount * boxCount;

await knex('PRICE')
.transacting(trx)
.select({ priceid, endtime: null })
.update({ count: newCount });
.update({ count: newCount })
.where('PRICE.barcode', barcode);

return newCount;
});
Expand Down

0 comments on commit 1f89224

Please sign in to comment.