/** * Change invoice status * * @param integer $status * @param User $by * @param DateValue $on * @return null */ function setStatus($status, $by = null, $on = null) { $on = instance_of($on, 'DateValue') ? $on : new DateValue(); $by = instance_of($by, 'User') ? $by : get_logged_user(); switch ($status) { // Mark invoice as draft case INVOICE_STATUS_DRAFT: parent::setStatus($status); $this->setIssuedOn(null); $this->setIssuedById(null); $this->setIssuedByName(null); $this->setIssuedByEmail(null); $this->setClosedOn(null); $this->setClosedById(null); $this->setClosedByName(null); $this->setClosedByEmail(null); break; // Mark invoice as issued // Mark invoice as issued case INVOICE_STATUS_ISSUED: parent::setStatus($status); if ($on) { $this->setIssuedOn($on); } // if if ($by) { $this->setIssuedById($by->getId()); $this->setIssuedByName($by->getName()); $this->setIssuedByEmail($by->getEmail()); } // if $this->setClosedOn(null); $this->setClosedById(null); $this->setClosedByName(null); $this->setClosedByEmail(null); $this->setTimeRecordsStatus(BILLABLE_STATUS_PENDING_PAYMENT); break; // Mark invoice as billed // Mark invoice as billed case INVOICE_STATUS_BILLED: parent::setStatus(INVOICE_STATUS_BILLED); $this->setClosedOn($on); $this->setClosedById($by->getId()); $this->setClosedByName($by->getName()); $this->setClosedByEmail($by->getEmail()); $this->setTimeRecordsStatus(BILLABLE_STATUS_BILLED); break; // Mark invoice as canceled // Mark invoice as canceled case INVOICE_STATUS_CANCELED: parent::setStatus(INVOICE_STATUS_CANCELED); $this->setClosedOn($on); $this->setClosedById($by->getId()); $this->setClosedByName($by->getName()); $this->setClosedByEmail($by->getEmail()); InvoicePayments::deleteByInvoice($this); $this->setTimeRecordsStatus(BILLABLE_STATUS_BILLABLE); $this->releaseTimeRecords(); break; default: return new InvalidParamError('status', $status, '$status is not valid invoice status', true); } // switch }