<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title><?=$title;?></title>
		<link href="<?= $favicon;?>" rel="icon">
		<style>
			@page {
			margin: 0 0;
            }
			body {
			margin-top: 0cm;
			margin-left: 0.5cm;
			margin-right: 1cm;
			margin-bottom: 0cm;
			font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;
            }
			
			.invoice-box {
			position: relative;
			width:100%;
			margin: 0 auto;
			padding: 10px;
			font-size: 12px;
			line-height: 18px;
			font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;
			color: #555;
			}
			.spk-page-label{position:absolute;top:10px;right:12px;font-size:9pt;font-weight:bold;color:#666;line-height:12px;text-align:right}
			.plate-box{display:inline-block;width:13px;height:13px;border:1.3px solid #444;text-align:center;font-family:DejaVu Sans,sans-serif;font-size:10px;font-weight:bold;line-height:12px;color:#fff;vertical-align:-1px}.plate-box.is-checked{background:#111;border-color:#111}
			
            /** Define the footer rules **/
            footer {
			position: fixed; 
			bottom: 0cm; 
			left: 0cm; 
			right: 0cm;
			height: 0.5cm;
			padding:5px;
			
			/** Extra personal styles **/
			background-color: <?=$color;?>;
			color: white;
			text-align: center;
            }
			.invoice-box table {
			width: 100%;
			line-height: inherit;
			text-align: left;
			}
			
			.invoice-box table td {
			padding: 0 5px 0 5px;
			vertical-align: top;
			}
			
			.invoice-box table tr td:nth-child(2) {
			
			}
			
			.invoice-box table tr.top table td {
			padding-bottom: 0;
			}
			
			.invoice-box table tr.top table td.title {
			font-size: 45px;
			line-height: 45px;
			color: #333;
			}
			
			.invoice-box table tr.information table td {
			
			}
			
			.invoice-box table tr.heading td {
			background: <?=$color;?>;
			color: #fff;
			font-weight: normal;
			padding: 5px;
			text-transform: uppercase;
			}
			
			.invoice-box table tr.details td {
			padding-bottom: 20px;
			}
			
			.invoice-box table tr.item td{
			border-bottom: 1px solid <?=$color;?>;
			}
			.invoice-box table tr.item td{
			border-bottom: 1px solid <?=$color;?>;
			}
			.invoice-box table tr.item1:first-child td {
			border-bottom:1px dotted <?=$color;?>;  
			}
			.invoice-box table tr.item2:first-child td {
			border-bottom:1px solid <?=$color;?>;  
			}
			
			.invoice-box table tr.item2:last-child td {
			border-top:1px dotted <?=$color;?>;  
			border-bottom:1px solid <?=$color;?>;  
			}
			
			.invoice-box table tr.kepada td{
			font-weight:bold;
			color: #fff;
			border-bottom:1px dotted #000
			}
			
			.invoice-box table tr.detail td{
			border-bottom:1px dotted #000
			}
			
			.invoice-box table td.tdetail {
			border-bottom:1px dotted #fff !important;
			width:250px!important
			}
			
			.invoice-box table td.detail_tgl {
			border-bottom:1px dotted #fff !important;
			}
			
			.invoice-box table td.sub-detail {
			border-bottom:1px dotted #fff !important;
			}
			
			.invoice-box table tr.item.last td {
			
			}
			.invoice-box table tr.total{
			font-weight: bold;
			text-align:right;
			}
			.invoice-box table tr.hormat{
			font-weight: bold;
			text-align:left;
			}
			.invoice-box table tr.pelanggan{
			font-weight: bold;
			text-align:center;
			}
			.invoice-box table td.total {
			text-align:right;
			}
			.invoice-box table td.tgl {
			font-weight:bold;
			border-bottom:1px dotted #000;
			}
			.invoice-box table td.tkepada {
			background:<?=$color;?>;
			opacity:0.7;
			width:12%!important
			}
			.invoice-box table tr.alamat{
			color:#000;
			width:50%!important;
			vertical-align: top!important;
			}
			.invoice-box table tr.kepada td.bawah {
			color:#000;
			font-weight:normal;
			width:30%!important
			}
			
			.invoice-box table tr.alamat td.nomor {
			font-weight:bold;
			vertical-align: text-bottom!important;
			}
			.invoice-box table td.total1 {
			border-left:1px solid <?=$color;?>;
			border-top:1px solid <?=$color;?>;
			border-bottom:1px dotted <?=$color;?>;
			}
			.invoice-box table td.total2 {
			border-top:1px solid <?=$color;?>;
			border-right:1px solid <?=$color;?>;
			border-bottom:1px dotted <?=$color;?>;
			text-align:right;
			font-weight:bold;
			}
			
			.invoice-box table td.lunas1 {
			border-left:1px solid <?=$color;?>;
			border-bottom:1px solid <?=$color;?>;
			background:<?=$color;?>;
			color:#fff;
			}
			.invoice-box table td.lunas2 {
			border-right:1px solid <?=$color;?>;
			border-bottom:1px solid <?=$color;?>;
			text-align:right;
			font-weight:bold;
			background:<?=$color;?>;
			color:#fff;
			}
			
			.invoice-box table td.umuka1 {
			border-left:1px solid <?=$color;?>;
			border-bottom:1px dotted <?=$color;?>;
			}
			.invoice-box table td.umuka2 {
			border-right:1px solid <?=$color;?>;
			border-bottom:1px dotted <?=$color;?>;
			text-align:right;
			font-weight:bold;
			}
			
			.invoice-box table td.sisa1 {
			border-left:1px solid <?=$color;?>;
			border-bottom:1px solid <?=$color;?>;
			}
			.invoice-box table td.sisa2 {
			border-right:1px solid <?=$color;?>;
			border-bottom:1px solid <?=$color;?>;
			text-align:right;
			font-weight:bold;
			}
			.invoice-box table td.ttd {
			border-bottom:1px dotted <?=$color;?>;
			text-align:center;
			font-weight:bold;
			}
			.invoice-box table td.border {
			border-right:1px dotted <?=$color;?>;
			}
			
			
			.invoice-box .table img{
			position: fixed;
			z-index:-1000;
			width:200px;
			}
			
			.alamat{font-size:11pt;}
			.sosmed{font-size:8pt;}
			
		</style>
		<?php if($html=="Y"){ ?>
			<style>
				@media print {
				.invoice-box {
				width:100%;
				margin: auto;
				padding: 10px;
				font-size: 12px;
				line-height: 18px;
				font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;
				color: #555;
				}
				
				.invoice-box table {
				width: 100%;
				line-height: inherit;
				text-align: left;
				}
				
				.invoice-box table td {
				padding: 0 5px 0 5px;
				vertical-align: top;
				}
				
				.invoice-box table tr td:nth-child(2) {
				
				}
				
				.invoice-box table tr.top table td {
				padding-bottom: 0;
				}
				
				.invoice-box table tr.top table td.title {
				font-size: 45px;
				line-height: 45px;
				color: #333;
				}
				
				.invoice-box table tr.information table td {
				
				}
				
				.invoice-box table tr.heading td {
				background: #<?=$color;?>;
				color: #fff;
				font-weight: normal;
				padding: 5px;
				text-transform: uppercase;
				}
				
				.invoice-box table tr.details td {
				padding-bottom: 20px;
				}
				
				.invoice-box table tr.item td{
				border-bottom: 1px solid #000;
				
				}
				.invoice-box table tr.kepada td{
				font-weight:bold;
				color: #fff;
				border-bottom:1px dotted #000
				}
				
				.invoice-box table tr.item.last td {
				
				}
				.invoice-box table tr.total{
				font-weight: bold;
				text-align:right;
				}
				.invoice-box table tr.hormat{
				font-weight: bold;
				text-align:left;
				}
				.invoice-box table tr.pelanggan{
				font-weight: bold;
				text-align:center;
				}
				.invoice-box table td.total {
				text-align:right;
				}
				.invoice-box table td.tgl {
				font-weight:bold;
				border-bottom:1px dotted #000;
				}
				.invoice-box table td.tkepada {
				background:#<?=$color;?>;
				opacity:0.7;
				width:12%!important
				}
				.invoice-box table tr.kepada td.bawah {
				color:#000;
				width:30%!important
				}
				.invoice-box table td.nomor {
				font-weight:bold;
				}
				.invoice-box table td.total1 {
				border-left:1px solid <?=$color;?>;
				border-top:1px solid <?=$color;?>;
				border-bottom:1px dotted <?=$color;?>;
				}
				.invoice-box table td.total2 {
				border-top:1px solid <?=$color;?>;
				border-right:1px solid <?=$color;?>;
				border-bottom:1px dotted <?=$color;?>;
				text-align:right;
				font-weight:bold;
				}
				.invoice-box table td.lunas1 {
				border-left:1px solid <?=$color;?>;
				border-bottom:1px solid <?=$color;?>;
				}
				.invoice-box table td.lunas2 {
				border-right:1px solid <?=$color;?>;
				border-bottom:1px solid <?=$color;?>;
				text-align:right;
				font-weight:bold;
				}
				.invoice-box table td.umuka1 {
				border-left:1px solid <?=$color;?>;
				border-bottom:1px dotted <?=$color;?>;
				}.invoice-box table td.umuka2 {
				border-right:1px solid <?=$color;?>;
				border-bottom:1px dotted <?=$color;?>;
				text-align:right;
				font-weight:bold;
				}
				.invoice-box table td.sisa1 {
				border-left:1px solid <?=$color;?>;
				border-bottom:1px solid <?=$color;?>;
				}
				.invoice-box table td.sisa2 {
				border-right:1px solid <?=$color;?>;
				border-bottom:1px solid <?=$color;?>;
				text-align:right;
				font-weight:bold;
				}
				.invoice-box table td.ttd {
				border-bottom:1px dotted #000;
				text-align:center;
				font-weight:bold;
				}
				.invoice-box table td.border {
				border-right:1px dotted #000;
				}
				
				
				.invoice-box .table img{
				position: fixed;
				z-index:-1000;
				}
				.watermark{
				top:<?=$top;?>;
				right:4cm;
				width:    4.5cm;
				height:   auto;
				opacity:0.2;
				z-index:-1
				
				/** Your watermark should be behind every content**/
				}
				.sosmed{font-size:8pt;}
				}
			</style>
			<script type="text/javascript">
				<!--
				window.print();
				window.onfocus=function(){ window.close();}
				//-->
			</script>
			<?php }
			
		?>
		<style>
			img.logo{max-width:300px;max-height:100px}
			.invoice-box table.finishing-options td{border-bottom:0!important;padding:0 10px 0 0!important;height:18px;white-space:nowrap;vertical-align:middle}
			.invoice-box table.finishing-options .finish-box{display:inline-block;width:10px;height:10px;border:1.2px solid #444;margin:0 4px 0 0;vertical-align:-1px;text-align:center;font-family:DejaVu Sans,sans-serif;font-size:8px;font-weight:bold;line-height:9px;color:#fff}.invoice-box table.finishing-options .finish-box.is-checked{background:#111;border-color:#111}
			.invoice-box table.finishing-options .finish-text{display:inline-block;line-height:11px;vertical-align:0}
			.invoice-box table tr.finishing-row td{border-bottom:0!important}
			.invoice-box table.order-summary td{border-bottom:0!important;padding:0!important;vertical-align:top}
			.invoice-box table.finishing-process-card{width:100%;border:1px solid #9aa4b2;border-collapse:collapse;margin:3px 0 4px;background:#fff}
			.invoice-box table.finishing-process-card td{height:16px;padding:2px 6px!important;border-bottom:1px dotted #aeb5bf!important;vertical-align:middle}
			.invoice-box table.finishing-process-card tr:last-child td{border-bottom:0!important}
			.invoice-box table.finishing-process-card td.finishing-card-title{height:18px;background:#eef1f5;border-bottom:1px solid #9aa4b2!important;font-weight:bold;font-size:8pt;letter-spacing:.3px;color:#303846}
			.invoice-box table.finishing-process-card td.finishing-sign-title{width:15%;height:18px;background:#eef1f5;border-right:1px solid #9aa4b2!important;border-bottom:1px solid #9aa4b2!important;text-align:center;font-weight:bold;font-size:7.5pt;letter-spacing:.15px;color:#303846;white-space:nowrap}
			.invoice-box table.finishing-process-card td.finishing-sign-box{width:15%;border-right:1px solid #9aa4b2!important;border-bottom:0!important;background:#fff}
			.invoice-box table.finishing-process-card td.finishing-card-label{width:42%;white-space:nowrap}
			.invoice-box table.finishing-process-card td.finishing-card-colon{width:8px;text-align:center}
			.invoice-box table.finishing-process-card td.finishing-card-value{text-align:left}
			.invoice-box table.process-card-grid{width:100%;border-collapse:separate;border-spacing:5px 4px;margin-top:3px;table-layout:fixed}
			.invoice-box table.process-card-grid>tbody>tr>td{width:50%;padding:0!important;border:0!important;vertical-align:top}
			.invoice-box table.process-card-grid table.finishing-process-card{margin:0;height:92px}
			.invoice-box table.spk-visual-grid{width:100%;border-collapse:separate;border-spacing:8px 0;margin-top:10px;table-layout:fixed;page-break-inside:avoid}
			.invoice-box table.spk-visual-grid>tbody>tr>td{width:50%;height:300px;padding:8px!important;border:1px solid #9aa4b2!important;vertical-align:top;text-align:center;overflow:hidden}
			.spk-visual-title{font-size:12pt;text-align:center;margin:0 0 5px}
			.spk-reference-image{height:265px;margin:0;text-align:center;overflow:hidden;page-break-inside:avoid}
			.spk-reference-image img{display:block;margin:0 auto;max-width:100%;max-height:260px}
		</style>
	</head>
	<?php 
		if($konsumen['tampil']==1){
			$nama = $konsumen['perusahaan'];
			$perusahaan = cek_jenis_lembaga($konsumen['jenis']);
			$telp = phone_number($konsumen['no_telp']);
			$alamat = $konsumen['alamat_lembaga'];
			}else{
			$nama = $konsumen['nama'];
			$perusahaan = cek_jenis_lembaga($konsumen['jenis']);
			$telp = phone_number($konsumen['no_hp']);
			$alamat = $konsumen['alamat'];
		}
		$tanggal_order = !empty($cetak->tgl_trx) && strpos($cetak->tgl_trx, '0000-00-00') !== 0
			? date('d/m/Y', strtotime($cetak->tgl_trx)) : '-';
		$tanggal_deadline = !empty($cetak->tgl_ambil) && strpos($cetak->tgl_ambil, '0000-00-00') !== 0
			? date('d/m/Y', strtotime($cetak->tgl_ambil)) : '-';
		$spk_pages = array();
		foreach ((is_array($detail) ? $detail : array()) as $spk_item) {
			$base_draft = isset($spk_drafts[(int)$spk_item['id_rincianinvoice']]) && is_array($spk_drafts[(int)$spk_item['id_rincianinvoice']]) ? $spk_drafts[(int)$spk_item['id_rincianinvoice']] : array();
			$spk_pages[] = array('item'=>$spk_item, 'draft'=>$base_draft);
			$extra_pages = isset($base_draft['additional_pages']) && is_array($base_draft['additional_pages']) ? $base_draft['additional_pages'] : array();
			foreach ($extra_pages as $extra_page) {
				if (!is_array($extra_page)) continue;
				$extra_draft = $base_draft;
				unset($extra_draft['additional_pages']);
				foreach (array('plat','keterangan','stock_bahan_id','jenis_nama_bahan','jumlah_bahan_plano','ukuran_plano','ukuran_kertas_masuk','jumlah_kertas_masuk','mesin_cetak','jumlah_plat','warna_cetakan','finishing','finishing_proses','mulai_cetak','selesai_cetak','hasil_akhir','potong_mode','potong_margin','potong_gap','cara_potong','cara_potong_svg','gambar_spk') as $extra_key) {
					if (array_key_exists($extra_key, $extra_page)) $extra_draft[$extra_key] = $extra_page[$extra_key];
				}
				$spk_pages[] = array('item'=>$spk_item, 'draft'=>$extra_draft);
			}
		}
		$total_spk = count($spk_pages);
		$page_spk = 0;
		foreach($spk_pages AS $spk_page){
			$page_spk++;
			$val = $spk_page['item'];
			$spk_draft = $spk_page['draft'];
			$draft_value = static function($key) use ($spk_draft){ return isset($spk_draft[$key]) ? html_escape($spk_draft[$key]) : '&nbsp;'; };
			$draft_finishing = isset($spk_draft['finishing']) && is_array($spk_draft['finishing']) ? $spk_draft['finishing'] : array();
			$finish_checked = static function($key) use ($draft_finishing){ return in_array($key, $draft_finishing, true); };
			$finish_process_labels = array('laminating'=>'LAMINATING','spot_uv'=>'SPOT UV','foil'=>'FOIL','potong_paska_cetak'=>'POTONG PASKA CETAK','pond'=>'POND','lem'=>'LEM','packing'=>'PACKING');
			$finish_processes = isset($spk_draft['finishing_proses']) && is_array($spk_draft['finishing_proses']) ? $spk_draft['finishing_proses'] : array();
			$print_process_card = array('label'=>'CETAK','values'=>array('mulai'=>isset($spk_draft['mulai_cetak'])?$spk_draft['mulai_cetak']:'','selesai'=>isset($spk_draft['selesai_cetak'])?$spk_draft['selesai_cetak']:'','hasil'=>isset($spk_draft['hasil_akhir'])?$spk_draft['hasil_akhir']:''));
			$process_cards = array();
			foreach ($finish_processes as $process_key=>$process_values) {
				if (isset($finish_process_labels[$process_key]) && is_array($process_values)) $process_cards[] = array('label'=>$finish_process_labels[$process_key],'values'=>$process_values);
			}
			array_splice($process_cards, min(1, count($process_cards)), 0, array($print_process_card));
			$spk_reference = null;
			$spk_image_relative = isset($spk_draft['gambar_spk']) ? str_replace('\\', '/', trim((string)$spk_draft['gambar_spk'])) : '';
			if (preg_match('#^uploads/spk_produksi/[A-Za-z0-9._-]+\.webp$#i', $spk_image_relative)) {
				$spk_image_path = FCPATH.str_replace('/', DIRECTORY_SEPARATOR, $spk_image_relative);
				$spk_image_size = is_file($spk_image_path) ? @getimagesize($spk_image_path) : false;
				if ($spk_image_size && $spk_image_size[0] > 0 && $spk_image_size[1] > 0) {
					$spk_image_scale = min(1, 680 / $spk_image_size[0], 285 / $spk_image_size[1]);
					$spk_pdf_image_data = file_get_contents($spk_image_path);
					$spk_pdf_mime = 'image/webp';
					if (function_exists('imagecreatefromwebp')) {
						$spk_pdf_source = @imagecreatefromwebp($spk_image_path);
						if ($spk_pdf_source) {
							ob_start();
							imagepng($spk_pdf_source, null, 7);
							$spk_pdf_image_data = ob_get_clean();
							imagedestroy($spk_pdf_source);
							$spk_pdf_mime = 'image/png';
						}
					}
					$spk_reference = array(
						'width'=>max(1, (int)floor($spk_image_size[0] * $spk_image_scale)),
						'height'=>max(1, (int)floor($spk_image_size[1] * $spk_image_scale)),
						'src'=>'data:'.$spk_pdf_mime.';base64,'.base64_encode($spk_pdf_image_data)
					);
				}
			}
			if($val['status_hitung'] ==1)
			{
				$qty = $val['jumlah'];
				}else{
				$qty = $val['jumlah'].' '.get_satuan($val['satuan']);
			}
		?>
		<body>
			
			<div class="invoice-box">
				<div class="spk-page-label">Page <?=$page_spk;?> dari <?=$total_spk;?></div>
				
				<table style="width:100%;margin-top:10px" cellpadding="0" cellspacing="0">
					<tr>
						<td colspan="5" align="center"style="font-weight:bold;font-size:18pt">SURAT PERINTAH KERJA</td>
					</tr>
				</table>
				<table cellpadding="0" cellspacing="0" style="margin-top:5px; width:100%">
					<tbody>
						<tr>
							<td colspan="7" align="center">
								<span style="display:inline-block;margin-right:50px"><span class="plate-box <?=isset($spk_draft['plat']) && $spk_draft['plat']==='baru'?'is-checked':'';?>"><?=isset($spk_draft['plat']) && $spk_draft['plat']==='baru'?'X':'';?></span>&nbsp; PLAT BARU</span>
								<span style="display:inline-block;margin-right:50px"><span class="plate-box <?=isset($spk_draft['plat']) && $spk_draft['plat']==='lama'?'is-checked':'';?>"><?=isset($spk_draft['plat']) && $spk_draft['plat']==='lama'?'X':'';?></span>&nbsp; PLAT LAMA</span>
								<span style="display:inline-block"><span class="plate-box <?=isset($spk_draft['plat']) && $spk_draft['plat']==='tanpa'?'is-checked':'';?>"><?=isset($spk_draft['plat']) && $spk_draft['plat']==='tanpa'?'X':'';?></span>&nbsp; TANPA CETAK / PLAT</span>
							</td>
						</tr>
						<tr class="detail">
							<td class="tdetail">NO. SPK</td>
							<td class="sub-detail" style="width:2px">:</td>
							<td colspan="2" class="bawah"><?=$val['no_spk'];?></td>
							<td colspan="3">NO. ORDER : <?=$cetak->id_transaksi;?></td>
						</tr>
						<tr class="detail">
							<td class="tdetail">NAMA PELANGGAN</td>
							<td class="sub-detail">:</td>
							<td colspan="5" class="bawah"><?=$nama;?></td>
						</tr>
						<tr class="detail">
							<td class="tdetail">TANGGAL ORDER</td>
							<td class="sub-detail">:</td>
							<td colspan="2"><?=$tanggal_order;?></td>
							<td colspan="3" style="white-space:nowrap">TANGGAL DEADLINE : <?=$tanggal_deadline;?></td>
						</tr>
						<tr class="detail">
							<td class="tdetail">JENIS CETAKAN</td>
							<td class="sub-detail">:</td>
							<td colspan="5">
								<table class="order-summary" cellpadding="0" cellspacing="0" style="width:100%; table-layout:fixed">
									<tr>
										<td style="width:72%; white-space:nowrap"><?=$val['nbahan'];?></td>
										<td style="width:28%; white-space:nowrap">QTY&nbsp;&nbsp;: <?=$qty;?></td>
									</tr>
								</table>
							</td>
						</tr>
						<tr class="detail">
							<td class="tdetail">KETERANGAN</td>
							<td class="sub-detail">:</td>
							<td colspan="5"><?=$draft_value('keterangan');?></td>
						</tr>
						<tr class="detail">
							<td class="tdetail">JENIS / NAMA BAHAN</td>
							<td class="sub-detail">:</td>
							<td colspan="5" rowspan="1"><?=$draft_value('jenis_nama_bahan');?></td>
						</tr>
						<tr class="detail"><td class="tdetail">JUMLAH BAHAN PLANO</td><td class="sub-detail">:</td><td colspan="5"><?=$draft_value('jumlah_bahan_plano');?></td></tr>
						<tr class="detail"><td class="tdetail">UKURAN PLANO</td><td class="sub-detail">:</td><td colspan="5"><?=$draft_value('ukuran_plano');?></td></tr>
						<tr class="detail"><td class="tdetail">UKURAN POTONG KERTAS MASUK MESIN</td><td class="sub-detail">:</td><td colspan="5"><?=isset($spk_draft['ukuran_kertas_masuk']) ? html_escape($spk_draft['ukuran_kertas_masuk']) : $draft_value('ukuran_jumlah_kertas');?></td></tr>
						<tr class="detail"><td class="tdetail">JUMLAH KERTAS MASUK MESIN</td><td class="sub-detail">:</td><td colspan="4"><?=$draft_value('jumlah_kertas_masuk');?></td><td style="text-align:right;width:134px">LEMBAR</td></tr>
						<tr class="detail">
							<td class="tdetail">MESIN CETAK</td>
							<td class="sub-detail">:</td>
							<td colspan="5" rowspan="1"><?=$draft_value('mesin_cetak');?></td>
						</tr>
						<tr class="detail">
							<td class="tdetail">JUMLAH PLAT</td>
							<td class="sub-detail">:</td>
							<td colspan="5" rowspan="1"><?=$draft_value('jumlah_plat');?></td>
						</tr>
						<tr class="detail">
							<td class="tdetail">WARNA CETAKAN</td>
							<td class="sub-detail">:</td>
							<td colspan="5" rowspan="1"><?=$draft_value('warna_cetakan');?></td>
						</tr>
						<tr class="detail finishing-row">
							<td class="tdetail">FINISHING</td>
							<td class="sub-detail">:</td>
							<td colspan="5" rowspan="1" style="padding-top:2px; padding-bottom:2px">
								<table class="finishing-options" cellpadding="0" cellspacing="0" style="width:100%; font-size:9px; line-height:16px">
									<tr>
										<td><span class="finish-box <?=$finish_checked('laminating_glossy')?'is-checked':'';?>"><?=$finish_checked('laminating_glossy')?'X':'';?></span><span class="finish-text">LAMINATING GLOSY</span></td>
										<td><span class="finish-box <?=$finish_checked('laminating_doff')?'is-checked':'';?>"><?=$finish_checked('laminating_doff')?'X':'';?></span><span class="finish-text">LAMINATING DOFF</span></td>
										<td><span class="finish-box <?=$finish_checked('spot_uv')?'is-checked':'';?>"><?=$finish_checked('spot_uv')?'X':'';?></span><span class="finish-text">SPOT UV</span></td>
										<td><span class="finish-box <?=$finish_checked('foil')?'is-checked':'';?>"><?=$finish_checked('foil')?'X':'';?></span><span class="finish-text">FOIL</span></td>
									</tr>
									<tr>
										<td><span class="finish-box <?=$finish_checked('potong_paska_cetak')?'is-checked':'';?>"><?=$finish_checked('potong_paska_cetak')?'X':'';?></span><span class="finish-text">POTONG PASKA CETAK</span></td>
										<td><span class="finish-box <?=$finish_checked('pond')?'is-checked':'';?>"><?=$finish_checked('pond')?'X':'';?></span><span class="finish-text">POND</span></td>
										<td><span class="finish-box <?=$finish_checked('lem')?'is-checked':'';?>"><?=$finish_checked('lem')?'X':'';?></span><span class="finish-text">LEM</span></td>
										<td><span class="finish-box <?=$finish_checked('packing')?'is-checked':'';?>"><?=$finish_checked('packing')?'X':'';?></span><span class="finish-text">PACKING</span></td>
										<td>&nbsp;</td>
									</tr>
								</table>
							</td>
						</tr>
						<tr class="detail">
							<td colspan="7" style="padding:0!important;border-bottom:0!important">
								<table class="process-card-grid" cellpadding="0" cellspacing="0">
									<?php foreach (array_chunk($process_cards, 2) as $card_pair): ?>
									<tr>
										<?php foreach ($card_pair as $process_card): $process_label=$process_card['label']; $process_values=$process_card['values']; ?>
										<td>
											<table class="finishing-process-card" cellpadding="0" cellspacing="0">
												<tr><td class="finishing-sign-title">TTD</td><td colspan="3" class="finishing-card-title"><?=$process_label;?></td></tr>
												<tr><td rowspan="3" class="finishing-sign-box">&nbsp;</td><td class="finishing-card-label">MULAI <?=$process_label;?></td><td class="finishing-card-colon">:</td><td class="finishing-card-value"><?=isset($process_values['mulai'])?html_escape($process_values['mulai']):'&nbsp;';?></td></tr>
												<tr><td class="finishing-card-label">SELESAI <?=$process_label;?></td><td class="finishing-card-colon">:</td><td class="finishing-card-value"><?=isset($process_values['selesai'])?html_escape($process_values['selesai']):'&nbsp;';?></td></tr>
												<tr><td class="finishing-card-label">HASIL AKHIR <?=$process_label;?></td><td class="finishing-card-colon">:</td><td class="finishing-card-value" style="text-align:right"><?=isset($process_values['hasil'])?html_escape($process_values['hasil']):'&nbsp;';?>&nbsp;&nbsp; LEMBAR</td></tr>
											</table>
										</td>
										<?php endforeach; ?>
										<?php if (count($card_pair) < 2): ?><td>&nbsp;</td><?php endif; ?>
									</tr>
									<?php endforeach; ?>
								</table>
							</td>
						</tr>
						<tr class="detail">
							<td colspan="7" style="padding:0!important;border-bottom:0!important">
							<table class="spk-visual-grid" cellpadding="0" cellspacing="0"><tr>
							<td><div class="spk-visual-title">CARA POTONG KERTAS</div>
								<table width="90%" border="0" cellspacing="0" cellpadding="0" style="border:3px double #858b94">
									<tr>
										<td align="center" style="padding:8px;height:270px;border-bottom:0!important">
											<?php if (!empty($spk_draft['cara_potong_svg'])): ?>
												<?php
													$print_cut_svg = str_replace(
														array('rgba(79,70,229,.12)', 'rgba(244,63,94,.12)'),
														array('#eef2ff', '#fff1f2'),
														$spk_draft['cara_potong_svg']
													);
													$plano_svg_width = 100;
													$plano_svg_height = 100;
													if (preg_match('/viewBox=["\']0\s+0\s+([0-9.]+)\s+([0-9.]+)["\']/', $print_cut_svg, $svg_viewbox)) {
														$plano_svg_width = max(1, (float)$svg_viewbox[1]);
														$plano_svg_height = max(1, (float)$svg_viewbox[2]);
													}
													$map_width = 360;
													$map_height = 218;
													$map_padding = 5;
													$map_scale = min(($map_width - ($map_padding * 2)) / $plano_svg_width, ($map_height - ($map_padding * 2)) / $plano_svg_height);
													$map_x = ($map_width - ($plano_svg_width * $map_scale)) / 2;
													$map_y = ($map_height - ($plano_svg_height * $map_scale)) / 2;
													$svg_body = preg_replace('/<defs\b[^>]*>.*?<\/defs>/is', '', $print_cut_svg);
													$svg_body = preg_replace('/^.*?<svg\b[^>]*>/is', '', $svg_body);
													$svg_body = preg_replace('/<\/svg>\s*$/is', '', $svg_body);
													$svg_body = preg_replace('/<rect\b[^>]*\/?\s*>/i', '', $svg_body, 1);
													$hatch_lines = '';
													for ($diagonal = -$plano_svg_height; $diagonal <= $plano_svg_width; $diagonal += 5) {
														$points = array();
														if (-$diagonal >= 0 && -$diagonal <= $plano_svg_height) $points[] = array(0, -$diagonal);
														if (($plano_svg_width - $diagonal) >= 0 && ($plano_svg_width - $diagonal) <= $plano_svg_height) $points[] = array($plano_svg_width, $plano_svg_width - $diagonal);
														if ($diagonal >= 0 && $diagonal <= $plano_svg_width) $points[] = array($diagonal, 0);
														if (($plano_svg_height + $diagonal) >= 0 && ($plano_svg_height + $diagonal) <= $plano_svg_width) $points[] = array($plano_svg_height + $diagonal, $plano_svg_height);
														if (count($points) >= 2) $hatch_lines .= '<line x1="'.$points[0][0].'" y1="'.$points[0][1].'" x2="'.$points[1][0].'" y2="'.$points[1][1].'" stroke="#fda4af" stroke-width="0.35"/>';
													}
													$print_cut_svg = '<svg xmlns="http://www.w3.org/2000/svg" width="'.$map_width.'" height="'.$map_height.'" viewBox="0 0 '.$map_width.' '.$map_height.'" preserveAspectRatio="xMidYMid meet">'
														.'<g transform="translate('.$map_x.' '.$map_y.') scale('.$map_scale.')">'
														.'<rect width="'.$plano_svg_width.'" height="'.$plano_svg_height.'" fill="#ffffff" stroke="#f43f5e" stroke-width="0.6" stroke-dasharray="2 1"/>'
														.$hatch_lines.$svg_body.'</g></svg>';
													$cut_mode = isset($spk_draft['potong_mode']) ? strtolower($spk_draft['potong_mode']) : 'auto';
													$cut_count = 0;
													if (preg_match('/(\d+)\s+potong\/plano/i', isset($spk_draft['cara_potong']) ? $spk_draft['cara_potong'] : '', $cut_match)) $cut_count = (int)$cut_match[1];
													$plano_size = preg_match_all('/[0-9.]+/', isset($spk_draft['ukuran_plano']) ? $spk_draft['ukuran_plano'] : '', $plano_match) === 2 ? array_map('floatval', $plano_match[0]) : array(0, 0);
													$cut_size = preg_match_all('/[0-9.]+/', isset($spk_draft['ukuran_kertas_masuk']) ? $spk_draft['ukuran_kertas_masuk'] : '', $paper_match) === 2 ? array_map('floatval', $paper_match[0]) : array(0, 0);
													$used_percent = ($plano_size[0] * $plano_size[1]) > 0 ? ($cut_count * $cut_size[0] * $cut_size[1] / ($plano_size[0] * $plano_size[1]) * 100) : 0;
													$plano_count = isset($spk_draft['jumlah_bahan_plano']) ? (int)$spk_draft['jumlah_bahan_plano'] : 0;
												?>
												<table width="100%" cellspacing="2" cellpadding="0" style="font-size:6pt;margin-bottom:4px"><tr>
													<?php foreach (array('auto'=>'AUTO','portrait'=>'POTRET','landscape'=>'LANSKAP') as $mode_key=>$mode_label): ?>
													<td align="center" style="height:16px;border:1px solid <?=$cut_mode===$mode_key?'#4f46e5':'#cfd6e4';?>!important;background:<?=$cut_mode===$mode_key?'#4f46e5':'#ffffff';?>;color:<?=$cut_mode===$mode_key?'#ffffff':'#222222';?>"><?=$mode_label;?></td>
													<?php endforeach; ?>
												</tr></table>
												<div style="height:218px;border:1px dashed #cdd6e8;background:#fbfcff;text-align:center;overflow:hidden">
													<img alt="Peta cara potong" width="<?=$map_width;?>" height="<?=$map_height;?>" style="display:block;max-width:100%;height:auto;margin:0 auto" src="data:image/svg+xml;base64,<?=base64_encode($print_cut_svg);?>">
												</div>
												<table width="100%" cellspacing="0" cellpadding="0" style="font-size:6pt;font-weight:bold;margin-top:4px"><tr><td align="left" style="border:0!important;padding:0"><?=$cut_count;?> potong/plano</td><td align="center" style="border:0!important;padding:0"><?=number_format($used_percent,1);?>% terpakai</td><td align="right" style="border:0!important;padding:0"><?=$plano_count;?> plano</td></tr></table>
											<?php else: ?>
												<div style="height:180px;padding-top:8px"><?=$draft_value('cara_potong');?></div>
											<?php endif; ?>
										</td>
									</tr>
								</table>
							</td>
							<td>
								<div class="spk-visual-title">GAMBAR REFERENSI SPK</div>
								<div class="spk-reference-image">
									<?php if ($spk_reference): ?><img alt="Gambar referensi SPK" width="<?=$spk_reference['width'];?>" height="<?=$spk_reference['height'];?>" src="<?=$spk_reference['src'];?>"><?php endif; ?>
								</div>
							</td>
							</tr></table>
						</tr>
					</tbody>
				</table>
				
			</div>
		</body>
	<?php } ?>
</html>
