This function credits accounts earnings based ont eh plan they have chosed but what i am doing is add ing the part to chk to see if the end_date is equal to the current date if it is then return the earnings plus the orginal amount invested.
Here is the orginal function, then i will show you what the function looks like now
Code: Select all
function credit_account($account, $investment, $rate)
{
global $debug;
$earnings = $investment * $rate / 100;
$query = "UPDATE accounts
SET acct_balance = acct_balance + {$earnings},
earned_total = earned_total + {$earnings}
WHERE id = {$account}";
if ($debug === TRUE)
{
echo nl2br($query) . "<br /><br />";
}
else
{
mysql_query($query) or die(mysql_error());
}
this is what i have now shown below.
Code: Select all
function credit_account($account, $investment, $rate)
{
$q = mysql_query("SELECT * FROM package_settings WHERE id='1'") or die(mysql_error());
$pack_settings = mysql_fetch_array($q, MYSQL_ASSOC);
@mysql_free_result($q);
$today = date("Y-m-d");
global $debug;
if($pack_settings['return_principal']=='1')
{
echo 'feature is on';
if($row['end_date'] == $today)
{
echo 'today is the end';
//add back invested amount
$earnings = $investment * $rate / 100 + $investment;
$query = "UPDATE accounts
SET acct_balance = acct_balance + {$earnings},
earned_total = earned_total + {$earnings}
WHERE id = {$account}";
} else {
$earnings = $investment * $rate / 100;
$query = "UPDATE accounts
SET acct_balance = acct_balance + {$earnings},
earned_total = earned_total + {$earnings}
WHERE id = {$account}";
if ($debug === TRUE)
{
echo nl2br($query) . "<br /><br />";
}
else
{
mysql_query($query) or die(mysql_error());
}
}
}
}
the problem I think or have narrowed it down to is everything is fine BUT its not chking the end date and there is a function above this one that does the following.
Code: Select all
function get_account_plans($account)
{
$query = "SELECT inv.id, inv.username,inv.user_id,inv.plan_id,inv.plan_name, inv.total_invest, inv.rate, inv.`date`,inv.end_date,
plans.parent, packages.days
FROM investments AS inv
INNER JOIN plans ON inv.plan_id = plans.id
INNER JOIN packages ON plans.parent = packages.id
WHERE inv.user_id = {$account}
AND inv.end_date > NOW()";
$result = mysql_query($query);
$plans = array();
while ($row = mysql_fetch_assoc($result))
{
$plans[] = $row;
}
return $plans;
}
Thanks