<?php
//===GET===
$sql['get_data'] = 
   "SELECT 
      golbrgId as gol_id,
      (golbrgKode*100) as gol_kode,
      golbrgNama as gol_nama,
      bidangbrgId as id,
      ((golbrgKode*100)+bidangbrgKode) as kode,
      bidangbrgNama as nama
   FROM 
      golongan_barang_ref as a
      JOIN bidang_barang_ref as b ON (b.bidangbrgGolbrgId = a.golbrgId)
	WHERE
      golbrgId = %d %OPERATOR%
      (((golbrgKode*100)+bidangbrgKode) 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%
      (((golbrgKode*100)+bidangbrgKode) 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,
      (golbrgKode*100) as kode,
      bidangbrgId as bidang
   FROM
      golongan_barang_ref
      LEFT JOIN bidang_barang_ref ON golbrgId = bidangbrgGolbrgId
   GROUP BY golbrgId
   ORDER BY golbrgNama
";

$sql['get_kode_golongan_last'] = 
   "SELECT
      MAX(golbrgKode) as kode
   FROM
      golongan_barang_ref
";

$sql['cek_kode_golongan'] = 
   "SELECT
      golbrgId as id
   FROM
      golongan_barang_ref
   WHERE
      golbrgKode = %s
";

$sql['get_kode_bidang_last'] = "
SELECT
   bidangbrgGolbrgId as id,
   MAX(bidangbrgKode) as kode
FROM
   bidang_barang_ref
GROUP BY
   bidangbrgGolbrgId
";

$sql['cek_kode_bidang'] = 
   "SELECT
      bidangbrgId as id
   FROM
      bidang_barang_ref
   WHERE
      bidangbrgKode = %s AND
      bidangbrgGolbrgId = %s
";

//===DO===
$sql['do_add_golongan'] = "
   INSERT INTO
      golongan_barang_ref
      (
         golbrgKode,
         golbrgNama
      )
   VALUES
      (
         %d,
         '%s'
      )";

$sql['do_update_golongan'] = "
   UPDATE
      golongan_barang_ref
   SET
         golbrgKode = %d,
         golbrgNama = %s
   WHERE
      golbrgId = %d";
		
$sql['do_add_bidang'] = "
   INSERT INTO
      bidang_barang_ref
      (
			bidangbrgGolbrgId,
         bidangbrgKode,
         bidangbrgNama
      )
   VALUES
      (
         %d,
			%d,
         '%s'
      )";

$sql['do_update_bidang'] = "
   UPDATE
      bidang_barang_ref
   SET
		bidangbrgGolbrgId = %d,
		bidangbrgKode = %d,
		bidangbrgNama = '%s'
   WHERE
      bidangbrgId = %d";

$sql['do_delete_bidang'] = "
   DELETE FROM
      bidang_barang_ref
   WHERE
      bidangbrgId = %d";

$sql['do_mass_delete_bidang'] = "
   DELETE FROM
      bidang_barang_ref
   WHERE
      bidangbrgId IN (%s)";

$sql['do_delete_golongan'] = "
   DELETE FROM
      golongan_barang_ref
   WHERE
      golbrgId = %d";

$sql['do_mass_delete_golongan'] = "
   DELETE FROM
      golongan_barang_ref
   WHERE
      golbrgId IN (%s)";

?>
