<?php
//===GET===
$sql['get_data'] = "
   SELECT 
      CONCAT(LPAD(golbrgKode,'2','0'),'.',LPAD(bidangbrgKode,'2','0')) as `kodeBidang`,
      `bidangbrgNama` as `namaBidang`,
      CONCAT(LPAD(golbrgKode,'2','0'),'.',LPAD(bidangbrgKode,'2','0'),'.',LPAD(kelbrgKode,'2','0')) as `kode`,
      `kelbrgId` as `id`,
      `kelbrgNama` 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`)
      LEFT JOIN (SELECT subkelbrgKelbrgId as id, MAX(subkelbrgKode) as last_code FROM sub_kelompok_barang_ref GROUP BY subkelbrgKelbrgId) a ON id = kelbrgId
   WHERE
      `bidangbrgId` = %d %OPERATOR%
      (CONCAT(LPAD(golbrgKode,'2','0'),'.',LPAD(bidangbrgKode,'2','0'),'.',LPAD(kelbrgKode,'2','0')) LIKE '%s' OR `kelbrgNama` LIKE '%s')
   ORDER BY 
      `bidangbrgNama`, `kelbrgNama`
   LIMIT %d, %d
   ";

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