Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6.  
  7. use App\Model\Division;
  8. use App\Model\Employee;
  9. use App\Model\Evaluation;
  10. use App\Model\IPCR;
  11. use App\Model\IPCRLog;
  12. use App\Model\Monitoring;
  13. use App\Model\Rating;
  14.  
  15. class ExportJsonDataController extends Controller
  16. {
  17. public function get_spms_data(Request $request) {
  18.  
  19. // Dummy data only
  20. $paramData = [
  21. 'username' => $request['username'],
  22. 'password' => $request['password'],
  23. 'year' => $request['year'],
  24. 'sem' => $request['sem'],
  25. ];
  26.  
  27. // dd($paramData);
  28.  
  29. $username = $paramData['username'];
  30. $password = $paramData['password'];
  31.  
  32. if($password == "neda123")
  33. $password = "12345";
  34.  
  35. $year = $paramData['year'];
  36. $sem = ($paramData['sem']==1) ? "First" : "Second" ;
  37.  
  38. $userdata = array('username'=> $username, 'password' => $password);
  39. $valid = auth()->validate($userdata);
  40.  
  41. return json_encode($paramData);
  42.  
  43. // if(!auth()->attempt(['username' => $username, 'password' => $password])) {
  44. if(!$valid) {
  45.  
  46. $message = 'Please check your credentials and try again.';
  47.  
  48. $api_data = [
  49. 'status' => false,
  50. 'message' => $message,
  51. 'perf_evaluation' => null,
  52. 'perf_activity' => null,
  53. 'perf_monitoring' => null,
  54. 'perf_review' => null,
  55. ];
  56.  
  57. return json_encode($api_data);
  58. }
  59.  
  60. $user = Employee::where('username', $username)->first();
  61. $eval = Evaluation::where('sem', $sem)->where('year', $year)->first();
  62. $division = Division::find($user->division_id);
  63. $forms = IPCR::where('evaluation_id', $eval->id)->where('user_id', $user->id)->get();
  64.  
  65. $aforms = array();
  66. foreach ($forms as $form) {
  67. if(IPCRLog::CheckIfApprovedInReviewEvaluation($form->id)) // get only those approved
  68. {
  69. $aforms[] = $form;
  70. }
  71. }
  72.  
  73. if($aforms!=null) {
  74. // PER EVALUATION
  75. foreach ($aforms as $aform) {
  76. $temp_pe = [
  77. "employee_perf_eval_id" => $aform->id,
  78. "employee_id" => $user->id,
  79. "perf_sem" => ($sem == "First") ? "1" : "2",
  80. "perf_year" => $year,
  81. "evaluation_start_date" => $eval->start_month,
  82. "evaluation_end_date" => $eval->end_month,
  83. "rating" => $aform->average_rating,
  84. "rating_description" => Rating::Adjectival($aform->average_rating),
  85. "remarks" => $aform->remarks_re,
  86. "classification_field_id" => "0",
  87. "doc_type" => "IPCR",
  88. "org_code" => $division->abbreviation,
  89. ];
  90.  
  91. $perf_eval[] = $temp_pe;
  92. }
  93.  
  94. // PERF ACTIVITY
  95. foreach ($aforms as $aform) {
  96.  
  97. $temp_pa = array();
  98.  
  99. foreach ($aform->ipcr_main_details as $ipcr_main_detail) {
  100. $activity_id = $ipcr_main_detail->id;
  101. $activity_type = $ipcr_main_detail->label_name;
  102.  
  103. foreach ($ipcr_main_detail->ipcr_details as $ipcr_detail) {
  104.  
  105. $temp_pa[] = [
  106. 'perf_activities_id' => $activity_id,
  107. 'employee_perf_eval_id' => $aform->id,
  108. 'activity_type' => $activity_type,
  109. 'success_indicator' => $ipcr_detail->success_indicator,
  110. 'emp_remarks' => $ipcr_detail->remarks_re,
  111. 'sup_remarks' => $ipcr_detail->super_remarks_re,
  112. ];
  113.  
  114. }
  115. }
  116.  
  117. $perf_act[] = $temp_pa;
  118. }
  119.  
  120. // PERF MONITORING
  121. $chiefId = Employee::getDivisionChiefIdByDivId($user->division_id);
  122. $monitoring = Monitoring::where('evaluation_id', $eval->id)->where('user_id', $chiefId)->first();
  123. // dd($monitoring);
  124. $perf_mon = null;
  125. if($monitoring!=null) {
  126. foreach ($monitoring->getMonitoringDetailsForJsonData($user->id) as $mdetail) {
  127.  
  128. $officers = array();
  129. foreach ($mdetail->detail_users() as $user) {
  130. $officers[] = $user->fname . ' ' . $user->lname;
  131. }
  132.  
  133. $perf_mon[] = [
  134. 'perf_activities_id' => $mdetail->id,
  135. 'subject' => $mdetail->subject,
  136. 'action_officer' => $officers,
  137. 'output' => $mdetail->output,
  138. 'assigned_date' => $mdetail->date_assigned,
  139. 'accomplished_date' => $mdetail->date_accomplished,
  140. 'emp_remarks' => $mdetail->remarks,
  141. 'sup_remarks' => $mdetail->superior_remarks,
  142. ];
  143. }
  144. }
  145.  
  146. // PERF REVIEW
  147. foreach ($aforms as $aform) {
  148. $temp_pr = [
  149. 'perf_activities_id' => $aform->id,
  150. 'accomplished_date' => IPCRLog::GetStatusDateOfStatus($aform->id, 'APPROVED'),
  151. 'rating' => $aform->average_rating,
  152. 'emp_remarks' => $aform->remarks_re,
  153. 'sup_remarks' => $aform->superior_remarks_re,
  154. ];
  155.  
  156. $perf_rev[] = $temp_pr;
  157. }
  158.  
  159.  
  160. $api_data = [
  161. 'status' => true,
  162. 'message' => "Successful",
  163. 'perf_evaluation' => $perf_eval,
  164. 'perf_activity' => $perf_act,
  165. 'perf_monitoring' => $perf_mon,
  166. 'perf_review' => $perf_rev,
  167. ];
  168.  
  169. } else {
  170. $message = 'Successfully logged in but no form/s approved yet.';
  171.  
  172. $api_data = [
  173. 'status' => false,
  174. 'message' => $message,
  175. 'perf_evaluation' => null,
  176. 'perf_activity' => null,
  177. 'perf_monitoring' => null,
  178. 'perf_review' => null,
  179. ];
  180. }
  181.  
  182. // dd($api_data);
  183.  
  184. return json_encode($api_data);
  185. }
  186.  
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement