Beispiel #1
0
            $fromTfID = $db->f("tfID");
        } else {
            $msg .= "<b>Warning: Could not find active TF for account '{$account}'</b><br>";
            continue;
        }
        // Check for an existing transaction
        $query = prepare("SELECT * FROM transaction WHERE transactionType='expense' AND transactionDate='%s' AND product='%s' AND amount > %0.3f and amount < %0.3f", $date, $memo, $amount - 0.004, $amount + 0.004);
        $db->query($query);
        if ($db->next_record()) {
            $msg .= "Warning: Expense '{$memo}' on {$date} already exixsts.<br>";
            continue;
        }
        // Create a transaction object and then save it
        $transaction = new transaction();
        $transaction->set_value("companyDetails", $description);
        $transaction->set_value("product", $memo);
        $transaction->set_value("amount", $amount);
        $transaction->set_value("status", "pending");
        $transaction->set_value("expenseFormID", "0");
        $transaction->set_value("fromTfID", $fromTfID);
        $transaction->set_value("tfID", config::get_config_item("mainTfID"));
        $transaction->set_value("quantity", 1);
        $transaction->set_value("invoiceItemID", "0");
        $transaction->set_value("transactionType", "expense");
        $transaction->set_value("transactionDate", "{$date}");
        $transaction->save();
        $msg .= "Expense '{$memo}' on {$date} saved.<br>";
    }
    $TPL["msg"] = $msg;
}
include_template("templates/expenseUploadM.tpl");
Beispiel #2
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();
 }
Beispiel #3
0
    */
    $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"]) {
                alloc_redirect($TPL["url_alloc_transaction"] . "new=true");
            }
            if ($_POST["saveGoTf"]) {
                alloc_redirect($TPL["url_alloc_transactionList"] . "tfID=" . $transaction->get_value("tfID"));
            }
            alloc_redirect($TPL["url_alloc_transaction"] . "transactionID=" . $transaction->get_id());
        }
    }
} else {
    if ($_POST["delete"]) {
        $transaction->delete();
        alloc_redirect($TPL["url_alloc_transactionList"] . "tfID=" . $transaction->get_value("tfID"));
Beispiel #4
0
 function createTransaction($product, $amount, $tfID, $transactionType, $status = "", $fromTfID = false)
 {
     if ($amount == 0) {
         return 1;
     }
     $status or $status = "pending";
     $fromTfID or $fromTfID = $this->fromTfID;
     if ($tfID == 0 || !$tfID || !is_numeric($tfID) || !is_numeric($amount)) {
         return "Error -> \$tfID: " . $tfID . "  and  \$amount: " . $amount;
     } else {
         $transaction = new transaction();
         $transaction->set_value("product", $product);
         $transaction->set_value("amount", $amount);
         $transaction->set_value("status", $status);
         $transaction->set_value("fromTfID", $fromTfID);
         $transaction->set_value("tfID", $tfID);
         $transaction->set_value("transactionDate", date("Y-m-d"));
         $transaction->set_value("transactionType", $transactionType);
         $transaction->set_value("timeSheetID", $this->get_id());
         $transaction->set_value("currencyTypeID", $this->get_value("currencyTypeID"));
         $transaction->save();
         return 1;
     }
 }
 function create_transaction($fromTfID, $tfID, $amount, $description, $currency = false, $productCostID = false, $transactionType = 'sale')
 {
     global $TPL;
     $currency or $currency = config::get_config_item("currency");
     $productSale = $this->get_foreign_object("productSale");
     $date = $productSale->get_value("productSaleDate") or $date = date("Y-m-d");
     $tfID = $productSale->translate_meta_tfID($tfID);
     $fromTfID = $productSale->translate_meta_tfID($fromTfID);
     $transaction = new transaction();
     $transaction->set_value("productSaleID", $this->get_value("productSaleID"));
     $transaction->set_value("productSaleItemID", $this->get_id());
     $transaction->set_value("productCostID", $productCostID);
     $transaction->set_value("fromTfID", $fromTfID);
     $transaction->set_value("tfID", $tfID);
     $transaction->set_value("amount", $amount);
     $transaction->set_value("currencyTypeID", $currency);
     $transaction->set_value("status", 'pending');
     $transaction->set_value("transactionDate", $date);
     $transaction->set_value("transactionType", $transactionType);
     $transaction->set_value("product", $description);
     $transaction->save();
 }