コード例 #1
0
function add_activities($offset, $limit)
{
    global $dt_db, $si_db, $company_rates, $user_rates, $invoices, $checks;
    debug("add_activities({$limit}, offset)");
    $task_activity_sql = "\n\tSELECT ta.id, ta.task_id, ta.user_id, ta.text, ta.start_ts, ta.end_ts, ta.invoice, ta.check, p.company_id \n\tFROM `task_activities` AS ta\n\tLEFT JOIN tasks AS t ON t.id = ta.task_id\n\tLEFT JOIN projects AS p ON p.id = t.project_id\n\tLIMIT {$offset}, {$limit}\n\t";
    $task_activity_result = $dt_db->query($task_activity_sql, TRUE);
    assert_die($task_activity_result, "Could not get task activities!\n" . $dt_db->getLastError());
    debug('Got ' . $task_activity_result->numRows() . ' task activity rows from phpdt.');
    while ($row = $task_activity_result->fetchArray(MYSQL_ASSOC)) {
        $ta = new SI_TaskActivity();
        $ta->task_id = $row['task_id'];
        $ta->user_id = $row['user_id'];
        $ta->text = $row['text'];
        $ta->start_ts = $row['start_ts'];
        $ta->end_ts = $row['end_ts'];
        $ta->hourly_rate = $company_rates[$row['company_id']];
        $ta->hourly_cost = $user_rates[$row['user_id']];
        // Special exception for david
        if ($row['user_id'] == 10 && $row['end_ts'] < mktime(0, 0, 0, 1, 1, 2005)) {
            $ta->getUser();
            $ta->_user->rate_type = 'HOURLY';
        }
        $GLOBALS['phpdt_cost_ts'] = $row['end_ts'];
        assert_die($ta->add(), "Error adding task activity!\n" . $ta->getLastError());
        $invoices[$row['invoice']]['company_id'] = $row['company_id'];
        if ($ta->end_ts > $invoices[$row['invoice']]['timestamp']) {
            $invoices[$row['invoice']]['timestamp'] = $ta->end_ts;
        }
        $invoices[$row['invoice']]['ids'][] = $ta->id;
        $checks[$row['check']]['user_id'] = $row['user_id'];
        $checks[$row['check']]['ids'][] = $ta->cost_trans_id;
        if ($ta->end_ts > $checks[$row['check']]['timestamp']) {
            $checks[$row['check']]['timestamp'] = $ta->end_ts;
        }
        $checks[$row['check']]['amount'] += $ta->cost;
    }
    $task_activity_result->free();
    debug('Added task activities to sureinvoice!');
}