Browse Source

Merge pull request 'dev-msy' (#2) from dev-msy into staging

Reviewed-on: OSPRO/ADW-Backend#2
pull/3/head
yusuf 2 years ago
parent
commit
c54235b7ba
  1. 1
      .gitignore
  2. 14
      app/Http/Controllers/ActivityController.php
  3. 19
      app/Http/Controllers/AssignMaterialController.php
  4. 30
      app/Http/Controllers/DivisiController.php
  5. 1
      app/Http/Controllers/MaterialResourceController.php
  6. 43
      app/Http/Controllers/ReportActivityMaterialController.php
  7. 3
      app/Http/Controllers/RequestMaterialController.php
  8. 3
      app/Models/AssignMaterial.php
  9. 19
      app/Models/Divisi.php
  10. 27
      app/Models/ReportActivityMaterial.php
  11. 3
      app/Models/RequestMaterial.php

1
.gitignore vendored

@ -10,3 +10,4 @@ Homestead.yaml
api-testing.http api-testing.http
bootstrap/backup bootstrap/backup
.config-prod.json .config-prod.json
activity_log.txt

14
app/Http/Controllers/ActivityController.php

@ -325,8 +325,8 @@ class ActivityController extends Controller
} }
$data = Activity::find($id); $data = Activity::find($id);
$oldRencanaBiaya = (int)$data->rencana_biaya; $oldRencanaBiaya = $data->rencana_biaya;
$newRencanaBiaya = (int)$request->rencana_biaya; $newRencanaBiaya = str_replace(",",".",$request->rencana_biaya);
if($oldRencanaBiaya==$newRencanaBiaya){ if($oldRencanaBiaya==$newRencanaBiaya){
$updateBobot = false; $updateBobot = false;
}else{ }else{
@ -341,7 +341,6 @@ class ActivityController extends Controller
$dataUpdate['type_activity'] = $request->type; $dataUpdate['type_activity'] = $request->type;
} }
if($data){ if($data){
$upactual = false;
$result = $data->update($dataUpdate); $result = $data->update($dataUpdate);
if($result){ if($result){
if($parent && (int)$parent > 0){ if($parent && (int)$parent > 0){
@ -448,6 +447,7 @@ class ActivityController extends Controller
$data = Activity::find($id); $data = Activity::find($id);
if($data){ if($data){
$data->progress = (int)$data->persentase_progress/100; $data->progress = (int)$data->persentase_progress/100;
$data->rencana_biaya = str_replace(".", ",", $data->rencana_biaya);
$data->jobs_done = $this->sumVolumeActualMaterial($data->id); $data->jobs_done = $this->sumVolumeActualMaterial($data->id);
$data->assign_hr = $this->getUserActivity($data->id); $data->assign_hr = $this->getUserActivity($data->id);
$data->assign_tools = $this->getToolsActivity($data->id); $data->assign_tools = $this->getToolsActivity($data->id);
@ -475,14 +475,6 @@ class ActivityController extends Controller
} }
} }
private function calculateProgress($id)
{
$sumBobot = Activity::where("parent_id", $id)->sum("bobot_planning");
$dataActivity = Activity::find($id);
$restBobot = $dataActivity->bobot_planning - $sumBobot;
return $restBobot;
}
private function updatePersentaseProgress($id) private function updatePersentaseProgress($id)
{ {
$sumProgress = Activity::where("parent_id", $id)->sum("persentase_progress"); $sumProgress = Activity::where("parent_id", $id)->sum("persentase_progress");

19
app/Http/Controllers/AssignMaterialController.php

@ -99,7 +99,16 @@ class AssignMaterialController extends Controller
public function datatables(Request $request){ public function datatables(Request $request){
$id_activity = $request->query('idact'); $id_activity = $request->query('idact');
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom")->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")->where('assign_material_to_activity.activity_id', $id_activity)->get(); $data = AssignMaterial::select(
"assign_material_to_activity.*","m.description as material_name", "m.uom as uom"
)
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $id_activity)
->orderBy('plan_date', 'desc')
->get();
foreach($data as $d){
$d->budget = str_replace(".", ",", $d->budget);
}
return Datatables::of($data) return Datatables::of($data)
->addIndexColumn() ->addIndexColumn()
->addColumn('action', function($row){ ->addColumn('action', function($row){
@ -111,7 +120,13 @@ class AssignMaterialController extends Controller
public function datatablesForReportActivity(Request $request){ public function datatablesForReportActivity(Request $request){
$id_activity = $request->query('idact'); $id_activity = $request->query('idact');
$data = AssignMaterial::select(AssignMaterial::raw('SUM(qty_planning) as qty_planning'), "m.description as material_name", "assign_material_to_activity.activity_id as activity_id") $data =
AssignMaterial::select(
AssignMaterial::raw(
'SUM(qty_planning) as qty_planning'),
"m.description as material_name",
"assign_material_to_activity.activity_id as activity_id"
)
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->groupBy("m.description") ->groupBy("m.description")
->groupBy("assign_material_to_activity.activity_id") ->groupBy("assign_material_to_activity.activity_id")

30
app/Http/Controllers/DivisiController.php

@ -7,10 +7,20 @@ use App\Models\Divisi;
class DivisiController extends Controller class DivisiController extends Controller
{ {
private function getAllChildren($divisi, $depth = 0, $array = []) {
$array[$divisi->id] = $divisi->name;
foreach($divisi->children as $child){
$array = $this->getAllChildren($child, $depth + 1, $array);
}
return $array;
}
public function add(Request $request){ public function add(Request $request){
$this->validate($request, [ $this->validate($request, [
'name' => 'required', 'name' => 'required',
'description' => 'required' 'description' => 'string',
'parent' => 'integer'
]); ]);
$data = $request->all(); $data = $request->all();
@ -53,7 +63,6 @@ class DivisiController extends Controller
$delete = $data->delete(); $delete = $data->delete();
if(!$delete) if(!$delete)
return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500); return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500);
@ -64,6 +73,9 @@ class DivisiController extends Controller
{ {
$payload = $request->all(); $payload = $request->all();
if($payload['columns'][0]['value'] == "")
$this->list();
$dataBuilder = $this->setUpPayload($payload, 'm_divisi'); $dataBuilder = $this->setUpPayload($payload, 'm_divisi');
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
@ -75,12 +87,16 @@ class DivisiController extends Controller
public function list() public function list()
{ {
$data = Divisi::all(); $parentMenus = Divisi::whereNull('parent')->with('children')->get();
$countData = $data->count(); $divisions = [];
foreach($parentMenus as $menu){
if(!$data) $childs = $this->getAllChildren($menu);
$divisions = $divisions + $childs;
}
$countData = count($divisions);
if($countData == 0)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200);
} }
} }

1
app/Http/Controllers/MaterialResourceController.php

@ -18,6 +18,7 @@ class MaterialResourceController extends Controller
]); ]);
$data = $request->all(); $data = $request->all();
$data['description'] = trim($data['description']);
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;

43
app/Http/Controllers/ReportActivityMaterialController.php

@ -17,31 +17,15 @@ class ReportActivityMaterialController extends Controller
'qty' => 'required' 'qty' => 'required'
]); ]);
$valAssignMaterialId = AssignMaterial::where('activity_id', $request->activity_id)->first();
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
$data['assign_material_id'] = $valAssignMaterialId->id; $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first();
$checkPrice = AssignMaterial::where("id", $valAssignMaterialId->id)->first(); if(!ReportActivityMaterial::create($data))
$price = $checkPrice->budget; return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400]);
$updateActivity = Activity::find($request->activity_id);
if($updateActivity){
$costActualOld = $updateActivity->biaya_actual == null ? 0 : (int)$updateActivity->biaya_actual;
$costActualNew = $costActualOld + ($price*$request->qty);
$updateActivity->biaya_actual = $costActualNew;
$updateActivity->save();
$result = ReportActivityMaterial::create($data);
if($result){
$this->countForProgress($request->activity_id); $this->countForProgress($request->activity_id);
return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200]); return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200]);
}else{
return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400]);
}
}else{
return response()->json(['status'=>'success','message'=>'Update cost actual failed','code'=>400]);
}
} }
public function updateStatusStartFinish(Request $request){ public function updateStatusStartFinish(Request $request){
@ -71,21 +55,10 @@ class ReportActivityMaterialController extends Controller
public function delete($id) public function delete($id)
{ {
$data = ReportActivityMaterial::find($id); if(!ReportActivityMaterial::findOrFail($id)->delete())
return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400);
die();
}
if($delete){ return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200);
return response()->json(['status'=>'success','message'=>'data menu successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data menu failed deleted!','code'=>400], 400);
}
} }
private function countForProgress($id) private function countForProgress($id)

