Merged in izzati-addfeat-laporan-outstanding-v2 (pull request #401)
tambah baik laporan stok audit keseluruhan
This commit is contained in:
@@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Reports;
|
namespace App\Http\Controllers\Reports;
|
||||||
use App\Cawangan;
|
use App\Cawangan;
|
||||||
|
use App\Gadai;
|
||||||
use App\Helper;
|
use App\Helper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class StokAuditController extends Controller
|
class StokAuditController extends Controller
|
||||||
{
|
{
|
||||||
@@ -38,6 +40,40 @@ class StokAuditController extends Controller
|
|||||||
|
|
||||||
public function getSummaryLaporanStokAudit(Request $request)
|
public function getSummaryLaporanStokAudit(Request $request)
|
||||||
{
|
{
|
||||||
|
$connections = $this->getActiveCawanganConnections();
|
||||||
|
|
||||||
|
// MODE 1: TARIKH SEMASA
|
||||||
|
if ($request->dateOption === 'current') {
|
||||||
|
|
||||||
|
$today = Carbon::today();
|
||||||
|
|
||||||
|
$total_audit = $connections->map(function ($connection) {
|
||||||
|
|
||||||
|
$data = Gadai::on($connection->mysql)
|
||||||
|
->where('tagpalsu', 0)
|
||||||
|
->where(function($q) {
|
||||||
|
$q->where('sttebus', '')
|
||||||
|
->orWhereNull('sttebus');
|
||||||
|
})
|
||||||
|
->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' => 0,
|
||||||
|
'total_ujrah' => $data->sum('ujrah'),
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
// MODE 2: BULAN TERTENTU
|
||||||
|
else {
|
||||||
|
|
||||||
$month = $request->month;
|
$month = $request->month;
|
||||||
$year = $request->year;
|
$year = $request->year;
|
||||||
|
|
||||||
@@ -59,34 +95,24 @@ class StokAuditController extends Controller
|
|||||||
'total_ujrah' => $data->sum('ujrah'),
|
'total_ujrah' => $data->sum('ujrah'),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$getTotalAcrossCawangan = function($property) use($total_audit) {
|
// TOTAL SEMUA CAWANGAN
|
||||||
$total = array_reduce($total_audit->toArray(), function($carry, $subarray) use($property) {
|
$total_all = [
|
||||||
return $carry + $subarray[$property];
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
return $total;
|
|
||||||
};
|
|
||||||
|
|
||||||
$total_all_cawangan_audit = [
|
|
||||||
'cawangan' => 'Total Semua Cawangan',
|
'cawangan' => 'Total Semua Cawangan',
|
||||||
'bilangan_pembiayaan' => $getTotalAcrossCawangan('bilangan_pembiayaan'),
|
'bilangan_pembiayaan' => $total_audit->sum('bilangan_pembiayaan'),
|
||||||
'berat' => $getTotalAcrossCawangan('berat'),
|
'berat' => $total_audit->sum('berat'),
|
||||||
'nilai_marhun' => $getTotalAcrossCawangan('nilai_marhun'),
|
'nilai_marhun' => $total_audit->sum('nilai_marhun'),
|
||||||
'baki_pembiayaan' => $getTotalAcrossCawangan('baki_pembiayaan'),
|
'baki_pembiayaan' => $total_audit->sum('baki_pembiayaan'),
|
||||||
'pembiayaan' => $getTotalAcrossCawangan('pembiayaan'),
|
'pembiayaan' => $total_audit->sum('pembiayaan'),
|
||||||
'upah_belum_bayar' => $getTotalAcrossCawangan('upah_belum_bayar'),
|
'upah_belum_bayar' => $total_audit->sum('upah_belum_bayar'),
|
||||||
'total_utg_onepercent' => $getTotalAcrossCawangan('total_utg_onepercent'),
|
'total_utg_onepercent' => $total_audit->sum('total_utg_onepercent'),
|
||||||
'total_ujrah' => $getTotalAcrossCawangan('total_ujrah'),
|
'total_ujrah' => $total_audit->sum('total_ujrah'),
|
||||||
];
|
];
|
||||||
|
|
||||||
$total_audit->push($total_all_cawangan_audit);
|
$total_audit->push($total_all);
|
||||||
|
|
||||||
if (sizeof($total_audit) == 0) {
|
return response()->json($total_audit, 200);
|
||||||
return response()->json('failed', 200);
|
|
||||||
} else {
|
|
||||||
return response()->json($total_audit, 200);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user