Esempio n. 1
0
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndex()
 {
     if (!Yii::app()->user->isAdmin()) {
         $this->redirect(array('../index.php/venda'));
     }
     $totalProdutos = Produto::model()->getTotal();
     $totalVendasHoje = Venda::model()->getTotalVendaHoje();
     $totalVendasPrazoHoje = Venda::model()->getTotalvendasPrazoHoje();
     $totalCliente = Cliente::model()->getTotal();
     $totalPagamentos = Pagamento::model()->getToalPagamentosDia();
     $totalFornecedores = Fornecedor::model()->getTotal();
     $totalVendasVista = $totalVendasHoje - $totalVendasPrazoHoje;
     $data = array('totalProdutos' => $totalProdutos, 'totalVendaHoje' => $totalVendasHoje, 'totalVendasPrazoHoje' => $totalVendasPrazoHoje, 'totalCliente' => $totalCliente, 'totalPagamentos' => $totalPagamentos, 'totalFornecedores' => $totalFornecedores, 'totalVendasVista' => $totalVendasVista, 'itensMaisVendidos' => Produto::model()->getItensMaisVendidos());
     $this->render('index', $data);
 }
Esempio n. 2
0
 public function actionFinalizarVendaAPrazo()
 {
     try {
         // $this->viewData(Yii::app()->session['venda']);
         $transaction = Venda::model()->dbConnection->beginTransaction();
         if (isset(Yii::app()->session['venda'])) {
             $itensVenda = Yii::app()->session['venda']['itensVenda'];
         } else {
             throw new Exception("Não há nenhum item de venda para ser registrado");
         }
         $idVenda = $this->registrarVenda($itensVenda);
         if (!$idVenda) {
             throw new Exception("Não foi possível registrar esta venda");
         } else {
             //$this->viewData($_POST['venda']);
             $venda = Venda::model()->findByPk($idVenda);
             $venda->observacao = $_POST['venda']['observacao'];
             $venda->desconto = isset(Yii::app()->session['venda']['desconto']) ? Yii::app()->session['venda']['desconto'] : 0;
             $venda->save();
         }
         if (isset($_POST['cliente']['idCliente'])) {
             $idCliente = $_POST['cliente']['idCliente'];
         } elseif (isset($_POST['cliente'])) {
             $cliente = $_POST['cliente'];
             $modelCliente = $this->cadastraCliente($cliente);
             $idCliente = $modelCliente->idCliente;
         } else {
             throw new Exception("Nenhum cliente foi enviado para cadastro.");
         }
         $this->cadastraConta($idCliente, $idVenda);
         if (isset($_POST['venda']['pagamento'])) {
             $valor = $_POST['venda']['pagamento'];
             if ($valor != null || !empty($valor)) {
                 $this->registraPagamento($valor, $idVenda);
             }
         }
         $transaction->commit();
         unset(Yii::app()->session['venda']);
         $this->setFlashMessage('success', "Venda registrada com sucesso");
     } catch (Exception $e) {
         $this->setFlashMessage('error', $e->getMessage());
         $transaction->rollback();
     }
     $this->redirect(array('index'));
 }
Esempio n. 3
0
 /**
  * Action Venda : FINDALL
  */
 public function actionCarregarVendas()
 {
     $dadosPost = Yii::app()->request->rawBody;
     $parametros = CJSON::decode($dadosPost, true);
     $condition = " tipovenda=:tipovenda ";
     $params = array(":tipovenda" => $parametros['tipovenda']);
     $criteria = new CDbCriteria();
     $criteria->condition = $condition;
     $criteria->params = $params;
     $criteria->together = true;
     $criteria->order = 'data asc';
     $vendas = Venda::model()->findAll($criteria);
     $jsons = array();
     foreach ($vendas as $key => $venda) {
         $dados = array();
         $dados['id'] = $venda->id;
         $dados['valor'] = $venda->valor;
         $dados['animal'] = $venda->animal;
         $dados['animalnome'] = isset($venda->Animal) ? $venda->Animal->nome : '';
         $dados['animal2'] = $venda->animal2;
         $dados['animal2nome'] = isset($venda->Animal2) ? $venda->Animal2->nome : '';
         $dados['tipovenda'] = $venda->tipovenda;
         $dados['tipovendanome'] = isset($venda->Tipovenda) ? $venda->Tipovenda->nome : '';
         $dados['data'] = strftime('%d%m%Y', strtotime($venda->data));
         $dados['datanome'] = strftime('%d de %b, %Y', strtotime($venda->data));
         if ($venda->animal != 0) {
             if ($venda->Animal->pai != 0 && $venda->Animal->mae != 0) {
                 $dados['nomepaiemae'] = $venda->Animal->Pai->nome . " X " . $venda->Animal->Mae->nome;
             } else {
                 if ($venda->Animal->pai != 0) {
                     $dados['nomepaiemae'] = $venda->Animal->Pai->nome;
                 } else {
                     if ($venda->Animal->mae != 0) {
                         $dados['nomepaiemae'] = $venda->Animal->Mae->nome;
                     }
                 }
             }
         }
         $dados['imagens'] = array();
         $imagem = array();
         $imagem['url'] = $venda->url;
         $dados['imagens'][] = $imagem;
         $jsons[] = $dados;
     }
     header('Content-type: application/json; charset=utf-8');
     echo CJSON::encode($jsons);
     Yii::app()->end();
 }