3
app/Http/Controllers/RequestMaterialController.php

@ -19,7 +19,8 @@ class RequestMaterialController extends Controller
]); ]);
$data = $request->all(); $data = $request->all();
$data['price'] = str_replace(",", ".", $data['price']);
$data['qty'] = str_replace(",", ".", $data['qty']);
$data['status'] = "fom"; $data['status'] = "fom";
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;

3
app/Models/AssignMaterial.php

@ -20,8 +20,7 @@ class AssignMaterial extends Model
protected $casts = [ protected $casts = [
'id' => 'integer', 'id' => 'integer',
'budget' => 'float', 'budget' => 'string',
'qty_planning' => 'float',
]; ];
public static function boot() { public static function boot() {

19
app/Models/Divisi.php

@ -13,10 +13,29 @@ class Divisi extends Model
protected $fillable = [ protected $fillable = [
'name', 'name',
'parent',
'description', 'description',
'created_at', 'created_at',
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by' 'updated_by'
]; ];
public static function boot() {
parent::boot();
static::deleting(function($data) {
$data->children()->delete();
});
}
public function parent()
{
return $this->belongsTo('App\Models\Divisi','parent')->where('parent', null)->with('parent');
}
public function children()
{
return $this->hasMany('App\Models\Divisi','parent')->with('children');
}
} }

27
app/Models/ReportActivityMaterial.php

@ -3,6 +3,8 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Models\Activity;
use App\Models\AssignMaterial;
class ReportActivityMaterial extends Model class ReportActivityMaterial extends Model
{ {
@ -15,4 +17,29 @@ class ReportActivityMaterial extends Model
'activity_id', 'user_id', 'qty', 'lat', 'lon','assign_material_id', 'activity_id', 'user_id', 'qty', 'lat', 'lon','assign_material_id',
'report_date', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' 'report_date', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'
]; ];
public static function boot() {
parent::boot();
static::created(function($data) {
$activity = Activity::find($data->activity_id);
$assignedMaterial = AssignMaterial::find($data->assign_material_id);
$activity->biaya_actual += floatval($assignedMaterial->budget) * floatval($data->qty);
$activity->save();
});
static::deleted(function($data) {
$activity = Activity::find($data->activity_id);
$assignedMaterial = AssignMaterial::find($data->assign_material_id);
$activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty);
$activity->save();
});
}
} }

3
app/Models/RequestMaterial.php

@ -13,8 +13,7 @@ class RequestMaterial extends Model
protected $casts = [ protected $casts = [
'id' => 'integer', 'id' => 'integer',
'price' => 'float', 'price' => 'string',
'qty' => 'float',
]; ];
protected $fillable = [ protected $fillable = [

Loading…
Cancel
Save