1523 lines
59 KiB
PHP
1523 lines
59 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 PDF;
|
|
use App\Models\Cawangan;
|
|
use App\Models\JenisEmas;
|
|
use App\Models\JenisKarat;
|
|
use App\Models\Gadai;
|
|
use App\Models\Lelong;
|
|
use App\Models\CawanganLelong;
|
|
use App\Models\FileMarhun;
|
|
use App\Models\LelongBid;
|
|
use App\Models\LelongBidMarhun;
|
|
use App\Models\LelKarat;
|
|
use App\Models\LelKarat_temp;
|
|
use App\Models\Pengesahan;
|
|
use App\Models\GadaiMarhun;
|
|
use App\Models\ScanSemak;
|
|
use App\Models\TangguhLelong;
|
|
use Carbon\Carbon;
|
|
use App\Models\ScanMarhun;
|
|
|
|
class MarhunController extends Controller
|
|
{
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
/**
|
|
* Show the application dashboard.
|
|
*
|
|
* @return \Illuminate\Contracts\Support\Renderable
|
|
*/
|
|
|
|
//Khazanah
|
|
public function index($lelong_id)
|
|
{
|
|
$user = Auth::user();
|
|
|
|
$caw = Cawangan::where('caw_code','=',$user->kodcaw)->first();
|
|
|
|
$lelongbid = LelongBid::where('lelong_id', '=', $lelong_id) //keseluruhan
|
|
->where('caw_id','=', $caw->id)
|
|
->get();
|
|
// dd($lelongbid->toArray());
|
|
|
|
$sag = LelongBid::where('lelong_id', $lelong_id) //belum disemak
|
|
->where('caw_id', $caw->id)
|
|
->where('status_semak', 0)
|
|
->get();
|
|
// dd($sag);
|
|
|
|
//Get data filtered which is other than tangguh lelong from PC
|
|
|
|
$sdhdisemak = LelongBid::where('lelongbid.lelong_id', $lelong_id)
|
|
->where('lelongbid.caw_id', $caw->id)
|
|
->where('lelongbid.status_semak', 1)
|
|
->get();
|
|
// dd($sdhdisemak);
|
|
|
|
$dalamproses = Pengesahan::select('pengesahan.norujukan')
|
|
->join('lelongbid', 'pengesahan.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('pengesahan.lelong_id', $lelong_id)
|
|
->where('lelongbid.caw_id','=', $caw->id)
|
|
->where('pengesahan.diminta_oleh', $user['id'])
|
|
->where('pengesahan.status', 0)
|
|
->where('pengesahan.status_ubah', '!=', 6)
|
|
->whereNull('pengesahan.disahkan_oleh')
|
|
->distinct()
|
|
->get();
|
|
// dd($dalamproses);
|
|
|
|
$sdhdisahkan = Pengesahan::join('lelongbid', 'pengesahan.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('pengesahan.diminta_oleh', $user['id'])
|
|
->where('pengesahan.status', 1)
|
|
->where('pengesahan.status_ubah', '!=', 6)
|
|
->where('pengesahan.lelong_id', $lelong_id)
|
|
->whereNotNull('pengesahan.disahkan_oleh')
|
|
->where('lelongbid.status_semak', 1)
|
|
->get();
|
|
// dd($sdhdisahkan);
|
|
|
|
//Get data filtered which is from PC
|
|
$sdhdisemaktangguhlel = LelongBid::join('pengesahan', 'lelongbid.id', '=', 'pengesahan.lelongbid_id')
|
|
->where('lelongbid.lelong_id', $lelong_id)
|
|
->where('lelongbid.caw_id', $caw->id)
|
|
->where('lelongbid.status_semak', 1)
|
|
->where('pengesahan.status', 2)
|
|
->where('pengesahan.status_ubah', 6)
|
|
->get();
|
|
|
|
$dalamprosestangguhlel = Pengesahan::join('lelongbid', 'pengesahan.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('pengesahan.lelong_id', $lelong_id)
|
|
->where('lelongbid.caw_id','=', $caw->id)
|
|
->where('pengesahan.status', 2)
|
|
->where('pengesahan.status_ubah', 6)
|
|
->whereNull('pengesahan.disahkan_oleh')
|
|
->get();
|
|
|
|
$sdhdisahkantangguhlel = Pengesahan::join('lelongbid', 'pengesahan.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('pengesahan.status', 2)
|
|
->where('pengesahan.status_ubah', 6)
|
|
->where('pengesahan.lelong_id', $lelong_id)
|
|
->where('caw_id','=', $caw->id)
|
|
->whereNotNull('pengesahan.disahkan_oleh')
|
|
->where('lelongbid.status_semak', 1)
|
|
->distinct()
|
|
->get();
|
|
|
|
foreach($lelongbid as $index1=>$bid)
|
|
{
|
|
$sudahdisahkan = Pengesahan::where('lelongbid_id', $bid['id'])
|
|
->where('lelong_id', $lelong_id)
|
|
->get();
|
|
|
|
$statusdrpdpc = Pengesahan::where('lelongbid_id', $bid['id'])
|
|
->where('lelong_id', $lelong_id)
|
|
->where('status_ubah', 6)
|
|
->first();
|
|
|
|
$statusSemakMarhun = ScanSemak::where('lelongbid_id', $bid['id'])
|
|
->whereNotNull('scan_keluar')
|
|
->whereNull('serah_marhun')
|
|
->first();
|
|
if ($statusSemakMarhun) {
|
|
$lelongbid[$index1]['statusterimamarhun'] = 1;
|
|
}
|
|
|
|
$lelongbid[$index1]['statustangguhlel'] = $statusdrpdpc;
|
|
|
|
if($sudahdisahkan)
|
|
{
|
|
foreach($sudahdisahkan as $sahkan)
|
|
{
|
|
// dd($sahkan);
|
|
$lelongbidmarhun = LelongBidMarhun::join('pengesahan', 'lelongbidmarhun.id', '=', 'pengesahan.lelongbidmarhun_id')
|
|
->where('lelongbidmarhun.id', $sahkan['lelongbidmarhun_id'])
|
|
->select('pengesahan.disahkan_oleh',
|
|
'pengesahan.disahkan_pada'
|
|
)
|
|
->first();
|
|
|
|
$lelongbid[$index1]['pengesahan'] = $lelongbidmarhun;
|
|
// dd($lelongbid[$index1]['pengesahan']);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
}
|
|
|
|
$marhun = LelongBidMarhun::where('lelongbid_id','=',$bid['id'])->get()->toArray();;
|
|
$lelongbid[$index1]['marhun'] = $marhun;
|
|
|
|
}
|
|
|
|
return view('marhun.senaraimarhun',compact('lelongbid','lelong_id', 'caw', 'sag', 'dalamproses', 'sdhdisemak', 'sdhdisahkan', 'sdhdisemaktangguhlel',
|
|
'dalamprosestangguhlel', 'sdhdisahkantangguhlel'
|
|
));
|
|
}
|
|
|
|
public function kemaskini(Request $request)
|
|
{
|
|
// dd($request->all());
|
|
//idmarhun => lelongbidmarhun_id
|
|
$user = Auth::user();
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateTimeString();
|
|
|
|
$marhun = LelongBidMarhun::where('id','=',$request->idmarhun)->first();
|
|
$lelongbid = LelongBid::where('id','=',$marhun->lelongbid_id)->first();
|
|
// dd($marhun);
|
|
|
|
if($marhun->marhun != $request->marhun)
|
|
{
|
|
$txtmarhun = ",1 " . $marhun->marhun ;
|
|
$lelongbid->marhun = $lelongbid->marhun ."1 " . $request->marhun . "," ;
|
|
$lelongbid->marhun = str_replace( $txtmarhun,"",$lelongbid->marhun);
|
|
}
|
|
$caw = CawanganLelong::where('id','=',$lelongbid->caw_id)->first();
|
|
$lelong = Lelong::where('id','=',$lelongbid->lelong_id)->first();
|
|
|
|
$ubahberatmin = 0.3;
|
|
$bezaberat = $marhun->old_berat - $request->berat_emas;
|
|
$bezahargaasas = $marhun->old_hargaasas - $request->harga_asas;
|
|
|
|
if(($request->karat < $marhun->old_karat) && ($bezaberat > $ubahberatmin))
|
|
{
|
|
$marhun->marhun = $request->marhun;
|
|
$marhun->karat = $request->karat;
|
|
$marhun->berat = $request->berat_emas;
|
|
$marhun->harga = $request->harga;
|
|
$marhun->n_marhun = $request->nilai_marhun;
|
|
$marhun->hargaasas = $request->harga_asas;
|
|
$marhun->save();
|
|
|
|
$lelongbid->berat = $lelongbid->berat - ($bezaberat);
|
|
$lelongbid->hargaasas = $lelongbid->hargaasas - ($bezahargaasas);
|
|
$lelongbid->save();
|
|
|
|
$pengesahan = Pengesahan::where('lelongbidmarhun_id', $request->idmarhun)
|
|
->where('lelongbid_id', $marhun->lelongbid_id)
|
|
->get();
|
|
|
|
if(isset($pengesahan['id']))
|
|
{
|
|
$pengesahan->id = $pengesahan->id;
|
|
$pengesahan->lelong_id = $lelong->id;
|
|
$pengesahan->lelongbid_id = $lelongbid->id;
|
|
$pengesahan->lelongbidmarhun_id = $marhun->id;
|
|
$pengesahan->norujukan = $lelongbid->norujukan;
|
|
$pengesahan->diminta_oleh = $user->id;
|
|
$pengesahan->diminta_pada = $currentdate;
|
|
$pengesahan->status_ubah = 5;
|
|
$pengesahan->save();
|
|
}
|
|
else
|
|
{
|
|
$berat = new Pengesahan;
|
|
$berat->lelong_id = $lelong->id;
|
|
$berat->lelongbid_id = $lelongbid->id;
|
|
$berat->lelongbidmarhun_id = $marhun->id;
|
|
$berat->norujukan = $lelongbid->norujukan;
|
|
$berat->diminta_oleh = $user->id;
|
|
$berat->diminta_pada = $currentdate;
|
|
$berat->status_ubah = 5;
|
|
$berat->save();
|
|
}
|
|
|
|
}
|
|
|
|
else if($request->karat < $marhun->old_karat)
|
|
{
|
|
$marhun->marhun = $request->marhun;
|
|
$marhun->karat = $request->karat;
|
|
$marhun->berat = $request->berat_emas;
|
|
$marhun->harga = $request->harga;
|
|
$marhun->n_marhun = $request->nilai_marhun;
|
|
$marhun->hargaasas = $request->harga_asas;
|
|
$marhun->save();
|
|
|
|
$pengesahan = Pengesahan::where('lelongbidmarhun_id', $request->idmarhun)
|
|
->where('lelongbid_id', $marhun->lelongbid_id)
|
|
->get();
|
|
|
|
if(isset($pengesahan['id']))
|
|
{
|
|
$pengesahan->id = $pengesahan->id;
|
|
$pengesahan->lelong_id = $lelong->id;
|
|
$pengesahan->lelongbid_id = $lelongbid->id;
|
|
$pengesahan->lelongbidmarhun_id = $marhun->id;
|
|
$pengesahan->norujukan = $lelongbid->norujukan;
|
|
$pengesahan->diminta_oleh = $user->id;
|
|
$pengesahan->diminta_pada = $currentdate;
|
|
$pengesahan->status_ubah = 1;
|
|
$pengesahan->save();
|
|
}
|
|
else
|
|
{
|
|
$karat = new Pengesahan;
|
|
$karat->lelong_id = $lelong->id;
|
|
$karat->lelongbid_id = $lelongbid->id;
|
|
$karat->lelongbidmarhun_id = $marhun->id;
|
|
$karat->norujukan = $lelongbid->norujukan;
|
|
$karat->diminta_oleh = $user->id;
|
|
$karat->diminta_pada = $currentdate;
|
|
$karat->status_ubah = 1;
|
|
$karat->save();
|
|
}
|
|
}
|
|
|
|
else if($bezaberat > $ubahberatmin)
|
|
{
|
|
$marhun->marhun = $request->marhun;
|
|
$marhun->karat = $request->karat;
|
|
$marhun->berat = $request->berat_emas;
|
|
$marhun->harga = $request->harga;
|
|
$marhun->n_marhun = $request->nilai_marhun;
|
|
$marhun->hargaasas = $request->harga_asas;
|
|
$marhun->save();
|
|
|
|
$lelongbid->berat = $lelongbid->berat - ($bezaberat);
|
|
$lelongbid->hargaasas = $lelongbid->hargaasas - ($bezahargaasas);
|
|
$lelongbid->save();
|
|
|
|
$pengesahan = Pengesahan::where('lelongbidmarhun_id', $request->idmarhun)
|
|
->where('lelongbid_id', $marhun->lelongbid_id)
|
|
->get();
|
|
|
|
if(isset($pengesahan['id']))
|
|
{
|
|
$pengesahan->id = $pengesahan->id;
|
|
$pengesahan->lelong_id = $lelong->id;
|
|
$pengesahan->lelongbid_id = $lelongbid->id;
|
|
$pengesahan->lelongbidmarhun_id = $marhun->id;
|
|
$pengesahan->norujukan = $lelongbid->norujukan;
|
|
$pengesahan->diminta_oleh = $user->id;
|
|
$pengesahan->diminta_pada = $currentdate;
|
|
$pengesahan->status_ubah = 4;
|
|
$pengesahan->save();
|
|
}
|
|
else
|
|
{
|
|
$berat = new Pengesahan;
|
|
$berat->lelong_id = $lelong->id;
|
|
$berat->lelongbid_id = $lelongbid->id;
|
|
$berat->lelongbidmarhun_id = $marhun->id;
|
|
$berat->norujukan = $lelongbid->norujukan;
|
|
$berat->diminta_oleh = $user->id;
|
|
$berat->diminta_pada = $currentdate;
|
|
$berat->status_ubah = 4;
|
|
$berat->save();
|
|
}
|
|
|
|
}
|
|
//beza berat kurang daripada 0.30 & penambahan berat (tak perlu pengesahan)
|
|
else
|
|
{
|
|
$marhun->id = $request->idmarhun;
|
|
$marhun->marhun = $request->marhun;
|
|
$marhun->karat = $request->karat;
|
|
$marhun->berat = $request->berat_emas;
|
|
$marhun->harga = $request->harga;
|
|
$marhun->n_marhun = $request->nilai_marhun;
|
|
$marhun->hargaasas = $request->harga_asas;
|
|
$marhun->save();
|
|
|
|
$pengesahan = Pengesahan::where('lelongbidmarhun_id', $request->idmarhun)
|
|
->where('lelongbid_id', $marhun->lelongbid_id)
|
|
->delete();
|
|
|
|
$lelongbid->berat = $lelongbid->berat - ($bezaberat);
|
|
$lelongbid->hargaasas = $lelongbid->hargaasas - ($bezahargaasas);
|
|
$lelongbid->save();
|
|
}
|
|
|
|
return redirect()->route('marhun.show', [$lelongbid->id, $lelong->id])
|
|
->with('success','Kemaskini Marhun Berjaya, SILA KLIK BUTANG SEMAK DIBAWAH UNTUK MEMBUAT PENGEMASKINIAN');
|
|
}
|
|
|
|
public function kemaskiniMarhun(Request $request) {
|
|
// dd($request->all());
|
|
$user = Auth::user();
|
|
$currentdate = Carbon::now();
|
|
// $currentdate = $currentdate->toDateTimeString();
|
|
$lelongBidMarhun = LelongBidMarhun::where('id','=',$request->idmarhun)->first();
|
|
$lelongbid = LelongBid::where('id','=',$lelongBidMarhun->lelongbid_id)->first();
|
|
$lelong = Lelong::where('id','=',$lelongbid->lelong_id)->first();
|
|
|
|
// $perluPengesahan = false;
|
|
$parameterBezaBerat = 0.3; //parameterBezaBerat = (berat sebelum) - (berat selepas)
|
|
$bezaBerat = $lelongBidMarhun->berat - $request->berat_emas;
|
|
|
|
if ($bezaBerat > $parameterBezaBerat && $lelongBidMarhun->karat > $request->karat) {
|
|
$pengesahan = new Pengesahan;
|
|
$pengesahan->lelong_id = $lelong->id;
|
|
$pengesahan->lelongbid_id = $lelongbid->id;
|
|
$pengesahan->lelongbidmarhun_id = $lelongBidMarhun->id;
|
|
$pengesahan->norujukan = $lelongbid->norujukan;
|
|
$pengesahan->diminta_oleh = $user->id;
|
|
$pengesahan->diminta_pada = $currentdate->toDateTimeString();
|
|
$pengesahan->status_ubah = 5; //ubah mutu & berat
|
|
$pengesahan->request_berat = $request->berat_emas;
|
|
$pengesahan->request_karat = $request->karat;
|
|
$pengesahan->save();
|
|
// dd($pengesahan);
|
|
|
|
}
|
|
else if ($bezaBerat > $parameterBezaBerat) {
|
|
$pengesahan = new Pengesahan;
|
|
$pengesahan->lelong_id = $lelong->id;
|
|
$pengesahan->lelongbid_id = $lelongbid->id;
|
|
$pengesahan->lelongbidmarhun_id = $lelongBidMarhun->id;
|
|
$pengesahan->norujukan = $lelongbid->norujukan;
|
|
$pengesahan->diminta_oleh = $user->id;
|
|
$pengesahan->diminta_pada = $currentdate->toDateTimeString();
|
|
$pengesahan->status_ubah = 4; //ubah berat
|
|
$pengesahan->request_berat = $request->berat_emas;
|
|
$pengesahan->save();
|
|
}
|
|
else if ($lelongBidMarhun->karat > $request->karat) {
|
|
$pengesahan = new Pengesahan;
|
|
$pengesahan->lelong_id = $lelong->id;
|
|
$pengesahan->lelongbid_id = $lelongbid->id;
|
|
$pengesahan->lelongbidmarhun_id = $lelongBidMarhun->id;
|
|
$pengesahan->norujukan = $lelongbid->norujukan;
|
|
$pengesahan->diminta_oleh = $user->id;
|
|
$pengesahan->diminta_pada = $currentdate->toDateTimeString();
|
|
$pengesahan->status_ubah = 1; //ubah karat
|
|
$pengesahan->request_karat = $request->karat;
|
|
$pengesahan->save();
|
|
}
|
|
else {
|
|
// $lelongBidMarhun->id;
|
|
$lelongBidMarhun->marhun = $request->marhun;
|
|
$lelongBidMarhun->old_berat = $lelongBidMarhun->berat;
|
|
$lelongBidMarhun->old_karat = $lelongBidMarhun->karat;
|
|
$lelongBidMarhun->old_nmarhun = $lelongBidMarhun->n_marhun;
|
|
$lelongBidMarhun->berat = $request->berat_emas;
|
|
$lelongBidMarhun->karat = $request->karat;
|
|
$lelongBidMarhun->n_marhun = $request->berat_emas * $lelongBidMarhun->harga;
|
|
$lelongBidMarhun->update();
|
|
|
|
// $existingPengesahan = Pengesahan::where('lelongbidmarhun_id', '=', $request->idmarhun)
|
|
// ->first()
|
|
// ->delete();
|
|
}
|
|
|
|
// if ($perluPengesahan == true) {
|
|
// $pengesahan = Pengesahan::where('lelongbidmarhun_id', $request->idmarhun)
|
|
// ->where('lelongbid_id', $lelongBidMarhun->lelongbid_id)
|
|
// ->first();
|
|
|
|
// if(!$pengesahan)
|
|
// {
|
|
|
|
// $pengesahan = new Pengesahan;
|
|
// $pengesahan->lelong_id = $lelong->id;
|
|
// $pengesahan->lelongbid_id = $lelongbid->id;
|
|
// $pengesahan->lelongbidmarhun_id = $lelongBidMarhun->id;
|
|
// $pengesahan->norujukan = $lelongbid->norujukan;
|
|
// $pengesahan->diminta_oleh = $user->id;
|
|
// $pengesahan->diminta_pada = $currentdate;
|
|
// $pengesahan->status_ubah = 1;
|
|
// $pengesahan->save();
|
|
|
|
// } else {
|
|
// $pengesahan->id;
|
|
// $pengesahan->lelong_id = $lelong->id;
|
|
// $pengesahan->lelongbid_id = $lelongbid->id;
|
|
// $pengesahan->lelongbidmarhun_id = $lelongBidMarhun->id;
|
|
// $pengesahan->norujukan = $lelongbid->norujukan;
|
|
// $pengesahan->diminta_oleh = $user->id;
|
|
// $pengesahan->diminta_pada = $currentdate;
|
|
// $pengesahan->status_ubah = 1;
|
|
// $pengesahan->update();
|
|
// }
|
|
// }
|
|
// dd($lelongBidMarhun);
|
|
|
|
// $totallelbid = LelongBid::where('id', $lelongBidMarhun->lelongbid_id)->first();
|
|
// dd($totallelbid);
|
|
return redirect()->route('marhun.show', [$lelongbid->id, $lelong->id])->with('success','Kemaskini Marhun Berjaya, SILA KLIK BUTANG SEMAK DIBAWAH UNTUK MEMBUAT PENGEMASKINIAN');
|
|
}
|
|
|
|
public function show($id, $lelong_id)
|
|
{
|
|
$lelongbid = LelongBid::where('id', '=', $id)->first();
|
|
$filemarhun = FileMarhun::where('lelongbid_id', '=', $lelongbid['id'])
|
|
->where('photo_type', '=', '1')->first();
|
|
if (isset($filemarhun)) {
|
|
$lelongbid->filemarhun_filename = $filemarhun->filename;
|
|
$lelongbid->filemarhun_id = $filemarhun->id;
|
|
}
|
|
$marhun = LelongBidMarhun::with(
|
|
// ['pengesahan' => function ($query)
|
|
// {
|
|
// $query->select('norujukan');
|
|
// }
|
|
// ]
|
|
'pengesahan'
|
|
)
|
|
->where('lelongbid_id', '=', $id)->get();
|
|
foreach ($marhun as $index) {
|
|
$eachmarhun = FileMarhun::where('lelongbidmarhun_id', '=', $index['id'])->first();
|
|
if (isset($eachmarhun)) {
|
|
$index->eachmarhun_filename = $eachmarhun->filename;
|
|
$index->eachmarhun_id = $eachmarhun->id;
|
|
}
|
|
}
|
|
$lelkarat = LelKarat::where('lelong_id','=',$lelongbid->lelong_id)->get();
|
|
$karatall = JenisKarat::all();
|
|
$emasall = JenisEmas::all();
|
|
return view('marhun.marhun',compact('marhun','lelongbid','karatall','emasall','lelkarat', 'lelong_id'));
|
|
}
|
|
|
|
|
|
public function senarailelongmarhun(Request $request){
|
|
|
|
$user = Auth::user();
|
|
$arrayinfo = [];
|
|
|
|
$lelong = CawanganLelong::join('lelong','cawangan_lelong.lelong_id','=','lelong.id')
|
|
->join('cawangan','cawangan_lelong.caw_id', '=', 'cawangan.id')
|
|
->where('cawangan.caw_code', $user->kodcaw)
|
|
->where('sts_lelong', 0)
|
|
->select('lelong.fasa','lelong_id','tarikh_lelong','cawangan_lelong.masatamat_lelong','harga_emas_asas','jbg','cajlelong','sts_lelong')
|
|
->get()
|
|
->toArray();
|
|
|
|
foreach($lelong as $info)
|
|
{
|
|
|
|
$detailsinfo = CawanganLelong::join('cawangan','cawangan_lelong.caw_id','=','cawangan.id')
|
|
->where('lelong_id',$info['lelong_id'])
|
|
->where('cawangan.caw_code', $user->kodcaw)
|
|
->get()
|
|
->toArray();
|
|
array_push($arrayinfo,['info'=>$info, 'detailsinfo'=>$detailsinfo]);
|
|
|
|
}
|
|
|
|
return view('marhun.senarailelongmarhun',compact('lelong', 'arrayinfo'));
|
|
|
|
}
|
|
|
|
|
|
public function senaraiLelongTerimaSerah()
|
|
{
|
|
|
|
$lelong = Lelong::orderBy('id', 'desc')->get();
|
|
|
|
return view('marhun.senarailelongterimaserah', compact('lelong'));
|
|
}
|
|
|
|
public function senarailelongscan(Request $request){
|
|
|
|
$user = Auth::user();
|
|
$arrayinfo = [];
|
|
|
|
$lelong = CawanganLelong::join('lelong','cawangan_lelong.lelong_id','=','lelong.id')
|
|
->join('cawangan','cawangan_lelong.caw_id', '=', 'cawangan.id')
|
|
->where('cawangan.caw_code', $user->kodcaw)
|
|
->where('sts_lelong', 0)
|
|
->select('lelong_id','tarikh_lelong','cawangan_lelong.masatamat_lelong','harga_emas_asas','jbg','cajlelong','sts_lelong')
|
|
->get()
|
|
->toArray();
|
|
|
|
foreach($lelong as $info)
|
|
{
|
|
|
|
$detailsinfo = CawanganLelong::join('cawangan','cawangan_lelong.caw_id','=','cawangan.id')
|
|
->where('lelong_id',$info['lelong_id'])
|
|
->where('cawangan.caw_code', $user->kodcaw)
|
|
->get()
|
|
->toArray();
|
|
array_push($arrayinfo,['info'=>$info, 'detailsinfo'=>$detailsinfo]);
|
|
|
|
}
|
|
|
|
return view('marhun.senarailelongscan',compact('lelong', 'arrayinfo'));
|
|
|
|
}
|
|
|
|
public function semak($id, $lelong_id)
|
|
{
|
|
//$id => lelongbid_id
|
|
$lelongbid = LelongBid::where('id','=',$id)
|
|
->where('lelong_id', $lelong_id)
|
|
->first();
|
|
|
|
// $lelongbidmarhun = LelongBidMarhun::where('lelongbid_id', $id)->get();
|
|
|
|
// foreach($lelongbidmarhun as $lelbidmarhun)
|
|
// {
|
|
// if($lelbidmarhun['karat'] == null && $lelbidmarhun['berat'] == null && $lelbidmarhun['harga'] == null && $lelbidmarhun['n_marhun'] == null && $lelbidmarhun['hargaasas'] == null)
|
|
// {
|
|
// $lelbidmarhun->lelongbid_id = $id;
|
|
// $lelbidmarhun->karat = $lelbidmarhun['old_karat'];
|
|
// $lelbidmarhun->berat = $lelbidmarhun['old_berat'];
|
|
// $lelbidmarhun->harga = $lelbidmarhun['old_harga'];
|
|
// $lelbidmarhun->n_marhun = $lelbidmarhun['old_nmarhun'];
|
|
// $lelbidmarhun->hargaasas = $lelbidmarhun['old_hargaasas'];
|
|
// $lelbidmarhun->save();
|
|
// }
|
|
// }
|
|
|
|
$lelongbid->status_semak = 1;
|
|
$lelongbid->save();
|
|
|
|
return redirect()->route('marhun.senaraimarhun',[ $lelong_id ])
|
|
->with('success','Semakan Marhun Berjaya');
|
|
}
|
|
|
|
public function tambahmarhun(Request $request)
|
|
{
|
|
// dd($request->all());
|
|
//get request from form and create lelongbidmarhun
|
|
$user = Auth::user();
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateTimeString();
|
|
|
|
$lelongbid = LelongBid::where('norujukan', $request->norujukan_marhuntambahan)->first();
|
|
$lelong = Lelong::where('id','=',$lelongbid->lelong_id)->first();
|
|
|
|
$lelongbidmarhun = new LelongBidMarhun;
|
|
$lelongbidmarhun->lelongbid_id = $lelongbid->id;
|
|
$lelongbidmarhun->bil = 1;
|
|
$lelongbidmarhun->marhun = $request->marhuntambahan;
|
|
$lelongbidmarhun->nota = $request->notatambahan;
|
|
$lelongbidmarhun->old_karat = $request->karattambahan;
|
|
$lelongbidmarhun->karat = $request->karattambahan;
|
|
$lelongbidmarhun->old_berat = $request->berat_emastambahan;
|
|
$lelongbidmarhun->berat = $request->berat_emastambahan;
|
|
$lelongbidmarhun->old_harga = $request->hargatambahan;
|
|
$lelongbidmarhun->harga = $request->hargatambahan;
|
|
$lelongbidmarhun->old_nmarhun = $request->nilai_marhuntambahan;
|
|
$lelongbidmarhun->n_marhun = $request->nilai_marhuntambahan;
|
|
$lelongbidmarhun->old_hargaasas = $request->harga_asastambahan;
|
|
$lelongbidmarhun->hargaasas = $request->harga_asastambahan;
|
|
$lelongbidmarhun->status_semak = 0;
|
|
$lelongbidmarhun->save();
|
|
|
|
$lelongbid->marhun = $lelongbid->marhun ."1 " . $request->marhuntambahan . "," ;
|
|
$lelongbid->berat = $lelongbid->berat + $request->berat_emastambahan;
|
|
$lelongbid->hargaasas = $lelongbid->hargaasas + $request->harga_asastambahan;
|
|
$lelongbid->save();
|
|
|
|
$karat = new Pengesahan;
|
|
$karat->lelong_id = $lelong->id;
|
|
$karat->lelongbid_id = $lelongbid->id;
|
|
$karat->lelongbidmarhun_id = $lelongbidmarhun->id;
|
|
$karat->norujukan = $lelongbid->norujukan;
|
|
$karat->diminta_oleh = $user->id;
|
|
$karat->diminta_pada = $currentdate;
|
|
$karat->status_ubah = 2;
|
|
$karat->save();
|
|
|
|
return redirect()->route('marhun.show',[$lelongbid->id,$lelongbid->lelong_id])
|
|
->with('success','Marhun Berjaya Ditambah');
|
|
}
|
|
|
|
public function exportmarhundetails($lelong_id)
|
|
{
|
|
$user = Auth::user();
|
|
//dd($user);
|
|
$lelongs= LelongBid::where('lelong_id','=',$lelong_id)
|
|
->where('kodcaw','=',$user['kodcaw'])
|
|
->get()
|
|
->toArray();
|
|
//dd($lelongs);
|
|
|
|
|
|
|
|
$arraycaw= [];
|
|
|
|
$total_berat = 0;
|
|
$berat = 0;
|
|
|
|
$total_harga = 0;
|
|
$harga = 0;
|
|
|
|
$total_nmarhun = 0;
|
|
$nilai_marhun = 0;
|
|
|
|
$total_hargaasas = 0;
|
|
$hargaasas = 0;
|
|
|
|
foreach($lelongs as $index1=>$lelong){
|
|
|
|
$marhun= LelongBidMarhun::where('lelongbid_id','=',$lelong['id'])->get();
|
|
$total_berat = $total_berat + ($marhun->sum('berat'));
|
|
$total_harga = $total_harga + ($marhun->sum('harga'));
|
|
$total_nmarhun = $total_nmarhun + ($marhun->sum('n_marhun'));
|
|
$total_hargaasas = $total_hargaasas + ($marhun->sum('hargaasas'));
|
|
|
|
$lelongs[$index1]['detailmarhun']=$marhun;
|
|
|
|
}
|
|
|
|
array_push($arraycaw,[
|
|
'berat'=>$berat,
|
|
'harga'=>$harga,
|
|
'n_marhun'=>$nilai_marhun,
|
|
'hargaasas'=>$hargaasas
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$pdf = PDF::loadView('pdf.marhundetails',compact('lelongs','arraycaw','total_nmarhun','total_berat','total_harga','total_hargaasas'
|
|
))->setPaper('a4', 'potrait');
|
|
|
|
return $pdf->download('Senarai Marhun.pdf');
|
|
|
|
|
|
}
|
|
|
|
public function senlelmarhun()
|
|
{
|
|
$user = Auth::user();
|
|
|
|
$arrayinfo = [];
|
|
|
|
$lelong = CawanganLelong::join('lelong','cawangan_lelong.lelong_id','=','lelong.id')
|
|
->join('cawangan','cawangan_lelong.caw_id', '=', 'cawangan.id')
|
|
->where('cawangan.caw_code', $user->kodcaw)
|
|
->where('sts_lelong', 0)
|
|
->select('lelong.fasa','lelong_id','tarikh_lelong','lelong.masatamat_lelong','harga_emas_asas','jbg','cajlelong','sts_lelong')
|
|
->groupBy('lelong_id')
|
|
->get()
|
|
->toArray();
|
|
|
|
foreach($lelong as $info)
|
|
{
|
|
|
|
$detailsinfo = CawanganLelong::join('cawangan','cawangan_lelong.caw_id','=','cawangan.id')
|
|
->where('lelong_id',$info['lelong_id'])
|
|
->where('cawangan.caw_code', $user->kodcaw)
|
|
->get()
|
|
->toArray();
|
|
array_push($arrayinfo,['info'=>$info, 'detailsinfo'=>$detailsinfo]);
|
|
}
|
|
|
|
return view('marhun.senlelmarhun',compact('lelong', 'arrayinfo'));
|
|
}
|
|
|
|
public function sentangguhlelongsah($lelong_id)
|
|
{
|
|
$user = Auth::user();
|
|
// dd($user);
|
|
|
|
$lelong = CawanganLelong::join('lelong','cawangan_lelong.lelong_id','=','lelong.id')
|
|
->join('cawangan','cawangan_lelong.caw_id', '=', 'cawangan.id')
|
|
->where('cawangan.caw_code', $user->kodcaw)
|
|
->select('tarikh_lelong', 'caw_name')
|
|
->first();
|
|
|
|
$sdhdisahkan = TangguhLelong::join('gadai', 'tangguhlelong.norujukan', '=', 'gadai.norujukan')
|
|
->where('gadai.kodcaw', $user['kodcaw'] )
|
|
->where('tangguhlelong.lelong_id', $lelong_id)
|
|
// ->where('lelongbid.status_semak', 1)
|
|
->select('tangguhlelong.id as tangguhlelong_id',
|
|
'tangguhlelong.norujukan',
|
|
'gadai.marhun',
|
|
'gadai.berat',
|
|
'tangguhlelong.ditangguh_pada',
|
|
'tangguhlelong.pinjaman',
|
|
'tangguhlelong.nota'
|
|
)
|
|
->get();
|
|
|
|
return view('marhun.sentangguhlelongsah', compact('sdhdisahkan', 'lelong'));
|
|
|
|
}
|
|
//Khazanah
|
|
|
|
//Operasi
|
|
public function senarailelongubahmutu()
|
|
{
|
|
$arrayinfo = [];
|
|
|
|
$lelong = pengesahan::join('lelong','lelong.id','=','pengesahan.lelong_id')
|
|
// ->where('sts_lelong', 0)
|
|
->whereIn('pengesahan.status_ubah', [1,2,3,4,5])
|
|
->select('lelong.fasa','pengesahan.lelong_id','lelong.id','lelong.tarikh_lelong','lelong.masatamat_lelong','lelong.harga_emas_asas','lelong.jbg','lelong.cajlelong','sts_lelong')
|
|
// ->groupBy('pengesahan.lelong_id')
|
|
|
|
->distinct()
|
|
->get()
|
|
->toArray();
|
|
// dd($lelong);
|
|
|
|
foreach($lelong as $info)
|
|
{
|
|
$detailsinfo = CawanganLelong::join('cawangan','cawangan_lelong.caw_id','=','cawangan.id')
|
|
->where('lelong_id',$info['lelong_id'])
|
|
->get()
|
|
->toArray();
|
|
array_push($arrayinfo,['info'=>$info, 'detailsinfo'=>$detailsinfo]);
|
|
}
|
|
|
|
return view('pengesahan.senarailelongubahmutu',compact('lelong', 'arrayinfo'));
|
|
}
|
|
|
|
public function sahubahmutu($id){
|
|
|
|
$user = Auth::user();
|
|
$mutumarhun = Pengesahan::join('lelongbid','lelongbid.norujukan','=','pengesahan.norujukan')
|
|
->where('lelongbid.kodcaw', $user->kodcaw)
|
|
->whereNull('disahkan_oleh')
|
|
->whereNull('disahkan_pada')
|
|
->where('pengesahan.lelong_id', $id)
|
|
->whereIn('status_ubah', [1,2,3,4,5])
|
|
->selectRaw('count(*) as total, sum(status) as tstat,pengesahan.norujukan')
|
|
->groupBy('pengesahan.norujukan')
|
|
->get()
|
|
->toArray();
|
|
|
|
foreach($mutumarhun as $index1=>$mutu)
|
|
{
|
|
$cawangan = LelongBid::join('cawangan', 'lelongbid.caw_id', 'cawangan.id')
|
|
->where('lelongbid.kodcaw', $user->kodcaw)
|
|
->where('lelongbid.lelong_id', $id)
|
|
->where('lelongbid.norujukan', $mutu['norujukan'])
|
|
->select('cawangan.caw_name')
|
|
->first();
|
|
|
|
$mutumarhun[$index1]['cawangan_name'] = $cawangan['caw_name'];
|
|
}
|
|
|
|
// foreach($mutumarhun as $index1=>$marhun)
|
|
// {
|
|
// $pengesahan = Pengesahan::where('lelong_id', $id)
|
|
// ->where('norujukan', $marhun['norujukan'])
|
|
// ->select('id as pengesahan_id')
|
|
// ->get();
|
|
|
|
// $mutumarhun[$index1]['pengesahan_id'] = $pengesahan;
|
|
// }
|
|
|
|
return view('pengesahan.perubahanmutumarhun', compact('mutumarhun', 'id'));
|
|
|
|
}
|
|
|
|
public function mutumarhun($norujukan, $id)
|
|
{
|
|
$lelbidmarhuns = LelongBidMarhun::join('lelongbid', 'lelongbidmarhun.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('lelongbid.lelong_id', $id)
|
|
->where('lelongbid.norujukan', $norujukan)
|
|
->select(
|
|
'lelongbidmarhun.id as lelongbidmarhun_id',
|
|
'lelongbid.id as lelongbid_id',
|
|
'lelongbidmarhun.bil',
|
|
'lelongbidmarhun.marhun',
|
|
'lelongbidmarhun.nota',
|
|
'lelongbidmarhun.karat',
|
|
'lelongbidmarhun.berat',
|
|
'lelongbidmarhun.harga',
|
|
'lelongbidmarhun.n_marhun',
|
|
'lelongbidmarhun.hargaasas',
|
|
'lelongbidmarhun.status_semak',
|
|
'lelongbid.lelong_id',
|
|
'lelongbid.caw_id',
|
|
'lelongbid.kodcaw',
|
|
'lelongbid.norujukan',
|
|
'lelongbid.t_lelong',
|
|
'lelongbid.jbg',
|
|
'lelongbid.kadarupah',
|
|
'lelongbid.upahsimpan',
|
|
'lelongbid.bakiupah',
|
|
'lelongbid.ansuran',
|
|
'lelongbid.nilaimarhun',
|
|
'lelongbid.pinjaman',
|
|
'lelongbid.bakiupah',
|
|
'lelongbid.cajlelong',
|
|
'lelongbid.baki',
|
|
'lelongbid.percent'
|
|
)
|
|
->get();
|
|
|
|
$arraygadai = $lelbidmarhuns->pluck('norujukan')->toArray();
|
|
$datagadai = $lelbidmarhuns;
|
|
|
|
|
|
$gadai = GadaiMarhun::on($datagadai[0]['kodcaw'])->whereIn('norujukan', $arraygadai)
|
|
->get()->toArray();
|
|
|
|
foreach($gadai as $index2=>$gadai2)
|
|
{
|
|
|
|
$listgadai = GadaiMarhun::on($datagadai[0]['kodcaw'])->whereIn('norujukan', $arraygadai)
|
|
->get();
|
|
$gadai[$index2]['listgadai'] = $listgadai;
|
|
}
|
|
// $gadai[$index2]['listgadai'] = $listgadai;
|
|
// dd($gadai);
|
|
$arraylelbidmarhun = [];
|
|
$bakilelong = 0;
|
|
$rugilelong = 0;
|
|
foreach($lelbidmarhuns as $lelbidmarhun)
|
|
{
|
|
$marhuns = LelongBidMarhun::where('lelongbid_id', $lelbidmarhun->lelongbid_id)
|
|
->where('id', $lelbidmarhun->lelongbidmarhun_id)
|
|
->get()->toArray();
|
|
|
|
$marhunsdet = LelongBidMarhun::where('lelongbid_id', $lelbidmarhun->lelongbid_id)
|
|
// ->where('id', $lelbidmarhun->lelongbidmarhun_id)
|
|
->get();
|
|
|
|
$totalhargaasas = $marhunsdet->sum('hargaasas');
|
|
$tothargaasas = bcdiv($totalhargaasas,1);
|
|
// dd($totalhargaasas);
|
|
// dd($totalhargaasas);
|
|
|
|
// $marhunsgadai = GadaiMarhun::where('norujukan', $norujukan)
|
|
// // ->where('karat', $lelbidmarhun->karat)
|
|
// // ->where('id', $lelbidmarhun->idgadaimarhun)
|
|
// ->first();
|
|
// // dd($lelbidmarhun->idgadaimarhun);
|
|
|
|
$lelongbid = LelongBid::where('lelongbid.id', $lelbidmarhun->lelongbid_id)
|
|
->where('lelongbid.lelong_id', $id)
|
|
->first();
|
|
|
|
|
|
$karat = Lelkarat::where('lelong_id', $id)->get();
|
|
|
|
// dd($lelbidmarhuns);
|
|
foreach($marhuns as $index1=>$marhun)
|
|
{
|
|
// dd($marhun);
|
|
$status = Pengesahan::where('lelongbidmarhun_id', $lelbidmarhun->lelongbidmarhun_id)
|
|
->where('lelongbid_id', $marhun['lelongbid_id'])
|
|
->select('status_ubah', 'request_karat', 'request_berat', 'request_marhun')
|
|
->first();
|
|
// dd($status);
|
|
|
|
// $gadaimarhun = GadaiMarhun::where('marhun', $marhun['marhun'])
|
|
// ->where('norujukan', $lelongbid->norujukan)
|
|
// ->first();
|
|
|
|
$lelong = Lelong::where('id',$id)->get();
|
|
|
|
$sumcajlelong = $totalhargaasas * ($lelong[0]['cajlelong']/100);
|
|
//$cajlelong = $cajlelong + bcdiv($sumcajlelong,1,1);
|
|
$totalbaki = $totalhargaasas - $lelongbid->pinjaman - $lelongbid->bakiupah - bcdiv($sumcajlelong,1,1);
|
|
// dd($totalbaki);
|
|
if($totalbaki > 0)
|
|
{
|
|
$bakilelong = $totalbaki;
|
|
}
|
|
else
|
|
{
|
|
$rugilelong = $totalbaki;
|
|
}
|
|
|
|
// $marhuns[$index1]['harga_gadai'] = $marhunsgadai['harga'];
|
|
$marhuns[$index1]['nmarhun_gadai'] = $marhun['old_nmarhun'];
|
|
$marhuns[$index1]['old_marhun'] = $marhun['marhun'];
|
|
$marhuns[$index1]['status_ubah'] = $status;
|
|
$marhuns[$index1]['pembiayaan'] = $lelongbid->pinjaman;
|
|
$marhuns[$index1]['bakiupah'] = $lelongbid->bakiupah;
|
|
$marhuns[$index1]['baki_lelong'] = $bakilelong;
|
|
$marhuns[$index1]['rugi_lelong'] = $rugilelong;
|
|
$marhuns[$index1]['cajlelong'] = bcdiv($sumcajlelong,1,1);
|
|
}
|
|
|
|
array_push($arraylelbidmarhun,$marhuns);
|
|
}
|
|
|
|
|
|
return view('pengesahan.mutumarhun', compact('lelongbid', 'norujukan', 'id', 'arraylelbidmarhun', 'marhuns','gadai'));
|
|
}
|
|
|
|
public function terimaperubahan(Request $request)
|
|
{
|
|
//update mutu marhun - gadaimarhun
|
|
// dd($request->all());
|
|
$user = Auth::user();
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateTimeString();
|
|
|
|
$pengesahan = Pengesahan::where('norujukan', $request->norujukan)
|
|
->where('lelong_id', $request->lelong_id)
|
|
->where('lelongbid_id', $request->lelongbid_id)
|
|
->get();
|
|
|
|
foreach($pengesahan as $sah)
|
|
{
|
|
$updatepengesahan = Pengesahan::where('id', $sah['id'])->first();
|
|
$updatepengesahan->disahkan_oleh = $user['id'];
|
|
$updatepengesahan->disahkan_pada = $currentdate;
|
|
$updatepengesahan->save();
|
|
|
|
$lelongbid = LelongBid::where('id', $sah['lelongbid_id'])->first();
|
|
|
|
}
|
|
|
|
if($request->jenis_button == "terima")
|
|
{
|
|
foreach($pengesahan as $terimalel)
|
|
{
|
|
$lelongbidmarhuns = LelongBidMarhun::join('pengesahan', 'lelongbidmarhun.lelongbid_id', '=', 'pengesahan.lelongbid_id')
|
|
->where('pengesahan.lelongbid_id', $terimalel['lelongbid_id'])
|
|
->where('pengesahan.id', $terimalel['id'])
|
|
->get();
|
|
|
|
foreach($lelongbidmarhuns as $bidmarhuns)
|
|
{
|
|
if($bidmarhuns->status_ubah == 3)
|
|
{
|
|
$deletemarhun = LelongBidMarhun::where('id', $bidmarhuns->lelongbidmarhun_id)
|
|
->where('lelongbid_id', $bidmarhuns->lelongbid_id)
|
|
->delete();
|
|
}
|
|
else
|
|
{
|
|
//
|
|
}
|
|
$txtmarhun = ",1 " . $bidmarhuns->marhun ;
|
|
}
|
|
|
|
$pengesahans = Pengesahan::join('lelongbidmarhun', 'pengesahan.lelongbid_id', '=', 'lelongbidmarhun.lelongbid_id')
|
|
->where('pengesahan.lelongbid_id', $terimalel['lelongbid_id'])
|
|
->select('pengesahan.id as pengesahan_id',
|
|
'pengesahan.status'
|
|
)
|
|
->update(['status' => 1]);
|
|
|
|
$lelongbids = LelongBid::where('id', $lelongbid['id'])->first();
|
|
$lelongbids->marhun = str_replace( $txtmarhun,"",$lelongbids->marhun);
|
|
$lelongbids->berat = $lelongbids->berat;
|
|
$lelongbids->hargaasas = $lelongbids->hargaasas;
|
|
$lelongbids->save();
|
|
|
|
// $this->pcdelete($request->pengesahan_id, $pengesahan->lelongbid_id);
|
|
}
|
|
}
|
|
|
|
|
|
else if($request->jenis_button == "tangguhlelong")
|
|
{
|
|
//add into table tangguhlelong
|
|
$tangguhlelong = new TangguhLelong;
|
|
$tangguhlelong->kodcaw = $request->kodcaw;
|
|
$tangguhlelong->lelong_id = $request->lelong_id;
|
|
$tangguhlelong->lelongbid_id = $request->lelongbid_id;
|
|
$tangguhlelong->norujukan = $request->norujukan;
|
|
$tangguhlelong->pinjaman = $lelongbid['pinjaman'];
|
|
$tangguhlelong->tarikhtangguh = $currentdate;
|
|
$tangguhlelong->ditangguh_oleh = $user->id;
|
|
$tangguhlelong->ditangguh_pada = $currentdate;
|
|
if($request->nota == NULL){
|
|
$tangguhlelong->nota = 'Tiada';}
|
|
else{
|
|
$tangguhlelong->nota = $request->nota;}
|
|
$tangguhlelong->save();
|
|
|
|
// $updategadai = Gadai::where('norujukan','=',$request->norujukan)->first();
|
|
// $updategadai->taglel = 0;
|
|
// $updategadai->update();
|
|
|
|
$marhundelete = LelongBid::where('id', $request->lelongbid_id)->delete();
|
|
}
|
|
|
|
else
|
|
{
|
|
//
|
|
}
|
|
|
|
return redirect()->route('pengesahan.senarailelongubahmutu')->with('success','Pengesahan Mutu Marhun Berjaya');
|
|
}
|
|
|
|
public function submitdelete(Request $request){
|
|
|
|
// dd($request->all());
|
|
$user = Auth::user();
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateTimeString();
|
|
|
|
|
|
$marhun = LelongBidMarhun::join('lelongbid', 'lelongbidmarhun.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('lelongbidmarhun.id','=',$request->lelongbidmarhun_id)
|
|
->where('lelongbid.id', $request->lelongbid_id)
|
|
->first();
|
|
|
|
$id = $request->lelongbid_id;
|
|
$lelong_id = $marhun->lelong_id;
|
|
|
|
$pengesahan = new Pengesahan;
|
|
$pengesahan->lelong_id = $marhun->lelong_id;
|
|
$pengesahan->lelongbid_id = $request->lelongbid_id;
|
|
$pengesahan->lelongbidmarhun_id = $request->lelongbidmarhun_id;
|
|
$pengesahan->norujukan = $marhun->norujukan;
|
|
$pengesahan->diminta_oleh = $user->id;
|
|
$pengesahan->diminta_pada = $currentdate;
|
|
$pengesahan->status_ubah = 3;
|
|
$pengesahan->save();
|
|
|
|
return redirect()->route('marhun.show', compact('id', 'lelong_id'))
|
|
->with('success','Permohonan Pengesahan Padam Marhun Telah Berjaya Dihantar');
|
|
|
|
}
|
|
|
|
|
|
public function senarailelong()
|
|
{
|
|
$arrayinfo = [];
|
|
|
|
// $lelong = Lelong::join('tangguhlelong','lelong.id','=','tangguhlelong.lelong_id')
|
|
// ->select('tangguhlelong.norujukan','tangguhlelong.lelong_id','lelong.id','lelong.tarikh_lelong','lelong.masatamat_lelong','lelong.harga_emas_asas','lelong.jbg','lelong.cajlelong','sts_lelong')
|
|
// ->distinct()
|
|
// ->get()
|
|
// ->toArray();
|
|
|
|
|
|
$lelong = TangguhLelong::join('lelong','lelong.id','=','tangguhlelong.lelong_id')
|
|
->select('tangguhlelong.lelong_id','lelong.id','lelong.tarikh_lelong','lelong.masatamat_lelong','lelong.harga_emas_asas','lelong.jbg','lelong.cajlelong','sts_lelong')
|
|
->distinct()
|
|
->orderBy('lelong_id')
|
|
->get()
|
|
->toArray();
|
|
// dd($lelong);
|
|
foreach($lelong as $details)
|
|
{
|
|
|
|
// $detailsinfo = CawanganLelong::join('cawangan','cawangan_lelong.caw_id','=','cawangan.id')
|
|
|
|
// ->where('cawangan_lelong.lelong_id', $details['id'])
|
|
// ->distinct()
|
|
// ->get()
|
|
// ->toArray();
|
|
|
|
$detailsinfo = CawanganLelong::select('tangguhlelong.lelong_id','cawangan_lelong.caw_id','caw_name','caw_code')
|
|
->join('cawangan','cawangan_lelong.caw_id','=','cawangan.id')
|
|
->join('tangguhlelong','tangguhlelong.lelong_id','=','cawangan_lelong.lelong_id')
|
|
->where('tangguhlelong.lelong_id', $details['id'])
|
|
// ->where('tangguhlelong.norujukan', $details['norujukan'])
|
|
->distinct()
|
|
->orderBy('lelong_id')
|
|
->get()
|
|
->toArray();
|
|
// dd($detailsinfo);
|
|
|
|
array_push($arrayinfo,['detail'=>$details, 'detailsinfo'=>$detailsinfo]);
|
|
}
|
|
|
|
return view('pengesahan.senarailelong',compact('lelong', 'arrayinfo'));
|
|
}
|
|
|
|
public function senaraitangguhlelong($id, $caw_code)
|
|
{
|
|
// dd($id);
|
|
$tangguhlelong = TangguhLelong::join('lelong', 'tangguhlelong.lelong_id', '=', 'lelong.id')
|
|
->where('tangguhlelong.norujukan', 'like', "%$caw_code%")
|
|
->where('tangguhlelong.lelong_id', $id)
|
|
->whereNotNull('tangguhlelong.tarikhtangguh')
|
|
->select('tangguhlelong.id as tangguhlelong_id',
|
|
'tangguhlelong.lelongbid_id',
|
|
'tangguhlelong.norujukan',
|
|
'tangguhlelong.tarikhtangguh',
|
|
'tangguhlelong.ditangguh_pada',
|
|
'tangguhlelong.ditangguh_oleh',
|
|
'tangguhlelong.nota',
|
|
'lelong.id as lelong_id',
|
|
'lelong.tarikh_lelong',
|
|
'lelong.harga_emas_asas',
|
|
'lelong.jbg',
|
|
'lelong.cajlelong',
|
|
'lelong.sts_lelong'
|
|
)
|
|
->get();
|
|
//dd($tangguhlelong);
|
|
|
|
foreach($tangguhlelong as $index1=>$tanguhlel)
|
|
{
|
|
$getkodcaw = LelongBid::join('cawangan', 'lelongbid.kodcaw', '=', 'cawangan.caw_code')
|
|
->where('lelong_id', $id)
|
|
->where('kodcaw', $caw_code)
|
|
->select('cawangan.caw_name')
|
|
->first();
|
|
|
|
$tangguhlelong[$index1]['details'] = $tanguhlel;
|
|
// $tangguhlelong[$index1]['nama_caw'] = $getkodcaw;
|
|
}
|
|
|
|
return view('pengesahan.senaraitangguhlelong',compact('tangguhlelong','id', 'caw_code'));
|
|
}
|
|
|
|
public function lelbidmarhun($id, $norujukan, $tangguhlelong_id)
|
|
{
|
|
$tangguhlelong = TangguhLelong::join('gadaimarhun', 'tangguhlelong.norujukan', '=', 'gadaimarhun.norujukan')
|
|
->where('gadaimarhun.norujukan', $norujukan)
|
|
->where('tangguhlelong.id', $tangguhlelong_id)
|
|
// ->where('tangguhlelong.lelong_id', $id)
|
|
->select('tangguhlelong.id as tangguhlelong_id',
|
|
'tangguhlelong.lelong_id',
|
|
'tangguhlelong.lelongbid_id',
|
|
'tangguhlelong.norujukan',
|
|
'tangguhlelong.pinjaman',
|
|
'tangguhlelong.tarikhtangguh',
|
|
'tangguhlelong.nota as tangguh_nota',
|
|
'tangguhlelong.pinjaman',
|
|
'gadaimarhun.bil',
|
|
'gadaimarhun.marhun',
|
|
'gadaimarhun.nota as gadai_nota',
|
|
'gadaimarhun.karat',
|
|
'gadaimarhun.berat',
|
|
'gadaimarhun.harga',
|
|
'gadaimarhun.n_marhun'
|
|
)
|
|
->get();
|
|
// dd($tangguhlelong);
|
|
|
|
$caw_names = GadaiMarhun::join('cawangan', 'gadaimarhun.kodcaw', '=', 'cawangan.caw_code')
|
|
->where('gadaimarhun.norujukan', $norujukan)
|
|
->select('cawangan.caw_name', 'cawangan.caw_code')
|
|
->first();
|
|
// dd($caw_names);
|
|
|
|
return view('pengesahan.lelbidmarhun',compact('tangguhlelong', 'id', 'norujukan', 'caw_names'));
|
|
|
|
}
|
|
|
|
public function listsahubahmutu($id){
|
|
|
|
$user = Auth::user();
|
|
|
|
$cawangan = Pengesahan::join('users', 'pengesahan.diminta_oleh', 'users.id')
|
|
->where('pengesahan.lelong_id', $id)
|
|
->whereNotNull('pengesahan.disahkan_oleh')
|
|
->select('pengesahan.diminta_oleh','pengesahan.disahkan_oleh', 'pengesahan.disahkan_pada', 'pengesahan.norujukan', 'pengesahan.lelong_id', 'users.id as user_id', 'users.name', 'users.username', 'users.kodcaw')
|
|
->distinct()
|
|
->get();
|
|
// dd($cawangan);
|
|
|
|
foreach($cawangan as $index1=>$caw)
|
|
{
|
|
// dd($caw);
|
|
$getpengesahan = Cawangan::where('caw_code', $caw['kodcaw'])->first();
|
|
// dd($getpengesahan);
|
|
|
|
$getdisahkanoleh = User::where('id', $caw['disahkan_oleh'])->first();
|
|
$getdimintaoleh = User::where('id', $caw['diminta_oleh'])->first();
|
|
// dd($getdisahkanoleh);
|
|
|
|
$cawangan[$index1]['namacaw'] = $getpengesahan['caw_name'];
|
|
$cawangan[$index1]['disahkan_oleh'] = $getdisahkanoleh['name'];
|
|
$cawangan[$index1]['diminta_oleh'] = $getdimintaoleh['name'];
|
|
}
|
|
|
|
return view('pengesahan.listperubahanmutumarhun', compact('cawangan', 'id'));
|
|
|
|
}
|
|
|
|
public function terimaserahmarhun($lelong_id)
|
|
{
|
|
$user = Auth::user();
|
|
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)->first();
|
|
|
|
$senaraiScanKeluar = ScanSemak::where('kodcaw', '=', $caw->caw_code)
|
|
->where('lelong_id', $lelong_id)
|
|
->whereNull('terima_marhun')
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
|
|
$sedangDinilai = ScanSemak::where('kodcaw', '=', $caw->caw_code)
|
|
->whereNotNull('terima_marhun')
|
|
->whereNull('serah_marhun')
|
|
->where('lelong_id', $lelong_id)
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
|
|
$sudahSerah = ScanSemak::where('kodcaw', '=', $caw->caw_code)
|
|
->whereNotNull('serah_marhun')
|
|
->where('lelong_id', $lelong_id)
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
|
|
if ($senaraiScanKeluar || $sedangDinilai || $sudahSerah) {
|
|
return view('marhun.terimaserahmarhun', compact('senaraiScanKeluar', 'sedangDinilai', 'sudahSerah','lelong_id'));
|
|
} else {
|
|
return redirect()->route('marhun.senarailelongterimaserah')->with('failed', 'Tiada Surat Untuk Dilelong Pada Tarikh Ini.');
|
|
}
|
|
}
|
|
|
|
public function terimaMarhun(Request $request)
|
|
{
|
|
$user = Auth::user();
|
|
$current = Carbon::now();
|
|
|
|
foreach ($request->scanKeluar_id as $index) {
|
|
$terimaMarhun = ScanSemak::where('id', '=', $index)->first();
|
|
$terimaMarhun->penilai_id = $user->id;
|
|
$terimaMarhun->terima_marhun = $current->toDateTimeString();
|
|
$terimaMarhun->update();
|
|
}
|
|
return redirect()->route('marhun.terimaserahmarhun', $terimaMarhun->lelong_id)->with('success', 'Terima Marhun Berjaya Direkodkan');
|
|
}
|
|
|
|
public function serahMarhun(Request $request)
|
|
{
|
|
$user = Auth::user();
|
|
$current = Carbon::now();
|
|
|
|
foreach ($request->sedangDinilai_id as $index) {
|
|
$serahMarhun = ScanSemak::where('id', '=', $index)->first();
|
|
$serahMarhun->serah_marhun = $current->toDateTimeString();
|
|
$serahMarhun->update();
|
|
}
|
|
return redirect()->route('marhun.terimaserahmarhun', $serahMarhun->lelong_id)->with('success', 'Serah Marhun Berjaya Direkodkan');
|
|
}
|
|
|
|
public function listScanBarcode($lelong_id)
|
|
{
|
|
$user = Auth::user();
|
|
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)->first();
|
|
|
|
$lelongDetail = Lelong::where('id', '=', $lelong_id)->first();
|
|
$lelongbid = LelongBid::where('lelong_id', '=', $lelong_id)
|
|
->where('caw_id', '=', $caw->id)
|
|
->get();
|
|
|
|
$senaraiScanKeluar = ScanSemak::where('lelong_id', '=', $lelong_id)
|
|
->where('kodcaw', '=', $caw->caw_code)
|
|
->whereNull('scan_masuk')
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
|
|
$senaraiScanMasuk = ScanSemak::where('lelong_id', '=', $lelong_id)
|
|
->where('kodcaw', '=', $caw->caw_code)
|
|
->whereNotNull('scan_masuk')
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
|
|
return view('marhun.scanbarcode', compact('lelong_id', 'lelongDetail', 'lelongbid', 'senaraiScanKeluar', 'senaraiScanMasuk'));
|
|
}
|
|
|
|
public function scanKeluarMarhun(Request $request)
|
|
{
|
|
|
|
$user = Auth::user();
|
|
$current = Carbon::now();
|
|
|
|
$checkExisting = ScanSemak::where('norujukan', '=', $request->norujukan_barcode)
|
|
->whereNull('scan_masuk')
|
|
->get();
|
|
|
|
if ($checkExisting->isEmpty()) {
|
|
$lelongbidItem = LelongBid::where('norujukan', '=', $request->norujukan_barcode)->first();
|
|
|
|
$scanKeluar = new ScanSemak();
|
|
$scanKeluar->kodcaw = $lelongbidItem['kodcaw'];
|
|
$scanKeluar->lelong_id = $lelongbidItem['lelong_id'];
|
|
$scanKeluar->lelongbid_id = $lelongbidItem['id'];
|
|
$scanKeluar->norujukan = $lelongbidItem['norujukan'];
|
|
$scanKeluar->khazanah_id = $user['id'];
|
|
$scanKeluar->scan_keluar = $current->toDateTimeString();
|
|
$scanKeluar->save();
|
|
|
|
return redirect()->route('marhun.scanbarcode', $request->lelong_id)
|
|
->with('success', 'Marhun Berjaya Di Scan Keluar Dari Peti Besi.');
|
|
} else {
|
|
return redirect()->route('marhun.scanbarcode', $request->lelong_id)
|
|
->with('failed', 'Marhun Sudah Berada Di Luar Peti Besi.');
|
|
}
|
|
}
|
|
|
|
public function scanMasukMarhun(Request $request)
|
|
{
|
|
$user = Auth::user();
|
|
$current = Carbon::now();
|
|
|
|
$scanMasuk = ScanSemak::where('norujukan', '=', $request->norujukan_barcode)
|
|
->whereNotNull('serah_marhun')
|
|
->first();
|
|
|
|
if ($scanMasuk) {
|
|
$scanMasuk->scan_masuk = $current->toDateTimeString();
|
|
$scanMasuk->update();
|
|
return redirect()->route('marhun.scanbarcode', $request->lelong_id)
|
|
->with('success', 'Marhun Berjaya Di Scan Masuk Ke Peti Besi.');
|
|
} else {
|
|
return redirect()->route('marhun.scanbarcode', $request->lelong_id)
|
|
->with('failed', 'Gagal Scan, Marhun Belum Diserah Oleh Penilai.');
|
|
}
|
|
}
|
|
|
|
public function senaraiScanKeluar(Request $request)
|
|
{
|
|
$user = Auth::user();
|
|
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)->first();
|
|
|
|
$senaraiScanKeluar = ScanMarhun::where('lelong_id', '=', $request->lelong_id)
|
|
->where('kodcaw', '=', $caw)
|
|
->get();
|
|
}
|
|
|
|
public function addPhotoMarhun(Request $request)
|
|
{
|
|
$data = base64_encode($request->gambarMarhun->get());
|
|
$file_type = $request->gambarMarhun->extension();
|
|
|
|
$addfile = new FileMarhun();
|
|
$addfile->lelongbid_id = $request->lelongbid_id;
|
|
$addfile->file_type = $file_type;
|
|
$addfile->filename = $data;
|
|
if ($request->photo_type == 1) {
|
|
$addfile->photo_type = 1;
|
|
$addfile->save();
|
|
} else if ($request->photo_type == 2) {
|
|
$addfile->photo_type = 2;
|
|
$addfile->lelongbidmarhun_id = $request->lelongbidmarhun_id;
|
|
$addfile->save();
|
|
}
|
|
return redirect()->route('marhun.show', [$request->lelongbid_id, $request->lelong_id])
|
|
->with('success', 'Gambar Berjaya Di Simpan.');
|
|
}
|
|
|
|
public function deletePhotoMarhun(Request $request)
|
|
{
|
|
$deleteFile = FileMarhun::where('id', '=', $request->filemarhun_id)->first();
|
|
$deleteFile->delete();
|
|
|
|
return redirect()->route('marhun.show', [$request->lelongbid_id, $request->lelong_id])
|
|
->with('success', 'Gambar Berjaya Di Padam.');
|
|
}
|
|
|
|
public function updatePhotoMarhun(Request $request)
|
|
{
|
|
$data = base64_encode($request->gambarMarhun->get());
|
|
$file_type = $request->gambarMarhun->extension();
|
|
|
|
$addfile = new FileMarhun();
|
|
$addfile->lelongbid_id = $request->lelongbid_id;
|
|
$addfile->file_type = $file_type;
|
|
$addfile->filename = $data;
|
|
if ($request->photo_type == 1) {
|
|
$addfile->photo_type = 1;
|
|
$addfile->save();
|
|
} else if ($request->photo_type == 2) {
|
|
$addfile->photo_type = 2;
|
|
$addfile->lelongbidmarhun_id = $request->lelongbidmarhun_id;
|
|
$addfile->save();
|
|
}
|
|
$deleteFile = FileMarhun::where('id', '=', $request->filemarhun_id)->first();
|
|
$deleteFile->delete();
|
|
|
|
return redirect()->route('marhun.show', [$request->lelongbid_id, $request->lelong_id])
|
|
->with('success', 'Gambar Berjaya Di Tukar.');
|
|
}
|
|
|
|
public function cetakkeluarscanbarcode($lelong_id)
|
|
{
|
|
$user = Auth::user();
|
|
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)->first();
|
|
|
|
$lelongDetail = Lelong::where('id', '=', $lelong_id)->first();
|
|
$lelongbid = LelongBid::where('lelong_id', '=', $lelong_id)
|
|
->where('caw_id', '=', $caw->id)
|
|
->get();
|
|
|
|
$senaraiScanKeluar = ScanSemak::where('lelong_id', '=', $lelong_id)
|
|
->where('kodcaw', '=', $caw->caw_code)
|
|
->whereNull('scan_masuk')
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
|
|
$senaraiScanMasuk = ScanSemak::where('lelong_id', '=', $lelong_id)
|
|
->where('kodcaw', '=', $caw->caw_code)
|
|
->whereNotNull('scan_masuk')
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
|
|
// return view('pdf.cetakkeluarscanbarcode', compact('lelong_id', 'lelongDetail', 'lelongbid', 'senaraiScanKeluar', 'senaraiScanMasuk','caw'));
|
|
$pdf = PDF::loadView('pdf.cetakkeluarscanbarcode',compact('caw','lelong_id', 'lelongDetail', 'lelongbid', 'senaraiScanKeluar', 'senaraiScanMasuk'
|
|
))->setPaper('a4', 'potrait');
|
|
|
|
return $pdf->download('Senarai Keluar Peti Besi.pdf');
|
|
}
|
|
|
|
public function cetakmasukscanbarcode($lelong_id)
|
|
{
|
|
$user = Auth::user();
|
|
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)->first();
|
|
|
|
$lelongDetail = Lelong::where('id', '=', $lelong_id)->first();
|
|
$lelongbid = LelongBid::where('lelong_id', '=', $lelong_id)
|
|
->where('caw_id', '=', $caw->id)
|
|
->get();
|
|
|
|
$senaraiScanKeluar = ScanSemak::where('lelong_id', '=', $lelong_id)
|
|
->where('kodcaw', '=', $caw->caw_code)
|
|
->whereNull('scan_masuk')
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
|
|
$senaraiScanMasuk = ScanSemak::where('lelong_id', '=', $lelong_id)
|
|
->where('kodcaw', '=', $caw->caw_code)
|
|
->whereNotNull('scan_masuk')
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
|
|
// return view('pdf.cetakmasukscanbarcode', compact('lelong_id', 'lelongDetail', 'lelongbid', 'senaraiScanKeluar', 'senaraiScanMasuk','caw'));
|
|
$pdf = PDF::loadView('pdf.cetakmasukscanbarcode',compact('caw','lelong_id', 'lelongDetail', 'lelongbid', 'senaraiScanKeluar', 'senaraiScanMasuk'
|
|
))->setPaper('a4', 'potrait');
|
|
|
|
return $pdf->download('Senarai Masuk Peti Besi.pdf');
|
|
}
|
|
public function cetakterimaserahmarhun($lelong_id)
|
|
{
|
|
$user = Auth::user();
|
|
$caw = Cawangan::where('caw_code', '=', $user->kodcaw)->first();
|
|
|
|
$senaraiScanKeluar = ScanSemak::where('kodcaw', '=', $caw->caw_code)
|
|
->where('lelong_id', $lelong_id)
|
|
->whereNull('terima_marhun')
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
|
|
$sedangDinilai = ScanSemak::where('kodcaw', '=', $caw->caw_code)
|
|
->whereNotNull('terima_marhun')
|
|
->whereNull('serah_marhun')
|
|
->where('lelong_id', $lelong_id)
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
|
|
$sudahSerah = ScanSemak::where('kodcaw', '=', $caw->caw_code)
|
|
->whereNotNull('serah_marhun')
|
|
->where('lelong_id', $lelong_id)
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
|
|
if ($senaraiScanKeluar || $sedangDinilai || $sudahSerah) {
|
|
// return view('pdf.cetakterimaserahmarhun', compact('senaraiScanKeluar', 'sedangDinilai', 'sudahSerah','lelong_id','caw'));
|
|
$pdf = PDF::loadView('pdf.cetakterimaserahmarhun',compact('senaraiScanKeluar', 'sedangDinilai', 'sudahSerah','lelong_id','caw'
|
|
))->setPaper('a4', 'potrait');
|
|
return $pdf->download('Laporan Serahan Marhun.pdf');
|
|
} else {
|
|
return redirect()->route('marhun.senarailelongterimaserah')->with('failed', 'Tiada Surat Untuk Dilelong Pada Tarikh Ini.');
|
|
}
|
|
}
|
|
|
|
}
|