public function generate_payslip($empid, $start_date, $end_date, $payslip_type = 'Semi-Monthly')
 {
     $data['employee'] = $this->retrieveEmployeeInfo($empid);
     if ($payslip_type == 'Semi-Monthly') {
         $divisor = 2;
     } else {
         $divisor = 4;
     }
     $data['cutoffsalary'] = $data['employee']->salary / $divisor;
     $data['perdaysalary'] = $data['employee']->salary * 12 / 261;
     $data['perhoursalary'] = $data['perdaysalary'] / 8;
     $data['attendance'] = $this->getAttendance($empid, $start_date, $end_date);
     $data['allowances'] = $this->computeAllowances(Allowance_model::view_allowances(), $data['cutoffsalary'], $divisor);
     $data['total'] = $this->retrieveTotalHours($empid, $start_date, $end_date);
     $data['total_absent'] = $this->totalAbsent($data['attendance']);
     $data['total_overtime'] = $data['total']->overtime * ($data['perhoursalary'] * 1.25);
     $data['total_tardiness'] = $data['total']->tardiness * ($data['perhoursalary'] * 1.25);
     $data['total_leaves'] = $this->totalLeaves($data['attendance']) * $data['perdaysalary'];
     $data['total_absent_amount'] = $data['total_absent'] * $data['perdaysalary'];
     $data['total_allowance'] = $this->totalAmount($data['allowances']);
     $data['gross_income'] = $data['cutoffsalary'] + $data['total_overtime'] + $data['total_leaves'] - $data['total_absent_amount'] - $data['total_tardiness'];
     $data['taxes'] = $this->computeTaxes(Taxes_model::compute_taxes($data['cutoffsalary']), $data['cutoffsalary'], $divisor);
     $data['total_tax'] = $this->totalAmount($data['taxes']);
     $data['net_income'] = $data['gross_income'] + $data['total_allowance'] - $data['total_tax'];
     $records = array("attendance" => $data['attendance'], "allowances" => $data['allowances'], "taxes" => $data['taxes'], "employee" => $data['employee'], "cutoffsalary" => $data['cutoffsalary'], "perdaysalary" => $data['perdaysalary'], "total" => $data['total'], "total_absent" => $data['total_absent'], "total_overtime" => $data['total_overtime'], "total_tardiness" => $data['total_tardiness'], "total_absent_amount" => $data['total_absent_amount'], "total_allowance" => $data['total_allowance'], "total_tax" => $data['total_tax'], "net_income" => $data['net_income'], "gross_income" => $data['gross_income']);
     return $records;
 }
 public function multiple_payslips()
 {
     //$this->output->enable_profiler(TRUE);
     $this->form_validation->set_rules('txtPayrollDate', 'Pay Date', 'trim|required');
     $this->form_validation->set_rules('txtStartDate', 'Start Date', 'trim|required');
     $this->form_validation->set_rules('txtEndDate', 'End Date', 'trim|required');
     $data = array();
     $data['payslips'] = array();
     if ($this->form_validation->run()) {
         $post = $this->input->post();
         if (isset($post['btnGenerate'])) {
             $employee_count = $post["hidTotalEmp"];
             $data['post'] = array("txtPayrollDate" => $post['txtPayrollDate'], "txtStartDate" => $post['txtStartDate'], "txtEndDate" => $post['txtEndDate']);
             for ($empctr = 1; $empctr <= $employee_count; $empctr++) {
                 $tempAllowance = Attendance_model::computeAllowances(Allowance_model::view_allowances(), $post['hidBasicSalary' . $empctr], 2);
                 $tempTaxes = Attendance_model::computeTaxes(Taxes_model::compute_taxes($post['hidBasicSalary' . $empctr]), $post['hidBasicSalary' . $empctr], 2);
                 $allowances = array();
                 foreach ($tempAllowance as $row) {
                     if ($row->active == 1) {
                         array_push($allowances, array('allowance_id' => $row->allowance_id, 'percentage' => $row->percentage, 'computation' => $row->computation, 'amount' => $row->amount, 'total' => $row->total));
                     }
                 }
                 $taxes = array();
                 foreach ($tempTaxes as $row) {
                     if ($row->active == 1) {
                         if ($row->ranges_active == 1) {
                             array_push($taxes, array('tax_id' => $row->tax_id, 'percentage' => $row->percentage, 'computation' => $row->computation, 'amount' => $row->amount, 'total' => $row->total));
                         } else {
                             array_push($taxes, array('tax_id' => $row->tax_id, 'percentage' => 0, 'computation' => 0, 'amount' => 0, 'total' => $row->total));
                         }
                     }
                 }
                 $insert_payslip = array('emp_id' => $post['hidID' . $empctr], 'payslip_date' => $post['hidPayDate'], 'start_date' => $post['hidPayStart'], 'end_date' => $post['hidPayEnd'], 'monthly_rate' => $post['hidMonthlyRate' . $empctr], 'basic_salary' => $post['hidBasicSalary' . $empctr], 'total_overtime' => $post['hidTotalOvertime' . $empctr], 'total_tardiness' => $post['hidTotalTardiness' . $empctr], 'days_absent' => $post['hidTotalAbsent' . $empctr], 'total_absent_amount' => $post['hidTotalAbsentAmount' . $empctr], 'total_allowances' => $post['hidTotalAllowance' . $empctr], 'total_taxes' => $post['hidTotalTax' . $empctr], 'gross_pay' => $post['hidGrossIncome' . $empctr], 'net_pay' => $post['hidNetIncome' . $empctr], "allowances" => $allowances, "taxes" => $taxes, 'remarks' => "");
                 $this->attendance_model->insert_payslip($insert_payslip);
                 //print_r($insert_payslip);
                 $this->session->set_userdata('added', 1);
             }
         } else {
             $emp_ids = $this->attendance_model->retrieveEmployeesFromCutoff($post['txtStartDate'], $post['txtEndDate']);
             foreach ($emp_ids as $id) {
                 //$data['payslip'] = $this->attendance_model->retrievePayslipDates($post['cboDate']);
                 $data['record'] = $this->attendance_model->generate_payslip($id->emp_id, $post['txtStartDate'], $post['txtEndDate']);
                 //$data['post'] = $post;
                 $data['post'] = array("txtPayrollDate" => $post['txtPayrollDate'], "txtStartDate" => $post['txtStartDate'], "txtEndDate" => $post['txtEndDate']);
                 /*if(isset($post['btnGenerate'])){
                 			$insert_payslip = array(
                 				'emp_id'=>$id->emp_id,
                 				'payslip_date'=>$post['hidPayDate'],
                 				'start_date'=>$post['hidPayStart'],
                 				'end_date'=>$post['hidPayEnd'],
                 				'monthly_rate'=>$data['record']['employee']->salary,
                 				'basic_salary'=>$data['record']['employee']->salary/2,
                 				'total_overtime'=>$data['record']['total_overtime'],
                 				'total_tardiness'=>$data['record']['total_tardiness'],
                 				'days_absent'=>$data['record']['total_absent'],
                 				'total_absent_amount'=>$data['record']['total_absent_amount'],
                 				'total_allowances'=>$data['record']['total_allowance'],
                 				'total_taxes'=>$data['record']['total_tax'],
                 				'gross_pay'=>$data['record']['gross_income'],
                 				'net_pay'=>$data['record']['net_income'],
                 				"allowances"=>$data['record']['allowances'],
                 				"taxes"=>$data['record']['taxes'],
                 				'remarks'=>"");
                 			$this->attendance_model->insert_payslip($insert_payslip);
                 			$this->session->set_userdata('added', 1);
                 		}*/
                 array_push($data['payslips'], $data['record']);
             }
         }
     } else {
         $data['record'] = array("attendance" => array(), "allowances" => array(), "taxes" => array(), "employee" => array(), "cutoffsalary" => 0, "perdaysalary" => 0, "total" => array(), "total_absent" => 0, "total_overtime" => 0, 'total_tardiness' => 0, "total_absent_amount" => 0, "total_allowance" => 0, "total_tax" => 0, "net_income" => 0, "gross_income" => 0);
     }
     /*
     		$post = $this->input->post();
     		if($post){
     			$emp_ids = $this->attendance_model->retrieveEmployeesFromCutoff('2015-06-01', '2015-06-15');
     			foreach($emp_ids as $id){
     				//$data['payslip'] = $this->attendance_model->retrievePayslipDates($post['cboDate']);
     				$data['record'] = $this->attendance_model->generate_payslip($id->emp_id, '2015-06-01', '2015-06-15');
     				//$data['post'] = $post;
     				$data['post'] = array(
     					"cboEmployee"=>1,
     					"txtPayrollDate"=>'2015-06-20',
     					"txtStartDate"=>'2015-06-01',
     					"txtEndDate"=>'2015-06-15');
     				if(isset($post('btnGenerate'))){
     					$insert_payslip = array(
     						'emp_id'=>$id->emp_id,
     						'payslip_date'=>$post['hidPayDate'],
     						'start_date'=>$post['hidPayStart'],
     						'end_date'=>$post['hidPayEnd'],
     						'monthly_rate'=>$data['record']['employee']->salary,
     						'basic_salary'=>$data['record']['employee']->salary/2,
     						'total_overtime'=>$data['record']['total_overtime'],
     						'total_tardiness'=>$data['record']['total_tardiness'],
     						'days_absent'=>$data['record']['total_absent'],
     						'total_absent_amount'=>$data['record']['total_absent_amount'],
     						'total_allowances'=>$data['record']['total_allowance'],
     						'total_taxes'=>$data['record']['total_tax'],
     						'gross_pay'=>$data['record']['gross_income'],
     						'net_pay'=>$data['record']['net_income'],
     						"allowances"=>$data['record']['allowances'],
     						"taxes"=>$data['record']['taxes'],
     						'remarks'=>"");
     					$this->attendance_model->insert_payslip($insert_payslip);
     				}
     				array_push($data['payslips'], $data['record']);
     			}
     		}*/
     $data['pageTitle'] = 'Add Multiple Payslips - MSInc.';
     $data['content'] = 'payroll/multiple_payslips';
     $this->load->view($this->master_layout, $data);
     $this->display_notif();
 }