export const CHECK_MANIFESTARTICLE_ACCESS = ` SELECT ma.id FROM manifestarticle ma INNER JOIN manifest m ON ma.manifest_id = m.id WHERE ma.id = @manifestarticleId AND m.company_id = @companyId; `; export const GET_LATEST_ROW = ` SELECT TOP 1 id, manifestarticle_id, transaction_type, amount, transaction_text, hash_version, prev_hash, created_at FROM ledger WITH (UPDLOCK, HOLDLOCK) ORDER BY id DESC; `; export const INSERT_ROW = ` INSERT INTO ledger ( manifestarticle_id, transaction_type, amount, transaction_text, hash_version, prev_hash ) OUTPUT INSERTED.id, INSERTED.manifestarticle_id, INSERTED.transaction_type, INSERTED.amount, INSERTED.transaction_text, INSERTED.hash_version, INSERTED.prev_hash, INSERTED.created_at VALUES ( @manifestarticleId, @transactionType, @amount, @transactionText, @hashVersion, @prevHash ); `; export const LIST_BY_MANIFESTARTICLE = ` SELECT l.id, l.manifestarticle_id, ma.sku, l.transaction_type, l.amount, l.transaction_text, l.hash_version, l.prev_hash, l.created_at FROM ledger l INNER JOIN manifestarticle ma ON l.manifestarticle_id = ma.id INNER JOIN manifest m ON ma.manifest_id = m.id WHERE l.manifestarticle_id = @manifestarticleId AND m.company_id = @companyId AND (@transactionType IS NULL OR l.transaction_type = @transactionType) ORDER BY l.id ASC; `; export const LIST_BY_SKU = ` SELECT l.id, l.manifestarticle_id, ma.sku, l.transaction_type, l.amount, l.transaction_text, l.hash_version, l.prev_hash, l.created_at FROM ledger l INNER JOIN manifestarticle ma ON l.manifestarticle_id = ma.id INNER JOIN manifest m ON ma.manifest_id = m.id WHERE ma.sku = @sku AND m.company_id = @companyId AND (@transactionType IS NULL OR l.transaction_type = @transactionType) ORDER BY l.id ASC; `;