Example #1
0
 public function getTotalVendaCliente($cliente_id)
 {
     $venda = $this->venda->where('cliente_id', $cliente_id)->get();
     $total = 0;
     foreach ($venda as $v) {
         foreach ($v->venda_itens as $vi) {
             $total += $vi->quantidade * $vi->preco_venda;
         }
     }
     return $total;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, $id)
 {
     $venda = Venda::find($id);
     if (isset($request->fp['entrada'])) {
         $this->insertLancamentos($venda, $request->fp['entrada']);
     }
     if (isset($request->fp['desconto'])) {
         $this->insertDescontos($venda, $request->fp['desconto']);
     }
     if (isset($request->fp['boleto'])) {
         $this->insertBoletos($venda, $request->fp['boleto']);
     }
     if (isset($request->fp['cheque'])) {
         $this->insertCheques($venda, $request->fp['cheque']);
     }
     flash()->success('Lançamento salvo com sucesso');
     if ($request->btn == 'save') {
         return redirect('/vendas');
     }
     if ($request->btn == 'finalizar') {
         // Altera o status da venda para concluĂ­do
         $venda->status = 2;
         $venda->save();
         return redirect('/vendas');
     }
 }
Example #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Venda::find();
     $query->joinWith(['clienteIdcliente', 'lojaIdloja']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     if ($this->dataVendaPeriodo) {
         //2015-07-15 - 2015-07-22
         $dataInicial = substr($this->dataVendaPeriodo, 0, 10);
         $dataFinal = substr($this->dataVendaPeriodo, -10);
         $query->andFilterWhere(['between', 'data', $dataInicial . ' 00:00:00', $dataFinal . ' 23:59:59']);
     }
     if ($this->clienteNome) {
         $query->joinWith(['clienteIdcliente']);
         $query->andFilterWhere(['like', 'cliente.nome', $this->clienteNome]);
     }
     if ($this->lojaId) {
         $query->andFilterWhere(['loja.idloja' => $this->lojaId]);
     }
     $query->andFilterWhere(['idvenda' => $this->idvenda, 'data' => $this->data, 'desconto' => $this->desconto, 'valortotal' => $this->valortotal, 'cliente_idcliente' => $this->cliente_idcliente, 'vendedor_idvendedor' => $this->vendedor_idvendedor, 'forma_pagamento_idforma_pagamento' => $this->forma_pagamento_idforma_pagamento, 'loja_idloja' => $this->loja_idloja]);
     return $dataProvider;
 }
Example #4
0
 public function actionSinteticoVenda()
 {
     #VENDA
     $searchModelVenda = new VendaSearch();
     //$searchModel->dataVendaPeriodo  = date('Y-m-d') .' - '.date('Y-m-d') ; //'2015-07-15 - 2015-07-22'
     if (Yii::$app->user->identity->perfil != 'Administrador') {
         $searchModelVenda->loja_idloja = Yii::$app->user->identity->loja_idloja;
     }
     $query = Venda::find()->select(['fp.forma_pagamento as formaPagamentoNome, SUM(valortotal - desconto) as valorFinalVenda'])->innerJoin('forma_pagamento fp', 'venda.forma_pagamento_idforma_pagamento=fp.idforma_pagamento')->groupBy('forma_pagamento_idforma_pagamento');
     $dataProviderVenda = new ActiveDataProvider(['query' => $query]);
     $searchModelVenda->load(Yii::$app->request->queryParams);
     if ($searchModelVenda->dataVendaPeriodo) {
         //2015-07-15 - 2015-07-22
         $dataInicial = substr($searchModelVenda->dataVendaPeriodo, 0, 10);
         $dataFinal = substr($searchModelVenda->dataVendaPeriodo, -10);
         $query->andFilterWhere(['between', 'data', $dataInicial . ' 00:00:00', $dataFinal . ' 23:59:59']);
     }
     $query->andFilterWhere(['loja_idloja' => $searchModelVenda->loja_idloja]);
     #TIPO PRODUTOS
     $searchModelTipoProduto = new VendaHasProdutoSearch();
     $query2 = VendaHasProduto::find()->select('pc.categoria as nomeProdutoTipo, SUM(quantidade) as quantidade')->innerJoin('produto p', 'venda_has_produto.produto_idproduto=p.idproduto')->innerJoin('produto_categoria pc', 'p.produto_categoria_idproduto_categoria=pc.idproduto_categoria')->innerJoin('venda v', 'venda_has_produto.venda_idvenda=v.idvenda')->groupBy('pc.idproduto_categoria');
     //VarDumper::dump($query2->all(),10,true);die;
     $dataProviderVendaHasProduto = new ActiveDataProvider(['query' => $query2]);
     if ($searchModelVenda->dataVendaPeriodo) {
         //2015-07-15 - 2015-07-22
         $dataInicial = substr($searchModelVenda->dataVendaPeriodo, 0, 10);
         $dataFinal = substr($searchModelVenda->dataVendaPeriodo, -10);
         $query2->andFilterWhere(['between', 'v.data', $dataInicial . ' 00:00:00', $dataFinal . ' 23:59:59']);
     }
     $query2->andFilterWhere(['v.loja_idloja' => $searchModelVenda->loja_idloja]);
     return $this->render('sinteticoVendas', ['dataProviderVenda' => $dataProviderVenda, 'searchModelVenda' => $searchModelVenda, 'dataProviderVendaHasProduto' => $dataProviderVendaHasProduto]);
 }
 public function addProduto(Request $request)
 {
     $itens = $request->itens;
     //$venda = Venda::find($itens->venda_id);
     $produto = VendaItem::create($itens);
     Produto::removeEstoque($produto['produto_id'], $produto['quantidade']);
     //echo $produto->id;
     $total_venda = Venda::totalVenda($itens['venda_id']);
     $dados = ['total' => $total_venda[0]->total, 'id' => $produto->id];
     return $dados;
 }
