HEX
Server: Apache/2.2.15 (CentOS)
System: Linux ip-10-0-2-146.eu-west-1.compute.internal 2.6.32-754.35.1.el6.centos.plus.x86_64 #1 SMP Sat Nov 7 11:33:42 UTC 2020 x86_64
User: root (0)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: /www/exchange0old/exchange/classes/Display/DInvestorUser.php
<?php
include_once('admin/classes/Display/DBase.php');
class Display_DInvestorUser extends DBase
{
	
	function getSorting($sort,$inc,$type){

		$query=new Bin_Query();
		$sql = "SELECT * FROM search_terms where search_type = '".$type."' && published = 1 ORDER BY ordering ASC";
		$query->executeQuery($sql);
		$sort_values = $query->records;

		for($j=$sort;$j<=$inc;$j++){
			
			if($name =='sorts'){
					$ordrid = 'ordrs';
			}else{
					$ordrid = 'ordr';
			}
		
			$sort = array();
			$output .= Display_DInvestorUser::getSortOrder($_REQUEST["ordr$j"], $j);

			$output .='<td align="left" style="padding:0 2px;" id="select'.$j.'"><select name="sort'.$j.'" class="cmb_bx1" id="sorti'.$j.'"  style="width:190px;margin:0;" onchange="advsearch(this.value);">';
	
			$i=0;$flag =0; // 7 11 17 23
			
			$sort[$j] = $_REQUEST["sort$j"];

			foreach($sort_values as $key){
				
				
				if ($i==1 || $key['search_id'] == '7' || $key['search_id'] == '11' || $key['search_id'] == '17' || $key['search_id'] == '23'){
					if($flag == '0'){
						
						$output .='<option value="'.$key['search_id'].'" ';
							if($sort[$j] == $key['search_id']) $output .=' selected ="selected"';
							$output .=' style="font-size:11px; line-height:20px;">'.$key['search_title'].'</option>';
						$flag =1;
					}else{
				
						$output .='</optgroup><optgroup label="'.$key['search_title'].'">';
					
					}
				}else if($key['search_title'] != ''){

					if($i == 0){
				
						if($j == '1'){
						}else{
							
							$output .='<option value="" ';
							if($sort[$j] == '') $output .=' selected ="selected"';
							$output .=' style="font-size:11px; line-height:20px;">Please choose</option>';	
						}
						
						$output .='<option style="font-size:11px; line-height:20px;" value="0"';
						
						if($sort[$j] == '0') $output .=' selected ="selected"';
						$output .='>Selected Check Boxes</option>';
						
						$output .='<optgroup label="--------------------------">';
						
						$output .='<option value="'.$key['search_id'].'" ';
						if($sort[$j] == $key['search_id']) $output .=' selected ="selected"';
						$output .=' style="font-size:11px; line-height:20px;">'.$key['search_title'].'</option>';
					}else{
						//if($key == '--------------------------'){
							$output .='<option value="'.$key['search_id'].'" ';
							if($sort[$j] == $key['search_id']) $output .=' selected ="selected"';
							$output .=' style="font-size:11px; line-height:20px;">'.$key['search_title'].'</option>';
						//}
						
						/*if($key['search_id'] == '9' || $key['search_id'] == '36'){
							$output .='<option value="61"';
							if($sort[$j] == '61') $output .=' selected ="selected"';
							$output .=' style="font-size:11px; line-height:20px;">Revolving Sale</option>';	
						}*/
					}

				}
				$i++;			
			}
			
			/*$output .='<option value="60"';
							if($sort[$j] == '60') $output .=' selected ="selected"';
							$output .=' style="font-size:11px; line-height:20px;"> Add More</option>';
*/
			$output .='</optgroup></select></td>';
			
		}
		return $output;
	}

	function getSortOrder($sort, $j){

		
		$output .='<td style="padding:0 2px;" align="right" id="check'.$j.'"><input type="checkbox" name="ordr'.$j.'" id="ordri'.$j.'" value="1"';
		if($sort == "1"){
				$output .=' checked="true" ';
		}

		$output .=' style="margin: 5px 0 0 0;"></td><td style="padding:0 2px;" align="right" id="img'.$j.'">';
		
		if($sort == "1"){
			$output .='<img src="../images/arrow_asc.png" height="16" style="margin: 5px 0 2px 0;">';
		}else{
			$output .='<img src="../images/arrow_desc.png" height="16" style="margin: 5px 0 2px 0;">';
		}

		return $output.'</td>';


	}
	
	function getAdvSorting($sort,$inc,$type){

		$query=new Bin_Query();
		$sql = "SELECT * FROM search_terms where search_type = '".$type."' && published = 1";
		$query->executeQuery($sql);
		$sort_values = $query->records;
		
		for($j=$sort;$j<=$inc;$j++){
			
			$sort = array();
			$output .= Display_DInvestorUser::getAdvSortOrder($_REQUEST["ordr$j"], $j,$ordrid);

			$output .='<td align="left" style="padding:0 2px;" id="select'.$j.'"><select name="sort'.$j.'" class="cmb_bx1" id="sorts'.$j.'"  style="width:190px;margin:0;" onchange="advsearch(this.value);">';
	
			$i=0;$flag =0; // 7 11 17 23

			$sort[$j] = $_REQUEST["sort$j"];
			foreach($sort_values as $key){

				if ($i==1 || $key['search_id'] == '7' || $key['search_id'] == '11' || $key['search_id'] == '17' || $key['search_id'] == '23'){
					if($flag == '0'){
						
						$output .='<option value="'.$key['search_id'].'" ';
							if($sort[$j] == $key['search_id']) $output .=' selected ="selected"';
							$output .=' style="font-size:11px; line-height:20px;">'.$key['search_title'].'</option>';
						$flag =1;
					}else{
				
						$output .='</optgroup><optgroup label="'.$key['search_title'].'">';
					
					}
				}else if($key['search_title'] != ''){

					if($i == 0){
						$output .='<option value="" ';
						if($sort[$j] == '') $output .=' selected ="selected"';
						$output .=' style="font-size:11px; line-height:20px;">Please choose</option>';
						
						/*$output .='<option value="60"';
							if($sort[$j] == '60') $output .=' selected ="selected"';
							$output .=' style="font-size:11px; line-height:20px;">Advanced Sort</option>';*/
						
						$output .='<option style="font-size:11px; line-height:20px;" value="0"';
						
						if($sort[$j] == '0') $output .=' selected ="selected"';
						$output .='>Selected Check Boxes</option>';
						
						$output .='<optgroup label="--------------------------">';
						
						$output .='<option value="'.$key['search_id'].'" ';
						if($sort[$j] == $key['search_id']) $output .=' selected ="selected"';
						$output .=' style="font-size:11px; line-height:20px;">'.$key['search_title'].'</option>';
					}else{
						//if($key == '--------------------------'){
							$output .='<option value="'.$key['search_id'].'" ';
							if($sort[$j] == $key['search_id']) $output .=' selected ="selected"';
							$output .=' style="font-size:11px; line-height:20px;">'.$key['search_title'].'</option>';
						//}
						
						if($key['search_id'] == '9' || $key['search_id'] == '36'){
							$output .='<option value="61"';
							if($sort[$j] == '61') $output .=' selected ="selected"';
							$output .=' style="font-size:11px; line-height:20px;">Revolving Sale</option>';	
						}
					}

				}
				$i++;			
			}
			
			

			$output .='</optgroup></select></td>';
			
		}

		return $output;

	}

	function getAdvSortOrder($sort, $j){

		$output .='<td style="padding:0 2px;" align="right" id="check'.$j.'"><input type="checkbox" name="ordr'.$j.'" id="ordrs'.$j.'" value="1"';
		if($sort == "1"){
				$output .=' checked="true" ';
		}

		$output .=' style="margin: 5px 0 0 0;"></td><td style="padding:0 2px;" align="right" id="img'.$j.'">';
		
		if($sort == "1"){
			$output .='<img src="../images/arrow_asc.png" height="16" style="margin: 5px 0 2px 0;">';
		}else{
			$output .='<img src="../images/arrow_desc.png" height="16" style="margin: 5px 0 2px 0;">';
		}

		return $output.'</td>';
	}
	
