ProgramController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Http\Controllers\Program;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Support\Facades\Crypt;
  5. use Illuminate\Http\Request;
  6. use App\Model\Privillage\Role;
  7. use App\Model\Inspeksi\Inspeksi;
  8. use Auth;
  9. use App\Model\TemplateProgram;
  10. use App\Model\TahunProgram;
  11. use App\Model\TahunProgramDetail;
  12. use Session;
  13. class ProgramController extends Controller
  14. {
  15. public function __construct()
  16. {
  17. $this->table = New TahunProgramDetail;
  18. $this->middleware('auth');
  19. }
  20. public function index(){
  21. $year = date('Y');
  22. // Check the tahunProgram table for an entry with status = 1 and deleted_at is null
  23. $tahunProgram = TahunProgram::where('status', 1)
  24. ->whereNull('deleted_at')
  25. ->value('value'); // Get the 'value' column which should be the year
  26. // If an entry is found, use that year
  27. if ($tahunProgram) {
  28. $year = $tahunProgram;
  29. }
  30. $getStatus = Role::where('id',Auth::user()->role_id)->value('akses');
  31. $data_pk = $this->table->with('templateProgram','tahunProgram');
  32. $data_pk = $data_pk->whereHas('tahunProgram',function($query) use ($year){
  33. $query->where('value',$year);
  34. });
  35. $data_pk = $data_pk->whereHas('templateProgram',function($q){
  36. $q->where('tipe',0);
  37. });
  38. $data_pk = $data_pk->distinct('id_template_program')->get();
  39. $data_non_pk = $this->table->with('templateProgram','tahunProgram');
  40. $data_non_pk = $data_non_pk->whereHas('tahunProgram',function($query) use ($year){
  41. $query->where('value',$year);
  42. });
  43. $data_non_pk = $data_non_pk->whereHas('templateProgram',function($q){
  44. $q->where('tipe',1);
  45. });
  46. $data_non_pk = $data_non_pk->distinct('id_template_program')->get();
  47. return view('program.program',compact('data_pk','data_non_pk','getStatus'));
  48. }
  49. }