public static function updateConfigEmpreendimento()
 {
     $EmpreendimentoTO = new EmpreendimentoTO();
     $EmpreendimentoDao = new EmpreendimentoDao();
     $EmpreendimentoTO->id = isset($_POST['id']) ? $_POST['id'] : NULL;
     $EmpreendimentoTO->nome_empreendimento = isset($_POST['nome_empreendimento']) ? $_POST['nome_empreendimento'] : NULL;
     $EmpreendimentoTO->nickname = isset($_POST['nickname']) ? $_POST['nickname'] : NULL;
     $EmpreendimentoTO->dsc_empreendimento = isset($_POST['dsc_empreendimento']) ? $_POST['dsc_empreendimento'] : NULL;
     $EmpreendimentoTO->url_facebook = isset($_POST['url_facebook']) ? $_POST['url_facebook'] : NULL;
     $EmpreendimentoTO->url_twitter = isset($_POST['url_twitter']) ? $_POST['url_twitter'] : NULL;
     $EmpreendimentoTO->url_google_plus = isset($_POST['url_google_plus']) ? $_POST['url_google_plus'] : NULL;
     $EmpreendimentoTO->url_linkedin = isset($_POST['url_linkedin']) ? $_POST['url_linkedin'] : NULL;
     $EmpreendimentoTO->url_pinterest = isset($_POST['url_pinterest']) ? $_POST['url_pinterest'] : NULL;
     $EmpreendimentoTO->nme_logo = isset($_POST['nme_logo']) ? $_POST['nme_logo'] : NULL;
     $EmpreendimentoTO->end_email_contato = isset($_POST['end_email_contato']) ? $_POST['end_email_contato'] : NULL;
     $EmpreendimentoTO->num_telefone = isset($_POST['num_telefone']) ? $_POST['num_telefone'] : NULL;
     $EmpreendimentoTO->num_cnpj = isset($_POST['num_cnpj']) ? $_POST['num_cnpj'] : NULL;
     $EmpreendimentoTO->num_inscricao_estadual = isset($_POST['num_inscricao_estadual']) ? $_POST['num_inscricao_estadual'] : NULL;
     $EmpreendimentoTO->num_inscricao_municipal = isset($_POST['num_inscricao_municipal']) ? $_POST['num_inscricao_municipal'] : NULL;
     $EmpreendimentoTO->nme_razao_social = isset($_POST['nme_razao_social']) ? $_POST['nme_razao_social'] : NULL;
     $EmpreendimentoTO->nme_fantasia = isset($_POST['nme_fantasia']) ? $_POST['nme_fantasia'] : NULL;
     $EmpreendimentoTO->num_cep = isset($_POST['num_cep']) ? $_POST['num_cep'] : NULL;
     $EmpreendimentoTO->nme_logradouro = isset($_POST['nme_logradouro']) ? $_POST['nme_logradouro'] : NULL;
     $EmpreendimentoTO->num_logradouro = isset($_POST['num_logradouro']) ? $_POST['num_logradouro'] : NULL;
     $EmpreendimentoTO->nme_bairro_logradouro = isset($_POST['nme_bairro_logradouro']) ? $_POST['nme_bairro_logradouro'] : NULL;
     $EmpreendimentoTO->cod_estado = isset($_POST['cod_estado']) ? $_POST['cod_estado'] : NULL;
     $EmpreendimentoTO->cod_cidade = isset($_POST['cod_cidade']) ? $_POST['cod_cidade'] : NULL;
     $EmpreendimentoTO->num_percentual_credito_simples = isset($_POST['num_percentual_credito_simples']) ? $_POST['num_percentual_credito_simples'] : NULL;
     $EmpreendimentoTO->flg_contribuinte_icms = isset($_POST['flg_contribuinte_icms']) ? (int) $_POST['flg_contribuinte_icms'] : NULL;
     $EmpreendimentoTO->flg_contribuinte_ipi = isset($_POST['flg_contribuinte_ipi']) ? (int) $_POST['flg_contribuinte_ipi'] : NULL;
     $EmpreendimentoTO->num_inscricao_estadual_st = isset($_POST['num_inscricao_estadual_st']) ? $_POST['num_inscricao_estadual_st'] : NULL;
     $EmpreendimentoTO->cod_regime_tributario = isset($_POST['cod_regime_tributario']) && is_numeric($_POST['cod_regime_tributario']) ? $_POST['cod_regime_tributario'] : NULL;
     $EmpreendimentoTO->cod_regime_pis_cofins = isset($_POST['cod_regime_pis_cofins']) && is_numeric($_POST['cod_regime_pis_cofins']) ? $_POST['cod_regime_pis_cofins'] : NULL;
     $EmpreendimentoTO->cod_tipo_empresa = isset($_POST['cod_tipo_empresa']) && is_numeric($_POST['cod_tipo_empresa']) ? $_POST['cod_tipo_empresa'] : NULL;
     $EmpreendimentoTO->cod_zoneamento = isset($_POST['cod_zoneamento']) && is_numeric($_POST['cod_zoneamento']) ? $_POST['cod_zoneamento'] : NULL;
     $Validator = new DataValidator();
     $Validator->set_msg('O nome do empreendimento é obrigatório')->set('nome_empreendimento', $EmpreendimentoTO->nome_empreendimento)->is_required();
     $Validator->set_msg('O ID do empreendimento é obrigatório')->set('id', $EmpreendimentoTO->id)->is_required();
     $Validator->set_msg('O nickname do empreendimento é obrigatório')->set('nickname', $EmpreendimentoTO->nickname)->is_required();
     if (isset($_FILES['nme_logo'])) {
         $status_upload = false;
         $handle = new upload($_FILES['nme_logo']);
         $handle->allowed = array('image/jpeg', 'image/jpg', 'image/gif', 'image/png');
         list($width, $height) = getimagesize($_FILES['nme_logo']['tmp_name']);
         if (!($width >= 118 && $height >= 36)) {
             $Validator->_errors['nme_logo'][] = 'O Tamanho da imagem deve ser igual ou superior a 118x36. Está imagem tem ' . $width . "x" . $height;
         } else {
             if ($handle->uploaded) {
                 $handle->Process(CAMINHO_UPLOAD_IMG_LOGO);
                 if ($handle->processed) {
                     $status_upload = true;
                     $EmpreendimentoTO->nme_logo = $handle->file_dst_name;
                 }
             }
             if (!$status_upload) {
                 if ($handle->error == 'Incorrect type of file') {
                     $Validator->_errors['nme_logo'][] = 'O formato da imagem deve ser jpeg, jpg ou gif';
                 } else {
                     Flight::halt(500, 'Ocorreu um erro ao fazer o upload da imagem ' . $handle->error);
                 }
             }
         }
     }
     if (!$Validator->validate()) {
         Flight::response()->status(406)->header('Content-Type', 'application/json')->write(json_encode($Validator->get_errors()))->send();
         return;
     }
     if ($EmpreendimentoDao->updateConfigEmpreendimento($EmpreendimentoTO)) {
         $inscricoes_estaduais = isset($_POST['inscricoes_estaduais']) ? $_POST['inscricoes_estaduais'] : array();
         $ids_not_delete = array();
         foreach ($inscricoes_estaduais as $key => $value) {
             $InscricaoEstadualDao = new InscricaoEstadualDao();
             $InscricaoEstadual = new stdClass();
             $InscricaoEstadual->id_empreendimento = $value['id_empreendimento'];
             $InscricaoEstadual->num_inscricao_estadual = $value['num_inscricao_estadual'];
             $InscricaoEstadual->num_inscricao_estadual_st = $value['num_inscricao_estadual_st'];
             $InscricaoEstadual->uf = $value['uf'];
             if (!(isset($value['id']) && $value['id'])) {
                 $InscricaoEstadualTO = new InscricaoEstadualTO();
                 $InscricaoEstadualTO->__setAll($value);
                 $ids_not_delete[] = $InscricaoEstadualDao->save($InscricaoEstadualTO);
             } else {
                 $ids_not_delete[] = $value['id'];
                 $InscricaoEstadualDao->updateInscricao($InscricaoEstadual, 'id=' . $value['id']);
             }
         }
         $InscricaoEstadualDao->deleteInscricao('id_empreendimento = ' . $EmpreendimentoTO->id . ' AND id NOT IN(' . join(',', $ids_not_delete) . ')');
         Flight::halt(200);
     } else {
         Flight::halt(500, 'erro ao atualizar empreendimento');
     }
 }