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ů.

SendNoticeLetter.php 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 Illuminate\Http\Request;
  9. use Carbon\Carbon;
  10. use App\Model\Module\Compound;
  11. use App\Model\Module\LetterNotice;
  12. use App\Model\Module\TemplateNotice;
  13. use App\Model\Module\History;
  14. use App\Model\Module\SubHistory;
  15. class SendNoticeLetter implements ShouldQueue
  16. {
  17. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  18. /**
  19. * Create a new job instance.
  20. *
  21. * @return void
  22. */
  23. public function __construct()
  24. {
  25. }
  26. /**
  27. * Execute the job.
  28. *
  29. * @return void
  30. */
  31. public function handle()
  32. {
  33. $template = TemplateNotice::all();
  34. $now = Carbon::now();
  35. $compound = Compound::with('LetterNotice')->get();
  36. foreach($template as $key => $a) {
  37. foreach($compound as $c){
  38. $tempoh = new Carbon($c->created_at);
  39. $diff = $tempoh->diffInDays($now);
  40. if($a->status == 'aktif'){
  41. if(count($c->LetterNotice) > 0){
  42. foreach ($c->LetterNotice as $key => $l) {
  43. if($l->no_rujukan != $a->no_rujukan){
  44. if($a->tempoh_hantar == "13"){
  45. if($diff < 14){
  46. $dataLetter = [
  47. "tempoh_hantar" => $a->tempoh_hantar,
  48. "jenis_amaran" => $a->jenis_amaran,
  49. "alasan" => "Sebelum tempoh 14 hari",
  50. "no_rujukan" => $a->no_rujukan,
  51. "subjek" => $a->subjek,
  52. "kandungan" => $a->kandungan,
  53. "no_pos" => "",
  54. ];
  55. $c->letternotice()->create($dataLetter);
  56. }
  57. }else if($a->tempoh_hantar == "14"){
  58. if($diff >= 14){
  59. $dataLetter = [
  60. "tempoh_hantar" => $a->tempoh_hantar,
  61. "jenis_amaran" => $a->jenis_amaran,
  62. "alasan" => "Selepas tempoh 14 hari",
  63. "no_rujukan" => $a->no_rujukan,
  64. "subjek" => $a->subjek,
  65. "kandungan" => $a->kandungan,
  66. "no_pos" => "",
  67. ];
  68. $c->letternotice()->create($dataLetter);
  69. }
  70. }else if($a->tempoh_hantar == "28"){
  71. if($diff > 28){
  72. $dataLetter = [
  73. "tempoh_hantar" => $a->tempoh_hantar,
  74. "jenis_amaran" => $a->jenis_amaran,
  75. "alasan" => "Selepas tempoh 28 hari",
  76. "no_rujukan" => $a->no_rujukan,
  77. "subjek" => $a->subjek,
  78. "kandungan" => $a->kandungan,
  79. "no_pos" => "",
  80. ];
  81. $c->letternotice()->create($dataLetter);
  82. }
  83. }
  84. }
  85. }
  86. }else {
  87. if($a->tempoh_hantar == "13"){
  88. if($diff < 14){
  89. $dataLetter = [
  90. "tempoh_hantar" => $a->tempoh_hantar,
  91. "jenis_amaran" => $a->jenis_amaran,
  92. "alasan" => "Selepas tempoh 28 hari",
  93. "no_rujukan" => $a->no_rujukan,
  94. "subjek" => $a->subjek,
  95. "kandungan" => $a->kandungan,
  96. "no_pos" => "",
  97. ];
  98. $c->letternotice()->create($dataLetter);
  99. }
  100. }else if($a->tempoh_hantar == "14"){
  101. if($diff >= 14){
  102. $dataLetter = [
  103. "tempoh_hantar" => $a->tempoh_hantar,
  104. "jenis_amaran" => $a->jenis_amaran,
  105. "alasan" => "Selepas tempoh 28 hari",
  106. "no_rujukan" => $a->no_rujukan,
  107. "subjek" => $a->subjek,
  108. "kandungan" => $a->kandungan,
  109. "no_pos" => "",
  110. ];
  111. $c->letternotice()->create($dataLetter);
  112. }
  113. }else if($a->tempoh_hantar == "28"){
  114. if($diff > 28){
  115. $dataLetter = [
  116. "tempoh_hantar" => $a->tempoh_hantar,
  117. "jenis_amaran" => $a->jenis_amaran,
  118. "alasan" => "Selepas tempoh 28 hari",
  119. "no_rujukan" => $a->no_rujukan,
  120. "subjek" => $a->subjek,
  121. "kandungan" => $a->kandungan,
  122. "no_pos" => "",
  123. ];
  124. $c->letternotice()->create($dataLetter);
  125. }
  126. }
  127. }
  128. }
  129. }
  130. }
  131. }
  132. }