Browse Source

Merge branch 'Dev-Fuad' of https://git.oslog.id/ordo/surveyor_indonesia_backend into dev-wahyun

pull/5/head
SitiAfridaFitriyani 4 months ago
parent
commit
a96ba15bbe
  1. 920
      app/Helpers/MasterFunctionsHelper.php
  2. 1693
      app/Helpers/MasterFunctionsHelperOld.php
  3. 87
      app/Http/Controllers/ActivityDokumenController.php
  4. 12
      app/Http/Controllers/Controller.php
  5. 77
      app/Http/Controllers/HumanResourceController.php
  6. 27
      app/Http/Controllers/ProjectController.php
  7. 7
      app/Http/Controllers/ReportActivityMaterialController.php
  8. 8163
      composer.lock
  9. 6
      routes/web.php

920
app/Helpers/MasterFunctionsHelper.php

File diff suppressed because it is too large Load Diff

1693
app/Helpers/MasterFunctionsHelperOld.php

File diff suppressed because it is too large Load Diff

87
app/Http/Controllers/ActivityDokumenController.php

@ -8,51 +8,52 @@ use App\Models\ActivityDokumen;
class ActivityDokumenController extends Controller class ActivityDokumenController extends Controller
{ {
public function dokumenByActivityId($id)
public function dokumenByActivityId($id){ {
if(empty($id) || !is_int((int)$id)) if (empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'activity id is required!', 'code' => 400], 400);
$dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); $dataDokumen = ActivityDokumen::where("activity_id", $id)->get();
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200); return response()->json(['status' => 'success', 'data' => $dataDokumen, 'code' => 200], 200);
} }
public function delete($id, $company_id) public function delete($id)
{ {
if(empty($id) || !is_int((int)$id)) if (empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400);
$document = ActivityDokumen::find($id); $document = ActivityDokumen::find($id);
if(!$document) { if (!$document) {
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
$company = Company::find($company_id);
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
if(file_exists($destinationPath['pathActivityDocument'].$document->file)){
unlink($destinationPath['pathActivityDocument'].$document->file);
} }
$destinationPath = $this->setCustomeDirectoryUpload();
if (file_exists($destinationPath['pathActivityDocument'] . $document->file)) {
unlink($destinationPath['pathActivityDocument'] . $document->file);
} }
$document->delete(); $document->delete();
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Dokumen deleted successfully!', 'code' => 200], 200);
} }
public function uploadProjectDokumen(Request $request) public function uploadProjectDokumen(Request $request)
{ {
if(!$request->hasFile('dokumen')) {
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400);
}
$activity_id = $request->activity_id; $activity_id = $request->activity_id;
$document = $request->file('dokumen'); $document = $request->file('dokumen');
$name = $document->getClientOriginalName(); $name = $document->getClientOriginalName();
$company = Company::find($request->company_id); $fileSize = $document->getSize();
if($company) { $maximumSizeFile = $fileSize > 15 * 1024 * 1024; // 15 MB
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); if ($maximumSizeFile) {
$result = $document->move($destinationPath['pathActivityDocument'], $name); return response()->json(['status' => 'failed', 'message' => 'This file is too large. Allowed maximum size is 15MB', 'code' => 500], 500);
} }
if(!$result || !$company) { $this->validate($request, [
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); 'dokumen' => 'required|file|max:15360'
]);
if (!$request->hasFile('dokumen')) {
return response()->json(['status' => 'failed', 'message' => 'file is required!', 'code' => 400], 400);
}
$result = $document->move($this->directories['pathActivityDocument'], $name);
if (!$result) {
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500);
} }
$data = [ $data = [
'activity_id' => (int)$activity_id, 'activity_id' => (int)$activity_id,
@ -60,14 +61,15 @@ class ActivityDokumenController extends Controller
'description' => $request->description 'description' => $request->description
]; ];
$result = ActivityDokumen::create($data); $result = ActivityDokumen::create($data);
if(!$result || !$company) { if (!$result) {
unlink($destinationPath['pathActivityDocument'].$name); unlink($this->directories['pathActivityDocument'] . $name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500);
} }
return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Upload success!', 'code' => 200], 200);
} }
public function searchDocProject(Request $request){ public function searchDocProject(Request $request)
{
$payload = $request->all(); $payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); $dataBuilder = $this->setUpPayload($payload, 'm_document_activity');
@ -76,26 +78,23 @@ class ActivityDokumenController extends Controller
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
} }
public function downloadDokumen($id, $company_id) public function downloadDokumen($id)
{ {
if(empty($id) || !is_int((int)$id)) { if (empty($id) || !is_int((int)$id)) {
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400);
} }
$document = ActivityDokumen::find($id); $document = ActivityDokumen::find($id);
$company = Company::find($company_id); if (!$document) {
if(!$document || !$company) { return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 400], 400);
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
} }
if($company) { $destinationPath = $this->setCustomeDirectoryUpload();
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); if (file_exists($destinationPath['pathActivityDocument'] . $document->file)) {
if(file_exists($destinationPath['pathActivityDocument'].$document->file)) { $pathToFile = $destinationPath['pathActivityDocument'] . $document->file;
$pathToFile = $destinationPath['pathActivityDocument'].$document->file;
return response()->download($pathToFile); return response()->download($pathToFile);
} }
} return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 400], 400);
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
} }
} }

