Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT zz.barcode, zz.qty_sisa AS qty, zz.toko
- FROM (
- SELECT msk.barcode AS barcode, msk.qty-IFNULL(klr.qty, 0) AS qty_sisa, msk.toko
- FROM
- (
- SELECT a.barcode,SUM(a.qty) AS qty, a.toko
- FROM
- (
- SELECT barcode, SUM(qty) AS qty, toko
- FROM nifn_saldo_awal_pos
- WHERE
- toko = 'HM2C'
- GROUP BY barcode
- UNION
- SELECT a.barcode,SUM(a.qty) AS qty, b.toko
- FROM nifn_trans_klr_barang_detail AS a
- JOIN nifn_trans_klr_barang_master AS b ON a.id_transaksi = b.id_masuk
- WHERE
- b.toko = 'HM2C' AND a.validated = 1
- GROUP BY a.barcode
- UNION
- SELECT a.barcode, SUM(a.qty) AS qty, b.tujuan AS toko
- FROM nifn_trans_mutasi_pos_detail AS a
- JOIN nifn_trans_mutasi_pos_master AS b ON a.id_transaksi = b.id_masuk
- WHERE
- b.tujuan = 'HM2C' AND a.validated = 1 AND b.validated = 1
- GROUP BY
- a.barcode
- UNION
- SELECT a.barcode, SUM(a.qty) AS qty, b.id_cabang AS toko
- FROM nifn_trans_exchange_detail AS a
- JOIN nifn_trans_exchange_master AS b ON a.id_transaksi = b.id_transaksi
- WHERE
- b.id_cabang = 'HM2C' GROUP BY a.barcode
- ) AS a
- GROUP BY barcode
- ) AS msk
- LEFT JOIN
- (
- SELECT a.barcode, SUM(a.qty) AS qty
- FROM
- (
- SELECT a.barcode, SUM(a.qty) AS qty
- FROM nifn_trans_pos_detail AS a
- JOIN nifn_trans_pos_master AS b ON a.id_transaksi = b.pos_id_transaksi
- WHERE b.pos_toko = 'HM2C'
- GROUP BY a.barcode
- UNION
- SELECT a.barcode, SUM(a.qty) AS qty
- FROM nifn_trans_mutasi_pos_detail AS a
- JOIN nifn_trans_mutasi_pos_master AS b ON a.id_transaksi = b.id_masuk
- WHERE b.dari = 'HM2C'
- GROUP BY a.barcode
- UNION
- SELECT a.barcode, SUM(a.qty) AS qty
- FROM nifn_trans_retur_gudang_detail AS a
- JOIN nifn_trans_retur_gudang_master AS b ON a.id_transaksi = b.id_retur
- WHERE b.toko = 'HM2C'
- GROUP BY a.barcode
- ) AS a GROUP BY barcode
- ) AS klr ON msk.barcode = klr.barcode
- ) AS zz
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement