Browse Source

bug fix

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
3b3129d5b7
  1. 14
      app/Models/Activity.php
  2. 18
      app/Models/AssignMaterial.php

14
app/Models/Activity.php

@ -57,6 +57,10 @@ class Activity extends Model
private function updateBobot() private function updateBobot()
{ {
$rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->where('type_activity', 'header')
->first();
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))')
@ -72,10 +76,6 @@ class Activity extends Model
->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){
@ -130,9 +130,9 @@ class Activity extends Model
public function getJobsDoneAttribute() public function getJobsDoneAttribute()
{ {
$tmpPercentage = []; $tmpPercentage = [];
if(!ReportActivityMaterial::where('activity_id', $this->id)->first()) if(!ReportActivityMaterial::where('activity_id', $this->id)->first())
return 0; return 0;
if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get()) if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get())
return 0; return 0;
foreach ($dataPlan as $value) { foreach ($dataPlan as $value) {
$tmpPercentage[] = 100; $tmpPercentage[] = 100;

18
app/Models/AssignMaterial.php

@ -29,32 +29,14 @@ class AssignMaterial extends Model
static::created(function($data) { static::created(function($data) {
$activity = Activity::find($data->activity_id); $activity = Activity::find($data->activity_id);
$material = RequestMaterial::where("id", $data->material_id)->first(); $material = RequestMaterial::where("id", $data->material_id)->first();
$old = $activity->rencana_biaya;
$activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning); $activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning);
$activity->save(); $activity->save();
$msg = Carbon::now()->toDateTimeString() . ": ".$activity->id." ".$activity->name.PHP_EOL;
$msg .= "Added: ".$material->desc." (".floatval($material->price)." * ".floatval($data->qty_planning)."), Cost plan old: ".$old." | +".$activity->rencana_biaya.PHP_EOL;
$msg .= "Data type (".gettype(floatval($material->price))." * ".gettype(floatval($material->qty_planning))."), ".gettype(floatval($old))." | ".gettype(floatval($activity->rencana_biaya)).PHP_EOL;
$msg .= "Data type origin (".gettype($material->price)." * ".gettype($material->qty_planning)."), ".gettype($old)." | ".gettype($activity->rencana_biaya).PHP_EOL;
$msg .= "------".PHP_EOL;
file_put_contents('activity_log.txt', $msg, FILE_APPEND | LOCK_EX);
}); });
static::deleted(function($data) { static::deleted(function($data) {
$activity = Activity::where('id', $data->activity_id)->first(); $activity = Activity::where('id', $data->activity_id)->first();
$old = $activity->rencana_biaya;
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); $activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning);
$activity->save(); $activity->save();
$material = RequestMaterial::where("id", $data->material_id)->first();
$msg = Carbon::now()->toDateTimeString() . ": ".$activity->id." ".$activity->name.PHP_EOL;
$msg .= "Deleted: ".$material->desc." (".floatval($data->budget)." * ".floatval($data->qty_planning)."), Cost plan old: ".$old." | -".$activity->rencana_biaya.PHP_EOL;
$msg .= "Data type (".gettype(floatval($data->budget))." * ".gettype(floatval($data->qty_planning))."), ".gettype(floatval($old))." | ".gettype(floatval($activity->rencana_biaya)).PHP_EOL;
$msg .= "Data type origin (".gettype($data->budget)." * ".gettype($data->qty_planning)."), ".gettype($old)." | ".gettype($activity->rencana_biaya).PHP_EOL;
$msg .= "------".PHP_EOL;
file_put_contents('activity_log.txt', $msg, FILE_APPEND | LOCK_EX);
}); });
} }

Loading…
Cancel
Save