<?php
require_once "common/config.php";
$q = strtoupper($_GET["q"]);
$id_branchfrom = $_GET['id_branchfrom']; //echo $id_branchfrom; exit;
if (!$q) return;

if($id_branchfrom == 0)
											{
             $sql = "select type,kode_stock,barcodeno,id_stock from
									  (select 'Diamond' as type,kode_stock,barcodeno,id_stock from  inventory_diamond where id_branch = 1 and status_stock=1
									  union all
									  select 'Gold' as type,kode_stock,barcodeno,id_stock from  inventory_gold  where id_branch = 1 and status_stock=1
									  union all
									  select 'Logam Mulia' as type,kode_stock,barcodeno,id_stock from  inventory_logam  where id_branch = 1 and status_stock=1
									  union all
									  select 'Ready Item' as type,kode_stock,barcodeno,id_stock from  inventory_readyitem  where id_branch = 1 and status_stock=1
									   union all
									  select 'Cincin' as type,kode_stock,barcodeno,id_stock from  inventory_cincin  where id_branch = 1 and status_stock=1 							
									  union all
									  select 'Mastura' as type,kode_stock,barcodeno,id_stock from  inventory_mastura  where id_branch = 1 and status_stock=1
									   
									   union all
									  select 'Liontin' as type,kode_stock,barcodeno,id_stock from  inventory_liontin  where id_branch = 1 and status_stock=1
									  union all
									  select 'Kerabu' as type,kode_stock,barcodeno,id_stock from  inventory_kerabu  where id_branch = 1 and status_stock=1
									  union all
									  select 'Gelang Kaku Gelang Rantai' as type,kode_stock,barcodeno,id_stock from  inventory_gkgr  where id_branch = 1 and status_stock=1
									  union all
									  select 'Rangka' as type,kode_stock,barcodeno,id_stock from  inventory_rangka  where id_branch = 1 and status_stock=1) a
											where kode_stock not in (select kode_stock from inventory_detailsconsigment a inner join inventory_consigment b on a.id_consigment = b.id_consigment
											where status_consigment = 1 and user_receive = '')
									  order by type,kode_stock,barcodeno";
											}
											else
											{
											$sql = "select type,kode_stock,barcodeno,id_stock from
											  (select 'Diamond' as type,kode_stock,barcodeno,id_stock from  inventory_diamond where id_branch='$id_branchfrom' and status_stock=1
											  union all
											  select 'Gold' as type,kode_stock,barcodeno,id_stock from  inventory_gold  where id_branch='$id_branchfrom' and status_stock=1
											  union all
											  select 'Logam Mulia' as type,kode_stock,barcodeno,id_stock from  inventory_logam  where id_branch='$id_branchfrom' and status_stock=1
											  union all
											  select 'Ready Item' as type,kode_stock,barcodeno,id_stock from  inventory_readyitem  where id_branch='$id_branchfrom' and status_stock=1
											   union all
									  select 'Cincin' as type,kode_stock,barcodeno,id_stock from  inventory_cincin  where id_branch='$id_branchfrom' and status_stock=1 							
									  union all
									  select 'Mastura' as type,kode_stock,barcodeno,id_stock from  inventory_mastura  where id_branch='$id_branchfrom' and status_stock=1
									   
									   union all
									  select 'Liontin' as type,kode_stock,barcodeno,id_stock from  inventory_liontin  where id_branch='$id_branchfrom' and status_stock=1
									  union all
									  select 'Kerabu' as type,kode_stock,barcodeno,id_stock from  inventory_kerabu  where id_branch='$id_branchfrom' and status_stock=1
									  union all
									  select 'Gelang Kaku Gelang Rantai' as type,kode_stock,barcodeno,id_stock from  inventory_gkgr  where id_branch='$id_branchfrom' and status_stock=1
									  union all
									  select 'Rangka' as type,kode_stock,barcodeno,id_stock from  inventory_rangka  where id_branch='$id_branchfrom' and status_stock=1) a
													where kode_stock not in (select kode_stock from inventory_detailsconsigment a inner join inventory_consigment b on a.id_consigment = b.id_consigment
													where status_consigment = 1 and user_receive = '')
											  order by type,kode_stock,barcodeno";
											}
											
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
	$cname = $rs['kode_stock']."-".$rs['type']."-".$rs['barcodeno'];
	echo "$cname\n";
}
?>