807f6c2087
feat: add purchase receipts management with create, update, find, and delete functionalities feat: implement sales invoice items management with create, update, find, and delete functionalities feat: add sales invoices management with create, update, find, and delete functionalities feat: implement stock adjustments management with create, update, find, and delete functionalities feat: add stock balance retrieval functionality feat: implement stock movements management with create, update, find, and delete functionalities
18 lines
594 B
SQL
18 lines
594 B
SQL
SELECT
|
|
`pos`.`Stock_Movements`.`productId` AS `productId`,
|
|
`pos`.`Stock_Movements`.`inventoryId` AS `inventoryId`,
|
|
sum(
|
|
(
|
|
CASE
|
|
WHEN (`pos`.`Stock_Movements`.`type` = 'IN') THEN `pos`.`Stock_Movements`.`quantity`
|
|
WHEN (`pos`.`Stock_Movements`.`type` = 'OUT') THEN -(`pos`.`Stock_Movements`.`quantity`)
|
|
WHEN (`pos`.`Stock_Movements`.`type` = 'ADJUST') THEN `pos`.`Stock_Movements`.`quantity`
|
|
ELSE 0
|
|
END
|
|
)
|
|
) AS `stock`
|
|
FROM
|
|
`pos`.`Stock_Movements`
|
|
GROUP BY
|
|
`pos`.`Stock_Movements`.`productId`,
|
|
`pos`.`Stock_Movements`.`inventoryId` |