【发布时间】:2015-01-02 20:48:08
【问题描述】:
我正在创建一个页面,我可以在其中使用来自 jqueryui.com 的日期范围、日期选择器,而且我对 laravel 框架非常陌生。
我有如下雄辩的查询,
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'));
}
注意:此功能将显示模板上的所有数据
另一个功能是
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'));
}
我有一个名为 OrderByDAte.blade.php
的模板按日期销售
{{ 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>
也是显示表格的循环。
现在
**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
注意:我认为我的提交按钮不起作用。不知道为什么?
现在我想使用 datepicker 按日期过滤它,在我的路线中我知道我必须使用 post 并且在提交日期后我必须获取该范围内的数据表。
这里如何使用 $startDate 和 $endDate。在我雄辩的询问中。我必须为 startDate 输入 'w.created_at' 字段,还为 $endDate 输入 'w.created_at' 字段。 我想我必须像这样在我的函数中使用外观输入。
$startDate = Input::get('w.created_at');
$endDate = Input::get('w.created_at');
但是这个功能不起作用。
我目前正在使用引导日期选择器。但如果你认识其他人,那么你可以给我举个例子。
现在有两个模板用于
Route::get('orderbydate', array('as'=>'orderbydate', 'uses'=>'SalesFlatController@orderbydatesales'))
将所有数据放入我的模板中。
对于我使用的帖子
Route::get('result', array('as'=>'result', 'uses'=>'SalesFlatController@orderbydate'))
注意:我收到类似 Missing 1 参数的错误。
任何人都可以帮助我知道我哪里出错了吗?
【问题讨论】:
标签: laravel-4 eloquent jquery-ui-datepicker laravel-routing