function delete()
 {
     $timeSheetID = $this->get_value("timeSheetID");
     $db = new db_alloc();
     $q = prepare("SELECT invoiceItem.*\n                    FROM invoiceItem\n               LEFT JOIN invoice ON invoiceItem.invoiceID = invoice.invoiceID\n                   WHERE timeSheetID = %d\n                     AND invoiceStatus != 'finished'", $timeSheetID);
     $db->query($q);
     while ($row = $db->row()) {
         $ii = new invoiceItem();
         $ii->set_id($row["invoiceItemID"]);
         $ii->select();
         if ($ii->get_value("timeSheetItemID") == $this->get_id()) {
             $ii->delete();
         } else {
             if (!$ii->get_value("timeSheetItemID")) {
                 invoiceEntity::save_invoice_timeSheet($row["invoiceID"], $timeSheetID);
                 // will update the existing invoice item
             }
         }
     }
     return parent::delete();
 }
Exemple #2
0
function show_new_invoiceItem($template)
{
    global $TPL;
    global $invoice;
    global $invoiceID;
    $current_user =& singleton("current_user");
    // Don't show entry form if no ID
    if (!$invoiceID) {
        return;
    }
    $TPL["div1"] = "";
    $TPL["div2"] = " class=\"hidden\"";
    $TPL["div3"] = " class=\"hidden\"";
    $TPL["div4"] = " class=\"hidden\"";
    if (is_object($invoice) && $invoice->get_value("invoiceStatus") == 'edit' && $current_user->have_role('admin')) {
        // If we are editing an existing invoiceItem
        if (is_array($_POST["invoiceItem_edit"])) {
            $invoiceItemID = key($_POST["invoiceItem_edit"]);
            $invoiceItem = new invoiceItem();
            $invoiceItem->currency = $invoice->get_value("currencyTypeID");
            $invoiceItem->set_id($invoiceItemID);
            $invoiceItem->select();
            $invoiceItem->set_tpl_values("invoiceItem_");
            $TPL["invoiceItem_buttons"] = '
        <button type="submit" name="invoiceItem_delete[' . $invoiceItemID . ']" value="1" class="delete_button">Delete<i class="icon-trash"></i></button>
        <button type="submit" name="invoiceItem_save[' . $invoiceItemID . ']" value="1" class="save_button">Save Item<i class="icon-edit"></i></button>
      ';
            if ($invoiceItem->get_value("timeSheetID")) {
                unset($TPL["div2"]);
                $TPL["div1"] = " class=\"hidden\"";
                $TPL["sbs_link"] = "timeSheet_ii";
            } else {
                if ($invoiceItem->get_value("expenseFormID")) {
                    unset($TPL["div3"]);
                    $TPL["div1"] = " class=\"hidden\"";
                    $TPL["sbs_link"] = "expenseForm_ii";
                } else {
                    if ($invoiceItem->get_value("productSaleID")) {
                        unset($TPL["div4"]);
                        $TPL["div1"] = " class=\"hidden\"";
                        $TPL["sbs_link"] = "productSale_ii";
                    }
                }
            }
            // Else default values for creating a new invoiceItem
        } else {
            $invoiceItem = new invoiceItem();
            $invoiceItem->set_values("invoiceItem_");
            $TPL["invoiceItem_buttons"] = '
         <button type="submit" name="invoiceItem_save" value="1" class="save_button">Add Item<i class="icon-plus-sign"></i></button>
      ';
        }
        // Build dropdown lists for timeSheet and expenseForm options.
        if ($invoice->get_value("clientID")) {
            // Time Sheet dropdown
            $db = new db_alloc();
            $q = prepare("SELECT projectID FROM project WHERE clientID = %d", $invoice->get_value("clientID"));
            $db->query($q);
            $projectIDs = array();
            while ($row = $db->row()) {
                $projectIDs[] = $row["projectID"];
            }
            if ($projectIDs) {
                $q = prepare("SELECT timeSheet.*, project.projectName \n                        FROM timeSheet\n                   LEFT JOIN project ON project.projectID = timeSheet.projectID \n                       WHERE timeSheet.projectID IN (%s) \n                         AND timeSheet.status != 'finished'\n                    GROUP BY timeSheet.timeSheetID\n                    ORDER BY timeSheetID\n                     ", $projectIDs);
                $db->query($q);
                $timeSheetStatii = timeSheet::get_timeSheet_statii();
                while ($row = $db->row()) {
                    $t = new timeSheet();
                    $t->read_db_record($db);
                    $t->load_pay_info();
                    $dollars = $t->pay_info["total_customerBilledDollars"] or $dollars = $t->pay_info["total_dollars"];
                    $timeSheetOptions[$row["timeSheetID"]] = "Time Sheet #" . $t->get_id() . " " . $row["dateFrom"] . " " . $dollars . " for " . person::get_fullname($row["personID"]) . ", Project: " . $row["projectName"] . " [" . $timeSheetStatii[$t->get_value("status")] . "]";
                }
                $TPL["timeSheetOptions"] = page::select_options($timeSheetOptions, $invoiceItem->get_value("timeSheetID"), 150);
            }
            // Expense Form dropdown
            $db = new db_alloc();
            $q = prepare("SELECT expenseFormID, expenseFormCreatedUser\n                      FROM expenseForm \n                     WHERE expenseFormFinalised = 1 \n                       AND seekClientReimbursement = 1\n                       AND clientID = %d\n                  ORDER BY expenseForm.expenseFormCreatedTime", $invoice->get_value("clientID"));
            $db->query($q);
            while ($row = $db->row()) {
                $expenseFormOptions[$row["expenseFormID"]] = "Expense Form #" . $row["expenseFormID"] . " " . page::money(config::get_config_item("currency"), expenseForm::get_abs_sum_transactions($row["expenseFormID"]), "%s%m %c") . " " . person::get_fullname($row["expenseFormCreatedUser"]);
            }
            if ($invoiceItem->get_value("expenseFormID")) {
                $id = $invoiceItem->get_value("expenseFormID");
            }
            $TPL["expenseFormOptions"] = page::select_options($expenseFormOptions, $id, 90);
            $q = prepare("SELECT *\n                      FROM productSale\n                     WHERE clientID = %d\n                       AND status = 'admin'\n                   ", $invoice->get_value("clientID"));
            $invoice->get_value("projectID") and $q .= prepare(" AND projectID = %d", $invoice->get_value("projectID"));
            $db->query($q);
            while ($row = $db->row()) {
                $productSale = new productSale();
                $productSale->set_id($row["productSaleID"]);
                $productSale->select();
                $ps_row = $productSale->get_amounts();
                $productSaleOptions[$row["productSaleID"]] = "Sale #" . $row["productSaleID"] . " " . $ps_row["total_sellPrice"] . " " . person::get_fullname($row["personID"]);
            }
            if ($invoiceItem->get_value("productSaleID")) {
                $id = $invoiceItem->get_value("productSaleID");
            }
            $TPL["productSaleOptions"] = page::select_options($productSaleOptions, $id, 90);
        }
        $TPL["invoiceItem_iiQuantity"] or $TPL["invoiceItem_iiQuantity"] = 1;
        $TPL["invoiceItem_invoiceID"] = $invoice->get_id();
        include_template($template);
    }
}
Exemple #3
0
 function close_related_entities()
 {
     $db = new db_alloc();
     $invoiceItemIDs = $this->get_invoiceItems();
     foreach ($invoiceItemIDs as $invoiceItemID) {
         $q = prepare("SELECT *\n                      FROM transaction\n                     WHERE invoiceItemID = %d\n                       AND status = 'pending'", $invoiceItemID);
         $db->query($q);
         if (!$db->next_record()) {
             $invoiceItem = new invoiceItem();
             $invoiceItem->set_id($invoiceItemID);
             $invoiceItem->select();
             $invoiceItem->close_related_entity();
         }
     }
 }