<?php  return 'function elements_modsnippet_43($scriptProperties= array()) {
global $modx;
if (is_array($scriptProperties)) {
extract($scriptProperties, EXTR_SKIP);
}
$trosk = $modx->getService(\'trosk\',\'Trosk\',$modx->getOption(\'doodles.core_path\',null,$modx->getOption(\'core_path\').\'components/trosk/\').\'model/trosk/\',$scriptProperties);
if (!($trosk instanceof Trosk)) return \'\';

$toXls=$_REQUEST[\'toxls\'];
if(empty($toXls)) return \'\';

$projectId=$_REQUEST[\'proj_id\'];
if(empty($projectId)) return \'wwww\';
$brojevi=$trosk->xlsRenderTrosk($projectId);

//return \'uf\';


require_once($modx->getOption(\'core_path\').\'components/phpexcel/Classes/PHPExcel.php\');
//include \'PHPExcel.php\';

/** PHPExcel_Writer_Excel2007 */
require_once($modx->getOption(\'core_path\').\'components/phpexcel/Classes/PHPExcel/Writer/Excel2007.php\');

// Create new PHPExcel object
//echo date(\'H:i:s\') . " Create new PHPExcel object\\n";
$objPHPExcel = new PHPExcel();

// Set properties
//echo date(\'H:i:s\') . " Set properties\\n";
$objPHPExcel->getProperties()->setCreator("troskovnik.hr");
$objPHPExcel->getProperties()->setLastModifiedBy("troskovnik.hr");
$objPHPExcel->getProperties()->setTitle("troskovnik.hr");
$objPHPExcel->getProperties()->setSubject("troskovnik.hr");
$objPHPExcel->getProperties()->setDescription("Generirao: troskovnik.hr");


// Add some data
//echo date(\'H:i:s\') . " Add some data\\n";
$objPHPExcel->setActiveSheetIndex(0);

$objPHPExcel->getActiveSheet()->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
$objPHPExcel->getActiveSheet()->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);

$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn(1)->setWidth(55);


$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0,1,\'kreirao: http://troskovnik.hr\');

$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);

$fill = array(\'type\' => PHPExcel_Style_Fill::FILL_SOLID, \'startcolor\' => array(\'rgb\' => \'B4F500\') );
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0,3,\'\');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1,3,\'Opis stavke\');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2,3,\'Jed.mj.\');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3,3,\'Količina\');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5,3,\'Ponuda 1\');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5,4,\'Jed.cijena\');
$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(5,4)->getFill()->applyFromArray($fill);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6,4,\'Ukupno\');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8,3,\'Ponuda 2\');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8,4,\'Jed.cijena\');
$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(8,4)->getFill()->applyFromArray($fill);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9,4,\'Ukupno\');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(11,3,\'Ponuda 3\');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(11,4,\'Jed.cijena\');
$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(11,4)->getFill()->applyFromArray($fill);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(12,4,\'Ukupno\');


$i=4;
foreach ($brojevi as $value) {
	$i++;
	$element=explode(\'|\',$value);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0,$i,$element[0]);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1,$i,$element[1]);
	$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(1,$i)->getAlignment()->setWrapText(true);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2,$i+1,$element[2]);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3,$i+1,$element[3]);
	if(!empty($element[3])){
//		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5,$i,\'jed.cijena:\');
                $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(5,$i+1)->getFill()->applyFromArray($fill);
//		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6,$i,\'ukupno:\');
		$k=$i+1;
		$formula=\'=ROUND(D\'.$k.\'*F\'.$k.\',2)\';
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6,$i+1,$formula);
                $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(6,$i+1)->getNumberFormat()->setFormatCode(\'#0.00#\');
//                $objPHPExcel->getActiveSheet()->protectCells(\'G5:G\'.$i+2, \'PHPExcel\');
                $objPHPExcel->getActiveSheet()->getStyle(\'A5:F\'.$i)->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);


//		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8,$i,\'jed.cijena:\');
                $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(8,$i+1)->getFill()->applyFromArray($fill);
//		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9,$i,\'ukupno:\');
		$formula=\'=ROUND(D\'.$k.\'*I\'.$k.\',2)\';
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9,$i+1,$formula);
                $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(9,$i+1)->getNumberFormat()->setFormatCode(\'#0.00#\');
//                $objPHPExcel->getActiveSheet()->protectCells(\'J5:J\'.$i+2, \'PHPExcel\');
                $objPHPExcel->getActiveSheet()->getStyle(\'H5:I\'.$i)->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);



//		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(11,$i,\'jed.cijena:\');
                $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(11,$i+1)->getFill()->applyFromArray($fill);
//		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(12,$i,\'ukupno:\');
		$formula=\'=ROUND(D\'.$k.\'*L\'.$k.\',2)\';
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(12,$i+1,$formula);
                $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(12,$i+1)->getNumberFormat()->setFormatCode(\'#0.00#\');
//                $objPHPExcel->getActiveSheet()->protectCells(\'M5:M\'.$i+2, \'PHPExcel\');
                $objPHPExcel->getActiveSheet()->getStyle(\'K5:L\'.$i)->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);

		
		$i++;
	}
}

$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5,$i+2,\'UKUPNO:\');
$formula=\'=ROUND(SUM(G1:G\'.$i.\'),2)\';
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6,$i+2,$formula);
$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(6,$i+2)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(6,$i+2)->getNumberFormat()->setFormatCode(\'#0.00#\');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7,$i+2,\'kn\');

$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8,$i+2,\'UKUPNO:\');
$formula=\'=ROUND(SUM(J1:J\'.$i.\'),2)\';
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9,$i+2,$formula);
$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(9,$i+2)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(9,$i+2)->getNumberFormat()->setFormatCode(\'#0.00#\');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10,$i+2,\'kn\');

$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(11,$i+2,\'UKUPNO:\');
$formula=\'=ROUND(SUM(M1:M\'.$i.\'),2)\';
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(12,$i+2,$formula);
$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(12,$i+2)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(12,$i+2)->getNumberFormat()->setFormatCode(\'#0.00#\');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(13,$i+2,\'kn\');

$objPHPExcel->getActiveSheet()->getStyle(\'D5:M\'.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

// Rename sheet
//echo date(\'H:i:s\') . " Rename sheet\\n";
$objPHPExcel->getActiveSheet()->setTitle(\'troskovnik.hr\');

$objPHPExcel->getActiveSheet()->freezePane(\'A5\');

// Save Excel 2007 file
//echo date(\'H:i:s\') . " Write to Excel2007 format\\n";
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);

header(\'Content-Description: File Transfer\');
if (headers_sent()) {
	return \'error\';
}
header(\'Cache-Control: public, must-revalidate, max-age=0\'); // HTTP/1.1
header(\'Pragma: public\');
header(\'Expires: Sat, 26 Jul 1997 05:00:00 GMT\'); // Date in the past
header(\'Last-Modified: \'.gmdate(\'D, d M Y H:i:s\').\' GMT\');
// force download dialog
if (strpos(php_sapi_name(), \'cgi\') === false) {
	header(\'Content-Type: application/force-download\');
	header(\'Content-Type: application/octet-stream\', false);
	header(\'Content-Type: application/download\', false);
	//header(\'Content-Type: application/vnd.ms-excel\', false);
} else {
	header(\'Content-Type: application/vnd.ms-excel\');
}
// use the Content-Disposition header to supply a recommended filename
header(\'Content-Disposition: attachment; filename="troskovnik.hr.xlsx";\');
header(\'Content-Transfer-Encoding: binary\');

$objWriter->save(\'php://output\');
exit;
// Echo done
//echo date(\'H:i:s\') . " Done writing file.\\r\\n";
}
';