2026-04-08 07:22:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use App\Models\Pivot_Tasks;
|
|
|
|
|
use App\Models\Attendance;
|
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
|
use App\Models\Tasks;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TaskController extends Controller
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function tasks()
|
|
|
|
|
{
|
|
|
|
|
$user = User::where('user_name', $_COOKIE['user_identity'])->first();
|
|
|
|
|
$tasks = $user->tasks;
|
|
|
|
|
$users = User::get();
|
|
|
|
|
|
|
|
|
|
$state_order = [
|
|
|
|
|
"c73c2044-ea14-42cb-b08d-cecf3d1fdfb5",
|
|
|
|
|
"a9ce312f-cfca-491e-8e3d-1975aa6ebc10",
|
|
|
|
|
"dea1fb57-a281-4fe7-8f3e-ee5567637e35",
|
|
|
|
|
"770fbe42-99f6-41db-9b9e-773d9cced1a5",
|
|
|
|
|
"b0e464e1-34eb-41ea-b2f7-3ef7483bc9f0",
|
|
|
|
|
"d61d14a3-72f7-4f44-894b-efe8b2a75be1",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$work_item = $tasks->whereNull('parent')->sortBy(fn($t) => array_search($t->state, $state_order));
|
|
|
|
|
$sub_work_items = $tasks->whereNotNull('parent')->sortBy(fn($t) => array_search($t->state, $state_order));
|
|
|
|
|
|
|
|
|
|
foreach ($work_item as $w) {
|
|
|
|
|
foreach ($sub_work_items as $t) {
|
|
|
|
|
foreach ($users as $u) {
|
|
|
|
|
if ($t->created_by == $u->plain_id)
|
|
|
|
|
$t->created_by = $u->name;
|
|
|
|
|
if ($w->created_by == $u->plain_id)
|
|
|
|
|
$w->created_by = $u->name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return view('tasks.tasks', compact('tasks', 'work_item', 'sub_work_items'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function activeTask(Request $request)
|
|
|
|
|
{
|
|
|
|
|
// dd($request->all());
|
|
|
|
|
// dd($request->uid);
|
|
|
|
|
$user = User::where('id', $request->uid)->first();
|
|
|
|
|
$p_task = Pivot_Tasks::where('task_id', $request->task_id)
|
|
|
|
|
->where('user_id', $user->plain_id)->first();
|
|
|
|
|
$task = Tasks::where('task_id', $request->task_id)->first();
|
|
|
|
|
if ($p_task) {
|
|
|
|
|
// dd('task is set in pivot');
|
|
|
|
|
if ($p_task->started_at == null || ($p_task->started_at !== null && $p_task->ended_at !== null)) {
|
|
|
|
|
// dd('in if');
|
|
|
|
|
|
|
|
|
|
$p_task->started_at = now();
|
|
|
|
|
$p_task->ended_at = null;
|
|
|
|
|
$user->active_task = $task->name;
|
|
|
|
|
$p_task->save();
|
|
|
|
|
$user->save();
|
|
|
|
|
return back()->with('message', [
|
|
|
|
|
'color' => 'green',
|
|
|
|
|
'text' => 'وظیفه شما شروع شد، موفق باشید.'
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
// dd('in elseif');
|
|
|
|
|
|
|
|
|
|
$now = now();
|
|
|
|
|
$attendance = new Attendance();
|
|
|
|
|
$s = Carbon::parse($p_task->started_at)->format('H:i:s');
|
|
|
|
|
$e = Carbon::parse($now)->format('H:i:s');
|
|
|
|
|
$duration = $p_task->duration;
|
|
|
|
|
if ($e > $s) {
|
|
|
|
|
$diff = $attendance->duration($s, $e);
|
|
|
|
|
if ($duration !== null) {
|
|
|
|
|
[$h1, $m1, $s1] = explode(':', $duration);
|
|
|
|
|
$durationSeconds = $h1 * 3600 + $m1 * 60 + $s1;
|
|
|
|
|
|
|
|
|
|
[$h2, $m2, $s2] = explode(':', $diff);
|
|
|
|
|
$diffSeconds = $h2 * 3600 + $m2 * 60 + $s2;
|
|
|
|
|
|
|
|
|
|
$totalSeconds = $durationSeconds + $diffSeconds;
|
|
|
|
|
|
|
|
|
|
$hours = floor($totalSeconds / 3600);
|
|
|
|
|
$minutes = floor(($totalSeconds % 3600) / 60);
|
|
|
|
|
$seconds = $totalSeconds % 60;
|
|
|
|
|
|
|
|
|
|
$duration = sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
|
|
|
|
|
} else {
|
|
|
|
|
$duration = $diff;
|
|
|
|
|
}
|
|
|
|
|
$p_task->ended_at = $now;
|
|
|
|
|
$p_task->duration = $duration;
|
|
|
|
|
$user->active_task = null;
|
|
|
|
|
$p_task->save();
|
|
|
|
|
$user->save();
|
|
|
|
|
return back()->with('message', [
|
|
|
|
|
'color' => 'green',
|
|
|
|
|
'text' => 'وظیفه شما با موفقیت پایان یافت.'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return back()->with('message', [
|
|
|
|
|
'color' => 'red',
|
|
|
|
|
'text' => 'وظیفه یافت نشد✖️'
|
|
|
|
|
]);
|
|
|
|
|
// $action = $request->input('action_type');
|
|
|
|
|
// $start = $request->input('started_at');
|
|
|
|
|
// $end = $request->input('ended_at');
|
|
|
|
|
// $duration = $request->input('duration');
|
|
|
|
|
//
|
|
|
|
|
// if ($action == 'end') {
|
|
|
|
|
// $attendance = new Attendance();
|
|
|
|
|
// $s = Carbon::parse($start)->format('H:i:s');
|
|
|
|
|
// $e = Carbon::parse($end)->format('H:i:s');
|
|
|
|
|
// if ($e > $s) {
|
|
|
|
|
// $diff = $attendance->duration($s, $e);
|
|
|
|
|
// if ($duration !== null) {
|
|
|
|
|
// [$h1, $m1, $s1] = explode(':', $duration);
|
|
|
|
|
// $durationSeconds = $h1 * 3600 + $m1 * 60 + $s1;
|
|
|
|
|
//
|
|
|
|
|
// [$h2, $m2, $s2] = explode(':', $diff);
|
|
|
|
|
// $diffSeconds = $h2 * 3600 + $m2 * 60 + $s2;
|
|
|
|
|
//
|
|
|
|
|
// $totalSeconds = $durationSeconds + $diffSeconds;
|
|
|
|
|
//
|
|
|
|
|
// $hours = floor($totalSeconds / 3600);
|
|
|
|
|
// $minutes = floor(($totalSeconds % 3600) / 60);
|
|
|
|
|
// $seconds = $totalSeconds % 60;
|
|
|
|
|
//
|
|
|
|
|
// $duration = sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
|
|
|
|
|
// } else {
|
|
|
|
|
// $duration = $diff;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// $data = [
|
|
|
|
|
// 'started_at' => $start,
|
|
|
|
|
// 'ended_at' => $end,
|
|
|
|
|
// 'duration' => $duration,
|
|
|
|
|
// ];
|
|
|
|
|
// } else {
|
|
|
|
|
// $data = [
|
|
|
|
|
// 'started_at' => $start,
|
|
|
|
|
// 'ended_at' => null,
|
|
|
|
|
//
|
|
|
|
|
// ];
|
|
|
|
|
// }
|
|
|
|
|
// try {
|
|
|
|
|
//
|
|
|
|
|
// DB::table('pivot_tasks')->where('id', $request->p_id)->update($data);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// return "record saved";
|
|
|
|
|
// } catch (\Exception $e) {
|
|
|
|
|
// return $e->getMessage();
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createTask()
|
|
|
|
|
{
|
|
|
|
|
$users = User::whereNotNull('plain_id')->get();
|
|
|
|
|
$tasks = Tasks::all();
|
|
|
|
|
|
|
|
|
|
return view('tasks.create', [
|
|
|
|
|
'users' => $users,
|
|
|
|
|
'tasks' => $tasks,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addTask(Request $request){
|
|
|
|
|
// dd($request);
|
|
|
|
|
$task = new Tasks();
|
|
|
|
|
$task->name = $request->input('taskTitle');
|
|
|
|
|
$task->created_at = Carbon::now()->format('Y-m-d H:i:s');
|
|
|
|
|
$task->save();
|
|
|
|
|
return response()->with('message', "تسک اضافه شد");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public function storeTask(Request $request)
|
|
|
|
|
{
|
2026-04-21 16:46:39 +00:00
|
|
|
$created_by = User::where('user_name', $_COOKIE['user_identity'])->first()->plain_id;
|
2026-04-08 07:22:13 +00:00
|
|
|
|
2026-04-21 16:46:39 +00:00
|
|
|
Tasks::create([
|
|
|
|
|
"name" => $request->name,
|
|
|
|
|
"desc" => $request->description_html,
|
|
|
|
|
"priority" => $request->priority,
|
|
|
|
|
"start_date" => $request->start_date,
|
|
|
|
|
"target_date" => $request->target_date,
|
|
|
|
|
"state" => $request->state,
|
|
|
|
|
"assignees" => $request->assignees,
|
|
|
|
|
"parent" => $request->parent,
|
|
|
|
|
"estimate_point" => $request->estimate_point,
|
2026-04-08 07:22:13 +00:00
|
|
|
|
2026-04-21 16:46:39 +00:00
|
|
|
]);
|
2026-04-08 07:22:13 +00:00
|
|
|
|
2026-04-21 16:46:39 +00:00
|
|
|
// $headers = [
|
|
|
|
|
// 'x-api-key' => 'plane_api_ec378e977ceb4bd1bbd2332855370645',
|
|
|
|
|
// 'Content-Type' => 'application/json'
|
|
|
|
|
// ];
|
|
|
|
|
//
|
|
|
|
|
// $body = json_encode([
|
|
|
|
|
// "name" => $name,
|
|
|
|
|
// "description_html" => $desc ?: '',
|
|
|
|
|
// "priority" => $priority ?: 'none',
|
|
|
|
|
// "start_date" => $start_date ?: null,
|
|
|
|
|
// "target_date" => $target_date ?: null,
|
|
|
|
|
// "estimate_point" => $estimate_point ?: '',
|
|
|
|
|
// "state" => $state ?: '',
|
|
|
|
|
// "parent" => $parent ?: '',
|
|
|
|
|
// "assignees" => $assignees ?: '',
|
|
|
|
|
// // "labels" => $labels ?: null,
|
|
|
|
|
// // "created_by" => $created_by
|
|
|
|
|
// ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
|
|
|
|
//
|
|
|
|
|
// $client = new Client();
|
|
|
|
|
//
|
|
|
|
|
// $response = $client->post(
|
|
|
|
|
// 'https://api.plane.so/api/v1/workspaces/montzar/projects/c1df4085-582f-4b57-b3c6-95b7d4d19007/issues/',
|
|
|
|
|
// [
|
|
|
|
|
// 'headers' => $headers,
|
|
|
|
|
// 'body' => $body,
|
|
|
|
|
// ]
|
|
|
|
|
// );
|
|
|
|
|
//
|
|
|
|
|
// $data = json_decode($response->getBody(), true);
|
2026-04-08 07:22:13 +00:00
|
|
|
|
|
|
|
|
// update_tasks($data);
|
|
|
|
|
|
|
|
|
|
return back()->with('message', [
|
|
|
|
|
'color' => 'green',
|
|
|
|
|
'text' => 'وظیفه با موفقیت ایجاد شد.'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-21 16:46:39 +00:00
|
|
|
// public function webhookPlane(Request $request)
|
|
|
|
|
// {
|
|
|
|
|
// $d = $request->all();
|
|
|
|
|
//
|
|
|
|
|
// // فقط وقتی تغییر state هست
|
|
|
|
|
// if (isset($d['event'], $d['action'], $d['data']['name'], $d['data']['state']['name'])) {
|
|
|
|
|
// $msg = "Event: {$d['event']}\nAction: {$d['action']}\nName: {$d['data']['name']}\nNew Status: {$d['data']['state']['name']}";
|
|
|
|
|
//
|
|
|
|
|
// // ارسال به تلگرام
|
|
|
|
|
// Http::get("https://api.wwwapp.ir/telegran_send.php", [
|
|
|
|
|
// 'botToken' => "7467099619:AAF2V6yYcbAb8oSIRSCyH5i2GKfdWVO3a7k",
|
|
|
|
|
// 'chatId' => "-4742642674",
|
|
|
|
|
// 'message' => $msg,
|
|
|
|
|
// ]);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // اگر خواستی ثبت در دیتابیس هم اضافه کنی
|
|
|
|
|
// // DB::table('tst')->insert([
|
|
|
|
|
// // 'data' => json_encode($d, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE),
|
|
|
|
|
// // ]);
|
|
|
|
|
//
|
|
|
|
|
// return response()->json(['status' => 'ok'], 200);
|
|
|
|
|
// }
|
2026-04-08 07:22:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|