Excel download .xls or .xlsx

Standard

https://github.com/mpdf/mpdf

 

include_once APPPATH.’/mpdf60/mpdf.php’;

 

 

function downloadempinvoice()
{
$this->load->model(‘Members_invoice_model’);
$resultdata[‘recordinfoData’] = $this->Members_invoice_model->Employeeinvoice();
$countdata=sizeof($resultdata[‘recordinfoData’]);

for($i=0; $i< sizeof($resultdata[‘recordinfoData’]); $i++)
{

$x = 0;

while($x <= $i) {

$id=$resultdata[‘recordinfoData’][$x][‘id’];
$name=$resultdata[‘recordinfoData’][$x][‘Name’];
$Datemain=explode(“-“,$resultdata[‘recordinfoData’][$x][‘Date’]);
$Date=$Datemain[2].”-“.$Datemain[1].”-“.$Datemain[0];
$yrdata= strtotime($resultdata[‘recordinfoData’][$x][‘Date’]);
$monthlate= date(‘F-Y’, $yrdata);

$invoice_no=$resultdata[‘recordinfoData’][$x][‘invoice_no’];
$Amount=$resultdata[‘recordinfoData’][$x][‘Amount’];
$Account_Details=$resultdata[‘recordinfoData’][$x][‘Account_Details’];
$emailid=$resultdata[‘recordinfoData’][$x][’email_id’];
$pan_no=$resultdata[‘recordinfoData’][$x][‘pan_no’];
$emp_address=$resultdata[‘recordinfoData’][$x][’emp_address’];
$Currency=$resultdata[‘recordinfoData’][$x][‘Currency’];
$Nature=explode(“,”,$resultdata[‘recordinfoData’][$x][‘Nature’]);

$Consultancy_fee=$resultdata[‘recordinfoData’][$x][‘Consultancy_fee’];
$Internet=$resultdata[‘recordinfoData’][$x][‘Internet’];
$Incentive=$resultdata[‘recordinfoData’][$x][‘Incentive’];
$Arrears=$resultdata[‘recordinfoData’][$x][‘Arrears’];
$Advance=$resultdata[‘recordinfoData’][$x][‘Advance’];
$Reimbursement=$resultdata[‘recordinfoData’][$x][‘Reimbursement’];

$databank=explode(“,”,$Account_Details);
$wordamount=ucwords($this->convertToIndianCurrency($Amount));

$mpdf=new mPDF();
$record=$mpdf->WriteHTML(‘<table width=”100%”>
<tr><td>PAN No :’.$pan_no.'</td><td align=”right”> <b><h2 style=”color:blue;”>INVOICE</h2></b></td></tr>
<br>
<tr><td>Name : &nbsp; ‘.$name.'</td></tr>
<br>
<tr><td>Address : ‘.$emp_address.'</td><td align=”right”><b><h4><b style=”color:blue;”>Invoice</b>: ‘.$invoice_no.'</h4></b></td></tr>

<tr><td>E-mail : ‘.$emailid.'</td><td align=”right”><b style=”color:blue;”>Date:</b> &nbsp; ‘.$Date.'</td></tr>
<br>
<br>
<tr><td><b style=”color:blue;”>To</b> <br>

ABC Singapore Pte Ltd
583 Orchard Road #06-01
Forum Singapore 238884

</td><td align=”right”><b style=”color:blue;”>FOR</b> Consultancy fee</td></tr>

<td colspan=”2″><br><br><br><br><br><br><br><br><br><br><br><br></td>
<tr><td colspan=”2″>
<table width=”100%”>

<tr>
<td width=”70%” style=”border: 1px solid blue; color:blue;” align=”center”>Description</td>
<td style=”border: 1px solid blue; color:blue;” align=”center”>Amount in ‘.$Currency.'</td>

</tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[0].'</td><td align=”center” style=”border: 1px solid blue;”>’.$Consultancy_fee.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[1].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Internet.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[2].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Incentive.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[3].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Arrears.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[4].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Advance.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[5].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Reimbursement.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>&nbsp;</td><td style=”border: 1px solid blue;” align=”center”>&nbsp;</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”><b style=”color:blue;”>Amounts in words</b>:’.$wordamount.’Only</td><td style=”border: 1px solid blue;” align=”center” >’.$Currency.’.’.$Amount.’/</td></tr>
<tr>
<td colspan=”2″><br><br><br><br><br></td>
</tr>
<tr>
<td width=”60%”>
<table>
<tr><td>’.$databank[0].'</td></tr>
<tr><td>’.$databank[1].'</td></tr>
<tr><td>’.$databank[2].'</td></tr>
<tr><td>’.$databank[3].'</td></tr>
<tr><td>’.$databank[4].'</td></tr>

</table>

</td>

<td>

 
 
 
 
 
                Sign : ‘.$name.’

</td>
</tr>

</table>

</td></tr>
<tr>
<td>
<br>
<br>
<br>
<br>
<br>
<br>

</td>
</tr>
<tr><td colspan=”2″ style=”text-align:center;color:blue;”>THANK YOU FOR YOUR BUSINESS!</td></tr>

</table>’);

$d = date(‘Y-m-d’);
$maindata=explode(“-“,$d);
$recorddate=$maindata[2].”-“.$maindata[1].”-“.$maindata[0];

@mkdir(“assets/allinvoice/” . $recorddate, 0700);

$datapdf=$mpdf->Output(‘assets/allinvoice/’.$recorddate.’/’.$name.’-‘.$id.’.pdf’,’F’);

/*$mpdf->progbar_altHTML = ‘

Creating PDF file. Please wait…

‘;
$mpdf->StartProgressBarOutput(); */

//$record = $this->download($resultdata[‘recordinfoData’][$x][‘id’]);
$x++;
}

if($x==$countdata)
{

$this->load->library(‘zip’);

$path=’assets/allinvoice/’.$recorddate;
$this->zip->read_dir($path);
$this->zip->archive($path.’employee_invoice-‘.’.zip’);
$recorddatefolder= scandir($path);
$dataval=$this->zip->download(’employee_invoice-‘.$recorddate.’.zip’);
copy($dataval, ‘assets/allinvoice/’);
if($recorddatefolder!=””)
{
$this->session->set_flashdata(‘updated’, ‘Invoice generated successfuly!’);
redirect(‘/admin_adminusers/employeelistinvoice’, ‘refresh’);
}

/*$d = date(‘Y-m-d’);
@mkdir(“assets/allinvoice/” . $d , 0700);

$source = “assets/allinvoice/”;
$destination = “assets/allinvoice/”.$d.”/”;

$files = scandir($source);

foreach ($files as $file) {
if (in_array($file, array(“.”,”..”))) continue;

if (copy($source.$file, $destination.$file)) {
$delete[] = $source.$file;
}
}
foreach ($delete as $file) {
unlink($file);
}
$newarchive = date(‘Y-m-d’).’_invoice’;
@mkdir(“assets/allinvoice/”.$newarchive, 0700);

$archive=’assets/allinvoice/’.$newarchive.’/’;
$recorddatefolder= scandir($destination);

foreach ($recorddatefolder as $file) {
if (in_array($file, array(“.”,”..”))) continue;
// If we copied this successfully, mark it for deletion
if (copy($destination.$file, $archive.$file)) {
//$delete[] = $source.$file;
$this->load->library(‘zip’);

$this->zip->add_data($file,$record);
$this->zip->compression_level = 0;
$this->zip->archive($source.$newarchive.’.zip’);
//$this->zip->download($archive.’.zip’);
}
}*/

}

}

}

 

