Skip to content

Instantly share code, notes, and snippets.

@dhyegocalota
Last active July 20, 2018 21:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhyegocalota/71455141860039b8974a45a2a7678679 to your computer and use it in GitHub Desktop.
Save dhyegocalota/71455141860039b8974a45a2a7678679 to your computer and use it in GitHub Desktop.
// var products = [{ sku: 1 }, { sku: 2 }]; // Sample data (SKU of products from Magento Database)
var productsSku = products
.map(product => (product.sku || '').toString())
.map(sku => sku.split(' ').filter(node => node.match(/^\S+$/)))
.reduce((acc, target) => Array.prototype.concat.apply(acc, target))
.filter((value, index, self) => self.indexOf(value) === index)
.map(sku => `'${sku}'`)
.sort((x, y) => x - y)
.join(', ');
console.log(`
SELECT
Produtos.Codigo,
Produtos.Descricao,
Produtos.DataCad,
ProdutosEstoque.LJ01,
ProdutosEstoque.LJ03,
ProdutosEstoque.LJ05,
ProdutosEstoque.LJ07
FROM
virtual.dbo.Produtos_Todos AS Produtos
INNER JOIN
virtual.dbo.ProdutosEstoque AS ProdutosEstoque
ON (ProdutosEstoque.Produto = Produtos.Codigo)
WHERE
ProdutosEstoque.LJ03 > 0
AND Produtos.Codigo NOT IN (${productsSku})
ORDER BY
Produtos.Descricao ASC
`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment