public function multisalarySlippdf_mail () {
$this->load->helper('form');
$month = $this->input->post('month');
$year = $this->input->post('year');
$employee_id = $this->input->post('employee_id');
$department = $this->input->post('department');
$wihoutemail = $this->input->post('wihoutemail');
$this->load->model('Report_model', 'report');
//new modify code...
if ($month > 9) {
$e_Setupdate = $year . '-' . $month . '-01';
}
else {
$e_Setupdate = $year . '-0' . $month . '-01';
}
// end here ............
if (!empty($employee_id)) {
$salaries = $this->report->find_oneemployee_ids($employee_id);
}
else {
$salaries = $this->report->find_employee_id($department);
}
foreach ($salaries as $sal) {
if (!empty($wihoutemail)) {
if ($sal->official_email <> '' OR $sal->personal_email <> '') {
goto end;
}
}
$mon_dat = $this->report->find_all_monhtlydata($sal->employee_id, $month, $year);
$n_data = $this->report->find_pay_ledger_data_oneemployee($sal->employee_id, $month, $year);
$m_data = $this->report->find_workingdays($sal->employee_id, $month, $year);
$esetup_data = $this->report->find_basicpay($sal->employee_id, $e_Setupdate);
if (!empty($esetup_data)) {
foreach ($esetup_data as $setup) {
if ($setup->code == 'BSCRT') {
$basicpay = $setup->amount;
}
}
}
switch ($month) {
case "1":
$month_txt = "Jan" . '-' . $year;
break;
case "2":
$month_txt = "Feb" . '-' . $year;
break;
case "3":
$month_txt = "Mar" . '-' . $year;
break;
case "4":
$month_txt = "Apr" . '-' . $year;
break;
case "5":
$month_txt = "May" . '-' . $year;
break;
case "6":
$month_txt = "jun" . '-' . $year;
break;
case "7":
$month_txt = "Jul" . '-' . $year;
break;
case "8":
$month_txt = "Aug" . '-' . $year;
break;
case "9":
$month_txt = "Sep" . '-' . $year;
break;
case "10":
$month_txt = "Oct" . '-' . $year;
break;
case "11":
$month_txt = "Nov" . '-' . $year;
break;
case "12":
$month_txt = "Dec" . '-' . $year;
break;
default:
"";
}
$d = [];
$k = 0;
$negative = $positive = [];
foreach ($n_data as $data) {
$d[0] = $data->code;
$d[1] = $data->amount;
if ($d[1] >= 0) {
array_push($positive, $d);
}
else if ($d[1] < 0) {
array_push($negative, $d);
}
$k++;
}
if (!empty($m_data)) {
foreach ($m_data as $mdata) {
$leave_days = $mdata->leave_days;
$working_days = $mdata->working_days;
$present = $mdata->present_days;
$absent = $mdata->absent_days;
$extraday = $mdata->extradays_inholiday;
$additionalday = $mdata->additional_days;
$weekoff = $mdata->week_off;
$dojDaysDiff = 0;
$this->load->model('Income_model', 'income');
$doj = $this->income->find_employementdetails($sal->employee_id);
$dojDays = date_diff(date_create($doj->joining_date), date_create($e_Setupdate));
if ($doj->joining_date > $e_Setupdate) {
$dojDaysDiff = $dojDays->format("%a");
}
}
}
else {
$leave_days = 0;
$working_days = 0;
$present = 0;
$absent = 0;
$extraday = 0;
$additionalday = 0;
$weekoff = 0;
}
$max = max(count($positive), count($negative));
$grossamount = 0;
$grossdeduction = 0;
for ($i = 0; $i <= $max; $i++) {
if (isset($positive[$i])) {
$grossamount += $positive[$i][1];
}
if (isset($negative[$i])) {
$grossdeduction += $negative[$i][1];
}
$data1 = array(
'salaries' => $sal,
'positive' => $positive,
'negative' => $negative,
'max' => $max,
'month' => $month_txt,
'grossamount' => $grossamount,
'grossdeduction' => $grossdeduction,
'leaves' => $leave_days,
'workingDays' => $working_days,
'present' => $present,
'absent' => $absent,
'extraday' => $extraday,
'basicpay' => $basicpay,
'additionalday' => $additionalday,
'weekoff' => $weekoff,
'dojDaysDiff' => $dojDaysDiff
);
$html = $this->load->view('admin/salarySlippdf', $data1, true);
}
$file = '';
$file = 'Salary-Slip' . $sal->employee_id;
$pdfFilePath = "";
$pdfFilePath = FCPATH . "uploads/" . $file . ".pdf";
$this->load->library('m_pdf'); // load MPDF library
$mpdf = new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output($pdfFilePath, "F");
//$this->m_pdf->pdf->WriteHTML($html);
//$this->m_pdf->pdf->Output($pdfFilePath, "F");
//$this->m_pdf->pdf->Output($pdfFilePath, "D");
$emailid = $sal->official_email;
if (!empty($emailid)) {
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'pccplatiq07@gmail.com',
'smtp_pass' => 'pccpl55@Atiq07',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$subject = " Salary Slip";
$message = $html;//"Please Download file";
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('mohd.atiq07@gmail.com');
$this->email->to($emailid);
$this->email->subject($subject);
$this->email->message($message);
$this->email->attach($pdfFilePath);
//$this->email->attach($this->m_pdf->pdf->WriteHTML($html));
if ($this->email->send()) {
echo 'Email send.';
$this->email->clear(true);
}
else {
show_error($this->email->print_debugger());
}
}
end:
unlink($pdfFilePath);
}
$this->m_pdf->pdf->Output($pdfFilePath, "D");
return redirect('admin/report/salaryslipmail');
}
Это полный код для динамического генерирования квитанции о зарплате в pdf, а также получения квитанции о зарплате по почте. Работает идеально для меня. :)