123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?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 Illuminate\Http\Request;
-
- use Carbon\Carbon;
-
- use App\Model\Module\Compound;
- use App\Model\Module\LetterNotice;
- use App\Model\Module\TemplateNotice;
- use App\Model\Module\History;
- use App\Model\Module\SubHistory;
-
-
- class SendNoticeLetter implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
-
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct()
- {
-
- }
-
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- $template = TemplateNotice::all();
- $now = Carbon::now();
- $compound = Compound::with('LetterNotice')->get();
- foreach($template as $key => $a) {
- foreach($compound as $c){
-
- $tempoh = new Carbon($c->created_at);
- $diff = $tempoh->diffInDays($now);
-
- if($a->status == 'aktif'){
- if(count($c->LetterNotice) > 0){
- foreach ($c->LetterNotice as $key => $l) {
- if($l->no_rujukan != $a->no_rujukan){
- if($a->tempoh_hantar == "13"){
- if($diff < 14){
- $dataLetter = [
- "tempoh_hantar" => $a->tempoh_hantar,
- "jenis_amaran" => $a->jenis_amaran,
- "alasan" => "Sebelum tempoh 14 hari",
- "no_rujukan" => $a->no_rujukan,
- "subjek" => $a->subjek,
- "kandungan" => $a->kandungan,
- "no_pos" => "",
- ];
- $c->letternotice()->create($dataLetter);
- }
- }else if($a->tempoh_hantar == "14"){
- if($diff >= 14){
- $dataLetter = [
- "tempoh_hantar" => $a->tempoh_hantar,
- "jenis_amaran" => $a->jenis_amaran,
- "alasan" => "Selepas tempoh 14 hari",
- "no_rujukan" => $a->no_rujukan,
- "subjek" => $a->subjek,
- "kandungan" => $a->kandungan,
- "no_pos" => "",
- ];
- $c->letternotice()->create($dataLetter);
- }
- }else if($a->tempoh_hantar == "28"){
- if($diff > 28){
- $dataLetter = [
- "tempoh_hantar" => $a->tempoh_hantar,
- "jenis_amaran" => $a->jenis_amaran,
- "alasan" => "Selepas tempoh 28 hari",
- "no_rujukan" => $a->no_rujukan,
- "subjek" => $a->subjek,
- "kandungan" => $a->kandungan,
- "no_pos" => "",
- ];
- $c->letternotice()->create($dataLetter);
- }
- }
- }
- }
- }else {
-
- if($a->tempoh_hantar == "13"){
- if($diff < 14){
- $dataLetter = [
- "tempoh_hantar" => $a->tempoh_hantar,
- "jenis_amaran" => $a->jenis_amaran,
- "alasan" => "Selepas tempoh 28 hari",
- "no_rujukan" => $a->no_rujukan,
- "subjek" => $a->subjek,
- "kandungan" => $a->kandungan,
- "no_pos" => "",
- ];
- $c->letternotice()->create($dataLetter);
- }
- }else if($a->tempoh_hantar == "14"){
- if($diff >= 14){
- $dataLetter = [
- "tempoh_hantar" => $a->tempoh_hantar,
- "jenis_amaran" => $a->jenis_amaran,
- "alasan" => "Selepas tempoh 28 hari",
- "no_rujukan" => $a->no_rujukan,
- "subjek" => $a->subjek,
- "kandungan" => $a->kandungan,
- "no_pos" => "",
- ];
- $c->letternotice()->create($dataLetter);
- }
- }else if($a->tempoh_hantar == "28"){
- if($diff > 28){
- $dataLetter = [
- "tempoh_hantar" => $a->tempoh_hantar,
- "jenis_amaran" => $a->jenis_amaran,
- "alasan" => "Selepas tempoh 28 hari",
- "no_rujukan" => $a->no_rujukan,
- "subjek" => $a->subjek,
- "kandungan" => $a->kandungan,
- "no_pos" => "",
- ];
- $c->letternotice()->create($dataLetter);
- }
- }
- }
- }
- }
- }
- }
- }
|