Browse Source

Merge branch 'staging' of https://git.oslog.id/ordo/adw-backend into dev-ibnu

pull/3/head
ibnu 1 year ago
parent
commit
ecca24ccfc
  1. 29
      app/Helpers/MasterFunctionsHelper.php
  2. 7
      app/Http/Controllers/ActivityController.php
  3. 163
      app/Http/Controllers/DashboardBoDController.php
  4. 7
      app/Http/Controllers/ProjectController.php
  5. 2
      app/Models/AssignMaterial.php
  6. 2
      app/Models/UserToProyek.php

29
app/Helpers/MasterFunctionsHelper.php

@ -200,8 +200,8 @@ class MasterFunctionsHelper
->where('a.version_gantt_id', '=', $keyGantt['id'])
->max("a.planned_end"); // plan date overlapped with assign_material_to_activity's, it should be m_activity'
$maxDate = max(new \DateTime($plannedMaxDate), new \DateTime($actualMaxDate));
$end = $maxDate;
$end->modify('last month');
$end = new \DateTime($maxDate->format('Y-m-d') . ' Friday');
$end->modify('next Friday');
$interval = new \DateInterval('P7D');
}
$period = new \DatePeriod($begin, $interval, $end);
@ -605,6 +605,12 @@ class MasterFunctionsHelper
->where('activity_id', '=', $keyActualM->activity_id)
->groupBy('activity_id')
->first();
if (!isset($sumVolActual)) {
$sumVolActual = (object) [
'activity_id' => $keyActualM->activity_id,
'ttl_qty_plan' => "0"
];
}
$sumReportActual = DB::table('report_activity_material')
->where('activity_id', $keyActualM->activity_id)
->sum('qty');
@ -624,18 +630,29 @@ class MasterFunctionsHelper
->where('activity_id', '=', $keyActualM->activity_id)
->orderBy('status_activity', 'ASC')
->first();
$dataTempReport[$w]['percentage'] = ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
if (!isset($checkStatusActivity)) {
$checkStatusActivity = (object) [
'activity_id' => $keyActualM->activity_id,
'status_activity' => 'open'
];
}
if ($sumVolActual->ttl_qty_plan == "0") {
$actual = 0;
} else {
$actual = $keyActualM->qty / $sumVolActual->ttl_qty_plan;
}
$dataTempReport[$w]['percentage'] = $actual * $keyActualM->bobot_planning;
// $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
// if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){
if ($checkStatusActivity->status_activity == 'done') {
$sumPercentageActual += $keyActualM->bobot_planning / $reportCount;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else {
if ($keyActualM->qty / $sumVolActual->ttl_qty_plan >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) {
$sumPercentageActual += (($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning) * (95 / 100);
if ( $actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) {
$sumPercentageActual += ($actual * $keyActualM->bobot_planning) * (95 / 100);
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else {
$sumPercentageActual += ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
$sumPercentageActual += $actual * $keyActualM->bobot_planning;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
}
}

7
app/Http/Controllers/ActivityController.php

@ -248,7 +248,9 @@ class ActivityController extends Controller
$data['created_by'] = $this->currentName;
$max = Activity::where('version_gantt_id', $request->version_gantt_id)->max('sortorder');
$data['sortorder'] = $max + 1;
$data['type_activity'] = "task";
if (!isset($data['type_activity'])) {
$data['type_activity'] = "task";
}
$parent = $data['parent_id'] ?? null;
if ($parent) {
@ -360,6 +362,9 @@ class ActivityController extends Controller
$activityToUpdate = $activity->firstWhere('id', $entity['data']['id']);
$entity['data']['name'] = $entity['data']['text'];
$entity['data']['persentase_progress'] = $entity['data']['progress'] * 100;
if (isset($entity['data']['target'])) {
$this->updateOrder($entity['data']['id'], $entity['data']['target']);
}
if(!$activityToUpdate->update($entity['data']))
return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500);
$updatedJobsDone = $activityToUpdate->jobs_done;

163
app/Http/Controllers/DashboardBoDController.php

@ -14,16 +14,18 @@ use Illuminate\Support\Facades\Log;
class DashboardBoDController extends Controller
{
private function interpolateYear($year){
if($year)
$year = '%'.$year.'%';
private function interpolateYear($year)
{
if ($year)
$year = '%' . $year . '%';
return $year;
}
private function curlReq($url, $token){
private function curlReq($url, $token)
{
$ch = curl_init();
$headers = [
'Authorization: '.$token
'Authorization: ' . $token
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
@ -37,7 +39,8 @@ class DashboardBoDController extends Controller
return json_decode($response);
}
private function getInvoiceIntegration($search) {
private function getInvoiceIntegration($search)
{
// if(empty($search))
// return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
//
@ -52,30 +55,31 @@ class DashboardBoDController extends Controller
}
// to do
public function getCompanyCashFlow($year = '%') {
public function getCompanyCashFlow($year = '%')
{
$year = $this->interpolateYear($year);
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0;
// we can't use eloquent's sum() method because someone decided to use varchar as datatype in rencana_biaya field
$totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
/* ->orWhere('akhir_proyek', 'like', $year) */
->pluck('sum')
->first();
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->get();
foreach($projects as $project){
foreach ($projects as $project) {
$project->expenses = 0;
$resp = null;
if($project->kode_sortname != ""){
if ($project->kode_sortname != "") {
$resp = $this->getInvoiceIntegration($project->kode_sortname);
/* $resp = $project->kode_sortname; */
$cost = $resp->data->total_cost ?? 0;
$cost = substr($cost, 0, strpos($cost, "."));
$totalExpenditure+= (int) $cost;
$totalExpenditure += (int) $cost;
$totalInvoice += $resp->data->total_invoice_amount ?? 0;
$totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0;
}
@ -87,20 +91,21 @@ class DashboardBoDController extends Controller
'total_budget' => (int) $totalBudgets ?? 0,
'total_expenditure' => $totalExpenditure,
'total_invoice' => $totalInvoice,
'total_paid_invoice' => $totalPaidInvoice ,
'total_paid_invoice' => $totalPaidInvoice,
]
], 200);
}
public function getInvoiceOutstanding($year = '%'){
public function getInvoiceOutstanding($year = '%')
{
$year = $this->interpolateYear($year);
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->get();
$return = [];
foreach($projects as $project){
foreach ($projects as $project) {
$resp = null;
if($project->kode_sortname != ""){
if ($project->kode_sortname != "") {
$resp = $this->getInvoiceIntegration($project->kode_sortname);
array_push($return, [
'project' => $project->nama,
@ -117,7 +122,8 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerScheduleHealth($year = '%'){
public function getTotalProjectPerScheduleHealth($year = '%')
{
$year = $this->interpolateYear($year);
$return = [
@ -127,48 +133,49 @@ class DashboardBoDController extends Controller
];
$projects = Project::where('mulai_proyek', 'like', $year)->get();
foreach($projects as $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$selisihProgress = 0;
if($project->scurve && $project->scurve[0]){
$planningArray = $project->scurve[0]['data']['percentagePlan'];
$actualArray = $project->scurve[0]['data']['percentageReal'];
$planningProgress = !empty($planningArray) ? $planningArray[count($planningArray) - 1] : 0;
$actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0;
}
$selisihProgress = $planningProgress - $actualProgress;
foreach ($projects as $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$selisihProgress = 0;
if ($project->scurve && $project->scurve[0]) {
$planningArray = $project->scurve[0]['data']['percentagePlan'];
$actualArray = $project->scurve[0]['data']['percentageReal'];
$planningProgress = !empty($planningArray) ? $planningArray[count($planningArray) - 1] : 0;
$actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0;
}
$selisihProgress = $planningProgress - $actualProgress;
try {
if($selisihProgress > 0 && $selisihProgress <= 5)
$return['warning'] += 1;
elseif($selisihProgress == 0)
$return['on-schedule'] += 1;
else
$return['behind-schedule'] += 1;
if ($selisihProgress > 0 && $selisihProgress <= 5)
$return['warning'] += 1;
elseif ($selisihProgress == 0)
$return['on-schedule'] += 1;
else
$return['behind-schedule'] += 1;
} catch (\Error $e) {
return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200);
return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200);
}
}
return response()->json(['data' => $return, 'q' => $projects], 200);
}
public function getTotalProjectScheduleHealthPerDivision($year = '%'){
public function getTotalProjectScheduleHealthPerDivision($year = '%')
{
$year = $this->interpolateYear($year);
$divisions = Divisi::whereNull('parent')->get();
foreach($divisions as $division){
foreach ($divisions as $division) {
$scheduleData = new Collection();
$behindSchedule = $warning = $onSchedule = 0;
$projects = Project::where('mulai_proyek', 'like', $year)->where('divisi_id', $division->id)->get();
foreach($projects as $project) {
foreach ($projects as $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5)
if (@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5)
$warning++;
elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100)
elseif (@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100)
$behindSchedule++;
elseif(@$project->scurve['difference'] == 0)
elseif (@$project->scurve['difference'] == 0)
$onSchedule++;
}
@ -184,7 +191,8 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerBudgetHealth($year = '%'){
public function getTotalProjectPerBudgetHealth($year = '%')
{
$year = $this->interpolateYear($year);
return response()->json([
'data' => [
@ -195,28 +203,30 @@ class DashboardBoDController extends Controller
], 200);
}
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health){
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health)
{
return Project::where('divisi_id', $divisi)
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('budget_health', $health)
->count();
}
public function getTotalProjectBudgetHealthPerDivision($year = '%'){
public function getTotalProjectBudgetHealthPerDivision($year = '%')
{
$year = $this->interpolateYear($year);
$divisions = Divisi::select('id','name')
$divisions = Divisi::select('id', 'name')
->with('children')
->whereNull('parent')
->get();
// to do : count in more than 1 level child
foreach($divisions as $division){
foreach ($divisions as $division) {
$budgetData = new Collection();
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'overrun'), 'overrun');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'warning'), 'warning');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'on-budget'), 'on-budget');
foreach($division->children as $d){
foreach ($division->children as $d) {
$budgetData['overrun'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'overrun');
$budgetData['warning'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'warning');
$budgetData['on-budget'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'on-budget');
@ -224,7 +234,7 @@ class DashboardBoDController extends Controller
unset($division->children);
$division->budgetData = $budgetData;
}
foreach($divisions as $division){
foreach ($divisions as $division) {
}
return response()->json([
'data' => [
@ -233,14 +243,15 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerPhase($year = '%'){
public function getTotalProjectPerPhase($year = '%')
{
$year = $this->interpolateYear($year);
$projectPhases = ProjectPhase::orderBy('order')->get();
foreach($projectPhases as $phase){
foreach ($projectPhases as $phase) {
$phase->totalProject = Project::where('phase_id', $phase->id)
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->count();
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->count();
}
return response()->json([
'data' => [
@ -249,24 +260,26 @@ class DashboardBoDController extends Controller
], 200);
}
private function countTotalProjectInDivision($id, $year){
private function countTotalProjectInDivision($id, $year)
{
return Project::where('divisi_id', $id)
->where('mulai_proyek', 'like', $year)
->count();
}
public function getTotalProjectPerDivision($year = '%') {
public function getTotalProjectPerDivision($year = '%')
{
$year = $this->interpolateYear($year);
$divisions = Divisi::select('id','name')
$divisions = Divisi::select('id', 'name')
->with('children')
->whereNull('parent')
->get();
// to do : count in more than 1 level child
foreach($divisions as $v){
foreach ($divisions as $v) {
$v->total = $this->countTotalProjectInDivision($v->id, $year);
foreach($v->children as $d){
foreach ($v->children as $d) {
$v->total += $this->countTotalProjectInDivision($d->id, $year);
}
unset($v->children);
@ -277,27 +290,29 @@ class DashboardBoDController extends Controller
], 200);
}
private function countTotalProjectValueInDivision($id, $year){
private function countTotalProjectValueInDivision($id, $year)
{
return Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('divisi_id', $id)
->pluck('sum')
->first();
}
public function getTotalProjectValuePerDivision($year = '%') {
public function getTotalProjectValuePerDivision($year = '%')
{
$year = $this->interpolateYear($year);
$divisions = Divisi::select('id','name')
$divisions = Divisi::select('id', 'name')
->with('children')
->whereNull('parent')
->get();
// to do : count in more than 1 level child
foreach($divisions as $v){
foreach ($divisions as $v) {
$v->total = $this->countTotalProjectValueInDivision($v->id, $year);
foreach($v->children as $d){
foreach ($v->children as $d) {
$v->total += $this->countTotalProjectValueInDivision($d->id, $year);
}
unset($v->children);
@ -309,16 +324,17 @@ class DashboardBoDController extends Controller
}
public function getDetailExpenditure($year = '%'){
public function getDetailExpenditure($year = '%')
{
$year = $this->interpolateYear($year);
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->orderBy('id', 'desc')
->get();
foreach($projects as $project){
foreach ($projects as $project) {
$lastGantt = MasterFunctionsHelper::getLatestGantt($project->id);
if($project->kode_sortname != ""){
if ($project->kode_sortname != "") {
$resp = $this->getInvoiceIntegration($project->kode_sortname);
$project->invoice = [
'invoiced' => $resp->data->total_invoice_amount ?? 0,
@ -328,12 +344,12 @@ class DashboardBoDController extends Controller
$project->pm = User::find($project->pm_id);
/* $project->header = Activity::where('proyek_id', $project->id)->where('version_gantt_id', $lastGantt['last_gantt_id'])->whereNull('parent_id')->first(); */
if(!isset($lastGantt['last_gantt_id'])){
$project->manPowers = 0;
} else {
$project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count();
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
}
if (!isset($lastGantt['last_gantt_id'])) {
$project->manPowers = 0;
} else {
$project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count();
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
}
$project->lastGanttId = MasterFunctionsHelper::getLatestGantt($project->id);
}
@ -342,5 +358,4 @@ class DashboardBoDController extends Controller
'total_manpowers' => User::count()
], 200);
}
}
}

7
app/Http/Controllers/ProjectController.php

@ -278,7 +278,7 @@ class ProjectController extends Controller
}
try {
$projectsByType = DB::table('m_proyek')
->select('m_type_proyek.name', DB::raw('count(id) as total'))
->select('m_type_proyek.name', DB::raw('count(m_type_proyek.id) as total'))
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id')
->groupBy('m_type_proyek.name')
->get();
@ -340,7 +340,10 @@ class ProjectController extends Controller
public static function setSyncDate($activity_id, $activity, $report) {
$status = AssignMaterial::select('status_activity')->where('activity_id', $activity_id)->first();
if (isset($status->status_activity) && $status->status_activity != 'done') {
if (!isset($status->status_activity)) {
$status->status_activity = 'open';
}
if ($status->status_activity != 'done') {
$minDate = date_create($report->report_date);
$maxDate = date_create($report->report_date);
date_add($maxDate, date_interval_create_from_date_string($activity->duration . " days"));

2
app/Models/AssignMaterial.php

@ -5,6 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\RequestMaterial;
use App\Models\Activity;
use App\Models\ReportActivityMaterial;
class AssignMaterial extends Model
{
@ -35,6 +36,7 @@ class AssignMaterial extends Model
});
static::deleted(function($data) {
$reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete();
$activity = Activity::where('id', $data->activity_id)->first();
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning);
$activity->save();

2
app/Models/UserToProyek.php

@ -14,6 +14,6 @@ class UserToProyek extends Model
protected $fillable = [
'user_id', 'proyek_id', 'rbs', 'project_role', 'group_r', 'max_used', 'standart_rate',
'uom_standart_rate', 'overtime_rate', 'uom_overtime_rate', 'cost_per_used', 'accrue_at',
'base_calender', 'created_at', 'created_by', 'updated_at', 'updated_by'
'base_calender', 'is_customer', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

Loading…
Cancel
Save