TransWar File Browser

Path: C:\

<?php
ini_set('max_execution_time',259200); 
ini_set ('memory_limit','-1');
require_once("API07_MobileRestHandler.php");
date_default_timezone_set('America/Sao_Paulo');
$final    = date("d/m/Y"); 
$dtlimite = date("Ymd"); 
$base1    = date("d-m-Y"); 
$inicio   = date('d/m/Y', strtotime($base1. ' - 1 week'));
$coleta   = date('d/m/Y', strtotime($base1. ' - 1 month'));
$grupo    = $_SESSION['grupo'];
$ds_grupo = $_SESSION['dsgru'];
$empresa  = $_SESSION['empresa'];
$ano1=substr($inicio, 6);
$mes1=substr($inicio, 3,-5);
$dia1=substr($inicio, 0,-8);
$data1=$ano1.$mes1.$dia1;
$ano2=substr($final, 6);
$mes2=substr($final, 3,-5);
$dia2=substr($final, 0,-8);
$data2=$ano2.$mes2.$dia2;
$ano3=substr($coleta, 6);
$mes3=substr($coleta, 3,-5);
$dia3=substr($coleta, 0,-8);
$data3=$ano3.$mes3.$dia3;
$mobileRestHandler = new MobileRestHandler();
$linha = $mobileRestHandler->getMobile($data1, $data2, $data3, $grupo, $ds_grupo, $empresa);
$lin=count($linha);
if (isset($linha['error']))
{ $erro=$linha['error'];}
else
{ $erro='';
$nf='n';
for ($q=0; $q <= 150; $q++) {$tot_entrega[$q]=$tot_entregaA[$q]=$tot_entregaB[$q]=0;$tot_coleta[$q]=0;$tot[$q]=0;} 
$matriz    = $_SESSION['matriz'];
$principal = json_decode($matriz, true);
$oc=count($principal);
$x1=0;for ($x=0;$x<$oc;$x++)
{ if($principal[$x]['cor']=='black')
  { $x1++;$black[$x1]=$principal[$x]['id'];}
}$x1++;$black[$x1]=108;
$x3=0;for ($x=0;$x<$oc;$x++)
{ if($principal[$x]['cor']=='green')
  { $x3++;$green[$x3]=$principal[$x]['id'];}
}
$z=1;
for ($q=1; $q <= $lin; $q++) 
{ $ind=intval($linha[$q][25]);	//pega o ID da ocorrência
  $stop=0;for($i=1;$i<$x1;$i++){if($ind==$black[$i]){$stop=1;}}
  if($stop==0)
  { $finaliz=0;if ($ind==34 or $ind==35){$finaliz=1;}else{for($i=1;$i<$x3;$i++){if($ind==$green[$i]){$finaliz=1;}}}
    if ($finaliz==1)
    { $nf='s';
  		if ($linha[$q][35]>=$data2)
    	{	if ($linha[$q][7]=='COLETA')
    		{	
          if($linha[$q][26]=='COLETADA (SEM OCORRÊNCIA)'){$linha[$q][26]='SERVIÇO REALIZADO NORMALMENTE';}
    			$oco_coleta[$ind]=$linha[$q][26];
      		$tot_coleta[$ind]++;
    		}
    		else
      	{	$oco_entrega[$ind]=$linha[$q][26];
          if($linha[$q][41]=='S')
          { $tot_entregaA[$ind]++;}
          else
          { $tot_entregaB[$ind]++;}
      	}
      }
    }
    else
    {	if ($linha[$q][7]=='ENTREGA')
			{ if ($q>=2){if ($linha[$q][9]<>$linha[$q-1][9]){$nf='n';}}
				if ($q==$lin)
				{	if ($nf=='n')
    			{	
    				$oco_entrega[$ind]=$linha[$q][26];
            if($linha[$q][41]=='S')
            { $tot_entregaA[$ind]++;}
            else
            { $tot_entregaB[$ind]++;}
            if ($ind==107){$colL=strtotime('now')-strtotime($linha[$q][35].' '.$linha[$q][28]);if($colL>=3600){$tot[$ind]++;}}
        	}
				}
				else
				{	if ($linha[$q][9]<>($linha[$q+1][9]))
		      { if ($nf=='n')
		    		{	
		    			$oco_entrega[$ind]=$linha[$q][26];
              if($linha[$q][41]=='S')
              { $tot_entregaA[$ind]++;}
              else
              { $tot_entregaB[$ind]++;}
              if ($ind==107){$colL=strtotime('now')-strtotime($linha[$q][35].' '.$linha[$q][28]);if($colL>=3600){$tot[$ind]++;}}
		        }
		        else
		        { 
		          $nf='n';
		        }
		      }
	    	}
	    }
	    else
	    {	if ($ind<>69)
	    	{	if ($q>1){if ($linha[$q][12]<>$linha[$q-1][12]){$nf='n';}}
					if ($q==$lin)
					{	if ($nf=='n')
	    			{	if ($ind==146 or $ind==149)
              { $ano4=substr($linha[$q][30], 6);
                $mes4=substr($linha[$q][30], 3,-5);
                $dia4=substr($linha[$q][30], 0,-8);
                $data4=$ano4.$mes4.$dia4;
                if($dtlimite>=$data4){$tot[$ind]++;}
              }
              if ($linha[$q][32]=='S' and $linha[$q][35]<>$data2)
              { $linha[$q][26]='SERVIÇO REALIZADO NORMALMENTE';$linha[$q][25]='32';$ind=32;
                if ($linha[$q][35]>=$data2)
                {
                  $oco_coleta[$ind]=$linha[$q][26];
                  $tot_coleta[$ind]++;
                }
              }
              else
              {
                $oco_coleta[$ind]=$linha[$q][26];
                $tot_coleta[$ind]++;
              }
	        	}
					}
					else
					{	if ($linha[$q][12]<>($linha[$q+1][12]))
			      { $nf='n';
              if ($ind==146 or $ind==149)
              { $ano4=substr($linha[$q][30], 6);
                $mes4=substr($linha[$q][30], 3,-5);
                $dia4=substr($linha[$q][30], 0,-8);
                $data4=$ano4.$mes4.$dia4;
                if($dtlimite>=$data4){$tot[$ind]++;}
              }
              if ($linha[$q][32]=='S' and $linha[$q][35]<>$data2)
              { $linha[$q][26]='SERVIÇO REALIZADO NORMALMENTE';$linha[$q][25]='32';$ind=32;
                if ($linha[$q][35]>=$data2)
                {
                  $oco_coleta[$ind]=$linha[$q][26];
                  $tot_coleta[$ind]++;
                }
              }
              else
              {
                $oco_coleta[$ind]=$linha[$q][26];
                $tot_coleta[$ind]++;
              }
			      }
			    }
				}
	    }
    }
    $linha2[$z]=$linha[$q];$z++;
  }
}
$rows_entrega='{
  "cols": [
        {"id":"","label":"Tôpico","pattern":"","type":"string"},
        {"id":"","label":"Fatia","pattern":"","type":"number"},
        {"id":"","label":"Ocorrência","pattern":"","type":"number"},
        {"id":"","label":"Alerta","pattern":"","type":"number"}
      ],'.PHP_EOL.'"rows": ['.PHP_EOL;$b=0;
for ($q=0; $q <= 150; $q++) 
{ if ($tot_entregaA[$q]<>0 or $tot_entregaB[$q]<>0)
  { if ($b==1){$rows_entrega=$rows_entrega.','.PHP_EOL;}
    $rows_entrega=$rows_entrega.' {"c":[{"v":"'.$oco_entrega[$q].'","f":null},{"v":'.($tot_entregaA[$q]+$tot_entregaB[$q]).',"f":null},{"v":'.$q.',"f":null},{"v":'.$tot[$q].',"f":null}]}';$b=1;
  }
}$rows_entrega=$rows_entrega.PHP_EOL.']'.PHP_EOL.'}'.PHP_EOL;

$rows_entregaA='{
  "cols": [
        {"id":"","label":"Tôpico","pattern":"","type":"string"},
        {"id":"","label":"Fatia","pattern":"","type":"number"},
        {"id":"","label":"Ocorrência","pattern":"","type":"number"},
        {"id":"","label":"Alerta","pattern":"","type":"number"}
      ],'.PHP_EOL.'"rows": ['.PHP_EOL;$b=0;
for ($q=0; $q <= 150; $q++) 
{ if ($tot_entregaA[$q]<>0)
  { if ($b==1){$rows_entregaA=$rows_entregaA.','.PHP_EOL;}
    $rows_entregaA=$rows_entregaA.' {"c":[{"v":"'.$oco_entrega[$q].'","f":null},{"v":'.$tot_entregaA[$q].',"f":null},{"v":'.$q.',"f":null},{"v":'.$tot[$q].',"f":null}]}';$b=1;
  }
}$rows_entregaA=$rows_entregaA.PHP_EOL.']'.PHP_EOL.'}'.PHP_EOL;

$rows_entregaB='{
  "cols": [
        {"id":"","label":"Tôpico","pattern":"","type":"string"},
        {"id":"","label":"Fatia","pattern":"","type":"number"},
        {"id":"","label":"Ocorrência","pattern":"","type":"number"},
        {"id":"","label":"Alerta","pattern":"","type":"number"}
      ],'.PHP_EOL.'"rows": ['.PHP_EOL;$b=0;
for ($q=0; $q <= 150; $q++) 
{ if ($tot_entregaB[$q]<>0)
  { if ($b==1){$rows_entregaB=$rows_entregaB.','.PHP_EOL;}
    $rows_entregaB=$rows_entregaB.' {"c":[{"v":"'.$oco_entrega[$q].'","f":null},{"v":'.$tot_entregaB[$q].',"f":null},{"v":'.$q.',"f":null},{"v":'.$tot[$q].',"f":null}]}';$b=1;
  }
}$rows_entregaB=$rows_entregaB.PHP_EOL.']'.PHP_EOL.'}'.PHP_EOL;

$rows_coleta='{
  "cols": [
        {"id":"","label":"Tôpico","pattern":"","type":"string"},
        {"id":"","label":"Fatia","pattern":"","type":"number"},
        {"id":"","label":"Ocorrência","pattern":"","type":"number"},
        {"id":"","label":"Alerta","pattern":"","type":"number"}
      ],'.PHP_EOL.'"rows": ['.PHP_EOL;$b=0;
for ($q=0; $q <= 150; $q++) 
{ if ($tot_coleta[$q]<>0)
  { if ($b==1){$rows_coleta=$rows_coleta.','.PHP_EOL;}
    $rows_coleta=$rows_coleta.' {"c":[{"v":"'.$oco_coleta[$q].'","f":null},{"v":'.$tot_coleta[$q].',"f":null},{"v":'.$q.',"f":null},{"v":'.$tot[$q].',"f":null}]}';$b=1;
  }
}$rows_coleta=$rows_coleta.PHP_EOL.']'.PHP_EOL.'}'.PHP_EOL;

$json = json_encode($linha2); // Isto ira converter a array em json
$_SESSION['json']     =$json;
$_SESSION['coleta']   =$rows_coleta;
$_SESSION['entrega']  =$rows_entrega;
$_SESSION['entregaA'] =$rows_entregaA;
$_SESSION['entregaB'] =$rows_entregaB;
$_SESSION['inicio']   =$inicio;
$_SESSION['final']    =$final;
}
?>