Merge remote-tracking branch 'origin/main' into prod-kopkb
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Miscellaneous;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Cawangan;
|
||||
use App\Gadai;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\Reports\GadaianService as ReportGadaianService;
|
||||
use App\Helper;
|
||||
use App\Tebus;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
|
||||
class StatistikService
|
||||
{
|
||||
protected $kodcaw;
|
||||
protected $mysql;
|
||||
protected $mula;
|
||||
protected $akhir;
|
||||
|
||||
public function __construct($kodcaw,$mula,$akhir)
|
||||
{
|
||||
$this->kodcaw = $kodcaw;
|
||||
$this->mysql = Cawangan::on('mysql7')->where('kodcaw', $kodcaw)->value('mysql');
|
||||
$this->mula = $mula;
|
||||
$this->akhir = $akhir;
|
||||
}
|
||||
|
||||
public function LaporanStatistik($gadai) : array
|
||||
{
|
||||
$reportPembiayaan = $this->countPawnByType($gadai);
|
||||
$reportLoanAmount = $this->countPawnByLoan($gadai);
|
||||
$reportMarhunValue = $this->countMarhunByValue($gadai);
|
||||
$reportMarhunMargin = $this->countMarhunByMargin($gadai);
|
||||
$reportCustomerJob = $this->countCustomerByJob($gadai);
|
||||
$reportCustomerRace = $this->countCustomerByRace($gadai);
|
||||
// dd($reportCustomerRace);
|
||||
|
||||
return [
|
||||
'reportPembiayaan' => $reportPembiayaan,
|
||||
'reportLoanAmount' => $reportLoanAmount,
|
||||
'reportMarhunValue' => $reportMarhunValue,
|
||||
'reportMarhunMargin' => $reportMarhunMargin,
|
||||
'reportCustomerJob' => $reportCustomerJob,
|
||||
'reportCustomerRace' => $reportCustomerRace,
|
||||
];
|
||||
}
|
||||
|
||||
private function countPawnByType($gadai)
|
||||
{
|
||||
$pembiayaanbaru = Tebus::on($this->mysql)
|
||||
->join('gadai as g1', 'tebus.norujukan', '=', 'g1.norujukan')
|
||||
->join('gadai as g2', function ($join) {
|
||||
$join->on('g2.nokp', '=', 'g1.nokp')
|
||||
->on('g2.t_gadai', '=', 'tebus.t_tebus')
|
||||
->whereRaw('ABS(g2.berat - g1.berat) <= 0.02')
|
||||
->whereColumn('g2.norujukan', '!=', 'g1.norujukan');
|
||||
})
|
||||
->whereBetween('tebus.t_tebus', [$this->mula, $this->akhir])
|
||||
->groupBy('tebus.norujukan')
|
||||
->selectRaw("
|
||||
tebus.norujukan as norujukan_tebus,
|
||||
MAX(g2.norujukan) as norujukanpembiayaansemula,
|
||||
MAX(g1.taglel) as taglel_lama
|
||||
")
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
$pembiayaanbaruNorujukan = array_column($pembiayaanbaru, 'norujukanpembiayaansemula');
|
||||
$filteredNorujukanLelongan = array_column(
|
||||
array_filter($pembiayaanbaru, function ($item) {
|
||||
return $item['taglel_lama'] == 1;
|
||||
}),
|
||||
'norujukanpembiayaansemula'
|
||||
);
|
||||
$filteredPSNorujukan = array_column(
|
||||
array_filter($pembiayaanbaru, function ($item) {
|
||||
return $item['taglel_lama'] == 0;
|
||||
}),
|
||||
'norujukanpembiayaansemula'
|
||||
);
|
||||
|
||||
|
||||
$pembiayaanbaru = $gadai->whereIn('norujukan', $filteredPSNorujukan)->count();
|
||||
$pembiayaansemula = $gadai->whereNotIn('norujukan', $pembiayaanbaruNorujukan)->count();
|
||||
$lelongan = $gadai->whereIn('norujukan', $filteredNorujukanLelongan)->count();
|
||||
|
||||
return [
|
||||
'pembiayaanbaru' => $pembiayaanbaru,
|
||||
'pembiayaansemula' => $pembiayaansemula,
|
||||
'lelongan' => $lelongan
|
||||
];
|
||||
}
|
||||
|
||||
private function countPawnByLoan($gadai)
|
||||
{
|
||||
return collect($gadai)->countBy(function ($item) {
|
||||
$loan = $item['pinjaman'];
|
||||
|
||||
if ($loan <= 400.99) return '< 400.99';
|
||||
if ($loan >= 401 && $loan <= 2000) return '401 - 2000';
|
||||
if ($loan >= 2001 && $loan <= 24999) return '2001 - 2499';
|
||||
if ($loan >= 2500) return '>= 2500';
|
||||
if ($loan > 101000) return '>101000';
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
private function countMarhunByValue($gadai)
|
||||
{
|
||||
return collect($gadai)->countBy(function ($item) {
|
||||
$nilaimarhun = $item['nilaimarhun'];
|
||||
|
||||
if ($nilaimarhun <= 400.99) return '< 1-400';
|
||||
if ($nilaimarhun >= 401 && $nilaimarhun <= 2000) return '401-2000';
|
||||
if ($nilaimarhun > 2001) return '> 2001';
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
private function countMarhunByMargin($gadai)
|
||||
{
|
||||
return collect($gadai)->countBy(function ($item) {
|
||||
$margin= $item['percentpinj'];
|
||||
|
||||
if ($margin >= 10 && $margin <= 40.99) return '10-40.99';
|
||||
if ($margin >= 41 && $margin <= 60.99) return '41-60.99';
|
||||
if ($margin >= 61 && $margin <= 80) return '> 61-80';
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
private function countCustomerByJob($gadai)
|
||||
{
|
||||
$jobMap = [
|
||||
1 => 'Peniaga',
|
||||
2 => 'Pekerja Swasta',
|
||||
3 => 'Pekerja Kerajaan',
|
||||
4 => 'Bekerja Sendiri',
|
||||
5 => 'Suri Rumah',
|
||||
6 => 'Lain-lain',
|
||||
];
|
||||
|
||||
return collect($gadai)->countBy(function ($item) use ($jobMap) {
|
||||
$kodkerja = floatval($item['kodkerja']);
|
||||
return $jobMap[$kodkerja] ?? 'Lain-lain';
|
||||
})->toArray();
|
||||
|
||||
}
|
||||
|
||||
private function countCustomerByRace($gadai){
|
||||
|
||||
$raceMap = [
|
||||
'M' => 'Melayu',
|
||||
'C' => 'Cina',
|
||||
'I' => 'India',
|
||||
'L' => 'Lain-lain',
|
||||
];
|
||||
|
||||
return collect($gadai)->countBy(function ($item) use ($raceMap) {
|
||||
return $raceMap[$item['bangsa']] ?? 'Lain-lain';
|
||||
|
||||
})->toArray();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -377,7 +377,8 @@ class ImbangDugaService
|
||||
return $transaction->trans_type !== 'A';
|
||||
})->sum('keuntungan_rebet');
|
||||
|
||||
$total = $total_ansuran + $total_tebus + $get_imbangduga['keun_sebenar'];
|
||||
$backdate_keun_sebenar = isset($get_imbangduga['keun_sebenar']) ? $get_imbangduga['keun_sebenar'] : 0;
|
||||
$total = $total_ansuran + $total_tebus + $backdate_keun_sebenar;
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class LelonganService
|
||||
$marhun_lelongan = $this->getMarhunLelongan($total_lelongan, $cawangan_connection);
|
||||
$cawangan_detail = $this->getCawanganDetail($cawangan_connection);
|
||||
|
||||
$total_lelongan = $total_lelongan->zip($customer_info, $marhun_lelongan)->map(function ($data) {
|
||||
$total_lelongan = $total_lelongan->zip($customer_info, $marhun_lelongan)->map(function ($data) use ($total_lelongan) {
|
||||
|
||||
[$lelong, $customer_info, $marhun_lelongan] = $data;
|
||||
|
||||
@@ -76,31 +76,38 @@ class LelonganService
|
||||
'bakipjm' => $lelong['bakipjm'],
|
||||
'keuntungan' => $lelong['bakiupah'],
|
||||
'cajlelong' => $lelong['cajlelong'],
|
||||
'hargaasas' => $lelong['hargaasas'],
|
||||
'hargajual' => $lelong['hargajual'],
|
||||
'baki' => $lelong['baki'],
|
||||
'teller' => $lelong['teller'],
|
||||
];
|
||||
dd($data);
|
||||
});
|
||||
|
||||
|
||||
$total_lelongan = $total_lelongan->groupBy('teller');
|
||||
|
||||
$lelongan_tellers = $total_lelongan->keys();
|
||||
$result = [];
|
||||
|
||||
$total_lelongan = $total_lelongan
|
||||
->zip($total_summary_lelongan_teller)
|
||||
->map(function ($data) {
|
||||
foreach ($total_lelongan as $teller => $lelongan) {
|
||||
$result[$teller] = [
|
||||
'lelongan' => $lelongan->values(),
|
||||
'summary_lelongan_teller' => $total_summary_lelongan_teller[$teller] ?? [
|
||||
'total_lelongan' => 0,
|
||||
'total_berat' => 0,
|
||||
'total_nilai_marhun' => 0,
|
||||
'total_pembiayaan' => 0,
|
||||
'total_bakipjm' => 0,
|
||||
'total_keuntungan' => 0,
|
||||
'total_cajlelong' => 0,
|
||||
'total_hargaasas' => 0,
|
||||
'total_hargajual' => 0,
|
||||
'total_baki' => 0,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
[$lelongan, $summary] = $data;
|
||||
$total_lelongan = collect($result);
|
||||
|
||||
return [
|
||||
'lelongan' => $lelongan,
|
||||
'summary_lelongan_teller' => $summary,
|
||||
];
|
||||
});
|
||||
|
||||
$total_lelongan = $lelongan_tellers->combine($total_lelongan);
|
||||
|
||||
$data = [
|
||||
'query' => [
|
||||
@@ -143,6 +150,7 @@ class LelonganService
|
||||
sum(gadai.bakipjm) as total_bakipjm,
|
||||
sum(lelong.bakiupah) as total_keuntungan,
|
||||
sum(lelong.cajlelong) as total_cajlelong,
|
||||
sum(lelong.hargaasas) as total_hargaasas,
|
||||
sum(lelong.hargajual) as total_hargajual,
|
||||
sum(lelong.baki) as total_baki')
|
||||
->get()
|
||||
@@ -155,32 +163,54 @@ class LelonganService
|
||||
'total_bakipjm' => $x['total_bakipjm'],
|
||||
'total_keuntungan' => $x['total_keuntungan'],
|
||||
'total_cajlelong' => $x['total_cajlelong'],
|
||||
'total_hargaasas' => $x['total_hargaasas'],
|
||||
'total_hargajual' => $x['total_hargajual'],
|
||||
'total_baki' => $x['total_baki']
|
||||
];
|
||||
});
|
||||
// dd($total_summary_lelongan);
|
||||
|
||||
return $total_summary_lelongan[0];
|
||||
}
|
||||
// private function getTotalSummaryLelonganGroupByTeller(Builder $query_total_lelongan)
|
||||
// {
|
||||
|
||||
// $total_summary_lelongan_groupByTeller = (clone $query_total_lelongan)
|
||||
// ->selectRaw('count(lelong.norujukan) as total_lelongan,
|
||||
// sum(lelong.berat) as total_berat,
|
||||
// sum(lelong.nilaimarhun) as total_nilai_marhun,
|
||||
// sum(lelong.pinjaman) as total_pembiayaan,
|
||||
// sum(gadai.bakipjm) as total_bakipjm,
|
||||
// sum(lelong.bakiupah) as total_keuntungan,
|
||||
// sum(lelong.cajlelong) as total_cajlelong,
|
||||
// sum(lelong.hargaasas) as total_hargaasas,
|
||||
// sum(lelong.hargajual) as total_hargajual,
|
||||
// sum(lelong.baki) as total_baki')
|
||||
// ->groupBy('lelong.teller')
|
||||
// ->get();
|
||||
// return $total_summary_lelongan_groupByTeller;
|
||||
// }
|
||||
private function getTotalSummaryLelonganGroupByTeller(Builder $query_total_lelongan)
|
||||
{
|
||||
|
||||
$total_summary_lelongan_groupByTeller = (clone $query_total_lelongan)
|
||||
->selectRaw('count(lelong.norujukan) as total_lelongan,
|
||||
sum(lelong.berat) as total_berat,
|
||||
sum(lelong.nilaimarhun) as total_nilai_marhun,
|
||||
sum(lelong.pinjaman) as total_pembiayaan,
|
||||
sum(gadai.bakipjm) as total_bakipjm,
|
||||
sum(lelong.bakiupah) as total_keuntungan,
|
||||
sum(lelong.cajlelong) as total_cajlelong,
|
||||
sum(lelong.hargajual) as total_hargajual,
|
||||
sum(lelong.baki) as total_baki')
|
||||
return (clone $query_total_lelongan)
|
||||
->selectRaw('
|
||||
lelong.teller,
|
||||
count(lelong.norujukan) as total_lelongan,
|
||||
sum(lelong.berat) as total_berat,
|
||||
sum(lelong.nilaimarhun) as total_nilai_marhun,
|
||||
sum(lelong.pinjaman) as total_pembiayaan,
|
||||
sum(gadai.bakipjm) as total_bakipjm,
|
||||
sum(lelong.bakiupah) as total_keuntungan,
|
||||
sum(lelong.cajlelong) as total_cajlelong,
|
||||
sum(lelong.hargaasas) as total_hargaasas,
|
||||
sum(lelong.hargajual) as total_hargajual,
|
||||
sum(lelong.baki) as total_baki
|
||||
')
|
||||
->groupBy('lelong.teller')
|
||||
->get();
|
||||
return $total_summary_lelongan_groupByTeller;
|
||||
->get()
|
||||
->keyBy('teller'); // ⭐ PENTING
|
||||
}
|
||||
|
||||
|
||||
private function getTotalLelongan(Builder $query_total_lelongan)
|
||||
{
|
||||
$total_lelongan = (clone $query_total_lelongan)
|
||||
@@ -199,6 +229,7 @@ class LelonganService
|
||||
'gadai.bakipjm',
|
||||
'lelong.bakiupah',
|
||||
'lelong.cajlelong',
|
||||
'lelong.hargaasas',
|
||||
'lelong.hargajual',
|
||||
'lelong.baki')
|
||||
->orderBy('lelong.teller')
|
||||
@@ -311,6 +342,7 @@ class LelonganService
|
||||
'bakipjm' => $lelong['bakipjm'],
|
||||
'keuntungan' => $lelong['bakiupah'],
|
||||
'cajlelong' => $lelong['cajlelong'],
|
||||
'hargaasas' => $lelong['hargaasas'],
|
||||
'hargajual' => $lelong['hargajual'],
|
||||
'baki' => $lelong['baki'],
|
||||
'teller' => $lelong['teller'],
|
||||
|
||||
@@ -1322,7 +1322,7 @@ class RingkasanHarianService
|
||||
return floatval($totalSerahan);
|
||||
}
|
||||
|
||||
return floatval(0);
|
||||
return floatval($serahanpkbTawarruq);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user