function init() { parent::init(); $this->addCondition('status', 'Active'); $date = $this->app->today; $this->addExpression('first_in')->set(function ($m, $q) use($date) { return $m->refSQL('EmployeeMovements')->addCondition('date', $date)->addCondition('direction', 'In')->setOrder('movement_at', 'asc')->setLimit(1)->fieldQuery('movement_at'); }); $this->addExpression('last_out')->set(function ($m, $q) use($date) { return $m->refSQL('EmployeeMovements')->addCondition('date', $date)->addCondition('direction', 'Out')->setOrder('movement_at', 'desc')->setLimit(1)->fieldQuery('movement_at'); }); $this->addExpression('is_late')->set(function ($m, $q) use($date) { return $q->expr("IF([0]>= CONCAT('[1]',' ',[2]),1,0)", [$m->getElement('first_in'), $date, $m->getElement('in_time')]); }); $this->addExpression('last_direction')->set(function ($m, $q) { $temp = $m->refSQL('EmployeeMovements')->setOrder('movement_at', 'desc')->setLimit(1); return $q->expr('IFNULL([0],"Out")', [$temp->fieldQuery('direction')]); }); $this->addExpression('last_direction_today')->set(function ($m, $q) { $temp = $m->refSQL('EmployeeMovements')->addCondition('date', $this->app->today)->setOrder('movement_at', 'desc')->setLimit(1); return $q->expr('IFNULL([0],"Out")', [$temp->fieldQuery('direction')]); }); $this->addExpression('is_in')->set(function ($m, $q) { return $q->expr("IF([0]='In' AND [1]=\t[2],'In','Out')", [$m->getElement('last_direction'), $m->getElement('date'), $this->app->today]); }); $this->addExpression('is_out')->set(function ($m, $q) { return $q->expr("IF([0]='Out','Out','In')", [$m->getElement('last_direction_today')]); }); $this->addExpression('in_color')->set(function ($m, $q) use($date) { return $q->expr("IF([0]<= CONCAT('[1]',' ',[2]),'success','danger')", [$m->getElement('first_in'), $date, $m->getElement('in_time')]); }); $this->addExpression('out_color')->set(function ($m, $q) use($date) { return $q->expr("IF([0]>= CONCAT('[1]',' ',[2]),'success','danger')", [$m->getElement('last_out'), $date, $m->getElement('out_time')]); }); }
function init() { parent::init(); $this->addCondition('status', 'Active'); $this->addExpression('pending_works')->set(function ($m, $q) { $task = $this->add('xepan\\projects\\Model_Task'); $task->addCondition('assign_to_id', $q->getField('id'))->addCondition('type', 'Task')->addCondition('created_by_id', '<>', $q->getField('id'))->addCondition('received_at', '>=', $this->start_date)->addCondition([['submitted_at', '<', $this->end_date], ['submitted_at', null]]); return $task->count(); }); $this->addExpression('please_receive')->set(function ($m, $q) { $task = $this->add('xepan\\projects\\Model_Task'); $task->addCondition('assign_to_id', $q->getField('id'))->addCondition('type', 'Task')->addCondition('created_by_id', '<>', $q->getField('id'))->addCondition('created_at', '>=', $this->start_date)->addCondition([['received_at', '<', $this->end_date], ['received_at', null]]); return $task->count(); }); $this->addExpression('received_so_far')->set(function ($m, $q) { $task = $this->add('xepan\\projects\\Model_Task'); $task->addCondition('assign_to_id', $q->getField('id'))->addCondition('type', 'Task')->addCondition('created_by_id', '<>', $q->getField('id'))->addCondition('received_at', '>=', $this->start_date)->addCondition([['submitted_at', '<', $this->end_date], ['submitted_at', null]]); return $task->count(); }); $this->addExpression('total_tasks_assigned')->set(function ($m, $q) { $task = $this->add('xepan\\projects\\Model_Task'); $task->addCondition('assign_to_id', '<>', $q->getField('id'))->addCondition('type', 'Task')->addCondition('created_by_id', $q->getField('id'))->addCondition('created_at', '>=', $this->start_date)->addCondition([['received_at', '<', $this->end_date], ['received_at', null]]); return $task->count(); }); $this->addExpression('take_report_on_pending')->set(function ($m, $q) { $task = $this->add('xepan\\projects\\Model_Task'); $task->addCondition('assign_to_id', '<>', $q->getField('id'))->addCondition('type', 'Task')->addCondition('created_by_id', $q->getField('id'))->addCondition('received_at', '>=', $this->start_date)->addCondition([['submitted_at', '<', $this->end_date], ['submitted_at', null]]); return $task->count(); }); $this->addExpression('check_submitted')->set(function ($m, $q) { $task = $this->add('xepan\\projects\\Model_Task'); $task->addCondition('assign_to_id', '<>', $q->getField('id'))->addCondition('type', 'Task')->addCondition('created_by_id', $q->getField('id'))->addCondition('submitted_at', '>=', $this->start_date)->addCondition([['completed_at', '<', $this->end_date], ['completed_at', null]]); return $task->count(); }); }
function init() { parent::init(); $this->addCondition('status', 'Active'); if ($this->entity == 'Personal') { $this->addCondition('id', $this->app->employee->id); } if ($this->entity == 'Department') { if ($this->dept_id) { $this->addCondition('department_id', $this->dept_id); } else { $this->addCondition('department_id', $this->app->employee['department_id']); } } $this->addExpression('pending_works')->set(function ($m, $q) { $task = $this->add('xepan\\projects\\Model_Task'); $task->addCondition('assign_to_id', $q->getField('id'))->addCondition('type', 'Task')->addCondition('created_by_id', '<>', $q->getField('id'))->addCondition('status', 'Pending')->addCondition('created_at', '>=', $this->start_date)->addCondition('created_at', '<=', $this->end_date); return $task->count(); }); $this->addExpression('please_receive')->set(function ($m, $q) { $task = $this->add('xepan\\projects\\Model_Task'); $task->addCondition('assign_to_id', $q->getField('id'))->addCondition('type', 'Task')->addCondition('created_by_id', '<>', $q->getField('id'))->addCondition('status', 'Assigned')->addCondition('created_at', '>=', $this->start_date)->addCondition('created_at', '<=', $this->end_date); return $task->count(); }); $this->addExpression('received_so_far')->set(function ($m, $q) { $task = $this->add('xepan\\projects\\Model_Task'); $task->addCondition('assign_to_id', $q->getField('id'))->addCondition('type', 'Task')->addCondition('created_by_id', '<>', $q->getField('id'))->addCondition('created_at', '>=', $this->start_date)->addCondition('created_at', '<=', $this->end_date); return $task->count(); }); $this->addExpression('total_tasks_assigned')->set(function ($m, $q) { $task = $this->add('xepan\\projects\\Model_Task'); $task->addCondition('assign_to_id', '<>', $q->getField('id'))->addCondition('type', 'Task')->addCondition('created_by_id', $q->getField('id'))->addCondition('created_at', '>=', $this->start_date)->addCondition('created_at', '<=', $this->end_date); return $task->count(); }); $this->addExpression('take_report_on_pending')->set(function ($m, $q) { $task = $this->add('xepan\\projects\\Model_Task'); $task->addCondition('assign_to_id', '<>', $q->getField('id'))->addCondition('type', 'Task')->addCondition('created_by_id', $q->getField('id'))->addCondition('status', ['Pending', 'Assigned'])->addCondition('created_at', '>=', $this->start_date)->addCondition('created_at', '<=', $this->end_date); return $task->count(); }); $this->addExpression('check_submitted')->set(function ($m, $q) { $task = $this->add('xepan\\projects\\Model_Task'); $task->addCondition('assign_to_id', '<>', $q->getField('id'))->addCondition('type', 'Task')->addCondition('created_by_id', $q->getField('id'))->addCondition('status', 'Submitted')->addCondition('created_at', '>=', $this->start_date)->addCondition('created_at', '<=', $this->end_date); return $task->count(); }); }
function init() { parent::init(); $this->addCondition('status', 'Active'); if ($this->entity == 'Personal') { $this->addCondition('id', $this->app->employee->id); } // total number of tasks alloted to employee $this->addExpression('total_tasks')->set(function ($m, $q) { return $this->add('xepan\\projects\\Model_Task')->addCondition('type', 'Task')->addCondition('assign_to_id', $m->getElement('id'))->count(); }); $this->addExpression('total_pending_tasks')->set(function ($m, $q) { return $this->add('xepan\\projects\\Model_Task')->addCondition('type', 'Task')->addCondition('assign_to_id', $m->getElement('id'))->addCondition('status', 'Pending')->count(); }); // total hours alloted $this->addExpression('total_hours_alloted')->set(function ($m, $q) { $task_m = $this->add('xepan\\projects\\Model_Task', ['table_alias' => 'emptsk'])->addCondition('type', 'Task')->addCondition('assign_to_id', $q->getField('id')); $task_m->addExpression('diff_time')->set(function ($m, $q) { return $q->expr('TIMESTAMPDIFF([0],[1],[2])', ['HOUR', $q->getField('starting_date'), $q->getField('deadline')]); }); return $task_m->_dsql()->del('fields')->field($q->expr('sum([0])', [$task_m->getElement('diff_time')])); }); // total amount of estimate hours $this->addExpression('total_estimated_hours')->set(function ($m, $q) { $task_m = $this->add('xepan\\projects\\Model_Task')->addCondition('type', 'Task')->addCondition('assign_to_id', $m->getElement('id')); return $task_m->_dsql()->del('fields')->field($q->expr('sum([0])', [$task_m->getElement('estimate_time')])); }); // total amount of time employee worked $this->addExpression('total_minutes_taken')->set(function ($m, $q) { $timesheet_m = $this->add('xepan\\projects\\Model_Timesheet')->addCondition('employee_id', $m->getElement('id')); $timesheet_m->addExpression('diff_time')->set(function ($m, $q) { return $q->expr('TIMESTAMPDIFF([0],[1],[2])', ['MINUTE', $q->getField('starttime'), $q->getField('endtime')]); }); return $timesheet_m->_dsql()->del('fields')->field($q->expr('sum([0])', [$timesheet_m->getElement('diff_time')])); }); // total_minutes_taken converted in hours $this->addExpression('total_hours_taken')->set(function ($m, $q) { return $q->expr('([0])/60', [$m->getElement('total_minutes_taken')]); }); }