Jump to content

Read line by line on .EDI File


luiggicc

Recommended Posts

Hello everyone, i got this problem.

I have to read .EDI file, it was hard but i already did it but i found a little problem.

EDI file structure is complex, so my php function read all the data structure and save on an array and that array pass the values to others function to insert data on a html table. The problem is when i read my file, it only reads the first line, i know there's so many documentation, but in this case is little bit different because the fact is reading files with extension ".edi".

My function to read the file is this.

if(isset($_FILES['ufile']['name'])){
       if ($_POST['teste'] == "S"){
		  echo "<table><tr><td><strong>File: ".$_FILES['ufile']['name']."</strong></td></tr></table><br>";
	   }
	   
	   $tmpName = $_FILES['ufile']['tmp_name'];
       $newName = "" . $_FILES['ufile']['name'];   
       if(!is_uploaded_file($tmpName) || !move_uploaded_file($tmpName, $newName)){
            echo "<table><tr><td><strong>Failed to read file ".$_FILES['ufile']['name']."</strong></td></tr></table>";
       } else {
            echo "<br>";
            
            //coloca o conteudo do arquivo para a variavel $arquivo			
			$ponteiro = fopen ($_FILES['ufile']['name'],"r");
            $arquivo = '';
            
            
			while (!feof ($ponteiro)) {
				$arquivo = $arquivo.fgets($ponteiro);
			}			
			fclose ($ponteiro);
			if (unlink($_FILES['ufile']['name']) != 1) echo "Erro ao deletar arquivo!";			
				
			$padrao = fnc_resgata_padrao($arquivo);
			

			if ($padrao == "COARRI"){
				$a = fnc_processa_coarri(trim($arquivo));
				prc_mostra_coarri($a);				
				
			}
			elseif ($padrao == "CODECO") {
				$a = fnc_processa_codeco(trim($arquivo));
				echo $a;
				prc_mostra_codeco($a);				
			}
            else {
                echo "<table><tr><td><strong>Invalid file</strong></td></tr></table>";
			}			
			
       } 

   } else {
     echo "You need to select a file.  Please try again.";
  }

Any suggestion? This .edi files are getting my crazy.

Link to comment
Share on other sites

How do you know that only the first line is read? Where in your code do you check that?

 

Because if a do a var_dump in this function, shows me what is inside the array.

if ($padrao == "COARRI"){
	$a = fnc_processa_coarri(trim($arquivo));
        var_dump($a);
	prc_mostra_coarri($a);						
}

I will explain a little bit more with EDI data.

 

 

UNB+UNOA:2+TPG005+COSCO+170212:2038+OPER1702122038'

UNH+00000001+COARRI:D:95B:UN:ITG12'

BGM+270+201702122038+9'

TDT+20+028W+1++CCL:172:20+++9484003:146::COSCO ADEN'

RFF+VON:028W/W'

LOC+9+ECGYE:139:6+:BER:ZZZ'

DTM+132:201702111400:203'

DTM+133:201702122038:203'

NAD+CA+CCL:160:20'

EQD+CN+CBHU6071322+4200:102:5+++4'

RFF+BN:E0003128380'

DTM+203:20170212200500:203'

LOC+9+ECGYE:139:6'

LOC+11+CNNGB:139:6'

LOC+7+CNNGB:139:6'

LOC+147+0620382::5'

MEA+AAE+VGM+KGM:3721'

DAM+1++++G'

NAD+CF+CCL:160:20'

EQD+CN+CCLU5183626+4200:102:5+++4'

RFF+BN:E0003128380'

DTM+203:20170212195000:203'

LOC+9+ECGYE:139:6'

LOC+11+CNNGB:139:6'

LOC+7+CNNGB:139:6'

LOC+147+0100612::5'

MEA+AAE+VGM+KGM:3641'

DAM+1++++G'

NAD+CF+CCL:160:20'

EQD+CN+MAGU4876676+4200:102:5+++4'

RFF+BN:E0003128380'

DTM+203:20170212195800:203'

LOC+9+ECGYE:139:6'

LOC+11+CNNGB:139:6'

LOC+7+CNNGB:139:6'

LOC+147+0620188::5'

MEA+AAE+VGM+KGM:3611'

DAM+1++++G'

NAD+CF+CCL:160:20'

EQD+CN+CBHU6243381+4200:102:5+++4'

RFF+BN:E0003128380'

DTM+203:20170212195900:203'

LOC+9+ECGYE:139:6'

LOC+11+CNNGB:139:6'

LOC+7+CNNGB:139:6'

LOC+147+0620584::5'

MEA+AAE+VGM+KGM:3721'

DAM+1++++G'

NAD+CF+CCL:160:20'

EQD+CN+CCLU4982567+4210:102:5+++4'

RFF+BN:E0003128380'

DTM+203:20170212200000:203'

LOC+9+ECGYE:139:6'

LOC+11+CNNGB:139:6'

LOC+7+CNNGB:139:6'

LOC+147+0620186::5'

MEA+AAE+VGM+KGM:3741'

DAM+1++++G'

NAD+CF+CCL:160:20'

EQD+CN+CCLU4568794+4210:102:5+++4'

RFF+BN:E0003128380'

DTM+203:20170212200100:203'

LOC+9+ECGYE:139:6'

LOC+11+CNNGB:139:6'

LOC+7+CNNGB:139:6'

LOC+147+0620086::5'

MEA+AAE+VGM+KGM:3741'

DAM+1++++G'

NAD+CF+CCL:160:20'

EQD+CN+CSLU5160848+4210:102:5+++4'

RFF+BN:E0003128380'

DTM+203:20170212200400:203'

LOC+9+ECGYE:139:6'

LOC+11+CNNGB:139:6'

LOC+7+CNNGB:139:6'

LOC+147+0620084::5'

MEA+AAE+VGM+KGM:3741'

DAM+1++++G'

NAD+CF+CCL:160:20'

EQD+CN+CCLU4263666+4200:102:5+++4'

RFF+BN:E0003128380'

DTM+203:20170212200500:203'

LOC+9+ECGYE:139:6'

LOC+11+CNNGB:139:6'

LOC+7+CNNGB:139:6'

LOC+147+0620088::5'

MEA+AAE+VGM+KGM:3651'

DAM+1++++G'

NAD+CF+CCL:160:20'

EQD+CN+CCLU4899426+4200:102:5+++4'

RFF+BN:E0003128380'

DTM+203:20170212200800:203'

LOC+9+ECGYE:139:6'

LOC+11+CNNGB:139:6'

LOC+7+CNNGB:139:6'

LOC+147+0620182::5'

MEA+AAE+VGM+KGM:3741'

DAM+1++++G'

NAD+CF+CCL:160:20'

EQD+CN+CBHU1949945+4200:102:5+++4'

RFF+BN:E0003128380'

DTM+203:20170212201000:203'

LOC+9+ECGYE:139:6'

LOC+11+CNNGB:139:6'

LOC+7+CNNGB:139:6'

LOC+147+0620582::5'

MEA+AAE+VGM+KGM:3721'

DAM+1++++G'

NAD+CF+CCL:160:20'

EQD+CN+CBHU1984490+4200:102:5+++4'

RFF+BN:E0003128380'

DTM+203:20170212203800:203'

LOC+9+ECGYE:139:6'

LOC+11+CNNGB:139:6'

LOC+7+CNNGB:139:6'

LOC+147+0100514::5'

MEA+AAE+VGM+KGM:3721'

DAM+1++++G'

 

This is the data on a .EDI file. On the second line start with UNH, this is like the header of the data and the rest is the body that has information about containers (Maritime industry). The function must read line by line, but only reads the first container data and not all.

 

I tried so many things, i know the part i must re-code is this, i guess:

$ponteiro = fopen ($_FILES['ufile']['name'],"r");
$arquivo = '';
while (!feof ($ponteiro)) {
 $arquivo = $arquivo.fgets($ponteiro);
}

Because in this part i manage and read the data of the file, i don't have an idea on how to read properly all data instead of the first position (cero)

Edited by luiggicc
Link to comment
Share on other sites

The file content is stored in the string $arquivo. Is this string complete? Then there is no problem with reading the file.

 

If there's an issue in some other function, we need to see that function.

 

Yes, it is a string. I was trying with file_get_contents, i can see all the data as i want, the good part. The bad part is that send me error on the "while".

 

 

Warning: feof() expects parameter 1 to be resource, string given in C:\xampp\htdocs\EDI\ler.php on line 890

 

Warning: fgets() expects parameter 1 to be resource, string given in C:\xampp\htdocs\EDI\ler.php on line 891

 

Lines 890 and 891 are:

while (!feof ($ponteiro)) {
 $arquivo = $arquivo.fgets($ponteiro);
}	
Link to comment
Share on other sites

I have no idea what you're doing there. You're supposed to replace the entire fopen/feof/fgets stuff with a single file_get_contents() call. Like this:

$arquivo = file_get_contents('/path/to/file');

Note that accepting arbitrary files and moving them around on your server is dangerous. Anybody can upload malware this way. It's not even clear where you want to move the files, because you haven't provided a target path, just a filename. If you just want to read the content, don't move the file at all.

Link to comment
Share on other sites

I have no idea what you're doing there. You're supposed to replace the entire fopen/feof/fgets stuff with a single file_get_contents() call. Like this:

 

I just did that but there's a problem. It is still getting only the first position. When i do this:

$arquivo = file_get_contents($_FILES['ufile']['name']);
echo "<pre>";
echo $arquivo;
echo "</pre>";

It shows all the data of my .EDI File.

 

But when i do a Print_r on the function that is stored on a variable only returns the first position.

 

if ($padrao == "COARRI"){
   $a = fnc_processa_coarri(trim($arquivo));
   echo "<pre>";
   print_r($a);
   echo "</pre>"; 
   prc_mostra_coarri($a);				
}

Like this:

 

Array(    [Sender] => Array        (            [0] => TPG005        )    [Recipient] => Array        (            [0] => COSCO        )

 

The function that process the data is this:

function fnc_processa_coarri($p_arquivo)
{
  $segmento = fnc_obter_linha_segmento ($p_arquivo, "UNB");
  $ini = strpos($p_arquivo,"UNH",0);
  $fim = strpos($p_arquivo,"UNT",0);
  for( $i = 0; $i <= substr_count($p_arquivo, "UNH")-1; $i++ ) {
	  $parte = substr($p_arquivo,$ini,$fim-$ini);
	  if ($i == 0) {
          $a = ['Sender'=>[fnc_edi_recupera_compnte($segmento,2,0)],
		        'Recipient'=>[fnc_edi_recupera_compnte($segmento,3,0)],
				'DateDoc'=>[fnc_edi_recupera_compnte($segmento,4,1)],
				'TimeDoc'=>[fnc_edi_recupera_compnte($segmento,4,2)],
				'IdSender'=>[fnc_edi_recupera_compnte($segmento,5,0)],
				'Seq'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "BGM"),2,0)],
				'Move'=>[fnc_resgata_tipo_movimento(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "BGM"),1,0))], 
				'FunctionMsg'=>[fnc_resgata_funcao_mensagem(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "BGM"),3,0))], 
				'Voyage'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),2,0)], 				
				'ModeTransp1'=>[fnc_resgata_modo_transp(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),3,0))], 				
				'TranspMeans1'=>[fnc_resgata_transp_means(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),4,0))], 				
				'CarrierCode1'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),5,1)], 				
				'VesselId'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),8,1)], 				
				'TypeId'=>[fnc_resgata_tipo_id_navio(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),8,2))], 				
				'VesselName'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),8,4)],
				'PortLoad'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+9",5),2,1)],
				'PortDischarge'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+11",6),2,1)],
				'Arrival'=>[fnc_formata_data(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DTM+132",7),1,2))],
				'Departure'=>[fnc_formata_data(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DTM+133",7),1,2))],
				'Operator'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "NAD+CF",6),2,0)],
				'Carrier'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "NAD+CA",6),2,0)],
				'Agent'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "NAD+AG",6),2,0)],
				'EquipQualif'=>[fnc_resgata_qualif_equipamento(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),1,0))],
		        'EquipIdent'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),2,0)],
                'SizeType'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),3,1)],
				'Category'=>[fnc_resgata_categoria(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),5,0))],
				'Status'=>[fnc_resgata_status(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),6,0))],
				'Booking'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RFF+BN",6),1,2)],
				'BL'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RFF+BM",6),1,2)],
				'OwnerCargo'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RFF+AAE",7),1,2)],
				'ExecutionDate'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DTM+203",7),1,2)],
				'PositionOnVessel'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+147",7),2,1)],				
				'FinalDest'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+7",5),2,1)],
				'TareWeight'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+T",9),3,2)],				
				'TareWeightUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+T",9),3,1)],				
				'GrossWeight'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+G",9),3,2)],				
				'GrossWeightUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+G",9),3,1)],				
				'Seal'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "SEL"),1,0)],								
				'TypeSeal'=>[fnc_resgata_tipo_lacre(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "SEL"),2,0))],
				'IdealTemp'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TMP"),2,1)],
				'IdealTempUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TMP"),2,2)],
				'MinTemp'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RNG"),2,2)],
				'MaxTemp'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RNG"),2,3)],
				'MinMaxTempUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RNG"),2,1)],
				'OverDmsFrontLen'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,2)],
				'OverDmsFrontWid'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,3)],
				'OverDmsFrontHei'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,4)],
				'OverDmsFrontUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,1)],				
				'OverDmsBackLen'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,2)],
				'OverDmsBackWid'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,3)],
				'OverDmsBackHei'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,4)],
				'OverDmsBackUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,1)],				
				'OverDmsRightLen'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,2)],
				'OverDmsRightWid'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,3)],
				'OverDmsRightHei'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,4)],
				'OverDmsRightUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,1)],				
				'OverDmsLeftLen'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,2)],
				'OverDmsLeftWid'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,3)],
				'OverDmsLeftHei'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,4)],
				'OverDmsLeftUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,1)],				
				'OverDmsGenLen'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,2)],
				'OverDmsGenWid'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,3)],
				'OverDmsGenHei'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,4)],				
				'OverDmsGenUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,1)],												
				'OverDmsExtLen'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,2)],
				'OverDmsExtWid'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,3)],
				'OverDmsExtHei'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,4)],
				'OverDmsExtUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,1)],				
				'ModeTransp2'=>[fnc_resgata_modo_transp(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),3,0))],				
				'TranspMeans2'=>[fnc_resgata_transp_means(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),4,0))],							
				'CarrierCode2'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),8,1)],
				'Responsible'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),8,4)],
				'Damage'=>[fnc_determina_dano(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DAM"),1,0))],
				'DamageCode'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DAM"),5,0)],
	            ];		
	    }
	  else {
		array_push($a["Sender"], fnc_edi_recupera_compnte($segmento,2,0));	
		array_push($a["Recipient"], fnc_edi_recupera_compnte($segmento,3,0));	
		array_push($a["DateDoc"], fnc_edi_recupera_compnte($segmento,4,1));	
		array_push($a["TimeDoc"], fnc_edi_recupera_compnte($segmento,4,2));	
		array_push($a["IdSender"], fnc_edi_recupera_compnte($segmento,5,0));	
		array_push($a["Seq"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "BGM"),2,0));	
		array_push($a["Move"], fnc_resgata_tipo_movimento(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "BGM"),1,0)));	
		array_push($a["FunctionMsg"], fnc_resgata_funcao_mensagem(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "BGM"),3,0)));	
		array_push($a["Voyage"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),2,0));	
		array_push($a["ModeTransp1"], fnc_resgata_modo_transp(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),3,0)));	
		array_push($a["TranspMeans1"], fnc_resgata_transp_means(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),4,0)));	
		array_push($a["CarrierCode1"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),5,1));	
		array_push($a["VesselId"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),8,1));	
		array_push($a["TypeId"], fnc_resgata_tipo_id_navio(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),8,2)));	
		array_push($a["VesselName"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),8,4));	
		array_push($a["PortLoad"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+9",5),2,1));	
		array_push($a["PortDischarge"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+11",6),2,1));	
		array_push($a["Arrival"], fnc_formata_data(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DTM+132",7),1,2)));	
		array_push($a["Departure"], fnc_formata_data(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DTM+133",7),1,2)));	
		array_push($a["Operator"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "NAD+CF",6),2,0));	
		array_push($a["Carrier"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "NAD+CA",6),2,0));	
		array_push($a["Agent"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "NAD+AG",6),2,0));	
		array_push($a["EquipQualif"], fnc_resgata_qualif_equipamento(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),1,0)));	
		array_push($a["EquipIdent"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),2,0));	
        array_push($a["SizeType"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),3,1));	  	
		array_push($a["Category"], fnc_resgata_categoria(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),5,0)));	  	
		array_push($a["Status"], fnc_resgata_status(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),6,0)));	  	
		array_push($a["Booking"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RFF+BN",6),1,2));	  	
		array_push($a["BL"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RFF+BM",6),1,2));	  	
		array_push($a["OwnerCargo"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RFF+AAE",7),1,2));	  	
		array_push($a["ExecutionDate"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DTM+203",7),1,2));	  			
		array_push($a["PositionOnVessel"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+147",7),2,1));	  			
		array_push($a["FinalDest"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+7",5),2,1));	  	
		array_push($a["TareWeight"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+T",9),3,2));	  	
		array_push($a["TareWeightUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+T",9),3,1));	  	
		array_push($a["GrossWeight"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+G",9),3,2));	  	
		array_push($a["GrossWeightUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+G",9),3,1));	  	
		array_push($a["Seal"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "SEL"),1,0));	  	
		array_push($a["TypeSeal"], fnc_resgata_tipo_lacre(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "SEL"),2,0)));	  	
		array_push($a["IdealTemp"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TMP"),2,1));	  	
		array_push($a["IdealTempUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TMP"),2,2));
        array_push($a["MinTemp"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RNG"),2,2));	  		  	
		array_push($a["MaxTemp"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RNG"),2,3));
		array_push($a["MinMaxTempUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RNG"),2,1));
		array_push($a["OverDmsFrontLen"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,2));
		array_push($a["OverDmsFrontWid"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,3));
		array_push($a["OverDmsFrontHei"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,4));		
		array_push($a["OverDmsFrontUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,1));		
		array_push($a["OverDmsBackLen"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,2));
		array_push($a["OverDmsBackWid"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,3));
		array_push($a["OverDmsBackHei"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,4));
		array_push($a["OverDmsBackUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,1));		
		array_push($a["OverDmsRightLen"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,2));
		array_push($a["OverDmsRightWid"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,3));
		array_push($a["OverDmsRightHei"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,4));
		array_push($a["OverDmsRightUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,1));		
		array_push($a["OverDmsLeftLen"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,2));
		array_push($a["OverDmsLeftWid"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,3));
		array_push($a["OverDmsLeftHei"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,4));
		array_push($a["OverDmsLeftUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,1));		
		array_push($a["OverDmsGenLen"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,2));
		array_push($a["OverDmsGenWid"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,3));
		array_push($a["OverDmsGenHei"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,4));
		array_push($a["OverDmsGenUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,1));		
		array_push($a["OverDmsExtLen"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,2));
		array_push($a["OverDmsExtWid"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,3));
		array_push($a["OverDmsExtHei"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,4));
		array_push($a["OverDmsExtUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,1));
		array_push($a["ModeTransp2"], fnc_resgata_modo_transp(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),3,0)));
		array_push($a["TranspMeans2"], fnc_resgata_transp_means(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),4,0)));
		array_push($a["CarrierCode2"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),8,1));
		array_push($a["Responsible"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),8,4));
		array_push($a["Damage"], fnc_determina_dano(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DAM"),1,0)));
		array_push($a["DamageCode"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DAM"),5,0));
	  }	

	  $ini = strpos($p_arquivo,"UNH",$fim);
	  $fim = strpos($p_arquivo,"UNT",$ini);
  }  
  return $a;    
}
Link to comment
Share on other sites

Yeah, well, so what is the problem? What should the data look like?

 

You keep saying that only the first line is read, but how did you determine that? What specifically is missing? I'm not a mind reader.

 

If you want me to take a wild guess, I'd say you're missing the “UNT”. Your function extracts everything between “UNH” and “UNT”, but your sample data has no “UNT”, so nothing gets extracted. Unless you've left out all relevant bits, which would be somewhat silly.

 

In any case: Do some basic debugging with var_dump() so that you can provide concrete information. I'm not interested in guessing games with foreign languages and exotic data formats.

Link to comment
Share on other sites

Yeah, i know. i didn't paste all data from the .EDI because is too large. It has UNH and UNT, but only 1 in this case. And the function that i paste on my last post start by each UNH and UNT that has the file, but in my case, i got only as i said, 1 UNH and UNT and inside them has the information that i want to show it.

 

Complete .EDI

 

 

UNB+UNOA:2+TPG005+COSCO+170212:2038+OPER1702122038'
UNH+00000001+COARRI:D:95B:UN:ITG12'
BGM+270+201702122038+9'
TDT+20+028W+1++CCL:172:20+++9484003:146::COSCO ADEN'
RFF+VON:028W/W'
LOC+9+ECGYE:139:6+:BER:ZZZ'
DTM+132:201702111400:203'
DTM+133:201702122038:203'
NAD+CA+CCL:160:20'
EQD+CN+CBHU6071322+4200:102:5+++4'
RFF+BN:E0003128380'
DTM+203:20170212200500:203'
LOC+9+ECGYE:139:6'
LOC+11+CNNGB:139:6'
LOC+7+CNNGB:139:6'
LOC+147+0620382::5'
MEA+AAE+VGM+KGM:3721'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+CCLU5183626+4200:102:5+++4'
RFF+BN:E0003128380'
DTM+203:20170212195000:203'
LOC+9+ECGYE:139:6'
LOC+11+CNNGB:139:6'
LOC+7+CNNGB:139:6'
LOC+147+0100612::5'
MEA+AAE+VGM+KGM:3641'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+MAGU4876676+4200:102:5+++4'
RFF+BN:E0003128380'
DTM+203:20170212195800:203'
LOC+9+ECGYE:139:6'
LOC+11+CNNGB:139:6'
LOC+7+CNNGB:139:6'
LOC+147+0620188::5'
MEA+AAE+VGM+KGM:3611'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+CBHU6243381+4200:102:5+++4'
RFF+BN:E0003128380'
DTM+203:20170212195900:203'
LOC+9+ECGYE:139:6'
LOC+11+CNNGB:139:6'
LOC+7+CNNGB:139:6'
LOC+147+0620584::5'
MEA+AAE+VGM+KGM:3721'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+CCLU4982567+4210:102:5+++4'
RFF+BN:E0003128380'
DTM+203:20170212200000:203'
LOC+9+ECGYE:139:6'
LOC+11+CNNGB:139:6'
LOC+7+CNNGB:139:6'
LOC+147+0620186::5'
MEA+AAE+VGM+KGM:3741'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+CCLU4568794+4210:102:5+++4'
RFF+BN:E0003128380'
DTM+203:20170212200100:203'
LOC+9+ECGYE:139:6'
LOC+11+CNNGB:139:6'
LOC+7+CNNGB:139:6'
LOC+147+0620086::5'
MEA+AAE+VGM+KGM:3741'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+CSLU5160848+4210:102:5+++4'
RFF+BN:E0003128380'
DTM+203:20170212200400:203'
LOC+9+ECGYE:139:6'
LOC+11+CNNGB:139:6'
LOC+7+CNNGB:139:6'
LOC+147+0620084::5'
MEA+AAE+VGM+KGM:3741'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+CCLU4263666+4200:102:5+++4'
RFF+BN:E0003128380'
DTM+203:20170212200500:203'
LOC+9+ECGYE:139:6'
LOC+11+CNNGB:139:6'
LOC+7+CNNGB:139:6'
LOC+147+0620088::5'
MEA+AAE+VGM+KGM:3651'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+CCLU4899426+4200:102:5+++4'
RFF+BN:E0003128380'
DTM+203:20170212200800:203'
LOC+9+ECGYE:139:6'
LOC+11+CNNGB:139:6'
LOC+7+CNNGB:139:6'
LOC+147+0620182::5'
MEA+AAE+VGM+KGM:3741'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+CBHU1949945+4200:102:5+++4'
RFF+BN:E0003128380'
DTM+203:20170212201000:203'
LOC+9+ECGYE:139:6'
LOC+11+CNNGB:139:6'
LOC+7+CNNGB:139:6'
LOC+147+0620582::5'
MEA+AAE+VGM+KGM:3721'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+CBHU1984490+4200:102:5+++4'
RFF+BN:E0003128380'
DTM+203:20170212203800:203'
LOC+9+ECGYE:139:6'
LOC+11+CNNGB:139:6'
LOC+7+CNNGB:139:6'
LOC+147+0100514::5'
MEA+AAE+VGM+KGM:3721'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+CXRU1493740+4530:102:5+++5'
RFF+BN:8008092200'
DTM+203:20170212203200:203'
LOC+9+ECGYE:139:6'
LOC+11+HKHKG:139:6'
LOC+7+VNHPH:139:6'
LOC+147+0100582::5'
MEA+AAE+VGM+KGM:29640'
TMP+2+-18.0:CEL'
RNG+5+CEL:-18.0:-18.0'
SEL+3758325+CA'
SEL+0093299+SH'
SEL+H129803+SH'
SEL+TS63833+SH'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+TEMU9277959+4530:102:5+++5'
RFF+BN:8008092630'
DTM+203:20170212202700:203'
LOC+9+ECGYE:139:6'
LOC+11+HKHKG:139:6'
LOC+7+VNHPH:139:6'
LOC+147+0100784::5'
MEA+AAE+VGM+KGM:29630'
TMP+2+-18.0:CEL'
RNG+5+CEL:-18.0:-18.0'
SEL+3761499+CA'
SEL+0093296+CA'
SEL+H129821+CA'
SEL+TS63741+SH'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+CXRU1499944+4530:102:5+++5'
RFF+BN:8008093770'
DTM+203:20170212202100:203'
LOC+9+ECGYE:139:6'
LOC+11+HKHKG:139:6'
LOC+7+VNHPH:139:6'
LOC+147+0100782::5'
MEA+AAE+VGM+KGM:31760'
TMP+2+-18.0:CEL'
RNG+5+CEL:-18.0:-18.0'
SEL+3758196+CA'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+TRIU8876857+4530:102:5+++5'
RFF+BN:8008093780'
DTM+203:20170212202400:203'
LOC+9+ECGYE:139:6'
LOC+11+HKHKG:139:6'
LOC+7+VNHPH:139:6'
LOC+147+0100884::5'
MEA+AAE+VGM+KGM:31980'
TMP+2+-18.0:CEL'
RNG+5+CEL:-18.0:-18.0'
SEL+3758235+CA'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+SZLU9142009+4530:102:5+++5'
RFF+BN:8008092610'
DTM+203:20170212203100:203'
LOC+9+ECGYE:139:6'
LOC+11+HKHKG:139:6'
LOC+7+VNHPH:139:6'
LOC+147+0100682::5'
MEA+AAE+VGM+KGM:29870'
TMP+2+-18.0:CEL'
RNG+5+CEL:-18.0:-18.0'
SEL+3759791+CA'
SEL+0093298+CA'
SEL+H129975+CA'
SEL+TS63710+SH'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+CXRU1492240+4530:102:5+++5'
RFF+BN:8008093310'
DTM+203:20170212202900:203'
LOC+9+ECGYE:139:6'
LOC+11+HKHKG:139:6'
LOC+7+VNHPH:139:6'
LOC+147+0100882::5'
MEA+AAE+VGM+KGM:31690'
TMP+2+-20.0:CEL'
RNG+5+CEL:-20.0:-20.0'
SEL+3758236+CA'
SEL+1BSP010124+SH'
SEL+C1SP01367+SH'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+CCLU8585866+4530:102:5+++5'
RFF+BN:8008093620'
DTM+203:20170212203700:203'
LOC+9+ECGYE:139:6'
LOC+11+HKHKG:139:6'
LOC+7+VNHPH:139:6'
LOC+147+0180182::5'
MEA+AAE+VGM+KGM:30780'
TMP+2+-20.0:CEL'
RNG+5+CEL:-20.0:-20.0'
SEL+3761369+CA'
SEL+1BSP010218+CA'
SEL+C1SP01690+SH'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+BMOU9504581+4530:102:5+++5'
RFF+BN:8008093640'
DTM+203:20170212203500:203'
LOC+9+ECGYE:139:6'
LOC+11+HKHKG:139:6'
LOC+7+VNHPH:139:6'
LOC+147+0180284::5'
MEA+AAE+VGM+KGM:30850'
TMP+2+-20.0:CEL'
RNG+5+CEL:-20.0:-20.0'
SEL+3758232+CA'
SEL+1BSP010214+SH'
SEL+C1SP01683+SH'
DAM+1++++G'
NAD+CF+CCL:160:20'
EQD+CN+TTNU8014009+4530:102:5+++5'
RFF+BN:8008093740'
DTM+203:20170212202100:203'
LOC+9+ECGYE:139:6'
LOC+11+HKHKG:139:6'
LOC+7+VNHPH:139:6'
LOC+147+0100984::5'
MEA+AAE+VGM+KGM:27200'
TMP+2+-20.0:CEL'
RNG+5+CEL:-20.0:-20.0'
SEL+3758249+CA'
SEL+053624+SH'
SEL+202455+SH'
SEL+C140092+SH'
DAM+1++++G'
NAD+CF+CCL:160:20'
CNT+1:1'
UNT+255+00000001'
UNZ+1+OPER1702122038'

 

And complete process function

function fnc_processa_coarri($p_arquivo)
{
  $segmento = fnc_obter_linha_segmento ($p_arquivo, "UNB");
  $ini = strpos($p_arquivo,"UNH",0);
  $fim = strpos($p_arquivo,"UNT",0);
  for( $i = 0; $i <= substr_count($p_arquivo, "UNH")-1; $i++ ) {
  	$parte = substr($p_arquivo,$ini,$fim-$ini);
	  if ($i == 0) {
          $a = ['Sender'=>[fnc_edi_recupera_compnte($segmento,2,0)],
		        'Recipient'=>[fnc_edi_recupera_compnte($segmento,3,0)],
				'DateDoc'=>[fnc_edi_recupera_compnte($segmento,4,1)],
				'TimeDoc'=>[fnc_edi_recupera_compnte($segmento,4,2)],
				'IdSender'=>[fnc_edi_recupera_compnte($segmento,5,0)],
				'Seq'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "BGM"),2,0)],
				'Move'=>[fnc_resgata_tipo_movimento(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "BGM"),1,0))], 
				'FunctionMsg'=>[fnc_resgata_funcao_mensagem(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "BGM"),3,0))], 
				'Voyage'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),2,0)], 				
				'ModeTransp1'=>[fnc_resgata_modo_transp(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),3,0))], 				
				'TranspMeans1'=>[fnc_resgata_transp_means(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),4,0))], 				
				'CarrierCode1'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),5,1)], 				
				'VesselId'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),8,1)], 				
				'TypeId'=>[fnc_resgata_tipo_id_navio(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),8,2))], 				
				'VesselName'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),8,4)],
				'PortLoad'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+9",5),2,1)],
				'PortDischarge'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+11",6),2,1)],
				'Arrival'=>[fnc_formata_data(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DTM+132",7),1,2))],
				'Departure'=>[fnc_formata_data(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DTM+133",7),1,2))],
				'Operator'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "NAD+CF",6),2,0)],
				'Carrier'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "NAD+CA",6),2,0)],
				'Agent'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "NAD+AG",6),2,0)],
				'EquipQualif'=>[fnc_resgata_qualif_equipamento(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),1,0))],
		        'EquipIdent'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),2,0)],
                'SizeType'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),3,1)],
				'Category'=>[fnc_resgata_categoria(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),5,0))],
				'Status'=>[fnc_resgata_status(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),6,0))],
				'Booking'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RFF+BN",6),1,2)],
				'BL'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RFF+BM",6),1,2)],
				'OwnerCargo'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RFF+AAE",7),1,2)],
				'ExecutionDate'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DTM+203",7),1,2)],
				'PositionOnVessel'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+147",7),2,1)],				
				'FinalDest'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+7",5),2,1)],
				'TareWeight'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+T",9),3,2)],				
				'TareWeightUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+T",9),3,1)],				
				'GrossWeight'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+G",9),3,2)],				
				'GrossWeightUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+G",9),3,1)],				
				'Seal'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "SEL"),1,0)],								
				'TypeSeal'=>[fnc_resgata_tipo_lacre(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "SEL"),2,0))],
				'IdealTemp'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TMP"),2,1)],
				'IdealTempUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TMP"),2,2)],
				'MinTemp'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RNG"),2,2)],
				'MaxTemp'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RNG"),2,3)],
				'MinMaxTempUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RNG"),2,1)],
				'OverDmsFrontLen'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,2)],
				'OverDmsFrontWid'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,3)],
				'OverDmsFrontHei'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,4)],
				'OverDmsFrontUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,1)],				
				'OverDmsBackLen'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,2)],
				'OverDmsBackWid'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,3)],
				'OverDmsBackHei'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,4)],
				'OverDmsBackUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,1)],				
				'OverDmsRightLen'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,2)],
				'OverDmsRightWid'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,3)],
				'OverDmsRightHei'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,4)],
				'OverDmsRightUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,1)],				
				'OverDmsLeftLen'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,2)],
				'OverDmsLeftWid'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,3)],
				'OverDmsLeftHei'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,4)],
				'OverDmsLeftUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,1)],				
				'OverDmsGenLen'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,2)],
				'OverDmsGenWid'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,3)],
				'OverDmsGenHei'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,4)],				
				'OverDmsGenUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,1)],												
				'OverDmsExtLen'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,2)],
				'OverDmsExtWid'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,3)],
				'OverDmsExtHei'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,4)],
				'OverDmsExtUnit'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,1)],				
				'ModeTransp2'=>[fnc_resgata_modo_transp(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),3,0))],				
				'TranspMeans2'=>[fnc_resgata_transp_means(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),4,0))],							
				'CarrierCode2'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),8,1)],
				'Responsible'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),8,4)],
				'Damage'=>[fnc_determina_dano(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DAM"),1,0))],
				'DamageCode'=>[fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DAM"),5,0)],
	            ];		
	    }
	  else {
		array_push($a["Sender"], fnc_edi_recupera_compnte($segmento,2,0));	
		array_push($a["Recipient"], fnc_edi_recupera_compnte($segmento,3,0));	
		array_push($a["DateDoc"], fnc_edi_recupera_compnte($segmento,4,1));	
		array_push($a["TimeDoc"], fnc_edi_recupera_compnte($segmento,4,2));	
		array_push($a["IdSender"], fnc_edi_recupera_compnte($segmento,5,0));	
		array_push($a["Seq"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "BGM"),2,0));	
		array_push($a["Move"], fnc_resgata_tipo_movimento(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "BGM"),1,0)));	
		array_push($a["FunctionMsg"], fnc_resgata_funcao_mensagem(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "BGM"),3,0)));	
		array_push($a["Voyage"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),2,0));	
		array_push($a["ModeTransp1"], fnc_resgata_modo_transp(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),3,0)));	
		array_push($a["TranspMeans1"], fnc_resgata_transp_means(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),4,0)));	
		array_push($a["CarrierCode1"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),5,1));	
		array_push($a["VesselId"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),8,1));	
		array_push($a["TypeId"], fnc_resgata_tipo_id_navio(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),8,2)));	
		array_push($a["VesselName"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT"),8,4));	
		array_push($a["PortLoad"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+9",5),2,1));	
		array_push($a["PortDischarge"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+11",6),2,1));	
		array_push($a["Arrival"], fnc_formata_data(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DTM+132",7),1,2)));	
		array_push($a["Departure"], fnc_formata_data(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DTM+133",7),1,2)));	
		array_push($a["Operator"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "NAD+CF",6),2,0));	
		array_push($a["Carrier"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "NAD+CA",6),2,0));	
		array_push($a["Agent"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "NAD+AG",6),2,0));	
		array_push($a["EquipQualif"], fnc_resgata_qualif_equipamento(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),1,0)));	
		array_push($a["EquipIdent"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),2,0));	
        array_push($a["SizeType"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),3,1));	  	
		array_push($a["Category"], fnc_resgata_categoria(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),5,0)));	  	
		array_push($a["Status"], fnc_resgata_status(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "EQD"),6,0)));	  	
		array_push($a["Booking"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RFF+BN",6),1,2));	  	
		array_push($a["BL"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RFF+BM",6),1,2));	  	
		array_push($a["OwnerCargo"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RFF+AAE",7),1,2));	  	
		array_push($a["ExecutionDate"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DTM+203",7),1,2));	  			
		array_push($a["PositionOnVessel"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+147",7),2,1));	  			
		array_push($a["FinalDest"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "LOC+7",5),2,1));	  	
		array_push($a["TareWeight"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+T",9),3,2));	  	
		array_push($a["TareWeightUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+T",9),3,1));	  	
		array_push($a["GrossWeight"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+G",9),3,2));	  	
		array_push($a["GrossWeightUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "MEA+AAE+G",9),3,1));	  	
		array_push($a["Seal"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "SEL"),1,0));	  	
		array_push($a["TypeSeal"], fnc_resgata_tipo_lacre(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "SEL"),2,0)));	  	
		array_push($a["IdealTemp"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TMP"),2,1));	  	
		array_push($a["IdealTempUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TMP"),2,2));
        array_push($a["MinTemp"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RNG"),2,2));	  		  	
		array_push($a["MaxTemp"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RNG"),2,3));
		array_push($a["MinMaxTempUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "RNG"),2,1));
		array_push($a["OverDmsFrontLen"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,2));
		array_push($a["OverDmsFrontWid"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,3));
		array_push($a["OverDmsFrontHei"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,4));		
		array_push($a["OverDmsFrontUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+5",5),2,1));		
		array_push($a["OverDmsBackLen"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,2));
		array_push($a["OverDmsBackWid"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,3));
		array_push($a["OverDmsBackHei"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,4));
		array_push($a["OverDmsBackUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+6",5),2,1));		
		array_push($a["OverDmsRightLen"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,2));
		array_push($a["OverDmsRightWid"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,3));
		array_push($a["OverDmsRightHei"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,4));
		array_push($a["OverDmsRightUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+7",5),2,1));		
		array_push($a["OverDmsLeftLen"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,2));
		array_push($a["OverDmsLeftWid"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,3));
		array_push($a["OverDmsLeftHei"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,4));
		array_push($a["OverDmsLeftUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+8",5),2,1));		
		array_push($a["OverDmsGenLen"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,2));
		array_push($a["OverDmsGenWid"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,3));
		array_push($a["OverDmsGenHei"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,4));
		array_push($a["OverDmsGenUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+9",5),2,1));		
		array_push($a["OverDmsExtLen"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,2));
		array_push($a["OverDmsExtWid"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,3));
		array_push($a["OverDmsExtHei"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,4));
		array_push($a["OverDmsExtUnit"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DIM+10",6),2,1));
		array_push($a["ModeTransp2"], fnc_resgata_modo_transp(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),3,0)));
		array_push($a["TranspMeans2"], fnc_resgata_transp_means(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),4,0)));
		array_push($a["CarrierCode2"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),8,1));
		array_push($a["Responsible"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "TDT+1",5),8,4));
		array_push($a["Damage"], fnc_determina_dano(fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DAM"),1,0)));
		array_push($a["DamageCode"], fnc_edi_recupera_compnte(fnc_obter_linha_segmento ($parte, "DAM"),5,0));
	  }	

	  $ini = strpos($p_arquivo,"UNH",$fim);
	  $fim = strpos($p_arquivo,"UNT",$ini);
  }  
  return $a;    
}  

The logic would be that must repeat by each "EQD" that is found on the EDI file. UNH and UNT is the start and end of every data block that has container information.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.