where('api_token',$request->api_token)->first(); if(empty($staff)){ return $this->sendError('Gagal', 'penguatkuasa tidak wujud'); }else { $compound = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first(); if (!empty($compound)) { $jumlah = ''; if($compound->jumlah_kemaskini_kompaun == ''){ $jumlah = $compound->jumlah_asal_kompaun; }else{ $jumlah = $compound->jumlah_kemaskini_kompaun; } if($request->jumlah_bayar != $jumlah){ array_push($data, array( 'kpd' => $request->kpd, 'jumlah_kompaun' => $jumlah, 'jumlah_bayar' => $request->jumlah_bayar, )); return $this->sendError($data, 'Jumlah yang dibayar tidak sama dengan jumlah kompaun!'); }else{ if($compound->status == 'Belum Bayar'){ $kompaun = Compound::where('kpd', $request->kpd)->first(); $kesalahan = Faulty::where('itkod', $kompaun->seksyen_kesalahan)->first(); $reportData = [ 'name' => $request->name, 'kesalahan' => $kesalahan->nama, 'kpd' => $request->kpd, 'nric' => $request->ic, 'mobile' => $request->telefon, 'email' => $request->email, 'total' => $request->jumlah_bayar, 'penguatkuasa' => $staff->no_badan, ]; $report = ReportPayment::create($reportData); $compound->status = 'Berbayar'; $compound->receipt = $request->receipt; $compound->amount_payment = $jumlah; $compound->save(); array_push($data, array( 'kpd' => $request->kpd, 'amount' => $jumlah, )); $now = Carbon::now(); $gDate = $now->format('F Y'); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; $subHistory = [ 'no_siri' => $compound->ConfidentialFile->no_siri, 'tajuk' => "Pembayaran kompaun ".$request->kpd." telah dibuat secara tunai", 'huraian' => "Pembayaran tunai diserahkan kepada ".$staff->roles_access." _id."/profile'>".$staff->StaffDetail->full_name.".", ]; $groupByDate = History::where('tarikh_kumpulan', $gDate)->first(); if(!empty($groupByDate)){ $groupByDate->subhistory()->create($subHistory); $compound->ConfidentialFile->history()->attach($groupByDate); }else{ $history = History::create($historyData); $history->subhistory()->create($subHistory); $compound->ConfidentialFile->history()->attach($history); } return $this->sendResponse($data, 'Kompaun ini berjaya dibayar!'); }else if($compound->status == 'Berbayar'){ array_push($data, array( 'kpd' => $request->kpd, 'amount' => $jumlah, )); return $this->sendError($data, 'Kompaun ini dah dibayar!'); } } }else { return $this->sendError($data, 'Tiada data'); } } } public function updatePayment(Request $request){ $compound = Compound::with('ConfidentialFile')->where('kpd', $request->orderid)->first(); if(!empty($compound)){ $compound->status = 'Berbayar'; $compound->save(); $now = Carbon::now(); $gDate = $now->format('F Y'); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; $subHistory = [ 'no_siri' => $compound->ConfidentialFile->no_siri, 'tajuk' => "Pembayaran kompaun ".$request->orderid." telah dibuat secara 'online'", 'huraian' => "Pembayaran kompaun ".$request->orderid." telah dijelaskan pada hari ini.", ]; $groupByDate = History::where('tarikh_kumpulan', $gDate)->first(); if(!empty($groupByDate)){ $groupByDate->subhistory()->create($subHistory); $compound->ConfidentialFile->history()->attach($groupByDate); }else{ $history = History::create($historyData); $history->subhistory()->create($subHistory); $compound->ConfidentialFile->history()->attach($history); } return $this->sendResponse('', 'status pembayaran kompaun berjaya dikemaskini dari BELUM BAYAR ke BERBAYAR'); }else{ return $this->sendError('', 'status pembayaran kompaun tidak dapat dikemaskini sebab rekod tidak dijumpai'); } } public function reportpaymentList(){ $nested_data = array(); $report = ReportPayment::orderBy('updated_at','DESC')->get(); $curr = Carbon::now()->getTimestamp(); $i = 1; foreach($report as $a) { $n1 = ''; $enforcer = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "Baru/"; }else{ $n1 = ""; } $staff = Staff::with('StaffDetail')->where('_id',$a->penguatkuasa)->first(); if(!empty($staff)){ $enforcer = '['.$staff->no_badan.'] '.$staff->StaffDetail->full_name; } // $noKPD = Compound::where('kpd', $a->kpd)->first(); // $namaSeksyen = Faulty::where('itkod',$a->seksyen_kesalahan)->first(); array_push($nested_data, array( '#' => $n1.$i, 'kpd' => $a->kpd, 'nama' => $a->name, 'kesalahan' => $a->kesalahan, 'identity' => $a->nric, 'mobile' => $a->mobile, 'email' => $a->email, 'jumlah' => 'Rm '.$a->total, 'no_badan' => $enforcer, )); $i++; } return \DataTables::of($nested_data)->make(true); } }