// 'member_of' => array()); // List of groups, membership in which is required for user to be authenticated.
// define('AUTH_DEBUG', false); // Note: enabling AUTH_DEBUG breaks redirects as debug output is printed before setting redirect header. Do not enable on production systems.
+
+// team manager can set monthly quota for years between these values:
+define('MONTHLY_QUOTA_YEARS_START', 2010); // if nothing is specified, it falls back to 2010
+define('MONTHLY_QUOTA_YEARS_END', 2031); // if nothing is specified it falls back to 2030
static function update($team_id, $fields)
{
// We'll require team name to be always set.
- if (!isset($fields['name'])) return false;
+ if (!isset($fields['name']) || $fields['name'] == "") return false;
$mdb2 = getConnection();
$name_part = 'name = '.$mdb2->quote($fields['name']);
$record_type_part = '';
$plugins_part = '';
$lock_spec_part = '';
+ $working_hours_part = '';
if (isset($fields['address'])) $addr_part = ', address = '.$mdb2->quote($fields['address']);
if (isset($fields['currency'])) $currency_part = ', currency = '.$mdb2->quote($fields['currency']);
if (isset($fields['record_type'])) $record_type_part = ', record_type = '.intval($fields['record_type']);
if (isset($fields['plugins'])) $plugins_part = ', plugins = '.$mdb2->quote($fields['plugins']);
if (isset($fields['lock_spec'])) $lock_spec_part = ', lock_spec = '.$mdb2->quote($fields['lock_spec']);
+ if (isset($fields['working_hours'])) $working_hours_part = ', daily_working_hours = '.$mdb2->quote($fields['working_hours']);
$sql = "update tt_teams set $name_part $addr_part $currency_part $lang_part $decimal_mark_part
$date_format_part $time_format_part $week_start_part $tracking_mode_part $record_type_part
- $plugins_part $lock_spec_part where id = $team_id";
+ $plugins_part $lock_spec_part $working_hours_part where id = $team_id";
$affected = $mdb2->exec($sql);
if (is_a($affected, 'PEAR_Error')) return false;
// 'label.year' => 'Year',
// 'label.month' => 'Month',
// 'label.quota' => 'Quota',
+// 'label.dailyWorkingHours' => 'Daily working hours',
+// 'label.empty_values_explanation' => 'If values are empty, quotas are calculated automatically based on holidays in config',
// Form titles.
'title.login' => 'Anmelden',
'label.year' => 'Year',
'label.month' => 'Month',
'label.quota' => 'Quota',
+'label.dailyWorkingHours' => 'Daily working hours',
+'label.empty_values_explanation' => 'If values are empty, quotas are calculated automatically based on holidays in config',
// Form titles.
'title.login' => 'Login',
// 'label.year' => 'Year',
// 'label.month' => 'Month',
// 'label.quota' => 'Quota',
+// 'label.dailyWorkingHours' => 'Daily working hours',
+// 'label.empty_values_explanation' => 'If values are empty, quotas are calculated automatically based on holidays in config',
// Form titles.
'title.login' => 'Sesión iniciada',
// 'label.year' => 'Year',
// 'label.month' => 'Month',
// 'label.quota' => 'Quota',
+// 'label.dailyWorkingHours' => 'Daily working hours',
+// 'label.empty_values_explanation' => 'If values are empty, quotas are calculated automatically based on holidays in config',
// Form titles.
'title.login' => 'ورود',
// 'label.year' => 'Year',
// 'label.month' => 'Month',
// 'label.quota' => 'Quota',
+// 'label.dailyWorkingHours' => 'Daily working hours',
+// 'label.empty_values_explanation' => 'If values are empty, quotas are calculated automatically based on holidays in config',
// Form titles.
'title.login' => 'Kirjautuminen',
// 'label.year' => 'Year',
// 'label.month' => 'Month',
// 'label.quota' => 'Quota',
+// 'label.dailyWorkingHours' => 'Daily working hours',
+// 'label.empty_values_explanation' => 'If values are empty, quotas are calculated automatically based on holidays in config',
// Form titles.
'title.login' => 'Connexion',
// 'label.year' => 'Year',
// 'label.month' => 'Month',
// 'label.quota' => 'Quota',
+// 'label.dailyWorkingHours' => 'Daily working hours',
+// 'label.empty_values_explanation' => 'If values are empty, quotas are calculated automatically based on holidays in config',
// Form titles.
'title.login' => 'כניסה',
// 'label.year' => 'Year',
// 'label.month' => 'Month',
// 'label.quota' => 'Quota',
+// 'label.dailyWorkingHours' => 'Daily working hours',
+// 'label.empty_values_explanation' => 'If values are empty, quotas are calculated automatically based on holidays in config',
// Form titles.
'title.login' => 'Aanmelden',
// 'label.year' => 'Year',
// 'label.month' => 'Month',
// 'label.quota' => 'Quota',
+// 'label.dailyWorkingHours' => 'Daily working hours',
+// 'label.empty_values_explanation' => 'If values are empty, quotas are calculated automatically based on holidays in config',
// Form titles.
'title.login' => 'Logowanie',
// 'label.year' => 'Year',
// 'label.month' => 'Month',
// 'label.quota' => 'Quota',
+// 'label.dailyWorkingHours' => 'Daily working hours',
+// 'label.empty_values_explanation' => 'If values are empty, quotas are calculated automatically based on holidays in config',
// Form titles.
'title.login' => 'Login',
// 'label.year' => 'Year',
// 'label.month' => 'Month',
// 'label.quota' => 'Quota',
+// 'label.dailyWorkingHours' => 'Daily working hours',
+// 'label.empty_values_explanation' => 'If values are empty, quotas are calculated automatically based on holidays in config',
// Form titles.
'title.login' => 'Вход в систему',
// 'label.year' => 'Year',
// 'label.month' => 'Month',
// 'label.quota' => 'Quota',
+// 'label.dailyWorkingHours' => 'Daily working hours',
+// 'label.empty_values_explanation' => 'If values are empty, quotas are calculated automatically based on holidays in config',
// Form titles.
'title.login' => 'Prihlásenie',
// 'label.year' => 'Year',
// 'label.month' => 'Month',
// 'label.quota' => 'Quota',
+// 'label.dailyWorkingHours' => 'Daily working hours',
+// 'label.empty_values_explanation' => 'If values are empty, quotas are calculated automatically based on holidays in config',
// Form titles.
'title.login' => 'Prijava',
{$forms.monthlyQuotaForm.open}
+<div style="padding: 0 0 10 0">
+ <table border="0" class="divider">
+ <tr>
+ <td align="center">
+ <table>
+ <tr>
+ <td>{$i18n.label.dailyWorkingHours}</td>
+ <td>{$forms.monthlyQuotaForm.dailyWorkingHours.control}</td>
+ <td><input type="submit" name="dailyHours" value="{$i18n.button.save}"></td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+</div>
<table>
<tr>
- <td>{$i18n.label.year}</td>
+ <td>{$i18n.label.year}:</td>
<td>{$forms.monthlyQuotaForm.years.control}</td>
</tr>
<tr>
<td>{$month}</td>
<td>{$forms.monthlyQuotaForm.$month.control}</td>
</tr>
- {/foreach}
+ {/foreach}
<tr>
<td colspan="2" style="text-align:center;">
- <input type="submit" value="{$i18n.button.save}">
+ <input type="submit" name="quotas" value="{$i18n.button.save}*">
</td>
</tr>
</table>
</td>
</tr>
</table>
+<div>* - {$i18n.label.empty_values_explanation}</div>
{$forms.monthlyQuotaForm.close}
<script>
function yearChange(value){
{$forms.reportForm.open}
<div style="padding: 0 0 10 0;">
- <table border="0" bgcolor="#efefef" width="720">
+ <table border="0" class="divider">
<tr>
<td>
<table cellspacing="1" cellpadding="3" border="0">
</table>
<div style="padding: 10 0 10 0;">
- <table border="0" bgcolor="#efefef" width="720">
+ <table border="0" class="divider">
<tr>
<td align="center">
<table cellspacing="1" cellpadding="3" border="0">
require_once('initialize.php');
require_once('plugins/MonthlyQuota.class.php');
import('form.Form');
+import('WEB-INF/lib/ttTeamHelper');
// Access check.
if (!ttAccessCheck(right_manage_team)) {
exit();
}
-$form = new Form('monthlyQuotaForm');
-// months are zero indexed
-$months = $i18n->monthNames;
+// fallback values
+$yearStart = 2010;
+$yearEnd = 2030;
+
+if (defined('MONTHLY_QUOTA_YEARS_START')){
+ $yearStart = (int)MONTHLY_QUOTA_YEARS_START;
+}
+if (defined('MONTHLY_QUOTA_YEARS_END')){
+ $yearEnd = (int)MONTHLY_QUOTA_YEARS_END;
+}
+
+// create values for dropdown
$years = array();
-for ($i=1990; $i < 2040; $i++) {
+for ($i=$yearStart; $i < $yearEnd; $i++) {
array_push($years, array('id'=>$i, 'name'=>$i));
}
-$year = $request->getParameter("year");
-if (!$year or !ttValidInteger($year)){
- $year = date("Y");
-}else {
- $year = intval($year);
+// get selected year from url parameters
+$selectedYear = $request->getParameter("year");
+if (!$selectedYear or !ttValidInteger($selectedYear)){
+ $selectedYear = date("Y");
+} else {
+ $selectedYear = intval($selectedYear);
}
+// months are zero indexed
+$months = $i18n->monthNames;
+
$quota = new MonthlyQuota();
if ($request->isPost()){
- $postedYear = $request->getParameter("years");
- $year = intval($postedYear);
$res = false;
- for ($i=0; $i < count($months); $i++){
- $res = $quota->update($postedYear, $i+1, $request->getParameter($months[$i]));
+ // if user pressed save fpr monthly quotas
+ if ($_POST["quotas"]){
+ $postedYear = $request->getParameter("years");
+ $selectedYear = intval($postedYear);
+ for ($i=0; $i < count($months); $i++){
+ $res = $quota->update($postedYear, $i+1, $request->getParameter($months[$i]));
+ }
+ }
+ // if user saved required working hours for a day
+ if ($_POST["dailyHours"]){
+ $hours = $request->getParameter("dailyWorkingHours");
+ $teamDetails = ttTeamHelper::getTeamDetails($quota->usersTeamId);
+ $res = ttTeamHelper::update($quota->usersTeamId, array('name'=>$teamDetails['team_name'],
+ 'working_hours'=>$hours));
}
- if ($res){
+ if ($res) {
header('Location: profile_edit.php');
exit();
- } else
- $err->add($i18n->getKey('error.db'));
+ } else {
+ $err->add($i18n->getKey('error.db'));
+ }
}
// returns months where January is month 1, not 0
-$monthsData = $quota->get($year);
+$monthsData = $quota->get($selectedYear);
+
+$form = new Form('monthlyQuotaForm');
-$form->addInput(array('type'=>'combobox', 'name'=>'years', 'data'=>$years, 'datakeys'=>array('id', 'name'), 'value'=>$year, 'onchange'=>'yearChange(this.value);'));
+$form->addInput(array('type'=>'combobox', 'name'=>'years', 'data'=>$years, 'datakeys'=>array('id', 'name'), 'value'=>$selectedYear, 'onchange'=>'yearChange(this.value);'));
for ($i=0; $i < count($months); $i++) {
$value = "";
if (array_key_exists($i+1, $monthsData)){
$name = $months[$i];
$form->addInput(array('type'=>'text', 'name'=>$name, 'maxlength'=>3, 'value'=> $value, 'style'=>'width:50px'));
}
+$form->addInput(array('type'=>'text', 'name'=>'dailyWorkingHours', 'value'=>$quota->getDailyWorkingHours(), 'style'=>'width:50px'));
$smarty->assign('months', $months);
$smarty->assign('forms', array($form->getName()=>$form->toArray()));
+$smarty->assign('title', $i18n->getKey('title.monthly_quota'));
$smarty->assign('content_page_name', 'cf_monthly_quota.tpl');
$smarty->display('index.tpl');
}
if ($_POST["convert1900to1930"]){
- setChange("CREATE TABLE `timetracker`.`tt_monthly_quota` ( `year` SMALLINT UNSIGNED NOT NULL , `month` TINYINT UNSIGNED NOT NULL , `quota` SMALLINT UNSIGNED NOT NULL , PRIMARY KEY (`year`, `month`))");
+ setChange("CREATE TABLE `tt_monthly_quota` (`team_id` int(11) NOT NULL, `year` smallint(5) UNSIGNED NOT NULL, `month` tinyint(3) UNSIGNED NOT NULL, `quota` smallint(5) UNSIGNED NOT NULL, PRIMARY KEY (`year`,`month`,`team_id`))");
+ setChange("ALTER TABLE `tt_monthly_quota` ADD CONSTRAINT `FK_TT_TEAM_CONSTRAING` FOREIGN KEY (`team_id`) REFERENCES `tt_teams` (`id`) ON DELETE CASCADE ON UPDATE CASCADE");
+ setChange("ALTER TABLE `tt_teams` ADD `daily_working_hours` SMALLINT NULL DEFAULT '8' AFTER `lock_spec`");
+ setChange("UPDATE `tt_teams` SET `daily_working_hours` = 8");
}
-
+
// The update_clients function updates projects field in tt_clients table.
if ($_POST["update_clients"]) {
$mdb2 = getConnection();
setChange("OPTIMIZE TABLE tt_fav_reports");
setChange("OPTIMIZE TABLE tt_invoices");
setChange("OPTIMIZE TABLE tt_log");
+ setChange("OPTIMIZE TABLE tt_monthly_quota");
setChange("OPTIMIZE TABLE tt_project_task_binds");
setChange("OPTIMIZE TABLE tt_projects");
setChange("OPTIMIZE TABLE tt_tasks");
border-bottom: 1px solid silver;
}
+.borderTop td {
+ border-top: 1px solid silver;
+}
+
.sectionHeaderNoBorder {
font-weight: bold;
}
color: #0000c0;
}
+.divider {
+ background-color: #efefef;
+}
+table.divider {
+ width: 720px;
+}
+
div#LoginAboutText { width:400px; }
`plugins` varchar(255) default NULL, # a list of enabled plugins for team
`lock_spec` varchar(255) default NULL, # Cron specification for record locking,
# for example: "0 10 * * 1" for "weekly on Mon at 10:00".
+ `daily_working_hours` smallint(6) DEFAULT '8', # number of working hours per days, a worker is suppose to work
`custom_logo` tinyint(4) default '0', # whether to use a custom logo or not
`status` tinyint(4) default '1', # team status
PRIMARY KEY (`id`)
#
# Structure for table tt_monthly_quota.
-# This table lists expense items.
+# This table lists monthly quota per team.
#
-CREATE TABLE `tt_monthly_quota` (
- `year` SMALLINT UNSIGNED NOT NULL , # year we'setting monthly quota for
- `month` TINYINT UNSIGNED NOT NULL , # month we're settng monthly quota for
- `quota` SMALLINT UNSIGNED NOT NULL , # the monthly quota
- PRIMARY KEY (`year`, `month`)
+CREATE TABLE `tt_monthly_quota` (
+ `team_id` int(11) NOT NULL, # team's id
+ `year` smallint(5) UNSIGNED NOT NULL, # year we'setting monthly quota for
+ `month` tinyint(3) UNSIGNED NOT NULL, # month we're settng monthly quota for
+ `quota` smallint(5) UNSIGNED NOT NULL, # the monthly quota
+ PRIMARY KEY (`year`,`month`,`team_id`)
);
+
+ALTER TABLE `tt_monthly_quota`
+ ADD CONSTRAINT `FK_TT_TEAM_CONSTRAING` FOREIGN KEY (`team_id`) REFERENCES `tt_teams` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
+
var $db;
var $holidays;
+ var $usersTeamId;
// Old style constructors are DEPRECATED in PHP 7.0, and will be removed in a future version. You should always use __construct() in new code.
function __construct() {
$this->db = getConnection();
$i18n = $GLOBALS['I18N'];
$this->holidays = $i18n->holidays;
+ global $user;
+ $this->usersTeamId = $user->team_id;
}
public function update($year, $month, $quota) {
- $deleteSql = "DELETE FROM tt_monthly_quota WHERE year = $year AND month = $month";
+ $teamId = $this->usersTeamId;
+ $deleteSql = "DELETE FROM tt_monthly_quota WHERE year = $year AND month = $month AND team_id = $teamId";
$this->db->exec($deleteSql);
- $insertSql = "INSERT INTO tt_monthly_quota (year, month, quota) values ($year, $month, $quota)";
- $affected = $this->db->exec($insertSql);
- return (!is_a($affected, 'PEAR_Error'));
+ if ($quota){
+ $insertSql = "INSERT INTO tt_monthly_quota (team_id, year, month, quota) values ($teamId, $year, $month, $quota)";
+ $affected = $this->db->exec($insertSql);
+ return (!is_a($affected, 'PEAR_Error'));
+ }
+ return true;
}
public function get($year, $month) {
-
if (is_null($month)){
return $this->getMany($year);
}
return $this->getSingle($year, $month);
}
+
+ public function getDailyWorkingHours(){
+ $teamId = $this->usersTeamId;
+ $sql = "SELECT daily_working_hours FROM tt_teams where id = $teamId";
+ $reader = $this->db->query($sql);
+ if (is_a($reader, 'PEAR_Error')) {
+ return false;
+ }
+
+ $row = $reader->fetchRow();
+ return $row["daily_working_hours"];
+ }
private function getSingle($year, $month) {
-
- $sql = "SELECT quota FROM tt_monthly_quota WHERE year = $year AND month = $month";
+ $teamId = $this->usersTeamId;
+ $sql = "SELECT quota FROM tt_monthly_quota WHERE year = $year AND month = $month AND team_id = $teamId";
$reader = $this->db->query($sql);
if (is_a($reader, 'PEAR_Error')) {
return false;
}
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
- return $this->getWorkingDays("$year-$month-01", "$year-$month-$daysInMonth", $holidaysWithYear) * 8;
+ return $this->getWorkingDays("$year-$month-01", "$year-$month-$daysInMonth", $holidaysWithYear) * $this->getDailyWorkingHours();
}
return $row["quota"];
}
private function getMany($year){
- $sql = "SELECT year, month, quota FROM tt_monthly_quota WHERE year = $year";
+ $teamId = $this->usersTeamId;
+ $sql = "SELECT month, quota FROM tt_monthly_quota WHERE year = $year AND team_id = $teamId";
$result = array();
$res = $this->db->query($sql);
if (is_a($res, 'PEAR_Error')) {