-2
I am in trouble when accessing a column in the Windows query Builder, the following code works in Sql Workbench.
Vendas::selectRaw('if(faturamento.Codfaturamento is null, vendas.totalvenda, faturamento.valor) AS vlrFatura')
->leftjoin('faturamento', 'faturamento.CodVenda','=','vendas.CodVenda')
->leftjoin('cartaoaux', 'cartaoaux.idfatura','=','faturamento.Codfaturamento')
->leftjoin('cartao', 'cartaoaux.idcartao','=','cartao.id')
->leftjoin('chequeterceiros', 'chequeterceiros.CodCheque','=','faturamento.CodCheque')
->leftjoin('boleto', 'boleto.idFatura','=','faturamento.Codfaturamento')
->leftjoin('boleto_cedente', 'boleto_cedente.id','=','boleto.idCedente')
->whereRaw('day(vendas.dataemissao)=(day(NOW()) -1) and month(vendas.dataemissao)=(month(NOW())) and year(vendas.dataemissao)=(year(NOW())) and
CASE
WHEN faturamento.tipo = "Cartao" THEN if(cartao.tipo="D","À Vista", "A Prazo")
WHEN faturamento.tipo = "Cheque" THEN if(DATE(chequeterceiros.DataVencimento) > DATE(vendas.dataemissao), "A Prazo", "À Vista")
WHEN faturamento.tipo = "Boleto" THEN "A Prazo"
WHEN faturamento.tipo = "Conta" THEN "A Prazo"
WHEN faturamento.tipo = "DebitoCC" THEN "A Prazo"
WHEN vendas.Status = "Conta cliente" THEN "A Prazo"
WHEN faturamento.tipo = "-" then "A Prazo"
else "À Vista" end = "A Prazo"')
->sum('vlrFatura');
I need to sum up the "vlrFatura" column that comes from the if(faturamento.Codfaturamento is null, vendas.totalvenda, faturamento.valor) AS vlrFatura, and when I do the ->sum('vlrFatura') he always returns to me:
Column not found: 1054 Unknown column 'vlrFatura' in 'field list' (SQL: select sum(vlrFatura) as Aggregate from vendas left Join faturamento on faturamento.CodVenda = vendas.CodVenda left Join cartaoaux on cartaoaux.idfatura = faturamento.Codfaturamento left Join cartao on cartaoaux.idcartao = cartao.id left Join chequeterceiros on chequeterceiros.CodCheque = faturamento.CodCheque left Join boleto on boleto.idFatura = faturamento.Codfaturamento left Join boleto_cedente on boleto_cedente.id = boleto.idCedente Where day(sales.outgoing date)=(day(NOW()) -1) and Month(sales.outgoing date)=(Month(NOW())) and year(sales.outgoing date)=(year(NOW())) and CASE WHEN billing.type = "Card" THEN IF(card.type="D","AT SIGHT", "AT TIME") WHEN billing.type = "Check" THEN if(DATE(Checkers.Date) > DATE(Sales.Date Issued), "On Time", "On Time") WHEN Billing.Type = "Ticket" THEN "On Time" WHEN Billing.Type = "Account" THEN "On Time" WHEN Billing.Type = "Debitocc" THEN "On Time" WHEN Sales. Status = "Customer Account" THEN "On Time" WHEN billing.type = "-" then "On Time" Else "On Time" end = "On Time")
From now on I thank you all.