# RPT_MASTER

rpt_SQLScript:
SELECT (B.V_QTY+V_GIVE_QTY) AS V_QTY2,a.*,b.*,(b.qty+b.give_qty)*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
       (B.B_PRICE-B.V_PRICE)*B.QTY AS U_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM INSTORAGE_MASTER a INNER JOIN INSTORAGE_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT (b.V_QTY+b.V_GIVE_QTY) AS V_QTY2,a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
(B.B_PRICE-B.V_PRICE)*B.V_QTY AS U_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA 
FROM INSTORAGEBK_MASTER a inner JOIN INSTORAGEBK_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT A.*,B.CUST_CLASSNAME,C.EMPLOYEE_NAME FROM CUSTOMER A
LEFT OUTER JOIN CUST_CLASS B
ON A.CUST_CLASSID = B.CUST_CLASSID
LEFT OUTER JOIN EMPLOYEE C
ON A.SALES_ID = C.EMPLOYEE_ID
WHERE A.CUST_ID BETWEEN :SID AND :EID
ORDER BY A.CUST_ID


rpt_SQLScript:
SELECT A.*,'GN'||A.CARD_ID AS CARD FROM MEMBER A 
WHERE A.MEMBER_ID BETWEEN :SID AND :EID
ORDER BY A.MEMBER_ID


rpt_SQLScript:
SELECT A.*,B.* FROM PSALE_MASTER A ,PSALE_SUB B
WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.MASTERBILLID = :SID


rpt_SQLScript:
SELECT A.*,B.* FROM PSALE_MASTER A,PSALE_SUB B
WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.MASTERBILLID = :SID


rpt_SQLScript:
SELECT PROD_ID,PROD_NAME,STD_COST,UNITNAME,
       PROVIDER_ID,PROVIDER_NAME,PROD_BARCODE,
       SALE_PRICE,PSALE_PRICE,VIP_PRICE,NOW_QTY,
       FIRST_COST,STD_COST,AVG_COST,P_LTCOST,
       PACK1_QTY,PACK2_QTY,PACK1,PACK2,
       (PACK1_QTY*PACK2_QTY) AS  PACK3_QTY,
       (STD_COST*PACK1_QTY) AS PACK1_COST, 
       ((STD_COST*PACK1_QTY)*PACK2_QTY) AS PACK2_COST,
       PUT_ID,PUT_FACE,PUT_X,PUT_Y
FROM PRODUCT
WHERE PROVIDER_ID =:SID  
ORDER  BY  PROD_BARCODE,PROD_ID


rpt_SQLScript:
SELECT PROD_ID,PROD_BARCODE,PROD_NAME,UNITNAME,
       STD_COST,AVG_COST,
       NOW_QTY,PD_ITEMID,PD_ITEMNAME,PSALE_PRICE,VIP_PRICE,
       PACK1_QTY,PACK2_QTY,PACK1,PACK2,
       (PACK1_QTY*PACK2_QTY) AS  PACK3_QTY,
       (STD_COST*PACK1_QTY) AS PACK1_COST, 
       ((STD_COST*PACK1_QTY)*PACK2_QTY) AS PACK2_COST,
       (STD_COST*NOW_QTY) AS S_COST, 
       (AVG_COST*NOW_QTY) AS A_COST,
       (PSALE_PRICE*NOW_QTY) AS T_PRICE 
FROM PRODUCT
WHERE DEL_FLAG = 'False'
  AND PD_ITEMID BETWEEN :SID AND :EID
ORDER  BY  PD_ITEMID,PROD_ID


rpt_SQLScript:
SELECT a.* ,b.PROD_ID,b.PROD_NAME,B.STD_COST
FROM PD_BOM a,PRODUCT b
WHERE a.PROD_ID = b.PROD_ID
  AND a.PROD_ID BETWEEN :SID AND :EID
ORDER BY a.PROD_ID,a.DE_PRODID


rpt_SQLScript:
SELECT (b.v_qty+v_give_qty) as V_QTY2,a.*,b.*,c.*,b.B_PRICE*b.V_QTY AS B_AMT,
(b.B_PRICE*b.V_QTY)-(b.V_PRICE*b.V_QTY) AS C_AMT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOT_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA,
d.CARTER_NAME
FROM SAL_MASTER a INNER JOIN SAL_SUB b ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN CUSTOMER C ON A.CUST_ID  = C.CUST_ID
LEFT OUTER JOIN CARTER   D ON A.CARTER_ID = D.CARTER_ID
WHERE a.MASTERBILLID >=:SID
  AND a.MASTERBILLID <=:EID
ORDER BY a.MASTERBILLID,b.KEYINTIME


rpt_SQLScript:
SELECT (B.V_QTY+B.V_GIVE_QTY) AS V_QTY2,a.*,b.*,c.*,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA,
D.EMPLOYEE_NAME,e.CARTER_NAME
FROM SALBK_MASTER a INNER JOIN SALBK_SUB b ON      a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN CUSTOMER C ON A.CUST_ID  = C.CUST_ID
LEFT OUTER JOIN EMPLOYEE D ON A.CHG_USER = D.EMPLOYEE_ID
LEFT OUTER JOIN CARTER   E ON A.CARTER_ID = E.CARTER_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,c.*
FROM QUOT_MASTER a,QUOT_SUB b,PROVIDER c 
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.PROVIDER_ID  = c.PROVIDER_ID
  AND a.MASTERBILLID =:SID
ORDER BY b.PROD_ID


rpt_SQLScript:
SELECT a.*,b.*,c.*,(b.V_QTY+V_GIVE_QTY) as V_QTY2,
D.EMPLOYEE_NAME AS CHG_NAME,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM ORDER_MASTER a LEFT OUTER JOIN EMPLOYEE D ON A.CHG_USER = D.EMPLOYEE_ID,ORDER_SUB b,CUSTOMER c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.CUST_ID      = c.CUST_ID
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.* 
FROM ASM_MASTER a,ASM_SUB b
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.MASTERBILLID =:SID
ORDER BY b.D_PROD_ID


rpt_SQLScript:
SELECT a.*,b.*,
(c.TOTAL_DISCOUNT+c.TOTAL_DISCOUNT2) as DISCOUNT, 
(d.TOTAL_DISCOUNT+d.TOTAL_DISCOUNT2) as BK_DISCOUNT
FROM PAY_MASTER a LEFT OUTER join PAY_SUB b  
                   on  a.MASTERBILLID = b.MASTERBILLID
     LEFT OUTER join INSTORAGE_MASTER c  
                   on  b.TRAN_BILLID = c.MASTERBILLID
                   and b.FLAG =  c.FLAG
     LEFT OUTER join INSTORAGEBK_MASTER D  
                   on  b.TRAN_BILLID = d.MASTERBILLID
                   and b.FLAG =  d.FLAG
WHERE a.MASTERBILLID =:SID
ORDER BY b.FLAG,b.TRAN_BILLID


rpt_SQLScript:
SELECT a.*,b.* 
FROM REC_MASTER a,REC_SUB b
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.MASTERBILLID =:SID
ORDER BY b.FLAG,b.TRAN_BILLID


rpt_SQLScript:
SELECT * FROM MEMBER WHERE MEMBER_ID BETWEEN :SID AND :EID
ORDER BY MEMBER_ID


rpt_SQLScript:
SELECT * FROM CUSTOMER
WHERE CUST_ID BETWEEN :SID AND :EID
ORDER BY CUST_ID


rpt_SQLScript:
SELECT * FROM PROVIDER
WHERE PROVIDER_ID BETWEEN :SID AND :EID
ORDER BY PROVIDER_ID


rpt_SQLScript:
SELECT a.*,b.*,(b.qty+b.give_qty)*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
       (B.B_PRICE-B.V_PRICE)*B.QTY AS U_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM INSTORAGE_MASTER a inner JOIN INSTORAGE_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
(B.B_PRICE-B.V_PRICE)*B.V_QTY AS U_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA 
FROM INSTORAGEBK_MASTER a inner JOIN INSTORAGEBK_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT A.*,B.*,C.*,CAST(B.BILL_DATE AS DATE)+1 AS VDATE 
FROM CUSTOMER A INNER JOIN SAL_MASTER B 
  ON A.CUST_ID = B.CUST_ID
                INNER JOIN SAL_SUB C 
ON B.MASTERBILLID = C.MASTERBILLID
WHERE A.CUST_ID IN
(SELECT CUST_ID FROM SAL_MASTER WHERE MASTERBILLID = :SID)
AND B.MASTERBILLID = :SID