Example #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getVendaIdvenda()
 {
     return $this->hasOne(Venda::className(), ['idvenda' => 'venda_idvenda']);
 }
Example #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getVendas()
 {
     return $this->hasMany(Venda::className(), ['id_cliente' => 'id']);
 }
Example #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getVendas()
 {
     return $this->hasMany(Venda::className(), ['loja_idloja' => 'idloja']);
 }
 private function getValorTotalLancamentos($venda_id)
 {
     $venda = Venda::find($venda_id);
     $total_venda = VendaItem::where('venda_id', $venda_id);
     $total_venda->select(DB::raw('sum(quantidade * preco_venda) as total'));
     $total_venda = $total_venda->get();
     $retorno = Lancamento::where('venda_id', $venda_id);
     $total = $total_venda[0]->total;
     $saldo = $retorno->sum('valor');
     return ['total_geral' => $total, 'saldo' => $saldo, 'descontos' => $retorno->sum('desconto')];
 }
Example #10
0
 /**
  * Finds the Venda model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Venda the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Venda::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #11
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getVendaIdvendas()
 {
     return $this->hasMany(Venda::className(), ['idvenda' => 'venda_idvenda'])->viaTable('venda_has_produto', ['produto_idproduto' => 'idproduto']);
 }
 public function postRelatorioFantasia(Request $request, VendasService $vendasService)
 {
     $address = new EnderecosCapa();
     $address = $address->getCapa($request, 'App\\Models\\Cliente');
     $clientes = Venda::select('vendas.data_venda', 'vendas.num_talao', 'vendas.id as venda_id', DB::raw('sum(venda_itens.quantidade * venda_itens.preco_venda) as total'), 'clientes.fantasia', 'clientes.nome_razao', 'clientes.id', 'enderecos.estado', 'enderecos.cidade', 'enderecos.bairro')->leftJoin('venda_itens', 'vendas.id', '=', 'venda_itens.venda_id')->leftJoin('clientes', 'vendas.cliente_id', '=', 'clientes.id')->leftJoin('enderecos', function ($q) use($address) {
         $q->on('enderecos.enderecavel_id', '=', 'clientes.id');
         $q->where('enderecos.enderecavel_type', '=', 'App\\Models\\Cliente');
         $q->whereIn('estado', $address['estados']);
         $q->whereIn('cidade', $address['cidades']);
         $q->whereIn('bairro', $address['bairros']);
     })->where('data_venda', '>=', setDataBR($address['data_inicial']))->where('data_venda', '<=', setDataBR($address['data_final']))->groupBy('vendas.id')->orderBy('enderecos.estado')->orderBy('enderecos.cidade')->orderBy('enderecos.bairro')->orderBy('clientes.fantasia')->get();
     return view('clientes/relatorios/relatorio_fantasia_pdf', compact('address', 'collection_estados', 'collection_cidades', 'clientes'));
 }
Example #13
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getVendas()
 {
     return $this->hasMany(Venda::className(), ['vendedor_idvendedor' => 'idvendedor']);
 }
Example #14
0
 public function viewPdf($id)
 {
     $venda = Venda::with('cliente', 'venda_itens', 'lancamentos')->find($id);
     return view('vendas/view_pdf', compact('venda'));
     //$pdf = App::make('dompdf.wrapper');
     //$pdf->loadView('vendas/view_pdf', compact('venda'));
     //return $pdf->stream();
 }
Example #15
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getVendas()
 {
     return $this->hasMany(Venda::className(), ['forma_pagamento_idforma_pagamento' => 'idforma_pagamento']);
 }