<style>
.style15 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
}
</style>
<script>
function edit_job_details(edit_id,jobcard_no)
{
window.location.href="main_fram.php?file=jobcard_creation&main_id=" + edit_id + "&jobcard_no=" + jobcard_no;
}

</script>

<?php error_reporting(0);
/***************************** PREVIOUS NEXT CODING ****************************************/
include ("../../include/db.php");
ob_start();
session_start();
$user_id = $_SESSION['login_user_id'];

$show = 20;
$num_links = 19;
$from = $_GET['from'];
if (empty($from))
	 {
		$from = "0";
	 } 
else 
	{
	$html_query = $html_query. "&from=$from";
	}
	
$cust_name=$_GET['customer_name'];
$from_date=$_GET['from_date'];
$to_date=$_GET['to_date'];
$status=$_GET['jobtype'];
$job_card_num=$_GET['job_card_num'];
$status1=$_GET['status1'];
$fabric_types=$_GET['fabric_type'];
$value=explode(',',$_GET['fabric_type']);
 
                   for($i=0;$i<count($value);$i++){                  
                    $fabric1.=$value[$i];                 
				    
				   if($i<(count($value)-1)) {
                   $fabric1.="','";
                  
                   }
				   }
$current_date=date('Y-m-d');


if($cust_name!=""){ $customer_name1= "cust_name='$cust_name'"; }else{$customer_name1=''; }
if($from_date!=""){ $from_date1= "DATE_FORMAT( entry_date,'%Y-%m-%d' )>='$from_date'"; }else{$from_date1="DATE_FORMAT(entry_date,'%Y-%m-%d' )='$cur_dates'"; }
if($to_date!=""){ $to_date1 = "DATE_FORMAT(entry_date,'%Y-%m-%d' )<='$to_date'";}else{$to_date1="DATE_FORMAT(entry_date,'%Y-%m-%d' )='$cur_dates'";}
if($status!=""){ $jobtype1 = "job_type='$status'";}else{$jobtype1='';}
if($job_card_num!=""){ $job_card_nums = "jobcard_no='$job_card_num'";}else{$job_card_nums='';}
if($fabric_types!=""){ $fabric_type1 = "fabric_type IN ('$fabric1')";}else{$fabric_type1='';}
if($status1!=""){ $status1 = "approval_status= '$status1'";}else{$status1='';}
$all_value10 = $customer_name1.";".$from_date1.";".$to_date1.";".$jobtype1.";".$job_card_nums.";".$fabric_type1.";".$status1;
$all_array10 = explode(';',$all_value10);
foreach($all_array10 as $value10)
{ 
if($value10!='')
{
$get_query102 .= $value10." AND ";
}
}	  
 
if(($from_date=='')&&($to_date==''))
  {
   $sql="select * from  jobcard_main where  DATE_FORMAT( entry_date,  '%Y-%m-%d' )='$current_date'  order by jobcard_no ASC ";
  } 
  else
  {
   $sql="select * from  jobcard_main where $get_query102 	main_id!='' order by jobcard_no ASC ";
  }

$html_query = "main_fram.php?file=jobcard_creation_list";
$result=mysql_query($sql);
$num_results=mysql_num_rows($result);
if ($num_results == 0) 
{
 $confirmation = "No Records!";
} 
elseif ($num_results == 1) 
{
$confirmation = "Found 1 Record.";
} 
else 
{
$confirmation = "Found $num_results Records.";
} 
?>
<style type="text/css">
<!--
.style1 {font-size: 16px}
-->
</style>
<table width="100%">
   <tr>
<td width="1%">&nbsp;</td>
<td width="7%" class="style15">&nbsp;</td> 
<td width="13%" align="center">&nbsp;</td>
<td width="1%">&nbsp;</td>
<td width="6%" class="style15">&nbsp;</td>
<td width="14%" align="center"  class="style15">&nbsp;</td>
<td width="2%">&nbsp;</td>
<td width="11%" class="style15">&nbsp;</td>
<td width="24%" align="left" >&nbsp;</td>
<td width="8%" align="center">&nbsp;</td>
<td width="2%"><a onclick="javascript:jobcard_creation_report_overall_excel('<?php echo $_GET['customer_name']; ?>','<?php echo $_GET['from_date']; ?>','<?php echo $_GET['to_date']; ?>','<?php echo $status; ?>','<?php echo $job_card_num; ?>','<?php echo $fabric_types; ?>')" style="float:right"><img  align="right" src="img/excel-icon.png" width="30" height="30" border="0" title="click to export"></a></td>
<td width="7%" align="center"><a href="javascript:print_jobcard('jobcard/jobcard_entry/jobcard_main_print.php?customer_name=<?php echo $_GET['customer_name'];?>&from_date=<?php echo $_GET['from_date'];?>&to_date=<?php echo $_GET['to_date'];?>&jobtype=<?php echo $status; ?>&job_card_num=<?php echo $job_card_num; ?>&fabric_types=<?php echo $fabric_types; ?>');" style="text-decoration:none;"><img src="img/PrinterBlack.png" width="35" height="35" title="Print" value="Print"/></a></td>
  </tr>
</table>
<div class="row-fluid">
<div class="span12">
<div class="table-responsive">
<div class="CSSTableGenerator">  
<table width="99%" border="0" align="center"  cellpadding="0" cellspacing="0" style="border:2px solid #eaeaea;border:1px solid #ddd"  >
      <tr>
      <th align="center" style="border:1px solid #ddd" >S.No</th>
      <th scope="col" align="left" style="border:1px solid #ddd" >&nbsp;Date</th>
      <th width="120" align="left" style="border:1px solid #ddd" scope="col" >&nbsp;&nbsp;Jobcard No</th>
      <th scope="col" align="left" style="border:1px solid #ddd" >Created By</th>
      <th width="255" align="left" scope="col" style="border:1px solid #ddd" >Customer Name</th>
      <th width="131" align="left" scope="col" style="border:1px solid #ddd" >Job Type</th>
      <th width="120" align="left" style="border:1px solid #ddd" scope="col" >&nbsp;&nbsp;Fabric Type</th>
       <th width="108" align="right" scope="col" style="border:1px solid #ddd" >Total Qty&nbsp;</th>
      <th width="90" align="right" scope="col" style="border:1px solid #ddd" >Total Value&nbsp;</th>
      <th width="85" align="center" scope="col" style="border:1px solid #ddd" >View</th>
      <?php if(($user_id=='1'))
	 { 
	 ?>
      <th width="45" align="center" scope="col" style="border:1px solid #ddd" >Edit</th>
      <th width="69" align="center" scope="col" style="border:1px solid #ddd" >Delete</th>
	<?php } ?>
	<th width="69" align="center" scope="col" style="border:1px solid #ddd" colspan="2">Approve</th>
      </tr>
  <?php
  include ("../../include/db.php");
  
  function place_branch_name($book_branch)
  {
	$sql_user="select * from branch_creation where branch_id='$book_branch' and delete_status!='1' ";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$branch_name=$rsdata_user->branch_name;
	}
	return $branch_name;
  }
 function get_tot_qty_jobcard($jobcard_no)
  {
	$sql_user="select sum(qty) as qty from jobcard_sublist where jobcard_no='$jobcard_no'";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$qty12=$rsdata_user->qty;
	}
	return $qty12;
  }
 
  function book_place_names($book_place)
  {
	$sql_user="select * from place_creation where id='$book_place'";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$location=$rsdata_user->location;
	}
	return $location;
  }
  
  function gets_book_count($booking_no)
  {
	  $sql_user="select * from booking_sub_list where book_no='$booking_no'";
	  $rs_user=mysql_query($sql_user);
	  $rs_count=mysql_num_rows($rs_user); 
	  return $rs_count;
  }
  

$cust_name=$_GET['customer_name'];
$from_date=$_GET['from_date'];
$to_date=$_GET['to_date'];
$status=$_GET['jobtype'];
$current_date=date('Y-m-d');
$job_card_num=$_GET['job_card_num'];
$fabric_types=$_GET['fabric_type'];
$status1=$_GET['status1'];
$value=explode(',',$_GET['fabric_type']);
 
                   for($i=0;$i<count($value);$i++){                  
                    $fabric.=$value[$i];                 
				    
				   if($i<(count($value)-1)) {
                   $fabric.="','";
                  
                   }
				   }

if($cust_name!=""){ $customer_name1= "cust_name='$cust_name'"; }else{$customer_name1=''; }
if($from_date!=""){ $from_date1= "DATE_FORMAT( entry_date,'%Y-%m-%d' )>='$from_date'"; }else{$from_date1="DATE_FORMAT(entry_date,'%Y-%m-%d' )='$cur_dates'"; }
if($to_date!=""){ $to_date1 = "DATE_FORMAT(entry_date,'%Y-%m-%d' )<='$to_date'";}else{$to_date1="DATE_FORMAT(entry_date,'%Y-%m-%d' )='$cur_dates'";}
if($status!=""){ $jobtype1 = "job_type='$status'";}else{$jobtype1='';}
if($job_card_num!=""){ $job_card_nums = "jobcard_no='$job_card_num'";}else{$job_card_nums='';}
if($fabric_types!=""){ $fabric_type1 = "fabric_type IN ('$fabric')";}else{$fabric_type1='';}
if($status1!=""){ $status1 = "approval_status= '$status1'";}else{$status1='';}
$all_value10 = $customer_name1.";".$from_date1.";".$to_date1.";".$jobtype1.";".$job_card_nums.";".$fabric_type1.";".$status1;
$all_array10 = explode(';',$all_value10);
foreach($all_array10 as $value10)
{ 
if($value10!='')
{
 $get_query103 .= $value10." AND ";
}
}	  


