kpd = $kpd; } /** * Execute the job. * * @return void */ public function handle() { // $curr = Carbon::now()->getTimestamp(); $harga_tawaran = ''; // invididu Kompoun if($this->kpd != 'null'){ $compound = Compound::with('ConfidentialFile')->where('kpd', $this->kpd)->first(); $file = ConfidentialFile::with(['Memo' => function($q){ $q->orderBy('updated_at','ASC'); }])->where('no_siri',$compound->ConfidentialFile->no_siri)->first(); // Update Harga if($compound->status == "Belum Bayar"){ $faulty = Faulty::where('_id',$compound->seksyen_kesalahan)->first(); if(!empty($faulty)){ $tarikh_keluar = $compound->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($faulty->amount_before_14 != '0'){ $compound->jumlah_kemaskini_kompaun = $faulty->amount_before_14; $compound->save(); } }else if($curr > $tempoh_hari7 && $curr <= $tempoh_hari14){ if($faulty->amount_before_14 != '0'){ $compound->jumlah_kemaskini_kompaun = $faulty->amount_before_14; $compound->save(); } }else if($curr > $tempoh_hari14 && $curr <= $tempoh_hari30){ if($faulty->amount_before_30 != '0'){ $compound->jumlah_kemaskini_kompaun = $faulty->amount_before_30; $compound->save(); } }else if($curr > $tempoh_hari30){ $compound->jumlah_kemaskini_kompaun = ''; $compound->save(); } } }else{ $compound->jumlah_kemaskini_kompaun = ''; $compound->save(); } // Update Memo if(!empty($file)){ foreach ($file->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)$compound->jumlah_asal_kompaun; $addition = (int)$m->tawaran_kompaun; $harga_tawaran = number_format( $price + ($price * ($addition / 100)) , 2); $compound->jumlah_kemaskini_kompaun = $harga_tawaran; $compound->save(); }else if($m->jenis_memo == "Lain-lain"){ } }else{ $compound->jumlah_kemaskini_kompaun = ''; $compound->save(); } } } } }else if($this->kpd == 'null'){ $compound = Compound::with('ConfidentialFile','Faulty')->get(); if(!empty($compound)){ foreach($compound as $c){ if($c->status == "Belum Bayar"){ // $faulty = Faulty::where('_id',$c->seksyen_kesalahan)->first(); if(!empty($faulty)){ $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_14; $c->save(); } }else if($curr > $tempoh_hari14 && $curr <= $tempoh_hari30){ if($c->Faulty->amount_before_30 != '0'){ $c->jumlah_kemaskini_kompaun = $c->Faulty->amount_before_30; $c->save(); } }else if($curr > $tempoh_hari30){ $c->jumlah_kemaskini_kompaun = ''; $c->save(); } } }else{ $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(); } } } } } } } } }