Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

MemoController.php 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace App\Http\Controllers\api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Api\BaseController;
  5. use Config;
  6. use File;
  7. use Carbon\Carbon;
  8. use App\Model\Staff;
  9. use App\Model\StaffDetail;
  10. use App\Model\Module\Department;
  11. use App\Model\Module\Roles;
  12. use App\Model\Module\Attachment;
  13. use App\Model\Module\Faulty;
  14. use App\Model\Module\Memo;
  15. use App\Model\Module\ConfidentialFile;
  16. use App\Model\Module\Compound;
  17. use App\Model\Module\History;
  18. use App\Model\Module\SubHistory;
  19. use App\Jobs\UpdateCompoundPrice;
  20. class MemoController extends BaseController
  21. {
  22. /**
  23. * Create a memo list controller.
  24. *
  25. * @return json
  26. */
  27. public function memoList($no_siri){
  28. $nested_data = array();
  29. $memo = ConfidentialFile::with(['Memo' => function($q){
  30. $q->orderBy('updated_at', 'desc');
  31. }])->where('no_siri',$no_siri)->first();
  32. $curr = Carbon::now()->getTimestamp();
  33. $i = 1;
  34. foreach($memo->Memo as $a)
  35. {
  36. $n1 = ''; $dikeluarkan = ''; $disahkan = ''; $modul = '';
  37. $reg_time = $a->updated_at;
  38. $expiry_date = $reg_time->addDays(3);
  39. $expiry_date = $expiry_date->getTimestamp();
  40. if($curr < $expiry_date) {
  41. $n1 = "Baru/";
  42. }else{
  43. $n1 = "";
  44. }
  45. $staffD = Staff::with('StaffDetail')->where('_id',$a->dikeluarkan)->first();
  46. if(!empty($staffD)){
  47. $dikeluarkan = $staffD->StaffDetail->full_name;
  48. }
  49. $staffS = Staff::with('StaffDetail')->where('_id',$a->disahkan)->first();
  50. if(!empty($staffS)){
  51. $disahkan = $staffD->StaffDetail->full_name;
  52. }
  53. if($a->modul != '-'){
  54. $modul = Roles::where('kod',$a->modul)->first();
  55. $modul = $modul->name;
  56. }else{
  57. $modul = '-';
  58. }
  59. array_push($nested_data, array(
  60. 'index' => $n1.$i,
  61. 'modul' => $modul,
  62. 'jenis' => $a->jenis_memo,
  63. 'no_rujukan' => $a->no_rujukan,
  64. 'mula' => date('d/m/Y h:i a', strtotime($a->tarikh_mula)),
  65. 'akhir' => date('d/m/Y h:i a', strtotime($a->tarikh_akhir)),
  66. 'dikeluakan' => $dikeluarkan,
  67. 'disahkan' => $disahkan,
  68. 'tindakan' => $a->_id
  69. ));
  70. $i++;
  71. }
  72. return \DataTables::of($nested_data)->make(true);
  73. }
  74. public function deleteMemo(Request $request){
  75. $staff = Staff::with('StaffDetail')->where('_id',$request->staff)->first();
  76. $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kpd)->first();
  77. $memo = Memo::with('Attachment')->where('_id',$request->id)->first();
  78. $compound->ConfidentialFile->memo()->detach($memo);
  79. if(!empty($memo)){
  80. if($memo->jenis_data == "pdf"){
  81. $memo->attachment()->delete();
  82. $memo->delete();
  83. $now = Carbon::now();
  84. $gDate = $now->format('F Y');
  85. $historyData = [
  86. 'tarikh_kumpulan' => $gDate,
  87. ];
  88. $subHistory = [
  89. 'no_siri' => $compound->ConfidentialFile->no_siri,
  90. 'tajuk' => $staff->StaffDetail->roles_access." ".$staff->StaffDetail->full_name." mengemaskini memo ".$memo->no_rujukan,
  91. 'huraian' => "Rekod memo (".$memo->no_rujukan.") dikemaskini/di buang oleh ".$staff->StaffDetail->roles_access." <a href='".url('/main/staff')."/".$staff->_id."/profile'>".$staff->StaffDetail->full_name."</a>.",
  92. ];
  93. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  94. if(!empty($groupByDate)){
  95. $groupByDate->subhistory()->create($subHistory);
  96. $compound->ConfidentialFile->history()->attach($groupByDate);
  97. }else{
  98. $history = History::create($historyData);
  99. $history->subhistory()->create($subHistory);
  100. $compound->ConfidentialFile->history()->attach($history);
  101. }
  102. $this->dispatch(new UpdateCompoundPrice($request->kpd));
  103. return response()->json(['status' => 'true', 'desc' => 'Buang rekod memo ( '.$memo->no_rujukan.' )']);
  104. }else if($memo->jenis_data == "manual"){
  105. $memo->delete();
  106. $now = Carbon::now();
  107. $gDate = $now->format('F Y');
  108. $historyData = [
  109. 'tarikh_kumpulan' => $gDate,
  110. ];
  111. $subHistory = [
  112. 'no_siri' => $compound->ConfidentialFile->no_siri,
  113. 'tajuk' => $staff->StaffDetail->roles_access." ".$staff->StaffDetail->full_name." mengemaskini memo ".$memo->no_rujukan,
  114. 'huraian' => "Rekod memo (".$memo->no_rujukan.") dikemaskini/di buang oleh ".$staff->StaffDetail->roles_access." <a href='".url('/main/staff')."/".$staff->_id."/profile'>".$staff->StaffDetail->full_name."</a>.",
  115. ];
  116. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  117. if(!empty($groupByDate)){
  118. $groupByDate->subhistory()->create($subHistory);
  119. $compound->ConfidentialFile->history()->attach($groupByDate);
  120. }else{
  121. $history = History::create($historyData);
  122. $history->subhistory()->create($subHistory);
  123. $compound->ConfidentialFile->history()->attach($history);
  124. }
  125. $this->dispatch(new UpdateCompoundPrice($request->kpd));
  126. return response()->json(['status' => 'true', 'desc' => 'Buang rekod memo ( '.$memo->no_rujukan.' )']);
  127. }else{
  128. return response()->json(['status' => 'false', 'desc' => 'Buang rekod memo ( '.$memo->no_rujukan.' )']);
  129. }
  130. }else{
  131. return response()->json(['status' => 'false', 'desc' => 'Buang rekod memo ( '.$memo->no_rujukan.' )']);
  132. }
  133. }
  134. }