SELECT
	tanggal_transaksi,
	description,
	CONCAT(
		 Rp.  ,
	FORMAT( masuk,  N ,  en-us  )) AS pemasukan,
	CONCAT(
		 Rp.  ,
	FORMAT( keluar,  N ,  en-us  )) AS pengeluaran 
FROM
	(
	SELECT
		tanggal AS tanggal_transaksi,
		description,
		masuk,
		keluar 
	FROM
		(
		SELECT
			tanggal,
			nama AS description,
			   AS masuk,
			keluar 
		FROM
			(
			SELECT
				a.tanggal_obat_masuk AS tanggal,
				CONCAT(
					 Pembelian  ,
					b.nama_obat,
					 <br>No. Batch :  ,
					a.no_batch,
					 <br>Jumlah :  ,
					a.quantity,
					 <br>Harga Satuan : Rp.  ,
				FORMAT( a.harga_beli,  N ,  en-us  )) AS nama,
				a.harga_beli AS satuan,
				a.quantity,
				( a.harga_beli * a.quantity ) AS keluar 
			FROM
				sub_master_obat_masuk a
				JOIN m_master_obat b ON a.id_obat = b.id UNION ALL
			SELECT
				a.tanggal_transaksi AS tanggal,
				CONCAT(
					 Pembelian  ,
					b.nama_brng,
					 <br>No. Batch :  ,
					a.no_batch,
					 <br>Jumlah :  ,
					a.quantity,
					 <br>Harga Satuan : Rp.  ,
					FORMAT( a.harga_beli,  N ,  en-us  ) 
				) AS nama,
				a.harga_beli AS satuan,
				a.quantity,
				( a.harga_beli * a.quantity ) AS k 
			FROM
				transaksi_barang a
				JOIN databarang b ON a.kode_barang = b.kode_brng 
			WHERE
				a.jenis_transaksi =  in  
			) a UNION
		SELECT
			DATE_FORMAT( b.created_date,  %Y-%m-%d  ) AS tanggal,
			CONCAT(  Pelayanan  , d.nama_cluster,  <br>Nama Pasien :  , UPPER( c.nama_depan ),  <br>No. RM :  , c.no_rekam_medis ),
			a.total AS masuk,
			   AS keluar 
		FROM
			kasir a
			JOIN pendaftaran b ON a.id_pendaftaran = b.id
			JOIN m_penduduk c ON b.id_penduduk = c.id_penduduk
			JOIN cluster d ON a.id_cluster = d.id_cluster 
		WHERE
			a.STATUS =  done  
		) tabel 
	ORDER BY
		tanggal DESC 
	) x UNION
SELECT
	 <b>Total</b> ,
	  ,
	CONCAT( Rp.  , FORMAT(SUM( masuk ),  N ,  en-us )) as pemasukan,
	CONCAT( Rp.  , FORMAT(SUM( keluar ),  N ,  en-us )) as pengeluaran
FROM
	(
	SELECT
		tanggal AS tanggal_transaksi,
		description,
		masuk,
		keluar 
	FROM
		(
		SELECT
			tanggal,
			nama AS description,
			   AS masuk,
			keluar 
		FROM
			(
			SELECT
				a.tanggal_obat_masuk AS tanggal,
				CONCAT(
					 Pembelian  ,
					b.nama_obat,
					 <br>No. Batch :  ,
					a.no_batch,
					 <br>Jumlah :  ,
					a.quantity,
					 <br>Harga Satuan : Rp.  ,
				FORMAT( a.harga_beli,  N ,  en-us  )) AS nama,
				a.harga_beli AS satuan,
				a.quantity,
				( a.harga_beli * a.quantity ) AS keluar 
			FROM
				sub_master_obat_masuk a
				JOIN m_master_obat b ON a.id_obat = b.id UNION ALL
			SELECT
				a.tanggal_transaksi AS tanggal,
				CONCAT(
					 Pembelian  ,
					b.nama_brng,
					 <br>No. Batch :  ,
					a.no_batch,
					 <br>Jumlah :  ,
					a.quantity,
					 <br>Harga Satuan : Rp.  ,
					FORMAT( a.harga_beli,  N ,  en-us  ) 
				) AS nama,
				a.harga_beli AS satuan,
				a.quantity,
				( a.harga_beli * a.quantity ) AS k 
			FROM
				transaksi_barang a
				JOIN databarang b ON a.kode_barang = b.kode_brng 
			WHERE
				a.jenis_transaksi =  in  
			) a UNION
		SELECT
			DATE_FORMAT( b.created_date,  %Y-%m-%d  ) AS tanggal,
			CONCAT(  Pelayanan  , d.nama_cluster,  <br>Nama Pasien :  , UPPER( c.nama_depan ),  <br>No. RM :  , c.no_rekam_medis ),
			a.total AS masuk,
			   AS keluar 
		FROM
			kasir a
			JOIN pendaftaran b ON a.id_pendaftaran = b.id
			JOIN m_penduduk c ON b.id_penduduk = c.id_penduduk
			JOIN cluster d ON a.id_cluster = d.id_cluster 
		WHERE
			a.STATUS =  done  
		) tabel 
	ORDER BY
	tanggal DESC 
	) xx