<?php
class surattugas  {
	var $mgr;
	var $mypdf;
	var $info;
	var $pejabat;
	var $pengikut;
	var $pangkat;
	public function __construct($obj) {
		if (!isset($_GET["p"])) die();
		
		$this->mgr=$obj;
		$this->prepareData();
		
		$this->mgr->createPDF();
		$this->printHeader();
		$this->printDetail();
		$this->printFooter();
		//$this->mgr->helper->renderHTML($html);
		$this->mgr->pdf->Output('surat_tugas.pdf', 'I');
				
	}
	protected function prepareData() {
		$this->mgr->factory->Models->load("spdpelaksana,refall,spdpengikut");
		$this->mgr->factory->Utils->load("string");
		
		$this->info=$this->mgr->factory->Models->spdpelaksana->getDetail($_GET["p"]);
		if ($this->info["id_pelaksana"]=="") die();
		$this->pejabat=$this->mgr->factory->Models->refall->getPejabat("1");
		$this->pengikut=$this->mgr->factory->Models->spdpengikut->getDetail($_GET["p"]);
		$this->pangkat=$this->mgr->factory->Models->refall->getNamaGol($this->info["gol_karyawan"]);
	}
	protected function printHeader() {
		$this->mgr->helper->printCell("Lampiran SK DIreksi PT. DLN","R");
		$this->mgr->helper->printCell("Tanggal 3 Juli 2017","R");
		$this->mgr->pdf->ln(1);		
		$this->mgr->helper->printCellPair("No.",$this->info["no_kegiatan"],135);
		$this->mgr->helper->printCell();
		$this->mgr->setSize(15,"UB");
		$this->mgr->helper->printCell("Surat Perjalanan Dinas ( SPD )","C");
		$this->mgr->pdf->ln(2);
		$this->mgr->setNormalSize(12);
		
		$this->mgr->setSize(13,"C");
		$this->mgr->helper->printCell("Nomor  : ".$this->info["no_surat"],"C");
		$this->mgr->pdf->ln(0);
		$this->mgr->setNormalSize(12);
		$this->mgr->helper->printCell();
	}
	protected function printDetail() {
	
		$w2="35%";
		$w4="5%";
		$w3="57%";
		$w5="3%";
		$spasi= "<br>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		$html = '<p>
<table border="0" cellpadding="1" cellspacing="0">
          <tr>
            <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">1</td>
            <td width="'.$w2.'"><p>a. Nama/NIP</p></td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'">'.$this->info["nama_karyawan"].' / '.$this->info["nip_karyawan"].'</td>
          </tr>
          <tr>
            <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">&nbsp;</td>
            <td width="'.$w2.'">b. Jabatan</td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'">'.$this->info["jabatan_karyawan"].'</td>
		  </tr>
          <tr >
			<td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">&nbsp;</td>
            <td width="'.$w2.'">'.$spasi.' Pangkat dan Golongan ruang gaji'.$spasi.' Tingkat Biaya Perjalanan Dinas</td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'">'.$this->pangkat.' Gol '.$this->info["gol_karyawan"].'<br/>
              '.$this->info["tingkat_biaya"].'</td>
		</tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">2</td>
            <td width="'.$w2.'">a. Tempat yang dituju</td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'">'.$this->info["tempat_tujuan"].'</td>
  </tr>
          <tr>
            <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">&nbsp;</td>
            <td width="'.$w2.'">b. Rencana Perjalanan</td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'">'.$this->info["tempat_asal"].' - '.$this->info["tempat_tujuan"].' - '.$this->info["tempat_asal"].'</td>
  </tr>
          <tr >
		    <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">&nbsp;</td>
            <td width="'.$w2.'">c. Rencana Pekerjaan</td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'">'.$this->info["agenda"].'</td>
		  </tr>
          <tr >
            <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">&nbsp;</td>
            <td width="'.$w2.'">d. Pengikut</td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'">'.$this->printPengikut().'&nbsp;</td>
          </tr>
          <tr >
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr >
            <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">3</td>
            <td width="'.$w2.'">a. Lama perjalanan dinas</td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'">'.$this->info["durasi"].' hari</td>
  </tr>
          <tr >
            <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">&nbsp;</td>
            <td width="'.$w2.'">b. Berangkat Tanggal</td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'">'.$this->mgr->factory->Utils->string->dateId($this->info["tgl_berangkat"]).'</td>
  </tr>
          <tr >
            <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">&nbsp;</td>
            <td width="'.$w2.'">c. Kembali Tanggal</td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'">'.$this->mgr->factory->Utils->string->dateId($this->info["tgl_kembali"]).'</td>
  		  </tr>
          <tr >
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr >
            <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">4</td>
            <td width="'.$w2.'">a. Pengangkutan</td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'">'.$this->info["alat_angkut"].'</td>
  </tr>
          <tr >
            <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">&nbsp;</td>
            <td width="'.$w2.'">b. Penginapan</td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'">Diberikan & Terlampir</td>
  </tr>
            <tr >
            <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">&nbsp;</td>
            <td width="'.$w2.'">c. Uang Saku</td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'">Diberikan & Terlampir</td>
		    </tr>
			<tr >
            <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">5</td>
            <td width="'.$w2.'">Pembebanan Anggaran'.$spasi.'a. Instansi'.$spasi.'b. Akun</td>
            <td width="'.$w5.'">:</td>
            <td width="'.$w3.'"><br />
                <br/>
              a. '.$this->info["satuan_kerja"].'<br />
              b. '.$this->info["akun_anggaran"].'</td>
          </tr>
          <tr >
		    <td width="'.$w4.'">&nbsp;</td>
            <td width="'.$w5.'">6</td>
            <td width="'.$w2.'"> Keterangan lain-lain</td>
            <td width="'.$w5.'">&nbsp;</td>
            <td width="'.$w3.'">&nbsp;</td>
          </tr>
        </table>
</p>
';
$this->mgr->helper->renderHTML($html);
	}
	protected function printPengikut() {
		$w1="35%";
		$w2="15%";
		$w3="40%";
		$tb="";
		$i=1;
		foreach ($this->pengikut as $row) {
			if ($i==1) {
				$tb .='<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				$tb .='<table border="0" cellpadding="3" cellspacing="0">';
				$tb .='<tr><td width="'.$w1.'"><b>Nama</b></td><td width="'.$w2.'"><b>Tgl Lahir</b></td><td width="'.$w3.'"><b>Keterangan</b></td></tr>';
			}
			$tb .='<tr><td width="'.$w1.'">'.$i.'. '.$row["nama_pengikut"].'</td><td width="'.$w2.'">'.$row["tgl_lahir"].'</td><td width="'.$w3.'">'.$row["keterangan"].'</td></tr>';
			$i++;
		}
		if ($tb != "") $tb .= '</table>';
		return $tb;
	}
	protected function printFooter() {
		$this->mgr->helper->printCellPair("Jakarta",$this->mgr->factory->Utils->string->dateId($this->info["tgl_surat"]),120,25);
		$this->mgr->setSize("","B");
		$this->mgr->pdf->setX(120);
		$this->mgr->helper->printCell("PT. DHARMA LAUTAN NUSANTARA");
		$this->mgr->pdf->setX(120);
		$this->mgr->helper->printCell($this->pejabat["jabatan"]);
		$this->mgr->pdf->ln(15);
		$this->mgr->pdf->setX(120);
		$this->mgr->helper->printCell($this->pejabat["nama"]);
		$this->mgr->pdf->setX(120);
		$this->mgr->helper->printCell("NIP. ".$this->pejabat["nip"]);
		$this->mgr->setNormalSize();
		$this->mgr->helper->printCell("Tembusan:");
		$this->mgr->setNormalSize();
		$this->mgr->helper->printCell("1. Direksi");
		$this->mgr->setNormalSize();
		$this->mgr->helper->printCell("2. Kadiv dan Ka.SPI");
		$this->mgr->setNormalSize();
		$this->mgr->pdf->ln(5);
		$this->mgr->helper->printCell("Mengetahui/Melapor	:");
		$this->mgr->setNormalSize();
		$this->mgr->helper->printCell("Tiba Tanggal													:");
		$this->mgr->setNormalSize();
		$this->mgr->helper->printCell("Kembali Tanggal						:");
		$this->mgr->setNormalSize();
	}
}