	function getActiveInvestorFloor($trade,$trade_count,$flag){
		
		
		$holidayFlag1		= Model_MInvestorUser::investorFloorDisable(1);
		$holidayFlag2		= Model_MInvestorUser::investorFloorHoliday(1);
		$holidayFlag3		= Model_MInvestorUser::investorFloorWeekends(1);
		$holidayFlag4		= Model_MInvestorUser::investorFloorTime(1);
		
		if($flag == '1')
			$i= 1;
		else
		 $i=$trade_count+1;
if(count($trade) > 0){
            $output = ' 
                <tr class="grays_bg1" style="padding:0; margin:0;">
                      <td valign="top" align="left" colspan="13" style="padding:0; margin:0;background:none;">
						<ul style="height: 35px; background:#C0C0C0;">
						<li style="width: 82px; padding: 0px 7px;"><b>Debtor</b></li>
						<li style="width: 50px; padding: 0px 7px;"><b>Nc/Nd</b></li>
						<li style="border-right: 4px solid #FFF; padding: 0px 10px; width: 66px;"><b>R/C</b>\'000</li>
						<li style=" padding: 0 29px 0 5px; width: 79px;"><b>Tdr/Bkr</b></li>
						
						<li style=" padding: 0 1px; width: 68px;"><b>R/C</b>\'000</li>
						<li style=" width: 50px; padding: 0px 1px;"><b>Tm S&T</b></li>
						<li style="padding: 0 7px 0 12px; text-align: left;width: 54px;"><b>Value</b></li>
						<li style=" padding: 0 10px; width: 36px;"><b>Date</b></li>
						
						<li style="border-left: 4px solid #FFFFFF;padding: 0 4px;text-align: center;width: 55px;"><b>Offer</b></li>
						<li style="width: 67px; padding: 0px 10px; border-left: 4px solid #FFF;"><b>Offer/Bid</b></li>
						<li style="padding: 0pt 3px; width: 31px;"><b>Dis%</b></li>
						<li style="width: 45px; border-left: 4px solid #FFF; padding: 0px 5px 0 6px; text-align: center;"><b>D/T</b></li>
						<li style="width: 100px; padding: 0px; ">';
					  if($flag == '1'){
							  if($_SESSION['user']['usertype'] == 1 || $_SESSION['user']['usertype'] == 2){
							  $output .= '
							  <input type="text" class="buy_tr" value="Buy" name="" style="float:left; margin-top:10px;" onclick=\'return openBuyWindow();\' readonly="readonly" >
							  
							  <span style="font-size:9px !important; float:right; margin:3px 0 0 0;">Select all</span><input type="checkbox" name="select_all" id="select_all" value="all" style="float:right;margin:13px 2px 0 0; width:15px;" onclick="all_set();">';
							  }
					  }
			  $output .= '</li></td>
		</tr>
				';
}
		if(count($trade) == 0){
			//$output .='<tr class="row2"><td align="center"><b> No Active Invoice Found</b></td></tr>'; 
		}
		
		foreach($trade as $tradefloor){

			 

			$trader_id = str_replace("-","",$tradefloor['doj'])."000";

			$trader_id = $trader_id + $tradefloor['ref_id'];

			if($i%2 == 0){
				$bg_class = "row2";
			}else{
				$bg_class = "row1";	
			}
			
			if($tradefloor['sales_type'] !="0"){
					

				$bid_query=new Bin_Query();
				$bid_sql = "SELECT * FROM invoice_bidding_history where invoice_id = '".$tradefloor['invoice_id']."'";
				$bid_query->executeQuery($bid_sql);
				$history = $bid_query->records;

				if(count($history) ==0){
					$style="color:#000000;"; //black
				}else{

					$bid_query1=new Bin_Query();
					$bid_sql1 = "SELECT * FROM invoice_bidding_history where invoice_id = '".$tradefloor['invoice_id']."' && user_id ='".$_SESSION['user']['userid']."'";
					$bid_query1->executeQuery($bid_sql1);
					$history1 = $bid_query1->records;
					
					if(count($history1) ==0){
						$style="color:#3F48CC;"; // blue
					}else{
						$bid_query=new Bin_Query();
						
						if($tradefloor['sales_type'] =="1"){
						
						$bid_sql = "SELECT * FROM invoice_bidding where invoice_id = '".$tradefloor['invoice_id']."' order by min_advance DESC limit 1";
						}else{
							$bid_sql = "SELECT * FROM invoice_bidding where invoice_id = '".$tradefloor['invoice_id']."' order by max_thirty_reserve ASC limit 1";
						}
							
						$bid_query->executeQuery($bid_sql);
						$history = $bid_query->records[0];

						if($_SESSION['user']['userid'] != $history['user_id']){
							$style="color:#ED1C24;"; //red
						}else{
							$style="color:#22B14C;"; //green
						}
					}
				}
				
				
				
				
				if($tradefloor['sales_type'] =="1"){
					
					$bid_query=new Bin_Query();
					$bid_sql = "SELECT min_advance , max_thirty_reserve, user_id  FROM invoice_bidding where invoice_id = '".$tradefloor['invoice_id']."' order by min_advance DESC limit 1";
					$bid_query->executeQuery($bid_sql);
					$history = $bid_query->records[0];
		
					if(count($history) ==0){
						$history['min_advance']		= $tradefloor['min_advance'];
						$history['max_thirty_reserve']	= $tradefloor['max_thirty_day_reserve'];
						
					}
					
					$_SESSION['invBook'][$tradefloor['invoice_id']] = $history['min_advance'];
					
					$_SESSION['invBookUserID'][$tradefloor['invoice_id']] = $history['user_id'];
					
					$history['max_thirty_reserve'] ='&nbsp;';

					
					
					/*$annualYield = ((($tradefloor['face_value'] - 7 - 50)/$history['min_advance'])-1) * 
									(360 / ( $tradefloor['exp_days']   - ($tradefloor['days']  + 3)));
				
					$yield = number_format(abs($annualYield),3,'.','');
					
					if($tradefloor['buy_out'] == 1) {
						
						$buy_annualYield = ((($tradefloor['face_value'] - 7 - 50)/$history['buy_min_advance'])-1) * 
											(360 / ( $tradefloor['exp_days']   - ($tradefloor['days']  + 3)));
						
						$buy_yield = number_format(abs($buy_annualYield),3,'.','');
					}*/
					
					
					if($history['min_advance'] >= 1000000 ){
				
						$history['min_advance'] = $history['min_advance'] / 1000000;
						
						$history['min_advance'] = $tradefloor['currency_code'].number_format($history['min_advance'], 1, '.', ',')."M";
					}else{
						$history['min_advance'] = $tradefloor['currency_code'].number_format(round($history['min_advance']));
					}
					
					
					$min_advance = $tradefloor['min_advance'];
					if($tradefloor['min_advance'] >= 1000000 ){
				
						$tradefloor['min_advance'] = $tradefloor['min_advance'] / 1000000;
						
						$tradefloor['min_advance'] = $tradefloor['currency_code'].number_format($tradefloor['min_advance'], 1, '.', ',')."M";
					}else{
						$tradefloor['min_advance'] = $tradefloor['currency_code'].number_format($tradefloor['min_advance']);
					}
					
					
					
				}else{
					
					
					$bid_query=new Bin_Query();
					$bid_sql = "SELECT min_advance , max_thirty_reserve, user_id  FROM invoice_bidding where invoice_id = '".$tradefloor['invoice_id']."' order by max_thirty_reserve ASC limit 1";
					$bid_query->executeQuery($bid_sql);
					$history = $bid_query->records[0];
		
					if(count($history) ==0){
						$history['min_advance']		= $tradefloor['min_advance'];
						$history['max_thirty_reserve']	= $tradefloor['max_thirty_day_reserve'];
						
					}
					
					$_SESSION['invBook'][$tradefloor['max_thirty_reserve']] = $history['max_thirty_reserve'];
					$_SESSION['invBookUserID'][$tradefloor['invoice_id']] = $history['user_id'];
					
					if($tradefloor['sales_type'] =="2"){
						$tradeValues 							= $tradefloor;
						$tradeValues['min_advance'] 			= $history['min_advance'];
						$tradeValues['max_thirty_day_reserve'] 	= $history['max_thirty_reserve'];
						$tradeValues['yield'] 					= $tradefloor['bid_yield'];
						$returnCalc 							= Model_MHelpers::manageYieldValue($tradeValues);
						
					}elseif($tradefloor['sales_type'] =="3"){
						$tradeValues 							= $tradefloor;
						$tradeValues['min_advance'] 			= $history['min_advance'];
						$tradeValues['max_thirty_day_reserve'] 	= $history['max_thirty_reserve'];
						$tradeValues['yield'] 					= $tradefloor['bid_yield'];
						$returnCalc 							= Model_MHelpers::performYieldValue($tradeValues);	
					}else if($tradefloor['sales_type'] =="5"){
				
						$tradeValues 							= $tradefloor;
						$tradeValues['min_advance'] 			= $history['min_advance'];
						$tradeValues['max_thirty_day_reserve'] 	= $history['max_thirty_reserve'];
						$returnCalc 							= Model_MHelpers::performInstallYieldValue($tradeValues);
						
					}
					
					$yieldValue			= $returnCalc['yieldValue'];
					$tPurchasePrice		= $returnCalc['tPurchasePrice'];
					$valReturn			= $returnCalc['valReturn'];
				
					$history['min_advance'] ='&nbsp;';
					
					
					$actual_date 		= $tradefloor['actual_date'];
					$non_days_sql 		= "SELECT  DATEDIFF(expected_date , DATE(trading_close_date)) AS days ,".
										" DATEDIFF('$actual_date' , trading_close_date) AS days1 FROM invoice_master ".
										" WHERE invoice_id = '".$tradefloor['invoice_id']."' "; 
					$non_query			=new Bin_Query();
					$non_query->executeQuery($non_days_sql);
					$non_days 			= $non_query->records;
					$non_diff_days 		= $non_days[0]['days'] - $non_days[0]['days1'];
					
					
					//=(((C6-D18)/(C6/(1+((D19/360)*(C7*12)))))-1)*360/(C5-C3-(C4-C3)+1)
					
					$non_face_value = $tradefloor['face_value'];
					$fee 			= 10;
					$bankfee 		= 7;
					$rebate_refund	= Base_actions::getSiteSettings('rebate_refund');
					
					$non_yield		= ((($non_face_value-$bankfee)/($non_face_value/(1+(($rebate_refund/360)*(($tradefloor['max_thirty_day_reserve']/100)*12)))))-1)*360/($non_diff_days+1);
					
					$non_yield = number_format($non_yield*100, 3, '.', '')."%";
					
					
					$buy_non_yield	= ((($non_face_value-$bankfee)/($non_face_value/(1+(($rebate_refund/360)*(($tradefloor['buy_max_thirty_day_reserve']/100)*12)))))-1)*360/($non_diff_days+1);
					
					$buy_non_yield = number_format($buy_non_yield*100, 3, '.', '')."%";
					
					
								
					$history['max_thirty_reserve'] = number_format(($history['max_thirty_reserve']), 3, '.', '');
					
					
					$tradefloor['max_thirty_day_reserve'] = number_format(($tradefloor['max_thirty_day_reserve']), 3, '.', '')."%";
					$tradefloor['buy_max_thirty_day_reserve'] = number_format(($tradefloor['buy_max_thirty_day_reserve']), 3, '.', '')."%";
				}
						
			}//else{}
	
			$face_value = $tradefloor['currency_code'].number_format($tradefloor['face_value'], 2, '.', ',');
			$face_value1 = $tradefloor['face_value'];
			
			if($face_value1 >= 1000000 ){
				
				$face_value1 = $face_value1 / 1000000;
				
				$face_value1 = $tradefloor['currency_code'].number_format($face_value1, 1, '.', ',')."M";
			}else{
				$face_value1 = $tradefloor['currency_code'].number_format(round($tradefloor['face_value']));
			}
			

			
			$debtor_limit 	= Model_MCreditRiskSetting::getDebtorRiskLimit($tradefloor);
			$tradefloor['debtor_risk'] 	= Model_MCreditRiskSetting::getDebtorRiskScore($tradefloor);
			$tradefloor['risks']		= Model_MCreditRiskSetting::getOrgRiskScore($tradefloor);
			
			$tooltip 		= $tradefloor['debtor_name'].", Average Risk: ".$tradefloor['debtor_risk']." & Credit Limit: ".$debtor_limit;
			$limits 		= Model_MCreditRiskSetting::getOrgRiskLimit($tradefloor);
			$risk 			= Model_MCreditRiskSetting::getDebtorRisk($tradefloor);
			$risk 			= Display_DCreditRiskSetting::showRisk($risk, $tradefloor,0);
			$risk_org		= Model_MCreditRiskSetting::getOrgRisk($tradefloor);
			$risk_org		= Display_DCreditRiskSetting::showRisk($risk_org, $tradefloor,1);

			$tradefloor['yield'] 		= $tradefloor['yield'] * 100;
			$tradefloor['buy_yield'] 	= $tradefloor['buy_yield'] * 100;
			$tradefloor['bid_yield'] 	= $tradefloor['bid_yield'] * 100;
			
			$output .='<tr><td align="left" valign="top" colspan="14">';
			if($i ==1){
				$output .='<div id="trade_'.$i.'" ondblclick="addin('.$i.');" style="position:relative;">';
				$display = "none";
			}else{
				$output .='<div id="trade_'.$i.'"  class="clsTradeBook" ondblclick="addin('.$i.');" style="position:relative;">';
				$display = "none";
			}
			
		 
		
		
			if(trim($tradefloor['debtor_risk']) == ''){
				$tradefloor['debtor_risk'] ='&nbsp;';
			}
			
			if(trim($tradefloor['risks']) == ''){
				$tradefloor['risks'] ='&nbsp;';
			}
			
			if(trim($debtor_limit) == '0' || trim($debtor_limit) == ''){
				$debtor_limit ='&nbsp;';
			}
			if(trim($limits) == '0' || trim($limits) == ''){
				$limits ='&nbsp;';
			}
 
     
      
      
      $output .='<span style="float: left; position: absolute; height: 27px; z-index: 100; left: -3px; width: 970px; display:none;" id="blink_'.$tradefloor['invoice_id'].'"></span>
      <div class="cat_middle '.$bg_class.'"> <span ondblclick="" class="categrey_u">
	  
        <ul style="display:block; height:30px;" class="td_floor">
          <li style="float: left; width: 97px; margin:0px;" class="tool-tip">&nbsp;<a href="javascript:void(0);" title="'.$tooltip.'"><img alt="" src="../images/i_bttn.png"></a>&nbsp;<span ><b class="black">'.substr($tradefloor['debtor_name'],0,7).'...</b></span></li>
          <li style="float: left; width: 30px; margin:0 0 0 5px;">'.$tradefloor['d_nace_group_id'].' </li>
          <li style="float: left; width: 27px;  text-align:right; margin:0 10px 0 0 ">'.$tradefloor['d_nace_id'].'</li>
          <li style="float: left; width: 25px; margin:0; ">'.$tradefloor['debtor_risk'].'</li>
          <li style="float: left; width: 42px; margin:0 5px 0 5px; text-align:right;">'.$debtor_limit.'</li>
          <li style="float: left; padding: 0 10px 0 6px; width: 80px; border-left:4px solid #FFF; text-align:left;">'.$tradefloor['organisation_reference_id'].'</li>
          <li style="float: left; margin:0 5px 0 5px; width: 23px;"> '.$tradefloor['risks'].'</li>
          <li style="float: left; width: 45px; margin:0px; text-align:right;">'.$limits.'</li>
          <li style="float: left;margin: 0 0 0 9px;width: 21px; text-align:right;">'.$tradefloor['payment_terms'].'</li><li style="float: left;   margin: 0 2px 0 5px;width: 10px;">S</li><li style="float: left;margin: 0 0 0 5px;width: 10px;"><b>';
            
             
			
			if($tradefloor['revolving'] =="1" || $tradefloor['root_invoice_id'] !=0){
				$output .='R';
			}else if($tradefloor['sales_type'] =="1"){
				$output .='O';
			}else if($tradefloor['sales_type'] =="2"){
				$output .='M';
			}else if($tradefloor['sales_type'] =="5"){
				$output .='I';
			}else{
				$output .='P';
			}
            
            $output .='</b></li>
          <li style="float: left; width: 65px; margin:0 2px 0 0; text-align:right;"><span class="black"><b>'.$face_value1.'</b></span></li>
          <li style="float: left; width: 50px; margin: 0 5px; text-align:center;">';
            
            $expected_date = explode("-",$tradefloor['expected_date']);
            
            
            $output .=$tradefloor['expected_date'];

            
            $output .='</li>';
          
          
          if($tradefloor['sales_type'] !=1)
          $align="text-align:right;";
          else
          $align ="text-align:left;";
          
		  
		  
                                
									
          if($tradefloor['sales_type'] =='1'){
		  
          $output .='
          <li style="float: left; border-left: 4px solid #FFFFFF; margin: 0 5px 0 1px;text-align: right;width: 58px;">'.$tradefloor['min_advance'].'</li>
          <li style="border-left: 4px solid #FFFFFF;  float: left;padding: 0 2px 0 2px; width: 70px; text-align:right;"><span  class="black" id="min_'.$tradefloor['invoice_id'].'" style=""><b style="'.$style.'" id="cnt_min_'.$tradefloor['invoice_id'].'">'.$history['min_advance'].'</b></span></li>
          <li style="width:50px; position:relative;float: left;border-right: 4px solid #FFFFFF;"> <span class="black" id="max_'.$tradefloor['invoice_id'].'"><b style="'.$style.'" id="cnt_min_'.$tradefloor['invoice_id'].'">'.$history['max_thirty_reserve'].'</b></span></li>
          ';
          
          }else{
			  
			  if($tradefloor['sales_type'] =='3'){
				$return = $tradefloor['face_value'] -7 - 50 ;
                $val_return = $tradefloor['currency_code'].number_format($return);
			  }else{
				  $val_return ='&nbsp;';
			  }
				
           
		  $output .='
          <li style="float: left; border-left: 4px solid #FFFFFF; margin: 0 5px 0 1px;text-align: right;width: 58px;">'.$tradefloor['max_thirty_day_reserve'].'</li>
          <li style="border-left: 4px solid #FFFFFF;  float: left;padding: 0 2px 0 2px; width: 70px; text-align:right;"><span  class="black" id="min_'.$tradefloor['invoice_id'].'" style=""><b style="'.$style.'" id="cnt_min_'.$tradefloor['invoice_id'].'">'.$val_return.'</b></span></li>
          <li style="width:50px; position:relative;float: left;border-right: 4px solid #FFFFFF;text-align:right;"> <span class="black" id="max_'.$tradefloor['invoice_id'].'"><b style="'.$style.'" id="cnt_min_'.$tradefloor['invoice_id'].'">'.$history['max_thirty_reserve'].'</b></span></li>
          ';
          
          }
          
		  $hidden_style = str_replace("color:#",'',$style);
		  $hidden_style = str_replace(";",'',$hidden_style);
		  
          $output .='
          <li style="float: left; margin: 0 1px 0 3px; text-align:right;
    width:51px;"> <span style="display:none;" id="style_'.$tradefloor['invoice_id'].'">'.$hidden_style.'</span>';
            
            $exp = explode(" ",$tradefloor['trading_close_date']);
            $date = explode("-",$exp[0]);
            $time = explode(":",$exp[1]);
            
            $inv = $tradefloor;
            
            
            
            
            
            $output .='<span id="defaultCountdown_'.$inv['invoice_id'].'">'.$tradefloor['days'].'D:'.$tradefloor['hours'].'H</span> </li>
          <li style="float:left; width:100px; margin:0 0 0 2px;">';
            
            
            if($tradefloor['sales_type'] =='3'){
				$height =434;
			}else{
				$height =405;
			}
            
            $holiday 					= Model_MTradeFloor::holidayCalc($tradefloor['invoice_id'],2);

			if($holiday == '0' && $holidayFlag1 == 2 && $holidayFlag2 == 2 && $holidayFlag3 == 2 && $holidayFlag4 == 2) {
				
				$output .='<input type="text" class="trade_tr" value="Bid" name="" onclick=\'openWin("'.$tradefloor['invoice_id'].'",'.$height.',0);\' style="float:right; margin:5px 3px 5px 8px; width:25px;" readonly="readonly" >';
				
				if($tradefloor['buy_out'] == 1) {
				
					$output .='<input type="text" class="buy_tr" value="Buy" name="" onclick=\'return openWin("'.$tradefloor['invoice_id'].'",'.$height.',1);\' style="float:left; margin-top:5px;" readonly="readonly" >';
					
					$output .='<input style="float:right;margin:8px 7px 0 0; width:15px;" type="checkbox" name="inv_all[]" value="'.$tradefloor['invoice_id'].'"';
					
				}else{	
				
					$output .='<input style="float:right;margin:8px 7px 0 0; width:15px;" type="checkbox" name="inv_all[]" value="'.$tradefloor['invoice_id'].'"';

				}
				
				$output .= '>';
			
			}
							

							
            
            
            
            $output .='</li>
        </ul>
        <script>
						
							
		
						</script>
        </span> </div>
      <div class="categ">
                    <ul id="search_id_'.$i.'" style="display: '.$display.';" class="trd_detail">
          <li style="padding-bottom:10px;">
								   <table cellspacing="0" cellpadding="0" border="0" width="100%">
							  		<tbody>
                            <tr>
                  <td align="left" width="26%" valign="top" style="line-height: 20px; padding-left: 15px;"><b class="black"> Debtor Details</b><br>
                                Name  : '.self::substr($tradefloor['debtor_name'],22).'<br>
                                <table width="100%" cellspacing="0" cellpadding="0" border="0">
							    	<tbody>
										<tr>
											<td>NACEC :</td>
											<td align="right"><span style="float:right;margin: 0 23px 0 0; display:block;">'.$tradefloor['d_nace_group_id'].'</span></td>
										</tr>
										<tr>
											<td>NACED:</td>
											<td align="right"><span style="float:right;margin: 0 23px 0 0; display:block;">'.$tradefloor['d_nace_id'].'</span></td>
										</tr>
									</tbody>
								</table>
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">'.$risk.'</table>';
								$output .='	</td>
                  <td align="left" width="24%" valign="top" style="line-height: 20px;"><b class="black">Trader Details</b><br>
								<table width="100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr>
									<td>Reference Code  :</td>
									<td align="right"><span style="float:right;margin: 0 23px 0 0; display:block;">'.$tradefloor['organisation_reference_id'].'</span></td>
								</tr>
								</table>
                                NACEC : '.$tradefloor['t_nace_group_id'].'<br>
                                NACED : '.$tradefloor['t_nace_id'].' <br>
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">'.$risk_org.'</table>';
								$output .='	</td>
                  <td rowspan="3" align="left" width="29%" valign="top" style="line-height: 18px;">
				  
				  				<b class="black">Trade Details</b><br>
				  				Trade ID: <a href="javascript:void(0);" style="color:#0033FF; font-size:11px; text-decoration:underline;" onclick=\'return openWin("'.$tradefloor['invoice_id'].'",'.$height.',1);\'>'.$tradefloor['trade_reference_id'].'</a> <br>
								Sales Type: <b class="black">'.$tradefloor['type_name'].'</b> <br>
								<table width="100%" border="0" cellspacing="0" cellpadding="1">
								  <tr>
									<td width="51%">Face Value :</td>
									<td align="right" width="30%"> '.$face_value.'</td>
									<td width="19%">&nbsp;</td>
								  </tr>';
				  				

                                
                                
                                
            if($tradefloor['sales_type'] =="2"){
									
				$return 	= $tradefloor['face_value'] -7;
				$val_return = number_format($return, 2, '.', ',');
		

				$yield 		= number_format($tradefloor['yield'],'3','.',',');
				
				$output 	.=' <tr>
									<td>Purchase Price : </td>
									<td align="right" id="trade_purchase_'.$tradefloor['invoice_id'].'">'.$tPurchasePrice.'</td>
									<td>&nbsp;</td>
								</tr>';
							
				$output 	.=' <tr>
									<td>Percentage Offered : </td>
									<td align="right" id="trade_offer_'.$tradefloor['invoice_id'].'">'
									.$tradefloor['max_thirty_day_reserve'].'</td>
									<td>&nbsp;</td>
								</tr>';
				$output 	.=' <tr>
									<td>Value Returned : </td>
									<td align="right" id="trade_return_'.$tradefloor['invoice_id'].'">'.$valReturn.'</td>
									<td>&nbsp;</td>
								</tr>';
				$output 	.=' <tr>
									<td><b>Yield :</b> </td>
									<td align="right" id="trade_yield_'.$tradefloor['invoice_id'].'"><b>'.$yield.'%</b></td>
									<td>&nbsp;</td>
								</tr>';
				$output 	.=' <tr>
									<td>Yield Value :</td>
									<td align="right" id="trade_yieldval_'.$tradefloor['invoice_id'].'">'.$yieldValue.'</td>
									<td>&nbsp;</td>
								</tr>';
							
				if($tradefloor['buy_out'] == 1) {
					$output .='	<tr>
									<td colspan="3"><b class="black"> Buy Out Details</b></td>
								</tr>';

					$output .=' <tr>
									<td>Percentage Offered :</td>
									<td align="right">'.$tradefloor['buy_max_thirty_day_reserve'].'</td>
									<td>&nbsp;</td>
								</tr>';
					$output .=' <tr>
									<td colspan="3">
										<table width="100%" border="0" cellspacing="0" cellpadding="0">
										  <tr>
											<td align="left"><b>Yield :</b></td>
											<td align="right"><b>'.number_format($tradefloor['buy_yield'],'3','.','').'%</b></td>
											<td align="right" width="37%">';
					if($holiday == '0' && $holidayFlag1 == 2 && $holidayFlag2 == 2 && $holidayFlag3 == 2 && $holidayFlag4 == 2) {					
						$output .='			<input type="text" class="buy_tr1" value="Buy" name="" onclick=\'return openBuyWin("'.$tradefloor['invoice_id'].'",'.$height.');\'>';
											
					}
					
					$output .='				</td>
											<td width="19%">&nbsp;</td>
										  </tr>
										</table>
									</td>
								</tr>';
				}
				
				
			}elseif($tradefloor['sales_type'] =="3"){
				
				$return = $tradefloor['face_value'] -7;
				$val_return = number_format($return, 2, '.', ',');
		

				$yield 			= number_format($tradefloor['yield'],'3','.',',');
				$output 	.= '<tr>
									<td>Purchase Price : </td>
									<td align="right" id="trade_purchase_'.$tradefloor['invoice_id'].'">'.$tPurchasePrice.'</td>
									<td>&nbsp;</td>
								</tr>';
							
				$output 	.= '<tr>
									<td>Percentage Offered : </td>
									<td align="right" id="trade_offer_'.$tradefloor['invoice_id'].'">
									'.$tradefloor['max_thirty_day_reserve'].'</td>
									<td>&nbsp;</td>
								</tr>';
				$output 	.= '<tr>
									<td>Value Returned : </td>
									<td align="right" id="trade_return_'.$tradefloor['invoice_id'].'">'.$valReturn.'</td>
									<td>&nbsp;</td>
								</tr>';
				$output 	.= '<tr>
									<td><b>Yield :</b> </td>
									<td align="right" id="trade_yield_'.$tradefloor['invoice_id'].'"><b>'.$yield.'%</b></td>
									<td>&nbsp;</td>
								</tr>';
				$output 	.= '<tr>
									<td>Yield Value :</td>
									<td align="right" id="trade_yieldval_'.$tradefloor['invoice_id'].'">'.$yieldValue.'</td>
									<td>&nbsp;</td>
								</tr>';
				$output 	.= '<tr>
									<td>Non-Performance Yield :</td>
									<td align="right" id="trade_nonyield_'.$tradefloor['invoice_id'].'">'.$non_yield.'</td>
									<td>&nbsp;</td>
								</tr>';
							
					
				if($tradefloor['buy_out'] == 1) {
					$output .= '<tr>
									<td colspan="3"><b class="black"> Buy Out Details</b></td>
								</tr>';

					$output .= '<tr>
									<td>Percentage Offered :</td>
									<td align="right">'.$tradefloor['buy_max_thirty_day_reserve'].'</td>
									<td>&nbsp;</td>
								</tr>';
					$output .= '<tr>
									<td colspan="3">
										<table width="100%" border="0" cellspacing="0" cellpadding="0">
										  <tr>
											<td align="left"><b>Yield :</b></td>
											<td align="right"><b>'.number_format($tradefloor['buy_yield'],'3','.','').'%</b></td>
											<td align="right" width="37%">';
					if($holiday == '0' && $holidayFlag1 == 2 && $holidayFlag2 == 2 && $holidayFlag3 == 2 && $holidayFlag4 == 2) {					
						$output .='			<input type="text" class="buy_tr1" value="Buy" name="" onclick=\'return openBuyWin("'.$tradefloor['invoice_id'].'",'.$height.');\'>';
											
					}
					
					$output .='</td>
											<td width="19%">&nbsp;</td>
										  </tr>
										</table>
									</td>
								</tr>';
					$output .=' <tr>
								<td>Non-Performance Yield :</td>
								<td align="right">'.$buy_non_yield.'</td><td>&nbsp;</td>
							</tr>';
				}
				
				
		
				
			}elseif($tradefloor['sales_type'] =="5"){
				
				$return = $tradefloor['face_value'] -7;
				$val_return = number_format($return, 2, '.', ',');
		

				$yield 			= number_format($tradefloor['yield'],'3','.',',');
				$output 	.= '<tr>
									<td>Purchase Price : </td>
									<td align="right" id="trade_purchase_'.$tradefloor['invoice_id'].'">'.$tPurchasePrice.'</td>
									<td>&nbsp;</td>
								</tr>';
							
				$output 	.= '<tr>
									<td>Percentage Offered : </td>
									<td align="right" id="trade_offer_'.$tradefloor['invoice_id'].'">
									'.$tradefloor['max_thirty_day_reserve'].'</td>
									<td>&nbsp;</td>
								</tr>';
				$output 	.= '<tr>
									<td>Value Returned : </td>
									<td align="right" id="trade_return_'.$tradefloor['invoice_id'].'">'.$valReturn.'</td>
									<td>&nbsp;</td>
								</tr>';
				$output 	.= '<tr>
									<td><b>Yield :</b> </td>
									<td align="right" id="trade_yield_'.$tradefloor['invoice_id'].'"><b>'.$yield.'%</b></td>
									<td>&nbsp;</td>
								</tr>';
				$output 	.= '<tr>
									<td>Yield Value :</td>
									<td align="right" id="trade_yieldval_'.$tradefloor['invoice_id'].'">'.$yieldValue.'</td>
									<td>&nbsp;</td>
								</tr>';
			 
							
					
				if($tradefloor['buy_out'] == 1) {
					$output .= '<tr>
									<td colspan="3"><b class="black"> Buy Out Details</b></td>
								</tr>';

					$output .= '<tr>
									<td>Percentage Offered :</td>
									<td align="right">'.$tradefloor['buy_max_thirty_day_reserve'].'</td>
									<td>&nbsp;</td>
								</tr>';
					$output .= '<tr>
									<td colspan="3">
										<table width="100%" border="0" cellspacing="0" cellpadding="0">
										  <tr>
											<td align="left"><b>Yield :</b></td>
											<td align="right"><b>'.number_format($tradefloor['buy_yield'],'3','.','').'%</b></td>
											<td align="right" width="37%">';
					if($holiday == '0' && $holidayFlag1 == 2 && $holidayFlag2 == 2 && $holidayFlag3 == 2 && $holidayFlag4 == 2) {					
						$output .='			<input type="text" class="buy_tr1" value="Buy" name="" onclick=\'return openBuyWin("'.$tradefloor['invoice_id'].'",'.$height.');\'>';
											
					}
					
					$output .='</td>
											<td width="19%">&nbsp;</td>
										  </tr>
										</table>
									</td>
								</tr>';
				}
			}else{
				
				$checked	= '';
				if($tradefloor['debx'] =='1'){
					$checked= 'checked="true"';	
					$return = $tradefloor['face_value'] -7 - 50 ;
				}else{
					$return = $tradefloor['face_value'] -7;	
				}
				$val_return	= $tradefloor['currency_code'].number_format($return, 2, '.', ',');
				
				$yield 		= number_format($tradefloor['yield'],'3','.',',');
				
				
				$output 	.=' <tr>
									<td>Price Offered : </td>
									<td align="right" id="trade_offer_'.$tradefloor['invoice_id'].'">
									'.$tradefloor['currency_code'].number_format($min_advance, 2, '.', ',').'</td>
									<td>&nbsp;</td>
								</tr>';
								
				$output 	.=' <tr>
									<td>Value Returned : </td>
									<td align="right"  id="trade_return_'.$tradefloor['invoice_id'].'">
									'.$tradefloor['currency_code'].number_format($tradefloor['return'],'2','.',',').'</td>
									<td>&nbsp;</td>
								</tr>';
								
				$output 	.=' <tr>
									<td><b>Yield :</b> </td>
									<td align="right" id="trade_yield_'.$tradefloor['invoice_id'].'"><b>'.$yield.'%</b></td>
									<td>&nbsp;</td>
								</tr>';
							
				$output 	.= '<tr>
									<td colspan="2">
										<p style="font-size:11px;">
											<input type="checkbox" id="debx" name="debx" value="1" '.$checked.' readonly="readonly"> Use <a style="color:#0033FF; font-size:11px; text-decoration:underline;" onclick="javascript:window.open(\''.Base_actions::tokenUrl('/exchange-help/collection').'\',\'\',\'scrollbars=yes,width=1000,height=800\');" href="javascript:void(0);">ETR Collection Service</a>
										</p>
									</td>
									<td>&nbsp;</td>
								</tr>';


				if($tradefloor['buy_out'] == 1) {
					
					$output .='	<tr>
									<td colspan="3"><b class="black"> Buy Out Details</b></td>
								</tr>';

					$output .=' <tr>
									<td>Price Offered :</td>
									<td align="right">'.$tradefloor['currency_code'].
									number_format($tradefloor['buy_min_advance'], 2, '.', ',').'</td>
									<td>&nbsp;</td>
								</tr>';
								
					$output .=' <tr>
									<td colspan="3">
										<table width="100%" border="0" cellspacing="0" cellpadding="0">
										  <tr>
											<td align="left"><b>Yield :</b></td>
											<td align="right"><b>'.number_format($tradefloor['buy_yield'],'3','.','').'%</b></td>
											<td align="right" width="37%">';
					if($holiday == '0' && $holidayFlag1 == 2 && $holidayFlag2 == 2 && $holidayFlag3 == 2 && $holidayFlag4 == 2) {					
						$output .='			<input type="text" class="buy_tr1" value="Buy" name="" onclick=\'return openBuyWin("'.$tradefloor['invoice_id'].'",'.$height.');\'>';
											
					}
					
					$output .= '</td>
											<td width="19%">&nbsp;</td>
										  </tr>
										</table>
									</td>
								</tr>';
				}
			
			}
                                
                                $output .='</table></td>
                  			<td align="left" valign="top" style="line-height: 18px;  padding: 0px 5px;">
								<table width="100%" border="0" cellspacing="0" cellpadding="0" >
								  <tr>
									<td colspan="2"><b>Time</b></td>
								  </tr>
								  <tr>
									<td>Trade is open :</td>
									<td align="right">'.$tradefloor['c_days'].'D:'.$tradefloor['c_hours'].'H:'.$tradefloor['c_minutes'].'M
									</td>
								  </tr>
								  <tr>
									<td>Payment Terms :</td>
									<td align="right">'.$tradefloor['payment_terms'].' Days</td>
								  </tr>';

								  if($tradefloor['sales_type']=='5'){

								  	$output.='<tr>
									<td align="right"> Trade Authorised :</td>
									<td align="right">'.$tradefloor['approvedday'].'</td>
								  	</tr>

								  	<tr>
									<td>Expected Date:</td>
									<td align="right">'.$tradefloor['expectedday'].'</td>
								  </tr>';
								  	}else{

									$output.='<tr>
										<td align="right"> Trade Authorised :</td>
										<td align="right">'.$tradefloor['authorisedday'].'</td>
									  </tr>

									  <tr>
									<td>Expected Date:</td>
									<td align="right">'.$tradefloor['expected_date'].'</td>
								  </tr>';
									}
								  
								  $output.='
								   <tr>
									<td>Setlted Date:</td>
									<td align="right"><!--'.$tradefloor['expected_date'].'--></td>
								  </tr>';
								
                                $days = $tradefloor['exp_days'];
								$week = str_replace(".00","",number_format(($days / 7), 2, '.', ''));
								$months = str_replace(".00","",number_format(($days / 30), 2, '.', ''));
								$quaters = str_replace(".00","",number_format(($days / 90), 2, '.', ''));
								if($tradefloor['sales_type'] !="1"){
                               $output .='
								  <tr>
									<td aign="left" >Actual Trade:</td>
									<td align="right"><!--'.$days.' Days--></td>
								  </tr>
								  <!--<tr>
									<td align="right" colspan="2">'.$week.' Weeks</td>
								  </tr>
								  <tr>
									<td align="right" colspan="2">'.$quaters.' Quarters</td>
								  </tr>-->';
								}
							   $output .='</table>';
							$output.='</td></tr><tr><td style="line-height: 20px; padding-left: 15px;padding-bottom:5px; padding-top:5px;" valign="bottom" rowspan="2">';
							$output.='</td><td style="line-height: 20px; padding-bottom:5px; padding-top:5px;" valign="bottom" rowspan="2">';
							$output.='</td>
									<td style="line-height: 18px;  padding: 0px 5px;" valign="bottom" rowspan="2">
											<!--<table width="100%" border="0" cellspacing="0" cellpadding="0">
												<tr>
													<td valign="bottom"><b>Buy <a href="/exchange/cdp.php"  target="_blank" style="color:#0033FF; font-size:11px; text-decoration:underline;">CDP</a> :</b></td>
													<td align="right" valign="bottom"><input type="checkbox"> @ 0.500%</td>
											  	</tr>
										   		<tr>
													<td valign="bottom">Time Remaining:</td>
													<td align="right" valign="bottom"><span style="font-size:11px;font-weight:bold;"> '.$tradefloor['days'].'D:'.$tradefloor['hours'].'H:'.$tradefloor['minutes'].'M </span></td>
										  		</tr>
											</table>-->
									</td>
										</tr>
									</tbody>
								</table>
							</li>
						 </ul>
						</div></div>
					</td>
				</tr>';
				$i++;

		}
		
		return $output;
	}
	
