NEW PAYROLL CHANGES

This commit is contained in:
velz2020 2017-10-05 17:06:40 +05:30
parent 9f11e8a7e8
commit 818aa7c289
36 changed files with 4561 additions and 264 deletions

View File

@ -148,13 +148,14 @@ $route['pageNotFound'] = "user/pageNotFound";
$route['checkEmailExists'] = "user/checkEmailExists";
$route['forgotPassword'] = "login/forgotPassword";
$route['ExcelUpload'] = "payslip/viewUpload";
$route['monthlypay'] = "payslip/monthlyInputs";
$route['ExcelUpload2'] = "payslip/viewUpload2";
$route['FileUpload'] = "payslip/uploadExcel";
$route['FileUpload2'] = "payslip/uploadExcel2";
$route['PrintPdf'] = "payslip/PrintPdf";
$route['ViewPay'] = "payslip/viewGenerator";
$route['updatepayroll'] = "payslip/updatepayroll";
$route['BankReport'] = "payslip/loadBankreportScreen";
//<-----------Application Requistion Flow Routes------------>

View File

@ -61,7 +61,7 @@ class emppaydate extends BaseController
$result['empdetails'] = $this->payroll_model->getEmpID($q);
//$data['emp_id'] = $this->monthlypay_model->getmonthlypay();
$this->global['pageTitle'] = 'Siddharth : Add Employee Pay';
@ -81,30 +81,12 @@ class emppaydate extends BaseController
$this->form_validation->set_rules('HRA_Amount','HRA_Amount','trim|required');
$this->form_validation->set_rules('Basic_Pay','Basic_Pay','trim|required');
$this->form_validation->set_rules('Total_salary','Total_salary','trim|required');
$this->form_validation->set_rules('OT_Rate','OT_Rate','trim|required');
$this->form_validation->set_rules('Allowances','Allowances','trim|required');
$this->form_validation->set_rules('PF_Rate','PF_Rate','trim|required');
$this->form_validation->set_rules('ESI_Rate','ESI_Rate','trim|required');
$this->form_validation->set_rules('Food_Allowances','Food_Allowances','trim|required');
//$Loan_Amount=$this->input->post('Loan_Amount');
// echo "before if";
// if($Loan_Amount != 0.00 || $Loan_Amount != "")
// {
// echo "indisde ";
// $Load_Issued_date=$this->input->post('loan_issued_date');
// $Due_Amount=$this->input->post('monthly_due');
// $Due_Started=$this->input->post('due_started');
// echo $Load_Issued_date ."-".$Due_Amount."-".$Due_Started;
// if($Load_Issued_date == "" || $Due_Started =="" || $Due_Amount == "" || $Due_Amount == 0)
// //echo "FAIL";die();
// $this->form_validation->set_rules('Loan_Amount','Loan_Amount','trim|required');
// $this->form_validation->set_rules('loan_issued_date','loan_issued_date','trim|required');
// $this->form_validation->set_rules('monthly_due','monthly_due','trim|required');
// $this->form_validation->set_rules('Food_Allodue_startedwances','due_started','trim|required');
// }
//die();
if($this->form_validation->run() == FALSE || $EmpID == -1)
{
@ -112,13 +94,13 @@ class emppaydate extends BaseController
}
else
{
//$Pay_Data_ID=$this->input->post('Pay_Data_ID');
$EmpID = $this->input->post('EmpID');
$Total_Salary=$this->input->post('Total_salary');
$Basic_Pay=$this->input->post('Basic_Pay');
$HRA_Rate=$this->input->post('HRA_Rate');
$HRA_Amount=$this->input->post('HRA_Amount');
$OT_Rate=$this->input->post('OT_Rate');
$Allowances=$this->input->post('Allowances');
$PF_Rate=$this->input->post('PF_Rate');
$ESI_Rate=$this->input->post('ESI_Rate');
@ -141,20 +123,20 @@ class emppaydate extends BaseController
$Remaining_Due=$this->input->post('remaining_due');
$Paid_Amount=$this->input->post('Paid_Amount');
//$All = $this->input->post('All');
$CreateBy = $this->session->userdata ( 'userId' );
$chked = $this->input->post('is_Active');
$IsActive = '1';
$emppay = array('EmpID'=>$EmpID,'TotalSalary'=>$Total_Salary,'Basic_Pay'=>$Basic_Pay,'HRA_Rate'=>$HRA_Rate,'HRA_Amount'=>$HRA_Amount, 'OT_Rate'=>$OT_Rate, 'Allowances'=>$Allowances, 'PF_Rate'=>$PF_Rate, 'ESI_Rate'=>$ESI_Rate ,'Food_Allowances'=>$Food_Allowances,'Loan_Amount'=>$Loan_Amount,'Loan_Issued_Date'=>$Load_Issued_date,'Monthly_Due'=>$Due_Amount,'Due_Start_Date'=>$Due_Started,'No_of_Dues'=>$No_Of_Dues,'Paid_Due'=>$Paid_due,'Remaining_Due'=>$Remaining_Due,'Paid_Amount'=>$Paid_Amount,'Created_By'=>$CreateBy);
$emppay = array('EmpID'=>$EmpID,'TotalSalary'=>$Total_Salary,'Basic_Pay'=>$Basic_Pay,'HRA_Rate'=>$HRA_Rate,'HRA_Amount'=>$HRA_Amount,'Allowances'=>$Allowances, 'PF_Rate'=>$PF_Rate, 'ESI_Rate'=>$ESI_Rate ,'Food_Allowances'=>$Food_Allowances,'Loan_Amount'=>$Loan_Amount,'Loan_Issued_Date'=>$Load_Issued_date,'Monthly_Due'=>$Due_Amount,'Due_Start_Date'=>$Due_Started,'No_of_Dues'=>$No_Of_Dues,'Paid_Due'=>$Paid_due,'Remaining_Due'=>$Remaining_Due,'Paid_Amount'=>$Paid_Amount,'Created_By'=>$CreateBy);
//print_r($emppay);die();
$result = $this->emppaydate_model->addNewemppay($emppay);
if($result > 0)
{
// $this->session->set_flashdata('success', 'New Asset created successfully');
redirect('emppaydate/emppayListing','refresh');
echo "<script>alert('Employee Pay List Created successfully!');</script>";
@ -176,8 +158,7 @@ class emppaydate extends BaseController
{
$data['emppay'] = $this->emppaydate_model->getUserInfo($paydataid);
// print_r($data);
//$data['monthly_pay_inputs'] = $this->monthlylisting_model->getUserInfo($employeeid);
$this->global['pageTitle'] = 'Siddharth : Edit Employee Pay Monthly Details ';
@ -203,7 +184,7 @@ class emppaydate extends BaseController
$this->form_validation->set_rules('Total_Salary','Total_Salary','trim|required');
$this->form_validation->set_rules('Basic_Pay','Basic_Pay','trim|required');
$this->form_validation->set_rules('HRA_Rate','HRA_Rate','trim|required');
$this->form_validation->set_rules('OT_Rate','OT_Rate','trim|required');
$this->form_validation->set_rules('Allowances','Allowances','trim|required');
$this->form_validation->set_rules('PF_Rate','PF_Rate','trim|required');
$this->form_validation->set_rules('ESI_Rate','ESI_Rate','trim|required');
@ -229,7 +210,7 @@ class emppaydate extends BaseController
$Basic_Pay=$this->input->post('Basic_Pay');
$HRA_Rate=$this->input->post('HRA_Rate');
$HRA_Amount=$this->input->post('HRA_Amount');
$OT_Rate=$this->input->post('OT_Rate');
$Allowances=$this->input->post('Allowances');
$PF_Rate=$this->input->post('PF_Rate');
$ESI_Rate=$this->input->post('ESI_Rate');
@ -252,25 +233,12 @@ class emppaydate extends BaseController
$Last_Mod_By=$this->session->userdata('userId');
$Last_Mod_Time=date('d-m-Y h:i:sa');
$Food_Allowances=$this->input->post('Food_Allowances');
// $chked = $this->input->post('is_Active');
// if( $chked != '')
// {
// $IsActive = '1';
// }
// else
// {
// $IsActive = '0';
// }
//$emppaydatas = array();
$emppaydatas = array('Pay_Data_ID'=>$Pay_Data_ID,'EmpID'=>$EmpID,'TotalSalary'=>$TotalSalary,'Basic_Pay'=>$Basic_Pay,'HRA_Rate'=>$HRA_Rate,'HRA_Amount'=>$HRA_Amount, 'OT_Rate'=>$OT_Rate, 'Allowances'=>$Allowances, 'PF_Rate'=>$PF_Rate, 'ESI_Rate'=>$ESI_Rate ,'Food_Allowances'=>$Food_Allowances,'Loan_Amount'=>$Loan_Amount,'Loan_Issued_Date'=>$Load_Issued_date,'Monthly_Due'=>$Due_Amount,'Due_Start_Date'=>$Due_Started,'No_of_Dues'=>$No_Of_Dues,'Paid_Due'=>$Paid_due,'Remaining_Due'=>$Remaining_Due,'Paid_Amount'=>$Paid_Amount,'Last_Mod_By'=>$Last_Mod_By,'Last_Mod_Time'=>$Last_Mod_Time);
// print_r($emppaydatas);die();
$emppaydatas = array('Pay_Data_ID'=>$Pay_Data_ID,'EmpID'=>$EmpID,'TotalSalary'=>$TotalSalary,'Basic_Pay'=>$Basic_Pay,'HRA_Rate'=>$HRA_Rate,'HRA_Amount'=>$HRA_Amount,'Allowances'=>$Allowances, 'PF_Rate'=>$PF_Rate, 'ESI_Rate'=>$ESI_Rate ,'Food_Allowances'=>$Food_Allowances,'Loan_Amount'=>$Loan_Amount,'Loan_Issued_Date'=>$Load_Issued_date,'Monthly_Due'=>$Due_Amount,'Due_Start_Date'=>$Due_Started,'No_of_Dues'=>$No_Of_Dues,'Paid_Due'=>$Paid_due,'Remaining_Due'=>$Remaining_Due,'Paid_Amount'=>$Paid_Amount,'Last_Mod_By'=>$Last_Mod_By,'Last_Mod_Time'=>$Last_Mod_Time);
$result = $this->emppaydate_model->editemppay($emppaydatas);
@ -278,7 +246,7 @@ class emppaydate extends BaseController
if($result == true)
{
echo "<script>alert('Employee Status Updated Sucessfully..!');</script>";
//$this->session->set_flashdata('success', 'updated successfully');
}
else
@ -294,135 +262,24 @@ class emppaydate extends BaseController
}
/**
* This function is used load user edit information
* @param number $userId : Optional : This is user id
*/
/*function editOldcost($CostCode = NULL)
function deleteEmpPay()
{
if($CostCode == '')
{
$CostCenterID = $_GET['CostCode'];
}
else
{
$CostCenterID = $CostCode; }
$data['CostMaster'] = $this->costcenter_model->GetCostCenterMaster($CostCenterID);
$data['CostDepts'] = $this->costcenter_model->GetCostCenterDepartment($CostCenterID);
$data['CostBudget'] = $this->costcenter_model->GetCostCenterBudget($CostCenterID);
// $data['DeptList'] = $this->costcenter_model->GetDepartmentNotinCostCenter($CostCenterID);
$this->global['pageTitle'] = 'Siddharth : Edit Cost';
$this->loadViews("editOldcost", $this->global, $data,NULL);
}
function ech()
{
echo $this->input->post('CostCentreID');
echo $this->input->post('CostName');
echo $this->input->post('Description');
$EmpID = $this->input->post('id');
//echo $EmpID;
$result = $this->emppaydate_model->deleteEmployeePay($EmpID);
if($result == 1)
{
echo "Deleted Sucessfully..!";
}
else
{
echo "Something Went wrong. Try Later..!";
}
}
/**
* This function is used to edit the user information
function editcost()
{
$this->load->library('form_validation');
$CostCenterID = $this->input->post('CostCentreID');
$this->form_validation->set_rules('CostName','Cost Name','trim|required|');
$this->form_validation->set_rules('Description','Description','trim|required|');
if($this->form_validation->run() == FALSE)
{
$this->editcost($CostCenterID);
}
else
{
$CostCenterID = $this->input->post('CostCentreID');
$CostName = ucwords(strtolower($this->input->post('CostName')));
$Description = $this->input->post('Description');
//$this->costcenter_model->editcost($Cost);
$cost = array();
$Cost = array('CostCentreID'=>$CostCenterID,'CostName'=>$CostName, 'Description'=>$Description,'createdDate'=>date('Y-m-d H:i:sa'));
$result = $this->costcenter_model->editcost($Cost, $CostCenterID);
if($result == true)
{
$this->session->set_flashdata('success', 'Cost updated successfully');
}
else
{
$this->session->set_flashdata('error', 'Cost updation failed');
}
redirect('costListing');
}
}
function viewcost($CostCenterID = NULL)
{
if($CostCenterID == null)
{
redirect('costListing');
}
$data['Cost'] = $this->costcenter_model->getuserinfo($CostCenterID);
//$data['users'] = $this->purchaseorder_model->getusers();
$this->global['pageTitle'] = 'Siddharth : View Cost';
$this->loadViews("viewcost", $this->global, $data,NULL);
}
/**
* This function is used to delete the user using userId
* @return boolean $result : TRUE / FALSE
function deletecost()
{
if($this->isAdmin() == TRUE)
{
echo(json_encode(array('status'=>'access')));
}
else
{
$CostCenterID = $this->input->Costst('CostCentreID');
$cost = array('CreateDate'=>date('Y-m-d H:i:sa'));
$result = $this->costcenter_model->deletecost($Cost, $CostCenterID);
if ($result > 0) { echo(json_encode(array('status'=>TRUE))); }
else { echo(json_encode(array('status'=>FALSE))); }
}
}
*/
function pageNotFound()
{

View File

@ -18,10 +18,15 @@ class payslip extends BaseController
{
parent::__construct();
$this->load->model('payroll_model');
$this->load->model('monthlypay_model');
$this->load->library('form_validation');
$this->isLoggedIn();
}
function phpAlert($msg) {
echo '<script type="text/javascript">alert("' . $msg . '")</script>';
}
/**
* This function used to call stored procedure named with final_payroll_data()
@ -37,6 +42,113 @@ class payslip extends BaseController
}
function loadBankreportScreen()
{
$Data['Payon'] = $this->payroll_model->getPayOn();
$Data['Bank'] = $this->payroll_model->getBankInfo();
$this->global['pageTitle'] = 'Siddharth : Bank Report Screen';
$this->loadViews("bankreport", $this->global,$Data,NULL);
}
function getBankReport()
{
$bank = $this->input->post('bank');
$payon = $this->input->post('month');
$monthsoptions = array("01" => "Jan", "02" => "Feb","03" => "Mar","04" => "Apr","05" => "May","06" => "June","07"=> "July","08"=> "Aug","09" => "Sep","10"=> "Oct","11" => "Nov","12"=>"Dec");
$m = substr($payon,0,2);
$y = substr($payon,3);
$month = $monthsoptions[$m]."-".$y;
$filename = '';
if($this->input->post('Bank_Report'))
{
$data['result'] = $this->payroll_model->getReportforBank($bank,$payon);
$totamtwords = '';
$totalamt=0.00;
if(!empty($data['result'])){
foreach($data['result'] as $amt)
{
$totalamt += $amt->LessAdvance;
}
}
$totamtwords = $this->convertNumber($totalamt);
$data['BankName']=$bank;
$data['Totalamount']=$totalamt;
$data['Totalamtwords']=$totamtwords;
$data['PayMonth']=$month;
$filename = 'Bank Report for'.$payon.'pdf' ;
$this->load->View("bankreportprint",$data);
}
if($this->input->post('PF_Report'))
{
$data['PFESI'] = $this->payroll_model->getReportforPFESI($payon);
$data['PayMonth']=$month;
$totamtwords = '';
$totalamt=0.00;
if(!empty($data['PFESI'])){
foreach($data['PFESI'] as $pf)
{
$totalamt += ($pf->PF + $pf->CompanyPF);
}
}
$data['Totalamount']=$totalamt;
$totamtwords = $this->convertNumber($totalamt);
$data['Totalamtwords']=$totamtwords;
$filename = 'PF Report for'.$payon.'pdf' ;
$this->load->View("pfreportprint",$data);
}
if($this->input->post('ESI_Report'))
{
$data['PFESI'] = $this->payroll_model->getReportforPFESI($payon);
$data['PayMonth']=$month;
$totamtwords = '';
$totalamt=0.00;
if(!empty($data['PFESI'])){
foreach($data['PFESI'] as $pf)
{
$totalamt += ($pf->EmployeeESI + $pf->CompanyESI);
}
}
$data['Totalamount']=$totalamt;
$totamtwords = $this->convertNumber($totalamt);
$data['Totalamtwords']=$totamtwords;
$filename = 'ESI Report for'.$payon.'pdf';
$this->load->View("esireportprint",$data);
}
$php = $this->output->get_output();
// Load library
$this->load->library('dompdf_gen');
require_once(APPPATH .'third_party/dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF();
$dompdf->set_paper('A4', 'portrait');
$dompdf->load_html($php);
$dompdf->render();
// add the header
$canvas = $dompdf->get_canvas();
$font = Font_Metrics::get_font("helvetica", "bold");
// the same call as in my previous example
$canvas->page_text(72, 18,"",
$font, 6, array(0,0,0));
$dompdf->stream($filename);
}
/**
@ -50,15 +162,170 @@ class payslip extends BaseController
$this->loadViews("payslipupload2", $this->global, NULL);
}
public function monthlyInputs()
{
$current = date("m-Y");
$data['month'] = $this-> monthlypay_model->monthlyListing($current);
$data['fresh'] = $this-> monthlypay_model->getEmpPayDetails();
$this->global['pageTitle'] = 'Siddharth : Payroll Monthly Inputs';
$this->loadViews("monthlypayinputs", $this->global,$data,NULL);
}
function changeMonth()
{
$current = $this->input->post('param1');
$month = $this-> monthlypay_model->monthlyListing($current);
$fresh = $this-> monthlypay_model->getEmpPayDetails();
$data = json_encode(array_merge($month,$fresh));
echo $data;
}
function saveMonthlyData()
{
$month = $this->input->post('param2');
$jsondata =$this->input->post('param1');
$json = json_decode($jsondata,true);
/**
* This function used to load the first screen of the user
*/
$mon = substr($month,0,1);
$year = substr($month,2);
if($mon <10)
{
$mon = '0'.$mon;
}
$month = $mon ."-". $year;
//echo $month;
$total = 0;
$ErrorEmpId = '';
$TotalErrorFlag = 0;
foreach($json as $j)
{
$ErrorFlag = 0;
$EmpID = $j['Employee Id'];
$Name = $j['Employee Name'];
$LOP_Days = $j['LOP Days'];
$Paid_leave = $j['Paid Leave'];
$OT_Hrs_Worked = $j['OT Hours Worked in Hrs'];
$Loan_Recovered = $j['Loan Recovered in ₹'];
$Incentives = $j['Incentives in ₹'];
$Other_Deductions = $j['Other Deductions in ₹'];
$Created_By = $this->session->userdata ( 'userId' );
if(!is_numeric($LOP_Days) || ($LOP_Days > 31) || (strlen((string)$LOP_Days)) > 5 )
{
//echo $EmpID . "-LOP_Days Invalid Data!";
$ErrorFlag++;
}
if(!is_numeric($Paid_leave) || ($Paid_leave > 31) || (strlen((string)$Paid_leave)) > 5)
{
//echo $EmpID . "-Paid Leave Invalid Data!";
$ErrorFlag++;
}
$OT_Hrs_Worked_first = explode(".",$OT_Hrs_Worked);
if(!is_numeric($OT_Hrs_Worked) || (strlen((string)$OT_Hrs_Worked))>6 || (strlen((string)$OT_Hrs_Worked_first[0])) >= 4)// || (strlen((string)$OT_Hrs_Worked_first[1]))> 3 )
{
//echo $EmpID . "-OT Hrs Invalid Data!";
$ErrorFlag++;
}
$Loan_Recovered_first = explode(".",$Loan_Recovered);
if(!is_numeric($Loan_Recovered) || (strlen((string)$Loan_Recovered))>8 || (strlen((string)$Loan_Recovered_first[0]))> 5)
{
//echo $EmpID . "-Loan Recoverd Invalid Data!";
$ErrorFlag++;
}
$Incentives_first = explode(".",$Incentives);
if(!is_numeric($Incentives) || (strlen((string)$Incentives))>8 || (strlen((string)$Incentives_first[0]))> 5)
{
//echo $EmpID . "-Loan Recoverd Invalid Data!";
$ErrorFlag++;
}
$Other_Deductions_first = explode(".",$Other_Deductions);
if(!is_numeric($Other_Deductions) || (strlen((string)$Other_Deductions))>8 || (strlen((string)$Other_Deductions_first[0]))> 5)
{
//echo $EmpID . "-Loan Recoverd Invalid Data!";
$ErrorFlag++;
}
if($ErrorFlag != 0)
{
//echo $EmpID ."- has Invalid Data!";
$ErrorEmpId = $ErrorEmpId ."|". $EmpID;
$TotalErrorFlag++;
}
else//if($ErrorFlag == 0)
{
//nothing
}
}
if($TotalErrorFlag == 0)
{
foreach($json as $j)
{
$EmpID = $j['Employee Id'];
$Name = $j['Employee Name'];
$LOP_Days = $j['LOP Days'];
$Paid_leave = $j['Paid Leave'];
$OT_Hrs_Worked = $j['OT Hours Worked in Hrs'];
$Loan_Recovered = $j['Loan Recovered in ₹'];
$Incentives = $j['Incentives in ₹'];
$Other_Deductions = $j['Other Deductions in ₹'];
$Created_By = $this->session->userdata ( 'userId' );
$monthlypaydata = array('Month_Year'=>$month,'EmpID'=>$EmpID,'LOP_Days'=>$LOP_Days,'Paid_leave'=>$Paid_leave,'OT_Hrs_Worked'=>$OT_Hrs_Worked,'Loan_Recovered'=>$Loan_Recovered,'Incentives'=>$Incentives,'Other_Deductions'=>$Other_Deductions,'Created_By'=>$Created_By);
$result = $this->monthlypay_model->saveMonthlyData_model($monthlypaydata);
$total = $total + $result;
}
}
//echo "<script> alert($ErrorEmpId + '- are have Invalid Data!'); </script>";
if(!empty($ErrorEmpId))
{
echo $ErrorEmpId . "- are have Invalid Data!";
}
echo $total . "- Employees Updated Successfully ";
}
function payslipLisiting()
{
$this->global['pageTitle'] = 'Siddharth : Payslip Listing';
$data['PayInfo'] = $this->payroll_model->GetPayslipdata();
$this->loadViews("paysliplist", $this->global, $data , NULL);
}
function editPayslip($EmpID,$PayOn)
{
$this->global['pageTitle'] = 'Siddharth : Edit Employee Payslip';
$data['PayInfo'] = $this->payroll_model->GetPayslipdata($PayOn,$EmpID);
$this->loadViews("editpayslip", $this->global, $data , NULL);
}
public function viewGenerator()
{
//echo 'inside funtion';
$Data['Payon'] = $this->payroll_model->getPayOn();
//$Data['Emplist'] = $this->payroll_model->getEmployeelist();
$this->global['pageTitle'] = 'Siddharth : Payroll Generater';
@ -138,7 +405,7 @@ function getEmployee()
else
{
$Payon = $this->input->post('PayOn');
//echo "Payon" . $Payon;
if($All != '')
{
@ -155,7 +422,7 @@ function getEmployee()
$EmpID = $result[$i]['EmpId'];
$Data['PayDetails'] = $this->payroll_model->GetPayslipdata($Payon,$EmpID);
//print_r($Data['PayDetails']);//die();
-
$totalsalary =$Data['PayDetails'][0]->LessAdvance;
$totalsalaryinwords = $this->convertNumber(round($totalsalary));
$Data['amtinwords']=$totalsalaryinwords;
@ -170,11 +437,13 @@ function getEmployee()
else
{
$EmpID = $this->input->post('Employee');
//echo "EmpID" . $EmpID;
$Data['PayDetails'] = $this->payroll_model->GetPayslipdata($Payon,$EmpID);
$totalsalary =$Data['PayDetails'][0]->LessAdvance;
$totalsalaryinwords = $this->convertNumber(round($totalsalary));
$Data['amtinwords']=$totalsalaryinwords;
$this->load->View("payslipgenerateprint", $Data );
}
@ -214,6 +483,32 @@ function getEmployee()
}
function updatePayslip()
{
$paykey = $this->input->post("Key");
$EmpID = $this->input->post("EmpID");
$PayOn = $this->input->post("PayOn");
$otherallowence = $this->input->post("otherallowence");
$otherdeductions = $this->input->post("otherdeductions");
$incentive = $this->input->post("incentive");
$netpay = $this->input->post("netpay");
$esi = $this->input->post("txtesi");
$pf = $this->input->post("txtpf");
$basic = $this->input->post("txtbasicda");
$hra = $this->input->post("txthra");
$otsalary = $this->input->post("otsalary");
$Totaldeduction = $esi + $pf + $otherdeductions;
$SalaryAsPerPF = ($basic + $hra + $otsalary) - $Totaldeduction;
$userid = $this->session->userdata ( 'userId' );
$remarks = 'Manual Edit By' . $userid ." On " . date('Y-m-d');
$paydetails = array('Key'=>$paykey,'EmpID'=>$EmpID,'PayOn'=>$PayOn,'Other_allowances'=>$otherallowence,'OtherDeductions'=>$otherdeductions,'Incentive'=>$incentive,'LessAdvance'=>$netpay,'TotalSalary'=>$netpay,'SalaryAsPerPF'=>$SalaryAsPerPF,'Totaldeduction'=>$Totaldeduction,'remarks'=>$remarks);
$result = $this->payroll_model->updateEmpPayslip($paydetails);
echo $result;
}
/**
* This function used to upload the Excel file Details

View File

@ -9,3 +9,12 @@ ERROR - 2017-10-05 07:02:30 --> Severity: Warning --> DOMXPath::query(): Invali
ERROR - 2017-10-05 07:02:30 --> Severity: Warning --> DOMXPath::query(): Invalid expression /opt/lampp/htdocs/5oct/siddharth_application/application/third_party/dompdf/include/stylesheet.cls.php 697
ERROR - 2017-10-05 07:02:31 --> Severity: Warning --> DOMXPath::query(): Invalid expression /opt/lampp/htdocs/5oct/siddharth_application/application/third_party/dompdf/include/stylesheet.cls.php 697
ERROR - 2017-10-05 07:02:31 --> Severity: Warning --> DOMXPath::query(): Invalid expression /opt/lampp/htdocs/5oct/siddharth_application/application/third_party/dompdf/include/stylesheet.cls.php 697
ERROR - 2017-10-05 13:21:32 --> Severity: Notice --> Undefined variable: searchText C:\5.6\xampp\htdocs\SIA\SIANEW\siddharth_application\application\views\emppayListing.php 26
ERROR - 2017-10-05 13:21:32 --> Severity: Notice --> Undefined property: stdClass::$OT_Rate C:\5.6\xampp\htdocs\SIA\SIANEW\siddharth_application\application\views\emppayListing.php 68
ERROR - 2017-10-05 13:21:32 --> Severity: Notice --> Undefined property: stdClass::$OT_Rate C:\5.6\xampp\htdocs\SIA\SIANEW\siddharth_application\application\views\emppayListing.php 68
ERROR - 2017-10-05 13:21:32 --> Severity: Notice --> Undefined property: stdClass::$OT_Rate C:\5.6\xampp\htdocs\SIA\SIANEW\siddharth_application\application\views\emppayListing.php 68
ERROR - 2017-10-05 13:21:32 --> Severity: Notice --> Undefined property: stdClass::$OT_Rate C:\5.6\xampp\htdocs\SIA\SIANEW\siddharth_application\application\views\emppayListing.php 68
ERROR - 2017-10-05 13:21:32 --> Severity: Notice --> Undefined property: stdClass::$OT_Rate C:\5.6\xampp\htdocs\SIA\SIANEW\siddharth_application\application\views\emppayListing.php 68
ERROR - 2017-10-05 13:21:32 --> Severity: Notice --> Undefined property: stdClass::$OT_Rate C:\5.6\xampp\htdocs\SIA\SIANEW\siddharth_application\application\views\emppayListing.php 68
ERROR - 2017-10-05 13:21:32 --> Severity: Notice --> Undefined property: stdClass::$OT_Rate C:\5.6\xampp\htdocs\SIA\SIANEW\siddharth_application\application\views\emppayListing.php 68
ERROR - 2017-10-05 13:21:37 --> Severity: Notice --> Undefined property: stdClass::$OT_Rate C:\5.6\xampp\htdocs\SIA\SIANEW\siddharth_application\application\views\editOldemppay.php 93

View File

@ -25,6 +25,14 @@ class emppaydate_model extends CI_Model
return $result;
}
function deleteEmployeePay($EmpID)
{
$this->db->where('EmpID',$EmpID);
$query = $this->db->delete('T_Emp_Pay_Data');
return $query;
}

View File

@ -10,19 +10,68 @@ class monthlypay_model extends CI_Model
* @param number $segment : This is pagination limit
* @return array $result : This is result
*/
function monthlyListing()
function monthlyListing($current="")
{
$this->db->select('T_Monthly_Pay_Inputs.*,T_Employee_Details.FirstName,T_Employee_Details.LastName');
$this->db->from('T_Monthly_Pay_Inputs');
$this->db->join('T_Employee_Details','T_Monthly_Pay_Inputs.EmpID=T_Employee_Details.EmpID');
$this->db->order_by("Month_Year", "desc");
$this->db->where('Month_Year',$current);
$query = $this->db->get();
$result = $query->result();
return $result;
$result = $query->result();
return $result;
}
function getEmpPayDetails()
{
$this->db->select('T_Emp_Pay_Data.EmpID,T_Employee_Details.FirstName,T_Employee_Details.LastName');
$this->db->from('T_Emp_Pay_Data');
$this->db->join('T_Employee_Details','T_Emp_Pay_Data.EmpID=T_Employee_Details.EmpID');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function saveMonthlyData_model($data)
{
$month = $data['Month_Year'];
$empid = $data['EmpID'];
$count=0;
$this->db->select('count(*) as count');
$this->db->from('T_Monthly_Pay_Inputs');
$this->db->where('Month_Year',$month);
$this->db->where('EmpID',$empid);
$isExits = $this->db->get();
$res = $isExits->result_array();
if(!empty($res))
{
$count = $res[0]['count'];
}
if($count == 0 )
{
$i = $this->db->insert('T_Monthly_Pay_Inputs',$data);
return $i;
}
elseif($count == 1)
{
$this->db->where('Month_Year',$month);
$this->db->where('EmpID',$empid);
$i = $this->db->update('T_Monthly_Pay_Inputs',$data);
return $i;
}
}
function addNewmonthlisting($m_list)
@ -41,8 +90,7 @@ function addNewmonthlisting($m_list)
$this->db->select('T_Monthly_Pay_Inputs.*,T_Employee_Details.FirstName,T_Employee_Details.LastName');
$this->db->from('T_Monthly_Pay_Inputs');
$this->db->join('T_Employee_Details','T_Monthly_Pay_Inputs.EmpID=T_Employee_Details.EmpID');
//$this->db->where('isDeleted', 0);
//$this->db->where('roleId !=', 1);
$this->db->where('T_Monthly_Pay_Inputs.EmpID', $EmpID);
$this->db->where('T_Monthly_Pay_Inputs.Month_Year', $month_year);
$query = $this->db->get();
@ -56,9 +104,9 @@ function addNewmonthlisting($m_list)
$monthyear=$monthdata['Month_Year'];
//$this->db->where('EmpID',$employeeid);
$this->db->where('EmpID' ,$EmpID);
//$this->db->where('Month_Year' ,$EmpID);
$this->db->where('Month_Year',$monthyear);
$this->db->update('T_Monthly_Pay_Inputs',$monthdata);

View File

@ -140,22 +140,33 @@ class Payroll_model extends CI_Model
*/
function GetPayslipdata($PayOn='',$EmpId='')
{
$this->db->select('Pay.*,payfile.TotalNoofDays as TotalNoofDays ,Emp.FirstName as FName ,Emp.LastName as Lname,Emp.DateofBirth as Dob,Emp.PANNo as Pan,Emp.BankBranchName as BankName,Emp.AadharNo,Emp.IFSCCode as IFSCCode,Emp.DateofJoining as DOJ,Emp.Designation as Designation,Dep.DepartmentName as DeptName');
//echo "FROM MODEL" . $PayOn . $EmpId;
$this->db->select('Pay.*,Emp.FirstName as FName ,Emp.LastName as Lname,Emp.DateofBirth as Dob,Emp.PANNo as Pan,Emp.BankBranchName as BankName,Emp.AadharNo,Emp.IFSCCode as IFSCCode,Emp.DateofJoining as DOJ,Emp.Designation as Designation,Dep.DepartmentName as DeptName');
$this->db->from('T_Payroll Pay');
$this->db->join('T_Payroll_File payfile', 'Pay.PayOn = payfile.PayOn');
//$this->db->join('T_Payroll_File payfile', 'Pay.PayOn = payfile.PayOn');
$this->db->join('T_Employee_Details Emp', 'Pay.EmpID = Emp.EmpID');
$this->db->join('T_DepartmentDetails Dep', 'Emp.Departmentcode = Dep.DEPCode');
if($PayOn != '')
{
$this->db->where('Pay.PayOn', $PayOn);
}
if($EmpId != '')
{
$this->db->where('Pay.EmpID', $EmpId);
}
$this->db->order_by("Pay.EmpID", "asc");
if($PayOn != '')
{
$this->db->order_by("Pay.EmpID", "asc");
}
if($PayOn == '' && $EmpId == '')
{
$this->db->order_by("Pay.PayOn", "desc");
}
$query = $this->db->get();
return $query->result();
//print_r($query->result());die();
}
/* *//**
@ -164,12 +175,45 @@ class Payroll_model extends CI_Model
*/
function getPayOn()
{
$this->db->select('DISTINCT(PayOn)');
$this->db->from('T_Payroll_File');
$this->db->select('DISTINCT(Month_Year)');
$this->db->from('T_Monthly_Pay_Inputs');
$this->db->order_by("Month_Year", "desc");
$query = $this->db->get();
return $query->result();
}
function getBankInfo()
{
$this->db->select('*');
$this->db->from('T_Bank_Details');
//$this->db->order_by("Month_Year", "desc");
$query = $this->db->get();
return $query->result();
}
function getReportforBank($bank,$payon)
{
$this->db->select('Pay.*,Emp.FirstName as FName ,Emp.LastName as Lname,Emp.PANNo as Pan,Emp.BankBranchName as BankName,Emp.IFSCCode as IFSC,Bank.Address as BAddress');
$this->db->from('T_Payroll Pay');
$this->db->join('T_Employee_Details Emp', 'Pay.EmpID = Emp.EmpID');
$this->db->join('T_Bank_Details Bank', 'Emp.BankBranchName = Bank.Bank_name');
$this->db->where('Emp.BankBranchName',$bank);
$this->db->where('Pay.PayOn',$payon);
$query = $this->db->get();
return $query->result();
}
function getReportforPFESI($payon)
{
$this->db->select('Pay.EmployeeESI,Pay.PF,Pay.CompanyESI,Pay.CompanyPF,Emp.FirstName as FName ,Emp.LastName as Lname,Emp.PFNO,Emp.ESI');
$this->db->from('T_Payroll Pay');
$this->db->join('T_Employee_Details Emp', 'Pay.EmpID = Emp.EmpID');
$this->db->where('Pay.PayOn',$payon);
$query = $this->db->get();
return $query->result();
}
/* *//**
* This function is used to get the PayOn details from T_Payroll_File
* @return array $result : This is result of the query
@ -258,5 +302,20 @@ class Payroll_model extends CI_Model
}
function updateEmpPayslip($data)
{
$key = $data['Key'];
$PayOn = $data['PayOn'];
$EmpID = $data['EmpID'];
$this->db->where('Key', $key);
$this->db->where('PayOn',$PayOn);
$this->db->where('EmpID',$EmpID);
$result = $this->db->update('T_Payroll',$data);
return $result;
}
}
?>

View File

@ -156,19 +156,7 @@ $("#due_started").datepicker({
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<span for="OT_Rate">OT Rate(Per Hour)</span><font color="Red">*</font>
<div class="form-group">
<?php
$data = array('name' => 'OT_Rate','value' => set_value('OT_Rate'), 'class' => 'form-control num' ,'style'=>'text-transform:uppercase;','pattern="([0-9]{1,3}([.][0-9]{1,2})?' ,'title'=>'Enter the Valid OT Rate, Minimum 1 digit, Maximum 2 digit');
echo form_input($data);
?>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<span for="Allowances">Allowances</span><font color="Red">*</font>
@ -195,13 +183,8 @@ $("#due_started").datepicker({
</div>
</div>
</div>
</div><!--row completed div-->
<div class="row">
<div class="col-md-3">
<div class="col-md-3">
<div class="form-group">
<span for="ESI_Rate">ESI Rate(%)</span><font color="Red">*</font>
<div class="form-group">
@ -213,6 +196,13 @@ $("#due_started").datepicker({
</div>
</div>
</div>
</div><!--row completed div-->
<div class="row">
<!--for food allowances-->
<div class="col-md-3">
<div class="form-group">
@ -372,12 +362,9 @@ function duecalculation()
var totaldue=0;
var loan=document.getElementById('Loan_Amount').value;
var due=document.getElementById('monthly_due').value;
//alert(loan+'-'+due);
// if(loan == ""){
// $('#Loan_Amount').val(0.00);
// $('#monthly_due').val(0.00);
// }
if(loan != 0)
{
if(due == 0)
@ -387,7 +374,7 @@ function duecalculation()
}
else
{
//due=document.getElementById('monthly_due').value;
totaldue=loan/due;
if(totaldue < 1)

View File

@ -0,0 +1,165 @@
<?php
$monthsoptions = array("01" => "Jan", "02" => "Feb","03" => "Mar","04" => "Apr","05" => "May","06" => "June","07"=> "July","08"=> "Aug","09" => "Sep","10"=> "Oct","11" => "Nov","12"=>"Dec");
?>
<script>
$(function() {
$(".select2").select2();
$("#bankreport").click(function(){
var bank = $('#bank').val();
var payon = $('#month').val();
if(bank != '-1' && payon !='-1')
{
$('#content').loader('show');
$('#BankReportGenerator').attr('action', '<?php echo base_url() ?>payslip/getBankReport');
$('form#BankReportGenerator').submit();
$('#content').loader('hide');
}
else
{
alert('Select Bank Name and Pay Date');
return false;
}
});
$("#pfreport").click(function(){
var bank = $('#bank').val();
var payon = $('#month').val();
// alert(payon);
if(payon !='-1')
{
$('#content').loader('show');
$('#BankReportGenerator').attr('action', '<?php echo base_url() ?>payslip/getBankReport');
$('form#BankReportGenerator').submit();
$('#content').loader('hide');
}
else
{
alert('Select Pay Date');
return false;
}
});
$("#esireport").click(function(){
var bank = $('#bank').val();
var payon = $('#month').val();
//alert(payon);
if(payon !='-1')
{
$('#content').loader('show');
$('#BankReportGenerator').attr('action', '<?php echo base_url() ?>payslip/getBankReport');
$('form#BankReportGenerator').submit();
$('#content').loader('hide');
}
else
{
alert('Select Pay Date');
return false;
}
});
});
</script>
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
<center>Siddharth Industries - Bank Report Generator</center>
</h1>
</section>
<section class="content">
<div class="row" style="border:2px dotted; padding:5%">
<form id="BankReportGenerator" action="" method="post" role="form" >
<div class="row" >
<div class="col-md-4">
<span for="selectmonth">Select Bank</span>
<select id="bank" name="bank" class="form-control select2" style="width: 100%;">
<option value="-1">Select Bank</option>
<?php
if(!empty($Bank))
{
foreach ($Bank as $b)
{
if (!empty($b->Bank_name))
{
echo "<option value=\"".$b->Bank_name."\">".$b->Bank_name."</option>";
}
}
}
?>
</select>
</div>
<div id="content"></div>
<div class="col-md-4 col-md-offset-2">
<span>Month</span>
<select id="month" name="month" class="form-control select2" type="text" class="form-control">
<option value="-1">Select Pay Date</option>
<?php
if(!empty($Payon)){
foreach($Payon as $pay)
{
$m = substr($pay->Month_Year,0,2);
$y = substr($pay->Month_Year,3);
$tot = $monthsoptions[$m]."-".$y;
echo "<option value=\"".$pay->Month_Year."\">".$tot."</option>";
}
}
?>
</select>
</div>
</div>
<br/>
<div class="col-md-4 col-md-offset-6" align = "right">
<input type="submit" class="btn btn-info" id="bankreport" name="Bank_Report" value="Bank Report" />
<input type="submit" class="btn btn-info" id="pfreport" name="PF_Report" value="PF Report" />
<input type="submit" class="btn btn-info" id="esireport" name="ESI_Report" value="ESI Report" />
</div>
</div>
</section>
</div>

View File

@ -0,0 +1,83 @@
<?php
$Bankname = '';
$TotalAmount = '';
$TotalAmtwords = '';
$address = '';
if(!empty($result))
{
foreach($result as $r)
{
$address=$r->BAddress;
//die();
}
}
?>
<html>
<head>
<style>
table {
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
}
p
{
text-indent: 40px;
}
</style>
</head>
<body>
<center><h2>Bank Letter</h2></center>
To<br> &nbsp;&nbsp;&nbsp; The bank Manager,<br>
&nbsp;&nbsp;&nbsp; <?php echo $BankName;?>,<br>
&nbsp;&nbsp;&nbsp; <?php echo $address;?>.<br>
<br>
Sir/Madam,
<br><br><p>
For Your kindly information please credit employees salary of <?php echo $PayMonth;?> for Siddharth Indistries.Total Amount i- <b>Rs.<?php echo number_format($Totalamount,2,'.','');?></b>
&nbsp;&nbsp;<b>(<?php echo $Totalamtwords;?>)</b> with cheque <b>No:123456789</b></p>
<p>Employee List given Below:</p>
<table style="height: 13px;" width="500" ;>
<thead>
<tr>
<th style="width: 108px;">Employee Name</th>
<th style="width: 108px;">Salary Amount</th>
<th style="width: 109px;">Ac No</th>
<th style="width: 109px;">IFSC</th>
<th style="width: 80px;">BANK Name</th>
</tr>
</thead>
<tbody>
<?php
if(!empty($result))
{
foreach($result as $data)
{
?>
<tr>
<td style="width: 108px;"><?php echo $data->FName . " ".$data->Lname;?></td>
<td style="width: 108px;text-align:right;"><?php echo number_format($data->LessAdvance,2,'.','');?></td>
<td style="width: 109px;"><?php echo $data->BankAccountNumber;?></td>
<td style="width: 109px;"><?php echo $data->IFSC;?></td>
<td style="width: 111px;"><?php echo $data->BankName;?></td>
</tr>
<?php }}?>
</tbody>
</table>
</body>
</html>

View File

@ -0,0 +1,843 @@
<?php
$Key = '';
$PayOn='';
$EmpID='';
$Empname="";
$Basic_Pay='';
$HRA_Rate='';
$TotalCalDays = '';
$NoofDaysWorked = '';
$LOP = '';
$Paid_Leave = '';
$ActualSalary ='';
$PerDaySalary = '';
$WorkedSalary = '';
$HRA = '';
$OTperHours = '';
$OTSalary = '';
$ESIGrossSalary = '';
$EmployeeESI = '';
$PF = '';
$CompanyESI = '';
$CompanyPF = '';
$TotalCompCon = '';
$OtherDeductions = '';
$TotalDeduction = '';
$SalaryAsPerPF = '';
$FoodAllowance='';
$Incentive = '';
$Advance = '';
$BalanceAdvance = '';
$LessAdvance = '';
$Other_allowances = '';
$Remarks = '';
$BankAccountNumber = '';
$PFNumber = '';
$ESINumber = '';
$UANNO = '';
$Dob = '';
$Pan = '';
$BankName = '';
$AadharNo = '';
$IFSCCode = '';
$DOJ = '';
$Designation = '';
$DeptName = '';
$totalearnings ='';
$totaldeductions = '';
$monthsoptions = array("01" => "Jan", "02" => "Feb","03" => "Mar","04" => "Apr","05" => "May","06" => "June","07"=> "July","08"=> "Aug","09" => "Sep","10"=> "Oct","11" => "Nov","12"=>"Dec");
if(!empty($PayInfo))
{
foreach ($PayInfo as $ep)
{
$Key = $ep->Key;
$PayOn1=$ep->PayOn;
$month = substr($PayOn1,0,2);
$year = substr($PayOn1,3);
$PayOn = $monthsoptions[$month]."-".$year;
$EmpID=$ep->EmpID;
$Empname=$ep->FName ." ". $ep->Lname ;
$EmpDetails = $EmpID ."-".$Empname;
$TotalCalDays = $ep->TotalCalDays;
$NoofDaysWorked = $ep->NoofDaysWorked;
$LOP = $ep->LOP;
$Paid_Leave = $ep->Paid_Leave;
$ActualSalary = $ep->ActualSalary;
$PerDaySalary = $ep->PerDaySalary;
$WorkedSalary = $ep->WorkedSalary;
$HRA = $ep->HRA;
$OTperHours = $ep->OTperHours;
$OTSalary = $ep->OTSalary;
$ESIGrossSalary = $ep->ESIGrossSalary;
$EmployeeESI = $ep->EmployeeESI;
$PF = $ep->PF;
$CompanyESI = $ep->CompanyESI;
$CompanyPF = $ep->CompanyPF;
$TotalCompCon = $ep->TotalCompCon;
$OtherDeductions = $ep->OtherDeductions;
$TotalDeduction = $ep->TotalDeduction;
$SalaryAsPerPF = $ep->SalaryAsPerPF;
$FoodAllowance=$ep->FoodAllowance;
$Incentive = $ep->Incentive;
$Advance = $ep->Advance;
$BalanceAdvance = $ep->BalanceAdvance;
$LessAdvance = $ep->LessAdvance;
$Other_allowances = $ep->Other_allowances;
$Remarks = $ep->Remarks;
$BankAccountNumber = $ep->BankAccountNumber;
$PFNumber = $ep->PFNumber;
$ESINumber = $ep->ESINumber;
$UANNO = $ep->UANNO;
$Dob = date_create($ep->Dob);
$Dob = date_format($Dob,"Y-m-d");
$Pan = $ep->Pan;
$BankName = $ep->BankName;
$AadharNo = $ep->AadharNo;
$IFSCCode = $ep->IFSCCode;
$DOJ = date_create($ep->DOJ);
$DOJ = date_format($DOJ,"Y-m-d");
$Designation = $ep->Designation;
$DeptName = $ep->DeptName;
$totalearnings = $WorkedSalary + $HRA + $FoodAllowance + $Other_allowances + $Incentive + $OTSalary;
$totaldeductions = $PF + $EmployeeESI + $Advance + $OtherDeductions;
}
}
?>
<style type="text/css">
.num {
text-align:right;
}
</style>
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
<!--title-->
<center>Edit Payslip Details - <?php echo $PayOn ."-".$EmpID . "-" .$Empname; ?> </center>
</h1>
</section>
<section class="content">
<div style="text-align:right;">
<a href="<?php echo base_url() ?>PaysilpListing" class="btn btn-primary" value="Back">Back</a>
</div>
<br/>
<div class="row">
<!-- left column -->
<div class="col-md-12">
<!-- general form elements -->
<div class="box box-primary">
<!-- form start-->
<form role="form" id="editpayslip" action="<?php echo base_url() ?>payslip/updatePayslip" method="post">
<div class="box-body">
<div class="col-md-12">
<legend>Pay Details</legend>
</div>
<div class="row">
<input type="hidden" readonly id="Key" name="Key" value="<?php echo $Key; ?>">
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for="EmpID">PayOn</span>
<input type="hidden" name="PayOn" value="<?php echo $PayOn1; ?>">
<input type="hidden" name="EmpID" value="<?php echo $EmpID; ?>">
<input type="text" class="form-control" readonly id="PayOn" name="PayOn1" value="<?php echo $PayOn; ?>">
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for="EmpID">Employee ID</span>
<input type="text" class="form-control" readonly id="Emp" name="Emp" value="<?php echo $EmpDetails; ?>">
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for="Basic_Pay">Designation & Dept</span>
<input type="text" class="form-control requried num" id="Designation" name="Designation" value="<?php echo $Designation ." - ". $DeptName ; ?>" readonly>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for="PF_Rate">Total Calendar Days</span>
<input type="text" class="form-control required num" id="totoaldays" name="totoaldays" value="<?php echo $TotalCalDays;?>" readonly> <!-- pattern="([0-9]{1,2}([.][0-9]{1,2})?)" title="Minimum 1 digit,Maximum 2 Digit">-->
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for="PF_Rate">Loss Of Pay</span>
<input type="text" class="form-control required num" id="LOP" name="LOP" value="<?php echo $LOP;?>" readonly> <!-- pattern="([0-9]{1,2}([.][0-9]{1,2})?)" title="Minimum 1 digit,Maximum 2 Digit">-->
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for="PF_Rate">Paid Days</span>
<input type="text" class="form-control required num" id="Paiddays" name="Paiddays" value="<?php echo $NoofDaysWorked;?>" readonly> <!-- pattern="([0-9]{1,2}([.][0-9]{1,2})?)" title="Minimum 1 digit,Maximum 2 Digit"> -->
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for="PF_Rate">Paid Leave</span>
<input type="text" class="form-control required num" id="paidleave" name="paidleave" value="<?php echo $Paid_Leave;?>" readonly><!-- pattern="([0-9]{1,2}([.][0-9]{1,2})?)" title="Minimum 1 digit,Maximum 2 Digit"> -->
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for="PF_Rate">Loan Balance</span>
<input type="text" class="form-control required num" id="loanbal" name="loanbal" value="<?php echo $BalanceAdvance;?>" readonly> <!-- pattern="([0-9]{1,2}([.][0-9]{1,2})?)" title="Minimum 1 digit,Maximum 2 Digit"> -->
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for="ESI_Rate">OT Hrs Worked</span>
<input type="text" class="form-control required num" id="othrs" name="othrs" value="<?php echo $OTperHours; ?>" readonly> <!-- pattern="([0-9]{1,2}([.][0-9]{1,2})?)" title="Minimum 1 digit,Maximum 2 Digit"> -->
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for="ESI_Rate">Bank Name</span>
<input type="text" class="form-control required num" id="bankname" name="bankname" value="<?php echo $BankName; ?>" readonly> <!-- pattern="([0-9]{1,2}([.][0-9]{1,2})?)" title="Minimum 1 digit,Maximum 2 Digit">-->
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for="ESI_Rate">Account No</span>
<input type="text" class="form-control required num" id="acno" name="acno" value="<?php echo $BankAccountNumber; ?>" readonly><!--pattern="([0-9]{1,2}([.][0-9]{1,2})?)" title="Minimum 1 digit,Maximum 2 Digit">-->
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for="ESI_Rate">IFSC Code</span>
<input type="text" class="form-control required num" id="ifsc" name="ifsc" value="<?php echo $IFSCCode; ?>" readonly><!--pattern="([0-9]{1,2}([.][0-9]{1,2})?)" title="Minimum 1 digit,Maximum 2 Digit">-->
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for="ESI_Rate">PAN</span>
<input type="text" class="form-control required num" id="pan" name="pan" value="<?php $Pan; ?>" readonly><!-- pattern="([0-9]{1,2}([.][0-9]{1,2})?)" title="Minimum 1 digit,Maximum 2 Digit">-->
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for ="Food_Allowances">PF Number</span>
<input type="text" class="form-control required num" id="pf" name="pf" value="<?php echo $PFNumber; ?>" readonly><!--pattern="([0-9]{1,3}([.][0-9]{1,2})?)" title="Minimum 1 digit,Maximum 3 Digit"> -->
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for ="Food_Allowances">ESI Number</span>
<input type="text" class="form-control required num" id="esi" name="esi" value="<?php echo $ESINumber; ?>" readonly><!-- pattern="([0-9]{1,3}([.][0-9]{1,2})?)" title="Minimum 1 digit,Maximum 3 Digit"> -->
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div class="form-group">
<span for ="Food_Allowances">Aadhar No</span>
<input type="text" class="form-control required num" id="aadhar" name="aadhar" value="<?php echo $AadharNo; ?>"readonly><!-- pattern="([0-9]{1,3}([.][0-9]{1,2})?)" title="Minimum 1 digit,Maximum 3 Digit"> -->
</div>
</div>
</div>
</div>
<div class="col-md-12">
<legend>Total Earnings&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total Deductions</legend>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label style="display:block;text-align:right;"><h4>Basic Plus DA</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control num" id="txtbasicda" name="txtbasicda" value="<?php echo $WorkedSalary;?>" onchange="calculateSalary();" readonly>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label style="display:block;text-align:right;"><h4>Providenet Fund</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control requried num" id="txtpf" name="txtpf" value="<?php echo $PF;?>" onchange="calculateSalary();" readonly>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label style="display:block;text-align:right;"><h4>House Rent Allowence</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control num" id="txthra" name="txthra" value="<?php echo $HRA;?>" onchange="calculateSalary();" readonly>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label style="display:block;text-align:right;"><h4>Employee State Insurance</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control requried num" id="txtesi" name="txtesi" value="<?php echo $EmployeeESI; ?>" onchange="calculateSalary();" readonly>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label style="display:block;text-align:right;"><h4>Food Allowance</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control num" id="txtfood" name="txtfood" value="<?php echo $FoodAllowance?>" onchange="calculateSalary();" readonly>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label style="display:block;text-align:right;"><h4>Loan Recovery</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control requried num" id="txtloandue" name="txtloandue" value="<?php echo $Advance;?>" onchange="calculateSalary();" readonly>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label style="display:block;text-align:right;"><h4>Other Allowance</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control num" id="otherallowence" name="otherallowence" value="<?php echo $Other_allowances;?>" onchange="calculateSalary();" >
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label style="display:block;text-align:right;"><h4>Other Deductions</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control requried num" id="otherdeductions" name="otherdeductions" value="<?php echo $OtherDeductions; ?>" onchange="calculateSalary();" >
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label style="display:block;text-align:right;"><h4>Incentive</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control num" id="incentive" name="incentive" value="<?php echo $Incentive;?>" onchange="calculateSalary();" >
</div>
</div>
</div>
<div class="col-md-3">
</div>
</div>
<div class="col-md-3">
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label style="display:block;text-align:right;"><h4>OT Salary</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control num" id="otsalary" name="otsalary" value="<?php echo $OTSalary;?>" onchange="calculateSalary();" readonly>
</div>
</div>
</div>
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
</div>
<legend></legend>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label style="display:block;text-align:right;"><h4>Total Earnings</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control num" id="totalearnings" name="totalearnings" value="<?php echo number_format(round($totalearnings),2,'.','');?>" readonly>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label style="display:block;text-align:right;"><h4>Total Deductions</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control requried num" id="totaldeductions" name="totaldeductions" value="<?php echo number_format(round($totaldeductions),2,'.','');?>" readonly>
</div>
</div>
</div>
</div>
<legend></legend>
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label><h4>Net Pay(Rounded)</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control requried num" id="netpay" name="netpay" value="<?php echo number_format(round($LessAdvance),2,'.',''); ?>" readonly>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<center><label><h4>Company Contribution</h4></label></center>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control requried num" id="companycon" name="companycon" value="<?php echo number_format(round($TotalCompCon),2,'.','');?>" readonly>
</div>
</div>
</div>
</div>
<legend></legend>
<div id="content">
<div class="box-footer" style="text-align:right">
<input type="button" id ="save" class="btn btn-primary" value="Submit" />
<input type="reset" class="btn btn-primary" value="Reset" />
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<script>
function calculateSalary()
{
var otherallowence = 0.00;
var otherdeductions = 0.00;
var incentive = 0.00;
var txtbasicda = 0.00;
var txtpf = 0.00;
var txthra = 0.00;
var txtesi = 0.00;
var txtfood = 0.00;
var txtloandue =0.00;
var otherallowence = 0.00;
var otherdeductions = 0.00;
var incentive =0.00;
var otsalary = 0.00;
var totalearnings = 0.00;
var totaldeductions = 0.00;
var netpay = 0.00;
var res = isNaN($('#otherallowence').val());
var res1 = isNaN($('#otherdeductions').val());
var res2 = isNaN($('#incentive').val());
if(res || res1 || res2)
{
alert("Enter a Number");
return false;
}else
{
otherallowence = parseFloat($('#otherallowence').val());
otherdeductions = parseFloat($('#otherdeductions').val());
incentive = parseFloat($('#incentive').val());
txtbasicda = parseFloat($('#txtbasicda').val());
txtpf = parseFloat($('#txtpf').val());
txthra = parseFloat($('#txthra').val());
txtesi = parseFloat($('#txtesi').val());
txtfood = parseFloat($('#txtfood').val());
txtloandue = parseFloat($('#txtloandue').val());
otherallowence = parseFloat($('#otherallowence').val());
otherdeductions = parseFloat($('#otherdeductions').val());
incentive = parseFloat($('#incentive').val());
otsalary = parseFloat($('#otsalary').val());
totalearnings = parseFloat($('#totalearnings').val());
totaldeductions = parseFloat($('#totaldeductions').val());
netpay = parseFloat($('#netpay').val());
totalearnings = parseFloat(txtbasicda + txthra + txtfood + otherallowence + incentive + otsalary,2);
totaldeductions = parseFloat(otherdeductions + txtpf + txtesi + txtloandue,2);
netpay = totalearnings - totaldeductions;
$('#totalearnings').val((Math.round(totalearnings)).toFixed(2));
$('#totaldeductions').val((Math.round(totaldeductions)).toFixed(2));
$('#netpay').val((Math.round(netpay)).toFixed(2));
return true;
}
}
$("#save").click(function(){
if(calculateSalary())
{
$.ajax({
data:$("#editpayslip").serialize(),
type:"POST",
url:"<?php echo base_url();?>payslip/updatePayslip",
success:function(result) {
if(result)
{
var i =result;
if(i == "1")
{
alert("sucessfully Updated..!");
}
else
{
alert("Something went wrong. Try later..!");
}
window.location.href = "<?php echo base_url();?>PaysilpListing";
}
}
});
}
});
</script>

View File

@ -19,17 +19,7 @@
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<!-- <div class="box-tools">
<form action="<?php echo base_url() ?>emppaydate/emppayListing" method="POST" id="searchList">
<div class="input-group">
<input type="text" name="searchText" value="<?php echo $searchText; ?>" class="form-control input-sm pull-right" style="width: 150px;" placeholder="Search"/>
<div class="input-group-btn">
<button class="btn btn-sm btn-default searchList"><i class="fa fa-search"></i></button>
</div>
</div>
</form>
</div> -->
</div><!-- /.box-header -->
<div class="box-body">
<table id="datatable" class="table table-bordered table-hover" style="font-size:12px;text-align: right;">
@ -41,7 +31,7 @@
<th width="8%">Basic Pay in </th>
<th width="8%">HRA Rate in %</th>
<th width="8%">HRA Amt in </th>
<th width="8%">OT Rate in </th>
<th width="9%">Allowances in </th>
<th width="8%">PF Ratein %</th>
<th width="8%">ESI Rate in %</th>
@ -65,7 +55,7 @@
<td><?php echo $record->Basic_Pay ?></td>
<td><?php echo $record->HRA_Rate ?></td>
<td><?php echo $record->HRA_Amount; ?></td>
<td><?php echo $record->OT_Rate ?></td>
<td><?php echo $record->Allowances ?></td>
<td><?php echo $record->PF_Rate ?></td>
<td><?php echo $record->ESI_Rate ?></td>
@ -82,7 +72,7 @@
</div><!-- /.box-body -->
<!-- <div class="box-footer clearfix">
<?php //echo $this->pagination->create_links(); ?>
</div> -->
</div><!-- /.box -->
</div>
@ -91,15 +81,7 @@
</div>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/common.js" charset="utf-8"></script>
<script type="text/javascript">
// jQuery(document).ready(function(){
// jQuery('ul.pagination li a').click(function (e) {
// e.preventDefault();
// var link = jQuery(this).get(0).href;
// var value = link.substring(link.lastIndexOf('/') + 1);
// jQuery("#searchList").attr("action", baseURL + "emppayListings/" + value);
// jQuery("#searchList").submit();
// });
// });
$(function () {
$('#datatable').DataTable({
@ -107,7 +89,7 @@
"lengthChange": true,
"searching": true,
"ordering": true,
"aaSorting": [[ 0, "desc" ]],
"aaSorting": [[ 0, "asc" ]],
"info": true,
"autoWidth": true

View File

@ -0,0 +1,85 @@
<?php
if(!empty($result))
{
foreach($result as $r)
{
$address=$r->BAddress;
//die();
}
}
?>
<html>
<head>
<style>
table {
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
}
p
{
text-indent: 40px;
}
</style>
</head>
<body>
<center><h2>ESI Letter</h2></center>
To<br> &nbsp;&nbsp;&nbsp; The Consultant,<br>
&nbsp;&nbsp;&nbsp; For Employees State Insurance,<br>
&nbsp;&nbsp;&nbsp; Chennai.<br>
<br>
Sir/Madam,
<br><br><p>
For Your kindly information please credit employees ESI of <?php echo $PayMonth;?> for Siddharth Indistries.
&nbsp;&nbsp;
<p>Employee List given Below:</p>
<table style="height: 13px;" width="500" ;>
<thead>
<tr>
<th style="width: 108px;">Employee Name</th>
<th style="width: 108px;">ESI Account No</th>
<th style="width: 109px;">Employee ESI</th>
<th style="width: 109px;">Company Share</th>
<th style="width: 80px;">Total Amount</th>
</tr>
</thead>
<tbody>
<?php
$total = 0.00;
if(!empty($PFESI))
{
foreach($PFESI as $data)
{
?>
<tr>
<td style="width: 120px;"><?php echo $data->FName . " ".$data->Lname;?></td>
<td style="width: 108px;"><?php echo $data->ESI;?></td>
<td style="width: 109px;text-align:right;"><?php echo number_format($data->EmployeeESI,2,'.','');?></td>
<td style="width: 109px;text-align:right;"><?php echo number_format($data->CompanyESI,2,'.','');?></td>
<td style="width: 111px;text-align:right;"><?php echo number_format(($data->EmployeeESI + $data->CompanyESI),2,'.','');?></td>
</tr>
<?php }}?>
</tbody>
</table>
<h4 style="text-align:right;"> Total Amount:<?php echo $Totalamount;?></h4>
<h4 style="text-align:right;"> Total Amount:<?php echo $Totalamtwords;?></h4>
</body>
</html>

View File

@ -445,15 +445,15 @@ $(function() {
<span id="menu" data-toggle="dropdown" ><i class="fa fa-thumb-tack"></i> PaySlip <span class="caret"></span></span>
<ul class="dropdown-menu" role="menu" aria-labelledby="menu3">
<li class="treeview">
<a href="<?php echo base_url(); ?>ExcelUpload">
<a href="<?php echo base_url(); ?>monthlypay">
<i class="fa fa-upload"></i>
<span>Upload Salary</span>
<span>Monthly Pay Information</span>
</a>
</li>
<li class="treeview">
<a href="<?php echo base_url(); ?>ExcelUpload2">
<i class="fa fa-keyboard-o"></i>
<span>Monthly Salary Inputs</span>
<span>Monthly Pay Upload</span>
</a>
</li>
<li class="treeview">
@ -463,8 +463,8 @@ $(function() {
</a>
</li>
<li class="treeview">
<a href="<?php echo base_url(); ?>updatepayroll" >
<i class="fa fa-credit-card-alt"></i> <span>Payslip</span>
<a href="<?php echo base_url(); ?>PaysilpListing" >
<i class="fa fa-credit-card-alt"></i> <span>Edit Payslip</span>
</a>
</li>
<li class="treeview">
@ -473,8 +473,8 @@ $(function() {
</a>
</li>
<li class="treeview">
<a href="<?php echo base_url(); ?>monthlyListings" >
<i class="fa fa-table"></i> <span>Employee Monthly Payment</span>
<a href="<?php echo base_url(); ?>BankReport" >
<i class="fa fa-table"></i> <span>Bank Report</span>
</a>
</li>

View File

@ -0,0 +1,366 @@
<?php
$sample = array_merge($month,$fresh);
?>
<script src="<?php echo base_url()?>assets/lightswitch/lightswitch/lib/jquery.tabletojson.js"></script>
<script src="<?php echo base_url()?>assets/lightswitch/lightswitch/lib/jquery.tabletojson.min.js"></script>
</script>
<style type="text/css">
.num {
text-align:right;
}
</style>
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
<center>Employee Monthly Payment Listing</center>
</h1>
</section>
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<!--<center><h3 class="box-title">-->
<div class="box-tools">
<!-- <form action="<?php echo base_url() ?>assetListing" method="POST" id="searchList">-->
<form action="<?php echo base_url() ?>monthlypay/monthlyListing" method="POST" id="searchList">
</form>
</div><!--</h3></center>-->
</div><!-- /.box-header -->
<?php
$year = date("Y");
$current = date("m-Y");
$month = date("m");
if($month < 10)
{
$month = substr($month,1);
}
$currentselection = $month . "-" . $year;
$options = array();
$monthsoptions = array("1" => "Jan", "2" => "Feb","3" => "Mar","4" => "Apr","5" => "May","6" => "June","7"=> "July","8"=> "Aug","9" => "Sep","10"=> "Oct","11" => "Nov","12"=>"Dec");
$currentmontharray = array(array($month."-".$year => $monthsoptions[$month]."-".$year));
// For find out Next and previous month and year from current year
$aftersix = array();
for ($i = 0; $i <3;$i++){
$month++;;
if($month > 12)
{
$month = 1;
$year = $year +1;
}
$aftersix[]=array($month."-".$year => $monthsoptions[$month]."-".$year);
}
$year = date("Y");
$month = date("m");
$beforesix = array();
for ($i = 3; $i >0;$i--){
$month--;
if($month < 1 )
{
$month = 12;
$year = $year - 1;
}
$beforesix[]=array($month."-".$year => $monthsoptions[$month]."-".$year);
}
$beforesix = array_reverse($beforesix);
$options = array_merge($options,$beforesix);
//echo count($options);
$options = array_merge($options,$currentmontharray);
$options = array_merge($options,$aftersix);
$ot = array();
foreach($options as $o)
{
foreach($o as $key => $value)
{
$ot[$key] = $value;
}
}
?>
<div class="row">
<div class="col-md-3">
<?php echo form_dropdown('name="monthyear"',$ot,set_value('monthyear',$currentselection),'id="monthyear"' ,'class="form-control select2');?>
</div>
</div>
<div class="box-body">
<table id="monthlylistings" class="table table-bordered table-hover" style="background-color:#fff;font-size:12px;">
<thead style="background-color:#ddf">
<tr>
<th>S.No</th>
<th>Employee Id</th>
<th>Employee Name</th>
<th>LOP Days</th>
<th>Paid Leave</th>
<th>OT Hours Worked in Hrs</th>
<th>Loan Recovered in </th>
<th>Incentives in </th>
<th>Other Deductions in </th>
</tr>
</thead>
<tbody>
<?php
$index=0;
$testarray=array();
if(!empty($sample))
{
foreach($sample as $record)
{
$index++;
if(in_array($record->EmpID,$testarray))
{
$index--;
}
else{
array_push($testarray,$record->EmpID);
?>
<tr>
<td style="text-align:right;"><?php echo $index; ?></td>
<td style="text-align:right;"><?php echo $record->EmpID ?></td>
<td><?php echo $record->FirstName ." ". $record->LastName ?></td>
<td contenteditable='true' style="text-align:right;"><?php if(!empty($record->LOP_Days)){echo $record->LOP_Days;}else{echo "0.00";}?></td>
<td contenteditable='true' style="text-align:right;"><?php if(!empty($record->Paid_leave)){echo $record->Paid_leave;}else { echo number_format(0.00,2,'.','');} ?></td>
<td contenteditable='true' style="text-align:right;"><?php if(!empty($record->OT_Hrs_Worked)){echo $record->OT_Hrs_Worked;}else { echo number_format(0.00,2,'.','');} ?></td>
<td contenteditable='true' style="text-align:right;"><?php if(!empty($record->Loan_Recovered)){if(is_numeric($record->Loan_Recovered)){echo number_format($record->Loan_Recovered,2,'.','');}else {echo $record->Loan_Recovered;}}else{echo number_format(0.00,2,'.','');} ?></td>
<td contenteditable='true' style="text-align:right;"><?php if(!empty($record->Incentives)){echo $record->Incentives;}else{ echo number_format(0.00,2,'.','');;} ?></td>
<td contenteditable='true' style="text-align:right;"><?php if(!empty($record->Other_Deductions)){echo $record->Other_Deductions; }else{ echo number_format(0.00,2,'.','');;} ?></td>
</tr>
<?php
}
}
}
?>
</tbody>
</table>
<p>&nbsp;</p>
<div class="row">
<div class="col-md-3" id="savebutton">
<input type="button" id="submit" value = "Save" class="btn btn-primary" onclick="getAllData();">
</div>
</div>
</div><!-- /.box-body -->
<!-- <div class="box-footer clearfix">
</div> -->
</div><!-- /.box -->
</div>
</div>
</section>
</div>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/common.js" charset="utf-8"></script>
<script type="text/javascript">
$(function () {
$('#monthlylisting').DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"aaSorting": [[ 0, "asc" ]],
"info": true,
"autoWidth": true
});
});
function getAllData()
{
var alldata = $("#monthlylistings").tableToJSON();
//alert(JSON.stringify(alldata));
alldata=JSON.stringify(alldata)
var month = $('#monthyear').val();
$('#content').loader('hide');
$.ajax({
data:{param1:alldata,param2:month},
//dataType:"json",
type:"POST",
url:"<?php echo base_url() ?>payslip/saveMonthlyData",
success:function(data) {
if(data)
{
$('#content').loader('hide');
alert(data);
//console.log(data);
}
}
});
}
$("#monthyear").change(function(){
var curselection = $("#monthyear").val();
var currentdate = new Date();
var currentmonth = currentdate.getMonth();
currentmonth++;
var res = curselection.split("-");
var selmonth = res[0];
var savebuttonstatus = currentmonth - selmonth;
if(savebuttonstatus >= 2)
{
$("#savebutton").hide();
}
else if(savebuttonstatus < 0)
{
$("#savebutton").hide();
}
else if(savebuttonstatus == 0)
{
$("#savebutton").show();
}
$("#monthlyListings tbody tr").remove();
var zero = '0';
var month='';
var hyphan = '-';
var currentselection = $("#monthyear").val();
//alert(currentselection);
var res = currentselection.split("-");
month = res[0];
if(res[0] <10)
{
var month = zero.concat(res[0]);
}
var finaldate = month.concat(hyphan);
var finaldate = finaldate.concat(res[1]);
//alert(finaldate);
$.ajax({
data:{param1:finaldate},
type:"POST",
url:"<?php echo base_url() ?>payslip/changeMonth",
success:function(data)
{
//alert(data);
if(data)
{
$('#content').loader('hide');
//alert(data);
var trHTML="";
var obj =JSON.parse(data);
var temparray = [];
var j=0;
jQuery.each(obj, function(i, val) {
function checkExist(emp) {
return emp == val.EmpID;
}
//++i;
var tmp= temparray.find(checkExist);
if(tmp != null)
{
j++;
}else{
//alert(val.EmpID + "First");
temparray.push(val.EmpID);
++i
i=i-j;
var LOP_Days = val.LOP_Days;
if(LOP_Days == null){ LOP_Days="0.00";}
var Paid_leave = val.Paid_leave;
if(Paid_leave == null){ Paid_leave = "0.00";}
var OT_Hrs_Worked = val.OT_Hrs_Worked;
if(OT_Hrs_Worked == null){ OT_Hrs_Worked = "0.00";}
var Loan_Recovered = val.Loan_Recovered;
if(Loan_Recovered == null){ Loan_Recovered = "0.00";}
var Incentives = val.Incentives;
if(Incentives == null){ Incentives = "0.00";}
var Other_Deductions = val.Other_Deductions;
if(Other_Deductions == null){ Other_Deductions = "0.00";}
//alert(val.EmpID +"-"+val.FirstName+"-"+val.LastName);
trHTML += '<tr>' +
'<td style="text-align:right;">' + (i) + '</td>' +
'<td style="text-align:right;">' + val.EmpID + '</td>' +
'<td>' + val.FirstName+" "+ val.LastName + '</td>' +
'<td contenteditable="true" style="text-align:right;">' + LOP_Days + '</td>' +
'<td contenteditable="true" style="text-align:right;">' + Paid_leave + '</td>' +
'<td contenteditable="true" style="text-align:right;">' + OT_Hrs_Worked + '</td>' +
'<td contenteditable="true" style="text-align:right;">' + Loan_Recovered + '</td>' +
'<td contenteditable="true" style="text-align:right;">' + Incentives + '</td>' +
'<td contenteditable="true" style="text-align:right;">' + Other_Deductions+ '</td>' +
'</tr>';
}
});
// //alert(trHTML);
//alert(temparray);
$('#monthlyListings > tbody').append(trHTML);
}
}
});
});
</script>

View File

@ -8,11 +8,11 @@
$(function() {
//Initialize Select2 Elements
$(".select2").select2();
//$('#content').html('<img id="loader-img" alt="" src="<?php echo base_url();?>assets/dist/loader.gif" align="center" />');
$('#All').click(function(){
//alert('clicked');
if ($('#All').prop('checked'))
{
$('#Employee').attr('disabled', 'true');
@ -203,9 +203,10 @@ $(function() {
<?php
if(!empty($Payon))
{
foreach ($Payon as $rl)
{
$Pay =$rl->PayOn;
$Pay =$rl->Month_Year;
if ($_POST['PayOn'] == $Pay)
{
@ -240,10 +241,9 @@ $(function() {
<div class="col-md-4 col-md-offset-6" align = "right">
<input type="button" class="btn btn-info" id="Calculate" value="Calculate Pay"/>
<!-- <input type="submit" class="btn btn-info" id="Generate" value="Generate"/>-->
<!-- <a href="<?php echo base_url(); ?>payslip/updatepayroll" ><input type="submit" class="btn btn-info" value="Update" /></a>
</div> -->
</div>
<div class="row" >

View File

@ -18,6 +18,7 @@
$ESInumber = '';
$TotalNoofDays = '';
$NoOfWorkingdays ='';
$paidleave = 0.00;
$LOP='';
$ActualSalary = '';
$PerDaySalary = '';
@ -45,6 +46,7 @@
$LoanAdvance='0.00';
$Otherallowances='0.00';
$TotalAmountInWords='';
$TotalComapanyContribution = 0.00;
if(!empty($Count))
{
@ -81,8 +83,10 @@ if(!empty($PayDetails))
$BankBranchName = $Pay->BankName;
$PFnumber = $Pay->PFNumber;
$ESInumber = $Pay->ESINumber;
$TotalNoofDays = $Pay->TotalNoofDays;
$TotalNoofDays = $Pay->TotalCalDays;
$NoOfWorkingdays =$Pay->NoofDaysWorked;
$paidleave = $Pay->Paid_Leave;
$NoOfWorkingdays = $NoOfWorkingdays + $paidleave;
$ActualSalary = $Pay->ActualSalary;
$LOP=$Pay->LOP;
$PerDaySalary = $Pay->PerDaySalary;
@ -92,6 +96,7 @@ if(!empty($PayDetails))
$OTWage = $Pay->OTWages;
$OtherDeductions=$Pay->OtherDeductions;
$LoanAdvance=$Pay->Advance;
$TotalComapanyContribution=$Pay->TotalCompCon;
if($OTWage == '')
{
@ -213,13 +218,13 @@ if($RecCount > 0)
<td style="border-left: 0px ;border-bottom: 0px; border-right: 0px ;border-top: 0px ;">Date Of Birth </td>
<td style="border-left: 0px ;border-bottom: 0px; border-right: 0px ;border-top: 0px ;"><?php echo ':&nbsp;'.$DateofBirth ?></td>
<td style="border-left: 0px ;border-bottom: 0px; border-right: 0px ;border-top: 0px ;">Loss Of Pay Days </td>
<td style="border-left: 0px ;border-bottom: 0px; border-right: 0px ;border-top: 0px ;"> <?php echo ':&nbsp;'. number_format($LOP); ?></td>
<td style="border-left: 0px ;border-bottom: 0px; border-right: 0px ;border-top: 0px ;"> <?php echo ':&nbsp;'. number_format((double)$LOP,2,'.',''); ?></td>
</tr>
<tr>
<td style="border-left: 0px ;border-bottom: 0px; border-right: 0px ;border-top: 0px ;">PF Account Number </td>
<td style="border-left: 0px ;border-bottom: 0px; border-right: 0px ;border-top: 0px ;" ><?php echo ':&nbsp;'.$PFnumber ?></td>
<td style="border-left: 0px ;border-bottom: 0px; border-right: 0px ;border-top: 0px ;">Paid Days </td>
<td style="border-left: 0px ;border-bottom: 0px; border-right: 0px ;border-top: 0px ;"><?php echo ':&nbsp;'.$NoOfWorkingdays ?></td>
<td style="border-left: 0px ;border-bottom: 0px; border-right: 0px ;border-top: 0px ;"><?php echo ':&nbsp;'.number_format($NoOfWorkingdays,2,'.',''); ?></td>
</tr>
<tr>
<td style="border-left: 0px ;border-bottom: 0px; border-right: 0px ;border-top: 0px ;">Bank Name </td>
@ -298,6 +303,9 @@ if($RecCount > 0)
<tr><th style="text-align: right;" colspan="3">Net Pay (TE - TD)(Rounded) &nbsp;</th>
<td style="text-align: right;" colspan="1"><?php echo number_format(round($LessAdvance),2,'.','') ?>&nbsp;</td>
</tr>
<tr><th style="text-align: right;" colspan="3">Company Contribution(Rounded) &nbsp;</th>
<td style="text-align: right;" colspan="1"><?php echo number_format(round($TotalComapanyContribution),2,'.','') ?>&nbsp;</td>
</tr>
<tr><th style="text-align: right;" colspan="1">Total Amount In Words &nbsp;</th>
<td style="text-align: right;" colspan="3"><?php if(!empty($amtinwords)){ print_r($amtinwords);} ?></td>
</tr>

View File

@ -0,0 +1,104 @@
<?php //print_r($PayInfo);?>
<style type="text/css">
.num {
text-align:right;
}
</style>
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
<center>Employee Monthly Payslip </center>
</h1>
</section>
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<div class="box-tools">
</form>
</div><!--</h3></center>-->
</div><!-- /.box-header -->
<div class="box-body">
<table id="monthlylistings" class="table table-bordered table-hover" style="background-color:#fff;font-size:12px;">
<thead style="background-color:#ddf">
<tr>
<th>Month Year</th>
<th>Employee Id</th>
<th>Employee Name</th>
<th>Paid Days</th>
<th>Salary in </th>
<th>Company Contribution in </th>
<th>Loan Recoverd in </th>
<th>Loan Balance in </th>
<th>Action</th>
</tr>
</thead>
<?php
if(!empty($PayInfo))
{
foreach($PayInfo as $record)
{
?>
<tr>
<td style="text-align:right;"><?php echo $record->PayOn ?></td>
<td><?php echo $record->EmpID ?></td>
<td><?php echo $record->FName ." ". $record->Lname ?></td>
<td style="text-align:right;"><?php echo ($record->NoofDaysWorked + $record->Paid_Leave) ?></td>
<td style="text-align:right;"><?php echo $record->LessAdvance ?></td>
<td style="text-align:right;"><?php echo $record->TotalCompCon ?></td>
<td style="text-align:right;"><?php if(is_numeric($record->Advance)){echo number_format($record->Advance,2,'.','');}else {echo $record->Advance;} ?></td>
<td style="text-align:right;"><?php echo $record->BalanceAdvance ?></td>
<td>
<a href="<?php echo base_url().'payslip/editPayslip/'.$record->EmpID.'/'.$record->PayOn;?>"><i class="btn btn-primary">EDIT</i></a>
</td>
</tr>
<?php
}
}
?>
</table>
</div><!-- /.box-body -->
<!-- <div class="box-footer clearfix">
<?php //echo $this->pagination->create_links(); ?>
</div> -->
</div><!-- /.box -->
</div>
</div>
</section>
</div>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/common.js" charset="utf-8"></script>
<script type="text/javascript">
$(function () {
$('#monthlylistings').DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"aaSorting": [[ 0, "desc" ]],
"info": true,
"autoWidth": true
});
});
</script>

View File

@ -0,0 +1,85 @@
<?php
if(!empty($result))
{
foreach($result as $r)
{
$address=$r->BAddress;
//die();
}
}
?>
<html>
<head>
<style>
table {
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
}
p
{
text-indent: 40px;
}
</style>
</head>
<body>
<center><h2>PF Letter</h2></center>
To<br> &nbsp;&nbsp;&nbsp; The Consultant,<br>
&nbsp;&nbsp;&nbsp; For Provident Fund,<br>
&nbsp;&nbsp;&nbsp; Chennai.<br>
<br>
Sir/Madam,
<br><br><p>
For Your kindly information please credit employees PF of <?php echo $PayMonth;?> for Siddharth Indistries.
&nbsp;&nbsp;
<p>Employee List given Below:</p>
<table style="height: 13px;" width="500" ;>
<thead>
<tr>
<th style="width: 108px;">Employee Name</th>
<th style="width: 108px;">PF Account No</th>
<th style="width: 109px;">Employee PF</th>
<th style="width: 109px;">Company Share</th>
<th style="width: 80px;">Total Amount</th>
</tr>
</thead>
<tbody>
<?php
$total = 0.00;
if(!empty($PFESI))
{
foreach($PFESI as $data)
{
?>
<tr>
<td style="width: 120px;"><?php echo $data->FName . " ".$data->Lname;?></td>
<td style="width: 108px;"><?php echo $data->PFNO;?></td>
<td style="width: 109px;text-align:right;"><?php echo number_format($data->PF,2,'.','');?></td>
<td style="width: 109px;text-align:right;"><?php echo number_format($data->CompanyPF,2,'.','');?></td>
<td style="width: 111px;text-align:right;"><?php echo number_format(($data->PF + $data->CompanyPF),2,'.','');?></td>
</tr>
<?php }}?>
</tbody>
</table>
<h4 style="text-align:right;"> Total Amount:<?php echo $Totalamount;?></h4>
<h4 style="text-align:right;"> Total Amount:<?php echo $Totalamtwords;?></h4>
</body>
</html>

View File

@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

View File

@ -0,0 +1 @@
node_modules/

View File

@ -0,0 +1,24 @@
{
"bitwise" : true,
"camelcase" : true,
"curly" : true,
"eqeqeq" : true,
"es3" : true,
"eqnull" : true,
"forin" : true,
"freeze" : true,
"immed" : true,
"indent" : 2,
"jquery" : true,
"latedef" : true,
"newcap" : true,
"noarg" : true,
"noempty" : true,
"nonbsp" : true,
"nonew" : true,
"quotmark" : "single",
"sub" : true,
"trailing" : true,
"undef" : true,
"unused" : true
}

View File

@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.12"
- "0.11"
- "0.10"

View File

@ -0,0 +1,56 @@
## 2017-07-14 - Release 0.13.0
* Skip columns where headers are not present.
## 2017-05-10 - Release 0.12.0
* Added `extractor` option.
## 2015-06-05 - Release 0.11.1
* Fixed `colspan` & `rowspan` support for complicated tables.
## 2015-02-06 - Release 0.11.0
* Added `textExtractor` option.
## 2014-11-21 - Release 0.10.0
* Added `ignoreEmptyRows` option.
## 2014-9-24 - Release 0.9.0
* Added `includeRowId` option.
## 2014-4-14 - Release 0.8.3
* Updated to correct version number.
## 2014-4-14 - Release 0.8.2
* Updated `onlyColumns` & `ignoreColumns` to work with colspans ([demo](http://jsfiddle.net/Mottie/4E2L6/10/)).
## 2014-4-13 - Release 0.8.1
* Added basic `.gitattributes` file.
* Updated `colspan` & `rowspan` support to work when applied to the same cell ([demo](http://jsfiddle.net/Mottie/4E2L6/9/)).
## 2014-4-6 - Release 0.8.0
* Added `colspan` & `rowspan` support.
* Fixed missing license banner.
* Updated Grunt plugins.
* Added more JSHint requirements and cleaned code.
## 2014-3-26 - Release 0.7.0
* Added `allowHTML` option to preserve HTML tags from table cells.
* Fixed Travis & Grunt tests.
## 2013-07-25 - Release 0.6.0
* Added `headings` option to define the headings of a table. When supplied, treats entire table as values.
## 2013-04-23 - Release 0.5.1
* Halved execution time.
* Added more JSHint requirements.
## 2013-04-15 - Release 0.5.0
* **The release breaks backwards compatibility for both option names and data-* attributes.**
* Changed option `ignoreColNum` to `ignoreColumns`.
* Merged `data-cell-value` and `data-column-name` into a single attribute: `data-override`.
* Added a new option `onlyColumns` to set which columns are included and ignores all others.
## 2013-04-12 - Release 0.4.0
* No longer requires the use of `th` elements - always uses the first row as column names.
## 2013-02-15 - Release 0.3.0
* Added tests and fixed many bugs.

View File

@ -0,0 +1,81 @@
/*global module:false*/
module.exports = function(grunt) {
'use strict';
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON( 'package.json' ),
clean: {
build: [ 'lib' ]
},
concat: {
options: {
banner: '/**\n' +
' * <%= pkg.name %>\n' +
' * <%= pkg.description %>\n' +
' *\n' +
' * @author <%= pkg.author.name %>\n' +
' * @copyright <%= pkg.author.name %> <%= grunt.template.today("yyyy") %>\n' +
' * @license <%= pkg.licenses[0].type %> <<%= pkg.licenses[0].url %>>\n' +
' * @link <%= pkg.homepage %>\n' +
' * @module <%= pkg.name %>\n' +
' * @version <%= pkg.version %>\n' +
' */\n'
},
dist: {
src: [
'src/jquery.tabletojson.js'
],
dest : 'lib/jquery.tabletojson.js'
}
},
jshint: {
files: {
src: [
'Gruntfile.js',
'src/**/*.js',
'test/specs/*.js'
]
},
options: {
jshintrc: '.jshintrc'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= pkg.author.name %> */\n',
report: 'gzip'
},
dist: {
files: {
'lib/jquery.tabletojson.min.js': ['<banner>','lib/jquery.tabletojson.js']
}
}
},
qunit: {
files: ['test/index.html']
},
watch: {
scripts: {
files: ['src/**/*.js'],
tasks: ['build']
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean' );
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
// Default task.
grunt.registerTask('build', ['clean:build', 'concat', 'uglify']);
grunt.registerTask('test', ['jshint', 'qunit']);
grunt.registerTask('default', ['test', 'build']);
};

View File

@ -0,0 +1,7 @@
Copyright (c) 2017 Daniel White
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,163 @@
# Table To JSON
[![Build Status](https://travis-ci.org/lightswitch05/table-to-json.png?branch=master)](https://travis-ci.org/lightswitch05/table-to-json)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/lightswitch05/table-to-json?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
jQuery plugin to serialize HTML tables into javascript objects.
## Links
- Demo: http://lightswitch05.github.io/table-to-json/
- Plunker Template: http://plnkr.co/edit/iQFtcEEZkvsMJ2UqcrlW?p=preview
## Features
- Automatically finds column headings
- Override found column headings by using `data-override="overridden column name"`
- Always uses first row as column headings regardless of `th` and `td` tags
- Override cell values column names by using `data-override="new value"`
- Ignorable columns
- Not confused by nested tables
- Works with `rowspan` and `colspan`
## Options
- `ignoreColumns`
- Array of column indexes to ignore.
- Default: `[]`
- `onlyColumns`
- Array of column indexes to include, all other columns are ignored. This takes presidence over `ignoreColumns` when provided.
- Default: `null` - all columns
- `ignoreHiddenRows`
- Boolean if hidden rows should be ignored or not.
- Default: `true`
- `ignoreEmptyRows`
- Boolean if empty rows should be ignored or not.
- Default: `false`
- `headings`
- Array of table headings to use. When supplied, treats entire table as values including the first `<tr>`
- Default: `null`
- `allowHTML`
- Boolean if HTML tags in table cells should be preserved
- Default: `false`
- `includeRowId`
- Either a `boolean` or a `string`. If `true`, the the `id` attribute on the table's `<tr>` elements will be included in the JSON as `rowId`. To override the name `rowId`, supply a string of the name you would like to use.
- Default: `false`
- `textDataOverride`
- String containing data-attribute which contains data which overrides the text contained within the table cell
- Default: 'data-override'
- `textExtractor`
- alias of `extractor`
- `extractor`
- Function : function that is used on all *tbody* cells to extract text from the cells; a value in `data-override` will prevent this function from being called. Example:
```js
$('table').tableToJSON({
extractor : function(cellIndex, $cell) {
// get text from the span inside table cells;
// if empty or non-existant, get the cell text
return $cell.find('span').text() || $cell.text();
}
});
```
```js
$('table').tableToJSON({
extractor : function(cellIndex, $cell) {
return {
name: $cell.find('span').text(),
avatar: $cell.find('img').attr('src')
};
}
});
```
- Object : object containing a zero-based cell index (this *does not* take `colspan` cells into account!) of the table; a value in `data-override` will prevent this function from being called. Example:
```js
$('table').tableToJSON({
extractor : {
0 : function(cellIndex, $cell) {
return $cell.find('em').text();
},
1 : function(cellIndex, $cell) {
return $cell.find('span').text();
}
}
});
```
- Default: `null`
## Example
```html
<table id='example-table'>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th data-override="Score">Points</th></tr>
</thead>
<tbody>
<tr>
<td>Jill</td>
<td>Smith</td>
<td data-override="disqualified">50</td></tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td></tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td></tr>
<tr>
<td>Adam</td>
<td>Johnson</td>
<td>67</td></tr>
</tbody>
</table>
<script type="text/javascript">
// Basic Usage
var table = $('#example-table').tableToJSON();
// table == [{"First Name"=>"Jill", "Last Name"=>"Smith", "Score"=>"disqualified"},
// {"First Name"=>"Eve", "Last Name"=>"Jackson", "Score"=>"94"},
// {"First Name"=>"John", "Last Name"=>"Doe", "Score"=>"80"},
// {"First Name"=>"Adam", "Last Name"=>"Johnson", "Score"=>"67"}]
// Ignore first column (name)
var table = $('#example-table').tableToJSON({
ignoreColumns: [0]
});
// table == [{"Last Name"=>"Smith", "Score"=>"disqualified"},
// {"Last Name"=>"Jackson", "Score"=>"94"},
// {"Last Name"=>"Doe", "Score"=>"80"},
// {"Last Name"=>"Johnson", "Score"=>"67"}]
</script>
```
## Contributing
* Install [Node.js](http://nodejs.org/).
* this will also the `npm` package manager.
* run `npm install` from app root directory.
* This installs grunt and other dependencies See `package.json` for a full list.
* run `npm install -g grunt-cli`.
* run `grunt` to run tests and create a new build in `/lib`.
* Make the changes you want.
* Make tests for the changes.
* Submit a pull request, please submit to the `develop` branch.
### Looking for a server-side solution?
[Colin Tremblay](https://github.com/tremblay) is working on a PHP implementation at [HTML-Table-To-JSON](https://github.com/tremblay/HTML-Table-to-JSON)
### Special Thanks
* [imamathwiz](https://github.com/imamathwiz) for adding `allowHTML` option and various other changes.
* [nenads](https://github.com/nenads) for adding `headings` option.
* [Mottie](https://github.com/Mottie) for adding `rowspan` & `colspan` support. Also adding the `textExtractor` & `dataOverride` feature!
* [station384](https://github.com/station384) for adding `includeRowId` support.
* [dayAlone](https://github.com/dayAlone) for adding `ignoreEmptyRows` option.
* [danielapsmaior](https://github.com/danielapsmaior) for discovering and fixing a `rowspan` & `colspan` bug.
* [koshuang](https://github.com/koshuang) for adding `extractor` feature!
* [noma4i](https://github.com/noma4i) added feature "Skip columns where headers are not present"

View File

@ -0,0 +1,27 @@
{
"name": "table-to-json",
"version": "0.13.0",
"main": [
"./lib/jquery.tabletojson.min.js"
],
"dependencies": {
"jquery": "*"
},
"homepage": "https://github.com/lightswitch05/table-to-json",
"authors": [
"Daniel White <daniel@developerdan.com>"
],
"description": "jQuery plugin that reads an HTML table and returns a javascript object representing the values and columns of the table",
"license": "MIT",
"keywords": [
"table-to-json"
],
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests",
"src"
]
}

View File

@ -0,0 +1,193 @@
/**
* table-to-json
* jQuery plugin that reads an HTML table and returns a javascript object representing the values and columns of the table
*
* @author Daniel White
* @copyright Daniel White 2017
* @license MIT <https://github.com/lightswitch05/table-to-json/blob/master/MIT-LICENSE>
* @link https://github.com/lightswitch05/table-to-json
* @module table-to-json
* @version 0.13.0
*/
(function( $ ) {
'use strict';
$.fn.tableToJSON = function(opts) {
// Set options
var defaults = {
ignoreColumns: [],
onlyColumns: null,
ignoreHiddenRows: true,
ignoreEmptyRows: false,
headings: null,
allowHTML: false,
includeRowId: false,
textDataOverride: 'data-override',
extractor: null,
textExtractor: null
};
opts = $.extend(defaults, opts);
var notNull = function(value) {
return value !== undefined && value !== null;
};
var notEmpty = function(value) {
return value !== undefined && value.length > 0;
};
var ignoredColumn = function(index) {
if( notNull(opts.onlyColumns) ) {
return $.inArray(index, opts.onlyColumns) === -1;
}
return $.inArray(index, opts.ignoreColumns) !== -1;
};
var arraysToHash = function(keys, values) {
var result = {}, index = 0;
$.each(values, function(i, value) {
// when ignoring columns, the header option still starts
// with the first defined column
if ( index < keys.length && notNull(value) ) {
if (notEmpty(keys[index])){
result[ keys[index] ] = value;
}
index++;
}
});
return result;
};
var cellValues = function(cellIndex, cell, isHeader) {
var $cell = $(cell),
// extractor
extractor = opts.extractor || opts.textExtractor,
override = $cell.attr(opts.textDataOverride),
value;
// don't use extractor for header cells
if ( extractor === null || isHeader ) {
return $.trim( override || ( opts.allowHTML ? $cell.html() : cell.textContent || $cell.text() ) || '' );
} else {
// overall extractor function
if ( $.isFunction(extractor) ) {
value = override || extractor(cellIndex, $cell);
return typeof value === 'string' ? $.trim( value ) : value;
} else if ( typeof extractor === 'object' && $.isFunction( extractor[cellIndex] ) ) {
value = override || extractor[cellIndex](cellIndex, $cell);
return typeof value === 'string' ? $.trim( value ) : value;
}
}
// fallback
return $.trim( override || ( opts.allowHTML ? $cell.html() : cell.textContent || $cell.text() ) || '' );
};
var rowValues = function(row, isHeader) {
var result = [];
var includeRowId = opts.includeRowId;
var useRowId = (typeof includeRowId === 'boolean') ? includeRowId : (typeof includeRowId === 'string') ? true : false;
var rowIdName = (typeof includeRowId === 'string') === true ? includeRowId : 'rowId';
if (useRowId) {
if (typeof $(row).attr('id') === 'undefined') {
result.push(rowIdName);
}
}
$(row).children('td,th').each(function(cellIndex, cell) {
result.push( cellValues(cellIndex, cell, isHeader) );
});
return result;
};
var getHeadings = function(table) {
var firstRow = table.find('tr:first').first();
return notNull(opts.headings) ? opts.headings : rowValues(firstRow, true);
};
var construct = function(table, headings) {
var i, j, len, len2, txt, $row, $cell,
tmpArray = [], cellIndex = 0, result = [];
table.children('tbody,*').children('tr').each(function(rowIndex, row) {
if( rowIndex > 0 || notNull(opts.headings) ) {
var includeRowId = opts.includeRowId;
var useRowId = (typeof includeRowId === 'boolean') ? includeRowId : (typeof includeRowId === 'string') ? true : false;
$row = $(row);
var isEmpty = ($row.find('td').length === $row.find('td:empty').length) ? true : false;
if( ( $row.is(':visible') || !opts.ignoreHiddenRows ) && ( !isEmpty || !opts.ignoreEmptyRows ) && ( !$row.data('ignore') || $row.data('ignore') === 'false' ) ) {
cellIndex = 0;
if (!tmpArray[rowIndex]) {
tmpArray[rowIndex] = [];
}
if (useRowId) {
cellIndex = cellIndex + 1;
if (typeof $row.attr('id') !== 'undefined') {
tmpArray[rowIndex].push($row.attr('id'));
} else {
tmpArray[rowIndex].push('');
}
}
$row.children().each(function(){
$cell = $(this);
// skip column if already defined
while (tmpArray[rowIndex][cellIndex]) { cellIndex++; }
// process rowspans
if ($cell.filter('[rowspan]').length) {
len = parseInt( $cell.attr('rowspan'), 10) - 1;
txt = cellValues(cellIndex, $cell);
for (i = 1; i <= len; i++) {
if (!tmpArray[rowIndex + i]) { tmpArray[rowIndex + i] = []; }
tmpArray[rowIndex + i][cellIndex] = txt;
}
}
// process colspans
if ($cell.filter('[colspan]').length) {
len = parseInt( $cell.attr('colspan'), 10) - 1;
txt = cellValues(cellIndex, $cell);
for (i = 1; i <= len; i++) {
// cell has both col and row spans
if ($cell.filter('[rowspan]').length) {
len2 = parseInt( $cell.attr('rowspan'), 10);
for (j = 0; j < len2; j++) {
tmpArray[rowIndex + j][cellIndex + i] = txt;
}
} else {
tmpArray[rowIndex][cellIndex + i] = txt;
}
}
}
txt = tmpArray[rowIndex][cellIndex] || cellValues(cellIndex, $cell);
if (notNull(txt)) {
tmpArray[rowIndex][cellIndex] = txt;
}
cellIndex++;
});
}
}
});
$.each(tmpArray, function( i, row ){
if (notNull(row)) {
// remove ignoredColumns / add onlyColumns
var newRow = notNull(opts.onlyColumns) || opts.ignoreColumns.length ?
$.grep(row, function(v, index){ return !ignoredColumn(index); }) : row,
// remove ignoredColumns / add onlyColumns if headings is not defined
newHeadings = notNull(opts.headings) ? headings :
$.grep(headings, function(v, index){ return !ignoredColumn(index); });
txt = arraysToHash(newHeadings, newRow);
result[result.length] = txt;
}
});
return result;
};
// Run
var headings = getHeadings(this);
return construct(this, headings);
};
})( jQuery );

View File

@ -0,0 +1,2 @@
/*! table-to-json - v0.13.0 - Daniel White */
!function(a){"use strict";a.fn.tableToJSON=function(b){var c={ignoreColumns:[],onlyColumns:null,ignoreHiddenRows:!0,ignoreEmptyRows:!1,headings:null,allowHTML:!1,includeRowId:!1,textDataOverride:"data-override",extractor:null,textExtractor:null};b=a.extend(c,b);var d=function(a){return void 0!==a&&null!==a},e=function(a){return void 0!==a&&a.length>0},f=function(c){return d(b.onlyColumns)?-1===a.inArray(c,b.onlyColumns):-1!==a.inArray(c,b.ignoreColumns)},g=function(b,c){var f={},g=0;return a.each(c,function(a,c){g<b.length&&d(c)&&(e(b[g])&&(f[b[g]]=c),g++)}),f},h=function(c,d,e){var f,g=a(d),h=b.extractor||b.textExtractor,i=g.attr(b.textDataOverride);return null===h||e?a.trim(i||(b.allowHTML?g.html():d.textContent||g.text())||""):a.isFunction(h)?(f=i||h(c,g),"string"==typeof f?a.trim(f):f):"object"==typeof h&&a.isFunction(h[c])?(f=i||h[c](c,g),"string"==typeof f?a.trim(f):f):a.trim(i||(b.allowHTML?g.html():d.textContent||g.text())||"")},i=function(c,d){var e=[],f=b.includeRowId,g="boolean"==typeof f?f:"string"==typeof f,i="string"==typeof f==!0?f:"rowId";return g&&void 0===a(c).attr("id")&&e.push(i),a(c).children("td,th").each(function(a,b){e.push(h(a,b,d))}),e},j=function(a){var c=a.find("tr:first").first();return d(b.headings)?b.headings:i(c,!0)};return function(c,e){var i,j,k,l,m,n,o,p=[],q=0,r=[];return c.children("tbody,*").children("tr").each(function(c,e){if(c>0||d(b.headings)){var f=b.includeRowId,g="boolean"==typeof f?f:"string"==typeof f;n=a(e);var r=n.find("td").length===n.find("td:empty").length;!n.is(":visible")&&b.ignoreHiddenRows||r&&b.ignoreEmptyRows||n.data("ignore")&&"false"!==n.data("ignore")||(q=0,p[c]||(p[c]=[]),g&&(q+=1,void 0!==n.attr("id")?p[c].push(n.attr("id")):p[c].push("")),n.children().each(function(){for(o=a(this);p[c][q];)q++;if(o.filter("[rowspan]").length)for(k=parseInt(o.attr("rowspan"),10)-1,m=h(q,o),i=1;i<=k;i++)p[c+i]||(p[c+i]=[]),p[c+i][q]=m;if(o.filter("[colspan]").length)for(k=parseInt(o.attr("colspan"),10)-1,m=h(q,o),i=1;i<=k;i++)if(o.filter("[rowspan]").length)for(l=parseInt(o.attr("rowspan"),10),j=0;j<l;j++)p[c+j][q+i]=m;else p[c][q+i]=m;m=p[c][q]||h(q,o),d(m)&&(p[c][q]=m),q++}))}}),a.each(p,function(c,h){if(d(h)){var i=d(b.onlyColumns)||b.ignoreColumns.length?a.grep(h,function(a,b){return!f(b)}):h,j=d(b.headings)?e:a.grep(e,function(a,b){return!f(b)});m=g(j,i),r[r.length]=m}}),r}(this,j(this))}}(jQuery);

View File

@ -0,0 +1,35 @@
{
"name": "table-to-json",
"description": "jQuery plugin that reads an HTML table and returns a javascript object representing the values and columns of the table",
"version": "0.13.0",
"homepage": "https://github.com/lightswitch05/table-to-json",
"main": "lib/jquery.tabletojson.js",
"demo": "http://lightswitch05.github.io/table-to-json/",
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/lightswitch05/table-to-json.git"
},
"author": {
"name": "Daniel White"
},
"scripts": {
"test": "grunt test"
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
"grunt-contrib-jshint": "~0.11.2",
"grunt-contrib-qunit": "~0.7.0",
"grunt-contrib-concat": "~0.5.1",
"grunt-contrib-uglify": "~0.9.1",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-watch": "~0.6.1"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/lightswitch05/table-to-json/blob/master/MIT-LICENSE"
}
]
}

View File

@ -0,0 +1,182 @@
(function( $ ) {
'use strict';
$.fn.tableToJSON = function(opts) {
// Set options
var defaults = {
ignoreColumns: [],
onlyColumns: null,
ignoreHiddenRows: true,
ignoreEmptyRows: false,
headings: null,
allowHTML: false,
includeRowId: false,
textDataOverride: 'data-override',
extractor: null,
textExtractor: null
};
opts = $.extend(defaults, opts);
var notNull = function(value) {
return value !== undefined && value !== null;
};
var notEmpty = function(value) {
return value !== undefined && value.length > 0;
};
var ignoredColumn = function(index) {
if( notNull(opts.onlyColumns) ) {
return $.inArray(index, opts.onlyColumns) === -1;
}
return $.inArray(index, opts.ignoreColumns) !== -1;
};
var arraysToHash = function(keys, values) {
var result = {}, index = 0;
$.each(values, function(i, value) {
// when ignoring columns, the header option still starts
// with the first defined column
if ( index < keys.length && notNull(value) ) {
if (notEmpty(keys[index])){
result[ keys[index] ] = value;
}
index++;
}
});
return result;
};
var cellValues = function(cellIndex, cell, isHeader) {
var $cell = $(cell),
// extractor
extractor = opts.extractor || opts.textExtractor,
override = $cell.attr(opts.textDataOverride),
value;
// don't use extractor for header cells
if ( extractor === null || isHeader ) {
return $.trim( override || ( opts.allowHTML ? $cell.html() : cell.textContent || $cell.text() ) || '' );
} else {
// overall extractor function
if ( $.isFunction(extractor) ) {
value = override || extractor(cellIndex, $cell);
return typeof value === 'string' ? $.trim( value ) : value;
} else if ( typeof extractor === 'object' && $.isFunction( extractor[cellIndex] ) ) {
value = override || extractor[cellIndex](cellIndex, $cell);
return typeof value === 'string' ? $.trim( value ) : value;
}
}
// fallback
return $.trim( override || ( opts.allowHTML ? $cell.html() : cell.textContent || $cell.text() ) || '' );
};
var rowValues = function(row, isHeader) {
var result = [];
var includeRowId = opts.includeRowId;
var useRowId = (typeof includeRowId === 'boolean') ? includeRowId : (typeof includeRowId === 'string') ? true : false;
var rowIdName = (typeof includeRowId === 'string') === true ? includeRowId : 'rowId';
if (useRowId) {
if (typeof $(row).attr('id') === 'undefined') {
result.push(rowIdName);
}
}
$(row).children('td,th').each(function(cellIndex, cell) {
result.push( cellValues(cellIndex, cell, isHeader) );
});
return result;
};
var getHeadings = function(table) {
var firstRow = table.find('tr:first').first();
return notNull(opts.headings) ? opts.headings : rowValues(firstRow, true);
};
var construct = function(table, headings) {
var i, j, len, len2, txt, $row, $cell,
tmpArray = [], cellIndex = 0, result = [];
table.children('tbody,*').children('tr').each(function(rowIndex, row) {
if( rowIndex > 0 || notNull(opts.headings) ) {
var includeRowId = opts.includeRowId;
var useRowId = (typeof includeRowId === 'boolean') ? includeRowId : (typeof includeRowId === 'string') ? true : false;
$row = $(row);
var isEmpty = ($row.find('td').length === $row.find('td:empty').length) ? true : false;
if( ( $row.is(':visible') || !opts.ignoreHiddenRows ) && ( !isEmpty || !opts.ignoreEmptyRows ) && ( !$row.data('ignore') || $row.data('ignore') === 'false' ) ) {
cellIndex = 0;
if (!tmpArray[rowIndex]) {
tmpArray[rowIndex] = [];
}
if (useRowId) {
cellIndex = cellIndex + 1;
if (typeof $row.attr('id') !== 'undefined') {
tmpArray[rowIndex].push($row.attr('id'));
} else {
tmpArray[rowIndex].push('');
}
}
$row.children().each(function(){
$cell = $(this);
// skip column if already defined
while (tmpArray[rowIndex][cellIndex]) { cellIndex++; }
// process rowspans
if ($cell.filter('[rowspan]').length) {
len = parseInt( $cell.attr('rowspan'), 10) - 1;
txt = cellValues(cellIndex, $cell);
for (i = 1; i <= len; i++) {
if (!tmpArray[rowIndex + i]) { tmpArray[rowIndex + i] = []; }
tmpArray[rowIndex + i][cellIndex] = txt;
}
}
// process colspans
if ($cell.filter('[colspan]').length) {
len = parseInt( $cell.attr('colspan'), 10) - 1;
txt = cellValues(cellIndex, $cell);
for (i = 1; i <= len; i++) {
// cell has both col and row spans
if ($cell.filter('[rowspan]').length) {
len2 = parseInt( $cell.attr('rowspan'), 10);
for (j = 0; j < len2; j++) {
tmpArray[rowIndex + j][cellIndex + i] = txt;
}
} else {
tmpArray[rowIndex][cellIndex + i] = txt;
}
}
}
txt = tmpArray[rowIndex][cellIndex] || cellValues(cellIndex, $cell);
if (notNull(txt)) {
tmpArray[rowIndex][cellIndex] = txt;
}
cellIndex++;
});
}
}
});
$.each(tmpArray, function( i, row ){
if (notNull(row)) {
// remove ignoredColumns / add onlyColumns
var newRow = notNull(opts.onlyColumns) || opts.ignoreColumns.length ?
$.grep(row, function(v, index){ return !ignoredColumn(index); }) : row,
// remove ignoredColumns / add onlyColumns if headings is not defined
newHeadings = notNull(opts.headings) ? headings :
$.grep(headings, function(v, index){ return !ignoredColumn(index); });
txt = arraysToHash(newHeadings, newRow);
result[result.length] = txt;
}
});
return result;
};
// Run
var headings = getHeadings(this);
return construct(this, headings);
};
})( jQuery );

View File

@ -0,0 +1,30 @@
{
"name": "tabletojson",
"title": "Table To JSON",
"description": "jQuery plugin that reads an HTML table and returns a javascript object representing the values and columns of the table",
"keywords": [
"table",
"serialize",
"tabletojson",
"json"
],
"version": "0.12.0",
"author": {
"name": "Daniel White",
"url": "http://www.developerdan.com"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/lightswitch05/table-to-json/blob/master/MIT-LICENSE"
}
],
"bugs": "https://github.com/lightswitch05/table-to-json/issues",
"homepage": "https://github.com/lightswitch05/table-to-json",
"docs": "https://github.com/lightswitch05/table-to-json",
"download": "https://github.com/lightswitch05/table-to-json",
"demo": "http://lightswitch05.github.io/table-to-json/",
"dependencies": {
"jquery": ">=1.5"
}
}

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Table To JSON Test</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.13.0.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://code.jquery.com/qunit/qunit-1.13.0.js"></script>
</head>
<body>
<h1 id="qunit-header">MyApp Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture"></div>
<script type="text/javascript" src="../src/jquery.tabletojson.js"></script>
<script type="text/javascript" src="specs/core.test.js"></script>
<script type="text/javascript" src="specs/content.test.js"></script>
</body>
</html>

View File

@ -0,0 +1,645 @@
/*global module, test, expect, deepEqual */
module('content');
/* Ignore nested tables in cells with just td's*/
test('ignore nested <td> in cells', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve <table><tr><td>1</td></tr><tr><td>2</td></tr></table> </td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [{'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'First Name':'Eve 12', 'Last Name':'Jackson', 'Points':'94'},
{'First Name':'John', 'Last Name':'Doe', 'Points':'80'}];
deepEqual(table, expected);
});
/* Ignore nested tables in cells with th's and td's*/
test('ignore nested <th> and <td> in cells', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve <table><tr><th>number</th></tr><tr><td>1</td></tr><tr><td>2</td></tr></table> </td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [{'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'First Name':'Eve number12', 'Last Name':'Jackson', 'Points':'94'},
{'First Name':'John', 'Last Name':'Doe', 'Points':'80'}];
deepEqual(table, expected);
});
/* Ignore nested tables in headings with just td's*/
test('ignore nested <td> in headings', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name <table><tr><td>1</td></tr><tr><td>2</td></tr></table> </th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [{'First Name':'Jill', 'Last Name 12':'Smith', 'Points':'50'},
{'First Name':'Eve', 'Last Name 12':'Jackson', 'Points':'94'},
{'First Name':'John', 'Last Name 12':'Doe', 'Points':'80'}];
deepEqual(table, expected);
});
/* Ignore nested tables in headings with th's and td's*/
test('ignore nested <th> and <td> in headings', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name <table><tr><th>number</th></tr><tr><td>1</td></tr><tr><td>2</td></tr></table> </th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [{'First Name':'Jill', 'Last Name number12':'Smith', 'Points':'50'},
{'First Name':'Eve', 'Last Name number12':'Jackson', 'Points':'94'},
{'First Name':'John', 'Last Name number12':'Doe', 'Points':'80'}];
deepEqual(table, expected);
});
/* Links are retrieved as values */
test('links are just values', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td><a href="#">Jill</a></td>' +
'<td><a href="#">Smith</a></td>' +
'<td><a href="#">50</a></td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [{'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'First Name':'Eve', 'Last Name':'Jackson', 'Points':'94'},
{'First Name':'John', 'Last Name':'Doe', 'Points':'80'}];
deepEqual(table, expected);
});
/* A complex table */
test('complex table', function() {
$('#qunit-fixture').html(
'<table id="test-table" class="table table-striped table-hover table-condensed" data-role="rate_table"> <thead> <tr> <th data-override="id"><input type="checkbox" data-role="checkall" data-check-name="row_ids[]"></th> <th data-override="State">Status</th> <th data-override="BCS">Location</th> <th data-override="ZONE">Zone</th> <th data-override="TIER">Tier</th> <th data-override="INSTALL_CALC">Install Calc</th> <th data-override="INSTALL_R1">Install Rate</th> </tr> </thead> <tbody> <tr> <td data-override="oaWd4cs2JHY660pG"><input id="oaWd4cs2JHY660pG" name="row_ids[]" type="checkbox" value="oaWd4cs2JHY660pG"> <i class="icon-arrow-down hover" data-title="Copy row" data-role="copy-row" data-original-title=""></i> <i class="icon-remove hover" data-title="Delete row" data-role="delete-row" data-original-title=""></i> <i class="icon-warning-sign hover" data-role="ok-modal" data-modal-name="row-errors-modal" data-title="Display rate table errors" data-original-title=""></i> <div class="hidden" data-role="row-errors-modal" title="Rate Table Errors"> <p> The specified value () is invalid for the field (ACCSIN_TYP). </p> <p> The specified value () is invalid for the field (ZONE). </p> <p> The specified value () is invalid for the field (TIERIND). </p> <p> The specified value () is invalid for the field (CALCTYPE). </p> <p> The required decimal value is not valid. The value must be between (-9999999999.999999) and (9999999999.999999). </p> </div> <i data-title="Row Audit Trail" data-modal-name="audit-modal" data-role="ok-modal" class="icon-tags hover" data-original-title=""></i> <div class="hidden" data-role="audit-modal" title="Audit Trail"> <table class="table table-striped table-hover table-condensed"> <thead> <tr> <th>Date</th> <th>User ID</th> <th>From</th> <th>To</th> <th>Action</th> </tr> </thead> <tbody><tr> <td> 2013-02-12 09:26:21 </td> <td> tapadmin </td> <td> </td> <td> INCOMPLETE </td> <td> Rate Table Detail Creation </td> </tr><tr> <td> 2013-02-12 09:26:21 </td> <td> tapadmin </td> <td> INCOMPLETE </td> <td> INCOMPLETE </td> <td> Rate table change </td> </tr><tr> <td> 2013-02-13 07:37:26 </td> <td> tapadmin </td> <td> INCOMPLETE </td> <td> INCOMPLETE </td> <td> Rate table change </td> </tr><tr> <td> 2013-02-14 09:04:40 </td> <td> tapadmin </td> <td> INCOMPLETE </td> <td> INCOMPLETE </td> <td> Rate table change </td> </tr><tr> <td> 2013-02-14 09:05:33 </td> <td> tapadmin </td> <td> INCOMPLETE </td> <td> INCOMPLETE </td> <td> Rate table change </td> </tr><tr> <td> 2013-02-14 09:49:55 </td> <td> tapadmin </td> <td> INCOMPLETE </td> <td> INCOMPLETE </td> <td> Rate table change </td> </tr><tr> <td> 2013-02-14 09:50:11 </td> <td> tapadmin </td> <td> INCOMPLETE </td> <td> INCOMPLETE </td> <td> Rate table change </td> </tr><tr> <td> 2013-02-14 09:50:11 </td> <td> tapadmin </td> <td> </td> <td> INCOMPLETE </td> <td> Rate row created </td> </tr></tbody></table> </div> </td> <td data-type="row-status">INCOMPLETE</td> <td> <a data-type="text" data-group-code="ACCSIN_TYP" class="editable editable-click editable-unsaved" data-original-title="">location</a> </td> <td> <a data-type="select" data-group-code="ZONE" class="editable editable-click editable-unsaved" data-original-title="">1</a> </td> <td> <a data-type="select" data-group-code="TIERIND" class="editable editable-click editable-unsaved" data-original-title="">QTY</a> </td> <td> <a data-type="text" data-group-code="" class="editable editable-click editable-unsaved" data-original-title="">B</a> </td> <td> <a data-type="text" data-group-code="" class="editable editable-click editable-unsaved" data-original-title="">9.5</a> </td> </tr> <tr style="display: none;"> <td data-override=""><input id="" name="row_ids[]" type="checkbox" value="new_row"> <i class="icon-arrow-down hover" data-title="Copy row" data-role="copy-row" data-original-title=""></i> <i class="icon-remove hover" data-title="Delete row" data-role="delete-row" data-original-title=""></i> </td> <td data-type="row-status">INCOMPLETE</td> <td> <a data-type="text" data-group-code="ACCSIN_TYP" class="editable editable-click editable-empty">Empty</a> </td> <td> <a data-type="select" data-group-code="ZONE" class="editable editable-click editable-empty">Empty</a> </td> <td> <a data-type="select" data-group-code="TIERIND" class="editable editable-click editable-empty">Empty</a> </td> <td> <a data-type="text" data-group-code="" class="editable editable-click editable-empty">Empty</a> </td> <td> <a data-type="text" data-group-code="" class="editable editable-click editable-empty">Empty</a> </td> </tr> </tbody> </table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [{'id':'oaWd4cs2JHY660pG', 'State':'INCOMPLETE', 'BCS':'location', 'ZONE':'1', 'TIER':'QTY', 'INSTALL_CALC':'B', 'INSTALL_R1':'9.5'}];
deepEqual(table, expected);
});
/* A table with rowspan & colspan */
test('rowspan & colspan in tbody', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr><th>line</th><th>value1</th><th>value2</th><th>value3</th><th>value4</th></tr>' +
'<tr><td rowspan="2">1</td><td>1.1</td><td>1.2</td><td>1.3</td><td rowspan="2">1.4</td></tr>' +
'<tr><td>1.5</td><td>1.6</td><td>1.7</td></tr>' +
'<tr><td rowspan="2">2</td><td>2.1</td><td>2.2</td><td>2.3</td><td>2.4</td></tr>' +
'<tr><td colspan="2">2.5</td><td>2.6</td><td>2.7</td></tr>' +
'<tr><td rowspan="2">3</td><td rowspan="2" colspan="2">3.1</td><td colspan="2">3.2</td></tr>' +
'<tr><td>3.4</td><td>3.5</td></tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [
{'line':'1','value1':'1.1','value2':'1.2','value3':'1.3','value4':'1.4'},
{'line':'1','value1':'1.5','value2':'1.6','value3':'1.7','value4':'1.4'},
{'line':'2','value1':'2.1','value2':'2.2','value3':'2.3','value4':'2.4'},
{'line':'2','value1':'2.5','value2':'2.5','value3':'2.6','value4':'2.7'},
{'line':'3','value1':'3.1','value2':'3.1','value3':'3.2','value4':'3.2'},
{'line':'3','value1':'3.1','value2':'3.1','value3':'3.4','value4':'3.5'}
];
deepEqual(table, expected);
});
/* A table with rowspan & colspan & ignoreColumns */
test('ignoreColumns with rowspan & colspan in tbody', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr><th>line</th><th>value1</th><th>value2</th><th>value3</th><th>value4</th></tr>' +
'<tr><td rowspan="2">1</td><td>1.1</td><td>1.2</td><td>1.3</td><td rowspan="2">1.4</td></tr>' +
'<tr><td>1.5</td><td>1.6</td><td>1.7</td></tr>' +
'<tr><td rowspan="2">2</td><td>2.1</td><td>2.2</td><td>2.3</td><td>2.4</td></tr>' +
'<tr><td colspan="2">2.5</td><td>2.6</td><td>2.7</td></tr>' +
'<tr><td rowspan="2">3</td><td rowspan="2" colspan="2">3.1</td><td colspan="2">3.2</td></tr>' +
'<tr><td>3.4</td><td>3.5</td></tr>' +
'</table>'
);
expect(5);
var $table = $('#test-table');
$table.find('tr:eq(0)').hide();
var table = $table.tableToJSON({ headings: [ 'v1','v2','v3','v4' ], ignoreColumns : [0] });
$table.find('tr:eq(0)').show();
var expected = [
{'v1':'1.1','v2':'1.2','v3':'1.3','v4':'1.4'},
{'v1':'1.5','v2':'1.6','v3':'1.7','v4':'1.4'},
{'v1':'2.1','v2':'2.2','v3':'2.3','v4':'2.4'},
{'v1':'2.5','v2':'2.5','v3':'2.6','v4':'2.7'},
{'v1':'3.1','v2':'3.1','v3':'3.2','v4':'3.2'},
{'v1':'3.1','v2':'3.1','v3':'3.4','v4':'3.5'}
];
deepEqual(table, expected);
table = $table.tableToJSON({ ignoreColumns : [1] });
expected = [
{'line':'1','value2':'1.2','value3':'1.3','value4':'1.4'},
{'line':'1','value2':'1.6','value3':'1.7','value4':'1.4'},
{'line':'2','value2':'2.2','value3':'2.3','value4':'2.4'},
{'line':'2','value2':'2.5','value3':'2.6','value4':'2.7'},
{'line':'3','value2':'3.1','value3':'3.2','value4':'3.2'},
{'line':'3','value2':'3.1','value3':'3.4','value4':'3.5'}
];
deepEqual(table, expected);
table = $table.tableToJSON({ ignoreColumns : [2] });
expected = [
{'line':'1','value1':'1.1','value3':'1.3','value4':'1.4'},
{'line':'1','value1':'1.5','value3':'1.7','value4':'1.4'},
{'line':'2','value1':'2.1','value3':'2.3','value4':'2.4'},
{'line':'2','value1':'2.5','value3':'2.6','value4':'2.7'},
{'line':'3','value1':'3.1','value3':'3.2','value4':'3.2'},
{'line':'3','value1':'3.1','value3':'3.4','value4':'3.5'}
];
deepEqual(table, expected);
table = $table.tableToJSON({ ignoreColumns : [3] });
expected = [
{'line':'1','value1':'1.1','value2':'1.2','value4':'1.4'},
{'line':'1','value1':'1.5','value2':'1.6','value4':'1.4'},
{'line':'2','value1':'2.1','value2':'2.2','value4':'2.4'},
{'line':'2','value1':'2.5','value2':'2.5','value4':'2.7'},
{'line':'3','value1':'3.1','value2':'3.1','value4':'3.2'},
{'line':'3','value1':'3.1','value2':'3.1','value4':'3.5'}
];
deepEqual(table, expected);
table = $table.tableToJSON({ ignoreColumns : [4] });
expected = [
{'line':'1','value1':'1.1','value2':'1.2','value3':'1.3'},
{'line':'1','value1':'1.5','value2':'1.6','value3':'1.7'},
{'line':'2','value1':'2.1','value2':'2.2','value3':'2.3'},
{'line':'2','value1':'2.5','value2':'2.5','value3':'2.6'},
{'line':'3','value1':'3.1','value2':'3.1','value3':'3.2'},
{'line':'3','value1':'3.1','value2':'3.1','value3':'3.4'}
];
deepEqual(table, expected);
});
/* A complex table with row & col spans */
test('complex table with row & col spans', function() {
$('#qunit-fixture').html(
'<table id="test-table" data-numcols="0" data-numrows="36"> <tr> <th>Rota</th> <th>Descrição Descritor</th> <th>Ano</th> <th>Mês (completo)</th> <th>Dia</th> <th>Intervalo 30min</th> <th>Totais</th> </tr><tr> <td rowspan="14">null</td><td rowspan="2">AutoAtendimento</td><td rowspan="2">2015</td><td rowspan="2">01-Jan</td><td rowspan="2">06</td><td rowspan="1">11:00:00</td><td data-for="row0">1</td></tr><tr> <td rowspan="1">12:00:00</td><td data-for="row1">3</td></tr><tr> <td rowspan="6">Fila</td><td rowspan="6">2015</td><td rowspan="6">01-Jan</td><td rowspan="2">06</td><td rowspan="1">11:00:00</td><td data-for="row2">1</td></tr><tr> <td rowspan="1">12:00:00</td><td data-for="row3">2</td></tr><tr> <td rowspan="4">27</td><td rowspan="1">11:30:00</td><td data-for="row4">1</td></tr><tr> <td rowspan="1">12:00:00</td><td data-for="row5">1</td></tr><tr> <td rowspan="1">15:00:00</td><td data-for="row6">4</td></tr><tr> <td rowspan="1">16:00:00</td><td data-for="row7">2</td></tr><tr> <td rowspan="6">Inicio</td><td rowspan="6">2015</td><td rowspan="6">01-Jan</td><td rowspan="2">06</td><td rowspan="1">11:00:00</td><td data-for="row8">2</td></tr><tr> <td rowspan="1">12:00:00</td><td data-for="row9">5</td></tr><tr> <td rowspan="4">27</td><td rowspan="1">11:30:00</td><td data-for="row10">1</td></tr><tr> <td rowspan="1">12:00:00</td><td data-for="row11">1</td></tr><tr> <td rowspan="1">15:00:00</td><td data-for="row12">4</td></tr><tr> <td rowspan="1">16:00:00</td><td data-for="row13">2</td></tr><tr> <td rowspan="22">Rota externa</td><td rowspan="2">AutoAtendimento</td><td rowspan="2">2015</td><td rowspan="2">01-Jan</td><td rowspan="2">06</td><td rowspan="1">12:00:00</td><td data-for="row14">1</td></tr><tr> <td rowspan="1">12:30:00</td><td data-for="row15">2</td></tr><tr> <td rowspan="9">Fila</td><td rowspan="9">2015</td><td rowspan="9">01-Jan</td><td rowspan="2">06</td><td rowspan="1">12:00:00</td><td data-for="row16">1</td></tr><tr> <td rowspan="1">12:30:00</td><td data-for="row17">2</td></tr><tr> <td rowspan="7">27</td><td rowspan="1">10:30:00</td><td data-for="row18">1</td></tr><tr> <td rowspan="1">11:00:00</td><td data-for="row19">2</td></tr><tr> <td rowspan="1">11:30:00</td><td data-for="row20">1</td></tr><tr> <td rowspan="1">12:00:00</td><td data-for="row21">2</td></tr><tr> <td rowspan="1">16:00:00</td><td data-for="row22">2</td></tr><tr> <td rowspan="1">18:30:00</td><td data-for="row23">1</td></tr><tr> <td rowspan="1">19:00:00</td><td data-for="row24">1</td></tr><tr> <td rowspan="11">Inicio</td><td rowspan="11">2015</td><td rowspan="10">01-Jan</td><td rowspan="2">06</td><td rowspan="1">12:00:00</td><td data-for="row25">2</td></tr><tr> <td rowspan="1">12:30:00</td><td data-for="row26">4</td></tr><tr> <td rowspan="7">27</td><td rowspan="1">10:30:00</td><td data-for="row27">2</td></tr><tr> <td rowspan="1">11:00:00</td><td data-for="row28">2</td></tr><tr> <td rowspan="1">11:30:00</td><td data-for="row29">1</td></tr><tr> <td rowspan="1">12:00:00</td><td data-for="row30">2</td></tr><tr> <td rowspan="1">16:00:00</td><td data-for="row31">2</td></tr><tr> <td rowspan="1">18:30:00</td><td data-for="row32">1</td></tr><tr> <td rowspan="1">19:00:00</td><td data-for="row33">1</td></tr><tr> <td rowspan="1">30</td><td rowspan="1">20:00:00</td><td data-for="row34">1</td></tr><tr> <td rowspan="1">02-Feb</td><td rowspan="1">03</td><td rowspan="1">14:30:00</td><td data-for="row35">1</td></tr><tr> <th colspan="6">Totais</th> <td>34</td></tr></table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [
{
'Ano': '2015',
'Descrição Descritor': 'AutoAtendimento',
'Dia': '06',
'Intervalo 30min': '11:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'AutoAtendimento',
'Dia': '06',
'Intervalo 30min': '12:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '3'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '06',
'Intervalo 30min': '11:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '06',
'Intervalo 30min': '12:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '27',
'Intervalo 30min': '11:30:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '27',
'Intervalo 30min': '12:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '27',
'Intervalo 30min': '15:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '4'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '27',
'Intervalo 30min': '16:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '06',
'Intervalo 30min': '11:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '06',
'Intervalo 30min': '12:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '5'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '27',
'Intervalo 30min': '11:30:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '27',
'Intervalo 30min': '12:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '27',
'Intervalo 30min': '15:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '4'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '27',
'Intervalo 30min': '16:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'null',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'AutoAtendimento',
'Dia': '06',
'Intervalo 30min': '12:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'AutoAtendimento',
'Dia': '06',
'Intervalo 30min': '12:30:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '06',
'Intervalo 30min': '12:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '06',
'Intervalo 30min': '12:30:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '27',
'Intervalo 30min': '10:30:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '27',
'Intervalo 30min': '11:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '27',
'Intervalo 30min': '11:30:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '27',
'Intervalo 30min': '12:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '27',
'Intervalo 30min': '16:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '27',
'Intervalo 30min': '18:30:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Fila',
'Dia': '27',
'Intervalo 30min': '19:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '06',
'Intervalo 30min': '12:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '06',
'Intervalo 30min': '12:30:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '4'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '27',
'Intervalo 30min': '10:30:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '27',
'Intervalo 30min': '11:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '27',
'Intervalo 30min': '11:30:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '27',
'Intervalo 30min': '12:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '27',
'Intervalo 30min': '16:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '2'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '27',
'Intervalo 30min': '18:30:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '27',
'Intervalo 30min': '19:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '30',
'Intervalo 30min': '20:00:00',
'Mês (completo)': '01-Jan',
'Rota': 'Rota externa',
'Totais': '1'
},
{
'Ano': '2015',
'Descrição Descritor': 'Inicio',
'Dia': '03',
'Intervalo 30min': '14:30:00',
'Mês (completo)': '02-Feb',
'Rota': 'Rota externa',
'Totais': '1'
},
{
'Ano': 'Totais',
'Descrição Descritor': 'Totais',
'Dia': 'Totais',
'Intervalo 30min': 'Totais',
'Mês (completo)': 'Totais',
'Rota': 'Totais',
'Totais': '34'
}
];
deepEqual(table, expected);
});

View File

@ -0,0 +1,817 @@
/*global module, test, expect, deepEqual */
module('core');
/* Basic Usage */
test('basic usage', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [{'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'First Name':'Eve', 'Last Name':'Jackson', 'Points':'94'},
{'First Name':'John', 'Last Name':'Doe', 'Points':'80'}];
deepEqual(table, expected);
});
/* Basic Usage with thead and tbody*/
test('basic usage with thead and tbody', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<thead>' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'</thead>' +
'<tbody>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</tbody>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [{'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'First Name':'Eve', 'Last Name':'Jackson', 'Points':'94'},
{'First Name':'John', 'Last Name':'Doe', 'Points':'80'}];
deepEqual(table, expected);
});
/* Override Column Names */
test('override column names', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th data-override="Nickname">First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [{'Nickname':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'Nickname':'Eve', 'Last Name':'Jackson', 'Points':'94'},
{'Nickname':'John', 'Last Name':'Doe', 'Points':'80'}];
deepEqual(table, expected);
});
/* Override Cell Values */
test('override column names', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th data-override="Nickname">First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td data-override="disqualified">50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [{'Nickname':'Jill', 'Last Name':'Smith', 'Points':'disqualified'},
{'Nickname':'Eve', 'Last Name':'Jackson', 'Points':'94'},
{'Nickname':'John', 'Last Name':'Doe', 'Points':'80'}];
deepEqual(table, expected);
});
/* Ignore Column */
test('ignore columns', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({
ignoreColumns: [0]
});
var expected = [
{'Last Name':'Smith', 'Points':'50'},
{'Last Name':'Jackson', 'Points':'94'},
{'Last Name':'Doe', 'Points':'80'}
];
deepEqual(table, expected);
});
/* Ignore Hidden Row */
test('ignore hidden rows', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr style="display: none;">' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [{'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'First Name':'Eve', 'Last Name':'Jackson', 'Points':'94'}];
deepEqual(table, expected);
});
/* Include Hidden Rows */
test('Include Hidden Rows', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr style="display: none;">' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({
ignoreHiddenRows: false
});
var expected = [{'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'First Name':'Eve', 'Last Name':'Jackson', 'Points':'94'},
{'First Name':'John', 'Last Name':'Doe', 'Points':'80'}];
deepEqual(table, expected);
});
/* Ignore Empty Row */
test('ignore empty rows', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr">' +
'<td></td>' +
'<td></td>' +
'<td></td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({ignoreEmptyRows:true});
var expected = [{'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'First Name':'Eve', 'Last Name':'Jackson', 'Points':'94'}];
deepEqual(table, expected);
});
/* Include Empty Row */
test('ignore empty rows', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr">' +
'<td></td>' +
'<td></td>' +
'<td></td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [{'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'First Name':'Eve', 'Last Name':'Jackson', 'Points':'94'},
{'First Name':'', 'Last Name':'', 'Points':''}];
deepEqual(table, expected);
});
/* Ignore Row Option */
test('ignore empty rows', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr data-ignore="true">' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr data-ignore="false">' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({ignoreEmptyRows:true});
var expected = [{'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'First Name':'John', 'Last Name':'Doe', 'Points':'80'}];
deepEqual(table, expected);
});
/* Read first row of td's as column when there are no th's*/
test('without any <th>', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<td>First Name</td>' +
'<td>Last Name</td>' +
'<td>Points</td>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON();
var expected = [{'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'First Name':'Eve', 'Last Name':'Jackson', 'Points':'94'},
{'First Name':'John', 'Last Name':'Doe', 'Points':'80'}];
deepEqual(table, expected);
});
/* Uses the onlyColumns option to only include the first column*/
test('Ony include 1 column', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({
onlyColumns: [0]
});
var expected = [
{'First Name':'Jill'},
{'First Name':'Eve'},
{'First Name':'John'}
];
deepEqual(table, expected);
});
/* onlyColumns option overrides ignoreColumns option */
test('onlyColumns option overrides ignoreColumns option', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({
onlyColumns: [0, 1],
ignoreColumns: [0, 1]
});
var expected = [
{'First Name':'Jill', 'Last Name':'Smith'},
{'First Name':'Eve', 'Last Name':'Jackson'},
{'First Name':'John', 'Last Name':'Doe'}
];
deepEqual(table, expected);
});
/* headings option uses all rows as data */
test('headings option uses all rows as data', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({
headings: ['First Name', 'Last Name', 'Points']
});
var expected = [
{'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'First Name':'Eve', 'Last Name':'Jackson', 'Points':'94'},
{'First Name':'John', 'Last Name':'Doe', 'Points':'80'}
];
deepEqual(table, expected);
});
/* headings option works with ignoreColumns option */
test('headings option works with ignoreColumns option', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({
ignoreColumns: [0],
headings: ['Last Name', 'Points']
});
var expected = [
{'Last Name':'Smith', 'Points':'50'},
{'Last Name':'Jackson', 'Points':'94'},
{'Last Name':'Doe', 'Points':'80'}
];
deepEqual(table, expected);
});
/* headings option works with onlyColumns option */
test('headings option works with onlyColumns option', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr>' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr>' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({
onlyColumns: [1, 2],
headings: ['Last Name', 'Points']
});
var expected = [
{'Last Name':'Smith', 'Points':'50'},
{'Last Name':'Jackson', 'Points':'94'},
{'Last Name':'Doe', 'Points':'80'}
];
deepEqual(table, expected);
});
/* allowHTML option allows HTML tags within a table to remain in the object */
test('allowHTML option allows HTML tags within a table to remain in the object', function () {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr>' +
'<td><strong>Jill</strong></td>' +
'<td><span class="lastName">Smith</span></td>' +
'<td><em>50</em></td>' +
'</tr>' +
'<tr>' +
'<td><strong>Eve</strong></td>' +
'<td><span class="lastName">Jackson</span></td>' +
'<td><em>94</em></td>' +
'</tr>' +
'<tr>' +
'<td><strong>John</strong></td>' +
'<td><span class="lastName">Doe</span></td>' +
'<td><em>80</em></td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({
allowHTML: true
});
var expected = [
{'First Name':'<strong>Jill</strong>', 'Last Name':'<span class="lastName">Smith</span>', 'Points':'<em>50</em>'},
{'First Name':'<strong>Eve</strong>', 'Last Name':'<span class="lastName">Jackson</span>', 'Points':'<em>94</em>'},
{'First Name':'<strong>John</strong>', 'Last Name':'<span class="lastName">Doe</span>', 'Points':'<em>80</em>'}
];
deepEqual(table, expected);
});
/* includeRowId option boolean type places the attribute ID from the row as a property of the row */
test('includeRowId option boolean type places the attribute ID from the row as a property of the row', function () {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr id="1">' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr id="2">' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr id="3">' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'<tr>' +
'<td>No</td>' +
'<td>Row</td>' +
'<td>ID</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({
includeRowId: true
});
var expected = [
{'rowId':'1', 'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'rowId':'2', 'First Name':'Eve', 'Last Name':'Jackson', 'Points':'94'},
{'rowId':'3', 'First Name':'John', 'Last Name':'Doe', 'Points':'80'},
{'rowId':'', 'First Name':'No', 'Last Name':'Row', 'Points':'ID'}
];
deepEqual(table, expected);
});
/* includeRowId option custom, instead of a boolean use a string, and string value will be the property name. */
test('includeRowId option string type, instead of a boolean use a string, and string value will be the property name', function () {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<tr>' +
'<th>First Name</th>' +
'<th>Last Name</th>' +
'<th>Points</th>' +
'</tr>' +
'<tr id="1">' +
'<td>Jill</td>' +
'<td>Smith</td>' +
'<td>50</td>' +
'</tr>' +
'<tr id="2">' +
'<td>Eve</td>' +
'<td>Jackson</td>' +
'<td>94</td>' +
'</tr>' +
'<tr id="3">' +
'<td>John</td>' +
'<td>Doe</td>' +
'<td>80</td>' +
'</tr>' +
'<tr>' +
'<td>No</td>' +
'<td>Row</td>' +
'<td>ID</td>' +
'</tr>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({
includeRowId: 'customIDname'
});
var expected = [
{'customIDname':'1', 'First Name':'Jill', 'Last Name':'Smith', 'Points':'50'},
{'customIDname':'2', 'First Name':'Eve', 'Last Name':'Jackson', 'Points':'94'},
{'customIDname':'3', 'First Name':'John', 'Last Name':'Doe', 'Points':'80'},
{'customIDname':'', 'First Name':'No', 'Last Name':'Row', 'Points':'ID'}
];
deepEqual(table, expected);
});
test('Basic Usage extractor option', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<thead>' +
'<tr>' +
'<th>Title</th>' +
'<th>Street</th>' +
'</tr>' +
'</thead>' +
'<tbody>' +
'<tr>' +
'<td><span>Doctor</span> Jill Smith</td>' +
'<td>123 <span>Main</span> Street</td>' +
'</tr>' +
'<tr>' +
'<td><span>President</span> Eve Jackson</td>' +
'<td>999 <span>National</span> Blvd.</td>' +
'</tr>' +
'<tr>' +
'<td><span>Mr.</span> John Doe</td>' +
'<td>555 <span>Letter</span> Ave.</td>' +
'</tr>' +
'</tbody>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({
extractor : function(cellIndex, $cell) {
return $cell.find('span').text();
}
});
var expected = [{'Title':'Doctor', 'Street':'Main'},
{'Title':'President', 'Street':'National'},
{'Title':'Mr.', 'Street':'Letter'}];
deepEqual(table, expected);
});
test('extractor option per column', function() {
$('#qunit-fixture').html(
'<table id="test-table">' +
'<thead>' +
'<tr>' +
'<th>Title</th>' +
'<th>Number</th>' +
'<th>Date</th>' +
'</tr>' +
'</thead>' +
'<tbody>' +
'<tr>' +
'<td><span>Doctor</span> Jill Smith</td>' +
'<td data-override="345"><em>123</em> Main Street</td>' +
'<td>1/31/2015</td>' +
'</tr>' +
'<tr>' +
'<td><span>President</span> Eve Jackson</td>' +
'<td><em>999</em> National Blvd.</td>' +
'<td>2/1/2014</td>' +
'</tr>' +
'<tr>' +
'<td><span>Mr.</span> John Doe</td>' +
'<td><em>555</em> Letter Ave.</td>' +
'<td>12/2/2014</td>' +
'</tr>' +
'</tbody>' +
'</table>'
);
expect(1);
var table = $('#test-table').tableToJSON({
extractor : {
0 : function(cellIndex, $cell) {
return $cell.find('span').text();
},
1 : function(cellIndex, $cell) {
return $cell.find('em').text();
},
2 : function(cellIndex, $cell) {
return new Date( $cell.text() ).toString();
}
}
});
var dates = [ '1/31/2015', '2/1/2014', '12/2/2014' ];
$.each(dates, function(i,v){
dates[i] = new Date(v).toString();
});
var expected = [{'Title':'Doctor', 'Number':'345', 'Date': dates[0]},
{'Title':'President', 'Number':'999', 'Date': dates[1]},
{'Title':'Mr.', 'Number':'555', 'Date': dates[2] }];
deepEqual(table, expected);
});