Files
lelong/app/Http/Controllers/LelongController.php
T
Azfar Arsyad 6ae5062c22 update
2021-12-22 16:14:00 +08:00

337 lines
13 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\Simulasi;
use App\Models\SimulasiBid;
use App\Models\SimulasiBidMarhun;
use App\Models\SimKarat;
use App\Models\SimKarat_temp;
use App\Models\CawanganSimulasi;
use App\Models\Lelong;
use App\Models\CawanganLelong;
use App\Models\LelongBid;
use App\Models\LelongBidMarhun;
use App\Models\LelKarat;
use App\Models\LelKarat_temp;
class LelongController 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 index()
{
$lelong = Lelong::all();
return view('lelong.senarailelong',compact('lelong'));
}
public function show($id)
{
$simulasi_id = $id;
$simulasi = Simulasi::where('id','=',$id)->first();
$cawangansim = CawanganSimulasi::where('simulasi_id','=',$id)->get();
$simkarat = SimKarat::where('simulasi_id','=',$id)->get();
$arraydata = [];
$arraycaw = [];
$data = [];
$total_marhun = 0;
$total_berat = 0;
$total_nmarhun = 0;
$total_pinjaman = 0;
$total_upah = 0;
$total_hargaasas = 0;
$total_cazlelong = 0;
$total_rugilelong = 0;
$total_bakilelong = 0;
$total24Kgb = 0;
$total24K = 0;
$total23k = 0;
$total22K = 0;
$total21K = 0;
$total20K = 0;
$total18Kp = 0;
$total18K = 0;
$total14Kp = 0;
$total14K = 0;
$total9K = 0;
foreach($cawangansim as $cawsim)
{
$cawangan = Cawangan::where('id','=',$cawsim->caw_id)->first();
$databid = SimulasiBid::where('caw_id','=',$cawsim->caw_id)->get();
$packet = 0;
$berat = 0;
$nilai_marhun = 0;
$pinjaman =0;
$upah = 0;
$hargaasas = 0;
$cajlelong = 0;
$rugilelong = 0;
$bakilelong = 0;
foreach($databid as $bid)
{
$marhun = SimulasiBidMarhun::where('simulasibid_id','=',$bid->id)->get();
$berat = $berat + $bid->berat;
$nilai_marhun = $nilai_marhun + ($marhun->sum('n_marhun'));
$pinjaman =$pinjaman + $bid->pinjaman;
$upah = $upah + $bid->upah;
$hargaasas = $hargaasas + $bid->hargaasas;
$cajlelong = $cajlelong + $bid->cajlelong;
if($bid->baki > 0)
{
$bakilelong = $bakilelong + $bid->baki;
}
else
{
$rugilelong = $rugilelong - $bid->baki;
}
$total24Kgb += SimulasiBidMarhun::where('simulasibid_id','=',$bid->id)
->where('karat','=','24.0Kgb')
->sum('berat');
$total24K += SimulasiBidMarhun::where('simulasibid_id','=',$bid->id)
->where('karat','=','24.0K')
->sum('berat');
$total23k += SimulasiBidMarhun::where('simulasibid_id','=',$bid->id)
->where('karat','=','23.0K')
->sum('berat');
$total22K += SimulasiBidMarhun::where('simulasibid_id','=',$bid->id)
->where('karat','=','22.0K')
->sum('berat');
$total21K += SimulasiBidMarhun::where('simulasibid_id','=',$bid->id)
->where('karat','=','21.0K')
->sum('berat');
$total20K += SimulasiBidMarhun::where('simulasibid_id','=',$bid->id)
->where('karat','=','20.0K')
->sum('berat');
$total18Kp += SimulasiBidMarhun::where('simulasibid_id','=',$bid->id)
->where('karat','=','18.0Kp')
->sum('berat');
$total18K += SimulasiBidMarhun::where('simulasibid_id','=',$bid->id)
->where('karat','=','18.0K')
->sum('berat');
$total14Kp += SimulasiBidMarhun::where('simulasibid_id','=',$bid->id)
->where('karat','=','14.0Kp')
->sum('berat');
$total14K += SimulasiBidMarhun::where('simulasibid_id','=',$bid->id)
->where('karat','=','14.0K')
->sum('berat');
$total9K += SimulasiBidMarhun::where('simulasibid_id','=',$bid->id)
->where('karat','=','9.0K')
->sum('berat');
}
array_push($arraycaw,[
'cawangan'=>$cawangan->caw_name,
't_lelong'=>$simulasi->tarikh_lelong,
'bil_marhun'=>sizeof($databid),
'berat'=>$berat,
'n_marhun'=>$nilai_marhun,
'pinjaman'=>$pinjaman,
'upah'=>0,
'hargaasas'=>$hargaasas,
'cajlelong'=>$cajlelong,
'rugilelong'=>$rugilelong,
'bakilelong'=>$bakilelong,
]);
$total_marhun = $total_marhun + sizeof($databid);
$total_berat = $total_berat + $berat;
$total_nmarhun = $total_nmarhun + $nilai_marhun;
$total_pinjaman = $total_pinjaman + $pinjaman;
$total_upah = $total_upah + 0;
$total_hargaasas = $total_hargaasas + $hargaasas;
$total_cazlelong = $total_cazlelong + $cajlelong;
$total_rugilelong = $total_rugilelong + $rugilelong;
$total_bakilelong = $total_bakilelong + $bakilelong;
}
return view('simulasi.showsimulasi',compact(
'arraycaw',
'total_marhun',
'total_berat',
'total_nmarhun',
'total_pinjaman',
'total_upah',
'total_hargaasas',
'total_cazlelong',
'total_rugilelong',
'total_bakilelong',
'total24Kgb',
'total24K',
'total23k',
'total22K',
'total21K',
'total20K',
'total18Kp',
'total18K',
'total14Kp',
'total14K',
'total9K',
'simkarat',
'simulasi_id'));
}
public function create($id)
{
$simulasi = Simulasi::where('id','=',$id)->first();
$cawangansim = CawanganSimulasi::where('simulasi_id','=',$id)->get();
$simkarat = SimKarat::where('simulasi_id','=',$id)->get();
$lelong = new Lelong();
$lelong->tarikh_lelong = $simulasi->tarikh_lelong;
$lelong->harga_emas_asas = $simulasi->harga_emas_asas;
$lelong->jbg = $simulasi->jbg;
$lelong->cajlelong = $simulasi->cajlelong;
$lelong->save();
foreach($simkarat as $simulasikarat)
{
$lelkarat = new LelKarat;
$lelkarat->lelong_id = $lelong->id;
$lelkarat->karat = $simulasikarat->karat;
$lelkarat->keterangan = $simulasikarat->keterangan;
$lelkarat->harga = $simulasikarat->harga;
$lelkarat->harga2 = $simulasikarat->harga2;
$lelkarat->save();
}
foreach($cawangansim as $caw)
{
$caw_lelong = new CawanganLelong;
$caw_lelong->lelong_id = $lelong->id;
$caw_lelong->caw_id = $caw->caw_id;
$caw_lelong->online = $caw->online;
$caw_lelong->lokasi = $caw->lokasi;
$caw_lelong->save();
$datasimbid = SimulasiBid::where('caw_id','=',$caw->caw_id)->get();
foreach ($datasimbid as $simulasibid ) {
$lelongbid = new LelongBid;
$lelongbid->caw_id = $simulasibid->caw_id;
$lelongbid->kodcaw =$simulasibid->kodcaw;
$lelongbid->norujukan =$simulasibid->norujukan;
$lelongbid->t_lelong =$simulasibid->t_lelong;
$lelongbid->hargaasas =$simulasibid->hargaasas;
$lelongbid->hargajual =$simulasibid->hargajual;
$lelongbid->t_jual =$simulasibid->t_jual;
$lelongbid->nopembeli =$simulasibid->nopembeli;
$lelongbid->jbg =$simulasibid->jbg;
$lelongbid->kadarupah =$simulasibid->kadarupah;
$lelongbid->upahsimpan =$simulasibid->upahsimpan;
$lelongbid->ansuran =$simulasibid->ansuran;
$lelongbid->nilaimarhun =$simulasibid->nilaimarhun;
$lelongbid->pinjaman =$simulasibid->pinjaman;
$lelongbid->bakiupah =$simulasibid->bakiupah;
$lelongbid->cajlain =$simulasibid->cajlain;
$lelongbid->cajlelong =$simulasibid->cajlelong;
$lelongbid->baki =$simulasibid->baki;
$lelongbid->berat =$simulasibid->berat;
$lelongbid->marhun =$simulasibid->marhun;
$lelongbid->gst_hj =$simulasibid->gst_hj;
$lelongbid->gst_cl =$simulasibid->gst_cl;
$lelongbid->percent =$simulasibid->percent;
$lelongbid->status_jual =$simulasibid->status_jual;
$lelongbid->status_payment =$simulasibid->status_payment;
$lelongbid->mora_upah =$simulasibid->mora_upah;
$lelongbid->save();
$simulasibidmarhun = SimulasiBidMarhun::where('simulasibid_id','=',$simulasibid->id)->get();
foreach($simulasibidmarhun as $simbidmarhun)
{
$lelongbidmarhun = new LelongBidMarhun;
$lelongbidmarhun->lelongbid_id = $lelongbid->id;
$lelongbidmarhun->bil = $simbidmarhun->bil;
$lelongbidmarhun->marhun = $simbidmarhun->marhun;
$lelongbidmarhun->nota = $simbidmarhun->nota;
$lelongbidmarhun->karat = $simbidmarhun->karat;
$lelongbidmarhun->berat = $simbidmarhun->berat;
$lelongbidmarhun->harga = $simbidmarhun->harga;
$lelongbidmarhun->n_marhun = $simbidmarhun->n_marhun;
$lelongbidmarhun->hargaasas = $simbidmarhun->hargaasas;
$lelongbidmarhun->save();
}
}
}
return redirect()->route('analisa.senaraisimulasi')
->with('success','Create Lelong Berjaya');
}
public function delete($id)
{
$lelong = Lelong::where('id','=',$id)->first();
// dd($role);
$lelong->delete();
return redirect()->route('lelong.senarailelong')
->with('success','Padam Lelong Berjaya');
}
public function start($id)
{
$lelong = Lelong::where('id','=',$id)->first();
$lelong->masatamat_lelong = '2021-12-20 04:51:50';
$lelong->save();
return redirect()->route('lelong.senarailelong')
->with('success','Lelongan bermula');
}
public function refresh()
{
return redirect()->route('lelong.senarailelong')
->with('success','Kemaskini Berjaya');
}
}