$expense_item_part .= " user_id=\"".$this->userMap[$expense_item['user_id']]."\"";
$expense_item_part .= " client_id=\"".$this->clientMap[$expense_item['client_id']]."\"";
$expense_item_part .= " project_id=\"".$this->projectMap[$expense_item['project_id']]."\"";
- $expense_item_part .= " timesheet_id=\"".$this->timesheetMap[$expense_item['timesheet_id']]."\"";
$expense_item_part .= " name=\"".htmlspecialchars($expense_item['name'])."\"";
$expense_item_part .= " cost=\"".$expense_item['cost']."\"";
$expense_item_part .= " invoice_id=\"".$this->invoiceMap[$expense_item['invoice_id']]."\"";
$user_id = (int) $fields['user_id'];
$client_id = $fields['client_id'];
$project_id = $fields['project_id'];
- $timesheet_id = $fields['timesheet_id'];
$name = $fields['name'];
$cost = str_replace(',', '.', $fields['cost']);
$invoice_id = $fields['invoice_id'];
$created = ', now(), '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', '.$user->id;
$sql = "insert into tt_expense_items".
- " (date, user_id, group_id, org_id, client_id, project_id, timesheet_id, name,".
+ " (date, user_id, group_id, org_id, client_id, project_id, name,".
" cost, invoice_id, approved, paid, created, created_ip, created_by, status)".
" values (".$mdb2->quote($date).", $user_id, $group_id, $org_id, ".$mdb2->quote($client_id).", ".$mdb2->quote($project_id).
- ", ".$mdb2->quote($timesheet_id).", ".$mdb2->quote($name).", ".$mdb2->quote($cost).", ".$mdb2->quote($invoice_id).
+ ", ".$mdb2->quote($name).", ".$mdb2->quote($cost).", ".$mdb2->quote($invoice_id).
", $approved, $paid $created, ".$mdb2->quote($status).")";
$affected = $mdb2->exec($sql);
return (!is_a($affected, 'PEAR_Error'));
$group_id = $user->getGroup();
$org_id = $user->org_id;
- // A shortcut for timesheets.
- if ($options['timesheet_id']) {
- $where = " where ei.timesheet_id = ".$options['timesheet_id']." and ei.group_id = $group_id and ei.org_id = $org_id";
- return $where;
- }
-
// Prepare dropdown parts.
$dropdown_parts = '';
if ($options['client_id'])
if ($options['project_id']) $dropdown_parts .= ' and ei.project_id = '.$options['project_id'];
if ($options['invoice']=='1') $dropdown_parts .= ' and ei.invoice_id is not null';
if ($options['invoice']=='2') $dropdown_parts .= ' and ei.invoice_id is null';
- if ($options['timesheet']==TIMESHEET_NOT_ASSIGNED) $dropdown_parts .= ' and ei.timesheet_id is null';
- if ($options['timesheet']==TIMESHEET_ASSIGNED) $dropdown_parts .= ' and ei.timesheet_id is not null';
+ if (isset($options['timesheet']) && ($options['timesheet']!=TIMESHEET_ALL && $options['timesheet']!=TIMESHEET_NOT_ASSIGNED)) {
+ $dropdown_parts .= ' and 0 = 1'; // Expense items do not have a timesheet_id.
+ }
if ($options['approved']=='1') $dropdown_parts .= ' and ei.approved = 1';
if ($options['approved']=='2') $dropdown_parts .= ' and ei.approved = 0';
if ($options['paid_status']=='1') $dropdown_parts .= ' and ei.paid = 1';
if (($canViewReports || $isClient) && $options['show_invoice'])
array_push($fields, 'i.name as invoice');
if ($options['show_timesheet'])
- array_push($fields, 'ts.name as timesheet_name');
+ array_push($fields, 'null as timesheet_name');
// Prepare sql query part for left joins.
$left_joins = null;
if (($canViewReports || $isClient) && $options['show_invoice'])
$left_joins .= " left join tt_invoices i on (i.id = ei.invoice_id and i.status = 1)";
- // Prepare sql query part for inner joins.
- $inner_joins = null;
- if ($user->isPluginEnabled('ts')) {
- $timesheet_option = $options['timesheet'];
- if ($timesheet_option == TIMESHEET_PENDING)
- $inner_joins .= " inner join tt_timesheets ts on (ei.timesheet_id = ts.id and ts.submit_status = 1 and ts.approve_status is null)";
- else if ($timesheet_option == TIMESHEET_APPROVED)
- $inner_joins .= " inner join tt_timesheets ts on (ei.timesheet_id = ts.id and ts.approve_status = 1)";
- else if ($timesheet_option == TIMESHEET_NOT_APPROVED)
- $inner_joins .= " inner join tt_timesheets ts on (ei.timesheet_id = ts.id and ts.approve_status = 0)";
- else if ($options['show_timesheet'])
- $inner_joins .= " left join tt_timesheets ts on (ei.timesheet_id = ts.id)"; // Left join for timesheet name.
- }
-
$where = ttReportHelper::getExpenseWhere($options);
// Construct sql query for expense items.
- $sql_for_expense_items = "select ".join(', ', $fields)." from tt_expense_items ei $left_joins $inner_joins $where";
+ $sql_for_expense_items = "select ".join(', ', $fields)." from tt_expense_items ei $left_joins $where";
// Construct a union.
$sql = "($sql) union all ($sql_for_expense_items)";
// If we have expenses, query becomes a bit more complex.
if ($options['show_cost'] && $user->isPluginEnabled('ex')) {
- // Prepare sql query part for inner joins.
- $inner_joins = null;
- if ($user->isPluginEnabled('ts') && $options['timesheet']) {
- $timesheet_option = $options['timesheet'];
- if ($timesheet_option == TIMESHEET_PENDING)
- $inner_joins .= " inner join tt_timesheets ts on (ei.timesheet_id = ts.id and ts.submit_status = 1 and ts.approve_status is null)";
- else if ($timesheet_option == TIMESHEET_APPROVED)
- $inner_joins .= " inner join tt_timesheets ts on (ei.timesheet_id = ts.id and ts.approve_status = 1)";
- else if ($timesheet_option == TIMESHEET_NOT_APPROVED)
- $inner_joins .= " inner join tt_timesheets ts on (ei.timesheet_id = ts.id and ts.approve_status = 0)";
- }
$where = ttReportHelper::getExpenseWhere($options);
$sql_for_expenses = "select null as time";
if ($options['show_work_units']) $sql_for_expenses .= ", null as units";
- $sql_for_expenses .= ", sum(cost) as cost, sum(cost) as expenses from tt_expense_items ei $inner_joins $where";
+ $sql_for_expenses .= ", sum(cost) as cost, sum(cost) as expenses from tt_expense_items ei $where";
// Create a combined query.
$combined = "select sum(time) as time";
if (ttReportHelper::groupingBy('project', $options)) {
$join .= ' left join tt_projects p on (ei.project_id = p.id)';
}
- // Prepare inner joins.
- $inner_joins = null;
- if ($user->isPluginEnabled('ts') && $options['timesheet']) {
- $timesheet_option = $options['timesheet'];
- if ($timesheet_option == TIMESHEET_PENDING)
- $inner_joins .= " inner join tt_timesheets ts on (ei.timesheet_id = ts.id and ts.submit_status = 1 and ts.approve_status is null)";
- else if ($timesheet_option == TIMESHEET_APPROVED)
- $inner_joins .= " inner join tt_timesheets ts on (ei.timesheet_id = ts.id and ts.approve_status = 1)";
- else if ($timesheet_option == TIMESHEET_NOT_APPROVED)
- $inner_joins .= " inner join tt_timesheets ts on (ei.timesheet_id = ts.id and ts.approve_status = 0)";
- }
- $join .= $inner_joins;
return $join;
}
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
- <td align="center"> Anuko Time Tracker 1.18.50.4811 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+ <td align="center"> Anuko Time Tracker 1.18.51.4812 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
<a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
<a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
<a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
print "Updated $tt_expense_items_updated tt_expense_items records...<br>\n";
}
- if ($_POST["convert11797to11850"]) {
+ if ($_POST["convert11797to11851"]) {
ttExecute("ALTER TABLE `tt_fav_reports` CHANGE `group_by` `group_by1` varchar(20) default NULL");
ttExecute("ALTER TABLE `tt_fav_reports` ADD `group_by2` varchar(20) default NULL AFTER `group_by1`");
ttExecute("ALTER TABLE `tt_fav_reports` ADD `group_by3` varchar(20) default NULL AFTER `group_by2`");
ttExecute("UPDATE `tt_site_config` SET param_value = '1.18.49', modified = now() where param_name = 'version_db' and param_value = '1.18.48'");
ttExecute("ALTER TABLE `tt_timesheets` ADD `project_id` int(11) default NULL AFTER `client_id`");
ttExecute("UPDATE `tt_site_config` SET param_value = '1.18.50', modified = now() where param_name = 'version_db' and param_value = '1.18.49'");
+ ttExecute("drop index timesheet_idx on tt_expense_items");
+ ttExecute("ALTER TABLE `tt_expense_items` DROP `timesheet_id`");
+ ttExecute("UPDATE `tt_site_config` SET param_value = '1.18.51', modified = now() where param_name = 'version_db' and param_value = '1.18.50'");
}
if ($_POST["cleanup"]) {
<h2>DB Install</h2>
<table width="80%" border="1" cellpadding="10" cellspacing="0">
<tr>
- <td width="80%"><b>Create database structure (v1.18.50)</b>
+ <td width="80%"><b>Create database structure (v1.18.51)</b>
<br>(applies only to new installations, do not execute when updating)</br></td><td><input type="submit" name="crstructure" value="Create"></td>
</tr>
</table>
</tr>
</tr>
<tr valign="top">
- <td>Update database structure (v1.17.97 to v1.18.50)</td>
- <td><input type="submit" name="convert11797to11850" value="Update"></td>
+ <td>Update database structure (v1.17.97 to v1.18.51)</td>
+ <td><input type="submit" name="convert11797to11851" value="Update"></td>
</tr>
</table>
`org_id` int(11) default NULL, # organization id
`client_id` int(11) default NULL, # client id
`project_id` int(11) default NULL, # project id
- `timesheet_id` int(11) default NULL, # timesheet id
`name` text NOT NULL, # expense item name (what is an expense for)
`cost` decimal(10,2) default '0.00', # item cost (including taxes, etc.)
`invoice_id` int(11) default NULL, # invoice id
create index group_idx on tt_expense_items(group_id);
create index client_idx on tt_expense_items(client_id);
create index project_idx on tt_expense_items(project_id);
-create index timesheet_idx on tt_expense_items(timesheet_id);
create index invoice_idx on tt_expense_items(invoice_id);
PRIMARY KEY (`param_name`)
);
-INSERT INTO `tt_site_config` (`param_name`, `param_value`, `created`) VALUES ('version_db', '1.18.50', now()); # TODO: change when structure changes.
+INSERT INTO `tt_site_config` (`param_name`, `param_value`, `created`) VALUES ('version_db', '1.18.51', now()); # TODO: change when structure changes.