public function actionConsultar($id=null)
{
$model = new Incidencia();
$mname=null;
$val=$id;
$mname= \app\models\Municipio::findOne($val);
$mname=$mname->municipiog;
$mes=date("n")-1;
//arreglos auxiliares para recorrer los diferens de delitos
$arr=array('in','v', 'h', 'n', 's', 'rc', 'rn', 'rt', 'rv',);
$arrmes=array('ENE', 'FEB', 'MAR', 'ABR', 'MAY', 'JUN', 'JUL', 'AGO', 'SEP', 'OCT', 'NOV', 'DIC',);
$mes_string=$arrmes[$mes-1];
$sqlpd='select modalidad.modalidad, tipo.tipo, subtipo.subTipo, sum('.strtolower($mes_string).') as '.strtolower($mes_string).' from seisp.incidencia INNER JOIN seisp.modalidad ON incidencia.modalidad_id=modalidad.id INNER JOIN seisp.tipo ON incidencia.tipo_id=tipo.id INNER JOIN seisp.subtipo ON incidencia.subtipo_id=subtipo.id where municipio_id=:munchen and anio_id=6 and '.strtolower($mes_string).'>0 group by subtipo ORDER BY '.strtolower($mes_string).' ASC';
$sql='select anio_id, SUM(ene) as ENE ,sum(feb) as FEB, sum(mar) as MAR,sum(abr) as ABR, sum(may) as MAY, sum(jun) as JUN, sum(jul) as JUL, sum(ago) as AGO, sum(sep) as SEP, sum(oct) as OCT, sum(nov) as NOV, sum(dic) as DIC from seisp.incidencia where municipio_id=:munchen and anio_id>2 group by anio_id asc';
$sqlvio='select anio_id, SUM(ene) as ENE ,sum(feb) as FEB, sum(mar) as MAR,sum(abr) as ABR, sum(may) as MAY, sum(jun) as JUN, sum(jul) as JUL, sum(ago) as AGO, sum(sep) as SEP, sum(oct) as OCT, sum(nov) as NOV, sum(dic) as DIC from seisp.incidencia where municipio_id=:munchen and modalidad_id=2 and anio_id>2 group by anio_id asc';
$sqlhd='select anio_id, SUM(ene) as ENE ,sum(feb) as FEB, sum(mar) as MAR,sum(abr) as ABR, sum(may) as MAY, sum(jun) as JUN, sum(jul) as JUL, sum(ago) as AGO, sum(sep) as SEP, sum(oct) as OCT, sum(nov) as NOV, sum(dic) as DIC from seisp.incidencia where municipio_id=:munchen and modalidad_id=3 and tipo_id=10 and anio_id>2 group by anio_id asc';
$sqlnm='select anio_id, SUM(ene) as ENE ,sum(feb) as FEB, sum(mar) as MAR,sum(abr) as ABR, sum(may) as MAY, sum(jun) as JUN, sum(jul) as JUL, sum(ago) as AGO, sum(sep) as SEP, sum(oct) as OCT, sum(nov) as NOV, sum(dic) as DIC from seisp.narcomenudeo where municipio_id=:munchen and anio_id>2 group by anio_id asc';
$sqlsec='select anio_id, SUM(ene) as ENE ,sum(feb) as FEB, sum(mar) as MAR,sum(abr) as ABR, sum(may) as MAY, sum(jun) as JUN, sum(jul) as JUL, sum(ago) as AGO, sum(sep) as SEP, sum(oct) as OCT, sum(nov) as NOV, sum(dic) as DIC from seisp.incidencia where municipio_id=:munchen and modalidad_id=6 and anio_id>2 group by anio_id asc';
$sqlrch='select anio_id, SUM(ene) as ENE ,sum(feb) as FEB, sum(mar) as MAR,sum(abr) as ABR, sum(may) as MAY, sum(jun) as JUN, sum(jul) as JUL, sum(ago) as AGO, sum(sep) as SEP, sum(oct) as OCT, sum(nov) as NOV, sum(dic) as DIC from seisp.incidencia where municipio_id=:munchen and subtipo_id=6 and anio_id>2 group by anio_id asc';
$sqlran='select anio_id, SUM(ene) as ENE ,sum(feb) as FEB, sum(mar) as MAR,sum(abr) as ABR, sum(may) as MAY, sum(jun) as JUN, sum(jul) as JUL, sum(ago) as AGO, sum(sep) as SEP, sum(oct) as OCT, sum(nov) as NOV, sum(dic) as DIC from seisp.incidencia where municipio_id=:munchen and subtipo_id=8 and anio_id>2 group by anio_id asc';
$sqlrat='select anio_id, SUM(ene) as ENE ,sum(feb) as FEB, sum(mar) as MAR,sum(abr) as ABR, sum(may) as MAY, sum(jun) as JUN, sum(jul) as JUL, sum(ago) as AGO, sum(sep) as SEP, sum(oct) as OCT, sum(nov) as NOV, sum(dic) as DIC from seisp.incidencia where municipio_id=:munchen and subtipo_id=9 and anio_id>2 group by anio_id asc';
$sqlrdv='select anio_id, SUM(ene) as ENE ,sum(feb) as FEB, sum(mar) as MAR,sum(abr) as ABR, sum(may) as MAY, sum(jun) as JUN, sum(jul) as JUL, sum(ago) as AGO, sum(sep) as SEP, sum(oct) as OCT, sum(nov) as NOV, sum(dic) as DIC from seisp.incidencia where municipio_id=:munchen and subtipo_id=19 and anio_id>2 group by anio_id asc';
$in=Incidencia::findBySql($sql,[':munchen'=>$val])->asArray()->all();
$v=Incidencia::findBySql($sqlvio,[':munchen'=>$val])->asArray()->all();
$h=Incidencia::findBySql($sqlhd,[':munchen'=>$val])->asArray()->all();
$n=\app\models\Narcomenudeo::findBySql($sqlnm,[':munchen'=>$val])->asArray()->all();
$s=Incidencia::findBySql($sqlsec,[':munchen'=>$val])->asArray()->all();
$rc=Incidencia::findBySql($sqlrch,[':munchen'=>$val])->asArray()->all();
$rn=Incidencia::findBySql($sqlran,[':munchen'=>$val])->asArray()->all();
$rt=Incidencia::findBySql($sqlrat,[':munchen'=>$val])->asArray()->all();
$rv=Incidencia::findBySql($sqlrdv,[':munchen'=>$val])->asArray()->all();
for ($x=0; $x < count($arr) ; $x++) {
$daux=$arr[$x];
for ($i=0; $i < count(${$daux}); $i++) {
unset(${$daux}[$i]['anio_id']);
if ($i==3) {
for ($y=$mes; $y <count($arrmes); $y++) {
$maux=$arrmes[$y];
unset(${$daux}[3][$maux]);
}
}
${$daux.$i}= array_map( create_function('$value', 'return (int)$value;'), ${$daux}[$i]);
${'sum'.$daux.$i}=0;
for ($y=0; $y < $mes ; $y++) {
$maux=$arrmes[$y];
${'sum'.$daux.$i}+=${$daux.$i}[$maux];
}
}
${'dif'.$daux}=${'sum'.$daux.'3'}-${'sum'.$daux.'2'};
}
$array_periodo=array('ENE', 'ENE-FEB', 'ENE-MAR', 'ENE-ABR', 'ENE-MAY', 'ENE-JUN', 'ENE-JUL', 'ENE-AGO', 'ENE-SEP', 'ENE-OCT', 'ENE-NOV', 'ENE-DIC',);
$periodo=$array_periodo[$mes-1];
return $this -> actionGenerar($mname, $mes,
$periodo, $in0, $in1, $in2, $in3, $v0, $v1, $v2, $v3,$h0, $h1, $h2, $h3, $n0, $n1, $n2, $n3, $s0, $s1, $s2, $s3, $rc0, $rc1, $rc2, $rc3, $rn0, $rn1, $rn2, $rn3, $rt0, $rt1, $rt2, $rt3, $rv0, $rv1, $rv2, $rv3, $sumin2, $sumin3, $sumv2, $sumv3, $sumh2, $sumh3, $sumn2, $sumn3, $sums2, $sums3, $sumrc2, $sumrc3, $sumrn2, $sumrn3, $sumrt2, $sumrt3, $sumrv2, $sumrv3, $difin, $difv, $difh, $difn, $difs, $difrc, $difrn, $difrt, $difrv);
}