<?php include 'connection.php';
session_start();
if (!isset($_SESSION['is_logged_in'])) {
    header("Location:login.php");
    die();
    }
    date_default_timezone_set('Asia/Calcutta');
$today = date("d/m/Y");
$today1 = date("d/m");
$currentmonth = date(m);
    function randomPassword() {
    $alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < 5; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass); //turn the array into a string
}
$unique_id = randomPassword();



$query2job = "select * from check_month";
$resultjob = mysql_query($query2job,$conn);
while($rowmonth=mysql_fetch_array($resultjob))
{
$check_month = $rowmonth['check_month'];
}


?>







<?php
$fin_year=$_REQUEST['fin_year'];

$query2job = "select * from auto_number_job where f_year='$fin_year'";
//echo $query2job;
$resultjob = mysql_query($query2job,$conn);
while($rowjob=mysql_fetch_array($resultjob))

{
$auto_number1 = $rowjob['auto_number'];
 }
 $auto_number=$auto_number1+1;
 $main_job_no= sprintf("%03d", $auto_number);
 if($currentmonth>$check_month) { 
 $datey=date("Y");
 $datey01 =date("y")+1;
  } 
 else {
 $datey=date("Y")-1;
 $datey01 =date("y");
 }
 
  

$job_no_series = "Job"."$datey"."-"."$datey01"."/"."$main_job_no";
if($_REQUEST['main_job_no']!=''){

$f_year = $_REQUEST['f_year']; 
$tsqltp = "update auto_number_job set auto_number ='$auto_number',f_year='$fin_year' where 1 ";
//echo $tsqltp;
$r=mysql_query($tsqltp,$conn);



}


$customer_id = $_POST['customer_id'];
$main_job_no=$_POST['main_job_no'];
$ref_no = $_POST['ref_no'];
$account_of = $_POST['account_of'];
$inv_type = $_POST['inv_type'];
$job_date = $_POST['job_date'];


 $query2c = "select * from customer_master where customer_id='$customer_id'";
		                 				$result2c = mysql_query($query2c,$conn);	
										while($row = mysql_fetch_array($result2c)){
													 $customer_name = $row['customer_name'];
													 $customer_id = $row['customer_id'];
													 }
												
$query14 = "insert into main_job_details (customer_id,customer_name,main_job_no,ref_no,account_of,inv_type,job_date,entry_date,entry_by) values ('$customer_id','$customer_name','$main_job_no','$ref_no','$account_of','$inv_type','$job_date','$today','$user_id')";
$r14=mysql_query($query14,$conn);
//echo $query14;
 //exit();
?> 

<script>
javascript:window.location.href="view_all_jobs.php";
</script>