<?php

   $sql['get_combo_usulan_status'] ="
      SELECT
         usulanStatusId AS `id`,
         usulanStatusNama AS `name`
      FROM
         aset_pb_usulan_status
      WHERE usulanStatusId NOT IN(1,2)
    ";
	
	$sql['get_generate_number'] ="
      SELECT
		  usulanBrgId,
		  usulanBrgNoUsulan
		FROM aset_pb_usulan_brg
		ORDER BY usulanBrgNoUsulan DESC
		LIMIT 0,1
    ";

	//-- get data here
	$sql['get_data_status'] ="
		SELECT
		  usulanStatusId   AS id,
		  usulanStatusNama AS `name`
		FROM aset_pb_usulan_status
   ";
	
	$sql['get_data_count_usulan_barang'] ="
		SELECT
		  COUNT(DISTINCT usulanBrgId) AS total
		FROM aset_pb_usulan_brg
		  LEFT JOIN unit_kerja_ref
			 ON unitkerjaId = usulanBrgUnitId
		  LEFT JOIN aset_pb_usulan_brg_det
			 ON usulanBrgDetUsulanBrgId = usulanBrgId
		  LEFT JOIN aset_pb_usulan_status
			 ON usulanStatusId = usulanBrgStatusId
		WHERE (usulanStatusId='%s' OR 'all'='%s')
   ";
	
	$sql['get_data_usulan_barang'] ="
		SELECT
		  usulanBrgId        AS id,
		  usulanBrgTglUsulan AS tanggal,
		  usulanBrgNoUsulan  AS kode,
		  unitkerjaNama      AS unit,
		  COUNT(usulanBrgDetId) AS jumlah,
		  usulanBrgPIC       AS pic,
		  usulanStatusNama   AS `status`,
		  usulanStatusId   AS `status_id`
		FROM aset_pb_usulan_brg
		  LEFT JOIN unit_kerja_ref
			 ON unitkerjaId = usulanBrgUnitId
		  LEFT JOIN aset_pb_usulan_brg_det
			 ON usulanBrgDetUsulanBrgId = usulanBrgId
		  LEFT JOIN aset_pb_usulan_status
			 ON usulanStatusId = usulanBrgStatusId
		WHERE (usulanStatusId='%s' OR 'all'='%s')
		GROUP BY usulanBrgId
		ORDER BY usulanBrgId DESC 
		LIMIT %s, %s
   ";
	
	$sql['get_data_usulan_barang_by_id'] ="
		SELECT
		  usulanBrgId          AS usulanId,
		  usulanBrgTglUsulan   AS tanggal,
		  usulanBrgNoUsulan    AS no_usulan,
		  unitkerjaNama        AS unit_name,
		  unitkerjaId          AS unit_id,
		  usulanBrgPIC         AS pic,
		  usulanBrgFile        AS `file`,
		  usulanBrgKet         AS keterangan,
		  usulanBrgDetBrgId    AS brgId,
		  CONCAT(LPAD(golbrgKode, 1, '0'), '.', 
		  LPAD(bidangbrgKode, 2, '0'), '.', 
		  LPAD(kelbrgKode, 2, '0'), '.', 
		  LPAD(subkelbrgKode, 2, '0'), '.', 
		  LPAD(barangKode, 3, '0')) AS `brgKode`,
		  barangNama           AS brgNama,
		  usulanBrgNilaiHps    AS brgHps,
		  usulanBrgDetJml	     AS jmlDO,
		  usulanBrgNilaiUsulan AS brgNilai
		FROM aset_pb_usulan_brg
		  LEFT JOIN unit_kerja_ref
			 ON unitkerjaId = usulanBrgUnitId
		  LEFT JOIN aset_pb_usulan_brg_det
			 ON usulanBrgDetUsulanBrgId = usulanBrgId
		  LEFT JOIN barang_ref
			 ON barangId = usulanBrgDetBrgId
		  JOIN sub_kelompok_barang_ref
			 ON subkelbrgId = barangSubkelbrgId
		  JOIN kelompok_barang_ref
			 ON kelbrgId = subkelbrgKelbrgId
		  JOIN bidang_barang_ref
			 ON bidangbrgId = kelbrgBidangbrgId
		  JOIN golongan_barang_ref
			 ON golbrgId = bidangbrgGolbrgId
		WHERE usulanBrgId = '%s'
   ";
	//-- end of get data
	
	//-- do add here
   $sql['add_usulan'] ="
		INSERT INTO aset_pb_usulan_brg
            (usulanBrgTglUsulan,
             usulanBrgNoUsulan,
             usulanBrgUnitId,
             usulanBrgPIC,
             usulanBrgKet,
             usulanBrgFile,
             usulanBrgUserId,
             usulanBrgTglUbah)
		VALUES ('%s',
				  '%s',
				  '%s',
				  '%s',
				  '%s',
				  '%s',
				  '%s',
				  NOW())
   ";
	
	$sql['add_detail_barang'] ="
		INSERT INTO aset_pb_usulan_brg_det
            (usulanBrgDetUsulanBrgId,
             usulanBrgDetBrgId,
             usulanBrgDetJml,
             usulanBrgNilaiHps,
             usulanBrgNilaiUsulan,
             usulanBrgTanggal,
             usulangBrgUserId)
		VALUES ('%s',
				  '%s',
				  '%s',
				  '%s',
				  '%s',
				  NOW(),
				  '%s')
   ";
	
	$sql['add_history_barang'] ="
		INSERT INTO aset_pb_usulan_history_status
            (usulanHistUsulanBrgId,
             usulanHistTglJamPengubahan,
             usulanHistStatusId,
             usulanHistUserId)
		VALUES ('%s',
				  NOW(),
				  '%s',
				  '%s')
   ";
	
	$sql['update_usulan'] ="
		UPDATE aset_pb_usulan_brg
		SET usulanBrgTglUsulan = '%s',
		  usulanBrgUnitId = '%s',
		  usulanBrgPIC = '%s',
		  usulanBrgKet = '%s',
		  usulanBrgFile = '%s',
		  usulanBrgUserId = '%s',
		  usulanBrgTglUbah = NOW()
		WHERE usulanBrgId = '%s'
   ";
	
	$sql['delete_detail_usulan_barang'] ="
		DELETE
		FROM aset_pb_usulan_brg_det
		WHERE usulanBrgDetUsulanBrgId = '%s'
   ";
	
	$sql['delete_usulan_barang'] ="
		DELETE
		FROM aset_pb_usulan_brg
		WHERE usulanBrgId = '%s'
   ";
?>