public function CloseDay($timestamp = false, $report = '', $bFieldsOnly = false) { global $APPLICATION; if (($last_entry = $this->_GetLastData(true)) && (!$last_entry['DATE_FINISH'] || $last_entry['PAUSED'] == 'Y')) { if ($this->OpenAction($bSkipCheck) === 'REOPEN') { $last_entry = $this->ReopenDay(); } if ($timestamp <= 0) { $timestamp = false; } else { $timestamp = CTimeMan::ConvertShortTS($timestamp - CTimeZone::GetOffset(), ConvertTimeStamp(MakeTimeStamp($last_entry['DATE_START'], FORMAT_DATETIME), 'SHORT')); } if ($this->State() == 'EXPIRED' && !$timestamp) { $GLOBALS['APPLICATION']->ThrowException('Workday is expired', 'WD_EXPIRED'); return false; } $arFields = array('USER_ID' => $this->USER_ID, 'DATE_START' => $last_entry['DATE_START'], 'DATE_FINISH' => ConvertTimeStamp(($timestamp ? $timestamp : time()) + CTimeZone::GetOffset(), 'FULL'), 'PAUSED' => 'N'); if (!$this->isEntryValid('CLOSE', $timestamp)) { $arFields['ACTIVE'] = 'N'; if (strlen($report) > 0) { $arFields['REPORTS'] = array(); if ($ex = $APPLICATION->GetException()) { $arFields['REPORTS'][] = array('REPORT_TYPE' => 'ERR_CLOSE', 'REPORT' => $ex->GetId() . ';' . date('c') . ';' . $ex->GetString()); } $arFields['REPORTS'][] = array('REPORT_TYPE' => 'REPORT_CLOSE', 'REPORT' => $report); } else { if ($ex = $APPLICATION->GetException()) { $APPLICATION->ThrowException($ex->GetString(), 'REPORT_NEEDED'); } return false; } } if ($timestamp === false) { $timestamp = time(); } if ($timestamp + CTimeZone::GetOffset() < MakeTimeStamp($last_entry['DATE_START'])) { return false; } $arFields['IP_CLOSE'] = $_SERVER['REMOTE_ADDR']; if ($bFieldsOnly) { return $arFields; } else { if (CTimeManEntry::Update($last_entry['ID'], $arFields)) { if (isset($arFields['ACTIVE']) && $arFields['ACTIVE'] == 'N') { CTimeManNotify::SendMessage($last_entry['ID']); } return $this->_GetLastData(true); } } } else { $GLOBALS['APPLICATION']->ThrowException('WD_NOT_OPEN'); } return false; }