rpt_SQLScript:
SELECT a.*,b.*,c.*,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM SAL_MASTER a,SAL_SUB b,CUSTOMER c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.CUST_ID      = c.CUST_ID
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,c.* 
FROM SAL_MASTER a,SAL_SUB b,CUSTOMER c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.CUST_ID      = c.CUST_ID
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT * FROM PRODUCT
WHERE STOCK_QTY = 'Y'
  AND PSALE_PRICE < AVG_COST
  AND PD_ITEMID BETWEEN :SID AND :EID
ORDER BY PD_ITEMID,PROD_BARCODE,PROD_ID


rpt_SQLScript:
SELECT * FROM PRODUCT
WHERE STOCK_QTY = 'Y'
  AND PSALE_PRICE < STD_COST
  AND PD_ITEMID BETWEEN :SID AND :EID
ORDER BY PD_ITEMID,PROD_BARCODE,PROD_ID


rpt_SQLScript:
SELECT * FROM PRODUCT
WHERE PD_ITEMID BETWEEN :SID AND :EID
  AND STOCK_QTY =:TID
ORDER BY PD_ITEMID,PROD_BARCODE,PROD_ID


rpt_SQLScript:
SELECT a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM BUYBILL_MASTER a inner JOIN BUYBILL_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT 
a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
(b.V_QTY+b.V_GIVE_QTY) AS V_QTY2,
(b.B_PRICE-b.V_PRICE)*b.QTY AS U_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA,
E.STOCK_NAME,F.PAYLIST_NAME
FROM BUYBILL_MASTER a inner JOIN BUYBILL_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D ON b.PROD_ID = D.PROD_ID
LEFT OUTER JOIN STOCK_ITEM E ON A.STOCK_ID = E.STOCK_ID
LEFT OUTER JOIN PAYLIST F ON C.PAYLIST_ID = F.PAYLIST_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT A.*,B.* FROM PTSALE_SUB B LEFT OUTER JOIN
PTSALE_MASTER A ON A.MASTERBILLID = B.MASTERBILLID
WHERE A.MASTERBILLID = :SID
ORDER BY B.PROD_BARCODE


rpt_SQLScript:
SELECT (B.V_QTY+B.V_GIVE_QTY) AS V_QTY2,a.*,b.*,c.*,b.STD_COST*b.QTY AS T_COST,
b.SALE_PRICE*b.QTY AS T_SAL,b.B_PRICE*b.V_QTY AS B_AMT,
(b.B_PRICE*b.V_QTY)-(b.V_PRICE*b.V_QTY) AS C_AMT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOT_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA,
d.EMPLOYEE_NAME,e.CARTER_NAME
FROM SAL_MASTER a INNER JOIN SAL_SUB b 
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN CUSTOMER C ON A.CUST_ID  = C.CUST_ID
LEFT OUTER JOIN EMPLOYEE D ON A.CHG_USER = D.EMPLOYEE_ID
LEFT OUTER JOIN CARTER   E ON A.CARTER_ID = E.CARTER_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM INSTORAGE_MASTER a inner JOIN INSTORAGE_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT (b.v_qty+b.v_give_qty) AS V_QTY2,a.*,b.*,(b.qty+b.give_qty)*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
       (B.B_PRICE-B.V_PRICE)*B.QTY AS U_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM INSTORAGE_MASTER a inner JOIN INSTORAGE_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT * FROM PRODUCT
WHERE DEL_FLAG = 'False'
  AND PROD_BARCODE BETWEEN :SID AND :EID
  
ORDER BY PROD_BARCODE


rpt_SQLScript:
SELECT a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE 
FROM BUYBILL_MASTER a inner JOIN BUYBILL_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.SOURCEID =:SID
ORDER BY A.MASTERBILLID,b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE 
FROM PETITION_MASTER a inner JOIN PETITION_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON B.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY A.MASTERBILLID,B.PROVIDER_ID,B.PROD_ID


rpt_SQLScript:
SELECT a.*,b.*,
cast(b.NOW_QTY*b.STD_COST as numeric(10,2)) as NS_COST,
cast(b.NOW_QTY*b.AVG_COST as numeric(10,2)) as NA_COST,
cast(b.OLD_QTY*b.STD_COST as numeric(10,2)) as OS_COST,
cast(b.OLD_QTY*b.AVG_COST as numeric(10,2)) as OA_COST,
cast(b.E_QTY*b.STD_COST as numeric(10,2)) as ES_COST,
cast(b.E_QTY*b.AVG_COST as numeric(10,2)) as EA_COST
FROM CHGQTY_MASTER a,CHGQTY_SUB b
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND (b.NOW_QTY <> 0 OR b.OLD_QTY<> 0)
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT * FROM CHGPRICE_MASTER A 
INNER JOIN CHGPRICE_SUB B
ON A.MASTERBILLID = B.MASTERBILLID
WHERE A.MASTERBILLID = :SID
ORDER BY B.PROD_ID


rpt_SQLScript:
SELECT a.*,b.*,
b.v_qty*b.v_price as t_cost,b.qty*D.Psale_price as t_price,D.PSALE_PRICE,b.v_qty * b.sale_price as all_sale 
FROM TRNOUT_MASTER a inner JOIN TRNOUT_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,
b.v_qty*b.v_price as t_cost,b.qty*D.Psale_price as t_price,D.PSALE_PRICE 
FROM TRNOUT_MASTER a inner JOIN TRNOUT_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT A.*,B.*,C.*,CAST(B.BILL_DATE AS DATE)+1 AS VDATE 
FROM CUSTOMER A INNER JOIN SAL_MASTER B ON A.CUST_ID =  B.CUST_ID
 INNER JOIN SAL_SUB C ON B.MASTERBILLID = C.MASTERBILLID
WHERE A.CUST_ID IN
(SELECT CUST_ID FROM SAL_MASTER WHERE MASTERBILLID = :SID)
AND B.MASTERBILLID = :SID


rpt_SQLScript:
SELECT a.*,b.*,
cast(b.NOW_QTY*b.STD_COST as numeric(10,2)) as NS_COST,
cast(b.NOW_QTY*b.AVG_COST as numeric(10,2)) as NA_COST,
cast(b.OLD_QTY*b.STD_COST as numeric(10,2)) as OS_COST,
cast(b.OLD_QTY*b.AVG_COST as numeric(10,2)) as OA_COST,
cast(b.E_QTY*b.STD_COST as numeric(10,2)) as ES_COST,
cast(b.E_QTY*b.AVG_COST as numeric(10,2)) as EA_COST
FROM CHGQTY_MASTER a,CHGQTY_SUB b
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND (b.E_QTY <> 0 OR b.OLD_QTY <> 0)
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,
b.v_qty*b.v_price as t_cost,b.qty*D.Psale_price as t_price,D.PSALE_PRICE 
FROM TRNIN_MASTER a inner JOIN TRNIN_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,
b.v_qty*b.v_price as t_cost,b.qty*D.Psale_price as t_price,D.PSALE_PRICE,b.sale_price*b.v_qty as all_sale 
FROM TRNIN_MASTER a inner JOIN TRNIN_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.* 
FROM CHGQTY_MASTER a,CHGQTY_SUB b
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.MASTERBILLID =:SID
AND b.e_qty <> 0
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,
cast(b.NOW_QTY*b.STD_COST as numeric(10,2)) as NS_COST,
cast(b.NOW_QTY*b.AVG_COST as numeric(10,2)) as NA_COST,
cast(b.OLD_QTY*b.STD_COST as numeric(10,2)) as OS_COST,
cast(b.OLD_QTY*b.AVG_COST as numeric(10,2)) as OA_COST,
cast(b.E_QTY*b.STD_COST as numeric(10,2)) as ES_COST,
cast(b.E_QTY*b.AVG_COST as numeric(10,2)) as EA_COST
FROM CHGQTY_MASTER a,CHGQTY_SUB b
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.MASTERBILLID =:SID
and b.E_QTY <> 0
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,
cast(b.NOW_QTY*b.STD_COST as numeric(10,2)) as NS_COST,
cast(b.NOW_QTY*b.AVG_COST as numeric(10,2)) as NA_COST,
cast(b.OLD_QTY*b.STD_COST as numeric(10,2)) as OS_COST,
cast(b.OLD_QTY*b.AVG_COST as numeric(10,2)) as OA_COST,
cast(b.E_QTY*b.STD_COST as numeric(10,2)) as ES_COST,
cast(b.E_QTY*b.AVG_COST as numeric(10,2)) as EA_COST
FROM CHGQTY_MASTER a,CHGQTY_SUB b
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.MASTERBILLID =:SID
  AND b.E_QTY <> 0
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT A.CUST_ID,C.CUST_NAME,A.PROD_ID,
B.PROD_NAME,B.PROD_BARCODE,B.P_LTCOST,A.U_PRICE,C.CHG_DATE 
FROM STORY_SAL a INNER JOIN PRODUCT b
     ON a.PROD_ID = b.PROD_ID
     LEFT OUTER JOIN CUSTOMER C ON A.CUST_ID = C.CUST_ID
WHERE a.CUST_ID BETWEEN :SID AND :EID
ORDER BY A.CUST_ID,A.PROD_ID


rpt_SQLScript:
SELECT A.*,B.* FROM INPROMOTION_MASTER A,INPROMOTION_SUB B
WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.MASTERBILLID = :SID


rpt_SQLScript:
SELECT * FROM CHGPRICE_MASTER A 
INNER JOIN CHGPRICE_SUB B
ON A.MASTERBILLID = B.MASTERBILLID
WHERE B.PROD_BARCODE BETWEEN :SID AND :EID
ORDER BY B.PROD_BARCODE,A.BILL_DATE DESC


rpt_SQLScript:
SELECT * FROM COLDIN_MASTER A,COLDIN_SUB B
WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.MASTERBILLID = :SID
ORDER BY A.MASTERBILLID


rpt_SQLScript:
SELECT * FROM COLDOUT_MASTER A,COLDOUT_SUB B
WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.MASTERBILLID = :SID


rpt_SQLScript:
SELECT a.*,b.*,c.*,b.STD_COST*b.QTY AS T_COST,
b.SALE_PRICE*b.QTY AS T_SAL
FROM ADMINISTER_MASTER a,ADMINISTER_SUB b,CUSTOMER c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.CUST_ID      = c.CUST_ID
  AND a.SOURCEID =:SID
ORDER BY a.MASTERBILLID,b.KEYINTIME


rpt_SQLScript:
SELECT PROJ_ID,PROD_ID,PROD_BARCODE,PROD_NAME,UNITNAME,
       STD_COST,AVG_COST,
       SUM(NOW_QTY) as NOW_QTY,
       SUM(OLD_QTY) as OLD_QTY,
       SUM(E_QTY)   as E_QTY,
SUM(cast(NOW_QTY*STD_COST as numeric(10,2))) as NS_COST,
SUM(cast(NOW_QTY*AVG_COST as numeric(10,2))) as NA_COST,
SUM(cast(OLD_QTY*STD_COST as numeric(10,2))) as OS_COST,
SUM(cast(OLD_QTY*AVG_COST as numeric(10,2))) as OA_COST,
SUM(cast(E_QTY*STD_COST as numeric(10,2))) as ES_COST,
SUM(cast(E_QTY*AVG_COST as numeric(10,2))) as EA_COST
FROM CHGQTY_SUB
WHERE PROJ_ID =:SID
GROUP BY PROJ_ID,PROD_ID,PROD_BARCODE,PROD_NAME,UNITNAME,
         STD_COST,AVG_COST        
ORDER BY PROD_BARCODE


rpt_SQLScript:
SELECT a.SAL_DATE,a.PD_ITEMID,SUM(a.QTY) AS QTY,
       SUM(a.R_AMT - a.T_COST) AS T_PROFIT,
       SUM(a.T_COST) AS T_COST,SUM(a.R_AMT) AS T_AMT,
       b.PD_ITEMNAME,c.PD_GRPNAME,d.TOP_ITEMNAME,
       d.TOP_ITEMID,c.PD_GRPID,b.PD_ITEMID
FROM X_DAYPOS_SUB a LEFT OUTER JOIN PROD_ITEM b  on                             a.PD_ITEMID = b.PD_ITEMID 
                    LEFT OUTER JOIN PROD_HIITEM c  on                           b.PD_GRPID  = c.PD_GRPID 
                    LEFT OUTER JOIN PROD_TOPITEM d on                           c.TOP_ITEMID  = d.TOP_ITEMID
WHERE a.SAL_DATE = :SID
GROUP BY a.SAL_DATE,a.PD_ITEMID,
         b.PD_ITEMID,b.PD_ITEMNAME,c.PD_GRPID,c.PD_GRPNAME,
         d.TOP_ITEMID,d.TOP_ITEMNAME
ORDER BY d.TOP_ITEMID,c.PD_GRPID,b.PD_ITEMID


rpt_SQLScript:
SELECT SAL_DATE,PD_TOPITEMID,PD_TOPITEMNAME,                
  SUM(BEFORE_COST) AS BEFORE_COST,
  SUM(INSTORAGE_AMT) AS INSTORAGE_AMT,
  SUM(INSTORAGEBK_AMT) AS INSTORAGEBK_AMT,
  SUM(SAL_COST+SALBK_COST) AS SAL_COST,
  SUM(POS_COST) AS POS_COST,
  SUM(VOID_COST) AS VOID_COST,
  SUM(NOW_COST) AS NOW_COST,
  SUM(TRNIN_AMT) AS TRNIN_AMT,
  SUM(TRNOUT_AMT) AS TRNOUT_AMT,
  SUM(DIF_COST) AS DIF_COST,
  SUM(CHG_COST) AS CHG_COST,
  SUM(END_COST) AS END_COST,

  SUM(BEFORE_COST1) AS BEFORE_COST1,
  SUM(INSTORAGE_AMT1) AS INSTORAGE_AMT1,
  SUM(INSTORAGEBK_AMT1) AS INSTORAGEBK_AMT1,
  SUM(SAL_COST1+SALBK_COST1) AS SAL_COST1,
  SUM(POS_COST1) AS POS_COST1,
  SUM(VOID_COST1) AS VOID_COST1,
  SUM(NOW_COST1) AS NOW_COST1,
  SUM(TRNIN_AMT1) AS TRNIN_AMT1,
  SUM(TRNOUT_AMT1) AS TRNOUT_AMT1,
  SUM(DIF_COST1) AS DIF_COST1,
  SUM(CHG_COST1) AS CHG_COST1,
  SUM(END_COST1) AS END_COST1,

  SUM(BEFORE_COST2) AS BEFORE_COST2,
  SUM(INSTORAGE_AMT2) AS INSTORAGE_AMT2,
  SUM(INSTORAGEBK_AMT2) AS INSTORAGEBK_AMT2,
  SUM(SAL_COST2+SALBK_COST2) AS SAL_COST2,
  SUM(POS_COST2) AS POS_COST2,
  SUM(VOID_COST2) AS VOID_COST2,
  SUM(NOW_COST2) AS NOW_COST2,
  SUM(TRNIN_AMT2) AS TRNIN_AMT2,
  SUM(TRNOUT_AMT2) AS TRNOUT_AMT2,
  SUM(DIF_COST2) AS DIF_COST2,
  SUM(CHG_COST2) AS CHG_COST2,
  SUM(END_COST2) AS END_COST2
FROM X_DAYACC_SUB 
WHERE SAL_DATE = :SID
GROUP BY SAL_DATE,PD_TOPITEMID,PD_TOPITEMNAME
ORDER BY PD_TOPITEMID


rpt_SQLScript:
SELECT SAL_DATE,PD_HIITEMID,PD_HIITEMNAME,
  SUM(BEFORE_COST) AS BEFORE_COST,
  SUM(INSTORAGE_AMT) AS INSTORAGE_AMT,
  SUM(INSTORAGEBK_AMT) AS INSTORAGEBK_AMT,
  SUM(SAL_COST+SALBK_COST) AS SAL_COST,
  SUM(POS_COST) AS POS_COST,
  SUM(VOID_COST) AS VOID_COST,
  SUM(NOW_COST) AS NOW_COST,
  SUM(TRNIN_AMT) AS TRNIN_AMT,
  SUM(TRNOUT_AMT) AS TRNOUT_AMT,
  SUM(DIF_COST) AS DIF_COST,
  SUM(CHG_COST) AS CHG_COST,
  SUM(END_COST) AS END_COST
FROM X_DAYACC_SUB 
WHERE SAL_DATE = :SID
GROUP BY SAL_DATE,PD_HIITEMID,PD_HIITEMNAME
ORDER BY PD_HIITEMID


rpt_SQLScript:
SELECT *  FROM X_DAYPOS_SUB 
WHERE SAL_DATE = :SID
  AND U_PROFIT < :EID
  AND STOCK_QTY = 'Y' 
