where('status','Belum Bayar')->chunk(300, function($compounds){ foreach ($compounds as $key => $c) { $curr = Carbon::now()->getTimestamp(); $tarikh_keluar = $c->created_at; $tempoh_hari7 = $tarikh_keluar->addDays(7)->getTimestamp(); $tempoh_hari14 = $tarikh_keluar->addDays(14)->getTimestamp(); $tempoh_hari30 = $tarikh_keluar->addDays(30)->getTimestamp(); if($curr <= $tempoh_hari7){ if($c->Faulty->amount_before_14 != '0'){ $c->jumlah_kemaskini_kompaun = $c->Faulty->amount_before_14; $c->save(); } }else if($curr > $tempoh_hari7 && $curr <= $tempoh_hari14){ if($c->Faulty->amount_before_14 != '0'){ $c->jumlah_kemaskini_kompaun = $c->Faulty->amount_before_30; $c->save(); } }else if($curr > $tempoh_hari14 && $curr <= $tempoh_hari30){ if($c->Faulty->amount_before_30 != '0'){ $c->jumlah_kemaskini_kompaun = ''; $c->save(); } }else if($curr > $tempoh_hari30){ $c->jumlah_kemaskini_kompaun = ''; $c->save(); } // //Update Memo // if(!empty($c->ConfidentialFile)){ // foreach ($c->ConfidentialFile->memo as $key => $m) { // $start = $m->tarikh_mula; // $akhir = $m->tarikh_akhir; // $start_date = strtotime($start); // $expiry_date = strtotime($akhir); // if($m->disahkan != ''){ // if($curr >= $start_date && $curr <= $expiry_date) { // if($m->jenis_memo == "Tambahan"){ // $price = (float)$c->jumlah_asal_kompaun; // $addition = (int)$m->tawaran_kompaun; // $harga_tawaran = number_format( $price + ($price * ($addition / 100)) , 2); // $c->jumlah_kemaskini_kompaun = $harga_tawaran; // $c->save(); // }else if($m->jenis_memo == "Lain-lain"){ // } // }else{ // $c->jumlah_kemaskini_kompaun = ''; // $c->save(); // } // } // } // } } }); echo 'finished'; // $this->dispatch(new UpdateCompoundPrice($kpd)); } public function sendLetterNotice(){ $this->dispatch(new SendNoticeLetter()); } }