1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Models\Upload; |
6
|
|
|
use DateTime; |
7
|
|
|
use Illuminate\Support\Facades\Auth; |
8
|
|
|
use Yajra\DataTables\DataTables; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class FilesController extends Controller |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
public function index() |
15
|
|
|
{ |
16
|
|
|
return Datatables::of(Upload::with(['classRoom'])->where('security_user_id','=',Auth::user()->id)) |
|
|
|
|
17
|
|
|
->editColumn('is_processed', function ($data) { |
18
|
|
|
|
19
|
|
|
$nowTime = \Carbon\Carbon::now(); |
20
|
|
|
$to = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', $nowTime); |
21
|
|
|
$from = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', $data->updated_at); |
22
|
|
|
$diff_in_hours = $to->diffInHours($from); |
23
|
|
|
|
24
|
|
|
if($diff_in_hours >= 2 && $data->is_processed == 3){ |
25
|
|
|
return "Terminated"; |
26
|
|
|
} |
27
|
|
|
elseif ($data->is_processed === 1) { |
28
|
|
|
return "Success"; |
29
|
|
|
}elseif ($data->is_processed === 2){ |
30
|
|
|
return "Failed"; |
31
|
|
|
}elseif($diff_in_hours < 2 && $data->is_processed == 3){ |
32
|
|
|
return "Processing"; |
33
|
|
|
}elseif ($data->is_processed == 4){ |
34
|
|
|
return "Process Paused"; |
35
|
|
|
}else{ |
36
|
|
|
return 'Pending'; |
37
|
|
|
}; |
38
|
|
|
|
39
|
|
|
}) |
40
|
|
|
->editColumn('is_email_sent', function ($data) { |
41
|
|
|
if ($data->is_email_sent == 1) { |
42
|
|
|
return "Success"; |
43
|
|
|
}elseif($data->is_email_sent == 2 ){ |
44
|
|
|
return 'Failed'; |
45
|
|
|
}else{ |
46
|
|
|
return 'Pending'; |
47
|
|
|
}; |
48
|
|
|
|
49
|
|
|
}) |
50
|
|
|
->editColumn('update', function ($data) { |
51
|
|
|
if ((int)$data->update == 0) { |
52
|
|
|
return "No Processes"; |
53
|
|
|
}elseif((int)$data->update == 1 ){ |
54
|
|
|
return 'Success'; |
55
|
|
|
}elseif((int)$data->update == 2 ){ |
56
|
|
|
return 'Failed'; |
57
|
|
|
}elseif((int)$data->update == 3 ){ |
58
|
|
|
return 'Partial Success'; |
59
|
|
|
}; |
60
|
|
|
|
61
|
|
|
}) |
62
|
|
|
->editColumn('insert', function ($data) { |
63
|
|
|
if ($data->insert == 0) { |
64
|
|
|
return "No Processes"; |
65
|
|
|
}elseif($data->insert == 1 ){ |
66
|
|
|
return 'Success'; |
67
|
|
|
}elseif($data->insert == 2 ){ |
68
|
|
|
return 'Failed'; |
69
|
|
|
}elseif($data->insert == 3 ){ |
70
|
|
|
return 'Partial Success'; |
71
|
|
|
}; |
72
|
|
|
|
73
|
|
|
}) |
74
|
|
|
->editColumn('filename', function ($data) { |
75
|
|
|
if(\App::environment('local') || \App::environment('stage')){ |
76
|
|
|
return '<a href="/download_file/'.$data->filename.'">'.$data->classRoom->name.'</a>'; |
77
|
|
|
|
78
|
|
|
}else{ |
79
|
|
|
return '<a href="/bulk-upload/download_file/'.$data->filename.'">'.$data->classRoom->name.'</a>'; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
}) |
83
|
|
|
->editColumn('error', function ($data) { |
84
|
|
|
if(\App::environment('local') || \App::environment('stage')){ |
85
|
|
|
return '<a href="/download/'.$data->filename.'">'.$data->classRoom->name.'</a>'; |
86
|
|
|
|
87
|
|
|
}else{ |
88
|
|
|
return '<a href="/bulk-upload/download/'.$data->filename.'">'.$data->classRoom->name.'</a>'; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
})->editColumn('actions', function ($data) { |
92
|
|
|
|
93
|
|
|
$nowTime = \Carbon\Carbon::now(); |
94
|
|
|
$to = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', $nowTime); |
95
|
|
|
$from = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', $data->updated_at); |
96
|
|
|
$diff_in_hours = $to->diffInHours($from); |
97
|
|
|
|
98
|
|
|
if($diff_in_hours >= 2 && $data->is_processed == 3){ |
99
|
|
|
return '<button onclick="updateProcess('.($data->id).',100)" class="btn btn-primary text-uppercase">reprocess</button>'; |
100
|
|
|
}elseif ($data->is_processed == 1){ |
101
|
|
|
return '<div><h6>Processing <span class="badge badge-success text-uppercase">Successful</span></h6></div>'; |
102
|
|
|
}elseif ($data->is_processed == 2){ |
103
|
|
|
return '<div><h6>Processing <span class="badge badge-danger text-uppercase">Failed</span></h6></div>'; |
104
|
|
|
}elseif ($data->is_processed == 0){ |
105
|
|
|
return '<button onclick="updateProcess('.($data->id).',200)" class="btn btn-block btn-warning text-uppercase">pause</button>'; |
106
|
|
|
}elseif ($data->is_processed == 4){ |
107
|
|
|
return '<button onclick="updateProcess('.($data->id).',100)" class="btn btn-block btn-success text-uppercase">resume</button>'; |
108
|
|
|
} |
109
|
|
|
}) |
110
|
|
|
->rawColumns(['filename','error','actions']) |
111
|
|
|
->make(true); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Show the form for creating a new resource. |
116
|
|
|
* |
117
|
|
|
* @return \Illuminate\Http\Response |
118
|
|
|
*/ |
119
|
|
|
public function create() |
120
|
|
|
{ |
121
|
|
|
return view('displaydata'); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|