Browse Source

calculate project expenditures

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
ae5b138096
  1. 32
      app/Http/Controllers/DashboardBoDController.php

32
app/Http/Controllers/DashboardBoDController.php

@ -5,8 +5,10 @@ namespace App\Http\Controllers;
use App\Models\Project; use App\Models\Project;
use App\Models\Divisi; use App\Models\Divisi;
use App\Models\ProjectPhase; use App\Models\ProjectPhase;
use App\Models\AssignMaterial;
use App\Models\ReportActivityMaterial;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use DB; use Illuminate\Support\Facades\DB;
class DashboardBoDController extends Controller class DashboardBoDController extends Controller
{ {
@ -26,12 +28,32 @@ class DashboardBoDController extends Controller
->pluck('sum') ->pluck('sum')
->first(); ->first();
/* $projectsWithMaterials = DB::table('m_proyek as p') */
/* ->join('assign_material_to_activity as ama', 'p.id', '=', 'ama.proyek_id') */
/* ->join('report_activity_material as ram', 'ama.id', '=', 'ram.assign_material_id') */
/* ->where('p.mulai_proyek', 'like', $year) */
/* ->get(); */
$totalExpenditure = 0;
$projects = Project::where('mulai_proyek', 'like', $year)->get();
foreach($projects as $project){
$project->expenses = 0;
$assignedMaterials = AssignMaterial::where('proyek_id', $project->id)->get();
foreach($assignedMaterials as $assignedMaterial) {
$reportedMaterials = ReportActivityMaterial::where('assign_material_id', $assignedMaterial->id)->get();
foreach($reportedMaterials as $reportedMaterial) {
$project->expenses += $reportedMaterial->qty * $assignedMaterial->budget;
}
}
$totalExpenditure += $project->expenses;
}
return response()->json([ return response()->json([
'data' => [ 'data' => [
'total_budget' => (int) $totalBudgets ?? rand(0,10000000000), 'total_budget' => (int) $totalBudgets ?? 0,
'total_expenditure' => rand(0,10000000000), // to do integrasi 'total_expenditure' => $totalExpenditure,
'total_invoice' => rand(0,10000000000), 'total_invoice' => 0,
'total_paid_invoice' => rand(0,10000000000), 'total_paid_invoice' => 0,
] ]
], 200); ], 200);
} }

Loading…
Cancel
Save