<?
	include 'putanja_abs.php';
	
	$g_path = $g_putanja_abs.'app/webroot/iso/my/';
	
	include $g_path."u_globals.php";
	include $g_path."html/f.php";
	//include '../../../views/reports/f.php';
	include $g_path."u_spoj_na_bazu.php";
	$can_live_alone = 1;
	include $g_path."u_headers.php";
	include $g_path."u_log.php";
	
	include $g_putanja_abs.'app/webroot/iso/_all_reports.php';
	
	
	$la_time = get_mailer_time_data();
	
	$l_tip_prog = get_item('select value from settings where name = "tipprog" ');
	
	$x = get_data('select id, name, redoslijed from reports where app_type = "'.$l_tip_prog.'" order by redoslijed ', 1);
	for($i = 0; $i < sizeof($x['id']); $i++){
		
		$l_sql = 'select mailer.id, mailer.creation_date, mailer.automatic, mailer.sent_to_owner, mailer.sent_to_accounting '.
			' from mailer '.
			' where mailer.report_id = '.$x['id'][$i].
			' and mailer_report_type_id = 2 '.
			' and mailer.creation_date = "'.$la_time['en']['last'].'" '.
			' and automatic = 1 '.
			' order by mailer.id desc limit 1 ';
			
		$y = get_data($l_sql, 0);
		
		if(empty($y['id'])){
			$l_rbr = 0;
		}else{
			$l_rbr = $y['id'];
		}
		create_accounting_report_and_send($l_rbr, $i, $x, $y, $la_time);
		
	}
	
?>