<?php
include_once('../../../php/sessionStart.php');
include_once('../../../php/db/dbExec.php');
include_once('../../../php/functions.php');
include_once('../../../php/timezone.php');
include_once('../../../php/privileges.php');
include_once('../../../php/maxExecTime.php');

$bitForm = "nom1020";
$bitMod = "nom";
$empCod = $_SESSION['empCod'];
$usuCod = utf8_decode($_SESSION['usuCod']);
$usuNom = utf8_decode($_SESSION['usuNom']);

switch ($_POST['action']) {
	case 'consultarPla':
		echo consultarPla();
		break;
	case 'consultarNp':
		echo consultarNp();
		break;

	case 'consultarEmple':
		echo consultarEmple();
		break;

	case 'guardar':
		echo guardar();
		break;

	case 'guardarAg':
		echo guardarAg();
		break;

	case 'borrar':
		echo borrar();
		break;

	case 'borrarReg':
		echo borrarReg();
		break;

}

function consultarPla() {
	global $empCod, $usuNom;

	$priv = new privileges();
	if (!$priv->consult($_SESSION['usuPriv'])) {
		return json_encode($priv->rErrorConsult());
	}

	$func = new functions();

	$numNum=$_POST['numNum'];

	# QUERYS

	$sNomper = "SELECT np.*, TRIM(mae.mae_nom) AS mae_nom, TRIM(mae.mae_ape) AS mae_ape,
				TRIM(tpu.tpu_nom) AS tpu_nom 
				FROM nomper np
 				LEFT JOIN maestro mae ON np.np_emp=mae.mae_emp AND np.np_cod = mae.mae_cod 
 				LEFT JOIN tpuesto tpu ON mae.mae_tpue = tpu.tpu_cod 
				WHERE np_emp='$empCod' AND np_numpla='$numNum'";

	$sPlani = "SELECT * 
              FROM ctrpla  
              WHERE ctrp_emp='$empCod' AND ctrp_num='$numNum'";

	# EJECUCION DE QUERYS
	$db = new dbExec();
	$resp["nomper"] = $db->sFetchAll($sNomper);
	$resp["ctrpla"] = $db->sFetchAssoc($sPlani);;
	$db->close();

	$func = new functions();
	return $func->jsonEncodeArray($resp, 'nomper');
}

function consultarNp() {
	global $empCod, $usuNom;

	$func = new functions();

	$numNum=$_POST['numNum'];
	$numCod=$_POST['numCod'];

	# QUERYS

	$sNomper = "SELECT *, TRIM(mae.mae_nom) AS mae_nom, TRIM(mae.mae_ape) AS mae_ape,
				TRIM(tpu.tpu_nom) AS tpu_nom
				FROM nomper np
 				LEFT JOIN maestro mae ON np.np_emp=mae.mae_emp and np.np_cod = mae.mae_cod 
 				LEFT JOIN tpuesto tpu ON mae.mae_tpue = tpu.tpu_cod 
				WHERE np_emp='$empCod' AND np_numpla='$numNum' AND np_cod='$numCod'";

	# EJECUCION DE QUERYS
	$db = new dbExec();
	$resp["nomper"] = $db->sFetchAssoc($sNomper);
	$db->close();

	$func = new functions();
	return $func->jsonEncodeArray($resp, 'nomper');
}

function consultarEmple() {
	global $empCod, $usuNom;

	$func = new functions();

	$numNum=$_POST['numNum'];
	$numCoddag=$_POST['numCoddag'];

	# QUERYS

	$sMaestro = "SELECT *, TRIM(mae.mae_nom) AS mae_nom, TRIM(mae.mae_ape) AS mae_ape,
				TRIM(tpu.tpu_nom) AS tpu_nom
				FROM maestro mae
 				LEFT JOIN tpuesto tpu ON mae.mae_tpue = tpu.tpu_cod 
				WHERE mae_emp ='$empCod' AND mae_cod='$numCoddag'";

	$sNomper = "SELECT *
				FROM nomper
				WHERE np_emp ='$empCod' AND np_numpla='$numNum' AND np_cod='$numCoddag'";

	# EJECUCION DE QUERYS
	$db = new dbExec();
	$resp = $db->sEx($sNomper, "nomper");
	$resp["maestro"] = $db->sFetchAssoc($sMaestro);
	$db->close();

	$func = new functions();
	return $func->jsonEncodeArray($resp, 'nomper', 'maestro');
}


