<?php
class CT_bc40form extends CI_Controller{
	function __construct()
	{
	  parent::__construct();
		if (!$this->dx_auth->is_logged_in()) {
			header('HTTP/1.1 401 Unauthorize');die('expire'); 
		}
		
		$uid = $this->session->userdata('DX_user_id');
		
		if(!permissionAuth(2) && $uid != RID){ 
			header('HTTP/1.1 401 Unauthorize');die('noaccess');
		}
		
		$this->load->model("pasi_exim/mdl_exim", 'pasi_mdl_exim');
		$this->load->model("pasi_settings/mdl_settings", 'pasi_mdl_settings');
		
	}

	function index(){
		$car = (isset($_POST['car']) &&!empty($_POST['car']))?$_POST['car']:'-';
		$KdKpbc = (isset($_POST['KdKpbc']) &&  !empty($_POST['KdKpbc']))?  $_POST['KdKpbc']:'-';
		$Tujuan = (isset($_POST['Tujuan']) &&  !empty($_POST['Tujuan']))?  $_POST['Tujuan']:'-';
		$JnsAngkutan = (isset($_POST['JnsAngkutan']) &&  !empty($_POST['JnsAngkutan']))?  $_POST['JnsAngkutan']:'-';
		$KemasJn = (isset($_POST['KemasJn']) &&  !empty($_POST['KemasJn']))?  $_POST['KemasJn']:'-';
		$KemasJm = (isset($_POST['KemasJm']) &&  !empty($_POST['KemasJm']))?  $_POST['KemasJm']:'-';
		$KemasMrk = (isset($_POST['KemasMrk']) &&  !empty($_POST['KemasMrk']))?  $_POST['KemasMrk']:'-';
		$KdKpbcBongkar = (isset($_POST['KdKpbcBongkar']) &&  !empty($_POST['KdKpbcBongkar']))?  $_POST['KdKpbcBongkar']:'-';
		$PasokNama = (isset($_POST['PasokNama']) &&  !empty($_POST['PasokNama']))?  $_POST['PasokNama']:'-';
		$PasokAlmt1 = (isset($_POST['PasokAlmt1']) &&  !empty($_POST['PasokAlmt1']))?  $_POST['PasokAlmt1']:'-';
		$Bruto = (isset($_POST['Bruto']) &&  !empty($_POST['Bruto']))?  $_POST['Bruto']:'-';
		$Netto = (isset($_POST['Netto']) &&  !empty($_POST['Netto']))?  $_POST['Netto']:'-';
		$NilSerah = (isset($_POST['NilSerah']) &&  !empty($_POST['NilSerah']))?  $_POST['NilSerah']:'-';
		$Nodaf = (isset($_POST['Nodaf']) &&  !empty($_POST['Nodaf']))?  $_POST['Nodaf']:'-';
		$Tgldaf = (isset($_POST['Tgldaf']) &&  !empty($_POST['Tgldaf']))?  $_POST['Tgldaf']:'-';
		$UsahaNama = (isset($_POST['UsahaNama']) &&  !empty($_POST['UsahaNama']))?  $_POST['UsahaNama']:'-';
		$UsahaNPWP = (isset($_POST['UsahaNPWP']) &&  !empty($_POST['UsahaNPWP']))?  $_POST['UsahaNPWP']:'-';
		$UsahaAlamat1 = (isset($_POST['UsahaAlamat1']) &&  !empty($_POST['UsahaAlamat1']))?  $_POST['UsahaAlamat1']:'-';
		$UsahaAlamat2 = (isset($_POST['UsahaAlamat2']) &&  !empty($_POST['UsahaAlamat2']))?  $_POST['UsahaAlamat2']:'-';
		$UsahaSkep = (isset($_POST['UsahaSkep']) &&  !empty($_POST['UsahaSkep']))?  $_POST['UsahaSkep']:'-';
		$PasokAlmt2 = (isset($_POST['PasokAlmt2']) &&  !empty($_POST['PasokAlmt2']))?  $_POST['PasokAlmt2']:'-';
		$PasokNPWP = (isset($_POST['PasokNPWP']) &&  !empty($_POST['PasokNPWP']))?  $_POST['PasokNPWP']:'-';
		$NoPackinglist = (isset($_POST['NoPackinglist']) &&  !empty($_POST['NoPackinglist']))?  $_POST['NoPackinglist']:'-';
		$NoKontrak = (isset($_POST['NoKontrak']) &&  !empty($_POST['NoKontrak']))?  $_POST['NoKontrak']:'-';
		$TgKontrak = (isset($_POST['TgKontrak']) &&  !empty($_POST['TgKontrak']))?  $_POST['TgKontrak']:'-';
		$SuratKep = (isset($_POST['SuratKep']) &&  !empty($_POST['SuratKep']))?  $_POST['SuratKep']:'-';
		$TgSuratKep = (isset($_POST['TgSuratKep']) &&  !empty($_POST['TgSuratKep']))?  $_POST['TgSuratKep']:'-';
		$SuratLain = (isset($_POST['SuratLain']) &&  !empty($_POST['SuratLain']))?  $_POST['SuratLain']:'-';
		$TgSuratLain = (isset($_POST['TgSuratLain']) &&  !empty($_POST['TgSuratLain']))?  $_POST['TgSuratLain']:'-';
		$Nopol = (isset($_POST['Nopol']) &&  !empty($_POST['Nopol']))?  $_POST['Nopol']:'-';
		$Volume = (isset($_POST['Volume']) &&  !empty($_POST['Volume']))?  $_POST['Volume']:'-';

		$data["car"] = $car;
		$data["KdKpbc"] = $KdKpbc;
		$data["Tujuan"] = $Tujuan;
		$data["JnsAngkutan"] = $JnsAngkutan;
		$data["KemasJn"] = $KemasJn;
		$data["KemasJm"] = $KemasJm;
		$data["KemasMrk"] = $KemasMrk;
		$data["KdKpbcBongkar"] = $KdKpbcBongkar;
		$data["PasokNama"] = $PasokNama;
		$data["PasokAlmt1"] = $PasokAlmt1;
		$data["Bruto"] = $Bruto;
		$data["Netto"] = $Netto;
		$data["NilSerah"] = $NilSerah;
		$data["Nodaf"] = $Nodaf;
		$data["Tgldaf"] = $Tgldaf;
		$data["UsahaNama"] = $UsahaNama;
		$data["UsahaNPWP"] = $UsahaNPWP;
		$data["UsahaAlamat1"] = $UsahaAlamat1;
		$data["UsahaAlamat2"] = $UsahaAlamat2;
		$data["UsahaSkep"] = $UsahaSkep;
		$data["PasokAlmt2"] = $PasokAlmt2;
		$data["PasokNPWP"] = $PasokNPWP;
		$data["NoPackinglist"] = $NoPackinglist;
		$data["NoKontrak"] = $NoKontrak;
		$data["TgKontrak"] = $TgKontrak;
		$data["SuratKep"] = $SuratKep;
		$data["TgSuratKep"] = $TgSuratKep;
		$data["SuratLain"] = $SuratLain;
		$data["TgSuratLain"] = $TgSuratLain;
		$data["Nopol"] = $Nopol;
		$data["Volume"] = $Volume;
		
/* 		$page = '1'; // get the requested page
		$limit = '100'; // get how many rows we want to have into the grid
		$sidx = 'id_master_supplier'; // get index row - i.e. user click to sort
		$sord = '0'; // get the direction
		$where = "1=1";
		
		$start = $limit*$page - $limit;
		if ($start<0) $start=0;
		
		$records = $this->pasi_mdl_settings->datasupplier_All($limit,$start,$sidx,$sord, $where);
		$UsahaNPWP = $records;
		$data['UsahaNPWP'] = $UsahaNPWP; */

		$this->load->view('pasi_exim/view_bc40form',$data);
		

	}
	
