<?php
if (!function_exists('harga_satuan_format')) {
	function harga_satuan_format($value) {
		$value = (string) $value;
		$parts = explode('.', $value, 2);
		$whole = preg_replace('/\D/', '', $parts[0]);
		$decimal = isset($parts[1]) ? rtrim(preg_replace('/\D/', '', $parts[1]), '0') : '';
		$formatted = number_format((int) ($whole === '' ? 0 : $whole), 0, ',', '.');
		return $decimal === '' ? $formatted : $formatted . ',' . $decimal;
	}
}
?>
<tr class="table-row" id="table-satuan-<?php echo $id; ?>" data-id="<?php echo $satuan; ?>" data-row="<?php echo $a; ?>">
	<td class="satuan-row-number"><?= $no; ?></td>
	<td onChange="getData(<?= $a; ?>,<?= $id; ?>)">
		<select name="load_satuan_edit" id="load_satuan_<?= $a; ?>" class="form-control form-control-sm satuan-unit-select"
		data-valueKey="id" data-displayKey="name" required>
		</select>
	</td>
	<td class="satuan-price-cell" contenteditable="true" title="Klik untuk mengubah harga beli" onBlur="saveToDatabase(this,'harga_pokok','<?php echo $id; ?>')"
	onClick="editRow(this);"><?php echo harga_satuan_format($harga_pokok); ?></td>
	<td class="satuan-price-cell" contenteditable="true" title="Klik untuk mengubah harga jual" onBlur="saveToDatabase(this,'harga_jual','<?php echo $id; ?>')" onClick="editRow(this);">
	<?php echo harga_satuan_format($harga_jual); ?></td>
	<td><button class="btn btn-sm satuan-delete-btn" title="Hapus satuan" aria-label="Hapus satuan" onclick="deleteRecord(<?php echo $id; ?>);"><i class="fa fa-trash"></i></button></td>
</tr>
