Ejemplo n.º 1
0
 function save()
 {
     $current_user =& singleton("current_user");
     global $TPL;
     $errors = $this->validate();
     if ($errors) {
         alloc_error($errors);
     } else {
         $existing = $this->all_row_fields;
         if ($existing["taskStatus"] != $this->get_value("taskStatus")) {
             $db = new db_alloc();
             $db->query("call change_task_status(%d,'%s')", $this->get_id(), $this->get_value("taskStatus"));
             $row = $db->qr("SELECT taskStatus\n                              ,dateActualCompletion\n                              ,dateActualStart\n                              ,dateClosed\n                              ,closerID\n                          FROM task\n                         WHERE taskID = %d", $this->get_id());
             // Changing a task's status changes these fields.
             // Unfortunately the call to save() below erroneously nukes these fields.
             // So we manually set them to whatever change_task_status() has dictated.
             $this->set_value("taskStatus", $row["taskStatus"]);
             $this->set_value("dateActualCompletion", $row["dateActualCompletion"]);
             $this->set_value("dateActualStart", $row["dateActualStart"]);
             $this->set_value("dateClosed", $row["dateClosed"]);
             $this->set_value("closerID", $row["closerID"]);
         }
         return parent::save();
     }
 }
Ejemplo n.º 2
0
 function save()
 {
     $current_user =& singleton("current_user");
     $timeSheet = new timeSheet();
     $timeSheet->set_id($this->get_value("timeSheetID"));
     $timeSheet->select();
     $timeSheet->load_pay_info();
     list($amount_used, $amount_allocated) = $timeSheet->get_amount_allocated("%mo");
     $this->currency = $timeSheet->get_value("currencyTypeID");
     $this->set_value("comment", rtrim($this->get_value("comment")));
     $amount_of_item = $this->calculate_item_charge($timeSheet->get_value("currencyTypeID"), $timeSheet->get_value("customerBilledDollars"));
     if ($amount_allocated && $amount_of_item + $amount_used > $amount_allocated) {
         alloc_error("Adding this Time Sheet Item would exceed the amount allocated on the Pre-paid invoice. Time Sheet Item not saved.");
     }
     // If unit is changed via CLI
     if ($this->get_value("timeSheetItemDurationUnitID") && $timeSheet->pay_info["project_rateUnitID"] && $timeSheet->pay_info["project_rateUnitID"] != $this->get_value("timeSheetItemDurationUnitID") && !$timeSheet->can_edit_rate()) {
         alloc_error("Not permitted to edit time sheet item unit.");
     }
     if (!$this->get_value("timeSheetItemDurationUnitID") && $timeSheet->pay_info["project_rateUnitID"]) {
         $this->set_value("timeSheetItemDurationUnitID", $timeSheet->pay_info["project_rateUnitID"]);
     }
     // Last ditch perm checking - useful for the CLI
     if (!is_object($timeSheet) || !$timeSheet->get_id()) {
         alloc_error("Unknown time sheet.");
     }
     if ($timeSheet->get_value("status") != "edit" && !$this->skip_tsi_status_check) {
         alloc_error("Time sheet is not at status edit");
     }
     if (!$this->is_owner()) {
         alloc_error("Time sheet is not editable for you.");
     }
     $rtn = parent::save();
     $timeSheet->update_related_invoices();
     return $rtn;
 }
Ejemplo n.º 3
0
 function save()
 {
     if (!imp($this->get_value("iiAmount"))) {
         $this->set_value("iiAmount", $this->get_value("iiQuantity") * $this->get_value("iiUnitPrice"));
     }
     $status = parent::save();
     $status2 = invoice::update_invoice_dates($this->get_value("invoiceID"));
     return $status && $status2;
 }
Ejemplo n.º 4
0
 function save()
 {
     $rtn = parent::save();
     $c = new client();
     $c->set_id($this->get_value("clientID"));
     $c->select();
     $c->save();
     return $rtn;
 }
Ejemplo n.º 5
0
 function save($dates = "")
 {
     $rtn = parent::save();
     if ($rtn) {
         $dates = str_replace(",", " ", $dates);
         $dates = preg_replace("/\\s+/", " ", trim($dates));
         $dates = explode(" ", $dates);
         $db = new db_alloc();
         $db->query("DELETE FROM invoiceRepeatDate WHERE invoiceRepeatID = %d", $this->get_id());
         foreach ($dates as $date) {
             $db->query("INSERT INTO invoiceRepeatDate (invoiceRepeatID,invoiceDate) VALUES (%d,'%s')", $this->get_id(), $date);
         }
     }
 }
Ejemplo n.º 6
0
 function save()
 {
     if ($this->get_value("commentType") == "comment") {
         $parent_comment = new comment();
         $parent_comment->set_id($this->get_value("commentLinkID"));
         $parent_comment->select();
         $this->set_value("commentMaster", $parent_comment->get_value("commentType"));
         $this->set_value("commentMasterID", $parent_comment->get_value("commentLinkID"));
     } else {
         $this->set_value("commentMaster", $this->get_value("commentType"));
         $this->set_value("commentMasterID", $this->get_value("commentLinkID"));
     }
     $this->set_value("comment", str_replace("\r\n", "\n", $this->get_value("comment")));
     return parent::save();
 }
 function save()
 {
     // Just ensure multiple 0 entries cannot be saved.
     if ($this->get_value("commissionPercent") == 0) {
         $q = prepare("SELECT * FROM projectCommissionPerson WHERE projectID = %d AND commissionPercent = 0 AND projectCommissionPersonID != %d", $this->get_value("projectID"), $this->get_id());
         $db = new db_alloc();
         $db->query($q);
         if ($db->next_record()) {
             $fail = true;
             alloc_error("Only one Time Sheet Commission is allowed to be set to 0%");
         }
     }
     if (!$fail) {
         parent::save();
     }
 }
