function test() { App::Import('Shell', 'Shell'); App::Import('Vendor', array('shells/sniffer_data')); $myShell = new SnifferDataShell(new Object()); $myShell->initialize(); // Select the method to call $Shell = $myShell->main($view = true, $debug = false); }
function tachionDetail($indicator = null) { // pr($indicator);exit(); // pr($this->Flotas->find('all')); $idx_empresa = $_SESSION['Auth']['User']['id_empresa']; $year = date('Y'); App::Import('Shell', 'Shell'); App::Import('Vendor', array('shells/sniffer_data')); $myShell = new SnifferDataShell(new Object()); $myShell->initialize(); // Select the method to call $Shell = $myShell->main($view = true, $debug = false); // pr($Shell['Toneladas']);exit(); App::Import('Shell', 'Shell'); App::Import('Vendor', array('shells/calendar')); $myCalendar = new CalendarShell(new Object()); $myCalendar->initialize(); $months = $myCalendar->months(true, false, $year); App::Import('Shell', 'Shell'); App::Import('Vendor', array('shells/flotas')); $fleet = new FlotasShell(new Object()); $fleet->initialize(); $fleets = $fleet->fleets(true, false); pr($fleets); // exit(); App::import('Controller', 'Holiday'); $Holiday = new HolidayController(); $Holiday->constructClasses(); $startDate = date('Y-m-d', mktime('0', '0', '0', date('n'), '01', date('Y'))); // for CurrentMonth $endDate = date('Y-m-d', mktime('0', '0', '0', date('n'), date('t'), date('Y'))); // for CurrentMonth $GoToWork = $Holiday->RetrieveHolidays($startDate, $endDate, $debug = true, $year = date('Y')); // pr($GoToWork); $toneladas_labour_days = $Shell['Toneladas']['DailyReport']['report_day']; $kilometros_labour_days = $Shell['kms']['report_daily']; $ingresos_labour_days = $Shell['ingresos']['report_daily']; foreach ($toneladas_labour_days as $id_empresa => $areas) { foreach ($areas as $area_name => $meses) { foreach ($meses as $NombreMes => $fracciones) { foreach ($fracciones as $NombreFraccion => $dias) { if (!empty($dias)) { foreach ($dias as $id_dia => $tons_value) { if ($NombreMes == date('M')) { if (!empty($tons_value)) { $dias_toneladas[$id_empresa][$area_name][$NombreMes][$NombreFraccion][$id_dia] = $tons_value; } } } } } } } } foreach ($kilometros_labour_days as $id_empresa => $areas) { foreach ($areas as $area_name => $meses) { foreach ($meses as $NombreMes => $fracciones) { foreach ($fracciones as $NombreFraccion => $dias) { foreach ($dias as $id_dia => $kms_value) { if ($NombreMes == date('M')) { if (!empty($kms_value)) { $dias_kilometros[$id_empresa][$area_name][$NombreMes][$NombreFraccion][$id_dia] = $kms_value; } } } } } } } foreach ($ingresos_labour_days as $id_empresa => $areas) { foreach ($areas as $area_name => $meses) { foreach ($meses as $NombreMes => $fracciones) { foreach ($fracciones as $NombreFraccion => $dias) { foreach ($dias as $id_dia => $ingresos_value) { if ($NombreMes == date('M')) { if (!empty($ingresos_value)) { $dias_ingresos[$id_empresa][$area_name][$NombreMes][$NombreFraccion][$id_dia] = $ingresos_value; } } } } } } } $promedio['toneladas'] = $dias_toneladas; $promedio['kilometros'] = $dias_kilometros; $promedio['ingresos'] = $dias_ingresos; foreach ($promedio as $indicador => $dias_indicador) { foreach ($dias_indicador as $id_empresa => $area) { foreach ($area as $area_name => $meses) { foreach ($meses as $meses_name => $fractiones) { foreach ($fractiones as $fractiones_name => $days_pr) { $acum_men = array_sum($days_pr); // pr($acum_men); $dias_laborados = count($days_pr); $projection[$indicador][$id_empresa][$area_name][$meses_name][$fractiones_name] = $acum_men / $dias_laborados * $GoToWork; } } } } } pr($projection); exit; if (!isset($indicator)) { $this->set('projection', $projection); } else { $this->set('projection', $projection[$indicator]); } $this->set('months', $months); $today = null; // exit(); }
function buildVars() { // $time1 = microtime(true); App::Import('Shell', 'Shell'); App::Import('Vendor', array('shells/sniffer_data')); $myShell = new SnifferDataShell(new Object()); $myShell->initialize(); // Select the method to call $_append = $myShell->Empresas(); $areas = $myShell->areas(); // $time2 = microtime(true); // echo "script execution time: ".($time2-$time1); //value in seconds // exit(); // ALERT this can change having the table.db /** ALERT => TODO rebuild the structure according to the new approach @param => This is going inside of _append loop to buid fraction for each Empresa **/ $TpoOp = explode(',', $filter['flota'] = null); // this select which is calculating ALERT @param => Expecting if (!isset($year)) { $year = date('Y'); } // $months = $myShell->months($return=true,$set=false,$year=date('Y')); if (!isset($_SESSION['projections']['months'])) { $_SESSION['projections']['months'] = $this->months($return = true, $set = false, $year = date('Y')); } $months = $_SESSION['projections']['months']; // $fraction = $myShell->Fraccion->find('list',array('fields'=>array('id','fraccion'))); if (!isset($_SESSION['projections']['fraction'])) { $_SESSION['projections']['fraction'] = $this->Fraccion->find('list', array('fields' => array('id', 'fraccion'))); } $fraction = $_SESSION['projections']['fraction']; foreach ($areas as $key => $data) { for ($i = 1; $i <= date('n'); $i++) { foreach ($data as $idx => $content) { // $toneladas[$key][trim($content)][date('M',mktime('0','0','0',$i,'01',$year))] = null ; // $kms[$key][trim($content)][date('M',mktime('0','0','0',$i,'01',$year))] = null ; // $ingresos[$key][trim($content)][date('M',mktime('0','0','0',$i,'01',$year))] = null ; $structure[$key][trim($content)][date('M', mktime('0', '0', '0', $i, '01', $year))] = null; foreach ($fraction as $h => $d) { // $toneladas[$key][trim($content)][date('M',mktime('0','0','0',$i,'01',$year))][$d] = null; // $kms[$key][trim($content)][date('M',mktime('0','0','0',$i,'01',$year))][$d] = null; // $ingresos[$key][trim($content)][date('M',mktime('0','0','0',$i,'01',$year))][$d] = null; $structure[$key][trim($content)][date('M', mktime('0', '0', '0', $i, '01', $year))][$d] = null; $TotalByFraction[$key][trim($content)][$d] = null; // pending ... } } } } // End of each area return $structure; }
function operations($year = null) { if (empty($year)) { $year = date('Y'); } $tipoOperacion = null; $operations = $this->dbOp(); App::Import('Shell', 'Shell'); App::Import('Vendor', array('shells/calendar')); $myCalendar = new CalendarShell(new Object()); $myCalendar->initialize(); $calendar = $myCalendar->main($year, false); $months = $calendar['months']; $fraction = $this->Fraccion->find('list', array('fields' => array('id', 'fraccion'))); // pr($fraction); App::Import('Shell', 'Shell'); App::Import('Vendor', array('shells/sniffer_data')); $myShell = new SnifferDataShell(new Object()); $myShell->initialize(); // Select the method to call $Shell = $myShell->main($view = true, $debug = false, $year); $coverOps['Toneladas']['days'] = $Shell['Toneladas']['DailyReport']['report_day']; $coverOps['Toneladas']['months'] = $Shell['Toneladas']['DetailData']['toneladas']; $coverOps['kms']['days'] = $Shell['kms']['report_daily_plus']; $coverOps['kms']['months'] = $Shell['kms']['kms_month_by_fraction']; $coverOps['ingresos']['days'] = $Shell['ingresos']['report_daily']; $coverOps['ingresos']['months'] = $Shell['ingresos']['total_ingresos_monthly']; /** * TODO this don't have a db is a add like a pluging **/ $coverOps['Viajes']['days'] = $Shell['kms']['count']['count_day']; $coverOps['Viajes']['months'] = $Shell['kms']['count']['count_month']; // $kms_detail['count']['count_day'] = $count_day; // sum of both count's before and classified by day // $kms_detail['count']['count_month'] = $count_month; // the sum counting by id_empresa, area, month and fraction // $kms_detail['count']['count_month_no_fraction'] = $count_month_no_fraction; //same as before with out fraction // $kms_detail['count']['count_year'] = $count_year ; //sum of all the months by area yearly by fraction // $kms_detail['count']['count_year_no_fraction'] = $count_year_no_fraction;//sum of all the months by area yearly foreach ($operations as $idOp => $opName) { $tipoOperacion = $idOp; if (in_array($operations[$tipoOperacion], $operations) == true) { $Operacion = $coverOps[$operations[$tipoOperacion]]['days']; $monthOperacion = $coverOps[$operations[$tipoOperacion]]['months']; } // Building databases foreach ($Operacion as $id_empresa => $areas) { foreach ($areas as $areaName => $Months) { foreach ($Months as $monthName => $Fractions) { foreach ($Fractions as $fractionName => $DaysOperacion) { if (isset($DaysOperacion)) { foreach ($DaysOperacion as $day => $operacion) { if (!empty($operacion)) { foreach ($months as $numMonth => $monthData) { foreach ($monthData as $description => $monthContent) { if ($monthData['short'] == $monthName) { $numMes = $monthData['num']; } } } foreach ($fraction as $id_fraction => $fractionDescription) { if ($fractionDescription == $fractionName) { $numFraction = $id_fraction; } } $day = str_pad((int) $day, '2', "0", STR_PAD_LEFT); $operacionesDiarias['Operacion'][] = array('id_empresa' => $id_empresa, 'area' => $areaName, 'year' => $year, 'day' => $day, 'operacion' => $operacion, 'tipoOperacion' => $tipoOperacion, 'month' => $monthName, 'numMes' => $numMes, 'id_fraction' => $numFraction, 'fraccion' => $fractionName); } } } // if isset($DaysToneladas) } } } } //next go for mensual toneladas // Reset the vars to reuse; $areas = $areaName = $monthName = $dataOperacion = $numMes = null; foreach ($monthOperacion as $id_empresa => $areas) { // in this case the Area is under Empresa foreach ($areas as $areaName => $month) { foreach ($month as $monthName => $dataOperacion) { foreach ($dataOperacion as $fractionName => $dataOperacionValue) { if (isset($dataOperacionValue) and !empty($dataOperacionValue)) { foreach ($months as $numMonth => $monthData) { foreach ($monthData as $description => $monthContent) { if ($monthData['short'] == $monthName) { $numMes = $monthData['num']; } } } foreach ($fraction as $id_fraction => $fractionDescription) { if ($fractionDescription == $fractionName) { $numFraction = $id_fraction; } } $operacionesMensuales['OperacionMensual'][] = array('id_empresa' => $id_empresa, 'area' => $areaName, 'year' => $year, 'operacion' => $dataOperacionValue, 'tipoOperacion' => $tipoOperacion, 'month' => $monthName, 'numMes' => $numMes, 'id_fraction' => $numFraction, 'fraccion' => $fractionName); } } } } } } //End of each operations $conditionsDaily['Operacion.year'] = $year; $this->idCheck($conditionsDaily, $operations[$tipoOperacion], $frecuency = 'Diaria', $data = $operacionesDiarias['Operacion'], $model = 'Operacion', $useTable = 'operacion', $system = false); $conditions['OperacionMensual.year'] = $year; $this->idCheck($conditions, $operations[$tipoOperacion], $frecuency = 'Mensual', $data = $operacionesMensuales['OperacionMensual'], $model = 'OperacionMensual', $useTable = 'operacionMensual', $system = false); }