query("SELECT a.*, b.staff_idno, b.staff_name, b.staff_image, b.branch_id, b.staff_icno, b.job_position_id, b.staff_date_joined FROM salary_slip a
JOIN staff b ON (a.staff_id = b.staff_id)
WHERE a.slip_id = '$slip_id' LIMIT 1") ;
$result_slip = mysqli_fetch_assoc($query_slip);
$branch_id = $result_slip['branch_id'];
$query_branch = $mysqli->query("SELECT * FROM branch WHERE branch_id = '$branch_id' LIMIT 1");
if ( $query_branch->num_rows > 0 ){
$result_branch = mysqli_fetch_assoc($query_branch) ;
$letter_head = html_entity_decode(htmlspecialchars_decode($result_branch['branch_content']));
}
$staff_id = $result_slip['staff_id'] ;
$job_position_id = $result_slip['job_position_id'] ;
$mysqli_position = $mysqli->query("SELECT a.job_position_id, b.job_position_desc FROM setting_job_position a
LEFT JOIN setting_job_position_translation b ON ( a.job_position_id = b.job_position_id )
WHERE a.deleted_at IS NULL AND b.lang = 'en' AND a.job_position_id = '".$job_position_id."' LIMIT 1") ;
$job_position_desc = '' ;
if ( $mysqli_position->num_rows > 0 ){
$row_position = $mysqli_position->fetch_assoc() ;
$job_position_desc = $row_position['job_position_desc'] ;
}
$total_earning = $result_slip['basic_salary'] + $result_slip['allowance'] + $result_slip['commission'];
$total_deduction = $result_slip['staff_epf'] + $result_slip['staff_socso'] + $result_slip['staff_eis'] + $result_slip['staff_pcb'] + $result_slip['staff_zakat'] + $result_slip['deduction'] ;
// left table
$left_table = [] ;
$left_table[] = [
'key' => 'WAGES',
'value' => number_format((float)$result_slip['basic_salary'], 2, '.', '')
] ;
if ( $result_slip['allowance'] > 0 ){
$left_table[] = [
'key' => 'ALLOWANCE',
'value' => number_format((float)$result_slip['allowance'], 2, '.', '')
] ;
}
if ( $result_slip['commission'] > 0 ){
$left_table[] = [
'key' => 'COMMISSION',
'value' => number_format((float)$result_slip['commission'], 2, '.', '')
] ;
}
// right table
$right_table = [] ;
if( $result_slip['staff_epf'] > 0 ){
$right_table[] = [
'key' => 'EPF (EMPLOYEE)',
'value' => number_format((float)$result_slip['staff_epf'], 2, '.', '')
] ;
}
if( $result_slip['staff_socso'] > 0 ){
$right_table[] = [
'key' => 'SOCSO (EMPLOYEE)',
'value' => number_format((float)$result_slip['staff_socso'], 2, '.', '')
] ;
}
if( $result_slip['staff_eis'] > 0 ){
$right_table[] = [
'key' => 'EIS (EMPLOYEE)',
'value' => number_format((float)$result_slip['staff_eis'], 2, '.', '')
] ;
}
if( $result_slip['staff_pcb'] > 0 ){
$right_table[] = [
'key' => 'PCB',
'value' => number_format((float)$result_slip['staff_pcb'], 2, '.', '')
] ;
}
if( $result_slip['staff_zakat'] > 0 ){
$right_table[] = [
'key' => 'MUSLIM ZAKAT FUND',
'value' => number_format((float)$result_slip['staff_zakat'], 2, '.', '')
] ;
}
if( $result_slip['deduction'] > 0 ){
$right_table[] = [
'key' => 'DEDUCTION',
'value' => number_format((float)$result_slip['deduction'], 2, '.', '')
] ;
}
// bottom table
$bottom_table = [] ;
if( $result_slip['employer_epf'] > 0 ){
$bottom_table[] = [
'key' => 'EPF',
'value' => number_format((float)$result_slip['employer_epf'], 2, '.', '')
] ;
}
if( $result_slip['employer_socso'] > 0 ){
$bottom_table[] = [
'key' => 'SOCSO',
'value' => number_format((float)$result_slip['employer_socso'], 2, '.', '')
] ;
}
if( $result_slip['employer_eis'] > 0 ){
$bottom_table[] = [
'key' => 'EIS',
'value' => number_format((float)$result_slip['employer_eis'], 2, '.', '')
] ;
}
$html .= '
'.$letter_head.'
|
PAYSLIP
|
| NAME |
: |
'.$result_slip['staff_name'].' |
|
DATE |
: |
'.strtoupper(date('07-m-y', strtotime($result_slip['month'].' +1 month'))).' |
| ID |
: |
'.$result_slip['staff_idno'].' |
|
IC NO |
: |
'.$result_slip['staff_icno'].' |
| POSITION |
: |
'.$job_position_desc.' |
|
MONTH |
: |
'.strtoupper(date('M-y', strtotime($result_slip['month']))).' |
| GROSS EARNING |
Amount(RM) |
DEDUCTIONS |
Amount(RM) |
| [LEFT01_TITLE] |
[LEFT01_VALUE] |
[RIGHT01_TITLE] |
[RIGHT01_VALUE] |
| [LEFT02_TITLE] |
[LEFT02_VALUE] |
[RIGHT02_TITLE] |
[RIGHT02_VALUE] |
| [LEFT03_TITLE] |
[LEFT03_VALUE] |
[RIGHT03_TITLE] |
[RIGHT03_VALUE] |
| [LEFT04_TITLE] |
[LEFT04_VALUE] |
[RIGHT04_TITLE] |
[RIGHT04_VALUE] |
| [LEFT05_TITLE] |
[LEFT05_VALUE] |
[RIGHT05_TITLE] |
[RIGHT05_VALUE] |
| [LEFT06_TITLE] |
[LEFT06_VALUE] |
[RIGHT06_TITLE] |
[RIGHT06_VALUE] |
| |
|
TOTAL EARNING / INCOME |
'.number_format((float)$total_earning, 2, '.', '').' |
TOTAL DEDUCTIONS |
'.number_format((float)$total_deduction, 2, '.', '').' |
| |
EMPLOYER CONTRIBUTIONS |
| NET PAY |
'.number_format( (float)$result_slip['total'], 2, '.', '').' |
[BOTTOM01_TITLE] |
[BOTTOM01_VALUE] |
|
[BOTTOM02_TITLE] |
[BOTTOM02_VALUE] |
|
[BOTTOM03_TITLE] |
[BOTTOM03_VALUE] |
| |
| REMARK : '.( dataFilter( $result_slip['remark'] ) ? dataFilter( $result_slip['remark'] ) : '-' ) .' |
' ;
$footer = '
| This is computer generated document. No signature is required. |
' ;
// reset
$count_left = 1 ;
$count_right = 1 ;
$count_bottom = 1 ;
for ( $a = 0 ; $a <= 5 ; $a++ ){
if ( count($left_table) > 0 ){
$html = str_replace( '[LEFT0'.$count_left.'_TITLE]', $left_table[0]['key'], $html ) ;
$html = str_replace( '[LEFT0'.$count_left.'_VALUE]', $left_table[0]['value'], $html ) ;
$count_left++ ;
array_shift( $left_table ) ;
}else{
$html = str_replace( '[LEFT0'.$count_left.'_TITLE]', ' ', $html ) ;
$html = str_replace( '[LEFT0'.$count_left.'_VALUE]', ' ', $html ) ;
$count_left++ ;
}
if ( count($right_table) > 0 ){
$html = str_replace( '[RIGHT0'.$count_right.'_TITLE]', $right_table[0]['key'], $html ) ;
$html = str_replace( '[RIGHT0'.$count_right.'_VALUE]', $right_table[0]['value'], $html ) ;
$count_right++ ;
array_shift( $right_table ) ;
}else{
$html = str_replace( '[RIGHT0'.$count_right.'_TITLE]', ' ', $html ) ;
$html = str_replace( '[RIGHT0'.$count_right.'_VALUE]', ' ', $html ) ;
$count_right++ ;
}
if ( count($bottom_table) > 0 ){
$html = str_replace( '[BOTTOM0'.$count_bottom.'_TITLE]', $bottom_table[0]['key'], $html ) ;
$html = str_replace( '[BOTTOM0'.$count_bottom.'_VALUE]', $bottom_table[0]['value'], $html ) ;
$count_bottom++ ;
array_shift( $bottom_table ) ;
}else{
$html = str_replace( '[BOTTOM0'.$count_bottom.'_TITLE]', ' ', $html ) ;
$html = str_replace( '[BOTTOM0'.$count_bottom.'_VALUE]', ' ', $html ) ;
$count_bottom++ ;
}
}
// page header
// $header = '' ;
// keep footer html content in variable
include_once 'MPDF/mpdf.php' ;
$mpdf = new mPDF('utf-8', 'A5', '', 'freesans', 10, 10, 7, 5, 5, 5) ;
ini_set("memory_limit", "9999M");
// Use different Odd/Even headers and footers and mirror margins
$mpdf->mirrorMargins = 1 ;
// set mpdf header
$mpdf->SetHTMLHeader($header) ;
$mpdf->SetHTMLHeader($header, 'E') ;
// set mpdf footer
$mpdf->SetHTMLFooter($footer) ;
$mpdf->SetHTMLFooter($footer, 'E') ;
//css
$stylesheet = file_get_contents('css/salary_pdf.css'); // external css
$mpdf->WriteHTML($stylesheet, 1);
// write in html
$mpdf->WriteHTML($html) ;
// set filename
$filename = $print_filename; // Your Filename whit local date and time
$filename_save = $filename.'.pdf' ;
$filename_jpeg = $filename.'.jpg' ;
$filename_temp = $filename ;
// turns all headers/footers off from new page onwards
$mpdf->useAdobeCJK = true;
// check output type
$page_type = ($_GET['page_type']) ;
$page_type_output = ($page_type == 'jpeg' ? 'F' : 'I') ;
//$mpdf->SetAutoFont(AUTOFONT_ALL);
$mpdf->Output($filename_save, $page_type_output);