12
app/Http/Controllers/Controller.php

@ -44,17 +44,15 @@ class Controller extends BaseController
$this->pathActivityDocument = config('assets.activity'); $this->pathActivityDocument = config('assets.activity');
} }
protected function setCustomeDirectoryUpload($company_name) protected function setCustomeDirectoryUpload()
{ {
$current_date = date('Y-m-d'); $current_date = date('Y-m-d');
[$year, $month] = explode('-', $current_date); [$year, $month] = explode('-', $current_date);
$yearMonth = $year.'-'.$month; $yearMonth = $year.'-'.$month;
$pathImage = 'assets/image/';
$pathImage = 'assets/' . $company_name .'/'. $yearMonth . '/image/'; $pathDocument = 'assets/file/project/';
$pathDocument = 'assets/' . $company_name .'/'. $yearMonth . '/file/project/'; $pathTmpImport = 'assets/file/tmpimport/';
$pathTmpImport = 'assets/' . $company_name .'/'. $yearMonth . '/file/tmpimport/'; $pathActivityDocument = 'assets/file/activity/';
$pathActivityDocument = 'assets/' . $company_name .'/'. $yearMonth . '/file/activity/';
return [ return [
'pathImage' => $pathImage, 'pathImage' => $pathImage,
'pathDocument' => $pathDocument, 'pathDocument' => $pathDocument,

77
app/Http/Controllers/HumanResourceController.php

@ -3,7 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\{HumanResource,ProductTransaction,UserToActivity,UserToProyek,User}; use App\Models\{HumanResource, ProductTransaction, UserToActivity, UserToProyek, User};
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
const URL_EMAIL = 'https://notifapp.odm-iu.com/service-mail/notif_mail.php'; const URL_EMAIL = 'https://notifapp.odm-iu.com/service-mail/notif_mail.php';
@ -22,44 +22,18 @@ class HumanResourceController extends Controller
'name' => 'required|string', 'name' => 'required|string',
'ktp_number' => 'required|string|unique:m_users,ktp_number', 'ktp_number' => 'required|string|unique:m_users,ktp_number',
'employee_type' => 'required|in:employee,subcon,freelance', 'employee_type' => 'required|in:employee,subcon,freelance',
'company_id' => 'required|integer',
'username' => 'string|unique:m_users,username', 'username' => 'string|unique:m_users,username',
'email' => 'string|unique:m_users,email' 'email' => 'string|unique:m_users,email'
], $messages); ], $messages);
$data = $request->all(); $data = $request->all();
!$request->is_customer ? $this->validate($request,['role_id' => 'required','divisi_id' => 'required'], $messages) : ''; !$request->is_customer ? $this->validate($request, ['role_id' => 'required', 'divisi_id' => 'required'], $messages) : '';
if (isset($request->password) && $request->password != "") { if (isset($request->password) && $request->password != "") {
$data['password'] = md5($request->password); $data['password'] = md5($request->password);
} }
$transaction = ProductTransaction::query()
->where('company_id', (int) $request->company_id);
$cloneQueryTransaction = clone $transaction;
$countCreate = false;
$projectResult = HumanResource::query()
->selectRaw('count(*) as total_hr')
->where('company_id', (int) $request->company_id)
->first();
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) {
if($projectResult['total_hr'] < 50) {
$countCreate = true;
}
} elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) {
if($projectResult['total_hr'] < 1) {
$countCreate = true;
}
} else {
$countCreate = true;
}
if($countCreate) {
$result = HumanResource::create($data); $result = HumanResource::create($data);
} else {
return response()->json(['status' => 'failed', 'message' => 'Limited to create human resource!', 'code' => 500], 500);
}
if ($result) { if ($result) {
return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]); return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]);
@ -76,7 +50,6 @@ class HumanResourceController extends Controller
'name' => 'required', 'name' => 'required',
'ktp_number' => 'required|string|unique:m_users,ktp_number', 'ktp_number' => 'required|string|unique:m_users,ktp_number',
'employee_type' => 'required', 'employee_type' => 'required',
'company_id' => 'required',
'username' => 'required', 'username' => 'required',
'email' => 'required|unique:m_users,email|email' 'email' => 'required|unique:m_users,email|email'
]); ]);
@ -121,15 +94,13 @@ class HumanResourceController extends Controller
'required' => 'Data tidak boleh kosong' 'required' => 'Data tidak boleh kosong'
]; ];
$request->validate($request, [ $this->validate($request, [
'name' => 'required|string', 'name' => 'required|string',
'ktp_number' => 'required|string|unique:m_users,ktp_number,'.$id . ',id', 'ktp_number' => 'required|string|unique:m_users,ktp_number,'.$id . ',id',
'employee_type' => 'required|in:employee,subcon,freelance', 'employee_type' => 'required|in:employee,subcon,freelance',
'company_id' => 'required|integer',
'username' => 'unique:m_users,username,'.$id . ',id', 'username' => 'unique:m_users,username,'.$id . ',id',
'email' => 'string|unique:m_users,email,'.$id . ',id' 'email' => 'string|unique:m_users,email,'.$id . ',id'
], $messages); ], $messages);
!$request->is_customer ? $this->validate($request,['role_id'=>'required', 'divisi_id'=>'required'], $messages) : ''; !$request->is_customer ? $this->validate($request,['role_id'=>'required', 'divisi_id'=>'required'], $messages) : '';
$request->password ? $this->validate($request,['password'=>'required|min:8']) : ''; $request->password ? $this->validate($request,['password'=>'required|min:8']) : '';
@ -140,47 +111,16 @@ class HumanResourceController extends Controller
} }
$humanresource = HumanResource::find($id); $humanresource = HumanResource::find($id);
if(empty($humanresource)) { if (empty($humanresource)) {
return response()->json(['status' => 'failed', 'message' => 'Data Human Resource not found!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'Data Human Resource not found!', 'code' => 400], 400);
} }
if($request->company_id && isset($request->password) && isset($request->username)) {
$transaction = ProductTransaction::query()
->where('company_id', $request->company_id);
$cloneQueryTransaction = clone $transaction;
$countCreate = false;
$projectResult = HumanResource::query()
->selectRaw('count(*) as total_hr')
->where([
['company_id', $request->company_id],
['username', '!=', null],
['password', '!=', null]
])
->first();
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) {
if($projectResult['total_hr'] < 10) {
$countCreate = true;
}
} elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) {
if($projectResult['total_hr'] < 1) {
$countCreate = true;
}
} else {
$countCreate = true;
}
} else {
$countCreate = true;
}
if (isset($request->password) && $request->password != "") { if (isset($request->password) && $request->password != "") {
$data['password'] = md5($request->password); $data['password'] = md5($request->password);
} }
if ($countCreate) { // $result = $humanresource->update($data);
$result = $humanresource->update($data); $result = true;
} else {
return response()->json(['status' => 'failed', 'message' => 'Limited to create human resource!', 'code' => 500], 500);
}
if ($result) { if ($result) {
return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Human Resource Pool successfully updated!', 'code' => 200], 200); return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Human Resource Pool successfully updated!', 'code' => 200], 200);
@ -220,7 +160,7 @@ class HumanResourceController extends Controller
public function list() public function list()
{ {
$data = HumanResource::select('id', 'name', 'role_id','company_id')->get(); $data = HumanResource::select('id', 'name', 'role_id')->get();
$countData = $data->count(); $countData = $data->count();
if ($data) { if ($data) {
@ -306,7 +246,7 @@ class HumanResourceController extends Controller
return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400); return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400);
} else { } else {
$this->reqHttpCurl($email, $password, $user->username, $user->name); $this->reqHttpCurl($email, $password, $user->username, $user->name);
return response()->json(['status' => 'error', 'code'=>400, 'message' => 'e-mail not found '], 400); return response()->json(['status' => 'error', 'code' => 400, 'message' => 'e-mail not found '], 400);
} }
} }
@ -352,6 +292,5 @@ class HumanResourceController extends Controller
} else { } else {
print_r(json_decode($response)); print_r(json_decode($response));
} }
} }
} }