Esempio n. 4
0
 public function actionHistorico($id = 0)
 {
     $historico = array();
     if (isset($_POST['historico'])) {
         $id = $_POST['idCliente'];
         $param = $_POST['historico'];
         $data1 = $param['data1'];
         $data2 = $param['data2'];
         $historico = Venda::model()->getHistorico($id, $data1, $data2);
     }
     $this->render('historico', array('model' => $this->loadModel($id), 'historico' => $historico));
 }
Esempio n. 5
0
 public function getDebitos($idCliente = 0)
 {
     if ($idCliente == 0) {
         $idCliente = $this->idCliente;
     }
     if ($idCliente == null) {
         return array();
     }
     $sql = "select v.* from venda v\n\t\t\t\tinner join conta co on co.id_Venda = v.idVenda\n\t\t\t\tinner join cliente c on co.id_cliente = c.idCliente\n\t\t\t\twhere c.idCliente = {$idCliente} and co.quitada = 0";
     $queryVendas = $this->getQuery($sql);
     $debitos = array();
     foreach ($queryVendas as $row) {
         $venda = $row;
         $sql = "select iv.*, p.descricao,p.codigo from item_venda iv\n\t\t\t\tinner join produto p on iv.id_produto = p.idProduto\n\t\t\t\tinner join venda v on iv.id_venda = v.idVenda\n\t\t\t\twhere v.idVenda = " . $row['idVenda'];
         $query = $this->getQuery($sql);
         $venda['itensVenda'] = $query;
         $totalVenda = Venda::model()->getTotalVenda($query);
         $totalPago = Venda::model()->getTotalPago($row['idVenda']);
         $desconto = $totalVenda * ($row['desconto'] / 100);
         $totalVenda -= $desconto;
         if ($totalVenda > $totalPago) {
             $venda['totalVenda'] = $totalVenda;
             $venda['desconto'] = $desconto;
             $venda['totalPago'] = $totalPago;
             $debitos[] = $venda;
         }
     }
     return $debitos;
 }
Esempio n. 6
0
 public function getHistorico($idCliente, $data1, $data2)
 {
     $data1 = $this->formataData($data1);
     //'2016-01-01';// $param['data1'];
     $data2 = $this->formataData($data2);
     //$param['data2'];
     $sql = "select * from venda v inner join conta c on v.idVenda = c.id_venda where\n\t\t\t\tc.id_cliente = {$idCliente} and (v.dataVenda >='{$data1}' AND v.dataVenda <= '{$data2}') ";
     $query = Yii::app()->db->createCommand($sql)->queryAll();
     $historico = array();
     foreach ($query as $row) {
         $itensVenda = Venda::model()->getItensVenda($row['idVenda']);
         $venda = $row;
         $venda['itensVenda'] = $itensVenda;
         $totalVenda = $this->getTotalVenda($itensVenda);
         $venda['totalPago'] = $this->getTotalPago($row['idVenda']);
         $desconto = $totalVenda * ($row['desconto'] / 100);
         $venda['totalVenda'] = $totalVenda - $desconto;
         $venda['desconto'] = $desconto;
         $historico[] = $venda;
     }
     return $historico;
 }