ORDER BY U_PROFIT


rpt_SQLScript:
SELECT a.*,b.*,c.*,b.STD_COST*b.QTY AS T_COST,
b.SALE_PRICE*b.QTY AS T_SAL
FROM CIN_STOCK a,CIN_STOCKSUB b,CUSTOMER c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.CUST_ID      = c.CUST_ID
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,c.*,b.STD_COST*b.QTY AS T_COST,
b.SALE_PRICE*b.QTY AS T_SAL
FROM COUT_STOCK a,COUT_STOCKSUB b,CUSTOMER c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.CUST_ID      = c.CUST_ID
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT A.*,B.*,(CASE WHEN B.CORD = '借' THEN AMOUNT ELSE 0 END) AS DR_AMT,
(CASE WHEN B.CORD = '貸' THEN AMOUNT ELSE 0 END) AS CR_AMT
,C.DEP_NAME
 FROM ACC_MAIN A,ACC_MAST B,ACC_DEPART C
WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.MASTERBILLID BETWEEN :SID AND :EID
AND B.CODE1 <> 'Y'
AND A.DEP_NO = C.DEP_NO
ORDER BY A.MASTERBILLID,B.ITEM


rpt_SQLScript:
SELECT A.*,B.*,(CASE WHEN B.CORD = '借' THEN AMOUNT ELSE 0 END) AS DR_AMT,
(CASE WHEN B.CORD = '貸' THEN AMOUNT ELSE 0 END) AS CR_AMT
,C.DEP_NAME
 FROM ACC_MAIN A,ACC_MAST B,ACC_DEPART C
WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.ACC_DATE BETWEEN :SID AND :EID
AND B.CODE1 <> 'Y'
AND A.DEP_NO = C.DEP_NO
ORDER BY A.MASTERBILLID,B.ITEM


rpt_SQLScript:
SELECT * FROM ACC_KIND
WHERE ACC_NO BETWEEN :SID AND :EID
ORDER BY ACC_NO


rpt_SQLScript:
SELECT a.*,b.*,c.*,D.SALE_PRICE,D.PSALE_PRICE,
(b.V_QTY+V_GIVE_QTY) as V_QTY2,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM ORDER_MASTER a,ORDER_SUB b,CUSTOMER c,product d
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.CUST_ID      = c.CUST_ID
  AND a.MASTERBILLID =:SID
  AND B.PROD_ID = D.PROD_ID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT * FROM TAKEITEM_MASTER A,TAKEITEM_SUB B
WHERE A.MASTERBILLID = B.MASTERBILLID
AND   A.MASTERBILLID = :SID


rpt_SQLScript:
SELECT * FROM TAKEITEMBK_MASTER A,TAKEITEMBK_SUB B
WHERE A.MASTERBILLID = B.MASTERBILLID
AND   A.MASTERBILLID = :SID


rpt_SQLScript:
SELECT * FROM RORDER_MASTER A,RORDER_SUB B,CUSTOMER C
WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.MASTERBILLID = :SID
AND A.CUST_ID = C.CUST_ID
ORDER BY B.KEYINTIME


rpt_SQLScript:
SELECT *  FROM LEND_MASTER A,LEND_SUB B,CUSTOMER C
WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.CUST_ID       = C.CUST_ID
AND a.MASTERBILLID =:SID
ORDER BY B.KEYINTIME


rpt_SQLScript:
SELECT *  FROM LENDBK_MASTER A,LENDBK_SUB B,CUSTOMER C
WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.CUST_ID       = C.CUST_ID
AND a.MASTERBILLID =:SID
ORDER BY B.KEYINTIME


rpt_SQLScript:
SELECT SUBSTR(A.BILL_DATE,1,4) AS YY,SUBSTR(A.BILL_DATE,6,7) AS MM,SUBSTR(A.BILL_DATE,9,10) AS DD,A.*,B.*,C.*,b.B_PRICE*b.V_QTY AS B_AMT,
(b.B_PRICE*b.V_QTY)-(b.V_PRICE*b.V_QTY) AS C_AMT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOT_DISCOUNT,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
 FROM SAL_MASTER A,SAL_SUB B,CUSTOMER C
WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.CUST_ID = C.CUST_ID
AND A.MASTERBILLID = :SID


rpt_SQLScript:
SELECT A.*,B.* FROM ADDCASH_SUB A INNER JOIN 
ADDCASH_MASTER B
ON A.MASTERBILLID = B.MASTERBILLID
WHERE A.MASTERBILLID = :SID 
ORDER BY A.MASTERCARD_ID,A.SUBCARD_ID


rpt_SQLScript:
SELECT * FROM MEMBER
WHERE SUBSTR(MEMBER_BIRTHDAY,1,7) = :SID
ORDER BY MEMBER_BIRTHDAY,MEMBER_ID


rpt_SQLScript:
SELECT * FROM EMPLOYEE
WHERE EMPLOYEE_ID BETWEEN :SID AND :EID
ORDER BY EMPLOYEE_ID


rpt_SQLScript:
SELECT A.* ,B.*
FROM MEMBER A  LEFT OUTER JOIN MEMBER_ITEM B  ON A.MEMBER_ITEMID = B.MEMBER_ITEMID
WHERE A.MEMBER_ID BETWEEN :SID AND :EID
ORDER BY A.MEMBER_ITEMID,A.MEMBER_ID


rpt_SQLScript:
SELECT *
FROM PT_SUB
WHERE MASTERBILLID = :SID
ORDER BY PROD_ID


rpt_SQLScript:
SELECT * FROM PRODUCT
WHERE PROD_ID BETWEEN :SID AND :EID
ORDER BY PROD_ID


rpt_SQLScript:
SELECT a.*,b.* ,c.*,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM BUYBILL_MASTER a,BUYBILL_SUB b,PROVIDER c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.PROVIDER_ID  = c.PROVIDER_ID
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.* ,c.*,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM INSTORAGEBK_MASTER a,INSTORAGEBK_SUB b,PROVIDER c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.PROVIDER_ID  = c.PROVIDER_ID
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.* ,
cast(b.NOW_QTY*b.STD_COST as numeric(10,2)) as NS_COST,
cast(b.NOW_QTY*b.AVG_COST as numeric(10,2)) as NA_COST,
cast(b.OLD_QTY*b.STD_COST as numeric(10,2)) as OS_COST,
cast(b.OLD_QTY*b.AVG_COST as numeric(10,2)) as OA_COST,
cast(b.E_QTY*b.STD_COST as numeric(10,2)) as ES_COST,
cast(b.E_QTY*b.AVG_COST as numeric(10,2)) as EA_COST
FROM CHGQTY_MASTER a,CHGQTY_SUB b
WHERE a.MASTERBILLID = b.MASTERBILLID
    AND (b.NOW_QTY <> 0 OR b.OLD_QTY<> 0)
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.* 
FROM VOID_MASTER a,VOID_SUB b
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM BUYBILL_MASTER a,BUYBILL_SUB b
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT * FROM MOVE_MASTER,MOVE_SUB
WHERE MOVE_MASTER.MASTERBILLID = MOVE_SUB.MASTERBILLID
AND MOVE_MASTER.MASTERBILLID = :SID
ORDER BY MOVE_SUB.PROD_ID


rpt_SQLScript:
SELECT a.*,b.*,c.*,b.B_PRICE*b.V_QTY AS B_AMT,
(b.B_PRICE*b.V_QTY)-(b.V_PRICE*b.V_QTY) AS C_AMT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOT_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM SAL_MASTER a INNER JOIN SAL_SUB b ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN CUSTOMER C ON A.CUST_ID  = C.CUST_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT (b.v_qty+v_give_qty) as V_QTY2,a.*,b.*,c.*,b.B_PRICE*b.V_QTY AS B_AMT,
(b.B_PRICE*b.V_QTY)-(b.V_PRICE*b.V_QTY) AS C_AMT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA,
d.CARTER_NAME
FROM SALBK_MASTER a INNER JOIN SALBK_SUB b ON      a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN CUSTOMER C ON A.CUST_ID  = C.CUST_ID
LEFT OUTER JOIN CARTER   D ON A.CARTER_ID = D.CARTER_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT * from OUTVOICE_MASTER A,OUTVOICE_ITEMSUB B
where B.invoice_id BETWEEN :SID AND :EID
AND A.invoice_id = B.INVOICE_ID
AND a.BILL_FLAG = b.BILL_FLAG
AND A.BILL_FLAG NOT LIKE '%折讓%'
order by B.invoice_id


