Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. select
  2. baseProdutos.produto as codigoProduto,
  3. p.descricaoGenerica as descricaoProduto,
  4. baseProdutos.numeroSerie,
  5. baseProdutos.quantidade as saldoAnterior,
  6. (select
  7. ifnull(sum(quantidade),0)
  8. from movimentoEstoque
  9. where produto=baseProdutos.produto
  10. and numeroSerie=baseProdutos.numeroSerie
  11. and data between $P!{P_DATAINICIAL} and $P!{P_DATAFINAL}
  12. and estoque = $P{P_ESTOQUE}
  13. and tipoMovimento = 'E'
  14. ) as entradas,
  15. (select
  16. ifnull(sum(quantidade),0)
  17. from movimentoEstoque
  18. where produto=baseProdutos.produto
  19. and numeroSerie=baseProdutos.numeroSerie
  20. and data between $P!{P_DATAINICIAL} and $P!{P_DATAFINAL}
  21. and estoque = $P{P_ESTOQUE}
  22. and tipoMovimento = 'S'
  23. ) as saidas,
  24.  
  25. (
  26. select count(*)
  27. from rastreioEstoque re inner join itemRastreioEstoque ir
  28. on ir.rastreioEstoque = re.id
  29. where re.estoque=$P{P_ESTOQUE}
  30. and re.dataEmissaoDocumento between $P!{P_DATAINICIAL} and $P!{P_DATAFINAL}
  31. and ir.produto = baseProdutos.produto
  32. and ir.numeroSerie = baseProdutos.numeroSerie
  33.  
  34. ) as rastreios
  35.  
  36. from
  37. (
  38. select distinct
  39. produto,
  40. numeroSerie,
  41. quantidade
  42. from
  43. (
  44. select
  45. produto,
  46. numeroSerie,
  47. quantidade
  48. from movimentoEstoque
  49. where estoque=$P{P_ESTOQUE}
  50. and data<$P!{P_DATAINICIAL}
  51. and tipoMovimento = 'E'
  52. union all
  53. select
  54. produto,
  55. numeroSerie,
  56. quantidade *-1
  57. from movimentoEstoque
  58. where estoque=$P{P_ESTOQUE}
  59. and data<$P!{P_DATAINICIAL}
  60. and tipoMovimento = 'S'
  61. ) as tbSaldo
  62. group by produto, numeroSerie
  63. having sum(quantidade)>0
  64. union all
  65. select
  66. produto,
  67. numeroSerie ,
  68. 0
  69. from movimentoEstoque me
  70. where estoque = $P{P_ESTOQUE}
  71. and data between $P!{P_DATAINICIAL} and $P!{P_DATAFINAL}
  72. ) as baseProdutos inner join produto p on p.id = baseProdutos.produto
  73.  
  74. where 0=0 $P!{WHERE}
  75. $P!{ORDERBY}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement