Example #1
0
 public function listar($ordem = "ASC", $campo = self::ID)
 {
     $info = parent::listar($ordem, $campo);
     if (!empty($info)) {
         $temp = new Cidade($info[self::ID]);
         $temp->nome = $info[self::NOME];
         $temp->ddd = $info[self::DDD];
         $lP = new ListaPaises();
         $lP->condicoes('', $info[self::PAIS], ListaPaises::ID);
         if ($lP->getTotal() > 0) {
             $temp->setPais($lP->listar());
         }
         $lE = new ListaEstados();
         $lE->condicoes('', $info[self::ESTADO], ListaEstados::ID);
         if ($lE->getTotal() > 0) {
             $temp->setEstado($lE->listar());
         }
         return $temp;
     }
 }
Example #2
0
 public function loadCep()
 {
     if (!empty($this->cep)) {
         $arq = self::_GetEnderecoByCep($this->cep);
         if ((string) $arq["status"] == "false") {
             $arq = Arquivos::__OpenArquivo(self::$urlCep . $this->cep, true);
         } else {
             $arq = JSON::_Encode($arq);
         }
         if (!empty($arq)) {
             $json = JSON::_Decode($arq);
             if (!empty($json->root->logradouro)) {
                 $this->logradouro = $json->root->logradouro;
             }
             if (!empty($json->root->bairro)) {
                 $this->bairro = $json->root->bairro;
             }
             if (!empty($json->root->uf)) {
                 $lE = new ListaEstados();
                 $lE->condicoes('', strtoupper($json->root->uf), ListaEstados::UF);
                 if ($lE->getTotal() > 0) {
                     $this->estado = $lE->listar();
                 } else {
                     $this->estado = new Estado();
                     $this->estado->uf = $json->root->uf;
                     $this->estado->nome = $json->root->estado;
                     $this->estado->setPais($this->pais);
                 }
             }
             if (!empty($json->root->idcidade)) {
                 $this->cidade = new Cidade($json->root->idcidade);
                 $this->cidade->nome = $json->root->cidade;
                 $this->cidade->setEstado($this->estado);
                 $this->cidade->setPais($this->pais);
             }
         }
     }
 }
Example #3
0
 public function alterar(Endereco $end)
 {
     parent::alterar($end);
     $where = "WHERE " . self::ID . " = '" . $end->getId() . "'";
     $e = $end->getEstado();
     if ($e->getId() <= 0) {
         $lE = new ListaEstados();
         $lE->inserir($e);
         $end->setEstado($e);
     }
     $c = $end->getCidade();
     if ($c->getId() <= 0) {
         $lC = new ListaCidades();
         $lC->inserir($c);
         $end->setCidade($c);
     } else {
         $lC = new ListaCidades();
         $lC->condicoes('', $c->getId(), ListaCidades::ID);
         if ($lC->getTotal() <= 0) {
             if ($c->getPais()->getId() <= 0) {
                 $c->setPais($end->getPais());
             }
             if ($c->getEstado()->getId() <= 0) {
                 $c->setEstado($end->getEstado());
             }
             $this->con->executar("INSERT INTO " . Sistema::$BDPrefixo . $lC->getTabela() . "(" . ListaCidades::ID . ", " . ListaCidades::PAIS . ", " . ListaCidades::ESTADO . ", " . ListaCidades::NOME . ", " . ListaCidades::DDD . ") VALUES('" . $c->getId() . "','" . $c->getPais()->getId() . "','" . $c->getEstado()->getId() . "','" . $c->nome . "','" . $c->ddd . "')");
             $id = $this->con->getId();
             $end->setCidade(new Cidade($id));
         }
     }
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::LOGRADOURO, $end->logradouro, $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::NUMERO, $end->numero, $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::COMPLEMENTO, $end->complemento, $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::BAIRRO, $end->bairro, $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::CIDADE, $end->getCidade()->getId(), $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::ESTADO, $end->getEstado()->getId(), $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::PAIS, $end->getPais()->getId(), $where);
     $this->con->alterar(Sistema::$BDPrefixo . $this->tabela, self::CEP, $end->getCep(), $where);
 }
Example #4
0
     }
     try {
         $p->calcularFrete();
     } catch (Exception $e) {
     }
     $p->calcular();
 }
 while ($pI = $p->getItem()->listar()) {
     $pI->quantidade = $_POST['quantidade'][$pI->getId()];
     $pI->valorVenda = $_POST['valor'][$pI->getId()];
     $p->addItem($pI);
 }
 if (!empty($_POST['CEP'])) {
     $end = $p->getEndereco();
     $end->setCep($_POST['CEP']);
     $lE = new ListaEstados();
     $lE->condicoes('', strtoupper($_POST['estado']), ListaEstados::UF);
     if ($lE->getTotal() > 0) {
         $end->setEstado($lE->listar());
     } else {
         $end->getEstado()->uf = strtoupper($_POST['estado']);
         $end->getEstado()->setPais(new Pais(1));
     }
     $lC = new ListaCidades();
     $lC->condicoes('', $_POST['cidade'], ListaCidades::NOME);
     if ($lC->getTotal() > 0) {
         $end->setCidade($lC->listar());
     } else {
         $end->getCidade()->nome = $_POST['cidade'];
         $end->getCidade()->setEstado($end->getEstado());
     }
Example #5
0
$iTCL->trocar("email", $cl->emailPrimario);
$iTCL->trocar("origemCadastro", $cl->origemCadastro);
$iTCL->condicao('condicao->POST', true);
$iTCL->condicao('condicao->alterar.Cliente', false);
//Endereço
$lPA = new ListaPaises();
$iTCL->createRepeticao("repetir->Pais");
while ($pA = $lPA->listar("ASC", ListaPaises::NOME)) {
    $iTCL->repetir();
    $iTCL->enterRepeticao()->trocar("id.Pais", $pA->getId());
    $iTCL->enterRepeticao()->trocar("nome.Pais", $pA->nome);
    if ($pA->getId() == $pais) {
        $iTCL->enterRepeticao()->trocar("selected.Pais", 'selected');
    }
}
$lE = new ListaEstados();
$iTCL->createRepeticao("repetir->Estado");
if (!empty($_GET['pais'])) {
    $lE->condicoes('', $_GET['pais'], ListaEstados::PAIS);
    if (isset($_GET['json'])) {
        $a = array();
        while ($e = $lE->listar("ASC", ListaEstados::NOME)) {
            $a[] = array('id' => $e->getId(), 'nome' => $e->nome, 'uf' => $e->uf);
        }
        echo JSON::_Encode($a, true);
        exit;
    }
}
/*
while($rs = $con->listar()){
	
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::get('/', function () {
    return View::make('listas');
});
//Ruta para consultar todos los paises
Route::get('paises', function () {
    return ListaPaises::all()->toJson();
});
//Ruta en la cual retornamos los estados relaccionados con el id del pais
Route::POST('estados', function () {
    return ListaEstados::where('id_pais', '=', Input::get('pais'))->get();
});