<?php
//===GET===
$sql['get_data'] = "
   SELECT
      CONCAT(LPAD(golbrgKode,'2','0'),'.',LPAD(bidangbrgKode,'2','0'),'.',LPAD(kelbrgKode,'2','0')) as `kodeKelompok`,
      `kelbrgNama` as `namaKelompok`,
      CONCAT(LPAD(golbrgKode,'2','0'),'.',LPAD(bidangbrgKode,'2','0'),'.',LPAD(kelbrgKode,'2','0'),'.',LPAD(subkelbrgKode,'2','0')) as `kode`,
      `subkelbrgId` as `id`,
      `subkelbrgNama` as `nama`,
      IFNULL(last_code,0) last_code
   FROM 
      `golongan_barang_ref`
      JOIN `bidang_barang_ref` ON (`bidangbrgGolbrgId` = `golbrgId`)
      JOIN `kelompok_barang_ref` ON (`kelbrgBidangbrgId` = `bidangbrgId`)
      JOIN `sub_kelompok_barang_ref` ON (`subkelbrgKelbrgId` = `kelbrgId`)
      LEFT JOIN (SELECT barangSubkelbrgId as id, MAX(barangKode) as last_code FROM barang_ref GROUP BY barangSubkelbrgId) a ON id = subkelbrgId
   WHERE
      `kelbrgId` = %d %OPERATOR%
      (CONCAT(LPAD(golbrgKode,'2','0'),'.',LPAD(bidangbrgKode,'2','0'),'.',LPAD(kelbrgKode,'2','0'),'.',LPAD(subkelbrgKode,'2','0')) LIKE '%s' OR `subkelbrgNama` LIKE '%s')
   ORDER BY 
      `kelbrgNama`, `subkelbrgNama`
   LIMIT %d, %d
   ";

$sql['get_count_data'] = "
   SELECT 
      COUNT(`subkelbrgNama`) as `total`
   FROM 
      `golongan_barang_ref`
      JOIN `bidang_barang_ref` ON (`bidangbrgGolbrgId` = `golbrgId`)
      JOIN `kelompok_barang_ref` ON (`kelbrgBidangbrgId` = `bidangbrgId`)
      JOIN `sub_kelompok_barang_ref` ON (`subkelbrgKelbrgId` = `kelbrgId`)
   WHERE
      `kelbrgId` = %d %OPERATOR%
      (CONCAT(LPAD(golbrgKode,'2','0'),'.',LPAD(bidangbrgKode,'2','0'),'.',LPAD(kelbrgKode,'2','0'),'.',LPAD(subkelbrgKode,'2','0')) LIKE '%s' OR `subkelbrgNama` LIKE '%s')
   ";
?>
