function clientpretask_tabs($enabled_pages,$clientpropertyid = 0, $url = '')
{
// ENABLED_PAGES COMES FROM clientpretask.php
// GLOBAL VARIABLE TO CHECK IF TABS ARE DISPLAYED
global $clientpretask_tabs_displayed;
// IF THEY ARE DISPLAYED, WE'RE DONE, ELSE SET THE VARIABLE
if($clientpretask_tabs_displayed)
return false;
else
$clientpretask_tabs_displayed = 1;
$clientcompany_tabs['all'] = 'All';
$clientcompany_tabs['my'] = 'My';
foreach($clientcompany_tabs as $key => $tab)
if(!$enabled_pages[$key])
unset($clientcompany_tabs[$key]);
?>
foreach($clientcompany_tabs as $key => $label){
// SET SELECTED TAB
if($key == $_GET['page'] || (!isset($_GET['page']) && strcasecmp($key, 'All') == 0))
$selected = true;
else
$selected = false;
if($url == '')
{
echo "- ";
echo "";
echo $label;
echo "";
}
elseif($url == 'action')
{
echo "
- ";
echo "";
echo $label;
echo "";
}
echo "
";
} ?>
}
function get_preferredvendorarr($zipcode, $categoryid=0)
{
if (!db_number($categoryid))
return false;
$sql = "
select preferredvendorid, perferredvendorname, cnt as preferredvendoropentaskcount
from (
select staffid, 0 accountstaffid, 0 externaluserid, 0 assignmentaliasclientstaffid, stafffname||' '||stafflname perferredvendorname from tblstaff
union
select 0 staffid, accountstaffid, 0 externaluserid, 0 assignmentaliasclientstaffid, accountstafffname||' '||accountstafflname perferredvendorname from tblaccountstaff
union
select 0 staffid, 0 accountstaffid, externaluserid, 0 assignmentaliasclientstaffid, externaluserfname||' '||externaluserlname perferredvendorname from tblexternaluser
union
select 0 staffid, 0 accountstaffid, 0 externaluserid, assignmentaliasclientstaffid, assignmentaliasclientstafffname||' '||assignmentaliasclientstafflname perferredvendorname from tblassignmentaliasclientstaff
) tblvnames
join (
--get the preferred vendor that matches -- join by all the ids, there should only every be one entry returned here
select *
from tblpreferredvendor
where preferredvendorzip = ".db_tick($zipcode)."
and lineitemcategoryid = ".db_number($categoryid)."
and lineitemcategoryid > 0
and clientcompanyid = ".clientcompanyid()."
) tblpreferredvendor using (staffid, accountstaffid, externaluserid, assignmentaliasclientstaffid)
left join(
--get a count of all of the open tasks, grouped by the ids and category
select count(1) as cnt, staffid, accountstaffid, externaluserid, assignmentaliasclientstaffid, lineitemcategoryid
from tblclienttask
join tblclientpretask using (clientpretaskid,clientcompanypropertyassignmentid)
join (select lineitemcategoryid, lineitemname from tbllineitemcategoryentry where clientcompanyid = ".clientcompanyid().")tbllineitemcategoryentry on (lower(lineitemname) = lower(clientpretaskname))
join tblclientcompanypropertyassignment using (clientcompanypropertyassignmentid)
where 0=0
--and tblclientpretask.lineitemcategoryid = tblpreferredvendor.lineitemcategoryid
and get_clienttask_statuskey(clienttaskduedate, clienttaskcompleteddate, clienttaskcompleteapproveddate, clienttaskrevokeddate, clienttaskholddate::date) in ('open', 'warning', 'pastdue')
group by staffid, accountstaffid, externaluserid, assignmentaliasclientstaffid, lineitemcategoryid
) tblopencountsbycatid using (staffid, accountstaffid, externaluserid, assignmentaliasclientstaffid)
";
//d(sql, $sql);
$qry = db_query($sql);
return $qry;
}
function get_specificlineitempricing($lineitemcategoryentryid, $zipregion, $clientcompanyclientid)
{
$retval = array();
$lineitemcategoryentryid = db_number($lineitemcategoryentryid);
if (!$lineitemcategoryentryid)
return $retval;
$retval = db_query("
select lineitempricingregion, clientcompanyclientid, lineitempricingvendorprice, lineitempricingclientprice
from tbllineitempricing
where lineitemcategoryentryid = " . $lineitemcategoryentryid
);
$retrow = null;
foreach($retval as $row)
{
if($row[lineitempricingregion] == $zipregion && $row[clientcompanyclientid] == $clientcompanyclientid)
{//Best possible match.
$retrow = $row;
break;
}
else if($row[lineitempricingregion] == $zipregion || $row[clientcompanyclientid] == $clientcompanyclientid)
{//Next best match; keep looking.
$retrow = $row;
}
else if($retrow === null)
{//Least preferred match; only take if no other choice.
$retrow = $row;
}
}
return $retrow;
}
/**
* @name format_alphanumsinglespace
* @param &$val which is passed by reference, so function works on argument without the need to use return value; $val is modified with all non-alphanumeric characters stripped out, and each section of contiguous whitespace modified to a single space
* @return None, so will not work if somebody does not realize that it is pass by reference. Need pass by reference so will work as a callback function for various php array functions, like array_walk.
*/
function format_alphanumsinglespace(&$val)
{
$val = preg_replace("/[^0-9a-zA-Z ]/", "", $val);
$val = preg_replace('!\s+!', ' ', $val);
$val = trim($val);
}