public function getNewOrders() { $stato = 2; $orders = \DB::select(\DB::raw("select ordine as new_orders from (select * from ordini_stato where (data_creazione,ordine) in (select max(data_creazione), ordine from ordini_stato group by ordine) order by ordine desc) os where stato ='" . $stato . "'")); $orders_id = json_decode(json_encode($orders), true); //Utilities::objectToArray($orders); $ordini = $this->ordine->where('cancellato', '=', false)->whereIn('id', $orders_id)->orderby('id', 'desc')->with('utenti.clienti')->with('stati')->paginate(20); $stati = $this->stato->get(); return view('ordini.index', compact('ordini', 'stati')); //var_dump($ordini); }
/** * Run the database seeds. * * @return void */ public function run() { $json = File::get(database_path() . '/data/ordini_testa.json'); $data = json_decode($json); foreach ($data as $obj) { try { OrdineTesta::create(array('id' => $obj->id, 'utente' => $obj->utente, 'costo' => $obj->costo, 'costospedizione' => $obj->costospedizione, 'sconto' => $obj->sconto, 'tipo_pagamento' => $obj->tipo_pagamento, 'data_creazione' => $obj->data_creazione)); } catch (QueryException $e) { var_dump($e->errorInfo); } } $this->command->info("tabella ordini_testa popolata"); }
public function search(Request $request) { $field = $request->get("field"); $operator = $request->get("operator"); if ($operator == "like") { $value = "%" . trim($request->get("value")) . "%"; } else { $value = trim($request->get("value")); } if ($field == "id" || $field == "ordine") { $operator = "="; $value = intval($request->get("value"), 0); } try { if ($field == "id" || $field == "cliente") { if ($field == "cliente") { $value = strtolower($value); $field = "username"; } $ordini = $this->ordine->with('utenti.clienti')->with('stati')->whereHas('utenti', function ($q) use($field, $operator, $value) { $q->where($field, $operator, $value); })->orderby('id', 'desc')->paginate(20); } else { if ($field == "ordine") { $field = "id"; } if ($field == "stato") { $value = intval($request->get("order-status-value")); $operator = "="; $ordini = $this->ordine->with('utenti.clienti')->with('stati')->whereHas('stati', function ($q) use($field, $operator, $value) { $q->where($field, $operator, $value); })->orderby('id', 'desc')->paginate(20); } else { $ordini = $this->ordine->with('utenti.clienti')->with('stati')->where($field, $operator, $value)->orderby('id', 'desc')->paginate(20); } } if (count($ordini) == 0) { $ordini = $this->ordine->where('cancellato', '=', false)->with('utenti.clienti')->with('stati')->orderby('id', 'desc')->paginate(20); } $stati = $this->stato->get(); return view('ordini.index', compact('ordini', 'stati')); } catch (QueryException $err) { $ordini = $this->ordine->where('cancellato', '=', false)->orderby('id', 'desc')->with('utenti.clienti')->with('stati')->paginate(20); $stati = $this->stato->get(); return view('ordini.index', compact('ordini', 'stati')); } }