################## FAKTA PEMESANAN # ################## IF EXISTS ( SELECT * FROM [DWH_Commeta].[dbo].

FilterTimeStamp WHERE namatable = 'FactPenjualan' ) SELECT Dim_waktu_key, u.Dim_user_key, po.Dim_produk_key, pr.Dim_program_key, sum(wb.quantity) as [Jumlah Produk Masuk], sum(p.stock) as [Total Persediaan] FROM [Commeta_DB].[dbo].Trx_warehouse AS w, [Commeta_DB].[dbo].trx_warehouse_barang AS wb, [Commeta_DB].[dbo].ms_Product AS pd, [DWH_Commeta].[dbo].DimWaktu AS dw, [DWH_Commeta].[dbo].DimCustomer AS c, [DWH_Commeta].[dbo].DimUser AS u, [DWH_Commeta].[dbo].DimProduk AS po, [DWH_Commeta].[dbo].DimProgram AS pr WHERE w.code_ware = wb.code_ware AND w.program_id = pr.program_id AND wb.product_id = po.produk_id AND wb._product_id = pd.product_id AND w.user_id = u.user_id AND w.opr = 'IN' UNION year(sj.Tanggal_transaksi ) = dw.Tahun AND month(sj.Tanggal_transaksi ) = dw.Bulan AND day(sj.Tanggal_transaksi) = dw.Hari AND sj.Inserted_Date > ( SELECT Last_ETL FROM [DWH_Commeta].[dbo].FilterTimeStamp WHERE namatable = 'FactPenjualan' ) GROUP BY Dim_waktu_key, c.Dim_customer_key, u.Dim_user_key, po.Dim_produk_key, pr.Dim_program_key ELSE SELECT Dim_waktu_key, c.Dim_customer_key, u.Dim_user_key, po.Dim_produk_key, pr.Dim_program_key, sum(sjd.quantity) as [Jumlah Produk Terjual], sum(sj.total_penjualan) as [Total Penjualan]

DimWaktu AS dw.DimProduk AS po.program_id AND pro.customer_id GROUP BY Dim_waktu_key.[dbo].[dbo].Dim_customer_key.product_id = po.detail_surat_jalan AS sjd.program_id = pr.[dbo].Dim_user_key. po. [Commeta_DB].kode_transaksi AND sj.[dbo].Dim_produk_key.user_id = u.program_id AND sjd.customer_id = cs.[dbo].user_id AND sj.[dbo]. [DWH_Commeta].kode_transaksi = sj. [Commeta_DB].produk_id AND sjd. [Commeta_DB]. [DWH_Commeta].[dbo].customer_id = c. [DWH_Commeta].DimProgram AS pr WHERE sjd.[dbo]. pr.Dim_program_key .customer_id AND cs.Trx_surat_jalan AS sj. [DWH_Commeta].[dbo].ms_program AS pro.DimUser AS u.ms_customer AS cs. u.kode_transaksi AND sj. c.program_id = pro. [DWH_Commeta].DimCustomer AS c.kode_transaksi = sj.FROM [Commeta_DB].