Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- baseProdutos.produto as codigoProduto,
- p.descricaoGenerica as descricaoProduto,
- baseProdutos.numeroSerie,
- baseProdutos.quantidade as saldoAnterior,
- (select
- ifnull(sum(quantidade),0)
- from movimentoEstoque
- where produto=baseProdutos.produto
- and numeroSerie=baseProdutos.numeroSerie
- and data between $P!{P_DATAINICIAL} and $P!{P_DATAFINAL}
- and estoque = $P{P_ESTOQUE}
- and tipoMovimento = 'E'
- ) as entradas,
- (select
- ifnull(sum(quantidade),0)
- from movimentoEstoque
- where produto=baseProdutos.produto
- and numeroSerie=baseProdutos.numeroSerie
- and data between $P!{P_DATAINICIAL} and $P!{P_DATAFINAL}
- and estoque = $P{P_ESTOQUE}
- and tipoMovimento = 'S'
- ) as saidas,
- (
- select count(*)
- from rastreioEstoque re inner join itemRastreioEstoque ir
- on ir.rastreioEstoque = re.id
- where re.estoque=$P{P_ESTOQUE}
- and re.dataEmissaoDocumento between $P!{P_DATAINICIAL} and $P!{P_DATAFINAL}
- and ir.produto = baseProdutos.produto
- and ir.numeroSerie = baseProdutos.numeroSerie
- ) as rastreios
- from
- (
- select distinct
- produto,
- numeroSerie,
- quantidade
- from
- (
- select
- produto,
- numeroSerie,
- quantidade
- from movimentoEstoque
- where estoque=$P{P_ESTOQUE}
- and data<$P!{P_DATAINICIAL}
- and tipoMovimento = 'E'
- union all
- select
- produto,
- numeroSerie,
- quantidade *-1
- from movimentoEstoque
- where estoque=$P{P_ESTOQUE}
- and data<$P!{P_DATAINICIAL}
- and tipoMovimento = 'S'
- ) as tbSaldo
- group by produto, numeroSerie
- having sum(quantidade)>0
- union all
- select
- produto,
- numeroSerie ,
- 0
- from movimentoEstoque me
- where estoque = $P{P_ESTOQUE}
- and data between $P!{P_DATAINICIAL} and $P!{P_DATAFINAL}
- ) as baseProdutos inner join produto p on p.id = baseProdutos.produto
- where 0=0 $P!{WHERE}
- $P!{ORDERBY}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement