158 lines
5.3 KiB
PHP
158 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use App\Models\User;
|
|
use App\Models\Cawangan;
|
|
use App\Models\CawanganLelong;
|
|
use App\Models\Lelong;
|
|
use App\Models\Payment;
|
|
use App\Models\LelongBid;
|
|
use App\Models\LelongBidder;
|
|
use App\Models\Resit;
|
|
|
|
class AccountController extends Controller
|
|
{
|
|
|
|
public function senarailelongan(){
|
|
|
|
$user = Auth::user();
|
|
|
|
$senarai = CawanganLelong::join('lelong', 'cawangan_lelong.lelong_id', '=', 'lelong.id')
|
|
->join('cawangan','cawangan_lelong.caw_id', '=', 'cawangan.id')
|
|
->where('lelong.sts_lelong', 3)
|
|
->get();
|
|
|
|
return view('account.senarailelongan',compact('senarai'));
|
|
}
|
|
|
|
public function listbayaranonline($lelong_id){
|
|
|
|
$listwinner = Payment::join('lelongbid', 'payment.lelongbid_id', '=', 'lelongbid.id')
|
|
->join('lelongbidder', 'payment.lelongbidder_id', '=', 'lelongbidder.id')
|
|
->where('lelongbidder.status_bidder', 1)
|
|
->where('lelongbid.lelong_id', $lelong_id)
|
|
->select('payment.user_id'
|
|
)
|
|
->groupBy('payment.user_id')
|
|
->get();
|
|
|
|
foreach($listwinner as $index1=>$winner){
|
|
|
|
$userdetails = User::where('id', $winner['user_id'])->first();
|
|
$SAGWin = Payment::join('lelongbid', 'payment.lelongbid_id', '=', 'lelongbid.id')
|
|
->join('lelongbidder', 'payment.lelongbidder_id', '=', 'lelongbidder.id')
|
|
->where('payment.user_id', $winner['user_id'])
|
|
->where('lelongbidder.status_bidder', 1)
|
|
->where('lelongbid.lelong_id', $lelong_id)
|
|
->get();
|
|
|
|
$total_payment = 0;
|
|
foreach($SAGWin as $SAG){
|
|
$payment = Payment::where('lelongbid_id', $SAG->lelongbid_id)
|
|
->first();
|
|
|
|
if($payment){
|
|
$total_payment = $total_payment + $payment->total_payment;
|
|
}
|
|
}
|
|
|
|
$listwinner[$index1]['details'] = $userdetails;
|
|
$listwinner[$index1]['total_surat'] = sizeof($SAGWin);
|
|
$listwinner[$index1]['totalBid'] = $SAGWin->sum('hargabida');
|
|
$listwinner[$index1]['totalPay'] = $total_payment;
|
|
|
|
}
|
|
|
|
|
|
return view('account.listbayaranonline',compact('listwinner','lelong_id'));
|
|
}
|
|
|
|
public function sahsagonline($lelong_id, $user_id)
|
|
{
|
|
$senaraisag = LelongBid::join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
|
->join('payment', 'lelongbid.id', '=', 'payment.lelongbid_id')
|
|
->where('lelongbid.lelong_id', $lelong_id)
|
|
->where('lelongbidder.user_id', $user_id)
|
|
->where('lelongbidder.status_bidder', 1)
|
|
->where('payment.status_payment_opt', 2)
|
|
->get()->toArray();
|
|
|
|
$total_payment = 0;
|
|
foreach($senaraisag as $index1=>$sagbid){
|
|
|
|
if($sagbid['total_payment']){
|
|
$total_payment = $total_payment +$sagbid['total_payment'];
|
|
}
|
|
}
|
|
|
|
return view('account.sahsagonline', compact('senaraisag', 'lelong_id', 'user_id', 'total_payment'));
|
|
}
|
|
|
|
public function sahbayaronline(Request $request)
|
|
{
|
|
// dd($request->all());
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateTimeString();
|
|
|
|
$user = Auth::user();
|
|
|
|
$senaraisag = LelongBid::join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
|
->join('payment', 'lelongbid.id', '=', 'payment.lelongbid_id')
|
|
->where('lelongbid.lelong_id', $request->lelong_id)
|
|
->where('lelongbidder.user_id', $request->user_id)
|
|
->where('lelongbidder.status_bidder', 1)
|
|
->where('payment.status_payment_opt', 2)
|
|
->get();
|
|
|
|
|
|
$total_payment = 0;
|
|
foreach($senaraisag as $sag)
|
|
{
|
|
$payment = Payment::where('lelong_id', $request->lelong_id)
|
|
->where('user_id', $request->user_id)
|
|
->where('lelongbid_id',$sag->lelongbid_id)
|
|
->first();
|
|
|
|
$payment->disahkan_oleh = $user->id;
|
|
$payment->disahkan_pada = $currentdate;
|
|
$payment->save();
|
|
|
|
$total_payment = $total_payment + $payment->total_payment;
|
|
$updatelelbidbidder = LelongBidder::where('lelongbid_id', $sag->lelongbid_id)
|
|
->first();
|
|
$updatelelbidbidder->status_payment = 1;
|
|
$updatelelbidbidder->save();
|
|
|
|
$eachbid = LelongBid::where('id',$sag->lelongbid_id)->first();
|
|
$eachbid->status_jual = 1;
|
|
$eachbid->t_jual = $currentdate;
|
|
$eachbid->save();
|
|
|
|
}
|
|
|
|
$senaraisagallpayment = LelongBid::join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
|
->where('lelongbid.lelong_id', $request->lelong_id)
|
|
->where('lelongbidder.user_id', $request->user_id)
|
|
->where('lelongbidder.status_bidder', 1)
|
|
->get();
|
|
|
|
$resit = Resit::where('id', $payment->resit_id)->first();
|
|
$resit->total_payment = $resit->total_payment + $total_payment;
|
|
|
|
if($resit->total_payment >= $senaraisagallpayment->sum('hargabida'))
|
|
{
|
|
$resit->status = 'PAID';
|
|
$resit->paid_at = $currentdate;
|
|
}
|
|
$resit->save();
|
|
|
|
return redirect()->route('account.senarailelongan')->with('success','Pembayaran Berjaya');
|
|
|
|
}
|
|
}
|