function guardar() {
	global $empCod, $usuNom, $bitMod, $bitForm;

	$priv = new privileges();
	if (!$priv->modify($_SESSION['usuPriv'])) {
		return json_encode($priv->rErrorModify());
	}

	$func = new functions();

	$numNum=$_POST['numNum'];
	$numdoc=$_POST['numNum'];
	$numCod=$_POST['numCod'];
	$numDtra=(empty($_POST['numDtra'])) ? 0 : $_POST['numDtra'];
	$numDsusi=(empty($_POST['numDsusi'])) ? 0 : $_POST['numDsusi'];
	$numDvaca=(empty($_POST['numDvaca'])) ? 0 : $_POST['numDvaca'];
	$numHsim=(empty($_POST['numHsim'])) ? 0 : $_POST['numHsim'];
	$numHdob=(empty($_POST['numHdob'])) ? 0 : $_POST['numHdob'];
	$numSord=(empty($_POST['numSord'])) ? 0 : $_POST['numSord'];
	$numSord=(empty($_POST['numSord'])) ? 0 : $_POST['numSord'];
	$numBoni=(empty($_POST['numBoni'])) ? 0 : $_POST['numBoni'];
	$numSexts=(empty($_POST['numSexts'])) ? 0 : $_POST['numSexts'];
	$numSextd=(empty($_POST['numSextd'])) ? 0 : $_POST['numSextd'];
    $numSext=$numSexts+$numSextd;
	$numBonii=(empty($_POST['numBonii'])) ? 0 : $_POST['numBonii'];
	$numBonoe=(empty($_POST['numBonoe'])) ? 0 : $_POST['numBonoe'];
	$numDepre=(empty($_POST['numDepre'])) ? 0 : $_POST['numDepre'];
	$numViati=(empty($_POST['numViati'])) ? 0 : $_POST['numViati'];
	$numComi=(empty($_POST['numComi'])) ? 0 : $_POST['numComi'];
	$numOtrp=(empty($_POST['numOtrp'])) ? 0 : $_POST['numOtrp'];
	$numTotdev=(empty($_POST['numTotdev'])) ? 0 : $_POST['numTotdev'];
	$numIgss=(empty($_POST['numIgss'])) ? 0 : $_POST['numIgss'];
	$numIsr=(empty($_POST['numIsr'])) ? 0 : $_POST['numIsr'];
	$numAnti=(empty($_POST['numAnti'])) ? 0 : $_POST['numAnti'];
	$numUnif=(empty($_POST['numUnif'])) ? 0 : $_POST['numUnif'];
	$numLent=(empty($_POST['numLent'])) ? 0 : $_POST['numLent'];
	$numPreb=(empty($_POST['numPreb'])) ? 0 : $_POST['numPreb'];
	$numPree=(empty($_POST['numPree'])) ? 0 : $_POST['numPree'];
	$numDesj=(empty($_POST['numDesj'])) ? 0 : $_POST['numDesj'];
	$numDescv=(empty($_POST['numDescv'])) ? 0 : $_POST['numDescv'];
	$numTotdes=(empty($_POST['numTotdes'])) ? 0 : $_POST['numTotdes'];
	$numLiqrec=(empty($_POST['numLiqrec'])) ? 0 : $_POST['numLiqrec'];
	# QUERYS PARA UN REGISTRO

	$uNomper="UPDATE nomper SET np_dtra='$numDtra', np_dsusi='$numDsusi', np_dvaca='$numDvaca', np_hsim='$numHsim', np_hdob='$numHdob', np_sord='$numSord', np_boni='$numBoni', np_sexts='$numSexts', np_sextd='$numSextd', np_sext='$numSext', np_bonii='$numBonii', np_bonoe='$numBonoe', np_depre='$numDepre', np_viati='$numViati', np_comi='$numComi', np_otrp='$numOtrp', np_totdev='$numTotdev', np_igss='$numIgss', np_isr='$numIsr', np_anti='$numAnti', np_unif='$numUnif', np_lent='$numLent', np_preb='$numPreb', np_pree='$numPree', np_desj='$numDesj', np_otrd='$numDescv', np_totdes='$numTotdes', np_liqrec='$numLiqrec'  WHERE np_emp='$empCod' AND np_numpla='$numNum' AND np_cod='$numCod' ";

	# EJECUCION DE QUERYS 
	$db = new dbExec();
		$resp= $db->uEx($uNomper);
		$db->iEx($func->iBitacora(utf8_decode("Se Modifico La planilla No. $numNum  Codigo: $numCod Usuario: ").$usuNom, $bitMod, $bitForm));
	$db->close();
	
	return json_encode($resp);
}


