To manage Stock in the POS System, We can build a View with the following Tables :
- Products
- Purchase Details
- Sell Details
- Purchase Return Details
- Sell Return Details
- Damage
CREATE OR REPLACE VIEW V_STOCK AS
SELECT A.PRODUCT_ID,
NVL(A.STOCK,0)
+NVL(B.QTY,0)
-NVL(C.QTY,0)
-NVL(D.QTY,0)
+NVL(E.QTY,0)
-NVL(F.QTY,0) CSTOCK
FROM
(SELECT PRODUCT_ID,STOCK FROM PRODUCTS) A,
(SELECT PRODUCT,SUM(QTY) QTY FROM PURCHASE_DETAILS GROUP BY PRODUCT) B,
(SELECT PRODUCT,SUM(QTY) QTY FROM SALES_DETAILS GROUP BY PRODUCT) C,
(SELECT PRODUCT,SUM(QTY) QTY FROM PURCHASE_RETURN_DETAILS GROUP BY PRODUCT) D,
(SELECT PRODUCT,SUM(QTY) QTY FROM SALES_RETURN_DETAILS GROUP BY PRODUCT) E,
(SELECT PRODUCT,SUM(QTY) QTY FROM DAMAGE GROUP BY PRODUCT) F
WHERE A.PRODUCT_ID=B.PRODUCT(+)
AND A.PRODUCT_ID=C.PRODUCT(+)
AND A.PRODUCT_ID=D.PRODUCT(+)
AND A.PRODUCT_ID=E.PRODUCT(+)
AND A.PRODUCT_ID=F.PRODUCT(+);
You can create a LOV with the following Query in Oracle Forms and Apex:
SELECT A.PRODUCT_ID ,A.PRODUCT_CODE ,A.PRODUCT_NAME ,A.CATEGORIES ,A.SUB_CATEGORIES ,A.UNIT_TYPE ,A.BRAND
,A.STOCK ,A.BUY_PRICE ,A.SELL_PRICE ,A.ENTRY_BY ,A.ENTRY_DATE ,A.UPDATE_BY ,A.UPDATE_DATE,B.CSTOCK
FROM
(SELECT PRODUCT_ID ,PRODUCT_CODE ,PRODUCT_NAME ,CATEGORIES ,SUB_CATEGORIES ,UNIT_TYPE ,BRAND
,STOCK ,BUY_PRICE ,SELL_PRICE ,ENTRY_BY ,ENTRY_DATE ,UPDATE_BY ,UPDATE_DATE
FROM PRODUCTS) A,
(SELECT PRODUCT_ID,CSTOCK FROM V_STOCK) B
WHERE A.PRODUCT_ID=B.PRODUCT_ID;
You can create report with the above query also.