Dashboard sipadu mbip
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

UpdateCompoundPrice.php 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace App\Jobs;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Queue\SerializesModels;
  5. use Illuminate\Queue\InteractsWithQueue;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Bus\Dispatchable;
  8. use Config;
  9. use File;
  10. use Carbon\Carbon;
  11. use App\Model\Module\Compound;
  12. use App\Model\Module\ConfidentialFile;
  13. use App\Model\Module\Memo;
  14. use App\Model\Module\Faulty;
  15. class UpdateCompoundPrice implements ShouldQueue
  16. {
  17. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  18. protected $kpd;
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct($kpd)
  25. {
  26. //
  27. $this->kpd = $kpd;
  28. }
  29. /**
  30. * Execute the job.
  31. *
  32. * @return void
  33. */
  34. public function handle()
  35. {
  36. //
  37. $curr = Carbon::now()->getTimestamp();
  38. $harga_tawaran = '';
  39. // invididu Kompoun
  40. if($this->kpd != 'null'){
  41. $compound = Compound::with('ConfidentialFile')->where('kpd', $this->kpd)->first();
  42. $file = ConfidentialFile::with(['Memo' => function($q){
  43. $q->orderBy('updated_at','ASC');
  44. }])->where('no_siri',$compound->ConfidentialFile->no_siri)->first();
  45. // Update Harga
  46. if($compound->status == "Belum Bayar"){
  47. $faulty = Faulty::where('_id',$compound->seksyen_kesalahan)->first();
  48. if(!empty($faulty)){
  49. $tarikh_keluar = $compound->created_at;
  50. $tempoh_hari7 = $tarikh_keluar->addDays(7)->getTimestamp();
  51. $tempoh_hari14 = $tarikh_keluar->addDays(14)->getTimestamp();
  52. $tempoh_hari30 = $tarikh_keluar->addDays(30)->getTimestamp();
  53. if($curr <= $tempoh_hari7){
  54. if($faulty->amount_before_14 != '0'){
  55. $compound->jumlah_kemaskini_kompaun = $faulty->amount_before_14;
  56. $compound->save();
  57. }
  58. }else if($curr > $tempoh_hari7 && $curr <= $tempoh_hari14){
  59. if($faulty->amount_before_14 != '0'){
  60. $compound->jumlah_kemaskini_kompaun = $faulty->amount_before_14;
  61. $compound->save();
  62. }
  63. }else if($curr > $tempoh_hari14 && $curr <= $tempoh_hari30){
  64. if($faulty->amount_before_30 != '0'){
  65. $compound->jumlah_kemaskini_kompaun = $faulty->amount_before_30;
  66. $compound->save();
  67. }
  68. }else if($curr > $tempoh_hari30){
  69. $compound->jumlah_kemaskini_kompaun = '';
  70. $compound->save();
  71. }
  72. }
  73. }else{
  74. $compound->jumlah_kemaskini_kompaun = '';
  75. $compound->save();
  76. }
  77. // Update Memo
  78. if(!empty($file)){
  79. foreach ($file->memo as $key => $m) {
  80. $start = $m->tarikh_mula;
  81. $akhir = $m->tarikh_akhir;
  82. $start_date = strtotime($start);
  83. $expiry_date = strtotime($akhir);
  84. if($m->disahkan != ''){
  85. if($curr >= $start_date && $curr <= $expiry_date) {
  86. if($m->jenis_memo == "Tambahan"){
  87. $price = (float)$compound->jumlah_asal_kompaun;
  88. $addition = (int)$m->tawaran_kompaun;
  89. $harga_tawaran = number_format( $price + ($price * ($addition / 100)) , 2);
  90. $compound->jumlah_kemaskini_kompaun = $harga_tawaran;
  91. $compound->save();
  92. }else if($m->jenis_memo == "Lain-lain"){
  93. }
  94. }else{
  95. $compound->jumlah_kemaskini_kompaun = '';
  96. $compound->save();
  97. }
  98. }
  99. }
  100. }
  101. }else if($this->kpd == 'null'){
  102. $compound = Compound::with('ConfidentialFile','Faulty')->get();
  103. if(!empty($compound)){
  104. foreach($compound as $c){
  105. if($c->status == "Belum Bayar"){
  106. // $faulty = Faulty::where('_id',$c->seksyen_kesalahan)->first();
  107. if(!empty($faulty)){
  108. $tarikh_keluar = $c->created_at;
  109. $tempoh_hari7 = $tarikh_keluar->addDays(7)->getTimestamp();
  110. $tempoh_hari14 = $tarikh_keluar->addDays(14)->getTimestamp();
  111. $tempoh_hari30 = $tarikh_keluar->addDays(30)->getTimestamp();
  112. if($curr <= $tempoh_hari7){
  113. if($c->Faulty->amount_before_14 != '0'){
  114. $c->jumlah_kemaskini_kompaun = $c->Faulty->amount_before_14;
  115. $c->save();
  116. }
  117. }else if($curr > $tempoh_hari7 && $curr <= $tempoh_hari14){
  118. if($c->Faulty->amount_before_14 != '0'){
  119. $c->jumlah_kemaskini_kompaun = $c->Faulty->amount_before_14;
  120. $c->save();
  121. }
  122. }else if($curr > $tempoh_hari14 && $curr <= $tempoh_hari30){
  123. if($c->Faulty->amount_before_30 != '0'){
  124. $c->jumlah_kemaskini_kompaun = $c->Faulty->amount_before_30;
  125. $c->save();
  126. }
  127. }else if($curr > $tempoh_hari30){
  128. $c->jumlah_kemaskini_kompaun = '';
  129. $c->save();
  130. }
  131. }
  132. }else{
  133. $c->jumlah_kemaskini_kompaun = '';
  134. $c->save();
  135. }
  136. // Update Memo
  137. if(!empty($c->ConfidentialFile)){
  138. foreach ($c->ConfidentialFile->memo as $key => $m) {
  139. $start = $m->tarikh_mula;
  140. $akhir = $m->tarikh_akhir;
  141. $start_date = strtotime($start);
  142. $expiry_date = strtotime($akhir);
  143. if($m->disahkan != ''){
  144. if($curr >= $start_date && $curr <= $expiry_date) {
  145. if($m->jenis_memo == "Tambahan"){
  146. $price = (float)$c->jumlah_asal_kompaun;
  147. $addition = (int)$m->tawaran_kompaun;
  148. $harga_tawaran = number_format( $price + ($price * ($addition / 100)) , 2);
  149. $c->jumlah_kemaskini_kompaun = $harga_tawaran;
  150. $c->save();
  151. }else if($m->jenis_memo == "Lain-lain"){
  152. }
  153. }else{
  154. $c->jumlah_kemaskini_kompaun = '';
  155. $c->save();
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. }