function borrar() {
	global $empCod, $usuNom, $bitMod, $bitForm;

	$priv = new privileges();
	if (!$priv->modify($_SESSION['usuPriv'])) {
		return json_encode($priv->rErrorModify());
	}

	$func = new functions();

	$numNum=$_POST['numNum'];
	$dtDel=$_POST['dtDel'];
	$dtAl=$_POST['dtAl'];

	# QUERYS PARA UN REGISTRO

	$dNomper="DELETE FROM nomper WHERE np_emp='$empCod' AND np_numpla='$numNum'";

	$dAnti="DELETE FROM antipla WHERE ant_emp='$empCod' AND ant_numpla='$numNum'";

	$uCtrpla="UPDATE ctrpla SET ctrp_stat='B', ctrp_obs='BORRADA' WHERE ctrp_emp='$empCod' AND ctrp_num='$numNum'";
	
	# QUERYS PARA VARIOS REGISTROS

	# EJECUCION DE QUERYS 
	$db = new dbExec();

	$resp = $db->dEx($dNomper);
	$db->dEx($dAnti);
	$db->uEx($uCtrpla);
	//
	$db->iEx($func->iBitacora(utf8_decode("Se Borro La planilla No.: $numNum  Del: $dtDel Al: $dtAl Usuario: ").$usuNom, $bitMod, $bitForm));
	$db->close();

	return json_encode($resp);
}

function borrarReg() {
	global $empCod, $usuNom, $bitMod, $bitForm;

	$priv = new privileges();
	if (!$priv->modify($_SESSION['usuPriv'])) {
		return json_encode($priv->rErrorModify());
	}

	$func = new functions();

	$numNum=$_POST['numNum'];
	$dtDel=$_POST['dtDel'];
	$dtAl=$_POST['dtAl'];
	$numCod=$_POST['numCod'];


	# QUERYS PARA UN REGISTRO

	$dNomper="DELETE FROM nomper WHERE np_emp='$empCod' AND np_numpla='$numNum' AND np_cod='$numCod'";
	
	# QUERYS PARA VARIOS REGISTROS

	# EJECUCION DE QUERYS 
	$db = new dbExec();

	$resp = $db->dEx($dNomper);
	//
	$db->iEx($func->iBitacora(utf8_decode("Se Borro Codigo: $numCod de la planilla No.: $numNum  Del: $dtDel Al: $dtAl  Usuario: ").$usuNom, $bitMod, $bitForm));
	$db->close();

	return json_encode($resp);
}

