export const CHECK_MANIFESTARTICLE_ACCESS = ` SELECT ma.id, ma.sku, ma.amount AS lineAmount, ma.net, ma.rebate, ma.taxrate, m.id AS manifestId, m.[number] AS manifestNumber, m.[type] AS manifestType, m.external_number AS externalNumber, e.name AS supplierName FROM manifestarticle ma INNER JOIN manifest m ON ma.manifest_id = m.id LEFT JOIN entity e ON e.id = m.entity_id WHERE ma.id = @manifestarticleId AND m.company_id = @companyId; `; export const CHECK_WAREHOUSE_ACCESS = ` SELECT id, name FROM warehouse WHERE id = @warehouseId AND company_id = @companyId; `; export const FIND_ARTICLES_FOR_HISTORY = ` SELECT DISTINCT asup.article_id AS articleId FROM articlesupplier asup INNER JOIN entity e ON e.id = asup.entity_id INNER JOIN customergroup cg ON cg.id = e.customergroup_id WHERE asup.sku = @sku AND cg.company_id = @companyId; `; export const INSERT_ARTICLE_HISTORY = ` INSERT INTO articlehistory (article_id, companyuser_id, [text]) VALUES (@articleId, @companyuserId, @text); `; export const GET_LATEST_ROW = ` SELECT TOP 1 id, manifestarticle_id, warehouse_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, warehouse_id, transaction_type, amount, transaction_text, hash_version, prev_hash ) OUTPUT INSERTED.id, INSERTED.manifestarticle_id, INSERTED.warehouse_id, INSERTED.transaction_type, INSERTED.amount, INSERTED.transaction_text, INSERTED.hash_version, INSERTED.prev_hash, INSERTED.created_at VALUES ( @manifestarticleId, @warehouseId, @transactionType, @amount, @transactionText, @hashVersion, @prevHash ); `; export const LIST_BY_MANIFESTARTICLE = ` SELECT l.id, l.manifestarticle_id, l.warehouse_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) AND (@warehouseId IS NULL OR l.warehouse_id = @warehouseId) ORDER BY l.id ASC; `; export const LIST_BY_SKU = ` SELECT l.id, l.manifestarticle_id, l.warehouse_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) AND (@warehouseId IS NULL OR l.warehouse_id = @warehouseId) ORDER BY l.id ASC; `;