示例#1
0
 function close_related_entity()
 {
     global $TPL;
     // It checks for approved transactions and only approves the timesheets
     // or expenseforms that are completely paid for by an invoice item.
     $db = new db_alloc();
     $q = prepare("SELECT amount, currencyTypeID, status \n                    FROM transaction \n                   WHERE invoiceItemID = %d \n                ORDER BY transactionCreatedTime DESC \n                   LIMIT 1\n                 ", $this->get_id());
     $db->query($q);
     $row = $db->row();
     $total = $row["amount"];
     $currency = $row["currencyTypeID"];
     $status = $row["status"];
     $timeSheetID = $this->get_value("timeSheetID");
     $expenseFormID = $this->get_value("expenseFormID");
     if ($timeSheetID) {
         $timeSheet = new timeSheet();
         $timeSheet->set_id($timeSheetID);
         $timeSheet->select();
         $db = new db_alloc();
         if ($timeSheet->get_value("status") == "invoiced") {
             // If the time sheet doesn't have any transactions and it is in
             // status invoiced, then we'll simulate the "Create Default Transactions"
             // button being pressed.
             $q = prepare("SELECT count(*) as num_transactions \n                        FROM transaction \n                       WHERE timeSheetID = %d \n                         AND invoiceItemID IS NULL\n                     ", $timeSheet->get_id());
             $db->query($q);
             $row = $db->row();
             if ($row["num_transactions"] == 0) {
                 $_POST["create_transactions_default"] = true;
                 $timeSheet->createTransactions($status);
                 $TPL["message_good"][] = "Automatically created time sheet transactions.";
             }
             // Get total of all time sheet transactions.
             $q = prepare("SELECT SUM(amount) AS total \n                        FROM transaction \n                       WHERE timeSheetID = %d \n                         AND status != 'rejected' \n                         AND invoiceItemID IS NULL\n                     ", $timeSheet->get_id());
             $db->query($q);
             $row = $db->row();
             $total_timeSheet = $row["total"];
             if ($total >= $total_timeSheet) {
                 $timeSheet->pending_transactions_to_approved();
                 $timeSheet->change_status("forwards");
                 $TPL["message_good"][] = "Closed Time Sheet #" . $timeSheet->get_id() . " and marked its Transactions: " . $status;
             } else {
                 $TPL["message_help"][] = "Unable to close Time Sheet #" . $timeSheet->get_id() . " the sum of the Time Sheet's *Transactions* (" . page::money($timeSheet->get_value("currencyTypeID"), $total_timeSheet, "%s%mo %c") . ") is greater than the Invoice Item Transaction (" . page::money($currency, $total, "%s%mo %c") . ")";
             }
         }
     } else {
         if ($expenseFormID) {
             $expenseForm = new expenseForm();
             $expenseForm->set_id($expenseFormID);
             $expenseForm->select();
             $total_expenseForm = $expenseForm->get_abs_sum_transactions();
             if ($total == $total_expenseForm) {
                 $expenseForm->set_status("approved");
                 $TPL["message_good"][] = "Approved Expense Form #" . $expenseForm->get_id() . ".";
             } else {
                 $TPL["message_help"][] = "Unable to approve Expense Form #" . $expenseForm->get_id() . " the sum of Expense Form Transactions does not equal the Invoice Item Transaction.";
             }
         }
     }
 }
示例#2
0
    $_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");
}
示例#3
0
 function save_invoice_expenseFormItems($invoiceID, $expenseFormID)
 {
     $expenseForm = new expenseForm();
     $expenseForm->set_id($expenseFormID);
     $expenseForm->select();
     $db = new db_alloc();
     $q1 = $db->query("SELECT * FROM transaction WHERE expenseFormID = %d", $expenseFormID);
     while ($row = $db->row($q1)) {
         $amount = page::money($row["currencyTypeID"], $row["amount"], "%mo");
         $q = prepare("SELECT * FROM invoiceItem WHERE expenseFormID = %d AND transactionID = %d", $expenseFormID, $row["transactionID"]);
         $db = new db_alloc();
         $q2 = $db->query($q);
         $r2 = $db->row($q2);
         $ii = new invoiceItem();
         if ($r2) {
             $ii->set_id($r2["invoiceItemID"]);
         }
         $ii->currency = $row["currencyTypeID"];
         $ii->set_value("invoiceID", $invoiceID);
         $ii->set_value("expenseFormID", $expenseForm->get_id());
         $ii->set_value("transactionID", $row["transactionID"]);
         $ii->set_value("iiMemo", "Expenses for " . person::get_fullname($expenseForm->get_value("expenseFormCreatedUser")) . ", " . $row["product"]);
         $ii->set_value("iiQuantity", $row["quantity"]);
         $ii->set_value("iiUnitPrice", $amount / $row["quantity"]);
         $ii->set_value("iiAmount", $amount);
         $ii->set_value("iiDate", $row["transactionDate"]);
         $ii->set_value("iiTax", config::get_config_item("taxPercent"));
         $ii->save();
     }
 }