if(($from_date=='')&&($to_date==''))
  {
   $sql="select * from  jobcard_main where  DATE_FORMAT( entry_date, '%Y-%m-%d' )='$current_date'  order by jobcard_no  ASC LIMIT $from,20";
  } 
  else
  {
   $sql="select * from  jobcard_main where $get_query103 main_id!='' order by jobcard_no ASC LIMIT $from,20";
  }
  
	$rs=mysql_query($sql);
	$sno=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				$sno=$sno+1;
				$from=$from+1;
   				$main_id=$rsdata['main_id'];
   				$jobcard_no=$rsdata['jobcard_no'];
				$created_by=$rsdata['created_by'];
	   			$cust_name=$rsdata['cust_name'];
				$book_place_names=book_place_names($book_place);
	   			$entry_date=$rsdata['entry_date'];
				$book_branch_names=place_branch_name($book_branch);
				$job_type=$rsdata['job_type'];
	   			$fabric_type=$rsdata['fabric_type'];
	   			$overall_value=$rsdata['overall_value'];
	   			$net_total=$rsdata['net_total'];
				$item_image=$rsdata['item_image'];
				$approval_status=$rsdata['approval_status'];
				// echo $approval_status;
				$tot_qty=get_tot_qty_jobcard($jobcard_no);
  ?>
  <tr>
    <td width="55"  align="center" style="border:1px solid #ddd"><?php echo $from; ?></td>
    <td width="93" align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo date("d-m-Y",strtotime($entry_date));?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $jobcard_no;?></td>
    <td width="125" align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo $created_by;?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo $cust_name;?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;<?php echo $job_type;?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo $fabric_type;?></td>
     <td align="right" style="border:1px solid #ddd"><?php echo number_format($tot_qty,2);?>&nbsp;</td>
    <td align="right" style="border:1px solid #ddd"><?php echo number_format($net_total,2);?>&nbsp;</td>
    <?php if($user_id=='11')
   { ?>
    <td align="center" style="cursor:pointer; border:1px solid #ddd"><a href="javascript:individual_print_jobcard('jobcard/jobcard_entry/jobcard_view_print_with_rate.php?jobcard_no=<?php echo $jobcard_no;?>&cust_name=<?php echo $cust_name;?>&item_image=<?php echo $item_image;?>');" style="text-decoration:none;"><img src="img/PrinterBlack.png" width="30" height="30" title="With Rate Print" value="Print"/></a>

    <span align="center" style="cursor:pointer; "></span><a href="javascript:individual_print_jobcard('jobcard/jobcard_entry/jobcard_view_print.php?jobcard_no=<?php echo $jobcard_no;?>&cust_name=<?php echo $cust_name;?>&item_image=<?php echo $item_image;?>');" style="text-decoration:none;"><img src="img/PrinterBlack.png" width="30" height="30" title="Without Rate Print" value="Print"/></a></td>
  <?php }else{?>
     <td align="center" style="cursor:pointer;border:1px solid #ddd "><a href="javascript:individual_print_jobcard('jobcard/jobcard_entry/jobcard_view_print.php?jobcard_no=<?php echo $jobcard_no;?>&cust_name=<?php echo $cust_name;?>&item_image=<?php echo $item_image;?>');" style="text-decoration:none;"><img src="img/PrinterBlack.png" width="30" height="30" title="Print" value="Print"/></a></td>
   <?php }?>
    <?php if(($user_id=='1'))
	 { 
	 ?> <td align="center" style="cursor:pointer; border:1px solid #ddd"><img src="img/edit.png" width="17" height="20" title="EDIT" onclick="javascript:edit_job_details('<?php echo $main_id;?>','<?php echo $jobcard_no;?>');"/></td> <?php } ?><?php if(($user_id=='1'))
	 { 
	 ?> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
    <td align="center" style="border:1px solid #ddd" ><img src="img/trash.png" style="cursor:pointer" onClick="del_job_main('<?php echo $main_id;?>','<?php echo  $jobcard_no;?>')" width="20px" height="22px">
    </td><?php } $query="select * from   jobcard_sublist where jobcard_no='$jobcard_no'";
 $rack=mysql_query($query);
 				$app=2;
   		while($luckey=mysql_fetch_array($rack))
  			{ 
  				$width=$luckey['width'];
				$height=$luckey['height'];
				$conformed_amt=$luckey['conformed_amt'];
    		$rate=$luckey['rate'];
    		$conformed_rate=($conformed_amt)/($width*$height);
    		$jerry=number_format($conformed_rate,4);
    		// $jerry=number_format($rate,4);
    		  // echo $jerry.'<br>'."Lokie";
				}?><input type="hidden" name="app" id="app" value="<?php echo $jerry; ?>">
				<?php $app=2;  if($jerry<=0.02){  if(($user_id=='1')) { ?>
   <td align="center"><?php  if($approval_status=='1'){?><span id="boot-icon" class="bi bi-hand-thumbs-up" style="font-size: 10rem; color: rgb(50,205,50);font-size: 1.5rem;"></span> <?php } else{?><input type="button" id="approval" name="approval" value="Approve" style="color: blue;" onclick="approval_check('<?php echo $main_id; ?>','<?php echo $jobcard_no; ?>')"><?php } ?>
 <?php }}else{ $test1=mysql_query("update jobcard_main set approval_status = '$app' where main_id = $main_id");?><?php } ?>  
  <?php } ?>
  </td>
  </tr>
</table>
</div>
<table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" >

 <tr>
    <th height="19" align="left" style="font-size:12px; font-family:sans-serif; padding-top:10px;" scope="col"><?php echo $confirmation;?></th>
	<th scope="cols" width="8%" align="right"><?php  
			  if ($num_results > $show) 
			  { 			  $show;
			include("footer_links1.php");
			  }
	?></th>
 </tr>
</table>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script type="text/javascript">
	function approval_check(main_id,jobcard_no){
		  // alert(jobcard_no);
		$.ajax({
    		type: "POST",
			url: "jobcard/jobcard_entry/approval.php?action=SUBMIT",
			data: "main_id="+main_id+"&jobcard_no="+jobcard_no,
			success: function(data){

				// alert(data);
			window.location.reload(true);
						document.getElementById('#approval').style.visibility = 'hidden';
   		},
			
		});
		btn.style.display = 'none';
	}


</script>
