function getAmountSumByUserIdAndEntryNameIdAndDate($id, $entry_name_id, $date = NULL, $exclude_id = NULL, $where = NULL, $order = NULL) { if ($id == '') { return FALSE; } if ($entry_name_id == '') { return FALSE; } if ($date == '') { $date = TTDate::getTime(); } $pplf = new PayPeriodListFactory(); $pslf = new PayStubListFactory(); $psalf = new PayStubAmendmentListFactory(); $ph = array('date' => $this->db->BindTimeStamp($date), 'user_id' => $id, 'entry_name_id' => $entry_name_id, 'exclude_id' => (int) $exclude_id, 'user_id2' => $id, 'entry_name_id2' => $entry_name_id, 'date2' => $date); $query = ' select sum(amount) as amount, sum(units) as units from ( select sum(amount) as amount, sum(units) as units from ' . $this->getTable() . ' as a, ' . $pslf->getTable() . ' as b where a.pay_stub_id = b.id AND b.pay_period_id in (select id from ' . $pplf->getTable() . ' as y where y.pay_period_schedule_id = ( select pay_period_schedule_id from ' . $pplf->getTable() . ' as z where z.id = b.pay_period_id ) AND y.start_date < ? AND y.deleted=0) AND b.user_id = ? AND a.pay_stub_entry_name_id = ? AND a.id != ? AND a.deleted = 0 AND b.deleted=0 UNION select sum(amount) as amount, sum(units) as units from ' . $psalf->getTable() . ' as m where m.user_id = ? AND m.ytd_adjustment = 1 AND m.pay_stub_entry_name_id = ? AND m.effective_date < ? AND m.deleted=0 ) as tmp_table '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order); $row = $this->db->GetRow($query, $ph); if ($row['amount'] === NULL) { $row['amount'] = 0; } if ($row['units'] === NULL) { $row['units'] = 0; } Debug::Arr($ph, 'Place Holders ', __FILE__, __LINE__, __METHOD__, 10); Debug::text('Over All Sum for ' . $entry_name_id . ': Amount ' . $row['amount'] . ' Units: ' . $row['units'], __FILE__, __LINE__, __METHOD__, 10); return $row; }