Browse Source

[Refactor] Menghapus company_id

pull/7/head
Fuad Hadisurya 5 months ago
parent
commit
15cf5188b6
  1. 16
      app/Http/Controllers/ActivityController.php
  2. 4
      app/Http/Controllers/DivisiController.php
  3. 7
      app/Http/Controllers/FolderDocumentProyekController.php
  4. 1
      app/Http/Controllers/ProductTransactionController.php
  5. 42
      app/Http/Controllers/ProjectDokumenController.php
  6. 1
      app/Http/Controllers/ProjectExpenditureController.php
  7. 1
      app/Http/Controllers/ProjectFinancialHealthController.php
  8. 1
      app/Http/Controllers/ProjectInvoiceController.php
  9. 2
      app/Http/Controllers/ProjectRoleController.php
  10. 1
      app/Http/Controllers/ProjectScheduleHealthController.php
  11. 4
      app/Http/Controllers/RoleController.php
  12. 11
      app/Http/Controllers/UserToProyekController.php
  13. 4
      routes/web.php

16
app/Http/Controllers/ActivityController.php

@ -635,41 +635,37 @@ class ActivityController extends Controller
$activity_id = (int)$id;
$data = Activity::query()
->from('m_activity as ma')
->select('mp.company_id')
->select('ma.id')
->join('m_proyek as mp', 'ma.proyek_id', 'mp.id')
->where('ma.id', $activity_id);
$cloneQuery = clone $data;
if (!$data->exists()) {
DB::rollBack();
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404);
}
$this->deleteRelative($activity_id, $cloneQuery->first()->company_id);
$this->deleteRelative($activity_id);
if (!$data->delete()) {
DB::rollBack();
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data activity failed deleted!', 'code' => 500], 500);
}
DB::commit();
DB::rollBack();
return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'Data activity successfully deleted!', 'code' => 200], 200);
}
private function deleteRelative($activity_id, $company_id)
private function deleteRelative($activity_id)
{
DB::transaction(function() use($activity_id, $company_id) {
DB::transaction(function () use ($activity_id) {
UserToActivity::where('activity_id', $activity_id)->delete();
AssignMaterial::where('activity_id', $activity_id)->delete();
$dataAd = ActivityDokumen::where("activity_id", $activity_id)->get();
$company = Company::find($company_id);
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$destinationPath = $this->setCustomeDirectoryUpload();
foreach ($dataAd as $ad) {
if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) {
unlink($destinationPath['pathActivityDocument'] . $ad->file);
}
}
ActivityDokumen::where("activity_id", $activity_id)->delete();
}
});
}

4
app/Http/Controllers/DivisiController.php

