Files
lelong/app/Http/Controllers/NotisController.php
T
ismailmasseran e29a5891c8 Bugfix/list clickup issue (#5)
Reviewed-on: #5
Co-authored-by: ISMAIL MASSERAN <ismail@koppkb.com>
Co-committed-by: ISMAIL MASSERAN <ismail@koppkb.com>
2026-10-19 13:30:36 +08:00

2636 lines
106 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Jobs\GenerateJanaNotisPdf;
use App\Jobs\WhatsappNotisLelongFasa1;
use App\Jobs\WhatsappNotisLelongFasa2;
use App\Jobs\WhatsappNotisPeringatanKedua;
use App\Jobs\WhatsappNotisTuntutBaki;
use App\Models\Cawangan;
use App\Models\CawanganLelong;
use App\Models\CawanganNotis;
use App\Models\Customer;
use App\Models\FailedJob;
use App\Models\Gadai;
use App\Models\JanaNotisExport;
use App\Models\Lelong;
use App\Models\LelongBid;
use App\Models\LelongCawangan;
use App\Models\LelongTebus;
use App\Models\LogUser;
use App\Models\Notis;
use App\Models\NotisBid;
use App\Models\Tetapan;
use App\Models\TransaksiKeuntungan;
use App\Models\WtdDraft;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use PDF;
class NotisController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function notislelong()
{
$user = Auth::user();
$lelongid = CawanganLelong::join('lelong', 'cawangan_lelong.lelong_id', '=', 'lelong.id')
->join('cawangan', 'cawangan_lelong.caw_id', '=', 'cawangan.id')
->where('cawangan.caw_code', '=', $user->kodcaw)
->where('lelong.sts_lelong', '=', 0)
->get();
// dd($lelongid);
foreach ($lelongid as $index1 => $bil) {
$listsag = LelongBid::where('lelong_id', $bil['lelong_id'])
->where('kodcaw', '=', $user->kodcaw)
->get();
$lelongid[$index1]['bilangan'] = count($listsag);
// dd(sizeof($listsag));
}
$latestExports = JanaNotisExport::where('kodcaw', $user->kodcaw)
->whereIn('lelong_id', $lelongid->pluck('lelong_id'))
->orderByDesc('id')
->get()
->unique(function ($export) {
return $export->lelong_id.'_'.$export->fasa;
})
->keyBy(function ($export) {
return $export->lelong_id.'_'.$export->fasa;
});
$hasPendingExport = $latestExports->contains(function ($export) {
return $export->isInProgress();
});
return view('jananotis.notislelong', compact('lelongid', 'latestExports', 'hasPendingExport'));
}
public function senarainotis($lelong_id)
{
$user = Auth::user();
$bayaran = 0;
$arraydetails = [];
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)
->first();
$lelong_id = $lelong_id;
$marhun = LelongBid::join('cawangan', 'lelongbid.caw_id', '=', 'cawangan.id')
->where('lelong_id', '=', $lelong_id)
->where('lelongbid.kodcaw', '=', $user->kodcaw);
$arraynorujukan = $marhun->pluck('norujukan')->toArray();
$datalelong = $marhun->get();
$marhuns = Gadai::on($datalelong[0]['kodcaw'])->whereIn('norujukan', $arraynorujukan)
->select('nokp')
->groupBy('nokp')
->get();
// dd($marhuns);
$arraysag = [];
foreach ($marhuns as $index1 => $cal) {
$customer = Customer::where('kpbaru', '=', $cal['nokp'])
->orWhere('kplama', '=', $cal['nokp'])
->first();
$listsag = Gadai::on($datalelong[0]['kodcaw'])->whereIn('norujukan', $arraynorujukan)
->where('nokp', '=', $cal['nokp'])
->get();
// dd($listgadai);
foreach ($listsag as $index => $listing) {
$bayaran = $listing['hargajualan'] - $listing['bakihargajualan'];
// dd($bayaran);
$listsag[$index]['bayaran'] = $bayaran;
}
$marhuns[$index1]['nama'] = $customer;
$marhuns[$index1]['listsag'] = $listsag;
}
return view('jananotis.senarainotis', compact('marhuns', 'lelong_id', 'bayaran', 'listsag'));
}
public function senarainotis2($lelong_id)
{
$user = Auth::user();
$lelong = Lelong::find($lelong_id);
// dd($lelong);
$caw = Cawangan::with(['lelongBid' => function ($q) use ($lelong_id) {
$q->where('lelong_id', '=', $lelong_id)->select('id', 'caw_id', 'kodcaw', 'norujukan', 'hargaasas', 'pinjaman', 'bakiupah');
}])
->where('caw_code', '=', $user->kodcaw)->first();
$lelongbid_data_pluck_norujukan = $caw->lelongBid->pluck('norujukan')->toArray();
$lelongbid_keyby_norujukan = $caw->lelongBid->keyBy('norujukan');
// dd($lelongbid_keyby_norujukan);
$gadai_all = Gadai::on($caw->caw_code)->whereIn('norujukan', $lelongbid_data_pluck_norujukan)
->select('nokp', 'tempoh', 'norujukan', 'bakipjm', 'bakiupah', 'hargajualan', 'bakihargajualan')
->orderBy('nokp', 'ASC')
->get();
$gadai_all_pluck_nokp = $gadai_all->pluck('nokp')->unique();
$customers = Customer::whereIn('kpbaru', $gadai_all_pluck_nokp)
->orWhereIn('kplama', $gadai_all_pluck_nokp)
->select('kpbaru', 'kplama', 'alamat1', 'alamat2', 'alamat3', 'telefon')
->get();
// dd($customers->toArray());
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
$gadai_all_groupby_nokp = $gadai_all->groupBy('nokp');
foreach ($customers as $index => $customer) {
if ($customer->kpbaru != '') {
$customers[$index]['nokp'] = $customer->kpbaru;
} elseif ($customer->kplama != '') {
$customers[$index]['nokp'] = $customer->kplama;
}
if ($gadai_all_groupby_nokp[$customer->nokp]) {
$customers[$index]['gadai'] = $gadai_all_groupby_nokp[$customer->nokp];
}
foreach ($customer['gadai'] as $index2 => $datagadai) {
if ($lelongbid_keyby_norujukan[$datagadai->norujukan]) {
// $customer['gadai'][$index2]['lelongbid'] = $lelongbid_keyby_norujukan[$datagadai->norujukan];
$lelongbid_true = $lelongbid_keyby_norujukan[$datagadai->norujukan];
$ktlhbyr = $datagadai->hargajualan - $datagadai->bakihargajualan;
$sumcajlelong = $lelongbid_true->hargaasas * ($lelong->cajlelong / 100);
$cajlelongnew = round($sumcajlelong, 1, 1);
$totalbaki = $lelongbid_true->hargaasas - $lelongbid_true->pinjaman - $lelongbid_true->bakiupah - $cajlelongnew;
$customer['gadai'][$index2]['bakilelong'] = number_format($totalbaki, 2, '.', ',');
$customer['gadai'][$index2]['ktlhbyr'] = number_format($ktlhbyr, 2, '.', ',');
}
}
// dd($customer);
}
return view('jananotis.senarainotis2', compact('customers', 'lelong_id'));
}
public function jananotis($lelong_id)
{
$user = Auth::user();
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)
->first();
$lelong_id = $lelong_id;
$current = Carbon::now();
$current = new Carbon;
$tarikh_cetak = $current->toDateString();
$marhun = LelongBid::join('cawangan', 'lelongbid.caw_id', '=', 'cawangan.id')
->where('lelong_id', '=', $lelong_id)
->where('lelongbid.kodcaw', '=', $user->kodcaw);
$arraynorujukan = $marhun->pluck('norujukan')->toArray();
$datalelong = $marhun->get();
$marhuns = Gadai::on($datalelong[0]['kodcaw'])->whereIn('norujukan', $arraynorujukan)
->select('nokp', 'norujukan')
->orderBy('nokp', 'asc')
->get();
// dd($marhuns);
$arraysag = [];
foreach ($marhuns as $index1 => $cal) {
$customer = Customer::where('kpbaru', '=', $cal['nokp'])
->orWhere('kplama', '=', $cal['nokp'])
->join('poskod', 'customer.poskod', '=', 'poskod.poskod')
->join('daerah', 'poskod.koddaerah', '=', 'daerah.koddaerah')
->join('negeri', 'poskod.kodnegeri', '=', 'negeri.kodnegeri')
->first();
$listsag = Gadai::on($datalelong[0]['kodcaw'])->whereIn('norujukan', $arraynorujukan)
->where('nokp', '=', $cal['nokp'])
->get();
// dd($listsag);
foreach ($listsag as $index => $listing) {
$bayaran = $listing['hargajualan'] - $listing['bakihargajualan'];
}
$marhuns[$index1]['nama'] = ($customer) ? $customer : dd($cal['nokp']);
$marhuns[$index1]['listsag'] = $listsag;
}
$lelongid = CawanganLelong::join('lelong', 'cawangan_lelong.lelong_id', '=', 'lelong.id')
->join('cawangan', 'cawangan_lelong.caw_id', '=', 'cawangan.id')
->where('cawangan.caw_code', '=', $user->kodcaw)
->where('cawangan_lelong.lelong_id', $lelong_id)
->get();
$pdf = PDF::loadView('pdf.jananotis', compact('marhuns', 'lelong_id', 'lelongid', 'caw', 'tarikh_cetak', 'customer', 'listsag'))
->setPaper('a4', 'potrait');
return $pdf->download('Penjanaan Notis Fasa 1:Batch Lelong '.$lelong_id.'.pdf');
}
public function jananotis2($lelong_id)
{
// focus only on variable: $marhuns, $lelongid, $caw, $tarikh_cetak
// variable not use: $lelong_id, $customer, $listsag
$user = Auth::user();
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)->first();
$currentdate = Carbon::now();
$tarikh_cetak = $currentdate->toDateString();
$current_date_time = $currentdate->toDateTimeString();
Log::info('Jana notis fasa 1: '.$user->kodcaw.', '.$user->name);
NotifyJanaNotis::dispatch($user->id, $user->kodcaw, $user->name, 'Jana Notis Fasa 1', $current_date_time);
$lelongid = Lelong::find($lelong_id);
$arraynorujukan = LelongBid::where('lelong_id', $lelong_id)->where('kodcaw', $caw->caw_code)->pluck('norujukan');
$marhuns = Gadai::on($caw->caw_code)->whereIn('norujukan', $arraynorujukan)->select('nokp', 'norujukan', 'bakipjm')->orderBy('nokp', 'asc')->get();
$marhuns_pluck_nokp = $marhuns->pluck('nokp');
$customers = Customer::whereIn('kpbaru', $marhuns_pluck_nokp)
->orWhereIn('kplama', $marhuns_pluck_nokp)
->join('poskod', 'customer.poskod', '=', 'poskod.poskod')
->join('daerah', 'poskod.koddaerah', '=', 'daerah.koddaerah')
->join('negeri', 'poskod.kodnegeri', '=', 'negeri.kodnegeri')
->get();
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
foreach ($marhuns as $index => $marhun) {
if ($customers_keyBy_noKp[$marhun->nokp]) {
$marhuns[$index]['nama'] = $customers_keyBy_noKp[$marhun->nokp];
}
// apigetkeuntungan
$getkeuntungansemasa = Http::get(config('app.api_url').'kiraUpahTawarruq', [
'kodcaw' => $user->kodcaw,
'norujukan' => $marhun->norujukan,
])->json();
$marhuns[$index]['keuntungan'] = $getkeuntungansemasa;
$nilaips = (float) $getkeuntungansemasa['keuntungan'] + (float) $getkeuntungansemasa['bakipjm'];
$nilaitebus = (float) $getkeuntungansemasa['keuntunganrebet'] + (float) $getkeuntungansemasa['bakipjm'];
// dd($nilaips);
$marhuns[$index]['nilaitebus'] = $nilaitebus;
$marhuns[$index]['nilaips'] = $nilaips;
}
$pdf = PDF::loadView('pdf.jananotis', compact('marhuns', 'lelongid', 'caw', 'tarikh_cetak'))
->setPaper('a4', 'potrait');
return $pdf->download('Penjanaan Notis Fasa 1:Batch Lelong '.$lelong_id.'.pdf');
}
public function jananotis2_new($lelong_id)
{
return $this->queueJanaNotisExport($lelong_id, 1);
}
public function jananotis2_new2($lelong_id)
{
return $this->queueJanaNotisExport($lelong_id, 2);
}
protected function queueJanaNotisExport($lelong_id, $fasa)
{
$user = Auth::user();
$existing = JanaNotisExport::where('lelong_id', $lelong_id)
->where('kodcaw', $user->kodcaw)
->where('fasa', $fasa)
->whereIn('status', [
JanaNotisExport::STATUS_PENDING,
JanaNotisExport::STATUS_PROCESSING,
JanaNotisExport::STATUS_COMPLETED,
])
->latest('id')
->first();
if ($existing) {
if ($existing->isReady()) {
return redirect()->route('jananotis.notislelong')
->with('success', 'Notis Fasa '.$fasa.' untuk batch '.$lelong_id.' telah dijana. Sila muat turun fail sedia ada.');
}
return redirect()->route('jananotis.notislelong')
->with('success', 'Penjanaan Notis Fasa '.$fasa.' untuk batch '.$lelong_id.' masih dalam proses.');
}
$export = JanaNotisExport::create([
'user_id' => $user->id,
'lelong_id' => $lelong_id,
'kodcaw' => $user->kodcaw,
'fasa' => $fasa,
'status' => JanaNotisExport::STATUS_PENDING,
]);
GenerateJanaNotisPdf::dispatch($export->id);
Log::info("Queued Jana notis fasa {$fasa}: {$user->kodcaw}, {$user->name}, export #{$export->id}");
return redirect()->route('jananotis.notislelong')
->with('success', 'Penjanaan Notis Fasa '.$fasa.' untuk batch '.$lelong_id.' telah dimulakan. Sila tunggu dan muat turun apabila siap.');
}
public function downloadJanaNotisExport($export_id)
{
$user = Auth::user();
$export = JanaNotisExport::where('id', $export_id)
->where('kodcaw', $user->kodcaw)
->firstOrFail();
if (! $export->isReady() || ! Storage::disk('local')->exists($export->file_path)) {
return redirect()->route('jananotis.notislelong')
->with('error', 'Fail PDF belum siap atau tidak dijumpai. Sila jana semula.');
}
return Storage::disk('local')->download($export->file_path, $export->file_name);
}
public function listnotis(Request $request)
{
$lelong_id = $request->lelong_id;
$user = Auth::user();
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)
->first();
$bayaran = 0;
$arraydetails = [];
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)
->first();
$lelong_id = $lelong_id;
$marhun = LelongBid::join('cawangan', 'lelongbid.caw_id', '=', 'cawangan.id')
->where('lelong_id', '=', $lelong_id)
->where('lelongbid.kodcaw', '=', $user->kodcaw)
->orderBy('norujukan');
$arraynorujukan = $marhun->pluck('norujukan')->toArray();
$datalelong = $marhun->get();
$marhuns = Gadai::on($datalelong[0]['kodcaw'])->whereIn('norujukan', $arraynorujukan)
->select('nokp')
->groupBy('nokp')
->get();
// dd($marhuns);
$arraysag = [];
foreach ($marhuns as $index1 => $cal) {
$customer = Customer::where('kpbaru', '=', $cal['nokp'])
->orWhere('kplama', '=', $cal['nokp'])
->get();
$listsag = Gadai::on($datalelong[0]['kodcaw'])->whereIn('norujukan', $arraynorujukan)
->where('nokp', '=', $cal['nokp'])
->get();
// dd($listgadai);
foreach ($listsag as $index => $listing) {
$bayaran = $listing['hargajualan'] - $listing['bakihargajualan'];
}
$marhuns[$index1]['nama'] = $customer;
$marhuns[$index1]['listsag'] = $listsag;
// dd($marhuns[$index1]['nama']);
}
$listsaglelong = Gadai::on($datalelong[0]['kodcaw'])->whereIn('norujukan', $arraynorujukan)
->get();
foreach ($listsaglelong as $index2 => $sag) {
$nokp = Customer::where('kpbaru', '=', $sag['nokp'])
->orWhere('kplama', '=', $sag['nokp'])
->first();
$listsaglelong[$index2]['nama'] = $nokp;
}
if ($request->type == 'excel') {
return view('excel.listnotis_excel', compact('marhuns', 'lelong_id', 'bayaran', 'listsag', 'caw'));
} elseif ($request->type == 'excelbysag') {
return view('excel.listnotis_excelbysag', compact('listsaglelong', 'lelong_id', 'bayaran', 'listsag', 'caw'));
} else {
$pdf = PDF::loadView('pdf.listnotis', compact('marhuns', 'lelong_id', 'bayaran', 'listsag', 'caw'))
->setPaper('a4', 'landscape');
return $pdf->download('Senarai Notis.pdf');
}
}
public function listnotis2(Request $request)
{
$user = Auth::user();
$lelong_id = $request->lelong_id;
$lelong = Lelong::find($lelong_id);
$caw = Cawangan::with(['lelongBid' => function ($q) use ($lelong_id) {
$q->where('lelong_id', '=', $lelong_id)->select('id', 'caw_id', 'kodcaw', 'norujukan', 'hargaasas', 'pinjaman', 'bakiupah');
}])
->where('caw_code', '=', $user->kodcaw)->first();
$lelongbid_data_pluck_norujukan = $caw->lelongBid->pluck('norujukan')->toArray();
$lelongbid_keyby_norujukan = $caw->lelongBid->keyBy('norujukan');
// dd($lelongbid_keyby_norujukan);
$gadai_all = Gadai::on($caw->caw_code)->whereIn('norujukan', $lelongbid_data_pluck_norujukan)
->select('nokp', 'tempoh', 'norujukan', 'bakipjm', 'bakiupah', 'hargajualan', 'bakihargajualan')
->orderBy('norujukan', 'ASC')
->get();
// dd($gadai_all);
$gadai_all_pluck_nokp = $gadai_all->pluck('nokp')->unique();
$customers = Customer::whereIn('kpbaru', $gadai_all_pluck_nokp)
->orWhereIn('kplama', $gadai_all_pluck_nokp)
->select('nama', 'kpbaru', 'kplama', 'alamat1', 'alamat2', 'alamat3', 'telefon')
->get();
// dd($customers->toArray());
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
$gadai_all_groupby_nokp = $gadai_all->groupBy('nokp');
foreach ($gadai_all as $index3 => $gadai) {
if ($customers_keyBy_noKp[$gadai->nokp]) {
$gadai_all[$index3]['cust_info'] = $customers_keyBy_noKp[$gadai->nokp];
}
}
foreach ($customers as $index => $customer) {
if ($customer->kpbaru != '') {
$customers[$index]['nokp'] = $customer->kpbaru;
} elseif ($customer->kplama != '') {
$customers[$index]['nokp'] = $customer->kplama;
}
if ($gadai_all_groupby_nokp[$customer->nokp]) {
$customers[$index]['gadai'] = $gadai_all_groupby_nokp[$customer->nokp];
}
foreach ($customer['gadai'] as $index2 => $datagadai) {
if ($lelongbid_keyby_norujukan[$datagadai->norujukan]) {
// $customer['gadai'][$index2]['lelongbid'] = $lelongbid_keyby_norujukan[$datagadai->norujukan];
$lelongbid_true = $lelongbid_keyby_norujukan[$datagadai->norujukan];
$ktlhbyr = $datagadai->hargajualan - $datagadai->bakihargajualan;
$sumcajlelong = $lelongbid_true->hargaasas * ($lelong->cajlelong / 100);
$cajlelongnew = round($sumcajlelong, 1, 1);
$totalbaki = $lelongbid_true->hargaasas - $lelongbid_true->pinjaman - $lelongbid_true->bakiupah - $cajlelongnew;
$customer['gadai'][$index2]['bakilelong'] = number_format($totalbaki, 2, '.', ',');
$customer['gadai'][$index2]['ktlhbyr'] = number_format($ktlhbyr, 2, '.', ',');
}
}
// dd($customer);
}
if ($request->type == 'excel') {
return view('excel.listnotis_excel2', compact('customers', 'lelong_id', 'caw'));
} elseif ($request->type == 'excelbysag') {
return view('excel.listnotis_excelbysag2', compact('gadai_all', 'lelong_id', 'caw'));
} else {
$pdf = PDF::loadView('pdf.listnotis2', compact('customers', 'lelong_id', 'caw'))
->setPaper('a4', 'landscape');
return $pdf->download('Senarai Notis.pdf');
}
}
public function kemaskininotis(Request $request)
{
$tetapan = Tetapan::where('id', '=', 1)->get();
return view('jananotis.kemaskininotis', compact('tetapan'));
}
public function storeall(Request $request)
{
// dd($request->all());
$tetapan = Tetapan::find(1);
$tetapan->para2 = $request->para2;
$tetapan->update();
$cawangan = Cawangan::all();
foreach ($cawangan as $updatecaw) {
$update = Cawangan::where('id', $updatecaw['id'])
->update(['para2' => $request->para2]);
// $update->para2 = $request->para2;
// $update->update();
}
return redirect()->route('jananotis.kemaskininotis')
->with('success', 'Kemaskini Berjaya');
}
public function store(Request $request)
{
// dd($request->all());
$tetapan = Tetapan::find(1);
$tetapan->para2caw = $request->para2;
$tetapan->update();
$cawangan = Cawangan::all();
foreach ($cawangan as $updatecaw) {
$update = Cawangan::where('id', $updatecaw['id'])
->where('caw_code', $request->kodcaw)
->update(['para2' => $request->para2]);
}
return redirect()->route('jananotis.kemaskininotisbycaw')
->with('success', 'Kemaskini Berjaya');
}
public function kemaskininotisbycaw(Request $request)
{
$caw = Cawangan::all();
return view('jananotis.kemaskininotisbycaw', compact('caw'));
}
public function jananotisfasa2($lelong_id)
{
$user = Auth::user();
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)->first();
$currentdate = Carbon::now();
$tarikh_cetak = $currentdate->toDateString();
$current_date_time = $currentdate->toDateTimeString();
Log::info('Jana notis fasa 1: '.$user->kodcaw.', '.$user->name);
NotifyJanaNotis::dispatch($user->id, $user->kodcaw, $user->name, 'Jana Notis Fasa 1', $current_date_time);
$lelongid = Lelong::find($lelong_id);
$arraynorujukan = LelongBid::where('lelong_id', $lelong_id)->where('kodcaw', $caw->caw_code)->pluck('norujukan');
$marhuns = Gadai::on($caw->caw_code)->whereIn('norujukan', $arraynorujukan)->select('nokp', 'norujukan', 'bakipjm')->orderBy('nokp', 'asc')->get();
$marhuns_pluck_nokp = $marhuns->pluck('nokp');
$customers = Customer::whereIn('kpbaru', $marhuns_pluck_nokp)
->orWhereIn('kplama', $marhuns_pluck_nokp)
->join('poskod', 'customer.poskod', '=', 'poskod.poskod')
->join('daerah', 'poskod.koddaerah', '=', 'daerah.koddaerah')
->join('negeri', 'poskod.kodnegeri', '=', 'negeri.kodnegeri')
->get();
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
foreach ($marhuns as $index => $marhun) {
if ($customers_keyBy_noKp[$marhun->nokp]) {
$marhuns[$index]['nama'] = $customers_keyBy_noKp[$marhun->nokp];
}
// apigetkeuntungan
$getkeuntungansemasa = Http::get(config('app.api_url').'kiraUpahTawarruq', [
'kodcaw' => $user->kodcaw,
'norujukan' => $marhun->norujukan,
])->json();
$marhuns[$index]['keuntungan'] = $getkeuntungansemasa;
$nilaips = (float) $getkeuntungansemasa['keuntungan'] + (float) $getkeuntungansemasa['bakipjm'];
$nilaitebus = (float) $getkeuntungansemasa['keuntunganrebet'] + (float) $getkeuntungansemasa['bakipjm'];
// dd($nilaips);
$marhuns[$index]['nilaitebus'] = $nilaitebus;
$marhuns[$index]['nilaips'] = $nilaips;
}
// return view('pdf.jananotisfasa2',compact('marhuns','lelong_id','lelongid','caw','tarikh_cetak','customer','listsag'));
$pdf = PDF::loadView('pdf.jananotisfasa2', compact('marhuns', 'lelongid', 'caw', 'tarikh_cetak'))
->setPaper('a4', 'potrait');
return $pdf->download('Penjanaan Notis Fasa 2:Batch Lelong '.$lelong_id.'.pdf');
}
public function storeallfasa2(Request $request)
{
// dd($request->all());
$tetapan = Tetapan::find(1);
$tetapan->para3 = $request->para3;
$tetapan->update();
$cawangan = Cawangan::all();
foreach ($cawangan as $updatecaw) {
$update = Cawangan::where('id', $updatecaw['id'])
->update(['para3' => $request->para3]);
// $update->para2 = $request->para2;
// $update->update();
}
return redirect()->route('jananotis.kemaskininotis')
->with('success', 'Kemaskini Berjaya');
}
public function jananotisperingatan()
{
$currentDate = Carbon::now();
$currentDate = $currentDate->toDateString();
$caw = Cawangan::all();
$tetapan = Tetapan::where('id', '=', 1)->first();
return view('notisperingatan.jananotisperingatan', compact('caw', 'tetapan', 'currentDate'));
}
public function senaraitempnotisperingatan(Request $request)
{
$fasa = $request->fasa;
$jbg = $request->jbg;
$jbg2 = $request->jbg2;
if ($request->fasa == '1') {
$cawangan_all = Cawangan::orderBy('caw_name')->get();
// dd($cawangan_all);
$senarai = [];
$total_bil_lelong = 0;
foreach ($cawangan_all as $cawangan) {
$getsurat1 = NotisBid::where('kodcaw', $cawangan->caw_code)->get();
$sag_pluck_norujukan = $getsurat1->pluck('norujukan');
// dd($sag_pluck_norujukan);
$getsurat = Gadai::on($cawangan->caw_code)
->whereNotIn('norujukan', $sag_pluck_norujukan)
->where('tempoh', '>=', $jbg)
->where('tempoh', '<=', $jbg2)
->where('sttebus', '=', '')
->where('tagpalsu', '=', 0)
->where('tagpalsu2', '=', 0)
->where('taglel', '=', 0)
->where('lelong_tawarruq', '=', 1)
->whereNotNull('upah12');
$bil_lelong = $getsurat->count('norujukan');
$total_bil_lelong += $bil_lelong;
$total_berat = $getsurat->sum('berat');
$total_nilaimarhun = $getsurat->sum('nilaimarhun');
$total_pembiayaan = $getsurat->sum('pinjaman');
// $total_bakipjm = $getsurat->sum('bakipjm');
$data = [
'bil_lelong' => $bil_lelong,
'total_berat' => $total_berat,
'total_nilaimarhun' => $total_nilaimarhun,
'total_pembiayaan' => $total_pembiayaan,
// 'total_bakipjm'=>$total_bakipjm,
'kodcaw' => $cawangan->caw_code,
'caw_name' => $cawangan->caw_name];
array_push($senarai, $data);
// dump($data);
}
} elseif ($request->fasa == '2') {
$cawangan_all = Cawangan::all();
$senarai = [];
$total_bil_lelong = 0;
// dd($jbgadai);
foreach ($cawangan_all as $cawangan) {
$getsurat1 = NotisBid::where('kodcaw', $cawangan->caw_code)->get();
$sag_pluck_norujukan = $getsurat1->pluck('norujukan');
// dd($sag_pluck_norujukan);
$getsurat = Gadai::on($cawangan->caw_code)
->whereNotIn('norujukan', $sag_pluck_norujukan)
->where('tempoh', '>=', $jbg)
// ->where('tempoh', '<=', $jbg2)
->where('sttebus', '=', '')
->where('tagpalsu', '=', 0)
->where('tagpalsu2', '=', 0)
->where('taglel', '=', 0)
// ->where('lelong_tawarruq','=',1)
->whereNotNull('upah12');
// $cawangan_simulasi = CawanganLelong::where('caw_id',$cawangan->id)->where('kali', '=' ,$kali)->count();
// if($cawangan_simulasi == 0){
$bil_lelong = $getsurat->count('norujukan');
$total_bil_lelong += $bil_lelong;
$total_berat = $getsurat->sum('berat');
$total_nilaimarhun = $getsurat->sum('nilaimarhun');
$total_pembiayaan = $getsurat->sum('pinjaman');
$total_bakipjm = $getsurat->sum('bakipjm');
$data = [
'bil_lelong' => $bil_lelong,
'total_berat' => $total_berat,
'total_nilaimarhun' => $total_nilaimarhun,
'total_pembiayaan' => $total_pembiayaan,
'total_bakipjm' => $total_bakipjm,
'kodcaw' => $cawangan->caw_code,
'caw_name' => $cawangan->caw_name];
array_push($senarai, $data);
// dd($data);
// }
}
}
// dd($data);
if ($total_bil_lelong == 0) {
return redirect()->route('notisperingatan.jananotisperingatan')
->with('failed', 'Tiada surat untuk di dijana');
}
return view('notisperingatan.senaraitempnotisperingatan', compact(
'getsurat',
'senarai',
'fasa',
'jbg',
'jbg2'
));
}
public function tempbycawnotisperingatan(Request $request)
{
$fasa = $request->fasa;
$jbg = $request->jbg;
$jbg2 = $request->jbg2;
$details = $request->kodcaw;
// dd($jbg);
if ($fasa == '1') {
$getsurat = Gadai::on($details)
->where('tempoh', '>=', $jbg)
->where('tempoh', '<=', $jbg2)
->where('kodcaw', $details)
->where('sttebus', '=', '')
->where('lelong_tawarruq', '=', 1)
->where('taglel', '=', 0)
->where('tagpalsu', '=', 0)
->where('tagpalsu2', '=', 0)
->whereNotNull('upah12')
->get();
// dd($getsurat);
$gadai_data_pluck_norujukan = $getsurat->pluck('norujukan')->toArray();
// dd($gadai_data_pluck_norujukan);
$t_gadais = Gadai::on($details)
->where('tempoh', '>=', $jbg)
->where('tempoh', '<=', $jbg2)
->where('sttebus', '=', '')
->where('taglel', '=', 0)
->where('tagpalsu', '=', 0)
->where('tagpalsu2', '=', 0)
->whereNotNull('upah12')
->orderBy('t_gadai')
->select('t_gadai')
->first();
} else {
$getsurat = Gadai::on($details)
->where('tempoh', '>=', $jbg)
// ->where('tempoh', '<=', $jbg2)
->where('kodcaw', $details)
->where('sttebus', '=', '')
->where('taglel', '=', 0)
->where('tagpalsu', '=', 0)
->where('tagpalsu2', '=', 0)
->whereNotNull('upah12')
->get();
$gadai_data_pluck_norujukan = $getsurat->pluck('norujukan')->toArray();
$t_gadais = Gadai::on($details)
->where('tempoh', '>=', $jbg)
// ->where('tempoh', '<=', $jbg2)
->where('sttebus', '=', '')
->where('taglel', '=', 0)
->where('tagpalsu', '=', 0)
->where('tagpalsu2', '=', 0)
->whereNotNull('upah12')
->orderBy('t_gadai')
->select('t_gadai')
->first();
}
$gadai_all_keyBy_norujukan = $getsurat->keyBy('norujukan');
// $gadai_all = Gadai::on($details)->whereIn('norujukan', $gadai_data_pluck_norujukan)
// ->select('kadarupah','nokp','tempoh','tempohbayar','norujukan','berat','nilaimarhun','pinjaman','bakipjm','bakiupah','hargajualan','bakihargajualan')
// ->orderBy('norujukan','ASC')
// ->get();
// dd($gadai_all);
$transaksi_all = TransaksiKeuntungan::on('main')->whereIn('norujukan', $gadai_data_pluck_norujukan)
->select('keuntungan_rebet', 'bayaran_keuntungan', 'norujukan')
->get();
$transaksi_all_groupby_norujukan = $transaksi_all->groupBy('norujukan');
foreach ($transaksi_all_groupby_norujukan as $index7 => $transaksi) {
if ($gadai_all_keyBy_norujukan[$index7]) {
$gadai_true = $gadai_all_keyBy_norujukan[$index7];
$gadai_true['data_transaksi'] = $transaksi;
}
}
foreach ($getsurat as $index1 => $surats) {
// dd($surats['data_transaksi']);
if (isset($surats['data_transaksi'])) {
$data_transaksi = $transaksi_all_groupby_norujukan[$surats->norujukan];
$total_untung_rebet = $data_transaksi->sum('keuntungan_rebet');
$total_untung_asal = $data_transaksi->sum('bayaran_keuntungan');
$beza_keuntungan = $total_untung_asal - $total_untung_rebet;
// dd($beza_keuntungan);
// dd(true);
$jbg = $surats->tempoh - $surats->tempohbayar;
$jbg2 = 12 - $surats->tempohbayar;
if ($surats->tempoh <= '12.00') {
$keuntungan = bcdiv(($jbg) * $surats->kadarupah / 100 * $surats->bakipjm, 1, 1) - $beza_keuntungan;
} else {
$keuntungan = bcdiv(($jbg2) * $surats->kadarupah / 100 * $surats->bakipjm, 1, 1) - $beza_keuntungan;
}
} else {
// dd(false);
$jbg = $surats->tempoh - $surats->tempohbayar;
$jbg2 = 12 - $surats->tempohbayar;
$beza_keuntungan = 0.00;
// dd($beza_keuntungan);
if ($surats->tempoh <= '12.00') {
// dd($jbg,$datagadai->kadarupah, $datagadai->bakipjm);
$keuntungan = bcdiv(($jbg) * $surats->kadarupah / 100 * $surats->bakipjm, 1, 1) - $beza_keuntungan;
} else {
// dd(false);
$keuntungan = bcdiv(($jbg2) * $surats->kadarupah / 100 * $surats->bakipjm, 1, 1) - $beza_keuntungan;
}
}
// dd($keuntungan);
$ktlhbyr = $surats['hargajualan'] - $surats['bakihargajualan'];
// dd($ktlhbyr);
// $getsurat[$index1]['list_norujukan'] = $senarai;
$getsurat[$index1]['keuntungan'] = $keuntungan;
$getsurat[$index1]['ktlhbyr'] = $ktlhbyr;
}
// $keuntungantlhbyr = TransaksiKeuntungan::on('mysql2')
// ->sum('bayaran_keuntungan');
return view('notisperingatan.tempbycawnotisperingatan', compact('getsurat',
'details',
'keuntungan',
't_gadais',
'ktlhbyr'
));
}
public function janadatanotisperingatan(Request $request)
{
$fasa = $request->fasa;
$jbg = $request->jbg;
$jbg2 = $request->jbg2;
$current = Carbon::now();
$current = new Carbon;
$tarikh_notis = $current->toDateString();
$selected_caw = $request->caw;
if (! empty($selected_caw)) {
$caws = Cawangan::whereIn('caw_code', $selected_caw)->get();
$bil_surat = 0;
$sag_cawangans = [];
foreach ($caws as $caw) {
if ($fasa == '1') {
$surat = Gadai::on($caw->caw_code)
->where('tempoh', '>=', $jbg)
->where('tempoh', '<=', $jbg2)
->where('sttebus', '=', '')
->where('tagpalsu', '=', 0)
->where('tagpalsu2', '=', 0)
->where('taglel', '=', 0)
->where('lelong_tawarruq', '=', 1);
// ->count('norujukan');
} elseif ($fasa == '2') {
$surat = Gadai::on($caw->caw_code)
->where('tempoh', '>=', $jbg)
->where('sttebus', '=', '')
->where('tagpalsu', '=', 0)
->where('tagpalsu2', '=', 0)
->where('taglel', '=', 0);
// ->count('norujukan');
}
$bil_sag_cawangan = $surat->count('norujukan');
array_push($sag_cawangans, ['cawangan' => $caw, 'data' => $surat->get()]);
$bil_surat += $bil_sag_cawangan;
}
if ($bil_surat == 0) {
return redirect()->route('notisperingatan.jananotisperingatan')
->with('failed', 'Tiada surat untuk di jana');
}
// create notis
$notis = Notis::create([
'tarikh_notis' => $tarikh_notis,
'daritempoh' => $jbg,
'hinggatempoh' => $jbg2,
'sts_notis' => 1,
'fasa' => $fasa,
]);
foreach ($sag_cawangans as $index => $cawnotis) {
$caw_notis = new CawanganNotis;
$caw_notis->notis_id = $notis->id;
$caw_notis->caw_id = $cawnotis['cawangan']->id;
$caw_notis->fasa = $request->fasa;
$caw_notis->daritempoh = $request->jbg;
$caw_notis->hinggatempoh = $request->jbg2;
$caw_notis->status = 1;
$caw_notis->save();
$suratcaw = $cawnotis['data'];
$notis_bid_arr = [];
$now = Carbon::now();
foreach ($suratcaw as $surat) {
$notis_to_be_inserted = new NotisBid;
$notis_to_be_inserted->notis_id = $notis->id;
$notis_to_be_inserted->tarikh_notis = $tarikh_notis;
$notis_to_be_inserted->caw_id = $cawnotis['cawangan']->id;
$notis_to_be_inserted->kodcaw = $surat->kodcaw;
$notis_to_be_inserted->norujukan = $surat->norujukan;
$notis_to_be_inserted->nokp = $surat->nokp;
$notis_to_be_inserted->jbg = $surat->tempoh;
$notis_to_be_inserted->kadarupah = $surat->kadarupah;
$notis_to_be_inserted->nilaimarhun = $surat->nilaimarhun;
$notis_to_be_inserted->pinjaman = $surat->bakipjm;
$notis_to_be_inserted->bakiupah = $surat->bakiupah;
$notis_to_be_inserted->berat = $surat->berat;
$notis_to_be_inserted->marhun = $surat->marhun;
$notis_to_be_inserted->percent = $surat->percentpinj;
$notis_to_be_inserted->fasa = $request->fasa;
$notis_bid_arr[] = $notis_to_be_inserted->attributesToArray();
}
$notis_bid_collection = collect($notis_bid_arr);
NotisBid::insert($notis_bid_arr);
}
} else {
return redirect()->route('notisperingatan.jananotisperingatan')->with('failed', 'Tiada surat untuk di jana');
}
return redirect()->route('notisperingatan.shownotisperingatanall', ['tarikhnotis' => $tarikh_notis, 'notisid' => $notis->id]);
// return redirect()->route('analisa.senaraisimulasi')->with('success',"Success daftar simulasi!");
}
public function shownotisperingatan($id)
{
$notis_id = $id;
$notis = Notis::with(['cawangan', 'notisBid'])->find($id);
$data = $notis;
$cawanganAll = $notis->cawangan;
$notisBidGroupByCawId = $notis->notisBid->groupBy('caw_id');
foreach ($cawanganAll as $caw_key_by_id) {
if ($notisBidGroupByCawId[$caw_key_by_id['id']]);
$caw_key_by_id['notisBid'] = $notisBidGroupByCawId[$caw_key_by_id['id']];
}
$total_marhun = 0;
$total_nilaimarhun = 0;
$total_pinjaman = 0;
$total_bakiupah = 0;
$total_berat = 0;
$arraycaw = [];
foreach ($cawanganAll as $caw) {
$berat = 0;
$nilai_marhun = 0;
$pinjaman = 0;
$bakiupah = 0;
foreach ($caw['notisBid'] as $notis_bid) {
$total_marhun += 1;
$nilai_marhun += $notis_bid->nilaimarhun;
$pinjaman += $notis_bid->pinjaman;
$bakiupah += $notis_bid->bakiupah;
$berat += $notis_bid->berat;
}
array_push($arraycaw, [
'id_cawangan' => $caw['id'],
'cawangan' => $caw->caw_name,
'bil_marhun' => count($caw['notisBid']),
'berat' => $berat,
'n_marhun' => $nilai_marhun,
'pinjaman' => $pinjaman,
'upahsimpan' => $bakiupah,
'bakiupah' => $bakiupah,
]);
$total_nilaimarhun += $nilai_marhun;
$total_pinjaman += $pinjaman;
$total_bakiupah += $bakiupah;
$total_berat += $berat;
}
return view('notisperingatan.shownotisperingatan', compact(
'data',
'arraycaw',
'total_marhun',
'total_berat',
'total_pinjaman',
'notis_id',
'total_bakiupah',
'total_nilaimarhun',
'notis'
));
}
public function senarainotisall()
{
$arrayinfo = [];
$notis = Notis::select('tarikh_notis', 'id')
->groupBy('tarikh_notis')
->get();
// ->toArray();
// dd($notis);
foreach ($notis as $info) {
$detailsinfo = CawanganNotis::join('cawangan', 'cawangan_notis.caw_id', '=', 'cawangan.id')
// ->where('kali',$info->kali)
->get()
->toArray();
// dd($detailsinfo);
array_push($arrayinfo, ['info' => $info, 'detailsinfo' => $detailsinfo]);
}
return view('notisperingatan.senarainotisall', compact('notis', 'arrayinfo'));
}
public function shownotisperingatanall(Request $request)
{
$arraydata = [];
$arraycaw = [];
$data = [];
$total_marhun = 0;
$total_berat = 0;
$total_nmarhun = 0;
$total_pinjaman = 0;
$total_upah = 0;
$total_bakiupah = 0;
$total_nilaimarhun = 0;
$tarikhnotis = $request->tarikhnotis;
$notisid = $request->notisid;
$notis = Notis::with(['cawangan', 'notisBid', 'cawanganNotis'])->where('tarikh_notis', $tarikhnotis)->get();
foreach ($notis as $not) {
// dd($not);
$cawanganAll = $not->cawangan;
// dd($not->cawanganNotis);
// dump($not['id']);
$notBidGroupByCawId = $not->notisBid->groupBy('caw_id');
$notBidGroupByCawnotis = $not->cawanganNotis->groupBy('caw_id');
foreach ($cawanganAll as $caw_key_by_id) {
// dd($caw_key_by_id);
if ($notBidGroupByCawId[$caw_key_by_id['id']]);
$caw_key_by_id['notisBid'] = $notBidGroupByCawId[$caw_key_by_id['id']];
$caw_key_by_id['status'] = $notBidGroupByCawnotis[$caw_key_by_id['id']];
}
foreach ($cawanganAll as $cawnot) {
$berat = 0;
$nilai_marhun = 0;
$pinjaman = 0;
$bakiupah = 0;
foreach ($cawnot['notisBid'] as $not_bid) {
$berat += $not_bid->berat;
$nilai_marhun += $not_bid->nilaimarhun;
$pinjaman += $not_bid->pinjaman;
$bakiupah += $not_bid->bakiupah;
$total_marhun += 1;
$total_berat = $total_berat + $berat;
$total_nilaimarhun = $total_nilaimarhun + $nilai_marhun;
$total_pinjaman = $total_pinjaman + $pinjaman;
$total_bakiupah = $total_bakiupah + $bakiupah;
}
foreach ($cawnot['status'] as $not_bid_status) {
$statusnotis = $not_bid_status->status;
}
array_push($arraycaw, [
'id_cawangan' => $cawnot['id'],
'cawangan' => $cawnot['caw_name'],
't_notis' => $tarikhnotis,
'notis_id' => $not->id,
'bil_marhun' => count($cawnot['notisBid']),
'berat' => $berat,
'n_marhun' => $nilai_marhun,
'pinjaman' => $pinjaman,
'bakiupah' => $bakiupah,
'daritempoh' => $not->daritempoh,
'hinggatempoh' => $not->hinggatempoh,
'fasa' => $not->fasa,
'status' => $statusnotis,
]);
}
}
// dd($arraycaw);
return view('notisperingatan.shownotisperingatanall', compact(
'notisid',
'arraycaw',
'total_marhun',
'total_berat',
'total_nmarhun',
'total_pinjaman',
'total_upah',
'data',
'tarikhnotis',
'total_bakiupah',
'total_nilaimarhun'
));
}
public function senaraimarhunnotis($notisid, $cawid)
{
$total_berat = 0;
$total_pinjaman = 0;
$total_upah = 0;
$total_hargaasas = 0;
$total_bakiupah = 0;
$total_nilaimarhun = 0;
$total_cazlelong = 0;
$rugilelong = 0;
$bakilelong = 0;
$keuntungan = 0;
$total_baki = 0;
$total_ktlhbyr = 0;
$total_bakipjm = 0;
$notis_id = $notisid;
$notislel = Notis::with('cawangan')->find($notis_id);
$cawanganDetail = $notislel->cawangan->find($cawid);
$caw = Cawangan::with(['notisBid' => function ($q) use ($notis_id) {
$q->where('notis_id', '=', $notis_id)->select('id', 'caw_id', 'kodcaw', 'norujukan', 'nokp', 'pinjaman', 'bakiupah');
}])
->where('caw_code', '=', $cawanganDetail->caw_code)->first();
$notisbid_data_pluck_norujukan = $caw->notisBid->pluck('norujukan')->toArray();
$notisbid_keyby_norujukan = $caw->notisBid->keyBy('norujukan');
$notis_all = Gadai::on($cawanganDetail->caw_code)->whereIn('norujukan', $notisbid_data_pluck_norujukan)
->select('nokp', 'jbg', 'norujukan', 'berat', 'nilaimarhun', 'pinjaman', 'bakiupah', 'kadarupah', 'bakipjm', 'tempoh', 'tempohbayar', 'sttebus')
->orderBy('norujukan', 'ASC')
->get();
$transaksi_all = TransaksiKeuntungan::on('main')->whereIn('norujukan', $notisbid_data_pluck_norujukan)
->select('keuntungan_rebet', 'bayaran_keuntungan', 'norujukan')
->get();
$transaksi_all_groupby_norujukan = $transaksi_all->groupBy('norujukan');
$notis_all_keyBy_norujukan = $notis_all->keyBy('norujukan');
foreach ($transaksi_all_groupby_norujukan as $index7 => $transaksi) {
// dd($notis_all_keyBy_norujukan);
if ($notis_all_keyBy_norujukan[$index7]) {
$gadai_true = $notis_all_keyBy_norujukan[$index7];
$gadai_true['data_transaksi'] = $transaksi;
}
// dd($transaksi);
}
$notis_all_data_pluck_nokp = $caw->notisBid->pluck('nokp')->toArray();
$customers = Customer::whereIn('kpbaru', $notis_all_data_pluck_nokp)
->orWhereIn('kplama', $notis_all_data_pluck_nokp)
->select('nama', 'telefon', 'kpbaru', 'kplama', 'alamat1', 'alamat2', 'alamat3')
->get();
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
foreach ($notis_all as $index1 => $gadai) {
if (isset($gadai['data_transaksi'])) {
$data_transaksi = $transaksi_all_groupby_norujukan[$gadai->norujukan];
$total_untung_rebet = $data_transaksi->sum('keuntungan_rebet');
$total_untung_asal = $data_transaksi->sum('bayaran_keuntungan');
$total_bayaran_pembiayaan = $data_transaksi->sum('bayaran_pembiayaan');
$beza_keuntungan = $total_untung_asal - $total_untung_rebet;
// dd($beza_keuntungan);
// dd(true);
$jbg = $gadai->tempoh - $gadai->tempohbayar;
$jbg2 = 12 - $gadai->tempohbayar;
if ($gadai->tempoh <= '12.00') {
$keuntungan = bcdiv(($jbg) * $gadai->kadarupah / 100 * $gadai->bakipjm, 1, 1) - $beza_keuntungan;
} else {
$keuntungan = bcdiv(($jbg2) * $gadai->kadarupah / 100 * $gadai->bakipjm, 1, 1) - $beza_keuntungan;
}
$ktlhbyr = $total_untung_asal;
$total_ktlhbyr = $total_ktlhbyr + $ktlhbyr;
$notis_all[$index1]['ktlhbyr'] = $ktlhbyr ? $ktlhbyr : 0.00;
} else {
// dd(false);
$jbg = $gadai->tempoh - $gadai->tempohbayar;
$jbg2 = 12 - $gadai->tempohbayar;
$beza_keuntungan = 0.00;
// dd($gadai->kadarupah);
if ($gadai->tempoh <= '12.00') {
// dd($jbg,$gadai->kadarupah, $gadai->bakipjm);
$keuntungan = bcdiv(($jbg) * $gadai->kadarupah / 100 * $gadai->pinjaman, 1, 1) - $beza_keuntungan;
} else {
// dd(false);
$keuntungan = bcdiv(($jbg2) * $gadai->kadarupah / 100 * $gadai->pinjaman, 1, 1) - $beza_keuntungan;
}
}
// dd($gadai->pinjaman);
if ($customers_keyBy_noKp[$gadai->nokp]) {
$notis_all[$index1]['cust_info'] = $customers_keyBy_noKp[$gadai->nokp];
}
$total_berat = $total_berat + $gadai['berat'];
$total_pinjaman = $total_pinjaman + $gadai['pinjaman'];
$total_bakipjm = $total_bakipjm + $gadai['bakipjm'];
$total_nilaimarhun = $total_nilaimarhun + $gadai['nilaimarhun'];
$total_bakiupah = $total_bakiupah + $gadai['bakiupah'];
$notis_all[$index1]['keuntungan'] = $keuntungan;
}
return view('notisperingatan.senaraimarhunnotis', compact('notis_all', 'total_berat',
'total_nilaimarhun',
'total_pinjaman',
'total_bakipjm',
'total_bakiupah',
'total_ktlhbyr',
'notislel',
'notis_id',
'cawid',
'cawanganDetail'));
}
public function kemaskinidatanotis(Request $request)
{
$user = Auth::user();
$currentdate = Carbon::now();
$currentdate = $currentdate->toDateTimeString();
$data = [];
$tarikhnotis = $request->tarikhnotis;
$notisid = $request->notisid;
$notis = Notis::with(['cawangan', 'notisBid', 'cawanganNotis'])->where('tarikh_notis', $tarikhnotis)->get();
foreach ($notis as $not) {
$cawanganAll = $not->cawangan;
$notBidGroupByCawId = $not->notisBid->groupBy('caw_id');
$notBidGroupByCawnotis = $not->cawanganNotis->groupBy('caw_id');
$notisbid_pluck_by_norujukan = $not->notisBid->pluck('norujukan')->toArray();
foreach ($cawanganAll as $caw_key_by_id) {
$cawanganDetail = $cawanganAll->find($caw_key_by_id['id']);
$gadai_all = Gadai::on($cawanganDetail['caw_code'])->whereIn('norujukan', $notisbid_pluck_by_norujukan)
->select('sttebus', 'kadarupah', 'nokp', 'tempoh', 'tempohbayar', 'norujukan', 'berat', 'nilaimarhun', 'pinjaman', 'bakipjm', 'bakiupah', 'hargajualan', 'bakihargajualan')
->orderBy('norujukan', 'ASC')
->get();
$gadai_all_groupby_norujukan = $gadai_all->groupBy('norujukan');
$transaksi_all = TransaksiKeuntungan::on('main')->whereIn('norujukan', $notisbid_pluck_by_norujukan)
->select('keuntungan_rebet', 'bayaran_keuntungan', 'norujukan')
->get();
// dd($transaksi_all);
$transaksi_all_groupby_norujukan = $transaksi_all->groupBy('norujukan');
if ($notBidGroupByCawId[$caw_key_by_id['id']]);
$caw_key_by_id['datagadai'] = $gadai_all_groupby_norujukan;
// dd($gadai_true['data_transaksi']);
}
foreach ($cawanganAll as $cawnot) {
foreach ($cawnot['datagadai'] as $index => $dataG) {
$data = $dataG[0];
if ($data['sttebus'] == 'T' || $data['sttebus'] == 'L') {
$lelongtebus = new LelongTebus;
$lelongtebus->tarikh = $currentdate;
$lelongtebus->kodcaw = $cawanganDetail['caw_code'];
$lelongtebus->teller = $user->name;
$lelongtebus->norujukan = $data['norujukan'];
$lelongtebus->batch_no = $not['id'];
$lelongtebus->nilaimarhun = $data['nilaimarhun'];
$lelongtebus->pinjaman = $data['pinjaman'];
$lelongtebus->upah = $data['bakiupah'];
$lelongtebus->jbg = $data['tempoh'];
if ($data['sttebus'] == 'T') {
$lelongtebus->jenis_tebus = 'T';
} elseif ($data['sttebus'] == 'L') {
$lelongtebus->jenis_tebus = 'L';
}
$lelongtebus->save();
// insert loguser
$loguser = new LogUser;
$loguser->user_id = $user->id;
$loguser->date = $currentdate;
$loguser->username = $user->username;
$loguser->nama_user = $user->name;
$loguser->norujukan = $data['norujukan'];
if ($data['sttebus'] == 'T') {
$loguser->nota = 'OUT NOTIS TEBUS '.$not['id'];
} elseif ($data['sttebus'] == 'L') {
$loguser->nota = 'OUT NOTIS LELONG '.$not['id'];
}
$loguser->save();
// hapus notisbid
$updatelelong = NotisBid::where('norujukan', '=', $data['norujukan'])->first();
$updatelelong->delete();
$checksag = NotisBid::where('kodcaw', $cawanganDetail['caw_code'])
->where('notis_id', $not['id'])
->first();
// dd($checksag);
if (empty($checksag)) {
$notisbatch = CawanganNotis::where('caw_id', '=', $cawanganDetail['id'])->first();
$notisbatch->delete();
// insert loguser
$loguser = new LogUser;
$loguser->user_id = $user->id;
$loguser->date = $currentdate;
$loguser->username = $user->username;
$loguser->nama_user = $user->name;
$loguser->nota = 'HAPUS CAW NOTIS '.$not['id'];
$loguser->save();
}
} else {
// insert loguser
$loguser = new LogUser;
$loguser->user_id = $user->id;
$loguser->date = $currentdate;
$loguser->username = $user->username;
$loguser->nama_user = $user->name;
$loguser->norujukan = $data['norujukan'];
$loguser->nota = 'KEMASKINI NOTIS'.$not['id'];
}
}
}
}
return redirect()->route('notisperingatan.shownotisperingatanall', [$tarikhnotis, $not['id']])
->with('success', 'Kemaskini Berjaya');
}
public function jananotisperingatan2(Request $request)
{
$notisid = $request->notisid;
$cawid = $request->cawid;
$user = Auth::user();
$caw = Cawangan::where('id', '=', $cawid)->first();
$currentdate = Carbon::now();
$tarikh_cetak = $currentdate->toDateString();
$notis = Notis::find($notisid);
// dd($notisid);
$arraynorujukan = NotisBid::where('notis_id', $notisid)->where('kodcaw', $caw->caw_code)->pluck('norujukan');
// dd($arraynorujukan);
$marhuns = Gadai::on($caw->caw_code)->whereIn('norujukan', $arraynorujukan)->select('nokp', 'norujukan', 'bakipjm', 't_matang', 'tempoh')->orderBy('nokp', 'asc')->get();
$marhuns_pluck_nokp = $marhuns->pluck('nokp');
$customers = Customer::whereIn('kpbaru', $marhuns_pluck_nokp)
->orWhereIn('kplama', $marhuns_pluck_nokp)
->join('poskod', 'customer.poskod', '=', 'poskod.poskod')
->join('daerah', 'poskod.koddaerah', '=', 'daerah.koddaerah')
->join('negeri', 'poskod.kodnegeri', '=', 'negeri.kodnegeri')
->get();
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
foreach ($marhuns as $index => $marhun) {
if ($customers_keyBy_noKp[$marhun->nokp]) {
$marhuns[$index]['nama'] = $customers_keyBy_noKp[$marhun->nokp];
$marhuns[$index]['notis'] = $notis;
}
}
// update status cetak
$updatestatus = CawanganNotis::where('notis_id', '=', $notisid)->where('caw_id', '=', $cawid)->first();
$updatestatus->status = '2';
$updatestatus->save();
$pdf = PDF::loadView('pdf.jananotisperingatan', compact('marhuns', 'notis', 'notisid', 'caw', 'tarikh_cetak'))
->setPaper('a4', 'potrait');
return $pdf->download('Penjanaan Notis Peringatan Fasa 1 '.$notisid.'.pdf');
}
public function jananotisperingatan2fasa2(Request $request)
{
$notisid = $request->notisid;
$cawid = $request->cawid;
$user = Auth::user();
$caw = Cawangan::where('id', '=', $cawid)->first();
$currentdate = Carbon::now();
$tarikh_cetak = $currentdate->toDateString();
$notis = Notis::find($notisid);
// dd($notisid);
$arraynorujukan = NotisBid::where('notis_id', $notisid)->where('kodcaw', $caw->caw_code)->pluck('norujukan');
// dd($arraynorujukan);
$marhuns = Gadai::on($caw->caw_code)->whereIn('norujukan', $arraynorujukan)->select('nokp', 'norujukan', 'bakipjm', 't_matang1', 'tempoh')->orderBy('nokp', 'asc')->get();
$marhuns_pluck_nokp = $marhuns->pluck('nokp');
$customers = Customer::whereIn('kpbaru', $marhuns_pluck_nokp)
->orWhereIn('kplama', $marhuns_pluck_nokp)
->join('poskod', 'customer.poskod', '=', 'poskod.poskod')
->join('daerah', 'poskod.koddaerah', '=', 'daerah.koddaerah')
->join('negeri', 'poskod.kodnegeri', '=', 'negeri.kodnegeri')
->get();
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
foreach ($marhuns as $index => $marhun) {
if ($customers_keyBy_noKp[$marhun->nokp]) {
$marhuns[$index]['nama'] = $customers_keyBy_noKp[$marhun->nokp];
$marhuns[$index]['notis'] = $notis;
}
}
// update status cetak
$updatestatus = CawanganNotis::where('notis_id', '=', $notisid)->where('caw_id', '=', $cawid)->first();
$updatestatus->status = '2';
$updatestatus->save();
$pdf = PDF::loadView('pdf.jananotisperingatan2', compact('marhuns', 'notis', 'notisid', 'caw', 'tarikh_cetak'))
->setPaper('a4', 'potrait');
return $pdf->download('Penjanaan Notis Peringatan Fasa 2 '.$notisid.'.pdf');
}
public function blastnotisperingatan1($notisid, $cawid)
{
$user = Auth::user();
$caw = Cawangan::where('id', '=', $cawid)->first();
$currentdate = Carbon::now();
$tarikh_cetak = $currentdate->toDateString();
$notis = Notis::find($notisid);
// dd($notis->tarikh_notis);
$notis_bid_all = NotisBid::select('id', 'nokp', 'norujukan', 'jbg', 'pinjaman', 'fasa')->where('notis_id', $notisid)->where('kodcaw', $caw->caw_code)->get();
$arraynorujukan_notis_bid_all = NotisBid::where('notis_id', $notisid)->where('kodcaw', $caw->caw_code)->pluck('norujukan');
$arraynorujukan = NotisBid::where('notis_id', $notisid)->where('kodcaw', $caw->caw_code)->pluck('norujukan');
$gadai_all = Gadai::on($caw->caw_code)->whereIn('norujukan', $arraynorujukan)->select('nokp', 'norujukan', 'bakipjm', 't_matang', 't_matang1', 'tempoh')->orderBy('nokp', 'asc')->get();
$customers_list = $gadai_all->pluck('nokp')->unique();
$customers = Customer::whereIn('kpbaru', $customers_list)
->orWhereIn('kplama', $customers_list)
->select('id', 'kpbaru', 'kplama', 'nama', 'telefon')
->get()->keyBy('id');
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
$customers_pluck_notel = $customers_keyBy_noKp->pluck('telefon');
// dd($customers_pluck_notel);
foreach ($customers_pluck_notel as $index1 => $custphone) {
// dd($custphone);
$special = preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $custphone);
// dump($special);
if ($special == 0) {
if ($custphone == '') {
$newtel = '';
} elseif ($custphone != '') {
$newtel = '6'.$custphone;
}
} elseif ($special == 1) {
if ($custphone == '') {
$newtel = '';
} elseif ($custphone != '') {
$newtel = '6'.str_replace(['-'], '', $custphone);
}
}
// dump($newtel);
}
$notis_bid_all_groupby_norujukan = $notis_bid_all->groupBy('norujukan');
$notis_all_keyBy_norujukan = $gadai_all->keyBy('norujukan');
foreach ($notis_bid_all_groupby_norujukan as $index7 => $notisbid) {
// dd($notis_all_keyBy_norujukan);
if ($notis_all_keyBy_norujukan[$index7]) {
$gadai_true = $notis_all_keyBy_norujukan[$index7];
$gadai_true['data_notisbid'] = $notisbid;
}
}
// dd($gadai_all);
foreach ($gadai_all as $index => $suratnotis) {
$datanotisbid = $suratnotis['data_notisbid'][0]->fasa;
// dd($suratnotis);
if ($customers_keyBy_noKp[$suratnotis->nokp]) {
$mobile_no = '60178916936';
// $mobile_no = $newtel;
$user_true = $customers_keyBy_noKp[$suratnotis->nokp];
$nama = $user_true->nama;
$bakipjm = number_format($suratnotis->bakipjm, 2, '.', ',');
$t_matang = Carbon::parse($suratnotis->t_matang);
$t_matang1 = Carbon::parse($suratnotis->t_matang1);
$t_matangf1 = $t_matang->format('d-m-Y');
$t_matangf2 = $t_matang1->format('d-m-Y');
$cawname = $caw->caw_name;
// dd($t_matang1);
if ($datanotisbid == '1') {
$message = '*NOTIS PEMBERITAHUAN*
Nama: *'.$nama.'*
No.KP: *'.$suratnotis->nokp.'*'.'
No.Rujukan: *'.$suratnotis->norujukan.'*
Baki Pembiayaan: *RM'.$bakipjm.'*'.'
Tarikh Matang: *'.$t_matangf1.'*
Tempoh: *'.$suratnotis->tempoh.' bulan*
Tuan/puan atau wakil adalah dikehendaki menebus/membayar *KOS KEUNTUNGAN* tersebut secepat mungkin. Jika pihak tuan/puan menghadapi sebarang masalah, sila hubungi kami sebagaimana alamat di dalam *Surat Akaun Gadaian* ATAU datang sendiri ke *'.$cawname.'* dengan membawa bersama salinan asal Surat Akaun Gadaian tuan/puan.
Sekian, terima kasih.';
} elseif ($datanotisbid == '2') {
$message = '*NOTIS PEMBERITAHUAN*
Nama: *'.$nama.'*
No.KP: *'.$suratnotis->nokp.'*
No.Rujukan: *'.$suratnotis->norujukan.'*
Baki Pembiayaan: *RM'.$bakipjm.'*'.'
Tarikh Tamat Kontrak: *'.$t_matangf2.'*
Tempoh: *'.$suratnotis->tempoh.' bulan*.
Tuan/puan atau wakil adalah dikehendaki menebus/membayar *KOS KEUNTUNGAN* tersebut secepat mungkin. Jika pihak tuan/puan menghadapi sebarang masalah, sila hubungi kami sebagaimana alamat di dalam *Surat Akaun Gadaian* ATAU datang sendiri ke *'.$cawname.'* dengan membawa bersama salinan asal Surat Akaun Gadaian tuan/puan.
Sekian, terima kasih.';
}
// dd($message);
// $message = 'Hello%20Nadine%0Ahow%20are%20you%0A';
if (config('app.env') != 'production') {
$mobile_no = config('app.admin_phone_number');
}
$response = Http::get(env('WABOT_API'), [
'number' => $mobile_no,
'type' => 'text',
'message' => $message,
'instance_id' => env('WABOT_INSTANCES_ID'),
'access_token' => env('WABOT_TOKEN_KEYS'),
]);
$res_json = $response->json();
if ($res_json['status'] == 'error') {
$message = 'WABOT: '.$res_json['message'].' - '.$res_json['data'];
Log::error($message);
} else {
$message = 'WABOT: Success '.$res_json['data']['key']['remoteJid'].' - '.$res_json['data']['message']['extendedTextMessage']['text'];
Log::info($message);
}
}
// dd($suratnotis['data_notisbid'][$index]);
}
$updatestatus = CawanganNotis::where('notis_id', '=', $notisid)->where('caw_id', '=', $cawid)->first();
$updatestatus->status = '3'; // blastwabot
$updatestatus->save();
return redirect()->route('notisperingatan.shownotisperingatanall', [$notis->tarikh_notis, $notisid])
->with('success', 'Kemaskini Berjaya');
}
public function blastnotisperingatan($notisid, $cawid)
{
$user = Auth::user();
$caw = Cawangan::where('id', '=', $cawid)->first();
$currentdate = Carbon::now();
$tarikh_cetak = $currentdate->toDateString();
$notis = Notis::find($notisid);
WhatsappNotisPeringatanKedua::dispatch($user->id, $user->kodcaw, $notisid, $cawid);
$updatestatus = CawanganNotis::where('notis_id', '=', $notisid)->where('caw_id', '=', $cawid)->first();
$updatestatus->status = '3'; // blastwabot
$updatestatus->save();
return redirect()->route('notisperingatan.shownotisperingatanall', [$notis->tarikh_notis, $notisid])
->with('success', 'Kemaskini Dalam Proses');
}
public function failedjob()
{
$failed = FailedJob::all();
return view('notisperingatan.failedjob', compact('failed'));
}
public function notistuntutbaki()
{
$user = Auth::user();
$lelongid = CawanganLelong::join('lelong', 'cawangan_lelong.lelong_id', '=', 'lelong.id')
->join('cawangan', 'cawangan_lelong.caw_id', '=', 'cawangan.id')
->where('cawangan.caw_code', '=', $user->kodcaw)
->where('lelong.sts_lelong', '=', 3)
->orderby('lelong.tarikh_lelong', 'DESC')
->get();
// dd($lelongid);
foreach ($lelongid as $index1 => $bil) {
$lel = Lelong::with('cawangan')->find($bil['lelong_id']);
// dd($bil['lelong_id']);
$cawanganDetail = $lel->cawangan->find($bil['caw_id']);
$lelong_id = $bil['lelong_id'];
$caw = Cawangan::with(['lelongBid' => function ($q) use ($lelong_id) {
$q->where('lelong_id', '=', $lelong_id)->select('id', 'caw_id', 'kodcaw', 'norujukan', 'pinjaman', 'bakiupah', 'hargaasas', 'nilaimarhun', 'cajlelong', 'baki');
}])
->where('caw_code', '=', $cawanganDetail->caw_code)->first();
$lelongbid_data_pluck_norujukan = $caw->lelongBid->pluck('norujukan')->toArray();
// $listsag = LelongBid::where('lelong_id', $bil['lelong_id'])
// ->where('kodcaw','=',$user->kodcaw)
// ->get();
$listsag = LelongCawangan::on($cawanganDetail->caw_code)->whereIn('lelong.norujukan', $lelongbid_data_pluck_norujukan)
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
->select('lelong.trkhtuntut', 'gadai.nokp', 'lelong.jbg', 'lelong.norujukan', 'lelong.berat', 'lelong.nilaimarhun', 'lelong.pinjaman', 'lelong.bakiupah', 'lelong.kadarupah', 'lelong.bakipjm', 'gadai.tempoh', 'gadai.tempohbayar', 'gadai.sttebus')
->where('trkhtuntut', '=', null)
->where('baki', '>', '0.00')
->orderBy('norujukan', 'ASC')
->get();
$lelongid[$index1]['bilangan'] = count($listsag);
// dd(sizeof($listsag));
$caw_id = $bil['caw_id'];
}
return view('jananotis.notistuntutbaki', compact('lelongid', 'caw_id', 'caw'));
}
public function senaraituntutbaki($lelongid, $cawid)
{
$total_berat = 0;
$total_pinjaman = 0;
$total_upah = 0;
$total_hargaasas = 0;
$total_bakiupah = 0;
$total_nilaimarhun = 0;
$total_cazlelong = 0;
$rugilelong = 0;
$bakilelong = 0;
$keuntungan = 0;
$total_baki = 0;
$total_ktlhbyr = 0;
$total_bakipjm = 0;
$total_cazlelong = 0;
$total_hargajual = 0;
$lelongid = $lelongid;
$lel = Lelong::with('cawangan')->find($lelongid);
$cawanganDetail = $lel->cawangan->find($cawid);
$caw = Cawangan::with(['lelongBid' => function ($q) use ($lelongid) {
$q->where('lelong_id', '=', $lelongid)->select('id', 'caw_id', 'kodcaw', 'norujukan', 'pinjaman', 'bakiupah', 'hargajual', 'nilaimarhun', 'cajlelong', 'baki');
}])
->where('caw_code', '=', $cawanganDetail->caw_code)->first();
$lelongbid_data_pluck_norujukan = $caw->lelongBid->pluck('norujukan')->toArray();
$lelongbid_keyby_norujukan = $caw->lelongBid->keyBy('norujukan');
$lelongbid_all = LelongCawangan::on($cawanganDetail->caw_code)->whereIn('lelong.norujukan', $lelongbid_data_pluck_norujukan)
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
->select('lelong.trkhtuntut', 'gadai.nokp', 'lelong.jbg', 'lelong.norujukan', 'lelong.berat', 'lelong.nilaimarhun', 'lelong.pinjaman', 'lelong.bakiupah', 'lelong.kadarupah', 'lelong.bakipjm', 'gadai.tempoh', 'gadai.tempohbayar', 'gadai.sttebus')
->where('trkhtuntut', '=', null)
->where('baki', '>', '0.00')
->orderBy('norujukan', 'ASC')
->get();
// dd($lelongbid_all);
$transaksi_all_groupby_norujukan = $caw->lelongBid->groupBy('norujukan');
foreach ($transaksi_all_groupby_norujukan as $index7 => $transaksi) {
if ($lelongbid_keyby_norujukan[$index7]) {
$gadai_true = $lelongbid_keyby_norujukan[$index7];
$gadai_true['data'] = $transaksi;
}
}
// dd($gadai_true['data_transaksi']);
foreach ($lelongbid_all as $index1 => $gadai) {
$data_transaksi = $transaksi_all_groupby_norujukan[$gadai->norujukan];
// dd($data_transaksi[0]['cajlelong']);
$total_berat = $total_berat + $gadai['berat'];
$total_pinjaman = $total_pinjaman + $gadai['pinjaman'];
$total_bakipjm = $total_bakipjm + $gadai['bakipjm'];
$total_nilaimarhun = $total_nilaimarhun + $gadai['nilaimarhun'];
$total_bakiupah = $total_bakiupah + $gadai['bakiupah'];
$total_cazlelong = $total_cazlelong + $data_transaksi[0]['cajlelong'];
$total_hargajual = $total_hargajual + $data_transaksi[0]['hargajual'];
$lelongbid_all[$index1]['lelongbid'] = $data_transaksi;
}
$arrayinfo = [];
$lelong_id = Lelong::join('cawangan_lelong', 'lelong.id', '=', 'cawangan_lelong.lelong_id')
->where('cawangan_lelong.lelong_id', '=', $lelongid)
->select('lelong_id', 'tarikh_lelong', 'lelong.fasa')
->groupBy('lelong_id')
->get()->toArray();
foreach ($lelong_id as $laporan) {
$details = CawanganLelong::join('cawangan', 'cawangan_lelong.caw_id', '=', 'cawangan.id')
->where('lelong_id', $laporan['lelong_id'])
->where('caw_id', $cawid)
->get()
->toArray();
array_push($arrayinfo, ['laporan' => $laporan, 'details' => $details]);
}
return view('lelong.senaraituntutbaki', compact('arrayinfo', 'lelongbid_all', 'total_berat',
'total_nilaimarhun',
'total_pinjaman',
'total_bakipjm',
'total_bakiupah',
'total_ktlhbyr',
'total_cazlelong',
'total_hargajual',
'lel',
'lelongid',
'cawid',
'cawanganDetail'));
}
public function surattuntutbakipdf($lelong_id)
{
// focus only on variable: $marhuns, $lelongid, $caw, $tarikh_cetak
// variable not use: $lelong_id, $customer, $listsag
$user = Auth::user();
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)->first();
$currentdate = Carbon::now();
$tarikh_cetak = $currentdate->toDateString();
$taxation = config('app.taxation');
// $lelongid = Lelong::find($lelong_id);
// $arraynorujukan = LelongBid::where('lelong_id', $lelong_id)->where('kodcaw', $caw->caw_code)->pluck('norujukan');
// $marhuns = Gadai::on($caw->caw_code)->whereIn('norujukan', $arraynorujukan)->select('nokp', 'norujukan')->orderBy('nokp', 'asc')->get();
$lel = Lelong::with('cawangan')->find($lelong_id);
$cawanganDetail = $lel->cawangan->find($caw->id);
$cawangan = Cawangan::with(['lelongBid' => function ($q) use ($lelong_id) {
$q->where('lelong_id', '=', $lelong_id)->select('id', 'caw_id', 'kodcaw', 'norujukan', 'pinjaman', 'bakiupah', 'hargaasas', 'nilaimarhun', 'cajlelong', 'baki');
}])
->where('caw_code', '=', $cawanganDetail->caw_code)->first();
$lelongbid_data_pluck_norujukan = $cawangan->lelongBid->pluck('norujukan')->toArray();
$marhuns = LelongCawangan::on($cawanganDetail->caw_code)->whereIn('lelong.norujukan', $lelongbid_data_pluck_norujukan)
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
->where('trkhtuntut', '=', null)
->where('baki', '>', '0.00')
->select('nokp', 'lelong.norujukan', 'lelong.t_lelong AS tarikhlelong', 'lelong.hargajual', 'lelong.gst_hj', 'gadai.bakipjm', 'lelong.bakiupah', 'lelong.cajlelong', 'lelong.gst_cl', 'lelong.cajlain', 'lelong.baki')
->orderBy('nokp', 'asc')
->orderBy('lelong.norujukan', 'ASC')
->get();
// dd($marhuns);
$marhuns_pluck_nokp = $marhuns->pluck('nokp');
$customers = Customer::whereIn('kpbaru', $marhuns_pluck_nokp)
->orWhereIn('kplama', $marhuns_pluck_nokp)
->join('poskod', 'customer.poskod', '=', 'poskod.poskod')
->join('daerah', 'poskod.koddaerah', '=', 'daerah.koddaerah')
->join('negeri', 'poskod.kodnegeri', '=', 'negeri.kodnegeri')
->get();
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
foreach ($marhuns as $index => $marhun) {
if ($customers_keyBy_noKp[$marhun->nokp]) {
$marhuns[$index]['nama'] = $customers_keyBy_noKp[$marhun->nokp];
}
}
$pdf = PDF::loadView('pdf.pdfnotistuntutbaki', compact('marhuns', 'lelong_id', 'caw', 'tarikh_cetak', 'taxation'))
->setPaper('a4', 'potrait');
$updatestatus = CawanganLelong::where('lelong_id', '=', $lelong_id)->where('caw_id', '=', $caw->id)->first();
$updatestatus->status = 1; // jana pdf tuntutbaki
$updatestatus->save();
return $pdf->download('Penjanaan Notis Tuntut Baki '.$lelong_id.'.pdf');
}
public function blastnotistuntutbaki($lelong_id, $caw_id)
{
$user = Auth::user();
$caw = Cawangan::where('id', '=', $caw_id)->first();
$bilblast = 0;
$currentdate = Carbon::now();
$lel = Lelong::find($lelong_id);
WhatsappNotisTuntutBaki::dispatch($user->id, $user->kodcaw, $lelong_id, $caw_id);
$updatestatus = CawanganLelong::where('lelong_id', '=', $lelong_id)->where('caw_id', '=', $caw_id)->first();
$bilblast = $updatestatus->bilblast;
$bilblast++;
$updatestatus->bilblast = $bilblast; // blastwabot
$updatestatus->save();
return redirect()->route('jananotis.notistuntutbaki')
->with('success', 'Blast Whatsapp Dalam Proses');
}
public function kemaskininotistuntutbaki(Request $request)
{
$tetapan = Tetapan::where('id', '=', 1)->get();
return view('parameter.kemaskininotistuntutbaki', compact('tetapan'));
}
public function storeparabaki(Request $request)
{
// dd($request->all());
$tetapan = Tetapan::find(1);
$tetapan->parabaki = $request->parabaki;
$tetapan->update();
$cawangan = Cawangan::all();
foreach ($cawangan as $updatecaw) {
$update = Cawangan::where('id', $updatecaw['id'])
->update(['parabaki' => $request->parabaki]);
// $update->para2 = $request->para2;
// $update->update();
}
return redirect()->route('parameter.kemaskininotistuntutbaki')
->with('success', 'Kemaskini Berjaya');
}
public function storeparabaki2(Request $request)
{
// dd($request->all());
$tetapan = Tetapan::find(1);
$tetapan->parabaki2 = $request->parabaki2;
$tetapan->update();
$cawangan = Cawangan::all();
foreach ($cawangan as $updatecaw) {
$update = Cawangan::where('id', $updatecaw['id'])
->update(['parabaki2' => $request->parabaki2]);
// $update->para2 = $request->para2;
// $update->update();
}
return redirect()->route('parameter.kemaskininotistuntutbaki')
->with('success', 'Kemaskini Berjaya');
}
public function listnotistuntutbaki()
{
$cawangan_all = Cawangan::with(['cawanganLelong'])
->withCount(['cawanganLelong' => function ($query) {
$query->where('export_data_sts', 'SUCCESS');
}])
->orderBy('caw_name', 'ASC')
->get();
// dd($cawangan_all);
foreach ($cawangan_all as $index3 => $cawangan) {
$cawangan_all_groupby_caw = $cawangan->groupBy('caw_code');
$cawangan_all[$index3]['cawangan_info'] = $cawangan;
}
return view('parameter.listnotistuntutbaki', compact('cawangan_all'));
}
public function listnotistuntutbakidetail($cawid)
{
$lelongid = CawanganLelong::join('lelong', 'cawangan_lelong.lelong_id', '=', 'lelong.id')
->join('cawangan', 'cawangan_lelong.caw_id', '=', 'cawangan.id')
->where('cawangan.id', '=', $cawid)
->where('lelong.sts_lelong', '=', 3)
->orderby('lelong.tarikh_lelong', 'DESC')
->get();
// dd($lelongid);
$cawanganDetail = Cawangan::where('id', $cawid)->first();
foreach ($lelongid as $index1 => $bil) {
$lel = Lelong::with('cawangan')->find($bil['lelong_id']);
// dd($bil['lelong_id']);
$cawanganDetail = $lel->cawangan->find($cawid);
$lelong_id = $bil['lelong_id'];
$caw = Cawangan::with(['lelongBid' => function ($q) use ($lelong_id) {
$q->where('lelong_id', '=', $lelong_id)->select('id', 'caw_id', 'kodcaw', 'norujukan', 'pinjaman', 'bakiupah', 'hargaasas', 'nilaimarhun', 'cajlelong', 'baki');
}])
->where('caw_code', '=', $cawanganDetail->caw_code)->first();
// dd($caw);
$lelongbid_data_pluck_norujukan = $caw->lelongBid->pluck('norujukan')->toArray();
// $listsag = LelongBid::where('lelong_id', $bil['lelong_id'])
// ->where('kodcaw','=',$user->kodcaw)
// ->get();
$listsag = LelongCawangan::on($cawanganDetail->caw_code)->whereIn('lelong.norujukan', $lelongbid_data_pluck_norujukan)
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
->select('lelong.trkhtuntut', 'gadai.nokp', 'lelong.jbg', 'lelong.norujukan', 'lelong.berat', 'lelong.nilaimarhun', 'lelong.pinjaman', 'lelong.bakiupah', 'lelong.kadarupah', 'lelong.bakipjm', 'gadai.tempoh', 'gadai.tempohbayar', 'gadai.sttebus')
->where('trkhtuntut', '=', null)
->where('baki', '>', '0.00')
->orderBy('norujukan', 'ASC')
->get();
// dd($cawanganDetail->caw_code);
$lelongid[$index1]['bilangan'] = count($listsag);
// dd(sizeof($listsag));
}
$caw_id = $cawid;
return view('parameter.listnotistuntutbakidetail', compact('lelongid', 'caw_id', 'cawanganDetail'));
}
public function listcawanganwtdproses()
{
$cawangan_all = Cawangan::orderBy('caw_name', 'asc')->get();
foreach ($cawangan_all as $index3 => $cawangan) {
$cawangan_all_groupby_caw = $cawangan->groupBy('caw_code');
$bilwtddraft = WtdDraft::on('main')
->selectRaw('COUNT(norujukan) as bilangan')
->where('kodcaw', $cawangan->caw_code)
->where('batchno_serah', '0')
->get();
// dd($wtddraft);
$wtddraft = WtdDraft::on('main')
->where('kodcaw', $cawangan->caw_code)
->where('batchno_serah', '0')
->get();
$wtddraft_groupby_caw = $wtddraft->groupBy('kodcaw');
$wtddraft_data_pluck_norujukan = $wtddraft->pluck('norujukan')->toArray();
$lelong_all = LelongCawangan::on($cawangan->caw_code)->whereIn('lelong.norujukan', $wtddraft_data_pluck_norujukan)
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
->select('nokp', 'lelong.norujukan', 'lelong.t_lelong AS tarikhlelong', 'lelong.hargajual', 'lelong.gst_hj', 'gadai.bakipjm', 'lelong.bakiupah', 'lelong.cajlelong', 'lelong.gst_cl', 'lelong.cajlain', 'lelong.baki')
->orderBy('nokp', 'asc')
->orderBy('lelong.norujukan', 'ASC')
->get();
$cawangan_all[$index3]['cawangan_info'] = $cawangan;
$cawangan_all[$index3]['bil'] = $bilwtddraft;
$cawangan_all[$index3]['jumlahbaki'] = number_format($lelong_all->SUM('baki'), 2, '.', ',');
}
return view('wtd.listcawanganwtdproses', compact('cawangan_all'));
}
public function listsagwtdproses($kodcaw)
{
$wtddraft = WtdDraft::on('main')
->where('kodcaw', $kodcaw)
->where('batchno_serah', '0')
->orderBy('norujukan', 'ASC')
->get();
$wtddraft_groupby_caw = $wtddraft->groupBy('kodcaw');
$wtddraft_data_pluck_norujukan = $wtddraft->pluck('norujukan')->toArray();
$lelong_all = LelongCawangan::on($kodcaw)->whereIn('lelong.norujukan', $wtddraft_data_pluck_norujukan)
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
->select('nokp', 'lelong.norujukan', 'lelong.t_jual', 'lelong.hargajual', 'lelong.gst_hj', 'lelong.pinjaman', 'lelong.bakiupah', 'lelong.cajlelong', 'lelong.gst_cl', 'lelong.cajlain', 'lelong.baki')
->orderBy('lelong.norujukan', 'ASC')
->get();
$cawanganDetail = Cawangan::where('caw_code', $kodcaw)->first();
$lelong_all_pluck_nokp = $lelong_all->pluck('nokp')->unique();
$customers = Customer::whereIn('kpbaru', $lelong_all_pluck_nokp)
->orWhereIn('kplama', $lelong_all_pluck_nokp)
->select('nama', 'kpbaru', 'kplama', 'alamat1', 'alamat2', 'alamat3', 'telefon')
->get();
// dd($customers->toArray());
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
$lelong_all_groupby_nokp = $lelong_all->groupBy('nokp');
$jumlahbil = count($lelong_all);
$jumlahbaki = number_format($lelong_all->SUM('baki'), 2, '.', ',');
foreach ($lelong_all as $index1 => $bil) {
if ($customers_keyBy_noKp[$bil->nokp]) {
$lelong_all[$index1]['cust_info'] = $customers_keyBy_noKp[$bil->nokp];
}
// dd($customers_keyBy_noKp[$bil->nokp]);
}
return view('wtd.listsagwtdproses', compact('lelong_all', 'kodcaw', 'cawanganDetail', 'jumlahbil', 'jumlahbaki'));
}
public function pdflistsagwtdproses($kodcaw)
{
$wtddraft = WtdDraft::on('main')
->where('kodcaw', $kodcaw)
->where('batchno_serah', '0')
->orderBy('norujukan', 'ASC')
->get();
$wtddraft_groupby_caw = $wtddraft->groupBy('kodcaw');
$wtddraft_data_pluck_norujukan = $wtddraft->pluck('norujukan')->toArray();
$lelong_all = LelongCawangan::on($kodcaw)->whereIn('lelong.norujukan', $wtddraft_data_pluck_norujukan)
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
->select('nokp', 'lelong.norujukan', 'lelong.t_jual', 'lelong.hargajual', 'lelong.gst_hj', 'lelong.pinjaman', 'lelong.bakiupah', 'lelong.cajlelong', 'lelong.gst_cl', 'lelong.cajlain', 'lelong.baki')
->orderBy('lelong.norujukan', 'ASC')
->get();
$cawanganDetail = Cawangan::where('caw_code', $kodcaw)->first();
$lelong_all_pluck_nokp = $lelong_all->pluck('nokp')->unique();
$customers = Customer::whereIn('kpbaru', $lelong_all_pluck_nokp)
->orWhereIn('kplama', $lelong_all_pluck_nokp)
->select('nama', 'kpbaru', 'kplama', 'alamat1', 'alamat2', 'alamat3', 'telefon')
->get();
// dd($customers->toArray());
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
$lelong_all_groupby_nokp = $lelong_all->groupBy('nokp');
$jumlahbil = count($lelong_all);
$jumlahbaki = number_format($lelong_all->SUM('baki'), 2, '.', ',');
foreach ($lelong_all as $index1 => $bil) {
if ($customers_keyBy_noKp[$bil->nokp]) {
$lelong_all[$index1]['cust_info'] = $customers_keyBy_noKp[$bil->nokp];
}
// dd($customers_keyBy_noKp[$bil->nokp]);
}
// return view('wtd.listsagwtdproses',compact('lelong_all','kodcaw','cawanganDetail','jumlahbil','jumlahbaki'));
$pdf = PDF::loadView('wtd.pdflistsagwtdproses', compact('lelong_all', 'kodcaw', 'cawanganDetail', 'jumlahbil', 'jumlahbaki'))
->setPaper('a4', 'potrait');
return $pdf->download('Senarai SAG WTD Dalam Proses '.$cawanganDetail->caw_name.'.pdf');
}
public function listsagwtdprosesbycust($cawid)
{
$keuntungan = 0;
$arraylistgadai = 0;
$cawanganDetail = Cawangan::where('id', $cawid)->first();
$wtddraft = WtdDraft::on('main')
->where('kodcaw', $cawanganDetail->caw_code)
->where('batchno_serah', '0')
->orderBy('norujukan', 'ASC')
->get();
$wtddraft_groupby_caw = $wtddraft->groupBy('kodcaw');
$wtddraft_data_pluck_norujukan = $wtddraft->pluck('norujukan')->toArray();
$lelongbid_keyby_norujukan = $wtddraft->keyBy('norujukan');
$lelong_all = LelongCawangan::on($cawanganDetail->caw_code)->whereIn('lelong.norujukan', $wtddraft_data_pluck_norujukan)
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
->select('nokp', 'lelong.norujukan', 'lelong.t_jual', 'lelong.hargajual', 'lelong.gst_hj', 'lelong.pinjaman', 'lelong.bakiupah', 'lelong.cajlelong', 'lelong.gst_cl', 'lelong.cajlain', 'lelong.baki')
->orderBy('lelong.norujukan', 'ASC')
->get();
$jumlahbil = count($lelong_all);
$jumlahbaki = number_format($lelong_all->SUM('baki'), 2, '.', ',');
$lelong_all_groupby_norujukan = $lelong_all->groupBy('norujukan');
$gadai_all_pluck_nokp = $lelong_all->pluck('nokp')->unique();
$customers = Customer::whereIn('kpbaru', $gadai_all_pluck_nokp)
->orWhereIn('kplama', $gadai_all_pluck_nokp)
->select('nama', 'kpbaru', 'kplama', 'alamat1', 'alamat2', 'alamat3', 'telefon')
->orderBy('nama', 'ASC')
->get();
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
// $gadai_all_groupby_nokp = $gadai_all->groupBy('nokp');
$gadai_all_keyBy_norujukan = $lelong_all->keyBy('norujukan');
$gadai_all_groupby_nokp = $gadai_all_keyBy_norujukan->groupBy('nokp');
// dd($gadai_all_groupby_nokp['961114106974']);
foreach ($customers as $index => $customer) {
if ($customer->kpbaru != '') {
$customers[$index]['nokp'] = $customer->kpbaru;
} elseif ($customer->kplama != '') {
$customers[$index]['nokp'] = $customer->kplama;
}
// dd($gadai_all_groupby_nokp, $customer, $gadai_all_groupby_nokp[$customer->nokp]);
if ($gadai_all_groupby_nokp[$customer->nokp]) {
$customers[$index]['gadai'] = $gadai_all_groupby_nokp[$customer->nokp];
}
// dd($customer);
foreach ($customer['gadai'] as $index2 => $datagadai) {
// dd($datagadai);
if ($lelongbid_keyby_norujukan[$datagadai->norujukan]) {
// dd(isset($datagadai['data_transaksi']));
$lelongbid_true = $lelongbid_keyby_norujukan[$datagadai->norujukan];
$pinjaman = $lelongbid_true->pinjaman;
$customer['gadai'][$index2]['pnjaman'] = $pinjaman;
}
}
// dd($customer);
}
return view('wtd.listsagwtdprosesbycust', compact('customers', 'cawanganDetail', 'cawid', 'jumlahbil', 'jumlahbaki'));
// return view('lelong.listsagbycust',compact('lelonglel','cawanganDetail','marhuns','lelongid','cawid','listsag','ktlhbyr','arrayinfo'));
}
public function pdflistsagwtdprosesbycust($cawid)
{
$keuntungan = 0;
$arraylistgadai = 0;
$cawanganDetail = Cawangan::where('id', $cawid)->first();
$wtddraft = WtdDraft::on('main')
->where('kodcaw', $cawanganDetail->caw_code)
->where('batchno_serah', '0')
->orderBy('norujukan', 'ASC')
->get();
$wtddraft_groupby_caw = $wtddraft->groupBy('kodcaw');
$wtddraft_data_pluck_norujukan = $wtddraft->pluck('norujukan')->toArray();
$lelongbid_keyby_norujukan = $wtddraft->keyBy('norujukan');
$lelong_all = LelongCawangan::on($cawanganDetail->caw_code)->whereIn('lelong.norujukan', $wtddraft_data_pluck_norujukan)
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
->select('nokp', 'lelong.norujukan', 'lelong.t_jual', 'lelong.hargajual', 'lelong.gst_hj', 'lelong.pinjaman', 'lelong.bakiupah', 'lelong.cajlelong', 'lelong.gst_cl', 'lelong.cajlain', 'lelong.baki')
->orderBy('lelong.norujukan', 'ASC')
->get();
$jumlahbil = count($lelong_all);
$jumlahbaki = number_format($lelong_all->SUM('baki'), 2, '.', ',');
$lelong_all_groupby_norujukan = $lelong_all->groupBy('norujukan');
$gadai_all_pluck_nokp = $lelong_all->pluck('nokp')->unique();
$customers = Customer::whereIn('kpbaru', $gadai_all_pluck_nokp)
->orWhereIn('kplama', $gadai_all_pluck_nokp)
->select('nama', 'kpbaru', 'kplama', 'alamat1', 'alamat2', 'alamat3', 'telefon')
->orderBy('nama', 'ASC')
->get();
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
// $gadai_all_groupby_nokp = $gadai_all->groupBy('nokp');
$gadai_all_keyBy_norujukan = $lelong_all->keyBy('norujukan');
$gadai_all_groupby_nokp = $gadai_all_keyBy_norujukan->groupBy('nokp');
// dd($gadai_all_groupby_nokp['961114106974']);
foreach ($customers as $index => $customer) {
if ($customer->kpbaru != '') {
$customers[$index]['nokp'] = $customer->kpbaru;
} elseif ($customer->kplama != '') {
$customers[$index]['nokp'] = $customer->kplama;
}
// dd($gadai_all_groupby_nokp, $customer, $gadai_all_groupby_nokp[$customer->nokp]);
if ($gadai_all_groupby_nokp[$customer->nokp]) {
$customers[$index]['gadai'] = $gadai_all_groupby_nokp[$customer->nokp];
}
// dd($customer);
foreach ($customer['gadai'] as $index2 => $datagadai) {
// dd($datagadai);
if ($lelongbid_keyby_norujukan[$datagadai->norujukan]) {
// dd(isset($datagadai['data_transaksi']));
$lelongbid_true = $lelongbid_keyby_norujukan[$datagadai->norujukan];
$pinjaman = $lelongbid_true->pinjaman;
$customer['gadai'][$index2]['pnjaman'] = $pinjaman;
}
}
// dd($customer);
}
$pdf = PDF::loadView('wtd.pdflistsagwtdprosesbycust', compact('customers', 'cawanganDetail', 'cawid', 'jumlahbil', 'jumlahbaki'))
->setPaper('a4', 'potrait');
return $pdf->download('Senarai SAG WTD By Customer Dalam Proses '.$cawanganDetail->caw_name.'.pdf');
}
public function excellistsagwtdproses($kodcaw)
{
$wtddraft = WtdDraft::on('main')
->where('kodcaw', $kodcaw)
->where('batchno_serah', '0')
->orderBy('norujukan', 'ASC')
->get();
$wtddraft_groupby_caw = $wtddraft->groupBy('kodcaw');
$wtddraft_data_pluck_norujukan = $wtddraft->pluck('norujukan')->toArray();
$lelong_all = LelongCawangan::on($kodcaw)->whereIn('lelong.norujukan', $wtddraft_data_pluck_norujukan)
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
->select('nokp', 'lelong.norujukan', 'lelong.t_jual', 'lelong.hargajual', 'lelong.gst_hj', 'lelong.pinjaman', 'lelong.bakiupah', 'lelong.cajlelong', 'lelong.gst_cl', 'lelong.cajlain', 'lelong.baki')
->orderBy('lelong.norujukan', 'ASC')
->get();
$cawanganDetail = Cawangan::where('caw_code', $kodcaw)->first();
$lelong_all_pluck_nokp = $lelong_all->pluck('nokp')->unique();
$customers = Customer::whereIn('kpbaru', $lelong_all_pluck_nokp)
->orWhereIn('kplama', $lelong_all_pluck_nokp)
->select('nama', 'kpbaru', 'kplama', 'alamat1', 'alamat2', 'alamat3', 'telefon')
->get();
// dd($customers->toArray());
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
$lelong_all_groupby_nokp = $lelong_all->groupBy('nokp');
$jumlahbil = count($lelong_all);
$jumlahbaki = number_format($lelong_all->SUM('baki'), 2, '.', ',');
foreach ($lelong_all as $index1 => $bil) {
if ($customers_keyBy_noKp[$bil->nokp]) {
$lelong_all[$index1]['cust_info'] = $customers_keyBy_noKp[$bil->nokp];
}
// dd($customers_keyBy_noKp[$bil->nokp]);
}
return view('wtd.excellistsagwtdproses', compact('lelong_all', 'kodcaw', 'cawanganDetail', 'jumlahbil', 'jumlahbaki'));
}
public function excellistsagwtdprosesbycust($cawid)
{
$keuntungan = 0;
$arraylistgadai = 0;
$cawanganDetail = Cawangan::where('id', $cawid)->first();
$wtddraft = WtdDraft::on('main')
->where('kodcaw', $cawanganDetail->caw_code)
->where('batchno_serah', '0')
->orderBy('norujukan', 'ASC')
->get();
$wtddraft_groupby_caw = $wtddraft->groupBy('kodcaw');
$wtddraft_data_pluck_norujukan = $wtddraft->pluck('norujukan')->toArray();
$lelongbid_keyby_norujukan = $wtddraft->keyBy('norujukan');
$lelong_all = LelongCawangan::on($cawanganDetail->caw_code)->whereIn('lelong.norujukan', $wtddraft_data_pluck_norujukan)
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
->select('nokp', 'lelong.norujukan', 'lelong.t_jual', 'lelong.hargajual', 'lelong.gst_hj', 'lelong.pinjaman', 'lelong.bakiupah', 'lelong.cajlelong', 'lelong.gst_cl', 'lelong.cajlain', 'lelong.baki')
->orderBy('lelong.norujukan', 'ASC')
->get();
$jumlahbil = count($lelong_all);
$jumlahbaki = number_format($lelong_all->SUM('baki'), 2, '.', ',');
$lelong_all_groupby_norujukan = $lelong_all->groupBy('norujukan');
$gadai_all_pluck_nokp = $lelong_all->pluck('nokp')->unique();
$customers = Customer::whereIn('kpbaru', $gadai_all_pluck_nokp)
->orWhereIn('kplama', $gadai_all_pluck_nokp)
->select('nama', 'kpbaru', 'kplama', 'alamat1', 'alamat2', 'alamat3', 'telefon')
->orderBy('nama', 'ASC')
->get();
$customers_keyBy_noKp = $customers->keyBy(function ($item) {
if ($item->kpbaru != '') {
return $item->kpbaru;
} elseif ($item->kplama != '') {
return $item->kplama;
}
});
// $gadai_all_groupby_nokp = $gadai_all->groupBy('nokp');
$gadai_all_keyBy_norujukan = $lelong_all->keyBy('norujukan');
$gadai_all_groupby_nokp = $gadai_all_keyBy_norujukan->groupBy('nokp');
// dd($gadai_all_groupby_nokp['961114106974']);
foreach ($customers as $index => $customer) {
if ($customer->kpbaru != '') {
$customers[$index]['nokp'] = $customer->kpbaru;
} elseif ($customer->kplama != '') {
$customers[$index]['nokp'] = $customer->kplama;
}
// dd($gadai_all_groupby_nokp, $customer, $gadai_all_groupby_nokp[$customer->nokp]);
if ($gadai_all_groupby_nokp[$customer->nokp]) {
$customers[$index]['gadai'] = $gadai_all_groupby_nokp[$customer->nokp];
}
// dd($customer);
foreach ($customer['gadai'] as $index2 => $datagadai) {
// dd($datagadai);
if ($lelongbid_keyby_norujukan[$datagadai->norujukan]) {
// dd(isset($datagadai['data_transaksi']));
$lelongbid_true = $lelongbid_keyby_norujukan[$datagadai->norujukan];
$pinjaman = $lelongbid_true->pinjaman;
$customer['gadai'][$index2]['pnjaman'] = $pinjaman;
}
}
// dd($customer);
}
return view('wtd.excellistsagwtdprosesbycust', compact('customers', 'cawanganDetail', 'cawid', 'jumlahbil', 'jumlahbaki'));
}
public function listwtdprosescaw()
{
$user = Auth::user();
$cawangan_all = Cawangan::where('caw_code', $user->kodcaw)->get();
foreach ($cawangan_all as $index3 => $cawangan) {
$cawangan_all_groupby_caw = $cawangan->groupBy('caw_code');
$bilwtddraft = WtdDraft::on('main')
->selectRaw('COUNT(norujukan) as bilangan')
->where('kodcaw', $cawangan->caw_code)
->where('batchno_serah', '0')
->get();
// dd($wtddraft);
$wtddraft = WtdDraft::on('main')
->where('kodcaw', $cawangan->caw_code)
->where('batchno_serah', '0')
->get();
$wtddraft_groupby_caw = $wtddraft->groupBy('kodcaw');
$wtddraft_data_pluck_norujukan = $wtddraft->pluck('norujukan')->toArray();
$lelong_all = LelongCawangan::on($cawangan->caw_code)->whereIn('lelong.norujukan', $wtddraft_data_pluck_norujukan)
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
->select('nokp', 'lelong.norujukan', 'lelong.t_lelong AS tarikhlelong', 'lelong.hargajual', 'lelong.gst_hj', 'gadai.bakipjm', 'lelong.bakiupah', 'lelong.cajlelong', 'lelong.gst_cl', 'lelong.cajlain', 'lelong.baki')
->orderBy('nokp', 'asc')
->orderBy('lelong.norujukan', 'ASC')
->get();
$cawangan_all[$index3]['cawangan_info'] = $cawangan;
$cawangan_all[$index3]['bil'] = $bilwtddraft;
$cawangan_all[$index3]['jumlahbaki'] = number_format($lelong_all->SUM('baki'), 2, '.', ',');
}
return view('wtd.listcawanganwtdproses', compact('cawangan_all'));
}
public function kemaskininotislelwabot(Request $request)
{
$tetapan = Tetapan::where('id', '=', 1)->get();
return view('template.notislelwabot', compact('tetapan'));
}
public function storepara2blast(Request $request)
{
$tetapan = Tetapan::find(1);
$tetapan->para2blast = $request->para2blast;
$tetapan->update();
$cawangan = Cawangan::all();
foreach ($cawangan as $updatecaw) {
$update = Cawangan::where('id', $updatecaw['id'])
->update(['para2blast' => $request->para2blast]);
}
return redirect()->route('parameter.kemaskininotislelwabot')
->with('success', 'Kemaskini Berjaya');
}
public function storepara3blast(Request $request)
{
$tetapan = Tetapan::find(1);
$tetapan->para3blast = $request->para3blast;
$tetapan->update();
$cawangan = Cawangan::all();
foreach ($cawangan as $updatecaw) {
$update = Cawangan::where('id', $updatecaw['id'])
->update(['para3blast' => $request->para3blast]);
}
return redirect()->route('parameter.kemaskininotislelwabot')
->with('success', 'Kemaskini Berjaya');
}
public function blastnotislelongfasa1($lelong_id)
{
$user = Auth::user();
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)->first();
$currentdate = Carbon::now();
$lel = Lelong::find($lelong_id);
WhatsappNotisLelongFasa1::dispatch($user->id, $user->kodcaw, $lelong_id);
// insert loguser
$loguser = new LogUser;
$loguser->user_id = $user->id;
$loguser->date = $currentdate;
$loguser->username = $user->username;
$loguser->nama_user = $user->name;
$loguser->nota = 'BLAST NOTIS LELONG FASA 1: '.$lelong_id;
$loguser->save();
return redirect()->route('jananotis.notislelong')
->with('success', 'Blast Whatsapp Dalam Proses');
}
public function blastnotislelongfasa2($lelong_id)
{
$user = Auth::user();
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)->first();
$currentdate = Carbon::now();
$lel = Lelong::find($lelong_id);
WhatsappNotisLelongFasa2::dispatch($user->id, $user->kodcaw, $lelong_id);
// insert loguser
$loguser = new LogUser;
$loguser->user_id = $user->id;
$loguser->date = $currentdate;
$loguser->username = $user->username;
$loguser->nama_user = $user->name;
$loguser->nota = 'BLAST NOTIS LELONG FASA 2: '.$lelong_id;
$loguser->save();
return redirect()->route('jananotis.notislelong')
->with('success', 'Blast Whatsapp Dalam Proses');
}
}