<?

if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
	
global $sugar_version, $sugar_config, $current_user, $app_strings, $mod_strings, $current_user, $app_list_strings;
	
require_once('modules/EcmPayments/EcmPayment.php');
require_once('modules/EcmPayments/Forms.php');
require_once ('include/time.php');
require_once('include/json_config.php');

$json_config = new json_config();
	
$focus = new EcmPayment();   

if(isset($_REQUEST['record']))$focus->retrieve($_REQUEST['record']);

require_once('include/MVC/View/SugarView.php');  

if(file_exists('modules/EcmPayments/views/view.detail.php')) {
	require_once('modules/EcmPayments/views/view.detail.php');
	$detail = new EcmPayment();
}
else{
	require_once('include/MVC/View/views/view.detail.php');
	$detail = new ViewDetail();  
	$detail->ss = new Sugar_Smarty();
	$detail->module = 'EcmPayments';
}

global $app_list_strings;

$detail->bean = $focus;

$w=$GLOBALS['db']->query("select ee_id,ecmpayment_id as pid from ecmpayments_ecminvoiceouts_rel where ecmpayment_id='".$focus->id."'");
echo "select ee_id,ecmpayment_id as pid from ecmpayments_ecminvoiceouts_rel where ecmpayment_id='".$focus->id."'";
$i=0;
echo mysql_error();
$inv='<table cellspacing="0" cellpadding="0" border="0" width="100%">';
while($r=$GLOBALS['db']->fetchByAssoc($w)){
	
	$rrr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select ecminvoiceout_id from ecmpayments_ecminvoiceouts where id='".$r['ee_id']."' and deleted='0'"));
	$rr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select document_no,total,id,register_date from ecminvoiceouts where id='".$rrr['ecminvoiceout_id']."' and deleted='0'"));
	//if($i%3==0)
	$inv.='<tr>';
	if($rr['document_no'])$inv.='<td><a href="index.php?module=EcmInvoiceOuts&action=DetailView&record='.$rr['id'].'">'.$rr['document_no'].'</a> - '.$GLOBALS['timedate']->to_display_date($rr['register_date']).' - '.number_format($rr['total'],2,",",".").'</td>';
	//if($i%3==2)
	$inv.='</tr>';
	$i++;
}
$inv.='</table>';

$detail->ss->assign("INVOICES",$inv);

$detail->preDisplay();        
	
echo $detail->display();
echo '<div id="subpanels_div">';

require_once('subpanels.php');

echo '</div>';
?>