Last active
July 20, 2018 21:49
-
-
Save dhyegocalota/71455141860039b8974a45a2a7678679 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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