Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Model\Division;
- use App\Model\Employee;
- use App\Model\Evaluation;
- use App\Model\IPCR;
- use App\Model\IPCRLog;
- use App\Model\Monitoring;
- use App\Model\Rating;
- class ExportJsonDataController extends Controller
- {
- public function get_spms_data(Request $request) {
- // Dummy data only
- $paramData = [
- 'username' => $request['username'],
- 'password' => $request['password'],
- 'year' => $request['year'],
- 'sem' => $request['sem'],
- ];
- // dd($paramData);
- $username = $paramData['username'];
- $password = $paramData['password'];
- if($password == "neda123")
- $password = "12345";
- $year = $paramData['year'];
- $sem = ($paramData['sem']==1) ? "First" : "Second" ;
- $userdata = array('username'=> $username, 'password' => $password);
- $valid = auth()->validate($userdata);
- return json_encode($paramData);
- // if(!auth()->attempt(['username' => $username, 'password' => $password])) {
- if(!$valid) {
- $message = 'Please check your credentials and try again.';
- $api_data = [
- 'status' => false,
- 'message' => $message,
- 'perf_evaluation' => null,
- 'perf_activity' => null,
- 'perf_monitoring' => null,
- 'perf_review' => null,
- ];
- return json_encode($api_data);
- }
- $user = Employee::where('username', $username)->first();
- $eval = Evaluation::where('sem', $sem)->where('year', $year)->first();
- $division = Division::find($user->division_id);
- $forms = IPCR::where('evaluation_id', $eval->id)->where('user_id', $user->id)->get();
- $aforms = array();
- foreach ($forms as $form) {
- if(IPCRLog::CheckIfApprovedInReviewEvaluation($form->id)) // get only those approved
- {
- $aforms[] = $form;
- }
- }
- if($aforms!=null) {
- // PER EVALUATION
- foreach ($aforms as $aform) {
- $temp_pe = [
- "employee_perf_eval_id" => $aform->id,
- "employee_id" => $user->id,
- "perf_sem" => ($sem == "First") ? "1" : "2",
- "perf_year" => $year,
- "evaluation_start_date" => $eval->start_month,
- "evaluation_end_date" => $eval->end_month,
- "rating" => $aform->average_rating,
- "rating_description" => Rating::Adjectival($aform->average_rating),
- "remarks" => $aform->remarks_re,
- "classification_field_id" => "0",
- "doc_type" => "IPCR",
- "org_code" => $division->abbreviation,
- ];
- $perf_eval[] = $temp_pe;
- }
- // PERF ACTIVITY
- foreach ($aforms as $aform) {
- $temp_pa = array();
- foreach ($aform->ipcr_main_details as $ipcr_main_detail) {
- $activity_id = $ipcr_main_detail->id;
- $activity_type = $ipcr_main_detail->label_name;
- foreach ($ipcr_main_detail->ipcr_details as $ipcr_detail) {
- $temp_pa[] = [
- 'perf_activities_id' => $activity_id,
- 'employee_perf_eval_id' => $aform->id,
- 'activity_type' => $activity_type,
- 'success_indicator' => $ipcr_detail->success_indicator,
- 'emp_remarks' => $ipcr_detail->remarks_re,
- 'sup_remarks' => $ipcr_detail->super_remarks_re,
- ];
- }
- }
- $perf_act[] = $temp_pa;
- }
- // PERF MONITORING
- $chiefId = Employee::getDivisionChiefIdByDivId($user->division_id);
- $monitoring = Monitoring::where('evaluation_id', $eval->id)->where('user_id', $chiefId)->first();
- // dd($monitoring);
- $perf_mon = null;
- if($monitoring!=null) {
- foreach ($monitoring->getMonitoringDetailsForJsonData($user->id) as $mdetail) {
- $officers = array();
- foreach ($mdetail->detail_users() as $user) {
- $officers[] = $user->fname . ' ' . $user->lname;
- }
- $perf_mon[] = [
- 'perf_activities_id' => $mdetail->id,
- 'subject' => $mdetail->subject,
- 'action_officer' => $officers,
- 'output' => $mdetail->output,
- 'assigned_date' => $mdetail->date_assigned,
- 'accomplished_date' => $mdetail->date_accomplished,
- 'emp_remarks' => $mdetail->remarks,
- 'sup_remarks' => $mdetail->superior_remarks,
- ];
- }
- }
- // PERF REVIEW
- foreach ($aforms as $aform) {
- $temp_pr = [
- 'perf_activities_id' => $aform->id,
- 'accomplished_date' => IPCRLog::GetStatusDateOfStatus($aform->id, 'APPROVED'),
- 'rating' => $aform->average_rating,
- 'emp_remarks' => $aform->remarks_re,
- 'sup_remarks' => $aform->superior_remarks_re,
- ];
- $perf_rev[] = $temp_pr;
- }
- $api_data = [
- 'status' => true,
- 'message' => "Successful",
- 'perf_evaluation' => $perf_eval,
- 'perf_activity' => $perf_act,
- 'perf_monitoring' => $perf_mon,
- 'perf_review' => $perf_rev,
- ];
- } else {
- $message = 'Successfully logged in but no form/s approved yet.';
- $api_data = [
- 'status' => false,
- 'message' => $message,
- 'perf_evaluation' => null,
- 'perf_activity' => null,
- 'perf_monitoring' => null,
- 'perf_review' => null,
- ];
- }
- // dd($api_data);
- return json_encode($api_data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement