<html>
<head>
<link rel="stylesheet" href="css/jquery-ui.css" />
<link rel="stylesheet" href="css/jquery.autocomplete.css" type="text/css" />
<link rel="stylesheet" href="css/font.css" type="text/css" />
<script type="text/javascript" src="js/media_pur_ajax.js"></script>
<script src="js/jquery/jquery.js" type="text/javascript"></script>
<script src="js/jquery/jquery-1.8.2.js"></script>
<script src="js/jquery/jquery-ui.js"></script>
<script type="text/javascript" src="js/jquery/autocomplete_jquery_plugin.js"></script>
<script src="js/shortcut.js"  type="text/javascript"></script>
<script type="text/javascript" src="js/enter_event_ajax.js"></script>
<script>
function print_media(url)
{	
onmouseover10= window.open(url,'onmouseover10','height=400,width=650,scrollbars=no,resizable=no,left=50,top=50,toolbar=no,location=no,directories=no,status=no');	
}

var sm = jQuery.noConflict();
sm().ready(function() 
{ 
	sm("#in_jobcard_no_media").autocomplete("include/autocomplete/jobcard_no_media_autocomplete.php", {
	width: 250,
	matchContains: true,
	selectFirst: true
	});	
});

 function mediapur_close()
{
window.location.href="main_fram.php?file=media_purchase_list";
window.location.reaload(true);
}


</script>
<style> 
.someclass{ 
background:url(img/plus.png) no-repeat 0 0 ; 
} 
  .types_class1 { 
    height: 25px; 
    width: 250px; 
    background-color: transparent;  
    border-style: solid;  
    border-width: 0px 0px 1px 0px;  
    border-color:#CCC; 
    outline:0;
	font-size:13px;
	font-family:Verdana;
	
  }
input:focus {  border-color:#87BB07; }
select:focus {  border-color:#87BB07; } 
textarea:focus {  border-color:#87BB07; } 
</style> 
<?php
error_reporting(0);
date_default_timezone_set('Asia/Kolkata');
include ("include/db.php");	
$from_date=$_POST['from_date'];
$to_date=$_POST['to_date'];
/******************** Auto Generated ID*********************************************/
$date=date("Y");
$st_date=substr($date,2);
$month=date("m");	   
$datee=$st_date.$month;
$edit_id=$_GET['edit_id'];
ob_start();
session_start();
function get_user_type($login_user_name,$login_pass_word)
{
    $sql_user="select * from  user_creation where user_name='$login_user_name' and password='$login_pass_word'";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$user_type=$rsdata_user->user_type;
	}
	return $user_type;
}

function get_branch_names2($book_branchs1)
{
    $sql_user="select * from  branch_creation where branch_id='$book_branchs1'";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$branch_name=$rsdata_user->branch_name;
	}
	return $branch_name;
}

$login_user_name=$_SESSION['login_user_name'];
$login_pass_word=$_SESSION['login_pass_word'];
$book_branchs1=$_SESSION['branch'];
$get_user_type=get_user_type($login_user_name,$login_pass_word);
$get_branch_names=get_branch_names2($book_branchs1);


function get_branch_place_names($branch_places12)
{
    $sql_user="select * from  place_creation where id='$branch_places12'";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$location=$rsdata_user->location;
	}
	return $location;
}

if($_GET['edit_id']!='')
{
$table_display_styles1='style="display:inline;"';
} 
else
{
$table_display_stylesss='style="display:none;"';
}

  $in_edit_id=$_GET['edit_id'];
  $sql="select * from media_purchase where main_id='$_GET[edit_id]'";
  $rs=mysql_query($sql);
  $rscount=mysql_num_rows($rs);
 
  while($rsdata=mysql_fetch_array($rs))
  {
	   $sno=$sno+1;
	   $from=$from+1;
	   $main_id=$rsdata['main_id'];
	   $media_pur_no1=$rsdata['media_pur_no'];
	   $media_date=$rsdata['media_date'];
	   $total_mtr1=$rsdata['total_mtr'];
	 
  }
  
    	$fulldate=date("Y-m-d");
		  $fyear=date("Y");
		  $current_date=$fulldate;
		  $cur_year=$fyear;
	  
		  $acc_from=$cur_year."-04-01"; 
		  if($acc_from<=$current_date)
		  { 
		    	$fyear=date("Y");
		    	$eyear=date("Y")+1;
		  }
		  if($acc_from>$current_date)
		  {
		 		$fyear=date("Y")-1;
		 		$eyear=date("Y");
		  }
		 $start_year=$fyear."-04-01"; 
		 $end_year=$eyear."-03-31"; 

$curyear=date('Y');
$curmon=date('m');
$next_year=$curyear+1;

