farhantock
1 year ago
12 changed files with 266 additions and 237 deletions
@ -1,95 +1,95 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\ActivityDokumen; |
||||
|
||||
class ActivityDokumenController extends Controller |
||||
{ |
||||
|
||||
public function dokumenByActivityId($id){ |
||||
if(empty($id) || !is_int((int)$id)) |
||||
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); |
||||
|
||||
$dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); |
||||
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200); |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
if(empty($id) || !is_int((int)$id)) |
||||
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
||||
|
||||
$document = ActivityDokumen::find($id); |
||||
|
||||
if(!$document) |
||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||
|
||||
if(file_exists($this->pathActivityDocument.$document->file)) |
||||
unlink($this->pathActivityDocument.$document->file); |
||||
|
||||
$document->delete(); |
||||
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); |
||||
} |
||||
|
||||
public function uploadProjectDokumen(Request $request) |
||||
{ |
||||
if(!$request->hasFile('dokumen')) |
||||
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); |
||||
|
||||
$activity_id = $request->activity_id; |
||||
$document = $request->file('dokumen'); |
||||
$name = $document->getClientOriginalName(); |
||||
|
||||
$result = $document->move($this->pathActivityDocument, $name); |
||||
|
||||
if(!$result) |
||||
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); |
||||
|
||||
$data = [ |
||||
'activity_id' => (int)$activity_id, |
||||
'file' => $name, |
||||
'description' => $request->description |
||||
]; |
||||
|
||||
$result = ActivityDokumen::create($data); |
||||
|
||||
if(!$result){ |
||||
unlink($this->pathActivityDocument.$name); |
||||
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); |
||||
} |
||||
|
||||
return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200); |
||||
} |
||||
|
||||
public function searchDocProject(Request $request){ |
||||
$payload = $request->all(); |
||||
|
||||
$dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); |
||||
$builder = $dataBuilder['builder']; |
||||
$countBuilder = $dataBuilder['count']; |
||||
$dataGet = $builder->get(); |
||||
$totalRecord = $countBuilder->count(); |
||||
|
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||
} |
||||
|
||||
public function downloadDokumen($id) |
||||
{ |
||||
if(empty($id) || !is_int((int)$id)) |
||||
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
||||
|
||||
$document = ActivityDokumen::find($id); |
||||
|
||||
if(!$document) |
||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); |
||||
|
||||
if(file_exists($this->pathActivityDocument.$document->file)){ |
||||
$pathToFile = $this->pathActivityDocument.$document->file; |
||||
return response()->download($pathToFile); |
||||
} |
||||
|
||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\ActivityDokumen; |
||||
|
||||
class ActivityDokumenController extends Controller |
||||
{ |
||||
|
||||
public function dokumenByActivityId($id){ |
||||
if(empty($id) || !is_int((int)$id)) |
||||
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); |
||||
|
||||
$dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); |
||||
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200); |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
if(empty($id) || !is_int((int)$id)) |
||||
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
||||
|
||||
$document = ActivityDokumen::find($id); |
||||
|
||||
if(!$document) |
||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||
|
||||
if(file_exists($this->pathActivityDocument.$document->file)) |
||||
unlink($this->pathActivityDocument.$document->file); |
||||
|
||||
$document->delete(); |
||||
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); |
||||
} |
||||
|
||||
public function uploadProjectDokumen(Request $request) |
||||
{ |
||||
if(!$request->hasFile('dokumen')) |
||||
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); |
||||
|
||||
$activity_id = $request->activity_id; |
||||
$document = $request->file('dokumen'); |
||||
$name = $document->getClientOriginalName(); |
||||
|
||||
$result = $document->move($this->pathActivityDocument, $name); |
||||
|
||||
if(!$result) |
||||
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); |
||||
|
||||
$data = [ |
||||
'activity_id' => (int)$activity_id, |
||||
'file' => $name, |
||||
'description' => $request->description |
||||
]; |
||||
|
||||
$result = ActivityDokumen::create($data); |
||||
|
||||
if(!$result){ |
||||
unlink($this->pathActivityDocument.$name); |
||||
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); |
||||
} |
||||
|
||||
return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200); |
||||
} |
||||
|
||||
public function searchDocProject(Request $request){ |
||||
$payload = $request->all(); |
||||
|
||||
$dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); |
||||
$builder = $dataBuilder['builder']; |
||||
$countBuilder = $dataBuilder['count']; |
||||
$dataGet = $builder->get(); |
||||
$totalRecord = $countBuilder->count(); |
||||
|
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||
} |
||||
|
||||
public function downloadDokumen($id) |
||||
{ |
||||
if(empty($id) || !is_int((int)$id)) |
||||
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
||||
|
||||
$document = ActivityDokumen::find($id); |
||||
|
||||
if(!$document) |
||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); |
||||
|
||||
if(file_exists($this->pathActivityDocument.$document->file)){ |
||||
$pathToFile = $this->pathActivityDocument.$document->file; |
||||
return response()->download($pathToFile); |
||||
} |
||||
|
||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
@ -1,22 +1,22 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class CommentActivity extends Model |
||||
{ |
||||
protected $table = 'm_comment_activity'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'activity_id', |
||||
'comment', |
||||
'created_at', |
||||
'created_by', |
||||
'updated_at', |
||||
'updated_by' |
||||
]; |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class CommentActivity extends Model |
||||
{ |
||||
protected $table = 'm_comment_activity'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'activity_id', |
||||
'comment', |
||||
'created_at', |
||||
'created_by', |
||||
'updated_at', |
||||
'updated_by' |
||||
]; |
||||
} |
||||
|
@ -1,38 +1,38 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class HumanResource extends Model |
||||
{ |
||||
protected $table = 'm_users'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'role_id', |
||||
'username', |
||||
'password', |
||||
'session_login', |
||||
'name', |
||||
'phone_number', |
||||
'email', |
||||
'address', |
||||
'fcm_token', |
||||
'gender', |
||||
'birth_place', |
||||
'birth_date', |
||||
'blood_type', |
||||
'ktp_number', |
||||
'employee_type', |
||||
'status_resource', |
||||
'created_at', |
||||
'created_by', |
||||
'updated_at', |
||||
'updated_by', |
||||
'divisi_id', |
||||
'status_boundary' |
||||
]; |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class HumanResource extends Model |
||||
{ |
||||
protected $table = 'm_users'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'role_id', |
||||
'username', |
||||
'password', |
||||
'session_login', |
||||
'name', |
||||
'phone_number', |
||||
'email', |
||||
'address', |
||||
'fcm_token', |
||||
'gender', |
||||
'birth_place', |
||||
'birth_date', |
||||
'blood_type', |
||||
'ktp_number', |
||||
'employee_type', |
||||
'status_resource', |
||||
'created_at', |
||||
'created_by', |
||||
'updated_at', |
||||
'updated_by', |
||||
'divisi_id', |
||||
'status_boundary' |
||||
]; |
||||
} |
||||
|
@ -1,77 +1,77 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
use App\Models\Activity; |
||||
use App\Models\Link; |
||||
use DateTime; |
||||
|
||||
class VersionGantt extends Model |
||||
{ |
||||
protected $table = 'm_version_gantt'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name_version', |
||||
'description', |
||||
'date_base_line', |
||||
'proyek_id', |
||||
'config_dayoff', |
||||
'auto_schedule', |
||||
'calculation_type', |
||||
'committed_cost', |
||||
'cost_to_complete', |
||||
'progress', |
||||
'bobot', |
||||
'hierarchy_ftth_id', |
||||
'created_at', |
||||
'created_by', |
||||
'updated_at', |
||||
'updated_by' |
||||
]; |
||||
|
||||
public static function boot() { |
||||
parent::boot(); |
||||
|
||||
static::updated(function($data) { |
||||
$data->updateActDuration(); |
||||
}); |
||||
} |
||||
|
||||
public function updateActDuration(){ |
||||
$daysOff = explode(',', $this->config_dayoff); |
||||
if (in_array('0', $daysOff)) { |
||||
$key = array_search('0', $daysOff, false); |
||||
$daysOff[$key] = '7'; |
||||
} |
||||
$activities = Activity::where('version_gantt_id', $this->id)->get(); |
||||
foreach ($activities as $value) { |
||||
$exist = Link::where('t_activity_id', $value->id)->exists(); |
||||
$startDate = new DateTime($value->start_date); |
||||
$endDate = new DateTime($value->end_date); |
||||
$duration = $endDate->diff($startDate)->days + 1; |
||||
if ($exist) { |
||||
$duration--; |
||||
} |
||||
|
||||
// Iterate through each day and subtract the days off |
||||
for ($i = 0; $i < $duration; $i++) { |
||||
$currentDate = clone $startDate; |
||||
$currentDate->modify("+$i day"); |
||||
|
||||
$currentDayOfWeek = $currentDate->format('N'); // Get the day of the week (1 - Monday, 7 - Sunday) |
||||
|
||||
if (in_array($currentDayOfWeek, $daysOff)) { |
||||
$duration--; // Subtract one day from the duration for each day off |
||||
} |
||||
} |
||||
|
||||
// Update the activity duration |
||||
$value->duration = $duration; |
||||
$value->save(); |
||||
} |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
use App\Models\Activity; |
||||
use App\Models\Link; |
||||
use DateTime; |
||||
|
||||
class VersionGantt extends Model |
||||
{ |
||||
protected $table = 'm_version_gantt'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name_version', |
||||
'description', |
||||
'date_base_line', |
||||
'proyek_id', |
||||
'config_dayoff', |
||||
'auto_schedule', |
||||
'calculation_type', |
||||
'committed_cost', |
||||
'cost_to_complete', |
||||
'progress', |
||||
'bobot', |
||||
'hierarchy_ftth_id', |
||||
'created_at', |
||||
'created_by', |
||||
'updated_at', |
||||
'updated_by' |
||||
]; |
||||
|
||||
public static function boot() { |
||||
parent::boot(); |
||||
|
||||
static::updated(function($data) { |
||||
$data->updateActDuration(); |
||||
}); |
||||
} |
||||
|
||||
public function updateActDuration(){ |
||||
$daysOff = explode(',', $this->config_dayoff); |
||||
if (in_array('0', $daysOff)) { |
||||
$key = array_search('0', $daysOff, false); |
||||
$daysOff[$key] = '7'; |
||||
} |
||||
$activities = Activity::where('version_gantt_id', $this->id)->get(); |
||||
foreach ($activities as $value) { |
||||
$exist = Link::where('t_activity_id', $value->id)->exists(); |
||||
$startDate = new DateTime($value->start_date); |
||||
$endDate = new DateTime($value->end_date); |
||||
$duration = $endDate->diff($startDate)->days + 1; |
||||
if ($exist) { |
||||
$duration--; |
||||
} |
||||
|
||||
// Iterate through each day and subtract the days off |
||||
for ($i = 0; $i < $duration; $i++) { |
||||
$currentDate = clone $startDate; |
||||
$currentDate->modify("+$i day"); |
||||
|
||||
$currentDayOfWeek = $currentDate->format('N'); // Get the day of the week (1 - Monday, 7 - Sunday) |
||||
|
||||
if (in_array($currentDayOfWeek, $daysOff)) { |
||||
$duration--; // Subtract one day from the duration for each day off |
||||
} |
||||
} |
||||
|
||||
// Update the activity duration |
||||
$value->duration = $duration; |
||||
$value->save(); |
||||
} |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue