Browse Source

bug fix

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

34
app/Http/Controllers/ActivityController.php

@ -1,5 +1,4 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Activity; use App\Models\Activity;
@ -18,7 +17,7 @@ class ActivityController extends Controller
{ {
public function getByGanttId($id, $proyek_id) 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); $this->cloneTemplate($id, $proyek_id);
} }
@ -29,18 +28,20 @@ class ActivityController extends Controller
private function getDataActivity($id) private function getDataActivity($id)
{ {
$dataHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->first(); $checkHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count(); $finalData = [];
$startDate = date_create($dataHeader->start_date); if($checkHeader > 0){
$endDate = date_create($dataHeader->end_date); $dataHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->first();
$dataHeader->start_date = date_format($startDate,"Y-m-d H:i:s"); $startDate = date_create($dataHeader->start_date);
$dataHeader->end_date = date_format($endDate,"Y-m-d H:i:s"); $endDate = date_create($dataHeader->end_date);
$dataHeader->type = "project"; $dataHeader->start_date = date_format($startDate,"Y-m-d H:i:s");
$dataHeader->text = $dataHeader->name; $dataHeader->end_date = date_format($endDate,"Y-m-d H:i:s");
$finalData[] = $dataHeader; $dataHeader->type = "project";
$data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get(); $dataHeader->text = $dataHeader->name;
$finalData[] = $dataHeader;
if(Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count() == 0) $data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get();
$data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get(); }else{
$data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get();
}
foreach($data as $objRow){ foreach($data as $objRow){
$type = "project"; $type = "project";
@ -117,7 +118,7 @@ class ActivityController extends Controller
private function cloneTemplate($id, $proyek_id) private function cloneTemplate($id, $proyek_id)
{ {
$project = Project::findOrFail($proyek_id); $project = Project::find($proyek_id);
$rootActivity = Activity::create([ $rootActivity = Activity::create([
'version_gantt_id'=>$id, 'version_gantt_id'=>$id,
@ -126,7 +127,7 @@ class ActivityController extends Controller
'kode_sortname'=>$project->kode_sortname, 'kode_sortname'=>$project->kode_sortname,
'start_date'=> $project->mulai_proyek, 'start_date'=> $project->mulai_proyek,
'end_date'=> $project->akhir_proyek, 'end_date'=> $project->akhir_proyek,
'rencana_biaya'=> str_replace(".","", $project->rencana_biaya), 'rencana_biaya'=> $project->rencana_biaya,
'type_activity'=> 'header', 'type_activity'=> 'header',
'created_by'=>$this->currentName, 'created_by'=>$this->currentName,
]); ]);
@ -186,7 +187,6 @@ class ActivityController extends Controller
$parent = $data['parent_id'] ?? null; $parent = $data['parent_id'] ?? null;
if($parent){ if($parent){
$this->updateTypeProject($parent);
Activity::find($parent)->update(["type_activity"=>"project"]); Activity::find($parent)->update(["type_activity"=>"project"]);
CommentActivity::where('activity_id', $parent)->delete(); CommentActivity::where('activity_id', $parent)->delete();
UserToActivity::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', 'planned_start', 'planned_end', 'satuan_id',
'created_at', 'created_by', 'updated_at', 'updated_by' 'created_at', 'created_by', 'updated_at', 'updated_by'
]; ];
// this piece of shit prepend column on create(), causing bugs
protected $attributes = [ //protected $attributes = [
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools' // 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools'
]; //];
protected $appends = [ protected $appends = [
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools' 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools'
@ -57,7 +57,7 @@ class Activity extends Model
private function updateBobot() 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( $totalCost = Activity::select(
DB::raw('sum(cast(rencana_biaya as double precision))') 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) ->where("version_gantt_id", $this->version_gantt_id)
->whereNull("parent_id") ->whereNull("parent_id")
->first(); ->first();
} else {
$rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->where('type_activity', 'header')
->first();
$totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) $totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))
->where("proyek_id", $this->proyek_id) ->where("proyek_id", $this->proyek_id)
->where("version_gantt_id", $this->version_gantt_id) ->where("version_gantt_id", $this->version_gantt_id)
->where("parent_id", $rootActivity->id) ->where("parent_id", $rootActivity->id)
->first(); ->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){ if($totalCost->sum > 0){
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get(); $activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get();

Loading…
Cancel
Save