27
app/Http/Controllers/ProjectController.php

@ -60,7 +60,6 @@ class ProjectController extends Controller
'akhir_proyek' => 'required', 'akhir_proyek' => 'required',
'rencana_biaya' => 'required', 'rencana_biaya' => 'required',
'type_proyek_id' => 'required', 'type_proyek_id' => 'required',
'company_id' => 'required'
]); ]);
DB::beginTransaction(); DB::beginTransaction();
try { try {
@ -72,29 +71,9 @@ class ProjectController extends Controller
if (empty($data['phase_id'])) { if (empty($data['phase_id'])) {
$data['phase_id'] = 1; $data['phase_id'] = 1;
} }
$transaction = ProductTransaction::query()
->where('company_id', $request->company_id);
$cloneQueryTransaction = clone $transaction;
$countCreate = false;
$projectResult = Project::query()
->selectRaw('count(*) as total_project')
->where('company_id', $request->company_id)
->first();
if ($transaction->where([['type_paket', 'Basic'], ['amount', '!=', null]])->exists()) {
if ($projectResult['total_project'] < 10) {
$countCreate = true;
}
} elseif ($cloneQueryTransaction->where([['type_paket', 'Free'], ['amount', 0]])->exists()) {
if ($projectResult['total_project'] < 1) {
$countCreate = true;
}
} else {
$countCreate = true;
}
if ($countCreate) {
$result = Project::create($data); $result = Project::create($data);
if (!$result) { if (!$result) {
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500);
} else { } else {
@ -103,9 +82,6 @@ class ProjectController extends Controller
DB::commit(); DB::commit();
return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200);
} }
} else {
return response()->json(['status' => 'failed', 'message' => 'Limited to create project!', 'code' => 500], 500);
}
} catch (\Throwable $th) { } catch (\Throwable $th) {
DB::rollBack(); DB::rollBack();
} }
@ -150,7 +126,6 @@ class ProjectController extends Controller
'phase_id', 'phase_id',
'calculation_status', 'calculation_status',
'md.name as divisi_name', 'md.name as divisi_name',
'm_proyek.company_id'
) )
->leftJoin('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id') ->leftJoin('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id')
->where('m_proyek.id', $id) ->where('m_proyek.id', $id)

7
app/Http/Controllers/ReportActivityMaterialController.php

@ -102,14 +102,13 @@ class ReportActivityMaterialController extends Controller
} }
} }
public function delete($id, $company_id) public function delete($id)
{ {
$data = ReportActivityMaterial::findOrFail($id); $data = ReportActivityMaterial::findOrFail($id);
$company = Company::find($company_id);
$image = Image::where([['ref_id', $id],['category','report_activity']])->first(); $image = Image::where([['ref_id', $id],['category','report_activity']])->first();
if($data && $company && $image) { if($data && $image) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); $destinationPath = $this->setCustomeDirectoryUpload();
unlink($destinationPath['pathImage'].$image['image']); unlink($destinationPath['pathImage'].$image['image']);
} }
if(!$data->delete()) { if(!$data->delete()) {

8163
composer.lock generated

File diff suppressed because it is too large Load Diff

6
routes/web.php

@ -72,9 +72,9 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/document-activity/upload', 'ActivityDokumenController@uploadProjectDokumen'); $router->post('/document-activity/upload', 'ActivityDokumenController@uploadProjectDokumen');
$router->get('/document-activity/get/{id}', 'ActivityDokumenController@dokumenByActivityId'); $router->get('/document-activity/get/{id}', 'ActivityDokumenController@dokumenByActivityId');
$router->delete('/document-activity/delete/{id}/{company_id}', 'ActivityDokumenController@delete'); $router->delete('/document-activity/delete/{id}', 'ActivityDokumenController@delete');
$router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject'); $router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject');
$router->get('/document-activity/download/{id}/{company_id}', 'ActivityDokumenController@downloadDokumen'); $router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen');
$router->get('/project-by-customer/{id}', 'ProjectController@getByUser'); $router->get('/project-by-customer/{id}', 'ProjectController@getByUser');
$router->post('/project/search', 'ProjectController@search'); $router->post('/project/search', 'ProjectController@search');
@ -431,7 +431,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/report-activity-material/add', 'ReportActivityMaterialController@add'); $router->post('/report-activity-material/add', 'ReportActivityMaterialController@add');
$router->post('/report-activity-material/search', 'ReportActivityMaterialController@search'); $router->post('/report-activity-material/search', 'ReportActivityMaterialController@search');
$router->delete('/report-activity-material/delete/{id}/{company_id}', 'ReportActivityMaterialController@delete'); $router->delete('/report-activity-material/delete/{id}', 'ReportActivityMaterialController@delete');
$router->get('/report-activity-material/list', 'ReportActivityMaterialController@list'); $router->get('/report-activity-material/list', 'ReportActivityMaterialController@list');
$router->get('/report-activity-material/datatables', 'ReportActivityMaterialController@datatables'); $router->get('/report-activity-material/datatables', 'ReportActivityMaterialController@datatables');
$router->post('/report-activity-material/update-status', 'ReportActivityMaterialController@updateStatusStartFinish'); $router->post('/report-activity-material/update-status', 'ReportActivityMaterialController@updateStatusStartFinish');

Loading…
Cancel
Save