Auto generate invoice number in php with financial year format?
How to create auto generated invoice number in PHP with financial year format?
Here I am going to share one of my work to generate auto Invoice number in PHP along with current financial year just like 18-19/0000001, 18-19/0000002.
<?php
function invoiceId()
{
$db=getDB();
$max = $db->prepare("select max(id) mid from invoice_table");
$max->execute();
$row = $max->fetch(PDO::FETCH_BOTH);
$mid= $row['mid']+1;
$y=date('y');
$m=date('m');
$cy;
$ny;
if($m<4)
{
$cy=$y-1;
$ny=$y;
}
else
{
$cy=$y;
$ny=$y+1;
}
$id =$cy."-".$ny."/".str_pad($mid, 8, "0", STR_PAD_LEFT);
return $id;
}
?>
just call this function while inserting record it will return id.
Comments
Post a Comment