Browse Source

Merge pull request 'Dev-Farhan' (#308) from Dev-Farhan into staging

Reviewed-on: ordo/adw-backend#308
pull/1/head
farhantock 11 months ago
parent
commit
1ba1aa6028
  1. 110
      app/Http/Controllers/CompanyController.php
  2. 1
      app/Http/Controllers/Controller.php
  3. 195
      app/Http/Controllers/MenuCompanyController.php
  4. 11
      app/Http/Controllers/ProjectController.php
  5. 37
      app/Models/Company.php
  6. 1
      app/Models/HumanResource.php
  7. 27
      app/Models/MenuCompany.php
  8. 2
      app/Models/ProjectRole.php
  9. 2
      app/Models/Role.php
  10. 2
      app/Models/RoleMenu.php
  11. 2
      app/Models/Satuan.php
  12. 1
      routes/web.php

110
app/Http/Controllers/CompanyController.php

@ -1,110 +0,0 @@
<?php
namespace App\Http\Controllers;
use App\Models\Company;
use Illuminate\Http\Request;
class CompanyController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'name' => 'required',
'description' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = Company::create($data);
if ($result) {
return response()->json(['status' => 'success', 'message' => 'add Company successfully!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'add data Company 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 = Company::find($id);
if ($result) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get data Company, 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 = Company::find($id);
if ($data) {
$result = $data->update($request->all());
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400);
die();
}
if ($result) {
return response()->json(['status' => 'success', 'message' => 'data Company successfully updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company failed updated!', 'code' => 400], 400);
}
}
public function delete($id)
{
$data = Company::find($id);
if ($data) {
$delete = $data->delete();
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400);
die();
}
if ($delete) {
return response()->json(['status' => 'success', 'message' => 'data Company successfully deleted!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company failed deleted!', 'code' => 400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_company');
$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 = Company::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 Company, please try again later!', 'code' => 400], 400);
}
}
}

1
app/Http/Controllers/Controller.php

@ -33,7 +33,6 @@ class Controller extends BaseController
$this->currentDate = date("Y-m-d H:i:s");
$this->currentName = auth()->user() ? auth()->user()->name : "system";
$this->currentId = auth()->user() ? auth()->user()->id : 0;
$this->companyId = auth()->user() ? auth()->user()->company_id : 0;
$this->pathImage = config('assets.image');
$this->pathDocument = config('assets.project');
$this->pathActivityDocument = config('assets.activity');

195
app/Http/Controllers/MenuCompanyController.php

@ -1,195 +0,0 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\MenuCompany;
use App\Models\RoleMenu;
use Illuminate\Support\Facades\Log;
class MenuCompanyController extends Controller
{
// public function add(Request $request)
// {
// $this->validate($request, [
// 'icon' => 'required',
// 'name' => 'string|required',
// 'url' => 'required|unique:m_company_menu,url',
// 'sequence' => 'required|integer',
// ]);
// $data = $request->all();
// $data['created_by'] = $this->currentName;
// $result = MenuCompany::create($data);
// if ($result) {
// return response()->json(['status' => 'success', 'message' => 'add data menu successfully!', 'code' => 200], 200);
// } else {
// return response()->json(['status' => 'failed', 'message' => 'add data menu failed!', 'code' => 400], 400);
// }
// }
public function addMultiple(Request $request)
{
$menus = $request->all();
if (is_array($menus) && count($menus) > 0) {
$countRes = 0;
foreach ($menus as $menu) {
$dataInsert = array(
"menu_id" => $menu['menu_id'],
"parent_menu_id" => $menu['parent_id'],
"company_id" => $menu['company_id'],
"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 response()->json(['status' => 'success', 'message' => 'add data menu successfully!', 'code' => 200]);
} else {
return response()->json(['status' => 'failed', 'message' => 'add data menu failed created!', 'code' => 400]);
}
} else {
return response()->json(['status' => 'failed', 'message' => 'add data menu failed created!', 'code' => 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 = MenuCompany::find($id);
if ($result) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get data menu, 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);
}
$this->validate($request, [
'icon' => 'required',
'sequence' => 'required|integer',
]);
$data = MenuCompany::find($id);
if ($data) {
$result = $data->update($request->all());
} else {
return response()->json(['status' => 'failed', 'message' => 'data menu not found!', 'code' => 400], 400);
die();
}
if ($result) {
return response()->json(['status' => 'success', 'message' => 'data menu successfully updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data menu failed updated!', 'code' => 400], 400);
}
}
public function delete($id)
{
$data = MenuCompany::find($id);
if ($data) {
$delete = $data->delete();
} else {
return response()->json(['status' => 'failed', 'message' => 'data menu not found!', 'code' => 400], 400);
die();
}
if ($delete) {
return response()->json(['status' => 'success', 'message' => 'data menu successfully deleted!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data menu failed deleted!', 'code' => 400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_company_menu');
$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 listMenu($id)
{
$dataParent = RoleMenu::select("m_company_menu.*")
->join('m_company_menu', 'm_company_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->whereNull('m_company_menu.parent_id')
->where('m_roles.id', $id)
->orderBy('m_company_menu.sequence', 'ASC')
->get();
$finalData = [];
foreach ($dataParent as $data) {
$data->children = $this->getChildrenMenu($data->id, $id);
$finalData[] = $data;
}
return response()->json(['status' => 'success', 'code' => 200, 'data' => $finalData], 200);
}
protected function getChildrenMenu($id, $role_id)
{
$dataChildren = RoleMenu::select("m_company_menu.*")
->join('m_company_menu', 'm_company_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->where('m_roles.id', $role_id)
->where('m_company_menu.parent_id', $id)
->orderBy('m_company_menu.sequence', 'ASC')
->get();
$children = [];
if ($dataChildren) {
foreach ($dataChildren as $data) {
$data->children = $this->getChildrenMenu($data->id, $role_id);
$children[] = $data;
}
}
return $children;
}
public function list()
{
$data = MenuCompany::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 menu, please try again later!', 'code' => 400], 400);
}
}
}

11
app/Http/Controllers/ProjectController.php

@ -762,6 +762,17 @@ class ProjectController extends Controller
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
public function getProjectCostIntegration($name)
{
$search = urlencode($name);
if (empty($search))
return response()->json(['status' => 'error', 'message' => 'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw') . '/project_cost?project_no=SEARCH');
$response = MasterFunctionsHelper::curlReq($url);
return response()->json(['status' => 'success', 'data' => $response, 'code' => 200], 200);
}
private function httpReq($search)
{
$ch = curl_init();

37
app/Models/Company.php

@ -1,37 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Company extends Model
{
protected $table = 'm_company';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
"registration_no",
"company_name",
"address",
"phone_no",
"email",
"description",
"logo_login",
"logo_header",
"favicon_image",
"login_instruction",
"about",
"html_title",
"app_name",
"base_url",
"is_active",
"template_id",
'created_at',
'created_by',
'updated_at',
'updated_by',
'company_id'
];
}

1
app/Models/HumanResource.php

@ -34,6 +34,5 @@ class HumanResource extends Model
'updated_by',
'divisi_id',
'status_boundary',
'company_id'
];
}

27
app/Models/MenuCompany.php

@ -1,27 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class MenuCompany extends Model
{
protected $table = 'm_company_menu';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'menu_id',
'parent_menu_id',
'company_id',
'icon',
'alias_name',
'url',
'sequence',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}

2
app/Models/ProjectRole.php

@ -12,6 +12,6 @@ class ProjectRole extends Model
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

2
app/Models/Role.php

@ -12,6 +12,6 @@ class Role extends Model
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'description', 'default_page', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
'name', 'description', 'default_page', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

2
app/Models/RoleMenu.php

@ -12,6 +12,6 @@ class RoleMenu extends Model
const UPDATED_AT = 'updated_at';
protected $fillable = [
'role_id', 'menu_id', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id', "create", "read", "update", "delete"
'role_id', 'menu_id', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

2
app/Models/Satuan.php

@ -12,6 +12,6 @@ class Satuan extends Model
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

1
routes/web.php

@ -74,6 +74,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/project/get-overdue-activities', 'ProjectController@getOverdueActivities');
$router->post('/project/get-integration-invoice', 'ProjectController@getInvoiceIntegration');
$router->post('/project/get-report-distribution', 'ProjectController@getReportDistribution');
$router->get('/project/get-integration-project-cost={name}', 'ProjectController@getProjectCostIntegration');
/* $router->get('/project/get-expenditure/{id}/{date?}', 'ProjectController@getExpenditure'); */

Loading…
Cancel
Save