function get_links($invoiceID)
 {
     $rows = invoiceEntity::get("invoice", $invoiceID);
     // cheating :)
     foreach ($rows as $row) {
         if ($row["timeSheetID"]) {
             $timeSheet = new timeSheet($row["timeSheetID"]);
             $timeSheet_links[] = $timeSheet->get_link();
         }
         if ($row["expenseFormID"]) {
             $expenseForm = new expenseForm($row["expenseFormID"]);
             $expenseForm_links[] = $expenseForm->get_link();
         }
         if ($row["productSaleID"]) {
             $productSale = new productSale($row["productSaleID"]);
             $productSale_links[] = $productSale->get_link();
         }
     }
     $timeSheet_links and $rtn[] = "Time Sheet: " . implode(", ", (array) $timeSheet_links);
     $expenseForm_links and $rtn[] = "Expense Form: " . implode(", ", (array) $expenseForm_links);
     $productSale_links and $rtn[] = "Product Sale: " . implode(", ", (array) $productSale_links);
     return implode(" / ", (array) $rtn);
 }
Exemple #2
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;
     }
 }