farhantock
7 months ago
72 changed files with 14838 additions and 10556 deletions
@ -0,0 +1,28 @@
|
||||
<?php |
||||
|
||||
namespace App\Console\Commands; |
||||
|
||||
use App\Models\HierarchyFtth; |
||||
use Illuminate\Console\Command; |
||||
use App\Helpers\MasterFunctionsHelper; |
||||
use App\Models\Project; |
||||
|
||||
class CalculateProgressGantt extends Command |
||||
{ |
||||
protected $signature = 'calculate:progressgantt {hierarchy_id}'; |
||||
|
||||
protected $description = 'Calculate Progress Gantt'; |
||||
|
||||
public function handle() |
||||
{ |
||||
$hierarchy_id = $this->argument('hierarchy_id'); |
||||
$hierarchy = HierarchyFtth::findOrFail($hierarchy_id); |
||||
$project = Project::find($hierarchy->project_id); |
||||
|
||||
$data = MasterFunctionsHelper::calculateSCurveForProgressTree($hierarchy_id); |
||||
|
||||
$hierarchy->bobot_planning = 100; |
||||
$hierarchy->progress =round(((int) end($data[0]['data']['percentageReal']) / (int) end($data[0]['data']['percentagePlan'])) * 100, 2); |
||||
$hierarchy->save(); |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -1,160 +1,159 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\AssignTools; |
||||
use Datatables; |
||||
use App\Models\ToolsResource; |
||||
class AssignToolsController extends Controller |
||||
{ |
||||
public function add(Request $request){ |
||||
$this->validate($request, [ |
||||
'activity_id' => 'required', |
||||
'tools_id' => 'required', |
||||
'qty_planning' => 'required', |
||||
]); |
||||
|
||||
$checkStock = ToolsResource::where("id", $request->tools_id)->first(); |
||||
$currentStock = $checkStock->qty; |
||||
if((int)$currentStock < (int)$request->qty_planning){ |
||||
return response()->json(['status'=>'failed','message'=>'Not enough stock in warehouse!','code'=>400]); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
$data = $request->all(); |
||||
|
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = AssignTools::create($data); |
||||
if($result){ |
||||
$checkStock = ToolsResource::find($request->tools_id); |
||||
$newStock = (int)$checkStock->qty - (int)$request->qty_planning; |
||||
$dataUpdate = array( |
||||
"qty"=>$newStock, |
||||
"updated_by"=>$this->currentName |
||||
); |
||||
$checkStock->update($dataUpdate); |
||||
return response()->json(['status'=>'success','message'=>'Assign tools success!','code'=>200]); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed','code'=>400]); |
||||
} |
||||
} |
||||
|
||||
private function updateFromAdd($data){ |
||||
$assignTools = AssignTools::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id)->first(); |
||||
|
||||
$newQty = (int)$assignTools->qty_planning + (int)$data->qty_planning; |
||||
$dataUpdate = array( |
||||
"qty_planning"=>$newQty, |
||||
"updated_by"=>$this->currentName |
||||
); |
||||
|
||||
$dataWillUpdate = AssignMaterial::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id); |
||||
|
||||
return $dataWillUpdate->update($dataUpdate); |
||||
} |
||||
|
||||
public function update(Request $request, $id){ |
||||
|
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
} |
||||
$data = AssignTools::find($id); |
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'Assign tools successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = AssignTools::find($id); |
||||
|
||||
if($data){ |
||||
$id = $data->tools_id; |
||||
$stock = $data->qty_planning; |
||||
$toolsResource = ToolsResource::find($id); |
||||
if($toolsResource){ |
||||
$oldStock = $toolsResource->qty; |
||||
$newStock = $oldStock + $stock; |
||||
$dataUpdate = array( |
||||
"qty"=>$newStock, |
||||
"updated_by"=>$this->currentName |
||||
); |
||||
$toolsResource->update($dataUpdate); |
||||
} |
||||
|
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success','message'=>'Assign tools successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function edit($id){ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = AssignTools::find($id); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get data Assign tools, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'assign_tools_to_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 list() |
||||
{ |
||||
$data = AssignTools::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if($data){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get Assign tools, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function datatables(Request $request){ |
||||
$id_activity = $request->query('idact'); |
||||
$data = AssignTools::select("assign_tools_to_activity.*","m.name as tools_name","m.uom as uom")->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id")->where('assign_tools_to_activity.activity_id', $id_activity)->get(); |
||||
return Datatables::of($data) |
||||
->addIndexColumn() |
||||
->addColumn('action', function($row){ |
||||
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-tools-delete"><i class="fa fa-trash"></i></a>'; |
||||
return $actionBtn; |
||||
}) |
||||
->rawColumns(['action'])->make(true); |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use App\Models\{AssignMaterial,AssignTools,ToolsResource}; |
||||
use Illuminate\Http\Request; |
||||
use Yajra\Datatables\Datatables; |
||||
class AssignToolsController extends Controller |
||||
{ |
||||
public function add(Request $request){ |
||||
$this->validate($request, [ |
||||
'activity_id' => 'required', |
||||
'tools_id' => 'required', |
||||
'qty_planning' => 'required', |
||||
]); |
||||
|
||||
$checkStock = ToolsResource::where("id", $request->tools_id)->first(); |
||||
$currentStock = $checkStock->qty; |
||||
if((int)$currentStock < (int)$request->qty_planning){ |
||||
return response()->json(['status'=>'failed','message'=>'Not enough stock in warehouse!','code'=>400]); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
$data = $request->all(); |
||||
|
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = AssignTools::create($data); |
||||
if($result){ |
||||
$checkStock = ToolsResource::find($request->tools_id); |
||||
$newStock = (int)$checkStock->qty - (int)$request->qty_planning; |
||||
$dataUpdate = array( |
||||
"qty"=>$newStock, |
||||
"updated_by"=>$this->currentName |
||||
); |
||||
$checkStock->update($dataUpdate); |
||||
return response()->json(['status'=>'success','message'=>'Assign tools success!','code'=>200]); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed','code'=>400]); |
||||
} |
||||
} |
||||
|
||||
private function updateFromAdd($data){ |
||||
$assignTools = AssignTools::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id)->first(); |
||||
|
||||
$newQty = (int)$assignTools->qty_planning + (int)$data->qty_planning; |
||||
$dataUpdate = array( |
||||
"qty_planning"=>$newQty, |
||||
"updated_by"=>$this->currentName |
||||
); |
||||
|
||||
$dataWillUpdate = AssignMaterial::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id); |
||||
|
||||
return $dataWillUpdate->update($dataUpdate); |
||||
} |
||||
|
||||
public function update(Request $request, $id){ |
||||
|
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
} |
||||
$data = AssignTools::find($id); |
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'Assign tools successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = AssignTools::find($id); |
||||
|
||||
if($data){ |
||||
$id = $data->tools_id; |
||||
$stock = $data->qty_planning; |
||||
$toolsResource = ToolsResource::find($id); |
||||
if($toolsResource){ |
||||
$oldStock = $toolsResource->qty; |
||||
$newStock = $oldStock + $stock; |
||||
$dataUpdate = array( |
||||
"qty"=>$newStock, |
||||
"updated_by"=>$this->currentName |
||||
); |
||||
$toolsResource->update($dataUpdate); |
||||
} |
||||
|
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success','message'=>'Assign tools successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function edit($id){ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = AssignTools::find($id); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get data Assign tools, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'assign_tools_to_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 list() |
||||
{ |
||||
$data = AssignTools::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if($data){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get Assign tools, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function datatables(Request $request){ |
||||
$id_activity = $request->query('idact'); |
||||
$data = AssignTools::select("assign_tools_to_activity.*","m.name as tools_name","m.uom as uom")->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id")->where('assign_tools_to_activity.activity_id', $id_activity)->get(); |
||||
return Datatables::of($data) |
||||
->addIndexColumn() |
||||
->addColumn('action', function($row){ |
||||
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-tools-delete"><i class="fa fa-trash"></i></a>'; |
||||
return $actionBtn; |
||||
}) |
||||
->rawColumns(['action'])->make(true); |
||||
} |
||||
} |
||||
|
@ -1,97 +1,204 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Support\Facades\Auth; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\Hash; |
||||
|
||||
use App\Models\User; |
||||
use App\Models\Role; |
||||
use Illuminate\Http\JsonResponse; |
||||
use Illuminate\Support\Facades\Password; |
||||
use Illuminate\Validation\ValidationException; |
||||
|
||||
class AuthController extends Controller |
||||
{ |
||||
public function __construct() |
||||
{ |
||||
$this->middleware('auth:api', ['except' => ['login']]); |
||||
} |
||||
|
||||
public function login(Request $request) |
||||
{ |
||||
$username = $request->username; |
||||
$password = $request->password; |
||||
$remember = $request->remember; |
||||
$is_mobile = $request->is_mobile; |
||||
|
||||
if (empty($username) || empty($password)) |
||||
return response()->json(['status' => 'error', 'message' => 'You must fill all the fields'], 400); |
||||
|
||||
$usernameCheck = false; |
||||
$passwordCheck = false; |
||||
|
||||
if (User::where('username', $username)->exists()) |
||||
$usernameCheck = true; |
||||
|
||||
if (User::where('password', md5($password))->exists()) |
||||
$passwordCheck = true; |
||||
|
||||
if ($usernameCheck & $passwordCheck) { |
||||
$user = User::where('username', $username)->where('password', md5($password))->first(); |
||||
if ($is_mobile) { |
||||
$fcm_token = $request->fcm_token; |
||||
|
||||
if (!$fcm_token || $fcm_token == "") |
||||
return response()->json(['status' => 'error', 'message' => 'FCM Token is required'], 400); |
||||
|
||||
$dataUpdateFcm = array( |
||||
"fcm_token" => $fcm_token |
||||
); |
||||
|
||||
$hr = User::find($user->id); |
||||
|
||||
if ($hr) |
||||
$hr->update($dataUpdateFcm); |
||||
} |
||||
|
||||
$dataRole = Role::find($user->role_id); |
||||
$dataHierarchy = $this->getDataHierarchy($user->divisi_id, $user->id); |
||||
|
||||
if ($dataRole) |
||||
$user->role = $dataRole; |
||||
|
||||
if ($dataHierarchy) |
||||
$user->hierarchy = $dataHierarchy; |
||||
|
||||
if (!$token = Auth::login($user)) |
||||
return response()->json(['error' => 'Unauthorized'], 401); |
||||
|
||||
$ttl = 60; |
||||
if ($remember) |
||||
$ttl = 10080; |
||||
|
||||
// todo : change existing md5 hashed function to laravel's originally bcrypt |
||||
/* $token = auth()->setTTL($ttl)->attempt(['username' => $username, 'password' => Hash::make($password)]); */ |
||||
/* dd(response()->json(['code'=>'200', 'token' => $token, 'ttl' => $ttl])); */ |
||||
|
||||
return response()->json([ |
||||
'code' => 200, |
||||
'data' => array( |
||||
'data_user' => $user, |
||||
'access_token' => $token, |
||||
'token_type' => 'bearer', |
||||
'expires_in' => auth()->factory()->getTTL() * $ttl, |
||||
), |
||||
]); |
||||
} else { |
||||
if (!$usernameCheck && !$passwordCheck) |
||||
return response()->json(['code' => 201, 'message' => "username and password doesn't match"], 201); |
||||
if (!$passwordCheck) |
||||
return response()->json(['code' => 201, 'message' => "password doesn't match"], 201); |
||||
if (!$usernameCheck) |
||||
return response()->json(['code' => 201, 'message' => "username doesn't match"], 201); |
||||
} |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use App\Models\Role; |
||||
use App\Models\User; |
||||
use App\Models\Company; |
||||
|
||||
use Illuminate\Support\Str; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Http\JsonResponse; |
||||
use Illuminate\Support\Facades\Auth; |
||||
use Illuminate\Support\Facades\Hash; |
||||
use Illuminate\Support\Facades\Password; |
||||
use Illuminate\Validation\ValidationException; |
||||
|
||||
const URL_EMAIL = 'https://notifapp.odm-iu.com/service-mail/notif_mail.php'; |
||||
class AuthController extends Controller |
||||
{ |
||||
public function __construct() |
||||
{ |
||||
$this->middleware('auth:api', ['except' => ['login','sendEmail']]); |
||||
} |
||||
|
||||
public function login(Request $request) |
||||
{ |
||||
$username = $request->username; |
||||
$password = $request->password; |
||||
$remember = $request->remember; |
||||
$is_mobile = $request->is_mobile; |
||||
$usernameCheck = false; |
||||
$passwordCheck = false; |
||||
|
||||
if (empty($username) || empty($password)) { |
||||
return response()->json(['status' => 'error', 'message' => 'You must fill all the fields'], 400); |
||||
} |
||||
|
||||
$userQuery = User::query() |
||||
->where('username',$username); |
||||
|
||||
if ($userQuery->exists()) { |
||||
$usernameCheck = true; |
||||
$passwordValue = $userQuery->first()->password; |
||||
if($passwordValue === md5($password)) { |
||||
$passwordCheck = true; |
||||
} |
||||
} |
||||
|
||||
if ($usernameCheck && $passwordCheck) { |
||||
$user = User::where([['username', $username],['password', md5($password)]])->first(); |
||||
$checkExpiredOspro = $this->setExpiredTimeOspro($user['company_id']); |
||||
if($checkExpiredOspro === false && $user['company_id'] != null) { |
||||
return response()->json(['status' => 'error', 'message' => 'Expired! Please update license!'], 201); |
||||
} |
||||
if ($is_mobile) { |
||||
$fcm_token = $request->fcm_token; |
||||
|
||||
if (!$fcm_token || $fcm_token == "") { |
||||
return response()->json(['status' => 'error', 'message' => 'FCM Token is required'], 400); |
||||
} |
||||
|
||||
$dataUpdateFcm = array( |
||||
"fcm_token" => $fcm_token |
||||
); |
||||
|
||||
$hr = User::find($user->id); |
||||
|
||||
if ($hr) { |
||||
$hr->update($dataUpdateFcm); |
||||
} |
||||
} |
||||
|
||||
$dataRole = Role::find($user->role_id); |
||||
$dataHierarchy = $this->getDataHierarchy($user->divisi_id, $user->id); |
||||
$configApp = Company::where('id', $user->company_id)->first(); |
||||
if ($configApp) { |
||||
$logoLogin = json_decode($configApp->logo_login, true); |
||||
$favicon = json_decode($configApp->favicon_image, true); |
||||
$logoHeader = json_decode($configApp->logo_header, true); |
||||
$configApp->logo_login = $logoLogin; |
||||
$configApp->favicon_image = $favicon; |
||||
$configApp->logo_header = $logoHeader; |
||||
} |
||||
|
||||
if ($configApp) { |
||||
$user->configApp = $configApp; |
||||
} |
||||
|
||||
if ($dataRole) { |
||||
$user->role = $dataRole; |
||||
} |
||||
|
||||
if ($dataHierarchy) { |
||||
$user->hierarchy = $dataHierarchy; |
||||
} |
||||
|
||||
if (!$token = Auth::login($user)) { |
||||
return response()->json(['error' => 'Unauthorized'], 401); |
||||
} |
||||
|
||||
$ttl = 60; |
||||
if ($remember) { |
||||
$ttl = 10080; |
||||
} |
||||
|
||||
// todo : change existing md5 hashed function to laravel's originally bcrypt |
||||
/* $token = auth()->setTTL($ttl)->attempt(['username' => $username, 'password' => Hash::make($password)]); */ |
||||
/* dd(response()->json(['code'=>'200', 'token' => $token, 'ttl' => $ttl])); */ |
||||
|
||||
return response()->json([ |
||||
'code' => 200, |
||||
'data' => array( |
||||
'data_user' => $user, |
||||
'access_token' => $token, |
||||
'token_type' => 'bearer', |
||||
'expires_in' => auth()->factory()->getTTL() * $ttl, |
||||
), |
||||
]); |
||||
} else { |
||||
if (!$usernameCheck || !$passwordCheck) { |
||||
return response()->json(['code' => 201, 'message' => "Username or password doesn't match"], 201); |
||||
} else { |
||||
return response()->json(['code' => 500, 'message' => "Server error"], 500); |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
public function sendEmail(Request $request) |
||||
{ |
||||
if (empty($request->password)) { |
||||
$hashed = Str::random(15); |
||||
} else { |
||||
$hashed = $request->password; |
||||
} |
||||
|
||||
$email = $request->email; |
||||
$user = User::select('email', 'name', 'username')->where('email', $email)->first(); |
||||
|
||||
if (!$user || empty($email)) { |
||||
return response()->json(['status' => 'error', 'message' => 'e-mail not found'], 400); |
||||
} else { |
||||
if($request->username) { |
||||
$username = $request->username; |
||||
$name = $request->username; |
||||
} else { |
||||
$username = $user->username; |
||||
$name = $user->name; |
||||
} |
||||
$this->reqHttpCurl($email, $hashed, $username, $name); |
||||
if(empty($request->password)) { |
||||
if (User::where('email', $email)->update(['password' => md5($hashed)])) { |
||||
return response()->json(['status' => 'success', 'code' => 200, 'message' => 'Password already sent to mail'], 200); |
||||
} |
||||
} else { |
||||
return response()->json(['status' => 'success', 'code' => 200, 'message' => 'Password already sent to mail'], 200); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private function reqHttpCurl($email, $password, $username, $name) |
||||
{ |
||||
$postData = [ |
||||
"to" => $email, |
||||
"name" => $name, |
||||
"username" => $username, |
||||
"password" => $password, |
||||
"from" => "app.integrasia@integrasiautama.com", |
||||
"alias_from" => "OSPRO", |
||||
"subject" => "Registration OSPRO", |
||||
"body" => "registration-ospro" |
||||
]; |
||||
|
||||
$curl = curl_init(); |
||||
|
||||
curl_setopt_array($curl, array( |
||||
CURLOPT_URL => URL_EMAIL, // your preferred url |
||||
CURLOPT_RETURNTRANSFER => true, |
||||
CURLOPT_ENCODING => "", |
||||
CURLOPT_MAXREDIRS => 10, |
||||
CURLOPT_TIMEOUT => 30000, |
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
||||
CURLOPT_CUSTOMREQUEST => "POST", |
||||
CURLOPT_POSTFIELDS => json_encode($postData), |
||||
CURLOPT_HTTPHEADER => array( |
||||
// Set here requred headers |
||||
"accept: */*", |
||||
"accept-language: en-US,en;q=0.8", |
||||
"content-type: application/json", |
||||
), |
||||
)); |
||||
|
||||
$response = curl_exec($curl); |
||||
$err = curl_error($curl); |
||||
|
||||
curl_close($curl); |
||||
|
||||
if ($err) { |
||||
echo "cURL Error #:" . $err; |
||||
} else { |
||||
print_r(json_decode($response)); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,115 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use App\Models\ContactSales; |
||||
use Illuminate\Http\Request; |
||||
|
||||
class ContactSalesController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'name' => 'required', |
||||
'role' => 'required', |
||||
'email' => 'required', |
||||
'number_phone' => 'required', |
||||
'status' => 'required', |
||||
]); |
||||
|
||||
$data = $request->all(); |
||||
|
||||
$data['created_by'] = '@System'; |
||||
$data['status'] = 'New Request'; |
||||
|
||||
$result = ContactSales::create($data); |
||||
|
||||
if ($result) { |
||||
return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Your message has been successfully received by our Sales team! Someone from our team will be in touch with you shortly.', 'code' => 200], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'Your message has been failed!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
if (!$id || (int) $id < 0 || $id == "") { |
||||
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = ContactSales::find($id); |
||||
|
||||
if ($result) { |
||||
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'failed get data Contact Sales, please try again later!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if (!$id || (int) $id < 0 || $id == "") { |
||||
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
||||
} |
||||
|
||||
$data = ContactSales::find($id); |
||||
|
||||
|
||||
if ($data) { |
||||
$result = $data->update($request->all()); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'data Contact Sales not found!', 'code' => 400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if ($result) { |
||||
return response()->json(['status' => 'success', 'message' => 'data Contact Sales successfully updated!', 'code' => 200], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'data Contact Sales failed updated!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = ContactSales::find($id); |
||||
|
||||
if ($data) { |
||||
$delete = $data->delete(); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'data Contact Sales not found!', 'code' => 400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if ($delete) { |
||||
return response()->json(['status' => 'success', 'message' => 'data Contact Sales successfully deleted!', 'code' => 200], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'data Contact Sales failed deleted!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_contact_sales'); |
||||
$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 list() |
||||
{ |
||||
$data = ContactSales::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if ($data) { |
||||
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'failed get list Contact Sales, please try again later!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,116 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use App\Models\Demo; |
||||
use Illuminate\Http\Request; |
||||
|
||||
class DemoController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'name' => 'required', |
||||
'role' => 'required', |
||||
'email' => 'required', |
||||
'number_phone' => 'required', |
||||
'status' => 'required', |
||||
'message' => 'required' |
||||
]); |
||||
|
||||
$data = $request->all(); |
||||
|
||||
$data['created_by'] = '@System'; |
||||
$data['status'] = 'New Request'; |
||||
|
||||
$result = Demo::create($data); |
||||
|
||||
if ($result) { |
||||
return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Request Demo successfully!', 'code' => 200], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'Request Demo failed!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
if (!$id || (int) $id < 0 || $id == "") { |
||||
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = Demo::find($id); |
||||
|
||||
if ($result) { |
||||
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'failed get data Demo, please try again later!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if (!$id || (int) $id < 0 || $id == "") { |
||||
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
||||
} |
||||
|
||||
$data = Demo::find($id); |
||||
|
||||
|
||||
if ($data) { |
||||
$result = $data->update($request->all()); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'data Demo not found!', 'code' => 400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if ($result) { |
||||
return response()->json(['status' => 'success', 'message' => 'data Demo successfully updated!', 'code' => 200], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'data Demo failed updated!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = Demo::find($id); |
||||
|
||||
if ($data) { |
||||
$delete = $data->delete(); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'data Demo not found!', 'code' => 400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if ($delete) { |
||||
return response()->json(['status' => 'success', 'message' => 'data Demo successfully deleted!', 'code' => 200], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'data Demo failed deleted!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_demo'); |
||||
$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 list() |
||||
{ |
||||
$data = Demo::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if ($data) { |
||||
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'failed get list Demo, please try again later!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
} |
@ -1,131 +1,143 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\FolderDocumentProyek; |
||||
use App\Models\DokumenProject; |
||||
|
||||
class FolderDocumentProyekController extends Controller |
||||
{ |
||||
public function add(Request $request){ |
||||
$this->validate($request, [ |
||||
'name_folder' => 'required', |
||||
'proyek_id' => 'required' |
||||
]); |
||||
$data = $request->all(); |
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = FolderDocumentProyek::create($data); |
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfull created','code'=>200]); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed created','code'=>400]); |
||||
} |
||||
} |
||||
|
||||
public function update(Request $request, $id){ |
||||
|
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
} |
||||
$data = FolderDocumentProyek::find($id); |
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data Folder Document Proyek not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = FolderDocumentProyek::find($id); |
||||
|
||||
if($data){ |
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data Folder Document Proyek not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_FolderDocumentProyek'); |
||||
$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 list() |
||||
{ |
||||
$data = FolderDocumentProyek::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if($data){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get list tools request, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
public function getTree($id) |
||||
{ |
||||
$data = FolderDocumentProyek::where('proyek_id', $id)->whereNull('parent_id')->orderByRaw('id ASC')->get(); |
||||
$dataFile = DokumenProject::where('type_dokumen', 'project-document-out-folder')->where('ref_id', $id)->orderByRaw('id ASC')->get(); |
||||
$finalData = []; |
||||
foreach($data as $objRow){ |
||||
$objRow->children = $this->getChildren($id, $objRow->id); |
||||
$objRow->key = rand(1, 1000); |
||||
$objRow->isDir = true; |
||||
$finalData[] = $objRow; |
||||
} |
||||
|
||||
foreach($dataFile as $objRowFile) { |
||||
$objRowFile->key = rand(1, 1000); |
||||
$objRowFile->isDir = false; |
||||
$objRowFile->proyek_id = $id; |
||||
$finalData[] = $objRowFile; |
||||
} |
||||
|
||||
return response()->json(['status'=>'success','data'=>$finalData,'code'=>200], 200); |
||||
} |
||||
|
||||
private function getChildren($proyek_id, $parent_id) |
||||
{ |
||||
$finalData = []; |
||||
$data = FolderDocumentProyek::where('proyek_id', $proyek_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get(); |
||||
$dataFile = DokumenProject::where('type_dokumen', 'project-document-in-folder')->where('ref_id', $parent_id)->orderByRaw('id ASC')->get(); |
||||
foreach($data as $objRow){ |
||||
$objRow->key = rand(1, 1000); |
||||
$objRow->children = $this->getChildren($proyek_id, $objRow->id); |
||||
$objRow->isDir = true; |
||||
$finalData[] = $objRow; |
||||
} |
||||
|
||||
foreach($dataFile as $objRowFile) { |
||||
$objRowFile->key = rand(1, 1000); |
||||
$objRowFile->isDir = false; |
||||
$objRowFile->proyek_id = $proyek_id; |
||||
$finalData[] = $objRowFile; |
||||
} |
||||
|
||||
return $finalData; |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use App\Models\Company; |
||||
use Illuminate\Http\Request; |
||||
use App\Models\DokumenProject; |
||||
use App\Models\FolderDocumentProyek; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Support\Facades\Log; |
||||
|
||||
class FolderDocumentProyekController extends Controller |
||||
{ |
||||
public function add(Request $request){ |
||||
$this->validate($request, [ |
||||
'name_folder' => 'required', |
||||
'proyek_id' => 'required' |
||||
]); |
||||
$data = $request->all(); |
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = FolderDocumentProyek::create($data); |
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfull created','code'=>200]); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed created','code'=>400]); |
||||
} |
||||
} |
||||
|
||||
public function update(Request $request, $id){ |
||||
|
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
} |
||||
$data = FolderDocumentProyek::find($id); |
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data Folder Document Proyek not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id, $company_id) |
||||
{ |
||||
DB::beginTransaction(); |
||||
$data = FolderDocumentProyek::find($id); |
||||
$company = Company::find($company_id); |
||||
if($data && $company) { |
||||
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
||||
$dir = $destinationPath['pathDocument']; |
||||
$dataFile = DokumenProject::where([['type_dokumen', 'project-document-in-folder'],['ref_id', $data['id']]])->orderByRaw('id ASC')->get(); |
||||
if (is_dir($dir)) { |
||||
foreach ($dataFile as $file) { |
||||
unlink($dir.$file['file']); |
||||
} |
||||
} |
||||
if($data->delete()) { |
||||
DB::commit(); |
||||
return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfully deleted!','code'=>200], 200); |
||||
} else { |
||||
DB::rollBack(); |
||||
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed deleted!','code'=>400], 400); |
||||
} |
||||
} else { |
||||
DB::rollBack(); |
||||
return response()->json(['status'=>'failed','message'=>'Data Folder Document Proyek not found!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_FolderDocumentProyek'); |
||||
$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 list() |
||||
{ |
||||
$data = FolderDocumentProyek::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if($data){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get list tools request, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function getTree($id) |
||||
{ |
||||
$data = FolderDocumentProyek::where('proyek_id', $id)->whereNull('parent_id')->orderByRaw('id ASC')->get(); |
||||
$dataFile = DokumenProject::where('type_dokumen', 'project-document-out-folder')->where('ref_id', $id)->orderByRaw('id ASC')->get(); |
||||
$finalData = []; |
||||
foreach($data as $objRow){ |
||||
$objRow->children = $this->getChildren($id, $objRow->id); |
||||
$objRow->key = rand(1, 1000); |
||||
$objRow->isDir = true; |
||||
$finalData[] = $objRow; |
||||
} |
||||
|
||||
foreach($dataFile as $objRowFile) { |
||||
$objRowFile->key = rand(1, 1000); |
||||
$objRowFile->isDir = false; |
||||
$objRowFile->proyek_id = (int)$id; |
||||
$finalData[] = $objRowFile; |
||||
} |
||||
|
||||
return response()->json(['status'=>'success','data'=>$finalData,'code'=>200], 200); |
||||
} |
||||
|
||||
private function getChildren($proyek_id, $parent_id) |
||||
{ |
||||
$finalData = []; |
||||
$data = FolderDocumentProyek::where('proyek_id', $proyek_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get(); |
||||
$dataFile = DokumenProject::where('type_dokumen', 'project-document-in-folder')->where('ref_id', $parent_id)->orderByRaw('id ASC')->get(); |
||||
foreach($data as $objRow){ |
||||
$objRow->key = rand(1, 1000); |
||||
$objRow->children = $this->getChildren($proyek_id, $objRow->id); |
||||
$objRow->isDir = true; |
||||
$finalData[] = $objRow; |
||||
} |
||||
|
||||
foreach($dataFile as $objRowFile) { |
||||
$objRowFile->key = rand(1, 1000); |
||||
$objRowFile->isDir = false; |
||||
$objRowFile->proyek_id = (int)$proyek_id; |
||||
$finalData[] = $objRowFile; |
||||
} |
||||
|
||||
return $finalData; |
||||
} |
||||
} |
||||
|
@ -1,140 +1,140 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\Holiday; |
||||
use Datatables; |
||||
|
||||
class HolidayController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'proyek_id' => 'required', |
||||
'version_gantt_id' => 'required', |
||||
'date' => 'required' |
||||
]); |
||||
|
||||
$data = $request->all(); |
||||
$duration = $request->duration; |
||||
if(!$duration){ |
||||
$data['duration'] = 1; |
||||
} |
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = Holiday::create($data); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'add holiday successfully!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'add holiday failed!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function edit($id){ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = Holiday::find($id); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get data holiday, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
} |
||||
|
||||
$data = Holiday::find($id); |
||||
|
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'data holiday successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = Holiday::find($id); |
||||
|
||||
if($data){ |
||||
$deletedData = $data; |
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success', 'data'=>$deletedData,'message'=>'data holiday successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_holidays'); |
||||
$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 list() |
||||
{ |
||||
$data = Holiday::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if($data){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get list holiday, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function datatables(Request $request){ |
||||
$proyek_id = $request->query('proyek_id'); |
||||
$gantt_id = $request->query('gantt_id'); |
||||
|
||||
$data = Holiday::where('proyek_id', $proyek_id)->where('version_gantt_id', $gantt_id)->get(); |
||||
|
||||
return Datatables::of($data) |
||||
->editColumn('date', function($row) { |
||||
$date = date_create($row->date); |
||||
$dateFormat = date_format($date,"d-m-Y"); |
||||
return $dateFormat; |
||||
}) |
||||
->editColumn('duration', function($row) { |
||||
$day = (int)$row->duration > 1 ? "days" : "day"; |
||||
return $row->duration." ".$day; |
||||
}) |
||||
->addIndexColumn() |
||||
->addColumn('action', function($row){ |
||||
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-holiday-delete"><i class="fa fa-trash"></i></a>'; |
||||
return $actionBtn; |
||||
}) |
||||
|
||||
->rawColumns(['action'])->make(true); |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\Holiday; |
||||
use Yajra\Datatables\Datatables; |
||||
|
||||
class HolidayController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'proyek_id' => 'required', |
||||
'version_gantt_id' => 'required', |
||||
'date' => 'required' |
||||
]); |
||||
|
||||
$data = $request->all(); |
||||
$duration = $request->duration; |
||||
if(!$duration){ |
||||
$data['duration'] = 1; |
||||
} |
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = Holiday::create($data); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'add holiday successfully!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'add holiday failed!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function edit($id){ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = Holiday::find($id); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get data holiday, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
} |
||||
|
||||
$data = Holiday::find($id); |
||||
|
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'data holiday successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = Holiday::find($id); |
||||
|
||||
if($data){ |
||||
$deletedData = $data; |
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success', 'data'=>$deletedData,'message'=>'data holiday successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_holidays'); |
||||
$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 list() |
||||
{ |
||||
$data = Holiday::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if($data){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get list holiday, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function datatables(Request $request){ |
||||
$proyek_id = $request->query('proyek_id'); |
||||
$gantt_id = $request->query('gantt_id'); |
||||
|
||||
$data = Holiday::where('proyek_id', $proyek_id)->where('version_gantt_id', $gantt_id)->get(); |
||||
|
||||
return Datatables::of($data) |
||||
->editColumn('date', function($row) { |
||||
$date = date_create($row->date); |
||||
$dateFormat = date_format($date,"d-m-Y"); |
||||
return $dateFormat; |
||||
}) |
||||
->editColumn('duration', function($row) { |
||||
$day = (int)$row->duration > 1 ? "days" : "day"; |
||||
return $row->duration." ".$day; |
||||
}) |
||||
->addIndexColumn() |
||||
->addColumn('action', function($row){ |
||||
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-holiday-delete"><i class="fa fa-trash"></i></a>'; |
||||
return $actionBtn; |
||||
}) |
||||
|
||||
->rawColumns(['action'])->make(true); |
||||
} |
||||
} |
||||
|
@ -1,121 +1,292 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\Image; |
||||
|
||||
class ImageController extends Controller |
||||
{ |
||||
public function uploadImage(Request $request){ |
||||
|
||||
if($request->hasFile('files')){ |
||||
|
||||
$this->validate($request, [ |
||||
'ref_id' => 'required', |
||||
'category' => 'required' |
||||
]); |
||||
|
||||
$ref_id = $request->ref_id; |
||||
$dokumen = $request->file('files'); |
||||
$extension = $dokumen->extension(); |
||||
$name = $ref_id.date("YmdHis").".".$extension; |
||||
|
||||
$resultMove = $dokumen->move($this->pathImage, $name); |
||||
|
||||
if($resultMove){ |
||||
$data = [ |
||||
'ref_id' => (int)$ref_id, |
||||
'image' => $name, |
||||
'category' => $request->category |
||||
]; |
||||
|
||||
$result = Image::create($data); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success', "name_image"=>$name,'message'=>'image upload is successfully!','code'=>200], 200); |
||||
}else{ |
||||
unlink($this->pathImage.$name); |
||||
return response()->json(['status'=>'failed','message'=>'image upload is failed!','code'=>400], 400); |
||||
} |
||||
|
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'image upload is failed!','code'=>400], 400); |
||||
} |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'image is required!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = Image::find($id); |
||||
|
||||
if($data){ |
||||
unlink($this->pathImage.$data->image); |
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data image not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success','message'=>'data image successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data image failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_image'); |
||||
$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 deleteByRef($id, $category) |
||||
{ |
||||
$data = Image::where("ref_id", $id)->where("category", $category)->first(); |
||||
|
||||
if($data){ |
||||
unlink($this->pathImage.$data->image); |
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data image not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success','message'=>'data image successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data image failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function getByRefId($id, $category) |
||||
{ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
if(!$category || $category==""){ |
||||
return response()->json(['status'=>'failed','message'=>'category is required!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = Image::where("ref_id", $id)->where("category", $category)->first(); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get data image, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use App\Models\Image; |
||||
use App\Models\Company; |
||||
use Illuminate\Http\Request; |
||||
use App\Models\ProductTransaction; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Support\Facades\Log; |
||||
|
||||
class ImageController extends Controller |
||||
{ |
||||
public function uploadImage(Request $request){ |
||||
DB::beginTransaction(); |
||||
if($request->hasFile('files')){ |
||||
|
||||
$this->validate($request, [ |
||||
'ref_id' => 'required', |
||||
'category' => 'required' |
||||
]); |
||||
|
||||
$ref_id = $request->ref_id; |
||||
$dokumen = $request->file('files'); |
||||
$extension = $dokumen->extension(); |
||||
$category = $request->category; |
||||
$name = $ref_id.date("YmdHis").".".$extension; |
||||
// Limited Storage |
||||
$company = Company::where('company_name', $request->company_name)->first(); |
||||
if($company) { |
||||
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
||||
$getLimitStorage = $this->setLimitsStorage($company, $dokumen, $destinationPath['pathImage'], $destinationPath); |
||||
} |
||||
if(isset($getLimitStorage)) { |
||||
if($getLimitStorage === false) { |
||||
DB::rollBack(); |
||||
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500); |
||||
} |
||||
$data = [ |
||||
'ref_id' => (int)$ref_id, |
||||
'image' => $name, |
||||
'category' => $category |
||||
]; |
||||
|
||||
$result = Image::create($data); |
||||
|
||||
$company = Company::find((int)$ref_id); |
||||
if($company && $category === 'company_logo_login') { |
||||
$dataArray = json_decode($company['logo_login'], true); |
||||
if(isset($dataArray['slider'])) { |
||||
$jsonImageSlider['login'] = $name; |
||||
$jsonImageSlider['slider'] = $dataArray['slider']; |
||||
} else { |
||||
$jsonImageSlider['login'] = $name; |
||||
} |
||||
$company->update([ |
||||
'logo_login' => $jsonImageSlider |
||||
]); |
||||
} |
||||
|
||||
if($company && $category === 'company_logo_header') { |
||||
$company->update([ |
||||
'logo_header' => array('content' => $name) |
||||
]); |
||||
} |
||||
|
||||
if($company && $category === 'company_favicon') { |
||||
$company->update([ |
||||
'favicon_image' => array('content' => $name) |
||||
]); |
||||
} |
||||
if($dokumen->move($destinationPath['pathImage'], $name) && $result) { |
||||
DB::commit(); |
||||
return response()->json(['status' => 'success', "name_image" => $name,'message' => 'image upload is successfully!','code' => 200], 200); |
||||
} else { |
||||
DB::rollBack(); |
||||
unlink($destinationPath['pathImage'].$name); |
||||
return response()->json(['status' => 'failed','message' => 'image upload is failed!' ,'code' => 400], 400); |
||||
} |
||||
|
||||
} else { |
||||
DB::rollBack(); |
||||
return response()->json(['status'=>'failed','message'=>'image upload is failed!','code'=>400], 400); |
||||
} |
||||
} else { |
||||
DB::rollBack(); |
||||
return response()->json(['status'=>'failed','message'=>'image is required!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function uploadMultipleImage(Request $request) { |
||||
$this->validate($request, [ |
||||
'ref_id' => 'required', |
||||
'category' => 'required', |
||||
'files.*' => 'required|file|mimes:jpeg,png,jpg,gif|max:2048', |
||||
]); |
||||
|
||||
if ($request->hasFile('files')) { |
||||
$ref_id = $request->ref_id; |
||||
$category = $request->category; |
||||
$dokumen = $request->file('files'); |
||||
$successCount = 0; |
||||
$imageSlider = []; |
||||
// Limited Storage |
||||
$company = Company::where('company_name', $request->company_name)->first(); |
||||
if($company) { |
||||
$totalSize = 0; |
||||
$sizeFile = 0; |
||||
foreach ($dokumen as $file) { |
||||
$sizeFile += $file->getSize(); |
||||
} |
||||
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
||||
$folderPath = $destinationPath['pathImage']; |
||||
|
||||
if (!file_exists($folderPath)) { |
||||
mkdir($folderPath, 0777, true); |
||||
} |
||||
|
||||
$files = scandir($folderPath); |
||||
|
||||
foreach ($files as $file) { |
||||
if (is_file($folderPath . '/' . $file)) { |
||||
$totalSize += filesize($folderPath . '/' . $file); |
||||
} |
||||
} |
||||
$totalSize += $sizeFile; |
||||
$transaction = ProductTransaction::query() |
||||
->where('company_id', $company['id']); |
||||
$cloneQueryTransaction = clone $transaction; |
||||
|
||||
$countCreate = false; |
||||
if($transaction->where([['type_paket','Basic'], ['amount','!=',null]])->exists()) { |
||||
$maximumSize = 500 * 1024 * 1024; |
||||
$countCreate = true; |
||||
} elseif ($cloneQueryTransaction->where([['type_paket','Free'], ['amount', 0]])->exists()) { |
||||
$maximumSize = 50 * 1024 * 1024; |
||||
$countCreate = true; |
||||
} |
||||
if($countCreate) { |
||||
if ($totalSize > $maximumSize) { |
||||
return response()->json(['status'=>'failed','message'=>'Limited storage maximum!','code'=> 500], 500); |
||||
} |
||||
} |
||||
} |
||||
foreach ($dokumen as $file) { |
||||
$extension = $file->extension(); |
||||
$name = $ref_id.date("YmdHis").$successCount.".".$extension; |
||||
|
||||
$resultMove = $file->move($folderPath, $name); |
||||
|
||||
if ($resultMove) { |
||||
$data = [ |
||||
'ref_id' => (int) $ref_id, |
||||
'image' => $name, |
||||
'category' => $category |
||||
]; |
||||
$imageSlider[] = [ |
||||
'content' => $name |
||||
]; |
||||
$result = Image::create($data); |
||||
if ($result) { |
||||
$successCount++; |
||||
} else { |
||||
unlink($folderPath . $name); |
||||
} |
||||
} |
||||
} |
||||
$company = Company::find((int)$ref_id); |
||||
if($company && $category === 'company_slider_login') { |
||||
$dataArray = json_decode($company['logo_login'], true); |
||||
if(isset($dataArray['login'])) { |
||||
$jsonImageSlider['login'] = $dataArray['login']; |
||||
$jsonImageSlider['slider'] = $imageSlider; |
||||
} else { |
||||
$jsonImageSlider['slider'] = $imageSlider; |
||||
} |
||||
$company->update([ |
||||
'logo_login' => $jsonImageSlider |
||||
]); |
||||
} |
||||
if ($successCount > 0 && $company) { |
||||
return response()->json(['status' => 'success', 'message' => "$successCount images uploaded successfully!", 'code' => 200], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'No images uploaded successfully!', 'code' => 400], 400); |
||||
} |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'Image is required!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = Image::find($id); |
||||
|
||||
if($data){ |
||||
unlink($this->pathImage.$data->image); |
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data image not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
if($delete){ |
||||
return response()->json(['status'=>'success','message'=>'data image successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data image failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_image'); |
||||
$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 deleteByRef($id, $category, $company_id) |
||||
{ |
||||
$data = Image::where("ref_id", (int)$id)->where("category", $category)->first(); |
||||
$company = Company::find($company_id); |
||||
if($data && $company){ |
||||
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
||||
unlink($destinationPath['pathImage'].$data->image); |
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data image not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success','message'=>'data image successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data image failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function deleteByRefMultiple($id, $category, $company_id) |
||||
{ |
||||
$successCount = 0; |
||||
$data = Image::where([ |
||||
["ref_id", intval($id)], |
||||
["category", $category] |
||||
])->get(); |
||||
$company = Company::find($company_id); |
||||
if($data->isNotEmpty() && $company) { |
||||
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
||||
foreach($data as $img) { |
||||
unlink($destinationPath['pathImage'].$img->image); |
||||
$delete = $img->delete(); |
||||
if($delete){ |
||||
$successCount++; |
||||
} |
||||
} |
||||
} else { |
||||
return response()->json(['status'=>'failed','message'=>'data image not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
if($successCount > 0) { |
||||
return response()->json(['status'=>'success','message'=>'data image successfully deleted!','code'=>200], 200); |
||||
} else { |
||||
return response()->json(['status'=>'failed','message'=>'data image failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function getByRefId($id, $category) |
||||
{ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
if(!$category || $category==""){ |
||||
return response()->json(['status'=>'failed','message'=>'category is required!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = Image::where("ref_id", $id)->where("category", $category)->first(); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get data image, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,115 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\KanbanBoard; |
||||
|
||||
class KanbanBoardController extends Controller |
||||
{ |
||||
public function add(Request $request){ |
||||
$this->validate($request, [ |
||||
'name_board' => 'required', |
||||
'header_color' => 'required', |
||||
'body_color' => 'required', |
||||
'proyek_id' => 'required', |
||||
'version_gantt_id' => 'required', |
||||
'status_progress' => 'required' |
||||
]); |
||||
$data = $request->all(); |
||||
$data['created_by'] = $this->currentName; |
||||
$statusCount = KanbanBoard::where('version_gantt_id', $request->version_gantt_id) |
||||
->where('status_progress', $request->status_progress) |
||||
->get() |
||||
->count(); |
||||
|
||||
if ($statusCount < 1 || $request->status_progress == 'none') { |
||||
$result = KanbanBoard::create($data); |
||||
} else { |
||||
return response()->json(['status'=>'failed','message'=>'Board kanban failed created','code'=>400], 400); |
||||
} |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'Board kanban successfull created','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Board kanban failed created','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function update(Request $request, $id){ |
||||
|
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
} |
||||
$data = KanbanBoard::find($id); |
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data Board kanban not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'Board kanban successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Board kanban failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = KanbanBoard::find($id); |
||||
|
||||
if($data){ |
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data Board kanban not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success','message'=>'Board kanban successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Board kanban failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function edit($id){ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = KanbanBoard::find($id); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get data Board kanban, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'kanban_board'); |
||||
$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 list(Request $request) |
||||
{ |
||||
$query = KanbanBoard::select("*"); |
||||
$countData = $query->count(); |
||||
$data = $this->paramsMethodGet($query, $countData, $request); |
||||
|
||||
if($data) |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>count($data)], 200); |
||||
|
||||
return response()->json(['status'=>'failed','message'=>'failed get Board kanban, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
@ -0,0 +1,258 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use App\Models\User; |
||||
use App\Models\Project; |
||||
use App\Models\Activity; |
||||
use App\Models\KanbanCard; |
||||
use App\Models\KanbanBoard; |
||||
// use Illuminate\Support\Arr; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\DB; |
||||
|
||||
class KanbanCardController extends Controller |
||||
{ |
||||
private function add($board_id, $gantt_id, $type_activity, $status_progress) |
||||
{ |
||||
$dataActivity = Activity::where("version_gantt_id", $gantt_id) |
||||
->where("type_activity", $type_activity) |
||||
->get(); |
||||
foreach ($dataActivity as $keyA) { |
||||
// $this->add($keyA->id, $gantt_id, $board_id); |
||||
$data = array( |
||||
'activity_id' => $keyA->id, |
||||
'kanban_board_id' => $board_id, |
||||
'version_gantt_id' => $gantt_id, |
||||
'created_by' => $this->currentName |
||||
); |
||||
switch ($status_progress) { |
||||
case 'open': |
||||
if ($keyA->persentase_progress == 0) { |
||||
$add = KanbanCard::create($data); |
||||
} |
||||
break; |
||||
case 'on-progress': |
||||
if ($keyA->persentase_progress > 0 && $keyA->persentase_progress < 100) { |
||||
$cardIds = DB::table('kanban_card as kc') |
||||
->join('m_activity as ma', 'kc.activity_id', '=', 'ma.id') |
||||
->where('kc.activity_id', '=', $keyA->id) |
||||
->select('kc.id') |
||||
->get(); |
||||
foreach ($cardIds as $cardId) { |
||||
$this->delete($cardId->id); |
||||
} |
||||
$add = KanbanCard::create($data); |
||||
} |
||||
break; |
||||
case 'done': |
||||
if ($keyA->persentase_progress == 100) { |
||||
$cardIds = DB::table('kanban_card as kc') |
||||
->join('m_activity as ma', 'kc.activity_id', '=', 'ma.id') |
||||
->where('kc.activity_id', '=', $keyA->id) |
||||
->select('kc.id') |
||||
->get(); |
||||
foreach ($cardIds as $cardId) { |
||||
$this->delete($cardId->id); |
||||
} |
||||
$add = KanbanCard::create($data); |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
return "success"; |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
|
||||
if (!$id || (int) $id < 0 || $id == "") { |
||||
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
||||
} |
||||
$data = KanbanCard::where("activity_id", $id); |
||||
if ($data) { |
||||
$result = $data->update($request->all()); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'Data Card kanban not found!', 'code' => 400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$board = KanbanBoard::find($request->kanban_board_id); |
||||
$activity = Activity::find($id); |
||||
if ($board->status_progress == "done" && $activity) { |
||||
$activity->update(['persentase_progress' => 100]); |
||||
} else{ |
||||
if($activity['persentase_progress'] != 95 && $activity['persentase_progress'] != 100){ |
||||
$activity->update(['persentase_progress' => 0]); |
||||
}else{ |
||||
$activity->update(['persentase_progress' => 95]); |
||||
} |
||||
|
||||
} |
||||
|
||||
if ($result) { |
||||
return response()->json(['status' => 'success', 'message' => 'Board kanban successfully updated!', 'code' => 200], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'Board kanban failed updated!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = KanbanCard::find($id); |
||||
|
||||
if ($data) { |
||||
$delete = $data->delete(); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'Data Board kanban not found!', 'code' => 400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if ($delete) { |
||||
return response()->json(['status' => 'success', 'message' => 'Board kanban successfully deleted!', 'code' => 200], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'Board kanban failed deleted!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
if (!$id || (int) $id < 0 || $id == "") { |
||||
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = KanbanCard::find($id); |
||||
|
||||
if ($result) { |
||||
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'failed get data Board kanban, please try again later!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'kanban_board'); |
||||
$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 getData($project_id, $gantt_id, $board_id, Request $request) |
||||
{ |
||||
// cek ketika dia owner dari project maka |
||||
$SESSIONID = $request->session; |
||||
$status_progress = KanbanBoard::select("status_progress")->where('id', $board_id)->first(); |
||||
if ($status_progress) { |
||||
if (DB::table('user_to_version_gantt')->where('user_id', $SESSIONID)->where('version_gantt_id', $gantt_id)->exists()) { |
||||
$dataCard = $this->getDataAll($project_id, $gantt_id, $board_id, $status_progress->status_progress, true); |
||||
} else { |
||||
$dataCard = $this->getDataContributor($project_id, $gantt_id, $board_id, $request, $status_progress->status_progress, true); |
||||
} |
||||
} else { |
||||
return response()->json(['status' => 'empty', 'message' => 'data board is empty, please you insert!', 'code' => 200], 200); |
||||
} |
||||
|
||||
if ($dataCard && count($dataCard) > 0){ |
||||
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataCard, "totalRecord" => count($dataCard)], 200); |
||||
}else{ |
||||
return response()->json(['status' => 'empty', 'message' => 'data card is empty, please you insert!', 'code' => 200], 200); |
||||
} |
||||
|
||||
} |
||||
|
||||
private function getDataAll($project_id, $gantt_id, $board_id, $status_progress, $status) |
||||
{ |
||||
$dataFinal = []; |
||||
if($status == true){ |
||||
if ($status_progress != 'none') { |
||||
if (KanbanCard::where('kanban_board_id', $board_id)->where("version_gantt_id", $gantt_id)->count() == 0) { |
||||
$this->add($board_id, $gantt_id, 'task', $status_progress); |
||||
$this->getDataAll($project_id, $gantt_id, $board_id, $status_progress, false); |
||||
} |
||||
} |
||||
} |
||||
|
||||
$dataCard = DB::table("kanban_card as kc") |
||||
->select("ma.id as activity_id", "ma.name", "ma.start_date", "ma.end_date", "ma.persentase_bobot", "ma.jumlah_pekerjaan", "ma.bobot_planning", "ma.persentase_progress") |
||||
->join("m_activity as ma", "ma.id", "=", "kc.activity_id") |
||||
->where("kc.kanban_board_id", $board_id) |
||||
->where("kc.version_gantt_id", $gantt_id) |
||||
->orderBy('ma.sortorder') |
||||
->get(); |
||||
|
||||
foreach ($dataCard as $keyCard) { |
||||
$query = DB::table("assign_hr_to_activity as ahta") |
||||
->select("ahta.id", "mu.name", "mu.id as id_hr") |
||||
->join("m_users as mu", "mu.id", "=", "ahta.user_id") |
||||
->where("ahta.activity_id", $keyCard->activity_id) |
||||
->get(); |
||||
|
||||
$dataArray = array( |
||||
"id" => $keyCard->activity_id, |
||||
"assign_hr" => $query, |
||||
"activity" => $keyCard->name, |
||||
"start_date" => $keyCard->start_date, |
||||
"end_date" => $keyCard->end_date, |
||||
"jumlah_pekerjaan" => $keyCard->jumlah_pekerjaan, |
||||
"bobot_planning" => $keyCard->bobot_planning, |
||||
"persentase_progress" => $keyCard->persentase_progress |
||||
); |
||||
$dataFinal[] = $dataArray; |
||||
} |
||||
// } |
||||
return $dataFinal; |
||||
} |
||||
|
||||
private function getDataContributor($project_id, $gantt_id, $board_id, $request, $status_progress, $status) |
||||
{ |
||||
$dataFinal = []; |
||||
if($status == true){ |
||||
if ($status_progress != 'none') { |
||||
if (KanbanCard::where('kanban_board_id', $board_id)->where("version_gantt_id", $gantt_id)->count() == 0) { |
||||
$this->add($board_id, $gantt_id, 'task', $status_progress); |
||||
$this->getDataContributor($project_id, $gantt_id, $board_id, $request, $status_progress, false); |
||||
} |
||||
} |
||||
$dataUser = User::whereId($request->session)->first(); |
||||
$dataCard = DB::table("kanban_card as kc") |
||||
->select("ma.id as activity_id", "ma.name", "ma.start_date", "ma.end_date", "ma.persentase_bobot", "ma.jumlah_pekerjaan", "ma.bobot_planning", "ma.persentase_progress") |
||||
->join("m_activity as ma", "ma.id", "=", "kc.activity_id") |
||||
->where([ |
||||
["kc.created_by", $dataUser['name']], |
||||
["kc.kanban_board_id", $board_id], |
||||
["kc.version_gantt_id", $gantt_id] |
||||
]) |
||||
->orderBy('ma.sortorder') |
||||
->get(); |
||||
foreach ($dataCard as $keyCard) { |
||||
$query = DB::table("assign_hr_to_activity as ahta") |
||||
->select("ahta.id", "mu.name", "mu.id as id_hr") |
||||
->join("m_users as mu", "mu.id", "=", "ahta.user_id") |
||||
->where("ahta.activity_id", $keyCard->activity_id) |
||||
->get(); |
||||
|
||||
$dataArray = array( |
||||
"id" => $keyCard->activity_id, |
||||
"assign_hr" => $query, |
||||
"activity" => $keyCard->name, |
||||
"start_date" => $keyCard->start_date, |
||||
"end_date" => $keyCard->end_date, |
||||
"jumlah_pekerjaan" => $keyCard->jumlah_pekerjaan, |
||||
"bobot_planning" => $keyCard->bobot_planning, |
||||
"persentase_progress" => $keyCard->persentase_progress, |
||||
"test" => $request->session |
||||
); |
||||
$dataFinal[] = $dataArray; |
||||
} |
||||
} |
||||
|
||||
return $dataFinal; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,92 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\ProductTransaction; |
||||
|
||||
class ProductTransactionController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'company_id' => 'required|integer', |
||||
'type_paket' => 'required|string', |
||||
'amount' => 'required', |
||||
'exp_ospro' => 'required' |
||||
]); |
||||
|
||||
$data = $request->all(); |
||||
|
||||
$data['created_by'] = $this->currentName; |
||||
$result = ProductTransaction::create($data); |
||||
|
||||
if ($result) { |
||||
return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Add Transaction successfully!', 'code' => 200], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'Add Transaction failed!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
if (!$id || (int) $id < 0 || $id == "") { |
||||
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = ProductTransaction::find($id); |
||||
|
||||
if ($result) { |
||||
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'Failed get data transaction, please try again later!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
||||
} |
||||
|
||||
$data = ProductTransaction::find($id); |
||||
|
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data transaction not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'Data transaction successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data transaction failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 't_transaction'); |
||||
$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 list() |
||||
{ |
||||
$data = ProductTransaction::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if ($data) { |
||||
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'failed get list Transaction, please try again later!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -1,105 +1,131 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\DokumenProject; |
||||
|
||||
class ProjectDokumenController extends Controller |
||||
{ |
||||
public function dokumenByProyekId($id){ |
||||
if(empty($id) || !is_int((int)$id)) { |
||||
return response()->json(['status'=>'failed','message'=>'project id is required!','code'=>400], 400); |
||||
} |
||||
|
||||
$document = DokumenProject::where("ref_id", $id)->get(); |
||||
|
||||
if(count($document) == 0) |
||||
return response()->json(['status'=>'','message'=>'Data not found!' ,'code'=>404], 404); |
||||
|
||||
return response()->json(['status'=>'success','data'=> $document ,'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 = DokumenProject::find($id); |
||||
if(!$document){ |
||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); |
||||
} |
||||
|
||||
if(file_exists($this->pathDocument.$document->file)){ |
||||
unlink($this->pathDocument.$document->file); |
||||
} |
||||
|
||||
$document->delete(); |
||||
|
||||
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); |
||||
} |
||||
|
||||
public function uploadProjectDokumen(Request $request) |
||||
{ |
||||
if($request->hasFile('dokumen')){ |
||||
$document = $request->file('dokumen'); |
||||
$ref_id = $request->ref_id; |
||||
$name = $document->getClientOriginalName(); |
||||
|
||||
$result = $document->move($this->pathDocument, $name); |
||||
if($result){ |
||||
$data = [ |
||||
'ref_id' => (int)$ref_id, |
||||
'file' => $name, |
||||
'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document' |
||||
]; |
||||
|
||||
$result = DokumenProject::create($data); |
||||
|
||||
if(!$result){ |
||||
unlink($this->pathDocument.$name); |
||||
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); |
||||
} |
||||
return response()->json(['status'=>'success','message'=>'Upload successful!','code'=>200], 200); |
||||
|
||||
} |
||||
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); |
||||
} |
||||
return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400); |
||||
} |
||||
|
||||
public function searchDocProject(Request $request){ |
||||
$payload = $request->all(); |
||||
|
||||
$dataBuilder = $this->setUpPayload($payload, 'document_project'); |
||||
$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 = DokumenProject::find($id); |
||||
|
||||
if(!$document) |
||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||
|
||||
if(!file_exists($this->pathDocument.$document->file)) |
||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||
|
||||
$pathToFile = $this->pathDocument.$document->file; |
||||
$name = pathinfo($pathToFile, PATHINFO_FILENAME) . "." . pathinfo($pathToFile, PATHINFO_EXTENSION); |
||||
$headers = [ |
||||
'Content-Disposition' => 'attachment; filename="'.$name.'"' |
||||
]; |
||||
// dd($name, $headers); |
||||
return response()->download($pathToFile, $name, $headers); |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\{DokumenProject,Company}; |
||||
use Carbon\Carbon; |
||||
use Illuminate\Support\Facades\DB; |
||||
|
||||
class ProjectDokumenController extends Controller |
||||
{ |
||||
public function dokumenByProyekId($id){ |
||||
if(empty($id) || !is_int((int)$id)) { |
||||
return response()->json(['status'=>'failed','message'=>'project id is required!','code'=>400], 400); |
||||
} |
||||
|
||||
$document = DokumenProject::where("ref_id", $id)->get(); |
||||
|
||||
if(count($document) == 0) |
||||
return response()->json(['status'=>'','message'=>'Data not found!' ,'code'=>404], 404); |
||||
|
||||
return response()->json(['status'=>'success','data'=> $document ,'code'=>200], 200); |
||||
} |
||||
|
||||
public function delete($id, $company_id) |
||||
{ |
||||
if(empty($id) || !is_int((int)$id)) { |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
} |
||||
|
||||
$document = DokumenProject::find($id); |
||||
if(!$document){ |
||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); |
||||
} |
||||
$company = Company::find($company_id); |
||||
if($company) { |
||||
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
||||
if(file_exists($destinationPath['pathDocument'].$document['file'])){ |
||||
unlink($destinationPath['pathDocument'].$document['file']); |
||||
} |
||||
} |
||||
$document->delete(); |
||||
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); |
||||
} |
||||
|
||||
public function uploadProjectDokumen(Request $request) |
||||
{ |
||||
DB::beginTransaction(); |
||||
$timeNow = Carbon::now(); |
||||
if($request->hasFile('dokumen')){ |
||||
$document = $request->file('dokumen'); |
||||
$ref_id = $request->ref_id; |
||||
|
||||
$originalFilename = $document->getClientOriginalName(); |
||||
$extension = pathinfo($originalFilename, PATHINFO_EXTENSION); |
||||
$filename = pathinfo($originalFilename, PATHINFO_FILENAME); |
||||
$name = $filename . '_' . $timeNow->format('d-m-y-His') . '.' . $extension; |
||||
// Limited Storage |
||||
$company = Company::whereId($request->company_id)->first(); |
||||
if($company) { |
||||
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
||||
$getLimitStorage = $this->setLimitsStorage($company, $document, $destinationPath['pathDocument'],$destinationPath); |
||||
} |
||||
if(isset($getLimitStorage)) { |
||||
if($getLimitStorage === false) { |
||||
DB::rollBack(); |
||||
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500); |
||||
} |
||||
$data = [ |
||||
'ref_id' => (int)$ref_id, |
||||
'file' => $name, |
||||
'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document' |
||||
]; |
||||
|
||||
$result = DokumenProject::create($data); |
||||
|
||||
if(!$document->move($destinationPath['pathDocument'], $name) && $result) { |
||||
unlink($destinationPath['pathDocument'].$name); |
||||
DB::rollBack(); |
||||
return response()->json(['status'=>'failed','message'=>'Dokumen project gagal diupload!','code'=> 500], 500); |
||||
} |
||||
DB::commit(); |
||||
return response()->json(['status'=>'success','message'=>'Dokumen project berhasil diupload!','code'=>200], 200); |
||||
} |
||||
DB::rollBack(); |
||||
return response()->json(['status'=>'failed','message'=>'Dokumen project gagal diupload!','code'=> 500], 500); |
||||
} |
||||
DB::rollBack(); |
||||
return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400); |
||||
} |
||||
|
||||
public function searchDocProject(Request $request){ |
||||
$payload = $request->all(); |
||||
|
||||
$dataBuilder = $this->setUpPayload($payload, 'document_project'); |
||||
$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, $company_id) |
||||
{ |
||||
if(empty($id) || !is_int((int)$id)) { |
||||
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
||||
} |
||||
$document = DokumenProject::find($id); |
||||
$company = Company::find($company_id); |
||||
|
||||
if(!$document || !$company) { |
||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||
} |
||||
|
||||
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
||||
$pathToFile = $destinationPath['pathDocument'].$document['file']; |
||||
|
||||
if(!file_exists($pathToFile)) { |
||||
return response()->json(['status'=>'failed','message'=>'Directory not found!','code'=> 404], 404); |
||||
} |
||||
if($company) { |
||||
$name = pathinfo($pathToFile, PATHINFO_FILENAME) . "." . pathinfo($pathToFile, PATHINFO_EXTENSION); |
||||
} |
||||
$headers = [ |
||||
'Content-Disposition' => 'attachment; filename="'.$name.'"' |
||||
]; |
||||
|
||||
return response()->download($pathToFile, $name, $headers); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,93 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\ProjectExpenditure; |
||||
|
||||
class ProjectExpenditureController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'name' => 'required' |
||||
]); |
||||
$data = $request->all(); |
||||
// Set Unique |
||||
$result = ProjectExpenditure::query() |
||||
->where([ |
||||
['company_id',$data['company_id']], |
||||
['name', $data['name']] |
||||
])->first(); |
||||
if($result) { |
||||
return response()->json(['status'=>'failed','message'=>'Name is already exists!','code'=> 500], 500); |
||||
die; |
||||
} |
||||
|
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
if(!ProjectExpenditure::create($data)) |
||||
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500); |
||||
|
||||
return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200); |
||||
} |
||||
|
||||
public function edit($id){ |
||||
if(!$id || (int) $id < 0 || $id=="") |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
|
||||
if(!$result = ProjectExpenditure::find($id)) |
||||
return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404); |
||||
|
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if(!$id || (int) $id < 0 || $id=="") |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
|
||||
if(!$data = ProjectExpenditure::find($id)) |
||||
return response()->json(['status'=>'failed','message'=>'data project expenditure not found!','code'=>400], 400); |
||||
|
||||
if(!$data->update($request->all())) |
||||
return response()->json(['status'=>'failed','message'=>'data project expenditure failed updated!','code'=>400], 400); |
||||
|
||||
return response()->json(['status'=>'success','message'=>'Data berhasil disimpan!','code'=>200], 200); |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
|
||||
if(!$data = ProjectExpenditure::find($id)) |
||||
return response()->json(['status'=>'failed','message'=>'data project expenditure not found!','code'=>400], 400); |
||||
|
||||
if(!$data->delete()) |
||||
return response()->json(['status'=>'failed','message'=>'Data gagal dihapus!','code'=> 500], 500); |
||||
|
||||
return response()->json(['status'=>'success','message'=>'Data berhasil dihapus!','code'=>200], 200); |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_proyek_expenditure'); |
||||
$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 list() |
||||
{ |
||||
$data = ProjectExpenditure::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if(!$data) |
||||
return response()->json(['status'=>'failed','message'=>'failed get list project expenditure, please try again later!','code'=>400], 400); |
||||
|
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,93 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\ProjectFinancialHealth; |
||||
|
||||
class ProjectFinancialHealthController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'name' => 'required' |
||||
]); |
||||
$data = $request->all(); |
||||
// Set Unique |
||||
$result = ProjectFinancialHealth::query() |
||||
->where([ |
||||
['company_id',$data['company_id']], |
||||
['name', $data['name']] |
||||
])->first(); |
||||
if($result) { |
||||
return response()->json(['status'=>'failed','message'=>'Name is already exists!','code'=> 500], 500); |
||||
die; |
||||
} |
||||
|
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
if(!ProjectFinancialHealth::create($data)) |
||||
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500); |
||||
|
||||
return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200); |
||||
} |
||||
|
||||
public function edit($id){ |
||||
if(!$id || (int) $id < 0 || $id=="") |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
|
||||
if(!$result = ProjectFinancialHealth::find($id)) |
||||
return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404); |
||||
|
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if(!$id || (int) $id < 0 || $id=="") |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
|
||||
if(!$data = ProjectFinancialHealth::find($id)) |
||||
return response()->json(['status'=>'failed','message'=>'data financial health not found!','code'=>400], 400); |
||||
|
||||
if(!$data->update($request->all())) |
||||
return response()->json(['status'=>'failed','message'=>'Data financial health failed updated!','code'=>400], 400); |
||||
|
||||
return response()->json(['status'=>'success','message'=>'Data berhasil disimpan!','code'=>200], 200); |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
|
||||
if(!$data = ProjectFinancialHealth::find($id)) |
||||
return response()->json(['status'=>'failed','message'=>'data financial health not found!','code'=>400], 400); |
||||
|
||||
if(!$data->delete()) |
||||
return response()->json(['status'=>'failed','message'=>'Data gagal dihapus!','code'=> 500], 500); |
||||
|
||||
return response()->json(['status'=>'success','message'=>'Data berhasil dihapus!','code'=>200], 200); |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_proyek_financial_health'); |
||||
$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 list() |
||||
{ |
||||
$data = ProjectFinancialHealth::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if(!$data) |
||||
return response()->json(['status'=>'failed','message'=>'failed get list financial health, please try again later!','code'=>400], 400); |
||||
|
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,93 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\ProjectInvoice; |
||||
|
||||
class ProjectInvoiceController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'name' => 'required' |
||||
]); |
||||
$data = $request->all(); |
||||
// Set Unique |
||||
$result = ProjectInvoice::query() |
||||
->where([ |
||||
['company_id',$data['company_id']], |
||||
['name', $data['name']] |
||||
])->first(); |
||||
if($result) { |
||||
return response()->json(['status'=>'failed','message'=>'Name is already exists!','code'=> 500], 500); |
||||
die; |
||||
} |
||||
|
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
if(!ProjectInvoice::create($data)) |
||||
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500); |
||||
|
||||
return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200); |
||||
} |
||||
|
||||
public function edit($id){ |
||||
if(!$id || (int) $id < 0 || $id=="") |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
|
||||
if(!$result = ProjectInvoice::find($id)) |
||||
return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404); |
||||
|
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if(!$id || (int) $id < 0 || $id=="") |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
|
||||
if(!$data = ProjectInvoice::find($id)) |
||||
return response()->json(['status'=>'failed','message'=>'data project invoice not found!','code'=>400], 400); |
||||
|
||||
if(!$data->update($request->all())) |
||||
return response()->json(['status'=>'failed','message'=>'data project invoice failed updated!','code'=>400], 400); |
||||
|
||||
return response()->json(['status'=>'success','message'=>'Data berhasil disimpan!','code'=>200], 200); |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
|
||||
if(!$data = ProjectInvoice::find($id)) |
||||
return response()->json(['status'=>'failed','message'=>'data project invoice not found!','code'=>400], 400); |
||||
|
||||
if(!$data->delete()) |
||||
return response()->json(['status'=>'failed','message'=>'Data gagal dihapus!','code'=> 500], 500); |
||||
|
||||
return response()->json(['status'=>'success','message'=>'Data berhasil dihapus!','code'=>200], 200); |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_proyek_invoice'); |
||||
$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 list() |
||||
{ |
||||
$data = ProjectInvoice::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if(!$data) |
||||
return response()->json(['status'=>'failed','message'=>'failed get list project invoice, please try again later!','code'=>400], 400); |
||||
|
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||
|
||||
} |
||||
} |
@ -1,120 +1,121 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\ProjectRole; |
||||
|
||||
class ProjectRoleController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'name' => 'required', |
||||
'description' => 'required' |
||||
]); |
||||
|
||||
$data = $request->all(); |
||||
|
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = ProjectRole::create($data); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'add data project role successfully!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'add data project role failed!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function edit($id){ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = ProjectRole::find($id); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get data project role, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
} |
||||
|
||||
$data = ProjectRole::find($id); |
||||
|
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data project role not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'data project role successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data project role failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = ProjectRole::find($id); |
||||
|
||||
if($data){ |
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data project role not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success','message'=>'data project role successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data project role failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_role_proyek'); |
||||
$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 list() |
||||
{ |
||||
$data = ProjectRole::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if($data){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get list project role, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function select(Request $request){ |
||||
$search = $request->query('search'); |
||||
if($search && !empty($search)){ |
||||
$data = ProjectRole::where("name", 'like', '%'.$search.'%')->get(); |
||||
}else{ |
||||
$data = ProjectRole::all(); |
||||
} |
||||
|
||||
return response()->json($data); |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\ProjectRole; |
||||
|
||||
class ProjectRoleController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'name' => 'required', |
||||
'description' => 'required', |
||||
'company_id' => 'required' |
||||
]); |
||||
|
||||
$data = $request->all(); |
||||
|
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = ProjectRole::create($data); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'add data project role successfully!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'add data project role failed!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function edit($id){ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = ProjectRole::find($id); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get data project role, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
} |
||||
|
||||
$data = ProjectRole::find($id); |
||||
|
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data project role not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'data project role successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data project role failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = ProjectRole::find($id); |
||||
|
||||
if($data){ |
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data project role not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success','message'=>'data project role successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data project role failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_role_proyek'); |
||||
$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 list() |
||||
{ |
||||
$data = ProjectRole::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if($data){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get list project role, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function select(Request $request){ |
||||
$search = $request->query('search'); |
||||
if($search && !empty($search)){ |
||||
$data = ProjectRole::where("name", 'like', '%'.$search.'%')->get(); |
||||
}else{ |
||||
$data = ProjectRole::all(); |
||||
} |
||||
|
||||
return response()->json($data); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,93 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\ProjectScheduleHealth; |
||||
|
||||
class ProjectScheduleHealthController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'name' => 'required' |
||||
]); |
||||
$data = $request->all(); |
||||
// Set Unique |
||||
$result = ProjectScheduleHealth::query() |
||||
->where([ |
||||
['company_id',$data['company_id']], |
||||
['name', $data['name']] |
||||
])->first(); |
||||
if($result) { |
||||
return response()->json(['status'=>'failed','message'=>'Name is already exists!','code'=> 500], 500); |
||||
die; |
||||
} |
||||
|
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
if(!ProjectScheduleHealth::create($data)) |
||||
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500); |
||||
|
||||
return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200); |
||||
} |
||||
|
||||
public function edit($id){ |
||||
if(!$id || (int) $id < 0 || $id=="") |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
|
||||
if(!$result = ProjectScheduleHealth::find($id)) |
||||
return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404); |
||||
|
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if(!$id || (int) $id < 0 || $id=="") |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
|
||||
if(!$data = ProjectScheduleHealth::find($id)) |
||||
return response()->json(['status'=>'failed','message'=>'data schedule health not found!','code'=>400], 400); |
||||
|
||||
if(!$data->update($request->all())) |
||||
return response()->json(['status'=>'failed','message'=>'data schedule health failed updated!','code'=>400], 400); |
||||
|
||||
return response()->json(['status'=>'success','message'=>'Data berhasil disimpan!','code'=>200], 200); |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
|
||||
if(!$data = ProjectScheduleHealth::find($id)) |
||||
return response()->json(['status'=>'failed','message'=>'data schedule health not found!','code'=>400], 400); |
||||
|
||||
if(!$data->delete()) |
||||
return response()->json(['status'=>'failed','message'=>'Data gagal dihapus!','code'=> 500], 500); |
||||
|
||||
return response()->json(['status'=>'success','message'=>'Data berhasil dihapus!','code'=>200], 200); |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_proyek_schedule_health'); |
||||
$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 list() |
||||
{ |
||||
$data = ProjectScheduleHealth::all(); |
||||
$countData = $data->count(); |
||||
|
||||
if(!$data) |
||||
return response()->json(['status'=>'failed','message'=>'failed get list schedule health, please try again later!','code'=>400], 400); |
||||
|
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,81 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use App\Models\RefferalCode; |
||||
use Illuminate\Http\Request; |
||||
|
||||
class RefferalCodeController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'code' => 'required|unique:refferal_code,code', |
||||
'exp' => 'nullable', |
||||
'type' => 'nullable', |
||||
'allocation' => 'nullable' |
||||
]); |
||||
|
||||
$data = $request->all(); |
||||
|
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = RefferalCode::create($data); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success', 'data'=> $result, 'message'=>'Add refferal code successfully!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Add refferal Code failed!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function edit($id) |
||||
{ |
||||
if (!$id || (int) $id < 0 || $id == "") { |
||||
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400); |
||||
die(); |
||||
} |
||||
|
||||
$result = RefferalCode::find($id); |
||||
|
||||
if ($result) { |
||||
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); |
||||
} else { |
||||
return response()->json(['status' => 'failed', 'message' => 'Failed get refferal code, please try again later!', 'code' => 400], 400); |
||||
} |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
||||
} |
||||
|
||||
$data = RefferalCode::find($id); |
||||
|
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Refferal code not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'Refferal code successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Refferal code failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'refferal_code'); |
||||
$builder = $dataBuilder['builder']; |
||||
$countBuilder = $dataBuilder['count']; |
||||
$dataGet = $builder->get(); |
||||
$totalRecord = $countBuilder->count(); |
||||
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); |
||||
} |
||||
} |
@ -0,0 +1,344 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Carbon\Carbon; |
||||
use Illuminate\Support\Str; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\{DB,Log}; |
||||
use App\Models\{User, Company, HumanResource, Menu, ProductTransaction, RefferalCode, Role, RoleMenu, MenuCompany}; |
||||
|
||||
const URL_EMAIL = 'https://notifapp.odm-iu.com/service-mail/notif_mail.php'; |
||||
class UserRegisterController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
DB::beginTransaction(); |
||||
$this->validate($request, [ |
||||
'cluster' => 'required|string', |
||||
'address' => 'required|string', |
||||
'email' => 'required|string', |
||||
'type_paket' => ($request->type_account === 'Personal' ? 'required' : 'nullable') . '|in:Basic,Free', |
||||
'phone_no' => 'required', |
||||
'type_account' => 'string|in:Personal,Company', |
||||
'company_name' => 'required|string', |
||||
'username' => 'required|string' |
||||
]); |
||||
try { |
||||
$data = $request->all(); |
||||
|
||||
$company_name = $data['company_name']; |
||||
$type_account = $data['type_account']; |
||||
$refferal = $request->refferal ? $data['refferal'] : null; |
||||
$cluster = $data['cluster']; |
||||
$address = $data['address']; |
||||
$phone_no = $data['phone_no']; |
||||
$email = $data['email']; |
||||
$username = $data['username']; |
||||
$type_paket = $data['type_paket']; |
||||
$company_address = $request->type_account === 'Company' ? $data['companyAddress'] : ''; |
||||
$full_name = $request->type_account === 'Personal' ? $data['full_name'] : ''; |
||||
|
||||
// check email & username already exist |
||||
$emailExists = Company::where('email', $email)->exists() || User::where('email', $email)->exists(); |
||||
if ($emailExists) { |
||||
return response()->json(['status' => 'failed', 'message' => 'Email already exists, please check again!', 'code' => 500], 500); |
||||
} |
||||
$usernameExists = User::where('username', $username)->exists(); |
||||
if ($usernameExists) { |
||||
return response()->json(['status' => 'failed', 'message' => 'Username already exists, please check again!', 'code' => 500], 500); |
||||
} |
||||
|
||||
// Get last registration number |
||||
$getCompany = $this->getCompany(); |
||||
|
||||
$formDataCompany = array( |
||||
'company_name' => $company_name, |
||||
'newRegistrationNumber' => $getCompany['newRegistrationNumber'], |
||||
'cluster' => $cluster, |
||||
'phone_no' => $phone_no, |
||||
'email' => $email, |
||||
'address' => $address, |
||||
'type_account' => $type_account, |
||||
'username' => $username, |
||||
'type_paket' => $type_paket, |
||||
'companyAddress' => $company_address, |
||||
'full_name' => $full_name |
||||
); |
||||
|
||||
if(empty($refferal)) { |
||||
$addCompany = $this->addCompany($formDataCompany, null); |
||||
} else { |
||||
$getRefferal = $this->getRefferalCode($refferal); |
||||
if(empty($getRefferal)) { |
||||
return response()->json(['status' => 'failed', 'message' => 'Refferal code not found!', 'code' => 404], 404); |
||||
} |
||||
$addCompany = $this->addCompany($formDataCompany, (int)$getRefferal['id']); |
||||
} |
||||
|
||||
if(empty($addCompany)) { |
||||
return; |
||||
} |
||||
|
||||
$addRole = $this->addRole((int)$addCompany['id']); |
||||
if(empty($addRole)) { |
||||
return; |
||||
} |
||||
|
||||
$addHR = $this->addHR((int)$addCompany['id'], (int)$addRole['id'], $formDataCompany); |
||||
if(empty($addHR)) { |
||||
return; |
||||
} |
||||
|
||||
$getMenu = $this->getMenu(); |
||||
if(empty($getMenu)) { |
||||
return; |
||||
} |
||||
$this->addTransaction((int)$addCompany['id'], $formDataCompany); |
||||
|
||||
$addMenuCompany = $this->addMenuCompany($getMenu, (int)$addCompany['id']); |
||||
if(empty($addMenuCompany)) { |
||||
return; |
||||
} |
||||
$addMenuRole = $this->addMenuRole($getMenu, (int)$addRole['id']); |
||||
if(empty($addMenuRole)) { |
||||
return; |
||||
} |
||||
DB::commit(); |
||||
return response()->json(['status' => 'success', 'message' => 'Register is successful, please check your email!', 'generateRandom' => $addHR['generateRandom'], 'code' => 200], 200); |
||||
} catch (\Throwable $th) { |
||||
DB::rollBack(); |
||||
Log::channel('daily')->error($th->getMessage()); |
||||
return response()->json(['status' => 'failed', 'message' => 'Failed to register, please check again!', 'code' => 500], 500); |
||||
} |
||||
} |
||||
|
||||
protected function getRefferalCode($refferal) |
||||
{ |
||||
$result = RefferalCode::query() |
||||
->select('id','code','amount','exp','type','allocation','description') |
||||
->where('code', $refferal) |
||||
->first(); |
||||
return $result; |
||||
} |
||||
|
||||
protected function addCompany($formData, $id_refferal) |
||||
{ |
||||
$formData = array( |
||||
'company_name' => $formData['company_name'], |
||||
'registration_no' => $formData['newRegistrationNumber'], |
||||
'cluster' => $formData['cluster'], |
||||
'date_register' => Carbon::now(), |
||||
'template_id' => 1, |
||||
'email' => $formData['email'], |
||||
'address' => $formData['type_account'] === 'Company' ? $formData['companyAddress'] : $formData['address'], |
||||
'phone_no' => $formData['phone_no'], |
||||
'type_account' => $formData['type_account'], |
||||
'is_active' => true, |
||||
'discount_id' => $id_refferal === null ? null : $id_refferal |
||||
); |
||||
$result = Company::create($formData); |
||||
return $result; |
||||
} |
||||
|
||||
protected function addRole($id_company) |
||||
{ |
||||
$formData = [ |
||||
'name' => 'Admin', |
||||
'company_id' => $id_company, |
||||
'description' => '-' |
||||
]; |
||||
$result = Role::create($formData); |
||||
return $result; |
||||
} |
||||
|
||||
protected function addHR($id_company, $id_role, $data) |
||||
{ |
||||
$generateRandom = Str::random(8); |
||||
$formData = array( |
||||
'name'=> $data['type_account'] === 'Company' ? $data['username'] : $data['full_name'], |
||||
'phone_number'=> $data['phone_no'], |
||||
'email'=> $data['email'], |
||||
'username' => $data['username'], |
||||
'password'=> md5($generateRandom), |
||||
'role_id'=> $id_role, |
||||
'ktp_number'=> $data['type_account'] === 'Company' ? 'CP-'. $generateRandom : 'PR-' . $generateRandom, |
||||
'employee_type'=> 'employee', |
||||
'address' => $data['address'], |
||||
'status_resource'=> 'active', |
||||
'company_id'=> $id_company |
||||
); |
||||
$result = HumanResource::create($formData); |
||||
if(!empty($result)) { |
||||
$this->sendEmail($data['email'], $generateRandom); |
||||
} |
||||
return [ |
||||
'result' => $result, |
||||
'generateRandom' => $generateRandom |
||||
]; |
||||
} |
||||
|
||||
protected function addMenuCompany($baseDataMenu, $id_company) |
||||
{ |
||||
$data = MenuCompany::where('company_id', $id_company); |
||||
if($data->exists()){ |
||||
$data->delete(); |
||||
} |
||||
if (is_object($baseDataMenu) && count($baseDataMenu) > 0 && isset($baseDataMenu)) { |
||||
$countRes = 0; |
||||
foreach ($baseDataMenu as $menu) { |
||||
$dataInsert = array( |
||||
"menu_id" => $menu['id'], |
||||
"parent_menu_id" => $menu['parent_id'], |
||||
"company_id" => $id_company, |
||||
"icon" => $menu['icon'], |
||||
"alias_name" => $menu['alias_name'], |
||||
"url" => $menu['url'], |
||||
"sequence" => $menu['sequence'], |
||||
"created_by" => $this->currentName |
||||
); |
||||
$result = MenuCompany::create($dataInsert); |
||||
if ($result) { |
||||
$countRes++; |
||||
} else { |
||||
$countRes--; |
||||
} |
||||
} |
||||
if ($countRes > 0) { |
||||
return $result; |
||||
} else { |
||||
die(); |
||||
} |
||||
} else { |
||||
die(); |
||||
} |
||||
} |
||||
|
||||
protected function addMenuRole($baseDataMenu, $id_role) |
||||
{ |
||||
if (is_object($baseDataMenu) && count($baseDataMenu) > 0 && isset($baseDataMenu)) { |
||||
$countRes = 0; |
||||
foreach ($baseDataMenu as $menu) { |
||||
$dataInsert = array( |
||||
"menu_id" => $menu['id'], |
||||
"role_id" => $id_role, |
||||
); |
||||
$result = RoleMenu::create($dataInsert); |
||||
if ($result) { |
||||
$countRes++; |
||||
} else { |
||||
$countRes--; |
||||
} |
||||
} |
||||
if ($countRes > 0) { |
||||
return $result; |
||||
} else { |
||||
die(); |
||||
} |
||||
} else { |
||||
die(); |
||||
} |
||||
} |
||||
|
||||
protected function addTransaction($id_company, $data) |
||||
{ |
||||
$currentDate = Carbon::now(); |
||||
$finalDate = $currentDate->copy()->addDays(30); |
||||
if(is_array($data)) { |
||||
$formData = array( |
||||
'company_id' => $id_company, |
||||
'type_paket' => $data['type_paket'], |
||||
'exp_ospro' => $finalDate, |
||||
'amount' => $data['type_paket'] === 'Free' ? 0 : 250000 |
||||
); |
||||
$result = ProductTransaction::create($formData); |
||||
return $result; |
||||
} |
||||
} |
||||
|
||||
protected function getMenu() |
||||
{ |
||||
$result = Menu::query() |
||||
->select("id", "name", "parent_id", "alias_name", "icon", "url", "sequence") |
||||
->whereNotIn('alias_name', ['Dashboard Customer', 'Registration Management', 'Demo Management']) |
||||
->get(); |
||||
return $result; |
||||
} |
||||
|
||||
protected function getCompany() |
||||
{ |
||||
$newRegistrationNumber = ''; |
||||
$company = Company::query() |
||||
->select('id','type_account','registration_no','discount_id') |
||||
->orderByDesc('id') |
||||
->first(); |
||||
|
||||
if(!empty($company)) { |
||||
$lastRegistrationNumber = $company['registration_no']; |
||||
$lastNumber = (int)preg_replace('/\D/', '', $lastRegistrationNumber); |
||||
$newNumber = $lastNumber + 1; |
||||
$newRegistrationNumber = 'RG-'. $newNumber; |
||||
} else{ |
||||
return false; |
||||
} |
||||
return [ |
||||
'newRegistrationNumber' => $newRegistrationNumber |
||||
]; |
||||
} |
||||
|
||||
public function sendEmail($email, $password) |
||||
{ |
||||
$user = User::select('email', 'name', 'username')->where('email', $email)->first(); |
||||
if (!$user) { |
||||
return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400); |
||||
} else { |
||||
$this->reqHttpCurl($email, $password, $user->username, $user->name); |
||||
return response()->json(['status' => 'error', 'code'=>400, 'message' => 'e-mail not found '], 400); |
||||
} |
||||
} |
||||
|
||||
private function reqHttpCurl($email, $password, $username, $name) |
||||
{ |
||||
$postData = [ |
||||
"to" => $email, |
||||
"name" => $name, |
||||
"username" => $username, |
||||
"password" => $password, |
||||
"from" => "app.integrasia@integrasiautama.com", |
||||
"alias_from" => "OSPRO", |
||||
"subject" => "Registration OSPRO", |
||||
"body" => "registration-ospro" |
||||
]; |
||||
|
||||
$curl = curl_init(); |
||||
|
||||
curl_setopt_array($curl, array( |
||||
CURLOPT_URL => URL_EMAIL, |
||||
CURLOPT_RETURNTRANSFER => true, |
||||
CURLOPT_ENCODING => "", |
||||
CURLOPT_MAXREDIRS => 10, |
||||
CURLOPT_TIMEOUT => 30000, |
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
||||
CURLOPT_CUSTOMREQUEST => "POST", |
||||
CURLOPT_POSTFIELDS => json_encode($postData), |
||||
CURLOPT_HTTPHEADER => array( |
||||
// Set here requred headers |
||||
"accept: */*", |
||||
"accept-language: en-US,en;q=0.8", |
||||
"content-type: application/json", |
||||
), |
||||
)); |
||||
|
||||
$response = curl_exec($curl); |
||||
$err = curl_error($curl); |
||||
|
||||
curl_close($curl); |
||||
|
||||
if ($err) { |
||||
echo "cURL Error #:" . $err; |
||||
} else { |
||||
print_r(json_decode($response)); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,27 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class ContactSales extends Model |
||||
{ |
||||
protected $table = 'm_contact_sales'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', |
||||
'company_name', |
||||
'email', |
||||
'role', |
||||
'number_phone', |
||||
'status', |
||||
'message', |
||||
'created_at', |
||||
'created_by', |
||||
'updated_at', |
||||
'updated_by', |
||||
]; |
||||
} |
@ -0,0 +1,26 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class Demo extends Model |
||||
{ |
||||
protected $table = 'm_demo'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', |
||||
'email', |
||||
'role', |
||||
'number_phone', |
||||
'status', |
||||
'message', |
||||
'created_at', |
||||
'created_by', |
||||
'updated_at', |
||||
'updated_by', |
||||
]; |
||||
} |
@ -0,0 +1,17 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class KanbanBoard extends Model |
||||
{ |
||||
protected $table = 'kanban_board'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name_board', 'header_color', 'body_color', 'status_progress', 'proyek_id', 'version_gantt_id', 'created_at', 'created_by', 'updated_at', 'updated_by' |
||||
]; |
||||
} |
@ -0,0 +1,17 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class KanbanCard extends Model |
||||
{ |
||||
protected $table = 'kanban_card'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'activity_id', 'kanban_board_id', 'version_gantt_id', 'created_at', 'created_by', 'updated_at', 'updated_by' |
||||
]; |
||||
} |
@ -0,0 +1,25 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class ProductTransaction extends Model |
||||
{ |
||||
protected $table = 't_transaction'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'company_id', |
||||
'type_paket', |
||||
'amount', |
||||
'exp_ospro', |
||||
'pay_date', |
||||
'created_at', |
||||
'updated_at', |
||||
'created_by', |
||||
'updated_by' |
||||
]; |
||||
} |
@ -0,0 +1,17 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class ProjectExpenditure extends Model |
||||
{ |
||||
protected $table = 'm_proyek_expenditure'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', 'color', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' |
||||
]; |
||||
} |
@ -0,0 +1,17 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class ProjectFinancialHealth extends Model |
||||
{ |
||||
protected $table = 'm_proyek_financial_health'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', 'color', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' |
||||
]; |
||||
} |
@ -0,0 +1,17 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class ProjectInvoice extends Model |
||||
{ |
||||
protected $table = 'm_proyek_invoice'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', 'color', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' |
||||
]; |
||||
} |
@ -1,17 +1,17 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class ProjectRole extends Model |
||||
{ |
||||
protected $table = 'm_role_proyek'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' |
||||
]; |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class ProjectRole extends Model |
||||
{ |
||||
protected $table = 'm_role_proyek'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', 'description', 'created_at', 'created_by', 'updated_at', 'company_id', 'updated_by' |
||||
]; |
||||
} |
||||
|
@ -0,0 +1,17 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class ProjectScheduleHealth extends Model |
||||
{ |
||||
protected $table = 'm_proyek_schedule_health'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', 'color', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' |
||||
]; |
||||
} |
@ -1,17 +1,17 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class ProjectType extends Model |
||||
{ |
||||
protected $table = 'm_type_proyek'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' |
||||
]; |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class ProjectType extends Model |
||||
{ |
||||
protected $table = 'm_type_proyek'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id', 'is_multiLocation' |
||||
]; |
||||
} |
||||
|
@ -0,0 +1,28 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class RefferalCode extends Model |
||||
{ |
||||
protected $table = 'refferal_code'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'code', |
||||
'amount', |
||||
'exp', |
||||
'type', |
||||
'allocation', |
||||
'description', |
||||
'created_at', |
||||
'created_by', |
||||
'updated_at', |
||||
'updated_by', |
||||
'deleted_at', |
||||
'deleted_by' |
||||
]; |
||||
} |
@ -1,17 +1,17 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class Satuan extends Model |
||||
{ |
||||
protected $table = 'm_satuan'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' |
||||
]; |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class Satuan extends Model |
||||
{ |
||||
protected $table = 'm_satuan'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' |
||||
]; |
||||
} |
||||
|
@ -1,203 +1,198 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject; |
||||
use Illuminate\Auth\Authenticatable; |
||||
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
use Laravel\Lumen\Auth\Authorizable; |
||||
use Carbon\Carbon; |
||||
|
||||
class User extends Model implements AuthenticatableContract, AuthorizableContract,JWTSubject |
||||
{ |
||||
use Authenticatable, Authorizable, HasFactory; |
||||
|
||||
protected $table = 'm_users'; |
||||
/** |
||||
* The attributes that are mass assignable. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $fillable = [ |
||||
'name', 'email', 'role_id', 'username', 'session_login', 'phone_number', 'email', 'address', |
||||
'fcm_token', 'gender', 'birth_place', 'birth_date', 'blood_type', 'ktp_number', 'working_hours', |
||||
'created_at', 'created_by', 'updated_at', 'updated_by', 'status_resource' |
||||
]; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
const DEFAULT_TZ = 'Asia/Jakarta'; |
||||
const INSIDE = "INSIDE"; |
||||
const OUTSIDE = "OUTSIDE"; |
||||
const HOLIDAY = "HOLIDAY"; |
||||
|
||||
/** |
||||
* The attributes excluded from the model's JSON form. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $hidden = [ |
||||
'password', |
||||
]; |
||||
|
||||
/** |
||||
* Get the identifier that will be stored in the subject claim of the JWT. |
||||
* |
||||
* @return mixed |
||||
*/ |
||||
public function getJWTIdentifier() |
||||
{ |
||||
return $this->getKey(); |
||||
} |
||||
|
||||
/** |
||||
* Return a key value array, containing any custom claims to be added to the JWT. |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function getJWTCustomClaims() |
||||
{ |
||||
return []; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get working hours for given timestamp |
||||
* |
||||
* @return array of carbon or NULL in case HOLIDAY |
||||
*/ |
||||
|
||||
public function getWorkingTime(Carbon $ts, $f = "08:00", $t = "17:00", $tz = self::DEFAULT_TZ) |
||||
{ |
||||
$workingTime = array( |
||||
"from"=> Carbon::createFromTimeString($f, $tz), |
||||
"to"=> Carbon::createFromTimeString($t, $tz) |
||||
); |
||||
|
||||
$userShift = UserShift::where('user_id', ) |
||||
->orderByDesc('from_date') |
||||
->first(); |
||||
|
||||
$shift = null; |
||||
if ($userShift !== null) |
||||
{ |
||||
$shiftId = null; |
||||
switch ($ts->shortEnglishDayOfWeek) |
||||
{ |
||||
case "Mon": |
||||
$shiftId = $userShift->mon_shift_id; |
||||
break; |
||||
case "Tue": |
||||
$shiftId = $userShift->tue_shift_id; |
||||
break; |
||||
case "Wed": |
||||
$shiftId = $userShift->wed_shift_id; |
||||
break; |
||||
case "Thu": |
||||
$shiftId = $userShift->thu_shift_id; |
||||
break; |
||||
case "Fri": |
||||
$shiftId = $userShift->fri_shift_id; |
||||
break; |
||||
case "Sat": |
||||
$shiftId = $userShift->sat_shift_id; |
||||
break; |
||||
case "Sun": |
||||
$shiftId = $userShift->sun_shift_id; |
||||
break; |
||||
} |
||||
|
||||
if ($shiftId === null) { |
||||
return null; |
||||
} |
||||
|
||||
$shift = Shift::where('id', $shiftId)->first(); |
||||
} else { |
||||
$shift = Shift::where('is_non_shift', true) |
||||
->orderByDesc('created_at') |
||||
->first(); |
||||
} |
||||
|
||||
|
||||
if ($shift !== null) |
||||
{ |
||||
$from = Carbon::createFromTimeString($shift->start_time, $tz) |
||||
->subMinutes($shift->flex_time_minute); |
||||
$to = Carbon::createFromTimeString($shift->end_time, $tz) |
||||
->addMinutes($shift->flex_time_minute); |
||||
|
||||
/* |
||||
if ($to->lessThan($from)) |
||||
{ |
||||
$to->addDay(); |
||||
} |
||||
*/ |
||||
$workingTime['from'] = $from; |
||||
$workingTime['to'] = $to; |
||||
} |
||||
|
||||
return $workingTime; |
||||
} |
||||
|
||||
/** |
||||
* Get presence status |
||||
*/ |
||||
public function presenceStatus(Carbon $at = null, $tz = self::DEFAULT_TZ) |
||||
{ |
||||
|
||||
$ts = $at; |
||||
if ($at !== null) |
||||
{ |
||||
$ts = Carbon::now($tz); |
||||
} |
||||
$tsSec = $ts->secondsSinceMidnight(); |
||||
|
||||
$status = ""; |
||||
$wt = $this->getWorkingTime($ts, $tz); |
||||
if ($wt === null) |
||||
{ |
||||
$status = self::HOLIDAY; |
||||
} else { |
||||
$from = $wt->from; |
||||
$to = $wt->to; |
||||
$tsFrom = $from->secondsSinceMidnight(); |
||||
$tsTo = $to->secondsSinceMidnight(); |
||||
|
||||
if ($from->greaterThan($to)) { |
||||
$tsMid = 24*60*60 - $tsFrom; |
||||
if ($tsSec >= $tsFrom || $tsSec < $tsTo) { |
||||
$status = self::INSIDE; |
||||
} else { |
||||
$status = self::OUTSIDE; |
||||
} |
||||
} else { |
||||
if ($tsSec < $tsFrom || $tsSec > $tsTo) { |
||||
$status = self::OUTSIDE; |
||||
} else { |
||||
$status = self::INSIDE; |
||||
} |
||||
} |
||||
} |
||||
|
||||
$clockIn = null; |
||||
$clockOut = null; |
||||
$inout = Presence::where('user_id', $this->id) |
||||
->orderByDesc('clock_in') |
||||
->first(); |
||||
if ($inout !== null) { |
||||
$clockIn = Carbon::parse($inout->clock_in, $tz); |
||||
$clockOut = Carbon::parse($inout->clock_out, $tz); |
||||
} |
||||
|
||||
return array( |
||||
"status"=>$status, |
||||
"ts" => $ts, |
||||
"clock_in" => $clockIn, |
||||
"clock_out" => $clockOut |
||||
); |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject; |
||||
use Illuminate\Auth\Authenticatable; |
||||
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
use Laravel\Lumen\Auth\Authorizable; |
||||
use Carbon\Carbon; |
||||
|
||||
class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject |
||||
{ |
||||
use Authenticatable, Authorizable, HasFactory; |
||||
|
||||
protected $table = 'm_users'; |
||||
/** |
||||
* The attributes that are mass assignable. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $fillable = [ |
||||
'name', 'email', 'role_id', 'username', 'session_login', 'phone_number', 'email', 'address', |
||||
'fcm_token', 'gender', 'birth_place', 'birth_date', 'blood_type', 'ktp_number', 'working_hours', |
||||
'created_at', 'created_by', 'updated_at', 'updated_by', 'status_resource', 'discount_id','company_id','is_customer' |
||||
]; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
const DEFAULT_TZ = 'Asia/Jakarta'; |
||||
const INSIDE = "INSIDE"; |
||||
const OUTSIDE = "OUTSIDE"; |
||||
const HOLIDAY = "HOLIDAY"; |
||||
|
||||
/** |
||||
* The attributes excluded from the model's JSON form. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $hidden = [ |
||||
'password', |
||||
]; |
||||
|
||||
/** |
||||
* Get the identifier that will be stored in the subject claim of the JWT. |
||||
* |
||||
* @return mixed |
||||
*/ |
||||
public function getJWTIdentifier() |
||||
{ |
||||
return $this->getKey(); |
||||
} |
||||
|
||||
/** |
||||
* Return a key value array, containing any custom claims to be added to the JWT. |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function getJWTCustomClaims() |
||||
{ |
||||
return []; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get working hours for given timestamp |
||||
* |
||||
* @return array of carbon or NULL in case HOLIDAY |
||||
*/ |
||||
|
||||
public function getWorkingTime(Carbon $ts, $f = "08:00", $t = "17:00", $tz = self::DEFAULT_TZ) |
||||
{ |
||||
$workingTime = array( |
||||
"from" => Carbon::createFromTimeString($f, $tz), |
||||
"to" => Carbon::createFromTimeString($t, $tz) |
||||
); |
||||
|
||||
$userShift = UserShift::where('user_id',) |
||||
->orderByDesc('from_date') |
||||
->first(); |
||||
|
||||
$shift = null; |
||||
if ($userShift !== null) { |
||||
$shiftId = null; |
||||
switch ($ts->shortEnglishDayOfWeek) { |
||||
case "Mon": |
||||
$shiftId = $userShift->mon_shift_id; |
||||
break; |
||||
case "Tue": |
||||
$shiftId = $userShift->tue_shift_id; |
||||
break; |
||||
case "Wed": |
||||
$shiftId = $userShift->wed_shift_id; |
||||
break; |
||||
case "Thu": |
||||
$shiftId = $userShift->thu_shift_id; |
||||
break; |
||||
case "Fri": |
||||
$shiftId = $userShift->fri_shift_id; |
||||
break; |
||||
case "Sat": |
||||
$shiftId = $userShift->sat_shift_id; |
||||
break; |
||||
case "Sun": |
||||
$shiftId = $userShift->sun_shift_id; |
||||
break; |
||||
} |
||||
|
||||
if ($shiftId === null) { |
||||
return null; |
||||
} |
||||
|
||||
$shift = Shift::where('id', $shiftId)->first(); |
||||
} else { |
||||
$shift = Shift::where('is_non_shift', true) |
||||
->orderByDesc('created_at') |
||||
->first(); |
||||
} |
||||
|
||||
|
||||
if ($shift !== null) { |
||||
$from = Carbon::createFromTimeString($shift->start_time, $tz) |
||||
->subMinutes($shift->flex_time_minute); |
||||
$to = Carbon::createFromTimeString($shift->end_time, $tz) |
||||
->addMinutes($shift->flex_time_minute); |
||||
|
||||
/* |
||||
if ($to->lessThan($from)) |
||||
{ |
||||
$to->addDay(); |
||||
} |
||||
*/ |
||||
$workingTime['from'] = $from; |
||||
$workingTime['to'] = $to; |
||||
} |
||||
|
||||
return $workingTime; |
||||
} |
||||
|
||||
/** |
||||
* Get presence status |
||||
*/ |
||||
public function presenceStatus(Carbon $at = null, $tz = self::DEFAULT_TZ) |
||||
{ |
||||
|
||||
$ts = $at; |
||||
if ($at !== null) { |
||||
$ts = Carbon::now($tz); |
||||
} |
||||
$tsSec = $ts->secondsSinceMidnight(); |
||||
|
||||
$status = ""; |
||||
$wt = $this->getWorkingTime($ts, $tz); |
||||
if ($wt === null) { |
||||
$status = self::HOLIDAY; |
||||
} else { |
||||
$from = $wt->from; |
||||
$to = $wt->to; |
||||
$tsFrom = $from->secondsSinceMidnight(); |
||||
$tsTo = $to->secondsSinceMidnight(); |
||||
|
||||
if ($from->greaterThan($to)) { |
||||
$tsMid = 24 * 60 * 60 - $tsFrom; |
||||
if ($tsSec >= $tsFrom || $tsSec < $tsTo) { |
||||
$status = self::INSIDE; |
||||
} else { |
||||
$status = self::OUTSIDE; |
||||
} |
||||
} else { |
||||
if ($tsSec < $tsFrom || $tsSec > $tsTo) { |
||||
$status = self::OUTSIDE; |
||||
} else { |
||||
$status = self::INSIDE; |
||||
} |
||||
} |
||||
} |
||||
|
||||
$clockIn = null; |
||||
$clockOut = null; |
||||
$inout = Presence::where('user_id', $this->id) |
||||
->orderByDesc('clock_in') |
||||
->first(); |
||||
if ($inout !== null) { |
||||
$clockIn = Carbon::parse($inout->clock_in, $tz); |
||||
$clockOut = Carbon::parse($inout->clock_out, $tz); |
||||
} |
||||
|
||||
return array( |
||||
"status" => $status, |
||||
"ts" => $ts, |
||||
"clock_in" => $clockIn, |
||||
"clock_out" => $clockOut |
||||
); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue