Browse Source

bug fix

pull/3/head
satori 2 years ago
parent
commit
8608510f6e
  1. 14
      app/Http/Controllers/ActivityController.php
  2. BIN
      app/Models/.Activity.php.swp
  3. 23
      app/Models/Activity.php

14
app/Http/Controllers/ActivityController.php

@ -1,5 +1,4 @@
<?php
namespace App\Http\Controllers;
use App\Models\Activity;
@ -18,7 +17,7 @@ class ActivityController extends Controller
{
public function getByGanttId($id, $proyek_id)
{
if(Activity::where("version_gantt_id", $id)->count() == 0) {
if(Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) {
$this->cloneTemplate($id, $proyek_id);
}
@ -29,6 +28,8 @@ class ActivityController extends Controller
private function getDataActivity($id)
{
$checkHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count(); $finalData = [];
if($checkHeader > 0){
$dataHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->first();
$startDate = date_create($dataHeader->start_date);
$endDate = date_create($dataHeader->end_date);
@ -38,9 +39,9 @@ class ActivityController extends Controller
$dataHeader->text = $dataHeader->name;
$finalData[] = $dataHeader;
$data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get();
if(Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count() == 0)
}else{
$data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get();
}
foreach($data as $objRow){
$type = "project";
@ -117,7 +118,7 @@ class ActivityController extends Controller
private function cloneTemplate($id, $proyek_id)
{
$project = Project::findOrFail($proyek_id);
$project = Project::find($proyek_id);
$rootActivity = Activity::create([
'version_gantt_id'=>$id,
@ -126,7 +127,7 @@ class ActivityController extends Controller
'kode_sortname'=>$project->kode_sortname,
'start_date'=> $project->mulai_proyek,
'end_date'=> $project->akhir_proyek,
'rencana_biaya'=> str_replace(".","", $project->rencana_biaya),
'rencana_biaya'=> $project->rencana_biaya,
'type_activity'=> 'header',
'created_by'=>$this->currentName,
]);
@ -186,7 +187,6 @@ class ActivityController extends Controller
$parent = $data['parent_id'] ?? null;
if($parent){
$this->updateTypeProject($parent);
Activity::find($parent)->update(["type_activity"=>"project"]);
CommentActivity::where('activity_id', $parent)->delete();
UserToActivity::where('activity_id', $parent)->delete();

BIN
app/Models/.Activity.php.swp

Binary file not shown.

23
app/Models/Activity.php

@ -25,10 +25,10 @@ class Activity extends Model
'planned_start', 'planned_end', 'satuan_id',
'created_at', 'created_by', 'updated_at', 'updated_by'
];
protected $attributes = [
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools'
];
// this piece of shit prepend column on create(), causing bugs
//protected $attributes = [
// 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools'
//];
protected $appends = [
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools'
@ -57,7 +57,7 @@ class Activity extends Model
private function updateBobot()
{
if(Activity::where('version_gantt_id', $this->version_gantt_id)->where("proyek_id", $this->proyek_id)->where('type_activity', 'header')->count() == 0)
if(Activity::where('version_gantt_id', $this->version_gantt_id)->where("proyek_id", $this->proyek_id)->where('type_activity', 'header')->count() == 0) {
$totalCost = Activity::select(
DB::raw('sum(cast(rencana_biaya as double precision))')
)
@ -65,17 +65,18 @@ class Activity extends Model
->where("version_gantt_id", $this->version_gantt_id)
->whereNull("parent_id")
->first();
$rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->where('type_activity', 'header')
->first();
} else {
$totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))
->where("proyek_id", $this->proyek_id)
->where("version_gantt_id", $this->version_gantt_id)
->where("parent_id", $rootActivity->id)
->first();
}
$rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->where('type_activity', 'header')
->first();
if($totalCost->sum > 0){
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get();

Loading…
Cancel
Save