php - auto increment receipt number and year -


currently project receipt number auto incrementing. eg: 1, 2, 3, ...n want prefix financial year differentiate recept number of every year. like, 2016-17/1 2016-17/2 , on. , year should change according financial year (1st april 31 march assume 1 year). once date 1st april receipt number should 2017-18/1 2017-18/2 , on. so, question is..is there code through can have recept no prefix year. thank in advance.

          <div style="float:left">                             <label> receipt no:</label>                              <input type="text" class="form-control"       style="width: 60% !important; color:#999999;" name="receipt_no" value="<?php                             $query = mysql_query("select `receipt_no` tsurphus");                             if(mysql_num_rows($query)>0){                             $data = mysql_query("select max(receipt_no)+1 tsurphus");                             $res = mysql_fetch_row($data);                             echo $res[0];                             echo $_post['$res'];                             }                             else {                                 echo 1;                             }                             ?>" readonly>                              </div> 

so 1/4 31/12 need <current_year> - <next_year> , 1/1 - 31/3 <last_year> - <current_year>

<div style="float:left"> <label> receipt no:</label>  <input type="text" class="form-control" style="width: 60% !important; color:#999999;" name="receipt_no" value="<?php   $curr_month = date('m');  if($curr_month >= 4 && $curr_month <= 12){     $year = date('y') . '-' . date('y', strtotime("+1 year")); } else {     $year = date("y",strtotime("-1 year")) . '-' . date("y");; } echo $year.'/';  $query = mysql_query("select `receipt_no` tsurphus"); if(mysql_num_rows($query)>0){     $data = mysql_query("select max(receipt_no)+1 tsurphus");     $res = mysql_fetch_row($data);     echo $res[0];     echo $_post['$res']; } else {     echo 1; } ?>" readonly> 

but receipt number continuing when financial change. instead of continuing receipt number should reset 1

you can try max counter current year , use it.

$query = mysql_query("select `receipt_no` tsurphus recipt_no '".$year."%'"); 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -