$_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"]) { $transaction_to_edit->set_id($_POST["transactionID"]); $transaction_to_edit->select(); $TPL["transactionID"] = $_POST["transactionID"]; } $transaction_to_edit->set_values(); if ($transaction_to_edit->get_value("quantity")) { $TPL["amount"] = $transaction_to_edit->get_value("amount", DST_HTML_DISPLAY) / $transaction_to_edit->get_value("quantity");
if ($db->next_record()) { $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; }
$status = "rejected"; } } } $query = prepare("UPDATE transaction SET status = '%s' WHERE timeSheetID = %d AND transactionType != 'invoice'", $status, $timeSheet->get_id()); $db = new db_alloc(); $db->query($query); // Take care of the transaction line items on an invoiced timesheet created by admin } else { if (($_POST["transaction_save"] || $_POST["transaction_delete"]) && $timeSheet->have_perm(PERM_TIME_INVOICE_TIMESHEETS)) { $transaction = new transaction(); $transaction->read_globals(); $transaction->read_globals("transaction_"); if ($_POST["transaction_save"]) { if (is_numeric($_POST["percent_dropdown"])) { $transaction->set_value("amount", $_POST["percent_dropdown"]); } $transaction->set_value("currencyTypeID", $timeSheet->get_value("currencyTypeID")); $transaction->save(); } else { if ($_POST["transaction_delete"]) { $transaction->delete(); } } } } // display the approved by admin and managers name and date $person = new person(); if ($timeSheet->get_value("approvedByManagerPersonID")) { $person_approvedByManager = new person(); $person_approvedByManager->set_id($timeSheet->get_value("approvedByManagerPersonID"));
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(); }
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; } }
} */ $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();
if (!preg_match("/^[-]?[0-9]+(\\.[0-9]+)?\$/", $amount)) { $msg .= "<b>Warning: Could not convert amount '{$amount}'</b><br>"; continue; } // Negate the amount - Wages are a debit from TF's $amount = -$amount; // Check for an existing transaction for this wage - note we have to use a range or amount because it is floating point $query = prepare("SELECT transactionID\n FROM transaction\n WHERE fromTfID=%d AND transactionDate='%s' AND amount=%d", $fromTfID, $transactionDate, page::money(config::get_config_item("currency"), $amount, "%mi")); $db->query($query); if ($db->next_record()) { $msg .= "Warning: Salary for employee #{$employeeNum} {$name} on {$transactionDate} already exists as transaction #" . $db->f("transactionID") . "<br>"; continue; } // Create a transaction object and then save it $transaction = new transaction(); $transaction->set_value("currencyTypeID", config::get_config_item("currency")); $transaction->set_value("fromTfID", $fromTfID); $transaction->set_value("tfID", config::get_config_item("outTfID")); $transaction->set_value("transactionDate", $transactionDate); $transaction->set_value("amount", $amount); $transaction->set_value("companyDetails", ""); $transaction->set_value("product", $account); $transaction->set_value("status", "approved"); $transaction->set_value("quantity", 1); $transaction->set_value("transactionType", "salary"); $transaction->save(); $msg .= "\${$amount} for employee {$employeeNum} {$name} on {$transactionDate} saved<br>"; } $TPL["msg"] = $msg; } $TPL["main_alloc_title"] = "Upload Wages File - " . APPLICATION_NAME;
$tf->set_id($transactionRepeat->get_value("tfID")); $tf->select(); if (!$tf->get_value("tfActive")) { 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); }
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(); }