if(($curmon>=4)&&($curyear==$curyear-1)||($curmon<=3)&&($curyear==$curyear))
{
	$academic=$curyear-1;
}
else
{
	$academic=$curyear;
}

$date=date("Y");
$st_date=substr($date,2);
$month=date("m");	   
$datee=$st_date.$month;

	$rs1=mysql_query("select media_pur_no from  media_purchase where createdate>='$start_year' and createdate<='$end_year' order by main_id desc");
	if($res1=mysql_fetch_assoc($rs1))
	{
		$media_array=explode('-',$res1['media_pur_no']);
	    $year1=$media_array[1];
        $year2=substr($year1, 0, 2);
	    $year='20'.$year2;
		$invoice_no=$media_array[2];
	}
	if($invoice_no=='')
		$invoice_number='MPR-'.$datee.'-0001';

	else
	{
		$invoice_no+=1;
		$invoice_number='MPR-'.$datee.'-'.str_pad($invoice_no, 4, '0', STR_PAD_LEFT);
	}
?>

<style type="text/css">
.style2 {color: #FF0000}
.style7{font-family: Tahoma, Arial, Helvetica, sans-serif;font-size: 13px;}
.style8{ text-align:center;font-family:Tahoma, Arial, Helvetica, sans-serif; font-size: 15px; padding:40px; font-weight: 500;color:#32328e;letter-spacing: 1px;}
.style9{ text-align:left;font-family:Tahoma, Arial, Helvetica, sans-serif; font-size: 15px; padding:0px; font-weight: 600;letter-spacing: 1px;padding:10px; background-color:#f7f7f7; color:#000;}
.style4 {border-bottom: solid 1px;border-bottom-color: #CCCCCC;}
.style5 {border-left: solid 1px;border-left-color: #CCCCCC;}
.text {font-family: Verdana; font-size:13px;}

</style>
<div class="container">
<div class="row-fluid">
<div class="span12">
<div class="table-responsive">
<form name="media_form"  id="media_form" method="post" action=""  enctype="multipart/form-data">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="border-top:solid 1px; color:#ddd;">
<tr align="left" style="font-size:14px; color:#000"><div class="style9">Media Purchase Form</div></tr>
<td width="12%" align="left"><img src="img/wrong.png" name="add_button" id="add_button" title="Media Close"  onclick="javascript:mediapur_close()" align="top" width="30" height="30" border="0"  style="cursor:pointer; margin-left:96%; margin-top:-34px;" class="button green-button" >
</td>
<tr></tr></table>
<table width="100%" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" >
          <tr>
            <td width="58" height="35"></td>
            <td width="191" align="right" class="text" style="padding-right: 50px; font-size: 14px; color:#F03;">&nbsp;<span style="color: #C30"><strong>Purchase No</strong></span></td>
            <td width="455" style="padding-left:30px;"><span class="text" style="font-size:14px;" >
              <input type="hidden" class="types_class1" name="media_pur_no" id="media_pur_no"  autofocus  value="<?php if($in_edit_id!='') { echo $media_pur_no1; } else {echo $invoice_number; } ?>" readonly><strong><?php if($in_edit_id!='') { echo $media_pur_no1; } else {echo $invoice_number; }  ?></strong> 
              
              
              
              
              </span><div id="in_jobcard_no_media_validation_div" style="color:#F00; font-size:14px; font-family:Verdana, sans-serif;"></div></td>
            <td width="270" align="right" class="text" style="padding-right: 50px; font-size: 14px;">Date &amp; Time</td>
            <td width="353" align="left" class="txt">
              <input type="datetime-local"  name="media_date" id="media_date"  <?php if($_SESSION['user_type']!=1) { ?> readonly <?php } ?>  class="types_class1" onKeyUp="enterevent(event,'customer_dc_no','media_date')"  tabindex="1" style="font-size:12px; height:25px; width:190px; " value="<?php if($in_edit_id!='') { echo $media_date; }  else{ echo  date('Y-m-d').'T'.date('H:i'); }?>"></td>
          </tr>
             
          </tr>
          <tr>
            <td height="327" colspan="5" align="center" ><div id="media_pur_sub_list_div"><?php include('media_pur_sublist.php');?></div></td>
            </tr>
          <tr>
            <td height="65" colspan="5" align="center" valign="bottom"><p>
              <input type="button" name="submit_edit"  id="submit_edit" style="background-color: #87BB07;    color: #fff;    border: 0px; font-family:verdana; font-size:14px; width:120px; height:27px; " value="<?php if($_GET['edit_id']!='') { echo "UPDATE";  } else { echo "SUBMIT"; } ?>" tabindex="7" class="button" onClick="media_purchase(media_pur_no.value,media_date.value,total.value,'<?php echo $edit_id;?>',this.value)">
            </p></td>
          </tr>
          </table>
</form>
</div>
</div>
</div>
</div>