uxsolutions formulario example eternicode espaƱol con bootstrap laravel-4 eloquent jquery-ui-datepicker laravel-routing

laravel-4 - example - formulario con datepicker en laravel



Laravel Datepicker y consulta elocuente (1)

Necesitas cambiar:

public function orderbydate($startDate, $endDate)

a:

public function orderbydate()

ya que estás obteniendo esos valores de Input::get() . Ponerías esas variables en la llamada a la función solo si esas variables provienen de variables en la ruta, es decir:

Route::get(''result/{startDate}/{endDate}'', array(''as''=>''result'', ''uses''=>''SalesFlatController@orderbydate''))

Estoy haciendo una página donde puedo usar el guardabosques, datepicker de jqueryui.com y estoy muy contento con laravel Framework.

Tengo la consulta elocuente de la siguiente manera,

public function orderbydate() { $order =DB::table(''sales_flat_order_items as s'') ->leftJoin(''sales_flat_orders as w'', ''w.entity_id'',''='',''s.order_id'') ->select(array(DB::Raw(''sum(s.amount_refunded) as amount_refunded''), DB::Raw(''sum(s.row_total) as row_total''), DB::Raw(''sum(s.discount_amount) as discount_amount''), DB::Raw(''sum(s.tax_amount) as tax_amount''), DB::Raw(''sum(s.qty_ordered) as qty_ordered''), DB::Raw(''sum(w.subtotal) as subtotal''), DB::Raw(''sum(w.total_invoiced) as total_invoiced''), DB::Raw(''sum(w.shipping_amount) as shipping_amount''))) ->where(''qty_canceled'',''='',''0'') ->where(''status'',''!='',''canceled'') ->get(); $orderbydate = DB::table(''sales_flat_order_items as s'') ->leftJoin(''sales_flat_orders as w'', ''w.entity_id'',''='',''s.order_id'') ->select(array(DB::Raw(''sum(s.amount_refunded) as amount_refunded''), DB::Raw(''sum(s.row_total) as row_total''), DB::Raw(''sum(s.discount_amount) as discount_amount''), DB::Raw(''sum(s.tax_amount) as tax_amount''), DB::Raw(''sum(s.qty_ordered) as qty_ordered''), DB::Raw(''sum(w.subtotal) as subtotal''), DB::Raw(''DATE(w.created_at) days''), DB::Raw(''sum(w.total_invoiced) as total_invoiced''), DB::Raw(''sum(w.shipping_amount) as shipping_amount''))) ->where(''qty_canceled'',''='',''0'') ->where(''status'',''!='',''canceled'') ->groupBy(''days'') ->orderBy(''s.created_at'') ->paginate(10); return View::make(''sales_flat_orders.orderbydate'', compact(''order'',''orderbydate'')); }

Nota: esta función le mostrará todos los datos en la plantilla

Otra función es

public function orderbydate1() { $startDate = Input::get(''w.created_at''); $endDate = Input::get(''w.created_at''); $order1 =DB::table(''sales_flat_order_items as s'') ->leftJoin(''sales_flat_orders as w'', ''w.entity_id'',''='',''s.order_id'') ->select(array(DB::Raw(''sum(s.amount_refunded) as amount_refunded''), DB::Raw(''sum(s.row_total) as row_total''), DB::Raw(''sum(s.discount_amount) as discount_amount''), DB::Raw(''sum(s.tax_amount) as tax_amount''), DB::Raw(''sum(s.qty_ordered) as qty_ordered''), DB::Raw(''sum(w.subtotal) as subtotal''), DB::Raw(''sum(w.total_invoiced) as total_invoiced''), DB::Raw(''sum(w.shipping_amount) as shipping_amount''))) ->where(''qty_canceled'',''='',''0'') ->where(''status'',''!='',''canceled'') ->get(); $orderbydate1 = DB::table(''sales_flat_order_items as s'') ->leftJoin(''sales_flat_orders as w'', ''w.entity_id'',''='',''s.order_id'') ->select(array(DB::Raw(''sum(s.amount_refunded) as amount_refunded''), DB::Raw(''sum(s.row_total) as row_total''), DB::Raw(''sum(s.discount_amount) as discount_amount''), DB::Raw(''sum(s.tax_amount) as tax_amount''), DB::Raw(''sum(s.qty_ordered) as qty_ordered''), DB::Raw(''sum(w.subtotal) as subtotal''), DB::Raw(''DATE(w.created_at) days''), DB::Raw(''sum(w.total_invoiced) as total_invoiced''), DB::Raw(''sum(w.shipping_amount) as shipping_amount''))) ->whereBetween(''w.created_at'',array($startDate,$endDate)) ->where(''qty_canceled'',''='',''0'') ->where(''status'',''!='',''canceled'') ->groupBy(''days'') ->orderBy(''s.created_at'') ->paginate(10); return View::make(''sales_flat_orders.result'', compact(''order'',''orderbydate1'')); }

Tengo una plantilla llamada OrderByDAte.blade.php

Ventas por fecha

{{ Form::open() }} <label for="from">From</label> <input type="text" id="from" name="from"> <label for="to">to</label> <input type="text" id="to" name="to"> <input type="submit" value="Submit" class="btn btn-info btn-block"> {{ Form::close() }} <script> $(function() { $( "#from" ).datepicker({ defaultDate: "+1w", changeMonth: true, numberOfMonths: 3, onClose: function( selectedDate ) { $( "#to" ).datepicker( "option", "minDate", selectedDate ); } }); $( "#to" ).datepicker({ defaultDate: "+1w", changeMonth: true, numberOfMonths: 3, onClose: function( selectedDate ) { $( "#from" ).datepicker( "option", "maxDate", selectedDate ); } }); }); </script>

También el bucle que muestra la tabla.

Y ahora

**result.blade.php** which displays the data. <table class="table table-striped table-bordered table-hover" id="dataTables-example"> <thead> <tr class="odd gradeX"> <th>DATE</th> <th>Items Ordered</th> <th>Subtotal</th> <th>Tax Amount</th> <th>Discount Amount</th> <th>Row Total</th> <th>Refunded</th> <th>Total Invoiced</th> <th>Shipping Amount</th> </tr> </thead> @foreach($orderbydate1 as $s) <tbody> <tr class="odd gradeX"> <td>{{date("d F, Y",strtotime($s->days))}}</td> <td>{{ round($s->qty_ordered, 2) }}</td> <td>{{round($s->subtotal,2)}}</td> <td>{{round($s->tax_amount,2)}}</td> <td>{{round($s->discount_amount,2)}}</td> <td>{{round($s->row_total,2)}}</td> <td>{{round($s->amount_refunded,2)}}</td> <td>{{round($s->total_invoiced,2)}}</td> <td>{{round($s->shipping_amount,2)}}</td> </tr> @endforeach

Nota: Creo que mi botón Enviar no funciona. No sé por qué?

Ahora quiero usar datepicker para filtrar esto por fecha, en mis rutas sé que tengo que usar la publicación y después de enviar la fecha debo obtener la tabla de datos en ese rango.

Cómo usar $ startDate y $ endDate aquí. en mi consulta elocuente. Tengo que tomar el campo de entrada ''w.created_at'' para mi startDate y también ''w.created_at'' para $ endDate. Creo que tengo que usar entrada de fachada en mi función de esta manera.

$startDate = Input::get(''w.created_at''); $endDate = Input::get(''w.created_at'');

Pero esta función no funciona.

Actualmente estoy usando el marcador de fecha bootstrap. Pero si conoces a otro, entonces U me puede dar ejemplos.

Ahora hay dos plantillas que utilizo para el

Route::get(''orderbydate'', array(''as''=>''orderbydate'', ''uses''=>''SalesFlatController@orderbydatesales''))

para obtener todos los datos en mi plantilla.

Y para el post que uso

Route::get(''result'', array(''as''=>''result'', ''uses''=>''SalesFlatController@orderbydate''))

Nota: me sale un error como Missing 1 argumento.

¿Alguien puede ayudarme un poco simplemente sabiendo dónde me estoy equivocando?