123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
-
- namespace App\Jobs;
-
- use Illuminate\Bus\Queueable;
- use Illuminate\Queue\SerializesModels;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
-
- use Config;
- use File;
- use Carbon\Carbon;
-
- use App\Model\Module\Compound;
- use App\Model\Module\ConfidentialFile;
- use App\Model\Module\Memo;
- use App\Model\Module\Faulty;
-
- class UpdateCompoundPrice implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- protected $kpd;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct($kpd)
- {
- //
- $this->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();
- }
- }
- }
- }
- }
- }
- }
- }
- }
|