<style>
.style15 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
}
</style>
<script>
function print_function311(url)
{
onmouseover= window.open(url,'','height=580,width=1000,scrollbars=yes,left=50,top=50,toolbar=no,location=no,directories=no,status=no,menubar=no');
}

function delete_porforma_invoice(invoice_no,p_id,billing_types)
{
	if(confirm('Are You Sure! You Want To Delete?'))
	{
		jQuery.ajax({

		type: "POST",

		url: "production/porforma_invoice/proforma_billing_unbilling_db.php",

		data: "invoice_no="+invoice_no+"&p_id="+p_id+"&billing_type="+billing_types+"&action=delete_porforma_invoice",
		success: function(msg){

jQuery("#proforma_billing_main_list_div").html(msg);

		window.location.reload(true);
	}
	});
    }
}

</script>
<?php 
error_reporting(0);
include ("../../include/db.php");
?>
<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%"></td>
<td width="7%" align="center"></td>
</tr>
</table>

<div class="row-fluid">
<div class="span12">
<div class="table-responsive">
<div class="CSSTableGenerator">  
<table width="97%" 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="163" align="left" style="border:1px solid #ddd" scope="col">&nbsp;&nbsp;Jobcard No</th>
      <th scope="col" align="left" style="border:1px solid #ddd" >&nbsp;&nbsp;Invoice No</th>
      <th scope="col" align="left" style="border:1px solid #ddd" >Customer Name</th>
      <th width="133" align="left" scope="col" style="border:1px solid #ddd" >Job Created</th>
      <th width="120" align="right" scope="col" style="border:1px solid #ddd" >Printed Qty</th>
      <th width="100" align="right" scope="col" style="border:1px solid #ddd" >Tot Value</th>
      <th width="131" style="border:1px solid #ddd" scope="col" >Print</th>
      <th width="70" style="border:1px solid #ddd" scope="col" >Delete</th>
      </tr>
 <?php
 include ("../../include/db.php");
ob_start();
session_start();

$user_id = $_SESSION['login_user_id'];
$from_date=$_GET['from_date'];
$to_date=$_GET['to_date'];
$cus_name=$_GET['cus_name'];
$billing_type=$_GET['billing_type'];

 $current_date=date('Y-m-d');
 
 if($from_date!=""){ $from_date1= "bill_date>='$from_date'"; }else{$from_date1="bill_date='$current_date'"; }
 if($to_date!=""){ $to_date1 = "bill_date<='$to_date'";}else{$to_date1='';}
 if($cus_name!=""){ $cus_name1= "cust_name='$cus_name'"; }else{$cus_name1=''; }
 if($billing_type!=""){ $billing_type1= "billing_type='$billing_type'"; }else{$billing_type1=''; }

$all_value10 = $from_date1."@".$to_date1."@".$cus_name1."@".$billing_type1;
$all_array10 = explode('@',$all_value10);
foreach($all_array10 as $value10)
{ 
if($value10!='')
{
$get_query103 .= $value10." AND ";
}
}	  
 function get_freight_charges_list($jobcard_no)
  {
   $sql="select frieght_charges as frieght from printer_production_main where job_card_no='$jobcard_no' union select frieght_charges as frieght from fusing_production_main where job_card_no='$jobcard_no'";
 $rs1=mysql_query($sql);
 while($rsdata=mysql_fetch_array($rs1))		
		{
		$frieght_charges=$rsdata['frieght'];
		}
 return $frieght_charges;
 } 

function get_billing_tot_value($job_card_no)
{
     		$sql2="select sum(jobcard_values) as jobcard_values from  jobcard_sublist where jobcard_no='$job_card_no'"; 
		    $rs2=mysql_query($sql2);
			while($rsdata2=mysql_fetch_array($rs2))
			{
	   			$jobcard_values2=$rsdata2['jobcard_values'];
  			}
  		return $jobcard_values2;
}
function get_tax_type_list($job_card_no)
  {
  $sql="select tax_type as tax_type from printer_production_main where job_card_no='$job_card_no' union select tax_type as tax_type from fusing_production_main where job_card_no='$job_card_no'";
 $rs1=mysql_query($sql);
 while($rsdata=mysql_fetch_array($rs1))		
		{
		$tax_type=$rsdata['tax_type'];
		}
 return $tax_type;
 } 
 
 
function  get_total_billing($invoice_no,$job_card_no,$billing_type)
  {
 $sql_fusing_sub="select * from fusing_jobcard_sub where invoice_no='$invoice_no'  and billing_type='$billing_type' ";
 $rs_fusing_sub=mysql_query($sql_fusing_sub);
 $count_fusing=mysql_num_rows($rs_fusing_sub);
if($count_fusing!=0)
{
  while($rsdata_fusing_sub=mysql_fetch_array($rs_fusing_sub))
  {
  $jobcard_no22=$rsdata_fusing_sub['jobcard_no'];
  $sql="select sum(jobcard_values) as jobcard_values,sum(qty) as qty from jobcard_sublist where jobcard_no='$jobcard_no22'";
   $sno=0;
	 $rs=mysql_query($sql);
	 $rscount=mysql_num_rows($rs);
	   $count_sub+=$rscount;
   		while($rsdata=mysql_fetch_array($rs))		
		{
		$jobcard_values+=$rsdata['jobcard_values'];
		}
	}
}
			else
			{  
			$sql="select sum(jobcard_values) as jobcard_values,sum(qty) as qty from jobcard_sublist where jobcard_no='$job_card_no'";
   $sno=0;
	 $rs=mysql_query($sql);
	 $rscount=mysql_num_rows($rs);
	   $count_sub=$rscount;
   		while($rsdata=mysql_fetch_array($rs))		
		{
	    $sno=$sno+1;
		$jobcard_values+=$rsdata['jobcard_values'];
		} 
}
return $jobcard_values;
}



function  get_qty_billing($invoice_no,$job_card_no,$billing_type)
{
 $sql_fusing_sub="select * from fusing_jobcard_sub where invoice_no='$invoice_no' and billing_type='$billing_type'  ";
 $rs_fusing_sub=mysql_query($sql_fusing_sub);
 $count_fusing=mysql_num_rows($rs_fusing_sub);
if($count_fusing!=0)
{
  while($rsdata_fusing_sub=mysql_fetch_array($rs_fusing_sub))
  {
  $jobcard_nos=$rsdata_fusing_sub['jobcard_no'];
  $sql="select sum(qty) as qty from jobcard_sublist where jobcard_no='$jobcard_nos'";
   $sno=0;
	 $rs=mysql_query($sql);
	 $rscount=mysql_num_rows($rs);
	   $count_sub+=$rscount;
   		while($rsdata=mysql_fetch_array($rs))		
		{
	  $qty_billing+=$rsdata['qty'];
		}
	}
}
else
	{  
	 $sql="select sum(qty) as qty from jobcard_sublist where jobcard_no='$job_card_no'";
	 $sno=0;
	 $rs=mysql_query($sql);
	 $rscount=mysql_num_rows($rs);
	   $count_sub=$rscount;
   		while($rsdata=mysql_fetch_array($rs))		
		{
	    $qty_billing+=$rsdata['qty'];
		} 
}
return $qty_billing;
}


