$compare) { if($compare===0 || $compare ==='0') //let values set to 0 continue ; elseif($compare=='' && $value) continue; // dont process it if compare is not set but a value is if($compare<=$value) // if the value in the returned array is less than the $value evaulating against , then include it in this array return $grade; } return 0; } function offerescalationlevel_dollar($clientcompanyclientid, $grade, $value, $matrixtypeshortname="", $rowkey="", $comparetype="",$groupid="") { if(($matrixtypeshortname == "") && ($groupid=="")) $level = match_escalationlevel($clientcompanyclientid, 'counterofferapproval', netsellingpricedollarreduction, $grade, $value); else $level = match_escalationlevel($clientcompanyclientid, $matrixtypeshortname, $rowkey, $grade, $value, $comparetype, $groupid); //d($level); return $level; } function offerescalationlevel_percent($clientcompanyclientid, $grade, $value, $matrixtypeshortname="", $rowkey="", $comparetype="",$groupid='') { if(($matrixtypeshortname == "") && ($groupid=="")) $level = match_escalationlevel($clientcompanyclientid, 'counterofferapproval', netsellingpricepercentreduction, $grade, $value); else $level = match_escalationlevel($clientcompanyclientid, $matrixtypeshortname, $rowkey, $grade, $value, $comparetype, $groupid); //d($level); return $level; } function match_escalationlevel($clientcompanyclientid, $shortname, $rowkey, $grade, $value, $comparetype="", $groupid='') { $levels = get_escalationlevels($clientcompanyclientid, $shortname , $rowkey, $grade, $groupid); //segment is required //loop through all levels from top to bottom until a match is made. //example array level 1=>5%, 2=>10%, 3=>20% //if the value is 6% the system will loop through the levels (in reverse) from 7 to 1 and see if 20 is less than 6, then 10 is less than 6, and then 5 is less than 6, which would return 1 //if the value is 10% the system will loop through the levels (in reverse) from 7 to 1 and see if 20 is less than 10, then 10 is less than 10, and then 5 is less than 10, which would return 1 //if the value is 5% the system will loop through the levels (in reverse) from 7 to 1 and see if 20 is less than 5, then 10 is less than 5, and then 5 is less than 5, which would return 0 $levels = array_reverse($levels,preservekeys); //d(levels,$levels); foreach($levels as $level=>$compare) { if(trim($compare)==='') continue; //echo "compare:$compare"; //d(compare,$compare); //d(value,$value); // MB - 2 / 26 we went through and made a business decision per Charis, that the $compare<$value should NOT HAVE an = sign. which makdes it so that it is everything OVER the value entered at each level, but not including that number if($comparetype=="") { //d("$compare< $value", "level: $level"); if($compare < $value) // if the value in the returned array is less than the $value evaulating against , then include it in this array return $level; } else { if(strstr($comparetype, 'Reduction')) { if(($value<= 0) && ($compare= 0) && ($compare<$value)) return $level; } elseif($compare < $value) // if the value in the returned array is less than the $value evaulating against , then include it in this array return $level; } } return 0; // if no level matches, then return the level 0 (no escalation level). } function is_grouprequestescalationneeded($groupid, $groupentryid, $clientcompanypropertyid, $newattributevalue) { //d("Function: is_grouprequestneedsescalation"); //d(groupid,$groupid); //d(groupentryid,$groupentryid); //d(clientcompanypropertyid,$clientcompanypropertyid); //d(newattributevalue,$newattributevalue); if(!$groupid || !is_numeric($groupid)) { ddie('Invalid Group ID'); //set_message('Invalid Group ID', 'error'); //return FALSE; } if(!$groupentryid || !is_numeric($groupentryid)) { ddie('Invalid Group Entry ID'); //set_message('Invalid Group Entry ID', 'error'); //return FALSE; } if(!$clientcompanypropertyid || !is_numeric($clientcompanypropertyid)) { ddie('Invalid Property ID'); //set_message('Invalid Property ID', 'error'); //return FALSE; } $groupentry=get_propertyextensiongroupentry($groupid, $groupentryid); //d(groupentry,$groupentry); if($groupentry) { if(stristr($groupentry[propertyextensiongrouptypeattr1label], "Compare Type")) { if(strstr($groupentry[propertyextensiongroupentrytypeattr1value], 'None')) return FALSE; //Check if there is an attribute to compare to beside itself. if(!$groupentry[propertyextensiongroupentrytypeattr2value] || ($groupentry[propertyextensiongroupentrytypeattr2value]==-1)) $currentattributevalue=get_clientpropertyextensionentry($clientcompanypropertyid,$groupentry[propertyextensionkey]); else $currentattributevalue=getgroupcompare_clientpropertyextensionentry($clientcompanypropertyid,$groupentry[propertyextensiongroupentrytypeattr2value]); //d(currentattributevalue,$currentattributevalue); //Commented this section to allow text comparison /* if(!is_numeric($newattributevalue)) { //Currently only numeric values for compare types are supported. //d(newattributevalue,$newattributevalue); $newattributevalue=db_number($newattributevalue); if(!is_numeric($newattributevalue)) { set_message('New Value Must be a Number', 'error'); return FALSE; } } if(!is_numeric($currentattributevalue)) { //Currently only numeric values for compare types are supported. //d(currentattributevalue,$currentattributevalue); set_message('New Value Must be a Number', 'error'); return FALSE; } */ if(is_null($currentattributevalue)) $currentattributevalue=0; if(is_null($newattributevalue)) $newattributevalue=0; $testcurrentattributevalue=trim(str_replace(",","",$currentattributevalue)); $testcurrentattributevalue=trim(str_replace("\$","",$testcurrentattributevalue)); $testnewattributevalue=trim(str_replace(",","",$newattributevalue)); $testnewattributevalue=trim(str_replace("\$","",$testnewattributevalue)); if(!is_numeric($testcurrentattributevalue) || !is_numeric($testnewattributevalue)) { if(!$currentattributevalue) $currentattributevalue=''; if(!$newattributevalue) $newattributevalue=''; $pricediff=strcmp($currentattributevalue, $newattributevalue); //$pricediff=$newattributevalue - $currentattributevalue; if(strlen($currentattributevalue)) $percentdiff = ((strlen($newattributevalue)-strlen($currentattributevalue))/strlen($currentattributevalue))*100; //Return the percent difference in the stringlength. else { if($pricediff>=0) $percentdiff=100; else $percentdiff=-100; } } else { $currentattributevalue=db_number($currentattributevalue); $newattributevalue=db_number($newattributevalue); $pricediff=$newattributevalue - $currentattributevalue; if($currentattributevalue && $currentattributevalue>0) $percentdiff = ($pricediff/$currentattributevalue)*100; else { if($pricediff>=0) $percentdiff=100; else $percentdiff=-100; } } $property = get_clientcompanyproperty($clientcompanypropertyid); //d(property,$property); $listprice = db_number(get_clientpropertyextensionentry($clientcompanypropertyid,propertyextensionlistprice)); //d(listprice,$listprice); if(!$listprice) $listprice=0; $propertygrade = get_escalationgrade($property[clientcompanyclientid],$listprice); if($propertygrade) $propertygradedescr = "Property Grade: " . strtoupper($propertygrade); //d(listprice,$listprice); d(newattributevalue,$newattributevalue); d(currentattributevalue,$currentattributevalue); //d(propertygrade,$propertygrade); d(pricediff,$pricediff); d(percentdiff,$percentdiff); //d(clientcompanyclientid,$property[clientcompanyclientid]); //d(type,$groupentry[propertyextensiongroupentrytypeattr1value]); //$groupshortname=str_replace("propertyextensiongroup", "", $groupentry[propertyextensiongroupshortname]); $matrixtypeshortname=get_propertyextensiongroup_matrixtype($groupid); /* if(strstr($groupentry[propertyextensiongroupentrytypeattr1value], 'Amount') || strstr($groupentry[propertyextensiongroupentrytypeattr1value], 'Value')) $dollarescalationlevel = groupescalationlevel_dollar($property[clientcompanyclientid],$propertygrade,$pricediff,$matrixtypeshortname,$groupentry[propertyextensionkey],$groupentry[propertyextensiongroupentrytypeattr1value]); elseif(strstr($groupentry[propertyextensiongroupentrytypeattr1value], 'Percent')) $percentescalationlevel = groupescalationlevel_percent($property[clientcompanyclientid],$propertygrade,$percentdiff,$matrixtypeshortname,$groupentry[propertyextensionkey],$groupentry[propertyextensiongroupentrytypeattr1value]); */ if(strstr($groupentry[propertyextensiongroupentrytypeattr1value], 'Amount') || strstr($groupentry[propertyextensiongroupentrytypeattr1value], 'Value')) $dollarescalationlevel = offerescalationlevel_dollar($property[clientcompanyclientid],$propertygrade,$pricediff,$matrixtypeshortname,$groupentry[propertyextensionkey],$groupentry[propertyextensiongroupentrytypeattr1value],$groupid); elseif(strstr($groupentry[propertyextensiongroupentrytypeattr1value], 'Percent')) $percentescalationlevel = offerescalationlevel_percent($property[clientcompanyclientid],$propertygrade,$percentdiff,$matrixtypeshortname,$groupentry[propertyextensionkey],$groupentry[propertyextensiongroupentrytypeattr1value],$groupid); //d(dollarescalationlevel,$dollarescalationlevel); //d(percentescalationlevel,$percentescalationlevel); $escalationlevel=$dollarescalationlevel; if($percentescalationlevel>$escalationlevel) $escalationlevel=$percentescalationlevel; if(!$escalationlevel) { //d("No Escalation is required grade:$propertygrade diff:$pricediff, percent:$percentdiff"); return FALSE; } else { return $escalationlevel; } } else { d("No Escalation is required because this attribute has no comparison type."); return FALSE; } } set_message('No Group Entry', 'error'); return FALSE; } function get_propertygrade($clientcompanyid,$propertyvalue) { //lets get the property grade of this property based on the client and the value $grades = get_propertygrades($clientcompanyid); array_reverse($grades); foreach($grades as $grade=>$valueabove) { if($propertyvalue>$valueabove) break; } return $grade; } function get_propertygrades($clientcompanyid) { return get_matrixentries_column(propertygrade,clientcompany,$clientcompanyid,propertyabovevalue); } function get_escalationcontactapprovers($clientcompanyclientid, $escalationlevel) { if(!$clientcompanyclientid) ddie("Invalid Client Company Client ID"); if(!$escalationlevel && $escalationlevel!==0) ddie("Invalid Escalation Level"); $client = get_clientcompanyclient($clientcompanyclientid); if($escalationlevel==0) return $client[clientcompanyclientescalation][$escalationlevel]; //d(client,$client); $escalationcontacts = $client[clientcompanyclientescalation][$escalationlevel]; //d(escalationcontacts,$escalationcontacts); $clientcompanyclientescalationcontrol=unserialize($client[clientcompanyclientescalationcontrol]); //d(clientcompanyclientescalationcontrol,$clientcompanyclientescalationcontrol); foreach($clientcompanyclientescalationcontrol as $level=>$control) { if($level > $escalationlevel) { //d(level,$level); //d(clientcompanyclientescalation,$clientcompanyclientescalation[$level][contactid()]); //d(control,$control); if($control=='approve_lower') { $approvelower=$client[clientcompanyclientescalation][$level]; //d(approvelower,$approvelower); foreach($approvelower as $contactkey=>$contactvalue) { if(!in_array($contactkey, array_keys($escalationcontacts))) $escalationcontacts[$contactkey]=$contactvalue; } } } } return $escalationcontacts; } function get_lowerescalationcontacts($clientcompanyclientid, $escalationlevel) { if(!$clientcompanyclientid) ddie("Invalid Client Company Client ID"); if(!$escalationlevel && $escalationlevel!==0) ddie("Invalid Escalation Level"); $client = get_clientcompanyclient($clientcompanyclientid); if($escalationlevel==0) return; //d(client,$client); $invitedescalationcontacts = $client[clientcompanyclientescalation][$escalationlevel]; $escalationcontacts = array(); //d(escalationcontacts,$escalationcontacts); $clientcompanyclientescalationcontrol=unserialize($client[clientcompanyclientescalationcontrol]); //d(clientcompanyclientescalationcontrol,$clientcompanyclientescalationcontrol); foreach($clientcompanyclientescalationcontrol as $level=>$control) { if($level < $escalationlevel) { $approvelower=$client[clientcompanyclientescalation][$level]; foreach($approvelower as $contactkey=>$contactvalue) { if(!in_array($contactkey, array_keys($escalationcontacts)) && !in_array($contactkey, array_keys($invitedescalationcontacts))) $escalationcontacts[$contactkey]=$contactvalue; } } } return $escalationcontacts; }