Browse Source

dashboard bod invoice integration

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

100
app/Http/Controllers/DashboardBoDController.php

@ -18,26 +18,56 @@ class DashboardBoDController extends Controller
return $year;
}
private function curlReq($url, $token){
$ch = curl_init();
$headers = [
'Authorization: '.$token
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if ($response === false)
$response = curl_error($ch);
curl_close($ch);
return json_decode($response);
}
private function getInvoiceIntegration($search) {
if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH');
$token = config('api.adw_token');
$response = $this->curlReq($url, $token);
if(@$response->data->project_no == "")
return null;
return $response;
}
// to do
public function getCompanyCashFlow($year = '%') {
$year = $this->interpolateYear($year);
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0;
// we can't use eloquent's sum() method because someone decided to use varchar as datatype in rencana_biaya field
$totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->pluck('sum')
->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();
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->get();
foreach($projects as $project){
$project->expenses = 0;
// expenditure
$assignedMaterials = AssignMaterial::where('proyek_id', $project->id)->get();
foreach($assignedMaterials as $assignedMaterial) {
$reportedMaterials = ReportActivityMaterial::where('assign_material_id', $assignedMaterial->id)->get();
@ -46,39 +76,49 @@ class DashboardBoDController extends Controller
}
}
$totalExpenditure += $project->expenses;
$resp = null;
if($project->kode_sortname != ""){
$resp = $this->getInvoiceIntegration($project->kode_sortname);
/* $resp = $project->kode_sortname; */
$totalInvoice += $resp->data->total_invoice_amount ?? 0;
$totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0;
}
}
return response()->json([
'data' => [
'total_budget' => (int) $totalBudgets ?? 0,
'total_expenditure' => $totalExpenditure,
'total_invoice' => 0,
'total_paid_invoice' => 0,
'total_invoice' => $totalInvoice,
'total_paid_invoice' => $totalPaidInvoice ,
]
], 200);
}
public function getInvoiceOutstanding($year = '%'){
$year = $this->interpolateYear($year);
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->get();
$return = [];
foreach($projects as $project){
$resp = null;
if($project->kode_sortname != ""){
$resp = $this->getInvoiceIntegration($project->kode_sortname);
array_push($return, [
'project' => $project->nama,
'invoiced' => $resp->data->total_invoice_amount ?? 0,
'paid' => $resp->data->total_invoice_paid_amount ?? 0,
'response' => $resp,
]);
}
}
return response()->json([
'data' => [
0 => [
'project' => 'Project A',
'invoiced' => rand(0, 9000000000),
'paid' => rand(0, 9000000000),
],
1 => [
'project' => 'Project B',
'invoiced' => rand(0, 9000000000),
'paid' => rand(0, 9000000000),
],
2 => [
'project' => 'Project C',
'invoiced' => rand(0, 9000000000),
'paid' => rand(0, 9000000000),
],
]
'data' => $return
], 200);
}
// to do
@ -128,6 +168,7 @@ class DashboardBoDController extends Controller
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health){
return Project::where('divisi_id', $divisi)
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('budget_health', $health)
->count();
}
@ -168,6 +209,7 @@ class DashboardBoDController extends Controller
foreach($projectPhases as $phase){
$phase->totalProject = Project::where('phase_id', $phase->id)
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->count();
}
return response()->json([
@ -180,6 +222,7 @@ class DashboardBoDController extends Controller
private function countTotalProjectInDivision($id, $year){
return Project::where('divisi_id', $id)
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->count();
}
@ -208,6 +251,7 @@ class DashboardBoDController extends Controller
private function countTotalProjectValueInDivision($id, $year){
return Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('divisi_id', $id)
->pluck('sum')
->first();

Loading…
Cancel
Save