Пример #1
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();
     }
 }
Пример #2
0
 public static function get_list($_FORM = array())
 {
     global $TPL;
     $filter = expenseForm::get_list_filter($_FORM);
     if (is_array($filter) && count($filter)) {
         $f = " AND " . implode(" AND ", $filter);
     }
     $db = new db_alloc();
     $dbTwo = new db_alloc();
     $transDB = new db_alloc();
     $expenseForm = new expenseForm();
     $transaction = new transaction();
     $rr_options = expenseForm::get_reimbursementRequired_array();
     $q = prepare("SELECT expenseForm.*\n                        ,SUM(transaction.amount * pow(10,-currencyType.numberToBasic)) as formTotal\n                        ,transaction.currencyTypeID\n                    FROM expenseForm, transaction\n               LEFT JOIN currencyType on transaction.currencyTypeID = currencyType.currencyTypeID\n                   WHERE expenseForm.expenseFormID = transaction.expenseFormID\n                         " . $f . "\n                GROUP BY expenseForm.expenseFormID, transaction.currencyTypeID\n                ORDER BY expenseFormID");
     $db->query($q);
     while ($row = $db->row()) {
         $amounts[$row["expenseFormID"]] .= $sp[$row["expenseFormID"]] . page::money($row["currencyTypeID"], $row["formTotal"], "%s%m");
         $sp[$row["expenseFormID"]] = " + ";
         $allrows[$row["expenseFormID"]] = $row;
     }
     foreach ((array) $allrows as $expenseFormID => $row) {
         $expenseForm = new expenseForm();
         if ($expenseForm->read_row_record($row)) {
             $expenseForm->set_values();
             $row["formTotal"] = $amounts[$expenseFormID];
             $row["expenseFormModifiedUser"] = person::get_fullname($expenseForm->get_value("expenseFormModifiedUser"));
             $row["expenseFormModifiedTime"] = $expenseForm->get_value("expenseFormModifiedTime");
             $row["expenseFormCreatedUser"] = person::get_fullname($expenseForm->get_value("expenseFormCreatedUser"));
             $row["expenseFormCreatedTime"] = $expenseForm->get_value("expenseFormCreatedTime");
             unset($extra);
             $expenseForm->get_value("paymentMethod") and $extra = " (" . $expenseForm->get_value("paymentMethod") . ")";
             $row["rr_label"] = $rr_options[$expenseForm->get_value("reimbursementRequired")] . $extra;
             $rows[] = $row;
         }
     }
     return (array) $rows;
 }