/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create($id) { $venda = Venda::find($id); $venda_itens = VendaItem::where('venda_id', $id)->with('produto')->get(); $produtos = Produto::orderBy('nome')->get(['id', 'nome', 'referencia']); $itens = VendaItem::with('produto')->where('venda_id', $id)->get(); $total_venda = Venda::totalVenda($id); return view('venda_itens.create', compact('venda', 'produtos', 'venda_itens', 'itens', 'total_venda')); }
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')]; }