single download

=====================

 

 

function downloadempinvoicesingle($downloadid)
{

$this->load->model(‘Members_invoice_model’);
$resultdata[‘recordinfoData’] = $this->Members_invoice_model->Employeeinvoicesingle($downloadid);

$countdata=sizeof($resultdata[‘recordinfoData’]);

for($i=0; $i< sizeof($resultdata[‘recordinfoData’]); $i++)
{

$x = 0;

while($x <= $i) {

$id=$resultdata[‘recordinfoData’][$x][‘id’];
$name=$resultdata[‘recordinfoData’][$x][‘Name’];
$Datemain=explode(“-“,$resultdata[‘recordinfoData’][$x][‘Date’]);
$Date=$Datemain[2].”-“.$Datemain[1].”-“.$Datemain[0];
$yrdata= strtotime($resultdata[‘recordinfoData’][$x][‘Date’]);
$monthlate= date(‘F-Y’, $yrdata);

$invoice_no=$resultdata[‘recordinfoData’][$x][‘invoice_no’];
$Amount=$resultdata[‘recordinfoData’][$x][‘Amount’];
$Account_Details=$resultdata[‘recordinfoData’][$x][‘Account_Details’];
$emailid=$resultdata[‘recordinfoData’][$x][’email_id’];
$pan_no=$resultdata[‘recordinfoData’][$x][‘pan_no’];
$emp_address=$resultdata[‘recordinfoData’][$x][’emp_address’];
$Currency=$resultdata[‘recordinfoData’][$x][‘Currency’];
$Nature=explode(“,”,$resultdata[‘recordinfoData’][$x][‘Nature’]);

$Consultancy_fee=$resultdata[‘recordinfoData’][$x][‘Consultancy_fee’];
$Internet=$resultdata[‘recordinfoData’][$x][‘Internet’];
$Incentive=$resultdata[‘recordinfoData’][$x][‘Incentive’];
$Arrears=$resultdata[‘recordinfoData’][$x][‘Arrears’];
$Advance=$resultdata[‘recordinfoData’][$x][‘Advance’];
$Reimbursement=$resultdata[‘recordinfoData’][$x][‘Reimbursement’];

$databank=explode(“,”,$Account_Details);
$wordamount=ucwords($this->convertToIndianCurrency($Amount));

$mpdf=new mPDF();
$record=$mpdf->WriteHTML(‘<table width=”100%”>
<tr><td>PAN No :’.$pan_no.'</td><td align=”right”> <b><h2 style=”color:blue;”>INVOICE</h2></b></td></tr>
<br>
<tr><td>Name : &nbsp; ‘.$name.'</td></tr>
<br>
<tr><td>Address : ‘.$emp_address.'</td><td align=”right”><b><h4><b style=”color:blue;”>Invoice</b>: ‘.$invoice_no.'</h4></b></td></tr>

<tr><td>E-mail : ‘.$emailid.'</td><td align=”right”><b style=”color:blue;”>Date:</b> &nbsp; ‘.$Date.'</td></tr>
<br>
<br>
<tr><td><b style=”color:blue;”>To</b> <br>

ABC Singapore Pte Ltd
583 Orchard Road #06-01
Forum Singapore 238884

</td><td align=”right”><b style=”color:blue;”>FOR</b> Consultancy fee</td></tr>

<td colspan=”2″><br><br><br><br><br><br><br><br><br><br><br><br></td>
<tr><td colspan=”2″>
<table width=”100%”>

<tr><td width=”70%” style=”border: 1px solid blue; color:blue;” align=”center”>Description</td> <td style=”border: 1px solid blue; color:blue;” align=”center”>Amount in ‘.$Currency.'</td>

</tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[0].'</td><td align=”center” style=”border: 1px solid blue;”>’.$Consultancy_fee.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[1].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Internet.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[2].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Incentive.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[3].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Arrears.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[4].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Advance.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>’.$Nature[5].'</td><td style=”border: 1px solid blue;” align=”center”>’.$Reimbursement.'</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”>&nbsp;</td><td style=”border: 1px solid blue;” align=”center”>&nbsp;</td></tr>
<tr ><td width=”70%” style=”border: 1px solid blue;”><b style=”color:blue;”>Amounts in words</b>:’.$wordamount.’Only</td><td style=”border: 1px solid blue;” align=”center” >’.$Currency.’.’.$Amount.’/</td></tr>
<tr>
<td colspan=”2″><br><br><br><br><br></td>
</tr>
<tr>
<td width=”60%”>
<table>
<tr><td>’.$databank[0].'</td></tr>
<tr><td>’.$databank[1].'</td></tr>
<tr><td>’.$databank[2].'</td></tr>
<tr><td>’.$databank[3].'</td></tr>
<tr><td>’.$databank[4].'</td></tr>

</table>

</td>

<td>

 
 
 
 
 
           Sign : ‘.$name.’

</td>
</tr>

</table>

</td></tr>
<tr>
<td>
<br>
<br>
<br>
<br>
<br>
<br>

</td>
</tr>
<tr><td colspan=”2″ style=”text-align:center;color:blue;”>THANK YOU FOR YOUR BUSINESS!</td></tr>

</table>’);

//$d = date(‘Y-m-d’);
//$maindata=explode(“-“,$d);
//$recorddate=$maindata[2].”-“.$maindata[1].”-“.$maindata[0];

//@mkdir(“assets/allinvoice/” . $recorddate, 0700);

$datapdf=$mpdf->Output(”.$name.’-‘.$id.’.pdf’,’D’);

$x++;
}

/*if($x==$countdata)
{

$this->load->library(‘zip’);

$path=’assets/allinvoice/’.$recorddate;
$this->zip->read_dir($path);
$this->zip->archive($path.’employee_invoice-‘.’.zip’);
$recorddatefolder= scandir($path);
$dataval=$this->zip->download(’employee_invoice-‘.$recorddate.’.zip’);
copy($dataval, ‘assets/allinvoice/’);
if($recorddatefolder!=””)
{
$this->session->set_flashdata(‘updated’, ‘Invoice generated successfuly!’);
redirect(‘/admin_adminusers/employeelistinvoice’, ‘refresh’);
}

} */

}
}