rpt_SQLScript:
SELECT a.SAL_DATE,a.PD_ITEMID,a.PD_ITEMNAME,
  a.BEFORE_COST,
  a.INSTORAGE_AMT,
  a.INSTORAGEBK_AMT,
  a.POS_COST,
  a.VOID_COST,
  a.NOW_COST,
  a.DIF_COST,
  a.CHG_COST,
  a.END_COST,
  a.TRNIN_AMT,
  a.TRNOUT_AMT,
  a.SAL_COST,
  a.SALBK_COST,
  SUM(b.R_AMT)  AS R_AMT,
  a.SAL_COST+a.SALBK_COST AS SAL_COST2
FROM X_DAYACC_SUB a LEFT OUTER JOIN X_DAYPOS_SUB b  
                      on  a.PD_ITEMID = b.PD_ITEMID 
                      and a.sal_date  = b.sal_date
WHERE a.SAL_DATE = :SID
GROUP BY a.SAL_DATE,a.PD_ITEMID,a.PD_ITEMNAME,
  a.BEFORE_COST,
  a.INSTORAGE_AMT,
  a.INSTORAGEBK_AMT,
  a.POS_COST,
  a.VOID_COST,
  a.NOW_COST,
  a.DIF_COST,
  a.CHG_COST,
  a.END_COST,
  a.TRNIN_AMT,
  a.TRNOUT_AMT,
  a.SAL_COST,
  a.SALBK_COST
ORDER BY a.PD_ITEMID


rpt_SQLScript:
SELECT A.PROD_ID,A.PROD_NAME,A.PROD_BARCODE,
A.PSALE_PRICE,A.UNITNAME,
B.SAL_BARCODE,B.SAL_NAME,B.PACK_QTY,B.SAL_UNITNAME,
B.SAL_PRICE
FROM PRODUCT A,PROD_SALE B
WHERE A.PROD_ID = B.PROD_ID
AND A.PROD_ID BETWEEN :SID AND :EID
ORDER BY A.PROD_ID


rpt_SQLScript:
SELECT * FROM WORK_MASTER A,WORK_SUB B
WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.MASTERBILLID = :SID
ORDER BY B.PROD_ID


rpt_SQLScript:
SELECT a.*,b.*,
cast(b.NOW_QTY*b.STD_COST as numeric(10,2)) as NS_COST,
cast(b.NOW_QTY*b.AVG_COST as numeric(10,2)) as NA_COST,
cast(b.OLD_QTY*b.STD_COST as numeric(10,2)) as OS_COST,
cast(b.OLD_QTY*b.AVG_COST as numeric(10,2)) as OA_COST,
cast(b.E_QTY*b.STD_COST as numeric(10,2)) as ES_COST,
cast(b.E_QTY*b.AVG_COST as numeric(10,2)) as EA_COST
FROM CHGQTY_MASTER a,CHGQTY_SUB b,PRODUCT C
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.MASTERBILLID =:SID
  AND B.PROD_ID = C.PROD_ID
  AND C.SEND_YN = 'N'
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,
cast(b.NOW_QTY*b.STD_COST as numeric(10,2)) as NS_COST,
cast(b.NOW_QTY*b.AVG_COST as numeric(10,2)) as NA_COST,
cast(b.OLD_QTY*b.STD_COST as numeric(10,2)) as OS_COST,
cast(b.OLD_QTY*b.AVG_COST as numeric(10,2)) as OA_COST,
cast(b.E_QTY*b.STD_COST as numeric(10,2)) as ES_COST,
cast(b.E_QTY*b.AVG_COST as numeric(10,2)) as EA_COST
FROM CHGQTY_MASTER a,CHGQTY_SUB b,PRODUCT C
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.MASTERBILLID =:SID
  AND B.PROD_ID = C.PROD_ID
  AND C.SEND_YN = 'Y'
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT PROD_ID,PROD_NAME,PROD_SCALE,SUM(QTY) AS QTY,SUM(AMT) AS AMT,SUM(QTY*STD_COST) AS T_COST
FROM VOID_SUB 
WHERE BILL_DATE BETWEEN :SID AND :EID
GROUP BY PROD_ID,PROD_NAME,PROD_SCALE
ORDER BY 4


rpt_SQLScript:
SELECT PROD_ID,PROD_NAME,PROD_SCALE,SUM(QTY) AS QTY,SUM(AMT) AS AMT,SUM(QTY*STD_COST) AS T_COST
FROM VOID_SUB 
WHERE BILL_DATE BETWEEN :SID AND :EID
AND  PROD_ID BETWEEN :SID2 AND :EID2
GROUP BY PROD_ID,PROD_NAME,PROD_SCALE
ORDER BY 4


rpt_SQLScript:
SELECT A.* ,B.CUST_NAME,C.PROD_NAME
FROM STORY_SAL A LEFT OUTER JOIN CUSTOMER B
     ON A.CUST_ID = B.CUST_ID
     LEFT OUTER JOIN PRODUCT C
     ON A.PROD_ID = C.PROD_ID
WHERE A.CUST_ID BETWEEN :SID AND :EID
ORDER BY A.CUST_ID,A.PROD_ID


rpt_SQLScript:
SELECT PROD_ID,PROD_NAME,SUM(QTY) FROM TAKEITEM_SUB
WHERE BILL_DATE BETWEEN :SID AND :EID
GROUP BY PROD_ID,PROD_NAME
ORDER BY PROD_ID


rpt_SQLScript:
SELECT PROD_ID,PROD_NAME,SUM(QTY) FROM TAKEITEMBK_SUB
WHERE BILL_DATE BETWEEN :SID AND :EID
GROUP BY PROD_ID,PROD_NAME
ORDER BY PROD_ID


rpt_SQLScript:
SELECT A.*,B.*,(CASE WHEN B.CORD = '借' THEN AMOUNT ELSE 0 END) AS DR_AMT,
(CASE WHEN B.CORD = '貸' THEN AMOUNT ELSE 0 END) AS CR_AMT
,C.DEP_NAME
 FROM ACC_MAIN A,ACC_MAST B,ACC_DEPART C
WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.MASTERBILLID = :SID
AND B.CODE1 <> 'Y'
AND A.DEP_NO = C.DEP_NO
ORDER BY A.MASTERBILLID,B.ITEM


rpt_SQLScript:
SELECT A.*,B.*,C.*,CAST(B.BILL_DATE AS DATE)+1 AS VDATE
FROM CUSTOMER A INNER JOIN SAL_MASTER B 
ON A.CUST_ID = B.CUST_ID
 INNER JOIN SAL_SUB C ON B.MASTERBILLID = C.MASTERBILLID
WHERE A.CUST_ID IN
(SELECT CUST_ID FROM SAL_MASTER WHERE MASTERBILLID = :SID)
AND B.MASTERBILLID = :SID


rpt_SQLScript:
SELECT a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE 
FROM CPETITION_MASTER a inner JOIN CPETITION_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN CUSTOMER c
ON B.CUST_ID = c.CUST_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY A.MASTERBILLID,B.CUST_ID,B.PROD_ID


rpt_SQLScript:
SELECT a.*,b.*,c.*,b.V_QTY*C.PSALE_PRICE AS T_SAMT
FROM BUYBILL_MASTER a,BUYBILL_SUB b,product c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.MASTERBILLID =:SID
  AND B.PROD_ID = C.PROD_ID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT 
  PSALE_MASTER.*,
  A.*,
  (SELECT FIRST 1 C.PSALE_PRICE FROM PSALE_SUB C
     WHERE C.PROD_ID = A.PROD_ID
      AND C.INI_DATE = A.INI_DATE
      AND C.END_DATE = A.END_DATE
      AND A.PACK_QTY > 1
  ) AS F_PRCE
FROM
  PSALE_SUB A
  LEFT OUTER JOIN PSALE_MASTER ON (PSALE_SUB.MASTERBILLID = PSALE_MASTER.MASTERBILLID)
WHERE A.MASTERBILLID = :SID


rpt_SQLScript:
SELECT A.*,B.*,CASE WHEN C.SAL_NAME IS NULL THEN B.PROD_NAME ELSE C.SAL_NAME END FROM PSALE_MASTER A ,PSALE_SUB B
 LEFT OUTER JOIN PROD_SALE C ON B.TEMPPRODID = C.SAL_BARCODE WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.MASTERBILLID = :SID


