<?php
//===GET===
$sql['get_data'] = 
   "SELECT 
      golbrgId as gol_id,
      CONCAT(LPAD(golbrgKode,'2','0'),'.00') as gol_kode,
      golbrgNama as gol_nama,
      bidangbrgId as id,
      CONCAT(LPAD(golbrgKode,'2','0'),'.',LPAD(bidangbrgKode,'2','0')) as kode,
      bidangbrgId as id,
      bidangbrgNama as nama,
      IFNULL(last_code, 0) as last_code
   FROM 
      golongan_barang_ref as a
      JOIN bidang_barang_ref as b ON (b.bidangbrgGolbrgId = a.golbrgId)
      LEFT JOIN (SELECT kelbrgBidangbrgId as id, MAX(kelbrgKode) as last_code FROM kelompok_barang_ref GROUP BY kelbrgBidangbrgId) c ON id = bidangbrgId
	WHERE
      golbrgId = %d %OPERATOR%
      (CONCAT(LPAD(golbrgKode,'2','0'),'.',LPAD(bidangbrgKode,'2','0')) LIKE '%s' OR bidangbrgNama LIKE '%s')
   ORDER BY 
      golbrgNama, bidangbrgNama
   LIMIT %d, %d";

$sql['get_count_data'] = 
   "SELECT 
      count(*) AS total
   FROM 
      golongan_barang_ref
      JOIN bidang_barang_ref ON (bidangbrgGolbrgId = golbrgId)
	WHERE
      golbrgId = %d %OPERATOR%
      (CONCAT(LPAD(golbrgKode,'2','0'),'.',LPAD(bidangbrgKode,'2','0')) LIKE '%s' OR bidangbrgNama LIKE '%s')
";

$sql['get_bidang_by_id'] = 
   "SELECT 
      golbrgId as gol_id,
      golbrgNama as gol_nama,
      bidangbrgId as id,
      bidangbrgKode as kode,
      bidangbrgNama as nama
   FROM 
      golongan_barang_ref
      JOIN bidang_barang_ref ON (bidangbrgGolbrgId = golbrgId)
	WHERE 
      bidangbrgId = %d
   LIMIT 1";

$sql['get_golongan_by_id'] = 
   "SELECT 
      golbrgKode as kode,
      golbrgNama as nama
   FROM 
      golongan_barang_ref
   WHERE
      golbrgId = '%s'";

$sql['get_combo_golongan'] = 
   "SELECT 
     golbrgId as id,
	  golbrgNama as name
   FROM 
      golongan_barang_ref
   ORDER BY golbrgNama
";

$sql['get_golongan_list'] = 
   "SELECT
      golbrgId as id,
      golbrgNama as name,
      CONCAT(LPAD(golbrgKode,'2','0'),'.00') as kode,
      bidangbrgId as bidang
   FROM
      golongan_barang_ref
      LEFT JOIN bidang_barang_ref ON golbrgId = bidangbrgGolbrgId
   GROUP BY golbrgId
   ORDER BY golbrgNama
";
?>