Advertisements

number to word converter function

Standard

Indian Rupees converter  function

function convertToIndianCurrency($number) {
$no = round($number);
$decimal = round($number – ($no = floor($number)), 2) * 100;
$digits_length = strlen($no);
$i = 0;
$str = array();
$words = array(
0 => ”,
1 => ‘One’,
2 => ‘Two’,
3 => ‘Three’,
4 => ‘Four’,
5 => ‘Five’,
6 => ‘Six’,
7 => ‘Seven’,
8 => ‘Eight’,
9 => ‘Nine’,
10 => ‘Ten’,
11 => ‘Eleven’,
12 => ‘Twelve’,
13 => ‘Thirteen’,
14 => ‘Fourteen’,
15 => ‘Fifteen’,
16 => ‘Sixteen’,
17 => ‘Seventeen’,
18 => ‘Eighteen’,
19 => ‘Nineteen’,
20 => ‘Twenty’,
30 => ‘Thirty’,
40 => ‘Forty’,
50 => ‘Fifty’,
60 => ‘Sixty’,
70 => ‘Seventy’,
80 => ‘Eighty’,
90 => ‘Ninety’);
$digits = array(”, ‘Hundred’, ‘Thousand’, ‘Lakh’, ‘Crore’);
while ($i < $digits_length) {
$divider = ($i == 2) ? 10 : 100;
$number = floor($no % $divider);
$no = floor($no / $divider);
$i += $divider == 10 ? 1 : 2;
if ($number) {
$plural = (($counter = count($str)) && $number > 9) ? ‘s’ : null;
$str [] = ($number < 21) ? $words[$number] . ‘ ‘ . $digits[$counter] . $plural : $words[floor($number / 10) * 10] . ‘ ‘ . $words[$number % 10] . ‘ ‘ . $digits[$counter] . $plural;
} else {
$str [] = null;
}
}

$Rupees = implode(‘ ‘, array_reverse($str));
$paise = ($decimal) ? “And Paise ” . ($words[$decimal – $decimal%10]) .” ” .($words[$decimal%10]) : ”;
return ($Rupees ? ‘Rupees’ . $Rupees : ”) . $paise . “Only”;
}