Ejemplo n.º 8
0
 function save()
 {
     // These need to be in here instead of validate(), because
     // validate is called after save() and we need these values set for save().
     $this->get_value("currencyTypeID") or $this->set_value("currencyTypeID", config::get_config_item("currency"));
     $this->get_value("destCurrencyTypeID") or $this->set_value("destCurrencyTypeID", config::get_config_item("currency"));
     // The data prior to the save
     $old = $this->all_row_fields;
     if ($old["status"] != $this->get_value("status") && $this->get_value("status") == "approved") {
         $this->set_value("dateApproved", date("Y-m-d"));
         $field_changed = true;
     } else {
         if ($this->get_value("status") != "approved") {
             $this->set_value("dateApproved", "");
         }
     }
     if ($old["currencyTypeID"] != $this->get_value("currencyTypeID")) {
         $field_changed = true;
     }
     if ($old["destCurrencyTypeID"] != $this->get_value("destCurrencyTypeID")) {
         $field_changed = true;
     }
     $db = new db_alloc();
     // If there already is an exchange rate set for an approved
     // transaction, then there's no need to update the exchange rate
     if ($this->get_value("exchangeRate") && $this->get_value("dateApproved") && !$field_changed) {
         // Else update the transaction's exchange rate
     } else {
         $this->get_value("transactionCreatedTime") and $date = format_date("Y-m-d", $this->get_value("transactionCreatedTime"));
         $this->get_value("transactionModifiedTime") and $date = format_date("Y-m-d", $this->get_value("transactionModifiedTime"));
         $this->get_value("transactionDate") and $date = $this->get_value("transactionDate");
         $this->get_value("dateApproved") and $date = $this->get_value("dateApproved");
         $er = exchangeRate::get_er($this->get_value("currencyTypeID"), $this->get_value("destCurrencyTypeID"), $date);
         if (!$er) {
             alloc_error("Unable to determine exchange rate for " . $this->get_value("currencyTypeID") . " to " . $this->get_value("destCurrencyTypeID") . " for date: " . $date);
         } else {
             $this->set_value("exchangeRate", $er);
         }
     }
     return parent::save();
 }
Ejemplo n.º 9
0
 function save()
 {
     if (!$this->get_value("currencyTypeID")) {
         if ($this->get_value("projectID")) {
             $project = $this->get_foreign_object("project");
             $currencyTypeID = $project->get_value("currencyTypeID");
         } else {
             if (config::get_config_item("currency")) {
                 $currencyTypeID = config::get_config_item("currency");
             }
         }
         if (!imp($this->get_value("maxAmount"))) {
             $this->set_value("maxAmount", '');
         }
         if ($currencyTypeID) {
             $this->set_value("currencyTypeID", $currencyTypeID);
         } else {
             alloc_error("Unable to save invoice. No currency is able to be determined. Either attach this invoice to a project, or set a Main Currency on the Setup -> Finance screen.");
         }
     }
     return parent::save();
 }
Ejemplo n.º 10
0
 function save()
 {
     global $TPL;
     // The data prior to the save
     $old = $this->all_row_fields;
     $ids = '';
     $commar = '';
     $db = new db_alloc();
     // If we're archiving the project, then archive the tasks.
     if ($old["projectStatus"] != "Archived" && $this->get_value("projectStatus") == "Archived") {
         $q = prepare("SELECT taskID FROM task WHERE projectID = %d AND SUBSTRING(taskStatus,1,6) != 'closed'", $this->get_id());
         $q1 = $db->query($q);
         while ($row = $db->row($q1)) {
             $q = prepare("call change_task_status(%d,'closed_archived')", $row["taskID"]);
             $db->query($q);
             $ids .= $commar . $row["taskID"];
             $commar = ", ";
         }
         $ids and $TPL["message_good"][] = "All open and pending tasks (" . $ids . ") have had their status changed to Closed: Archived.";
         // Else if we're un-archiving the project, then un-archive the tasks.
     } else {
         if ($old["projectStatus"] == "Archived" && $this->get_value("projectStatus") != "Archived") {
             $q = prepare("SELECT taskID FROM task WHERE projectID = %d AND taskStatus = 'closed_archived'", $this->get_id());
             $q1 = $db->query($q);
             while ($row = $db->row($q1)) {
                 $q = prepare("call change_task_status(%d,get_most_recent_non_archived_taskStatus(%d))", $row["taskID"], $row["taskID"]);
                 $db->query($q);
                 $ids .= $commar . $row["taskID"];
                 $commar = ", ";
             }
             $ids and $TPL["message_good"][] = "All archived tasks (" . $ids . ") have been set back to their former task status.";
         }
     }
     $TPL["message"] or $TPL["message_good"][] = "Project saved.";
     return parent::save();
 }
Ejemplo n.º 11
0
 function save()
 {
     $this->set_value("emailAddress", str_replace(array("<", ">"), "", $this->get_value("emailAddress")));
     return parent::save();
 }
Ejemplo n.º 12
0
 function save()
 {
     $rtn = parent::save();
     $this->update_related_invoices();
     return $rtn;
 }