NASER change task orders and make daily report and end task when emploee exit

This commit is contained in:
Montzar.ah.01
2026-04-28 19:53:46 +00:00
parent d1d092359e
commit f4ce38e560
4 changed files with 94 additions and 28 deletions
+57 -10
View File
@@ -2,6 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Carbon\CarbonInterval;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use function PHPUnit\Framework\throwException; use function PHPUnit\Framework\throwException;
use Illuminate\Support\Facades\Cookie; use Illuminate\Support\Facades\Cookie;
@@ -10,6 +11,7 @@ use Illuminate\Support\Facades\Http;
use App\Models\AttendanceBreak; use App\Models\AttendanceBreak;
use Morilog\Jalali\Jalalian; use Morilog\Jalali\Jalalian;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\TaskDuration;
use App\Models\Pivot_Tasks; use App\Models\Pivot_Tasks;
use App\Models\Attendance; use App\Models\Attendance;
use App\Models\Tasks; use App\Models\Tasks;
@@ -169,8 +171,6 @@ class AttendanceController extends Controller
// } // }
public function ai() public function ai()
{ {
$response = Http::withHeaders([ $response = Http::withHeaders([
@@ -286,13 +286,18 @@ class AttendanceController extends Controller
// خروج // خروج
//end task //end task
if (!empty($user->active_task)) { if (!empty($user->active_task)) {
$task = Tasks::where('name', $user->active_task)->first(); $taskDu = TaskDuration::where('user_id', $user->id)->whereNull('end')->whereNull('duration')->get();
if ($taskDu) {
if ($p_task = Pivot_Tasks::where('user_id', $user->plain_id)->where('task_id', $task->task_id)->whereNull('ended_at')->latest('started_at')->first()) { foreach ($taskDu as $item) {
$p_task->duration = $attendance->duration(Carbon::parse($p_task->started_at)->format('H:i:s'), Carbon::now()->format('H:i:s')); $fakeRequest = Request::create(
$p_task->ended_at = Carbon::now(); '/active_task', // مسیر فرضی (مهم نیست)
$p_task->save(); 'POST',
['task_id' => $item->task_id] // شناسه تسک
);
if ($item->end == null) {
(new TaskController())->activeTask($fakeRequest);
}
}
} }
$user->active_task = null; $user->active_task = null;
$user->save(); $user->save();
@@ -324,7 +329,7 @@ class AttendanceController extends Controller
$attendance->save(); $attendance->save();
$this->send($user->name, $attendance, 'attendance'); $this->send($user->name, $attendance, 'attendance');
$this->dailyReport($user->id, $user->name);
return redirect()->back()->with('message', [ return redirect()->back()->with('message', [
'color' => '#3b82f6', 'color' => '#3b82f6',
'text' => 'خروج با موفقیت ثبت شد.' 'text' => 'خروج با موفقیت ثبت شد.'
@@ -645,6 +650,48 @@ class AttendanceController extends Controller
]); ]);
} }
private function dailyReport($userId, $userName)
{
$tasks = Tasks::with(['duration'])->where('created_by', $userId)->orWhereJsonContains('assignees', $userId)->get();
$message = " *" . Jalalian::now()->format('j F') . "* "
. "\n * _{$userName}_ * ";
foreach ($tasks as $task) {
switch ($task->priority) {
case 'none':
$message .= "\n⚪";
break;
case 'low':
$message .= "\n🟢";
break;
case 'medium':
$message .= "\n🟡";
break;
case 'high':
$message .= "\n🟠";
break;
case 'urgent':
$message .= "\n🔴";
break;
}
$message .= "$task->title";
$today = now()->format('Y-m-d 00:00:00');
$totalSeconds = 0;
foreach ($task->duration as $item) {
if (($userId == $item->user_id && $item->duration !== null) && $item->start > $today) {
$totalSeconds += CarbonInterval::createFromFormat('H:i:s', $item->duration)->totalSeconds;
}
}
$task->totalDuration = CarbonInterval::seconds($totalSeconds)->cascade()->format('%H:%I');
$message .= " $task->totalDuration";
}
Http::withoutVerifying()->post('https://tapi.bale.ai/1482838710:sYbLzby0tuLRzHvP4d3LsbcNwg2sjSDLTAU/sendMessage', [
"chat_id" => '985309723',
'text' => $message,
]);
// $this->send_level1_admins($message);
}
} }
+7 -2
View File
@@ -139,7 +139,9 @@ class TaskController extends Controller
if ($user) { if ($user) {
if ($user->is_admin == 1) { if ($user->is_admin == 1) {
$tasks = Tasks::with(['duration', 'comments.user', 'appName']) $tasks = Tasks::with(['duration', 'comments.user', 'appName'])
->orderBy('target_date', 'desc') ->orderByRaw('target_date IS NULL')
->orderBy('target_date', 'asc')
->orderBy('updated_at', 'desc')
->get(); ->get();
// dd($tasks); // dd($tasks);
foreach ($tasks as $task) { foreach ($tasks as $task) {
@@ -157,8 +159,11 @@ class TaskController extends Controller
} else { } else {
$tasks = Tasks::with(['duration', 'comments.user'])->where('created_by', $user->id) $tasks = Tasks::with(['duration', 'comments.user'])->where('created_by', $user->id)
->orWhereJsonContains('assignees', (string)$user->id) ->orWhereJsonContains('assignees', (string)$user->id)
->orderBy('target_date', 'desc') ->orderByRaw('target_date IS NULL') // تسک‌های دارای مهلت اول بیایند (NULL آخر)
->orderBy('target_date', 'asc') // نزدیک‌ترین مهلت اول
->orderBy('updated_at', 'desc') // در صورت یکسان بودن مهلت، آخرین تغییر اول
->get(); ->get();
// dd($tasks); // dd($tasks);
foreach ($tasks as $task) { foreach ($tasks as $task) {
$totalSeconds = 0; $totalSeconds = 0;
+1
View File
@@ -35,6 +35,7 @@ class User extends Authenticatable
'plain_id', 'plain_id',
'break', 'break',
'req_counts', 'req_counts',
'active_task'
]; ];
+18 -5
View File
@@ -138,7 +138,7 @@ $state = [
@endphp @endphp
{{--@if($_COOKIE['user_identity'] == 'naser_me') {{dump($task)}} @endif--}} {{--@if($_COOKIE['user_identity'] == 'naser_me') {{dump($task)}} @endif--}}
<tr class="hover:bg-gray-50"> <tr class="hover:bg-gray-50">
<td class="px-2 py-2"> <td class="px-2 py-2 {{ $task->active ? 'border-s-4 border-cyan-400 ' : '' }}">
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<span class="inline-flex items-center justify-center w-5 h-5">{!! $stateIcon !!}</span> <span class="inline-flex items-center justify-center w-5 h-5">{!! $stateIcon !!}</span>
<div> <div>
@@ -963,7 +963,10 @@ $state = [
const tdEdit = $('#modalTaskTargetDateEdit'); const tdEdit = $('#modalTaskTargetDateEdit');
if (sdEdit.length) { if (sdEdit.length) {
try { sdEdit.persianDatepicker('destroy'); } catch (e) {} try {
sdEdit.persianDatepicker('destroy');
} catch (e) {
}
sdEdit.persianDatepicker({ sdEdit.persianDatepicker({
format: 'YYYY/MM/DD', format: 'YYYY/MM/DD',
autoClose: true, autoClose: true,
@@ -981,7 +984,10 @@ $state = [
} }
if (tdEdit.length) { if (tdEdit.length) {
try { tdEdit.persianDatepicker('destroy'); } catch (e) {} try {
tdEdit.persianDatepicker('destroy');
} catch (e) {
}
tdEdit.persianDatepicker({ tdEdit.persianDatepicker({
format: 'YYYY/MM/DD', format: 'YYYY/MM/DD',
autoClose: true, autoClose: true,
@@ -1038,7 +1044,12 @@ $state = [
if (tdView) tdView.textContent = currentTaskDetails.target_date ? formatJalaliDate(currentTaskDetails.target_date) : '-'; if (tdView) tdView.textContent = currentTaskDetails.target_date ? formatJalaliDate(currentTaskDetails.target_date) : '-';
// priority view // priority view
const priorityLabels = {'urgent': 'فوری', 'high': 'بالا', 'medium': 'متوسط', 'low': 'پایین'}; const priorityLabels = {
'urgent': 'فوری',
'high': 'بالا',
'medium': 'متوسط',
'low': 'پایین'
};
const priorityColors = { const priorityColors = {
'urgent': 'bg-red-100 text-red-800', 'urgent': 'bg-red-100 text-red-800',
'high': 'bg-orange-100 text-orange-800', 'high': 'bg-orange-100 text-orange-800',
@@ -1069,7 +1080,9 @@ $state = [
setQuickEditMode(false); setQuickEditMode(false);
}) })
.catch(() => alert('خطا در ذخیره تغییرات')) .catch(() => alert('خطا در ذخیره تغییرات'))
.finally(() => { saveBtn.disabled = false; }); .finally(() => {
saveBtn.disabled = false;
});
}; };
} }
}); });