195 lines
7.6 KiB
PHP
195 lines
7.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Carbon\Carbon;
|
|
use App\Models\Simulasi;
|
|
use App\Models\CawanganSimulasi;
|
|
use App\Models\SimKarat;
|
|
use App\Models\Lelong;
|
|
use App\Models\LelKarat;
|
|
use App\Models\CawanganLelong;
|
|
use App\Models\SimulasiBid;
|
|
use App\Models\LelongBid;
|
|
use App\Models\SimulasiBidMarhun;
|
|
use App\Models\LelongBidMarhun;
|
|
use App\Models\LogUser;
|
|
use DateTime;
|
|
|
|
class LelongUjrahController 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()
|
|
{
|
|
|
|
}
|
|
public function create($id)
|
|
{
|
|
$user = Auth::user();
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateTimeString();
|
|
$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->fasa = $simulasi->fasa;
|
|
$lelong->kali = $simulasi->kali;
|
|
$lelong->tagujrah = 1;
|
|
$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)
|
|
{
|
|
$cawanganlel = CawanganLelong::where('caw_id','=',$caw->caw_id)->orderBy('id','desc')->first();
|
|
if($cawanganlel)
|
|
{
|
|
$batchno = $cawanganlel->batchlel+1;
|
|
}
|
|
else
|
|
{
|
|
$batchno = 1;
|
|
}
|
|
$caw_lelong = new CawanganLelong;
|
|
$caw_lelong->batchlel = $batchno;
|
|
$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->fasa = $caw->fasa;
|
|
$caw_lelong->kali = $caw->kali;
|
|
$caw_lelong->tagujrah = 1;
|
|
$caw_lelong->save();
|
|
|
|
$datasimbid = SimulasiBid::where('caw_id','=',$caw->caw_id)->where('simulasi_id',$id)->get();
|
|
$suratcaw = $datasimbid->all();
|
|
foreach(array_chunk($suratcaw,100) as $data_chunk)
|
|
{
|
|
//dd($data);
|
|
foreach($data_chunk as $data)
|
|
{
|
|
//dd($simulasi->id);
|
|
$lelongbid = LelongBid::create([
|
|
"lelong_id" => $lelong->id,
|
|
"caw_id" => $data->caw_id,
|
|
"kodcaw" => $data->kodcaw,
|
|
"norujukan" => $data->norujukan,
|
|
"t_lelong" => $data->t_lelong,
|
|
"hargaasas" => $data->hargaasas,
|
|
"hargajual" => 0.00,
|
|
"jbg" => $data->jbg,
|
|
"kadarupah" => $data->kadarupah,
|
|
"ansuran" => $data->ansuran,
|
|
"nilaimarhun" => $data->nilaimarhun,
|
|
"pinjaman" => $data->pinjaman,
|
|
"bakiupah" => $data->bakiupah,
|
|
"upahsimpan" => $data->bakiupah,
|
|
"cajlain" => $data->cajlain,
|
|
"cajlelong" => 0.00,
|
|
"baki" => 0.00,
|
|
"berat" => $data->berat,
|
|
"marhun" => $data->marhun,
|
|
"percent" => $data->percent,
|
|
"status_jual" => 0,
|
|
"status_payment" => 0,
|
|
"mora_upah" => 0,
|
|
"fasa" => $data->fasa,
|
|
"tagujrah" => 1,
|
|
"onepercent" => $data->onepercent,
|
|
"ujrah" => $data->ujrah
|
|
]);
|
|
|
|
|
|
$simulasibidmarhun = SimulasiBidMarhun::where('simulasibid_id','=',$data->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->old_marhun = $simbidmarhun->marhun;
|
|
$lelongbidmarhun->old_karat = $simbidmarhun->karat;
|
|
$lelongbidmarhun->old_berat = $simbidmarhun->berat;
|
|
$lelongbidmarhun->old_harga = $simbidmarhun->harga;
|
|
$lelongbidmarhun->old_nmarhun = $simbidmarhun->n_marhun;
|
|
$lelongbidmarhun->old_hargaasas = $simbidmarhun->hargaasas;
|
|
$lelongbidmarhun->karat = $simbidmarhun->karat;
|
|
$lelongbidmarhun->berat = $simbidmarhun->berat;
|
|
$lelongbidmarhun->harga = $simbidmarhun->harga;
|
|
$lelongbidmarhun->n_marhun = $simbidmarhun->n_marhun;
|
|
$lelongbidmarhun->hargaasas = $simbidmarhun->hargaasas;
|
|
$lelongbidmarhun->save();
|
|
|
|
}
|
|
|
|
if($lelongbidmarhun->save())
|
|
{
|
|
// $updategadai = Gadai::where('norujukan','=', $data->norujukan)->first();
|
|
// $updategadai->taglel = 1;
|
|
// $updategadai->save();
|
|
|
|
$hapussimulasi = SimulasiBid::where('norujukan','=',$data->norujukan)->first();
|
|
$hapussimulasi->delete();
|
|
|
|
//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 = 'Daftar Batch Lelong Ujrah'.$lelong->id;
|
|
$loguser->save();
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
$simulasi = Simulasi::where('id','=',$id)->where('tagujrah', 1)->first();
|
|
// dd($role);
|
|
$simulasi->delete();
|
|
|
|
return redirect()->route('lelong.senarailelong')
|
|
->with('success','Pendaftaran Lelong Berjaya');
|
|
|
|
}
|
|
|
|
|
|
}
|