471 lines
14 KiB
PHP
471 lines
14 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Spatie\Permission\Models\Role;
|
|
use Spatie\Permission\Models\Permission;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Models\User;
|
|
use App\Models\Cawangan;
|
|
use App\Models\LelongBidder;
|
|
use App\Models\Lelong;
|
|
use App\Models\CawanganLelong;
|
|
use App\Models\LelongBid;
|
|
use App\Models\Payment;
|
|
use App\Models\Resit;
|
|
use App\Models\Gadai;
|
|
use App\Models\Daerah;
|
|
use App\Models\Negeri;
|
|
use App\Models\Tetapan;
|
|
use App\Models\Customer;
|
|
|
|
use Carbon\Carbon;
|
|
use PDF;
|
|
use DateTime;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Excel;
|
|
|
|
|
|
|
|
|
|
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'] = sizeof($listsag);
|
|
// dd(sizeof($listsag));
|
|
|
|
}
|
|
|
|
return view('jananotis.notislelong',compact('lelongid'));
|
|
}
|
|
|
|
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 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();
|
|
|
|
$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();
|
|
|
|
$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;
|
|
} else if ($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.jananotis', compact('marhuns', 'lelongid', 'caw', 'tarikh_cetak'))
|
|
->setPaper('a4', 'potrait');
|
|
|
|
return $pdf->download('Penjanaan Notis Fasa 1:Batch Lelong ' . $lelong_id . '.pdf');
|
|
}
|
|
|
|
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);
|
|
|
|
$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']);
|
|
|
|
}
|
|
|
|
if($request->type == 'excel')
|
|
{
|
|
|
|
return view('excel.listnotis_excel',compact('marhuns','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 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();
|
|
|
|
$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')
|
|
->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();
|
|
|
|
// return view('pdf.jananotisfasa2',compact('marhuns','lelong_id','lelongid','caw','tarikh_cetak','customer','listsag'));
|
|
$pdf = PDF::loadView('pdf.jananotisfasa2',compact('marhuns','lelong_id','lelongid','caw','tarikh_cetak','customer','listsag'))
|
|
->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');
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|