-
datcanlong
Newbie
-
Posts: 4
Threads: 1
Joined: Nov 2019
Reputation:
0
11-07-2019, 10:38 AM
(This post was last modified: 11-07-2019, 06:30 PM by datcanlong.)
// In view
PHP Code: <?php $v = ""; if ($this->input->post('date_range')) { $dr = explode(' - ', $this->input->post('date_range')); $v .= "&start_date=" . $dr[0]; $v .= "&end_date=" . $dr[1]; } ?>
<div class="panel-body"> <?php echo form_open("panel/reports/repairbyuser"); ?> <div class="form-group"> <?=lang('cuanhanvien', 'cuanhanvien');?> <div class="input-group"> <div class="input-group-addon"> <i class="fa fa-user"></i> </div> <select required id="user_id" name="user_id" class="form-control user_id" style="width: 100%"> <option value=""><?=lang('chonnhanvien'); ?></option> <?php foreach($users as $user){ echo '<option value="'.$user->id.'">'.$user->first_name . ' ' . $user->last_name .'</option>'; } ?> </select> </div> </div> <div class="form-group"> <?=lang('report_Status', 'report_Status');?> <div class="input-group"> <div class="input-group-addon"> <i class="fas fa-money-bill-alt"></i> </div> <select required id="status" name="status" class="form-control status" style="width: 100%"> <option value=""><?=lang('chontinhtrang'); ?></option> <option value="1"><?=lang('delivered_user'); ?></option> <option value="2"><?=lang('inprogress_user'); ?></option> </select> </div> </div>
<div class="form-group"> <?= lang('date_range', 'date_range'); ?> <input class="form-control" type="text" name="date_range" class="date_range" id="date_range" value='<?= set_value('date_range'); ?>'> </div> <div class="form-group"> <div class="controls"> <?php echo form_submit('submit', $this->lang->line("submit_draw"), 'class="btn btn-primary"'); ?> </div> </div> <?php echo form_close(); ?>
// In Controllers
PHP Code: function repairbyuser() { $this->mPageTitle = lang('user_report_detail'); $this->render('reports/repairbyuser'); } function getrepairbyuser($pdf = NULL, $xls = NULL) { if ($this->input->get('start_date')) { $start_date = date('Y-m-d', strtotime($this->input->get('start_date'))) . " 00:00:00"; } else { $start_date = date('Y-m-d 00:00:00'); } if ($this->input->get('end_date')) { $end_date = date('Y-m-d', strtotime($this->input->get('end_date'))) . " 23:59:59"; } else { $end_date = date('Y-m-d 23:59:59'); }
$user_id = $this->input->post('user_id');
$status= $this->input->post('status');
$this->load->library('datatables'); $this->datatables ->select("date_opening, code, date_closing, name, CONCAT(reparation.category, ' ', reparation.model_name) as tenmay, defect, (grand_total-total) as tiendvsc") ->from('reparation'); if ($status == NULL) { $this->datatables->where('reparation.date_opening BETWEEN "' . $start_date . '" and "' . $end_date . '"') ->where('assigned_to', '0'); } else if ($status == '1') { $this->datatables->where('reparation.date_opening BETWEEN "' . $start_date . '" and "' . $end_date . '"') ->where('assigned_to', $user_id) ->where('date_closing is not null');
} else if ($status == '2') { $this->datatables->where('reparation.date_opening BETWEEN "' . $start_date . '" and "' . $end_date . '"') ->where('assigned_to', $user_id) ->where('date_closing is null'); } echo $this->datatables->generate();
}
Value name "user_id" and "status" cannot get in controllers. Try assign $user_id ='1', $status ='1' in controllers if clause work ok.
Sorry my english not good and this code not mine, i try edit it
Thanks so much
-
Wouter60
Posting Freak
-
Posts: 851
Threads: 38
Joined: Feb 2015
Reputation:
77
The controller function that should get the values for user_id and status is getrepairbyuser().
The form in your view points to the function: repairbyuser().
This way, the post values won't reach the right function.
Please, use the php code button on the button bar of the forum editor next time.
PHP Code: <?php public function repairbyuser() {
}
This is much better than plain text.
-
datcanlong
Newbie
-
Posts: 4
Threads: 1
Joined: Nov 2019
Reputation:
0
(11-07-2019, 12:48 PM)Wouter60 Wrote: The controller function that should get the values for user_id and status is getrepairbyuser().
The form in your view points to the function: repairbyuser().
This way, the post values won't reach the right function.
Please, use the php code button on the button bar of the forum editor next time.
PHP Code: <?php public function repairbyuser() {
}
This is much better than plain text.
Thanks U. I edited first post
This code not mine, i try to edit but i don't know why with getrepairbyuser(), (start_date and end_date) of date_range get value in controllers. But use
PHP Code: ($this->input->get('start_date')
not is
PHP Code: ($this->input->post('start_date')
getrepairbyuser() use for generate datatable,
I'm newbie with CI ^^!
-
datcanlong
Newbie
-
Posts: 4
Threads: 1
Joined: Nov 2019
Reputation:
0
Hi, after 1 day I think that problem is not in form_open
($start_date) and ($end_date) get by sAjaxSource with ($v) in function
PHP Code: function getrepairbyuser($pdf = NULL, $xls = NULL) { if ($this->input->get('start_date')) { $start_date = date('Y-m-d', strtotime($this->input->get('start_date'))) . " 00:00:00"; } else { $start_date = date('Y-m-d 00:00:00'); } if ($this->input->get('end_date')) { $end_date = date('Y-m-d', strtotime($this->input->get('end_date'))) . " 23:59:59"; } else { $end_date = date('Y-m-d 23:59:59'); }
and I don't know how to send incule $status, $user_id with $v to (getrepairbyuser) ^^!
In view ( sAjaxSource) is
PHP Code: $(document).ready(function () {
$('.date').datepicker({ dateFormat: 'mm-dd-yy' }); var oTable = $('#dynamic-table').dataTable({ "aaSorting": [[0, "desc"]], "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]], "iDisplayLength": 10, 'bProcessing': true, 'bServerSide': true, 'sAjaxSource': '<?= site_url('panel/reports/getrepairbyuser/?v=1' . $v) ?>', 'fnServerData': function (sSource, aoData, fnCallback) { aoData.push({ "name": "<?= $this->security->get_csrf_token_name() ?>", "value": "<?= $this->security->get_csrf_hash() ?>" }); $.ajax({'dataType': 'json', 'type': 'POST', 'url': sSource, 'data': aoData, 'success': fnCallback}); }, "aoColumns": [ null, null, null, null, null, null, {mRender: formatToMoney}, ], "fnFooterCallback": function (nRow, aaData, iStart, iEnd, aiDisplay) { var gtotal = 0; for (var i = 0; i < aaData.length; i++) { gtotal += parseFloat(aaData[aiDisplay[i]][6]); } var nCells = nRow.getElementsByTagName('th'); nCells[6].innerHTML = formatMoney(parseFloat(gtotal)); } }); });
^^!
-
datcanlong
Newbie
-
Posts: 4
Threads: 1
Joined: Nov 2019
Reputation:
0
Hiii, problem has been fixed
add more value for $v in View
PHP Code: $st = $this->input->post('status'); $ui = $this->input->post('user_id'); $v = ""; if ($this->input->post('date_range')) { $dr = explode(' - ', $this->input->post('date_range')); $v .= "&start_date=" . $dr[0]; $v .= "&end_date=" . $dr[1]; $v .= "&status=" .$st; $v .= "&user_id=" .$ui; }
then in controlles, get value by method get
PHP Code: $user_id = $this->input->get('user_id'); $status = $this->input->get('status');
it work, only one $v send 4 value to controllers in function getrepairbyuser
|