Merged in afiqhamzah/feat/add-report-keseluruhan-stokaudit-api (pull request #164)
Afiqhamzah/feat/add report keseluruhan stokaudit api
This commit is contained in:
@@ -324,7 +324,7 @@ class BackupStokAuditController extends Controller
|
||||
}
|
||||
}
|
||||
// foreach($cawangan as $cawangan_mysql){
|
||||
|
||||
|
||||
// }
|
||||
|
||||
return 'success';
|
||||
@@ -381,6 +381,8 @@ class BackupStokAuditController extends Controller
|
||||
$audit = StokAudit12::on($cawangan['mysql'])->where('tahun',$tahun);
|
||||
}
|
||||
|
||||
$audit->where('pinjaman', '!=', '0.0');
|
||||
|
||||
$rekodaudit = $audit->get();
|
||||
$totalrekod = $audit->sum('pinjaman');
|
||||
$totalberat = $audit->sum('berat');
|
||||
@@ -403,7 +405,7 @@ class BackupStokAuditController extends Controller
|
||||
public function backupStokAuditProblemAkru(Request $request){
|
||||
|
||||
/* Classify all possible error */
|
||||
|
||||
|
||||
$this->validate($request, [
|
||||
'month' => 'required|numeric',
|
||||
'kodcaw' => 'required',
|
||||
@@ -461,7 +463,7 @@ class BackupStokAuditController extends Controller
|
||||
$ujrah_semasa = $bilang_bln * $upah['ujrah'];
|
||||
$keuntungan_semasa = $onepercentservices->getRoundedMethod($keuntungan_semasa);
|
||||
$ujrah_semasa = $onepercentservices->getRoundedMethod($ujrah_semasa);
|
||||
|
||||
|
||||
$pendapatan = $keuntungan_semasa + $ujrah_semasa;
|
||||
$arraypendapatan = [
|
||||
'keuntungan' => $keuntungan_semasa,
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
use App\Cawangan;
|
||||
use App\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class StokAuditController extends Controller
|
||||
{
|
||||
|
||||
public function getActiveCawanganConnections()
|
||||
{
|
||||
$cawangan_details = Cawangan::select(['details_caw', 'mysql'])->get();
|
||||
|
||||
$cawangan_details = $cawangan_details->filter(fn($x) => !in_array(strtolower($x->details_caw), config('report.excluded_cawangan')));
|
||||
|
||||
$connection_active_cawangan = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
return collect($cawangan_details->filter(fn($x) => in_array($x->mysql, $connection_active_cawangan)));
|
||||
|
||||
}
|
||||
|
||||
public function buildStokAuditModel($month)
|
||||
{
|
||||
// Create the class name dynamically based on the number
|
||||
$className = 'App\StokAudit' . $month;
|
||||
|
||||
// Ensure the class exists
|
||||
if (!class_exists($className)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$model = new $className();
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function getSummaryLaporanStokAudit(Request $request)
|
||||
{
|
||||
$month = $request->month;
|
||||
$year = $request->year;
|
||||
|
||||
$stokAudit = $this->buildStokAuditModel($month);
|
||||
$connections = $this->getActiveCawanganConnections();
|
||||
|
||||
$total_audit = $connections->map(function ($connection) use ($stokAudit, $year) {
|
||||
$data = $stokAudit->on($connection->mysql)->where('tahun', $year)->get();
|
||||
|
||||
return [
|
||||
'cawangan' => $connection->details_caw,
|
||||
'bilangan_pembiayaan' => $data->count(),
|
||||
'berat' => $data->sum('berat'),
|
||||
'nilai_marhun' => $data->sum('nilaimarhun'),
|
||||
'baki_pembiayaan' => $data->sum('bakipjm'),
|
||||
'pembiayaan' => $data->sum('pinjaman'),
|
||||
'upah_belum_bayar' => $data->sum('upahblmbyar'),
|
||||
'total_utg_onepercent' => $data->sum('utgonepercent'),
|
||||
'total_ujrah' => $data->sum('ujrah'),
|
||||
];
|
||||
});
|
||||
|
||||
$getTotalAcrossCawangan = function($property) use($total_audit) {
|
||||
$total = array_reduce($total_audit->toArray(), function($carry, $subarray) use($property) {
|
||||
return $carry + $subarray[$property];
|
||||
}, 0);
|
||||
|
||||
return $total;
|
||||
};
|
||||
|
||||
$total_all_cawangan_audit = [
|
||||
'cawangan' => 'Total Semua Cawangan',
|
||||
'bilangan_pembiayaan' => $getTotalAcrossCawangan('bilangan_pembiayaan'),
|
||||
'berat' => $getTotalAcrossCawangan('berat'),
|
||||
'nilai_marhun' => $getTotalAcrossCawangan('nilai_marhun'),
|
||||
'baki_pembiayaan' => $getTotalAcrossCawangan('baki_pembiayaan'),
|
||||
'pembiayaan' => $getTotalAcrossCawangan('pembiayaan'),
|
||||
'upah_belum_bayar' => $getTotalAcrossCawangan('upah_belum_bayar'),
|
||||
'total_utg_onepercent' => $getTotalAcrossCawangan('total_utg_onepercent'),
|
||||
'total_ujrah' => $getTotalAcrossCawangan('total_ujrah'),
|
||||
];
|
||||
|
||||
$total_audit->push($total_all_cawangan_audit);
|
||||
|
||||
if (sizeof($total_audit) == 0) {
|
||||
return response()->json('failed', 200);
|
||||
} else {
|
||||
return response()->json($total_audit, 200);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -62,6 +62,7 @@ $app->singleton(
|
||||
$app->configure('app');
|
||||
$app->configure('tinker');
|
||||
$app->configure('tennant_master');
|
||||
$app->configure('report');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'excluded_cawangan' => [
|
||||
'lahad datu',
|
||||
]
|
||||
];
|
||||
@@ -11,6 +11,7 @@ $router->group(['prefix' => 'api/reports'], function () use ($router) {
|
||||
$router->get('kawalan-stok/{kod_cawangan}', ['uses' => 'KawalanStokController@getLaporanCawangan']);
|
||||
$router->get('ringkasan-harian', ['uses' => 'RingkasanHarianController@getSummaryLaporanRingkasanHarian']);
|
||||
$router->get('ringkasan-harian/{kod_cawangan}', ['uses' => 'RingkasanHarianController@getLaporanCawangan']);
|
||||
$router->get('stok-audit', ['uses' => 'StokAuditController@getSummaryLaporanStokAudit']);
|
||||
|
||||
$router->get('onepercent/balance/{kod_cawangan}', ['uses' => 'OnePercentController@getKeuntunganImbangDuga']);
|
||||
$router->get('onepercent/ledger/{kod_cawangan}', ['uses' => 'OnePercentController@getKeuntunganLejerAm']);
|
||||
|
||||
Reference in New Issue
Block a user