select 'Template' AS jenis, '2033-12-31' AS `billdate`,'0' AS cust,'-' AS custname,'2033-12-31 01:00:01' AS `dateadded`,0 AS `debet`,'0' AS `kredit`,'0' AS akun from admins where pk = 1
	
	union all
	select 'Pembelian Tax dari ' AS `jenis`,`buy`.`billdate` AS `billdate`,`buy`.`cust` AS `cust`,(select `supplier`.`nama` from `supplier` where `supplier`.`id` = `buy`.`cust`) AS `custname`,`buy`.`dateadded` AS `dateadded`,(select sum(`buydetail`.`qty` * `buydetail`.`harga`) from `buydetail` where `buydetail`.`billno` = `buy`.`billno`) AS `debet`,'0' AS `kredit`,(select `akun_setup`.`debet` from `akun_setup` where `akun_setup`.`tipe` = 'Pembelian') AS `akun` from `buy` where `buy`.`billno` > 1100 and `buy`.`status` = 'V' 
	
	union all
	select 'Pembelian Tax dari ' AS `jenis`,`buy`.`billdate` AS `billdate`,`buy`.`cust` AS `cust`,(select `supplier`.`nama` from `supplier` where `supplier`.`id` = `buy`.`cust`) AS `custname`,`buy`.`dateadded` AS `dateadded`,'0' AS `debet`,(select sum(`buydetail`.`qty` * `buydetail`.`harga2`) from `buydetail` where `buydetail`.`billno` = `buy`.`billno`) AS `kredit`,(select `akun_setup`.`kredit` from `akun_setup` where `akun_setup`.`tipe` = 'Pembelian') AS `akun` from `buy` where `buy`.`billno` > 1100 and `buy`.`status` = 'V' 
	

	union all
	select 'PPN Pembelian Tax dari ' AS `jenis`,`buy`.`billdate` AS `billdate`,`buy`.`cust` AS `cust`,(select `supplier`.`nama` from `supplier` where `supplier`.`id` = `buy`.`cust`) AS `custname`,`buy`.`dateadded` AS `dateadded`,(select sum(`buydetail`.`qty` * (`buydetail`.`harga2` - `buydetail`.`harga`)) from `buydetail` where `buydetail`.`billno` = `buy`.`billno`) AS `debet`,'0' AS `kredit`,(select `akun_setup`.`debet` from `akun_setup` where `akun_setup`.`tipe` = 'PPNPembelianTAX') AS `akun` from `buy` where `buy`.`billno` > 1100 and `buy`.`status` = 'V'

union all

	select 'Template' AS jenis, '2033-12-31' AS `billdate`,'0' AS cust,'-' AS custname,'2033-12-31 01:00:01' AS `dateadded`,0 AS `debet`,'0' AS `kredit`,'0' AS akun from admins where pk = 1

	union all 
	
	select 'Laba Rugi' AS `Laba Rugi`,`labarugi`.`billdate` AS `billdate`,'0' AS `0`,'-' AS `-`,`labarugi`.`dateadded` AS `dateadded`,0 AS `0`,`labarugi`.`total` AS `total`,57 AS `57` from `labarugi`

 
	 union all select 'PenjualanTax ke ' AS `jenis`,`jualcstax`.`billdate` AS `billdate`,`jualcstax`.`cust` AS `cust`,(select `customer`.`nama` from `customer` where `customer`.`id` = `jualcstax`.`cust`) AS `custname`,`jualcstax`.`dateadded` AS `dateadded`,(select sum(`jualcstaxdetail`.`qty` * (`jualcstaxdetail`.`harga2` - `jualcstaxdetail`.`harga2` * `jualcstaxdetail`.`disc` / 100)) from `jualcstaxdetail` where `jualcstaxdetail`.`billno` = `jualcstax`.`billno` and `jualcstaxdetail`.`ucode` = `jualcstax`.`ucode`) AS `debet`,'0' AS `kredit`,(select `akun_setup`.`debet` from `akun_setup` where `akun_setup`.`tipe` = 'Penjualan') AS `akun` from `jualcstax` where `jualcstax`.`status` = 'N' 
	 
	 union all select 'PenjualanTax ke ' AS `jenis`,`jualcstax`.`billdate` AS `billdate`,`jualcstax`.`cust` AS `cust`,(select `customer`.`nama` from `customer` where `customer`.`id` = `jualcstax`.`cust`) AS `custname`,`jualcstax`.`dateadded` AS `dateadded`,'0' AS `debet`,(select sum(`jualcstaxdetail`.`qty` * (`jualcstaxdetail`.`harga` - `jualcstaxdetail`.`harga` * `jualcstaxdetail`.`disc` / 100)) from `jualcstaxdetail` where `jualcstaxdetail`.`billno` = `jualcstax`.`billno` and `jualcstaxdetail`.`ucode` = `jualcstax`.`ucode`) AS `kredit`,(select `akun_setup`.`kredit` from `akun_setup` where `akun_setup`.`tipe` = 'Penjualan') AS `akun` from `jualcstax` where `jualcstax`.`status` = 'N' 
	 
	 union all select 'PPN PenjualanTax ke ' AS `jenis`,`jualcstax`.`billdate` AS `billdate`,`jualcstax`.`cust` AS `cust`,(select `customer`.`nama` from `customer` where `customer`.`id` = `jualcstax`.`cust`) AS `custname`,`jualcstax`.`dateadded` AS `dateadded`,'0' AS `debet`,(select sum(`jualcstaxdetail`.`qty` * (`jualcstaxdetail`.`harga2` - `jualcstaxdetail`.`harga`)) from `jualcstaxdetail` where `jualcstaxdetail`.`billno` = `jualcstax`.`billno` and `jualcstaxdetail`.`ucode` = `jualcstax`.`ucode`) AS `kredit`,(select `akun_setup`.`kredit` from `akun_setup` where `akun_setup`.`tipe` = 'PPNPenjualanTAX') AS `akun` from `jualcstax` where `jualcstax`.`status` = 'N' 
	 
	 
	 
	 union all
	 
	 select 'Template' AS jenis, '2033-12-31' AS `billdate`,'0' AS cust,'-' AS custname,'2033-12-31 01:00:01' AS `dateadded`,0 AS `debet`,'0' AS `kredit`,'0' AS akun from admins where pk = 1

	union all 
	
	select 'Saldo Awal' AS `jenis`,'2019-12-31' AS `billdate`,'0' AS `supp`,'' AS `custname`,'2020-01-01 07:51:40' AS `dateadded`,`akun_master`.`saldodebet` AS `debet`,`akun_master`.`saldokredit` AS `kredit`,`akun_master`.`id` AS `akun` from `akun_master` where `akun_master`.`del` = 'N' 
 
 union all select concat(`kasmasuk`.`id`,' ',`kasmasuk`.`ket`,' ke ') AS `jenis`,`kasmasuk`.`billdate` AS `billdate`,`kasmasuk`.`supp` AS `supp`,(select `supplier`.`nama` from `supplier` where `supplier`.`id` = `kasmasuk`.`supp`) AS `custname`,`kasmasuk`.`dateadded` AS `dateadded`,`kasmasuk`.`debet` AS `debet`,'0' AS `kredit`,`kasmasuk`.`bank` AS `akun` from `kasmasuk` where `kasmasuk`.`del` = 'N' and `kasmasuk`.`pilih` = 'supp'

 union all select concat(`kasmasuk`.`id`,' ',`kasmasuk`.`ket`,' ke ') AS `jenis`,`kasmasuk`.`billdate` AS `billdate`,`kasmasuk`.`supp` AS `supp`,(select `supplier`.`nama` from `supplier` where `supplier`.`id` = `kasmasuk`.`supp`) AS `custname`,`kasmasuk`.`dateadded` AS `dateadded`,'0' AS `debet`,`kasmasuk`.`kredit` AS `kredit`,`kasmasuk`.`bank2` AS `akun` from `kasmasuk` where `kasmasuk`.`del` = 'N' and `kasmasuk`.`pilih` = 'supp' 
 
 union all select concat(`kasmasuk`.`id`,' ',`kasmasuk`.`ket`,' dari ') AS `jenis`,`kasmasuk`.`billdate` AS `billdate`,`kasmasuk`.`cust` AS `cust`,(select `customer`.`nama` from `customer` where `customer`.`id` = `kasmasuk`.`cust`) AS `custname`,`kasmasuk`.`dateadded` AS `dateadded`,'0' AS `debet`,`kasmasuk`.`kredit` AS `kredit`,`kasmasuk`.`bank2` AS `akun` from `kasmasuk` where `kasmasuk`.`del` = 'N' and `kasmasuk`.`pilih` = 'cust' 
 
 union all select concat(`kasmasuk`.`id`,' ',`kasmasuk`.`ket`,' dari ') AS `jenis`,`kasmasuk`.`billdate` AS `billdate`,`kasmasuk`.`cust` AS `cust`,(select `customer`.`nama` from `customer` where `customer`.`id` = `kasmasuk`.`cust`) AS `custname`,`kasmasuk`.`dateadded` AS `dateadded`,`kasmasuk`.`debet` AS `debet`,'0' AS `kredit`,`kasmasuk`.`bank` AS `akun` from `kasmasuk` where `kasmasuk`.`del` = 'N' and `kasmasuk`.`pilih` = 'cust'
	 
	  union all
	  
	  select 'Template' AS jenis, '2033-12-31' AS `billdate`,'0' AS cust,'-' AS custname,'2033-12-31 01:00:01' AS `dateadded`,0 AS `debet`,'0' AS `kredit`,'0' AS akun from admins where pk = 1

	
	 union all select 'Pembayaran Tax ke ' AS `jenis`,`hutangtax`.`billdate` AS `billdate`,`hutangtax`.`cust` AS `cust`,(select `supplier`.`nama` from `supplier` where `supplier`.`id` = `hutangtax`.`cust`) AS `custname`,`hutangtax`.`dateadded` AS `dateadded`,'0' AS `debet`,(select sum(`hutangtaxdetail`.`harga`) from `hutangtaxdetail` where `hutangtaxdetail`.`billno` = `hutangtax`.`billno`) AS `kredit`,`hutangtax`.`bank` AS `kredit` from `hutangtax` where `hutangtax`.`status` = 'N' 
	 
	 
	 union all select 'Pembayaran Tax ke ' AS `jenis`,`hutangtax`.`billdate` AS `billdate`,`hutangtax`.`cust` AS `cust`,(select `supplier`.`nama` from `supplier` where `supplier`.`id` = `hutangtax`.`cust`) AS `custname`,`hutangtax`.`dateadded` AS `dateadded`,(select sum(`hutangtaxdetail`.`harga`) from `hutangtaxdetail` where `hutangtaxdetail`.`billno` = `hutangtax`.`billno`) AS `total`,'0' AS `kredit`,(select `akun_setup`.`debet` from `akun_setup` where `akun_setup`.`tipe` = 'Pembayaran') AS `akun` from `hutangtax` where `hutangtax`.`status` = 'N' 
	 
	 
	 union all
	 
	 select 'Template' AS jenis, '2033-12-31' AS `billdate`,'0' AS cust,'-' AS custname,'2033-12-31 01:00:01' AS `dateadded`,0 AS `debet`,'0' AS `kredit`,'0' AS akun from admins where pk = 1

	
	 
 union all select 'Pendapatan Tax dari ' AS `jenis`,`piutangtax`.`billdate` AS `billdate`,`piutangtax`.`cust` AS `cust`,(select `customer`.`nama` from `customer` where `customer`.`id` = `piutangtax`.`cust`) AS `custname`,`piutangtax`.`dateadded` AS `dateadded`,(select sum(`piutangtaxdetail`.`harga`) from `piutangtaxdetail` where `piutangtaxdetail`.`billno` = `piutangtax`.`billno`) + `piutangtax`.`total` AS `debet`,'0' AS `kredit`,`piutangtax`.`bank` AS `akun` from `piutangtax` where `piutangtax`.`status` = 'N' 
 
 
 union all select 'Pendapatan Tax dari ' AS `jenis`,`piutangtax`.`billdate` AS `billdate`,`piutangtax`.`cust` AS `cust`,(select `customer`.`nama` from `customer` where `customer`.`id` = `piutangtax`.`cust`) AS `custname`,`piutangtax`.`dateadded` AS `dateadded`,if(`piutangtax`.`total` > 0,'0',`piutangtax`.`total` * -1) AS `debet`,if(`piutangtax`.`total` < 0,'0',`piutangtax`.`total`) AS `kredit`,`piutangtax`.`akun` AS `akun` from `piutangtax` where `piutangtax`.`status` = 'N' 
 
 
 union all select 'Pendapatan Tax dari ' AS `jenis`,`piutangtax`.`billdate` AS `billdate`,`piutangtax`.`cust` AS `cust`,(select `customer`.`nama` from `customer` where `customer`.`id` = `piutangtax`.`cust`) AS `custname`,`piutangtax`.`dateadded` AS `dateadded`,'0' AS `debet`,(select sum(`piutangtaxdetail`.`harga`) from `piutangtaxdetail` where `piutangtaxdetail`.`billno` = `piutangtax`.`billno`) AS `kredit`,(select `akun_setup`.`kredit` from `akun_setup` where `akun_setup`.`tipe` = 'Pendapatan') AS `akun` from `piutangtax` where `piutangtax`.`status` = 'N'
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 