$sql="select * from printer_production_main where  billed_status='1' and billing_type='Proforma Invoice' and  $get_query103 p_id!='' and invoice_no!='0' group by invoice_no,billing_type  union  select *  from fusing_production_main where billed_status='1' and  $get_query103 p_id!='' and invoice_no!='0' and billing_type='Proforma Invoice' group by invoice_no,billing_type order by bill_date,invoice_no,cust_name ASC";

    $rs=mysql_query($sql);
	$sno=0;
	$from=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				$sno=$sno+1;
				$from=$from+1;
   				$p_id=$rsdata['p_id'];
   				$job_card_no=$rsdata['job_card_no'];
				$bill_date=$rsdata['bill_date'];
	   			$cust_name=$rsdata['cust_name'];
	   			$job_created=$rsdata['job_created'];
				$cust_po=$rsdata['cust_po'];
	   			$style_no=$rsdata['style_no'];
	   			$style_name=$rsdata['style_name'];
				$combo=$rsdata['combo'];
	   			$printed_qty=$rsdata['printed_qty'];
				$billed_status=$rsdata['billed_status'];
			    $refer=$rsdata['refer'];
                $invoice_no=$rsdata['invoice_no'];
			 	$billing_types=$rsdata['billing_type'];
				$tax_type=$rsdata['tax_type'];
				$payment_terms=$rsdata['payment_terms'];
				$tot_values=get_billing_tot_value($job_card_no);
				$get_freight=get_freight_charges_list($job_card_no);
				$total_value_job=$tot_values+$get_freight;
				$tax_type_list=get_tax_type_list($job_card_no);
				$total_amount=get_total_billing($invoice_no,$job_card_no,$billing_types);
				$qty_billings=get_qty_billing($invoice_no,$job_card_no,$billing_types);
				$billing_type=$rsdata['billing_type'];
 
  if($tax_type_list=="VAT")
   { 
 	 $a=(($total_amount+$get_freight)*((70/100)*(5/100)));
	 $c=number_format($a,2); 
	}
				
 if($tax_type_list=="CST") 
 { 
  $a=(($total_amount+$get_freight)*((70/100)*(2/100)));
  $c=number_format($a,2); 
 }
		   
		   
 $round_tots=number_format(($total+$frieght_charges+$a),2);
 $b=explode(".",$round_tots);
 $d =$b[1];
 if($b[1]>=50)
 {
 $ss="0.".$b[1];
 $plus=1-$ss;
 }
			
if(($b[1]<=49)&&($b[1]!=0)) { $minus="- 0.".$b[1]; } 

if($billing_type!="Estimate")
{
	$overall_amount = round(($total_amount+$get_freight)+$a);
}
else
{
	$overall_amount = round($total_amount);
}
?>
  <tr>
    <td width="45"  align="center" style="border:1px solid #ddd"><?php echo $from; ?></td>
    <td width="138" align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo date("d-m-Y",strtotime($bill_date));?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $job_card_no;?></td>
    <td width="173" align="left" style="border:1px solid #ddd">&nbsp;<?php echo $invoice_no;?></td>
    <td width="240" align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo $cust_name;?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo $job_created;?></td>
    <td align="right" style="border:1px solid #ddd"><?php echo number_format($qty_billings,3);?></td>
      <td align="right" style="border:1px solid #ddd"><?php echo number_format($overall_amount,2);?></td>
    <td align="center" style="cursor:pointer; border:1px solid #ddd"><?php if($billing_types=='Proforma Invoice') { ?><a href="javascript:print_function311('production/porforma_invoice/proforma_billing_laser_print.php?job_card_no=<?php echo $job_card_no; ?>&invoice_no=<?php echo $invoice_no; ?>&billing_type=<?php echo $billing_types; ?>');" style="text-decoration:none;"><img src="img/PrinterBlack.png" width="28" height="26" title="Print" value="Print"/></a> <?php } ?></td>
    <td align="center" style="border:1px solid #ddd" > <?php if(($user_id=='1')){ ?><img src="img/trash.png" style="cursor:pointer" onClick="delete_porforma_invoice('<?php echo $invoice_no;?>','<?php echo $p_id;?>','<?php echo $billing_types;?>')" width="20px" height="22px"><?php } ?></td>
    </tr>
  <?php $totalss+=$overall_amount;
  $totalss_qtys+=$qty_billings;} ?>
   <tr>
   
    <td align="right" colspan="6" style="border:1px solid #ddd"><strong>Total&nbsp;</strong></td>
    <td align="right" style="border:1px solid #ddd"><strong><?php echo number_format($totalss_qtys,3);?></strong></td> 
   <td align="right" style="border:1px solid #ddd"><strong><?php echo number_format($totalss,3);?></strong></td> 
    <td align="center" style="border:1px solid #ddd"></td> 
     <td align="center" style="border:1px solid #ddd"></td> 
  </tr>
</table>
</div>
</div>
</div>
</div>