function guardarAg() {
	global $empCod, $usuNom, $bitMod, $bitForm, $numNum, $numpla, $dtDel, $dtAl, $mes, $ano;

	$priv = new privileges();
	if (!$priv->modify($_SESSION['usuPriv'])) {
		return json_encode($priv->rErrorModify());
	}

	$func = new functions();

	$numNum=$_POST['numNum'];
	$numpla=$_POST['numNum'];
	$dtDel=$_POST['dtDel'];
	$dtAl=$_POST['dtAl'];
	$numCoddag=$_POST['numCoddag'];
	$txtNomdag=$_POST['txtNomdag'];
    $ano=date("Y", strtotime($dtAl));
    $mes=date("n", strtotime($dtAl));
    $diaal=date("d", strtotime($dtAl));
    $diadel=date("d", strtotime($dtDel));

	function sRegvacd($cod) { 
		global $empCod;
		return "SELECT * FROM regvacd WHERE rvd_emp='$empCod' AND rvd_cod='$cod'";
	}

	function sSuspen($cod) { 
		global $empCod;
		return "SELECT * FROM suspen WHERE sus_emp='$empCod' AND sus_cod='$cod'";
	}

	function sPrestamos($cod) { 
		global $empCod;
		return "SELECT * FROM pres_mae WHERE pm_emp='$empCod' AND pm_cod='$cod'";
	}

	function sDescuentos($cod) { 
		global $empCod;
		return "SELECT * FROM descuentos WHERE d_emp='$empCod' AND d_cod='$cod'";
	}

	function sMaestro($cod) { 
		global $empCod;
		return "SELECT *, mae.mae_cod, TRIM(mae.mae_nom) AS mae_nom, TRIM(mae.mae_ape) AS mae_ape,
			TRIM(pue.tpu_nom) AS tpu_nom
			FROM maestro mae LEFT JOIN tpuesto pue ON mae.mae_tpue=pue.tpu_cod
			WHERE mae_emp='$empCod' AND mae_cod='$cod' ";
	}

	function iNomper($numpla,$cod,$grupo,$dep,$dtra,$dsusi,$dvaca,$snom,$sord,$boni,$bonii,$bonoe,$depre,$viati,$totdev,$igss,$isr,$pree,$preb,$anti,$unif,$lent,$desj,$otrd,$totdes,$liqrec,$boniinom,$bonoenom,$igsssn,$obs) { 
		global $empCod, $usuNom,  $dtDel, $dtAl, $ano, $mes;
		return "INSERT INTO nomper(np_emp, np_numpla, np_fini, np_ffin, np_cod, np_gru, np_dep, np_dtra, np_dsusi, np_dvaca, np_snom, np_sord,np_boni, np_bonii, np_bonoe, np_depre, np_viati, np_totdev, np_igss, np_isr, np_pree, np_preb, np_anti, np_unif, np_lent, np_desj, np_otrd, np_totdes, np_liqrec, np_boniinom, np_bonoenom, np_mes, np_ano, np_igsssn, np_genero,np_ulcam, np_obs) VALUES ('$empCod', '$numpla', '$dtDel','$dtAl','$cod','$grupo','$dep','$dtra', $dsusi,'$dvaca','$snom','$sord','$boni','$bonii','$bonoe','$depre','$viati','$totdev','$igss','$isr','$pree','$preb','$anti','$unif','$lent','$desj','$otrd','$totdes','$liqrec','$boniinom','$bonoenom','$mes','$ano','$igsssn','$usuNom','$usuNom','$obs')";
	}
	function iPres_mov($cod,$numpla,$monto,$predel,$preal,$tipopre,$nopres,$prestat) { 
		global $empCod, $usuNom, $dtDel, $dtAl, $ano, $mes;
		return "INSERT INTO pres_mov(pmo_emp,pmo_cod, pmo_npla, pmo_monto, pmo_plafini, pmo_plaffin, pmo_tipopre, pmo_noprest, pmo_desde, pmo_hasta, pmo_stat) VALUES ('$empCod','$cod','$numpla','$monto','$predel','$preal','$tipopre','$nopres','$dtDel','$dtAl','$prestat')";
	}
	# EJECUCION DE QUERYS 
	$db = new dbExec();

	$dias=30;

	$cod = $numCoddag;
	$paso="Si paso";

	$select["maestro"] = $db->query(sMaestro($cod));
	$fetchAssoc["maestro"] = $db->fetchAssoc($select["maestro"]);
    $snom=$fetchAssoc["maestro"]["mae_sueldo"];
    $boni=$fetchAssoc["maestro"]["mae_bonil"];
    $boninom=$fetchAssoc["maestro"]["mae_bonil"];
    $boniinom=$fetchAssoc["maestro"]["mae_bonii"];
    $bonoenom=$fetchAssoc["maestro"]["mae_bonoe"];
    $deprenom=$fetchAssoc["maestro"]["mae_depre"];
    $viatinom=$fetchAssoc["maestro"]["mae_viati"];
    $igsssn=$fetchAssoc["maestro"]["mae_igsssn"];
    $fing=$fetchAssoc["maestro"]["mae_fing"];
    $fsal=$fetchAssoc["maestro"]["mae_fsal"];
    $stat=$fetchAssoc["maestro"]["mae_stat"];
    $grupo=$fetchAssoc["maestro"]["mae_gru"];
    $dep=$fetchAssoc["maestro"]["mae_dep"];
    $puesto=$fetchAssoc["maestro"]["tpu_nom"];

    $sueldodia=$snom/30;
    $bonidia=$boni/30;
    $boniidia=$boniinom/30;
    $bonoedia=$bonoenom/30;
    $depredia=$deprenom/30;
    $viatidia=$viatinom/30;
	if (($diadel==1 && $diaal==15) || $diadel>15) {
		$dias=15;
	}
	if (($diadel==1 && $diaal>27)) {
		$dias=30;
	}

   	$horas=0;
   	$anti=0;

    if ($fing>$dtDel && $fing<=$dtAl) {
	    $dias = $func->dateDiff($fing,$dtAl);
		$dias = $dias->format('%d');    
	    $dias = $dias+1;
    }
    if ($stat=='B') {
      if ($fsal>=$dtDel && $fsal<=$dtAl) {
	    $dias = $func->dateDiff($dtDel,$fsal);
		$dias = $dias->format('%d');    
	    $dias = $dias+1;
      }
    }


    // Para revisar Suspensiones
    $dsusi=0;
    $obssusi="";
	$select["suspen"] = $db->query(sSuspen($cod));
	while ($recsus = $db->fetchAssoc($select['suspen'])) {
	    $susdel = $recsus["sus_del"];
	    $susal = $recsus["sus_al"];
	    $dsus1=0;
	    $dsusant1=0;
	    if ($susdel<$dtDel && $susal<=$dtAl && $susal>=$dtDel) {
		    $dsus1 = $func->dateDiff($dtDel,$susal);
			$dsus1 = $dsus1->format('%d');    
		    $dsus1 = $dsus1+1;
	    }
	    if ($susal>$dtAl && $susdel<=$dtAl) {
		    $dsus1 = $func->dateDiff($dtDel,$dtAl);
			$dsus1 = $dsus1->format('%d');    
		    $dsus1 = $dsus1+1;
	    }
	    if ($susdel>=$dtDel && $susal<=$dtAl) {
		    $dsus1 = $func->dateDiff($susdel,$susal);
			$dsus1 = $dsus1->format('%d');    
		    $dsus1 = $dsus1+1;
	    }
	    if ($susdel<=$dtDel && $susal>=$dtAl) {
		    $dsus1 = $func->dateDiff($dtDel,$dtAl);
			$dsus1 = $dsus1->format('%d');    
		    $dsus1 = $dsus1+1;
	    }
	    $dsusi=$dsusi+$dsus1;
	}
	if ($dsusi>=$dias) {
		$dias=0;
	} else {
		$dias=$dias-$dsusi;
	}
	if ($dsusi>0) {
		$obssusi="Suspendido del ".$susdel." al ".$susal;
	}

	// Para revisar Vacaciones
    $dvaca=0;
    $obsvaca="";
	$select["regvacd"] = $db->query(sRegvacd($cod));
	while ($recvac = $db->fetchAssoc($select['regvacd'])) {
	    $vacdel = $recvac["rvd_fdesi"];
	    $vacal = $recvac["rvd_fdesf"];
	    $dvac1=0;
	    if ($vacdel<$dtDel && $vacal<=$dtAl && $vacal>=$dtDel) {
		    $dvac1 = $func->dateDiff($dtDel,$vacal);
			$dvac1 = $dvac1->format('%d');    
		    $dvac1 = $dvac1+1;
	    }
	    if ($vacal>$dtAl && $vacdel<=$dtAl) {
		    $dvac1 = $func->dateDiff($dtDel,$dtAl);
			$dvac1 = $dvac1->format('%d');    
		    $dvac1 = $dvac1+1;
	    }
	    if ($vacdel>=$dtDel && $vacal<=$dtAl) {
		    $dvac1 = $func->dateDiff($vacdel,$vacal);
			$dvac1 = $dvac1->format('%d');    
		    $dvac1 = $dvac1+1;
	    }
	    if ($vacdel<=$dtDel && $vacal>=$dtAl) {
		    $dvac1 = $func->dateDiff($dtDel,$dtAl);
			$dvac1 = $dvac1->format('%d');    
		    $dvac1 = $dvac1+1;
	    }
	    $dvaca=$dvaca+$dvac1;
	}
	if ($dvaca>=$dias) {
		$dias=0;
	} else {
		$dias=$dias-$dvaca;
	}
	if ($dvaca>0) {
		$obsvaca="Vacaciones del ".$vacdel." al ".$vacal;
	}

	// Para revisar prestamos
    $pree=0;
    $preb=0;
    $prestat='P';
	$select["pres_mae"] = $db->query(sPrestamos($cod));
	while ($recpre = $db->fetchAssoc($select['pres_mae'])) {
	    $predel = $recpre["pm_desde"];
	    $preal = $recpre["pm_hasta"];
	    $tipopre = $recpre["pm_tipopre"];
	    $cuotam = $recpre["pm_cuotam"];
	    $saldo = $recpre["pm_saldo"];
	    $noprest = $recpre["pm_noprest"];
	    if ($saldo<0) {
	    	continue;
	    }	
	    if (($dtDel<$predel || $dtDel>$preal) && ($dtAl<$predel || $dtAl>$preal)) {
	    	continue;
	    }	
	    if ($tipopre == 'B') {
		    $pree = $pree+$cuotam;
	    } else {
		    $preb = $preb+$cuotam;

	    }
	    $db->iEx(iPres_mov($cod,$numpla,$cuotam,$predel,$preal,$tipopre,$noprest,$prestat));
	}
	// Para revisar prestamos
    $isr=0;
    $unif=0;
    $lent=0;
    $desj=0;
    $descv=0;
	$select["descuentos"] = $db->query(sDescuentos($cod));
	while ($recdesc = $db->fetchAssoc($select['descuentos'])) {
	    $descdel = $recdesc["d_feci"];
	    $descal = $recdesc["d_fecf"];
	    $codd = $recdesc["d_codd"];
	    $monto = $recdesc["d_monto"];
	    if ($monto<=0) {
	    	continue;
	    }	
	    if (($dtDel<$descdel || $dtDel>$descal) && ($dtAl<$descdel || $dtAl>$descal)) {
	    	continue;
	    }	
	    if ($codd == 2) {
		    $isr = $isr+$monto;
	    }
	    if ($codd == 3) {
		    $desj = $desj+$monto;
	    }
	    if ($codd == 10) {
		    $unif = $unif+$monto;
	    }
	    if ($codd == 19) {
		    $lent = $lent+$monto;
	    }
	    if ($codd!=2 && $codd!=3 && $codd!=10 && $codd!=19) {
		    $descv = $descv+$monto;
	    }
	}

	if ($dias==30) {
		$sord=$snom;
		$boni=$boni;
		$bonii=$boniinom;
		$bonoe=$bonoenom;
		$depre=$deprenom;
		$viati=$viatinom;
	} else {
		if ($dias==15) {
			$sord=round($snom/2,2);
			$boni=round($boni/2,2);
			$bonii=round($boniinom/2,2);
			$bonoe=round($bonoenom/2,2);
			$depre=round($deprenom/2,2);
			$viati=round($viatinom/2,2);
		} else {
			$sord=round($dias*$sueldodia,2);
			$boni=round($dias*$bonidia,2);
			$bonii=round($dias*$boniidia,2);
			$bonoe=round($dias*$bonoedia,2);
			$depre=round($dias*$depredia,2);
			$viati=round($dias*$viatidia,2);
		}
	}

	$anti=0;

	$totdev=($sord+$boni+$bonii+$bonoe+$depre+$viati);
	if ($igsssn=='S') {
		$igss=round($sord*$_SESSION['pIgsse']/100,2);
	} else {
		$igss=0;	
	}
	$totdes=($igss+$isr+$anti+$preb+$pree+$unif+$lent+$desj+$descv);
	$liqrec=$totdev-$totdes;
	$obs=$obssusi.$obsvaca;

	$db->iEx(iNomper($numpla,$cod,$grupo,$dep,$dias,$dsusi,$dvaca,$snom,$sord,$boni,$bonii,$bonoe,$depre,$viati,$totdev,$igss,$isr,$pree,$preb,$anti,$unif,$lent,$desj,$descv,$totdes,$liqrec,$boniinom,$bonoenom,$igsssn,$obs));

	$db->iEx($func->iBitacora(utf8_decode("Se Agrego Codigo: $numCoddag  Planilla:  $numNum  Del:  $dtDel   al  $dtAl Usuario: ").$usuNom, $bitMod, $bitForm));

	$resp["puesto"] = $puesto;
	$resp["totdev"] = $totdev;
	$resp["totdes"] = $totdes;
	$resp["liqrec"] = $liqrec;
	$db->close();
	return json_encode($resp);
}


?>