rpt_SQLScript:
SELECT BILL_DATE,PROD_ID,PROD_NAME,PROD_SCALE,
       SUM(QTY) AS QTY,SUM(AMT) AS AMT,
       SUM(QTY*STD_COST) AS T_COST
FROM VOID_SUB 
WHERE BILL_DATE BETWEEN :SID AND :EID
  AND  PROD_ID BETWEEN :SID2 AND :EID2
GROUP BY BILL_DATE,PROD_ID,PROD_NAME,PROD_SCALE
ORDER BY 1,5


rpt_SQLScript:
SELECT a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
       (B.B_PRICE-B.V_PRICE)*B.QTY AS U_DISCOUNT,(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY 
FROM INSTORAGEBK_MASTER a inner JOIN INSTORAGEBK_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,(b.qty+b.give_qty)*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
       (B.B_PRICE-B.V_PRICE)*B.QTY AS U_DISCOUNT,(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY
FROM INSTORAGEBK_MASTER a inner JOIN INSTORAGEBK_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
(B.B_PRICE-B.V_PRICE)*B.QTY AS U_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY 
FROM INSTORAGE_MASTER a inner JOIN INSTORAGE_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,(b.qty+b.give_qty)*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
       (B.B_PRICE-B.V_PRICE)*B.QTY AS U_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY
FROM INSTORAGE_MASTER a inner JOIN INSTORAGE_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA 
FROM BUYBILL_MASTER a inner JOIN BUYBILL_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.TEMPPRODID


rpt_SQLScript:
SELECT a.*,b.*,(b.qty+b.give_qty)*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
       (B.B_PRICE-B.V_PRICE)*B.QTY AS U_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM INSTORAGE_MASTER a inner JOIN INSTORAGE_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.TEMPPRODID


rpt_SQLScript:
SELECT a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
(B.B_PRICE-B.V_PRICE)*B.V_QTY AS U_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM INSTORAGEBK_MASTER a inner JOIN INSTORAGEBK_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.TEMPPRODID


rpt_SQLScript:
SELECT a.*,b.*,c.*,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM ORDER_MASTER a,ORDER_SUB b,CUSTOMER c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.CUST_ID      = c.CUST_ID
  AND a.MASTERBILLID =:SID
ORDER BY b.TEMPPRODID


rpt_SQLScript:
SELECT a.*,b.*,c.*,b.B_PRICE*b.V_QTY AS B_AMT,
(b.B_PRICE*b.V_QTY)-(b.V_PRICE*b.V_QTY) AS C_AMT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOT_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM SAL_MASTER a INNER JOIN SAL_SUB b ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN CUSTOMER C ON A.CUST_ID  = C.CUST_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.TEMPPRODID


rpt_SQLScript:
SELECT a.*,b.*,c.*,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA,
d.CARTER_NAME
FROM SALBK_MASTER a INNER JOIN SALBK_SUB b ON      a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN CUSTOMER C ON A.CUST_ID  = C.CUST_ID
LEFT OUTER JOIN CARTER   D ON A.CARTER_ID = D.CARTER_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.TEMPPRODID


rpt_SQLScript:
SELECT A.*,B.*,CASE WHEN C.SAL_NAME IS NULL THEN B.PROD_NAME ELSE C.SAL_NAME END FROM PSALE_MASTER A ,PSALE_SUB B
 LEFT OUTER JOIN PROD_SALE C ON B.TEMPPRODID = C.SAL_BARCODE WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.MASTERBILLID = :SID
ORDER BY PROD_ID,PACK_QTY


rpt_SQLScript:
SELECT a.*
FROM FIXBILL_MASTER a
WHERE a.CLOSED =:SID
  AND a.BILL_DATE >= '2010/09/01'
ORDER BY a.PROVIDER_ID,a.CUST_ID,a.MASTERBILLID


rpt_SQLScript:
SELECT DISTINCT A.PROVIDER_ID,A.PROVIDER_NAME,B.PROD_ID,PROD_BARCODE,PROD_NAME,B.IN_PRICE
FROM QUOT_MASTER a,QUOT_SUB b,PROVIDER c 
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.PROVIDER_ID  = c.PROVIDER_ID
  AND a.PROVIDER_ID BETWEEN :SID AND :EID
ORDER BY A.PROVIDER_ID


rpt_SQLScript:
SELECT a.*,b.*
FROM FIXBILL_MASTER a inner JOIN CUSTOMER b
ON a.CUST_ID = b.CUST_ID
WHERE a.MASTERBILLID =:SID


rpt_SQLScript:
SELECT a.*,b.*
FROM PAY_MASTER a LEFT OUTER join PAY_SUB b  
                   on  a.MASTERBILLID = b.MASTERBILLID
WHERE a.MASTERBILLID =:SID
ORDER BY b.FLAG,b.TRAN_BILLID


rpt_SQLScript:
SELECT  A.*,B.*,C.N_PRICE,C.SALE_PRICE,C.P_PRICE,
                C.P_PRICE2,C.VIP_PRICE,C.CR_PRICE
FROM SALPROMOTION_MASTER A INNER JOIN 
     SALPROMOTION_SUB B ON A.MASTERBILLID = B.MASTERBILLID
     INNER JOIN  PRODUCT C ON B.PROD_ID = C.PROD_ID
WHERE A.MASTERBILLID = :SID


rpt_SQLScript:
SELECT A.*,B.*,CASE WHEN C.SAL_NAME IS NULL THEN B.PROD_NAME ELSE C.SAL_NAME END,(B.OLD_PRICE-B.PSALE_PRICE) AS ERN_PRICE FROM PSALE_MASTER A ,PSALE_SUB B
 LEFT OUTER JOIN PROD_SALE C ON B.TEMPPRODID = C.SAL_BARCODE WHERE A.MASTERBILLID = B.MASTERBILLID
AND A.MASTERBILLID = :SID


rpt_SQLScript:
SELECT MOVE_MASTER_REDY.*,MOVE_SUB_REDY.*,C.STOCK_NAME AS T_NAME,D.STOCK_NAME AS S_NAME,E.PUT_ID,F.EMPLOYEE_NAME AS CHG_NAME FROM  MOVE_MASTER_REDY,MOVE_SUB_REDY,STOCK_ITEM C,STOCK_ITEM D,PRODUCT E,EMPLOYEE F
WHERE MOVE_MASTER_REDY.MASTERBILLID = MOVE_SUB_REDY.MASTERBILLID
AND MOVE_MASTER_REDY.MASTERBILLID = :SID
AND MOVE_MASTER_REDY.T_STOCKID = C.STOCK_ID
AND MOVE_MASTER_REDY.S_STOCKID = D.STOCK_ID
AND MOVE_SUB_REDY.PROD_ID = E.PROD_ID
AND MOVE_MASTER_REDY.CHG_USER = F.EMPLOYEE_ID
ORDER BY E.PUT_ID,MOVE_SUB_REDY.PROD_BARCODE


rpt_SQLScript:
SELECT MOVE_MASTER_REDY.*,MOVE_SUB_REDY.*,C.STOCK_NAME AS T_NAME,D.STOCK_NAME AS S_NAME,F.EMPLOYEE_NAME AS CHG_NAME FROM  MOVE_MASTER_REDY,MOVE_SUB_REDY,STOCK_ITEM C,STOCK_ITEM D,EMPLOYEE F 
WHERE MOVE_MASTER_REDY.MASTERBILLID = MOVE_SUB_REDY.MASTERBILLID
AND MOVE_MASTER_REDY.MASTERBILLID = :SID
AND MOVE_MASTER_REDY.T_STOCKID = C.STOCK_ID
AND MOVE_MASTER_REDY.S_STOCKID = D.STOCK_ID
AND MOVE_MASTER_REDY.CHG_USER = F.EMPLOYEE_ID
ORDER BY MOVE_SUB_REDY.U_DIS,MOVE_SUB_REDY.PROD_BARCODE


rpt_SQLScript:
SELECT MOVE_MASTER_REDY.*,MOVE_SUB_REDY.*,C.STOCK_NAME AS T_NAME,D.STOCK_NAME AS S_NAME,F.EMPLOYEE_NAME AS CHG_NAME FROM  MOVE_MASTER_REDY,MOVE_SUB_REDY,STOCK_ITEM C,STOCK_ITEM D,EMPLOYEE F 
WHERE MOVE_MASTER_REDY.MASTERBILLID = MOVE_SUB_REDY.MASTERBILLID
AND MOVE_MASTER_REDY.MASTERBILLID = :SID
AND MOVE_MASTER_REDY.T_STOCKID = C.STOCK_ID
AND MOVE_MASTER_REDY.S_STOCKID = D.STOCK_ID
AND MOVE_MASTER_REDY.CHG_USER = F.EMPLOYEE_ID
ORDER BY MOVE_SUB_REDY.PD_ITEMID


rpt_SQLScript:
SELECT MOVE_MASTER_REDY.*,MOVE_SUB_REDY.*,C.STOCK_NAME AS T_NAME,D.STOCK_NAME AS S_NAME,F.EMPLOYEE_NAME AS CHG_NAME FROM  MOVE_MASTER_REDY,MOVE_SUB_REDY,STOCK_ITEM C,STOCK_ITEM D,EMPLOYEE F 
WHERE MOVE_MASTER_REDY.MASTERBILLID = MOVE_SUB_REDY.MASTERBILLID
AND MOVE_MASTER_REDY.MASTERBILLID = :SID
AND MOVE_MASTER_REDY.T_STOCKID = C.STOCK_ID
AND MOVE_MASTER_REDY.S_STOCKID = D.STOCK_ID
AND MOVE_MASTER_REDY.CHG_USER = F.EMPLOYEE_ID
ORDER BY MOVE_SUB_REDY.PROD_BARCODE


rpt_SQLScript:
SELECT A.*,B.* FROM ADDCASH_SUB A INNER JOIN 
ADDCASH_MASTER B
ON A.MASTERBILLID = B.MASTERBILLID
WHERE A.BILL_DATE = :SID 
ORDER BY A.BILL_DATE,A.MASTERCARD_ID,A.SUBCARD_ID


rpt_SQLScript:
SELECT A.SAL_DATE,A.PD_HIITEMID,A.PD_HIITEMNAME,
  SUM(A.BEFORE_COST) AS BEFORE_COST,
  SUM(A.INSTORAGE_AMT) AS INSTORAGE_AMT,
  SUM(A.INSTORAGEBK_AMT) AS INSTORAGEBK_AMT,
  SUM(A.SAL_COST+A.SALBK_COST) AS SAL_COST,
  SUM(A.POS_COST) AS POS_COST,
  SUM(A.VOID_COST) AS VOID_COST,
  SUM(A.NOW_COST) AS NOW_COST,
  SUM(A.TRNIN_AMT) AS TRNIN_AMT,
  SUM(A.TRNOUT_AMT) AS TRNOUT_AMT,
  SUM(A.DIF_COST) AS DIF_COST,
  SUM(A.CHG_COST) AS CHG_COST,
  SUM(A.END_COST) AS END_COST,
  B.BEFORE_COST,B.NOW_COST,B.SUM_COST_STD,B.DIF_COST_STD,
  B.SUM_RNOW_COST,B.SUM_DIF_COST,B.SUM_END_COST
FROM X_DAYACC_SUB A,X_DAYACC_MASTER B
WHERE A.SAL_DATE = :SID
AND A.SAL_DATE = B.SAL_DATE
GROUP BY A.SAL_DATE,A.PD_HIITEMID,A.PD_HIITEMNAME,B.BEFORE_COST,B.NOW_COST,B.SUM_COST_STD,B.DIF_COST_STD,
  B.SUM_RNOW_COST,B.SUM_DIF_COST,B.SUM_END_COST
ORDER BY A.PD_HIITEMID


rpt_SQLScript:
SELECT a.*,b.* ,c.*
FROM BUYBILL_MASTER a,BUYBILL_SUB b,PROVIDER c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.PROVIDER_ID  = c.PROVIDER_ID
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT * FROM PRODUCT
WHERE CR_DATE = :SID
ORDER BY PROD_BARCODE,PROD_ID


rpt_SQLScript:
SELECT A.*,B.* FROM ADDCASH_SUB A INNER JOIN 
ADDCASH_MASTER B
ON A.MASTERBILLID = B.MASTERBILLID
WHERE A.SUBCARD_ID BETWEEN :SID  AND :EID 
ORDER BY A.MEMBER_ID,A.SUBCARD_ID,A.BILL_DATE


rpt_SQLScript:
SELECT A.MASTERBILLID,A.BILL_DATE,A.EMPLOYEE_ID,A.CHG_DATE,A.CHG_USER,A.NOTE,'1領料' AS FLAG,
       B.KEYINTIME,B.PROD_ID,B.PROD_NAME,B.PROD_SCALE,B.QTY,B.UNITNAME,B.TEMPPRODID,
       B.V_QTY,B.V_UNIT,B.REMARK,B.STOCK_ID,B.BILL_DATE,B.PACK_QTY,B.PROD_BARCODE,
       B.PR_VALUE,B.QTY*B.PR_VALUE AS PR_VALUE_T
FROM ASMPROD_MASTER A INNER JOIN ASMPROD_SRCSUB B ON A.MASTERBILLID = B.MASTERBILLID
WHERE A.MASTERBILLID = :SID
UNION ALL
SELECT A.MASTERBILLID,A.BILL_DATE,A.EMPLOYEE_ID,A.CHG_DATE,A.CHG_USER,A.NOTE,'2入庫' AS FLAG,
       B.KEYINTIME,B.PROD_ID,B.PROD_NAME,B.PROD_SCALE,B.QTY,B.UNITNAME,B.TEMPPRODID,
       B.V_QTY,B.V_UNIT,B.REMARK,B.STOCK_ID,B.BILL_DATE,B.PACK_QTY,B.PROD_BARCODE,
       B.PR_VALUE,B.QTY*B.PR_VALUE AS PR_VALUE_T
FROM ASMPROD_MASTER A INNER JOIN ASMPROD_TARSUB B ON A.MASTERBILLID = B.MASTERBILLID
WHERE A.MASTERBILLID = :SID
order by 1,7,8


rpt_SQLScript:
select A.MEMBER_HIITEMID,A.MEMBER_HIITEMNAME,B.MEMBER_ITEMID,B.MEMBER_ITEMNAME from MEMBER_HIITEM A
 INNER JOIN MEMBER_ITEM B ON 
 B.MEMBER_HIITEMID = A.MEMBER_HIITEMID
order by 1,3


rpt_SQLScript:
SELECT A.*,B.CUST_CLASSNAME,C.EMPLOYEE_NAME FROM CUSTOMER A
LEFT OUTER JOIN CUST_CLASS B
ON A.CUST_CLASSID = B.CUST_CLASSID
LEFT OUTER JOIN EMPLOYEE C
ON A.SALES_ID = C.EMPLOYEE_ID
WHERE A.SALES_ID BETWEEN :SID AND :EID
ORDER BY A.SALES_ID,A.CUST_ID


rpt_SQLScript:
SELECT a.*,b.*,(b.V_QTY+V_GIVE_QTY) as V_QTY2,C.*,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM ORDER_MASTER a,ORDER_SUB b,PRODUCT c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.MASTERBILLID =:SID
  AND B.PROD_ID = C.PROD_ID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT (B.V_QTY+B.V_GIVE_QTY) AS V_QTY2,a.*,b.*,c.*,
a.TOTAL_DISCOUNT+a.TOTAL_DISCOUNT2 AS TOT_DISCOUNT,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA,
D.EMPLOYEE_NAME
FROM SALBK_MASTER a LEFT OUTER JOIN EMPLOYEE D ON A.CHG_USER = D.EMPLOYEE_ID,SALBK_SUB b,CUSTOMER c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.CUST_ID      = c.CUST_ID
  AND a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*,c.*,(b.V_QTY+V_GIVE_QTY) as V_QTY2,
D.EMPLOYEE_NAME AS CHG_NAME,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_REC,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM ORDER_MASTER a LEFT OUTER JOIN EMPLOYEE D ON A.CHG_USER = D.EMPLOYEE_ID,ORDER_SUB b,CUSTOMER c
WHERE a.MASTERBILLID = b.MASTERBILLID
  AND a.CUST_ID      = c.CUST_ID
  AND a.BILL_DATE =:SID
ORDER BY a.MASTERBILLID,b.KEYINTIME


rpt_SQLScript:
SELECT A.PROVIDER_ID,C.PROVIDER_NAME,A.PROD_ID,A.STD_COST,
B.PROD_NAME,B.PROD_BARCODE,B.P_LTCOST,C.CHG_DATE 
FROM STORY_IN a INNER JOIN PRODUCT b
     ON a.PROD_ID = b.PROD_ID
     LEFT OUTER JOIN PROVIDER C ON A.PROVIDER_ID = C.PROVIDER_ID
WHERE a.PROVIDER_ID BETWEEN :SID AND :EID
ORDER BY A.PROVIDER_ID,A.PROD_ID


rpt_SQLScript:
SELECT a.*,b.*,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM INSTORAGE_MASTER a INNER JOIN PROVIDER b
ON a.PROVIDER_ID = b.PROVIDER_ID
WHERE a.MASTERBILLID =:SID
ORDER BY a.MASTERBILLID


rpt_SQLScript:
SELECT a.*,b.*,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM INSTORAGEBK_MASTER a INNER JOIN PROVIDER b
ON a.PROVIDER_ID = b.PROVIDER_ID
WHERE a.MASTERBILLID =:SID
ORDER BY a.MASTERBILLID


rpt_SQLScript:
SELECT (b.V_QTY+b.V_GIVE_QTY) AS V_QTY2,a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE,
(B.B_PRICE-B.V_PRICE)*B.V_QTY AS U_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2+
A.THEA_AMT) AS TOTAL_HEA
FROM INSTORAGEBK_MASTER a inner JOIN INSTORAGEBK_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT * FROM BANKIO  
WHERE  BILL_DATE =:SID
ORDER BY ACNT_ID,MASTERBILLID


rpt_SQLScript:
SELECT * FROM BANKIO  
WHERE SOURCEID IS NOT NULL
  AND BILL_DATE =:SID
ORDER BY ACNT_ID,MASTERBILLID


rpt_SQLScript:
SELECT a.*,b.*,c.*,
SUBSTR(a.BILL_FLAG,3,4)  as B_FLAG
FROM OUTVOICE_MASTER a INNER JOIN OUTVOICE_ITEMSUB b 
ON a.INVOICE_ID = b.INVOICE_ID 
AND a.BILL_FLAG = b.BILL_FLAG
LEFT OUTER JOIN CUSTOMER C ON A.CUST_ID  = C.CUST_ID
WHERE B.invoice_id =:SID
  AND A.BILL_FLAG LIKE '%折讓%'
ORDER BY B.invoice_id


rpt_SQLScript:
SELECT (b.V_QTY+b.V_GIVE_QTY) AS V_QTY2,a.*,b.*,b.qty*D.Psale_price as t_price,c.*,D.PSALE_PRICE ,
(b.B_PRICE-b.V_PRICE)*b.QTY AS U_DISCOUNT,
(A.TOTAL_DISCOUNT+A.TOTAL_DISCOUNT2) AS TOTAL_DIS,
(A.TOTAL_MONEY-A.TOTAL_DISCOUNT-A.TOTAL_DISCOUNT2) AS TOTAL_PAY,E.STOCK_NAME
FROM INSTORAGEBK_MASTER_REDY a inner JOIN INSTORAGEBK_SUB_REDY b
ON a.MASTERBILLID = b.MASTERBILLID
LEFT OUTER JOIN PROVIDER c
ON a.PROVIDER_ID = c.PROVIDER_ID
LEFT OUTER JOIN PRODUCT D
ON b.PROD_ID = D.PROD_ID
LEFT OUTER JOIN STOCK_ITEM E
ON A.STOCK_ID = E.STOCK_ID
WHERE a.MASTERBILLID =:SID
ORDER BY b.KEYINTIME


rpt_SQLScript:
SELECT a.*,b.*
FROM ASMPROD_TARSUB a INNER JOIN ASMPROD_SRCSUB b
ON a.MASTERBILLID = b.MASTERBILLID
WHERE a.MASTERBILLID =:SID
  AND A.PROD_ID = B.MAIN_PROD
 ORDER BY a.MASTERBILLID,A.PROD_ID,B.PROD_ID


rpt_SQLScript:
SELECT * FROM CHKRAGT_MASTER A,CHKRAGT_SUB B,
CHKRCV C,BANK_ACCOUNT D
WHERE A.MASTERBILLID = B.MASTERBILLID
AND B.CHK_ID = C.ID
AND A.ACNT_ID = D.ACNT_ID
AND A.MASTERBILLID = :SID
ORDER BY B.KEYINTIME


rpt_SQLScript:
SELECT SAL_DATE,PD_TOPITEMID,PD_TOPITEMNAME, 
  SUM(OLD_QTY) AS OLD_QTY,
  SUM(OLD_GIVEQTY2) AS OLD_GIVEQTY2,
  SUM(PT_QTY) AS PT_QTY,
  SUM(PT_GIVEQTY2) AS PT_GIVEQTY2,
  SUM(NOW_QTY) AS NOW_QTY,
  SUM(CHG_QTY) AS CHG_QTY,
  SUM(OLD_QTY1) AS OLD_QTY1,
  SUM(OLD_GIVEQTY21) AS OLD_GIVEQTY21,
  SUM(PT_QTY1) AS PT_QTY1,
  SUM(PT_GIVEQTY21) AS PT_GIVEQTY21,
  SUM(NOW_QTY1) AS NOW_QTY1,
  SUM(CHG_QTY1) AS CHG_QTY1,

  SUM(OLD_QTY2) AS OLD_QTY2,
  SUM(OLD_GIVEQTY22) AS OLD_GIVEQTY22,
  SUM(PT_QTY2) AS PT_QTY2,
  SUM(PT_GIVEQTY22) AS PT_GIVEQTY22,
  SUM(NOW_QTY2) AS NOW_QTY2,
  SUM(CHG_QTY2) AS CHG_QTY2,


  
  SUM(DIF_COST) AS DIF_COST,
  SUM(BEFORE_COST) AS BEFORE_COST,
  SUM(END_COST) AS END_COST,
  
  SUM(INSTORAGE_AMT) AS INSTORAGE_AMT,
  SUM(INSTORAGEBK_AMT) AS INSTORAGEBK_AMT,
  SUM(SAL_COST+SALBK_COST) AS SAL_COST,
  SUM(POS_COST) AS POS_COST,
  SUM(VOID_COST) AS VOID_COST,
  SUM(NOW_COST) AS NOW_COST,
  SUM(TRNIN_AMT) AS TRNIN_AMT,
  SUM(TRNOUT_AMT) AS TRNOUT_AMT,
  SUM(BEFORE_COST1) AS BEFORE_COST1,
  SUM(INSTORAGE_AMT1) AS INSTORAGE_AMT1,
  SUM(INSTORAGEBK_AMT1) AS INSTORAGEBK_AMT1,
  SUM(SAL_COST1+SALBK_COST1) AS SAL_COST1,
  SUM(POS_COST1) AS POS_COST1,
  SUM(VOID_COST1) AS VOID_COST1,
  SUM(NOW_COST1) AS NOW_COST1,
  SUM(TRNIN_AMT1) AS TRNIN_AMT1,
  SUM(TRNOUT_AMT1) AS TRNOUT_AMT1,
  SUM(DIF_COST1) AS DIF_COST1,
  SUM(END_COST1) AS END_COST1,
  SUM(BEFORE_COST2) AS BEFORE_COST2,
  SUM(INSTORAGE_AMT2) AS INSTORAGE_AMT2,
  SUM(INSTORAGEBK_AMT2) AS INSTORAGEBK_AMT2,
  SUM(SAL_COST2+SALBK_COST2) AS SAL_COST2,
  SUM(POS_COST2) AS POS_COST2,
  SUM(VOID_COST2) AS VOID_COST2,
  SUM(NOW_COST2) AS NOW_COST2,
  SUM(TRNIN_AMT2) AS TRNIN_AMT2,
  SUM(TRNOUT_AMT2) AS TRNOUT_AMT2,
  SUM(DIF_COST2) AS DIF_COST2,
  SUM(END_COST2) AS END_COST2
FROM X_DAYACC_SUB 
WHERE SAL_DATE = :SID
 and PD_TOPITEMID LIKE 'D%'
GROUP BY SAL_DATE,PD_TOPITEMID,PD_TOPITEMNAME
ORDER BY PD_TOPITEMID


rpt_SQLScript:
SELECT * from OUTVOICE_MASTER A,OUTVOICE_ITEMSUB B
where B.invoice_id =:SID
AND A.invoice_id = B.INVOICE_ID
AND A.BILL_FLAG NOT LIKE '%折讓%'
order by B.invoice_id


rpt_SQLScript:
SELECT a.*,b.*
FROM MAINGIVE_MASTER a inner JOIN MAINGIVE_SUB b
ON a.MASTERBILLID = b.MASTERBILLID
WHERE a.MASTERBILLID =:SID
ORDER BY b.GIVE_BARCODE


