Beispiel #1
0
 public function sendEmail($assunto, Idioma $idioma = null, $vendedor = false)
 {
     if (empty($idioma)) {
         $idioma = new Idioma();
         $idioma->sigla = 'br';
     } elseif (!$idioma->getId()) {
         $idioma = new Idioma();
         $idioma->sigla = 'br';
     }
     $temE = new InterFaces(new Arquivos(Sistema::$adminLayoutCaminhoDiretorio . "/email-padrao.html"));
     $temEE = new InterFaces(new Arquivos(Sistema::$adminLayoutCaminhoDiretorio . "/SistemaPedidos/email-pedido.html"));
     $temEE->setSession($idioma->sigla);
     $temEE->trocar('lang', $idioma->sigla);
     $p = $this->getCliente();
     $endP = $p->getEndereco()->listar();
     $telP = $p->getTelefone()->listar();
     $lP = new ListaProdutos();
     $temEE->createRepeticao("repetir->PedidoItens");
     $con = BDConexao::__Abrir();
     $con->executar("SELECT * FROM " . Sistema::$BDPrefixo . "frete");
     $rs = $con->getRegistro();
     $con->executar("SELECT * FROM " . Sistema::$BDPrefixo . "pagamentos");
     $rsP = $con->getRegistro();
     $total = 0;
     $end = $this->getEndereco();
     $temEE->condicao("condicao->Alterar.Endereco.Pedido", isset($_GET['alterar-endereco']) || $end->getCep() == '' || $end->logradouro == '' || $end->numero == '' || $end->bairro == '' || $end->getCidade()->nome == '' || $end->getEstado()->uf == '');
     $temEE->condicao("condicao->tipo.Endereco.Pedido", !empty($end->tipo));
     $temEE->trocar($end->tipo . '.Endereco.Pedido', "checked=\"checked\"");
     $temEE->trocar('cep.Endereco.Pedido', $end->getCep());
     $temEE->trocar('logradouro.Endereco.Pedido', $end->logradouro);
     $temEE->trocar('ddd.Telefone.Pedido', $tel->ddd);
     $temEE->trocar('telefone.Telefone.Pedido', $tel->telefone);
     $temEE->trocar('numero.Endereco.Pedido', $end->numero);
     $temEE->trocar('complemento.Endereco.Pedido', $end->complemento);
     $temEE->trocar('bairro.Endereco.Pedido', $end->bairro);
     $temEE->trocar('cidade.Endereco.Pedido', $end->getCidade()->nome);
     $temEE->trocar('estado.Endereco.Pedido', $end->getEstado()->uf);
     $temEE->trocar("tipoPagamento.Pedido", $this->getTipoPagamento());
     $temEE->trocar("status.Pedido", $idioma->getTraducaoByConteudo($this->getStatus())->traducao);
     $recuperar = true;
     $itens = new ListaPedidoItens();
     $a[1] = array('campo' => ListaPedidoItens::IDSESSAO, 'valor' => $this->id);
     $itens->condicoes($a);
     while ($pI = $itens->listar()) {
         if ($pI) {
             $lP->condicoes('', $pI->getProdutoPai(), ListaProdutos::ID);
             if ($lP->getTotal() > 0) {
                 $produtoPai = $lP->listar();
             }
             $cat = $produtoPai ? $produtoPai->getCategorias()->listar() : $pI->getCategorias()->listar();
             $temEE->repetir();
             $temEE->enterRepeticao()->trocar("n.PedidoItem", $this->getItem()->getParametros());
             $temEE->enterRepeticao()->trocar("id.PedidoItem", $pI->getId());
             $temEE->enterRepeticao()->trocar("quantidade.PedidoItem", $pI->quantidade);
             $temEE->enterRepeticao()->trocar("nome.PedidoItem", $idioma->getTraducaoByConteudo($pI->nome)->traducao . ($pI->observacao != '' ? ' ' . $pI->observacao : ''));
             $temEE->enterRepeticao()->trocar("valor.PedidoItem", "\$ " . $pI->valor->moeda());
             $valorP = $pI->valor;
             $temEE->enterRepeticao()->trocar("valorPonto.PedidoItem", (string) Numero::__CreateNumero($valorP->formatar())->formatar());
             $total += $pI->valor->num * $pI->quantidade;
             if ($pI->getImagens()->getTotal() > 0) {
                 $temEE->enterRepeticao()->trocar("imagem.PedidoItem", $pI->getImagens()->listar("DESC", ListaImagens::DESTAQUE)->getImage()->showHTML(60, 1000));
             }
             if ($pI->quantidade > $pI->estoque) {
                 $recuperar = false;
             }
         }
     }
     $temEE->condicao('condicao->Desconto', $this->getDesconto()->num > 0);
     $temEE->trocar('desconto', "\$ " . $this->getDesconto()->moeda());
     $total -= $this->getDesconto()->num;
     $temEE->condicao("condicao->RecuperarPedido", $this->getStatus()->getStatus() == PedidoStatus::CANCELADO && $recuperar);
     $temEE->condicao("condicao->EfetivarPagamento", $this->getStatus()->getStatus() == PedidoStatus::COBRANCA);
     $temEE->trocar("linkFinalizar.Pedido", Sistema::$caminhoURL . $idioma->sigla . "/finalizar-pedido&pedido=" . $this->getId() . "&recuperar");
     $temEE->condicao("condicao->DepositoPagamento", $this->getTipoPagamento() == PagamentoDeposito::GetTipo());
     $temEE->trocar("textoDeposito", nl2br($rsP['textodeposito']));
     $temEE->condicao('condicao->ExisteFrete', $this->hasFrete() && $this->getItem()->getTotal() > 0);
     $temEE->condicao('condicao->ExistePrazo', $this->getEndereco()->prazo > 0 && $this->getItem()->getTotal() > 0);
     $temEE->condicao('condicao->ExisteFreteCorreios', $rs['ativocorreio']);
     $temEE->trocar("valor.Endereco.Cliente", $this->freeFrete() ? $idioma->getTraducaoByConteudo('Grátis')->traducao : ($end->getValor()->num > 0 ? "\$ " . $end->getValor()->moeda() : ''));
     $temEE->trocar("tipo.Endereco.Pedido", PedidoEnderecoEntrega::GetNameType($end->tipo));
     $temEE->trocar("prazo.Endereco.Pedido", $this->getEndereco()->prazo);
     $temEE->trocar("total", "\$ " . Numero::__CreateNumero($total + $end->getValor()->num)->moeda());
     $temEE->trocar("observacoes", $this->observacoes);
     $temE->trocar('texto', $temEE->concluir());
     $msg = $temE->concluir();
     EnvioEmail::$de = Sistema::$nomeEmpresa . "<" . Sistema::$emailEmpresa . ">";
     EnvioEmail::$assunto = $idioma->getTraducaoByConteudo($assunto)->traducao . "!";
     EnvioEmail::$html = true;
     EnvioEmail::$msg = $msg;
     if (!$vendedor) {
         EnvioEmail::$de = Sistema::$nomeEmpresa . "<" . Sistema::$emailEmpresa . ">";
         EnvioEmail::$para = $p->emailPrimario;
     } else {
         EnvioEmail::$de = $p->nome . "<" . $p->emailPrimario . ">";
         EnvioEmail::$para = Sistema::$emailEmpresa;
     }
     EnvioEmail::enviar();
 }
 }
 if ($p->estoque == 1 && $status == PedidoStatus::CANCELADO) {
     $p->estoque = 0;
     $lPR = new ListaProdutos();
     while ($pI = $p->getItem()->listar()) {
         $lPR->condicoes('', $pI->getId(), ListaProdutos::ID);
         if ($lPR->getTotal() > 0) {
             $pR = $lPR->listar();
             $pR->estoque = $pR->estoque + $pI->quantidade;
             $lPR->alterar($pR);
         }
     }
 }
 if ($_POST['selecionado']) {
     foreach ($_POST['selecionado'] as $v) {
         $lPI = new ListaPedidoItens();
         $arPI[1] = array('campo' => ListaPedidoItens::ID, 'valor' => $v);
         $arPI[2] = array('campo' => ListaPedidoItens::IDSESSAO, 'valor' => $p->getId());
         $lPI->condicoes($arPI);
         if ($lPI->getTotal() > 0) {
             $lPI->deletar($lPI->listar(), $p);
         }
     }
     try {
         $p->calcularFrete();
     } catch (Exception $e) {
     }
     $p->calcular();
 }
 while ($pI = $p->getItem()->listar()) {
     $pI->quantidade = $_POST['quantidade'][$pI->getId()];