<?php
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
	die ( 'Not A Valid Entry Point' );
	
	// require_once('modules/EcmGroupSales/HeaderMenu.php');

global $sugar_version, $sugar_config, $current_user, $app_strings, $mod_strings;

require_once ('modules/EcmInsideOrders/EcmInsideOrder.php');
require_once ('include/time.php');
require_once ('include/json_config.php');

// add jquery
echo '<link rel="stylesheet" type="text/css" href="include/jQuery/jquery-table/jquery.appendGrid-1.3.1.css"/>';
echo '<link rel="stylesheet" type="text/css" href="include/jQuery/jquery-ui/themes/base/jquery-ui.css"/>';
echo '<script type="text/javascript"
src="include/jQuery/jquery-2.1.0.min.js"></script>';
echo '<script type="text/javascript"
src="include/jQuery/jquery-table/jquery.appendGrid-1.3.1.js"></script>';
echo '<script type="text/javascript"
src="include/jQuery/jquery-ui/ui/jquery-ui.js"></script>';

$json_config = new json_config ();

$focus = new EcmInsideOrder ();

if (isset ( $_REQUEST ['record'] )) {
	$focus->retrieve ( $_REQUEST ['record'] );
	$focus->format_all_fields ();
	$OPT ['status'] = $focus->status;
}

require_once ('include/MVC/View/SugarView.php');
require_once ('modules/EcmInsideOrders/views/DetailView/view.detail.my.php');
$edit = new ViewDetailMy ();
$edit->ss = new Sugar_Smarty ();
$edit->module = 'EcmInsideOrders';

$rdoc=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select * from ecminsideorders where id='".$_REQUEST['record']."'"));

$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select o.pw_id from ecminsideorders as o where o.id='".$focus->id."'"));
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select count(*) as c from ecmstockdocinsideins where id='".$r['pw_id']."'"));

$edit->ss->assign("CID",$r['c']);
$edit->ss->assign("EMPLOYERS",str_replace("|",", ",$rdoc['employers']));
// add pdf buttons
//$btn = '<input title="Generuj PDF" class="button" onclick="if($(\'#div_pdf\').css(\'display\') == \'none\'){$(\'#div_pdf\').show(\'slow\'); } else { $(\'#div_pdf\').hide(\'slow\'); }" type="button" name="productcard" id="productcard" value="Generuj PDF">';
//$btn .= '<div id="div_pdf" style="border: 1px solid #cccccc;background:#e6e6e6;padding:5px;position:absolute;display:none;">';
//$btn .= 'Typ: <select name="pdf_type" id="pdf_type"><option value="1">Dokument</option><option value="0">Operacje magazynowe</option></select><br /><br />';
$btn .= '<input name="quote_pdf" id="quote_pdf" title="Show PDF" accessKey="" class="button" onclick="window.open(\'index.php?module=EcmInsideOrders&action=createPDF&to_pdf=1&pdf_type=\'+$(\'#pdf_type\').val()+\'&record=' . $_REQUEST ['record'] . '\',\'_blank\');" type="button" value="Pokaż PDF"></div>';
$edit->ss->assign ( "CREATE_PDF", $btn );

$can_edit = false;
global $current_user;

//get operations
$db = $GLOBALS['db'];
$out = $db->fetchByAssoc($db->query("SELECT sum(price*quantity) as sum FROM ecmstockoperations WHERE type='1' AND parent_id='".$focus->id."'"));
$edit->ss->assign("OP_OUT", format_number($out['sum']));
$in = $db->fetchByAssoc($db->query("SELECT sum(price*quantity) as sum FROM ecmstockoperations WHERE type='0' AND parent_id='".$focus->id."'"));
$edit->ss->assign("OP_IN", format_number($in['sum']));
$edit->ss->assign ( "CREATED_BY_NAME", $focus->created_by_name );
$edit->ss->assign ( "MODIFIED_BY_NAME", $focus->modified_by_name );

$edit->bean = $focus;
$edit->tplFile = 'include/ECM/EcmViews/DetailView/Tabs/DetailView.tpl';

//var_dump($focus->getPositionList(true,$stockId));
$edit->preDisplay ();
echo $edit->display ();

require_once ('include/SubPanel/SubPanelTiles.php');
$subpanel = new SubPanelTiles ( $focus, 'EcmInsideOrders' );
echo $subpanel->display ();
// loading view
echo '<link rel="stylesheet" type="text/css" href="modules/EcmInsideOrders/javascript/helper.css" media="screen" /><div class="loading_panel"></div>';
?>