<?php
if (!function_exists('pj_fmt_stok_masuk')) {
	function pj_fmt_stok_masuk($val, $maxDec = 2)
	{
		if ($val === null || $val === '') return '0';

		$n = (float) $val;
		if (abs($n - round($n)) < 0.000000001) {
			return number_format($n, 0, ',', '.');
		}

		$s = number_format(round($n, $maxDec), $maxDec, ',', '.');
		return rtrim(rtrim($s, '0'), ',');
	}
}
?>
<div class="card-block stok-masuk-results">
	<table class="table table-striped table-mailcard stok-masuk-table">
		<thead>
			<tr>
				<th class="w-1 text-center">No</th>
				<th class="w-10 pl-1">Nama bahan</th>
				<th class="w-8 text-right">Stok Masuk</th>
				<th class="w-8 text-right">Aksi</th>
			</tr>
		</thead>
		<tbody>
			<?php if(!empty($result)){
				$no = 1;
				foreach ($result as $row){
					$jml_masuk = stok_masuk($row->id);
					$disabled = '';
					if($jml_masuk <= 0 ){
						$disabled = 'disabled';
					}
					echo "<tr><td class='text-center'>$no</td>
					<td class='pl-1'>".$row->title."</td>
					<td class='text-right'>".pj_fmt_stok_masuk($jml_masuk)."</td>
					<td class='text-right'>
					<div class='btn-group btn-group-sm' role='group'>
					<button type='button' class='btn btn-info btn-sm detail_stok_masuk' data-id='".$row->id."' data-title='".$row->title."' ".$disabled."><i class='fa fa-search'></i> Detail</button>
					<button type='button' class='btn btn-secondary btn-sm flat print_stok_masuk' data-toggle='tooltip' data-id='".$row->id."' data-original-title='Print PDF'><i class='fa fa-file-pdf-o fa-1x'></i> Print</button>
					</div>
					</td>
					</tr>";
					$no++;
				}
			}else{ ?>
			<tr>
				<td colspan="4">Data belum ada</td>
			</tr>
			<?php } ?>
		</tbody>
	</table>

	<div class="stok-masuk-mobile-list">
		<?php if(!empty($result)){
			$no = 1;
			foreach ($result as $row){
				$jml_masuk = stok_masuk($row->id);
				$disabled = '';
				if($jml_masuk <= 0 ){
					$disabled = 'disabled';
				}
		?>
		<div class="stok-masuk-mobile-card">
			<div class="stok-masuk-mobile-number"><?php echo $no; ?></div>
			<div class="stok-masuk-mobile-main">
				<div class="stok-masuk-mobile-title"><?php echo $row->title; ?></div>
				<div class="stok-masuk-mobile-label">Stok Masuk</div>
				<div class="stok-masuk-mobile-value"><?php echo pj_fmt_stok_masuk($jml_masuk); ?> pcs</div>
			</div>
			<div class="stok-masuk-mobile-actions">
				<button type="button" class="stok-masuk-mobile-btn stok-masuk-mobile-btn-detail detail_stok_masuk" data-id="<?php echo $row->id; ?>" data-title="<?php echo htmlspecialchars($row->title, ENT_QUOTES, 'UTF-8'); ?>" <?php echo $disabled; ?>>
					<i class="fa fa-search"></i> Detail
				</button>
				<button type="button" class="stok-masuk-mobile-btn stok-masuk-mobile-btn-print print_stok_masuk" data-id="<?php echo $row->id; ?>" data-toggle="tooltip" data-original-title="Print PDF">
					<i class="fa fa-print"></i> Print
				</button>
			</div>
		</div>
		<?php $no++; } ?>
		<div class="stok-masuk-mobile-info">
			<i class="fa fa-info-circle"></i>
			<span>Menampilkan : <?php echo count($result); ?></span>
		</div>
		<?php } else { ?>
		<div class="stok-masuk-mobile-empty">Data belum ada</div>
		<?php } ?>
	</div>

	<nav aria-label="Page navigation" class="mt-2 stok-masuk-pagination">
		<?php echo $this->ajax_pagination->create_links(); ?>
	</nav>
</div><!-- /.card-body -->