	function getInvestorFloor($trade, $count){ $i=1+$count;
	
	
            
            $output = ' 
                <tr class="grays_bg1" style="padding:0; margin:0;">
                      <td valign="top" align="left" colspan="13" style="padding:0; margin:0;background:none;"><script>
                     var iterate = '.(count($trade)+$count).'; 
                    function addin(str){
                            for(i=1; i<=iterate;i++){
                            var id = "#trade_"+i;
                            var drop = "#search_id_"+i;
                            
                            if(str == i){
                    
                                $(id).removeClass("clsTradeBook");
                                showMnu("search_id_"+i, this);
                                //$(id).addClass("nodisplay");
                            }else{
								
                                $(id).addClass("clsTradeBook");
                                //$(id).removeClass("nodisplay");
                                 $(drop).hide();
                            }
                        }
                    }
                    
                        //sorting function for Trade
                    
					
				
                    i=0;
					myWindow="undefined"; 
                    function openWin(str,height,flg)
                    {
						if(myWindow !="undefined"){
						myWindow.close();
						}
						if(flg == "1"){
							str +="&flg=buy";
						}
                        myWindow=window.open("index.php?do=tradewindow&trade_id="+str+"","mywin","width=750,height="+height+"");
                    
                        myWindow.focus();
                    }
					
					function openBuyWin(str,height){
						
						var r=confirm("Click OK to Buy Out this Trade, otherwise click Cancel")
						if (r==true)
						{
							$.post(  
							"?do=bid", 
								{inv_id: str,
								buy: 2 }, 
								function(responseText){ 
									if(responseText !=3){
										//alert("Buy Out Successful");
									}else{
										alert("Buy Out Unsuccessful");
									}
								},  
								"html"  
							);  	
							
						}else{
							
							return false;
						}
						
						
						
					}
					
					function openBuyWindow(){
						
						//alert(document.trade_floor.["inv_all[]"].length);
						
						var a=new Array();
						a=document.getElementsByName("inv_all[]");
						//alert("Length:"+a.length);
						
						var p=0;
						var output = "";
						for(i=0;i<a.length;i++){
							if(a[i].checked == true){
								output += a[i].value+",";
								p=1;
							}
						}
						if (p==0){
							alert("please select at least one check box");
							return false;
						}else{
							myWindow=window.open("index.php?do=buyoutwindow&inv_id="+output+"","mywin","width=820,height=600,scrollbars=yes");
							//alert(output);
						}
					}
					
                   function jumptoCart(str){
	
						$.post(  
							"?do=jumpcart",  
							{id: str},  
							function(responseText){  
								//window.close();
							},  
							"html"  
						);
					}
						
					
						function all_set(){
							
								 $( function() {
									$("INPUT[name=\'inv_all[]\']").attr(\'checked\', $(\'#select_all\').is(\':checked\')); 
								});
						}
                    
                    </script>';
				
			$output .='	<ul style="height: 35px; background:#C0C0C0;">
						<li style="width: 82px; padding: 0px 7px;"><b>Debtor</b></li>
						<li style="width: 50px; padding: 0px 7px;"><b>Nc/Nd</b></li>
						<li style="border-right: 4px solid #FFF; padding: 0px 10px; width: 66px;"><b>R/C</b>\'000</li>
						<li style=" padding: 0 29px 0 5px; width: 79px;"><b>Tdr/Bkr</b></li>
						
						<li style=" padding: 0 1px; width: 68px;"><b>R/C</b>\'000</li>
						<li style=" width: 50px; padding: 0px 1px;"><b>Tm S&T</b></li>
						<li style="padding: 0 7px 0 12px; text-align: left;width: 54px;"><b>Value</b></li>
						<li style=" padding: 0 10px; width: 36px;"><b>Date</b></li>
						
						<li style="border-left: 4px solid #FFFFFF;padding: 0 4px;text-align: center;width: 55px;"><b>Offer</b></li>
						<li style="width: 67px; padding: 0px 10px; border-left: 4px solid #FFF; text-align: center;"><b>Paid</b></li>
						<li style="padding: 0pt 3px; width: 31px; text-align: center;"><b>Yield</b></li>
						<li style="width: 75px; border-left: 4px solid #FFF; padding: 0px 5px 0 6px; text-align: center;"><b>D/Os</b></li>
						<li style="width: 70px; padding: 0px; ">Status</li></td></tr>';		


		foreach($trade as $tradefloor){


			$trader_id = str_replace("-","",$tradefloor['doj'])."000";

			$trader_id = $trader_id + $tradefloor['user_id'];

			if($i%2 == 0){
				$bg_class = "row2";
			}else{
				$bg_class = "row1";	
			}
			
			if($tradefloor['sales_type'] !="0"){
					

				$bid_query=new Bin_Query();
				$bid_sql = "SELECT * FROM invoice_bidding_history where invoice_id = '".$tradefloor['invoice_id']."'";
				$bid_query->executeQuery($bid_sql);
				$history = $bid_query->records;

				if(count($history) ==0){
					$style="color:#000000;"; //black
				}else{

					$bid_query1=new Bin_Query();
					$bid_sql1 = "SELECT * FROM invoice_bidding_history where invoice_id = '".$tradefloor['invoice_id']."' && user_id ='".$_SESSION['user']['userid']."'";
					$bid_query1->executeQuery($bid_sql1);
					$history1 = $bid_query1->records;
					
					if(count($history1) ==0){
						$style="color:#3F48CC;"; // blue
					}else{
						$bid_query=new Bin_Query();
						
						if($tradefloor['sales_type'] =="1"){
						
						$bid_sql = "SELECT * FROM invoice_bidding where invoice_id = '".$tradefloor['invoice_id']."' order by min_advance DESC limit 1";
						}else{
							$bid_sql = "SELECT * FROM invoice_bidding where invoice_id = '".$tradefloor['invoice_id']."' order by max_thirty_reserve ASC limit 1";
						}
							
						$bid_query->executeQuery($bid_sql);
						$history = $bid_query->records[0];

						if($_SESSION['user']['userid'] != $history['user_id']){
							$style="color:#ED1C24;"; //red
						}else{
							$style="color:#22B14B;"; //green
						}
					}
				}
				
				
				
				
				if($tradefloor['sales_type'] =="1"){
					
					$bid_query=new Bin_Query();
					$bid_sql = "SELECT min_advance , max_thirty_reserve, user_id  FROM invoice_bidding where invoice_id = '".$tradefloor['invoice_id']."' order by min_advance DESC limit 1";
					$bid_query->executeQuery($bid_sql);
					$history = $bid_query->records[0];
		
					if(count($history) ==0){
						$history['min_advance']		= $tradefloor['min_advance'];
						$history['max_thirty_reserve']	= $tradefloor['max_thirty_day_reserve'];
						
					}
					
					$_SESSION['invBook'][$tradefloor['min_advance']] = $history['min_advance'];
					$_SESSION['invBookUserID'][$tradefloor['invoice_id']] = $history['user_id'];
					
					$history['max_thirty_reserve'] ='&nbsp;';

					
					if($history['min_advance'] >= 1000000 ){
				
						$history['min_advance'] = $history['min_advance'] / 1000000;
						
						$history['min_advance'] = $tradefloor['currency_code'].number_format($history['min_advance'], 1, '.', ',')."M";
					}else{
						$history['min_advance'] = $tradefloor['currency_code'].number_format(round($history['min_advance']));
					}
					
					
					$min_advance = $tradefloor['min_advance'];
					if($tradefloor['min_advance'] >= 1000000 ){
				
						$tradefloor['min_advance'] = $tradefloor['min_advance'] / 1000000;
						
						$tradefloor['min_advance'] = $tradefloor['currency_code'].number_format($tradefloor['min_advance'], 1, '.', ',')."M";
					}else{
						$tradefloor['min_advance'] = $tradefloor['currency_code'].number_format($tradefloor['min_advance']);
					}
					
					
					
				}else{
					
					
					$bid_query=new Bin_Query();
					$bid_sql = "SELECT min_advance , max_thirty_reserve, user_id  FROM invoice_bidding where invoice_id = '".$tradefloor['invoice_id']."' order by max_thirty_reserve ASC limit 1";
					$bid_query->executeQuery($bid_sql);
					$history = $bid_query->records[0];
		
					if(count($history) ==0){
						$history['min_advance']		= $tradefloor['min_advance'];
						$history['max_thirty_reserve']	= $tradefloor['max_thirty_day_reserve'];
						
					}
					
					$_SESSION['invBook'][$tradefloor['max_thirty_reserve']] = $history['max_thirty_reserve'];
					$_SESSION['invBookUserID'][$tradefloor['invoice_id']] = $history['user_id'];
					
					if($tradefloor['sales_type'] =="2"){
						$tradeValues 							= $tradefloor;
						$tradeValues['min_advance'] 			= $history['min_advance'];
						$tradeValues['max_thirty_day_reserve'] 	= $history['max_thirty_reserve'];
						$tradeValues['yield'] 					= $tradefloor['bid_yield'];
						$returnCalc 							= Model_MHelpers::manageYieldValue($tradeValues);
						
					}elseif($tradefloor['sales_type'] =="3"){
						$tradeValues 							= $tradefloor;
						$tradeValues['min_advance'] 			= $history['min_advance'];
						$tradeValues['max_thirty_day_reserve'] 	= $history['max_thirty_reserve'];
						$tradeValues['yield'] 					= $tradefloor['bid_yield'];
						$returnCalc 							= Model_MHelpers::performYieldValue($tradeValues);	
					}else if($tradefloor['sales_type'] =="5"){
				
						$tradeValues 							= $tradefloor;
						$tradeValues['min_advance'] 			= $history['min_advance'];
						$tradeValues['max_thirty_day_reserve'] 	= $history['max_thirty_reserve'];
						$returnCalc 							= Model_MHelpers::performInstallYieldValue($tradeValues);
						
					}
					
					$yieldValue			= $returnCalc['yieldValue'];
					$tPurchasePrice		= $returnCalc['tPurchasePrice'];
					$valReturn			= $returnCalc['valReturn'];
					
				
					$history['min_advance'] ='&nbsp;';
					
					
					$actual_date 		= $tradefloor['actual_date'];
					$non_days_sql 		= "SELECT  DATEDIFF(expected_date , DATE(trading_close_date)) AS days ,".
										" DATEDIFF('$actual_date' , trading_close_date) AS days1 FROM invoice_master ".
										" WHERE invoice_id = '".$tradefloor['invoice_id']."' "; 
					$non_query			=new Bin_Query();
					$non_query->executeQuery($non_days_sql);
					$non_days 			= $non_query->records;
					$non_diff_days 		= $non_days[0]['days'] - $non_days[0]['days1'];

					
					$non_face_value = $tradefloor['face_value'];
					$fee 			= 10;
					$bankfee 		= 7;
					$rebate_refund	= Base_actions::getSiteSettings('rebate_refund');
					
					$non_yield		= ((($non_face_value-$bankfee)/($non_face_value/(1+(($rebate_refund/360)*(($tradefloor['max_thirty_day_reserve']/100)*12)))))-1)*360/($non_diff_days+1);
					
					$non_yield = number_format($non_yield*100, 3, '.', '')."%";
					
					
					$buy_non_yield	= ((($non_face_value-$bankfee)/($non_face_value/(1+(($rebate_refund/360)*(($tradefloor['buy_max_thirty_day_reserve']/100)*12)))))-1)*360/($non_diff_days+1);
					
					$buy_non_yield = number_format($buy_non_yield*100, 3, '.', '')."%";
					
					
					$history['max_thirty_reserve'] = number_format(($history['max_thirty_reserve']), 3, '.', '');
					
					
					$tradefloor['max_thirty_day_reserve'] = number_format(($tradefloor['max_thirty_day_reserve']), 3, '.', '')."%";
					$tradefloor['buy_max_thirty_day_reserve'] = number_format(($tradefloor['buy_max_thirty_day_reserve']), 3, '.', '')."%";
				}
						
			}//else{}
	
			$face_value = $tradefloor['currency_code'].number_format($tradefloor['face_value'], 2, '.', ',');
			$face_value1 = $tradefloor['face_value'];
			
			if($face_value1 >= 1000000 ){
				
				$face_value1 = $face_value1 / 1000000;
				
				$face_value1 = $tradefloor['currency_code'].number_format($face_value1, 1, '.', ',')."M";
			}else{
				$face_value1 = $tradefloor['currency_code'].number_format(round($tradefloor['face_value']));
			}
			
			
		
			
			$debtor_limit 	= Model_MCreditRiskSetting::getDebtorRiskLimit($tradefloor);
			$tradefloor['debtor_risk'] 	= Model_MCreditRiskSetting::getDebtorRiskScore($tradefloor);
			$tradefloor['risks']		= Model_MCreditRiskSetting::getOrgRiskScore($tradefloor);
			
			$tooltip 		= $tradefloor['debtor_name'].", Average Risk: ".$tradefloor['debtor_risk']." & Credit Limit: ".$debtor_limit;
			$limits 		= Model_MCreditRiskSetting::getOrgRiskLimit($tradefloor);
			$risk 			= Model_MCreditRiskSetting::getDebtorRisk($tradefloor);
			$risk 			= Display_DCreditRiskSetting::showRisk($risk, $tradefloor,0);
			$risk_org		= Model_MCreditRiskSetting::getOrgRisk($tradefloor);
			$risk_org		= Display_DCreditRiskSetting::showRisk($risk_org, $tradefloor,1);

			$tradefloor['yield'] 		= $tradefloor['yield'] * 100;
			$tradefloor['buy_yield'] 	= $tradefloor['buy_yield'] * 100;
			$tradefloor['bid_yield'] 	= $tradefloor['bid_yield'] * 100;
			
			$output .='<tr><td align="left" valign="top" colspan="14">';
			if($i ==1){
				$output .='<div id="trade_'.$i.'" ondblclick="addin('.$i.');" style="position:relative;">';
				$display = "none";
			}else{
				$output .='<div id="trade_'.$i.'"  class="clsTradeBook" ondblclick="addin('.$i.');" style="position:relative;">';
				$display = "none";
			}

			if(trim($tradefloor['debtor_risk']) == ''){
				$tradefloor['debtor_risk'] ='&nbsp;';
			}
			
			if(trim($tradefloor['risks']) == ''){
				$tradefloor['risks'] ='&nbsp;';
			}
			
			if(trim($debtor_limit) == '0' || trim($debtor_limit) == ''){
				$debtor_limit ='&nbsp;';
			}
			if(trim($limits) == '0' || trim($limits) == ''){
				$limits ='&nbsp;';
			}
      
     
	  
      $output .='<span style="position: absolute; height: 27px; z-index: 999; left: -3px; bottom:0px; top:1px;width: 970px; display:none;" id="blink_'.$tradefloor['invoice_id'].'"></span>';  
	  
      $output .=' 
      <div class="cat_middle '.$bg_class.'"> <span ondblclick="" class="categrey_u">
        <ul style="display:block; height:30px;" class="td_floor">
          <li style="float: left; width: 97px; margin:0px;" class="tool-tip">&nbsp;<a href="javascript:void(0);" title="'.$tooltip.'"><img alt="" src="../images/i_bttn.png"></a>&nbsp;<span ><b class="black">'.substr($tradefloor['debtor_name'],0,7).'...</b></span></li>
          <li style="float: left; width: 30px; margin:0 0 0 5px;">'.$tradefloor['d_nace_group_id'].' </li>
          <li style="float: left; width: 27px;  text-align:right; margin:0 10px 0 0 ">'.$tradefloor['d_nace_id'].'</li>
          <li style="float: left; width: 25px; margin:0; ">'.$tradefloor['debtor_risk'].'</li>
          <li style="float: left; width: 42px; margin:0 5px 0 5px; text-align:right;">'.$debtor_limit.'</li>
          <li style="float: left; padding: 0 10px 0 6px; width: 80px; border-left:4px solid #FFF; text-align:left;">'.$tradefloor['organisation_reference_id'].'</li>
          <li style="float: left; margin:0 5px 0 5px; width: 23px;"> '.$tradefloor['risks'].'</li>
          <li style="float: left; width: 45px; margin:0px; text-align:right;">'.$limits.'</li>
          <li style="float: left;margin: 0 0 0 9px;width: 21px; text-align:right;">'.$tradefloor['payment_terms'].'</li><li style="float: left;   margin: 0 2px 0 5px;width: 10px;">S</li><li style="float: left;margin: 0 0 0 5px;width: 10px;"><b>';
            
             
			
			if($tradefloor['revolving'] =="1"|| $tradefloor['root_invoice_id'] !=0){
				$output .='R';
			}else if($tradefloor['sales_type'] =="1"){
				$output .='O';
			}else if($tradefloor['sales_type'] =="2"){
				$output .='M';
			}else if($tradefloor['sales_type'] =="5"){
				$output .='I';
			}else{
				$output .='P';
			}
            
            $output .='</b></li>
          <li style="float: left; width: 65px; margin:0 2px 0 0; text-align:right;"><span class="black"><b>'.$face_value1.'</b></span></li>
          <li style="float: left; width: 50px; margin: 0 5px; text-align:center;">';
            
            $expected_date = explode("-",$tradefloor['expected_date']);
            
            $output .=$tradefloor['expected_date'];
            
            
            $output .='</li>
          ';
          
          
          if($tradefloor['sales_type'] !=1)
          $align="text-align:right;";
          else
          $align ="text-align:left;";
          
		  
		  $style="color:#000000;";
                                
									
          if($tradefloor['sales_type'] =='1'){
		  
          $output .='
          <li style="float: left; border-left: 4px solid #FFFFFF; margin: 0 5px 0 1px;text-align: right;width: 58px;">'.$tradefloor['min_advance'].'</li>
          <li style="border-left: 4px solid #FFFFFF;  float: left;padding: 0 2px 0 2px; width: 70px; text-align:center;"><span  class="black" id="min_'.$tradefloor['invoice_id'].'" ><b style="'.$style.'" id="cnt_min_'.$tradefloor['invoice_id'].'">-</b></span></li>
          <li style="width:50px; position:relative;float: left;border-right: 4px solid #FFFFFF;"><b style="float: right;">'.number_format($tradefloor['bid_yield'],'3','.','').''.'</b><span class="black" id="max_'.$tradefloor['invoice_id'].'" style="display:none;"><b style="'.$style.'" id="cnt_max_'.$tradefloor['invoice_id'].'">'.$history['max_thirty_reserve'].'</b></span></li>
          ';
          
          }else{
			  
			  if($tradefloor['sales_type'] =='3'){
				$return = $tradefloor['face_value'] -7 - 50 ;
                $val_return = $tradefloor['currency_code'].number_format($return);
			  }else{
				  $val_return ='&nbsp;';
			  }
		  
		  $val = explode(".",$tPurchasePrice);
		  $val = $val[0];
		  $output .='
          <li style="float: left; border-left: 4px solid #FFFFFF; margin: 0 5px 0 1px;text-align: right;width: 58px;">'.$tradefloor['max_thirty_day_reserve'].'</li>
          <li style="border-left: 4px solid #FFFFFF;  float: left;padding: 0 2px 0 2px; width: 70px; text-align:center;"><span  class="black" id="min_'.$tradefloor['invoice_id'].'" ><b style="'.$style.'" id="cnt_min_'.$tradefloor['invoice_id'].'">-</b></span></li>
          <li style="width:50px; position:relative;float: left;border-right: 4px solid #FFFFFF;text-align:right;"><b style="float: right;">'.number_format($tradefloor['bid_yield'],'3','.','').''.'</b><span class="black" id="max_'.$tradefloor['invoice_id'].'" style="display:none;"><b style="'.$style.'" id="cnt_max_'.$tradefloor['invoice_id'].'">'.$history['max_thirty_reserve'].'</b></span></li>
          ';
          
          }
		  
		   $hidden_style = str_replace("color:#",'',$style);
		  $hidden_style = trim(str_replace(";",'',$hidden_style));
		  
		  $query			= new Bin_Query();
			$sql 		= "SELECT s.* ".
						" FROM central_banking_statements as s , invoice_closed as c, invoice_master as m".
						" WHERE s.status = 3 && s.invoice_id = '".$tradefloor['invoice_id']."' && ".
						" c.close_id = s.closed_id && m.invoice_id = c.invoice_id  Limit 1";
			$query->executeQuery($sql);
			$authorise 		= $query->records; 	
			
			switch ($authorise[0]['authorise_status']) {
				case "1":
					$status	="Transferred";
					break;
				case "2":
					$status	="Held";
					break;
				case "3":
					$status	="Cleared";
					break;
				case "4":
					$status	="Charged";
					break;
				case "5":
					$status	="Received";
					break;
				case "6":
					$status	="Settled";
					break;
				case "7":
					$status	="Distributed";
					break;
				case "8":
					$status	="Completed";
					break;
				case "9":
					$status	="Rejected";
					break;
				default:
					$status	="Closed";
				break;
			}
			
			
          
          $output .='
          <li style="float: left; margin: 0 1px 0 3px; text-align:right;font-weight:bold;
    width:66px;padding:0 10px 0 0;">'.$tradefloor['exp_days'].' Days</li>
          <li style="float:left; width:75px; margin:0 0 0 2px;">'.$status.'<span style="display:none;" id="style_'.$tradefloor['invoice_id'].'">ED1C24</span></li>
						</ul>
						<script>
										
											
						
										</script>
						</span> </div>
					  <div class="categ">
									<ul id="search_id_'.$i.'" style="display: '.$display.';" class="trd_detail">
						  <li style="padding-bottom:10px;">
                   <table cellspacing="0" cellpadding="0" border="0" width="100%">
              <tbody>
                            <tr>
                  <td align="left" width="26%" valign="top" style="line-height: 20px; padding-left: 15px;"><b class="black"> Debtor Details</b><br>
                                Name  : '.self::substr($tradefloor['debtor_name'],22).'<br>
                                <table width="100%" cellspacing="0" cellpadding="0" border="0">
							    	<tbody>
										<tr>
											<td>NACEC :</td>
											<td align="right"><span style="float:right;margin: 0 23px 0 0; display:block;">'.$tradefloor['d_nace_group_id'].'</span></td>
										</tr>
										<tr>
											<td>NACED:</td>
											<td align="right"><span style="float:right;margin: 0 23px 0 0; display:block;">'.$tradefloor['d_nace_id'].'</span></td>
										</tr>
									</tbody>
								</table>
								
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">'.$risk.'</table>';
								
								$output .='	</td>		
                  <td align="left" width="24%" valign="top" style="line-height: 20px;"><b class="black">Trader Details</b><br>
								<table width="100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr>
									<td>Reference Code  :</td>
									<td align="right"><span style="float:right;margin: 0 23px 0 0; display:block;">'.$tradefloor['organisation_reference_id'].'</span></td>
								</tr>
								</tbody></table>
                                NACEC : '.$tradefloor['t_nace_group_id'].'<br>
                                NACED : '.$tradefloor['t_nace_id'].' <br>
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">'.$risk_org.'</table>';
								
								$output .='	</td>		
					
                 <td align="left" width="29%" valign="top" style="line-height: 18px;">
				  
				  				<b class="black">Trade Details</b><br>
				  				Trade ID: '.$tradefloor['trade_reference_id'].' <br>
								Sales Type: <b class="black">'.$tradefloor['type_name'].'</b> <br>
								<table width="100%" border="0" cellspacing="0" cellpadding="1" style="'.$margin.'">
								  <tr>
									<td width="51%">Face Value :</td>
									<td align="right" width="30%"> '.$face_value.'</td>
									<td width="19%">&nbsp;</td>
								  </tr>';
				  				

                                
                                
                                
                                
                                if($tradefloor['sales_type'] =="2"){
									
									$return = $tradefloor['face_value'] -7;
									$val_return = number_format($return, 2, '.', ',');
							

									$yield 			= number_format($tradefloor['bid_yield'],'3','.',',');
									
									$output .=' <tr>
													<td>Purchase Price : </td>
													<td align="right">'.$tPurchasePrice.'</td>
													<td>&nbsp;</td>
												</tr>';
												
									$output .=' <tr>
													<td>Percentage Offered : </td>
													<td align="right">'.$history['max_thirty_reserve'].'%</td>
													<td>&nbsp;</td>
												</tr>';
									$output .=' <tr>
													<td>Value Returned : </td>
													<td align="right">'.$valReturn.'</td>
													<td>&nbsp;</td>
												</tr>';
									$output .=' <tr>
													<td><b>Yield :</b> </td>
													<td align="right"><b>'.$yield.'%</b></td>
													<td>&nbsp;</td>
												</tr>';
									$output .=' <tr>
													<td>Yield Value :</td>
													<td align="right">'.$yieldValue.'</td>
													<td>&nbsp;</td>
												</tr>';
												
									if($tradefloor['buy_out'] == 1) {
										$output .='	<tr>
														<td colspan="3"><b class="black"> Buy Out Details</b></td>
													</tr>';

										$output .=' <tr>
														<td>Percentage Offered :</td>
														<td align="right">'.$tradefloor['buy_max_thirty_day_reserve'].'</td>
														<td>&nbsp;</td>
													</tr>';
										$output .=' <tr>
														<td colspan="3">
															<table width="100%" border="0" cellspacing="0" cellpadding="0">
															  <tr>
																<td align="left"><b>Yield :</b></td>
																<td align="right"><b>'.number_format($tradefloor['buy_yield'],'3','.','').'%</b></td>
																<td align="right" width="37%">&nbsp;</td>
																<td width="19%">&nbsp;</td>
															  </tr>
															</table>
														</td>
													</tr>';
									}
									
									
                                }elseif($tradefloor['sales_type'] =="3"){
									
									$return = $tradefloor['face_value'] -7;
									$val_return = number_format($return, 2, '.', ',');
							

									$yield 			= number_format($tradefloor['bid_yield'],'3','.',',');
									$output .=' <tr>
													<td>Purchase Price : </td>
													<td align="right">'.$tPurchasePrice.'</td>
													<td>&nbsp;</td>
												</tr>';
												
									$output .=' <tr>
													<td>Percentage Offered : </td>
													<td align="right">'.$history['max_thirty_reserve'].'%</td>
													<td>&nbsp;</td>
												</tr>';
									$output .=' <tr>
													<td>Value Returned : </td>
													<td align="right">'.$valReturn.'</td>
													<td>&nbsp;</td>
												</tr>';
									$output .=' <tr>
													<td><b>Yield :</b> </td>
													<td align="right"><b>'.$yield.'%</b></td>
													<td>&nbsp;</td>
												</tr>';
									$output .=' <tr>
													<td>Yield Value :</td>
													<td align="right">'.$yieldValue.'</td>
													<td>&nbsp;</td>
												</tr>';
									$output .=' <tr>
													<td>Non-Performance Yield :</td>
													<td align="right">'.$non_yield.'</td>
													<td>&nbsp;</td>
												</tr>';
												
												
												
									if($tradefloor['buy_out'] == 1) {
										$output .='	<tr>
														<td colspan="3"><b class="black"> Buy Out Details</b></td>
													</tr>';

										$output .=' <tr>
														<td>Percentage Offered :</td>
														<td align="right">'.$tradefloor['buy_max_thirty_day_reserve'].'</td>
														<td>&nbsp;</td>
													</tr>';
										$output .=' <tr>
														<td colspan="3">
															<table width="100%" border="0" cellspacing="0" cellpadding="0">
															  <tr>
																<td align="left"><b>Yield :</b></td>
																<td align="right"><b>'.number_format($tradefloor['buy_yield'],'3','.','').'%</b></td>
																<td align="right" width="37%">&nbsp;</td>
																<td width="19%">&nbsp;</td>
															  </tr>
															</table>
														</td>
													</tr>';
										$output .=' <tr>
													<td>Non-Performance Yield :</td>
													<td align="right">'.$buy_non_yield.'</td><td>&nbsp;</td>
												</tr>';
									}
									
									
                            
									
                                }elseif($tradefloor['sales_type'] =="5"){
									
									$return = $tradefloor['face_value'] -7;
									$val_return = number_format($return, 2, '.', ',');
							

									$yield 			= number_format($tradefloor['bid_yield'],'3','.',',');
									$output .=' <tr>
													<td>Purchase Price : </td>
													<td align="right">'.$tPurchasePrice.'</td>
													<td>&nbsp;</td>
												</tr>';
												
									$output .=' <tr>
													<td>Percentage Offered : </td>
													<td align="right">'.$history['max_thirty_reserve'].'%</td>
													<td>&nbsp;</td>
												</tr>';
									$output .=' <tr>
													<td>Value Returned : </td>
													<td align="right">'.$valReturn.'</td>
													<td>&nbsp;</td>
												</tr>';
									$output .=' <tr>
													<td><b>Yield :</b> </td>
													<td align="right"><b>'.$yield.'%</b></td>
													<td>&nbsp;</td>
												</tr>';
									$output .=' <tr>
													<td>Yield Value :</td>
													<td align="right">'.$yieldValue.'</td>
													<td>&nbsp;</td>
												</tr>';
												
									if($tradefloor['buy_out'] == 1) {
										$output .='	<tr>
														<td colspan="3"><b class="black"> Buy Out Details</b></td>
													</tr>';

										$output .=' <tr>
														<td>Percentage Offered :</td>
														<td align="right">'.$tradefloor['buy_max_thirty_day_reserve'].'</td>
														<td>&nbsp;</td>
													</tr>';
										$output .=' <tr>
														<td colspan="3">
															<table width="100%" border="0" cellspacing="0" cellpadding="0">
															  <tr>
																<td align="left"><b>Yield :</b></td>
																<td align="right"><b>'.number_format($tradefloor['buy_yield'],'3','.','').'%</b></td>
																<td align="right" width="37%">&nbsp;</td>
																<td width="19%">&nbsp;</td>
															  </tr>
															</table>
														</td>
													</tr>';
									}
									
                                }else{
									
									$checked='';
									if($tradefloor['debx'] =='1'){
										$checked 	= 'checked="true"';	
										$return 	= $tradefloor['face_value'] -7 - 50 ;
									}else{
										$return 	= $tradefloor['face_value'] -7;	
									}
									$val_return		= $tradefloor['currency_code'].number_format($return, 2, '.', ',');
									
									$yield 			= number_format($tradefloor['bid_yield'],'3','.',',');
									
									
									$output .=' <tr>
													<td>Price Offered : </td>
													<td align="right">'.$history['min_advance'].'</td>
													<td>&nbsp;</td>
												</tr>';
									$output .=' <tr>
													<td>Value Returned : </td>
													<td align="right">'.$tradefloor['currency_code'].number_format($tradefloor['return'],'2','.',',').'</td>
													<td>&nbsp;</td>
												</tr>';
									$output .=' <tr>
													<td><b>Yield :</b> </td>
													<td align="right"><b>'.$yield.'%</b></td>
													<td>&nbsp;</td>
												</tr>';
												
									$output .= '<tr>
													<td colspan="2">
														<p style="font-size:11px;">
															<input type="checkbox" id="debx" name="debx" value="1" '.$checked.' readonly="readonly"> Use <a style="color:#0033FF; font-size:11px; text-decoration:underline;" onclick="javascript:window.open(\''.Base_actions::tokenUrl('/exchange-help/collection').'\',\'\',\'scrollbars=yes,width=1000,height=800\');" href="javascript:void(0);">ETR Collection Service</a>
														</p>
													</td>
													<td>&nbsp;</td>
												</tr>';


									if($tradefloor['buy_out'] == 1) {
										$output .='	<tr>
														<td colspan="3"><b class="black"> Buy Out Details</b></td>
													</tr>';

										$output .=' <tr>
														<td>Price Offered :</td>
														<td align="right">'.$tradefloor['currency_code'].number_format($tradefloor['buy_min_advance'], 2, '.', ',').'</td>
														<td>&nbsp;</td>
													</tr>';
										$output .=' <tr>
														<td colspan="3">
															<table width="100%" border="0" cellspacing="0" cellpadding="0">
															  <tr>
																<td align="left"><b>Yield :</b></td>
																<td align="right"><b>'.number_format($tradefloor['buy_yield'],'3','.','').'%</b></td>
																<td align="right" width="37%">&nbsp;</td>
																<td width="19%">&nbsp;</td>
															  </tr>
															</table>
														</td>
													</tr>';
									}
                                
                                }
                                
                                
                                $output .='</table></td>
                  			<td align="left" valign="top" style="line-height: 18px;  padding: 0px 5px;">
								<table width="100%" border="0" cellspacing="0" cellpadding="0" >
								  <tr>
									<td colspan="2"><b>Time</b></td>
								  </tr>
								  <tr>
									<td>Trade is open :</td>
									<td align="right">'.$tradefloor['c_days'].'D:'.$tradefloor['c_hours'].'H:'.$tradefloor['c_minutes'].'M
									</td>
								  </tr>
								  <tr>
									<td>Payment Terms :</td>
									<td align="right">'.$tradefloor['payment_terms'].' Days</td>
								  </tr>';

								  
							  	if($tradefloor['sales_type']=='5'){

							  	$output.='<tr>
								<td>Trade Authorised :</td>
								<td align="right">'.$tradefloor['approvedday'].'</td>
							  	</tr>

							  	<tr>
									<td>Expected Date:</td>
									<td align="right">'.$tradefloor['expectedday'].'</td>
								  </tr>';
							  	}else{

								$output.='<tr>
									<td> Trade Authorised :</td>
									<td align="right">'.$tradefloor['authorisedday'].'</td>
								  </tr>

								  <tr>
									<td>Expected Date:</td>
									<td align="right">'.$tradefloor['expected_date'].'</td>
								  </tr>';
								}
								$output.='
								  <tr>
									<td>&nbsp;</td>
									<td align="right">&nbsp;</td>
								  </tr>
								   <tr>
									<td>Settled Date:</td>
									<td align="right"><!--'.$tradefloor['expected_date'].'--></td>
								  </tr>';
								
                                $days = $tradefloor['exp_days'];
								$week = str_replace(".00","",number_format(($days / 7), 2, '.', ''));
								$months = str_replace(".00","",number_format(($days / 30), 2, '.', ''));
								$quaters = str_replace(".00","",number_format(($days / 90), 2, '.', ''));
								if($tradefloor['sales_type'] !="1"){
                                $output .='
								  <tr>
									<td aign="left" >Actual Trade:</td>
									<td align="right"><!--'.$days.' Days--></td>
								  </tr>
								  <!--<tr>
									<td align="right" colspan="2">'.$week.' Weeks</td>
								  </tr>
								  <tr>
									<td align="right" colspan="2">'.$quaters.' Quarters</td>
								  </tr>-->';
								}
								
								 $output .='</table>';
							$output.='</td></tr>
										<tr><td style="line-height: 20px; padding-left: 15px;padding-bottom:5px;padding-top:5px;" valign="bottom">';
							$output.='</td><td style="line-height: 20px; padding-bottom:5px; padding-top:5px;" valign="bottom">';
							$output.='</td>
									<td style="line-height: 20px; padding-bottom:0px;padding-right: 52px;" align="right" valign="bottom"><a class="under_blue" href="index.php?do=viewbidhistory&id='.$tradefloor['invoice_id'].'" style="padding:3px 10px;">View Bid History</a></td>
									<td style="line-height: 18px;  padding: 0px 5px;" valign="bottom">
											<!--<table width="100%" border="0" cellspacing="0" cellpadding="0">
											   <tr>
												<td valign="bottom">Time Remaining:</td>
												<td align="right" valign="bottom"><span style="font-size:11px;font-weight:bold;"> '.$tradefloor['days'].'D:'.$tradefloor['hours'].'H:'.$tradefloor['minutes'].'M </span></td>
											  </tr>
											</table>-->
									</td>
										</tr>
									</tbody>
								</table>
								</li>
						 </ul>
						</div></div>
					</td>
				</tr>';
				$i++;


		}
		$_SESSION['flag_other_active'] =='';
		return $output.'<style> .ClsFloor li, .ClsFloor li span , .ClsFloor li span b { font-size:11px !important; } .grays_bg1 li { float:left; line-height:35px; } .clsTradeBook .blinks{ height:31px !important; }</style>'; 
	}
	

	
	
	function showInvestorInbox($records)
	{
		$output.='<td width="82%" align="right" valign="top"><form method="POST" action="?do=investormsgdelete" name="grid"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
                <td align="center" valign="top"><span style="color:#008000">'.$_SESSION['message'].'</span></td>
              </tr>
                                      <tr>
                                        <td align="left" valign="top" class="hdr_center">
                                        <table cellpadding="0" cellspacing="0" border="0" width="100%">
                                        <tr>
                                              <td align="left" valign="top" class="inves_top1">Inbox</td>
                                              <td align="right" valign="top" class="inves_top1"><input type="submit" class="under_blue" value="DELETE" name="delete">&nbsp;&nbsp;</td>
                                            </tr></table>
                                        
                                        <table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr class="grays_bg">
                                              <td width="6%" align="left" valign="top"><input type="checkbox" name="checkall" value=""  onclick="selectall(this.form);"/></td>
                                              <td width="13%" align="left" valign="top"><b>From</b></td>
                                              <td width="56%" align="left" valign="top"><b>Subject</b></td>
                                              <td width="25%"   align="left" valign="top"><b>Received on</b></td>
                                            </tr>';
if(count($records))
{
					$array_pagination=array();
					for($i=0;$i<count($records);$i++)
					{
						$query=new Bin_Query();
						$sql="SELECT first_name FROM temp_registration WHERE user_id='".$records[$i]['message_from']."'";
						$query->executeQuery($sql);
						$fname=$query->records[0]['first_name'];
						if($i%2=='0')
						$class='row1';
						else
						$class='row2';
						if($records[$i]['message_flag']=='1')
						{
							$nx='<b>'.$records[$i]['message_title'].'</b>';
						}
						else
						{
							$nx=''.$records[$i]['message_title'].'';
						}
					
                                            
                                            $array_pagination[]='
                                            <tr class="'.$class.'">
                                              <td width="6%" align="left" valign="top"><input name="checkbox[]" id="checkbox[]" type="checkbox" value="'.$records[$i]['message_id'].'"  /></td>
                                              <td width="13%" align="left" valign="top">'.$fname.'</td>
                                              <td width="56%" align="left" valign="top"><a href="?do=viewinvestormessage&mid='.$records[$i]['message_id'].'" >'.$nx.'</a></td>
                                              <td width="25%"   align="left" valign="top">'.$records[$i]['message_created_date'].'</td>
                                            </tr>'; 
					}
		
		$pagesize=20;
		if(isset($_GET['size']))
		{
			$pagesize=$_GET['size'];
		}
				
		if(isset($_GET['page']))
		{
			
			$start = trim($_GET['page']-1) *  $pagesize;
			$end = $start+ $pagesize;
		}	
		else 
		{
			$start = 0;
			$end =  $pagesize;
		}	
		$total=0;
		$total = ceil(count($array_pagination)/ $pagesize);

		if(count($array_pagination)<=$pagesize)
		{
			foreach($array_pagination as $key=>$value)
			{
                $output.=$value;
			}
		}
		else
		{
			for($i=$start;$i<$end;$i++)
			{
				$output.=$array_pagination[$i];
			}
		}
			$output.='<tr><td valign="top" align="right" colspan="7" class="pagination">'.self::generatePagination($total).'</td></tr>';
}
		else
		{
			$output.='<tr class="row1">
			<td valign="top" align="center" colspan="4">No Records Found</td>

			</tr>';
		}
					$output.='</table>  
				            </td>
                                            </tr>
                                          </table></form></td>';
return $output;
	}

 	function investorSent($records)
	{
		$output.='<td width="82%" align="right" valign="top"><form method="POST" action="?do=investormsgdelete" name="grid"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
                <td align="center" valign="top"><span style="color:#008000">'.$_SESSION['message'].'</span></td>
              </tr>
                                      <tr>
                                        <td align="left" valign="top" class="hdr_center">
                                        <table cellpadding="0" cellspacing="0" border="0" width="100%">
                                        <tr>
                                              <td align="left" valign="top" class="inves_top1">Sent Items</td>
                                              <td align="right" valign="top" class="inves_top1">&nbsp;&nbsp;</td>
                                            </tr></table>
                                        
                                        <table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr class="grays_bg">
                                              <td width="6%" align="left" valign="top">&nbsp;</td>
                                              <td width="13%" align="left" valign="top"><b>From</b></td>
                                              <td width="56%" align="left" valign="top"><b>Subject</b></td>
                                              <td width="25%"   align="left" valign="top"><b>Received on</b></td>
                                            </tr>';
if(count($records)>0)
{
					$array_pagination=array();
					for($i=0;$i<count($records);$i++)
					{
						$query=new Bin_Query();
						$sql="SELECT first_name FROM temp_registration WHERE user_id='".$records[$i]['message_to']."'";
						$query->executeQuery($sql);
						$fname=$query->records[0]['first_name'];
						if($i%2=='0')
						$class='row1';
						else
						$class='row2';

                                            
                                            $array_pagination[]='
                                            <tr class="'.$class.'">
                                              <td width="6%" align="left" valign="top">&nbsp;</td>
                                              <td width="13%" align="left" valign="top">'.$fname.'</td>
                                              <td width="56%" align="left" valign="top"><a href="?do=viewinvestorsent&mid='.$records[$i]['message_id'].'" >'.$records[$i]['message_title'].'</a></td>
                                              <td width="25%"   align="left" valign="top">'.$records[$i]['message_created_date'].'</td>
                                            </tr>'; 
					}
		
		$pagesize=20;	
		if(isset($_GET['size']))
		{
			$pagesize=$_GET['size'];
		}
				
		if(isset($_GET['page']))
		{
			
			$start = trim($_GET['page']-1) *  $pagesize;
			$end = $start+ $pagesize;
		}	
		else 
		{
			$start = 0;
			$end =  $pagesize;
		}	
		$total=0;
		$total = ceil(count($array_pagination)/ $pagesize);

		if(count($array_pagination)<=$pagesize)
		{
			foreach($array_pagination as $key=>$value)
			{
                $output.=$value;
			}
		}
		else
		{
			for($i=$start;$i<$end;$i++)
			{
				$output.=$array_pagination[$i];
			}
		}
		
        $output.='<tr><td valign="top" align="right" colspan="7" class="pagination">'.self::generatePagination($total).' </td></tr>';
}
		else
		{
			$output.='<tr class="row1">
			<td valign="top" align="center" colspan="4">No Records Found</td>

			</tr>';
		}

					$output.='</table>  
				            </td>
                                            </tr>
                                          </table></form></td>';
return $output;
	}


		function getInvestorBook($trade)
        {
         $i=1;
            $output = ' 
                <tr class="grays_bg1" style="padding:0; margin:0;">
                      <td valign="top" align="left" colspan="13" style="padding:0; margin:0;background:none;"><script>
                     var iterate = '.count($trade).'; 
                    function addin(str){
                            for(i=1; i<=iterate;i++){
                            var id = "#trade_"+i;
                            var drop = "#search_id_"+i;
                            
                            if(str == i){
                    
                                $(id).removeClass("clsTradeBook");
                                showMnu("search_id_"+i, this);
                                //$(id).addClass("nodisplay");
                            }else{
                                $(id).addClass("clsTradeBook");
                                //$(id).removeClass("nodisplay");
                                 $(drop).slideUp("slow");
                            }
                        }
                    }
                    
                        //sorting function for Trade
                    function sorting(str)
                    {
                        document.trade_floor.submit();
                    }
                    i=0;
					myWindow="undefined"; 
                    function openWin(str,height,flg)
                    {
						if(myWindow !="undefined"){
						myWindow.close();
						}
						if(flg == "1"){
							str +="&flg=buy";
						}
                        myWindow=window.open("index.php?do=tradewindow&trade_id="+str+"","mywin","width=750,height="+height+"");
                    
                        myWindow.focus();
                    }
					
					function openBuyWin(str,height){
						
						var r=confirm("Please Confirm, By Clicking OK, You are about to Buy the Trade")
						if (r==true)
						{
							$.post(  
							"?do=bid", 
								{inv_id: str,
								buy: 2 }, 
								function(responseText){  
									if(responseText !=3){
										alert("Buy out made Successfully");
										
									}else{
										alert("Not Allowed Try again Later");
									}
								},  
								"html"  
							);  	
							
						}else{
							
							return false;
						}
						
						
						
					}
					
					function openBuyWindow(){
						
						//alert(document.trade_floor.["inv_all[]"].length);
						
						var a=new Array();
						a=document.getElementsByName("inv_all[]");
						//alert("Length:"+a.length);
						
						var p=0;
						var output = "";
						for(i=0;i<a.length;i++){
							if(a[i].checked == true){
								output += a[i].value+",";
								p=1;
							}
						}
						if (p==0){
							alert("please select at least one check box");
							return false;
						}else{
							myWindow=window.open("index.php?do=buyoutwindow&inv_id="+output+"","mywin","width=820,height=600,scrollbars=yes");
							//alert(output);
						}
					}
					
                   $(document).ready(function(){
												$(".tool-tip a").tooltip({
													track: true,
													delay: 0,
													showURL: false,
													showBody: " - ",
													fade: 250
												});
											});
						
					
						function all_set(){
							
								 $( function() {
									$("INPUT[name=\'inv_all[]\']").attr(\'checked\', $(\'#select_all\').is(\':checked\')); 
								});
						}
                    
                    </script>
						<ul style="height: 35px; background:#C0C0C0;">
						<li style="width: 82px; padding: 0px 7px;"><b>Debtor</b></li>
						<li style="width: 50px; padding: 0px 7px;"><b>Nc/Nd</b></li>
						<li style="border-right: 4px solid #FFF; padding: 0px 10px; width: 66px;"><b>R/C</b>\'000</li>
						<li style=" padding: 0 29px 0 5px; width: 73px;"><b>Tdr/Bkr</b></li>

						<li style=" width: 50px; padding: 0px 1px;"><b>Tm S&T</b></li>
						
						<li style=" padding: 0 10px; width: 36px;"><b>Date</b></li>
						<li style="padding: 0 7px 0 12px; text-align: left;width: 51px;"><b>Value</b></li>

						<li style="width: 67px; padding: 0px 10px; border-left: 4px solid #FFF;"><b>Offer/Bid</b></li>
						<li style="padding: 0pt 3px; width: 31px;"><b>Dis%</b></li>
						<li style="width: 45px; border-left: 4px solid #FFF; padding: 0px 5px 0 6px; text-align: center;"><b>Status</b></li>
						</td>
		</tr>
				';


		foreach($trade as $tradefloor){


			$trader_id = str_replace("-","",$tradefloor['doj'])."000";

			$trader_id = $trader_id + $tradefloor['user_id'];

			if($i%2 == 0){
				$bg_class = "row2";
			}else{
				$bg_class = "row1";	
			}
			
			if($tradefloor['sales_type'] !="0"){
					

				$bid_query=new Bin_Query();
				$bid_sql = "SELECT * FROM invoice_bidding_history where invoice_id = '".$tradefloor['invoice_id']."'";
				$bid_query->executeQuery($bid_sql);
				$history = $bid_query->records;

				if(count($history) ==0){
					$style="color:#000000;"; //black
				}else{

					$bid_query1=new Bin_Query();
					$bid_sql1 = "SELECT * FROM invoice_bidding_history where invoice_id = '".$tradefloor['invoice_id']."' && user_id ='".$_SESSION['user']['userid']."'";
					$bid_query1->executeQuery($bid_sql1);
					$history1 = $bid_query1->records;
					
					if(count($history1) ==0){
						$style="color:#3F48CC;"; // blue
					}else{
						$bid_query=new Bin_Query();
						
						if($tradefloor['sales_type'] =="1"){
						
						$bid_sql = "SELECT * FROM invoice_bidding where invoice_id = '".$tradefloor['invoice_id']."' order by min_advance DESC limit 1";
						}else{
							$bid_sql = "SELECT * FROM invoice_bidding where invoice_id = '".$tradefloor['invoice_id']."' order by max_thirty_reserve ASC limit 1";
						}
							
						$bid_query->executeQuery($bid_sql);
						$history = $bid_query->records[0];

						if($_SESSION['user']['userid'] != $history['user_id']){
							$style="color:#ED1C24;"; //red
						}else{
							$style="color:#22B14B;"; //green
						}
					}
				}
				
				
				
				
				
				
				if($tradefloor['sales_type'] =="1"){
					
					$bid_query=new Bin_Query();
				$bid_sql = "SELECT min_advance , max_thirty_reserve  FROM invoice_bidding where invoice_id = '".$tradefloor['invoice_id']."' order by min_advance DESC limit 1";
				$bid_query->executeQuery($bid_sql);
				$history = $bid_query->records[0];
	
				if(count($history) ==0){
					$history['min_advance']		= $tradefloor['min_advance'];
					$history['max_thirty_reserve']	= $tradefloor['max_thirty_day_reserve'];
					
				}
					
					$history['max_thirty_reserve'] ='&nbsp;';
				
					if($history['min_advance'] >= 1000000 ){
				
						$history['min_advance'] = $history['min_advance'] / 1000000;
						
						$history['min_advance'] = $tradefloor['currency_code'].number_format($history['min_advance'], 1, '.', ',')."M";
					}else{
						$history['min_advance'] = $tradefloor['currency_code'].number_format(round($history['min_advance']));
					}
					
					
					$min_advance = $tradefloor['min_advance'];
					if($tradefloor['min_advance'] >= 1000000 ){
				
						$tradefloor['min_advance'] = $tradefloor['min_advance'] / 1000000;
						
						$tradefloor['min_advance'] = $tradefloor['currency_code'].number_format($tradefloor['min_advance'], 1, '.', ',')."M";
					}else{
						$tradefloor['min_advance'] = $tradefloor['currency_code'].number_format($tradefloor['min_advance']);
					}
					
					
					
				}else{
					
					
					$bid_query=new Bin_Query();
				$bid_sql = "SELECT min_advance , max_thirty_reserve  FROM invoice_bidding where invoice_id = '".$tradefloor['invoice_id']."' order by max_thirty_reserve ASC limit 1";
				$bid_query->executeQuery($bid_sql);
				$history = $bid_query->records[0];
	
				if(count($history) ==0){
					$history['min_advance']		= $tradefloor['min_advance'];
					$history['max_thirty_reserve']	= $tradefloor['max_thirty_day_reserve'];
					
				}
				
					$history['min_advance'] ='&nbsp;';
					
					
					$actual_date 		= $tradefloor['actual_date'];
					$non_days_sql 		= "SELECT  DATEDIFF(expected_date , DATE(trading_close_date)) AS days ,".
										" DATEDIFF('$actual_date' , trading_close_date) AS days1 FROM invoice_master ".
										" WHERE invoice_id = '".$tradefloor['invoice_id']."' "; 
					$non_query			=new Bin_Query();
					$non_query->executeQuery($non_days_sql);
					$non_days 			= $non_query->records;
					$non_diff_days 		= $non_days[0]['days'] - $non_days[0]['days1'];
					
					$non_face_value = $tradefloor['face_value'];
					$fee 			= 10;
					$bankfee 		= 7;
					$rebate_refund	= Base_actions::getSiteSettings('rebate_refund');
					
					$non_yield		= ((($non_face_value-$bankfee)/($non_face_value/(1+(($rebate_refund/360)*(($tradefloor['max_thirty_day_reserve']/100)*12)))))-1)*360/($non_diff_days+1);
					
					$non_yield 		= number_format($non_yield*100, 3, '.', '')."%";
					$buy_non_yield	= ((($non_face_value-$bankfee)/($non_face_value/(1+(($rebate_refund/360)*(($tradefloor['buy_max_thirty_day_reserve']/100)*12)))))-1)*360/($non_diff_days+1);
					
					$buy_non_yield 	= number_format($buy_non_yield*100, 3, '.', '')."%";
					$history['max_thirty_reserve'] 			= number_format(($history['max_thirty_reserve']), 3, '.', '');
					$tradefloor['max_thirty_day_reserve'] 	= number_format(($tradefloor['max_thirty_day_reserve']), 3, '.', '')."%";
					$tradefloor['buy_max_thirty_day_reserve'] = number_format(($tradefloor['buy_max_thirty_day_reserve']), 3, '.', '')."%";
				}
			}
	
			$face_value = $tradefloor['currency_code'].number_format($tradefloor['face_value'], 2, '.', ',');
			$face_value1 = $tradefloor['face_value'];
			
			if($face_value1 >= 1000000 ){
				
				$face_value1 = $face_value1 / 1000000;
				
				$face_value1 = $tradefloor['currency_code'].number_format($face_value1, 1, '.', ',')."M";
			}else{
				$face_value1 = $tradefloor['currency_code'].number_format(round($tradefloor['face_value']));
			}
			
			if($tradefloor['sales_type'] =="2"){
				$returnCalc 	= Model_MHelpers::manageYieldValue($tradefloor);
				
			}elseif($tradefloor['sales_type'] =="3"){
				$returnCalc 	= Model_MHelpers::performYieldValue($tradefloor);	
			}
			
			$yieldValue			= $returnCalc['yieldValue'];
			$tPurchasePrice		= $returnCalc['tPurchasePrice'];
			$valReturn			= $returnCalc['valReturn'];
			
			$debtor_limit 				= Model_MCreditRiskSetting::getDebtorRiskLimit($tradefloor);
			$tradefloor['debtor_risk'] 	= Model_MCreditRiskSetting::getDebtorRiskScore($tradefloor);
			$tradefloor['risks']		= Model_MCreditRiskSetting::getOrgRiskScore($tradefloor);
			$tooltip 		= $tradefloor['debtor_name'].", Average Risk: ".$tradefloor['debtor_risk']." & Credit Limit: ".$debtor_limit;
			$limits 		= Model_MCreditRiskSetting::getOrgRiskLimit($tradefloor);
			$risk 			= Model_MCreditRiskSetting::getDebtorRisk($tradefloor);
			$risk 			= Display_DCreditRiskSetting::showRisk($risk, $tradefloor,0);
			$risk_org		= Model_MCreditRiskSetting::getOrgRisk($tradefloor);
			$risk_org		= Display_DCreditRiskSetting::showRisk($risk_org, $tradefloor,1);


			$output .='<tr><td align="left" valign="top" colspan="14">';
			if($i ==1){
				$output .='<div id="trade_'.$i.'" ondblclick="addin('.$i.');" style="position:relative;">';
				$display = "none";
			}else{
				$output .='<div id="trade_'.$i.'"  class="clsTradeBook" ondblclick="addin('.$i.');" style="position:relative;">';
				$display = "none";
			} 
			
			$tradefloor['yield'] 		= $tradefloor['yield'] * 100;
			$tradefloor['buy_yield'] 	= $tradefloor['buy_yield'] * 100;
			$tradefloor['bid_yield'] 	= $tradefloor['bid_yield'] * 100;
			
			
			if(trim($tradefloor['debtor_risk']) == ''){
				$tradefloor['debtor_risk'] ='&nbsp;';
			}
			
			if(trim($tradefloor['risks']) == ''){
				$tradefloor['risks'] ='&nbsp;';
			}
			
			if(trim($debtor_limit) == '0' || trim($debtor_limit) == ''){
				$debtor_limit ='&nbsp;';
			}
			if(trim($limits) == '0' || trim($limits) == ''){
				$limits ='&nbsp;';
			}
      
      $output .='
      <div class="cat_middle '.$bg_class.'"> <span ondblclick="" class="categrey_u">
        <ul style="display:block; height:30px;" class="td_floor">
          <li style="float: left; width: 97px; margin:0px;" class="tool-tip">&nbsp;<a href="javascript:void(0);" title="'.$tooltip.'"><img alt="" src="../images/i_bttn.png"></a>&nbsp;<span ><b class="black">'.substr($tradefloor['debtor_name'],0,7).'...</b></span></li>
          <li style="float: left; width: 30px; margin:0 0 0 5px;">'.$tradefloor['d_nace_group_id'].' </li>
          <li style="float: left; width: 27px;  text-align:right; margin:0 10px 0 0 ">'.$tradefloor['d_nace_id'].'</li>
          <li style="float: left; width: 25px; margin:0; ">'.$tradefloor['debtor_risk'].'</li>
          <li style="float: left; width: 42px; margin:0 10px 0 0 ; text-align:right;">'.$debtor_limit.'</li>
          <li style="float: left; padding: 0 10px 0 6px; width: 80px; border-left:4px solid #FFF; text-align:left;">'.$tradefloor['organisation_reference_id'].'</li>

          <li style="float: left;margin: 0 0 0 9px;width: 21px; text-align:right;">'.$tradefloor['payment_terms'].'</li><li style="float: left;   margin: 0 2px 0 5px;width: 10px;">S</li><li style="float: left;margin: 0 0 0 5px;width: 10px;"><b>';
			
			if($tradefloor['sales_type'] =="1"){
				$output .='O';
			}else if($tradefloor['sales_type'] =="2"){
				$output .='M';
			}else{
				$output .='P';
			}
            
            $output .='</b></li>
          
          <li style="float: left; width: 50px; margin: 0 5px; text-align:center;">';
            
            $expected_date = explode("-",$tradefloor['expected_date']);
            
            $output .=$expected_date[2]."/".$expected_date[1]."/".substr($expected_date[0],2,4);
            
            $output .='</li>
			<li style="float: left; width: 65px; margin:0 2px 0 0; text-align:right;"><span class="black"><b>'.$face_value1.'</b></span></li>';
          
          
          if($tradefloor['sales_type'] !=1)
          $align="text-align:right;";
          else
          $align ="text-align:left;";
          
		  
		  
                                
									
          if($tradefloor['sales_type'] =='1'){
		  
          $output .='
         
          <li style="border-left: 4px solid #FFFFFF;  float: left;padding: 0 2px 0 2px; width: 70px; text-align:right;"><span  class="black" id="min_'.$tradefloor['invoice_id'].'" style=""><b style="'.$style.'" >'.$history['min_advance'].'</b></span></li>
          <li style="width:50px; position:relative;float: left;border-right: 4px solid #FFFFFF;"> <span class="black" id="max_'.$tradefloor['invoice_id'].'"><b style="'.$style.'" >'.$history['max_thirty_reserve'].'</b></span></li>
          ';
          
          }else{
			  
			  if($tradefloor['sales_type'] =='3'){
				$return = $tradefloor['face_value'] -7 - 50 ;
                $val_return = $tradefloor['currency_code'].number_format($return);
			  }else{
				  $val_return ='&nbsp;';
			  }
				
		  $output .='
         
          <li style="border-left: 4px solid #FFFFFF;  float: left;padding: 0 2px 0 2px; width: 70px; text-align:right;"><span  class="black" id="min_'.$tradefloor['invoice_id'].'" style=""><b style="'.$style.'" >'.$val_return.'</b></span></li>
          <li style="width:50px; position:relative;float: left;border-right: 4px solid #FFFFFF;text-align:right;"> <span class="black" id="max_'.$tradefloor['invoice_id'].'"><b style="'.$style.'" >'.$history['max_thirty_reserve'].'</b></span></li>
          ';
          
          }
          
          $output .='
          <li style="float: left; margin: 0 1px 0 3px; text-align:right;
    width:51px;">';
            
            $exp = explode(" ",$tradefloor['trading_close_date']);
            $date = explode("-",$exp[0]);
            $time = explode(":",$exp[1]);
            
            $inv = $tradefloor;
            
            
            
            
            
            $output .='&nbsp; </li>
        </ul>
        <script>
						
							
		
						</script>
        </span> </div>
      <div class="categ">
                    <ul id="search_id_'.$i.'" style="display: '.$display.';" class="trd_detail">
          <li>
                   <table cellspacing="0" cellpadding="0" border="0" width="100%">
              <tbody>
                            <tr>
                  <td align="left" width="26%" valign="top" style="line-height: 20px; padding-left: 15px;"><b class="black"> Debtor Details</b><br>
                                Name  : '.self::substr($tradefloor['debtor_name'],22).'<br>
                                <table width="100%" cellspacing="0" cellpadding="0" border="0">
							    	<tbody>
										<tr>
											<td>NACEC :</td>
											<td align="right"><span style="float:right;margin: 0 23px 0 0; display:block;">'.$tradefloor['d_nace_group_id'].'</span></td>
										</tr>
										<tr>
											<td>NACED:</td>
											<td align="right"><span style="float:right;margin: 0 23px 0 0; display:block;">'.$tradefloor['d_nace_id'].'</span></td>
										</tr>
									</tbody>
								</table>
                                Experian Risk Value : <span style="float:right;margin: 0 23px 0 0;">'.$tradefloor['debtor_risk'].'%</span><br>
                                Experian Credit Limit : <span style="float:right;margin: 0 35px 0 0;">'.$tradefloor['currency_code'].$debtor_limit.'</span><br>
                                <br>
                                <br>
                                <p> <a href="#">
                                  <input type="button" class="buy_repo" value="Buy Report" name="buyreport">
                                  </a></p></td>
                
                 <td align="left" width="29%" valign="top" style="line-height: 18px;">
				  
				  				<b class="black">Trade Details</b><br>
				  				Trade ID: <a href="javascript:void(0);" style="color:#0033FF; font-size:11px; text-decoration:underline;" onclick=\'return openWin("'.$tradefloor['invoice_id'].'",'.$height.',1);\'>'.$tradefloor['trade_reference_id'].'</a> <br>
								Sales Type: <b class="black">'.$tradefloor['type_name'].'</b> <br>
								<table width="100%" border="0" cellspacing="0" cellpadding="1">
								  <!--<tr>
									<td>Face Value :</td>
									<td align="right"> '.$face_value.'</td>
								  </tr>-->';
				  				

                                
                                
                                
                                
                                if($tradefloor['sales_type'] =="2"){
									
									$return = $tradefloor['face_value'] -7;
									$val_return = number_format($return, 2, '.', ',');
							

									$yield 			= number_format($tradefloor['yield'],'3','.',',');
									
									$output .=' <tr>
													<td>Purchase Price : </td>
													<td align="right">'.$tPurchasePrice.'</td>
												</tr>';
												
									$output .=' <tr>
													<td>Percentage Offered : </td>
													<td align="right">'.$tradefloor['max_thirty_day_reserve'].'</td>
												</tr>';
									$output .=' <tr>
													<td>Value Returned : </td>
													<td align="right">'.$valReturn.'</td>
												</tr>';
									$output .=' <tr>
													<td><b>Yield :</b> </td>
													<td align="right"><b>'.$yield.'%</b></td>
												</tr>';
									$output .=' <tr>
													<td>Yield Value :</td>
													<td align="right">'.$yieldValue.'</td>
												</tr>';
												
									if($tradefloor['buy_out'] == 1) {
										$output .='	<tr>
														<td colspan="2"><b class="black"> Buy Out Details</b></td>
													</tr>';

										$output .=' <tr>
														<td>Percentage Offered :</td>
														<td align="right">'.$tradefloor['buy_max_thirty_day_reserve'].'</td>
													</tr>';
										$output .=' <tr>
														<td><b>Yield :</b> </td>
														<td align="right"><b>'.number_format($tradefloor['buy_yield'],'3','.','').'%</b>
														</td>
													</tr>';
									}
									
									
                                }elseif($tradefloor['sales_type'] =="3"){
									
									$return = $tradefloor['face_value'] -7;
									$val_return = number_format($return, 2, '.', ',');
							

									$yield 			= number_format($tradefloor['yield'],'3','.',',');
									$output .=' <tr>
													<td>Purchase Price : </td>
													<td align="right">'.$tPurchasePrice.'</td>
												</tr>';
												
									$output .=' <tr>
													<td>Percentage Offered : </td>
													<td align="right">'.$tradefloor['max_thirty_day_reserve'].'</td>
												</tr>';
									$output .=' <tr>
													<td>Value Returned : </td>
													<td align="right">'.$valReturn.'</td>
												</tr>';
									$output .=' <tr>
													<td><b>Yield :</b> </td>
													<td align="right"><b>'.$yield.'%</b></td>
												</tr>';
									$output .=' <tr>
													<td>Yield Value :</td>
													<td align="right">'.$yieldValue.'</td>
												</tr>';
									$output .=' <tr>
													<td>Non-Performance Yield :</td>
													<td align="right">'.$non_yield.'</td>
												</tr>';
												
												
												
									if($tradefloor['buy_out'] == 1) {
										$output .='	<tr>
														<td colspan="2"><b class="black"> Buy Out Details</b></td>
													</tr>';

										$output .=' <tr>
														<td>Percentage Offered :</td>
														<td align="right">'.$tradefloor['buy_max_thirty_day_reserve'].'</td>
													</tr>';
										$output .=' <tr>
														<td><b>Yield :</b> </td>
														<td align="right"><b>'.number_format($tradefloor['buy_yield'],'3','.','').'%</b>
														</td>
													</tr>';
										$output .=' <tr>
													<td>Non-Performance Yield :</td>
													<td align="right">'.$buy_non_yield.'</td>
												</tr>';
									}
									
									
                            
									
                                }else{
									
									$checked='';
									if($tradefloor['debx'] =='1'){
										$checked 	= 'checked="true"';	
										$return 	= $tradefloor['face_value'] -7 - 50 ;
									}else{
										$return 	= $tradefloor['face_value'] -7;	
									}
									$val_return		= $tradefloor['currency_code'].number_format($return, 2, '.', ',');
									
									$yield 			= number_format($tradefloor['yield'],'3','.',',');
									
									
									$output .=' <tr>
													<td>Price Offered : </td>
													<td align="right">'.$tradefloor['currency_code'].number_format($min_advance, 2, '.', ',').'</td>
												</tr>';
									$output .=' <tr>
													<td>Value Returned : </td>
													<td align="right">'.$tradefloor['currency_code'].number_format($tradefloor['return'],'2','.',',').'</td>
												</tr>';
									$output .=' <tr>
													<td><b>Yield :</b> </td>
													<td align="right"><b>'.$yield.'%</b></td>
												</tr>';
												
									$output .= '<tr>
													<td colspan="2">
														<p style="font-size:11px;">
															<input type="checkbox" id="debx" name="debx" value="1" '.$checked.' readonly="readonly"> Use <a style="color:#0033FF; font-size:11px; text-decoration:underline;" onclick="javascript:window.open(\''.Base_actions::tokenUrl('/exchange-help/collection').'\',\'\',\'scrollbars=yes,width=1000,height=800\');" href="javascript:void(0);">ETR Collection Service</a>
														</p>
													</td>
													<td>&nbsp;</td>
												</tr>';


									if($tradefloor['buy_out'] == 1) {
										$output .='	<tr>
														<td colspan="2"><b class="black"> Buy Out Details</b></td>
													</tr>';

										$output .=' <tr>
														<td>Price Offered :</td>
														<td align="right">'.$tradefloor['currency_code'].number_format($tradefloor['buy_min_advance'], 2, '.', ',').'</td>
													</tr>';
										$output .=' <tr>
														<td><b>Yield :</b> </td>
														<td align="right"><b>'.number_format($tradefloor['buy_yield'],'3','.','').'%</b>
													</td>
													</tr>';
									}
                                }
                                
                                $output .='</table></td>
                  			<td align="left" valign="top" style="line-height: 18px;  padding: 0px 5px;">
								<b class="black">Time</b><br>
								
								<table width="100%" border="0" cellspacing="0" cellpadding="0">
								  <tr>
									<td>Trade is open :</td>
									<td align="right">'.$tradefloor['c_days'].'D:'.$tradefloor['c_hours'].'H:'.$tradefloor['c_minutes'].'M
									</td>
								  </tr>
								  <tr>
									<td>Payment Terms :</td>
									<td align="right">'.$tradefloor['payment_terms'].' Days</td>
								  </tr>
								  <tr>
									<td> Trade Authorised :</td>
									<td align="right">'.$tradefloor['authorisedday'].'</td>
								  </tr>
								  <tr>
									<td>Expected Date:</td>
									<td align="right">'.$tradefloor['expected_date'].'</td>
								  </tr>
								  <tr>
									<td>&nbsp;</td>
									<td align="right">&nbsp;</td>
								  </tr>
								   <tr>
									<td>Settled Date:</td>
									<td align="right"><!--'.$tradefloor['expected_date'].'--></td>
								  </tr>';
								
                                $days = $tradefloor['exp_days'];
								$week = str_replace(".00","",number_format(($days / 7), 2, '.', ''));
								$months = str_replace(".00","",number_format(($days / 30), 2, '.', ''));
								$quaters = str_replace(".00","",number_format(($days / 90), 2, '.', ''));
								if($tradefloor['sales_type'] !="1"){
                                $output .='
								  <tr>
									<td aign="left" >Actual Trade:</td>
									<td align="right"><!--'.$days.' Days--></td>
								  </tr>
								  <!--<tr>
									<td align="right" colspan="2">'.$week.' Weeks</td>
								  </tr>
								  <tr>
									<td align="right" colspan="2">'.$quaters.' Quarters</td>
								  </tr>-->';
								}
								
								 $output .='
								   <!--<tr>
									<td>Time Remaining:</td>
									<td align="right"><span style="font-size:11px;font-weight:bold;"> '.$tradefloor['days'].'D:'.$tradefloor['hours'].'H:'.$tradefloor['minutes'].'M </span></td>
								  </tr>-->
                                </table> ';
                                
                                
                              
                                
                                
							$output.='</td></tr>
									</tbody>
								</table>
							</li>
						 </ul>
						</div></div>
					</td>
				</tr>';
				$i++;


		}

		return $output.'<style> .ClsFloor li, .ClsFloor li span , .ClsFloor li span b { font-size:11px !important; } .grays_bg1 li { float:left; line-height:35px; }</style>'; }
}
?>