tambah laporan peti besi semua cawangan
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Reports;
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Cawangan;
|
use App\Cawangan;
|
||||||
use App\Gadai;
|
use App\Gadai;
|
||||||
|
use App\Vault;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use App\Services\Reports\OutstandingService as ReportOutstandingService;
|
use App\Services\Reports\OutstandingService as ReportOutstandingService;
|
||||||
@@ -83,6 +84,54 @@ class OutstandingController extends Controller
|
|||||||
return response()->json($response);
|
return response()->json($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSummaryLaporanPetibesi(Request $request)
|
||||||
|
{
|
||||||
|
$endDate = $request->endDate;
|
||||||
|
|
||||||
|
// Get active branch DBs from helper
|
||||||
|
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||||
|
|
||||||
|
// Fetch branch details with mysql info
|
||||||
|
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||||
|
->whereIn('mysql', $active_cawangan_db_connection)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
// Get db connections
|
||||||
|
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||||
|
|
||||||
|
// Map branch info for response
|
||||||
|
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||||
|
return [
|
||||||
|
'kodcaw' => $c->kodcaw,
|
||||||
|
'details_caw' => $c->details_caw,
|
||||||
|
];
|
||||||
|
})->values()->toArray();
|
||||||
|
|
||||||
|
// Query petibesi summary for each branch
|
||||||
|
$summary_petibesi_data = array_map(function ($db_connection) use ($endDate) {
|
||||||
|
|
||||||
|
|
||||||
|
// SEMUA
|
||||||
|
$queryAll = Vault::on($db_connection)
|
||||||
|
->selectRaw('bakieod');
|
||||||
|
|
||||||
|
if (!empty($endDate)) {
|
||||||
|
$queryAll->where('tarikh', '=', $endDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_merge(
|
||||||
|
$queryAll->first()->toArray()
|
||||||
|
);
|
||||||
|
}, $active_cawangan_db_connection);
|
||||||
|
|
||||||
|
// Combine data with branch info
|
||||||
|
$response = array_map(function ($cawangan_detail, $petibesi_data) {
|
||||||
|
return array_merge($cawangan_detail, $petibesi_data);
|
||||||
|
}, $active_cawangan_detail, $summary_petibesi_data);
|
||||||
|
|
||||||
|
return response()->json($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,5 +37,7 @@ $router->group(['prefix' => 'api/reports'], function () use ($router) {
|
|||||||
$router->get('aging', ['uses' => 'AgingController@getSummaryLaporanAging']);
|
$router->get('aging', ['uses' => 'AgingController@getSummaryLaporanAging']);
|
||||||
|
|
||||||
$router->get('outstanding', ['uses' => 'OutstandingController@getSummaryLaporanOutstanding']);
|
$router->get('outstanding', ['uses' => 'OutstandingController@getSummaryLaporanOutstanding']);
|
||||||
|
|
||||||
|
$router->get('petibesi', ['uses' => 'OutstandingController@getSummaryLaporanPetibesi']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user