Merged in afiqhamzah/feat/overall-report (pull request #23)
Afiqhamzah/feat/overall report
This commit is contained in:
@@ -7,6 +7,17 @@ use Illuminate\Support\Facades\DB;
|
||||
class Helper
|
||||
{
|
||||
|
||||
public static function getOnlineArrahnConnection()
|
||||
{
|
||||
|
||||
$online_arrahn_connection = array_filter(config('database.connections'), function ($connection) {
|
||||
if ($connection['database'] === 'online_arrahn') {
|
||||
return $connection;
|
||||
}
|
||||
});
|
||||
|
||||
return array_keys($online_arrahn_connection)[0];
|
||||
}
|
||||
public static function formatNumber($amount)
|
||||
{
|
||||
$formattedAmount = number_format($amount, 2, '.', ',');
|
||||
@@ -134,7 +134,7 @@ class GadaiController extends Controller
|
||||
$current = new Carbon();
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
|
||||
|
||||
try{
|
||||
DB::transaction(function () use ($cawangan, $kodcaw, $request, $current) {
|
||||
$gadai = Gadai::on($cawangan['mysql'])->create([
|
||||
@@ -155,7 +155,7 @@ class GadaiController extends Controller
|
||||
}catch(\Exception $e){
|
||||
|
||||
echo "Gadaian Gagal: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function createold($kodcaw,Request $request){
|
||||
@@ -248,7 +248,7 @@ class GadaiController extends Controller
|
||||
$total_berat = Marhun::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->sum('berat');
|
||||
|
||||
$kadar_raw = KadarUpah::where('min','<=',$total_nilai_marhun)->where('max','>=',$total_nilai_marhun)->first();
|
||||
|
||||
|
||||
$onepercentservices = new OnePercentServices();
|
||||
$keuntungan = $onepercentservices->kiraanKeuntunganSebenar($request->pinjaman,$total_nilai_marhun,$kadar_raw['kadarujrah'],$margin_pinjam);
|
||||
// $upah1 = $request->pinjaman * ($kadar_raw['kadarupdah']/100);
|
||||
@@ -372,7 +372,7 @@ class GadaiController extends Controller
|
||||
|
||||
public function kiraUpahRebet($kodcaw,$norujukan){
|
||||
$onepercentservices = new OnePercentServices();
|
||||
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->first();
|
||||
@@ -715,7 +715,7 @@ class GadaiController extends Controller
|
||||
$gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->update([
|
||||
'semakbarcode'=>'Lulus'
|
||||
]);
|
||||
|
||||
|
||||
return response()->json('success');
|
||||
}else{
|
||||
return response()->json('unavailable');
|
||||
@@ -3160,7 +3160,7 @@ class GadaiController extends Controller
|
||||
->where('gad.hargajualan','!=',null)
|
||||
->where([['t_jual','>=',$request->mula],['t_jual','<=',$request->hingga]])
|
||||
->sum('lelong.pinjaman');
|
||||
|
||||
|
||||
$Tebus += $pembiayaanlelong;
|
||||
|
||||
$rekod_pinjamandiberi = ['Gadai' => $Gadai,'Tebus' => $Tebus];
|
||||
@@ -3871,7 +3871,7 @@ class GadaiController extends Controller
|
||||
}
|
||||
|
||||
public function getOnePercent(Request $request){
|
||||
|
||||
|
||||
$onePercentServices = new OnePercentServices();
|
||||
|
||||
$keuntungan = $onePercentServices->kiraanKeuntunganSebenar($request->pembiayaan,$request->nilaimarhun,$request->kadarujrah,$request->margin);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Reports\AnsuranService as ReportAnsuranService;
|
||||
use App\Transaction;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AnsuranController extends Controller
|
||||
{
|
||||
|
||||
public function getLaporanCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$reportAnsuranService = new ReportAnsuranService($kod_cawangan, $request);
|
||||
return $reportAnsuranService->getCawanganReport();
|
||||
}
|
||||
|
||||
public function getSummaryLaporanAnsuran(Request $request)
|
||||
{
|
||||
$online_array_db_connection = Helper::getOnlineArrahnConnection();
|
||||
|
||||
$ansuran_query = Transaction::on($online_array_db_connection)
|
||||
->leftJoin('transaksi_keuntungan', function ($join) {
|
||||
$join->on('transaction.norujukan', '=', 'transaksi_keuntungan.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'transaksi_keuntungan.tarikh_bayaran');
|
||||
})
|
||||
->where('transaction.trans_type', '=', 'A')
|
||||
->whereDate('transaction.created_at', '>=', date($request->startDate))
|
||||
->whereDate('transaction.created_at', '<=', date($request->endDate))
|
||||
->selectRaw('
|
||||
count(transaction.norujukan) as bilangan_ansuran,
|
||||
sum(transaksi_keuntungan.bayaran_pembiayaan) as bayaran_pembiayaan,
|
||||
sum(transaksi_keuntungan.bayaran_keuntungan) as bayaran_kos_keuntungan,
|
||||
sum(transaction.duit_masuk) as jumlah_bayaran
|
||||
');
|
||||
|
||||
$summary_ansuran = (clone $ansuran_query)->get()->toArray()[0];
|
||||
|
||||
$summary_ansuran_by_cawangan = (clone $ansuran_query)
|
||||
->addSelect('transaction.kodcaw as kod_cawangan')
|
||||
->groupBy('transaction.kodcaw')
|
||||
->get();
|
||||
|
||||
$cawangan_available = Cawangan::on($online_array_db_connection)->select('kodcaw', 'details_caw')->get()->toArray();
|
||||
$kodcaw_array = array_column($cawangan_available, 'kodcaw');
|
||||
$cawangan_detail_array = array_column($cawangan_available, 'details_caw');
|
||||
$kod_caw_with_cawangan_detail_array = array_combine($kodcaw_array, $cawangan_detail_array);
|
||||
|
||||
$summary_ansuran_by_cawangan = $summary_ansuran_by_cawangan->map(function ($ansuran_cawangan) use ($kod_caw_with_cawangan_detail_array) {
|
||||
$ansuran_cawangan->cawangan_detail = $kod_caw_with_cawangan_detail_array[$ansuran_cawangan['kod_cawangan']];
|
||||
return $ansuran_cawangan;
|
||||
});
|
||||
|
||||
$response = [
|
||||
'summary_ansuran_by_cawangan' => $summary_ansuran_by_cawangan,
|
||||
'summary_ansuran' => $summary_ansuran,
|
||||
];
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Cawangan;
|
||||
use App\Gadai;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -10,7 +11,7 @@ use App\Services\Reports\GadaianService as ReportGadaianService;
|
||||
use App\Helper;
|
||||
|
||||
|
||||
class ReportGadaiController extends Controller
|
||||
class GadaianController extends Controller
|
||||
{
|
||||
|
||||
public function getLaporanCawangan(string $kod_cawangan, Request $request)
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Reports\PenebusanService as ReportPenebusanService;
|
||||
use App\Tebus;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PenebusanController extends Controller
|
||||
{
|
||||
|
||||
public function getLaporanCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$reportGadaianService = new ReportPenebusanService($kod_cawangan, $request);
|
||||
return $reportGadaianService->getCawanganReport();
|
||||
}
|
||||
|
||||
public function getSummaryLaporanTebus(Request $request)
|
||||
{
|
||||
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
$active_cawangan_db_name = array_map(function ($db_connection) {
|
||||
return config('database.connections' . '.' . $db_connection . '.' . 'database');
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
$active_cawangan_detail = Cawangan::select('kodcaw', 'details_caw')->whereIn('db_name', $active_cawangan_db_name)->get()->toArray();
|
||||
|
||||
$summary_penebusan_data = array_map(function ($db_connection) use ($request) {
|
||||
$penebusan = Tebus::on($db_connection)
|
||||
->join('gadai', 'tebus.norujukan', '=', 'gadai.norujukan')
|
||||
->where('gadai.upah12', '!=', null)
|
||||
->where('tebus.t_tebus', '>=', $request->startDate)
|
||||
->where('tebus.t_tebus', '<=', $request->endDate)
|
||||
->select(DB::raw('
|
||||
count(tebus.norujukan) as bilangan_tebus,
|
||||
sum(gadai.berat) as berat,
|
||||
sum(gadai.bakipjm) as nilai_pinjaman,
|
||||
sum(tebus.pinjaman) as baki_pinjaman,
|
||||
sum(tebus.nilaimarhun) as nilai_marhun,
|
||||
sum(tebus.bakiupah) as keuntungan_asal,
|
||||
sum(tebus.bakipjm - gadai.bakipjm) as keuntungan_rebet,
|
||||
sum(gadai.bakipjm) + sum(tebus.bakipjm - gadai.bakipjm) as bayaran_penebusan
|
||||
'))
|
||||
->get();
|
||||
|
||||
return $penebusan->toArray();
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
$response = array_map(function ($cawangan_detail, $summary_penebusan_data) {
|
||||
return array_merge($cawangan_detail, $summary_penebusan_data[0]);
|
||||
}, $active_cawangan_detail, $summary_penebusan_data);
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Reports;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\CawanganDetail;
|
||||
use App\Customer;
|
||||
use App\Gadai;
|
||||
use App\Helper;
|
||||
use App\Transaction;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AnsuranService
|
||||
{
|
||||
|
||||
public $kod_cawangan;
|
||||
public $startDate;
|
||||
public $endDate;
|
||||
|
||||
public function __construct($kod_cawangan, Request $request)
|
||||
{
|
||||
$this->kod_cawangan = $kod_cawangan;
|
||||
$this->startDate = $request->startDate;
|
||||
$this->endDate = $request->endDate;
|
||||
}
|
||||
|
||||
public function getCawanganReport()
|
||||
{
|
||||
$online_array_db_connection = Helper::getOnlineArrahnConnection();
|
||||
$cawangan_connection = Cawangan::where('kodcaw', $this->kod_cawangan)->first()->mysql;
|
||||
|
||||
$query_total_ansuran = Transaction::on($online_array_db_connection)
|
||||
->where('transaction.kodcaw', $this->kod_cawangan)
|
||||
->leftJoin('transaksi_keuntungan', function ($join) {
|
||||
$join->on('transaction.norujukan', '=', 'transaksi_keuntungan.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'transaksi_keuntungan.tarikh_bayaran');
|
||||
})
|
||||
->where('transaction.trans_type', '=', 'A')
|
||||
->whereDate('transaction.created_at', '>=', date($this->startDate))
|
||||
->whereDate('transaction.created_at', '<=', date($this->endDate));
|
||||
|
||||
$total_ansuran = $this->getTotalAnsuran($query_total_ansuran);
|
||||
$total_summary_ansuran_teller = $this->getTotalSummaryAnsuranGroupByTeller($query_total_ansuran);
|
||||
$total_summary_ansuran = $this->getTotalSummaryAnsuran($query_total_ansuran);
|
||||
$gadaian_ansuran = $this->getGadaianAnsuran($cawangan_connection, $total_ansuran->pluck('norujukan'));
|
||||
$customer_info = $this->getCustomerInfo($gadaian_ansuran);
|
||||
$cawangan_detail = $this->getCawanganDetail($cawangan_connection);
|
||||
|
||||
$total_ansuran = $total_ansuran->zip($gadaian_ansuran, $customer_info)->map(function ($data) {
|
||||
[$ansuran, $gadaian_ansuran, $customer_info] = $data;
|
||||
|
||||
return [
|
||||
'norujukan' => $ansuran->norujukan,
|
||||
'nama' => $customer_info['nama'],
|
||||
'no_kp' => $gadaian_ansuran->nokp,
|
||||
'teller' => $ansuran->teller,
|
||||
'bayaran_pembiayaan' => $ansuran->bayaran_pembiayaan,
|
||||
'bayaran_keuntungan' => $ansuran->bayaran_kos_keuntungan,
|
||||
'jumlah_ansuran' => $ansuran->jumlah_bayaran,
|
||||
];
|
||||
});
|
||||
|
||||
$total_ansuran = $total_ansuran->groupBy('teller');
|
||||
|
||||
$ansuran_tellers = $total_ansuran->keys();
|
||||
|
||||
$total_ansuran = $total_ansuran
|
||||
->zip($total_summary_ansuran_teller)
|
||||
->map(function ($data) {
|
||||
|
||||
[$ansuran, $summary] = $data;
|
||||
|
||||
return [
|
||||
'ansuran' => $ansuran,
|
||||
'summary_ansuran_teller' => $summary,
|
||||
];
|
||||
});
|
||||
|
||||
$total_ansuran = $ansuran_tellers->combine($total_ansuran);
|
||||
|
||||
$data = [
|
||||
'query' => [
|
||||
'startDate' => Helper::formatDate($this->startDate),
|
||||
'endDate' => Helper::formatDate($this->endDate),
|
||||
],
|
||||
'cawangan_detail' => $cawangan_detail,
|
||||
'total_ansuran' => $total_ansuran,
|
||||
'summary_ansuran' => $total_summary_ansuran,
|
||||
];
|
||||
|
||||
ray($data);
|
||||
return json_encode($data);
|
||||
|
||||
}
|
||||
|
||||
private function getTotalAnsuran($query_total_ansuran)
|
||||
{
|
||||
$total_ansuran = (clone $query_total_ansuran)
|
||||
->selectRaw('
|
||||
transaction.norujukan as norujukan,
|
||||
transaksi_keuntungan.bayaran_pembiayaan as bayaran_pembiayaan,
|
||||
transaksi_keuntungan.bayaran_keuntungan as bayaran_kos_keuntungan,
|
||||
transaction.duit_masuk as jumlah_bayaran,
|
||||
teller
|
||||
');
|
||||
|
||||
return $total_ansuran->get();
|
||||
|
||||
}
|
||||
|
||||
private function getCawanganDetail($cawangan_connection)
|
||||
{
|
||||
$cawangan_detail = CawanganDetail::on($cawangan_connection)->get()
|
||||
->map(function ($detail) {
|
||||
return [
|
||||
'nama' => $detail['namacaw'],
|
||||
'code' => $detail['kodcaw'] . ' Ar-Rahn ' . $detail['cawangan'],
|
||||
'alamat' => $detail['alamat1'],
|
||||
'waktu_operasi' => $detail['alamat4'],
|
||||
];
|
||||
});
|
||||
|
||||
return $cawangan_detail[0];
|
||||
|
||||
}
|
||||
|
||||
private function getTotalSummaryAnsuran(Builder $query_total_ansuran)
|
||||
{
|
||||
|
||||
$total_ansuran = (clone $query_total_ansuran)
|
||||
->selectRaw('
|
||||
count(transaction.norujukan) as sum_norujukan,
|
||||
sum(transaksi_keuntungan.bayaran_pembiayaan) as sum_bayaran_pembiayaan,
|
||||
sum(transaksi_keuntungan.bayaran_keuntungan) as sum_bayaran_kos_keuntungan,
|
||||
sum(transaction.duit_masuk) as sum_jumlah_bayaran,
|
||||
teller
|
||||
');
|
||||
|
||||
return $total_ansuran->get()->toArray()[0];
|
||||
}
|
||||
private function getTotalSummaryAnsuranGroupByTeller(Builder $query_total_ansuran)
|
||||
{
|
||||
|
||||
$total_summary_ansuran_groupByTeller = (clone $query_total_ansuran)
|
||||
->selectRaw('
|
||||
count(transaction.norujukan) as sum_norujukan,
|
||||
sum(transaksi_keuntungan.bayaran_pembiayaan) as sum_bayaran_pembiayaan,
|
||||
sum(transaksi_keuntungan.bayaran_keuntungan) as sum_bayaran_kos_keuntungan,
|
||||
sum(transaction.duit_masuk) as sum_jumlah_bayaran,
|
||||
teller
|
||||
')
|
||||
->groupBy('transaction.teller')
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
return $total_summary_ansuran_groupByTeller;
|
||||
}
|
||||
|
||||
private function getCustomerInfo($total_ansuran)
|
||||
{
|
||||
|
||||
$extract_nokp = $total_ansuran->pluck('nokp');
|
||||
|
||||
$customer_info = Customer::on('mysql7')
|
||||
->select(['nama', 'alamat1', 'kpbaru', 'kplama'])
|
||||
->where(function ($query) use ($extract_nokp) {
|
||||
$query->whereIn('kpbaru', $extract_nokp)
|
||||
->orWhereIn('kplama', $extract_nokp);
|
||||
})
|
||||
->get();
|
||||
|
||||
$customer_info = collect($extract_nokp)->map(function ($nokp) use ($customer_info) {
|
||||
return $customer_info->where('kpbaru', $nokp)->first() ?? $customer_info->where('kplama', $nokp)->first();
|
||||
})->toArray();
|
||||
|
||||
return $customer_info;
|
||||
}
|
||||
|
||||
private function getGadaianAnsuran($cawangan_connection, $list_norujukan)
|
||||
{
|
||||
|
||||
$gadaian_ansuran = Gadai::on($cawangan_connection)
|
||||
->whereIn('norujukan', $list_norujukan)
|
||||
->select('norujukan', 'nokp', 'teller')
|
||||
->get();
|
||||
|
||||
return $gadaian_ansuran;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Reports;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\CawanganDetail;
|
||||
use App\Customer;
|
||||
use App\Helper;
|
||||
use App\Tebus;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PenebusanService
|
||||
{
|
||||
|
||||
public $kod_cawangan;
|
||||
public $startDate;
|
||||
public $endDate;
|
||||
|
||||
public function __construct($kod_cawangan, Request $request)
|
||||
{
|
||||
$this->kod_cawangan = $kod_cawangan;
|
||||
$this->startDate = $request->startDate;
|
||||
$this->endDate = $request->endDate;
|
||||
}
|
||||
|
||||
public function getCawanganReport()
|
||||
{
|
||||
$cawangan_connection = Cawangan::where('kodcaw', $this->kod_cawangan)->first()->mysql;
|
||||
|
||||
$query_total_penebusan = Tebus::on($cawangan_connection);
|
||||
|
||||
$query_total_penebusan->join('gadai', 'tebus.norujukan', '=', 'gadai.norujukan');
|
||||
|
||||
$query_total_penebusan->where('gadai.upah12', '!=', null);
|
||||
$query_total_penebusan->when(!empty($this->startDate) and !empty($this->endDate), function ($q) {
|
||||
return $q->where('t_tebus', '>=', $this->startDate)
|
||||
->where('t_tebus', '<=', $this->endDate);
|
||||
});
|
||||
|
||||
$total_penebusan = $this->getTotalPenebusan($query_total_penebusan);
|
||||
$total_summary_penebusan_teller = $this->getTotalSummaryPenebusanGroupByTeller($query_total_penebusan);
|
||||
$total_summary_penebusan = $this->getTotalSummaryPenebusan($query_total_penebusan);
|
||||
$customer_info = $this->getCustomerInfo($total_penebusan);
|
||||
$cawangan_detail = $this->getCawanganDetail($cawangan_connection);
|
||||
|
||||
$total_penebusan = $total_penebusan->zip($customer_info)->map(function ($data) {
|
||||
|
||||
[$tebus, $customer_info] = $data;
|
||||
|
||||
return [
|
||||
'no_rujukan' => $tebus['norujukan'],
|
||||
'nama' => $customer_info['nama'],
|
||||
'no_kp' => $tebus['nokp'],
|
||||
'tarikh_gadai' => $tebus['t_gadai'],
|
||||
'jbg' => $tebus['jbg'],
|
||||
'nilai_pinjaman' => $tebus['nilai_pinjaman'],
|
||||
'baki_pinjaman' => $tebus['baki_pinjaman'],
|
||||
'kos_keuntungan' => $tebus['kos_keuntungan'],
|
||||
'kos_keuntungan_rebet' => $tebus['kos_keuntungan_rebet'],
|
||||
'bayaran_penebusan' => $tebus['bayaran_penebusan'],
|
||||
'nilai_marhun' => $tebus['nilai_marhun'],
|
||||
'jenis_tebus' => $tebus['jenis_tebus'],
|
||||
'teller' => $tebus['teller'],
|
||||
];
|
||||
|
||||
});
|
||||
|
||||
$total_penebusan = $total_penebusan->groupBy('teller');
|
||||
|
||||
$penebusan_tellers = $total_penebusan->keys();
|
||||
|
||||
$total_penebusan = $total_penebusan
|
||||
->zip($total_summary_penebusan_teller)
|
||||
->map(function ($data) {
|
||||
|
||||
[$penebusan, $summary] = $data;
|
||||
|
||||
return [
|
||||
'penebusan' => $penebusan,
|
||||
'summary_penebusan_teller' => $summary,
|
||||
];
|
||||
});
|
||||
|
||||
$total_penebusan = $penebusan_tellers->combine($total_penebusan);
|
||||
|
||||
$data = [
|
||||
'query' => [
|
||||
'startDate' => Helper::formatDate($this->startDate),
|
||||
'endDate' => Helper::formatDate($this->endDate),
|
||||
],
|
||||
'cawangan_detail' => $cawangan_detail,
|
||||
'penebusan' => $total_penebusan,
|
||||
'summary_penebusan' => $total_summary_penebusan,
|
||||
];
|
||||
|
||||
return json_encode($data);
|
||||
|
||||
}
|
||||
|
||||
private function getCawanganDetail($cawangan_connection)
|
||||
{
|
||||
$cawangan_detail = CawanganDetail::on($cawangan_connection)->get()
|
||||
->map(function ($detail) {
|
||||
return [
|
||||
'nama' => $detail['namacaw'],
|
||||
'code' => $detail['kodcaw'] . ' Ar-Rahn ' . $detail['cawangan'],
|
||||
'alamat' => $detail['alamat1'],
|
||||
'waktu_operasi' => $detail['alamat4'],
|
||||
];
|
||||
});
|
||||
|
||||
return $cawangan_detail[0];
|
||||
|
||||
}
|
||||
|
||||
private function getTotalSummaryPenebusan(Builder $query_total_penebusan)
|
||||
{
|
||||
|
||||
$total_summary_penebusan = (clone $query_total_penebusan)
|
||||
->select(
|
||||
DB::raw('sum(gadai.bakipjm) as nilai_pinjaman'),
|
||||
DB::raw('sum(tebus.pinjaman) as baki_pinjaman'),
|
||||
DB::raw('sum(tebus.bakiupah) as kos_keuntungan'),
|
||||
DB::raw('sum(tebus.bakipjm - gadai.bakipjm) as kos_keuntungan_rebet'),
|
||||
DB::raw('sum(gadai.bakipjm) + sum(tebus.bakipjm - gadai.bakipjm) as bayaran_penebusan'),
|
||||
DB::raw('sum(tebus.nilaimarhun) as nilai_marhun'),
|
||||
)
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
return $total_summary_penebusan[0];
|
||||
}
|
||||
private function getTotalSummaryPenebusanGroupByTeller(Builder $query_total_penebusan)
|
||||
{
|
||||
|
||||
$total_summary_penebusan_groupByTeller = (clone $query_total_penebusan)
|
||||
->select(
|
||||
DB::raw('sum(gadai.bakipjm) as nilai_pinjaman'),
|
||||
DB::raw('sum(tebus.pinjaman) as baki_pinjaman'),
|
||||
DB::raw('sum(tebus.bakiupah) as kos_keuntungan'),
|
||||
DB::raw('sum(tebus.bakipjm - gadai.bakipjm) as kos_keuntungan_rebet'),
|
||||
DB::raw('sum(gadai.bakipjm) + sum(tebus.bakipjm - gadai.bakipjm) as bayaran_penebusan'),
|
||||
DB::raw('sum(tebus.nilaimarhun) as nilai_marhun'),
|
||||
'tebus.teller',
|
||||
)
|
||||
->groupBy('tebus.teller')
|
||||
->get();
|
||||
|
||||
return $total_summary_penebusan_groupByTeller;
|
||||
}
|
||||
|
||||
private function getTotalPenebusan(Builder $query_total_penebusan)
|
||||
{
|
||||
|
||||
$total_penebusan = (clone $query_total_penebusan)
|
||||
->select(
|
||||
'tebus.norujukan',
|
||||
'gadai.nokp',
|
||||
'gadai.t_gadai',
|
||||
'gadai.jbg',
|
||||
'gadai.bakipjm as nilai_pinjaman',
|
||||
'tebus.pinjaman as baki_pinjaman',
|
||||
'tebus.bakiupah as kos_keuntungan',
|
||||
DB::raw('(tebus.bakipjm - gadai.bakipjm) as kos_keuntungan_rebet'),
|
||||
DB::raw('gadai.bakipjm + (tebus.bakipjm - gadai.bakipjm) as bayaran_penebusan'),
|
||||
'tebus.nilaimarhun as nilai_marhun',
|
||||
'tebus.jenistebus as jenis_tebus',
|
||||
'tebus.teller',
|
||||
)
|
||||
->orderBy('tebus.teller')
|
||||
->orderBy('gadai.sirig')
|
||||
->get();
|
||||
|
||||
return $total_penebusan;
|
||||
}
|
||||
|
||||
private function getCustomerInfo($total_penebusan)
|
||||
{
|
||||
|
||||
$extract_nokp = $total_penebusan->pluck('nokp');
|
||||
|
||||
$customer_info = Customer::on('mysql7')
|
||||
->select(['nama', 'alamat1', 'kpbaru', 'kplama'])
|
||||
->where(function ($query) use ($extract_nokp) {
|
||||
$query->whereIn('kpbaru', $extract_nokp)
|
||||
->orWhereIn('kplama', $extract_nokp);
|
||||
})
|
||||
->get();
|
||||
|
||||
$customer_info = collect($extract_nokp)->map(function ($nokp) use ($customer_info) {
|
||||
return $customer_info->where('kpbaru', $nokp)->first() ?? $customer_info->where('kplama', $nokp)->first();
|
||||
})->toArray();
|
||||
|
||||
return $customer_info;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user