예제 #1
0
    function payslip_update()
    {
        if ($this->request->data) {
            $this->set('employee_id', $this->request->data['SalaryRecord']['employee_id']);
            $res = $this->Employee->SalaryRecord->salarySearch($this->request->data['SalaryRecord']['employee_id'], $this->request->data['SalaryRecord']['salary_date']);
            if ($res['SalaryRecord']['payslip_generated'] != 1) {
                //debug($this->request->data);
                $earnings = $this->request->data['SalaryRecord']['basic'] + $this->request->data['SalaryRecord']['da'] + $this->request->data['SalaryRecord']['bonus'] + $this->request->data['SalaryRecord']['medical_allowance'] + $this->request->data['SalaryRecord']['tiffin'] + $this->request->data['SalaryRecord']['house_rent'] + $this->request->data['SalaryRecord']['education'] + $this->request->data['SalaryRecord']['entertainment'];
                $deductions = $this->request->data['SalaryRecord']['pf'] + $this->request->data['SalaryRecord']['esi'] + $this->request->data['SalaryRecord']['income_tax'];
                $this->request->data['SalaryRecord']['net_salary'] = $earnings - $deductions;
                $se = $this->Session->read("Auth");
                $this->request->data['SalaryRecord']['user_id'] = $se['User']['id'];
                $this->request->data['SalaryRecord']['print_copy'] = 1;
                $this->request->data['SalaryRecord']['payslip_generated'] = 1;
                //debug($this->request->data['SalaryRecord']);exit();
                if ($res['SalaryRecord']['id']) {
                    $this->Employee->SalaryRecord->id = $res['SalaryRecord']['id'];
                } else {
                    $this->Employee->SalaryRecord->create();
                }
                if ($this->Employee->SalaryRecord->save($this->request->data)) {
                    //update the loan amount
                    if ($this->request->data['SalaryRecord']['loan_amount'] > 0) {
                        $this->request->data['Loan']['loan_amount'] = $this->request->data['SalaryRecord']['loan_amount'];
                        $this->request->data['Loan']['employee_id'] = $this->request->data['SalaryRecord']['employee_id'];
                        $loan_save = $this->Employee->Loan->loanEntryUpdate($this->request->data['Loan']);
                    }
                    $this->set('salary_saved', 1);
                    $name = $this->request->data['SalaryRecord']['fname'];
                    if ($this->request->data['SalaryRecord']['mname'] != null) {
                        $name .= ' ' . $this->request->data['SalaryRecord']['mname'];
                    }
                    $name .= ' ' . $this->request->data['SalaryRecord']['lname'];
                    App::import('Vendor', 'xtcpdf');
                    $tcpdf = new XTCPDF();
                    $textfont = 'freesans';
                    // looks better, finer, and more condensed than 'dejavusans'
                    $tcpdf->SetAuthor("Company Name");
                    $tcpdf->SetAutoPageBreak(false);
                    $tcpdf->setPrintHeader(false);
                    $tcpdf->setPrintFooter(false);
                    //$tcpdf->setHeaderFont(array($textfont,'',40));
                    //$tcpdf->xheadercolor = array(0,0,0);
                    //$tcpdf->xheadertext = '';
                    //$tcpdf->xfootertext = '';
                    // add a page (required with recent versions of tcpdf)
                    $tcpdf->AddPage();
                    // Now you position and print your page content
                    // example:
                    $fill = 0;
                    $tcpdf->SetTextColor(0, 0, 0);
                    $tcpdf->SetFont($textfont, 'B', 20);
                    $header_html = '<span>Company Logo</span>';
                    $header_html2 = '<span>Company Address</span>';
                    $payslip_date = '<p style="font-size:20px!important">Playslip for the month of ' . $this->request->data['SalaryRecord']['salary_date'] . '</p>';
                    $emp_name = '<p style="font-size:20px!important">Name : ' . $name . '</p>';
                    $employee_id = '<p style="font-size:20px!important">Employee Id : emp' . $this->request->data['SalaryRecord']['employee_id'] . '</p>';
                    $department = '<p style="font-size:20px!important">Department : ' . $this->request->data['SalaryRecord']['department'] . '</p>';
                    $designation = '<p style="font-size:20px!important">Designation : ' . $this->request->data['SalaryRecord']['designation'] . '</p>';
                    $employee = $this->Employee->employeeSearch($this->request->data['SalaryRecord']['employee_id']);
                    $expected_earnings = $employee['Employee']['net_salary'] + $employee['Employee']['da'] + $employee['Employee']['bonus'] + $employee['Employee']['medical_allowance'] + $employee['Employee']['tiffin'] + $employee['Employee']['house_rent'] + $employee['Employee']['education'] + $employee['Employee']['entertainment'];
                    $expected_deductions = $employee['Employee']['pf'] + $employee['Employee']['esi'] + $employee['Employee']['income_tax'];
                    $earnings_content = '
<style>
	table{width:100%;border:none}
	th{font-size:12px;height:10px;font-size:22px!important;border-bottom:0px solid black}
	td{font-size:20px!important;width:100%;}
	.total{border-top:0px solid black}
</style>
<table>
 <tr>
  <th><b>Earnings</b></th>
 </tr>
 <tr>
 <td width="50%"></td>
  <td width="25%">Full (Rs.)</td>
  <td width="25%">Actual (Rs.)</td>
 </tr>
 <tr>
 <td width="50%">Basic</td>
  <td width="25%">' . $employee['Employee']['net_salary'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['basic'] . '</td>
 </tr>
 <tr>
  <td width="50%">DA</td>
  <td width="25%">' . $employee['Employee']['da'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['da'] . '</td>
 </tr>
 <tr>
  <td width="50%">Bonus</td>
  <td width="25%">' . $employee['Employee']['bonus'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['bonus'] . '</td>
 </tr>
 <tr>
  <td width="50%">Medical Allowance</td>
  <td width="25%">' . $employee['Employee']['medical_allowance'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['medical_allowance'] . '</td>
 </tr>
  <tr>
  <td width="50%">Tiffin Allowance</td>
  <td width="25%">' . $employee['Employee']['tiffin'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['tiffin'] . '</td>
 </tr>
  <tr>
  <td width="50%">House Rent Allowance</td>
  <td width="25%">' . $employee['Employee']['house_rent'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['house_rent'] . '</td>
 </tr>
 <tr>
  <td width="50%">Education Allowance</td>
  <td width="25%">' . $employee['Employee']['education'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['education'] . '</td>
 </tr>
  <tr>
  <td width="50%">Entertainment Allowance</td>
  <td width="25%">' . $employee['Employee']['entertainment'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['entertainment'] . '</td>
 </tr>
 <tr>
  <td width="50%"  class="total"><b>Total Earnings (Rs.) :</b></td>
  <td width="25%"  class="total"><b>' . $expected_earnings . '</b></td>
  <td width="25%"  class="total"><b>' . $earnings . '</b></td>
 </tr>
	 </table>';
                    $deductions_content = '
<style>
	table{width:100%;border:none}
	th{font-size:12px;height:10px;font-size:22px!important;border-bottom:0px solid black}
	td{font-size:20px!important;width:100%;}
	.total{border-top:0px solid black}

</style>
<table>
 <tr>
  <th><b>Deductions</b></th>
 </tr>
 <tr>
 <td width="50%"></td>
  <td width="25%">Full (Rs.)</td>
  <td width="25%">Actual (Rs.)</td>
 </tr>
 <tr>
 <td width="50%">PF</td>
  <td width="25%">' . $employee['Employee']['pf'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['pf'] . '</td>
 </tr>
 <tr>
  <td width="50%">ESI</td>
  <td width="25%">' . $employee['Employee']['esi'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['esi'] . '</td>
 </tr>
 <tr>
  <td width="50%">TDS</td>
  <td width="25%">' . $employee['Employee']['income_tax'] . '</td>
  <td width="25%">' . $this->request->data['SalaryRecord']['income_tax'] . '</td>
 </tr>
  <tr>
  <td width="50%">Advance</td>
  <td width="25%">0</td>
  <td width="25%">0</td>
 </tr>
  <tr>
  <td width="50%">Loan</td>
  <td width="25%">0</td>
  <td width="25%">0</td>
 </tr>
 <tr>
  <td width="50%"></td>
  <td width="25%"></td>
  <td width="25%"></td>
 </tr>
 <tr>
  <td width="50%"></td>
  <td width="25%"></td>
  <td width="25%"></td>
 </tr>
 <tr>
  <td width="50%"></td>
  <td width="25%"></td>
  <td width="25%"></td>
 </tr>
 <tr>
  <td width="50%"  class="total"><b>Total Deductions (Rs.) :</b></td>
  <td width="25%"  class="total"><b>' . $expected_deductions . '</b></td>
  <td width="25%"  class="total"><b>' . $deductions . '</b></td>
 </tr>
	 </table>';
                    $net_earnings = $earnings - $deductions;
                    $net_salary = '<p style="font-size:20px!important"><b>Net Salary : Rs. ' . $net_earnings . '</b></p>';
                    $auto_text = '<p style="font-size:22px!important;color:#cccccc">This is a computer-generated salary slip. Does not require a Signature</p>';
                    $tcpdf->SetFillColor(155, 100, 0);
                    $tcpdf->writeHTMLCell(50, 0, '', 10, $header_html, 0, 1, 0, true, 'L', true);
                    $tcpdf->writeHTMLCell(50, 0, 55, 10, $header_html2, 0, 0, 0, true, 'R', true);
                    $tcpdf->writeHTMLCell(0, 0, '', 35, $payslip_date, 0, 1, 0, true, 'L', true);
                    $tcpdf->writeHTMLCell(80, 5, '', 40, $emp_name, 'LRTB', 1, 0, true, 'C', true);
                    $tcpdf->writeHTMLCell(80, 5, 85, 40, $employee_id, 'RTB', 1, 0, true, 'C', true);
                    $tcpdf->writeHTMLCell(80, 5, '', 45, $department, 'LRB', 1, 0, true, 'C', true);
                    $tcpdf->writeHTMLCell(80, 5, 85, 45, $designation, 'RB', 1, 0, true, 'C', true);
                    $tcpdf->writeHTMLCell(80, '', '', 55, $earnings_content, 'LRTB', 1, 0, true, 'C', true);
                    $tcpdf->writeHTMLCell(80, '', 85, 55, $deductions_content, 'RTB', 1, 0, true, 'C', true);
                    $tcpdf->writeHTMLCell(155, 3, '', '', $net_salary, 'LRTB', 1, 0, true, 'L', true);
                    $tcpdf->writeHTMLCell(155, '', '', 105, $auto_text, '', 1, 0, true, 'L', true);
                    // ...
                    // etc.
                    // see the TCPDF examples
                    $file_name = time() . '.pdf';
                    echo $tcpdf->Output($file_name, 'F');
                    //setting view variables before sending email so that if email is not sent generated salry slip will still be viewed
                    $this->set('salaryrecord', $this->request->data['SalaryRecord']);
                    $this->set('employee', $employee);
                    $this->set('earnings', $earnings);
                    $this->set('deductions', $deductions);
                    $this->set('expected_earnings', $expected_earnings);
                    $this->set('net_earnings', $net_earnings);
                    App::uses('CakeEmail', 'Network/Email');
                    $Email = new CakeEmail();
                    $Email->to($this->request->data['SalaryRecord']['email']);
                    $Email->bcc($se['User']['email']);
                    $Email->subject('Salary Slip of ' . $name . ' [ emp' . $this->request->data['SalaryRecord']['employee_id'] . ' ] for ' . $this->request->data['SalaryRecord']['salary_date']);
                    $Email->replyTo($se['User']['email']);
                    $Email->from($se['User']['email']);
                    $Email->emailFormat('html');
                    $Email->viewVars(array('salary_record' => $this->request->data['SalaryRecord']));
                    $Email->attachments($file_name);
                    $Email->template('salaryslip');
                    //$Email->send();
                    App::uses('File', 'Utility');
                    $file = new File($file_name);
                    $file->delete();
                } else {
                    $this->set('salary_saved', 0);
                }
            }
        }
    }