TransWar File Browser

Path: C:\

<?php
ini_set('max_execution_time',259200); 
ini_set ('memory_limit','1536M');
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 month'));
$grupo='17';$ds_grupo="CRODA";
$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;
$mobileRestHandler = new MobileRestHandler();
$linha = $mobileRestHandler->getMobile($data1, $data2, $grupo, $ds_grupo);
$lin=count($linha);
$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 = file_get_contents('upload/matriz.json');
$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'];}
}

$custo1=$_SESSION['custo1'];
$custo2=$_SESSION['custo2'];
$custo3=$_SESSION['custo3'];
$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)
  { $stop=1;
    if(($custo1==1and$linha[$q][39]==171)or($custo2==1and$linha[$q][39]==169)or($custo3==1and$linha[$q][39]==170)or($linha[$q][7]=='COLETA')or($linha[$q][39]===null))
      {$stop=0;}
  }
  if($stop==0)
  { $linha2[$z]=$linha[$q];$z++;
    $finaliz=0;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 ($linha[$q][32]=='S' and $linha[$q][35]<>$data2){$linha[$q][26]='SERVIÇO REALIZADO NORMALMENTE';$linha[$q][25]='32';$ind=32;}
	    				$oco_coleta[$ind]=$linha[$q][26];
		        	$tot_coleta[$ind]++;
              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]++;}
                }
	        	}
					}
					else
					{	if ($linha[$q][12]<>($linha[$q+1][12]))
			      { if ($linha[$q][32]=='S' and $linha[$q][35]<>$data2){$linha[$q][26]='SERVIÇO REALIZADO NORMALMENTE';$linha[$q][25]='32';$ind=32;}	
			    		$oco_coleta[$ind]=$linha[$q][26];
				      $tot_coleta[$ind]++;
              $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]++;}
                }
			      }
			    }
				}
	    }
    }
  }
}
$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;
?>