2025-10-11 13:38:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
use App\Http\Controllers\AdminController;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Console\View\Components\Task;
|
2025-10-11 13:38:30 +00:00
|
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Response;
|
|
|
|
|
use App\Models\Attendance;
|
2026-04-08 07:22:13 +00:00
|
|
|
use \App\Models\AttendanceBreak;
|
2025-10-11 13:38:30 +00:00
|
|
|
use App\Models\ai;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
use Illuminate\Support\Facades\Cookie;
|
|
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
use Morilog\Jalali\Jalalian;
|
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
|
use App\Models\Tasks;
|
2026-04-08 07:22:13 +00:00
|
|
|
use App\Models\Pivot_Tasks;
|
|
|
|
|
use App\Http\Controllers\AttendanceController;
|
2026-07-26 10:49:48 +03:30
|
|
|
use App\Http\Controllers\LeaveController;
|
2025-10-11 13:38:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
Route::get('/', [AdminController::class, 'dashboard'])->name('admin.dashboard');
|
2025-10-11 13:38:30 +00:00
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
Route::get('/newuser', [AdminController::class, 'newUser'])->name('admin.new');
|
2025-10-11 13:38:30 +00:00
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
Route::post('/newuser', [AdminController::class, 'addUser'])->name('admin.new');
|
|
|
|
|
|
|
|
|
|
Route::post('/edit', [AdminController::class, 'edit'])->name('admin.edit');
|
|
|
|
|
|
|
|
|
|
Route::post('/delete', [AdminController::class, 'delete'])->name('admin.delete');
|
|
|
|
|
|
|
|
|
|
Route::post('/update', [AdminController::class, 'update'])->name('admin.update');
|
2025-10-11 13:38:30 +00:00
|
|
|
|
2026-07-26 10:49:48 +03:30
|
|
|
Route::post('/leave/decide', [LeaveController::class, 'decide'])->name('admin.leave.decide');
|
|
|
|
|
|
2025-10-11 13:38:30 +00:00
|
|
|
|
|
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
Route::get('/job', function () {
|
2025-10-11 13:38:30 +00:00
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
$users = User::with(['attendances' => function ($query) {
|
|
|
|
|
$query->whereNull('exited_at')->latest('entered_at');
|
|
|
|
|
}])->get();
|
2025-10-11 13:38:30 +00:00
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
$now = Carbon::now()->format('H:i:s');
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
|
$att = $user->attendances->first();
|
2025-10-11 13:38:30 +00:00
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
if ($att && strtotime(Carbon::parse($att->entered_at)->format('Y-m-d')) < strtotime(date('Y-m-d'))) {
|
|
|
|
|
$att->exited_at = $att->entered_at;
|
|
|
|
|
$att->save();
|
|
|
|
|
} elseif ($att && strtotime(Carbon::parse($att->entered_at)->format('Y-m-d')) == strtotime(date('Y-m-d'))) {
|
|
|
|
|
$a = new Attendance();
|
|
|
|
|
$diff = $a->duration(Carbon::parse($att->entered_at)->format('H:i:s'), $now);
|
2025-10-11 13:38:30 +00:00
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
if (Carbon::createFromFormat('H:i:s', $diff)->greaterThanOrEqualTo(Carbon::createFromFormat('H:i:s', '00:15:00'))) {
|
2025-10-11 13:38:30 +00:00
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
if (!$user->active_task) {
|
|
|
|
|
app(AttendanceController::class)->auto_break($user->user_name, "start");
|
|
|
|
|
sendbot($user->chatid, "به علت عدم انتخاب وظیفه استراحت ثبت شد، برای تغییر وضعیت یک وظیفه انتخاب کنید.");
|
|
|
|
|
} elseif ($user->active_task) {
|
|
|
|
|
$status = app(AttendanceController::class)->auto_break($user->user_name, "end");
|
2025-10-11 13:38:30 +00:00
|
|
|
}
|
2026-04-08 07:22:13 +00:00
|
|
|
} elseif (Carbon::createFromFormat('H:i:s', $diff)->greaterThanOrEqualTo(Carbon::createFromFormat('H:i:s', '00:10:00'))) {
|
|
|
|
|
if (!$user->active_task) {
|
|
|
|
|
sendbot($user->chatid, "هنوز وظیفه ای انتخاب نشده، برای انتخاب وظیفه 5 دقیقه دیگر فرصت دارید.");
|
2025-10-11 13:38:30 +00:00
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
}
|
2025-10-11 13:38:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-08 07:22:13 +00:00
|
|
|
return $users;
|
2025-10-11 13:38:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
//function sendbot($chatid, $mssg)
|
|
|
|
|
//{
|
|
|
|
|
// $chatid = '115247194';
|
|
|
|
|
// // ارسال به پیوی تلگرام
|
|
|
|
|
// $sent = Http::get("https://api.wwwapp.ir/telegran_send.php", [
|
|
|
|
|
// 'botToken' => "7467099619:AAF2V6yYcbAb8oSIRSCyH5i2GKfdWVO3a7k",
|
|
|
|
|
// 'chatId' => $chatid,
|
|
|
|
|
// 'message' => $mssg,
|
|
|
|
|
// 'parse_mode' => 'Markdown'
|
|
|
|
|
// ]);
|
|
|
|
|
//}
|
2025-10-11 13:38:30 +00:00
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
//function update_tasks($req)
|
|
|
|
|
//{
|
|
|
|
|
// if ($req['action'] == "deleted") {
|
|
|
|
|
// Pivot_Tasks::where('task_id', $req['data']['task_id'])->delete();
|
|
|
|
|
// Tasks::where('task_id', $req['data']['task_id'])->delete();
|
|
|
|
|
// return "deleted";
|
|
|
|
|
// } else {
|
|
|
|
|
// $req = $req['data'];
|
|
|
|
|
//
|
|
|
|
|
// $project_id = $req['project'];
|
|
|
|
|
// $task_id = $req['id'];
|
|
|
|
|
// $users = User::all();
|
|
|
|
|
// $task = Tasks::where('task_id', $task_id)->first();
|
|
|
|
|
//
|
|
|
|
|
// $client = new Client();
|
|
|
|
|
//
|
|
|
|
|
// $response = $client->get("https://api.plane.so/api/v1/workspaces/montzar/projects/$project_id/issues/$task_id", [
|
|
|
|
|
// 'headers' => [
|
|
|
|
|
// 'X-API-Key' => 'plane_api_ec378e977ceb4bd1bbd2332855370645',
|
|
|
|
|
// 'Accept' => 'application/json'
|
|
|
|
|
// ]
|
|
|
|
|
// ]);
|
|
|
|
|
//
|
|
|
|
|
// $data = json_decode($response->getBody(), true);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// $client = new Client();
|
|
|
|
|
//
|
|
|
|
|
// $res = $client->get("https://api.plane.so/api/workspaces/montzar/projects/$project_id/modules/", [
|
|
|
|
|
// 'headers' => [
|
|
|
|
|
// 'cookie' => 'session-id=vmc3jbuj391b5reqguhufrf7220dcu8pwceloulwisr1pxfqxbe7k2low9x7647sykt4onlwqdxci0holvqc023lvjac4xgwtst5umzxkl0mfu68xg2b2e3821f59797; '
|
|
|
|
|
// ]
|
|
|
|
|
// ]);
|
|
|
|
|
// $res = json_decode($res->getBody(), true);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//// sendbot(115247194, "api is ok");
|
|
|
|
|
// if ($task) {
|
|
|
|
|
//// sendbot(115247194, 'if ($task) worked');
|
|
|
|
|
// try {
|
|
|
|
|
// $task->task_id = $data['id'];
|
|
|
|
|
// $task->name = $data['name'];
|
|
|
|
|
// $task->description = $data['description'] ?? null;
|
|
|
|
|
// $task->workspace_slug = "montzar";
|
|
|
|
|
// $task->assignees = json_encode($data['assignees']) ?? null;
|
|
|
|
|
// $task->start_date = $data['start_date'] ?? null;
|
|
|
|
|
// $task->target_date = $data['target_date'] ?? null;
|
|
|
|
|
// $task->priority = $data['priority'];
|
|
|
|
|
// $task->description_html = $data['description_html'] ?? null;
|
|
|
|
|
// $task->completed_at = $data['completed_at'] ?? null;
|
|
|
|
|
// $task->project = $data['project'];
|
|
|
|
|
// $task->workspace = $data['workspace'];
|
|
|
|
|
// $task->state = $data['state'] ?? null;
|
|
|
|
|
// $task->json = json_encode($data);
|
|
|
|
|
// $task->created_at = $data['created_at'];
|
|
|
|
|
// $task->updated_at = $data['updated_at'];
|
|
|
|
|
// $task->deleted_at = $data['deleted_at'] ?? null;
|
|
|
|
|
// $task->created_by = $data['created_by'];
|
|
|
|
|
// $task->updated_by = $data['updated_by'];
|
|
|
|
|
// $task->deleted_by = $data['deleted_by'] ?? null;
|
|
|
|
|
// $task->parent = $data['parent'] ?? null;
|
|
|
|
|
// $task->task_type = !empty($data['parent']) ? 'sub_work_item' : 'work_item';
|
|
|
|
|
// $task->save();
|
|
|
|
|
// } catch (\Exception $e) {
|
|
|
|
|
//// sendbot(115247194, $e);
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
//// sendbot(115247194, 'else worked');
|
|
|
|
|
// try {
|
|
|
|
|
// $task = new Tasks();
|
|
|
|
|
// $task->task_id = $data['id'];
|
|
|
|
|
// $task->name = $data['name'];
|
|
|
|
|
// $task->description = $data['description'] ?? null;
|
|
|
|
|
// $task->workspace_slug = "montzar";
|
|
|
|
|
// $task->assignees = json_encode($data['assignees']) ?? null;
|
|
|
|
|
// $task->start_date = $data['start_date'] ?? null;
|
|
|
|
|
// $task->target_date = $data['target_date'] ?? null;
|
|
|
|
|
// $task->priority = $data['priority'];
|
|
|
|
|
// $task->description_html = $data['description_html'] ?? null;
|
|
|
|
|
// $task->completed_at = $data['completed_at'] ?? null;
|
|
|
|
|
// $task->project = $data['project'];
|
|
|
|
|
// $task->workspace = $data['workspace'];
|
|
|
|
|
// $task->state = $data['state'] ?? null;
|
|
|
|
|
// $task->json = json_encode($data);
|
|
|
|
|
// $task->created_at = $data['created_at'];
|
|
|
|
|
// $task->updated_at = $data['updated_at'];
|
|
|
|
|
// $task->deleted_at = $data['deleted_at'] ?? null;
|
|
|
|
|
// $task->created_by = $data['created_by'];
|
|
|
|
|
// $task->updated_by = $data['updated_by'];
|
|
|
|
|
// $task->deleted_by = $data['deleted_by'] ?? null;
|
|
|
|
|
// $task->parent = $data['parent'] ?? null;
|
|
|
|
|
// $task->save();
|
|
|
|
|
// } catch (\Exception $e) {
|
|
|
|
|
//// sendbot(115247194, $e);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// $assigns = $data['assignees'];
|
|
|
|
|
// $created_by = $data['created_by'];
|
|
|
|
|
// if (!empty($assigns)) {
|
|
|
|
|
//
|
|
|
|
|
// foreach ($users as $user) {
|
|
|
|
|
// if (in_array($user->plain_id, $assigns)) {
|
|
|
|
|
//// sendbot(115247194, 'if (in_array($user->plain_id, $assigns)) worked');
|
|
|
|
|
// Pivot_Tasks::insert([
|
|
|
|
|
// 'task_id' => $data['id'], // یا $task->task_id اگر این همون PK هست
|
|
|
|
|
// 'user_id' => $user->plain_id
|
|
|
|
|
// ]);
|
|
|
|
|
// }
|
|
|
|
|
// if (($user->plain_id == $created_by)) {
|
|
|
|
|
//// sendbot(115247194, 'if (($user->plain_id == $created_by)) worked');
|
|
|
|
|
// Pivot_Tasks::insertOrIgnore([
|
|
|
|
|
// 'task_id' => $data['id'], // یا $task->task_id اگر این همون PK هست
|
|
|
|
|
// 'user_id' => $user->plain_id
|
|
|
|
|
// ]);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2025-10-11 13:38:30 +00:00
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
//function tel_notif($username, $status)
|
|
|
|
|
//{
|
|
|
|
|
// $message = "درخواست شما {$status} شد.";
|
|
|
|
|
// $user = User::where('user_name', $username)->whereNotNull('chatid')->select('chatid', 'user_name')->first();
|
|
|
|
|
// if ($user) {
|
|
|
|
|
// Http::get("https://api.wwwapp.ir/telegran_send.php", [
|
|
|
|
|
// 'botToken' => "7467099619:AAF2V6yYcbAb8oSIRSCyH5i2GKfdWVO3a7k",
|
|
|
|
|
// 'chatId' => $user->chatid,
|
|
|
|
|
// 'message' => $message,
|
|
|
|
|
// ]);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//}
|
2025-10-11 13:38:30 +00:00
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
//public function update_tasks ($request) {
|
|
|
|
|
// $client = new Client();
|
|
|
|
|
//
|
|
|
|
|
// $response = $client->get('https://api.plane.so/api/v1/workspaces/montzar/projects/c1df4085-582f-4b57-b3c6-95b7d4d19007/issues/', [
|
|
|
|
|
// 'headers' => [
|
|
|
|
|
// 'X-API-Key' => 'plane_api_ec378e977ceb4bd1bbd2332855370645',
|
|
|
|
|
// 'Accept' => 'application/json'
|
|
|
|
|
// ],
|
|
|
|
|
// 'query' => [
|
|
|
|
|
// "filters" => "%7B%22assignee_id__in%22:%227730f957-3448-4b8c-bc16-a87fc2f2e4ae%22%7D",
|
|
|
|
|
// 'expand' => 'assignees',
|
|
|
|
|
// 'assignees' => 'c6a7f605-3088-4400-86dc-7b0702f896a7'
|
|
|
|
|
// ]
|
|
|
|
|
// ]);
|
|
|
|
|
//
|
|
|
|
|
// $data = json_decode($response->getBody(), true);
|
|
|
|
|
//// end of api
|
|
|
|
|
//
|
|
|
|
|
//// get users
|
|
|
|
|
// $users = User::all();
|
|
|
|
|
//// save in tasks table
|
|
|
|
|
//// foreach ($data['results'] as $a)
|
|
|
|
|
//// dd(gettype($a['assignees']));
|
|
|
|
|
//// dd('ridi');
|
|
|
|
|
// $tasks = Tasks::all();
|
|
|
|
|
// $i = 0;
|
|
|
|
|
// foreach ($data['results'] as $d) {
|
|
|
|
|
// if ($tasks->where('task_id', $d['id'])->first())
|
|
|
|
|
// continue;
|
|
|
|
|
// else {
|
|
|
|
|
// $i++;
|
|
|
|
|
// try {
|
|
|
|
|
// $task = new Tasks();
|
|
|
|
|
// $task->task_id = $d['id'];
|
|
|
|
|
// $task->name = $d['name'];
|
|
|
|
|
// $task->description = $d['description'] ?? null;
|
|
|
|
|
// $task->workspace_slug = "montzar";
|
|
|
|
|
// $task->assignees = json_encode($d['assignees']) ?? null;
|
|
|
|
|
// $task->start_date = $d['start_date'] ?? null;
|
|
|
|
|
// $task->target_date = $d['target_date'] ?? null;
|
|
|
|
|
// $task->priority = $d['priority'];
|
|
|
|
|
// $task->description_html = $d['description_html'] ?? null;
|
|
|
|
|
// $task->completed_at = $d['completed_at'] ?? null;
|
|
|
|
|
// $task->project = $d['project'];
|
|
|
|
|
// $task->workspace = $d['workspace'];
|
|
|
|
|
// $task->state = $d['state'] ?? null;
|
|
|
|
|
// $task->json = json_encode($d);
|
|
|
|
|
// $task->created_at = $d['created_at'];
|
|
|
|
|
// $task->updated_at = $d['updated_at'];
|
|
|
|
|
// $task->deleted_at = $d['deleted_at'] ?? null;
|
|
|
|
|
// $task->created_by = $d['created_by'];
|
|
|
|
|
// $task->updated_by = $d['updated_by'];
|
|
|
|
|
// $task->deleted_by = $d['deleted_by'] ?? null;
|
|
|
|
|
// $tasks->parent = $d['parent'] ?? null;
|
|
|
|
|
// $task->save();
|
|
|
|
|
//
|
|
|
|
|
// // فرض کردیم جدول واسط task_user باشه و ستونهاش task_id و user_id
|
|
|
|
|
// $assigns = $d['assignees'];
|
|
|
|
|
// foreach ($users as $user) {
|
|
|
|
|
// if (in_array($user->plain_id, $assigns))
|
|
|
|
|
// DB::table('pivot_tasks')->insertOrIgnore([
|
|
|
|
|
// 'task_id' => $d['id'], // یا $task->task_id اگر این همون PK هست
|
|
|
|
|
// 'user_id' => $user->plain_id
|
|
|
|
|
// ]);
|
|
|
|
|
// }
|
|
|
|
|
// echo $i;
|
|
|
|
|
//
|
|
|
|
|
// } catch (\Exception $e) {
|
|
|
|
|
// dd($e);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// dd("Added {$i} new tasks.");
|
|
|
|
|
// }
|
|
|
|
|
//};
|
2025-10-11 13:38:30 +00:00
|
|
|
|
2026-04-08 07:22:13 +00:00
|
|
|
//Route::get('/', function () {
|
|
|
|
|
//
|
|
|
|
|
// if (isset($_COOKIE['token-0'])) {
|
|
|
|
|
// $uname = $_COOKIE['token-0'];
|
|
|
|
|
// setcookie("user_identity", $_COOKIE['token-0'], time() + (60 * 60 * 24 * 365), '/');
|
|
|
|
|
// Cookie::queue(Cookie::forget('token-0'));
|
|
|
|
|
// } else
|
|
|
|
|
// $uname = $_COOKIE['user_identity'];
|
|
|
|
|
// $u = User::select('name', 'is_admin')
|
|
|
|
|
// ->where('user_name', $uname)
|
|
|
|
|
// ->first();
|
|
|
|
|
// if ($u->is_admin == '1') {
|
|
|
|
|
// setcookie('ad', '1', time() + (60 * 60 * 24 * 365 * 5), "/");
|
|
|
|
|
// $users = User::wherenotnull('user_name')
|
|
|
|
|
// ->with('attendances')
|
|
|
|
|
// ->get();
|
|
|
|
|
//
|
|
|
|
|
// $records = [];
|
|
|
|
|
// foreach ($users as $user) {
|
|
|
|
|
// $rec = [
|
|
|
|
|
// "user_name" => $user->user_name,
|
|
|
|
|
// "name" => $user->name,
|
|
|
|
|
// "attendances" => []
|
|
|
|
|
// ];
|
|
|
|
|
// foreach ($user->attendances as $attendance) {
|
|
|
|
|
// $key = "att-tempreq:{$user->user_name}:{$attendance->id}";
|
|
|
|
|
// $get = json_decode(Redis::get("{$key}"));
|
|
|
|
|
// $date = $attendance->entered_at ? Carbon::parse($attendance->entered_at)->format('Y-m-d') : null;
|
|
|
|
|
// if ($get)
|
|
|
|
|
// if ($get->function != 'rejected')
|
|
|
|
|
// $rec['attendances'][] = $get;
|
|
|
|
|
// }
|
|
|
|
|
// $key = "att-tempreq:{$user->user_name}:new";
|
|
|
|
|
// $get = json_decode(Redis::get("{$key}"));
|
|
|
|
|
// if ($get) {
|
|
|
|
|
//// dd($get);
|
|
|
|
|
//
|
|
|
|
|
// if ($get->function != 'rejected')
|
|
|
|
|
//
|
|
|
|
|
// $rec['attendances'][] = $get;
|
|
|
|
|
// }
|
|
|
|
|
// $records[] = $rec;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//// dd($users);
|
|
|
|
|
//// dd(json_decode($json,true));
|
|
|
|
|
// return view("admin..admin")->with(['message', [
|
|
|
|
|
// 'color' => '#ff8800ff',
|
|
|
|
|
// "text" => 'شما به پنل ادمین وارد شدید✔️'
|
|
|
|
|
// ],
|
|
|
|
|
// "users" => $users,
|
|
|
|
|
// 'reqs' => $records
|
|
|
|
|
// ]);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// return redirect()->back()->with('message', [
|
|
|
|
|
// 'color' => '#ff8800ff',
|
|
|
|
|
// "text" => 'شما دسترسی به این صفحه را ندارید!'
|
|
|
|
|
// ]);
|
|
|
|
|
//})->name('admin.dashboard');
|
2025-10-11 13:38:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
Route::get('/{user_name}', function ($user_name) {
|
|
|
|
|
// dd($user_name);
|
|
|
|
|
// $user = User::select('user_name', 'name', 'picture')
|
|
|
|
|
// ->where('user_name', $user_name)
|
|
|
|
|
// ->with('attendances')
|
|
|
|
|
// ->first();
|
|
|
|
|
|
|
|
|
|
setcookie('token-0', $_COOKIE['user_identity'], time() + (60 * 60 * 24 * 365), "/");
|
|
|
|
|
setcookie('user_identity', $user_name, time() + (60 * 60 * 24 * 365), "/");
|
|
|
|
|
// $_COOKIE['user_identity'] = $user_name;
|
|
|
|
|
return redirect(url('/'));
|
|
|
|
|
})->name('admin.user');
|
2026-04-08 07:22:13 +00:00
|
|
|
|
|
|
|
|
|