|
I need help with a PHP code for an investment fund Historical NAV. The formulas are pretty straight forward I just have no experience with PHP I know where the file is and I've done C++ programs before I just am not familiar with PHP and its basics. Not to mention I didn't make the code so working on it is more confusing than starting froms cratch.
Basically what we have in the website is 4 columns.
Gross Nav: Taken from the Database
Net Nav: Useless column, same as Gross Nav
Return: Not sure what this column does, but it's useless
Since Inception: This column is correct
We want to change them to something like below:
NAV Value (taken from the Database)
Monthly (the % change -/+ from last month)
YTD (the % change -/+ since the beginning of the year)
Since Inception (the % change -/+ since the beginning)
All Except NAV Value should have % sign in them.
The formulas are pretty simple, I can make them myself. It's the editing of the code that's already working and showing in the website is the tricky part. I think I know which .php file to be edited. I would greatly appreciate the help.
Below is the php code I think that's invovled with the calculations:
<?php
require_once('db.class.php');
$db = new MySQLConnect();
$stmt='SELECT v_cost_price.cost_date,
v_cost_price.fund_code,
v_cost_price.cost_price,
v_cost_price.cost_description,
v_funds.fund_name,
v_cost_price.gross_nav,
v_cost_price.total_units,
v_cost_price.dividend_units,
v_cost_price.cash_balance,
v_cost_price.investment_balance,
v_cost_price.other_assets,
v_funds.fund_currency,
v_cost_price.cost_final,
v_funds.fund_begin_price,
v_funds.fund_unit_format,
v_funds.fund_nav_format,
IfNull((SELECT c3.gross_nav FROM v_cost_price c3
WHERE c3.fund_code = v_cost_price.fund_code
AND year(c3.cost_date) = Year(date_add(v_cost_price.cost_date, INTERVAL -1 MONTH))
AND month(c3.cost_date) = month(date_add(v_cost_price.cost_date, INTERVAL -1 MONTH))
AND day(c3.cost_date) =
(SELECT max(day(c4.cost_date) ) FROM v_cost_price c4
WHERE c4.fund_code = c3.fund_code
AND year(c4.cost_date) = year(c3.cost_date)
AND month(c4.cost_date) = month(c3.cost_date))),0) as prior_month
FROM v_cost_price,
v_funds
WHERE ( v_funds.fund_code = v_cost_price.fund_code ) and
( ( v_funds.fund_code = '. $_POST['fund_code'].' ) )
ORDER BY v_funds.fund_name ASC,
v_cost_price.cost_date ASC';
$rs=$db->MySQLQuery($stmt);
/*
$rs = $db->MySQLQuery("SELECT v_cost_price.cost_date,
v_cost_price.fund_code,
v_cost_price.cost_price,
v_cost_price.cost_description,
v_funds.fund_name,
v_cost_price.gross_nav,
v_cost_price.total_units,
v_cost_price.dividend_units,
v_cost_price.cash_balance,
v_cost_price.investment_balance,
v_cost_price.other_assets,
v_funds.fund_currency,
v_cost_price.cost_final,
v_funds.fund_begin_price,
v_funds.fund_unit_format,
v_funds.fund_nav_format,
IfNull((SELECT c3.gross_nav FROM v_cost_price c3
WHERE c3.fund_code = v_cost_price.fund_code
AND year(c3.cost_date) = Year(date_add(v_cost_price.cost_date, INTERVAL -1 MONTH))
AND month(c3.cost_date) = month(date_add(v_cost_price.cost_date, INTERVAL -1 MONTH))
AND day(c3.cost_date) =
(SELECT max(day(c4.cost_date) ) FROM v_cost_price c4
WHERE c4.fund_code = c3.fund_code
AND year(c4.cost_date) = year(c3.cost_date)
AND month(c4.cost_date) = month(c3.cost_date))),0) as prior_month
FROM v_cost_price,
v_funds
WHERE ( v_funds.fund_code = v_cost_price.fund_code ) and
( ( v_funds.fund_code = '500' ) )
ORDER BY v_funds.fund_name ASC,
v_cost_price.cost_date ASC");
*/
$resp = '';
$year= '';
$i=0;
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC))
{
$return=$row["gross_nav"]-$row["prior_month"];
$since_inception=($row["gross_nav"])-($row["fund_begin_price"])/($row["fund_begin_price"]);
$performance=((($row["gross_nav"])-1)*100);
$resp .= '<nav date="'.$row["cost_date"].'" gross_nav="'.$row["gross_nav"].'" dividend="'.$row["dividend_units"].'" net_nav="'.$row["gross_nav"].'" return="'.round($return,4).'" since_inception="'.round($performance,4).'%"/>';
}
sendResponse($resp);
//////////////////////////////////////////////////////////////
function sendResponse($resp)
{
if($resp == "404")
{
header('HTTP/1.1 404 Not Found');
}
else
{
header('Content-Type: text/xml; charset=utf-8');
echo "<result>".$resp."</result>";
}
}
|