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();
 }
Esempio n. 2
0
 function grapBuild($id_empresa = null, $concepto = null, $area_name = null, $fracciones_name = null, $month_name = null, $grapColor = null, $operacion = null, $dateParam = null, $year = null)
 {
     // 		    build the data for ImagesShell
     // 		$operacion = array('1'=>'0');
     // 		$month_name = '';
     $EmpConditions['Empresas.active'] = '1';
     // Check if the area is alive
     $empresas = $this->Empresas->find('list', array('fields' => array('id_empresa', 'empresa'), array('conditions' => $EmpConditions)));
     App::Import('Shell', 'Shell');
     App::Import('Vendor', array('shells/calendar'));
     $myCalendar = new CalendarShell(new Object());
     $myCalendar->initialize();
     // 	  $calendar = $myCalendar->main($year=date('Y'),false);
     $month = $myCalendar->months(true, false, $year);
     //   		$url= '/tmp/images/';
     $url = "../../app/webroot/img/thumbs/daily/";
     $this->autoRender = false;
     // i don't remember why is this but do it
     App::import('Vendor', 'pData', array('file' => 'pcharts' . DS . 'class' . DS . 'pData.class.php'));
     App::import('Vendor', 'pDraw', array('file' => 'pcharts' . DS . 'class' . DS . 'pDraw.class.php'));
     App::import('Vendor', 'pImage', array('file' => 'pcharts' . DS . 'class' . DS . 'pImage.class.php'));
     $fontFolder = '..' . DS . '..' . DS . 'vendors' . DS . 'pcharts' . DS . 'fonts' . DS;
     $maxValue = max($operacion);
     /* Create and populate the pData object */
     $MyData = new pData();
     // 		$MyData->addPoints($report_day,"Temperature");
     $MyData->addPoints($operacion, $concepto);
     // 		$MyData->setSerieDrawable($concepto,TRUE);
     $MyData->setAxisName(0, $concepto);
     // 		$MyData->addPoints(array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"),"Labels");
     $MyData->addPoints($dateParam, "dateParam");
     $MyData->setSerieDescription("dateParam", "Dias");
     $MyData->setAbscissa("dateParam");
     // 		$MyData->drawAll();
     /* Create the per bar palette */
     $Palette = array("0" => array("R" => 188, "G" => 224, "B" => 46, "Alpha" => 80), "1" => array("R" => 143, "G" => 189, "B" => 216, "Alpha" => 80), "2" => array("R" => 239, "G" => 210, "B" => 121, "Alpha" => 80), "3" => array("R" => 122, "G" => 224, "B" => 146, "Alpha" => 80), "4" => array("R" => 224, "G" => 100, "B" => 46, "Alpha" => 80), "5" => array("R" => 46, "G" => 151, "B" => 224, "Alpha" => 80), "6" => array("R" => 137, "G" => 154, "B" => 173, "Alpha" => 80), "7" => array("R" => 76, "G" => 136, "B" => 190, "Alpha" => 80), "8" => array("R" => 229, "G" => 11, "B" => 11, "Alpha" => 80));
     // 		$MyData->normalize(100,"%");
     $xLenght = "220";
     /* Create the pChart object */
     $myPicture = new pImage(700, $xLenght, $MyData, TRUE);
     /* Draw serie 1 in red with a 80% opacity */
     $MyData->setPalette(array($concepto), $Palette[$grapColor]);
     $Settings = array("R" => 200, "G" => 200, "B" => 200, "StartR" => 250, "StartG" => 250, "StartB" => 250, "EndR" => 255, "EndG" => 255, "EndB" => 255, "Alpha" => 0);
     $Settings = array("R" => 255, "G" => 255, "B" => 255, "StartR" => 255, "StartG" => 255, "StartB" => 255, "EndR" => 255, "EndG" => 255, "EndB" => 255, "Alpha" => 0);
     //$myPicture->drawRectangle(0,0,699,229,array("R"=>200,"G"=>200,"B"=>200));
     $myPicture->drawFilledRectangle(0, 0, 700, $xLenght + 10, $Settings);
     /* Overlay with a gradient */
     $myPicture->drawGradientArea(0, 0, 700, $xLenght + 10, DIRECTION_VERTICAL, $Settings);
     /* Write the chart title */
     $myPicture->setFontProperties(array("FontName" => $fontFolder . "Forgotte.ttf", "FontSize" => 10));
     /* Draw some thresholds */
     // 		$myPicture->setShadow(FALSE);
     // 		$myPicture->drawThreshold(-40,array("WriteCaption"=>TRUE,"R"=>0,"G"=>0,"B"=>0,"Ticks"=>4));
     // 		$myPicture->drawThreshold($maxValue,array("WriteCaption"=>TRUE,"R"=>0,"G"=>0,"B"=>0,"Ticks"=>4));
     //TODO->Define if mensual or annual
     if (isset($month_name) and isset($area_name)) {
         if (trim($area_name) === 'Tijuana') {
             $area = 'Mexicali';
         } else {
             $area = $area_name;
         }
         $myPicture->drawText(350, 30, ucfirst($concepto) . "-" . $area . "-" . $month[$month_name]['spanish'] . "-" . $year, array("FontSize" => 14, "Align" => TEXT_ALIGN_BOTTOMMIDDLE));
         //Diario
     }
     if (!isset($month_name) and !isset($area_name)) {
         $myPicture->drawText(350, 30, ucfirst($concepto) . "-" . $empresas[$id_empresa] . "-" . $year, array("FontSize" => 14, "Align" => TEXT_ALIGN_BOTTOMMIDDLE));
         //Annual
     }
     if (!isset($month_name) and isset($area_name)) {
         if (trim($area_name) === 'Tijuana') {
             $area = 'Mexicali';
         } else {
             $area = $area_name;
         }
         $myPicture->drawText(350, 30, ucfirst($concepto) . "-" . $area . "-" . $year, array("FontSize" => 14, "Align" => TEXT_ALIGN_BOTTOMMIDDLE));
         //areaAnnual
     }
     if (isset($month_name) and !isset($area_name)) {
         $myPicture->drawText(350, 30, ucfirst($concepto) . "-" . $empresas[$id_empresa] . "-" . $month[$month_name]['spanish'] . "-" . $year, array("FontSize" => 14, "Align" => TEXT_ALIGN_BOTTOMMIDDLE));
         //areaAnnual
     }
     /* Define the 2nd chart area */
     $myPicture->setGraphArea(60, 35, 660, 200);
     $myPicture->setFontProperties(array("FontName" => $fontFolder . "pf_arma_five.ttf", "FontSize" => 6));
     /* Draw the scale */
     $scaleSettings = array("DrawSubTicks" => TRUE, "CycleBackground" => TRUE, "GridR" => 0, "GridG" => 0, "GridB" => 0, "GridAlpha" => 10, "RemoveXAxis" => FALSE, "Mode" => SCALE_MODE_ADDALL_START0, "DrawArrows" => TRUE, "ArrowSize" => 6);
     $myPicture->drawScale($scaleSettings);
     $myPicture->drawBarChart(array("DisplayPos" => LABEL_POS_INSIDE, "DisplayValues" => FALSE, "Rounded" => FALSE, "Surrounding" => 15, "InnerSurrounding" => 15));
     //TODO->Define if mensual or annual
     if (isset($month_name) and isset($area_name)) {
         $myPicture->autoOutput($url . "{$concepto}" . "_" . "{$area_name}" . "_" . "{$month_name}" . "_" . $year . ".png");
         //Diario
     }
     if (!isset($month_name) and !isset($area_name)) {
         $myPicture->autoOutput($url . $concepto . "_" . strtolower($empresas[$id_empresa]) . "_" . $year . ".png");
         //Annual
     }
     if (!isset($month_name) and isset($area_name)) {
         $myPicture->autoOutput($url . "{$concepto}" . "_" . $area_name . "_" . $year . ".png");
         //areaAnnual
     }
     if (isset($month_name) and !isset($area_name)) {
         $myPicture->autoOutput($url . $concepto . "_" . strtolower($empresas[$id_empresa]) . "_" . $month_name . "_" . $year . ".png");
         //areaAnnual
     }
 }