Example #1
0
function show_all_exp($template)
{
    global $TPL;
    global $expenseForm;
    global $db;
    global $transaction_to_edit;
    if ($expenseForm->get_id()) {
        if ($_POST["transactionID"] && ($_POST["edit"] || is_object($transaction_to_edit) && $transaction_to_edit->get_id())) {
            // if edit is clicked OR if we've rejected changes made to something so are still editing it
            $query = prepare("SELECT * FROM transaction WHERE expenseFormID=%d AND transactionID<>%d ORDER BY transactionID DESC", $expenseForm->get_id(), $_POST["transactionID"]);
        } else {
            $query = prepare("SELECT * FROM transaction WHERE expenseFormID=%d ORDER BY transactionID DESC", $expenseForm->get_id());
        }
        $db->query($query);
        while ($db->next_record()) {
            $transaction = new transaction();
            $transaction->read_db_record($db);
            $transaction->set_values();
            $transaction->get_value("quantity") and $TPL["amount"] = $transaction->get_value("amount") / $transaction->get_value("quantity");
            $TPL["lineTotal"] = $TPL["amount"] * $transaction->get_value("quantity");
            $tf = new tf();
            $tf->set_id($transaction->get_value("fromTfID"));
            $tf->select();
            $TPL["fromTfIDLink"] = $tf->get_link();
            $tf = new tf();
            $tf->set_id($transaction->get_value("tfID"));
            $tf->select();
            $TPL["tfIDLink"] = $tf->get_link();
            $projectID = $transaction->get_value("projectID");
            if ($projectID) {
                $project = new project();
                $project->set_id($transaction->get_value("projectID"));
                $project->select();
                $TPL["projectName"] = $project->get_value("projectName");
            }
            if ($transaction->get_value("fromTfID") == config::get_config_item("expenseFormTfID")) {
                $TPL['expense_class'] = "loud";
            } else {
                $TPL['expense_class'] = "";
            }
            include_template($template);
        }
    }
}
Example #2
0
function show_transaction($template)
{
    global $db;
    global $TPL;
    global $projectID;
    $current_user =& singleton("current_user");
    $transaction = new transaction();
    if (isset($projectID) && $projectID) {
        $query = prepare("SELECT transaction.*\n                          FROM transaction\n                          WHERE transaction.projectID = %d\n                      ORDER BY transactionModifiedTime desc\n                        ", $projectID);
        $db->query($query);
        while ($db->next_record()) {
            $transaction = new transaction();
            $transaction->read_db_record($db);
            $transaction->set_values("transaction_");
            $tf = $transaction->get_foreign_object("tf");
            $tf->set_values();
            $tf->set_values("tf_");
            $TPL["transaction_username"] = $db->f("username");
            $TPL["transaction_amount"] = page::money($TPL["transaction_currenyTypeID"], $TPL["transaction_amount"], "%s%mo");
            $TPL["transaction_type_link"] = $transaction->get_transaction_type_link() or $TPL["transaction_link"] = $transaction->get_value("transactionType");
            include_template($template);
        }
    }
}
Example #3
0
function show_transaction_list($template)
{
    global $TPL;
    global $tflist;
    global $transactionGroupID;
    $q = prepare("SELECT *, amount * pow(10,-currencyType.numberToBasic) as amount\n                  FROM transaction\n             LEFT JOIN currencyType on transaction.currencyTypeID = currencyType.currencyTypeID\n                 WHERE transactionGroupID = %d\n              ORDER BY transactionID\n               ", $transactionGroupID);
    $db = new db_alloc();
    $db->query($q);
    while ($row = $db->row()) {
        $transaction = new transaction();
        $transaction->read_array($row);
        $transaction->set_values();
        $tflist = add_inactive_tf($transaction->get_value("tfID"), $tflist);
        $tflist = add_inactive_tf($transaction->get_value("fromTfID"), $tflist);
        $TPL["display"] = "";
        $TPL["tfList_dropdown"] = page::select_options($tflist, $transaction->get_value("tfID"), 500);
        $TPL["fromTfList_dropdown"] = page::select_options($tflist, $transaction->get_value("fromTfID"), 500);
        $TPL["transactionType_dropdown"] = page::select_options(transaction::get_transactionTypes(), $transaction->get_value("transactionType"));
        $TPL["status_dropdown"] = page::select_options(transaction::get_transactionStatii(), $transaction->get_value("status"));
        $TPL["link"] = $transaction->get_link("transactionID");
        include_template($template);
    }
}
Example #4
0
function show_transaction_listR($template_name)
{
    global $timeSheet;
    global $TPL;
    $current_user =& singleton("current_user");
    global $percent_array;
    $db = new db_alloc();
    $db->query("SELECT * FROM transaction WHERE timeSheetID = %d", $timeSheet->get_id());
    if ($db->next_record() || $timeSheet->get_value("status") == "invoiced" || $timeSheet->get_value("status") == "finished") {
        $db->query("SELECT * \n                    FROM tf \n                   WHERE tfActive = 1\n                      OR tfID = %d \n                      OR tfID = %d \n                ORDER BY tfName", $db->f("tfID"), $db->f("fromTfID"));
        while ($db->row()) {
            $tf_array[$db->f("tfID")] = $db->f("tfName");
        }
        $status_options = array("pending" => "Pending", "approved" => "Approved", "rejected" => "Rejected");
        $transactionType_options = transaction::get_transactionTypes();
        if ($timeSheet->have_perm(PERM_TIME_INVOICE_TIMESHEETS) && $timeSheet->get_value("status") == "invoiced") {
            $db->query("SELECT * FROM transaction WHERE timeSheetID = %d ORDER BY transactionID", $timeSheet->get_id());
            while ($db->next_record()) {
                $transaction = new transaction();
                $transaction->read_db_record($db);
                $transaction->set_tpl_values("transaction_");
                $TPL["currency"] = page::money($transaction->get_value("currencyTypeID"), '', "%S");
                $TPL["currency_code"] = page::money($transaction->get_value("currencyTypeID"), '', "%C");
                $TPL["tf_options"] = page::select_options($tf_array, $TPL["transaction_tfID"]);
                $TPL["from_tf_options"] = page::select_options($tf_array, $TPL["transaction_fromTfID"]);
                $TPL["status_options"] = page::select_options($status_options, $transaction->get_value("status"));
                $TPL["transactionType_options"] = page::select_options($transactionType_options, $transaction->get_value("transactionType"));
                $TPL["percent_dropdown"] = page::select_options($percent_array, $empty);
                $TPL["transaction_buttons"] = '
            <button type="submit" name="transaction_delete" value="1" class="delete_button">Delete<i class="icon-trash"></i></button>
            <button type="submit" name="transaction_save" value="1" class="save_button">Save<i class="icon-ok-sign"></i></button>
          ';
                if ($transaction->get_value("transactionType") == "invoice") {
                    $TPL["transaction_transactionType"] = $transaction->get_transaction_type_link();
                    $TPL["transaction_fromTfID"] = tf::get_name($transaction->get_value("fromTfID"));
                    $TPL["transaction_tfID"] = tf::get_name($transaction->get_value("tfID"));
                    $TPL["currency_amount"] = page::money($transaction->get_value("currencyTypeID"), $transaction->get_value("amount"), "%S%mo %c");
                    include_template("templates/timeSheetTransactionListViewR.tpl");
                } else {
                    include_template($template_name);
                }
            }
        } else {
            // If you don't have perm INVOICE TIMESHEETS then only select
            // transactions which you have permissions to see.
            $query = prepare("SELECT * \n                            FROM transaction \n                           WHERE timeSheetID = %d\n                        ORDER BY transactionID", $timeSheet->get_id());
            $db->query($query);
            while ($db->next_record()) {
                $transaction = new transaction();
                $transaction->read_db_record($db);
                $transaction->set_tpl_values("transaction_");
                unset($TPL["transaction_amount_pos"]);
                unset($TPL["transaction_amount_neg"]);
                $TPL["currency_amount"] = page::money($transaction->get_value("currencyTypeID"), $transaction->get_value("amount"), "%S%mo %c");
                $TPL["transaction_fromTfID"] = tf::get_name($transaction->get_value("fromTfID"));
                $TPL["transaction_tfID"] = tf::get_name($transaction->get_value("tfID"));
                $TPL["transaction_transactionType"] = $transactionType_options[$transaction->get_value("transactionType")];
                include_template("templates/timeSheetTransactionListViewR.tpl");
            }
        }
    }
}
Example #5
0
    $TPL["expenseForm_link"] = "<a href=\"" . $TPL["url_alloc_expenseForm"] . "expenseFormID=" . $expenseForm->get_id() . "\">#" . $expenseForm->get_id() . "</a>";
}
$timeSheet = $transaction->get_foreign_object("timeSheet");
if ($timeSheet->get_id()) {
    $TPL["timeSheet_link"] = "<a href=\"" . $TPL["url_alloc_timeSheet"] . "timeSheetID=" . $timeSheet->get_id() . "\">#" . $timeSheet->get_id() . "</a>";
}
$transaction->set_values();
if ($_POST["save"] || $_POST["saveAndNew"] || $_POST["saveGoTf"]) {
    /*
      if ($transaction->get_value("status") != "pending") {
        alloc_error("This transaction is no longer editable.");
      }
    */
    $transaction->read_globals();
    // Tweaked validation to allow reporting of multiple errors
    $transaction->get_value("amount") or alloc_error("You must enter a valid amount");
    $transaction->get_value("transactionDate") or alloc_error("You must enter a date for the transaction");
    $transaction->get_value("product") or alloc_error("You must enter a product");
    $transaction->get_value("status") or alloc_error("You must set the status of the transaction");
    $transaction->get_value("fromTfID") or alloc_error("You must select a Source Tagged Fund to take this transaction from");
    $transaction->get_value("tfID") or alloc_error("You must select a Destination Tagged Fund to add this transaction against");
    $transaction->get_value("transactionType") or alloc_error("You must set a transaction type");
    $transaction->get_value("currencyTypeID") or alloc_error("You must set a transaction currency");
    #$transaction->get_value("projectID")       or alloc_error("You must select a project");
    #$transaction->get_value("companyDetails")  or alloc_error("You must enter the company details");
    if (!count($TPL["message"])) {
        $transaction->set_value("amount", str_replace(array("\$", ","), "", $transaction->get_value("amount")));
        if ($transaction->save()) {
            // need to check this again as transaction->save might have triggered an error
            $TPL["message_good"][] = "Transaction Saved";
            if ($_POST["saveAndNew"]) {
Example #6
0
            echo "<br>Skipping because tf not active: " . $tf->get_value("tfName");
            continue 2;
        }
        $tf = new tf();
        $tf->set_id($transactionRepeat->get_value("fromTfID"));
        $tf->select();
        if (!$tf->get_value("tfActive")) {
            echo "<br>Skipping because tf not active: " . $tf->get_value("tfName");
            continue 2;
        }
        $amount = page::money_out($transactionRepeat->get_value("currencyTypeID"), $transactionRepeat->get_value("amount"));
        $transaction = new transaction();
        $transaction->set_value("fromTfID", $transactionRepeat->get_value("fromTfID"));
        $transaction->set_value("tfID", $transactionRepeat->get_value("tfID"));
        $transaction->set_value("companyDetails", $transactionRepeat->get_value("companyDetails"));
        $transaction->set_value("amount", $amount);
        $transaction->set_value("currencyTypeID", $transactionRepeat->get_value("currencyTypeID"));
        $transaction->set_value("product", $transactionRepeat->get_value("product"));
        $transaction->set_value("transactionType", $transactionRepeat->get_value("transactionType"));
        $transaction->set_value("status", "pending");
        $transaction->set_value("transactionRepeatID", $transactionRepeat->get_id());
        $transaction->set_value("transactionDate", date("Y-m-d", $nextScheduled));
        $transaction->save();
        echo "\n<br>" . $transaction->get_value("transactionDate");
        echo " " . $transactionRepeat->get_value("paymentBasis") . " \$" . $transaction->get_value("amount") . " for TF: " . tf::get_name($transaction->get_value("tfID"));
        echo " (transactionID: " . $transaction->get_id() . " transactionRepeatID:" . $transactionRepeat->get_id() . " name:" . $transactionRepeat->get_value("product") . ")";
        $nextScheduled = timeWarp($nextScheduled, $timeBasisString);
    }
}
$TPL["main_alloc_title"] = "Execute Repeating Expenses - " . APPLICATION_NAME;
include_template("templates/checkRepeatM.tpl");
Example #7
0
function show_transaction_list($transactions = array(), $template)
{
    global $TPL;
    global $tflist;
    foreach ($transactions as $row) {
        $transaction = new transaction();
        $transaction->read_array($row);
        $transaction->set_values();
        $TPL["display"] = "";
        $m = new meta("currencyType");
        $currencyOptions = $m->get_assoc_array("currencyTypeID", "currencyTypeID");
        $TPL["currencyOptions"] = page::select_options($currencyOptions, $transaction->get_value("currencyTypeID"));
        $TPL["tfList_dropdown"] = page::select_options($tflist, $transaction->get_value("tfID"));
        $TPL["fromTfList_dropdown"] = page::select_options($tflist, $transaction->get_value("fromTfID"));
        $TPL["tfID_label"] = $tflist[$transaction->get_value("tfID")];
        $TPL["fromTfID_label"] = $tflist[$transaction->get_value("fromTfID")];
        if (CAN_APPROVE_TRANSACTIONS && $TPL["productSale_status"] == "admin") {
            $TPL["status"] = "<select name='status[]' class='txStatus'>";
            $TPL["status"] .= page::select_options(transaction::get_transactionStatii(), $transaction->get_value("status")) . "</select>";
        }
        $TPL["pc_productCostID"] = $row["pc_productCostID"];
        $TPL["pc_amount"] = $row["pc_amount"];
        $TPL["pc_isPercentage"] = $row["pc_isPercentage"];
        $TPL["pc_currency"] = $row["pc_currency"];
        $TPL["amountClass"] = $row["saleTransactionType"];
        include_template($template);
    }
}
Example #8
0
 function get_pending_repeat_transaction_list()
 {
     global $TPL;
     $transactionTypes = transaction::get_transactionTypes();
     $q = "SELECT * FROM transaction \n              LEFT JOIN transactionRepeat on transactionRepeat.transactionRepeatID = transaction.transactionRepeatID \n                  WHERE transaction.transactionRepeatID IS NOT NULL AND transaction.status = 'pending'";
     $db = new db_alloc();
     $db->query($q);
     while ($row = $db->row()) {
         $transaction = new transaction();
         $transaction->read_db_record($db);
         $transaction->set_values();
         $transactionRepeat = new transactionRepeat();
         $transactionRepeat->read_db_record($db);
         $transactionRepeat->set_values();
         $row["transactionType"] = $transactionTypes[$transaction->get_value("transactionType")];
         $row["formTotal"] = $db->f("amount");
         $row["transactionModifiedTime"] = $transaction->get_value("transactionModifiedTime");
         $row["transactionCreatedTime"] = $transaction->get_value("transactionCreatedTime");
         $row["transactionCreatedUser"] = person::get_fullname($transaction->get_value("transactionCreatedUser"));
         $rows[] = $row;
     }
     return (array) $rows;
 }
Example #9
0
 public static function get_list($_FORM)
 {
     $current_user =& singleton("current_user");
     global $TPL;
     /*
      * This is the definitive method of getting a list of transactions that need a sophisticated level of filtering
      *
      */
     $_FORM["tfIDs"] = transaction::reduce_tfs($_FORM);
     // Non-admin users must specify a valid TF
     if (!$current_user->have_role("admin") && !$_FORM["tfIDs"]) {
         return;
     }
     $filter = transaction::get_list_filter($_FORM);
     $debug = $_FORM["debug"];
     $debug and print "\n<pre>_FORM: " . print_r($_FORM, 1) . "</pre>";
     $debug and print "\n<pre>filter: " . print_r($filter, 1) . "</pre>";
     $_FORM["return"] or $_FORM["return"] = "html";
     $filter["prevBalance"] and $filter2[] = $filter["prevBalance"];
     $filter["tfIDs"] and $filter2[] = $filter["tfIDs"];
     $filter2 and $filter2[] = " (status = 'approved') ";
     unset($filter["prevBalance"]);
     if (is_array($filter2) && count($filter2)) {
         $filter2 = " WHERE " . implode(" AND ", $filter2);
     }
     if (is_array($filter) && count($filter)) {
         $filter = " WHERE " . implode(" AND ", $filter);
     }
     $_FORM["sortTransactions"] or $_FORM["sortTransactions"] = "transactionDate";
     $order_by = "ORDER BY " . $_FORM["sortTransactions"];
     // Determine opening balance
     if (is_array($_FORM['tfIDs']) && count($_FORM['tfIDs'])) {
         $q = prepare("SELECT SUM( IF(fromTfID IN (%s),-amount,amount) * pow(10,-currencyType.numberToBasic) * exchangeRate) AS balance\n                      FROM transaction \n                 LEFT JOIN currencyType ON currencyType.currencyTypeID = transaction.currencyTypeID\n                    " . $filter2, $_FORM['tfIDs']);
         $debug and print "\n<br>QUERY: " . $q;
         $db = new db_alloc();
         $db->query($q);
         $db->row();
         $_FORM["opening_balance"] = $db->f("balance");
         $running_balance = $db->f("balance");
     }
     $q = "SELECT *, \n                 (amount * pow(10,-currencyType.numberToBasic)) as amount1,\n                 (amount * pow(10,-currencyType.numberToBasic) * exchangeRate) as amount2,\n                 if(transactionModifiedTime,transactionModifiedTime,transactionCreatedTime) AS transactionSortDate,\n                 tf1.tfName as fromTfName,\n                 tf2.tfName as tfName\n            FROM transaction \n       LEFT JOIN currencyType ON currencyType.currencyTypeID = transaction.currencyTypeID\n       LEFT JOIN tf tf1 ON transaction.fromTfID = tf1.tfID\n       LEFT JOIN tf tf2 ON transaction.tfID = tf2.tfID\n         " . $filter . " \n         " . $order_by;
     $debug and print "\n<br>QUERY2: " . $q;
     $db = new db_alloc();
     $db->query($q);
     $for_cyber = config::for_cyber();
     while ($row = $db->next_record()) {
         #echo "<pre>".print_r($row,1)."</pre>";
         $i++;
         $t = new transaction();
         if (!$t->read_db_record($db)) {
             continue;
         }
         $print = true;
         // If the destination of this TF is not the current TfID, then invert the $amount
         $amount = $row["amount2"];
         if (!in_array($row["tfID"], (array) $_FORM["tfIDs"])) {
             $amount = -$amount;
             $row["amount1"] = -$row["amount1"];
         }
         $row["amount"] = $amount;
         $row["transactionURL"] = $t->get_url();
         $row["transactionName"] = $t->get_name($_FORM);
         $row["transactionLink"] = $t->get_transaction_link($_FORM);
         $row["transactionTypeLink"] = $t->get_transaction_type_link() or $row["transactionTypeLink"] = $row["transactionType"];
         $row["transactionSortDate"] = format_date("Y-m-d", $row["transactionSortDate"]);
         $row["fromTfIDLink"] = "<a href=\"" . $TPL["url_alloc_transactionList"] . "tfID=" . $row["fromTfID"] . "\">" . page::htmlentities($row["fromTfName"]) . "</a>";
         $row["tfIDLink"] = "<a href=\"" . $TPL["url_alloc_transactionList"] . "tfID=" . $row["tfID"] . "\">" . page::htmlentities($row["tfName"]) . "</a>";
         if ($t->get_value("status") == "approved") {
             $running_balance += $amount;
             $row["running_balance"] = page::money(config::get_config_item("currency"), $running_balance, "%m %c");
         }
         if ($amount > 0) {
             $row["amount_positive"] = page::money($row["currencyTypeID"], $row["amount1"], "%m %c");
             $total_amount_positive += $amount;
         } else {
             $row["amount_negative"] = page::money($row["currencyTypeID"], $row["amount1"], "%m %c");
             $total_amount_negative += $amount;
         }
         // Cyber only hackery for ext ref field on product sales
         if ($for_cyber && $row["productSaleID"]) {
             $ps = new productSale();
             $ps->set_id($row["productSaleID"]);
             if ($ps->select()) {
                 $ps->get_value("extRef") and $row["product"] .= " (Ext ref: " . $ps->get_value("extRef") . ")";
             }
         }
         $transactions[$row["transactionID"]] = $row;
     }
     $_FORM["total_amount_positive"] = page::money(config::get_config_item("currency"), $total_amount_positive, "%s%m %c");
     $_FORM["total_amount_negative"] = page::money(config::get_config_item("currency"), $total_amount_negative, "%s%m %c");
     $_FORM["running_balance"] = page::money(config::get_config_item("currency"), $running_balance, "%s%m %c");
     return array("totals" => $_FORM, "rows" => (array) $transactions);
 }