<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

	if ( ! function_exists('connectwebservice'))
	{
		
		/*function connectwebservice($XMLDATA_info = '', $tag='',&$sts,&$des,&$rows,&$detail)
		{
			$clientX_info = new SoapClient( APPWSPATH ); 
			$params_info = array('Param'=>base64_encode($XMLDATA_info)); 
			$webService_info = $clientX_info->OlahDataOutString($params_info); 
			$strXMLData_info = $webService_info->OlahDataOutStringResult; 
			$doc_report = DOMDocument::loadXML($strXMLData_info);
			$xpath_report = new DOMXpath($doc_report);
			$sts = $xpath_report ->query('//result/sts/no')->item(0)->nodeValue ;
			$sts=substr ($sts,2,2);

			// echo $sts;
			$des = $xpath_report ->query('//result/sts/des')->item(0)->nodeValue;
			if ($xpath_report ->query('//result/detail/sort')->item(0) !=null){
				
				$detail=  array(  'sort'=>$xpath_report ->query('//result/detail/sort')->item(0)->nodeValue,
							  'desc'=>$xpath_report ->query('//result/detail/desc')->item(0)->nodeValue,
							  'rowspage'=>$xpath_report ->query('//result/detail/rowspage')->item(0)->nodeValue,
							  'rows'=>$xpath_report ->query('//result/detail/rows')->item(0)->nodeValue,
							  'pages'=>$xpath_report ->query('//result/detail/pages')->item(0)->nodeValue
							);
			}else{
				$detail=  array(  'sort'=> 0,
							  'desc'=> 0,
							  'rowspage'=> 0,
							  'rows'=> 0,
							  'pages'=> 0
							);
			}
			
			if ($sts=="00"){
			$rows = $xpath_report->query('//result/xrow');
			}
			
		}*/
        
        function connectwebservice($XMLDATA_info = '', $tag='',&$sts,&$des,&$rows,&$detail)
        {
        $ky = "PalapaTcoTidCyb3rC3ycl3V2012XVIP"; // 32 * 8 = 256 bit key
        
        $clientX_info = new SoapClient( APPWSPATH );
        	$params_info = array('Param'=>encryptRJ256($ky,$XMLDATA_info)); 
        	 
        	$webService_info = $clientX_info->OlahDataOutStringWithEncrypt($params_info); 
        	$strXMLData_info = $webService_info->OlahDataOutStringWithEncryptResult; 
        	
        	$hasildescript=decryptRJ256($ky,$strXMLData_info);
        	//echo $hasildescript;
        	$doc_report = DOMDocument::loadXML($hasildescript);
        	 
        	$xpath_report = new DOMXpath($doc_report);
        	$sts = $xpath_report ->query('//result/sts/no')->item(0)->nodeValue ;
        	$sts=substr ($sts,2,2);
        	if ($sts=="00"){
        		$rows = $xpath_report->query('//result/xrow');
        	}
        	// echo $sts;
        	$des = $xpath_report ->query('//result/sts/des')->item(0)->nodeValue;
        	if ($xpath_report ->query('//result/detail/sort')->item(0) !=null){
        		foreach ($xpath_report ->query('//result/detail')->item(0)->childNodes as $field) {
				$detail[$field->nodeName]=$field->nodeValue;
				}
	 						 
        	}else{
        		$detail=  array(  'sort'=> 0,
        					  'desc'=> 0,
        					  'rowspage'=> 0,
        					  'rows'=> 0,
        					  'pages'=> 0
        					);
        	}
        }     
		
	}
	
	if ( ! function_exists('connectwebservicerekap'))
	{
		
		/*function connectwebservice($XMLDATA_info = '', $tag='',&$sts,&$des,&$rows,&$detail)
		{
			$clientX_info = new SoapClient( APPWSPATH ); 
			$params_info = array('Param'=>base64_encode($XMLDATA_info)); 
			$webService_info = $clientX_info->OlahDataOutString($params_info); 
			$strXMLData_info = $webService_info->OlahDataOutStringResult; 
			$doc_report = DOMDocument::loadXML($strXMLData_info);
			$xpath_report = new DOMXpath($doc_report);
			$sts = $xpath_report ->query('//result/sts/no')->item(0)->nodeValue ;
			$sts=substr ($sts,2,2);

			// echo $sts;
			$des = $xpath_report ->query('//result/sts/des')->item(0)->nodeValue;
			if ($xpath_report ->query('//result/detail/sort')->item(0) !=null){
				
				$detail=  array(  'sort'=>$xpath_report ->query('//result/detail/sort')->item(0)->nodeValue,
							  'desc'=>$xpath_report ->query('//result/detail/desc')->item(0)->nodeValue,
							  'rowspage'=>$xpath_report ->query('//result/detail/rowspage')->item(0)->nodeValue,
							  'rows'=>$xpath_report ->query('//result/detail/rows')->item(0)->nodeValue,
							  'pages'=>$xpath_report ->query('//result/detail/pages')->item(0)->nodeValue
							);
			}else{
				$detail=  array(  'sort'=> 0,
							  'desc'=> 0,
							  'rowspage'=> 0,
							  'rows'=> 0,
							  'pages'=> 0
							);
			}
			
			if ($sts=="00"){
			$rows = $xpath_report->query('//result/xrow');
			}
			
		}*/
        
        function connectwebservicerekap($XMLDATA_info = '', $tag='',&$sts,&$des,&$rows,&$detail, &$details)
        {
        $ky = "PalapaTcoTidCyb3rC3ycl3V2012XVIP"; // 32 * 8 = 256 bit key
        
        $clientX_info = new SoapClient( APPWSPATH );
        	$params_info = array('Param'=>encryptRJ256($ky,$XMLDATA_info)); 
        	 
        	$webService_info = $clientX_info->OlahDataOutStringWithEncrypt($params_info); 
        	$strXMLData_info = $webService_info->OlahDataOutStringWithEncryptResult; 
        	
        	$hasildescript=decryptRJ256($ky,$strXMLData_info);
        	//echo $hasildescript;
        	$doc_report = DOMDocument::loadXML($hasildescript);
        	 
        	$xpath_report = new DOMXpath($doc_report);
        	$sts = $xpath_report ->query('//result/sts/no')->item(0)->nodeValue ;
        	$sts=substr ($sts,2,2);
        	if ($sts=="00"){
        		$rows = $xpath_report->query('//result/xrow');
        	}
			
			if ($sts=="00"){
        		$details = $xpath_report->query('//result/detail');
        	}
        	// echo $sts;
        	$des = $xpath_report ->query('//result/sts/des')->item(0)->nodeValue;
        	if ($xpath_report ->query('//result/detail/sort')->item(0) !=null){
        		
        		$detail=  array(  'sort'=>$xpath_report ->query('//result/detail/sort')->item(0)->nodeValue,
        					  'desc'=>$xpath_report ->query('//result/detail/desc')->item(0)->nodeValue,
        					  'rowspage'=>$xpath_report ->query('//result/detail/rowspage')->item(0)->nodeValue,
        					  'rows'=>$xpath_report ->query('//result/detail/rows')->item(0)->nodeValue,
        					  'pages'=>$xpath_report ->query('//result/detail/pages')->item(0)->nodeValue,
							  'total_qty'=>$xpath_report ->query('//result/detail/total_qty')->item(0)->nodeValue,
        					  'barang_code'=>$xpath_report ->query('//result/detail/barang_code')->item(0)->nodeValue,
        					  'barang_name'=>$xpath_report ->query('//result/detail/barang_name')->item(0)->nodeValue

        					);
        	}else{
        		$detail=  array(  'sort'=> 0,
        					  'desc'=> 0,
        					  'rowspage'=> 0,
        					  'rows'=> 0,
        					  'pages'=> 0,
							  'total_qty'=> 0,
        					  'barang_code'=> 0,
        					  'barang_name'=> 0
        					 
        					);
        	}
        }     
		
	}
	
	function push_file($path, $name)
	{
  // make sure it's a file before doing anything!
  if(is_file($path))
	{
    // required for IE
    if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); }

    // get the file mime type using the file extension
    $this->load->helper('file');

    $mime = get_mime_by_extension($path);

    // Build the headers to push out the file properly.
    header('Pragma: public');     // required
    header('Expires: 0');         // no cache
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($path)).' GMT');
    header('Cache-Control: private',false);
    header('Content-Type: '.$mime);  // Add the mime type from Code igniter.
    header('Content-Disposition: attachment; filename="'.basename($name).'"');  // Add the file name
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: '.filesize($path)); // provide file size
    header('Connection: close');
    readfile($path); // push it out
    exit();
	}
	}
    
    
    
    function decryptRJ256($key,$string_to_decrypt)
    {
    	$iv = '741952uiexyt66#cs!234v887mxx8@9y'; // 32 * 8 = 256 bit iv
    
    	$string_to_decrypt = base64_decode($string_to_decrypt);
    	 
    	$rtn = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_decrypt, MCRYPT_MODE_CBC, $iv);
    	 
    	$rtn = rtrim($rtn, "\4");
    	 
    	return($rtn);
    	 
    }
     
    function encryptRJ256($key,$string_to_encrypt)
    {
    	$iv = '741952uiexyt66#cs!234v887mxx8@9y'; // 32 * 8 = 256 bit iv
    
    	$rtn = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_encrypt, MCRYPT_MODE_CBC, $iv);
    	 
    	$rtn = base64_encode($rtn);
    	 
    	return($rtn);
     
    }

	if ( ! function_exists('XMLbasic'))
	{
		function XMLbasic($storeprocedurename){
			$XMLDATA_info = '<param>'
								.'<xuser>'
									.'<xid>1</xid>'
									.'<xpass>2</xpass>'
								.'</xuser>'
							.'<command>'
							.'<spt>'.$storeprocedurename.'</spt>'
							.'</command>'
							.'<search>'
							.'</search>'
							.'<field>'
							.'</field>'
							.'</param>' ;
			$XML =DOMDocument::loadXML($XMLDATA_info);
			
			return $XML;
		}
	
	}
	
	if ( ! function_exists('getXMLValue'))
	{
		function getXMLValue($xmlnode,$tagName){ 
		$hasil='';
		if ($xmlnode !=null) {
			if ($xmlnode->getElementsByTagName($tagName)->item(0)!=null){
					$hasil = $xmlnode->getElementsByTagName($tagName)->item(0)->nodeValue;
				}
 				
			}
			return $hasil;
		}
	}
	
	 if ( ! function_exists('paramView'))
	{
		function paramView($doc,$rowspage,$page,$sort,$desc){
			$node = $doc->getElementsByTagName('param')->item(0);
			$search = $node->getElementsByTagName('field')->item(0);
			$search->setAttribute('rowspage',$rowspage);
			$search->setAttribute('page',$page);
			$search->setAttribute('sort',$sort);
			$search->setAttribute('desc',$desc);
		}
	}
	
    if ( ! function_exists('addSearchText'))
	{
		function addSearchText($doc,$name,$lr,$ll,$ft){
			$node = $doc->getElementsByTagName('param')->item(0);
			$search = $node->getElementsByTagName('search')->item(0);
			$element = $doc->createElement('r', '');
			$element->setAttribute('rID',$name);
			$element->setAttribute('cr','1');
			$element->setAttribute('lr',$lr);
			$element->setAttribute('ll',$ll);
			$element->setAttribute('ft',$ft);
			$element->setAttribute('ft2','');
			$element->setAttribute('cn','1');
			$search->appendChild($element);
		}
	}
	
	 if ( ! function_exists('addSearchNum'))
	{
		function addSearchNum($doc,$name,$num1,$num2,$cn){
			$node = $doc->getElementsByTagName('param')->item(0);
			$search = $node->getElementsByTagName('search')->item(0);
			$element = $doc->createElement('r', '');
			$element->setAttribute('rID',$name);
			$element->setAttribute('cr','1');
			$element->setAttribute('lr','0');
			$element->setAttribute('ll','0');
			$element->setAttribute('ft',$num1);
			$element->setAttribute('ft2',$num2);
			$element->setAttribute('cn',$cn);
			$search->appendChild($element);
		}
	}
	
	if ( ! function_exists('addSearchDate'))
	{
		function addSearchDate($doc,$name,$date1,$date2,$cn){
			$node = $doc->getElementsByTagName('param')->item(0);
			$search = $node->getElementsByTagName('search')->item(0);
			$element = $doc->createElement('r', '');
			$element->setAttribute('rID',$name);
			$element->setAttribute('cr','1');
			$element->setAttribute('lr','0');
			$element->setAttribute('ll','0');
			$element->setAttribute('ft',$date1);
 			$element->setAttribute('ft2',$date2);
			$element->setAttribute('cn',$cn);
			$search->appendChild($element);
		}	
    }
	
	//untuk add, update, status, combobox data
	if ( ! function_exists('AddField'))
	{
		function AddField($doc,$name,$value){
			$node = $doc->getElementsByTagName('param')->item(0);
			$search = $node->getElementsByTagName('field')->item(0);
			$element = $doc->createElement($name, $value);
			$search->appendChild($element);
		}
	}
    
    
    
    
    //==========================================================================
	if ( ! function_exists('AddDetailBarangDocIN_BC_New_doc'))
	{
	  function AddDetailBarangDocIN_BC_New_doc(&$doc
		,$barang_id
		,$urut_detail 
		,$jenis_barang_id 
		,$satuan_qty_doc
		,$harga_satuan
		,$kalibrasi_qty
		,$qty_doc
		,$hs_code
		,$hs_seri_tarif
		,$hs_bm_type_tarif_id
		,$hs_kode_satuan_bm
		,$hs_tbm
		,$hs_ppn
		,$hs_cukai_type_tarif_id
		,$hs_kode_satuan_cukai
		,$hs_cukai
		,$hs_tpbm
		,$kemasan_code
		,$kemasan_netto
		,$kemasan_qty
		,$negara_code_asal 
		)
		{
			 
			$node = $doc->getElementsByTagName('param')->item(0);
			$field = $node->getElementsByTagName('field')->item(0);
			
			if ($field->getElementsByTagName('detail_barang')->item(0)!=null){
				$detail_barang = $field->getElementsByTagName('detail_barang')->item(0);
			 
			}
			else {
				$detail_barang = $doc->createElement('detail_barang', '');
				$field->appendChild($detail_barang);
				 
			}
		 

				$element = $doc->createElement('db', '');
				$element->setAttribute('d1',$barang_id);
				$element->setAttribute('d2',$urut_detail);
				$element->setAttribute('d3',$jenis_barang_id);
				$element->setAttribute('d4',$satuan_qty_doc);
				$element->setAttribute('d5',$harga_satuan);
				$element->setAttribute('d6',$kalibrasi_qty);
				$element->setAttribute('d7',$qty_doc);
				$element->setAttribute('d8',$hs_code);
				$element->setAttribute('d9',$hs_seri_tarif);
				$element->setAttribute('d10',$hs_bm_type_tarif_id);
				$element->setAttribute('d11',$hs_kode_satuan_bm);
				$element->setAttribute('d12',$hs_tbm);
				$element->setAttribute('d13',$hs_ppn);
				$element->setAttribute('d14',$hs_cukai_type_tarif_id);
				$element->setAttribute('d15',$hs_kode_satuan_cukai);
				$element->setAttribute('d16',$hs_cukai);
				$element->setAttribute('d17',$hs_tpbm);
				$element->setAttribute('d18',$kemasan_code);
				$element->setAttribute('d19',$kemasan_netto);
				$element->setAttribute('d20',$kemasan_qty);
				$element->setAttribute('d21',$negara_code_asal);
				$detail_barang->appendChild($element);
			
			 
			
		}
	
	
	
	
	}
	
	if ( ! function_exists('AddApprovePlanBahan'))
	{
		function AddApprovePlanBahan(&$doc
		,$plan_produksi_bahan_id

		)
		{

			$node = $doc->getElementsByTagName('param')->item(0);
			$field = $node->getElementsByTagName('field')->item(0);

		if ($field->getElementsByTagName('detail_supply')->item(0)!=null){
			$detail_supply = $field->getElementsByTagName('detail_supply')->item(0);

		}
		else {
			$detail_supply = $doc->createElement('detail_supply', '');
			$field->appendChild($detail_supply);
			 
		}

			$element = $doc->createElement('bahan', '');
			$element->setAttribute('pb_id',$plan_produksi_bahan_id);
			$detail_supply->appendChild($element);

		}
	}
	
	if ( ! function_exists('AddApprovePlanBahanSupply'))
	{
		function AddApprovePlanBahanSupply(&$doc
		,$plan_produksi_bahan_id
		,$doc_in_barang_detail_id 
		,$qty_supply 
		)
		{
			 $xpath = new DOMXpath($doc);
			 $elements = $xpath->query("/param/field/detail_supply/bahan[@pb_id='".$plan_produksi_bahan_id."']")->item(0);
			  

				$element = $doc->createElement('ds', '');
				$element->setAttribute('i1',$doc_in_barang_detail_id);
				$element->setAttribute('i2',$qty_supply); 
				$elements->appendChild($element);
			 
		}
	}
	if ( ! function_exists('AddPlanBahan'))
	{
		function AddPlanBahan(&$doc
		,$barang_id
		,$type_bahan_in_out_id
		,$qty_plan 
		)
		{
			 
			$node = $doc->getElementsByTagName('param')->item(0);
			$field = $node->getElementsByTagName('field')->item(0);
			
			if ($field->getElementsByTagName('detail_bahan')->item(0)!=null){
				$detail_supply = $field->getElementsByTagName('detail_bahan')->item(0);
			 
			}
			else {
				$detail_supply = $doc->createElement('detail_bahan', '');
				$field->appendChild($detail_supply);
				 
			}

				$element = $doc->createElement('db', '');
				$element->setAttribute('d1',$barang_id);
				$element->setAttribute('d2',$type_bahan_in_out_id); 
				$element->setAttribute('d3',$qty_plan); 
				$detail_supply->appendChild($element);
			 
			 
		}
	}

	if ( ! function_exists('AddRequestPlanBahan'))
	{
		function AddRequestPlanBahan(&$doc
		,$plan_produksi_bahan_id
		,$qty_request  
		)
		{
			$node = $doc->getElementsByTagName('param')->item(0);
			$field = $node->getElementsByTagName('field')->item(0);
			
			if ($field->getElementsByTagName('detail_request')->item(0)!=null){
				$detail_supply = $field->getElementsByTagName('detail_request')->item(0);
			 
			}
			else {
				$detail_supply = $doc->createElement('detail_request', '');
				$field->appendChild($detail_supply);
				 
			}

				$element = $doc->createElement('db', '');
				$element->setAttribute('d1',$plan_produksi_bahan_id);
				$element->setAttribute('d2',$qty_request); 
				$detail_supply->appendChild($element);
			 
		}
	}
    
     
    
    if ( ! function_exists('AddDiffDetailBarangDocIN_BC_Approve_doc'))
	{
		function AddDiffDetailBarangDocIN_BC_Approve_doc(&$doc
		,$doc_in_barang_detail_id
		,$doc_qty 
		,$doc_qty_in 
		,$doc_qty_reject
		,$doc_qty_lost 
		)
		{
			 
			$node = $doc->getElementsByTagName('param')->item(0);
			$field = $node->getElementsByTagName('field')->item(0);
			
			if ($field->getElementsByTagName('list_barang')->item(0)!=null){
				$list_barang = $field->getElementsByTagName('list_barang')->item(0);
			 
			}
			else {
				$list_barang = $doc->createElement('list_barang', '');
				$field->appendChild($list_barang);
				 
			}
		 ;

				$element = $doc->createElement('lb', '');
				$element->setAttribute('lb_id',$doc_in_barang_detail_id);
				$element->setAttribute('dq',$doc_qty);
				$element->setAttribute('dqi',$doc_qty_in);
				$element->setAttribute('dqr',$doc_qty_reject);
				$element->setAttribute('dql',$doc_qty_lost); 
				$list_barang->appendChild($element);
			 
		}
	}
    
    if ( ! function_exists('AddDetailBarangDOC_OUT_PLAN_BC_ADD'))
	{
	  function AddDetailBarangDOC_OUT_PLAN_BC_ADD(&$doc
		,$barang_id
		,$urut_doc 
		,$doc_qty 
		,$doc_satuan_code
		,$harga
		,$kemasan_code
		,$kemasan_jumlah
		,$kemasan_netto
		,$kemasan_valume
		,$negara_code
		,$hs_code
		,$as_reject
		)
		{
			 
			$node = $doc->getElementsByTagName('param')->item(0);
			$field = $node->getElementsByTagName('field')->item(0);
			
			if ($field->getElementsByTagName('detail_request')->item(0)!=null){
				$detail_request = $field->getElementsByTagName('detail_request')->item(0);
			 
			}
			else {
				$detail_request = $doc->createElement('detail_request', '');
				$field->appendChild($detail_request);
				 
			};

				$element = $doc->createElement('db', '');
				$element->setAttribute('d1',$barang_id);
				$element->setAttribute('d2',$urut_doc);
				$element->setAttribute('d3',$doc_qty);
				$element->setAttribute('d4',$doc_satuan_code);
				$element->setAttribute('d5',$harga);
				$element->setAttribute('d6',$kemasan_code);
				$element->setAttribute('d7',$kemasan_jumlah);
				$element->setAttribute('d8',$kemasan_netto);
				$element->setAttribute('d9',$kemasan_valume);
				$element->setAttribute('d10',$negara_code);
				$element->setAttribute('d11',$hs_code);
				$element->setAttribute('d12',$as_reject);
				$detail_request->appendChild($element);
			
			 
			
		}
	
	}
    
    if ( ! function_exists('RPT_BARANG_PER_DOKUMENT_OUT_EXPORT_TO'))
    {
            function RPT_BARANG_PER_DOKUMENT_OUT_EXPORT_TO($PeriodeID, $ExportFormat = 'pdf' , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_BARANG_PER_DOKUMENT_OUT');
        paramView($XML,'50','1','r5','0');
        AddField($XML,'periode_id',$PeriodeID);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
    
    if ( ! function_exists('RPT_MUTASI_BAHAN_BAKU_EXPORT_TO'))
    {
            function RPT_MUTASI_BAHAN_BAKU_EXPORT_TO($PeriodeID, $ExportFormat = 'pdf' , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_MUTASI_BAHAN_BAKU');
        paramView($XML,'50','1','r5','0');
        AddField($XML,'periode_id',$PeriodeID);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
    
    if ( ! function_exists('RPT_MUTASI_BARANG_JADI_EXPORT_TO'))
    {
            function RPT_MUTASI_BARANG_JADI_EXPORT_TO($PeriodeID, $ExportFormat = 'pdf' , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_MUTASI_BARANG_JADI');
        paramView($XML,'50','1','r5','0');
        AddField($XML,'periode_id',$PeriodeID);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
    
    if ( ! function_exists('RPT_MUTASI_MESIN_EXPORT_TO'))
    {
            function RPT_MUTASI_MESIN_EXPORT_TO($PeriodeID, $ExportFormat = 'pdf' , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_MUTASI_MESIN');
        paramView($XML,'50','1','r5','0');
        AddField($XML,'periode_id',$PeriodeID);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
    
    if ( ! function_exists('RPT_MUTASI_SCRAP_EXPORT_TO'))
    {
            function RPT_MUTASI_SCRAP_EXPORT_TO($PeriodeID, $ExportFormat = 'pdf' , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_MUTASI_SCRAP');
        paramView($XML,'50','1','r5','0');
        AddField($XML,'periode_id',$PeriodeID);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
	if ( ! function_exists('RPT_BARANG_PER_DOKUMENT_IN_EXPORT_TO'))
    {
        function RPT_BARANG_PER_DOKUMENT_IN_EXPORT_TO($PeriodeID, $ExportFormat = 'pdf' , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_BARANG_PER_DOKUMENT_IN');
        paramView($XML,'50','1','r5','0');
        AddField($XML,'periode_id',$PeriodeID);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_DYNAMIC_BARANG_PER_DOKUMENT_IN'))
    {
        function RPT_DYNAMIC_BARANG_PER_DOKUMENT_IN($StartDate, $EndDate, $ExportFormat  , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_DYNAMIC_BARANG_PER_DOKUMENT_IN');
        paramView($XML,'50','1','r5','0');
        AddField($XML,'start_date',$StartDate);  
		AddField($XML,'end_date',$EndDate);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_DYNAMIC_BARANG_PER_DOKUMENT_IN_SPEC'))
    {
        function RPT_DYNAMIC_BARANG_PER_DOKUMENT_IN_SPEC($StartDate, $EndDate, $ExportFormat  , $tipe_bc , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_DYNAMIC_BARANG_PER_DOKUMENT_IN');
        paramView($XML,'50','1','r5','0');
		addSearchText($XML,'r1','1','1',$tipe_bc);		
        AddField($XML,'start_date',$StartDate);  
		AddField($XML,'end_date',$EndDate);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);
		 		
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_DYNAMIC_BARANG_PER_DOKUMENT_OUT'))
    {
        function RPT_DYNAMIC_BARANG_PER_DOKUMENT_OUT($StartDate, $EndDate, $ExportFormat  , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_DYNAMIC_BARANG_PER_DOKUMENT_OUT');
        paramView($XML,'50','1','r5','0');
        AddField($XML,'start_date',$StartDate);  
		AddField($XML,'end_date',$EndDate);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_DYNAMIC_BARANG_PER_DOKUMENT_OUT_SPEC'))
    {
        function RPT_DYNAMIC_BARANG_PER_DOKUMENT_OUT_SPEC($StartDate, $EndDate, $ExportFormat  ,$tipe , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_DYNAMIC_BARANG_PER_DOKUMENT_OUT');
        paramView($XML,'50','1','r5','0');
		addSearchText($XML,'r1','1','1',$tipe);
        AddField($XML,'start_date',$StartDate);  
		AddField($XML,'end_date',$EndDate);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat); 		
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_DYNAMIC_WIP'))
    {
        function RPT_DYNAMIC_WIP( $EndDate, $ExportFormat  , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_DYNAMIC_WIP');
        paramView($XML,'50','1','r1','0');
		AddField($XML,'end_date',$EndDate);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_DYNAMIC_MUTASI_BAHAN_BAKU'))
    {
        function RPT_DYNAMIC_MUTASI_BAHAN_BAKU($StartDate, $EndDate, $ExportFormat  , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_DYNAMIC_MUTASI_BAHAN_BAKU');
        paramView($XML,'50','1','r5','0');
        AddField($XML,'start_date',$StartDate);  
		AddField($XML,'end_date',$EndDate);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_DYNAMIC_MUTASI_BARANG_JADI'))
    {
        function RPT_DYNAMIC_MUTASI_BARANG_JADI($StartDate, $EndDate, $ExportFormat  , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_DYNAMIC_MUTASI_BARANG_JADI');
        paramView($XML,'50','1','r5','0');
        AddField($XML,'start_date',$StartDate);  
		AddField($XML,'end_date',$EndDate);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_DYNAMIC_MUTASI_SCRAP'))
    {
        function RPT_DYNAMIC_MUTASI_SCRAP($StartDate, $EndDate, $ExportFormat  , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_DYNAMIC_MUTASI_SCRAP');
        paramView($XML,'50','1','r5','0');
        AddField($XML,'start_date',$StartDate);  
		AddField($XML,'end_date',$EndDate);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_DYNAMIC_MUTASI_MESIN'))
    {
        function RPT_DYNAMIC_MUTASI_MESIN($StartDate, $EndDate, $ExportFormat  , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_DYNAMIC_MUTASI_MESIN');
        paramView($XML,'50','1','r5','0');
        AddField($XML,'start_date',$StartDate);  
		AddField($XML,'end_date',$EndDate);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
          
            
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_BUKTI_BARANG_MASUK'))
    {
        function RPT_BUKTI_BARANG_MASUK($DocinID, $ExportFormat  , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_BUKTI_BARANG_MASUK');
        paramView($XML,'50','1','r5','0');
		AddField($XML ,'data_by','0');
        AddField($XML,'doc_in_id',$DocinID);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_BUKTI_BARANG_KELUAR'))
    {
        function RPT_BUKTI_BARANG_KELUAR($DocinID, $ExportFormat  , &$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_BUKTI_BARANG_KELUAR');
        paramView($XML,'50','1','r5','0');
		AddField($XML ,'data_by','0');
        AddField($XML,'doc_out_plan_bc_id',$DocinID);  
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
                foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_PERNERIMAAN_BARANG'))
    {
            function RPT_PERNERIMAAN_BARANG($Doc_in_id, $SuratJalan, $Keterangan, $ExportFormat = 'pdf' ,&$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_PERNERIMAAN_BARANG');
        
		AddField($XML,'data_by', '0');
		AddField($XML,'doc_in_id',$Doc_in_id);  
        AddField($XML,'surat_jalan',$SuratJalan);  
		AddField($XML,'keterangan',$Keterangan); 
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
        foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }  
            
               
                        
                    
                       
             
        }
    }
	
	
	if ( ! function_exists('RPT_SURAT_JALAN'))
    {
            function RPT_SURAT_JALAN($Doc_out_plan_bc_id, $Angkutan, $Nomor_kendaraan, $Keterangan, $Ibk_no, $ExportFormat = 'pdf',&$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_SURAT_JALAN');
        
		AddField($XML,'data_by', '0');
		AddField($XML,'doc_out_plan_bc_id',$Doc_out_plan_bc_id);  
        AddField($XML,'angkutan',$Angkutan);  
		
		AddField($XML,'nomor_kendaraan',$Nomor_kendaraan);  
		AddField($XML,'keterangan',$Keterangan); 
		AddField($XML,'ibk_no',$Ibk_no); 
        AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
           foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }  
            
               
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_REQUEST_BAHAN'))
    {
            function RPT_REQUEST_BAHAN($Doc_out_supply_request_id, $Kepada, $Nomor_ws, $Keterangan, $ExportFormat = 'pdf',&$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_REQUEST_BAHAN');

		AddField($XML,'data_by', '0');
		AddField($XML,'doc_out_supply_request_id',$Doc_out_supply_request_id);  
        AddField($XML,'kepada',$Kepada);  		
		AddField($XML,'nomor_ws',$Nomor_ws);  
		AddField($XML,'keterangan',$Keterangan); 
		AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
           foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }  
            
               
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_BUKTI_BARANG_KELUAR_PRODUKSI'))
    {
            function RPT_BUKTI_BARANG_KELUAR_PRODUKSI($Doc_out_supply_request_id,  $ExportFormat = 'pdf',&$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_BUKTI_BARANG_KELUAR_PRODUKSI');

		AddField($XML,'data_by', '0');
		AddField($XML,'doc_out_supply_request_id',$Doc_out_supply_request_id);  
		AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
           foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }  
            
               
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_BARANG_JADI'))
    {
            function RPT_BARANG_JADI($Doc_in_id, $Kepada, $Nomor_ws, $Keterangan, $ExportFormat = 'pdf',&$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_BARANG_JADI');

		AddField($XML,'data_by', '0');
		AddField($XML,'doc_in_id',$Doc_in_id);  
        AddField($XML,'kepada',$Kepada);  		
		AddField($XML,'nomor_ws',$Nomor_ws);  
		AddField($XML,'keterangan',$Keterangan); 
		AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
           foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }  
            
               
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_RETUR_BAHAN'))
    {
            function RPT_RETUR_BAHAN($Doc_in_id, $Kepada, $Nomor_ws, $Keterangan, $ExportFormat = 'pdf',&$namafile, &$isifile)
        {
            
        $XML=XMLbasic('RPT_RETUR_BAHAN');

		AddField($XML,'data_by', '0');
		AddField($XML,'doc_in_id',$Doc_in_id);  
        AddField($XML,'kepada',$Kepada);  		
		AddField($XML,'nomor_ws',$Nomor_ws);  
		AddField($XML,'keterangan',$Keterangan); 
		AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
           foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }  
            
               
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_MG_DATA_BARANG_REKAP_IN'))
    {
            function RPT_MG_DATA_BARANG_REKAP_IN($barang_id, $ExportFormat = 'pdf',&$namafile, &$isifile)
        {
            
        $XML=XMLbasic('MG_DATA_BARANG_REKAP_IN');

		AddField($XML,'data_by', '0');
		paramView($XML,'50','1','r5','0');
		AddField($XML,'barang_id',$barang_id);  
		AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
           foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }  
            
               
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_MG_DATA_BARANG_REKAP_OUT'))
    {
            function RPT_MG_DATA_BARANG_REKAP_OUT($barang_id, $ExportFormat = 'pdf',&$namafile, &$isifile)
        {
            
        $XML=XMLbasic('MG_DATA_BARANG_REKAP_OUT');

		AddField($XML,'data_by', '0');
		paramView($XML,'50','1','r5','0');
		AddField($XML,'barang_id',$barang_id);  
		AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
           foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }  
            
               
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_MG_DATA_BARANG_REKAP_PLAN_IN'))
    {
            function RPT_MG_DATA_BARANG_REKAP_PLAN_IN($barang_id, $ExportFormat = 'pdf',&$namafile, &$isifile)
        {
            
        $XML=XMLbasic('MG_DATA_BARANG_REKAP_PLAN_IN');

		AddField($XML,'data_by', '0');
		paramView($XML,'50','1','r5','0');
		AddField($XML,'barang_id',$barang_id);  
		AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
           foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }  
            
               
                        
                    
                       
             
        }
    }
	
	if ( ! function_exists('RPT_MG_DATA_BARANG_REKAP_PLAN_OUT'))
    {
            function RPT_MG_DATA_BARANG_REKAP_PLAN_OUT($barang_id, $ExportFormat = 'pdf',&$namafile, &$isifile)
        {
            
        $XML=XMLbasic('MG_DATA_BARANG_REKAP_PLAN_OUT');

		AddField($XML,'data_by', '0');
		paramView($XML,'50','1','r5','0');
		AddField($XML,'barang_id',$barang_id);  
		AddField($XML,'mode','2');  
        AddField($XML,'format',$ExportFormat);   
        connectwebservice($XML->saveXML(), '',$sts,$des,$rows,$detail);
         
           foreach ($rows as $per_row) {
                        $namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
                        $isifile=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
                    }  
            
               
                        
                    
                       
             
        }
    }
	
    
    if ( ! function_exists('AddBahanFormulaScrap'))
    {
        function AddBahanFormulaScrap(&$doc ,$barang_id,$qty )
        {
            $node = $doc->getElementsByTagName('param')->item(0);
            $field = $node->getElementsByTagName('field')->item(0);
            
            if ($field->getElementsByTagName('formula_list')->item(0)!=null){
                $detail_supply = $field->getElementsByTagName('formula_list')->item(0);
             
            }
            else {
                $detail_supply = $doc->createElement('formula_list', '');
                $field->appendChild($detail_supply);
                 
            };
        
                $element = $doc->createElement('ls', '');
                $element->setAttribute('barang_id',$barang_id);
                $element->setAttribute('qty',$qty);  
                 $detail_supply->appendChild($element);
         
         }
     }
    
	if ( ! function_exists('parseDateYMD_db'))
    {
        function parseDateYMD_db($date_string)
        {
            $parse_date = explode("/",$date_string);
        
            $fdate = $parse_date[2].$parse_date[1].$parse_date[0];
            return $fdate;
        }
    }
	
    if ( ! function_exists('parseDateDMY'))
    {
        function parseDateDMY($date_string)
        {
            $parse_date = explode("/",$date_string);
        
            $fdate = $parse_date[2].$parse_date[1].$parse_date[0];
            return $fdate;
        }
    }
     
    if ( ! function_exists('parseDateMDY'))
    {
        function parseDateMDY($date_string)
        {
            $parse_date = explode("/",$date_string);
        
            $fdate = $parse_date[2].$parse_date[0].$parse_date[1];
            return $fdate;
        }
     }
	 
	  if ( ! function_exists('saveMyFile'))
    {
        function saveMyFile($rows,&$namafile,&$savedFile)
        {
		$data='';
		$namafile='';
		$savedFile='';
		$targetFolder = $_SERVER['DOCUMENT_ROOT'] . '/tempFile/file/'; 
			   if (!file_exists($targetFolder)) {
					mkdir($targetFolder, 0777, true);
				}
	 	
			if ($rows){
				foreach ($rows as $per_row) {
								$namafile=$per_row->getElementsByTagName('xfilename')->item(0)->nodeValue;
								$data=base64_decode($per_row->getElementsByTagName('xfile')->item(0)->nodeValue);
				}
 			
				$savedFile = $targetFolder . md5(uniqid("",true) ). '.html';
				$handle = fopen($savedFile, 'w') or die('Cannot open file: '.$savedFile);
				fwrite($handle, $data); 
				fclose($handle);
				sleep(2);
			}
           	
        }
     }
	  if ( ! function_exists('printMyFile'))
    {
        function printMyFile($filename,$filenamex)
        {
			if(file_exists($filename)) {
					$fileName = basename($filename);
					$fileSize = filesize($filename);

					// Output headers.
					header("Cache-Control: private");
					header("Content-Type: application/stream");
					header("Content-Length: ".$fileSize);
					header("Content-Disposition: attachment; filename=".$filenamex);

					// Output file.
					readfile ($filename);     
					unlink($filename);			
					exit();
			}
			else {
				die('The provided file path: ' . $filename .' is not valid.');
			}  
		}
	}
     
?>