function render()
 {
     $current_user =& singleton("current_user");
     global $TPL;
     // Get averages for hours worked over the past fortnight and year
     $t = new timeSheetItem();
     $day = 60 * 60 * 24;
     //mktime(0,0,0,date("m"),date("d")-1, date("Y"))
     $today = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 1, date("Y")));
     $yestA = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 2, date("Y")));
     $yestB = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 1, date("Y")));
     $fortn = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 14, date("Y")));
     list($hours_sum_today, $dollars_sum_today) = $t->get_averages($today, $current_user->get_id());
     list($hours_sum_yesterday, $dollars_sum_yesterday) = $t->get_averages($yestA, $current_user->get_id(), null, $yestB);
     list($hours_sum_fortnight, $dollars_sum_fortnight) = $t->get_averages($fortn, $current_user->get_id());
     list($hours_avg_fortnight, $dollars_avg_fortnight) = $t->get_fortnightly_average($current_user->get_id());
     $TPL["hours_sum_today"] = sprintf("%0.2f", $hours_sum_today[$current_user->get_id()]);
     $TPL["dollars_sum_today"] = page::money_print($dollars_sum_today[$current_user->get_id()]);
     $TPL["hours_sum_yesterday"] = sprintf("%0.2f", $hours_sum_yesterday[$current_user->get_id()]);
     $TPL["dollars_sum_yesterday"] = page::money_print($dollars_sum_yesterday[$current_user->get_id()]);
     $TPL["hours_sum_fortnight"] = sprintf("%0.2f", $hours_sum_fortnight[$current_user->get_id()]);
     $TPL["dollars_sum_fortnight"] = page::money_print($dollars_sum_fortnight[$current_user->get_id()]);
     $TPL["hours_avg_fortnight"] = sprintf("%0.2f", $hours_avg_fortnight[$current_user->get_id()]);
     $TPL["dollars_avg_fortnight"] = page::money(config::get_config_item("currency"), $dollars_avg_fortnight[$current_user->get_id()], "%s%m %c");
     $TPL["dateFrom"] = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 28, date("Y")));
     $TPL["dateTo"] = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 1, date("Y")));
     return true;
 }
Example #2
0
            $TPL["seekClientReimbursementOption"] = $seekClientReimbursementOption;
            $options["clientStatus"] = "Current";
            $ops = client::get_list($options);
            $ops = array_kv($ops, "clientID", "clientName");
            $TPL["field_clientID"] = "<select name=\"clientID\"><option value=\"\">" . page::select_options($ops, $expenseForm->get_value("clientID")) . "</select>";
            $TPL["field_expenseFormComment"] = page::textarea("expenseFormComment", $expenseForm->get_value("expenseFormComment", DST_HTML_DISPLAY));
        }
    }
}
if (is_object($expenseForm) && $expenseForm->get_id()) {
    $db = new db_alloc();
    $db->query(prepare("SELECT SUM(amount * pow(10,-currencyType.numberToBasic)) AS amount, \n                             transaction.currencyTypeID as currency\n                        FROM transaction\n                   LEFT JOIN currencyType on transaction.currencyTypeID = currencyType.currencyTypeID\n                       WHERE expenseFormID = %d\n                    GROUP BY transaction.currencyTypeID\n                  ", $expenseForm->get_id()));
    while ($row = $db->row()) {
        $rows[] = $row;
    }
    $TPL["formTotal"] = page::money_print($rows);
}
if (is_object($expenseForm) && $current_user->have_role("admin") && !$expenseForm->get_invoice_link() && $expenseForm->get_value("expenseFormFinalised") && $expenseForm->get_value("seekClientReimbursement")) {
    $ops["invoiceStatus"] = "edit";
    $ops["clientID"] = $expenseForm->get_value("clientID");
    $invoice_list = invoice::get_list($ops);
    $invoice_list = array_kv($invoice_list, "invoiceID", array("invoiceNum", "invoiceName"));
    $q = prepare("SELECT * FROM invoiceItem WHERE expenseFormID = %d", $expenseForm->get_id());
    $db = new db_alloc();
    $db->query($q);
    $row = $db->row();
    $sel_invoice = $row["invoiceID"];
    $TPL["attach_to_invoice_button"] = "<select name=\"attach_to_invoiceID\">";
    $TPL["attach_to_invoice_button"] .= "<option value=\"create_new\">Create New Invoice</option>";
    $TPL["attach_to_invoice_button"] .= page::select_options($invoice_list, $sel_invoice) . "</select>";
    $TPL["attach_to_invoice_button"] .= "<input type=\"submit\" name=\"attach_transactions_to_invoice\" value=\"Add to Invoice\"> ";
Example #3
0
 public static function get_list($_FORM)
 {
     /*
      * This is the definitive method of getting a list of timeSheets that need a sophisticated level of filtering
      *
      */
     global $TPL;
     $current_user =& singleton("current_user");
     $_FORM["showShortProjectLink"] and $_FORM["showProjectLink"] = true;
     $filter = timeSheet::get_list_filter($_FORM);
     // Used in timeSheetListS.tpl
     $extra["showFinances"] = $_FORM["showFinances"];
     $debug = $_FORM["debug"];
     $debug and print "<pre>_FORM: " . print_r($_FORM, 1) . "</pre>";
     $debug and print "<pre>filter: " . print_r($filter, 1) . "</pre>";
     $_FORM["return"] or $_FORM["return"] = "html";
     if (is_array($filter) && count($filter)) {
         $filter = " WHERE " . implode(" AND ", $filter);
     }
     $q = "SELECT timeSheet.*, person.personID, projectName, projectShortName\n            FROM timeSheet \n       LEFT JOIN person ON timeSheet.personID = person.personID\n       LEFT JOIN project ON timeSheet.projectID = project.projectID\n       LEFT JOIN timeSheetItem ON timeSheet.timeSheetID = timeSheetItem.timeSheetID \n                 " . $filter . "\n        GROUP BY timeSheet.timeSheetID\n        ORDER BY dateFrom,projectName,timeSheet.status,surname";
     $debug and print "Query: " . $q;
     $db = new db_alloc();
     $db->query($q);
     $status_array = timeSheet::get_timeSheet_statii();
     $people_array =& get_cached_table("person");
     while ($row = $db->next_record()) {
         $t = new timeSheet();
         if (!$t->read_db_record($db)) {
             continue;
         }
         $t->load_pay_info();
         if ($_FORM["timeSheetItemHours"] && !parse_operator_comparison($_FORM["timeSheetItemHours"], $t->pay_info["total_duration_hours"])) {
             continue;
         }
         $row["currencyTypeID"] = $t->get_value("currencyTypeID");
         $row["amount"] = $t->pay_info["total_dollars"];
         $amount_tallies[] = array("amount" => $row["amount"], "currency" => $row["currencyTypeID"]);
         $extra["amountTotal"] += exchangeRate::convert($row["currencyTypeID"], $row["amount"]);
         $extra["totalHours"] += $t->pay_info["total_duration_hours"];
         $row["totalHours"] += $t->pay_info["total_duration_hours"];
         $row["duration"] = $t->pay_info["summary_unit_totals"];
         if ($t->get_value("status") == "edit" && imp($current_user->prefs["timeSheetHoursWarn"]) && $t->pay_info["total_duration_hours"] >= $current_user->prefs["timeSheetHoursWarn"]) {
             $row["hoursWarn"] = page::help("This time sheet has gone over " . $current_user->prefs["timeSheetHoursWarn"] . " hours.", page::warn());
         }
         if ($t->get_value("status") == "edit" && imp($current_user->prefs["timeSheetDaysWarn"]) && (mktime() - format_date("U", $t->get_value("dateFrom"))) / 60 / 60 / 24 >= $current_user->prefs["timeSheetDaysWarn"]) {
             $row["daysWarn"] = page::help("This time sheet is over " . $current_user->prefs["timeSheetDaysWarn"] . " days old.", page::warn());
         }
         $row["person"] = $people_array[$row["personID"]]["name"];
         $row["status"] = $status_array[$row["status"]];
         $row["customerBilledDollars"] = $t->pay_info["total_customerBilledDollars"];
         $extra["customerBilledDollarsTotal"] += exchangeRate::convert($row["currencyTypeID"], $t->pay_info["total_customerBilledDollars"]);
         $billed_tallies[] = array("amount" => $row["customerBilledDollars"], "currency" => $row["currencyTypeID"]);
         if ($_FORM["showFinances"]) {
             list($pos, $neg) = $t->get_transaction_totals();
             $row["transactionsPos"] = page::money_print($pos);
             $row["transactionsNeg"] = page::money_print($neg);
             foreach ((array) $pos as $v) {
                 $pos_tallies[] = $v;
             }
             foreach ((array) $neg as $v) {
                 $neg_tallies[] = $v;
             }
         }
         $p = new project();
         $p->read_db_record($db);
         $row["projectLink"] = $t->get_link($p->get_name($_FORM));
         $rows[$row["timeSheetID"]] = $row;
     }
     $extra["amount_tallies"] = page::money_print($amount_tallies);
     $extra["billed_tallies"] = page::money_print($billed_tallies);
     $extra["positive_tallies"] = page::money_print($pos_tallies);
     $extra["negative_tallies"] = page::money_print($neg_tallies);
     if (!$_FORM["noextra"]) {
         return array("rows" => (array) $rows, "extra" => $extra);
     } else {
         return (array) $rows;
     }
 }
Example #4
0
}
$TPL["total_invoice_transactions_pending"] = page::money_print($rows);
$q = prepare("SELECT SUM((amount * pow(10,-currencyType.numberToBasic))) \n                  AS amount, transaction.currencyTypeID as currency\n                FROM transaction\n           LEFT JOIN invoiceItem on invoiceItem.invoiceItemID = transaction.invoiceItemID\n           LEFT JOIN invoice on invoice.invoiceID = invoiceItem.invoiceID\n           LEFT JOIN currencyType on currencyType.currencyTypeID = invoice.currencyTypeID\n               WHERE invoice.projectID = %d\n                 AND transaction.status = 'approved'\n            GROUP BY transaction.currencyTypeID\n              ", $project->get_id());
$db->query($q);
unset($rows);
while ($row = $db->row()) {
    $rows[] = $row;
}
$TPL["total_invoice_transactions_approved"] = page::money_print($rows);
$q = prepare("SELECT SUM((amount * pow(10,-currencyType.numberToBasic))) \n                  AS amount, transaction.currencyTypeID as currency\n                FROM transaction\n           LEFT JOIN currencyType on currencyType.currencyTypeID = transaction.currencyTypeID\n               WHERE transaction.projectID = %d\n                 AND transaction.status = 'approved'\n            GROUP BY transaction.currencyTypeID\n              ", $project->get_id());
$db->query($q);
unset($rows);
while ($row = $db->row()) {
    $rows[] = $row;
}
$TPL["total_expenses_transactions_approved"] = page::money_print($rows);
if ($project->get_id()) {
    $defaults["projectID"] = $project->get_id();
    $defaults["showFinances"] = true;
    if (!$project->have_perm(PERM_READ_WRITE)) {
        $defaults["personID"] = $current_user->get_id();
    }
    $rtn = timeSheet::get_list($defaults);
    $TPL["timeSheetListRows"] = $rtn["rows"];
    $TPL["timeSheetListExtra"] = $rtn["extra"];
}
if ($project->have_perm(PERM_READ_WRITE)) {
    include_template("templates/projectFormM.tpl");
} else {
    include_template("templates/projectViewM.tpl");
}