<?php
 require_once('../../../includes/load.php');

 $convert_utf8 = function ($s) {
         if (!mb_check_encoding($s, 'UTF-8')) {
             $s = utf8_encode($s);
         }
         return $s;
     };
$placa=$_REQUEST['placa'];
$anio=$_REQUEST['anio'];
$mes=$_REQUEST['mes'];

$rs= $db->query("SELECT cso.costo_mensual1, cgp.costo_mensual3, ctr.costo_mensual5, cd.costo_mensual2, cct.costokm, csoo.total as totalSueldoO, cie.costo_mensual4,cso.placa1,cgp.placa3,ctr.placa5,cd.placa2,cct.placa6,csoo.placa7,cie.placa4 FROM tb_configuracion_soat cso LEFT JOIN tb_configuracion_gps cgp ON cso.placa1 = cgp.placa3 LEFT JOIN tb_configuracion_revisiontecnica ctr ON cso.placa1 = ctr.placa5 LEFT JOIN tb_configuracion_depreciacion cd ON cso.placa1 = cd.placa2 LEFT JOIN tb_configuracion_costoneumatico cct ON cso.placa1 = cct.placa6 LEFT JOIN tb_configuracion_sueldooperaciones csoo ON cso.placa1 = csoo.placa7 LEFT JOIN tb_configuracion_impvehicular cie ON cso.placa1 = cie.placa4 WHERE cso.placa1 = '$placa' OR cgp.placa3 = '$placa' OR ctr.placa5 = '$placa' OR cd.placa2 = '$placa' OR cct.placa6 = '$placa' OR csoo.placa7 = '$placa' OR cie.placa4 = '$placa' ORDER BY cso.id DESC, cgp.id DESC, ctr.id DESC, cd.id DESC, cct.id DESC, csoo.id DESC, cie.id DESC LIMIT 1"); 

$rs2= $db->query("SELECT id,sctr,resultado AS gastoA FROM tb_configuracion_sueldo ORDER BY id DESC LIMIT 1 ");
$rs3= $db->query("SELECT id,total AS gastoSerP FROM tb_configuracion_sp ORDER BY id DESC LIMIT 1 ");
$rs4= $db->query("SELECT id, resultado AS GastoDepre FROM tb_configuracion_odepreciacion ORDER BY id DESC LIMIT 1 ");
$rs5= $db->query("SELECT id, total AS GastoUO FROM tb_configuracion_uo ORDER BY id DESC LIMIT 1 ");
$rs6= $db->query("SELECT id, total AS GastoEPPS FROM tb_configuracion_epps ORDER BY id DESC LIMIT 1 ");
$rs7= $db->query("SELECT id, total AS GastoAS FROM tb_configuracion_as ORDER BY id DESC LIMIT 1 ");
$rs8= $db->query("SELECT SUM(KM_FINAL) as KM_FINAL, SUM(KM_INICIAL) as KM_INICIAL from det_veh where mes = $mes and anio = $anio and ID_VEHICULO='$placa'");
$rs9= $db->query("SELECT NOMB_VEHIC, MODELO_VEHIC, COD_ACTIVO, PLACA, anio, num_motor, mtto_prevkm, mes_propiokm, rend_combkm FROM vehiculo WHERE PLACA = '$placa'");
$rs10=$db->query("SELECT anio AS anioM, mes AS mesM, placa FROM tb_maestra WHERE mes = $mes and anio = $anio and placa='$placa'");
$data = array();
 

while( $rows = mysqli_fetch_assoc($rs) ) {
        $data = array_map($convert_utf8, $rows);     
}
while ($rows2 = mysqli_fetch_assoc($rs2)) {
    $data = array_merge($data, $rows2);
}
while ($rows3 = mysqli_fetch_assoc($rs3)) {
    $data = array_merge($data, $rows3);
}
while ($rows4 = mysqli_fetch_assoc($rs4)) {
    $data = array_merge($data, $rows4);
}
while ($rows5 = mysqli_fetch_assoc($rs5)) {
    $data = array_merge($data, $rows5);
}
while ($rows6 = mysqli_fetch_assoc($rs6)) {
    $data = array_merge($data, $rows6);
}
while ($rows7 = mysqli_fetch_assoc($rs7)) {
    $data = array_merge($data, $rows7);
}
while ($rows8 = mysqli_fetch_assoc($rs8)) {
    $data = array_merge($data, $rows8);
}
while ($rows9 = mysqli_fetch_assoc($rs9)) {
    $data = array_merge($data, $rows9);
}
while ($rows10 = mysqli_fetch_assoc($rs10)) {
    $data = array_merge($data, $rows10);
}
 echo json_encode($data, JSON_UNESCAPED_UNICODE);
?>
