Browse Source

Merge pull request 'staging' (#48) from staging into master

Reviewed-on: ibnu/generic-ospro-backend#48
pull/1/head
farhantock 9 months ago
parent
commit
9ff5b3ad2a
  1. 31
      app/Http/Controllers/AuthController.php
  2. 28
      app/Http/Controllers/HumanResourceController.php
  3. 30
      app/Http/Controllers/ProductTransactionController.php
  4. 51
      app/Http/Controllers/ProjectController.php
  5. 1
      app/Models/Company.php
  6. 25
      app/Models/ProductTransaction.php
  7. 2
      routes/web.php

31
app/Http/Controllers/AuthController.php

@ -113,18 +113,33 @@ class AuthController extends Controller
public function sendEmail(Request $request)
{
$hashed = Str::random(15);
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);
return response()->json(['status' => 'error', 'message' => 'e-mail not found'], 400);
} else {
$this->reqHttpCurl($email, $hashed, $user->username, $user->name);
if (User::where('email', $email)->update(['password' => md5($hashed)]))
return response()->json(['status' => 'success', 'code' => 200, 'message' => 'Password already sent to mail'], 200);
return response()->json(['status' => 'error', 'code' => 400, 'message' => 'e-mail not found '], 400);
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);
}
}
}
@ -132,7 +147,7 @@ class AuthController extends Controller
{
$postData = [
"to" => $email,
"username" => $name,
"name" => $name,
"username" => $username,
"password" => $password,
"from" => "app.integrasia@integrasiautama.com",

28
app/Http/Controllers/HumanResourceController.php

@ -8,6 +8,7 @@ use App\Models\UserToProyek;
use Illuminate\Http\Request;
use App\Models\HumanResource;
use App\Models\UserToActivity;
use App\Models\ProductTransaction;
use Illuminate\Support\Facades\Artisan;
const URL_EMAIL = 'https://notifapp.odm-iu.com/service-mail/notif_mail.php';
@ -30,7 +31,32 @@ class HumanResourceController extends Controller
$data['password'] = md5($request->password);
}
$result = HumanResource::create($data);
$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)
->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;
}
if($countCreate) {
$result = HumanResource::create($data);
} else {
return response()->json(['status' => 'failed', 'message' => 'Limited to create human resource!', 'code' => 500], 500);
}
if ($result) {
return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]);

30
app/Http/Controllers/ProductTransactionController.php

@ -0,0 +1,30 @@
<?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 data Transaction failed!', 'code' => 400], 400);
}
}
}

51
app/Http/Controllers/ProjectController.php

@ -38,8 +38,10 @@ use App\Models\ProjectParticipants;
use App\Models\FolderDocumentProyek;
use App\Models\ProjectToChecklistK3;
use App\Helpers\MasterFunctionsHelper;
use App\Models\ProductTransaction;
use App\Models\ReportActivityMaterial;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Database\Query\Builder;
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1";
@ -63,10 +65,36 @@ class ProjectController extends Controller
$data['created_by'] = $this->currentName;
$data['created_by_id'] = $this->currentId;
if (empty($data['phase_id']))
$data['phase_id'] = 1;
$result = Project::create($data);
if (empty($data['phase_id'])) {
$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);
} else {
return response()->json(['status' => 'failed', 'message' => 'Limited to create project!', 'code' => 500], 500);
}
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500);
@ -531,6 +559,21 @@ class ProjectController extends Controller
return response()->json(['status' => 'success', 'message' => 'Set baseline success!', 'code' => 200], 200);
}
public function setBaselineActivity($activity_id, $gantt_id)
{
$activity = Activity::where([
["version_gantt_id", $gantt_id],
['id',$activity_id]
])->first();
$activity->update([
"planned_start" => $activity->start_date,
"planned_end" => $activity->end_date,
"early_start" => $activity->start_date,
"early_end" => $activity->end_date,
]);
return response()->json(['status' => 'success', 'message' => 'Set baseline activity success!', 'code' => 200], 200);
}
public function getInvoiceIntegration(Request $request)
{
$ganttCount = VersionGantt::where('proyek_id', $request->id)->count();

1
app/Models/Company.php

@ -33,6 +33,7 @@ class Company extends Model
'updated_at',
'updated_by',
'cluster',
'type_account',
'date_register'
];
}

25
app/Models/ProductTransaction.php

@ -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'
];
}

2
routes/web.php

@ -9,6 +9,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
// Landing Route
$router->post('/send-email', 'AuthController@sendEmail');
$router->post('/company-management-user/add', 'CompanyController@add');
$router->post('/product-transaction/add','ProductTransactionController@add');
$router->post('/company-management-user/search', 'CompanyController@search');
$router->post('/human-resource-user/add', 'HumanResourceController@add_user');
$router->get('/company-management-user/edit/{id}', 'CompanyController@edit');
@ -75,6 +76,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->delete('/project/delete/{id}', 'ProjectController@delete');
$router->get('/project/list', 'ProjectController@list');
$router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline');
$router->get('/project/set-baseline-activity/{activity_id}/{gantt_id}', 'ProjectController@setBaselineActivity');
$router->get('/project/synchronize-report/{gantt_id}', 'ProjectController@synchronizeReport');
$router->get('/project/manpower/{proyek_id}', 'ProjectController@getManpower');
$router->get('/project/manpower/assigned/{gantt_id}', 'ProjectController@getAssignedHR');

Loading…
Cancel
Save