Exemple #1
0
        alloc_error("Bad Expense Form ID");
        $expenseForm = new expenseForm();
    }
}
if ($_POST["add"]) {
    $_POST["product"] or alloc_error("You must enter a Product.");
    $_POST["companyDetails"] or alloc_error("You must enter the Company Details.");
    $_POST["fromTfID"] or alloc_error("You must enter the Source TF.");
    $_POST["quantity"] or $_POST["quantity"] = 1;
    config::get_config_item("mainTfID") or alloc_error("You must configure the Finance Tagged Fund on the Setup -> Finance screen.");
    if ($_POST["amount"] === "") {
        alloc_error("You must enter the Price.");
    }
    $_POST["amount"] = $_POST["amount"] * $_POST["quantity"];
    $transaction = new transaction();
    $transactionID && $transaction->set_id($_POST["transactionID"]);
    $transaction->read_globals();
    // check we have permission to make the transaction
    if (!$transaction->have_perm(PERM_CREATE)) {
        alloc_error("You do not have permission to create transactions for that Source TF.");
    }
    if (!count($TPL["message"])) {
        $transaction->set_value("transactionType", "expense");
        $transaction->set_value("expenseFormID", $expenseForm->get_id());
        $transaction->set_value("tfID", config::get_config_item("mainTfID"));
        $transaction->save();
    } else {
        $transaction_to_edit = $transaction;
    }
}
if ($_POST["edit"] && $_POST["expenseFormID"] && $_POST["transactionID"]) {
Exemple #2
0
    global $TPL;
    if ($tfID && !array_key_exists($tfID, $options)) {
        $tf = new tf();
        $tf->set_id($tfID);
        $tf->select();
        $options[$tfID] = $tf->get_value("tfName");
        $TPL[$warningKey] = sprintf($warningValue, $tf->get_value("tfName"));
    }
    return $options;
}
$db = new db_alloc();
$transaction = new transaction();
$transaction->read_globals();
$transactionID = $_POST["transactionID"] or $transactionID = $_GET["transactionID"];
if ($transactionID && !$_GET["new"]) {
    $transaction->set_id($transactionID);
    $transaction->select();
}
$invoice_item = $transaction->get_foreign_object("invoiceItem");
$invoice_item->set_values();
$invoice = $invoice_item->get_foreign_object("invoice");
if (!$invoice->get_id()) {
    $invoice = $transaction->get_foreign_object("invoice");
}
$invoice->set_values();
if ($invoice->get_id()) {
    $TPL["invoice_link"] = "<a href=\"" . $TPL["url_alloc_invoice"] . "invoiceID=" . $invoice->get_id() . "\">#" . $invoice->get_value("invoiceNum");
    $TPL["invoice_link"] .= " " . $invoice->get_value("invoiceDateFrom") . " to " . $invoice->get_value("invoiceDateTo") . "</a>";
}
$expenseForm = $transaction->get_foreign_object("expenseForm");
if ($expenseForm->get_id()) {
Exemple #3
0
 function create_transaction($amount, $tfID, $status)
 {
     $transaction = new transaction();
     $invoice = $this->get_foreign_object("invoice");
     $this->currency = $invoice->get_value("currencyTypeID");
     $db = new db_alloc();
     // If there already a transaction for this invoiceItem, use it instead of creating a new one
     $q = prepare("SELECT * FROM transaction WHERE invoiceItemID = %d ORDER BY transactionCreatedTime DESC LIMIT 1", $this->get_id());
     $db->query($q);
     if ($db->row()) {
         $transaction->set_id($db->f("transactionID"));
         $transaction->select();
     }
     // If there already a transaction for this timeSheet, use it instead of creating a new one
     if ($this->get_value("timeSheetID")) {
         $q = prepare("SELECT * \n                      FROM transaction \n                     WHERE timeSheetID = %d \n                       AND fromTfID = %d\n                       AND tfID = %d\n                       AND amount = %d\n                       AND (invoiceItemID = %d or invoiceItemID IS NULL)\n                  ORDER BY transactionCreatedTime DESC LIMIT 1\n                         ", $this->get_value("timeSheetID"), config::get_config_item("inTfID"), $tfID, page::money($this->currency, $amount, "%mi"), $this->get_id());
         $db->query($q);
         if ($db->row()) {
             $transaction->set_id($db->f("transactionID"));
             $transaction->select();
         }
     }
     $transaction->set_value("amount", $amount);
     $transaction->set_value("currencyTypeID", $this->currency);
     $transaction->set_value("fromTfID", config::get_config_item("inTfID"));
     $transaction->set_value("tfID", $tfID);
     $transaction->set_value("status", $status);
     $transaction->set_value("invoiceID", $this->get_value("invoiceID"));
     $transaction->set_value("invoiceItemID", $this->get_id());
     $transaction->set_value("transactionDate", $this->get_value("iiDate"));
     $transaction->set_value("transactionType", "invoice");
     $transaction->set_value("product", sprintf("%s", $this->get_value("iiMemo")));
     $this->get_value("timeSheetID") && $transaction->set_value("timeSheetID", $this->get_value("timeSheetID"));
     $transaction->save();
 }
Exemple #4
0
     foreach ($_POST["transactionID"] as $k => $transactionID) {
         // Delete
         if ($transactionID && in_array($transactionID, $_POST["deleteTransaction"])) {
             $transaction = new transaction();
             $transaction->set_id($transactionID);
             $transaction->select();
             $transaction->delete();
             $deleted .= $commar1 . $transactionID;
             $commar1 = ", ";
             // Save
         } else {
             if ($_POST["amount"][$k]) {
                 $a = array("amount" => $_POST["amount"][$k], "tfID" => $_POST["tfID"][$k], "fromTfID" => $_POST["fromTfID"][$k], "product" => $_POST["product"][$k], "description" => $_POST["description"][$k], "transactionType" => $_POST["transactionType"][$k], "transactionDate" => $_POST["transactionDate"][$k], "status" => $_POST["status"][$k], "transactionGroupID" => $transactionGroupID, "transactionID" => $_POST["transactionID"][$k]);
                 $transaction = new transaction();
                 if ($_POST["transactionID"][$k]) {
                     $transaction->set_id($_POST["transactionID"][$k]);
                     $transaction->select();
                 }
                 $transaction->read_array($a);
                 $v = $transaction->validate();
                 if ($v == "") {
                     $transaction->save();
                     $saved .= $commar2 . $transaction->get_id();
                     $commar2 = ", ";
                 } else {
                     alloc_error(implode("<br>", $v));
                 }
             }
         }
     }
 }