	function viewformbc40hdr_print(){
		$car = (isset($_GET['car']) &&!empty($_GET['car']))?$_GET['car']:'-';
		$KdKpbc= (isset($_GET['KdKpbc']) && !empty($_GET['KdKpbc']))? $_GET['KdKpbc']:'-';
		$Tujuan= (isset($_GET['Tujuan']) && !empty($_GET['Tujuan']))? $_GET['Tujuan']:'-';
		$JnsAngkutan= (isset($_GET['JnsAngkutan']) && !empty($_GET['JnsAngkutan']))? $_GET['JnsAngkutan']:'-';
		$KemasJn= (isset($_GET['KemasJn']) && !empty($_GET['KemasJn']))? $_GET['KemasJn']:'-';
		$KemasJm= (isset($_GET['KemasJm']) && !empty($_GET['KemasJm']))? $_GET['KemasJm']:'-';
		$KemasMrk= (isset($_GET['KemasMrk']) && !empty($_GET['KemasMrk']))? $_GET['KemasMrk']:'-';
		$KdKpbcBongkar= (isset($_GET['KdKpbcBongkar']) && !empty($_GET['KdKpbcBongkar']))? $_GET['KdKpbcBongkar']:'-';
		$PasokNama= (isset($_GET['PasokNama']) && !empty($_GET['PasokNama']))? $_GET['PasokNama']:'-';
		$PasokAlmt1= (isset($_GET['PasokAlmt1']) && !empty($_GET['PasokAlmt1']))? $_GET['PasokAlmt1']:'-';
		$Bruto= (isset($_GET['Bruto']) && !empty($_GET['Bruto']))? $_GET['Bruto']:'-';
		$Netto= (isset($_GET['Netto']) && !empty($_GET['Netto']))? $_GET['Netto']:'-';
		$NilSerah= (isset($_GET['NilSerah']) && !empty($_GET['NilSerah']))? $_GET['NilSerah']:'-';
		$Nodaf= (isset($_GET['Nodaf']) && !empty($_GET['Nodaf']))? $_GET['Nodaf']:'-';
		$Tgldaf= (isset($_GET['Tgldaf']) && !empty($_GET['Tgldaf']))? $_GET['Tgldaf']:'-';
		$UsahaNama= (isset($_GET['UsahaNama']) && !empty($_GET['UsahaNama']))? $_GET['UsahaNama']:'-';
		$UsahaNPWP= (isset($_GET['UsahaNPWP']) && !empty($_GET['UsahaNPWP']))? $_GET['UsahaNPWP']:'-';
		$UsahaAlamat1= (isset($_GET['UsahaAlamat1']) && !empty($_GET['UsahaAlamat1']))? $_GET['UsahaAlamat1']:'-';
		$UsahaAlamat2= (isset($_GET['UsahaAlamat2']) && !empty($_GET['UsahaAlamat2']))? $_GET['UsahaAlamat2']:'-';
		$UsahaSkep= (isset($_GET['UsahaSkep']) && !empty($_GET['UsahaSkep']))? $_GET['UsahaSkep']:'-';
		$PasokAlmt2= (isset($_GET['PasokAlmt2']) && !empty($_GET['PasokAlmt2']))? $_GET['PasokAlmt2']:'-';
		$PasokNPWP= (isset($_GET['PasokNPWP']) && !empty($_GET['PasokNPWP']))? $_GET['PasokNPWP']:'-';
		$NoPackinglist= (isset($_GET['NoPackinglist']) && !empty($_GET['NoPackinglist']))? $_GET['NoPackinglist']:'-';
		$NoKontrak= (isset($_GET['NoKontrak']) && !empty($_GET['NoKontrak']))? $_GET['NoKontrak']:'-';
		$TgKontrak= (isset($_GET['TgKontrak']) && !empty($_GET['TgKontrak']))? $_GET['TgKontrak']:'-';
		$SuratKep= (isset($_GET['SuratKep']) && !empty($_GET['SuratKep']))? $_GET['SuratKep']:'-';
		$TgSuratKep= (isset($_GET['TgSuratKep']) && !empty($_GET['TgSuratKep']))? $_GET['TgSuratKep']:'-';
		$SuratLain= (isset($_GET['SuratLain']) && !empty($_GET['SuratLain']))? $_GET['SuratLain']:'-';
		$TgSuratLain= (isset($_GET['TgSuratLain']) && !empty($_GET['TgSuratLain']))? $_GET['TgSuratLain']:'-';
		$Nopol= (isset($_GET['Nopol']) && !empty($_GET['Nopol']))? $_GET['Nopol']:'-';
		$Volume= (isset($_GET['Volume']) && !empty($_GET['Volume']))? $_GET['Volume']:'-';
		 
		$base_url="http://localhost/";
		$tanggal = date("Y-m-d");
		$nama_file= './upload/BC40_FORM_'.$tanggal.'.pdf';

		$a= 'c:\wamp\www\html2pdf\wkhtmltopdf.exe -s Letter "'.$base_url.'upload/view_bc40_form_hdr_print.php?KdKpbc='.$KdKpbc.'&car='.$car.'&Tujuan='.$Tujuan.'&JnsAngkutan='.$JnsAngkutan.'&KemasJn='.$KemasJn.'&KemasJm='.$KemasJm.'&KemasMrk='.$KemasMrk.'&KdKpbcBongkar='.$KdKpbcBongkar.'&PasokNama='.$PasokNama.'&PasokAlmt1='.$PasokAlmt1.'&Bruto='.$Bruto.'&Netto='.$Netto.'&NilSerah='.$NilSerah.'&Nodaf='.$Nodaf.'&Tgldaf='.$Tgldaf.'&UsahaNama='.$UsahaNama.'&UsahaNPWP='.$UsahaNPWP.'&UsahaAlamat1='.$UsahaAlamat1.'&UsahaAlamat2='.$UsahaAlamat2.'&UsahaSkep='.$UsahaSkep.'&PasokAlmt2='.$PasokAlmt2.'&PasokNPWP='.$PasokNPWP.'&NoPackinglist='.$NoPackinglist.'&NoKontrak='.$NoKontrak.'&TgKontrak='.$TgKontrak.'&SuratKep='.$SuratKep.'&TgSuratKep='.$TgSuratKep.'&SuratLain='.$SuratLain.'&TgSuratLain='.$TgSuratLain.'&Nopol='.$Nopol.'&Volume='.$Volume.'" '.$nama_file ;
		//echo $a;die();
		exec ($a);
		$file = $nama_file;;
		if(!file)
		{
				 // File doesn't exist, output error
				 die('file not found');
			 }
			 else
			 {
				 header('Content-Description: File Transfer');
					header('Content-Type: application/octet-stream');
					header('Content-Disposition: attachment; filename='.basename($file));
					header('Content-Transfer-Encoding: binary');
					header('Expires: 0');
					header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
					header('Pragma: public');
					header('Content-Length: ' . filesize($file));
					ob_clean();
					flush();
					readfile($file);
					unlink($file);
					exit;
			 }
		
		
		
		/*
		$file = $nama_file;;
		$pdf = file_get_contents($file);

		header('Content-Type: application/pdf');
		header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
		header('Pragma: public');
		header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
		header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
		header('Content-Length: '.strlen($pdf));
		header('Content-Disposition: inline; filename="'.basename($file).'";');
		ob_clean(); 
		flush(); 
		echo $pdf;

		unlink($file);
		*/
		
		  
	}
	
 }