Custom Sugar Logic function for retrieving YTD value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* File: ./custom/include/Expressions/Expression/String/GetYTDValueExpression.php */ | |
require_once('include/Expressions/Expression/String/StringExpression.php'); | |
class GetYTDValueExpression extends StringExpression | |
{ | |
function evaluate() { | |
$account_id = $this->context->id; | |
$q = "select round(sum(amount)) as ytdvalue from opportunities o "; | |
$q .= "join accounts_opportunities ao "; | |
$q .= "on o.id = ao.opportunity_id "; | |
$q .= "and ao.account_id = '{$account_id}' "; | |
$q .= "and ao.deleted = 0 "; | |
$q .= "and o.deleted = 0 "; | |
$q .= "and o.sales_stage = 'Closed Won' "; | |
$q .= "and year(o.date_entered) = year(curdate()) "; | |
$results = $this->context->db->query($q, true); | |
$row = $this->context->db->fetchByAssoc($results); | |
$ytdvalue = $row['ytdvalue']; | |
return $ytdvalue; | |
} | |
static function getJSEvaluate() { | |
return <<<EOQ | |
var s = ''; | |
return s; | |
EOQ; | |
} | |
static function getOperationName() { | |
return "GetYTDValue"; | |
} | |
static function getParamCount() { | |
return 0; | |
} | |
} | |
?> |
My original thought was to use SugarQuery for it but then shied away from it as I still need the RAW on the SELECT to use SUM(). I'll revisit over the next couple of days and advise.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any way to update this to use SugarQuery API?