<style type="text/css">
table {
	border-collapse: collapse;
}

th {
	border: 1px solid #000;
}

.center {
  text-align: center;
  vertical-align: middle;
}

table{
    table-layout: fixed;
}

td{
    word-wrap:break-word
}

.border{
	border: 1px solid #000;
}

.align-right{
	text-align: right;
}

.align-center{
	text-align: center;
}
</style>

<table>
	<tbody>
	<tr>
		<td colspan="10" class="center"><h3><b>MUTASI KARTU STOK</b></h3></td>
	</tr>
	@php
	$barang = "Semua Barang";
	if(count($induk['barang']) > 0){
        $barang = $induk['barang']->nama_barang;
    }
    if($induk['tanggal_awal'] != '' && $induk['tanggal_akhir'] != ''){
    	$tgl = date_range($induk['tanggal_awal'], $induk['tanggal_akhir']);
    }
	@endphp
	<tr>
		<td width="5%"></td>
		<td width="15%">Nama Barang</td>
		<td width="5%">:</td>
		<td width="30%">{{ $barang }}</td>

		<td width="15%">Nama Proses</td>
		<td width="5%">:</td>
		<td colspan="4">{{ ($induk['nama_proses'] != '') ? $induk['nama_proses']:"Semua Proses" }}</td>
	</tr>
	<tr>
		<td width="5%"></td>
		<td width="15%">Periode</td>
		<td width="5%">:</td>
		<td width="30%">{{ $tgl }}</td>

		<td width="15%">Warna</td>
		<td width="5%">:</td>
		<td colspan="4">{{ ($induk['nama_komposisi'] != '') ? $induk['nama_komposisi']:"Semua Warna" }}</td>
	</tr>
	<tr>
		<td width="5%"></td>
		<td width="15%">Motif</td>
		<td width="5%">:</td>
		<td width="30%">{{ ($induk['nama_motif'] != '') ? $induk['nama_motif']:"-" }}</td>

		<td width="15%">Lokasi</td>
		<td width="5%">:</td>
		<td colspan="4">{{ ($induk['nama_lokasi'] != '') ? $induk['nama_lokasi']:$induk['lokasi_gudang'] }}</td>
	</tr>

	<tr>
		<td width="5%"></td>
		<td width="15%">Corak</td>
		<td width="5%">:</td>
		<td width="30%">{{ ($induk['nama_corak'] != '') ? $induk['nama_corak']:"-" }}</td>

		<td width="15%">Pemroses</td>
		<td width="5%">:</td>
		@php
		$arr_pemroses = array();
        $pemroses = '';
        if($induk['kelompok'] != ''){
            $arr_pemroses[] = $induk['kelompok'];
            $arr_pemroses[] = $induk['rekanan'];

            $pemroses = get_stripe($arr_pemroses);
        }else if($induk['mesin'] != ''){
            $pemroses = $induk['mesin'];
        }
		@endphp
		<td colspan="4">{{ $pemroses }}</td>
	</tr>
	</tbody>
</table>
<br>
<table>
	<thead>
	<tr>
		<th class="center">NO</th>
		<th colspan="3" class="center">KET BARANG</th>
		<th class="center" colspan="2">SISA</th>
		<th class="center" colspan="2">BIAYA SATUAN</th>
		<th class="center" colspan="2">BIAYA</th>
	</tr>
	</thead>
	<tbody>
		@php 
		$row = "";
		$no = 1;
		$jumlah = array();
		if(count($detail) > 0){
			foreach ($detail as $k){
				$nama_proses = ($induk['nama_proses'] != '') ? get_empty($k->nama_proses):'';
                $nama_komposisi = ($induk['nama_komposisi'] != '') ? '':get_empty($k->inisial_warna);

                $garis = '';
                $garis_proses = '';
                if($k->nama_corak != '' || $nama_komposisi){
                    $garis = " -";
                }
                
                $nama_barang = get_stripe([$k->nama_motif, $nama_komposisi, $k->no_workorder_barang]);
                
                if($k->sisa > 0){
                    
                    $row = "
							<tr>
								<td class='center border'>".$no."</td>
								<td colspan='3' class='align-left border'>".$nama_barang."</td>
								<td class='align-right border' colspan='2'>".format_angkakoma($k->sisa)." ".$k->inisial_satuan."</td>
								<td class='align-right border' colspan='2'>".format_angkakoma($k->harga_satuan)."</td>
								<td class='align-right border' colspan='2'>".format_angkakoma($k->jumlah_harga)."</td>
							</tr>";
                    $no++;

                    if(isset($jumlah[$k->id_satuan])){
                        $jumlah[$k->id_satuan] = ['nama_satuan' => $k->inisial_satuan, 'sisa' => $jumlah[$k->id_satuan]['sisa']+$k->sisa, "harga" => $jumlah[$k->id_satuan]['harga']+$k->jumlah_harga];
                    }else{
                        $jumlah[$k->id_satuan] = ['nama_satuan' => $k->inisial_satuan, 'sisa' => $k->sisa, 'harga' => $k->jumlah_harga];
                    }
                }else{

                }
                echo $row;
			}

			
		}else{
			echo "
				<tr>
					<td class='center border'></td>
					<td colspan='3' class='center border'></td>
					<td colspan='2' class='center border'></td>
					<td colspan='2' class='border'></td>
					<td class='align-right border' colspan='2'></td>
				</tr>
				";
		}
		@endphp


		@php
		$jum = array_merge($jumlah, array());
        $jumlah_total = 0;
        if($jumlah > 0){
            for($i=0; $i<count($jumlah); $i++){
                echo "
					<tr>
						<th class='center border' colspan='6'>T O T A L</th>
						<th class='align-right border' colspan='2'>".format_angkakoma($jum[$i]['sisa'])." ".$jum[$i]['nama_satuan']."</th>
						<th class='align-right border' colspan='2'>".format_angkakoma($jum[$i]['harga'])."</th>
					</tr>";
            }
        }else{
            foreach($jumlah as $j){
                echo "
					<tr>
						<th class='center border' colspan='6'>T O T A L</th>
						<th class='align-right border' colspan='2'>".format_angkakoma($j['sisa'])." ".$j['nama_satuan']."</th>
						<th class='align-right border' colspan='2'>".format_angkakoma("0")."</th>
					</tr>";  
            }  
        }
		@endphp
		
	</tbody>
</table>