<?php

    //*******************************************************************	
	// INCLUDES nao alterar a ordem dos includes
    //*******************************************************************	
	include "includes/library.php";

	$clientes = request("cliente");
	
	$data = date('Y-m-d');
	$data = explode("-",$data);
	
	$iduser = request("iduser");
	
	foreach ($clientes as $aux_cliente){
		$sql = "UPDATE CLIENTE SET DESATIVACAO_DATA='".$data[1]."/".$data[2]."/".$data[0]."', DESATIVACAO_PORID='".$iduser."' WHERE ID ='$aux_cliente'";
		//echo $sql;
		$EXEC = new QUERY($DATABASE,$sql);
		$EXEC->FREE();
		
		
		$sql = "SELECT * FROM MODULO WHERE MODULO='NET CONTABIL'";
		$EXISTE = new QUERY($DATABASE,$sql);
		if ($EXISTE->NEXT()){
			$sql = "update CLIENTE set IMPORTAR_DADOS = null where ID = '".$aux_cliente."'";
			$EXEC = new QUERY($DATABASE,$sql);
		}
		
		$sql = "SELECT * FROM MODULO WHERE MODULO='FATURA SERVIÇOS'";
		$EXISTE = new QUERY($DATABASE,$sql);
		if ($EXISTE->NEXT()){
			$sql = "update CONTRATO set DATA_FINAL = '".$data[1]."/".$data[2]."/".$data[0]."' where CLIENTEID = '".$aux_cliente."' and DATA_FINAL is NULL";
			$CON = new QUERY($DATABASE,$sql);
		}
		
		
		
	}
	
	echo "Ok";
?>

