如何从post方法获取值并在foreach循环中爆炸。
public function generate_all_payslip() {
$data['title'] = "Generate All Payslip";
$this->payroll_model->_table_name = "tbl_department"; //table name
$this->payroll_model->_order_by = "department_id";
$all_dept_info = $this->payroll_model->get();
// get all department info and designation info
$dataalldep = array();
foreach ($all_dept_info as $v_dept_info) {
$dataalldep['all_department_info'][] = $this->payroll_model->get_add_department_by_id($v_dept_info->department_id);
}
foreach ($dataalldep['all_department_info'] as $keyemp=>$valemparray) {
$datae = array();
foreach($valemparray as $k=>$v) {
$datae['flag'] = 1;
$datae['designations_id'] = $v->designations_id;
$this->input->post('gapsbtn', TRUE);
$dataee['payment_date'] = $this->input->post('payment_date', TRUE);
$datepaymentmades = explode("-",$dataee['payment_date']);
$currentyears = $datepaymentmades[0];
$currentmonths = $datepaymentmades[1];
$currentyear = $currentyears ;
$currentmonth = $currentmonths ;
$datae['payment_date'] = $currentyear."-".$currentmonth;
$datae['employee_info'] = $this->payroll_model->get_emp_salary_list($emp = NULL, $datae['designations_id']);
$basicwagessalaey = $datae['employee_info'][0]->basic_salary;
$gross = $datae['employee_info'][0]->house_rent_allowance + $datae['employee_info'][0]->medical_allowance + $datae['employee_info'][0]->special_allowance + $datae['employee_info'][0]->fuel_allowance + $datae['employee_info'][0]->phone_bill_allowance + $datae['employee_info'][0]->other_allowance;
$deduction = $datae['employee_info'][0]->tax_deduction + $datae['employee_info'][0]->provident_fund + $datae['employee_info'][0]->other_deduction;
$net_extra = $gross - $deduction;
$workingdayscurrentmonth = $this->countDays($currentyear,$currentmonth, array(0));
$perdaysaaryperuser = $basicwagessalaey/30;
### full day ###
$queryfullday = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='1' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
$attendancecountarray = $queryfullday->result_array();
$attendancecounting = $attendancecountarray[0]['present_days'];
//$attendancecounting = 24;
$data['attendancecounting'] = $attendancecountarray[0]['present_days'];
if ($attendancecounting == $workingdayscurrentmonth) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*30)+$perdaysaaryperuser;
} else {
if ($workingdayscurrentmonth == 27) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*3);
}
if ($workingdayscurrentmonth == 26) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*4);
}
if ($workingdayscurrentmonth == 25) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*5);
}
if ($workingdayscurrentmonth == 24) {
$data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*6);
}
}
### half day ###
$queryhalfday = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='2' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
$attendancecountarray_half = $queryhalfday->result_array();
$attendancecounting_half = $attendancecountarray_half[0]['present_days'];
//$attendancecounting_half = 1;
$data['attendancecounting_half'] = $attendancecountarray_half[0]['present_days'];
$data['totalmonthwages_half'] = ($perdaysaaryperuser/2)*$attendancecounting_half;
### leave day ###
$queryleave = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='3' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
$attendancecountarray_leave = $queryleave->result_array();
$attendancecounting_leave = $attendancecountarray_leave[0]['present_days'];
//$attendancecounting_leave = 2;
$data['attendancecounting_leave'] = $attendancecountarray_leave[0]['present_days'];
$data['totalmonthwages_leave'] = $perdaysaaryperuser*$attendancecounting_leave;
### absent day ###
$queryabsent = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='0' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
$attendancecountarray_absent = $queryabsent->result_array();
$attendancecounting_absent = $attendancecountarray_absent[0]['present_days'];
//$attendancecounting_absent = 1;
$data['attendancecounting_absent'] = $attendancecountarray_absent[0]['present_days'];
$data['totalmonthwages_absent'] = $perdaysaaryperuser*$attendancecounting_absent;
######################
$querylastsalary = $this->db->query("SELECT * FROM `tbl_salary_payment` WHERE employee_id='".$data['employee_info'][0]->employee_id."' Order BY salary_payment_id desc LIMIT 1");
$lastsalary = $querylastsalary->result_array();
$paymentamountlastmonth = $lastsalary[0]['payment_amount'];
$data['totalmonthwage'] = ($data['totalmonthwagesfullday']+$data['totalmonthwages_half']+$net_extra)-($data['totalmonthwages_absent']);
if ($paymentamountlastmonth < 0) {
$data['totalmonthwages'] = $data['totalmonthwage']+$paymentamountlastmonth;
} else {
$data['totalmonthwages'] = $data['totalmonthwage'];
}
########## insert into tbl_salary_payment ##########
if ($datae['employee_info'][0]->employee_id !="") {
$dbinsert = array();
$dbinsert['employee_id'] = $datae['employee_info'][0]->employee_id;
$dbinsert['basic_salary'] = $datae['employee_info'][0]->basic_salary;
$dbinsert['house_rent_allowance'] = $datae['employee_info'][0]->house_rent_allowance;
$dbinsert['medical_allowance'] = $datae['employee_info'][0]->medical_allowance;
$dbinsert['special_allowance'] = $datae['employee_info'][0]->special_allowance;
$dbinsert['fuel_allowance'] = $datae['employee_info'][0]->fuel_allowance;
$dbinsert['phone_bill_allowance'] = $datae['employee_info'][0]->phone_bill_allowance;
$dbinsert['other_allowance'] = $datae['employee_info'][0]->other_allowance;
$dbinsert['tax_deduction'] = $datae['employee_info'][0]->tax_deduction;
$dbinsert['provident_fund'] = $datae['employee_info'][0]->provident_fund;
$dbinsert['other_deduction'] = $datae['employee_info'][0]->other_deduction;
$dbinsert['payment_for_month'] = $datae['payment_date'];
$dbinsert['payment_type'] = 'Cash Payment';
$dbinsert['payment_date'] = date('Y-m-d H:i:s');
$dbinsert['payment_amount'] = round($totalmonthwages);
$dbinsert['present'] = $attendancecounting;
$dbinsert['halfday'] = $attendancecounting_half;
$dbinsert['leave'] = $attendancecounting_leave;
$dbinsert['absent'] = $attendancecounting_absent;
$insertedid = $this->payroll_model->insertpayrolldata($dbinsert);
####### insert into tbl_salary_payslip ###
$dbinsertpayslip = array();
$dbinsertpayslip['payslip_number'] = date('Ymd');
$dbinsertpayslip['salary_payment_id'] = $insertedid;
$this->payroll_model->insertpayslipdata($dbinsertpayslip);
}
}
}
$data['subview'] = $this->load->view('admin/payroll/generate_all_payslip', $data, TRUE);
$this->load->view('admin/_layout_main', $data);
}
仅使用此代码错误
$this->input->post('gapsbtn', TRUE);
$dataee['payment_date'] = $this->input->post('payment_date', TRUE);
$datepaymentmades = explode("-",$dataee['payment_date']);
$currentyears = $datepaymentmades[0];
$currentmonths = $datepaymentmades[1];
$currentyear = $currentyears ;
$currentmonth = $currentmonths ;
如果我使用
$currentyear = date('Y');
$currentmonth = date('m');
它的工作正常。但我想使用我选择的日期而不是当前的系统日期 我该如何更正此代码。目前我看到这个错误
此页面无法使用
example.com目前无法处理此请求。
HTTP HTTP ERROR 500
答案 0 :(得分:0)
使用下面提到的行是否有任何具体的原因?
$datepaymentmades = explode("-",$dataee['payment_date']);
或者您告诉我们您想要做什么。
如果您想要月份,日期和年份,请查看以下内容。
$paymentDate = strtotime($dataee['payment_date']);
$month = date("m",strtotime($paymentDate));
$year = date("Y",strtotime($paymentDate));
$day = date("d",strtotime($paymentDate));