File: /www/exchange2/exchange/classes/Model/MPension.php
<?php
include_once('admin/classes/Model/traders_actions.php');
class Model_MPension extends Traders_actions
{
function showRetailInvestors($flg='1')
{
$query = new Bin_Query();
$query->executeQuery("SELECT IF(register_type=1,organization_name,GROUP_CONCAT(DISTINCT CONCAT(contact_details.first_name,' ',contact_details.last_name) SEPARATOR ' & ')) as realname,t.status as status,t.temp_reg_id as uid, SUM(investor_investments.amount * IF (investor_investments.currency_id=1,1,currency_rates.currency_rate )) as amount, GROUP_CONCAT(investor_investments.investment_group) as investment_groups, t.user_id as investor_id, 'EUR' as currency_code, t.ref_id, COUNT(investor_investments.investment_id) as rpa_qty
FROM `temp_registration` as t
LEFT JOIN investor_investments ON investor_investments.investor_id = t.user_id AND investor_investments.investment_type=".INVESTMENT_RPA."
LEFT JOIN currencies ON currencies.currency_id = investor_investments.currency_id
LEFT JOIN currency_rates ON currency_rates.currency_id = investor_investments.currency_id AND currency_rates.currency_date = investor_investments.investment_date
LEFT JOIN contact_details ON contact_details.temp_reg_id = t.temp_reg_id AND (contact_details.contact_flag=3 OR (contact_details.contact_flag=0 AND contact_details.bank_id=0))
WHERE t.dp_type=1 AND t.dp_organisation=".$_SESSION['org_id']."
GROUP BY t.user_id
ORDER BY realname");
$recordSet = $query->records;
if($flg == 2)
{
return count($recordSet);
}
include_once('admin/classes/Model/investor_actions.php');
$investor_actions = new Investor_actions();
foreach($recordSet as $index=>$investment)
{
if (!is_null($investment['investment_groups']))
{
$recordSet[$index]['current_value']=0;
$recordSet[$index]['renewal']='2038-01-01';
$is_completed=TRUE;
$total_amounts=0;
foreach(explode(',',$investment['investment_groups']) as $investment_group)
{
$details=$investor_actions->getInvestmentDetails($investment_group,$investment['investor_id']);
$recordSet[$index]['current_value']+=($details['amount']+$details['yield']);
$total_amounts+=$details['amount'];
if (!$details['is_completed'])
{
$recordSet[$index]['renewal']=date('Y-m-d',min(strtotime($details['expected_date']),strtotime($recordSet[$index]['renewal'])));
}
elseif($details['is_completed'] AND $details['amount']!=0)
{
$recordSet[$index]['renewal']=date('Y-m-d',min(strtotime($details['completed_at']),strtotime($recordSet[$index]['renewal'])));
}
$is_completed=($details['is_completed'] AND TRUE);
if (!is_null($details['renewal_date']))
{
$recordSet[$index]['last_renewal']=$details['renewal_date'];
}
}
if ($is_completed AND $total_amounts==0)
{
$recordSet[$index]['renewal']='-';
}
}
}
return $recordSet;
}
function showRetailInvusersView()
{
$query = new Bin_Query();
$query->executeQuery("SELECT t.*,c.work_address_id,c.birth_date,a.*,r.*,IFNULL(state_master.state_name,a.address_state) as state_name, country_mas.country_name, currencies.currency_code
FROM temp_registration t
LEFT JOIN contact_details c ON t.temp_reg_id=c.temp_reg_id
LEFT JOIN address_details a ON c.work_address_id=a.address_id
LEFT JOIN temp_retailer r ON t.temp_reg_id=r.temp_reg_id
LEFT JOIN state_master ON state_master.state_id = a.address_state
LEFT JOIN country_mas ON country_mas.country_id = a.address_country
LEFT JOIN currencies ON currencies.currency_id = t.currency_id
WHERE t.temp_reg_id='".$_GET['uid']."' AND t.dp_organisation = '".$_SESSION['org_id']."'
LIMIT 1 ");
$recordSet = $query->records[0];
if(count($recordSet) == 0)
{
if($_REQUEST['view'] == 'sta')
{
header('Location: index.php?do=pensioninvestors&page='.$_REQUEST['pg']);
exit(0);
}
else
{
header('Location: index.php?do=pensioninvestors&page='.$_REQUEST['pg']);
exit(0);
}
}
require_once ROOT_FOLDER.'/classes/Storage.php';
$storage = Storage_Repository::get(Storage_Repository::INV_DOCS);
if ($recordSet['pasport'])
{
$recordSet['pasport']=$storage->url($recordSet['pasport']);
}
if ($recordSet['bill'])
{
$recordSet['bill']=$storage->url($recordSet['bill']);
}
require_once ROOT_FOLDER.'/admin/classes/Model/MRetailInvestor.php';
$recordSet['additional_names']=Model_MRetailInvestor::getInvestorAdditionalNames($recordSet['temp_reg_id']);
return $recordSet;
}
function checkInvestor($investor_id)
{
$query = new Bin_Query();
$query->executeQuery('SELECT temp_registration.ref_id
FROM temp_registration
WHERE dp_organisation='.$_SESSION['org_id'].' AND user_id='.$investor_id);
return count($query->records)>0?TRUE:FALSE;
}
}
?>