has('year')){ $year = session('year'); } else{ $year = date('y'); } if(session()->has('color')){ $color = session('color'); } /*explode the $org_id string into 2 strings, which are separated by __. */ $vals_array = explode('__', $param_id); /*The first part of the string will be the type of id; org for org_id, year for year, timeline for timeline_date, color for color. */ $param = $vals_array[0]; /*If the param is org, assign the following values to these variables; org_id, year, timeline_date. */ if($param == 'org'){ /*The second part of the string will be the value of the param that will be used to assign the correct values to the criteria variables. */ $org_id = $vals_array[1]; /*Set the value of the org_id_val. This will be used to make the org sticky for the navbar. If a user looks at an org for any of the dashboards, this value will be set so the org will not change till user selects a different org. */ Session::put('org_id_val', $org_id); if(session()->has('timeline_date') && session('timeline_date') !== ''){ $timeline_date = session('timeline_date'); } else{ $month = date('m'); $day = date('d'); /*The timeline date will default to the current date. When a year is selected from the school_year dropdown, this value will reset to 6-30 of the selected year.*/ $timeline_date = date_create('20' . $year . '-' . $month . '-' . $day . ' 23:59:59')->format('Y-m-d h:i:s'); } }//end if $param == org elseif($param == 'year'){ $org_id = session('org_id'); /*The second part of the string will be the value of the param that will be used to assign the correct values to the criteria variables. */ $year = $vals_array[1]; /*If user types a future FISCAL year in the url there will be NO data to view. This will only happen if a user is bypassing the site restrictions, so set the year to the current year. Otherwise an error will happen*/ if($year > date('y') + 1){ $year = date('y'); } /*The timeline date will default to 6-30 of the current year. When a year is selected from the school_year dropdown, this value will reset to 6-30 of the selected year.*/ $timeline_date = date_create('20' . $year . '-06-30 23:59:59')->format('Y-m-d h:i:s'); }//end if $param == year elseif($param == 'timeline'){ /*The second part of the string will be the value of the param that will be used to assign the correct values to the criteria variables. */ $timeline_date = $vals_array[1] . ' 23:59:59'; $org_id = session('org_id'); /*Create a date object from the string date of the datepicker*/ /*The timeline date will default to 6-30 of the current year. When a year is selected from the school_year dropdown, this value will reset to 6-30 of the selected year.*/ $timeDate = date_create($timeline_date); /*Get the unix date equivalent to the $timeline_date from the datepicker. This will be used to compare the timeline_date to the fiscal year end*/ $timeDateUnix = strtotime($timeline_date); /*Get the 2 digit year from the datepicker's $timeline_date*/ $timeDateYear = $timeDate->format('y'); $yearEndDateUnix = strtotime('06/30/20' . $timeDateYear); if($timeDateUnix <= $yearEndDateUnix){ $year = $timeDateYear; } else{ $year = $timeDateYear + 1; } }//end if $param == timeline elseif($param == 'color'){ $org_id = session('org_id'); /*The second part of the string will be the value of the param that will be used to assign the correct values to the criteria variables. */ $color = $vals_array[1]; if($color == ""){ $color = "both"; } if(session()->has('timeline_date')){ $timeline_date = session('timeline_date'); } else{ /*The timeline date will default to 6-30 of the current year. When a year is selected from the school_year dropdown, this value will reset to 6-30 of the selected year.*/ $timeline_date = date_create('20' . $year . '-06-30')->format('Y-m-d'); } }//end if $param == color /**************************** BEGIN GET DATE VARIABLES **************************/ /*Used to have dynamic headings for the Projected and Next Years columns.*/ $proj_year = $year + 1; $proj_year_next = $year + 2; $gCalc = new GaugesCalcs($timeline_date); /*get the report path for the history report link*/ $history_report_path = $gCalc->getHistoryReportPath($org_id); /*UNIX timestamps*/ $startingDate = $gCalc->getStartingDate(); $endingDate = $gCalc->getEndingDate(); $endingDateForProjCalcs = $gCalc->getEndingDateForProjCalcs(); $todayDateUnix = strtotime(date('Y-m-d H:i:s')); $fiscalYearEndDateUnix = $gCalc->getFiscalYearEndDate(); /*The fiscal_year may NOT be the same as the year in the timeline, depending on which month is in the timeline. So we need to get the actual_fiscal_year to create the $yearTab value AND to select the correct year in the dropdown when a user clicks on a new timeline_date.*/ $actual_fiscal_year = $gCalc->getFiscalYear(); /*This will be only the date portion of the beginning of the fiscal year. It will be displayed at the top of the gauges pages as Commencement Date*/ $fiscalYearBegin = $gCalc->getStartingDateInput(); /*This will be displayed on the page as the commencement date. If an org has upgraded during the fiscal year, the date will be the new_upgrade_date instead of the usual beginning of the fiscal year of 7/1/yyyy*/ $actual_org_commencement_date = $gCalc->getOrgCommencementDate($org_id); /*These are string values for the starting and ending dates based on the value in the Timeline Date datepicker*/ $startingDateFormat = $gCalc->getStartingDateFormat(); $endingDateFormat = $gCalc->getEndingDateFormat(); /*If the user is looking at the page and leaves the year at the current year, there will be no yxxx table yet, so the $yearTab should be set to an empty string. This will make it so the current tables will be used instead of the yxxx tables. The current date should be between the start of the current fiscal year and the upcoming end of the same fiscal year.*/ /*If the month in the timeline is after June, the fiscal year value will be the NEXT year. There will be no yxxxx tables for this year until next 7/1. */ if($year == date('y') && date('m') > 6){ $yearTab = ''; } /* Today's date is after the fiscal-year start and before the fiscal-year end, so this is the current year and there will be no yxxxx tables for this year till 7/1 of next year. Here we are assigning the $yearTab based on this condition being FALSE.*/ else if(!($todayDateUnix >= $startingDate && $todayDateUnix <= $fiscalYearEndDateUnix)){ $yearTab = 'y20' . $actual_fiscal_year . '_'; } /*In any other conditions, do NOT assign a value to $yearTab. */ else{ $yearTab = ''; } $notReportingDate = $gCalc->getNotReportingDate(); $notReportingDateFormat = $gCalc->getNotReportingDateFormat(); $fiscal_days = $gCalc->getFiscalDays(); $last_sync_date = $gCalc->getLastSyncDate($yearTab, $org_id); $minYear = $gCalc->getMinYear(); //used to limit the number of past years in the dropdown $gCount = new GaugesCounts(); $toner_alert_count = $gCount->getTonerLowCount($yearTab, $org_id, $startingDateFormat, $endingDateFormat); $service_needed_count = $gCount->getServiceNeededCount($yearTab, $org_id, $startingDateFormat, $endingDateFormat, $year); $contract_devices_count = $gCount->getContractDeviceCount($yearTab, $org_id); $non_contract_devices_count = $gCount->getNonContractDeviceCount($yearTab, $org_id); $devices_reporting_count = $gCount->getReportingDeviceCount($yearTab, $org_id, $startingDateFormat, $endingDateFormat, $notReportingDateFormat); $not_reporting_count = $gCount->getNonReportingDeviceCount($yearTab, $org_id, $startingDateFormat, $endingDateFormat, $notReportingDateFormat); /*Assign these values to session variables*/ session(['org_id' => $org_id]); session(['year' => $year]); session(['color' => $color]); session(['yearTab' => $yearTab]); session(['timeline_date' => $timeline_date]); /**************************** END GET DATE VARIABLES **************************/ /* We want to only go back as far as 7 fiscal years so if this month is June or earlier, subtract 7, but if this month is July through December, subtract 6 to get the first fiscal year that can be selected.*/ if ($cur_month <= 6) { $maxYear = $cur_year; } else { $maxYear = $cur_year + 1; } /*Get the list of years for the dropdown*/ $years = DB::table('school_years') ->select(DB::raw('school_year, year_id')) ->where('year_id', '>=', $minYear) ->where('year_id', '<=', $maxYear)->get(); /*********************************** BEGIN VOLUME_TOTALS ************************************/ /*Used as a subquery in several queries*/ $serNumDateMetersMax = DB::table($yearTab . 'meters') ->select(DB::raw('max(created_date) as dt, serial_number')) ->where('created_date', '>=', $startingDateFormat) ->where('created_date', '<=', $endingDateFormat) ->where('black_meter', '>', 0) ->groupBy('serial_number'); /************************** BEGIN ORG COMMENCEMENT AND FISCAL DAYS ******************************/ /*This is the beginning of the fiscal year, which is the startingDateFormat value. It will be displayed at the top of the gauges pages.*/ $org_comm_dt = ''; $org_commencement_date = ''; $org_commencement_dt = ''; /*The raw db value w/o any value being assigned conditonally.*/ $org_commencement_date_raw = ''; $org_fiscal_days = 1; $org_name = ''; $display_meter_data; /*If the year is not the current fiscal year use the first if block of queries, otherwise use the else block of queries. The reason for this is that once a year is over and data has been archived, a record will be inserted into this table for each org with the data that is specific to this year.*/ if($yearTab != ''){ $org_commencement_dt = DB::table('org_year_specific_data as orgs') ->join('organizations', 'organizations.org_id', 'orgs.org_id') ->select(DB::raw('orgs.commencement_date as org_commencement_date, organizations.org_name, orgs.display_meter_data')) ->where('orgs.school_year', '=', $actual_fiscal_year) ->where('orgs.org_id', '=', $org_id)->get(); } else{ $org_commencement_dt = DB::table('organizations as orgs') ->select(DB::raw('orgs.commencement_date as org_commencement_date, orgs.org_name, orgs.display_meter_data')) ->where('orgs.org_id', '=', $org_id)->get(); } /*IMPORTANT !!! - - sjh 3/4/2023 - - I do not know why starDoc assigns starting date to org_commencement_date when org_commencement_date is < startingDate, and then they do not use that assigned date to calculate the projected values, but I do see that their values are based on thIs conditional, and they end up using the first condition (with $last_diff). It is like they have not yet assigned the $startingDate variable because they use the one directly from the query resultset. To mimic their process, I have added the variable $org_commencement_date_raw to hold the value directly from org_commencement_date in the db query. Interestingly, if I use this new variable in the conditional for the budgeted values, they DO NOT match starDoc. I added it tnto the case for the budgeted values and it didn't seem to change the values. I am keeping this note to look back into later. Using the original $org_commencement_date, they match exactly. if ($rs['org_commencement_date'] == NULL || $rs['org_commencement_date'] < $startingDate) { $projected_black = $consumed_black / $last_diff * 345;} else{ $projected_black = $consumed_black / $cm_diff * min($org_fiscal_days, 345); } */ foreach($org_commencement_dt as $row){ $org_commencement_date = strtotime($row->org_commencement_date); $org_commencement_date_raw = strtotime($row->org_commencement_date); $org_name = $row->org_name; $display_meter_data = $row->display_meter_data; /*Set the org commencment date*/ if ($row->org_commencement_date == NULL || $org_commencement_date < $startingDate) { $org_commencement_date = $startingDate; } /*Get the number of days between the organization commencement date and the ending fiscal date*/ //$org_fiscal_days = ($fiscalYearEndDateUnix - $org_commencement_date) /60/60/24; $org_fiscal_days = ($endingDate - $org_commencement_date) /60/60/24; /* SJH - 8/18/2023 - subtract 20 days from the total for the fiscal year per Pam. */ if ($org_fiscal_days > 345) { $org_fiscal_days = 345; }//end if }//end foreach /************************** END ORG COMMENCEMENT AND FISCAL DAYS ******************************/ $reporting = 'Y'; $org_cm_diff = $org_fiscal_days; $last_meter_date = ''; /*Array of months used in dropdown on Request Org Service History modal when annually is selected.*/ $month_array = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); /*Variables to hold calculated data*/ $consumed_black = 0; $consumed_black_cost = 0; $consumed_color = 0; $consumed_color_cost = 0; /*building totals*/ $consumed_black_bldg = 0; $consumed_black_bldg_cost = 0; $consumed_color_bldg = 0; $consumed_color_bldg_cost = 0; /*The budgeted and projected costs will be used to calculate the over_under_budget values for the modals of each machine.*/ $budgeted_black = 0; $budgeted_black_cost = 0; $budgeted_color = 0; $budgeted_color_cost = 0; /*building totals*/ $budgeted_black_bldg = 0; $budgeted_black_bldg_cost = 0; $budgeted_color_bldg = 0; $budgeted_color_bldg_cost = 0; $projected_black = 0; $projected_black_cost = 0; $projected_color = 0; $projected_color_cost = 0; /*building totals*/ $projected_black_bldg = 0; $projected_black_bldg_cost = 0; $projected_color_bldg = 0; $projected_color_bldg_cost = 0; $avg_black_per_student = 0; $avg_black_per_student_bldg = 0; $avg_blk_prints_per_student_bldg = 0; $avg_col_prints_per_student_bldg = 0; $avg_color_per_student = 0; $avg_color_per_student_bldg = 0; /*These will be the values for the Next years columns, which is really 2 years out.*/ $proj_blk_year_next = 0; $proj_blk_year_next_bldg = 0; $proj_blk_year_next_cost = 0; $proj_col_year_next = 0; $proj_col_year_next_bldg = 0; $proj_col_year_next_cost = 0; /*Variables to hold calculated data for the year total*/ $consumed_black_year = 0; $consumed_color_year = 0; $consumed_black_year_cost = 0; $consumed_color_year_cost = 0; $budgeted_black_year = 0; $budgeted_color_year = 0; $budgeted_black_year_cost = 0; $budgeted_color_year_cost = 0; $projected_black_year = 0; $projected_color_year = 0; $projected_black_year_cost = 0; $projected_color_year_cost = 0; $avg_black_per_student_year = 0; $avg_color_per_student_year = 0; $proj_blk_year_next_tot = 0; $proj_col_year_next_tot = 0; /*Used to calculate the avg per student (yearly projected / total students for the org) */ $total_students_per_bldg = 0; $consumed_black_estimated = 0; $consumed_black_estimated_cost = 0; $consumed_color_estimated = 0; $consumed_color_estimated_cost = 0; $over_under_budget_black = 0; $over_under_budget_color = 0; $over_under_budget_array = array(); $over_under_budget_bldg_array = array(); $proj_over_budget_black = 0; $proj_over_budget_color = 0; /*This will get the data for the first cell in the accordion child records*/ $mach_data = DB::table('model_details as mach'); $volume_totals = DB::table($yearTab . 'floorplan_machines as fpm') ->join($yearTab . 'floorplans as fp', 'fp.fp_id', '=', 'fpm.floorplans_id') ->join($yearTab . 'buildings as bldgs', 'bldgs.bldg_id', '=', 'fp.buildings_id') ->leftJoin($yearTab . 'meters as mtr', 'fpm.proposed_serial_number', '=', 'mtr.serial_number') ->joinSub($serNumDateMetersMax, 'serNumDateMetersMax', function($join){ $join->on('mtr.serial_number', '=', 'serNumDateMetersMax.serial_number'); $join->on('mtr.created_date', '=', 'serNumDateMetersMax.dt'); }) ->joinSub($mach_data, 'mach_data', function($join){ $join->on('fpm.proposed_model_id', '=', 'mach_data.model_id'); }) /*use cm_diff_orig to get the actual diff between endingDate and the device_commencement_date, then use cm_diff to further process. If cm_diff_orig is < 0, cm_diff will be 0. If cm_diff_orig is 0 or greater, then cm_diff will be the actual value of cm_diff_orig*/ ->select(DB::raw('@device_commencement_date := (CASE WHEN fpm.commencement_date IS NULL THEN ' . $org_commencement_date . ' WHEN UNIX_TIMESTAMP(fpm.commencement_date) < ' . $org_commencement_date . ' THEN ' . $org_commencement_date . ' ELSE UNIX_TIMESTAMP(fpm.commencement_date) END) device_commencement_date, @last_diff_orig := (CASE WHEN mtr.created_date IS NULL THEN 1 ELSE ((UNIX_TIMESTAMP(mtr.created_date) - @device_commencement_date) / 60/60/24) END) last_diff_orig, @last_diff := (CASE WHEN @last_diff_orig <= 0 THEN 1 ELSE @last_diff_orig END) last_diff, @cm_diff_orig := ((' . $endingDateForProjCalcs . '- @device_commencement_date) /60/60/24) cm_diff_orig, @cm_diff := (CASE WHEN @cm_diff_orig < 0 THEN 0 ELSE @cm_diff_orig END) cm_diff, (CASE WHEN fpm.commencement_black_meter IS NULL THEN mtr.black_meter WHEN mtr.black_meter > fpm.commencement_black_meter THEN (mtr.black_meter - fpm.commencement_black_meter) ELSE 0 END) consumed_black, (CASE WHEN fpm.commencement_color_meter IS NULL THEN mtr.color_meter WHEN mtr.color_meter > fpm.commencement_color_meter THEN (mtr.color_meter - fpm.commencement_color_meter) ELSE 0 END) consumed_color, (CASE WHEN fpm.commencement_black_meter IS NULL THEN mtr.black_meter * cpc_black ELSE (mtr.black_meter - fpm.commencement_black_meter) * cpc_black END) consumed_black_cost, (CASE WHEN fpm.commencement_color_meter IS NULL THEN mtr.color_meter * cpc_color ELSE (mtr.color_meter - fpm.commencement_color_meter) * cpc_color END) consumed_color_cost, fpm.budgeted_black budgeted_black, fpm.budgeted_color budgeted_color, bldgs.bldg_id, bldgs.bldg_name, bldgs.student_pop, mtr.created_date, fpm.closeout_date, fpm.proposed_serial_number, fpm.room_name, mach_make, model, machine_image, is_color, fp.floorplan_image, fpm.ip_address, fpm.cpc_black, fpm.cpc_color')) ->whereIn('fpm.proposed_serial_number', function($query) use($year, $yearTab, $org_id){ $query->select('fm.proposed_serial_number') ->from($yearTab . 'floorplan_machines as fm') ->join($yearTab . 'floorplans as fp', 'fp.fp_id', '=', 'fm.floorplans_id') ->join($yearTab . 'buildings as bldgs', 'bldgs.bldg_id', '=', 'fp.buildings_id') ->whereNotNull('fm.fyer_groups_id') ->where('bldgs.organizations_id', '=', $org_id); }) //->whereNotNull('fpm.fyer_groups_id') ->orderBy('bldgs.bldg_name') ->orderBy('fpm.proposed_serial_number') ->get(); $first_bldg = 'Y'; $bldg_name = ''; $array_bldgs = array(); $array_indiv_proj_vals = array(); $over_under_bldg_array = array(); /*Get the user's name and email address in case user wants to Request Org Service History*/ $user = Auth::user(); $user_name = $user->name; $user_email = $user->email; foreach($volume_totals as $row){ unset($over_under_array); /* If this is the first building, assign the bldg_name to $bldg_name, then change value of $first_bldg to N */ if($first_bldg == 'Y'){ $bldg_name = $row->bldg_name; $first_bldg = 'N'; /*Assign the student_pop for the first record of the first building here, then assign the student_pop for the first record of each of the other buildings in the elseif block ($bldg_name != $row->bldg_name). This is so we ONLY get the student_pop one time for each building. There are many device records for each building.*/ $total_students_per_bldg = $row->student_pop; }//end if $first_bldg == Y /* If the current building name = $bldg_name, then process fully*/ if($bldg_name == $row->bldg_name){ $cm_diff = $row->cm_diff; /*Process all rows for this building*/ $last_meter_date = strtotime($row->created_date); /*SJH - Note - the notReportingDate is just 15 days earlier than the last meter read date.*/ if ( ($row->created_date == null) || ($last_meter_date < $notReportingDate) ) { $reporting = "N"; } else { $reporting = "Y"; } /***********BEGIN GET BUDGETED AND PROJECTED VALUES BASED ON DATA FROM THE QUERY***********/ if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->budgeted_black > 0 && $fiscal_days > 0){ $budgeted_black = $row->budgeted_black / $fiscal_days * $org_fiscal_days; } else{ $budgeted_black = 0; } } else{ $budgeted_black = ($row->budgeted_black < 0) ? 0 : $row->budgeted_black; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->budgeted_color > 0 && $fiscal_days > 0){ $budgeted_color = $row->budgeted_color / $fiscal_days * $org_fiscal_days; } else{ $budgeted_color = 0; } } else{ $budgeted_color = ($row->budgeted_color < 0) ? 0 : $row->budgeted_color; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->budgeted_black > 0 && $fiscal_days > 0){ $budgeted_black_cost = $row->budgeted_black / $fiscal_days * $org_fiscal_days * $row->cpc_black; } else{ $budgeted_black_cost = 0; } } else{ $budgeted_black_cost = ($row->budgeted_black < 0) ? 0 : $row->budgeted_black * $row->cpc_black; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->budgeted_color > 0 && $fiscal_days > 0){ $budgeted_color_cost = $row->budgeted_color / $fiscal_days * $org_fiscal_days * $row->cpc_color; } else{ $budgeted_color_cost = 0; } } else{ $budgeted_color_cost = ($row->budgeted_color < 0) ? 0 : $row->budgeted_color * $row->cpc_color; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_black > 0 && $row->cm_diff > 0){ $projected_black = $row->consumed_black / $row->cm_diff * MIN($org_fiscal_days, 345); } else{ $projected_black = 0; } } else{ $projected_black = ($row->consumed_black < 0) ? 0 : $row->consumed_black / $row->last_diff * 345; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_color > 0 && $row->cm_diff > 0){ $projected_color = $row->consumed_color / $row->cm_diff * MIN($org_fiscal_days, 345); } else{ $projected_color = 0; } } else{ $projected_color = ($row->consumed_color < 0) ? 0 : $row->consumed_color / $row->last_diff * 345; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_black > 0 && $row->cm_diff > 0){ $proj_blk_year_next = $row->consumed_black / $row->cm_diff * MIN($org_fiscal_days, 345); } else{ $proj_blk_year_next = 0; } } else{ $proj_blk_year_next = $projected_black; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_color > 0 && $row->cm_diff > 0){ $proj_col_year_next = $row->consumed_color / $row->cm_diff * MIN($org_fiscal_days, 345); } else{ $proj_col_year_next = 0; } } else{ $proj_col_year_next = $projected_color; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_black > 0 && $row->cm_diff > 0){ $projected_black_cost = $row->consumed_black_cost / $row->cm_diff * MIN($org_fiscal_days, 345); } else{ $projected_black_cost = 0; } } else{ $projected_black_cost = $row->consumed_black_cost / $row->last_diff * 345; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_color > 0 && $row->cm_diff > 0){ $projected_color_cost = $row->consumed_color_cost / $row->cm_diff * MIN($org_fiscal_days, 345); } else{ $projected_color_cost = 0; } } else{ $projected_color_cost = $row->consumed_color_cost / $row->last_diff * 345; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_black > 0 && $row->cm_diff > 0){ $proj_blk_year_next_cost = $row->consumed_black_cost / $row->cm_diff * MIN($org_fiscal_days, 345) * 1.035; } else{ $proj_blk_year_next_cost = 0; } } else{ $proj_blk_year_next_cost = $projected_black_cost * 1.035; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_color > 0 && $row->cm_diff > 0){ $proj_col_year_next_cost = $row->consumed_color_cost / $row->cm_diff * MIN($org_fiscal_days, 345) * 1.035; } else{ $proj_col_year_next_cost = 0; } } else{ $proj_col_year_next_cost = $projected_color_cost * 1.035; } /***********END GET BUDGETED AND PROJECTED VALUES BASED ON DATA FROM THE QUERY ***********/ /*Get the device closeout_date for use in setting the projected values for machines no longer in use*/ $closeout_date = $row->closeout_date; $closeout_date_unix = strtotime($row->closeout_date); /*Get the consumed_black for each device. This will be used to calculate the projected_black*/ $consumed_black = ($row->consumed_black < 0) ? 0 : $row->consumed_black; $consumed_black_bldg += $consumed_black; $consumed_black_cost = ($row->consumed_black_cost< 0) ? 0 : $row->consumed_black_cost; $consumed_black_bldg_cost += $consumed_black_cost; /*Get the consumed_color for each device. This will be used to calculate the projected_color*/ $consumed_color = ($row->consumed_color < 0) ? 0 : $row->consumed_color; $consumed_color_bldg += $consumed_color; $consumed_color_cost = ($row->consumed_color_cost< 0) ? 0 : $row->consumed_color_cost; $consumed_color_bldg_cost += $consumed_color_cost; $budgeted_black_bldg += $budgeted_black; $budgeted_black_bldg_cost += $budgeted_black_cost; $budgeted_color_bldg += $budgeted_color; $budgeted_color_bldg_cost += $budgeted_color_cost; /*NOTE SJH 8/3/2023 - The bldg totals for projected values are incremented AFTER ALL OF THE CONDITIONAL PROCESSING IS DONE*/ /*This is the over_under_budget value that gets calculated with the budgeted and projected black and color costs. calc is (projected_black_cost + projected_color_cost) - (budgeted_black_cost + budgeted_color_cost)*/ $over_under_budget_mach_cost = 0; /*Increment the variables that hold the year totals*/ $consumed_black_year += $consumed_black; $consumed_black_year_cost += $consumed_black_cost; $consumed_color_year += $consumed_color; $consumed_color_year_cost += $consumed_color_cost; $budgeted_black_year += $budgeted_black; $budgeted_black_year_cost += $budgeted_black_cost; $budgeted_color_year += $budgeted_color; $budgeted_color_year_cost += $budgeted_color_cost; /*SJH- 7/21/23 - - added checks for $consumed_black > 0 and $consumed_color > 0 to avoid attempted div by zero. I did not add condition for $consumed_black_cost or $consumed_color_cost because if there is $comsumed_black (or color) > 0, then there should be $consumed_black (or color) _cost also.*/ if($row->cm_diff > 0){ if($consumed_black > 0){ $consumed_black_estimated = $consumed_black / $cm_diff * $org_cm_diff; $consumed_black_estimated_cost = $consumed_black_cost / $cm_diff * $org_cm_diff; } if($consumed_color > 0){ $consumed_color_estimated = $consumed_color / $cm_diff * $org_cm_diff; $consumed_color_estimated_cost = $consumed_color_cost / $cm_diff * $org_cm_diff; } } else { $consumed_black_estimated = $consumed_black; $consumed_black_estimated_cost = $consumed_black_cost; $consumed_color_estimated = $consumed_color; $consumed_color_estimated_cost = $consumed_color_cost; } /*Do further processing for projected values*/ if($reporting == 'N' && $org_fiscal_days > 0){ if($budgeted_black > 0){ /*If the projected black for the year is < the budgeted black for the year then use the budgeted black year amount instead of projected black.*/ if ($proj_blk_year_next < ($budgeted_black / $org_fiscal_days * $fiscal_days)) { $projected_black = $budgeted_black; $proj_blk_year_next = $projected_black; $projected_black_cost = $budgeted_black_cost; } }//end if $budgeted_black > 0 if ( $budgeted_color > 0) { /*If the projected color for the year is < the budgeted color for the year then use the budgeted color year amount instead of projected color.*/ if ($proj_col_year_next < ($budgeted_color / $org_fiscal_days * $fiscal_days)) { $projected_color = $budgeted_color; $proj_col_year_next = $projected_color; $projected_color_cost = $budgeted_color_cost; } }//end if $budgeted_color > 0 } /*If the closeout date for a device has passed then this device is no longer in use. Set the projected amounts to match the consumed amounts because the device will not add to print total. Set the projected next years volume to zero.*/ if($closeout_date != NULL && $closeout_date_unix < $endingDate){ $projected_black = $consumed_black_estimated; $projected_black_cost = $consumed_black_estimated_cost; $projected_color = $consumed_color_estimated; $projected_color_cost = $consumed_color_estimated_cost; $proj_blk_year_next = 0; $proj_blk_year_next_cost = 0; $proj_col_year_next = 0; $proj_col_year_next_cost = 0; } /*If any amount is less than 0 set that amount to 0. */ if($consumed_black_estimated < 0){$consumed_black_estimated = 0;} if($consumed_color_estimated < 0){$consumed_color_estimated = 0;} if($consumed_black_estimated_cost < 0){$consumed_black_estimated_cost = 0;} if($consumed_color_estimated_cost < 0){$consumed_color_estimated_cost = 0;} if($proj_blk_year_next < 0){$proj_blk_year_next = 0;} if($proj_blk_year_next_cost < 0){$proj_blk_year_next_cost = 0;} if($proj_col_year_next < 0){$proj_col_year_next = 0;} if($proj_col_year_next_cost < 0){$proj_col_year_next_cost = 0;} /*Assign the values here after all of the conditional processing has been done.*/ $projected_black_bldg += $projected_black; $projected_black_bldg_cost += $projected_black_cost; $projected_color_bldg += $projected_color; $projected_color_bldg_cost += $projected_color_cost; $projected_black_year += $projected_black; $projected_black_year_cost += $projected_black_cost; $projected_color_year += $projected_color; $projected_color_year_cost += $projected_color_cost; $proj_blk_year_next_bldg += $proj_blk_year_next; $proj_col_year_next_bldg += $proj_col_year_next; $proj_blk_year_next_tot += $proj_blk_year_next; $proj_col_year_next_tot += $proj_col_year_next; /*Add the projected values for the current serial_number to the $proj_vals_array, then add that array to the $array_indiv_proj_vals 2 dimensional array. These vals will be shown in the child records for each building in the accordion.*/ $proj_vals_array = array("projected_black"=>$projected_black, "projected_color"=>$projected_color, "proj_blk_year_next"=>$proj_blk_year_next, "proj_col_year_next"=>$proj_col_year_next); $array_indiv_proj_vals[$row->proposed_serial_number] = $proj_vals_array; /*Add the data, to $over_under_array, for the current serial_number that will be displayed in the over_under_budget modal. Then add that array to the $over_under_indiv_array 2 dimensional array. These vals will be shown when the user clicks on a gauge that is tied to over budget machines.*/ if($budgeted_black >= 0 && $projected_black >= 0){ $proj_over_budget_black = ($projected_black - $budgeted_black); } else{ $proj_over_budget_black = 0; } /*if($budgeted_color != 0 && $projected_color != 0){*/ if($budgeted_color >= 0 && $projected_color >= 0){ $proj_over_budget_color = ($projected_color - $budgeted_color); } else{ $proj_over_budget_color = 0; } /*Get the budgeted cost for individual machines. These vals will be used to calculate the over_under_budget for the gauge modals */ $over_under_budget_mach_cost = ($projected_black_cost + $projected_color_cost) - ($budgeted_black_cost + $budgeted_color_cost); $over_under_array = array("room_name"=>$row->room_name, "mach_make"=>$row->mach_make, "model"=>$row->model, "machine_image"=>$row->machine_image, "ip_address"=>$row->ip_address, "is_color"=>$row->is_color, "cpc_black"=>$row->cpc_black, "cpc_color"=>$row->cpc_color, "bldg_id"=>$row->bldg_id, "proj_over_budget_black"=>$proj_over_budget_black, "proj_over_budget_color"=>$proj_over_budget_color, "over_under_budget_mach_cost"=>$over_under_budget_mach_cost); $over_under_indiv_array[$row->proposed_serial_number] = $over_under_array; $over_under_bldg_array[$row->bldg_name] = $over_under_indiv_array; if($row->student_pop > 0){ if($projected_black > 0){ $avg_black_per_student = $projected_black / $row->student_pop; $avg_black_per_student_bldg += $avg_black_per_student; } if($projected_color > 0){ $avg_color_per_student = $projected_color / $row->student_pop; $avg_color_per_student_bldg += $avg_color_per_student; } } else{ $avg_black_per_student = 0; $avg_color_per_student = 0; } $row_array = array("consumed_black"=>$consumed_black_bldg, "budgeted_black"=>$budgeted_black_bldg, "projected_black"=>$projected_black_bldg, "avg_black_per_student"=>$avg_black_per_student_bldg, "next_year_black"=>$proj_blk_year_next_bldg, "consumed_color"=>$consumed_color_bldg, "budgeted_color"=>$budgeted_color_bldg, "projected_color"=>$projected_color_bldg, "avg_color_per_student"=>$avg_color_per_student_bldg, "next_year_color"=>$proj_col_year_next_bldg, "floorplan_image"=>"images/" . $row->floorplan_image); $array_bldgs[$bldg_name] = $row_array; }//end if($bldg_name == $row->bldg_name) /* If the current building name is different from $bldg_name, then this is a new building, so assign the new bldg_name to $bldg_name, then process fully */ elseif($bldg_name != $row->bldg_name){ unset($over_under_indiv_array); $cm_diff = $row->cm_diff; /*Assign the new building name to $bldg_name*/ $bldg_name = $row->bldg_name; /*Process all rows for this building*/ $last_meter_date = strtotime($row->created_date); /*SJH - Note - the notReportingDate is just 15 days earlier than the last meter read date.*/ if ( ($row->created_date == null) || ($last_meter_date < $notReportingDate) ) { $reporting = "N"; } else { $reporting = "Y"; } /***********BEGIN GET BUDGETED AND PROJECTED VALUES BASED ON DATA FROM THE QUERY***********/ if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->budgeted_black > 0 && $fiscal_days > 0){ $budgeted_black = $row->budgeted_black / $fiscal_days * $org_fiscal_days; } else{ $budgeted_black = 0; } } else{ $budgeted_black = ($row->budgeted_black < 0) ? 0 : $row->budgeted_black; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->budgeted_color > 0 && $fiscal_days > 0){ $budgeted_color = $row->budgeted_color / $fiscal_days * $org_fiscal_days; } else{ $budgeted_color = 0; } } else{ $budgeted_color = ($row->budgeted_color < 0) ? 0 : $row->budgeted_color; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->budgeted_black > 0 && $fiscal_days > 0){ $budgeted_black_cost = $row->budgeted_black / $fiscal_days * $org_fiscal_days * $row->cpc_black; } else{ $budgeted_black_cost = 0; } } else{ $budgeted_black_cost = ($row->budgeted_black < 0) ? 0 : $row->budgeted_black * $row->cpc_black; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->budgeted_color > 0 && $fiscal_days > 0){ $budgeted_color_cost = $row->budgeted_color / $fiscal_days * $org_fiscal_days * $row->cpc_color; } else{ $budgeted_color_cost = 0; } } else{ $budgeted_color_cost = ($row->budgeted_color < 0) ? 0 : $row->budgeted_color * $row->cpc_color; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_black > 0 && $row->cm_diff > 0){ $projected_black = $row->consumed_black / $row->cm_diff * MIN($org_fiscal_days, 345); } else{ $projected_black = 0; } } else{ $projected_black = ($row->consumed_black < 0) ? 0 : $row->consumed_black / $row->last_diff * 345; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_color > 0 && $row->cm_diff > 0){ $projected_color = $row->consumed_color / $row->cm_diff * MIN($org_fiscal_days, 345); } else{ $projected_color = 0; } } else{ $projected_color = ($row->consumed_color < 0) ? 0 : $row->consumed_color / $row->last_diff * 345; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_black > 0 && $row->cm_diff > 0){ $proj_blk_year_next = $row->consumed_black / $row->cm_diff * MIN($org_fiscal_days, 345); } else{ $proj_blk_year_next = 0; } } else{ $proj_blk_year_next = $projected_black; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_color > 0 && $row->cm_diff > 0){ $proj_col_year_next = $row->consumed_color / $row->cm_diff * MIN($org_fiscal_days, 345); } else{ $proj_col_year_next = 0; } } else{ $proj_col_year_next = $projected_color; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_black > 0 && $row->cm_diff > 0){ $projected_black_cost = $row->consumed_black_cost / $row->cm_diff * MIN($org_fiscal_days, 345); } else{ $projected_black_cost = 0; } } else{ $projected_black_cost = $row->consumed_black_cost / $row->last_diff * 345; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_color > 0 && $row->cm_diff > 0){ $projected_color_cost = $row->consumed_color_cost / $row->cm_diff * MIN($org_fiscal_days, 345); } else{ $projected_color_cost = 0; } } else{ $projected_color_cost = $row->consumed_color_cost / $row->last_diff * 345; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_black > 0 && $row->cm_diff > 0){ $proj_blk_year_next_cost = $row->consumed_black_cost / $row->cm_diff * MIN($org_fiscal_days, 345) * 1.035; } else{ $proj_blk_year_next_cost = 0; } } else{ $proj_blk_year_next_cost = $projected_black_cost * 1.035; } if(!($org_commencement_date_raw === NULL OR $org_commencement_date_raw < $startingDate)){ if($row->consumed_color > 0 && $row->cm_diff > 0){ $proj_col_year_next_cost = $row->consumed_color_cost / $row->cm_diff * MIN($org_fiscal_days, 345) * 1.035; } else{ $proj_col_year_next_cost = 0; } } else{ $proj_col_year_next_cost = $projected_color_cost * 1.035; } /***********END GET BUDGETED AND PROJECTED VALUES BASED ON DATA FROM THE QUERY ***********/ /*Get the device closeout_date for use in setting the projected values for machines no longer in use*/ $closeout_date = $row->closeout_date; $closeout_date_unix = strtotime($row->closeout_date); /*Get the consumed_black for each device. This will be used to calculate the projected_black*/ $consumed_black = ($row->consumed_black < 0) ? 0 : $row->consumed_black; $consumed_black_bldg = $consumed_black; $consumed_black_cost = ($row->consumed_black_cost< 0) ? 0 : $row->consumed_black_cost; $consumed_black_bldg_cost = $consumed_black_cost; /*Get the consumed_color for each device. This will be used to calculate the projected_color*/ $consumed_color = ($row->consumed_color < 0) ? 0 : $row->consumed_color; $consumed_color_bldg = $consumed_color; $consumed_color_cost = ($row->consumed_color_cost< 0) ? 0 : $row->consumed_color_cost; $consumed_color_bldg_cost = $consumed_color_cost; $budgeted_black_bldg = $budgeted_black; $budgeted_black_bldg_cost = $budgeted_black_cost; $budgeted_color_bldg = $budgeted_color; $budgeted_color_bldg_cost = $budgeted_color_cost; /*This is the over_under_budget value that gets calculated with the budgeted and projected black and color costs. calc is (projected_black_cost + projected_color_cost) - (budgeted_black_cost + budgeted_color_cost)*/ $over_under_budget_mach_cost = 0; /*Increment the variables that hold the year totals*/ $consumed_black_year += $consumed_black; $consumed_black_year_cost += $consumed_black_cost; $consumed_color_year += $consumed_color; $consumed_color_year_cost += $consumed_color_cost; $budgeted_black_year += $budgeted_black; $budgeted_black_year_cost += $budgeted_black_cost; $budgeted_color_year += $budgeted_color; $budgeted_color_year_cost += $budgeted_color_cost; /*SJH- 7/21/23 - - added checks for $consumed_black > 0 and $consumed_color > 0 to avoid attempted div by zero. I did not add condition for $consumed_black_cost or $consumed_black_color because if there is $comsumed_black > 0 (or color), then there should be $consumed_black_cost also.*/ if($row->cm_diff > 0){ if($consumed_black > 0){ $consumed_black_estimated = $consumed_black / $cm_diff * $org_cm_diff; $consumed_black_estimated_cost = $consumed_black_cost / $cm_diff * $org_cm_diff; } if($consumed_color > 0){ $consumed_color_estimated = $consumed_color / $cm_diff * $org_cm_diff; $consumed_color_estimated_cost = $consumed_color_cost / $cm_diff * $org_cm_diff; } } else { $consumed_black_estimated = $consumed_black; $consumed_black_estimated_cost = $consumed_black_cost; $consumed_color_estimated = $consumed_color; $consumed_color_estimated_cost = $consumed_color_cost; } /*Do further processing for projected values*/ if($reporting == 'N' && $org_fiscal_days > 0){ if($budgeted_black > 0){ /*If the $proj_blk_year_next, which is equal to the projected black value that was first calculated, for the year is < the budgeted black for the year then use the budgeted black year amount instead of projected black.*/ if ($proj_blk_year_next < ($budgeted_black / $org_fiscal_days * $fiscal_days)) { $projected_black = $budgeted_black; $projected_black_cost = $budgeted_black_cost; $proj_blk_year_next = $projected_black; $proj_blk_year_next_cost = $projected_black_cost * 1.035; } } if ( $budgeted_color > 0) { /*If the $proj_col_year_next, which is equal to the projected color value that was first calculated, for the year is < the budgeted color for the year then use the budgeted color year amount instead of projected color.*/ if ($proj_col_year_next < ($budgeted_color / $org_fiscal_days * $fiscal_days)) { $projected_color = $budgeted_color; $projected_color_cost = $budgeted_color_cost; $proj_col_year_next = $projected_color; $proj_col_year_next_cost = $projected_color_cost * 1.035; } } } /*If any amount is less than 0 set that amount to 0. */ if($consumed_black_estimated < 0){$consumed_black_estimated = 0;} if($consumed_color_estimated < 0){$consumed_color_estimated = 0;} if($consumed_black_estimated_cost < 0){$consumed_black_estimated_cost = 0;} if($consumed_color_estimated_cost < 0){$consumed_color_estimated_cost = 0;} if($proj_blk_year_next < 0){$proj_blk_year_next = 0;} if($proj_blk_year_next_cost < 0){$proj_blk_year_next_cost = 0;} if($proj_col_year_next < 0){$proj_col_year_next = 0;} if($proj_col_year_next_cost < 0){$proj_col_year_next_cost = 0;} /*If the closeout date for a device has passed then this device is no longer in use. Set the projected amounts to match the consumed amounts because the device will not add to print total. Set the projected next years volume to zero.*/ if($closeout_date != NULL && $closeout_date_unix < $endingDate){ $projected_black = $consumed_black_estimated; $projected_black_cost = $consumed_black_estimated_cost; $projected_color = $consumed_color_estimated; $projected_color_cost = $consumed_color_estimated_cost; $proj_blk_year_next = 0; $proj_blk_year_next_cost = 0; $proj_col_year_next = 0; $proj_col_year_next_cost = 0; } $projected_black_year += $projected_black; $projected_black_year_cost += $projected_black_cost; $projected_color_year += $projected_color; $projected_color_year_cost += $projected_color_cost; /*Assign the values here after all of the conditional processing has been done.*/ $projected_black_bldg = $projected_black; $projected_black_bldg_cost = $projected_black_cost; $projected_color_bldg = $projected_color; $projected_color_bldg_cost = $projected_color_cost; $proj_blk_year_next_bldg = $proj_blk_year_next; $proj_col_year_next_bldg = $proj_col_year_next; $projected_black_cost = $projected_black * $row->cpc_black; $projected_color_cost = $projected_color * $row->cpc_color; /*Do not reset these. They are the totals for the entire org for the year.*/ $proj_blk_year_next_tot += $proj_blk_year_next; $proj_col_year_next_tot += $proj_col_year_next; /*Add the projected values for the current serial_number to the $proj_vals_array, then add that array to the $array_indiv_proj_vals 2 dimensional array. These vals will be shown in the child records for each building in the accordion.*/ $proj_vals_array = array("projected_black"=>$projected_black, "projected_color"=>$projected_color, "proj_blk_year_next"=>$proj_blk_year_next, "proj_col_year_next"=>$proj_col_year_next); $array_indiv_proj_vals[$row->proposed_serial_number] = $proj_vals_array; /*Add the data, to $over_under_array, for the current serial_number that will be displayed in the over_under_budget modal. Then add that array to the $over_under_indiv_array 2 dimensional array. These vals will be shown when the user clicks on a gauge that is tied to over budget machines.*/ if($budgeted_black != 0 && $consumed_black != 0){ $proj_over_budget_black = ($consumed_black / $budgeted_black); } else{ $proj_over_budget_black = 0; } if($budgeted_color != 0 && $consumed_color != 0){ $proj_over_budget_color = ($consumed_color / $budgeted_color); } else{ $proj_over_budget_color = 0; } /*Get the budgeted cost for indiv machines. These vals will be used to calculate the over_under_budget for the gauge modals */ $over_under_budget_mach_cost = ($projected_black_cost + $projected_color_cost) - ($budgeted_black_cost + $budgeted_color_cost); $over_under_array = array("room_name"=>$row->room_name, "mach_make"=>$row->mach_make, "model"=>$row->model, "machine_image"=>$row->machine_image, "ip_address"=>$row->ip_address, "is_color"=>$row->is_color, "cpc_black"=>$row->cpc_black, "cpc_color"=>$row->cpc_color, "bldg_id"=>$row->bldg_id, "proj_over_budget_black"=>$proj_over_budget_black, "proj_over_budget_color"=>$proj_over_budget_color, "over_under_budget_mach_cost"=>$over_under_budget_mach_cost); $over_under_indiv_array[$row->proposed_serial_number] = $over_under_array; $over_under_bldg_array[$row->bldg_name] = $over_under_indiv_array; if($row->student_pop > 0){ $avg_black_per_student = $projected_black / $row->student_pop; $avg_black_per_student_bldg = $avg_black_per_student; $avg_color_per_student = $projected_color / $row->student_pop; $avg_color_per_student_bldg = $avg_color_per_student; /*Assign the student_pop for the first record of each building excluding the first building. The student_pop for the first building was assigned in the if block ($first_bldg == 'Y'). This is so we ONLY get the student_pop one time for each building. There are many device records for each building.*/ $total_students_per_bldg = $row->student_pop; } else{ $avg_black_per_student = 0; $avg_color_per_student = 0; } /*Now assign the current row values to the array under the new bldg_name*/ $row_array = array("consumed_black"=>$consumed_black_bldg, "budgeted_black"=>$budgeted_black_bldg, "projected_black"=>$projected_black_bldg, "avg_black_per_student"=>$avg_black_per_student_bldg, "next_year_black"=>$proj_blk_year_next_bldg, "consumed_color"=>$consumed_color_bldg, "budgeted_color"=>$budgeted_color_bldg, "projected_color"=>$projected_color_bldg, "avg_color_per_student"=>$avg_color_per_student_bldg, "next_year_color"=>$proj_col_year_next_bldg, "floorplan_image"=>"images/" . $row->floorplan_image); $array_bldgs[$bldg_name]= $row_array; }//end if($bldg_name != $row->bldg_name) /*************** BEGIN Add data to the $over_under_budget_bldg_arrays to display in the Black and Color gauge % *******/ /*SJH - 8/26/22 - Get the correct calculation for these*/ if($budgeted_black_bldg !== NULL && $budgeted_black_bldg != 0 && $consumed_black_bldg !== NULL && $consumed_black_bldg != 0){ $over_under_budget_black = round(($consumed_black_bldg / $budgeted_black_bldg) * 100); } else{ $over_under_budget_black = 0; } if($budgeted_color_bldg !== NULL && $budgeted_color_bldg != 0 && $consumed_color_bldg !== NULL && $consumed_color_bldg != 0){ $over_under_budget_color = round(($consumed_color_bldg / $budgeted_color_bldg) * 100); } else{ $over_under_budget_color = 0; } if($projected_black_bldg !== NULL && $projected_black_bldg != 0 && $total_students_per_bldg !== NULL && $total_students_per_bldg != 0){ $avg_blk_prints_per_student_bldg = $projected_black_bldg / $total_students_per_bldg; $avg_col_prints_per_student_bldg = $projected_color_bldg / $total_students_per_bldg; } /*Add the over_under_budget values for the current building to the $over_under_budget_array, then add that array to the $over_under_budget_bldg_array 2 dimensional array. These vals will be shown in the gauges for each building for black and color.*/ if($color == 'both' || $color ==''){ $over_under_budget_array = array("Black"=>$over_under_budget_black, "Color"=>$over_under_budget_color, "floorplan_image"=>"images/" . $row->floorplan_image, "avg_blk_prints_per_student_bldg"=>$avg_blk_prints_per_student_bldg, "avg_col_prints_per_student_bldg"=>$avg_col_prints_per_student_bldg); } elseif($color == 'black'){ $over_under_budget_array = array("Black"=>$over_under_budget_black, "floorplan_image"=>"images/" . $row->floorplan_image, "avg_blk_prints_per_student_bldg"=>$avg_blk_prints_per_student_bldg, "avg_col_prints_per_student_bldg"=>$avg_col_prints_per_student_bldg); } elseif($color == 'color'){ $over_under_budget_array = array("Color"=>$over_under_budget_color, "floorplan_image"=>"images/" . $row->floorplan_image, "avg_blk_prints_per_student_bldg"=>$avg_blk_prints_per_student_bldg, "avg_col_prints_per_student_bldg"=>$avg_col_prints_per_student_bldg); } $over_under_budget_bldg_array[$row->bldg_name] = $over_under_budget_array; /*************** END Add data to the $over_under_budget_bldg_arrays to display in the Black and Color gauge % *******/ }//end foreach if($total_students_per_bldg > 0){ $avg_black_per_student_year = $projected_black_year / $total_students_per_bldg; $avg_color_per_student_year = $projected_color_year / $total_students_per_bldg; } $year_totals_array = array("consumed_black_year"=>$consumed_black_year, "budgeted_black_year"=>$budgeted_black_year, "projected_black_year"=>$projected_black_year, "avg_black_per_student_year"=>$avg_black_per_student_year, "next_years_black_year"=>$proj_blk_year_next_tot, "consumed_color_year"=>$consumed_color_year, "budgeted_color_year"=>$budgeted_color_year, "projected_color_year"=>$projected_color_year, "avg_color_per_student_year"=>$avg_color_per_student_year, "next_years_color_year"=>$proj_col_year_next_tot, "consumed_black_year_cost"=>$consumed_black_year_cost, "budgeted_black_year_cost"=>$budgeted_black_year_cost, "projected_black_year_cost"=>$projected_black_year_cost, "consumed_color_year_cost"=>$consumed_color_year_cost, "budgeted_color_year_cost"=>$budgeted_color_year_cost, "projected_color_year_cost"=>$projected_color_year_cost); /************************************* BEGIN CODE TO RESTRICT ACCESS TO PAGE AND TO LIMIT ORGS IN DROPDOWN TO THOSE ASSOCIATED WITH THE CURRENT USER *************************************/ if (!Gate::allows('manage_gauges', $org_id)) { abort(403); } else{ /*******BEGIN - Get user data to limit the orgs in the select dropdown to ONLY those the user is associated with.*******/ /*Get the user data, for current logged in user,, from the user collection (The entire row from the users table)*/ $user = Auth::user(); /*Assign the id, to $user_id, from the $user collection*/ $user_id = $user->id; $userData = new UserData($user_id); $user_role = $userData->getUserRole(); $orgs_array = $userData->getUserOrgs(); /*Return the view with all orgs in the select dropdown if this user has the role of admin_spc. Otherwise, ONLY return the list of orgs that are associated with the current user.*/ $orgs = Organization::orderBy('org_name') ->whereIn('org_id', $orgs_array)->get(); /*******END - Get user data to limit the orgs in the select dropdown to ONLY those the user is associated with.*******/ return view('gauges.show', compact('orgs', 'org_id', 'org_name', 'year', 'years', 'actual_fiscal_year', 'timeline_date', 'color', 'display_meter_data', 'toner_alert_count', 'service_needed_count', 'contract_devices_count', 'non_contract_devices_count', 'devices_reporting_count', 'not_reporting_count', 'last_sync_date', 'array_bldgs', 'over_under_budget_bldg_array', 'year_totals_array', 'array_indiv_proj_vals', 'over_under_bldg_array', 'proj_year', 'proj_year_next', 'history_report_path', 'fiscalYearBegin', 'user_name', 'user_email', 'month_array', 'actual_org_commencement_date')); } /************************************* END CODE TO RESTRICT ACCESS TO PAGE AND TO LIMIT ORGS IN DROPDOWN TO THOSE ASSOCIATED WITH THE CURRENT USER *************************************/ } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { /*******BEGIN - Get user data to limit the orgs in the select dropdown to ONLY those the user is associated with.*******/ /*Get the user data, for current logged in user, from the user collection (The entire row from the users table)*/ $user = Auth::user(); /*Assign the id, to $user_id, from the $user collection*/ $user_id = $user->id; $userData = new UserData($user_id); $user_role = $userData->getUserRole(); $orgs_array = $userData->getUserOrgs(); /*Return the view with all orgs in the select dropdown if this user has the role of admin_spc. Otherwise, ONLY return the list of orgs that are associated with the current user.*/ $orgs = Organization::orderBy('org_name') ->whereIn('org_id', $orgs_array)->get(); /*******END - Get user data to limit the orgs in the select dropdown to ONLY those the user is associated with.*******/ return view('gauges.index', compact('orgs')); } public function create(){} public function store(Request $request){} public function edit($id){} public function update(Request $request, $id){} public function destroy($id){} }