@ -22,7 +22,7 @@ class DivisiController extends Controller
public function add(Request $request)
{
$this->validate($request, [
'name' => 'string|required|unique:m_divisi,name,NULL,id,company_id,' . $request->input('company_id'),
'name' => 'string|required|unique:m_divisi,name,NULL,id',
'description' => 'nullable|string',
'parent' => 'nullable|integer',
'color' => 'nullable|string|max:10'
@ -32,7 +32,6 @@ class DivisiController extends Controller
$data['created_by'] = $this->currentName;
$result = Divisi::create($data);
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Failed to add data', 'code' => 500]);
@ -86,7 +85,6 @@ class DivisiController extends Controller
{
$companyId = $request->input('columns.0.value');
$parentDivisi = Divisi::whereNull('parent')
->where('company_id', $companyId)
->with('children')
->get();
$divisions = [];

7
app/Http/Controllers/FolderDocumentProyekController.php

@ -47,13 +47,12 @@ class FolderDocumentProyekController extends Controller
}
}
public function delete($id, $company_id)
public function delete($id)
{
DB::beginTransaction();
$data = FolderDocumentProyek::find($id);
$company = Company::find($company_id);
if($data && $company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
if($data) {
$destinationPath = $this->setCustomeDirectoryUpload();
$dir = $destinationPath['pathDocument'];
$dataFile = DokumenProject::where([['type_dokumen', 'project-document-in-folder'],['ref_id', $data['id']]])->orderByRaw('id ASC')->get();
if (is_dir($dir)) {

1
app/Http/Controllers/ProductTransactionController.php

@ -10,7 +10,6 @@ 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'

42
app/Http/Controllers/ProjectDokumenController.php

@ -9,7 +9,8 @@ use Illuminate\Support\Facades\DB;
class ProjectDokumenController extends Controller
{
public function dokumenByProyekId($id){
public function dokumenByProyekId($id)
{
if (empty($id) || !is_int((int)$id)) {
return response()->json(['status' => 'failed', 'message' => 'project id is required!', 'code' => 400], 400);
}
@ -22,7 +23,7 @@ class ProjectDokumenController extends Controller
return response()->json(['status' => 'success', 'data' => $document, 'code' => 200], 200);
}
public function delete($id, $company_id)
public function delete($id)
{
if (empty($id) || !is_int((int)$id)) {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
@ -32,12 +33,9 @@ class ProjectDokumenController extends Controller
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']);
$destinationPath = $this->setCustomeDirectoryUpload();
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);
@ -55,17 +53,8 @@ class ProjectDokumenController extends Controller
$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);
}
$destinationPath = $this->setCustomeDirectoryUpload();
$data = [
'ref_id' => (int)$ref_id,
'file' => $name,
@ -73,7 +62,6 @@ class ProjectDokumenController extends Controller
];
$result = DokumenProject::create($data);
if (!$document->move($destinationPath['pathDocument'], $name) && $result) {
unlink($destinationPath['pathDocument'] . $name);
DB::rollBack();
@ -82,14 +70,12 @@ class ProjectDokumenController extends Controller
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){
public function searchDocProject(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'document_project');
@ -101,27 +87,25 @@ class ProjectDokumenController extends Controller
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)) {
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400);
}
$document = DokumenProject::find($id);
$company = Company::find($company_id);
if(!$document || !$company) {
if (!$document) {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$destinationPath = $this->setCustomeDirectoryUpload();
$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 . '"'
];

1
app/Http/Controllers/ProjectExpenditureController.php

@ -16,7 +16,6 @@ class ProjectExpenditureController extends Controller
// Set Unique
$result = ProjectExpenditure::query()
->where([
['company_id',$data['company_id']],
['name', $data['name']]
])->first();
if($result) {

1
app/Http/Controllers/ProjectFinancialHealthController.php

@ -16,7 +16,6 @@ class ProjectFinancialHealthController extends Controller
// Set Unique
$result = ProjectFinancialHealth::query()
->where([
['company_id',$data['company_id']],
['name', $data['name']]
])->first();
if($result) {

1
app/Http/Controllers/ProjectInvoiceController.php

@ -16,7 +16,6 @@ class ProjectInvoiceController extends Controller
// Set Unique
$result = ProjectInvoice::query()
->where([
['company_id',$data['company_id']],
['name', $data['name']]
])->first();
if($result) {

2
app/Http/Controllers/ProjectRoleController.php

@ -12,7 +12,6 @@ class ProjectRoleController extends Controller
$this->validate($request, [
'name' => 'required',
'description' => 'required',
'company_id' => 'required'
]);
$data = $request->all();
@ -20,7 +19,6 @@ class ProjectRoleController extends Controller
$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{

1
app/Http/Controllers/ProjectScheduleHealthController.php

@ -16,7 +16,6 @@ class ProjectScheduleHealthController extends Controller
// Set Unique
$result = ProjectScheduleHealth::query()
->where([
['company_id',$data['company_id']],
['name', $data['name']]
])->first();
if($result) {

4
app/Http/Controllers/RoleController.php

@ -11,9 +11,8 @@ class RoleController extends Controller
public function add(Request $request)
{
$this->validate($request, [
'name' => 'string|required|unique:m_roles,name,NULL,id,company_id,' . $request->input('company_id'),
'name' => 'string|required|unique:m_roles,name,NULL,id',
'description' => 'required',
'company_id' => 'required'
]);
$data = $request->all();
@ -24,7 +23,6 @@ class RoleController extends Controller
}
$result = Role::create($data);
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500);

11
app/Http/Controllers/UserToProyekController.php

@ -113,7 +113,7 @@ class UserToProyekController extends Controller
}
}
public function delete($id, $company_id)
public function delete($id)
{
$data = UserToProyek::find($id);
if ($data) {
@ -121,7 +121,7 @@ class UserToProyekController extends Controller
$proyekId = $data->proyek_id;
$delete = $data->delete();
if ($delete) {
$this->deleteRelative($proyekId, $userId, $company_id);
$this->deleteRelative($proyekId, $userId);
}
} else {
return response()->json(['status' => 'failed', 'message' => 'data assign hr to proyek not found!', 'code' => 400], 400);
@ -136,14 +136,12 @@ class UserToProyekController extends Controller
}
}
private function deleteRelative($proyekId, $userId, $company_id)
private function deleteRelative($proyekId, $userId)
{
$uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get();
foreach ($uta as $value) {
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get();
$company = Company::find($company_id);
if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$destinationPath = $this->setCustomeDirectoryUpload();
foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($images as $image) {
@ -155,7 +153,6 @@ class UserToProyekController extends Controller
}
ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->delete();
}
}
UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->delete();
}

4
routes/web.php

@ -66,9 +66,9 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/document-project/upload', 'ProjectDokumenController@uploadProjectDokumen');
$router->get('/document-project/get/{id}', 'ProjectDokumenController@dokumenByProyekId');
$router->delete('/document-project/delete/{id}/{company_id}', 'ProjectDokumenController@delete');
$router->delete('/document-project/delete/{id}', 'ProjectDokumenController@delete');
$router->post('/document-project/search', 'ProjectDokumenController@searchDocProject');
$router->get('/document-project/download/{id}/{company_id}', 'ProjectDokumenController@downloadDokumen');
$router->get('/document-project/download/{id}', 'ProjectDokumenController@downloadDokumen');
$router->post('/document-activity/upload', 'ActivityDokumenController@uploadProjectDokumen');
$router->get('/document-activity/get/{id}', 'ActivityDokumenController@dokumenByActivityId');

Loading…
Cancel
Save