You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CalendarController.php 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace App\Http\Controllers\Contractor;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use Carbon\Carbon;
  7. use Validator;
  8. use PDF;
  9. use App\Staff;
  10. use App\Model\StaffDetail;
  11. use App\Model\Form;
  12. use App\Model\Subscriber;
  13. use App\Model\WorkOrder;
  14. use App\Model\PackageDetail;
  15. use App\Model\Company;
  16. class CalendarController extends Controller
  17. {
  18. public function viewContractorDashboard()
  19. {
  20. $id = Auth::guard('contractor')->id();
  21. $user = Staff::with('StaffDetail')->find($id);
  22. $pp = count(WorkOrder::where('status','Pending Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
  23. $sp = count(WorkOrder::where('status','Success Non Prelaid')->where('contractor_id',$user->StaffDetail->company_id)->get());
  24. $rs = count(WorkOrder::where('status','Reschedule')->where('contractor_id',$user->StaffDetail->company_id)->get());
  25. $ss = count(WorkOrder::where('status','Suspend')->where('contractor_id',$user->StaffDetail->company_id)->get());
  26. $cm = count(WorkOrder::where('status','Completed')->where('contractor_id',$user->StaffDetail->company_id)->get());
  27. $today = Carbon::today();
  28. return view('contractor.view_dashboard', compact('user','pp','sp','rs','ss','cm','today'));
  29. }
  30. public function getAllCalendar(Request $request){
  31. $id = Auth::guard('contractor')->id();
  32. $user = Staff::with('StaffDetail')->find($id);
  33. $event = array(); $color = '';
  34. $cuw = $request->wk;
  35. if($request->status == ''){
  36. $wo = WorkOrder::where('contractor_id',$user->StaffDetail->company_id)->get();
  37. if(!empty($wo)){
  38. foreach ($wo as $key => $w) {
  39. if($w->wo == $cuw){
  40. $color = '#5C2983';
  41. }else if($w->wo != $cuw) {
  42. if($w->status == "Completed") {
  43. $color = '#00C853';
  44. }else if($w->status == "Suspend") {
  45. $color = '#DE006E';
  46. }else if($w->status == "Reschedule") {
  47. $color = '#FF6D00';
  48. }else if($w->status == "Success Non Prelaid"){
  49. $color = '#2962FF';
  50. }else if($w->status == "Pending Non Prelaid"){
  51. $color = '#FFD600';
  52. }else if($w->status == "Pending Contractor") {
  53. $color = '#6D4C41';
  54. }else if($w->status == "Pending Installer"){
  55. $color = '#546E7A';
  56. }
  57. }
  58. array_push($event, array(
  59. 'id' => $w->wo,
  60. 'title' => $w->wo,
  61. 'start' => Carbon::createFromTimestamp(strtotime($w->dateTimeStart))->toRfc2822String(),
  62. 'end' => Carbon::createFromTimestamp(strtotime($w->dateTimeEnd))->toRfc2822String(),
  63. 'url' => url('/contractor/work-order/generate-pdf/'.$w->wo),
  64. 'color' => $color,
  65. 'allDay' => false
  66. ));
  67. }
  68. }
  69. }else if($request->status != ''){
  70. $wo = WorkOrder::where('status',$request->status)->where('contractor_id',$user->StaffDetail->company_id)->get();
  71. if(!empty($wo)){
  72. foreach ($wo as $key => $w) {
  73. if($w->wo == $cuw){
  74. $color = '#5C2983';
  75. }else if($w->wo != $cuw) {
  76. if($w->status == "Completed") {
  77. $color = '#00C853';
  78. }else if($w->status == "Suspend") {
  79. $color = '#DE006E';
  80. }else if($w->status == "Reschedule") {
  81. $color = '#FF6D00';
  82. }else if($w->status == "Success Non Prelaid"){
  83. $color = '#2962FF';
  84. }else if($w->status == "Pending Non Prelaid"){
  85. $color = '#FFD600';
  86. }else if($w->status == "Pending Contractor") {
  87. $color = '#6D4C41';
  88. }else if($w->status == "Pending Installer"){
  89. $color = '#546E7A';
  90. }
  91. }
  92. array_push($event, array(
  93. 'id' => $w->wo,
  94. 'title' => $w->wo,
  95. 'start' => Carbon::createFromTimestamp(strtotime($w->dateTimeStart))->toRfc2822String(),
  96. 'end' => Carbon::createFromTimestamp(strtotime($w->dateTimeEnd))->toRfc2822String(),
  97. 'url' => url('/contractor/work-order/generate-pdf/'.$w->wo),
  98. 'color' => $color,
  99. 'allDay' => false
  100. ));
  101. }
  102. }
  103. }
  104. return response()->json($event);
  105. }
  106. public function getCompanyColor(Request $request){
  107. $datass = array();
  108. $company = Company::where("_id",$request->company)->first();
  109. if(!empty($company)){
  110. array_push($datass, array(
  111. 'name' => '('.$company->name.')',
  112. 'bg' => $company->color,
  113. 'text' => '#fff'
  114. ));
  115. }else {
  116. array_push($datass, array(
  117. 'name' => '',
  118. 'bg' => '#fff',
  119. 'text' => '#5F5F5F'
  120. ));
  121. }
  122. return response()->json($datass);
  123. }
  124. }