<?php
ini_set('max_execution_time', 0);
ini_set('display_errors', 'On');

require_once 'vendor/autoload.php';

$db = new Source\Conn\DataLayer();

$result = $db->db()->from('xml')
	->where('xml_sefaz')->isNull()
	->limit(50)
	->select()
	->all();
	
if($result){
	foreach($result as $r){
		
		$chave = substr($r->xml_chave, 0, 2);
		$sefaz = set_sefaz(substr($chave,0,2));
		echo $sefaz.'<br />';
		
		$up['xml_sefaz'] = $sefaz;
		
		$db->db()->update('xml')->where('xml_id')->is($r->xml_id)->set($up);
	}
}	

?>