-3
I have a stock value and need to display the information of the stock movement based on invoice.
Table Drive
Cod | Tipo | NumeroNota | Quantidade | DataEmissao | Material
1 | S | 12312 | 1 | 2019-05-16 | 1
2 | S | 12313 | 4 | 2019-05-17 | 1
3 | E | 12316 | 10 | 2019-05-17 | 1
4 | S | 12317 | 9 | 2019-05-18 | 1
5 | S | 12323 | 6 | 2019-05-20 | 1
6 | S | 12325 | 12 | 2019-05-20 | 1
7 | E | 12333 | 3 | 2019-05-24 | 1
The column Tipo
refers to the entry and exit, represented by the initial letters..
Historical Stock Table
Cod | DataEstoque | Quantidade | Material
1 | 2019-05-16 | 24 | 1 -> Antes da data tinha 25
2 | 2019-05-17 | 30 | 1
3 | 2019-05-18 | 21 | 1
4 | 2019-05-19 | 21 | 1
5 | 2019-05-20 | 3 | 1
... -> repete a mesma quantidade para os dias sem movimentação
9 | 2019-05-24 | 6 | 1
Having knowledge of the table above, what I imagine is to take the stock in the table HistoricoEstoque
based on the final date (HistoricoEstoque.DataEstoque = @DataFim
), so I have access to stock amount on order date. Join with table Movimentacao
in order to find the amount moved between the interval @DataInicio
and @DataFim
making a stock rule observing the Type of Movement (Input (E) and Output (S)).
As the quantidade
is from the data fim
stock, resalto that for each drive Tipo = E
should be subtracted(-) and to output(+). That is, because it is doing the opposite.
I want to know, the stock and the movement of the material in the interval of two dates.
Expected result: Filter: Start date = 2019-05-17 and end date = 2019-05-20
Material|DataEmissao|Quantidade|EstoqueAtual
1 |2019-05-20 | -12 | 3 -> tenha ser o estoque atual
1 |2019-05-20 | -6 | 15
1 |2019-05-18 | -9 | 21
1 |2019-05-17 | 10 | 30
1 |2019-05-17 | -4 | 20
1 |2019-05-16 | - | 24
What is possible to do? There is another suggestion?
Calm people, I am changing the question. The guys are negative without at least informing the reason, it is complicated to please the people here. @Sorack really lacks details, I’m completing.
– EmanuelF
The answer helped solve the problem and can solve similar questions of other users? If positive do not forget to mark as accepted. To do this just click on the left side of it (below the indicator of up and down votes).
– Sorack