我需要搜索特定日期范围内的数据。这就是我所做的
这是我的 模型
public function rangeDate($start_date, $end_date){
$query = $this->db->select($this->tables['invent_inv'].'.id,'.$this->tables['invent_inv'].'.inv_type,'.$this->tables['invent_inv'].'.inv_cno,'.$this->tables['invent_cust'].'.id as custid,'.$this->tables['invent_cust'].'.cust_name,'.$this->tables['invent_inv'].'.inv_price, '.$this->tables['invent_inv'].'.inv_tax,'.$this->tables['invent_inv'].'.pay_due, SUM('.$this->tables['invent_sales'].'.paid_amnt) as payment,'.$this->tables['invent_inv'].'.timestamp')
->join($this->tables['invent_cust'], $this->tables['invent_inv'].'.cust_id='.$this->tables['invent_cust'].'.id','LEFT')
->join($this->tables['invent_sales'], $this->tables['invent_inv'].'.inv_cno='.$this->tables['invent_sales'].'.inv_cno','LEFT')
->where($this->tables['invent_inv'].'.status !=', 1)
->where($this->tables['invent_inv'].'.status !=', 0)
->where($this->tables['invent_inv'].'.timestamp >=', $start_date)
->where($this->tables['invent_inv'].'.timestamp <=', $end_date)
->group_by($this->tables['invent_sales'].".inv_cno")
->group_by($this->tables['invent_inv'].".inv_cno")
->group_by($this->tables['invent_inv'].".timestamp")
->get($this->tables['invent_inv']);
return $query;
}
这是我的 CONTROLLER
public function rangeDates(){
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
$return = $this->ion_auth->rangeDate($start_date,$end_date);
echo json_encode($return);
}
这是ajax JS
$('.input-daterange').datepicker({
todayBtn: 'linked',
format: "yyyy-mm-dd",
autoclose: true
});
function fetch_data(start_date='', end_date=''){
var dataTable = $('#table-sales').DataTable({
"processing": true,
"serverSide": true,
"order":[],
"ajax":{
url: "sales/rangeDates",
type: "POST",
data:{
start_date:start_date, end_date:end_date
},
success:function(data){
$('#table-sales').html(data);
}
}
});
}
$('#search').click(function(){
var inv_type = $('#invType').val();
var start_date = $('#start_date').val();
var end_date = $('#end_date').val();
if(start_date != '' && end_date != '' && inv_type != 0){
$('#table-sales').DataTable().destroy();
fetch_data(start_date,end_date);
}else{
alert('Both Date is Required and Choose what to show!');
}
});
现在我的问题是,当我单击视图上的搜索按钮时,在屏幕上会弹出一个处理对话框,并且控制台上没有错误。所以我尝试查看网络,这是我发现的内容。
它们都是空的,我不知道为什么。有人可以指出我在这方面做错了什么。预先谢谢你。
更多信息:这是我的
查看
<div class="box-body">
<div class="table-responsive">
<div class="row">
<div class="input-daterange">
<div class="col-md-4">
<div class="form-group start-date">
<label>From</label>
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" class="form-control pull-right" id="start_date" name="start_date">
</div>
<!-- /.input group -->
</div>
</div>
<div class="col-md-4">
<div class="form-group end-date">
<label>To</label>
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" class="form-control pull-right" id="end_date" name="end_date">
</div>
<!-- /.input group -->
</div>
</div>
<div class="col-md-2">
<label>Select</label>
<select class="form-control select2" id="invType" name="invType" style="width: 100%;">
<option value="0" />Select</option>
<option value="1">Department Store</option>
<option value="2">Local</option>
<option value="3">Provincial</option>
<option value="4">UNITOP</option>
<option value="5">GAISANO</option>
</select>
</div>
<div class="col-md-2">
<div class="form-group">
<label>Go </label>
<div class="input-group date">
<button class="btn btn-warning btn-md btn-search" name = "search" id="search">Search!</button>
</div>
<!-- /.input group -->
</div>
</div>
</div>
</div>
<table id="table-sales" class="table table-bordered table-striped">
<thead>
<tr>
<th>DR</th>
<th>Date</th>
<th>Customer</th>
<th>Price</th>
<th>Paid Amnt</th>
<th>Balance</th>
<th>Receipt</th>
<th>Remarks</th>
<th>Items</th>
<th style="width:55px;">Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($sales_inv as $inv) {
$balance = $inv->inv_price-$inv->payment;
$status = "";
$payment = $inv->payment;
if ($inv->inv_type==1) {
$status = "Department Store";
}elseif($inv->inv_type==2){
$status = "Local";
}elseif($inv->inv_type==3){
$status = "Provincial";
}elseif($inv->inv_type==4){
$status = "UNITOP";
}elseif($inv->inv_type==5){
$status = "GAISANO";
}
?>
<tr class="row-<?php echo $inv->id; ?>">
<td><a href="#" class="btn-inv-show" data-value="<?php echo $inv->inv_cno; ?>@<?php echo $inv->id; ?>"><?php echo $inv->inv_cno; ?></a></td>
<td><?php echo date("M d, Y", strtotime($inv->timestamp)); ?></td>
<td><?php echo $inv->cust_name; ?></td>
<td class="price-<?php echo $inv->inv_cno; ?>">Php <?php echo number_format($inv->inv_price,2); ?></td>
<td class="payment-<?php echo $inv->inv_cno; ?>">Php <?php echo number_format($payment,2); ?></td>
<td class="bal-<?php echo $inv->inv_cno; ?>">Php <?php echo number_format($balance,2); ?></td>
<td><?php echo $status; ?></td>
<td>
<button class="btn btn-info btn-sm btn-rem" data-value="<?php echo $inv->id; ?>">View Remarks
</button>
</td>
<td>
<button class="btn btn-success btn-sm btn-item" data-value="<?php echo $inv->inv_cno; ?>">View Item
</button>
</td>
<td>
<button class="btn btn-primary btn-xs btn-print" data-value="<?php echo $inv->inv_cno; ?>"><i class="fa fa-print"></i></button>
<button class="btn btn-warning btn-xs btn-add-pay" data-value="<?php echo $inv->inv_cno; ?>@<?php echo $inv->custid; ?>@<?php echo $inv->id; ?>"><i class="fa fa-credit-card"></i></button>
<button class="btn btn-danger btn-xs btn-edit-pay" data-value="<?php echo $inv->inv_cno; ?>@<?php echo $inv->custid; ?>@<?php echo $inv->id; ?>"><i class="fa fa-edit"></i></button>
</td>
</tr>
<?php } ?>
</tbody>
<tfooter>
<tr>
<th>DR</th>
<th>Date</th>
<th>Customer</th>
<th>Price</th>
<th>Paid Amnt</th>
<th>Balance</th>
<th>Receipt</th>
<th>Remarks</th>
<th style="width:55px;">Action</th>
</tr>
</tfooter>
</table>
</div>
<!-- /.table-responsive -->
</div>
</div>
<!-- /.box -->
</section>
<!-- right col -->
</div>
答案 0 :(得分:1)
在基于日期范围从数据库中获取数据时,我遇到了类似的问题。我通过在开始日期添加00:00:00
和在结束日期添加23:59:59
解决了该问题。通过将23:59:59
添加到结束日期意味着它实际上将获取最后一个日期和时间的数据。检查是否可以解决您的问题。
在您的模型中执行
public function rangeDate($start_date, $end_date){
$start_date = $start_date .' 00:00:00';
$end_date = $end_date . ' 23:59:59';
$query = $this->db->select($this->tables['invent_inv'].'.id,'.$this->tables['invent_inv'].'.inv_type,'.$this->tables['invent_inv'].'.inv_cno,'.$this->tables['invent_cust'].'.id as custid,'.$this->tables['invent_cust'].'.cust_name,'.$this->tables['invent_inv'].'.inv_price, '.$this->tables['invent_inv'].'.inv_tax,'.$this->tables['invent_inv'].'.pay_due, SUM('.$this->tables['invent_sales'].'.paid_amnt) as payment,'.$this->tables['invent_inv'].'.timestamp')
->join($this->tables['invent_cust'], $this->tables['invent_inv'].'.cust_id='.$this->tables['invent_cust'].'.id','LEFT')
->join($this->tables['invent_sales'], $this->tables['invent_inv'].'.inv_cno='.$this->tables['invent_sales'].'.inv_cno','LEFT')
->where($this->tables['invent_inv'].'.status !=', 1)
->where($this->tables['invent_inv'].'.status !=', 0)
->where($this->tables['invent_inv'].'.timestamp >=', $start_date)
->where($this->tables['invent_inv'].'.timestamp <=', $end_date)
->group_by($this->tables['invent_sales'].".inv_cno")
->group_by($this->tables['invent_inv'].".inv_cno")
->group_by($this->tables['invent_inv'].".timestamp")
->get($this->tables['invent_inv']);
return $query;
}
答案 1 :(得分:1)